* @author Joerg Lehrke "; print_r($this->enums['type']); echo "
\n";
//echo "config-types:"; print_r($config_data['types']); echo "
\n";
$this->enums['type'] += $config_data['types'];
//echo "types:"; print_r($this->enums['type']); echo "
\n";
}
if ($config_data['group_owners']) $this->group_owners = $config_data['group_owners'];
$this->customfields = Api\Storage\Customfields::get('infolog');
if ($this->customfields)
{
foreach($this->customfields as $name => $field)
{
// old infolog customefield record
if(empty($field['type']))
{
if (count($field['values'])) $field['type'] = 'select'; // selectbox
elseif ($field['rows'] > 1) $field['type'] = 'textarea'; // textarea
elseif (intval($field['len']) > 0) $field['type'] = 'text'; // regular input field
else $field['type'] = 'label'; // header-row
$field['type2'] = $field['typ'];
unset($field['typ']);
$this->customfields[$name] = $field;
$save_config = true;
}
}
if (!empty($save_config)) Api\Config::save_value('customfields',$this->customfields,'infolog');
}
if (isset($config_data['responsible_edit']) && is_array($config_data['responsible_edit']))
{
$this->responsible_edit = array_merge($this->responsible_edit,$config_data['responsible_edit']);
}
if (isset($config_data['copy_excludefields']) && is_array($config_data['copy_excludefields']))
{
$this->copy_excludefields = array_merge($this->copy_excludefields,$config_data['copy_excludefields']);
}
if (!empty($config_data['sub_excludefields']) && is_array($config_data['sub_excludefields']))
{
$this->sub_excludefields = array_merge($this->sub_excludefields,$config_data['sub_excludefields']);
}
else
{
$this->sub_excludefields = array_merge($this->sub_excludefields,$this->default_sub_excludefields);
}
if ($config_data['implicit_rights'] == 'edit')
{
$this->implicit_rights = 'edit';
}
$this->history = $config_data['history'];
$this->limit_modified_n_month = $config_data['limit_modified_n_month'] ?? null;
}
// sort types by there translation
foreach($this->enums['type'] as $key => $val)
{
if (($val = lang($key)) != $key.'*') $this->enums['type'][$key] = lang($key);
}
natcasesort($this->enums['type']);
$this->user = $GLOBALS['egw_info']['user']['account_id'];
$this->now = time();
$this->user_time_now = Api\DateTime::server2user($this->now,'ts');
$this->grants = $GLOBALS['egw']->acl->get_grants('infolog',$this->group_owners ? $this->group_owners : true);
$this->so = new infolog_so($this->grants);
if ($info_id)
{
$this->read( $info_id );
}
else
{
$this->init();
}
}
/**
* checks if there are customfields for typ $typ
*
* @param string $type
* @return boolean True if there are customfields for $typ, else False
*/
function has_customfields($type)
{
foreach($this->customfields as $field)
{
if ((!$type || empty($field['type2']) || in_array($type,is_array($field['type2']) ? $field['type2'] : explode(',',$field['type2']))))
{
return True;
}
}
return False;
}
/**
* check's if user has the requiered rights on entry $info_id
*
* @param int|array $info data or info_id of infolog entry to check
* @param int $required_rights ACL::{READ|EDIT|ADD|DELETE}|infolog_bo::ACL_UNDELETE
* @param int $other uid to check (if info==0) or 0 to check against $this->user
* @param int $user = null user whos rights to check, default current user
* @return boolean
*/
function check_access($info,$required_rights,$other=0,$user=null)
{
$info_id = is_array($info) ? $info['info_id'] : $info;
if (!$user) $user = $this->user;
if ($user == $this->user)
{
$grants = $this->grants;
if ($info_id) $access =& static::$access_cache[$info_id][$required_rights]; // we only cache the current user!
}
else
{
$grants = $GLOBALS['egw']->acl->get_grants('infolog',$this->group_owners ? $this->group_owners : true,$user);
}
if (!$info)
{
$owner = $other ? $other : $user;
$grant = $grants[$owner];
return $grant & $required_rights;
}
if (!isset($access))
{
// handle delete for the various history modes
if (!is_array($info) && !($info = $this->so->read(array('info_id' => $info_id)))) return false;
if ($info['info_status'] == 'deleted' &&
($required_rights == Acl::EDIT || // no edit rights for deleted entries
$required_rights == Acl::ADD || // no add rights for deleted entries
$required_rights == Acl::DELETE && ($this->history == 'history_no_delete' || // no delete at all!
$this->history == 'history_admin_delete' && (!isset($GLOBALS['egw_info']['user']['apps']['admin']) || $user!=$this->user)))) // delete only for admins
{
$access = false;
}
elseif ($required_rights == self::ACL_UNDELETE)
{
if ($info['info_status'] != 'deleted')
{
$access = false; // can only undelete deleted items
}
else
{
// undelete requires edit rights
$access = $this->so->check_access( $info,Acl::EDIT,$this->implicit_rights == 'edit',$grants,$user );
}
}
if (!isset($access))
{
$access = $this->so->check_access( $info,$required_rights,$this->implicit_rights == 'edit',$grants,$user );
}
}
// else $cached = ' (from cache)';
// error_log(__METHOD__."($info_id,$required_rights,$other,$user) returning$cached ".array2string($access));
return $access;
}
/**
* Check if user is responsible for an entry: he or one of his memberships is in responsible
*
* @param array $info infolog entry as array
* @return boolean
*/
function is_responsible($info)
{
return $this->so->is_responsible($info);
}
/**
* init internal data to be empty
*/
function init()
{
static::$access_cache = array();
$this->so->init();
}
/**
* convert a link_id value into an info_from text
*
* @param array &$info infolog entry, key info_from gets set by this function
* @param string $not_app = '' app to exclude
* @param string $not_id = '' id to exclude
* @return boolean True if we have a linked item, False otherwise
*/
function link_id2from(&$info,$not_app='',$not_id='')
{
//error_log(__METHOD__ . "(subject='{$info['info_subject']}', link_id='{$info['info_link_id']}', from='{$info['info_from']}', not_app='$not_app', not_id='$not_id')");
if ($info['info_link_id'] > 0 &&
(isset($info['links']) && ($link = $info['links'][$info['info_link_id']]) || // use supplied links info
($link = Link::get_link($info['info_link_id'])) !== False)) // if link not found in supplied links, we always search!
{
if (isset($info['links']) && isset($link['app']))
{
$app = $link['app'];
$id = $link['id'];
}
else
{
$nr = $link['link_app1'] == 'infolog' && $link['link_id1'] == $info['info_id'] ? '2' : '1';
$app = $link['link_app'.$nr];
$id = $link['link_id'.$nr];
}
$title = Link::title($app,$id);
if ((string)$info['info_custom_from'] === '') // old entry
{
$info['info_custom_from'] = (int) ($title != $info['info_from'] && @htmlentities($title) != $info['info_from']);
}
if (!$info['info_custom_from'])
{
$info['info_from'] = '';
$info['info_custom_from'] = 0;
}
if ($app == $not_app && $id == $not_id)
{
return False;
}
// if link is a project and no other project selected, also add as project
if ($app == 'projectmanager' && $id && !$info['pm_id'])
{
$info['old_pm_id'] = $info['pm_id'] = $id;
}
else
{
// Link might be contact, check others
$this->get_pm_id($info);
}
$info['info_link'] = $info['info_contact'] = array(
'app' => $app,
'id' => $id,
'title' => (!empty($info['info_from']) ? $info['info_from'] : $title),
);
//echo " title='$title'
writing links for new entry $info_id
\n"; _debug_array($content['link_to']['to_id']); Link::link('infolog', $info_id, $to_write['link_to']['to_id']); $values['link_to']['to_id'] = $info_id; } } if ($values['info_id'] && $info_id) { $this->write_check_links($to_write); if(!$values['info_link_id'] || $values['info_link_id'] != $to_write['info_link_id']) { // Just got a link ID, need to save it unset($to_write['info_etag']); // we must not increment it again $this->so->write($to_write); $values['info_link_id'] = $to_write['info_link_id']; $values['info_contact'] = $to_write['info_contact']; $values['info_from'] = $to_write['info_from']; $this->link_id2from($values); } $values['pm_id'] = $to_write['pm_id']; if (($info_from_set = ($values['info_link_id'] && isset($values['info_from']) && empty($values['info_from'])))) { $values['info_from'] = $to_write['info_from'] = $this->link_id2from($values); } // create (and remove) links in custom fields if(!is_array($old)) { $old = array(); } Api\Storage\Customfields::update_links('infolog',$values,$old,'info_id'); // Check for restore of deleted entry, restore held links if($old['info_status'] == 'deleted' && $values['info_status'] != 'deleted') { Link::restore('infolog', $info_id); } // notify the link-class about the update, as other apps may be subscribt to it Link::notify_update('infolog',$info_id,$values, $change_type); // pre-cache the new values self::set_link_cache($values); // send email notifications and do the history logging if (!is_object($this->tracking)) { $this->tracking = new infolog_tracking($this); } if($old && ($missing_fields = array_diff_key($old, $values))) { // Some custom fields (multiselect with nothing selected) will be missing, // and that's OK. Don't put them back. foreach(array_keys($missing_fields) as $field) { if(array_key_exists($field, $values_in)) { unset($missing_fields[$field]); } } $values = array_merge($values, $missing_fields); } // Add keys missing in the $to_write array if(($missing_fields = array_diff_key($values, $to_write))) { $to_write = array_merge($to_write, $missing_fields); } $this->tracking->track($to_write, $old, $this->user, $values['info_status'] == 'deleted' || $old['info_status'] == 'deleted', null, $skip_notification ); // Clear access cache after notifications, it may get modified as notifications switches user unset(static::$access_cache[$info_id]); if($info_from_set) { $values['info_from'] = ''; } // Change new values back to user time before sending them back if($user2server) { $this->time2time($values); } // merge changes (keeping extra values from the UI) $values_in = array_merge($values_in, $values); // Update modified timestamp of parent if($values['info_id_parent'] && $touch_modified) { $parent = $this->read($values['info_id_parent'], true, 'server', true); $this->write($parent, false, true, false, true, false, null, $ignore_acl); } } return $info_id; } /** * Check links when writing an infolog entry * * Checks for info_contact properly linked, project properly linked and * adds or removes to correct. * * @param array $values */ protected function write_check_links(array &$values) { if(!$this->check_access($values, Acl::EDIT)) { return; } $old_link_id = (int)$values['info_link_id']; $from = $values['info_from']; if($values['info_contact'] && !( is_array($values['info_contact']) && $values['info_contact']['id'] == 'none' ) || ( is_array($values['info_contact']) && $values['info_contact']['id'] == 'none' && array_key_exists('search', $values['info_contact']) )) { if(is_array($values['info_contact'])) { // eTemplate2 returns the array all ready $app = $values['info_contact']['app']; $id = (int)$values['info_contact']['id']; $from = $values['info_contact']['search']; } else if($values['info_contact']) { list($app, $id) = explode(':', $values['info_contact'], 2); } // if project has been removed, but is still info_contact --> also remove it if ($app == 'projectmanager' && $id && $id == $values['old_pm_id'] && !$values['pm_id']) { unset($values['info_link_id'], $id, $values['info_contact']); } else if ($app && $id) { if(!is_array($values['link_to'])) { $values['link_to'] = array(); } $values['info_link_id'] = (int)($info_link_id = Link::link( 'infolog', $values['info_id'], $app,$id )); $values['info_from'] = Link::title($app, $id); if($values['pm_id']) { // They just changed the contact, don't clear the project unset($old_link_id); } } else if ($from) { $values['info_from'] = $from; } else { unset($values['info_link_id']); $values['info_from'] = null; } } else if ($values['pm_id'] && $values['info_id'] && !$values['old_pm_id']) { // Set for new entry with no contact $app = 'projectmanager'; $id = $values['pm_id']; $values['info_link_id'] = (int)($info_link_id = Link::link( 'infolog', $values['info_id'], $app,$id )); } else { unset($values['info_link_id']); unset($values['info_contact']); $values['info_from'] = $from ? $from : null; } if($values['info_id'] && $values['old_pm_id'] !== $values['pm_id']) { Link::unlink(0,'infolog',$values['info_id'],0,'projectmanager',$values['old_pm_id']); // Project has changed, but link is not to project if($values['pm_id']) { $link_id = Link::link('infolog', $values['info_id'], 'projectmanager', $values['pm_id']); if(!$values['info_link_id'] || !Link::get_link($values['info_link_id'])) { $values['info_link_id'] = $link_id; } } else { // Project removed, but primary link is not to project $values['pm_id'] = null; } } if ($old_link_id && $old_link_id != $values['info_link_id']) { $link = Link::get_link($old_link_id); // remove selected project, if removed link is that project if($link['link_app2'] == 'projectmanager' && $link['link_id2'] == $values['old_pm_id']) { unset($values['pm_id'], $values['old_pm_id']); } Link::unlink($old_link_id); } // if linked to a project and no other project selected, also add as project $links = Link::get_links('infolog', $values['info_id'], 'projectmanager'); if (!$values['pm_id'] && count($links)) { $values['old_pm_id'] = $values['pm_id'] = array_pop($links); } } /** * Query the number of children / subs for one or more info_id's * * @param int|array $info_id id * @return int|array number of subs */ function anzSubs( $info_id ) { return $this->so->anzSubs( $info_id ); } /** * Total returned, if search used limit modified optimization */ const LIMIT_MODIFIED_TOTAL = 9999; /** * Set 2^N to automatic retry N times, if limit modified optimization did not return enough rows */ const LIMIT_MODIFIED_RETRY = 8; /** * searches InfoLog for a certain pattern in $query * * @param $query[order] column-name to sort after * @param $query[sort] sort-order DESC or ASC * @param $query[filter] string with combination of acl-, date- and status-filters, eg. 'own-open-today' or '' * @param $query[cat_id] category to use or 0 or unset * @param $query[search] pattern to search, search is done in info_from, info_subject and info_des * @param $query[action] / $query[action_id] if only entries linked to a specified app/entry show be used * @param &$query[start], &$query[total] nextmatch-parameters will be used and set if query returns less entries * @param $query[col_filter] array with column-name - data pairs, data == '' means no filter (!) * @param boolean $no_acl =false true: ignore all acl * @return array with id's as key of the matching log-entries */ function &search(&$query, $no_acl=false) { //error_log(__METHOD__.'('.array2string($query).')'); if($query['filter'] == 'bydate') { if (is_int($query['startdate'])) $query['col_filter'][] = 'info_startdate >= '.$GLOBALS['egw']->db->quote($query['startdate']); if (is_int($query['enddate'])) $query['col_filter'][] = 'info_startdate <= '.$GLOBALS['egw']->db->quote($query['enddate']+(60*60*24)-1); } elseif ($query['filter'] == 'duedate') { if (is_int($query['startdate'])) $query['col_filter'][] = 'info_enddate >= '.$GLOBALS['egw']->db->quote($query['startdate']); if (is_int($query['enddate'])) $query['col_filter'][] = 'info_enddate <= '.$GLOBALS['egw']->db->quote($query['enddate']+(60*60*24)-1); } elseif ($query['filter'] == 'private') { $query['col_filter'][] = 'info_access = ' . $GLOBALS['egw']->db->quote('private'); } if (!isset($query['date_format']) || $query['date_format'] != 'server') { if (isset($query['col_filter'])) { foreach ($this->timestamps as $key) { if (!empty($query['col_filter'][$key])) { $query['col_filter'][$key] = Api\DateTime::user2server($query['col_filter'][$key],'ts'); } } } } $q = $query; unset($q['limit_modified_n_month']); for($n = 1; $n <= self::LIMIT_MODIFIED_RETRY; $n *= 2) { // apply modified limit only if requested AND we're sorting by modified AND NOT (searching, CRM-view, ...) if (!empty($query['limit_modified_n_month']) && empty($query['search']) && // no search empty($query['action']) && empty($query['action_id']) && empty($query['info_id']) && // no CRM view $query['order'] === 'info_datemodified' && $query['sort'] === 'DESC' && isset($query['start'])) { $q['col_filter'][99] = 'info_datemodified > '. (new Api\DateTime((-$n*$query['limit_modified_n_month']).' month'))->format('server'); } $ret = $this->so->search($q, $no_acl); $this->total = $query['total'] = $q['total']; if (!isset($q['col_filter'][99]) || count($ret) >= $query['num_rows']) { if (isset($q['col_filter'][99])) { $this->total = $query['total'] = self::LIMIT_MODIFIED_TOTAL; } break; // --> no modified limit, or got enough rows } // last retry without limit if (2*$n === self::LIMIT_MODIFIED_RETRY) { unset($q['col_filter'][99], $query['limit_modified_n_month']); } } if (is_array($ret)) { foreach ($ret as $id => &$data) { if (!$no_acl && !$this->check_access($data,Acl::READ)) { unset($ret[$id]); continue; } // convert system- to user-time foreach ($this->timestamps as $key) { if ($data[$key]) { $time = new Api\DateTime($data[$key], Api\DateTime::$server_timezone); if (!isset($query['date_format']) || $query['date_format'] != 'server') { if ($time->format('Hi') == '0000') { // we keep dates the same in user-time $arr = Api\DateTime::to($time,'array'); $time = new Api\DateTime($arr, Api\DateTime::$user_timezone); } else { $time->setTimezone(Api\DateTime::$user_timezone); } } $data[$key] = Api\DateTime::to($time,'ts'); } } // pre-cache title and file access self::set_link_cache($data); } } //echo "boinfolog::search(".print_r($query,True).")=
".print_r($ret,True)."\n"; return $ret; } /** * Query ctag for infolog * * @param array $filter = array('filter'=>'own','info_type'=>'task') * @return string */ public function getctag(array $filter=array('filter'=>'own','info_type'=>'task')) { $filter += array( 'order' => 'info_datemodified', 'sort' => 'DESC', 'date_format' => 'server', 'start' => 0, 'num_rows' => 1, ); // we need to query deleted entries too for a ctag! $filter['filter'] .= '+deleted'; $result =& $this->search($filter); if (empty($result)) return 'EGw-empty-wGE'; $entry = array_shift($result); return $entry['info_datemodified']; } /** * imports a mail identified by uid as infolog * * @author Cornelius Weiss
cal_to_include("; print_r($args); echo ")
\n"; $user = (int) $args['owner']; if ($user <= 0 && !checkdate($args['month'],$args['day'],$args['year'])) { return False; } Api\Translation::add_app('infolog'); $do_events = $args['location'] == 'calendar_include_events'; $to_include = array(); $date_wanted = sprintf('%04d/%02d/%02d',$args['year'],$args['month'],$args['day']); $query = array( 'order' => $args['order'] ? $args['order'] : 'info_startdate', 'sort' => $args['sort'] ? $args['sort'] : ($do_events ? 'ASC' : 'DESC'), 'filter'=> "user$user".($do_events ? 'date' : 'opentoday').$date_wanted, 'start' => 0, ); if ($GLOBALS['egw_info']['user']['preferences']['infolog']['cal_show'] || $GLOBALS['egw_info']['user']['preferences']['infolog']['cal_show'] === '0') { $query['col_filter']['info_type'] = explode(',',$GLOBALS['egw_info']['user']['preferences']['infolog']['cal_show']); } elseif ($this->customfields && !$GLOBALS['egw_info']['user']['preferences']['infolog']['cal_show_custom']) { $query['col_filter']['info_type'] = array('task','phone','note','email'); } while ($infos = $this->search($query)) { foreach ($infos as $info) { $start = new Api\DateTime($info['info_startdate'],Api\DateTime::$user_timezone); $title = ($do_events ? $start->format(false).' ' : ''). $info['info_subject']; $view = Link::view('infolog',$info['info_id']); $size = null; $edit = Link::edit('infolog',$info['info_id'], $size); $edit['size'] = $size; $content=array(); $status = $this->status[$info['info_type']][$info['info_status']]; $icons = array(); foreach(array( $info['info_type'] => 'navbar', $status => 'status' ) as $icon => $default) { $icons[Api\Image::find('infolog',$icon) ? $icon : $default] = $icon; } $content[] = Api\Html::a_href($title,$view); $html = Api\Html::table(array(1 => $content)); $to_include[] = array( 'starttime' => $info['info_startdate'], 'endtime' => ($info['info_enddate'] ? $info['info_enddate'] : $info['info_startdate']), 'title' => $title, 'view' => $view, 'edit' => $edit, 'icons' => $icons, 'content' => $html, ); } if ($query['total'] <= ($query['start']+=count($infos))) { break; // no more availible } } //echo "boinfolog::cal_to_include("; print_r($args); echo ")"; print_r($to_include); echo "\n"; return $to_include; } /** * Returm InfoLog (custom) information for projectmanager: status icon, type icon, css class * * @param array $args array with id's in $args['infolog'] * @return array with id => array with values for keys 'status', 'icon', 'class' */ function pm_icons($args) { if (isset($args['infolog']) && count($args['infolog'])) { $query = array( 'col_filter' => array('info_id' => $args['infolog']), 'subs' => true, 'cols' => 'main.info_id,info_type,info_status,info_percent,info_id_parent', ); $infos = array(); foreach($this->search($query) as $row) { $infos[$row['info_id']] = array( 'status' => $row['info_type'] != 'phone' && $row['info_status'] == 'ongoing' ? $row['info_percent'].'%' : 'infolog/'.$this->status[$row['info_type']][$row['info_status']], 'status_icon' => $row['info_type'] != 'phone' && $row['info_status'] == 'ongoing' ? 'ongoing' : 'infolog/'.$row['info_status'], 'class' => $row['info_id_parent'] ? 'infolog_rowHasParent' : null, ); if (Api\Image::find('infolog', $icon=$row['info_type'].'_element') || Api\Image::find('infolog', $icon=$row['info_type'])) { $infos[$row['info_id']]['icon'] = 'infolog/'.$icon; } } $anzSubs = $this->anzSubs(array_keys($infos)); if($anzSubs && is_array($anzSubs)) { foreach($anzSubs as $info_id => $subs) { if ($subs) $infos[$info_id]['class'] .= ' infolog_rowHasSubs'; } } } return $infos; } var $categories; /** * Find existing categories in database by name or add categories that do not exist yet * currently used for ical/sif import * * @param array $catname_list names of the categories which should be found or added * @param int $info_id = -1 match against existing infolog and expand the returned category ids * by the ones the user normally does not see due to category permissions - used to preserve categories * @return array category ids (found, added and preserved categories) */ function find_or_add_categories($catname_list, $info_id=-1) { if (!is_object($this->categories)) { $this->categories = new Api\Categories($this->user,'infolog'); } $old_cats_preserve = array(); if ($info_id && $info_id > 0) { // preserve Api\Categories without users read access $old_infolog = $this->read($info_id); $old_categories = explode(',',$old_infolog['info_cat']); if (is_array($old_categories) && count($old_categories) > 0) { foreach ($old_categories as $cat_id) { if ($cat_id && !$this->categories->check_perms(Acl::READ, $cat_id)) { $old_cats_preserve[] = $cat_id; } } } } $cat_id_list = array(); foreach ((array)$catname_list as $cat_name) { $cat_name = trim($cat_name); $cat_id = $this->categories->name2id($cat_name, 'X-'); if (!$cat_id) { // some SyncML clients (mostly phones) add an X- to the category names if (strncmp($cat_name, 'X-', 2) == 0) { $cat_name = substr($cat_name, 2); } $cat_id = $this->categories->add(array('name' => $cat_name, 'descr' => $cat_name, 'access' => 'private')); } if ($cat_id) { $cat_id_list[] = $cat_id; } } if (count($old_cats_preserve) > 0) { $cat_id_list = array_merge($old_cats_preserve, $cat_id_list); } if (count($cat_id_list) > 1) { $cat_id_list = array_unique($cat_id_list); // disable sorting until infolog supports multiple categories // to make sure that the preserved category takes precedence over a new one from the client /* sort($cat_id_list, SORT_NUMERIC); */ } return $cat_id_list; } /** * Get names for categories specified by their id's * * @param array|string $cat_id_list array or comma-sparated list of id's * @return array with names */ function get_categories($cat_id_list) { if (!is_object($this->categories)) { $this->categories = new Api\Categories($this->user,'infolog'); } if (!is_array($cat_id_list)) { $cat_id_list = explode(',',$cat_id_list); } $cat_list = array(); foreach($cat_id_list as $cat_id) { if ($cat_id && $this->categories->check_perms(Acl::READ, $cat_id) && ($cat_name = $this->categories->id2name($cat_id)) && $cat_name != '--') { $cat_list[] = $cat_name; } } return $cat_list; } /** * Send all async infolog notification * * Called via the async service job 'infolog-async-notification' */ function async_notification() { if (!($users = $this->so->users_with_open_entries())) { return; } //error_log(__METHOD__."() users with open entries: ".implode(', ',$users)); $save_account_id = $GLOBALS['egw_info']['user']['account_id']; $save_prefs = $GLOBALS['egw_info']['user']['preferences']; foreach($users as $user) { if (!($email = $GLOBALS['egw']->accounts->id2name($user,'account_email'))) continue; // create the enviroment for $user $this->user = $GLOBALS['egw_info']['user']['account_id'] = $user; $GLOBALS['egw']->preferences->__construct($user); $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(); $GLOBALS['egw']->acl->__construct($user); $this->grants = $GLOBALS['egw']->acl->get_grants('infolog',$this->group_owners ? $this->group_owners : true); $this->so = new infolog_so($this->grants); // so caches it's filters $notified_info_ids = array(); foreach(array( 'notify_due_responsible' => 'open-responsible-enddate', 'notify_due_delegated' => 'open-delegated-enddate', 'notify_start_responsible' => 'open-responsible-date', 'notify_start_delegated' => 'open-delegated-date', ) as $pref => $filter) { if (!($pref_value = $GLOBALS['egw_info']['user']['preferences']['infolog'][$pref])) continue; $filter .= date('Y-m-d',time()+24*60*60*(int)$pref_value); //error_log(__METHOD__."() checking with filter '$filter' ($pref_value) for user $user ($email)"); $params = array('filter' => $filter, 'custom_fields' => true, 'subs' => true); foreach($this->so->search($params) as $info) { // check if we already send a notification for that infolog entry, eg. starting and due on same day if (in_array($info['info_id'],$notified_info_ids)) continue; if (is_null($this->tracking) || $this->tracking->user != $user) { $this->tracking = new infolog_tracking($this); } switch($pref) { case 'notify_due_responsible': $info['prefix'] = lang('Due %1',$this->enums['type'][$info['info_type']]); $info['message'] = lang('%1 you are responsible for is due at %2',$this->enums['type'][$info['info_type']], $this->tracking->datetime($info['info_enddate'],false)); break; case 'notify_due_delegated': $info['prefix'] = lang('Due %1',$this->enums['type'][$info['info_type']]); $info['message'] = lang('%1 you delegated is due at %2',$this->enums['type'][$info['info_type']], $this->tracking->datetime($info['info_enddate'],false)); break; case 'notify_start_responsible': $info['prefix'] = lang('Starting %1',$this->enums['type'][$info['info_type']]); $info['message'] = lang('%1 you are responsible for is starting at %2',$this->enums['type'][$info['info_type']], $this->tracking->datetime($info['info_startdate'],null)); break; case 'notify_start_delegated': $info['prefix'] = lang('Starting %1',$this->enums['type'][$info['info_type']]); $info['message'] = lang('%1 you delegated is starting at %2',$this->enums['type'][$info['info_type']], $this->tracking->datetime($info['info_startdate'],null)); break; } //error_log("notifiying $user($email) about $info[info_subject]: $info[message]"); $this->tracking->send_notification($info,null,$email,$user,$pref); $notified_info_ids[] = $info['info_id']; } } } $GLOBALS['egw_info']['user']['account_id'] = $save_account_id; $GLOBALS['egw_info']['user']['preferences'] = $save_prefs; } /** conversion of infolog status to vtodo status * @private * @var array */ var $_status2vtodo = array( 'offer' => 'NEEDS-ACTION', 'not-started' => 'NEEDS-ACTION', 'ongoing' => 'IN-PROCESS', 'done' => 'COMPLETED', 'cancelled' => 'CANCELLED', 'billed' => 'COMPLETED', 'template' => 'CANCELLED', 'nonactive' => 'CANCELLED', 'archive' => 'CANCELLED', 'deferred' => 'NEEDS-ACTION', 'waiting' => 'IN-PROCESS', ); /** conversion of vtodo status to infolog status * @private * @var array */ var $_vtodo2status = array( 'NEEDS-ACTION' => 'not-started', 'NEEDS ACTION' => 'not-started', 'IN-PROCESS' => 'ongoing', 'IN PROCESS' => 'ongoing', 'COMPLETED' => 'done', 'CANCELLED' => 'cancelled', ); /** * Converts an infolog status into a vtodo status * * @param string $status see $this->status * @return string {CANCELLED|NEEDS-ACTION|COMPLETED|IN-PROCESS} */ function status2vtodo($status) { return isset($this->_status2vtodo[$status]) ? $this->_status2vtodo[$status] : 'NEEDS-ACTION'; } /** * Converts a vtodo status into an infolog status using the optional X-INFOLOG-STATUS * * X-INFOLOG-STATUS is only used, if translated to the vtodo-status gives the identical vtodo status * --> the user did not changed it * * @param string $_vtodo_status {CANCELLED|NEEDS-ACTION|COMPLETED|IN-PROCESS} * @param string $x_infolog_status preserved original infolog status * @return string */ function vtodo2status($_vtodo_status,$x_infolog_status=null) { $vtodo_status = strtoupper($_vtodo_status); if ($x_infolog_status && $this->status2vtodo($x_infolog_status) == $vtodo_status) { $status = $x_infolog_status; } else { $status = isset($this->_vtodo2status[$vtodo_status]) ? $this->_vtodo2status[$vtodo_status] : 'not-started'; } return $status; } /** * Get status of a single or all types * * As status value can have different translations depending on type, we list all translations * * @param string $type = null * @param array &$icons = null on return name of icons * @return array value => (commaseparated) translations */ function get_status($type=null, array &$icons=null) { // if filtered by type, show only the stati of the filtered type if ($type && isset($this->status[$type])) { $statis = $icons = $this->status[$type]; } else // show all stati { $statis = $icons = array(); foreach($this->status as $t => $stati) { if ($t === 'defaults') continue; foreach($stati as $val => $label) { $statis[$val][$label] = lang($label); if (!isset($icons[$val])) $icons[$val] = $label; } } foreach($statis as $val => &$labels) { $labels = implode(', ', $labels); } } // always add deleted status $statis['deleted'] = 'deleted'; return $statis; } /** * Activates an InfoLog entry (setting it's status from template or inactive depending on the completed percentage) * * @param array $info * @return string new status */ function activate($info) { switch((int)$info['info_percent']) { case 0: return 'not-started'; case 100: return 'done'; } return 'ongoing'; } /** * Get the Parent ID of an InfoLog entry * * @param string $_guid * @return string parentID */ function getParentID($_guid) { #Horde::logMessage("getParentID($_guid)", __FILE__, __LINE__, PEAR_LOG_DEBUG); $parentID = False; $myfilter = array('col_filter' => array('info_uid'=>$_guid)) ; if ($_guid && ($found=$this->search($myfilter)) && ($uidmatch = array_shift($found))) { $parentID = $uidmatch['info_id']; } return $parentID; } /** * Try to find a matching db entry * This expects timestamps to be in server-time. * * @param array $infoData the infolog data we try to find * @param boolean $relax = false if asked to relax, we only match against some key fields * @param string $tzid = null timezone, null => user time * * @return array of infolog_ids of matching entries */ function findInfo($infoData, $relax=false, $tzid=null) { $foundInfoLogs = array(); $filter = array(); if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '('. ($relax ? 'RELAX, ': 'EXACT, ') . $tzid . ')[InfoData]:' . array2string($infoData)); } if ($infoData['info_id'] && ($egwData = $this->read($infoData['info_id'], true, 'server'))) { // we only do a simple consistency check if (!$relax || strpos($egwData['info_subject'], $infoData['info_subject']) === 0) { return array($egwData['info_id']); } if (!$relax) return array(); } unset($infoData['info_id']); if (!$relax && !empty($infoData['info_uid'])) { $filter = array('col_filter' => array('info_uid' => $infoData['info_uid'])); foreach($this->so->search($filter) as $egwData) { if (!$this->check_access($egwData,Acl::READ)) continue; $foundInfoLogs[$egwData['info_id']] = $egwData['info_id']; } return $foundInfoLogs; } unset($infoData['info_uid']); if (empty($infoData['info_des'])) { $description = false; } else { // ignore meta information appendices $description = trim(preg_replace('/\s*\[[A-Z_]+:.*\].*/im', '', $infoData['info_des'])); $text = trim(preg_replace('/\s*\[[A-Z_]+:.*\]/im', '', $infoData['info_des'])); if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . "()[description]: $description"); } // Avoid quotation problems $matches = null; if (preg_match_all('/[\x20-\x7F]*/m', $text, $matches, PREG_SET_ORDER)) { $text = ''; foreach ($matches as $chunk) { if (strlen($text) < strlen($chunk[0])) { $text = $chunk[0]; } } if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . "()[search]: $text"); } $filter['search'] = $text; } } $this->time2time($infoData, $tzid, false); $filter['col_filter'] = $infoData; // priority does not need to match unset($filter['col_filter']['info_priority']); // we ignore description and location first unset($filter['col_filter']['info_des']); unset($filter['col_filter']['info_location']); foreach ($this->so->search($filter) as $itemID => $egwData) { if (!$this->check_access($egwData,Acl::READ)) continue; switch ($infoData['info_type']) { case 'task': if (!empty($egwData['info_location'])) { $egwData['info_location'] = str_replace("\r\n", "\n", $egwData['info_location']); } if (!$relax && !empty($infoData['info_location']) && (empty($egwData['info_location']) || strpos($egwData['info_location'], $infoData['info_location']) !== 0)) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[location mismatch]: ' . $infoData['info_location'] . ' <> ' . $egwData['info_location']); } continue 2; // +1 for switch } default: if (!empty($egwData['info_des'])) { $egwData['info_des'] = str_replace("\r\n", "\n", $egwData['info_des']); } if (!$relax && ($description && empty($egwData['info_des']) || !empty($egwData['info_des']) && empty($infoData['info_des']) || strpos($egwData['info_des'], $description) === false)) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[description mismatch]: ' . $infoData['info_des'] . ' <> ' . $egwData['info_des']); } continue 2; // +1 for switch } // no further criteria to match $foundInfoLogs[$egwData['info_id']] = $egwData['info_id']; } } if (!$relax && !empty($foundInfoLogs)) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[FOUND]:' . array2string($foundInfoLogs)); } return $foundInfoLogs; } if ($relax) { unset($filter['search']); } // search for matches by date only unset($filter['col_filter']['info_startdate']); unset($filter['col_filter']['info_enddate']); unset($filter['col_filter']['info_datecompleted']); // Some devices support lesser stati unset($filter['col_filter']['info_status']); // try tasks without category unset($filter['col_filter']['info_cat']); // Horde::logMessage("findVTODO Filter\n" // . print_r($filter, true), // __FILE__, __LINE__, PEAR_LOG_DEBUG); foreach ($this->so->search($filter) as $itemID => $egwData) { if (!$this->check_access($egwData,Acl::READ)) continue; // Horde::logMessage("findVTODO Trying\n" // . print_r($egwData, true), // __FILE__, __LINE__, PEAR_LOG_DEBUG); if (isset($infoData['info_cat']) && isset($egwData['info_cat']) && $egwData['info_cat'] && $infoData['info_cat'] != $egwData['info_cat']) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[category mismatch]: ' . $infoData['info_cat'] . ' <> ' . $egwData['info_cat']); } continue; } if (isset($infoData['info_startdate']) && $infoData['info_startdate']) { // We got a startdate from client if (isset($egwData['info_startdate']) && $egwData['info_startdate']) { // We compare the date only $taskTime = new Api\DateTime($infoData['info_startdate'],Api\DateTime::$server_timezone); $egwTime = new Api\DateTime($egwData['info_startdate'],Api\DateTime::$server_timezone); if ($taskTime->format('Ymd') != $egwTime->format('Ymd')) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[start mismatch]: ' . $taskTime->format('Ymd') . ' <> ' . $egwTime->format('Ymd')); } continue; } } elseif (!$relax) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[start mismatch]'); } continue; } } if ($infoData['info_type'] == 'task') { if (isset($infoData['info_status']) && isset($egwData['info_status']) && $egwData['info_status'] == 'done' && $infoData['info_status'] != 'done' || $egwData['info_status'] != 'done' && $infoData['info_status'] == 'done') { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[status mismatch]: ' . $infoData['info_status'] . ' <> ' . $egwData['info_status']); } continue; } if (isset($infoData['info_enddate']) && $infoData['info_enddate']) { // We got a enddate from client if (isset($egwData['info_enddate']) && $egwData['info_enddate']) { // We compare the date only $taskTime = new Api\DateTime($infoData['info_enddate'],Api\DateTime::$server_timezone); $egwTime = new Api\DateTime($egwData['info_enddate'],Api\DateTime::$server_timezone); if ($taskTime->format('Ymd') != $egwTime->format('Ymd')) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[DUE mismatch]: ' . $taskTime->format('Ymd') . ' <> ' . $egwTime->format('Ymd')); } continue; } } elseif (!$relax) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[DUE mismatch]'); } continue; } } if (isset($infoData['info_datecompleted']) && $infoData['info_datecompleted']) { // We got a completed date from client if (isset($egwData['info_datecompleted']) && $egwData['info_datecompleted']) { // We compare the date only $taskTime = new Api\DateTime($infoData['info_datecompleted'],Api\DateTime::$server_timezone); $egwTime = new Api\DateTime($egwData['info_datecompleted'],Api\DateTime::$server_timezone); if ($taskTime->format('Ymd') != $egwTime->format('Ymd')) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[completed mismatch]: ' . $taskTime->format('Ymd') . ' <> ' . $egwTime->format('Ymd')); } continue; } } elseif (!$relax) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[completed mismatch]'); } continue; } } elseif (!$relax && isset($egwData['info_datecompleted']) && $egwData['info_datecompleted']) { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[completed mismatch]'); } continue; } } $foundInfoLogs[$itemID] = $itemID; } if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '()[FOUND]:' . array2string($foundInfoLogs)); } return $foundInfoLogs; } }