| 1 |
<?php |
<?php |
| 2 |
// $Id: casetracker_client.module,v 1.2.2.2 2008/03/29 08:40:03 sime Exp $ |
// $Id: casetracker_client.module,v 1.2.2.5 2008/03/29 19:51:54 sime Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 14 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 15 |
*/ |
*/ |
| 16 |
function casetracker_client_menu($may_cache) { |
function casetracker_client_menu($may_cache) { |
| 17 |
if ($may_cache) { |
if ($may_cache) { |
| 18 |
|
// Replace the stylesheet. |
| 19 |
|
casetracker_client_get_css(true); |
| 20 |
|
|
| 21 |
$items[] = array( |
$items[] = array( |
| 22 |
'path' => 'admin/settings/casetracker_client', |
'path' => 'admin/settings/casetracker_client', |
| 23 |
'access' => user_access('administer site configuration'), |
'access' => user_access('administer site configuration'), |
| 162 |
* Get display a node from the Case Tracker server site. |
* Get display a node from the Case Tracker server site. |
| 163 |
*/ |
*/ |
| 164 |
function casetracker_client_node() { |
function casetracker_client_node() { |
| 165 |
drupal_add_css(drupal_get_path('module', 'casetracker_client') .'/casetracker_client.css', 'module', 'all', false); |
drupal_add_css(casetracker_client_get_css(), 'module', 'all', false); |
| 166 |
|
|
| 167 |
|
// Pass these to the theme function, so that late correction of urls can occur (but in theory it shouldn't be needed). |
| 168 |
$url = variable_get('casetracker_client_server_url', ''); |
$url = variable_get('casetracker_client_server_url', ''); |
| 169 |
$key = variable_get('casetracker_client_server_key', ''); |
$key = variable_get('casetracker_client_server_key', ''); |
| 170 |
|
|
| 226 |
} |
} |
| 227 |
} |
} |
| 228 |
|
|
| 229 |
drupal_add_css(drupal_get_path('module', 'casetracker_client') .'/casetracker_client.css'); |
drupal_add_css(casetracker_client_get_css(), 'module', 'all', false); |
| 230 |
|
|
| 231 |
if ($pid) { |
if ($pid) { |
| 232 |
$projects = casetracker_client_projects_list(); |
$projects = casetracker_client_projects_list(); |
| 233 |
$title = 'Cases for: '. $projects[$pid]['title']; |
$title = 'Cases for: '. $projects[$pid]['title']; |
|
|
|
| 234 |
// The 'all' stands for filter I haven't coded in the service yet. |
// The 'all' stands for filter I haven't coded in the service yet. |
|
// We add $key to the call url, it will be used by casetracker_services to restrict a project nid. |
|
| 235 |
$cases = casetracker_remote_call('casetracker.cases', $pid, 'all'); |
$cases = casetracker_remote_call('casetracker.cases', $pid, 'all'); |
|
// $cases = xmlrpc($url .'/services/xmlrpc/'. $key, 'casetracker.cases', $key, $pid, 'all'); |
|
| 236 |
return theme('casetracker_client_cases', $cases, $title); |
return theme('casetracker_client_cases', $cases, $title); |
| 237 |
} |
} |
| 238 |
else { |
else { |
| 277 |
|
|
| 278 |
/** |
/** |
| 279 |
* Theme our list of cases from the CT server. |
* Theme our list of cases from the CT server. |
| 280 |
|
* |
| 281 |
|
* TODO: Make this much more flexible. The server will send |
| 282 |
*/ |
*/ |
| 283 |
function theme_casetracker_client_cases($overview, $title = 'Cases overview') { |
function theme_casetracker_client_cases($overview, $title = 'Cases overview') { |
| 284 |
if (!is_array($overview['data']) || !count($overview['data'])) { |
if (!is_array($overview['data']) || !count($overview['data'])) { |
| 291 |
$type = $overview['lookup'][$case['case_type_id']]; |
$type = $overview['lookup'][$case['case_type_id']]; |
| 292 |
$priority = $overview['lookup'][$case['case_priority_id']]; |
$priority = $overview['lookup'][$case['case_priority_id']]; |
| 293 |
$row = array( |
$row = array( |
| 294 |
'class' => 'state-'. $case['case_status_id'] .' type-'. $case['case_type_id'], |
'class' => 'status-'. $case['case_status_id'] .' type-'. $case['case_type_id'] .' priority-'. $case['case_priority_id'], |
| 295 |
'data' => array( |
'data' => array( |
| 296 |
l($case['pid'], 'admin/casetracker_client/overview/'. $case['pid']), |
l($case['project_number'], 'admin/casetracker_client/overview/'. $case['pid']), |
| 297 |
$case['case_number'], |
$case['case_number'], |
| 298 |
l($case['title'], 'admin/casetracker_client/case/'. $case['nid']), |
l($case['title'], 'admin/casetracker_client/case/'. $case['nid']), |
| 299 |
format_date($case['last_comment_timestamp'], 'short'), |
format_date($case['last_comment_timestamp'], 'short'), |
| 300 |
$type, |
array('data' => $type, 'class' => 'col-type'), |
| 301 |
$status, |
array('data' => $status, 'class' => 'col-status'), |
| 302 |
$priority, |
array('data' => $priority, 'class' => 'col-priority'), |
| 303 |
), |
), |
| 304 |
); |
); |
| 305 |
$display[] = $row; |
$display[] = $row; |
| 306 |
} |
} |
| 307 |
$output = ''; |
$output = ''; |
| 308 |
|
|
| 309 |
$output .= '<h3>'. $title .'</h3>'. theme('table', array('PID', 'Case', 'Title', 'Updated', 'Type', 'Status', 'Prioirity'), $display); |
$output .= '<h3>'. $title .'</h3>'. theme('table', $overview['header'], $display); |
| 310 |
return $output . $overview['pager']; |
return $output . $overview['pager']; |
| 311 |
} |
} |
| 312 |
|
|
| 430 |
$nid = casetracker_remote_call('casetracker.log', $nid, $form_values); |
$nid = casetracker_remote_call('casetracker.log', $nid, $form_values); |
| 431 |
return 'admin/casetracker_client/case/'. $nid; |
return 'admin/casetracker_client/case/'. $nid; |
| 432 |
} |
} |
| 433 |
|
|
| 434 |
|
// We ask the remote site for a stylesheet to save locally. |
| 435 |
|
// We could instead point to the remote site but we'd still need to find out |
| 436 |
|
// where the stylesheet is. |
| 437 |
|
function casetracker_client_get_css($reset = false) { |
| 438 |
|
$path = file_directory_path() .'/casetracker_cache'; |
| 439 |
|
$path .= '/casetracker_client.css'; |
| 440 |
|
if ($reset || !file_exists($path)) { |
| 441 |
|
$style = casetracker_remote_call('casetracker.css'); |
| 442 |
|
// Write new stylesheet |
| 443 |
|
$file = fopen($path, 'w+'); |
| 444 |
|
fwrite($file, $style); |
| 445 |
|
fclose($file); |
| 446 |
|
// Set standard file permissions for webserver-generated files |
| 447 |
|
@chmod($path, 0664); |
| 448 |
|
} |
| 449 |
|
return $path; |
| 450 |
|
} |