diff --git a/timesheet/inc/class.timesheet_bo.inc.php b/timesheet/inc/class.timesheet_bo.inc.php index 28b6398755..f3b3583f9e 100644 --- a/timesheet/inc/class.timesheet_bo.inc.php +++ b/timesheet/inc/class.timesheet_bo.inc.php @@ -804,4 +804,47 @@ class timesheet_bo extends so_sql_cf } return array(); } + + /** + * receives notifications from the link-class: new, deleted links to timesheets, or updated content of linked entries + * + * Function makes sure timesheets linked or unlinked to projects via projectmanager behave like ones + * linked via timesheets project-selector, thought timesheet only stores project-title, not the id! + * + * @param array $data array with keys type, id, target_app, target_id, link_id, data + */ + function notify($data) + { + //error_log(__METHOD__.'('.array2string($data).')'); + $backup =& $this->data; // backup internal data in case class got re-used by ExecMethod + unset($this->data); + + if ($data['target_app'] == 'projectmanager' && $this->read($data['id'])) + { + switch($data['type']) + { + case 'link': + case 'update': + if (empty($this->data['ts_project'])) // timesheet has not yet project set --> set just linked one + { + $pm_id = $data['target_id']; + } + break; + + case 'unlink': // if current project got unlinked --> unset it + if ($this->data['ts_project'] == projectmanager_bo::link_title($data['target_id'])) + { + $pm_id = 0; + } + break; + } + if (isset($pm_id)) + { + $ts_project = $pm_id ? egw_link::title('projectmanager', $pm_id) : null; + $this->update(array('ts_project' => $ts_project)); + //error_log(__METHOD__."() setting pm_id=$pm_id --> ts_project=".array2string($ts_project)); + } + } + if ($backup) $this->data = $backup; + } } diff --git a/timesheet/inc/class.timesheet_hooks.inc.php b/timesheet/inc/class.timesheet_hooks.inc.php index 2db8a1298d..9c57013a99 100644 --- a/timesheet/inc/class.timesheet_hooks.inc.php +++ b/timesheet/inc/class.timesheet_hooks.inc.php @@ -57,6 +57,7 @@ class timesheet_hooks 'add_popup' => '600x425', 'file_access'=> TIMESHEET_APP.'.timesheet_bo.file_access', 'file_access_user' => true, // file_access supports 4th parameter $user + 'notify' => TIMESHEET_APP.'.timesheet_bo.notify', ); } diff --git a/timesheet/inc/class.timesheet_ui.inc.php b/timesheet/inc/class.timesheet_ui.inc.php index c7e4bdd622..536fe91027 100644 --- a/timesheet/inc/class.timesheet_ui.inc.php +++ b/timesheet/inc/class.timesheet_ui.inc.php @@ -63,9 +63,9 @@ class timesheet_ui extends timesheet_bo { if (!$this->read((int)$_GET['ts_id'])) { - $GLOBALS['egw']->common->egw_header(); + common::egw_header(); echo "\n"; - $GLOBALS['egw']->common->egw_exit(); + common::egw_exit(); } if (!$view && !$this->check_acl(EGW_ACL_EDIT)) { @@ -143,6 +143,14 @@ class timesheet_ui extends timesheet_bo { unset($this->data[$key]); } + // user switched project to none --> remove project and blur + if ($this->data['ts_project_blur'] && !$this->data['pm_id'] && $this->data['old_pm_id']) + { + unset($this->data['ts_project_blur']); + unset($content['ts_project_blur']); + unset($this->data['ts_project']); + unset($content['ts_project']); + } switch($button) { case 'edit': @@ -164,8 +172,8 @@ class timesheet_ui extends timesheet_bo { $etpl->set_validation_error('ts_quantity',lang('Starttime has to be before endtime !!!')); } - //echo "
ts_start=$content[ts_start], start_time=$content[start_time], end_time=$content[end_time], ts_duration=$content[ts_duration], ts_quantity=$content[ts_quantity]
\n"; - if (!$this->data['ts_project']) $this->data['ts_project'] = $this->data['ts_project_blur']; + // only store project-blur, if a project is selected + if (!$this->data['ts_project'] && $this->data['pm_id']) $this->data['ts_project'] = $this->data['ts_project_blur']; // set ts_title to ts_project if short viewtype (title is not editable) if($this->ts_viewtype == 'short') { @@ -191,6 +199,19 @@ class timesheet_ui extends timesheet_bo } if ($etpl->validation_errors()) break; // the user need to fix the error, before we can save the entry + // check if we are linked to a project, but that is NOT set as project + if (!$this->data['pm_id'] && is_array($content['link_to']['to_id'])) + { + foreach($content['link_to']['to_id'] as $data) + { + if ($data['app'] == 'projectmanager') + { + $this->data['pm_id'] = $data['id']; + break; + } + } + } + if ($this->save() != 0) { $msg = lang('Error saving the entry!!!'); @@ -263,7 +284,7 @@ class timesheet_ui extends timesheet_bo case 'cancel': $js .= 'window.close();'; echo "\n\n\n\n\n"; - $GLOBALS['egw']->common->egw_exit(); + common::egw_exit(); break; } } @@ -572,7 +593,7 @@ class timesheet_ui extends timesheet_bo $GLOBALS['egw_info']['flags']['app_header'] = lang('timesheet'); if ($query['col_filter']['ts_owner']) { - $GLOBALS['egw_info']['flags']['app_header'] .= ': '.$GLOBALS['egw']->common->grab_owner_name($query['col_filter']['ts_owner']); + $GLOBALS['egw_info']['flags']['app_header'] .= ': '.common::grab_owner_name($query['col_filter']['ts_owner']); #if ($GLOBALS['egw']->accounts->get_type($query['col_filter']['ts_owner']) == 'g') $GLOBALS['egw_info']['flags']['app_header'] .= ' '. lang("and its members"); #_debug_array($GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true)); if ($query['col_filter']['ts_owner']<0) $query['col_filter']['ts_owner'] = array_merge(array($query['col_filter']['ts_owner']),$GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true)); @@ -612,10 +633,10 @@ class timesheet_ui extends timesheet_bo else { $df = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; - $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . $GLOBALS['egw']->common->show_date($query['startdate']+12*60*60,$df,false); + $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . common::show_date($query['startdate']+12*60*60,$df,false); if ($start != $end) { - $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.$GLOBALS['egw']->common->show_date($query['enddate']+12*60*60,$df,false); + $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.common::show_date($query['enddate']+12*60*60,$df,false); } } if ($query['filter'] == 'custom') // show the custom dates @@ -677,7 +698,7 @@ class timesheet_ui extends timesheet_bo switch($row['ts_id']) { case 0: // day-sum - $row['ts_title'] = lang('Sum %1:',lang(date('l',$row['ts_start'])).' '.$GLOBALS['egw']->common->show_date($row['ts_start'], + $row['ts_title'] = lang('Sum %1:',lang(date('l',$row['ts_start'])).' '.common::show_date($row['ts_start'], $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],false)); // For some reason day sum checkbox on the etemplate is checked[1] instead of checked[0]