| 1 |
<?php |
<?php |
| 2 |
// $Id: timemap.module,v 1.2 2008/06/03 02:34:15 sethfreach Exp $ |
// $Id: timemap.module,v 1.3 2008/06/11 22:24:40 sethfreach Exp $ |
| 3 |
|
|
| 4 |
|
/* TODO Implement the hook_theme registry. Combine all theme registry entries |
| 5 |
|
into one hook_theme function in each corresponding module file. |
| 6 |
|
function timemap_theme() { |
| 7 |
|
return array( |
| 8 |
|
'timemap_admin_settings' => array( |
| 9 |
|
'file' => 'timemap.module', |
| 10 |
|
'arguments' => array( |
| 11 |
|
'form' => NULL, |
| 12 |
|
), |
| 13 |
|
), |
| 14 |
|
'timemap_viewable_reports_list_people' => array( |
| 15 |
|
'file' => 'timemap.module', |
| 16 |
|
'arguments' => array( |
| 17 |
|
'list' => array(), |
| 18 |
|
), |
| 19 |
|
), |
| 20 |
|
); |
| 21 |
|
} */ |
| 22 |
/** |
/** |
| 23 |
* @file |
* @file |
| 24 |
* Timemap module - Track how you spend your day with a simple as possible input interface. |
* Timemap module - Track how you spend your day with a simple as possible input interface. |
| 25 |
*/ |
*/ |
| 26 |
|
|
| 27 |
|
|
| 28 |
/** |
/** |
| 29 |
* Implementation of hook_perm |
* Implementation of hook_perm |
| 30 |
*/ |
*/ |
| 31 |
function timemap_perm() { |
function timemap_perm() { |
| 32 |
$perms = array( |
$perms = array( |
| 33 |
'enter tasks', |
'enter tasks', |
| 34 |
'edit own categories', |
'edit own categories', |
| 35 |
'edit global categories', |
'edit global categories', |
| 36 |
'edit timemap settings', |
'edit timemap settings', |
| 37 |
'view own report', |
'view own report', |
| 38 |
'view all reports', |
'view all reports', |
| 39 |
); |
); |
| 40 |
|
|
| 41 |
// If CiviCRM is installed, offer more perms that allow people to view subsets of reports |
// If CiviCRM is installed, offer more perms that allow people to view subsets of reports |
| 42 |
// as defined by CiviCRM relationships. |
// as defined by CiviCRM relationships. |
| 43 |
// |
// |
| 46 |
if (module_exists('civicrm')) { |
if (module_exists('civicrm')) { |
| 47 |
$perms[] = 'view subordinate reports'; |
$perms[] = 'view subordinate reports'; |
| 48 |
} |
} |
| 49 |
|
|
| 50 |
return $perms; |
return $perms; |
| 51 |
} |
} |
| 52 |
|
|
| 55 |
/** |
/** |
| 56 |
* Implementation of hook_menu |
* Implementation of hook_menu |
| 57 |
*/ |
*/ |
| 58 |
function timemap_menu($may_cache) { |
function timemap_menu() { |
| 59 |
if (! $may_cache) { |
$items['timemap'] = array( |
| 60 |
$items[] = array( |
'title' => 'Time Maps', |
| 61 |
'title' => t('Time Maps'), |
'page callback' => 'timemap_dashboard', |
| 62 |
'path' => 'timemap', |
'access arguments' => array('enter tasks'), |
| 63 |
'callback' => 'timemap_dashboard', |
); |
| 64 |
'access' => user_access('enter tasks'), |
$items['timemap/doing'] = array( |
| 65 |
); |
'title' => 'Enter a task', |
| 66 |
$items[] = array( |
'page callback' => 'timemap_enter_task', |
| 67 |
'title' => t('Enter a task'), |
'access arguments' => array('enter tasks'), |
| 68 |
'path' => 'timemap/doing', |
); |
| 69 |
'callback' => 'timemap_enter_task', |
$items['timemap/map'] = array( |
| 70 |
'access' => user_access('enter tasks'), |
'title' => 'Personal Time Map', |
| 71 |
); |
'page callback' => 'timemap_map', |
| 72 |
$items[] = array( |
'access arguments' => array('view own report'), |
| 73 |
'title' => t('Personal Time Map'), |
); |
| 74 |
'path' => 'timemap/map', |
$items['timemap/report'] = array( |
| 75 |
'callback' => 'timemap_map', |
'title' => 'Time Map Reports', |
| 76 |
'access' => user_access('view own report'), |
'page callback' => 'timemap_report', |
| 77 |
); |
'access arguments' => array('view own report'), |
| 78 |
$items[] = array( |
'type' => MENU_CALLBACK, // technically enable it, but effecively hide it while incomplete. |
| 79 |
'title' => t('Time Map Reports'), |
); |
| 80 |
'path' => 'timemap/report', |
$items['admin/settings/timemap'] = array( |
| 81 |
'callback' => 'timemap_report', |
'title' => 'Time Map Settings', |
| 82 |
'access' => user_access('view own report'), |
'description' => 'Change some settings and defaults for the Timemap module', |
| 83 |
'type' => MENU_CALLBACK, // technically enable it, but effecively hide it while incomplete. |
'page callback' => 'drupal_get_form', |
| 84 |
); |
'page arguments' => array('timemap_admin_settings'), |
| 85 |
$items[] = array( |
'access arguments' => (user_access('edit global categories') || user_access('edit timemap settings')), |
| 86 |
'path' => 'admin/settings/timemap', |
); |
| 87 |
'title' => t('Time Map Settings'), |
$items['timemap/map/serv'] = array( |
| 88 |
'description' => t('Change some settings and defaults for the Timemap module'), |
'title' => 'Time Spent Reports Server', |
| 89 |
'callback' => 'drupal_get_form', |
'page callback' => 'timemap_map_serv', |
| 90 |
'callback arguments' => array('timemap_admin_settings'), |
'access arguments' => array('view own report'), |
| 91 |
'access' => (user_access('edit global categories') || user_access('edit timemap settings')), |
'type' => MENU_CALLBACK, |
| 92 |
); |
); |
| 93 |
|
$items['timemap/doing/autoc'] = array( |
| 94 |
// } else { |
'title' => 'Task Entry Autocomplete Ajax Callback', |
| 95 |
|
'page callback' => 'timemap_doing_autoc', |
| 96 |
$items[] = array( |
'access arguments' => array('enter tasks'), |
| 97 |
'title' => t('Time Spent Reports Server'), |
'type' => MENU_CALLBACK, |
| 98 |
'path' => 'timemap/map/serv', |
); |
|
'callback' => 'timemap_map_serv', |
|
|
'access' => user_access('view own report'), |
|
|
'type' => MENU_CALLBACK, |
|
|
); |
|
|
$items[] = array( |
|
|
'path' => 'timemap/doing/autoc', |
|
|
'title' => t('Task Entry Autocomplete Ajax Callback'), |
|
|
'callback' => 'timemap_doing_autoc', |
|
|
'access' => user_access('enter tasks'), |
|
|
'type' => MENU_CALLBACK, |
|
|
); |
|
|
|
|
|
} |
|
| 99 |
|
|
| 100 |
return $items; |
return $items; |
| 101 |
} |
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 115 |
'title' => t('Time Mapping'), |
'title' => t('Time Mapping'), |
| 116 |
); |
); |
| 117 |
return $blocks; |
return $blocks; |
| 118 |
|
|
| 119 |
case 'view': |
case 'view': |
| 120 |
switch ($delta) { |
switch ($delta) { |
| 121 |
case 0: |
case 0: |
| 126 |
} |
} |
| 127 |
return $block; |
return $block; |
| 128 |
} |
} |
| 129 |
} |
} |
| 130 |
|
|
| 131 |
/*******************************************************/ |
/*******************************************************/ |
| 132 |
|
|
| 133 |
/** |
/** |
| 134 |
* form to admin and set the defaults. the "config" settings |
* form to admin and set the defaults. the "config" settings |
| 135 |
*/ |
*/ |
| 136 |
function timemap_admin_settings() { |
function timemap_admin_settings() { |
| 137 |
global $user; |
global $user; |
| 138 |
|
|
| 139 |
$form['#validate']['timemap_admin_settings_validate'] = array(); |
$form['#validate'][] = 'timemap_admin_settings_validate'; |
| 140 |
$form['#submit']['timemap_admin_settings_submit'] = array(); |
$form['#submit'][] = 'timemap_admin_settings_submit'; |
| 141 |
|
|
| 142 |
$form['gcats'] = array( |
$form['gcats'] = array( |
| 143 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 144 |
'#access' => user_access('edit global categories'), |
'#access' => user_access('edit global categories'), |
| 147 |
'#collapsed' => false, |
'#collapsed' => false, |
| 148 |
'#weight' => -2, |
'#weight' => -2, |
| 149 |
); |
); |
| 150 |
|
|
| 151 |
// add a new one. |
// add a new one. |
| 152 |
$form['gcats']['newgcat'] = array( |
$form['gcats']['newgcat'] = array( |
| 153 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 165 |
'#default_value' => '#ffffff', |
'#default_value' => '#ffffff', |
| 166 |
'#colorpicker' => 'color_new', |
'#colorpicker' => 'color_new', |
| 167 |
); |
); |
| 168 |
} |
} |
| 169 |
else { |
else { |
| 170 |
$form['gcats']['color_new_v'] = array( |
$form['gcats']['color_new_v'] = array( |
| 171 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 174 |
'#default_value' => '#ffffff', |
'#default_value' => '#ffffff', |
| 175 |
); |
); |
| 176 |
} |
} |
| 177 |
|
|
| 178 |
// edit existing ones. |
// edit existing ones. |
| 179 |
$result = db_query("select c.cid as cid, c.category as category, c.active as active, cc.hex as hex |
$result = db_query("select c.cid as cid, c.category as category, c.active as active, cc.hex as hex |
| 180 |
from {timemap_categories} c left join {timemap_catcolor} cc on c.cid = cc.cid |
from {timemap_categories} c left join {timemap_catcolor} cc on c.cid = cc.cid |
| 181 |
where c.uid = 0"); |
where c.uid = 0"); |
| 182 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 183 |
$categories[$row->cid] = array( |
$categories[$row->cid] = array( |
| 186 |
$row->hex, |
$row->hex, |
| 187 |
); |
); |
| 188 |
} |
} |
| 189 |
|
|
| 190 |
if (empty($categories)) { |
if (empty($categories)) { |
| 191 |
$categories = array(); |
$categories = array(); |
| 192 |
} |
} |
| 193 |
|
|
| 194 |
foreach ($categories as $cid => $c) { |
foreach ($categories as $cid => $c) { |
| 195 |
$form['gcats']['cid_enable_'. $cid] = array( |
$form['gcats']['cid_enable_'. $cid] = array( |
| 196 |
'#type' => 'radios', |
'#type' => 'radios', |
| 197 |
'#title' => t($c[0]), |
'#title' => t($c[0]), |
| 198 |
'#options' => array(0 => 'disabled', 1 => 'enabled'), |
'#options' => array(0 => 'disabled', 1 => 'enabled'), |
| 199 |
'#default_value' => $c[1], |
'#default_value' => $c[1], |
| 200 |
); |
); |
| 201 |
if (module_exists('colorpicker')) { |
if (module_exists('colorpicker')) { |
| 202 |
$form['gcats']['color_'. $cid] = array( |
$form['gcats']['color_'. $cid] = array( |
| 209 |
'#default_value' => $c[2], |
'#default_value' => $c[2], |
| 210 |
'#colorpicker' => 'color_'. $cid, |
'#colorpicker' => 'color_'. $cid, |
| 211 |
); |
); |
| 212 |
} |
} |
| 213 |
else { |
else { |
| 214 |
$form['gcats']['color_'. $cid .'_v'] = array( |
$form['gcats']['color_'. $cid .'_v'] = array( |
| 215 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 217 |
'#description' => t('Choose a color to display for this category. Enter it in 6 char hex *with* a preceding #.'), |
'#description' => t('Choose a color to display for this category. Enter it in 6 char hex *with* a preceding #.'), |
| 218 |
'#default_value' => $c[2], |
'#default_value' => $c[2], |
| 219 |
); |
); |
| 220 |
} |
} |
| 221 |
} |
} |
| 222 |
|
|
| 223 |
$form['gsets'] = array( |
$form['gsets'] = array( |
| 224 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 225 |
'#access' => user_access('edit timemap settings'), |
'#access' => user_access('edit timemap settings'), |
| 237 |
); |
); |
| 238 |
if (module_exists('civicrm')) { |
if (module_exists('civicrm')) { |
| 239 |
$supervisor_role_opts = array(); |
$supervisor_role_opts = array(); |
| 240 |
// TODO: This is a CiviCRM 1.8 API call. Add logic to determine correct CiviCRM version used and API call!! |
// TODO: This is a CiviCRM 1.8 API call. Add logic to determine correct CiviCRM version used and API call!! |
| 241 |
foreach(crm_get_relationship_types() as $rel) { |
foreach(crm_get_relationship_types() as $rel) { |
| 242 |
if ( |
if ( |
| 243 |
$rel->contact_type_a == 'Individual' && |
$rel->contact_type_a == 'Individual' && |
| 244 |
$rel->contact_type_b == 'Individual' && |
$rel->contact_type_b == 'Individual' && |
| 245 |
$rel->name_a_b != $rel->name_b_a |
$rel->name_a_b != $rel->name_b_a |
| 246 |
) { |
) { |
| 247 |
$supervisor_role_opts[] = $rel->name_a_b; |
$supervisor_role_opts[] = $rel->name_a_b; |
| 248 |
$supervisor_role_opts[] = $rel->name_b_a; |
$supervisor_role_opts[] = $rel->name_b_a; |
| 249 |
} |
} |
| 250 |
} |
} |
| 251 |
$form['gsets']['timemap_civicrm_subord_rel'] = array( |
$form['gsets']['timemap_civicrm_subord_rel'] = array( |
| 252 |
'#type' => 'select', |
'#type' => 'select', |
| 253 |
'#title' => t('Supervisory Relationship'), |
'#title' => t('Supervisory Relationship'), |
| 256 |
'#default_value' => variable_get('timemap_civicrm_subord_rel', null), |
'#default_value' => variable_get('timemap_civicrm_subord_rel', null), |
| 257 |
); |
); |
| 258 |
} |
} |
| 259 |
|
|
| 260 |
return system_settings_form($form); |
return system_settings_form($form); |
| 261 |
} |
} |
| 262 |
|
|
| 263 |
function timemap_admin_settings_validate($id, $values) { |
function timemap_admin_settings_validate($form, &$form_state) { |
| 264 |
if (user_access('edit global categories')) { |
if (user_access('edit global categories')) { |
| 265 |
if ($values['color_new_v'] && (! preg_match('/^#[0-9A-F]{6}$/i', $values['color_new_v'])) ) { |
if ($values['color_new_v'] && (! preg_match('/^#[0-9A-F]{6}$/i', $values['color_new_v'])) ) { |
| 266 |
form_set_error('color_new_v', t('Please enter a hex value with a preceding \'#\' sign')); |
form_set_error('color_new_v', t('Please enter a hex value with a preceding \'#\' sign')); |
| 267 |
} |
} |
| 268 |
} |
} |
| 269 |
|
|
| 270 |
if (user_access('edit timemap settings')) { |
if (user_access('edit timemap settings')) { |
| 271 |
if (! is_numeric($values['timemap_report_default_days_to_show'])) { |
if (! is_numeric($values['timemap_report_default_days_to_show'])) { |
| 272 |
form_set_error('timemap_report_default_days_to_show', t('Please enter a number')); |
form_set_error('timemap_report_default_days_to_show', t('Please enter a number')); |
| 273 |
} |
} |
| 274 |
} |
} |
| 275 |
} |
} |
| 276 |
|
|
| 277 |
function timemap_admin_settings_submit($id, $values) { |
function timemap_admin_settings_submit($form, &$form_state) { |
| 278 |
// enter any new global categories |
// enter any new global categories |
| 279 |
$newgcat = trim($values['newgcat']); |
$newgcat = trim($values['newgcat']); |
| 280 |
if (! empty($newgcat)) { |
if (! empty($newgcat)) { |
| 281 |
db_query("insert into {timemap_categories} (uid, category, active) values (0, '%s', 1)", $newgcat); |
db_query("insert into {timemap_categories} (uid, category, active) values (0, '%s', 1)", $newgcat); |
| 282 |
//this makes is mysql only... |
//this makes is mysql only... |
| 283 |
$cid = mysql_insert_id(); |
$cid = mysql_insert_id(); |
| 284 |
db_query("insert into {timemap_catcolor} (cid, hex) values (%d, '%s')", $cid, $values['color_new_v']); |
db_query("insert into {timemap_catcolor} (cid, hex) values (%d, '%s')", $cid, $values['color_new_v']); |
| 285 |
} |
} |
| 291 |
db_query("update {timemap_categories} set active = %d where cid = %d", $values[$k], $cid); |
db_query("update {timemap_categories} set active = %d where cid = %d", $values[$k], $cid); |
| 292 |
if (db_result(db_query("select cid from {timemap_catcolor} where cid=%d", $cid))) { |
if (db_result(db_query("select cid from {timemap_catcolor} where cid=%d", $cid))) { |
| 293 |
db_query("update {timemap_catcolor} set hex = '%s' where cid = %d", $values['color_'. $cid .'_v'], $cid); |
db_query("update {timemap_catcolor} set hex = '%s' where cid = %d", $values['color_'. $cid .'_v'], $cid); |
| 294 |
} |
} |
| 295 |
else { |
else { |
| 296 |
db_query("insert into {timemap_catcolor} (cid, hex) values (%d, '%s')", $cid, $values['color_'. $cid .'_v']); |
db_query("insert into {timemap_catcolor} (cid, hex) values (%d, '%s')", $cid, $values['color_'. $cid .'_v']); |
| 297 |
} |
} |
| 298 |
} |
} |
| 299 |
} |
} |
| 300 |
|
|
| 301 |
//update the variables |
//update the variables |
| 302 |
if (isset($values['timemap_report_default_days_to_show'])) { |
if (isset($values['timemap_report_default_days_to_show'])) { |
| 303 |
variable_set('timemap_report_default_days_to_show', (int) $values['timemap_report_default_days_to_show']); |
variable_set('timemap_report_default_days_to_show', (int) $values['timemap_report_default_days_to_show']); |
| 316 |
$out .= '</td><td>'; |
$out .= '</td><td>'; |
| 317 |
$out .= drupal_render($form['gcats']['color_new']); |
$out .= drupal_render($form['gcats']['color_new']); |
| 318 |
$out .= '</td></tr>'; |
$out .= '</td></tr>'; |
| 319 |
|
|
| 320 |
foreach ($form['gcats'] as $k => $cat) { |
foreach ($form['gcats'] as $k => $cat) { |
| 321 |
if (strpos($k, 'cid_enable_') !== false) { |
if (strpos($k, 'cid_enable_') !== false) { |
| 322 |
$cid = substr($k, 11); |
$cid = substr($k, 11); |
| 330 |
} |
} |
| 331 |
} |
} |
| 332 |
$out .= '</table>'; |
$out .= '</table>'; |
| 333 |
|
|
| 334 |
$out .= drupal_render($form); |
$out .= drupal_render($form); |
| 335 |
return $out; |
return $out; |
| 336 |
} |
} |
| 337 |
|
|
| 359 |
/** |
/** |
| 360 |
* The core facility! this form is the twitter like interface. |
* The core facility! this form is the twitter like interface. |
| 361 |
*/ |
*/ |
| 362 |
function timemap_enter_task_form($as_block = false) { |
function timemap_enter_task_form(&$form_state, $as_block = false) { |
| 363 |
global $user; |
global $user; |
| 364 |
$result = db_query("select cid, category from {timemap_categories} where uid in (0, %d) and active <> 0", $user->uid); |
$result = db_query("select cid, category from {timemap_categories} where uid in (0, %d) and active <> 0", $user->uid); |
| 365 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 366 |
$categories[$row->cid] = $row->category; |
$categories[$row->cid] = $row->category; |
| 367 |
} |
} |
| 368 |
|
|
| 369 |
$form['newcatfs'] = array( |
$form['newcatfs'] = array( |
| 370 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 371 |
'#access' => user_access('enter tasks'), |
'#access' => user_access('enter tasks'), |
| 392 |
'#default_value' => '#ffffff', |
'#default_value' => '#ffffff', |
| 393 |
'#colorpicker' => 'newcatcolor', |
'#colorpicker' => 'newcatcolor', |
| 394 |
); |
); |
| 395 |
} |
} |
| 396 |
else { |
else { |
| 397 |
$form['newcatfs']['newcatcolor_v'] = array( |
$form['newcatfs']['newcatcolor_v'] = array( |
| 398 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 405 |
'#type' => 'submit', |
'#type' => 'submit', |
| 406 |
'#value' => 'Create Category', |
'#value' => 'Create Category', |
| 407 |
); |
); |
| 408 |
|
|
| 409 |
$c_disp = 'radios'; |
$c_disp = 'radios'; |
| 410 |
if ($as_block) { |
if ($as_block) { |
| 411 |
$c_disp = 'select'; |
$c_disp = 'select'; |
| 412 |
} |
} |
| 413 |
|
|
| 414 |
if (! empty($categories)) { |
if (! empty($categories)) { |
| 415 |
$form['category'] = array( |
$form['category'] = array( |
| 416 |
'#type' => $c_disp, |
'#type' => $c_disp, |
| 431 |
'#type' => 'submit', |
'#type' => 'submit', |
| 432 |
'#value' => 'Update', |
'#value' => 'Update', |
| 433 |
); |
); |
| 434 |
|
|
| 435 |
// is being "done" the last thing we did? if so, don't show the button again. |
// is being "done" the last thing we did? if so, don't show the button again. |
| 436 |
$lastcat = db_result(db_query_range("select cid from {timemap_doings} WHERE uid = %d order by time desc", $user->uid, 0, 1)); |
$lastcat = db_result(db_query_range("select cid from {timemap_doings} WHERE uid = %d order by time desc", $user->uid, 0, 1)); |
| 437 |
if ($lastcat >= 0) { |
if ($lastcat >= 0) { |
| 440 |
'#value' => 'Quitin\' Time!', |
'#value' => 'Quitin\' Time!', |
| 441 |
); |
); |
| 442 |
} |
} |
| 443 |
|
|
| 444 |
return $form; |
return $form; |
| 445 |
} |
} |
| 446 |
function timemap_enter_task_form_validate($form_id, $form_values) { |
function timemap_enter_task_form_validate($form, &$form_state) { |
| 447 |
if ( (trim($form_values['entry']) == '') && ($form_values['op'] == $form_values['submit']) ) { |
/* TODO The 'op' element in the form values is deprecated. |
| 448 |
|
Each button can have #validate and #submit functions associated with it. |
| 449 |
|
Thus, there should be one button that submits the form and which invokes |
| 450 |
|
the normal form_id_validate and form_id_submit handlers. Any additional |
| 451 |
|
buttons which need to invoke different validate or submit functionality |
| 452 |
|
should have button-specific functions. */ |
| 453 |
|
if ( (trim($form_state['values']['entry']) == '') && ($form_state['values']['op'] == $form_state['values']['submit']) ) { |
| 454 |
form_set_error('entry'); |
form_set_error('entry'); |
| 455 |
} |
} |
| 456 |
if ( (trim($form_values['newcat']) == '') && ($form_values['op'] == $form_values['newcatsubmit']) ) { |
/* TODO The 'op' element in the form values is deprecated. |
| 457 |
|
Each button can have #validate and #submit functions associated with it. |
| 458 |
|
Thus, there should be one button that submits the form and which invokes |
| 459 |
|
the normal form_id_validate and form_id_submit handlers. Any additional |
| 460 |
|
buttons which need to invoke different validate or submit functionality |
| 461 |
|
should have button-specific functions. */ |
| 462 |
|
if ( (trim($form_state['values']['newcat']) == '') && ($form_state['values']['op'] == $form_state['values']['newcatsubmit']) ) { |
| 463 |
form_set_error('newcat'); |
form_set_error('newcat'); |
| 464 |
} |
} |
| 465 |
} |
} |
| 466 |
function timemap_enter_task_form_submit($form_id, $form_values) { |
function timemap_enter_task_form_submit($form, &$form_state) { |
| 467 |
global $user; |
global $user; |
| 468 |
|
|
| 469 |
// have we entered a new category? |
// have we entered a new category? |
| 470 |
if ($form_values['op'] == $form_values['newcatsubmit']) { |
/* TODO The 'op' element in the form values is deprecated. |
| 471 |
|
Each button can have #validate and #submit functions associated with it. |
| 472 |
|
Thus, there should be one button that submits the form and which invokes |
| 473 |
|
the normal form_id_validate and form_id_submit handlers. Any additional |
| 474 |
|
buttons which need to invoke different validate or submit functionality |
| 475 |
|
should have button-specific functions. */ |
| 476 |
|
if ($form_state['values']['op'] == $form_state['values']['newcatsubmit']) { |
| 477 |
db_query("insert into {timemap_categories} (uid, category, active) values (%d, '%s', %d)", |
db_query("insert into {timemap_categories} (uid, category, active) values (%d, '%s', %d)", |
| 478 |
$user->uid, $form_values['newcat'], 1); |
$user->uid, $form_state['values']['newcat'], 1); |
| 479 |
//this makes it mysql only... |
//this makes it mysql only... |
| 480 |
$cid = mysql_insert_id(); |
$cid = mysql_insert_id(); |
| 481 |
db_query("insert into {timemap_catcolor} (cid, hex) values (%d, '%s')", $cid, $form_values['newcatcolor_v']); |
db_query("insert into {timemap_catcolor} (cid, hex) values (%d, '%s')", $cid, $form_state['values']['newcatcolor_v']); |
| 482 |
} |
} |
| 483 |
|
|
| 484 |
// have we "clocked out"? |
// have we "clocked out"? |
| 485 |
// if so, enter a negative value for the category. the text is informational only. |
// if so, enter a negative value for the category. the text is informational only. |
| 486 |
if ($form_values['op'] == $form_values['done']) { |
/* TODO The 'op' element in the form values is deprecated. |
| 487 |
|
Each button can have #validate and #submit functions associated with it. |
| 488 |
|
Thus, there should be one button that submits the form and which invokes |
| 489 |
|
the normal form_id_validate and form_id_submit handlers. Any additional |
| 490 |
|
buttons which need to invoke different validate or submit functionality |
| 491 |
|
should have button-specific functions. */ |
| 492 |
|
if ($form_state['values']['op'] == $form_state['values']['done']) { |
| 493 |
// end the last 'task' entered |
// end the last 'task' entered |
| 494 |
db_query("update {timemap_doings} set stop=%d where uid=%d order by time desc limit 1", time(), $user->uid); |
db_query("update {timemap_doings} set stop=%d where uid=%d order by time desc limit 1", time(), $user->uid); |
| 495 |
|
|
| 496 |
// record the 'punch clock' stamp |
// record the 'punch clock' stamp |
| 497 |
db_query("insert into {timemap_doings} (uid, cid, task, time) values (%d, %d, '%s', %d)", |
db_query("insert into {timemap_doings} (uid, cid, task, time) values (%d, %d, '%s', %d)", |
| 498 |
$user->uid, -1, '***PUNCH CLOCK: OUT***', time()); |
$user->uid, -1, '***PUNCH CLOCK: OUT***', time()); |
| 499 |
drupal_set_message('Until next time... Thanks champ, you\'re a star!'); |
drupal_set_message('Until next time... Thanks champ, you\'re a star!'); |
| 500 |
} |
} |
| 501 |
|
|
| 502 |
// have we entered a task? |
// have we entered a task? |
| 503 |
if ($form_values['op'] == $form_values['submit']) { |
/* TODO The 'op' element in the form values is deprecated. |
| 504 |
|
Each button can have #validate and #submit functions associated with it. |
| 505 |
|
Thus, there should be one button that submits the form and which invokes |
| 506 |
|
the normal form_id_validate and form_id_submit handlers. Any additional |
| 507 |
|
buttons which need to invoke different validate or submit functionality |
| 508 |
|
should have button-specific functions. */ |
| 509 |
|
if ($form_state['values']['op'] == $form_state['values']['submit']) { |
| 510 |
// end the last 'task' entered |
// end the last 'task' entered |
| 511 |
db_query("update {timemap_doings} set stop=%d where uid=%d order by time desc limit 1", time(), $user->uid); |
db_query("update {timemap_doings} set stop=%d where uid=%d order by time desc limit 1", time(), $user->uid); |
| 512 |
|
|
| 513 |
// add the new one |
// add the new one |
| 514 |
db_query("insert into {timemap_doings} (uid, cid, task, time) values (%d, %d, '%s', %d)", |
db_query("insert into {timemap_doings} (uid, cid, task, time) values (%d, %d, '%s', %d)", |
| 515 |
$user->uid, $form_values['category'], $form_values['entry'], time()); |
$user->uid, $form_state['values']['category'], $form_state['values']['entry'], time()); |
| 516 |
drupal_set_message("roger, Roger: " . $form_values['entry']); |
drupal_set_message("roger, Roger: " . $form_state['values']['entry']); |
| 517 |
} |
} |
| 518 |
} |
} |
| 519 |
|
|
| 520 |
function timemap_doing_autoc($string) { |
function timemap_doing_autoc($string) { |
| 521 |
global $user; |
global $user; |
| 522 |
$result = db_query("select distinct task |
$result = db_query("select distinct task |
| 523 |
from {timemap_doings} |
from {timemap_doings} |
| 524 |
where uid = %d and task like '%s%%' |
where uid = %d and task like '%s%%' |
| 525 |
order by time desc", $user->uid, $string); |
order by time desc", $user->uid, $string); |
| 526 |
$return = array(); |
$return = array(); |
| 527 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 528 |
$return[$row->task] = $row->task; |
$return[$row->task] = $row->task; |
| 529 |
} |
} |
| 530 |
|
|
| 531 |
print drupal_to_js($return); |
print drupal_to_js($return); |
| 532 |
exit(); |
exit(); |
| 533 |
} |
} |
| 536 |
global $user; |
global $user; |
| 537 |
if (! $uid) { |
if (! $uid) { |
| 538 |
$uid = $user->uid; |
$uid = $user->uid; |
| 539 |
} |
} |
| 540 |
else { |
else { |
| 541 |
$user = user_load($uid); |
$user = user_load($uid); |
| 542 |
} |
} |
| 547 |
} |
} |
| 548 |
|
|
| 549 |
$people_chooser = theme('timemap_viewable_reports_list_people', $allowed); |
$people_chooser = theme('timemap_viewable_reports_list_people', $allowed); |
| 550 |
|
|
| 551 |
/* |
/* |
| 552 |
* The Simile Timeline lib from MIT can, per MIT's request, be loaded from the Internet. If, for some |
* The Simile Timeline lib from MIT can, per MIT's request, be loaded from the Internet. If, for some |
| 553 |
* reason, this is not an option, then the library code distro can be placed in the module dir in a dir |
* reason, this is not an option, then the library code distro can be placed in the module dir in a dir |
| 554 |
* called 'timeline'. In this case, it will be autodetected and loaded from the local copy. |
* called 'timeline'. In this case, it will be autodetected and loaded from the local copy. |
| 555 |
* |
* |
| 556 |
* To Download: http://simile.mit.edu/wiki/Timeline/Download_The_Source |
* To Download: http://simile.mit.edu/wiki/Timeline/Download_The_Source |
| 557 |
*/ |
*/ |
| 558 |
if (file_exists($_SERVER['DOCUMENT_ROOT'] . base_path() . drupal_get_path('module', 'timemap') ."/timeline/timeline-api.js")) { |
if (file_exists($_SERVER['DOCUMENT_ROOT'] . base_path() . drupal_get_path('module', 'timemap') ."/timeline/timeline-api.js")) { |
| 559 |
drupal_add_js(drupal_get_path('module', 'timemap') ."/timeline/timeline-api.js"); |
drupal_add_js(drupal_get_path('module', 'timemap') ."/timeline/timeline-api.js"); |
| 560 |
} |
} |
| 561 |
else { |
else { |
| 562 |
drupal_add_js(drupal_get_path('module', 'timemap') ."/load_timeline.js"); |
drupal_add_js(drupal_get_path('module', 'timemap') ."/load_timeline.js"); |
| 563 |
} |
} |
| 564 |
|
|
| 565 |
drupal_add_js(drupal_get_path('module', 'timemap') ."/timemap_simile-timeline.js"); |
drupal_add_js(drupal_get_path('module', 'timemap') ."/timemap_simile-timeline.js"); |
| 566 |
drupal_add_css(drupal_get_path('module', 'timemap') ."/timemap.css"); |
drupal_add_css(drupal_get_path('module', 'timemap') ."/timemap.css"); |
| 567 |
|
|
| 568 |
return $people_chooser .'<div id="timemap" basepath="'. base_path() .'" uid="'. $uid .'" offset="'. $user->timezone .'"></div><div class="timemap_controls" id="timemap_controls"></div>'; |
return $people_chooser .'<div id="timemap" basepath="'. base_path() .'" uid="'. $uid .'" offset="'. $user->timezone .'"></div><div class="timemap_controls" id="timemap_controls"></div>'; |
| 569 |
|
|
| 570 |
} |
} |
| 571 |
|
|
| 572 |
function theme_timemap_viewable_reports_list_people($list = array()) { |
function theme_timemap_viewable_reports_list_people($list = array()) { |
| 589 |
drupal_access_denied(); |
drupal_access_denied(); |
| 590 |
exit(); |
exit(); |
| 591 |
} |
} |
| 592 |
|
|
| 593 |
$result = db_query("select d.cid as cid, d.task as task, d.time as time, d.stop as stop, c.category as category, cc.hex as color |
$result = db_query("select d.cid as cid, d.task as task, d.time as time, d.stop as stop, c.category as category, cc.hex as color |
| 594 |
from {timemap_doings} d |
from {timemap_doings} d |
| 595 |
left join {timemap_categories} c on c.cid=d.cid |
left join {timemap_categories} c on c.cid=d.cid |
| 596 |
left join {timemap_catcolor} cc on c.cid=cc.cid |
left join {timemap_catcolor} cc on c.cid=cc.cid |
| 597 |
where d.uid = %d and d.cid >= 0 |
where d.uid = %d and d.cid >= 0 |
| 598 |
order by d.time", $uid); |
order by d.time", $uid); |
| 599 |
|
|
| 600 |
$return = array( |
$return = array( |
| 601 |
'dateTimeFormat' => 'iso8601', |
'dateTimeFormat' => 'iso8601', |
| 602 |
'events' => array(), |
'events' => array(), |
| 603 |
); |
); |
| 604 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 605 |
$end_k = $row->stop != '0' ? 'end' : 'earliestEnd'; |
$end_k = $row->stop != '0' ? 'end' : 'earliestEnd'; |
| 606 |
$end_v = $row->stop != '0' ? timemap_datify($row->stop) : timemap_datify(time()); |
$end_v = $row->stop != '0' ? timemap_datify($row->stop) : timemap_datify(time()); |
| 607 |
$return['events'][] = array( |
$return['events'][] = array( |
| 608 |
'start' => timemap_datify($row->time), |
'start' => timemap_datify($row->time), |
| 609 |
$end_k => $end_v, |
$end_k => $end_v, |
| 610 |
'title' => $row->task, |
'title' => $row->task, |
| 611 |
'color' => $row->color, |
'color' => $row->color, |
| 612 |
'description' => 'Category: <i>'. $row->category .'</i>', |
'description' => 'Category: <i>'. $row->category .'</i>', |
| 613 |
); |
); |
| 614 |
} |
} |
| 615 |
|
|
| 616 |
print drupal_to_js($return); |
print drupal_to_js($return); |
| 617 |
exit(); |
exit(); |
| 618 |
} |
} |
| 619 |
|
|
| 620 |
function timemap_datify($secs) { |
function timemap_datify($secs) { |
| 621 |
global $user; |
global $user; |
| 622 |
//$secs += $user->timezone; |
//$secs += $user->timezone; |
| 623 |
//return date(DATE_RFC3339, $secs); |
//return date(DATE_RFC3339, $secs); |
| 624 |
return gmdate('c', $secs); |
return gmdate('c', $secs); |
| 625 |
} |
} |
| 626 |
|
|
| 631 |
} |
} |
| 632 |
|
|
| 633 |
$allowed = timemap_viewable_reports_list(); |
$allowed = timemap_viewable_reports_list(); |
| 634 |
|
|
| 635 |
if ( ! in_array($uid, array_keys($allowed)) ) { |
if ( ! in_array($uid, array_keys($allowed)) ) { |
| 636 |
drupal_access_denied(); |
drupal_access_denied(); |
| 637 |
exit(); |
exit(); |
| 638 |
} |
} |
| 639 |
|
|
| 640 |
$return = ''; |
$return = ''; |
| 641 |
|
|
| 642 |
//are we the only only person who has reports we can view, or are there more to choose from? |
//are we the only only person who has reports we can view, or are there more to choose from? |
| 643 |
if ( ! ((count($allowed) == 1) && isset($allowed[$user->uid])) ) { |
if ( ! ((count($allowed) == 1) && isset($allowed[$user->uid])) ) { |
| 644 |
$return .= drupal_get_form('timemap_report_choose_person'); |
$return .= drupal_get_form('timemap_report_choose_person'); |
| 645 |
} |
} |
| 646 |
|
|
| 647 |
$return .= timemap_draw_report(timemap_get_report_stats($uid, $from, $numDays), $report); |
$return .= timemap_draw_report(timemap_get_report_stats($uid, $from, $numDays), $report); |
| 648 |
return $return; |
return $return; |
| 649 |
} |
} |
| 650 |
|
|
| 651 |
function timemap_report_choose_person() { |
function timemap_report_choose_person(&$form_state) { |
| 652 |
global $user; |
global $user; |
| 653 |
|
|
| 654 |
$form['uid'] = array( |
$form['uid'] = array( |
| 655 |
'#type' => 'select', |
'#type' => 'select', |
| 656 |
'#options' => timemap_viewable_reports_list(), |
'#options' => timemap_viewable_reports_list(), |
| 661 |
'#type' => 'submit', |
'#type' => 'submit', |
| 662 |
'#value' => t('Go'), |
'#value' => t('Go'), |
| 663 |
); |
); |
| 664 |
|
|
| 665 |
return $form; |
return $form; |
| 666 |
} |
} |
| 667 |
function timemap_report_choose_person_validate($id, $values) { |
function timemap_report_choose_person_validate($form, &$form_state) { |
| 668 |
return true; |
return true; |
| 669 |
} |
} |
| 670 |
function timemap_report_choose_person_submit($id, $values) { |
function timemap_report_choose_person_submit($form, &$form_state) { |
| 671 |
return 'timemap/report/'. $values['uid']; |
return 'timemap/report/'. $values['uid']; |
| 672 |
} |
} |
| 673 |
|
|
| 674 |
function timemap_viewable_reports_list() { |
function timemap_viewable_reports_list() { |
| 675 |
global $user; |
global $user; |
| 676 |
|
|
| 677 |
if ($user->uid == 1) { |
if ($user->uid == 1) { |
| 678 |
$names = array(1, $user->name); |
$names = array(1, $user->name); |
| 679 |
} |
} |
| 680 |
// view all? |
// view all? |
| 681 |
if ( user_access('view all reports') || ($user->uid == 1) ) { |
if ( user_access('view all reports') || ($user->uid == 1) ) { |
| 682 |
$result = db_query("select distinct uid from {timemap_doings}"); |
$result = db_query("select distinct uid from {timemap_doings}"); |
| 689 |
} |
} |
| 690 |
|
|
| 691 |
$return = array(); |
$return = array(); |
| 692 |
|
|
| 693 |
// view reports defined by CiviCRM groups? |
// view reports defined by CiviCRM groups? |
| 694 |
if (user_access('view subordinate reports')) { |
if (user_access('view subordinate reports')) { |
| 695 |
$rel = variable_get('timemap_civicrm_subord_rel'); |
$rel = variable_get('timemap_civicrm_subord_rel'); |
| 697 |
|
|
| 698 |
$return = array_merge($return, $names); |
$return = array_merge($return, $names); |
| 699 |
} |
} |
| 700 |
|
|
| 701 |
// view your own? |
// view your own? |
| 702 |
if (user_access('view own report')) { |
if (user_access('view own report')) { |
| 703 |
$names = array($user->uid => $user->name); |
$names = array($user->uid => $user->name); |
| 704 |
$return = array_merge($return, $names); |
$return = array_merge($return, $names); |
| 705 |
} |
} |
| 706 |
|
|
| 707 |
return $return; |
return $return; |
| 708 |
} |
} |
| 709 |
///////////////////////////////////////// |
///////////////////////////////////////// |
| 710 |
/** |
/** |
| 711 |
* Implementation of hook_timemap_report |
* Implementation of hook_timemap_report |
| 712 |
*/ |
*/ |
| 713 |
function timemap_timemap_report($op = 'list', $delta = 0, $stats = null) { |
function timemap_timemap_report($op = 'list', $delta = 0, $stats = null) { |
| 714 |
switch ($op) { |
switch ($op) { |
| 715 |
case 'list': |
case 'list': |
| 719 |
'delta' => 0, |
'delta' => 0, |
| 720 |
); |
); |
| 721 |
return $return; |
return $return; |
| 722 |
|
|
| 723 |
case 'view': |
case 'view': |
| 724 |
switch($delta) { |
switch($delta) { |
| 725 |
case 0: |
case 0: |
| 727 |
} |
} |
| 728 |
break; |
break; |
| 729 |
} |
} |
| 730 |
|
|
| 731 |
return array(); |
return array(); |
| 732 |
} |
} |
| 733 |
|
|
| 742 |
$report_detail = module_invoke($rpt['module'], 'timemap_report', 'view', $rpt['delta'], $stats); |
$report_detail = module_invoke($rpt['module'], 'timemap_report', 'view', $rpt['delta'], $stats); |
| 743 |
} |
} |
| 744 |
} |
} |
| 745 |
|
|
| 746 |
// if for some reason we've requested a report that isn't available, kick in our 'default' and notify |
// if for some reason we've requested a report that isn't available, kick in our 'default' and notify |
| 747 |
if (! isset($report_detail)) { |
if (! isset($report_detail)) { |
| 748 |
drupal_set_message("We cannot find a report called <i>$report</i>. Hopefully the following information will be helpful.", 'error'); |
drupal_set_message("We cannot find a report called <i>$report</i>. Hopefully the following information will be helpful.", 'error'); |
| 749 |
$report_detail = module_invoke('timemap', 'timemap_report', 'view', 0, $stats); |
$report_detail = module_invoke('timemap', 'timemap_report', 'view', 0, $stats); |
| 750 |
} |
} |
| 751 |
|
|
| 752 |
return $report_detail; |
return $report_detail; |
| 753 |
} |
} |
| 754 |
|
|
| 755 |
/** |
/** |
| 756 |
* Called from timemap_report(). Collect the stats for a given uid and date and return them. |
* Called from timemap_report(). Collect the stats for a given uid and date and return them. |
| 757 |
* These stats are then passed to whatever report is being used to draw some pretty pictures. |
* These stats are then passed to whatever report is being used to draw some pretty pictures. |
| 758 |
*/ |
*/ |
| 759 |
function timemap_get_report_stats($uid = null, $from = null, $days_to_show = null) { |
function timemap_get_report_stats($uid = null, $from = null, $days_to_show = null) { |
| 760 |
global $user; |
global $user; |
| 761 |
if (! $uid) { |
if (! $uid) { |
| 762 |
$uid = $user->uid; |
$uid = $user->uid; |
| 763 |
} |
} |
| 764 |
|
|
| 765 |
// expect and set variables as days |
// expect and set variables as days |
| 766 |
// we'll default to showing the "default" num of days starting from that many days ago... ie, up to today. |
// we'll default to showing the "default" num of days starting from that many days ago... ie, up to today. |
| 767 |
if (! isset($from)) { |
if (! isset($from)) { |
| 774 |
// turn days into unix times relative to now. |
// turn days into unix times relative to now. |
| 775 |
// 86400 = 24 * 60 * 60 --> no. secs to "see" |
// 86400 = 24 * 60 * 60 --> no. secs to "see" |
| 776 |
// days-1 because partial today will count as a whole 1 for our purposes |
// days-1 because partial today will count as a whole 1 for our purposes |
| 777 |
$secs = ($from - 1) * 86400; |
$secs = ($from - 1) * 86400; |
| 778 |
|
|
| 779 |
$lastmidnight = strtotime("12 am UTC"); |
$lastmidnight = strtotime("12 am UTC"); |
| 780 |
$from = $lastmidnight - $secs; |
$from = $lastmidnight - $secs; |
| 781 |
$secs_to_show = $from + ($days_to_show * 86400); |
$secs_to_show = $from + ($days_to_show * 86400); |
| 782 |
|
|
| 783 |
$result = db_query("select d.cid as cid, d.task as task, d.time as time, d.stop as stop, c.category as category |
$result = db_query("select d.cid as cid, d.task as task, d.time as time, d.stop as stop, c.category as category |
| 784 |
from {timemap_doings} d left join {timemap_categories} c on c.cid=d.cid |
from {timemap_doings} d left join {timemap_categories} c on c.cid=d.cid |
| 785 |
where d.uid = %d and d.time between %d and %d |
where d.uid = %d and d.time between %d and %d |
| 786 |
order by d.time", |
order by d.time", |
| 787 |
$uid, $from, $secs_to_show); |
$uid, $from, $secs_to_show); |
| 788 |
$stats_obj['info'] = array( |
$stats_obj['info'] = array( |
| 789 |
'days' => $days_to_show, |
'days' => $days_to_show, |
| 790 |
); |
); |
| 791 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 792 |
$stats_obj['items'][] = array( |
$stats_obj['items'][] = array( |
| 793 |
'cid' => $row->cid, |
'cid' => $row->cid, |
| 797 |
'stop' => $row->stop, |
'stop' => $row->stop, |
| 798 |
); |
); |
| 799 |
} |
} |
| 800 |
|
|
| 801 |
return $stats_obj; |
return $stats_obj; |
| 802 |
} |
} |