From 4259d8d62237e0bb3b746bb537df336732125346 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 4 Oct 2006 17:40:33 +0000 Subject: [PATCH] - primary link / contact con now be set direct in the contact line - checkbox to set a custom contact (additional to the linked contact) - new select/link entry custom fields (eg. to store a contact) - uses the stock customfield widget now - email is now a stock infolog type --- infolog/inc/class.boinfolog.inc.php | 2050 ++++++++--------- infolog/inc/class.soinfolog.inc.php | 1203 +++++----- infolog/inc/class.uicustomfields.inc.php | 655 +++--- infolog/inc/class.uiinfolog.inc.php | 2304 ++++++++++---------- infolog/index.php | 34 +- infolog/setup/etemplates.inc.php | 64 +- infolog/setup/phpgw_de.lang | 2 + infolog/setup/phpgw_en.lang | 2 + infolog/setup/setup.inc.php | 3 +- infolog/setup/tables_current.inc.php | 3 +- infolog/setup/tables_update.inc.php | 12 + infolog/templates/default/app.css | 3 +- infolog/templates/default/customfields.xet | 17 +- infolog/templates/default/edit.xet | 17 +- 14 files changed, 3242 insertions(+), 3127 deletions(-) diff --git a/infolog/inc/class.boinfolog.inc.php b/infolog/inc/class.boinfolog.inc.php index 831c29e39e..a40bc9507d 100644 --- a/infolog/inc/class.boinfolog.inc.php +++ b/infolog/inc/class.boinfolog.inc.php @@ -1,1001 +1,1109 @@ * - * originaly based on todo written by Joseph Engo * - * -------------------------------------------- * - * This program is free software; you can redistribute it and/or modify it * - * under the terms of the GNU General Public License as published by the * - * Free Software Foundation; either version 2 of the License, or (at your * - * option) any later version. * - \**************************************************************************/ - - /* $Id$ */ +/** + * InfoLog - Business object + * + * @link http://www.egroupware.org + * @author Ralf Becker + * @package infolog + * @copyright (c) 2003-6 by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - include_once(EGW_INCLUDE_ROOT.'/infolog/inc/class.soinfolog.inc.php'); +include_once(EGW_INCLUDE_ROOT.'/infolog/inc/class.soinfolog.inc.php'); +/** + * This class is the BO-layer of InfoLog, it also handles xmlrpc requests + */ +class boinfolog +{ + var $enums; /** - * This class is the BO-layer of InfoLog, it also handles xmlrpc requests + * Instance of our so class * - * @package infolog - * @author Ralf Becker - * @copyright (c) by Ralf Becker - * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @var soinfolog */ - class boinfolog + var $so; + /** + * Instance of the link class + * + * @var bolink + */ + var $link; + var $vfs; + var $vfs_basedir='/infolog'; + var $valid_pathes = array(); + var $send_file_ips = array(); + + var $xmlrpc_methods = array(); + var $soap_functions = array( + 'read' => array( + 'in' => array('int'), + 'out' => array('array') + ), + 'search' => array( + 'in' => array('array'), + 'out' => array('array') + ), + 'write' => array( + 'in' => array('array'), + 'out' => array() + ), + 'delete' => array( + 'in' => array('int'), + 'out' => array() + ), + 'categories' => array( + 'in' => array('bool'), + 'out' => array('array') + ), + ); + var $xmlrpc = False; // called via xmlrpc + + var $tz_offset = 0; + /** + * offset in secconds between user and server-time, + * it need to be add to a server-time to get the user-time or substracted from a user-time to get the server-time + * + * @var int + */ + var $tz_offset_s = 0; + var $user_time_now; + /** + * name of timestamps in an InfoLog entry + * + * @var array + */ + var $timestamps = array('info_startdate','info_enddate','info_datemodified','info_datecompleted'); + /** + * instance of the config class for infolog + * + * @var config + */ + var $config; + /** + * fields the responsible user can change + * + * @var array + */ + var $responsible_edit=array('info_status','info_percent','info_datecompleted'); + /** + * implicit ACL rights of the responsible user: read or edit + * + * @var string + */ + var $implicit_rights='read'; + /** + * Custom fields read from the infolog config + * + * @var array + */ + var $customfields=array(); + + /** + * Constructor Infolog BO + * + * @param int $info_id + * @param boolean $instanciate_link=true should the link class be instanciated, used by the link-registry to prevent infinit recursion + */ + function boinfolog($info_id = 0,$instanciate_link=true) { - var $enums; - var $so; - var $link; - var $vfs; - var $vfs_basedir='/infolog'; - var $valid_pathes = array(); - var $send_file_ips = array(); - - var $xmlrpc_methods = array(); - var $soap_functions = array( - 'read' => array( - 'in' => array('int'), - 'out' => array('array') - ), - 'search' => array( - 'in' => array('array'), - 'out' => array('array') - ), - 'write' => array( - 'in' => array('array'), - 'out' => array() - ), - 'delete' => array( - 'in' => array('int'), - 'out' => array() - ), - 'categories' => array( - 'in' => array('bool'), - 'out' => array('array') + $this->enums = $this->stock_enums = array( + 'priority' => array ( + 3 => 'urgent', + 2 => 'high', + 1 => 'normal', + 0 => 'low' ), + 'confirm' => array( + 'not' => 'not','accept' => 'accept','finish' => 'finish', + 'both' => 'both' ), + 'type' => array( + 'task' => 'task','phone' => 'phone','note' => 'note','email' => 'email' + /* ,'confirm' => 'confirm','reject' => 'reject','fax' => 'fax' not implemented so far */ ) ); - var $xmlrpc = False; // called via xmlrpc + $this->status = $this->stock_status = array( + 'defaults' => array( + 'task' => 'not-started', 'phone' => 'not-started', 'note' => 'done','email' => 'done'), + 'task' => array( + 'offer' => 'offer', // --> NEEDS-ACTION + 'not-started' => 'not-started', // iCal NEEDS-ACTION + 'ongoing' => 'ongoing', // iCal IN-PROCESS + 'done' => 'done', // iCal COMPLETED + 'cancelled' => 'cancelled', // iCal CANCELLED + 'billed' => 'billed' ), // --> DONE + 'phone' => array( + 'not-started' => 'call', // iCal NEEDS-ACTION + 'ongoing' => 'will-call', // iCal IN-PROCESS + 'done' => 'done', // iCal COMPLETED + 'billed' => 'billed' ), // --> DONE + 'note' => array( + 'ongoing' => 'ongoing', // iCal has no status on notes + 'done' => 'done'), + 'email' => array( + 'ongoing' => 'ongoing', // iCal has no status on notes + 'done' => 'done' + )); - var $tz_offset = 0; - /** - * @var int $tz_offset_s offset in secconds between user and server-time, - * it need to be add to a server-time to get the user-time or substracted from a user-time to get the server-time - */ - var $tz_offset_s = 0; - var $user_time_now; - /** - * @var array $timestamps name of timestamps in an InfoLog entry - */ - var $timestamps = array('info_startdate','info_enddate','info_datemodified','info_datecompleted'); - /** - * @var array $config infolog configuration - */ - var $config; - /** - * @var array $responsible_edit=array('info_status','info_percent','info_datecompleted') fields the responsible user can change - */ - var $responsible_edit=array('info_status','info_percent','info_datecompleted'); - /** - * @var string $implicit_rights='read' implicit ACL rights of the responsible user: read or edit - */ - var $implicit_rights='read'; - - /** - * Constructor Infolog BO - * - * @param int $info_id - * @param boolean $instanciate_link=true should the link class be instanciated, used by the link-registry to prevent infinit recursion - */ - function boinfolog($info_id = 0,$instanciate_link=true) + $this->so =& new soinfolog(); + + if (!is_object($GLOBALS['egw']->link) && $instanciate_link) { - $this->enums = $this->stock_enums = array( - 'priority' => array ( - 3 => 'urgent', - 2 => 'high', - 1 => 'normal', - 0 => 'low' - ), -/* 'status' => array( - 'offer' => 'offer','ongoing' => 'ongoing','call' => 'call', - 'will-call' => 'will-call','done' => 'done', - 'billed' => 'billed' ), -*/ 'confirm' => array( - 'not' => 'not','accept' => 'accept','finish' => 'finish', - 'both' => 'both' ), - 'type' => array( - 'task' => 'task','phone' => 'phone','note' => 'note' - /* ,'confirm' => 'confirm','reject' => 'reject','email' => 'email', - 'fax' => 'fax' not implemented so far */ ) - ); - $this->status = $this->stock_status = array( - 'defaults' => array( - 'task' => 'not-started', 'phone' => 'not-started', 'note' => 'done'), - 'task' => array( - 'offer' => 'offer', // --> NEEDS-ACTION - 'not-started' => 'not-started', // iCal NEEDS-ACTION - 'ongoing' => 'ongoing', // iCal IN-PROCESS - 'done' => 'done', // iCal COMPLETED - 'cancelled' => 'cancelled', // iCal CANCELLED - 'billed' => 'billed' ), // --> DONE - 'phone' => array( - 'not-started' => 'call', // iCal NEEDS-ACTION - 'ongoing' => 'will-call', // iCal IN-PROCESS - 'done' => 'done', // iCal COMPLETED - 'billed' => 'billed' ), // --> DONE - 'note' => array( - 'ongoing' => 'ongoing', // iCal has no status on notes - 'done' => 'done' - )); + $GLOBALS['egw']->link =& CreateObject('phpgwapi.bolink'); + } + $this->link =& $GLOBALS['egw']->link; - $this->so =& new soinfolog(); + $this->config =& CreateObject('phpgwapi.config','infolog'); + $this->config->read_repository(); - if (!is_object($GLOBALS['egw']->link) && $instanciate_link) + if ($this->config->config_data) + { + $this->link_pathes = $this->config->config_data['link_pathes']; + $this->send_file_ips = $this->config->config_data['send_file_ips']; + + if (isset($this->config->config_data['status']) && is_array($this->config->config_data['status'])) { - $GLOBALS['egw']->link =& CreateObject('phpgwapi.bolink'); - } - $this->link =& $GLOBALS['egw']->link; - - $this->config =& CreateObject('phpgwapi.config','infolog'); - $this->config->read_repository(); - - $this->customfields = array(); - if ($this->config->config_data) - { - $this->link_pathes = $this->config->config_data['link_pathes']; - $this->send_file_ips = $this->config->config_data['send_file_ips']; - - if (isset($this->config->config_data['status']) && is_array($this->config->config_data['status'])) + foreach($this->config->config_data['status'] as $key => $data) { - foreach($this->config->config_data['status'] as $key => $data) + if (!is_array($this->status[$key])) { - if (!is_array($this->status[$key])) - { - $this->status[$key] = array(); - } - $this->status[$key] = array_merge($this->status[$key],$this->config->config_data['status'][$key]); + $this->status[$key] = array(); + } + $this->status[$key] = array_merge($this->status[$key],$this->config->config_data['status'][$key]); + } + } + if (isset($this->config->config_data['types']) && is_array($this->config->config_data['types'])) + { + //echo "stock-types:
"; print_r($this->enums['type']); echo "
\n"; + //echo "config-types:
"; print_r($this->config->config_data['types']); echo "
\n"; + $this->enums['type'] += $this->config->config_data['types']; + //echo "types:
"; print_r($this->enums['type']); echo "
\n"; + } + if (isset($this->config->config_data['customfields']) && is_array($this->config->config_data['customfields'])) + { + if (!($this->customfields = $this->config->config_data['customfields'])) $this->customfields = array(); + 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] = $this->config->config_data['customfields'][$name] = $field; + $save_config = true; } } - if (isset($this->config->config_data['types']) && is_array($this->config->config_data['types'])) - { - //echo "stock-types:
"; print_r($this->enums['type']); echo "
\n"; - //echo "config-types:
"; print_r($this->config->config_data['types']); echo "
\n"; - $this->enums['type'] += $this->config->config_data['types']; - //echo "types:
"; print_r($this->enums['type']); echo "
\n"; - } - if (isset($this->config->config_data['customfields']) && is_array($this->config->config_data['customfields'])) - { - $this->customfields = $this->config->config_data['customfields']; - } - if (count(explode(',',$this->config->config_data['responsible_edit']))) - { - $this->responsible_edit = array_merge($this->responsible_edit,explode(',',$this->config->config_data['responsible_edit'])); - } - if ($this->config->config_data['implicit_rights'] == 'edit') - { - $this->implicit_rights = 'edit'; - } + if ($save_config) $this->config->save_repository(); } - $this->user = $GLOBALS['egw_info']['user']['account_id']; - /** - * @var int $tz_offset_s offset in secconds between user and server-time, - * it need to be add to a server-time to get the user-time or substracted from a user-time to get the server-time - */ - $this->tz_offset = $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; - $this->tz_offset_s = 60*60*$this->tz_offset; - $this->user_time_now = time() + $this->tz_offset_s; - - // are we called via xmlrpc? - $this->xmlrpc = is_object($GLOBALS['server']) && $GLOBALS['server']->last_method; - - if ($info_id) + if (count(explode(',',$this->config->config_data['responsible_edit']))) { - $this->read( $info_id ); + $this->responsible_edit = array_merge($this->responsible_edit,explode(',',$this->config->config_data['responsible_edit'])); } - else + if ($this->config->config_data['implicit_rights'] == 'edit') { - $this->init(); + $this->implicit_rights = 'edit'; } } + $this->user = $GLOBALS['egw_info']['user']['account_id']; - /** - * checks if there are customfields for typ $typ - * - * @param string $typ - * @return boolean True if there are customfields for $typ, else False - */ - function has_customfields($typ) + $this->tz_offset = $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; + $this->tz_offset_s = 60*60*$this->tz_offset; + $this->user_time_now = time() + $this->tz_offset_s; + + // are we called via xmlrpc? + $this->xmlrpc = is_object($GLOBALS['server']) && $GLOBALS['server']->last_method; + + if ($info_id) { - foreach($this->customfields as $name => $field) - { - if (empty($field['typ']) || $field['typ'] == $typ) - { - return True; - } - } - return False; + $this->read( $info_id ); } - - /** - * 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 EGW_ACL_{READ|EDIT|ADD|DELETE} - * @return boolean - */ - function check_access( $info,$required_rights ) + else { - static $cache = array(); - - $info_id = is_array($info) ? $info['info_id'] : $info; - - if (isset($cache[$info_id][$required_rights])) - { - return $cache[$info_id][$required_rights]; - } - return $cache[$info_id][$required_rights] = $this->so->check_access( $info,$required_rights,$this->implicit_rights == 'edit' ); - } - - /** - * init internal data to be empty - */ - function init() - { - $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='') - { - //echo "

boinfolog::link_id2from(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 && - ($link = $this->link->get_link($info['info_link_id'])) !== False) - { - $nr = $link['link_app1'] == 'infolog' && $link['link_id1'] == $info['info_id'] ? '2' : '1'; - $title = $this->link->title($link['link_app'.$nr],$link['link_id'.$nr]); - - if ($title == $info['info_from'] || @htmlentities($title) == $info['info_from']) - { - $info['info_from'] = ''; - } - if ($link['link_app'.$nr] == $not_app && $link['link_id'.$nr] == $not_id) - { - return False; - } - $info['info_link'] = array( - 'app' => $link['link_app'.$nr], - 'id' => $link['link_id'.$nr], - 'title' => (!empty($info['info_from']) ? $info['info_from'] : $title), - ); - - //echo " title='$title'

\n"; - return $info['blur_title'] = $title; - } - else - { - $info['info_link'] = array('title' => $info['info_from']); - $info['info_link_id'] = 0; // link might have been deleted - } - return False; - } - - /** - * Create a subject from a description: truncate it and add ' ...' - */ - function subject_from_des($des) - { - return substr($des,0,60).' ...'; - } - - /** - * Read an infolog entry specified by $info_id - * - * @param int/array $info_id integer id or array with key 'info_id' of the entry to read - * @param boolean $run_link_id2from=true should link_id2from run, default yes, - * need to be set to false if called from link-title to prevent an infinit recursion - * @return array/boolean infolog entry, null if not found or false if no permission to read it - */ - function &read($info_id,$run_link_id2from=true) - { - if (is_array($info_id)) - { - $info_id = (int) (isset($info_id['info_id']) ? $info_id['info_id'] : $info_id[0]); - } - - if ($this->so->read($info_id) === False) - { - if ($this->xmlrpc) - { - $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['not_exist'],$GLOBALS['xmlrpcstr']['not_exist']); - } - return null; - } - if (!$this->check_access($info_id,EGW_ACL_READ)) // check behind read, to prevent a double read - { - if ($this->xmlrpc) - { - $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); - } - return False; - } - $data = $this->so->data; - - if ($data['info_subject'] == $this->subject_from_des($data['info_des'])) - { - $data['info_subject'] = ''; - } - if ($run_link_id2from) $this->link_id2from($data); - - // convert system- to user-time - foreach($this->timestamps as $time) - { - if ($data[$time]) $data[$time] += $this->tz_offset_s; - } - if ($this->xmlrpc) - { - $data = $this->data2xmlrpc($data); - } - return $data; - } - - /** - * Delete an infolog entry, evtl. incl. it's children / subs - * - * @param int/array $info_id int id or array with keys 'info_id', 'delete_children' and 'new_parent' setting all 3 params - * @param boolean $delete_children should the children be deleted - * @param int/boolean $new_parent parent to use for not deleted children if > 0 - * @return boolean True if delete was successful, False otherwise ($info_id does not exist or no rights) - */ - function delete($info_id,$delete_children=False,$new_parent=False) - { - if (is_array($info_id)) - { - $delete_children = $info_id['delete_children']; - $new_parent = $info_id['new_parent']; - $info_id = (int)(isset($info_id[0]) ? $info_id[0] : (isset($info_id['info_id']) ? $info_id['info_id'] : $info_id['info_id'])); - } - if ($this->so->read($info_id) === False) - { - if ($this->xmlrpc) - { - $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['not_exist'],$GLOBALS['xmlrpcstr']['not_exist']); - } - return False; - } - if (!$this->check_access($info_id,EGW_ACL_DELETE)) - { - if ($this->xmlrpc) - { - $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); - } - return False; - } - - $this->link->unlink(0,'infolog',$info_id); - - $info = $this->read($info_id); - - $this->so->delete($info_id,$delete_children,$new_parent); - - $GLOBALS['egw']->contenthistory->updateTimeStamp('infolog_'.$info['info_type'], $info_id, 'delete', time()); - - return True; - } - - /** - * writes the given $values to InfoLog, a new entry gets created if info_id is not set or 0 - * - * checks and asures ACL - * - * @param array &$values values to write, if contains values for check_defaults and touch_modified, - * they have precedens over the parameters. The - * @param boolean $check_defaults=true check and set certain defaults - * @param boolean $touch_modified=true touch the modification data and sets the modiefier's user-id - * @return int/boolean info_id on a successfull write or false - */ - function write(&$values,$check_defaults=True,$touch_modified=True) - { - //echo "boinfolog::write()values="; _debug_array($values); - // allow to (un)set check_defaults and touch_modified via values, eg. via xmlrpc - foreach(array('check_defaults','touch_modified') as $var) - { - if(isset($values[$var])) - { - $$var = $values[$var]; - unset($values[$var]); - } - } - if ($status_only = $values['info_id'] && !$this->check_access($values['info_id'],EGW_ACL_EDIT)) - { - if (!isset($values['info_responsible'])) - { - if (!($values_read = $this->read($values['info_id']))) return false; - $responsible =& $values_read['info_responsible']; - } - else - { - $responsible =& $values['info_responsible']; - } - $status_only = in_array($this->user, $responsible); // responsible has implicit right to change status - } - if ($values['info_id'] && !$this->check_access($values['info_id'],EGW_ACL_EDIT) && !$status_only || - !$values['info_id'] && $values['info_id_parent'] && !$this->check_access($values['info_id_parent'],EGW_ACL_ADD)) - { - if ($this->xmlrpc) - { - $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); - } - return False; - } - if ($this->xmlrpc) - { - $values = $this->xmlrpc2data($values); - } - if ($status_only) // make sure only status gets writen - { - $set_completed = !$values['info_datecompleted'] && // set date completed of finished job, only if its not already set - (in_array($values['info_status'],array('done','billed','cancelled')) || (int)$values['info_percent'] == 100); - - $backup_values = $values; // to return the full values - $values = array( - 'info_id' => $values['info_id'], - 'info_datemodified' => $values['info_datemodified'], - ); - foreach($this->responsible_edit as $name) - { - if (isset($backup_values[$name])) $values[$name] = $backup_values[$name]; - } - if ($set_completed) - { - $values['info_datecompleted'] = $this->user_time_now; - $values['info_percent'] = '100%'; - if (!in_array($values['info_status'],array('done','billed','cancelled'))) $values['info_status'] = 'done'; - } - $check_defaults = False; - } - if ($check_defaults) - { - if (!$values['info_datecompleted'] && - (in_array($values['info_status'],array('done','billed')) || (int)$values['info_percent'] == 100)) - { - $values['info_datecompleted'] = $this->user_time_now; // set date completed to today if status == done - } - if (in_array($values['info_status'],array('done','billed'))) - { - $values['info_percent'] == '100%'; - } - if ((int)$values['info_percent'] == 100 && !in_array($values['info_status'],array('done','billed','cancelled'))) - { - $values['info_status'] = 'done'; - } - if (count($values['info_responsible']) && $values['info_status'] == 'offer') - { - $values['info_status'] = 'not-started'; // have to match if not finished - } - if (isset($values['info_subject']) && empty($values['info_subject'])) - { - $values['info_subject'] = $this->subject_from_des($values['info_des']); - } - } - if (!$values['info_id'] && !$values['info_owner']) - { - $values['info_owner'] = $this->so->user; - } - if ($info_from_set = ($values['info_link_id'] && isset($values['info_from']) && empty($values['info_from']))) - { - $values['info_from'] = $this->link_id2from($values); - } - if ($touch_modified || !$values['info_datemodified']) - { - // Should only an entry be updated which includes the original modification date? - // Used in the web-GUI to check against a modification by an other user while editing the entry. - // It's now disabled for xmlrpc, as otherwise the xmlrpc code need to be changed! - $check_modified = $values['info_datemodified'] && !$this->xmlrpc ? $values['info_datemodified']-$this->tz_offset_s : false; - $values['info_datemodified'] = $this->user_time_now; - } - if ($touch_modified || !$values['info_modifier']) - { - $values['info_modifier'] = $this->so->user; - } - $to_write = $values; - if ($status_only) $values = array_merge($backup_values,$values); - // convert user- to system-time - foreach($this->timestamps as $time) - { - if ($to_write[$time]) $to_write[$time] -= $this->tz_offset_s; - } - if(($info_id = $this->so->write($to_write,$check_modified))) - { - if (!isset($values['info_type']) || $status_only) - { - $values = $this->read($info_id); - } - if($values['info_id']) - { - // update - $GLOBALS['egw']->contenthistory->updateTimeStamp( - 'infolog_'.$values['info_type'], - $info_id, 'modify', time() - ); - } - else - { - // add - $GLOBALS['egw']->contenthistory->updateTimeStamp( - 'infolog_'.$values['info_type'], - $info_id, 'add', time() - ); - } - $values['info_id'] = $info_id; - - // notify the link-class about the update, as other apps may be subscribt to it - $this->link->notify_update('infolog',$info_id,$values); - } - if ($info_from_set) $values['info_from'] = ''; - - return $info_id; - } - - /** - * Query the number of children / subs - * - * @param int $info_id id - * @return int number of subs - */ - function anzSubs( $info_id ) - { - return $this->so->anzSubs( $info_id ); - } - - /** - * 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 (!) - * @return array with id's as key of the matching log-entries - */ - function &search(&$query) - { - //echo "

boinfolog::search(".print_r($query,True).")

\n"; - $ret = $this->so->search($query); - - // convert system- to user-time - if (is_array($ret) && $this->tz_offset_s) - { - foreach($ret as $id => $data) - { - foreach($this->timestamps as $time) - { - if ($data[$time]) $ret[$id][$time] += $this->tz_offset_s; - } - } - } - if ($this->xmlrpc && is_array($ret)) - { - $infos =& $ret; - unset($ret); - $ret = array(); - foreach($infos as $id => $data) - { - $ret[] = $this->data2xmlrpc($data); - } - } - //echo "

boinfolog::search(".print_r($query,True).")=

".print_r($ret,True)."
\n"; - return $ret; - } - - - /** - * imports a mail identified by uid as infolog - * - * @author Cornelius Weiss - * @todo search if infolog with from and subject allready exists ->appned body & inform user - * @param string $_email_address rfc822 conform emailaddresses - * @param string $_subject - * @param string $_message - * @param array $_attachments - * @param string $_date - * @return array $content array for uiinfolog - */ - function import_mail($_email_address,$_subject,$_message,$_attachments,$_date) - { - $address_array = imap_rfc822_parse_adrlist($_email_address,''); - foreach ((array)$address_array as $address) - { - $email[] = $emailadr = sprintf('%s@%s', - trim($address->mailbox), - trim($address->host)); - $name[] = !empty($address->personal) ? $address->personal : $emailadr; - } - - $info = array( - 'info_id' => 0, - 'info_type' => isset($this->enums['type']['email']) ? 'email' : 'note', - 'info_from' => implode(',',$name), - 'info_addr' => implode(',',$email), - 'info_subject' => $_subject, - 'info_des' => $_message, - 'info_startdate' => $_date, - 'info_status' => 'done', - 'info_priority' => 1, - 'info_percent' => 100, - 'referer' => false, - 'link_to' => array( - 'to_app' => 'infolog', - 'to_id' => 0, - ), - ); - - // find the addressbookentry to link with - $addressbook = CreateObject('addressbook.bocontacts'); - $contacts = array(); - foreach ($email as $mailadr) - { - $contacts = array_merge($contacts,(array)$addressbook->search( - array( - 'email' => $mailadr, - 'email_home' => $mailadr - ),True,'','','',false,'OR',false,null,'',false)); - } - - if (empty($contacts) || empty($contacts[0])) - { - $info['msg'] = lang('Attension: No Contact with address %1 found.',$info['info_addr']); - } - else - { - foreach ((array)$contacts as $contact) - { - if(!is_readable($attachment['tmp_name'])) continue; - $this->link->link('infolog',$info['link_to']['to_id'],'addressbook',$contact['id']); - } - } - - if (is_array($_attachments)) - { - foreach ($_attachments as $attachment) - { - $this->link->link('infolog',$info['link_to']['to_id'],'file',$attachment); - } - } - - return $info; - } - - /** - * Hook called by link-class to include infolog in the appregistry of the linkage - * - * @param array/string $location location and other parameters (not used) - * @return array with method-names - */ - function search_link($location) - { - return array( - 'query' => 'infolog.boinfolog.link_query', - 'title' => 'infolog.boinfolog.link_title', - 'view' => array( - 'menuaction' => 'infolog.uiinfolog.index', - 'action' => 'sp' - ), - 'view_id' => 'action_id', - 'add' => array( - 'menuaction' => 'infolog.uiinfolog.edit', - 'type' => 'task' - ), - 'add_app' => 'action', - 'add_id' => 'action_id', - 'add_popup' => '750x550', - ); - } - - /** - * get title for an infolog entry identified by $info - * - * Is called as hook to participate in the linking - * - * @param int/array $info int info_id or array with infolog entry - * @return string/boolean string with the title, null if $info not found, false if no perms to view - */ - function link_title( $info ) - { - if (!is_array($info)) - { - $info = $this->read( $info,false ); - } - if (!$info) - { - return $info; - } - return !empty($info['info_subject']) ? $info['info_subject'] : - $this->subject_from_des($info['info_descr']); - } - - /** - * query infolog for entries matching $pattern - * - * Is called as hook to participate in the linking - * - * @param string $pattern pattern to search - * @return array with info_id - title pairs of the matching entries - */ - function link_query( $pattern ) - { - $query = array( - 'search' => $pattern, - 'start' => 0, - 'subs' => true, - ); - $ids = $this->search($query); - $content = array(); - if (is_array($ids)) - { - foreach($ids as $id => $info ) - { - $content[$id] = $this->link_title($id); - } - } - return $content; - } - - /** - * hook called be calendar to include events or todos in the cal-dayview - * - * @param int $args[year], $args[month], $args[day] date of the events - * @param int $args[owner] owner of the events - * @param string $args[location] calendar_include_{events|todos} - * @return array of events (array with keys starttime, endtime, title, view, icon, content) - */ - function cal_to_include($args) - { - //echo "

cal_to_include("; print_r($args); echo ")

\n"; - $user = (int) $args['owner']; - if ($user <= 0 && !checkdate($args['month'],$args['day'],$args['year'])) - { - return False; - } - if (!is_object($GLOBALS['egw']->html)) - { - $GLOBALS['egw']->html =& CreateObject('phpgwapi.html'); - } - $GLOBALS['egw']->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' => 'info_startdate', - 'sort' => $do_events ? 'ASC' : 'DESC', - 'filter'=> "user$user".($do_events ? 'date' : 'opentoday').$date_wanted, - 'start' => 0, - ); - while ($infos = $this->search($query)) - { - foreach($infos as $info) - { - $time = (int) adodb_date('Hi',$info['info_startdate']); - $date = adodb_date('Y/m/d',$info['info_startdate']); - /* As event-like infologs are not showen in current calendar, - we need to present all open infologs to the user! (2006-06-27 nelius) - if ($do_events && !$time || - !$do_events && $time && $date == $date_wanted) - { - continue; - }*/ - $title = ($do_events?$GLOBALS['egw']->common->formattime(adodb_date('H',$info['info_startdate']),adodb_date('i',$info['info_startdate'])).' ':''). - $info['info_subject']; - $view = $this->link->view('infolog',$info['info_id']); - $content=array(); - foreach($icons = array( - $info['info_type'] => 'infolog', - $this->status[$info['info_type']][$info['info_status']] => 'infolog', - ) as $name => $app) - { - $content[] = $GLOBALS['egw']->html->image($app,$name,lang($name),'border="0" width="15" height="15"').' '; - } - $content[] = $GLOBALS['egw']->html->a_href($title,$view); - $content = $GLOBALS['egw']->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, - 'icons' => $icons, - 'content' => $content - ); - } - 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; - } - - /** - * handles introspection or discovery by the logged in client, - * in which case the input might be an array. The server always calls - * this function to fill the server dispatch map using a string. - * - * @param string $_type='xmlrpc' xmlrpc or soap - * @return array - */ - function list_methods($_type='xmlrpc') - { - if (is_array($_type)) - { - $_type = $_type['type'] ? $_type['type'] : $_type[0]; - } - - switch($_type) - { - case 'xmlrpc': - $xml_functions = array( - 'read' => array( - 'function' => 'read', - 'signature' => array(array(xmlrpcInt,xmlrpcInt)), - 'docstring' => lang('Read one record by passing its id.') - ), - 'search' => array( - 'function' => 'search', - 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), - 'docstring' => lang('Returns a list / search for records.') - ), - 'write' => array( - 'function' => 'write', - 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), - 'docstring' => lang('Write (add or update) a record by passing its fields.') - ), - 'delete' => array( - 'function' => 'delete', - 'signature' => array(array(xmlrpcInt,xmlrpcInt)), - 'docstring' => lang('Delete one record by passing its id.') - ), - 'categories' => array( - 'function' => 'categories', - 'signature' => array(array(xmlrpcBoolean,xmlrpcBoolean)), - 'docstring' => lang('List all categories') - ), - 'list_methods' => array( - 'function' => 'list_methods', - 'signature' => array(array(xmlrpcStruct,xmlrpcString)), - 'docstring' => lang('Read this list of methods.') - ) - ); - return $xml_functions; - break; - case 'soap': - return $this->soap_functions; - break; - default: - return array(); - break; - } - } - - /** - * Convert an InfoLog entry into its xmlrpc representation, eg. convert timestamps to datetime.iso8601 - * - * @param array $data infolog entry - * @param array xmlrpc infolog entry - */ - function data2xmlrpc($data) - { - $data['rights'] = $this->so->grants[$data['info_owner']]; - - // translate timestamps - if($data['info_enddate'] == 0) unset($data['info_enddate']); - foreach($this->timestamps as $name) - { - if (isset($data[$name])) - { - $data[$name] = $GLOBALS['server']->date2iso8601($data[$name]); - } - } - $ret[$id]['info_percent'] = (int)$data['info_percent'].'%'; - - // translate cat_id - if (isset($data['info_cat'])) - { - $data['info_cat'] = $GLOBALS['server']->cats2xmlrpc(array($data['info_cat'])); - } - foreach($data as $name => $val) - { - if (substr($name,0,5) == 'info_') - { - unset($data[$name]); - $data[substr($name,5)] = $val; - } - } - // unsetting everything which could result in an typeless - foreach($data as $key => $value) - { - if (is_null($value) || is_array($value) && !$value) - { - unset($data[$key]); - } - } - return $data; - } - - /** - * Convert an InfoLog xmlrpc representation into the internal one, eg. convert datetime.iso8601 to timestamps - * - * @param array $data infolog entry - * @param array xmlrpc infolog entry - */ - function xmlrpc2data($data) - { - foreach($data as $name => $val) - { - if (substr($name,0,5) != 'info_') - { - unset($data[$name]); - $data['info_'.$name] = $val; - } - } - // translate timestamps - foreach($this->timestamps as $name) - { - if (isset($data[$name])) - { - $data[$name] = $GLOBALS['server']->iso86012date($data[$name],True); - } - } - // translate cat_id - if (isset($data['info_cat'])) - { - $cats = $GLOBALS['server']->xmlrpc2cats($data['info_cat']); - $data['info_cat'] = (int)$cats[0]; - } - return $data; - } - - /** - * return array with all infolog categories (for xmlrpc) - * - * @param boolean $complete true returns array with all data for each cat, else only the title is returned - * @return array with cat_id / title or data pairs (see above) - */ - function categories($complete = False) - { - return $this->xmlrpc ? $GLOBALS['server']->categories($complete) : False; - } - - /** - * Returm InfoLog (custom) status icons for projectmanager - * - * @param array $args array with id's in $args['infolog'] - * @return array with id => icon pairs - */ - function pm_icons($args) - { - if (isset($args['infolog']) && count($args['infolog'])) - { - $icons = $this->so->get_status($args['infolog']); - foreach((array) $icons as $id => $status) - { - if ($status && substr($status,-1) != '%') - { - $icons[$id] = 'infolog/'.$status; - } - } - } - return $icons; + $this->init(); } } + + /** + * checks if there are customfields for typ $typ + * + * @param string $type + * @param boolean $links=false if true check only customfields containing links, default false = all custom fields + * @return boolean True if there are customfields for $typ, else False + */ + function has_customfields($type,$links=false) + { + if ($links) $link_types = $this->get_customfield_link_types(); + + foreach($this->customfields as $name => $field) + { + if ((!$type || empty($field['type2']) || $field['type2'] == $type) && + (!$links || in_array($field['type'],$link_types))) + { + return True; + } + } + return False; + } + + /** + * Get the customfield types containing links + * + * @return array with customefield types as values + */ + function get_customfield_link_types() + { + static $link_types; + + if (is_null($link_types)) + { + $link_types = array_keys($this->link->app_list()); + $link_types[] = 'link-entry'; + } + return $link_types; + } + + /** + * 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 EGW_ACL_{READ|EDIT|ADD|DELETE} + * @return boolean + */ + function check_access( $info,$required_rights ) + { + static $cache = array(); + + $info_id = is_array($info) ? $info['info_id'] : $info; + + if (isset($cache[$info_id][$required_rights])) + { + return $cache[$info_id][$required_rights]; + } + return $cache[$info_id][$required_rights] = $this->so->check_access( $info,$required_rights,$this->implicit_rights == 'edit' ); + } + + /** + * init internal data to be empty + */ + function init() + { + $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='') + { + //echo "

boinfolog::link_id2from(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 && + ($link = $this->link->get_link($info['info_link_id'])) !== False) + { + $nr = $link['link_app1'] == 'infolog' && $link['link_id1'] == $info['info_id'] ? '2' : '1'; + $title = $this->link->title($link['link_app'.$nr],$link['link_id'.$nr]); + + 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 ($link['link_app'.$nr] == $not_app && $link['link_id'.$nr] == $not_id) + { + return False; + } + $info['info_link'] = array( + 'app' => $link['link_app'.$nr], + 'id' => $link['link_id'.$nr], + 'title' => (!empty($info['info_from']) ? $info['info_from'] : $title), + ); + $info['info_contact'] = $link['link_app'.$nr].':'.$link['link_id'.$nr]; + + //echo " title='$title'

\n"; + return $info['blur_title'] = $title; + } + else + { + $info['info_link'] = array('title' => $info['info_from']); + $info['info_link_id'] = 0; // link might have been deleted + $info['info_custom_from'] = (int)!!$info['info_from']; + } + return False; + } + + /** + * Create a subject from a description: truncate it and add ' ...' + */ + function subject_from_des($des) + { + return substr($des,0,60).' ...'; + } + + /** + * Read an infolog entry specified by $info_id + * + * @param int/array $info_id integer id or array with key 'info_id' of the entry to read + * @param boolean $run_link_id2from=true should link_id2from run, default yes, + * need to be set to false if called from link-title to prevent an infinit recursion + * @return array/boolean infolog entry, null if not found or false if no permission to read it + */ + function &read($info_id,$run_link_id2from=true) + { + if (is_array($info_id)) + { + $info_id = (int) (isset($info_id['info_id']) ? $info_id['info_id'] : $info_id[0]); + } + + if ($this->so->read($info_id) === False) + { + if ($this->xmlrpc) + { + $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['not_exist'],$GLOBALS['xmlrpcstr']['not_exist']); + } + return null; + } + if (!$this->check_access($info_id,EGW_ACL_READ)) // check behind read, to prevent a double read + { + if ($this->xmlrpc) + { + $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); + } + return False; + } + $data = $this->so->data; + + if ($data['info_subject'] == $this->subject_from_des($data['info_des'])) + { + $data['info_subject'] = ''; + } + if ($run_link_id2from) $this->link_id2from($data); + + // convert system- to user-time + foreach($this->timestamps as $time) + { + if ($data[$time]) $data[$time] += $this->tz_offset_s; + } + if ($this->xmlrpc) + { + $data = $this->data2xmlrpc($data); + } + return $data; + } + + /** + * Delete an infolog entry, evtl. incl. it's children / subs + * + * @param int/array $info_id int id or array with keys 'info_id', 'delete_children' and 'new_parent' setting all 3 params + * @param boolean $delete_children should the children be deleted + * @param int/boolean $new_parent parent to use for not deleted children if > 0 + * @return boolean True if delete was successful, False otherwise ($info_id does not exist or no rights) + */ + function delete($info_id,$delete_children=False,$new_parent=False) + { + if (is_array($info_id)) + { + $delete_children = $info_id['delete_children']; + $new_parent = $info_id['new_parent']; + $info_id = (int)(isset($info_id[0]) ? $info_id[0] : (isset($info_id['info_id']) ? $info_id['info_id'] : $info_id['info_id'])); + } + if ($this->so->read($info_id) === False) + { + if ($this->xmlrpc) + { + $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['not_exist'],$GLOBALS['xmlrpcstr']['not_exist']); + } + return False; + } + if (!$this->check_access($info_id,EGW_ACL_DELETE)) + { + if ($this->xmlrpc) + { + $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); + } + return False; + } + + $this->link->unlink(0,'infolog',$info_id); + + $info = $this->read($info_id); + + $this->so->delete($info_id,$delete_children,$new_parent); + + $GLOBALS['egw']->contenthistory->updateTimeStamp('infolog_'.$info['info_type'], $info_id, 'delete', time()); + + return True; + } + + /** + * writes the given $values to InfoLog, a new entry gets created if info_id is not set or 0 + * + * checks and asures ACL + * + * @param array &$values values to write, if contains values for check_defaults and touch_modified, + * they have precedens over the parameters. The + * @param boolean $check_defaults=true check and set certain defaults + * @param boolean $touch_modified=true touch the modification data and sets the modiefier's user-id + * @return int/boolean info_id on a successfull write or false + */ + function write(&$values,$check_defaults=True,$touch_modified=True) + { + //echo "boinfolog::write()values="; _debug_array($values); + // allow to (un)set check_defaults and touch_modified via values, eg. via xmlrpc + foreach(array('check_defaults','touch_modified') as $var) + { + if(isset($values[$var])) + { + $$var = $values[$var]; + unset($values[$var]); + } + } + if ($status_only = $values['info_id'] && !$this->check_access($values['info_id'],EGW_ACL_EDIT)) + { + if (!isset($values['info_responsible'])) + { + if (!($values_read = $this->read($values['info_id']))) return false; + $responsible =& $values_read['info_responsible']; + } + else + { + $responsible =& $values['info_responsible']; + } + $status_only = in_array($this->user, $responsible); // responsible has implicit right to change status + } + if ($values['info_id'] && !$this->check_access($values['info_id'],EGW_ACL_EDIT) && !$status_only || + !$values['info_id'] && $values['info_id_parent'] && !$this->check_access($values['info_id_parent'],EGW_ACL_ADD)) + { + if ($this->xmlrpc) + { + $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); + } + return False; + } + if ($this->xmlrpc) + { + $values = $this->xmlrpc2data($values); + } + if ($status_only) // make sure only status gets writen + { + $set_completed = !$values['info_datecompleted'] && // set date completed of finished job, only if its not already set + (in_array($values['info_status'],array('done','billed','cancelled')) || (int)$values['info_percent'] == 100); + + $backup_values = $values; // to return the full values + $values = array( + 'info_id' => $values['info_id'], + 'info_datemodified' => $values['info_datemodified'], + ); + foreach($this->responsible_edit as $name) + { + if (isset($backup_values[$name])) $values[$name] = $backup_values[$name]; + } + if ($set_completed) + { + $values['info_datecompleted'] = $this->user_time_now; + $values['info_percent'] = '100%'; + if (!in_array($values['info_status'],array('done','billed','cancelled'))) $values['info_status'] = 'done'; + } + $check_defaults = False; + } + if ($check_defaults) + { + if (!$values['info_datecompleted'] && + (in_array($values['info_status'],array('done','billed')) || (int)$values['info_percent'] == 100)) + { + $values['info_datecompleted'] = $this->user_time_now; // set date completed to today if status == done + } + if (in_array($values['info_status'],array('done','billed'))) + { + $values['info_percent'] == '100%'; + } + if ((int)$values['info_percent'] == 100 && !in_array($values['info_status'],array('done','billed','cancelled'))) + { + $values['info_status'] = 'done'; + } + if (count($values['info_responsible']) && $values['info_status'] == 'offer') + { + $values['info_status'] = 'not-started'; // have to match if not finished + } + if (isset($values['info_subject']) && empty($values['info_subject'])) + { + $values['info_subject'] = $this->subject_from_des($values['info_des']); + } + } + if (!$values['info_id'] && !$values['info_owner']) + { + $values['info_owner'] = $this->so->user; + } + if ($info_from_set = ($values['info_link_id'] && isset($values['info_from']) && empty($values['info_from']))) + { + $values['info_from'] = $this->link_id2from($values); + } + if ($touch_modified || !$values['info_datemodified']) + { + // Should only an entry be updated which includes the original modification date? + // Used in the web-GUI to check against a modification by an other user while editing the entry. + // It's now disabled for xmlrpc, as otherwise the xmlrpc code need to be changed! + $check_modified = $values['info_datemodified'] && !$this->xmlrpc ? $values['info_datemodified']-$this->tz_offset_s : false; + $values['info_datemodified'] = $this->user_time_now; + } + if ($touch_modified || !$values['info_modifier']) + { + $values['info_modifier'] = $this->so->user; + } + $to_write = $values; + if ($status_only) $values = array_merge($backup_values,$values); + // convert user- to system-time + foreach($this->timestamps as $time) + { + if ($to_write[$time]) $to_write[$time] -= $this->tz_offset_s; + } + // if we have links in customfields, we need to get the old values, to be able to remove changed links + if ($this->has_customfields($values['info_type'],true) && $values['info_id']) + { + $old = $this->read($values['info_id']); + } + if(($info_id = $this->so->write($to_write,$check_modified))) + { + if (!isset($values['info_type']) || $status_only) + { + $values = $this->read($info_id); + } + if($values['info_id']) + { + // update + $GLOBALS['egw']->contenthistory->updateTimeStamp( + 'infolog_'.$values['info_type'], + $info_id, 'modify', time() + ); + } + else + { + // add + $GLOBALS['egw']->contenthistory->updateTimeStamp( + 'infolog_'.$values['info_type'], + $info_id, 'add', time() + ); + } + $values['info_id'] = $info_id; + + // create (and remove) links in custom fields + $this->update_customfield_links($values,$old); + + // notify the link-class about the update, as other apps may be subscribt to it + $this->link->notify_update('infolog',$info_id,$values); + } + if ($info_from_set) $values['info_from'] = ''; + + return $info_id; + } + + /** + * Check if there are links in the custom fields and update them + * + * @param array $values new values including the custom fields + * @param array $old=null old values before the update, if existing + */ + function update_customfield_links($values,$old=null) + { + $link_types = $this->get_customfield_link_types(); + + foreach($this->customfields as $name => $data) + { + if (!in_array($data['type'],$link_types)) continue; + + // do we have a different old value --> delete that link + if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name]) + { + if ($data['type'] == 'link-entry') + { + list($app,$id) = explode(':',$old['#'.$name]); + } + else + { + $app = $data['type']; + $id = $old['#'.$name]; + } + $this->link->unlink(false,'infolog',$values['info_id'],'',$app,$id); + } + if ($data['type'] == 'link-entry') + { + list($app,$id) = explode(':',$values['#'.$name]); + } + else + { + $app = $data['type']; + $id = $values['#'.$name]; + } + if ($id) // create new link, does nothing for already existing links + { + $this->link->link('infolog',$values['info_id'],$app,$id); + } + } + } + + /** + * Query the number of children / subs + * + * @param int $info_id id + * @return int number of subs + */ + function anzSubs( $info_id ) + { + return $this->so->anzSubs( $info_id ); + } + + /** + * 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 (!) + * @return array with id's as key of the matching log-entries + */ + function &search(&$query) + { + //echo "

boinfolog::search(".print_r($query,True).")

\n"; + $ret = $this->so->search($query); + + // convert system- to user-time + if (is_array($ret) && $this->tz_offset_s) + { + foreach($ret as $id => $data) + { + foreach($this->timestamps as $time) + { + if ($data[$time]) $ret[$id][$time] += $this->tz_offset_s; + } + } + } + if ($this->xmlrpc && is_array($ret)) + { + $infos =& $ret; + unset($ret); + $ret = array(); + foreach($infos as $id => $data) + { + $ret[] = $this->data2xmlrpc($data); + } + } + //echo "

boinfolog::search(".print_r($query,True).")=

".print_r($ret,True)."
\n"; + return $ret; + } + + + /** + * imports a mail identified by uid as infolog + * + * @author Cornelius Weiss + * @todo search if infolog with from and subject allready exists ->appned body & inform user + * @param string $_email_address rfc822 conform emailaddresses + * @param string $_subject + * @param string $_message + * @param array $_attachments + * @param string $_date + * @return array $content array for uiinfolog + */ + function import_mail($_email_address,$_subject,$_message,$_attachments,$_date) + { + $address_array = imap_rfc822_parse_adrlist($_email_address,''); + foreach ((array)$address_array as $address) + { + $email[] = $emailadr = sprintf('%s@%s', + trim($address->mailbox), + trim($address->host)); + $name[] = !empty($address->personal) ? $address->personal : $emailadr; + } + + $info = array( + 'info_id' => 0, + 'info_type' => isset($this->enums['type']['email']) ? 'email' : 'note', + 'info_from' => implode(',',$name), + 'info_addr' => implode(',',$email), + 'info_subject' => $_subject, + 'info_des' => $_message, + 'info_startdate' => $_date, + 'info_status' => 'done', + 'info_priority' => 1, + 'info_percent' => 100, + 'referer' => false, + 'link_to' => array( + 'to_app' => 'infolog', + 'to_id' => 0, + ), + ); + + // find the addressbookentry to link with + $addressbook =& CreateObject('addressbook.bocontacts'); + $contacts = array(); + foreach ($email as $mailadr) + { + $contacts = array_merge($contacts,(array)$addressbook->search( + array( + 'email' => $mailadr, + 'email_home' => $mailadr + ),True,'','','',false,'OR',false,null,'',false)); + } + + if (empty($contacts) || empty($contacts[0])) + { + $info['msg'] = lang('Attension: No Contact with address %1 found.',$info['info_addr']); + } + else + { + foreach ((array)$contacts as $contact) + { + if(!is_readable($attachment['tmp_name'])) continue; + $this->link->link('infolog',$info['link_to']['to_id'],'addressbook',$contact['id']); + } + } + + if (is_array($_attachments)) + { + foreach ($_attachments as $attachment) + { + $this->link->link('infolog',$info['link_to']['to_id'],'file',$attachment); + } + } + + return $info; + } + + /** + * Hook called by link-class to include infolog in the appregistry of the linkage + * + * @param array/string $location location and other parameters (not used) + * @return array with method-names + */ + function search_link($location) + { + return array( + 'query' => 'infolog.boinfolog.link_query', + 'title' => 'infolog.boinfolog.link_title', + 'view' => array( + 'menuaction' => 'infolog.uiinfolog.index', + 'action' => 'sp' + ), + 'view_id' => 'action_id', + 'add' => array( + 'menuaction' => 'infolog.uiinfolog.edit', + 'type' => 'task' + ), + 'add_app' => 'action', + 'add_id' => 'action_id', + 'add_popup' => '750x550', + ); + } + + /** + * get title for an infolog entry identified by $info + * + * Is called as hook to participate in the linking + * + * @param int/array $info int info_id or array with infolog entry + * @return string/boolean string with the title, null if $info not found, false if no perms to view + */ + function link_title( $info ) + { + if (!is_array($info)) + { + $info = $this->read( $info,false ); + } + if (!$info) + { + return $info; + } + return !empty($info['info_subject']) ? $info['info_subject'] : + $this->subject_from_des($info['info_descr']); + } + + /** + * query infolog for entries matching $pattern + * + * Is called as hook to participate in the linking + * + * @param string $pattern pattern to search + * @return array with info_id - title pairs of the matching entries + */ + function link_query( $pattern ) + { + $query = array( + 'search' => $pattern, + 'start' => 0, + 'subs' => true, + ); + $ids = $this->search($query); + $content = array(); + if (is_array($ids)) + { + foreach($ids as $id => $info ) + { + $content[$id] = $this->link_title($id); + } + } + return $content; + } + + /** + * hook called be calendar to include events or todos in the cal-dayview + * + * @param int $args[year], $args[month], $args[day] date of the events + * @param int $args[owner] owner of the events + * @param string $args[location] calendar_include_{events|todos} + * @return array of events (array with keys starttime, endtime, title, view, icon, content) + */ + function cal_to_include($args) + { + //echo "

cal_to_include("; print_r($args); echo ")

\n"; + $user = (int) $args['owner']; + if ($user <= 0 && !checkdate($args['month'],$args['day'],$args['year'])) + { + return False; + } + if (!is_object($GLOBALS['egw']->html)) + { + $GLOBALS['egw']->html =& CreateObject('phpgwapi.html'); + } + $GLOBALS['egw']->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' => 'info_startdate', + 'sort' => $do_events ? 'ASC' : 'DESC', + 'filter'=> "user$user".($do_events ? 'date' : 'opentoday').$date_wanted, + 'start' => 0, + ); + while ($infos = $this->search($query)) + { + foreach($infos as $info) + { + $time = (int) adodb_date('Hi',$info['info_startdate']); + $date = adodb_date('Y/m/d',$info['info_startdate']); + /* As event-like infologs are not showen in current calendar, + we need to present all open infologs to the user! (2006-06-27 nelius) + if ($do_events && !$time || + !$do_events && $time && $date == $date_wanted) + { + continue; + }*/ + $title = ($do_events?$GLOBALS['egw']->common->formattime(adodb_date('H',$info['info_startdate']),adodb_date('i',$info['info_startdate'])).' ':''). + $info['info_subject']; + $view = $this->link->view('infolog',$info['info_id']); + $content=array(); + foreach($icons = array( + $info['info_type'] => 'infolog', + $this->status[$info['info_type']][$info['info_status']] => 'infolog', + ) as $name => $app) + { + $content[] = $GLOBALS['egw']->html->image($app,$name,lang($name),'border="0" width="15" height="15"').' '; + } + $content[] = $GLOBALS['egw']->html->a_href($title,$view); + $content = $GLOBALS['egw']->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, + 'icons' => $icons, + 'content' => $content + ); + } + 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; + } + + /** + * handles introspection or discovery by the logged in client, + * in which case the input might be an array. The server always calls + * this function to fill the server dispatch map using a string. + * + * @param string $_type='xmlrpc' xmlrpc or soap + * @return array + */ + function list_methods($_type='xmlrpc') + { + if (is_array($_type)) + { + $_type = $_type['type'] ? $_type['type'] : $_type[0]; + } + + switch($_type) + { + case 'xmlrpc': + $xml_functions = array( + 'read' => array( + 'function' => 'read', + 'signature' => array(array(xmlrpcInt,xmlrpcInt)), + 'docstring' => lang('Read one record by passing its id.') + ), + 'search' => array( + 'function' => 'search', + 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), + 'docstring' => lang('Returns a list / search for records.') + ), + 'write' => array( + 'function' => 'write', + 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), + 'docstring' => lang('Write (add or update) a record by passing its fields.') + ), + 'delete' => array( + 'function' => 'delete', + 'signature' => array(array(xmlrpcInt,xmlrpcInt)), + 'docstring' => lang('Delete one record by passing its id.') + ), + 'categories' => array( + 'function' => 'categories', + 'signature' => array(array(xmlrpcBoolean,xmlrpcBoolean)), + 'docstring' => lang('List all categories') + ), + 'list_methods' => array( + 'function' => 'list_methods', + 'signature' => array(array(xmlrpcStruct,xmlrpcString)), + 'docstring' => lang('Read this list of methods.') + ) + ); + return $xml_functions; + break; + case 'soap': + return $this->soap_functions; + break; + default: + return array(); + break; + } + } + + /** + * Convert an InfoLog entry into its xmlrpc representation, eg. convert timestamps to datetime.iso8601 + * + * @param array $data infolog entry + * @param array xmlrpc infolog entry + */ + function data2xmlrpc($data) + { + $data['rights'] = $this->so->grants[$data['info_owner']]; + + // translate timestamps + if($data['info_enddate'] == 0) unset($data['info_enddate']); + foreach($this->timestamps as $name) + { + if (isset($data[$name])) + { + $data[$name] = $GLOBALS['server']->date2iso8601($data[$name]); + } + } + $ret[$id]['info_percent'] = (int)$data['info_percent'].'%'; + + // translate cat_id + if (isset($data['info_cat'])) + { + $data['info_cat'] = $GLOBALS['server']->cats2xmlrpc(array($data['info_cat'])); + } + foreach($data as $name => $val) + { + if (substr($name,0,5) == 'info_') + { + unset($data[$name]); + $data[substr($name,5)] = $val; + } + } + // unsetting everything which could result in an typeless + foreach($data as $key => $value) + { + if (is_null($value) || is_array($value) && !$value) + { + unset($data[$key]); + } + } + return $data; + } + + /** + * Convert an InfoLog xmlrpc representation into the internal one, eg. convert datetime.iso8601 to timestamps + * + * @param array $data infolog entry + * @param array xmlrpc infolog entry + */ + function xmlrpc2data($data) + { + foreach($data as $name => $val) + { + if (substr($name,0,5) != 'info_') + { + unset($data[$name]); + $data['info_'.$name] = $val; + } + } + // translate timestamps + foreach($this->timestamps as $name) + { + if (isset($data[$name])) + { + $data[$name] = $GLOBALS['server']->iso86012date($data[$name],True); + } + } + // translate cat_id + if (isset($data['info_cat'])) + { + $cats = $GLOBALS['server']->xmlrpc2cats($data['info_cat']); + $data['info_cat'] = (int)$cats[0]; + } + return $data; + } + + /** + * return array with all infolog categories (for xmlrpc) + * + * @param boolean $complete true returns array with all data for each cat, else only the title is returned + * @return array with cat_id / title or data pairs (see above) + */ + function categories($complete = False) + { + return $this->xmlrpc ? $GLOBALS['server']->categories($complete) : False; + } + + /** + * Returm InfoLog (custom) status icons for projectmanager + * + * @param array $args array with id's in $args['infolog'] + * @return array with id => icon pairs + */ + function pm_icons($args) + { + if (isset($args['infolog']) && count($args['infolog'])) + { + $icons = $this->so->get_status($args['infolog']); + foreach((array) $icons as $id => $status) + { + if ($status && substr($status,-1) != '%') + { + $icons[$id] = 'infolog/'.$status; + } + } + } + return $icons; + } +} diff --git a/infolog/inc/class.soinfolog.inc.php b/infolog/inc/class.soinfolog.inc.php index 8e1388e458..ee8ff34467 100644 --- a/infolog/inc/class.soinfolog.inc.php +++ b/infolog/inc/class.soinfolog.inc.php @@ -1,614 +1,611 @@ * - * originaly based on todo written by Joseph Engo * - * -------------------------------------------- * - * This program is free software; you can redistribute it and/or modify it * - * under the terms of the GNU General Public License as published by the * - * Free Software Foundation; either version 2 of the License, or (at your * - * option) any later version. * - \**************************************************************************/ +/** + * InfoLog - Storage object + * + * @link http://www.egroupware.org + * @author Ralf Becker + * @package infolog + * @copyright (c) 2003-6 by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - /* $Id$ */ +include_once(EGW_API_INC.'/class.solink.inc.php'); - include_once(EGW_API_INC.'/class.solink.inc.php'); +/** + * storage object / db-layer for InfoLog + * + * all values passed to this class are run either through intval or addslashes to prevent query-insertion + * and for pgSql 7.3 compatibility + * + * @package infolog + * @author Ralf Becker + * @copyright (c) by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + */ +class soinfolog // DB-Layer +{ + var $db; + var $grants; + var $data = array( ); + var $user; + var $info_table = 'egw_infolog'; + var $extra_table = 'egw_infolog_extra'; /** - * storage object / db-layer for InfoLog - * - * all values passed to this class are run either through intval or addslashes to prevent query-insertion - * and for pgSql 7.3 compatibility - * - * @package infolog - * @author Ralf Becker - * @copyright (c) by Ralf Becker - * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * constructor */ - class soinfolog // DB-Layer + function soinfolog( $info_id = 0) { - var $db; - var $grants; - var $data = array( ); - var $user; - var $info_table = 'egw_infolog'; - var $extra_table = 'egw_infolog_extra'; + $this->db = clone($GLOBALS['egw']->db); + $this->db->set_app('infolog'); + $this->grants = $GLOBALS['egw']->acl->get_grants('infolog'); + $this->user = $GLOBALS['egw_info']['user']['account_id']; - /** - * constructor - */ - function soinfolog( $info_id = 0) - { - $this->db = clone($GLOBALS['egw']->db); - $this->db->set_app('infolog'); - $this->grants = $GLOBALS['egw']->acl->get_grants('infolog'); - $this->user = $GLOBALS['egw_info']['user']['account_id']; + $this->links =& new solink(); - $this->links =& new solink(); + $this->tz_offset = $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; - $this->tz_offset = $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; - - $this->read( $info_id ); - } - - /** - * checks if user has the $required_rights to access $info_id (private access is handled too) - * - * @param array/int $info data or info_id of InfoLog entry - * @param int $required_rights EGW_ACL_xyz anded together - * @param boolean $implicit_edit=false responsible has only implicit read and add rigths, unless this is set to true - * @return boolean True if access is granted else False - */ - function check_access( $info,$required_rights,$implicit_edit=false ) - { - if (is_array($info)) - { - - } - elseif ((int) $info != $this->data['info_id']) // already loaded? - { - // dont change our own internal data, - // dont use new as it changes $phpgw->db - $private_info = $this; - $info = $private_info->read($info); - } - else - { - $info = $this->data; - } - if (!$info) - { - return False; - } - $owner = $info['info_owner']; - - $access_ok = $owner == $this->user || // user has all rights - // ACL only on public entrys || $owner granted _PRIVATE - (!!($this->grants[$owner] & $required_rights) || - // implicite rights for responsible user(s) - in_array($this->user, $info['info_responsible']) && ($required_rights == EGW_ACL_READ || $required_rights == EGW_ACL_ADD || $implicit_edit && $required_rights == EGW_ACL_EDIT)) && - //$info['info_responsible'] == $this->user && $required_rights == EGW_ACL_READ) && - ($info['info_access'] == 'public' || - !!($this->grants[$owner] & EGW_ACL_PRIVATE)); - - //echo "

check_access(info_id=$info_id (owner=$owner, user=$user),required_rights=$required_rights): access".($access_ok?"Ok":"Denied")."

\n"; - return $access_ok; - } - - /** - * generate sql to be AND'ed into a query to ensure ACL is respected (incl. _PRIVATE) - * - * @param $filter: none|all - list all entrys user have rights to see
- * private|own - list only his personal entrys (incl. those he is responsible for !!!), my = entries the user is responsible for - * @return string the necesary sql - */ - function aclFilter($filter = False) - { - preg_match('/(my|own|privat|all|none|user)([0-9]*)/',$filter_was=$filter,$vars); - $filter = $vars[1]; - $f_user = intval($vars[2]); - - if (isset($this->acl_filter[$filter.$f_user])) - { - return $this->acl_filter[$filter.$f_user]; // used cached filter if found - } - if (is_array($this->grants)) - { - foreach($this->grants as $user => $grant) - { - // echo "

grants: user=$user, grant=$grant

"; - if ($grant & (EGW_ACL_READ|EGW_ACL_EDIT)) - { - $public_user_list[] = $user; - } - if ($grant & EGW_ACL_PRIVATE) - { - $private_user_list[] = $user; - } - } - if (count($private_user_list)) - { - $has_private_access = 'info_owner IN ('.implode(',',$private_user_list).')'; - } - } - $filtermethod = " (info_owner=$this->user"; // user has all rights - - if ($filter == 'my') - { - $filtermethod .= " AND info_responsible='0'"; - } - // implicit read-rights for responsible user - $filtermethod .= " OR (".$this->db->concat("','",'info_responsible',"','")." LIKE '%,$this->user,%' AND info_access='public')"; - - // private: own entries plus the one user is responsible for - if ($filter == 'private' || $filter == 'own') - { - $filtermethod .= " OR (".$this->db->concat("','",'info_responsible',"','")." LIKE '%,$this->user,%'". - ($filter == 'own' && count($public_user_list) ? // offer's should show up in own, eg. startpage, but need read-access - " OR info_status = 'offer' AND info_owner IN(" . implode(',',$public_user_list) . ')' : '').")". - " AND (info_access='public'".($has_private_access?" OR $has_private_access":'').')'; - } - elseif ($filter != 'my') // none --> all entrys user has rights to see - { - if ($has_private_access) - { - $filtermethod .= " OR $has_private_access"; - } - if (count($public_user_list)) - { - $filtermethod .= " OR (info_access='public' AND info_owner IN(" . implode(',',$public_user_list) . '))'; - } - } - $filtermethod .= ') '; - - if ($filter == 'user' && $f_user > 0) - { - $filtermethod = " ((info_owner=$f_user AND info_responsible=0 OR ".$this->db->concat("','",'info_responsible',"','")." LIKE '%,$f_user,%') AND $filtermethod)"; - } - //echo "

aclFilter(filter='$filter_was',user='$user') = '$filtermethod', privat_user_list=".print_r($privat_user_list,True).", public_user_list=".print_r($public_user_list,True)."

\n"; - - return $this->acl_filter[$filter.$f_user] = $filtermethod; // cache the filter - } - - /** - * generate sql to filter based on the status of the log-entry - * - * @param $filter done = done or billed, open = not ()done or billed), offer = offer - * @return string the necesary sql - */ - function statusFilter($filter = '') - { - preg_match('/(done|open|offer)/',$filter,$vars); - $filter = $vars[1]; - - switch ($filter) - { - case 'done': return " AND info_status IN ('done','billed','cancelled')"; - case 'open': return " AND NOT (info_status IN ('done','billed','cancelled'))"; - case 'offer': return " AND info_status = 'offer'"; - } - return ''; - } - - /** - * generate sql to filter based on the start- and enddate of the log-entry - * - * @param $filter upcoming = startdate is in the future
- * today startdate < tomorrow
- * overdue enddate < tomorrow
- * limitYYYY/MM/DD not older or open - * @return string the necesary sql - */ - function dateFilter($filter = '') - { - preg_match('/(upcoming|today|overdue|date)([-\\/.0-9]*)/',$filter,$vars); - $filter = $vars[1]; - - if (isset($vars[2]) && !empty($vars[2]) && ($date = split('[-/.]',$vars[2]))) - { - $today = mktime(-$this->tz_offset,0,0,intval($date[1]),intval($date[2]),intval($date[0])); - $tomorrow = mktime(-$this->tz_offset,0,0,intval($date[1]),intval($date[2])+1,intval($date[0])); - } - else - { - $now = getdate(time()-60*60*$this->tz_offset); - $tomorrow = mktime(-$this->tz_offset,0,0,$now['mon'],$now['mday']+1,$now['year']); - } - switch ($filter) - { - case 'upcoming': - return " AND info_startdate >= '$tomorrow'"; - case 'today': - return " AND info_startdate < '$tomorrow'"; - case 'overdue': - return " AND (info_enddate != 0 AND info_enddate < '$tomorrow')"; - case 'date': - if (!$today || !$tomorrow) - { - return ''; - } - return " AND ($today <= info_startdate AND info_startdate < $tomorrow)"; - case 'limit': - return " AND (info_modified >= '$today' OR NOT (info_status IN ('done','billed','cancelled')))"; - } - return ''; - } - - /** - * initialise the internal $this->data to be empty - * - * only non-empty values got initialised - */ - function init() - { - $this->data = array( - 'info_owner' => $this->user, - 'info_priority' => 1, - 'info_responsible' => array(), - ); - } - - /** - * read InfoLog entry $info_id - * - * some cacheing is done to prevent multiple reads of the same entry - * - * @param $info_id id of log-entry - * @return array/boolean the entry as array or False on error (eg. entry not found) - */ - function read($info_id) // did _not_ ensure ACL - { - $info_id = (int) $info_id; - - if ($info_id && $info_id == $this->data['info_id']) - { - return $this->data; // return the already read entry - } - if ($info_id <= 0 || !$this->db->select($this->info_table,'*',array('info_id'=>$info_id),__LINE__,__FILE__) || - !(($this->data = $this->db->row(true)))) - { - $this->init( ); - return False; - } - if (!is_array($this->data['info_responsible'])) - { - $this->data['info_responsible'] = $this->data['info_responsible'] ? explode(',',$this->data['info_responsible']) : array(); - } - $this->db->select($this->extra_table,'info_extra_name,info_extra_value',array('info_id'=>$info_id),__LINE__,__FILE__); - while ($this->db->next_record()) - { - $this->data['#'.$this->db->f(0)] = $this->db->f(1); - } - return $this->data; - } - - /** - * Read the status of the given infolog-ids - * - * @param array $ids array with id's - * @return array with id => status pairs - */ - function get_status($ids) - { - $this->db->select($this->info_table,'info_id,info_type,info_status,info_percent',array('info_id'=>$ids),__LINE__,__FILE__); - while (($info = $this->db->row(true))) - { - switch ($info['info_type'].'-'.$info['info_status']) - { - case 'phone-not-started': - $status = 'call'; - break; - case 'phone-ongoing': - $status = 'will-call'; - break; - default: - $status = $info['info_status'] == 'ongoing' ? $info['info_percent'].'%' : $info['info_status']; - } - $stati[$info['info_id']] = $status; - } - return $stati; - } - - /** - * delete InfoLog entry $info_id AND the links to it - * - * @param int $info_id id of log-entry - * @param bool $delete_children delete the children, if not set there parent-id to $new_parent - * @param int $new_parent new parent-id to set for subs - */ - function delete($info_id,$delete_children=True,$new_parent=0) // did _not_ ensure ACL - { - //echo "

soinfolog::delete($info_id,'$delete_children',$new_parent)

\n"; - if ((int) $info_id <= 0) - { - return; - } - $this->db->delete($this->info_table,array('info_id'=>$info_id),__LINE__,__FILE__); - $this->db->delete($this->extra_table,array('info_id'=>$info_id),__LINE__,__FILE__); - $this->links->unlink(0,'infolog',$info_id); - - if ($this->data['info_id'] == $info_id) - { - $this->init( ); - } - // delete children, if they are owned by the user - if ($delete_children) - { - $db2 = clone($this->db); // we need an extra result-set - $db2->select($this->info_table,'info_id',array( - 'info_id_parent' => $info_id, - 'info_owner' => $this->user, - ),__LINE__,__FILE__); - while ($db2->next_record()) - { - $this->delete($db2->f(0),$delete_children); - } - } - // set parent_id to $new_parent or 0 for all not deleted children - $this->db->update($this->info_table,array('info_id_parent'=>$new_parent),array('info_id_parent'=>$info_id),__LINE__,__FILE__); - } - - /** - * changes or deletes entries with a spezified owner (for hook_delete_account) - * - * @param $owner old owner - * @param $new_owner new owner or 0 if entries should be deleted - */ - function change_delete_owner($owner,$new_owner=0) // new_owner=0 means delete - { - if (!(int) $new_owner) - { - $db2 = clone($this->db); // we need an extra result-set - $db2->select($this->info_table,'info_id',array('info_owner'=>$owner),__LINE__,__FILE__); - while($db2->next_record()) - { - $this->delete($this->db->f(0),False); - } - } - else - { - $this->db->update($this->info_table,array('info_owner'=>$new_owner),array('info_owner'=>$owner),__LINE__,__FILE__); - } - $this->db->update($this->info_table,array('info_responsible'=>$new_owner),array('info_responsible'=>$owner),__LINE__,__FILE__); - } - - /** - * writes the given $values to InfoLog, a new entry gets created if info_id is not set or 0 - * - * @param array $values with the data of the log-entry - * @param int $check_modified=0 old modification date to check before update (include in WHERE) - * @return int/boolean info_id, false on error or 0 if the entry has been updated in the meantime - */ - function write($values,$check_modified=0) // did _not_ ensure ACL - { - //echo "soinfolog::write(,$check_modified) values="; _debug_array($values); - $info_id = (int) $values['info_id']; - - if (array_key_exists('info_responsible',$values)) // isset($values['info_responsible']) returns false for NULL! - { - $values['info_responsible'] = $values['info_responsible'] ? implode(',',$values['info_responsible']) : '0'; - } - $table_def = $this->db->get_table_definitions('infolog',$this->info_table); - $to_write = array(); - foreach($values as $key => $val) - { - if ($key != 'info_id' && isset($table_def['fd'][$key])) - { - $to_write[$key] = $this->data[$key] = $val; // update internal data - } - } - if (($this->data['info_id'] = $info_id)) - { - $where = array('info_id' => $info_id); - if ($check_modified) $where['info_datemodified'] = $check_modified; - if (!$this->db->update($this->info_table,$to_write,$where,__LINE__,__FILE__)) - { - return false; // Error - } - if ($this->db->affected_rows() < 1) return 0; // someone else updated the modtime or deleted the entry - } - else - { - if (!isset($to_write['info_id_parent'])) $to_write['info_id_parent'] = 0; // must not be null - - $this->db->insert($this->info_table,$to_write,false,__LINE__,__FILE__); - $info_id = $this->data['info_id'] = $this->db->get_last_insert_id($this->info_table,'info_id'); - } - //echo "

soinfolog.write values= "; _debug_array($values); - - // write customfields now - foreach($values as $key => $val) - { - if ($key[0] != '#') - { - continue; // no customfield - } - $this->data[$key] = $val; // update internal data - - $this->db->insert($this->extra_table,array( - 'info_extra_value'=>$val - ),array( - 'info_id' => $info_id, - 'info_extra_name' => substr($key,1), - ),__LINE__,__FILE__); - } - // echo "

soinfolog.write this->data= "; _debug_array($this->data); - - return $this->data['info_id']; - } - - /** - * count the sub-entries of $info_id - * - * This is done now be search too (in key info_anz_subs), if DB can use sub-queries - * - * @param $info_id id of log-entry - * @return int the number of sub-entries - */ - function anzSubs( $info_id ) - { - if (($info_id = intval($info_id)) <= 0) - { - return 0; - } - $this->db->select($this->info_table,'count(*)',array( - 'info_id_parent' => $info_id, - $this->aclFilter() - ),__LINE__,__FILE__); - - $this->db->next_record(); - //echo "

anzSubs($info_id) = ".$this->db->f(0)." ($sql)

\n"; - return $this->db->f(0); - } - - /** - * searches InfoLog for a certain pattern in $query - * - * If DB can use sub-queries, the number of subs are under the key info_anz_subs. - * - * @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 $query[subs] boolean return subs or not, if unset the user preference is used - * @param $query[num_rows] number of rows to return if $query[start] is set, default is to use the value from the general prefs - * @return array with id's as key of the matching log-entries - */ - function search(&$query) - { - //echo "

soinfolog.search(".print_r($query,True).")

\n"; - $action2app = array( - 'addr' => 'addressbook', - 'proj' => 'projects', - 'event' => 'calendar' - ); - $action = isset($action2app[$query['action']]) ? $action2app[$query['action']] : $query['action']; - - if ($action != '') - { - $links = $this->links->get_links($action=='sp'?'infolog':$action,$query['action_id'],'infolog'); - - if (count($links)) - { - $link_extra = ($action == 'sp' ? 'OR' : 'AND')." main.info_id IN (".implode(',',$links).')'; - } - } - if (!empty($query['order']) && eregi('^[a-z_0-9, ]+$',$query['order']) && (empty($query['sort']) || eregi('^(DESC|ASC)$',$query['sort']))) - { - $order = array(); - foreach(explode(',',$query['order']) as $val) - { - $val = trim($val); - $val = (substr($val,0,5) != 'info_' ? 'info_' : '').$val; - if ($val == 'info_des' && $this->db->capabilities['order_on_text'] !== true) - { - if (!$this->db->capabilities['order_on_text']) continue; - - $val = sprintf($this->db->capabilities['order_on_text'],$val); - } - $order[] = $val; - } - $ordermethod = 'ORDER BY ' . implode(',',$order) . ' ' . $query['sort']; - } - else - { - $ordermethod = 'ORDER BY info_datemodified DESC'; // newest first - } - $acl_filter = $filtermethod = $this->aclFilter($query['filter']); - $filtermethod .= $this->statusFilter($query['filter']); - $filtermethod .= $this->dateFilter($query['filter']); - - if (is_array($query['col_filter'])) - { - foreach($query['col_filter'] as $col => $data) - { - if (substr($col,0,5) != 'info_') $col = 'info_'.$col; - if (!empty($data) && eregi('^[a-z_0-9]+$',$col)) - { - if ($col == 'info_responsible') - { - $data = (int) $data; - if (!$data) continue; - $filtermethod .= " AND (".$this->db->concat("','",'info_responsible',"','")." LIKE '%,$data,%' OR info_responsible='0' AND info_owner=$data)"; - } - else - { - if (!$this->table_defs) $this->table_defs = $this->db->get_table_definitions('infolog',$this->info_table); - $filtermethod .= ' AND '.$col.'='.$this->db->quote($data,$this->table_defs['fd'][$col]['type']); - } - } - } - } - //echo "

filtermethod='$filtermethod'

"; - - if ((int)$query['cat_id']) - { - //$filtermethod .= ' AND info_cat='.intval($query['cat_id']).' '; - if (!is_object($GLOBALS['egw']->categories)) - { - $GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories'); - } - $cats = $GLOBALS['egw']->categories->return_all_children((int)$query['cat_id']); - $filtermethod .= ' AND info_cat'.(count($cats)>1? ' IN ('.implode(',',$cats).') ' : '='.(int)$query['cat_id']); - } - $join = $distinct = $count_subs = ''; - if ($query['query']) $query['search'] = $query['query']; // allow both names - if ($query['search']) // we search in _from, _subject, _des and _extra_value for $query - { - $pattern = $this->db->quote('%'.$query['search'].'%'); - - $columns = array('info_from','info_addr','info_location','info_subject','info_extra_value'); - // at the moment MaxDB 7.5 cant cast nor search text columns, it's suppost to change in 7.6 - if ($this->db->capabilities['like_on_text']) $columns[] = 'info_des'; - - $sql_query = 'AND ('.(is_numeric($query['search']) ? 'main.info_id='.(int)$query['search'].' OR ' : ''). - implode(" LIKE $pattern OR ",$columns)." LIKE $pattern) "; - $join = "LEFT JOIN $this->extra_table ON main.info_id=$this->extra_table.info_id"; - // mssql and others cant use DISTICT if text columns (info_des) are involved - $distinct = $this->db->capabilities['distinct_on_text'] ? 'DISTINCT' : ''; - } - $pid = 'AND info_id_parent='.($action == 'sp' ? $query['action_id'] : 0); - - if (!$GLOBALS['egw_info']['user']['preferences']['infolog']['listNoSubs'] && - $action != 'sp' || isset($query['subs']) && $query['subs']) - { - $pid = ''; - } - $ids = array( ); - if ($action == '' || $action == 'sp' || count($links)) - { - $sql_query = "FROM $this->info_table main $join WHERE ($filtermethod $pid $sql_query) $link_extra"; - - $this->db->query($sql="SELECT $distinct main.info_id ".$sql_query,__LINE__,__FILE__); - $query['total'] = $this->db->num_rows(); - - if (isset($query['start']) && $query['start'] > $query['total']) - { - $query['start'] = 0; - } - if ($this->db->capabilities['sub_queries']) - { - $count_subs = ",(SELECT count(*) FROM $this->info_table sub WHERE sub.info_id_parent=main.info_id AND $acl_filter) AS info_anz_subs"; - } - $this->db->query($sql="SELECT $distinct main.* $count_subs $sql_query $ordermethod",__LINE__,__FILE__, - (int) $query['start'],isset($query['start']) ? (int) $query['num_rows'] : -1); - //echo "

db::query('$sql',,,".(int)$query['start'].','.(isset($query['start']) ? (int) $query['num_rows'] : -1).")

\n"; - while (($info =& $this->db->row(true))) - { - $info['info_responsible'] = $info['info_responsible'] ? explode(',',$info['info_responsible']) : array(); - - $ids[$info['info_id']] = $info; - } - } - else - { - $query['start'] = $query['total'] = 0; - } - return $ids; - } + $this->read( $info_id ); } + + /** + * checks if user has the $required_rights to access $info_id (private access is handled too) + * + * @param array/int $info data or info_id of InfoLog entry + * @param int $required_rights EGW_ACL_xyz anded together + * @param boolean $implicit_edit=false responsible has only implicit read and add rigths, unless this is set to true + * @return boolean True if access is granted else False + */ + function check_access( $info,$required_rights,$implicit_edit=false ) + { + if (is_array($info)) + { + + } + elseif ((int) $info != $this->data['info_id']) // already loaded? + { + // dont change our own internal data, + // dont use new as it changes $phpgw->db + $private_info = $this; + $info = $private_info->read($info); + } + else + { + $info = $this->data; + } + if (!$info) + { + return False; + } + $owner = $info['info_owner']; + + $access_ok = $owner == $this->user || // user has all rights + // ACL only on public entrys || $owner granted _PRIVATE + (!!($this->grants[$owner] & $required_rights) || + // implicite rights for responsible user(s) + in_array($this->user, $info['info_responsible']) && ($required_rights == EGW_ACL_READ || $required_rights == EGW_ACL_ADD || $implicit_edit && $required_rights == EGW_ACL_EDIT)) && + //$info['info_responsible'] == $this->user && $required_rights == EGW_ACL_READ) && + ($info['info_access'] == 'public' || + !!($this->grants[$owner] & EGW_ACL_PRIVATE)); + + //echo "

check_access(info_id=$info_id (owner=$owner, user=$user),required_rights=$required_rights): access".($access_ok?"Ok":"Denied")."

\n"; + return $access_ok; + } + + /** + * generate sql to be AND'ed into a query to ensure ACL is respected (incl. _PRIVATE) + * + * @param $filter: none|all - list all entrys user have rights to see
+ * private|own - list only his personal entrys (incl. those he is responsible for !!!), my = entries the user is responsible for + * @return string the necesary sql + */ + function aclFilter($filter = False) + { + preg_match('/(my|own|privat|all|none|user)([0-9]*)/',$filter_was=$filter,$vars); + $filter = $vars[1]; + $f_user = intval($vars[2]); + + if (isset($this->acl_filter[$filter.$f_user])) + { + return $this->acl_filter[$filter.$f_user]; // used cached filter if found + } + if (is_array($this->grants)) + { + foreach($this->grants as $user => $grant) + { + // echo "

grants: user=$user, grant=$grant

"; + if ($grant & (EGW_ACL_READ|EGW_ACL_EDIT)) + { + $public_user_list[] = $user; + } + if ($grant & EGW_ACL_PRIVATE) + { + $private_user_list[] = $user; + } + } + if (count($private_user_list)) + { + $has_private_access = 'info_owner IN ('.implode(',',$private_user_list).')'; + } + } + $filtermethod = " (info_owner=$this->user"; // user has all rights + + if ($filter == 'my') + { + $filtermethod .= " AND info_responsible='0'"; + } + // implicit read-rights for responsible user + $filtermethod .= " OR (".$this->db->concat("','",'info_responsible',"','")." LIKE '%,$this->user,%' AND info_access='public')"; + + // private: own entries plus the one user is responsible for + if ($filter == 'private' || $filter == 'own') + { + $filtermethod .= " OR (".$this->db->concat("','",'info_responsible',"','")." LIKE '%,$this->user,%'". + ($filter == 'own' && count($public_user_list) ? // offer's should show up in own, eg. startpage, but need read-access + " OR info_status = 'offer' AND info_owner IN(" . implode(',',$public_user_list) . ')' : '').")". + " AND (info_access='public'".($has_private_access?" OR $has_private_access":'').')'; + } + elseif ($filter != 'my') // none --> all entrys user has rights to see + { + if ($has_private_access) + { + $filtermethod .= " OR $has_private_access"; + } + if (count($public_user_list)) + { + $filtermethod .= " OR (info_access='public' AND info_owner IN(" . implode(',',$public_user_list) . '))'; + } + } + $filtermethod .= ') '; + + if ($filter == 'user' && $f_user > 0) + { + $filtermethod = " ((info_owner=$f_user AND info_responsible=0 OR ".$this->db->concat("','",'info_responsible',"','")." LIKE '%,$f_user,%') AND $filtermethod)"; + } + //echo "

aclFilter(filter='$filter_was',user='$user') = '$filtermethod', privat_user_list=".print_r($privat_user_list,True).", public_user_list=".print_r($public_user_list,True)."

\n"; + + return $this->acl_filter[$filter.$f_user] = $filtermethod; // cache the filter + } + + /** + * generate sql to filter based on the status of the log-entry + * + * @param $filter done = done or billed, open = not ()done or billed), offer = offer + * @return string the necesary sql + */ + function statusFilter($filter = '') + { + preg_match('/(done|open|offer)/',$filter,$vars); + $filter = $vars[1]; + + switch ($filter) + { + case 'done': return " AND info_status IN ('done','billed','cancelled')"; + case 'open': return " AND NOT (info_status IN ('done','billed','cancelled'))"; + case 'offer': return " AND info_status = 'offer'"; + } + return ''; + } + + /** + * generate sql to filter based on the start- and enddate of the log-entry + * + * @param $filter upcoming = startdate is in the future
+ * today startdate < tomorrow
+ * overdue enddate < tomorrow
+ * limitYYYY/MM/DD not older or open + * @return string the necesary sql + */ + function dateFilter($filter = '') + { + preg_match('/(upcoming|today|overdue|date)([-\\/.0-9]*)/',$filter,$vars); + $filter = $vars[1]; + + if (isset($vars[2]) && !empty($vars[2]) && ($date = split('[-/.]',$vars[2]))) + { + $today = mktime(-$this->tz_offset,0,0,intval($date[1]),intval($date[2]),intval($date[0])); + $tomorrow = mktime(-$this->tz_offset,0,0,intval($date[1]),intval($date[2])+1,intval($date[0])); + } + else + { + $now = getdate(time()-60*60*$this->tz_offset); + $tomorrow = mktime(-$this->tz_offset,0,0,$now['mon'],$now['mday']+1,$now['year']); + } + switch ($filter) + { + case 'upcoming': + return " AND info_startdate >= '$tomorrow'"; + case 'today': + return " AND info_startdate < '$tomorrow'"; + case 'overdue': + return " AND (info_enddate != 0 AND info_enddate < '$tomorrow')"; + case 'date': + if (!$today || !$tomorrow) + { + return ''; + } + return " AND ($today <= info_startdate AND info_startdate < $tomorrow)"; + case 'limit': + return " AND (info_modified >= '$today' OR NOT (info_status IN ('done','billed','cancelled')))"; + } + return ''; + } + + /** + * initialise the internal $this->data to be empty + * + * only non-empty values got initialised + */ + function init() + { + $this->data = array( + 'info_owner' => $this->user, + 'info_priority' => 1, + 'info_responsible' => array(), + ); + } + + /** + * read InfoLog entry $info_id + * + * some cacheing is done to prevent multiple reads of the same entry + * + * @param $info_id id of log-entry + * @return array/boolean the entry as array or False on error (eg. entry not found) + */ + function read($info_id) // did _not_ ensure ACL + { + $info_id = (int) $info_id; + + if ($info_id && $info_id == $this->data['info_id']) + { + return $this->data; // return the already read entry + } + if ($info_id <= 0 || !$this->db->select($this->info_table,'*',array('info_id'=>$info_id),__LINE__,__FILE__) || + !(($this->data = $this->db->row(true)))) + { + $this->init( ); + return False; + } + if (!is_array($this->data['info_responsible'])) + { + $this->data['info_responsible'] = $this->data['info_responsible'] ? explode(',',$this->data['info_responsible']) : array(); + } + $this->db->select($this->extra_table,'info_extra_name,info_extra_value',array('info_id'=>$info_id),__LINE__,__FILE__); + while ($this->db->next_record()) + { + $this->data['#'.$this->db->f(0)] = $this->db->f(1); + } + return $this->data; + } + + /** + * Read the status of the given infolog-ids + * + * @param array $ids array with id's + * @return array with id => status pairs + */ + function get_status($ids) + { + $this->db->select($this->info_table,'info_id,info_type,info_status,info_percent',array('info_id'=>$ids),__LINE__,__FILE__); + while (($info = $this->db->row(true))) + { + switch ($info['info_type'].'-'.$info['info_status']) + { + case 'phone-not-started': + $status = 'call'; + break; + case 'phone-ongoing': + $status = 'will-call'; + break; + default: + $status = $info['info_status'] == 'ongoing' ? $info['info_percent'].'%' : $info['info_status']; + } + $stati[$info['info_id']] = $status; + } + return $stati; + } + + /** + * delete InfoLog entry $info_id AND the links to it + * + * @param int $info_id id of log-entry + * @param bool $delete_children delete the children, if not set there parent-id to $new_parent + * @param int $new_parent new parent-id to set for subs + */ + function delete($info_id,$delete_children=True,$new_parent=0) // did _not_ ensure ACL + { + //echo "

soinfolog::delete($info_id,'$delete_children',$new_parent)

\n"; + if ((int) $info_id <= 0) + { + return; + } + $this->db->delete($this->info_table,array('info_id'=>$info_id),__LINE__,__FILE__); + $this->db->delete($this->extra_table,array('info_id'=>$info_id),__LINE__,__FILE__); + $this->links->unlink(0,'infolog',$info_id); + + if ($this->data['info_id'] == $info_id) + { + $this->init( ); + } + // delete children, if they are owned by the user + if ($delete_children) + { + $db2 = clone($this->db); // we need an extra result-set + $db2->select($this->info_table,'info_id',array( + 'info_id_parent' => $info_id, + 'info_owner' => $this->user, + ),__LINE__,__FILE__); + while ($db2->next_record()) + { + $this->delete($db2->f(0),$delete_children); + } + } + // set parent_id to $new_parent or 0 for all not deleted children + $this->db->update($this->info_table,array('info_id_parent'=>$new_parent),array('info_id_parent'=>$info_id),__LINE__,__FILE__); + } + + /** + * changes or deletes entries with a spezified owner (for hook_delete_account) + * + * @param $owner old owner + * @param $new_owner new owner or 0 if entries should be deleted + */ + function change_delete_owner($owner,$new_owner=0) // new_owner=0 means delete + { + if (!(int) $new_owner) + { + $db2 = clone($this->db); // we need an extra result-set + $db2->select($this->info_table,'info_id',array('info_owner'=>$owner),__LINE__,__FILE__); + while($db2->next_record()) + { + $this->delete($this->db->f(0),False); + } + } + else + { + $this->db->update($this->info_table,array('info_owner'=>$new_owner),array('info_owner'=>$owner),__LINE__,__FILE__); + } + $this->db->update($this->info_table,array('info_responsible'=>$new_owner),array('info_responsible'=>$owner),__LINE__,__FILE__); + } + + /** + * writes the given $values to InfoLog, a new entry gets created if info_id is not set or 0 + * + * @param array $values with the data of the log-entry + * @param int $check_modified=0 old modification date to check before update (include in WHERE) + * @return int/boolean info_id, false on error or 0 if the entry has been updated in the meantime + */ + function write($values,$check_modified=0) // did _not_ ensure ACL + { + //echo "soinfolog::write(,$check_modified) values="; _debug_array($values); + $info_id = (int) $values['info_id']; + + if (array_key_exists('info_responsible',$values)) // isset($values['info_responsible']) returns false for NULL! + { + $values['info_responsible'] = $values['info_responsible'] ? implode(',',$values['info_responsible']) : '0'; + } + $table_def = $this->db->get_table_definitions('infolog',$this->info_table); + $to_write = array(); + foreach($values as $key => $val) + { + if ($key != 'info_id' && isset($table_def['fd'][$key])) + { + $to_write[$key] = $this->data[$key] = $val; // update internal data + } + } + if (($this->data['info_id'] = $info_id)) + { + $where = array('info_id' => $info_id); + if ($check_modified) $where['info_datemodified'] = $check_modified; + if (!$this->db->update($this->info_table,$to_write,$where,__LINE__,__FILE__)) + { + return false; // Error + } + if ($this->db->affected_rows() < 1) return 0; // someone else updated the modtime or deleted the entry + } + else + { + if (!isset($to_write['info_id_parent'])) $to_write['info_id_parent'] = 0; // must not be null + + $this->db->insert($this->info_table,$to_write,false,__LINE__,__FILE__); + $info_id = $this->data['info_id'] = $this->db->get_last_insert_id($this->info_table,'info_id'); + } + //echo "

soinfolog.write values= "; _debug_array($values); + + // write customfields now + foreach($values as $key => $val) + { + if ($key[0] != '#') + { + continue; // no customfield + } + $this->data[$key] = $val; // update internal data + + $this->db->insert($this->extra_table,array( + 'info_extra_value'=>$val + ),array( + 'info_id' => $info_id, + 'info_extra_name' => substr($key,1), + ),__LINE__,__FILE__); + } + // echo "

soinfolog.write this->data= "; _debug_array($this->data); + + return $this->data['info_id']; + } + + /** + * count the sub-entries of $info_id + * + * This is done now be search too (in key info_anz_subs), if DB can use sub-queries + * + * @param $info_id id of log-entry + * @return int the number of sub-entries + */ + function anzSubs( $info_id ) + { + if (($info_id = intval($info_id)) <= 0) + { + return 0; + } + $this->db->select($this->info_table,'count(*)',array( + 'info_id_parent' => $info_id, + $this->aclFilter() + ),__LINE__,__FILE__); + + $this->db->next_record(); + //echo "

anzSubs($info_id) = ".$this->db->f(0)." ($sql)

\n"; + return $this->db->f(0); + } + + /** + * searches InfoLog for a certain pattern in $query + * + * If DB can use sub-queries, the number of subs are under the key info_anz_subs. + * + * @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 $query[subs] boolean return subs or not, if unset the user preference is used + * @param $query[num_rows] number of rows to return if $query[start] is set, default is to use the value from the general prefs + * @return array with id's as key of the matching log-entries + */ + function search(&$query) + { + //echo "

soinfolog.search(".print_r($query,True).")

\n"; + $action2app = array( + 'addr' => 'addressbook', + 'proj' => 'projects', + 'event' => 'calendar' + ); + $action = isset($action2app[$query['action']]) ? $action2app[$query['action']] : $query['action']; + + if ($action != '') + { + $links = $this->links->get_links($action=='sp'?'infolog':$action,$query['action_id'],'infolog'); + + if (count($links)) + { + $link_extra = ($action == 'sp' ? 'OR' : 'AND')." main.info_id IN (".implode(',',$links).')'; + } + } + if (!empty($query['order']) && eregi('^[a-z_0-9, ]+$',$query['order']) && (empty($query['sort']) || eregi('^(DESC|ASC)$',$query['sort']))) + { + $order = array(); + foreach(explode(',',$query['order']) as $val) + { + $val = trim($val); + $val = (substr($val,0,5) != 'info_' ? 'info_' : '').$val; + if ($val == 'info_des' && $this->db->capabilities['order_on_text'] !== true) + { + if (!$this->db->capabilities['order_on_text']) continue; + + $val = sprintf($this->db->capabilities['order_on_text'],$val); + } + $order[] = $val; + } + $ordermethod = 'ORDER BY ' . implode(',',$order) . ' ' . $query['sort']; + } + else + { + $ordermethod = 'ORDER BY info_datemodified DESC'; // newest first + } + $acl_filter = $filtermethod = $this->aclFilter($query['filter']); + $filtermethod .= $this->statusFilter($query['filter']); + $filtermethod .= $this->dateFilter($query['filter']); + + if (is_array($query['col_filter'])) + { + foreach($query['col_filter'] as $col => $data) + { + if (substr($col,0,5) != 'info_') $col = 'info_'.$col; + if (!empty($data) && eregi('^[a-z_0-9]+$',$col)) + { + if ($col == 'info_responsible') + { + $data = (int) $data; + if (!$data) continue; + $filtermethod .= " AND (".$this->db->concat("','",'info_responsible',"','")." LIKE '%,$data,%' OR info_responsible='0' AND info_owner=$data)"; + } + else + { + if (!$this->table_defs) $this->table_defs = $this->db->get_table_definitions('infolog',$this->info_table); + $filtermethod .= ' AND '.$col.'='.$this->db->quote($data,$this->table_defs['fd'][$col]['type']); + } + } + } + } + //echo "

filtermethod='$filtermethod'

"; + + if ((int)$query['cat_id']) + { + //$filtermethod .= ' AND info_cat='.intval($query['cat_id']).' '; + if (!is_object($GLOBALS['egw']->categories)) + { + $GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories'); + } + $cats = $GLOBALS['egw']->categories->return_all_children((int)$query['cat_id']); + $filtermethod .= ' AND info_cat'.(count($cats)>1? ' IN ('.implode(',',$cats).') ' : '='.(int)$query['cat_id']); + } + $join = $distinct = $count_subs = ''; + if ($query['query']) $query['search'] = $query['query']; // allow both names + if ($query['search']) // we search in _from, _subject, _des and _extra_value for $query + { + $pattern = $this->db->quote('%'.$query['search'].'%'); + + $columns = array('info_from','info_addr','info_location','info_subject','info_extra_value'); + // at the moment MaxDB 7.5 cant cast nor search text columns, it's suppost to change in 7.6 + if ($this->db->capabilities['like_on_text']) $columns[] = 'info_des'; + + $sql_query = 'AND ('.(is_numeric($query['search']) ? 'main.info_id='.(int)$query['search'].' OR ' : ''). + implode(" LIKE $pattern OR ",$columns)." LIKE $pattern) "; + $join = "LEFT JOIN $this->extra_table ON main.info_id=$this->extra_table.info_id"; + // mssql and others cant use DISTICT if text columns (info_des) are involved + $distinct = $this->db->capabilities['distinct_on_text'] ? 'DISTINCT' : ''; + } + $pid = 'AND info_id_parent='.($action == 'sp' ? $query['action_id'] : 0); + + if (!$GLOBALS['egw_info']['user']['preferences']['infolog']['listNoSubs'] && + $action != 'sp' || isset($query['subs']) && $query['subs']) + { + $pid = ''; + } + $ids = array( ); + if ($action == '' || $action == 'sp' || count($links)) + { + $sql_query = "FROM $this->info_table main $join WHERE ($filtermethod $pid $sql_query) $link_extra"; + + $this->db->query($sql="SELECT $distinct main.info_id ".$sql_query,__LINE__,__FILE__); + $query['total'] = $this->db->num_rows(); + + if (isset($query['start']) && $query['start'] > $query['total']) + { + $query['start'] = 0; + } + if ($this->db->capabilities['sub_queries']) + { + $count_subs = ",(SELECT count(*) FROM $this->info_table sub WHERE sub.info_id_parent=main.info_id AND $acl_filter) AS info_anz_subs"; + } + $this->db->query($sql="SELECT $distinct main.* $count_subs $sql_query $ordermethod",__LINE__,__FILE__, + (int) $query['start'],isset($query['start']) ? (int) $query['num_rows'] : -1); + //echo "

db::query('$sql',,,".(int)$query['start'].','.(isset($query['start']) ? (int) $query['num_rows'] : -1).")

\n"; + while (($info =& $this->db->row(true))) + { + $info['info_responsible'] = $info['info_responsible'] ? explode(',',$info['info_responsible']) : array(); + + $ids[$info['info_id']] = $info; + } + } + else + { + $query['start'] = $query['total'] = 0; + } + return $ids; + } +} diff --git a/infolog/inc/class.uicustomfields.inc.php b/infolog/inc/class.uicustomfields.inc.php index 1b09b4736b..37b2b1f297 100644 --- a/infolog/inc/class.uicustomfields.inc.php +++ b/infolog/inc/class.uicustomfields.inc.php @@ -1,345 +1,376 @@ * - * -------------------------------------------- * - * This program is free software; you can redistribute it and/or modify it * - * under the terms of the GNU General Public License as published by the * - * Free Software Foundation; either version 2 of the License, or (at your * - * option) any later version. * - \**************************************************************************/ +/** + * InfoLog - Custome fields + * + * @link http://www.egroupware.org + * @author Ralf Becker + * @package infolog + * @copyright (c) 2003-6 by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - /* $Id$ */ +/** + * Administration of custom fields, type and status + */ +class uicustomfields +{ + var $public_functions = array( + 'edit' => True + ); + /** + * Customfield types, without the link app-names + * + * @var array + */ + var $cf_types = array( + 'text' => 'Text', + 'label' => 'Label', + 'select' => 'Selectbox', + 'radio' => 'Radiobutton', + 'checkbox' => 'Checkbox', + 'link-entry' => 'Select an entry', + ); + /** + * Instance of the infolog BO class + * + * @var boinfolog + */ + var $bo; + /** + * Instance of the etemplate class + * + * @var etemplate + */ + var $tmpl; + /** + * instance of the config class for infolog + * + * @var config + */ + var $config; + + function uicustomfields( ) + { + $this->bo =& CreateObject('infolog.boinfolog'); + $this->tmpl =& CreateObject('etemplate.etemplate'); + $this->types = &$this->bo->enums['type']; + $this->status = &$this->bo->status; + $this->config = &$this->bo->config; + $this->fields = &$this->bo->customfields; + + $GLOBALS['egw']->translation->add_app('etemplate'); + foreach($this->cf_types as $name => $label) $this->cf_types[$name] = lang($label); + $link_types = $this->bo->link->app_list(); + ksort($link_types); + foreach($link_types as $name => $label) $this->cf_types[$name] = '- '.$label; + } /** - * Administration of custom fields, type and status + * Edit/Create an InfoLog Custom fields, typ and status * - * @package infolog - * @author Ralf Becker - * @copyright (c) by Ralf Becker - * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @param array $content Content from the eTemplate Exec */ - class uicustomfields + function edit($content=null) { - var $public_functions = array - ( - 'edit' => True - ); - - function uicustomfields( ) + $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Custom fields, typ and status'); + if (is_array($content)) { - $this->bo =& CreateObject('infolog.boinfolog'); - $this->tmpl =& CreateObject('etemplate.etemplate'); - $this->types = &$this->bo->enums['type']; - $this->status = &$this->bo->status; - $this->config = &$this->bo->config; - $this->fields = &$this->bo->customfields; - } - - /** - * Edit/Create an InfoLog Custom fields, typ and status - * - * @param array $content Content from the eTemplate Exec - */ - function edit($content=null) - { - $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Custom fields, typ and status'); - if (is_array($content)) + //echo '
'; print_r($content); echo "
\n"; + list($action) = @each($content['button']); + switch($action) { - //echo '
'; print_r($content); echo "
\n"; - list($action) = @each($content['button']); - switch($action) - { - case 'create': - $this->create($content); - break; - case 'delete': - $this->delete($content); - break; - default: - if (!$content['status']['create'] && !$content['status']['delete'] && - !$content['fields']['create'] && !$content['fields']['delete']) - { - break; // typ change - } - case 'save': - case 'apply': - $this->update($content); - if ($action != 'save') - { - break; - } - case 'cancel': - $GLOBALS['egw']->redirect_link('/admin/'); - exit; - } - } - else - { - list($typ) = each($this->types); - $content = array( - 'typ' => $typ, - ); - } - $readonlys = array(); - $readonlys['button[delete]'] = isset($this->bo->stock_enums['type'][$content['typ']]); - - $content['status'] = array( - 'default' => $this->status['defaults'][$content['typ']] - ); - $n = 0; - foreach($this->status[$content['typ']] as $name => $label) - { - $content['status'][++$n] = array( - 'name' => $name, - 'label' => $label, - 'disabled' => False - ); - $preserv_status[$n]['old_name'] = $name; - if (isset($this->bo->stock_status[$content['typ']][$name])) - { - $readonlys['status']["delete[$name]"] = - $readonlys['status'][$n.'[name]'] = True; - } - $readonlys['status']["create$name"] = True; - } - $content['status'][++$n] = array('name'=>''); // new line for create - $readonlys['status']["delete[]"] = True; - - //echo 'customfields=
'; print_r($this->fields); echo "
\n"; - $content['fields'] = array(); - $n = 0; - foreach($this->fields as $name => $data) - { - if (is_array($data['values'])) - { - $values = ''; - foreach($data['values'] as $var => $value) + case 'create': + $this->create($content); + break; + case 'delete': + $this->delete($content); + break; + default: + if (!$content['status']['create'] && !$content['status']['delete'] && + !$content['fields']['create'] && !$content['fields']['delete']) { - $values .= (!empty($values) ? "\n" : '').$var.'='.$value; + break; // typ change } - $data['values'] = $values; - } - $content['fields'][++$n] = $data + array( - 'name' => $name - ); - $preserv_fields[$n]['old_name'] = $name; - $readonlys['fields']["create$name"] = True; + case 'save': + case 'apply': + $this->update($content); + if ($action != 'save') + { + break; + } + case 'cancel': + $GLOBALS['egw']->redirect_link('/admin/'); + exit; } - $content['fields'][++$n] = array('typ'=>'','order' => 10 * $n); // new line for create - $readonlys['fields']["delete[]"] = True; + } + else + { + list($typ) = each($this->types); + $content = array( + 'type2' => $typ, + ); + } + $readonlys = array(); + $readonlys['button[delete]'] = isset($this->bo->stock_enums['type'][$content['type2']]); - //echo '

uicustomfields.edit(content =

'; print_r($content); echo "
\n"; - //echo 'readonlys =
'; print_r($readonlys); echo "
\n"; - $this->tmpl->read('infolog.customfields'); - $this->tmpl->exec('infolog.uicustomfields.edit',$content,array( - 'typ' => $this->types, - ),$readonlys,array( - 'status' => $preserv_status, - 'fields' => $preserv_fields - )); + $content['status'] = array( + 'default' => $this->status['defaults'][$content['type2']] + ); + $n = 0; + foreach($this->status[$content['type2']] as $name => $label) + { + $content['status'][++$n] = array( + 'name' => $name, + 'label' => $label, + 'disabled' => False + ); + $preserv_status[$n]['old_name'] = $name; + if (isset($this->bo->stock_status[$content['type2']][$name])) + { + $readonlys['status']["delete[$name]"] = + $readonlys['status'][$n.'[name]'] = True; + } + $readonlys['status']["create$name"] = True; + } + $content['status'][++$n] = array('name'=>''); // new line for create + $readonlys['status']["delete[]"] = True; + + //echo 'customfields=
'; print_r($this->fields); echo "
\n"; + $content['fields'] = array(); + $n = 0; + foreach($this->fields as $name => $field) + { + if (is_array($field['values'])) + { + $values = ''; + foreach($field['values'] as $var => $value) + { + $values .= (!empty($values) ? "\n" : '').$var.'='.$value; + } + $field['values'] = $values; + } + $content['fields'][++$n] = $field + array( + 'name' => $name + ); + $preserv_fields[$n]['old_name'] = $name; + $readonlys['fields']["create$name"] = True; + } + $content['fields'][++$n] = array('type2'=>'','order' => 10 * $n); // new line for create + $readonlys['fields']["delete[]"] = True; + + //echo '

uicustomfields.edit(content =

'; print_r($content); echo "
\n"; + //echo 'readonlys =
'; print_r($readonlys); echo "
\n"; + $this->tmpl->read('infolog.customfields'); + $this->tmpl->exec('infolog.uicustomfields.edit',$content,array( + 'type2' => $this->types, + 'type' => $this->cf_types, + ),$readonlys,array( + 'status' => $preserv_status, + 'fields' => $preserv_fields, + )); + } + + function update_fields(&$content) + { + $typ = $content['type2']; + $fields = &$content['fields']; + + $create = $fields['create']; + unset($fields['create']); + + if ($fields['delete']) + { + list($delete) = each($fields['delete']); + unset($fields['delete']); } - function update_fields(&$content) + foreach($fields as $field) { - $typ = $content['typ']; - $fields = &$content['fields']; + $name = trim($field['name']); + $old_name = $field['old_name']; - $create = $fields['create']; - unset($fields['create']); - - if ($fields['delete']) + if (!empty($delete) && $delete == $old_name) { - list($delete) = each($fields['delete']); - unset($fields['delete']); + unset($this->fields[$old_name]); + continue; } - - foreach($fields as $field) + if (isset($field['name']) && empty($name) && ($create || !empty($old_name))) // empty name not allowed { - $name = trim($field['name']); - $old_name = $field['old_name']; - - if (!empty($delete) && $delete == $old_name) + $content['error_msg'] = lang('Name must not be empty !!!'); + } + if (isset($field['old_name'])) + { + if (!empty($name) && $old_name != $name) // renamed { unset($this->fields[$old_name]); - continue; } - if (isset($field['name']) && empty($name) && ($create || !empty($old_name))) // empty name not allowed + elseif (empty($name)) { - $content['error_msg'] = lang('Name must not be empty !!!'); - } - if (isset($field['old_name'])) - { - if (!empty($name) && $old_name != $name) // renamed - { - unset($this->fields[$old_name]); - } - elseif (empty($name)) - { - $name = $old_name; - } - } - elseif (empty($name)) // new item and empty ==> ignore it - { - continue; - } - $values = array(); - if (!empty($field['values'])) - { - foreach(explode("\n",$field['values']) as $line) - { - list($var,$value) = split('=',trim($line),2); - $var = trim($var); - $values[$var] = empty($value) ? $var : $value; - } - } - $this->fields[$name] = array( - 'typ' => $field['typ'], - 'label' => empty($field['label']) ? $name : $field['label'], - 'help' => $field['help'], - 'values'=> $values, - 'len' => $field['len'], - 'rows' => intval($field['rows']), - 'order' => intval($field['order']) - ); - } - if (!function_exists('sort_by_order')) - { - function sort_by_order($arr1,$arr2) - { - return $arr1['order'] - $arr2['order']; + $name = $old_name; } } - uasort($this->fields,sort_by_order); - - $n = 0; - foreach($this->fields as $name => $data) + elseif (empty($name)) // new item and empty ==> ignore it { - $this->fields[$name]['order'] = ($n += 10); + continue; + } + $values = array(); + if (!empty($field['values'])) + { + foreach(explode("\n",$field['values']) as $line) + { + list($var,$value) = split('=',trim($line),2); + $var = trim($var); + $values[$var] = empty($value) ? $var : $value; + } + } + $this->fields[$name] = array( + 'type2' => $field['type2'], + 'type' => $field['type'], + 'label' => empty($field['label']) ? $name : $field['label'], + 'help' => $field['help'], + 'values'=> $values, + 'len' => $field['len'], + 'rows' => (int)$field['rows'], + 'order' => (int)$field['order'], + ); + } + if (!function_exists('sort_by_order')) + { + function sort_by_order($arr1,$arr2) + { + return $arr1['order'] - $arr2['order']; } } + uasort($this->fields,sort_by_order); - function update_status(&$content) + $n = 0; + foreach($this->fields as $name => $data) { - $typ = $content['typ']; - $status = &$content['status']; - - $default = $status['default']; - unset($status['default']); - - $create = $status['create']; - unset($status['create']); - - if ($status['delete']) - { - list($delete) = each($status['delete']); - unset($status['delete']); - } - - foreach($status as $stat) - { - $name = trim($stat['name']); - $old_name = $stat['old_name']; - - if (!empty($delete) && $delete == $old_name) - { - unset($this->status[$typ][$old_name]); - continue; - } - if (isset($stat['name']) && empty($name) && ($create || !empty($old_name))) // empty name not allowed - { - $content['error_msg'] = lang('Name must not be empty !!!'); - } - if (isset($stat['old_name'])) - { - if (!empty($name) && $old_name != $name) // renamed - { - unset($this->status[$typ][$old_name]); - - if ($default == $old_name) - { - $default = $name; - } - } - elseif (empty($name)) - { - $name = $old_name; - } - } - elseif (empty($name)) // new item and empty ==> ignore it - { - continue; - } - $this->status[$typ][$name] = empty($stat['label']) ? $name : $stat['label']; - } - $this->status['defaults'][$typ] = empty($default) ? $name : $default; - if (!isset($this->status[$typ][$this->status['defaults'][$typ]])) - { - list($this->status['defaults'][$typ]) = @each($this->status[$typ]); - } - } - - function update(&$content) - { - $this->update_status($content); - $this->update_fields($content); - - // save changes to repository - $this->save_repository(); - } - - function delete(&$content) - { - if (isset($this->bo->stock_enums['type'][$content['typ']])) - { - $content['error_msg'] .= lang("You can't delete one of the stock types !!!"); - return; - } - unset($this->types[$content['typ']]); - unset($this->status[$content['typ']]); - unset($this->status['defaults'][$content['typ']]); - $content['typ'] = ''; - - // save changes to repository - $this->save_repository(); - } - - function create(&$content) - { - $new_name = trim($content['new_name']); - unset($content['new_name']); - if (empty($new_name) || isset($this->types[$new_name])) - { - $content['error_msg'] .= empty($new_name) ? - lang('You have to enter a name, to create a new typ!!!') : - lang("Typ '%1' already exists !!!",$new_name); - } - else - { - $this->types[$new_name] = $new_name; - $this->status[$new_name] = array( - 'ongoing' => 'ongoing', - 'done' => 'done' - ); - $this->status['defaults'][$new_name] = 'ongoing'; - - // save changes to repository - $this->save_repository(); - - $content['typ'] = $new_name; // show the new entry - } - } - - function save_repository() - { - // save changes to repository - $this->config->value('types',$this->types); - //echo '

uicustomfields::save_repository() \$this->status=

'; print_r($this->status); echo "
\n"; - $this->config->value('status',$this->status); - //echo '

uicustomfields::save_repository() \$this->fields=

'; print_r($this->fields); echo "
\n"; - $this->config->value('customfields',$this->fields); - - $this->config->save_repository(); + $this->fields[$name]['order'] = ($n += 10); } } + + function update_status(&$content) + { + $typ = $content['type2']; + $status = &$content['status']; + + $default = $status['default']; + unset($status['default']); + + $create = $status['create']; + unset($status['create']); + + if ($status['delete']) + { + list($delete) = each($status['delete']); + unset($status['delete']); + } + + foreach($status as $stat) + { + $name = trim($stat['name']); + $old_name = $stat['old_name']; + + if (!empty($delete) && $delete == $old_name) + { + unset($this->status[$typ][$old_name]); + continue; + } + if (isset($stat['name']) && empty($name) && ($create || !empty($old_name))) // empty name not allowed + { + $content['error_msg'] = lang('Name must not be empty !!!'); + } + if (isset($stat['old_name'])) + { + if (!empty($name) && $old_name != $name) // renamed + { + unset($this->status[$typ][$old_name]); + + if ($default == $old_name) + { + $default = $name; + } + } + elseif (empty($name)) + { + $name = $old_name; + } + } + elseif (empty($name)) // new item and empty ==> ignore it + { + continue; + } + $this->status[$typ][$name] = empty($stat['label']) ? $name : $stat['label']; + } + $this->status['defaults'][$typ] = empty($default) ? $name : $default; + if (!isset($this->status[$typ][$this->status['defaults'][$typ]])) + { + list($this->status['defaults'][$typ]) = @each($this->status[$typ]); + } + } + + function update(&$content) + { + $this->update_status($content); + $this->update_fields($content); + + // save changes to repository + $this->save_repository(); + } + + function delete(&$content) + { + if (isset($this->bo->stock_enums['type'][$content['type2']])) + { + $content['error_msg'] .= lang("You can't delete one of the stock types !!!"); + return; + } + unset($this->types[$content['type2']]); + unset($this->status[$content['type2']]); + unset($this->status['defaults'][$content['type2']]); + list($content['type2']) = each($this->types); + + // save changes to repository + $this->save_repository(); + } + + function create(&$content) + { + $new_name = trim($content['new_name']); + unset($content['new_name']); + if (empty($new_name) || isset($this->types[$new_name])) + { + $content['error_msg'] .= empty($new_name) ? + lang('You have to enter a name, to create a new typ!!!') : + lang("Typ '%1' already exists !!!",$new_name); + } + else + { + $this->types[$new_name] = $new_name; + $this->status[$new_name] = array( + 'ongoing' => 'ongoing', + 'done' => 'done' + ); + $this->status['defaults'][$new_name] = 'ongoing'; + + // save changes to repository + $this->save_repository(); + + $content['type2'] = $new_name; // show the new entry + } + } + + function save_repository() + { + // save changes to repository + $this->config->value('types',$this->types); + //echo '

uicustomfields::save_repository() \$this->status=

'; print_r($this->status); echo "
\n"; + $this->config->value('status',$this->status); + //echo '

uicustomfields::save_repository() \$this->fields=

'; print_r($this->fields); echo "
\n"; + $this->config->value('customfields',$this->fields); + + $this->config->save_repository(); + } +} diff --git a/infolog/inc/class.uiinfolog.inc.php b/infolog/inc/class.uiinfolog.inc.php index f1f7ee9f03..cec33e8640 100644 --- a/infolog/inc/class.uiinfolog.inc.php +++ b/infolog/inc/class.uiinfolog.inc.php @@ -1,1252 +1,1252 @@ * - * originaly based on todo written by Joseph Engo * - * -------------------------------------------- * - * This program is free software; you can redistribute it and/or modify it * - * under the terms of the GNU General Public License as published by the * - * Free Software Foundation; either version 2 of the License, or (at your * - * option) any later version. * - \**************************************************************************/ +/** + * InfoLog - User interface + * + * @link http://www.egroupware.org + * @author Ralf Becker + * @package infolog + * @copyright (c) 2003-6 by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - /* $Id$ */ +include_once(EGW_INCLUDE_ROOT.'/infolog/inc/class.boinfolog.inc.php'); - include_once(EGW_INCLUDE_ROOT.'/infolog/inc/class.boinfolog.inc.php'); +/** + * This class is the UI-layer (user interface) of InfoLog + */ +class uiinfolog +{ + var $public_functions = array + ( + 'index' => True, + 'edit' => True, + 'delete' => True, + 'close' => True, + 'admin' => True, + 'hook_view' => True, + 'writeLangFile' => True, + 'import_mail' => True, + ); + /** + * reference to the infolog preferences of the user + * + * @var array + */ + var $prefs; + /** + * instance of the bo-class + * + * @var boinfolog + */ + var $bo; + /** + * reference to instance of the link-class of bo + * + * @var bolink + */ + var $link; + /** + * instance of the etemplate class + * + * @var etemplate + */ + var $tmpl; + /** + * reference to the html object of etemplate + * + * @var html + */ + var $html; + /** + * allowed units and hours per day, can be overwritten by the projectmanager configuration, default all units, 8h + * + * @var string + */ + var $duration_format = ','; // comma is necessary! + + var $icons = array( + 'type' => array( + 'task' => 'task.gif', 'task_alt' => 'Task', + 'phone' => 'phone.gif', 'phone_alt' => 'Phonecall', + 'note' => 'note.gif', 'note_alt' => 'Note', + 'confirm' => 'confirm.gif', 'confirm_alt' => 'Confirmation', + 'reject' => 'reject.gif', 'reject_alt' => 'Reject', + 'email' => 'email.gif', 'email_alt' => 'Email' ), + 'action' => array( + 'new' => 'new.gif', 'new_alt' => 'Add Sub', + 'view' => 'view.gif', 'view_alt' => 'View Subs', + 'parent' => 'parent.gif', 'parent_alt' => 'View other Subs', + 'edit' => 'edit.gif', 'edit_alt' => 'Edit', + 'addfile' => 'addfile.gif', 'addfile_alt' => 'Add a file', + 'delete' => 'delete.gif', 'delete_alt' => 'Delete', + 'close' => 'done.gif', 'close_alt' => 'Close' ), + 'status' => array( + 'billed' => 'billed.gif', 'billed_alt' => 'billed', + 'done' => 'done.gif', 'done_alt' => 'done', + 'will-call' => 'will-call.gif', 'will-call_alt' => 'will-call', + 'call' => 'call.gif', 'call_alt' => 'call', + 'ongoing' => 'ongoing.gif', 'ongoing_alt' => 'ongoing', + 'offer' => 'offer.gif', 'offer_alt' => 'offer' ) + ); + var $filters = array( + 'none' => 'no Filter', + 'done' => 'done', + 'my' => 'responsible', + 'my-open-today' => 'responsible open', + 'my-open-overdue' => 'responsible overdue', + 'my-upcoming' => 'responsible upcoming', + 'own' => 'own', + 'own-open-today' => 'own open', + 'own-open-overdue' => 'own overdue', + 'own-upcoming' => 'own upcoming', + 'open-today' => 'open', + 'open-overdue' => 'overdue', + 'upcoming' => 'upcoming' + ); + var $messages = array( + 'edit' => 'InfoLog - Edit', + 'add' => 'InfoLog - New', + 'add_sub' => 'InfoLog - New Subproject', + 'sp' => '- Subprojects from', + 're' => 'Re:' + ); + + function uiinfolog() + { + $this->bo =& new boinfolog(); + + $this->link = &$this->bo->link; + + $this->tmpl =& CreateObject('etemplate.etemplate'); + $this->html =& $this->tmpl->html; + + $this->user = $GLOBALS['egw_info']['user']['account_id']; + + $this->prefs =& $GLOBALS['egw_info']['user']['preferences']['infolog']; + + // read the duration format from project-manager + if ($GLOBALS['egw_info']['apps']['projectmanager']) + { + $pm_config =& CreateObject('phpgwapi.config','projectmanager'); + $pm_config->read_repository(); + $this->duration_format = str_replace(',','',$pm_config->config_data['duration_units']).','.$pm_config->config_data['hours_per_workday']; + unset($pm_config); + } + $GLOBALS['uiinfolog'] =& $this; // make ourself availible for ExecMethod of get_rows function + } + + function get_info($info,&$readonlys,$action='',$action_id='',$show_links=false,$details = 1) + { + if (!is_array($info)) + { + $info = $this->bo->read($info); + } + $id = $info['info_id']; + $done = $info['info_status'] == 'done' || $info['info_status'] == 'billed'; + $info['sub_class'] = $this->bo->enums['priority'][$info['info_priority']] . ($done ? '_done' : ''); + if (!$done && $info['info_enddate'] < $this->bo->user_time_now) + { + $info['end_class'] = 'overdue'; + } + if (!isset($info['info_anz_subs'])) $info['info_anz_subs'] = $this->bo->anzSubs($id); + $this->bo->link_id2from($info,$action,$action_id); // unset from for $action:$action_id + $info['info_percent'] = (int) $info['info_percent'].'%'; + + $readonlys["edit[$id]"] = !$this->bo->check_access($info,EGW_ACL_EDIT); + $readonlys["close[$id]"] = $done || ($readonlys["edit_status[$id]"] = !($this->bo->check_access($info,EGW_ACL_EDIT) || + in_array($this->user, (array)$info['info_responsible']))); + $readonlys["edit_status[$id]"] = $readonlys["edit_percent[$id]"] = + !$this->bo->check_access($info,EGW_ACL_EDIT) && !in_array($this->user, (array)$info['info_responsible']); + $readonlys["delete[$id]"] = !$this->bo->check_access($info,EGW_ACL_DELETE); + $readonlys["sp[$id]"] = !$this->bo->check_access($info,EGW_ACL_ADD); + $readonlys["view[$id]"] = $info['info_anz_subs'] < 1; + $readonlys['view[0]'] = True; // no parent + $readonlys["timesheet[$id]"] = !$this->prefs['show_times'] || !isset($GLOBALS['egw_info']['user']['apps']['timesheet']); + + if (!$show_links) $show_links = $this->prefs['show_links']; + + if (($show_links != 'none' && $show_links != 'no_describtion' || + $this->prefs['show_times'] && isset($GLOBALS['egw_info']['user']['apps']['timesheet'])) && + ($links = $this->link->get_links('infolog',$info['info_id']))) + { + $timesheets = array(); + foreach ($links as $link) + { + if ($show_links != 'none' && $show_links != 'no_describtion' && + $link['link_id'] != $info['info_link_id'] && + ($link['app'] != $action || $link['id'] != $action_id) && + ($show_links == 'all' || ($show_links == 'links') === ($link['app'] != $this->link->vfs_appname))) + { + $info['filelinks'][] = $link; + } + if (!$info['pm_id'] && $link['app'] == 'projectmanager') + { + $info['pm_id'] = $link['id']; + } + if ($link['app'] == 'timesheet') $timesheets[] = $link['id']; + + if ($link['app'] != 'timesheet' && $link['app'] != $this->link->vfs_appname) + { + $info['extra_links'] .= '&link_app[]='.$link['app'].'&link_id[]='.$link['id']; + } + } + if ($this->prefs['show_times'] && isset($GLOBALS['egw_info']['user']['apps']['timesheet']) && $timesheets) + { + $sum = ExecMethod('timesheet.botimesheet.sum',$timesheets); + $info['info_sum_timesheets'] = $sum['duration']; + } + } + $info['info_type_label'] = $this->bo->enums['type'][$info['info_type']]; + $info['info_status_label'] = $this->bo->status[$info['info_type']][$info['info_status']]; + + if (!$this->prefs['show_percent'] || $this->prefs['show_percent'] == 2 && !$details) + { + if ($info['info_status'] == 'ongoing' && $info['info_type'] != 'phone') + { + $info['info_status'] = $info['info_status_label'] = $info['info_percent']; + } + $readonlys["edit_percent[$id]"] = true; + } + elseif($readonlys["edit_percent[$id]"]) // show percent, but button is switched off + { + $info['info_percent2'] = $info['info_percent']; + } + if ($this->prefs['show_id'] == 1 || $this->prefs['show_id'] == 2 && $details) + { + $info['info_number'] = $info['info_id']; + } + return $info; + } + + function save_sessiondata($values) + { + $for = @$values['session_for'] ? $values['session_for'] : @$this->called_by; + //echo "

$for: uiinfolog::save_sessiondata(".print_r($values,True).") called_by='$this->called_by', for='$for'
".function_backtrace()."

\n"; + $GLOBALS['egw']->session->appsession($for.'session_data','infolog',array( + 'search' => $values['search'], + 'start' => $values['start'], + 'num_rows' => $values['num_rows'], + 'filter' => $values['filter'], + 'filter2' => $values['filter2'], + 'cat_id' => $values['cat_id'], + 'order' => $values['order'], + 'sort' => $values['sort'], + 'action' => $values['action'], + 'action_id' => $values['action_id'], + 'col_filter' => $values['col_filter'], + 'session_for' => $for + )); + } + + function read_sessiondata() + { + $values = $GLOBALS['egw']->session->appsession(@$this->called_by.'session_data','infolog'); + if (!@$values['session_for'] && $this->called_by) + { + $values['session_for'] = $this->called_by; + $this->save_sessiondata($values); + } + //echo "

called_by='$this->called_by': uiinfolog::read_sessiondata() = ".print_r($values,True)."

\n"; + return $values; + } + + function get_rows($query,&$rows,&$readonlys) + { + //echo "

uiinfolog.get_rows(start=$query[start],search='$query[search]',filter='$query[filter]',cat_id=$query[cat_id],action='$query[action]/$query[action_id]',col_filter=".print_r($query['col_filter'],True).")

\n"; + if (!isset($query['start'])) $query['start'] = 0; + + $this->save_sessiondata($query); + + $ids = $this->bo->search($query); + if (!is_array($ids)) + { + $ids = array( ); + } + $details = $query['filter2'] == 'all'; + $readonlys = $rows = array(); + foreach($ids as $id => $info) + { + $info = $this->get_info($info,$readonlys,$query['action'],$query['action_id'],$query['filter2'],$details); + if (!$query['filter2'] && $this->prefs['show_links'] == 'no_describtion' || + $query['filter2'] == 'no_describtion') + { + unset($info['info_des']); + } + $rows[] = $info; + } + if ($query['no_actions']) $rows['no_actions'] = true; + $rows['no_modified'] = !$this->prefs['show_modified'] || $this->prefs['show_modified'] == 2 && !$details; + $rows['no_times'] = !$this->prefs['show_times'] || $this->prefs['show_times'] == 2 && !$details; + $rows['no_timesheet'] = !isset($GLOBALS['egw_info']['user']['apps']['timesheet']); + $rows['duration_format'] = ','.$this->duration_format.',,1'; + $rows['no_users'] = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'none' && + !isset($GLOBALS['egw_info']['user']['apps']['admin']); + //echo "

readonlys = "; _debug_array($readonlys); + //echo "rows=

".print_r($rows,True)."
\n"; + + if ($GLOBALS['egw_info']['flags']['currentapp'] == 'infolog') + { + $GLOBALS['egw_info']['flags']['app_header'] = lang('Infolog').($query['filter'] == 'none' ? '' : + ' - '.lang($this->filters[$query['filter']])); + } + return $query['total']; + } /** - * This class is the UI-layer (user interface) of InfoLog + * Shows the infolog list * - * @package infolog - * @author Ralf Becker - * @copyright (c) by Ralf Becker - * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @param array/string $values=null etemplate content or 'reset_action_view' if called by index.php to reset an action-view + * @param string $action='' if set only entries liked to that $action:$action_id are shown + * @param string $action_id='' if set only entries liked to that $action:$action_id are shown + * @param mixed $called_as=0 this is how we got called, for a hook eg. the call-params of that page containing the hook + * @param boolean $extra_app_header=false + * @param boolean $return_html=false + * @param string $own_referer='' this is our own referer */ - class uiinfolog + function index($values = null,$action='',$action_id='',$called_as=0,$extra_app_header=False,$return_html=False,$own_referer='') { - var $public_functions = array - ( - 'index' => True, - 'edit' => True, - 'delete' => True, - 'close' => True, - 'admin' => True, - 'hook_view' => True, - 'writeLangFile' => True, - 'import_mail' => True, - ); - /** - * reference to the infolog preferences of the user - * - * @var array - */ - var $prefs; - /** - * instance of the bo-class - * - * @var boinfolog - */ - var $bo; - /** - * reference to instance of the link-class of bo - * - * @var bolink - */ - var $link; - /** - * instance of the etemplate class - * - * @var etemplate - */ - var $tmpl; - /** - * reference to the html object of etemplate - * - * @var html - */ - var $html; - /** - * allowed units and hours per day, can be overwritten by the projectmanager configuration, default all units, 8h - * - * @var string - */ - var $duration_format = ','; // comma is necessary! - - var $icons = array( - 'type' => array( - 'task' => 'task.gif', 'task_alt' => 'Task', - 'phone' => 'phone.gif', 'phone_alt' => 'Phonecall', - 'note' => 'note.gif', 'note_alt' => 'Note', - 'confirm' => 'confirm.gif', 'confirm_alt' => 'Confirmation', - 'reject' => 'reject.gif', 'reject_alt' => 'Reject', - 'email' => 'email.gif', 'email_alt' => 'Email' ), - 'action' => array( - 'new' => 'new.gif', 'new_alt' => 'Add Sub', - 'view' => 'view.gif', 'view_alt' => 'View Subs', - 'parent' => 'parent.gif', 'parent_alt' => 'View other Subs', - 'edit' => 'edit.gif', 'edit_alt' => 'Edit', - 'addfile' => 'addfile.gif', 'addfile_alt' => 'Add a file', - 'delete' => 'delete.gif', 'delete_alt' => 'Delete', - 'close' => 'done.gif', 'close_alt' => 'Close' ), - 'status' => array( - 'billed' => 'billed.gif', 'billed_alt' => 'billed', - 'done' => 'done.gif', 'done_alt' => 'done', - 'will-call' => 'will-call.gif', 'will-call_alt' => 'will-call', - 'call' => 'call.gif', 'call_alt' => 'call', - 'ongoing' => 'ongoing.gif', 'ongoing_alt' => 'ongoing', - 'offer' => 'offer.gif', 'offer_alt' => 'offer' ) - ); - var $filters = array( - 'none' => 'no Filter', - 'done' => 'done', - 'my' => 'responsible', - 'my-open-today' => 'responsible open', - 'my-open-overdue' => 'responsible overdue', - 'my-upcoming' => 'responsible upcoming', - 'own' => 'own', - 'own-open-today' => 'own open', - 'own-open-overdue' => 'own overdue', - 'own-upcoming' => 'own upcoming', - 'open-today' => 'open', - 'open-overdue' => 'overdue', - 'upcoming' => 'upcoming' - ); - var $messages = array( - 'edit' => 'InfoLog - Edit', - 'add' => 'InfoLog - New', - 'add_sub' => 'InfoLog - New Subproject', - 'sp' => '- Subprojects from', - 're' => 'Re:' - ); - - function uiinfolog() + if (is_array($values)) { - $this->bo =& new boinfolog(); - - $this->link = &$this->bo->link; - - $this->tmpl =& CreateObject('etemplate.etemplate'); - $this->html =& $this->tmpl->html; - - $this->user = $GLOBALS['egw_info']['user']['account_id']; - - $this->prefs =& $GLOBALS['egw_info']['user']['preferences']['infolog']; - - // read the duration format from project-manager - if ($GLOBALS['egw_info']['apps']['projectmanager']) - { - $pm_config =& CreateObject('phpgwapi.config','projectmanager'); - $pm_config->read_repository(); - $this->duration_format = str_replace(',','',$pm_config->config_data['duration_units']).','.$pm_config->config_data['hours_per_workday']; - unset($pm_config); - } - $GLOBALS['uiinfolog'] =& $this; // make ourself availible for ExecMethod of get_rows function + $called_as = $values['called_as']; + $own_referer = $values['own_referer']; } - - function get_info($info,&$readonlys,$action='',$action_id='',$show_links=false,$details = 1) + elseif ($own_referer === '') { - if (!is_array($info)) + $own_referer = $GLOBALS['egw']->common->get_referer(); + if (strstr($own_referer,'menuaction=infolog.uiinfolog.edit')) { - $info = $this->bo->read($info); + $own_referer = $GLOBALS['egw']->session->appsession('own_session','infolog'); } - $id = $info['info_id']; - $done = $info['info_status'] == 'done' || $info['info_status'] == 'billed'; - $info['sub_class'] = $this->bo->enums['priority'][$info['info_priority']] . ($done ? '_done' : ''); - if (!$done && $info['info_enddate'] < $this->bo->user_time_now) + else { - $info['end_class'] = 'overdue'; + $GLOBALS['egw']->session->appsession('own_session','infolog',$own_referer); } - if (!isset($info['info_anz_subs'])) $info['info_anz_subs'] = $this->bo->anzSubs($id); - $this->bo->link_id2from($info,$action,$action_id); // unset from for $action:$action_id - $info['info_percent'] = (int) $info['info_percent'].'%'; + } + if (!$action) + { + $action = $values['action'] ? $values['action'] : get_var('action',array('POST','GET')); + $action_id = $values['action_id'] ? $values['action_id'] : get_var('action_id',array('POST','GET')); - $readonlys["edit[$id]"] = !$this->bo->check_access($info,EGW_ACL_EDIT); - $readonlys["close[$id]"] = $done || ($readonlys["edit_status[$id]"] = !($this->bo->check_access($info,EGW_ACL_EDIT) || - in_array($this->user, (array)$info['info_responsible']))); - $readonlys["edit_status[$id]"] = $readonlys["edit_percent[$id]"] = - !$this->bo->check_access($info,EGW_ACL_EDIT) && !in_array($this->user, (array)$info['info_responsible']); - $readonlys["delete[$id]"] = !$this->bo->check_access($info,EGW_ACL_DELETE); - $readonlys["sp[$id]"] = !$this->bo->check_access($info,EGW_ACL_ADD); - $readonlys["view[$id]"] = $info['info_anz_subs'] < 1; - $readonlys['view[0]'] = True; // no parent - $readonlys["timesheet[$id]"] = !$this->prefs['show_times'] || !isset($GLOBALS['egw_info']['user']['apps']['timesheet']); - - if (!$show_links) $show_links = $this->prefs['show_links']; - - if (($show_links != 'none' && $show_links != 'no_describtion' || - $this->prefs['show_times'] && isset($GLOBALS['egw_info']['user']['apps']['timesheet'])) && - ($links = $this->link->get_links('infolog',$info['info_id']))) + if ($values === 'reset_action_view') // only read action from session, if not called by index.php { - $timesheets = array(); - foreach ($links as $link) - { - if ($show_links != 'none' && $show_links != 'no_describtion' && - $link['link_id'] != $info['info_link_id'] && - ($link['app'] != $action || $link['id'] != $action_id) && - ($show_links == 'all' || ($show_links == 'links') === ($link['app'] != $this->link->vfs_appname))) - { - $info['filelinks'][] = $link; - } - if (!$info['pm_id'] && $link['app'] == 'projectmanager') - { - $info['pm_id'] = $link['id']; - } - if ($link['app'] == 'timesheet') $timesheets[] = $link['id']; - - if ($link['app'] != 'timesheet' && $link['app'] != $this->link->vfs_appname) - { - $info['extra_links'] .= '&link_app[]='.$link['app'].'&link_id[]='.$link['id']; - } - } - if ($this->prefs['show_times'] && isset($GLOBALS['egw_info']['user']['apps']['timesheet']) && $timesheets) - { - $sum = ExecMethod('timesheet.botimesheet.sum',$timesheets); - $info['info_sum_timesheets'] = $sum['duration']; - } + $session = $this->read_sessiondata(); + $session['action'] = $action = ''; + $session['action_id'] = $action_id = 0; + $this->save_sessiondata($session); + unset($session); } - $info['info_type_label'] = $this->bo->enums['type'][$info['info_type']]; - $info['info_status_label'] = $this->bo->status[$info['info_type']][$info['info_status']]; - - if (!$this->prefs['show_percent'] || $this->prefs['show_percent'] == 2 && !$details) + elseif (!$action) { - if ($info['info_status'] == 'ongoing' && $info['info_type'] != 'phone') - { - $info['info_status'] = $info['info_status_label'] = $info['info_percent']; - } - $readonlys["edit_percent[$id]"] = true; + $session = $this->read_sessiondata(); + $action = $session['action']; + $action_id = $session['action_id']; + unset($session); } - elseif($readonlys["edit_percent[$id]"]) // show percent, but button is switched off - { - $info['info_percent2'] = $info['info_percent']; - } - if ($this->prefs['show_id'] == 1 || $this->prefs['show_id'] == 2 && $details) - { - $info['info_number'] = $info['info_id']; - } - return $info; } - - function save_sessiondata($values) + //echo "

uiinfolog::index(action='$action/$action_id',called_as='$called_as/$values[referer]',own_referer='$own_referer') values=\n"; _debug_array($values); + if (!is_array($values)) { - $for = @$values['session_for'] ? $values['session_for'] : @$this->called_by; - //echo "

$for: uiinfolog::save_sessiondata(".print_r($values,True).") called_by='$this->called_by', for='$for'
".function_backtrace()."

\n"; - $GLOBALS['egw']->session->appsession($for.'session_data','infolog',array( - 'search' => $values['search'], - 'start' => $values['start'], - 'num_rows' => $values['num_rows'], - 'filter' => $values['filter'], - 'filter2' => $values['filter2'], - 'cat_id' => $values['cat_id'], - 'order' => $values['order'], - 'sort' => $values['sort'], - 'action' => $values['action'], - 'action_id' => $values['action_id'], - 'col_filter' => $values['col_filter'], - 'session_for' => $for - )); + $values = array('nm' => $this->read_sessiondata()); + if (isset($_GET['filter']) && $_GET['filter'] != 'default' || !isset($values['nm']['filter']) && !$this->called_by) + { + $values['nm']['filter'] = $_GET['filter'] && $_GET['filter'] != 'default' ? $_GET['filter'] : + $this->prefs['defaultFilter']; + } + if (!isset($values['nm']['order']) || !$values['nm']['order']) + { + $values['nm']['order'] = 'info_datemodified'; + $values['nm']['sort'] = 'DESC'; + } + $values['msg'] = $_GET['msg']; + $values['action'] = $action; + $values['action_id'] = $action_id; } - - function read_sessiondata() + if ($values['nm']['add']) { - $values = $GLOBALS['egw']->session->appsession(@$this->called_by.'session_data','infolog'); - if (!@$values['session_for'] && $this->called_by) - { - $values['session_for'] = $this->called_by; - $this->save_sessiondata($values); - } - //echo "

called_by='$this->called_by': uiinfolog::read_sessiondata() = ".print_r($values,True)."

\n"; - return $values; + $values['add'] = $values['nm']['add']; + unset($values['nm']['add']); } - - function get_rows($query,&$rows,&$readonlys) + if ($values['add'] || $values['cancel'] || isset($values['nm']['rows']) || isset($values['main'])) { - //echo "

uiinfolog.get_rows(start=$query[start],search='$query[search]',filter='$query[filter]',cat_id=$query[cat_id],action='$query[action]/$query[action_id]',col_filter=".print_r($query['col_filter'],True).")

\n"; - if (!isset($query['start'])) $query['start'] = 0; - - $this->save_sessiondata($query); - - $ids = $this->bo->search($query); - if (!is_array($ids)) + if ($values['add']) { - $ids = array( ); + list($type) = each($values['add']); + return $this->edit(0,$action,$action_id,$type,$called_as); } - $details = $query['filter2'] == 'all'; - $readonlys = $rows = array(); - foreach($ids as $id => $info) + elseif ($values['cancel'] && $own_referer) { - $info = $this->get_info($info,$readonlys,$query['action'],$query['action_id'],$query['filter2'],$details); - if (!$query['filter2'] && $this->prefs['show_links'] == 'no_describtion' || - $query['filter2'] == 'no_describtion') - { - unset($info['info_des']); - } - $rows[] = $info; + $session = $this->read_sessiondata(); + unset($session['action']); + unset($session['action_id']); + $this->save_sessiondata($session); + $this->tmpl->location($own_referer); } - if ($query['no_actions']) $rows['no_actions'] = true; - $rows['no_modified'] = !$this->prefs['show_modified'] || $this->prefs['show_modified'] == 2 && !$details; - $rows['no_times'] = !$this->prefs['show_times'] || $this->prefs['show_times'] == 2 && !$details; - $rows['no_timesheet'] = !isset($GLOBALS['egw_info']['user']['apps']['timesheet']); - $rows['duration_format'] = ','.$this->duration_format.',,1'; - $rows['no_users'] = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'none' && - !isset($GLOBALS['egw_info']['user']['apps']['admin']); - //echo "

readonlys = "; _debug_array($readonlys); - //echo "rows=

".print_r($rows,True)."
\n"; - - if ($GLOBALS['egw_info']['flags']['currentapp'] == 'infolog') + else { - $GLOBALS['egw_info']['flags']['app_header'] = lang('Infolog').($query['filter'] == 'none' ? '' : - ' - '.lang($this->filters[$query['filter']])); - } - return $query['total']; - } - - /** - * Shows the infolog list - * - * @param array/string $values=null etemplate content or 'reset_action_view' if called by index.php to reset an action-view - * @param string $action='' if set only entries liked to that $action:$action_id are shown - * @param string $action_id='' if set only entries liked to that $action:$action_id are shown - * @param mixed $called_as=0 this is how we got called, for a hook eg. the call-params of that page containing the hook - * @param boolean $extra_app_header=false - * @param boolean $return_html=false - * @param string $own_referer='' this is our own referer - */ - function index($values = null,$action='',$action_id='',$called_as=0,$extra_app_header=False,$return_html=False,$own_referer='') - { - if (is_array($values)) - { - $called_as = $values['called_as']; - $own_referer = $values['own_referer']; - } - elseif ($own_referer === '') - { - $own_referer = $GLOBALS['egw']->common->get_referer(); - if (strstr($own_referer,'menuaction=infolog.uiinfolog.edit')) + list($do,$do_id) = isset($values['main']) ? each($values['main']) : @each($values['nm']['rows']); + list($do_id) = @each($do_id); + //echo "

infolog::index: do='$do/$do_id', referer="; _debug_array($called_as); + switch($do) { - $own_referer = $GLOBALS['egw']->session->appsession('own_session','infolog'); - } - else - { - $GLOBALS['egw']->session->appsession('own_session','infolog',$own_referer); - } - } - if (!$action) - { - $action = $values['action'] ? $values['action'] : get_var('action',array('POST','GET')); - $action_id = $values['action_id'] ? $values['action_id'] : get_var('action_id',array('POST','GET')); - - if ($values === 'reset_action_view') // only read action from session, if not called by index.php - { - $session = $this->read_sessiondata(); - $session['action'] = $action = ''; - $session['action_id'] = $action_id = 0; - $this->save_sessiondata($session); - unset($session); - } - elseif (!$action) - { - $session = $this->read_sessiondata(); - $action = $session['action']; - $action_id = $session['action_id']; - unset($session); - } - } - //echo "

uiinfolog::index(action='$action/$action_id',called_as='$called_as/$values[referer]',own_referer='$own_referer') values=\n"; _debug_array($values); - if (!is_array($values)) - { - $values = array('nm' => $this->read_sessiondata()); - if (isset($_GET['filter']) && $_GET['filter'] != 'default' || !isset($values['nm']['filter']) && !$this->called_by) - { - $values['nm']['filter'] = $_GET['filter'] && $_GET['filter'] != 'default' ? $_GET['filter'] : - $this->prefs['defaultFilter']; - } - if (!isset($values['nm']['order']) || !$values['nm']['order']) - { - $values['nm']['order'] = 'info_datemodified'; - $values['nm']['sort'] = 'DESC'; - } - $values['msg'] = $_GET['msg']; - $values['action'] = $action; - $values['action_id'] = $action_id; - } - if ($values['nm']['add']) - { - $values['add'] = $values['nm']['add']; - unset($values['nm']['add']); - } - if ($values['add'] || $values['cancel'] || isset($values['nm']['rows']) || isset($values['main'])) - { - if ($values['add']) - { - list($type) = each($values['add']); - return $this->edit(0,$action,$action_id,$type,$called_as); - } - elseif ($values['cancel'] && $own_referer) - { - $session = $this->read_sessiondata(); - unset($session['action']); - unset($session['action_id']); - $this->save_sessiondata($session); - $this->tmpl->location($own_referer); - } - else - { - list($do,$do_id) = isset($values['main']) ? each($values['main']) : @each($values['nm']['rows']); - list($do_id) = @each($do_id); - //echo "

infolog::index: do='$do/$do_id', referer="; _debug_array($called_as); - switch($do) - { - case 'edit': - case 'edit_status': - return $this->edit($do_id,$action,$action_id,'',$called_as); - case 'delete': - if (!($values['msg'] = $this->delete($do_id,$called_as,$called_as ? '' : 'index'))) return; - break; - case 'close': - return $this->close($do_id,$called_as,$do == 'close_subs'); - case 'sp': - return $this->edit(0,'sp',$do_id,'',$called_as); - case 'view': - $value = array(); - $action = 'sp'; - $action_id = $do_id; - break; - default: - $value = array(); - $action = ''; - $action_id = 0; - break; - } - } - } - switch ($action) - { - case 'sp': - if (!$this->bo->read($action_id)) - { + case 'edit': + case 'edit_status': + return $this->edit($do_id,$action,$action_id,'',$called_as); + case 'delete': + if (!($values['msg'] = $this->delete($do_id,$called_as,$called_as ? '' : 'index'))) return; + break; + case 'close': + return $this->close($do_id,$called_as,$do == 'close_subs'); + case 'sp': + return $this->edit(0,'sp',$do_id,'',$called_as); + case 'view': + $value = array(); + $action = 'sp'; + $action_id = $do_id; + break; + default: + $value = array(); $action = ''; $action_id = 0; break; - } - $values['main'][1] = $this->get_info($action_id,$readonlys['main']); - $values['main']['no_times'] = !$this->prefs['show_times']; - break; - } - $readonlys['cancel'] = $action != 'sp'; - - $this->tmpl->read('infolog.index'); - - $values['nm']['options-filter'] = $this->filters; - $values['nm']['get_rows'] = 'infolog.uiinfolog.get_rows'; - $values['nm']['options-filter2'] = (in_array($this->prefs['show_links'],array('all','no_describtion')) ? array() : array( - '' => 'default', - )) + array( - 'no_describtion' => 'no details', - 'all' => 'details', - ); - if(!isset($values['nm']['filter2'])) $values['nm']['filter2'] = $this->prefs['show_links']; - $values['nm']['header_right'] = 'infolog.index.header_right'; - if ($extra_app_header) - { - $values['nm']['header_left'] = 'infolog.index.header_left'; - } - $values['nm']['bottom_too'] = True; - $values['nm']['never_hide'] = isset($this->prefs['never_hide']) ? - $this->prefs['never_hide'] : $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 15; - $values['action'] = $persist['action'] = $values['nm']['action'] = $action; - $values['action_id'] = $persist['action_id'] = $values['nm']['action_id'] = $action_id; - $persist['called_as'] = $called_as; - $persist['own_referer'] = $own_referer; - - $all_stati = array(); - foreach($this->bo->status as $typ => $stati) - { - if ($typ != 'defaults') $all_stati += $stati; - } - if (!$called_as) - { - $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog'); - $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => 'ManualInfologIndex'); - } - else - { - $values['css'] = '"; - } - return $this->tmpl->exec('infolog.uiinfolog.index',$values,array( - 'info_type' => $this->bo->enums['type'], - 'info_status' => $all_stati - ),$readonlys,$persist,$return_html ? -1 : 0); - } - - function close($values=0,$referer='') - { - $info_id = (int) (is_array($values) ? $values['info_id'] : ($values ? $values : $_GET['info_id'])); - $referer = is_array($values) ? $values['referer'] : $referer; - - if ($info_id) - { - $values = array( - 'info_id' => $info_id, - 'info_status' => 'done', - 'info_percent'=> 100, - 'info_datecompleted' => $this->bo->now_su, - ); - $this->bo->write($values); - - $query = array('action'=>'sp','action_id'=>$info_id); - foreach((array)$this->bo->search($query) as $info) - { - if ($info['info_id_parent'] == $info_id) // search also returns linked entries! - { - $this->close($info['info_id'],$referer); // we call ourselfs recursive to process subs from subs too - } } } + } + switch ($action) + { + case 'sp': + if (!$this->bo->read($action_id)) + { + $action = ''; + $action_id = 0; + break; + } + $values['main'][1] = $this->get_info($action_id,$readonlys['main']); + $values['main']['no_times'] = !$this->prefs['show_times']; + break; + } + $readonlys['cancel'] = $action != 'sp'; + + $this->tmpl->read('infolog.index'); + + $values['nm']['options-filter'] = $this->filters; + $values['nm']['get_rows'] = 'infolog.uiinfolog.get_rows'; + $values['nm']['options-filter2'] = (in_array($this->prefs['show_links'],array('all','no_describtion')) ? array() : array( + '' => 'default', + )) + array( + 'no_describtion' => 'no details', + 'all' => 'details', + ); + if(!isset($values['nm']['filter2'])) $values['nm']['filter2'] = $this->prefs['show_links']; + $values['nm']['header_right'] = 'infolog.index.header_right'; + if ($extra_app_header) + { + $values['nm']['header_left'] = 'infolog.index.header_left'; + } + $values['nm']['bottom_too'] = True; + $values['nm']['never_hide'] = isset($this->prefs['never_hide']) ? + $this->prefs['never_hide'] : $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 15; + $values['action'] = $persist['action'] = $values['nm']['action'] = $action; + $values['action_id'] = $persist['action_id'] = $values['nm']['action_id'] = $action_id; + $persist['called_as'] = $called_as; + $persist['own_referer'] = $own_referer; + + $all_stati = array(); + foreach($this->bo->status as $typ => $stati) + { + if ($typ != 'defaults') $all_stati += $stati; + } + if (!$called_as) + { + $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog'); + $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => 'ManualInfologIndex'); + } + else + { + $values['css'] = '"; + } + return $this->tmpl->exec('infolog.uiinfolog.index',$values,array( + 'info_type' => $this->bo->enums['type'], + 'info_status' => $all_stati + ),$readonlys,$persist,$return_html ? -1 : 0); + } + + function close($values=0,$referer='') + { + $info_id = (int) (is_array($values) ? $values['info_id'] : ($values ? $values : $_GET['info_id'])); + $referer = is_array($values) ? $values['referer'] : $referer; + + if ($info_id) + { + $values = array( + 'info_id' => $info_id, + 'info_status' => 'done', + 'info_percent'=> 100, + 'info_datecompleted' => $this->bo->now_su, + ); + $this->bo->write($values); + + $query = array('action'=>'sp','action_id'=>$info_id); + foreach((array)$this->bo->search($query) as $info) + { + if ($info['info_id_parent'] == $info_id) // search also returns linked entries! + { + $this->close($info['info_id'],$referer); // we call ourselfs recursive to process subs from subs too + } + } + } + return $referer ? $this->tmpl->location($referer) : $this->index(); + } + + function delete($values=0,$referer='',$called_by='') + { + $info_id = (int) (is_array($values) ? $values['info_id'] : ($values ? $values : $_GET['info_id'])); + $referer = is_array($values) ? $values['referer'] : $referer; + + if (!is_array($values) && $info_id > 0 && !$this->bo->anzSubs($info_id)) // entries without subs get confirmed by javascript + { + $values = array('delete' => true); + } + //echo "

uiinfolog::delete(".print_r($values,true).",'$referer','$called_by') info_id=$info_id

\n"; + + if (is_array($values) || $info_id <= 0) + { + if (($values['delete'] || $values['delete_subs']) && $info_id > 0 && $this->bo->check_access($info_id,EGW_ACL_DELETE)) + { + $deleted = $this->bo->delete($info_id,$values['delete_subs'],$values['info_id_parent']); + } + if ($called_by) // direct call from the same request + { + return $deleted ? lang('InfoLog entry deleted') : ''; + } + if ($values['called_by'] == 'edit') // we run in the edit popup => give control back to edit + { + $this->edit(array( + 'info_id' => $info_id, + 'button' => array('deleted' => true), // not delete! + 'referer' => $referer, + 'msg' => $deleted ? lang('Infolog entry deleted') : '', + )); + } return $referer ? $this->tmpl->location($referer) : $this->index(); } + $readonlys = $values = array(); + $values['main'][1] = $this->get_info($info_id,$readonlys['main']); - function delete($values=0,$referer='',$called_by='') + $this->tmpl->read('infolog.delete'); + + $values['nm'] = array( + 'action' => 'sp', + 'action_id' => $info_id, + 'options-filter' => $this->filters, + 'get_rows' => 'infolog.uiinfolog.get_rows', + 'no_filter2' => True, + 'never_hide' => isset($this->prefs['never_hide']) ? + $this->prefs['never_hide'] : + $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 15, + ); + $values['main']['no_actions'] = $values['nm']['no_actions'] = True; + + $persist['info_id'] = $info_id; + $persist['referer'] = $referer; + $persist['info_id_parent'] = $values['main'][1]['info_id_parent']; + $persist['called_by'] = $called_by; + + $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Delete'); + $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => 'ManualInfologDelete'); + + $this->tmpl->exec('infolog.uiinfolog.delete',$values,'',$readonlys,$persist,$called_by == 'edit' ? 2 : 0); + } + + /** + * Edit/Create an InfoLog Entry + * + * @param array $content=null Content from the eTemplate Exec call or info_id on inital call + * @param string $action='' Name of an app of 'sp' for a infolog-sub + * @param int $action_id=0 Id of app-entry to which a link is created + * @param string $type='' Type of log-entry: note,todo,task + * @param string $referer='' array with param/get-vars of the refering page + */ + function edit($content = null,$action = '',$action_id=0,$type='',$referer='') + { + $tabs = 'description|links|delegation|project|customfields'; + + if (is_array($content)) { - $info_id = (int) (is_array($values) ? $values['info_id'] : ($values ? $values : $_GET['info_id'])); - $referer = is_array($values) ? $values['referer'] : $referer; - - if (!is_array($values) && $info_id > 0 && !$this->bo->anzSubs($info_id)) // entries without subs get confirmed by javascript + //echo "uiinfolog::edit: content="; _debug_array($content); + $info_id = $content['info_id']; + $action = $content['action']; + $action_id = $content['action_id']; + $referer = $content['referer']; + $no_popup = $content['no_popup']; + $caller = $content['caller']; + +/* if (isset($content['link_to']['primary'])) { - $values = array('delete' => true); - } - //echo "

uiinfolog::delete(".print_r($values,true).",'$referer','$called_by') info_id=$info_id

\n"; - - if (is_array($values) || $info_id <= 0) + $content['info_link_id'] = $content['link_to']['primary']; + }*/ + list($button) = @each($content['button']); + unset($content['button']); + if ($button) { - if (($values['delete'] || $values['delete_subs']) && $info_id > 0 && $this->bo->check_access($info_id,EGW_ACL_DELETE)) + //echo "

uiinfolog::edit(info_id=$info_id) '$button' button pressed, content="; _debug_array($content); + if (($button == 'save' || $button == 'apply') && empty($content['info_subject'])) { - $deleted = $this->bo->delete($info_id,$values['delete_subs'],$values['info_id_parent']); + $this->tmpl->set_validation_error('info_subject',lang('Field must not be empty !!!')); + $button = ''; // stop save or apply } - if ($called_by) // direct call from the same request + if (($button == 'save' || $button == 'apply') && $info_id) { - return $deleted ? lang('InfoLog entry deleted') : ''; + if (!($edit_acl = $this->bo->check_access($info_id,EGW_ACL_EDIT))) + { + $old = $this->bo->read($info_id); + $status_only = in_array($this->user, $old['info_responsible']); + } } - if ($values['called_by'] == 'edit') // we run in the edit popup => give control back to edit + if (($button == 'save' || $button == 'apply') && (!$info_id || $edit_acl || $status_only)) { - $this->edit(array( - 'info_id' => $info_id, - 'button' => array('deleted' => true), // not delete! - 'referer' => $referer, - 'msg' => $deleted ? lang('Infolog entry deleted') : '', - )); + if ($content['info_contact']) + { + $old_link_id = (int)$content['info_link_id']; + list($app,$id) = explode(':',$content['info_contact']); + $content['info_link_id'] = (int)($info_link_id = $this->link->link('infolog',$content['link_to']['to_id'],$app,$id)); + if ($old_link_id && $old_link_id != $content['info_link_id']) $this->link->unlink($old_link_id); + } + if (is_array($content['link_to']['to_id']) && count($content['link_to']['to_id'])) + { + $content['info_link_id'] = 0; // as field has to be int + } + $active_tab = $content[$tabs]; + if (!($info_id = $this->bo->write($content))) + { + $content['msg'] = $info_id !== 0 || !$content['info_id'] ? lang('Error: saving the entry') : + lang('Error: the entry has been updated since you opened it for editing!').'
'. + lang('Copy your changes to the clipboard, %1reload the entry%2 and merge them.','',''); + $button = ''; // not exiting edit + $info_id = $content['info_id']; + } + else + { + $content['msg'] = lang('InfoLog entry saved'); + if ($referer !== false) + { + $content['js'] = "opener.location.href='".($link=$GLOBALS['egw']->link($referer,array('msg' => $content['msg'])))."';"; + } + } + $content[$tabs] = $active_tab; + if ((int) $content['pm_id'] != (int) $content['old_pm_id']) + { + //echo "

pm_id changed: $content[old_pm_id] -> $content[pm_id]

\n"; + // update links accordingly, if selected project changed + if ($content['pm_id']) + { + //echo "

this->link->link('infolog',{$content['link_to']['to_id']},'projectmanager',{$content['pm_id']});

"; + $this->link->link('infolog',$content['link_to']['to_id'],'projectmanager',$content['pm_id']); + // making the project the selected link, if no other link selected + if (!$info_link_id || $info_link_id == 'projectmanager:'.$content['old_pm_id']) + { + $info_link_id = 'projectmanager:'.$content['pm_id']; + } + } + if ($content['old_pm_id']) + { + //echo "

this->link->unlink2(0,infolog,{$content['link_to']['to_id']},0,'projectmanager',{$content['old_pm_id']});

\n"; + $this->link->unlink2(0,infolog,$content['link_to']['to_id'],0,'projectmanager',$content['old_pm_id']); + $content['old_pm_id'] = $content['pm_id']; + } + } + // writing links for a new entry + if ($info_id && is_array($content['link_to']['to_id']) && count($content['link_to']['to_id'])) + { + $this->link->link('infolog',$info_id,$content['link_to']['to_id']); + $content['link_to']['to_id'] = $info_id; + } + if (strstr($info_link_id,':') !== false) // updating info_link_id if necessary + { + list($app,$id) = explode(':',$info_link_id); + $link = $this->link->get_link('infolog',$info_id,$app,$id); + if ((int) $content['info_link_id'] != (int) $link['link_id']) + { + $content['info_link_id'] = $link['link_id']; + + $to_write = array( + 'info_id' => $content['info_id'], + 'info_link_id' => $content['info_link_id'], + 'info_from' => $content['info_from'], + 'info_owner' => $content['info_owner'], + ); + $this->bo->write($to_write,False); + // we need eg. the new modification date, for further updates + $content = array_merge($content,$to_write); + } + } } - return $referer ? $this->tmpl->location($referer) : $this->index(); + elseif ($button == 'delete' && $info_id > 0) + { + if (!$referer && $action) $referer = array( + 'menuaction' => 'infolog.uiinfolog.index', + 'action' => $action, + 'action_id' => $action_id + ); + if (!($content['msg'] = $this->delete($info_id,$referer,'edit'))) return; // checks ACL first + + $content['js'] = "opener.location.href='".$GLOBALS['egw']->link($referer,array('msg' => $content['msg']))."';"; + } + // called again after delete confirmation dialog + elseif ($button == 'deleted' && $content['msg']) + { + $content['js'] = "opener.location.href='".$GLOBALS['egw']->link($referer,array('msg' => $content['msg']))."';"; + } + if ($button == 'save' || $button == 'cancel' || $button == 'delete' || $button == 'deleted') + { + if ($no_popup) + { + $GLOBALS['egw']->redirect_link($referer,array('msg' => $content['msg'])); + } + $content['js'] .= 'window.close();'; + echo ''; + $GLOBALS['egw']->common->egw_exit(); + } + if ($content['js']) $content['js'] = ''; + } + // on a type-change, set the status to the default status of that type, if the actual status is not supported by the new type + if (!in_array($content['info_status'],$this->bo->status[$content['info_type']])) + { + $content['info_status'] = $this->bo->status['defaults'][$content['info_type']]; + if ($content['info_status'] != 'done') $content['info_datecompleted'] = ''; } - $readonlys = $values = array(); - $values['main'][1] = $this->get_info($info_id,$readonlys['main']); - - $this->tmpl->read('infolog.delete'); - - $values['nm'] = array( - 'action' => 'sp', - 'action_id' => $info_id, - 'options-filter' => $this->filters, - 'get_rows' => 'infolog.uiinfolog.get_rows', - 'no_filter2' => True, - 'never_hide' => isset($this->prefs['never_hide']) ? - $this->prefs['never_hide'] : - $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 15, - ); - $values['main']['no_actions'] = $values['nm']['no_actions'] = True; - - $persist['info_id'] = $info_id; - $persist['referer'] = $referer; - $persist['info_id_parent'] = $values['main'][1]['info_id_parent']; - $persist['called_by'] = $called_by; - - $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Delete'); - $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => 'ManualInfologDelete'); - - $this->tmpl->exec('infolog.uiinfolog.delete',$values,'',$readonlys,$persist,$called_by == 'edit' ? 2 : 0); } - - /** - * Edit/Create an InfoLog Entry - * - * @param array $content=null Content from the eTemplate Exec call or info_id on inital call - * @param string $action='' Name of an app of 'sp' for a infolog-sub - * @param int $action_id=0 Id of app-entry to which a link is created - * @param string $type='' Type of log-entry: note,todo,task - * @param string $referer='' array with param/get-vars of the refering page - */ - function edit($content = null,$action = '',$action_id=0,$type='',$referer='') + else { - $tabs = 'description|links|delegation|project|customfields'; + //echo "

uiinfolog::edit: info_id=$info_id, action='$action', action_id='$action_id', type='$type', referer='$referer'

\n"; + $action = $action ? $action : get_var('action', array('POST','GET')); + $action_id = $action_id ? $action_id : get_var('action_id',array('POST','GET')); + $info_id = $content ? $content : get_var('info_id', array('POST','GET')); + $type = $type ? $type : get_var('type', array('POST','GET')); + $ref=$referer = $referer !== '' ? $referer : ($_GET['referer'] ? $_GET['referer'] : + $GLOBALS['egw']->common->get_referer('/index.php?menuaction=infolog.uiinfolog.index')); + $referer = preg_replace('/([&?]{1})msg=[^&]+&?/','\\1',$referer); // remove previou/old msg from referer + $no_popup = $_GET['no_popup']; + //echo "

uiinfolog::edit: info_id=$info_id, action='$action', action_id='$action_id', type='$type', referer='$referer'

\n"; - if (is_array($content)) + $content = $this->bo->read( $info_id || $action != 'sp' ? $info_id : $action_id ); + + if (is_numeric($_REQUEST['cat_id'])) { - //echo "uiinfolog::edit: content="; _debug_array($content); - $info_id = $content['info_id']; - $action = $content['action']; - $action_id = $content['action_id']; - $referer = $content['referer']; - $no_popup = $content['no_popup']; - $caller = $content['caller']; - - if (isset($content['link_to']['primary'])) + $content['info_cat'] = (int) $_REQUEST['cat_id']; + } + switch($this->prefs['set_start']) + { + case 'date': default: $set_startdate = mktime(0,0,0,date('m',$this->bo->user_time_now),date('d',$this->bo->user_time_now),date('Y',$this->bo->user_time_now)); break; + case 'datetime': $set_startdate = $this->bo->user_time_now; break; + case 'empty': $set_startdate = 0; break; + } + if ((int)$content['info_link_id'] > 0 && !$this->link->get_link($content['info_link_id'])) + { + $content['info_link_id'] = 0; // link has been deleted + if (!$content['info_custom_link']) $content['info_from'] = ''; + } + if (!$info_id && $action_id && $action == 'sp') // new SubProject + { + if (!$this->bo->check_access($action_id,EGW_ACL_ADD)) { - $content['info_link_id'] = $content['link_to']['primary']; + return $referer ? $this->tmpl->location($referer) : $this->index(0,$action,$action_id); } - list($button) = @each($content['button']); - unset($content['button']); - if ($button) + $parent = $this->bo->so->data; + $content['info_id'] = $info_id = 0; + $content['info_owner'] = $this->user; + $content['info_id_parent'] = $parent['info_id']; + /* + if ($parent['info_type']=='task' && $parent['info_status']=='offer') { - //echo "

uiinfolog::edit(info_id=$info_id) '$button' button pressed, content="; _debug_array($content); - if (($button == 'save' || $button == 'apply') && $info_id) - { - if (!($edit_acl = $this->bo->check_access($info_id,EGW_ACL_EDIT))) - { - $old = $this->bo->read($info_id); - $status_only = in_array($this->user, $old['info_responsible']); - } - } - if (($button == 'save' || $button == 'apply') && (!$info_id || $edit_acl || $status_only)) - { - if (is_array($content['link_to']['to_id']) && count($content['link_to']['to_id'])) - { - if (strstr($content['info_link_id'],':') !== False) - { - $info_link_id = $content['info_link_id']; - $content['info_link_id'] = 0; // as field has to be int - } - } - $active_tab = $content[$tabs]; - if (!($info_id = $this->bo->write($content))) - { - $content['msg'] = $info_id !== 0 || !$content['info_id'] ? lang('Error: saving the entry') : - lang('Error: the entry has been updated since you opened it for editing!').'
'. - lang('Copy your changes to the clipboard, %1reload the entry%2 and merge them.','',''); - $button = ''; // not exiting edit - $info_id = $content['info_id']; - } - else - { - $content['msg'] = lang('InfoLog entry saved'); - if ($referer !== false) - { - $content['js'] = "opener.location.href='".($link=$GLOBALS['egw']->link($referer,array('msg' => $content['msg'])))."';"; - } - } - $content[$tabs] = $active_tab; - if ((int) $content['pm_id'] != (int) $content['old_pm_id']) - { - //echo "

pm_id changed: $content[old_pm_id] -> $content[pm_id]

\n"; - // update links accordingly, if selected project changed - if ($content['pm_id']) - { - //echo "

this->link->link('infolog',{$content['link_to']['to_id']},'projectmanager',{$content['pm_id']});

"; - $this->link->link('infolog',$content['link_to']['to_id'],'projectmanager',$content['pm_id']); - // making the project the selected link, if no other link selected - if (!$info_link_id || $info_link_id == 'projectmanager:'.$content['old_pm_id']) - { - $info_link_id = 'projectmanager:'.$content['pm_id']; - } - } - if ($content['old_pm_id']) - { - //echo "

this->link->unlink2(0,infolog,{$content['link_to']['to_id']},0,'projectmanager',{$content['old_pm_id']});

\n"; - $this->link->unlink2(0,infolog,$content['link_to']['to_id'],0,'projectmanager',$content['old_pm_id']); - $content['old_pm_id'] = $content['pm_id']; - } - } - // writing links for a new entry - if ($info_id && is_array($content['link_to']['to_id']) && count($content['link_to']['to_id'])) - { - $this->link->link('infolog',$info_id,$content['link_to']['to_id']); - $content['link_to']['to_id'] = $info_id; - } - if (strstr($info_link_id,':') !== false) // updating info_link_id if necessary - { - list($app,$id) = explode(':',$info_link_id); - $link = $this->link->get_link('infolog',$info_id,$app,$id); - if ((int) $content['info_link_id'] != (int) $link['link_id']) - { - $content['info_link_id'] = $link['link_id']; - - $to_write = array( - 'info_id' => $content['info_id'], - 'info_link_id' => $content['info_link_id'], - 'info_from' => $content['info_from'], - 'info_owner' => $content['info_owner'], - ); - $this->bo->write($to_write,False); - // we need eg. the new modification date, for further updates - $content = array_merge($content,$to_write); - } - } - } - elseif ($button == 'delete' && $info_id > 0) - { - if (!$referer && $action) $referer = array( - 'menuaction' => 'infolog.uiinfolog.index', - 'action' => $action, - 'action_id' => $action_id - ); - if (!($content['msg'] = $this->delete($info_id,$referer,'edit'))) return; // checks ACL first - - $content['js'] = "opener.location.href='".$GLOBALS['egw']->link($referer,array('msg' => $content['msg']))."';"; - } - // called again after delete confirmation dialog - elseif ($button == 'deleted' && $content['msg']) - { - $content['js'] = "opener.location.href='".$GLOBALS['egw']->link($referer,array('msg' => $content['msg']))."';"; - } - if ($button == 'save' || $button == 'cancel' || $button == 'delete' || $button == 'deleted') - { - if ($no_popup) - { - $GLOBALS['egw']->redirect_link($referer,array('msg' => $content['msg'])); - } - $content['js'] .= 'window.close();'; - echo ''; - $GLOBALS['egw']->common->egw_exit(); - } - if ($content['js']) $content['js'] = ''; + $content['info_type'] = 'confirm'; // confirmation to parent + $content['info_responsible'] = $parent['info_owner']; } - // on a type-change, set the status to the default status of that type, if the actual status is not supported by the new type - if (!in_array($content['info_status'],$this->bo->status[$content['info_type']])) + */ + $content['info_type'] = $parent['info_type']; + $content['info_status'] = $this->bo->status['defaults'][$content['info_type']]; + $content['info_percent'] = $content['info_status'] == 'done' ? '100%' : '0%'; + $content['info_datecompleted'] =$content['info_status'] == 'done' ? $this->bo->user_time_now : 0; + $content['info_confirm'] = 'not'; + $content['info_subject']=lang($this->messages['re']).' '.$parent['info_subject']; + $content['info_des'] = ''; + $content['info_lastmodified'] = ''; + if ($content['info_startdate'] < $this->bo->user_time_now) // parent-startdate is in the past => today { - $content['info_status'] = $this->bo->status['defaults'][$content['info_type']]; - if ($content['info_status'] != 'done') $content['info_datecompleted'] = ''; + $content['info_startdate'] = $set_startdate; + } + if ($content['info_enddate'] < $this->bo->user_time_now) // parent-enddate is in the past => empty + { + $content['info_enddate'] = ''; } } else { - //echo "

uiinfolog::edit: info_id=$info_id, action='$action', action_id='$action_id', type='$type', referer='$referer'

\n"; - $action = $action ? $action : get_var('action', array('POST','GET')); - $action_id = $action_id ? $action_id : get_var('action_id',array('POST','GET')); - $info_id = $content ? $content : get_var('info_id', array('POST','GET')); - $type = $type ? $type : get_var('type', array('POST','GET')); - $ref=$referer = $referer !== '' ? $referer : ($_GET['referer'] ? $_GET['referer'] : - $GLOBALS['egw']->common->get_referer('/index.php?menuaction=infolog.uiinfolog.index')); - $referer = preg_replace('/([&?]{1})msg=[^&]+&?/','\\1',$referer); // remove previou/old msg from referer - $no_popup = $_GET['no_popup']; - //echo "

uiinfolog::edit: info_id=$info_id, action='$action', action_id='$action_id', type='$type', referer='$referer'

\n"; - - $content = $this->bo->read( $info_id || $action != 'sp' ? $info_id : $action_id ); - - if (is_numeric($_REQUEST['cat_id'])) + if ($info_id && !$this->bo->check_access($info_id,EGW_ACL_EDIT) && !in_array($this->user, (array)$content['info_responsible'])) { - $content['info_cat'] = (int) $_REQUEST['cat_id']; - } - switch($this->prefs['set_start']) - { - case 'date': default: $set_startdate = mktime(0,0,0,date('m',$this->bo->user_time_now),date('d',$this->bo->user_time_now),date('Y',$this->bo->user_time_now)); break; - case 'datetime': $set_startdate = $this->bo->user_time_now; break; - case 'empty': $set_startdate = 0; break; - } - if (intval($content['info_link_id']) > 0 && !$this->link->get_link($content['info_link_id'])) - { - $content['info_link_id'] = 0; // link has been deleted - } - - if (!$info_id && $action_id && $action == 'sp') // new SubProject - { - if (!$this->bo->check_access($action_id,EGW_ACL_ADD)) + if ($no_popup) { - return $referer ? $this->tmpl->location($referer) : $this->index(0,$action,$action_id); + $GLOBALS['egw']->common->egw_header(); + parse_navbar(); + echo '

'.lang('Permission denied')."

\n"; + $GLOBALS['egw']->common->egw_exit(); } - $parent = $this->bo->so->data; - $content['info_id'] = $info_id = 0; + $js = "alert('".lang('Permission denied')."'); window.close();"; + echo ''; + $GLOBALS['egw']->common->egw_exit(); + } + } + $content['links'] = $content['link_to'] = array( + 'to_id' => $info_id, + 'to_app' => 'infolog', + ); + switch ($action) + { + case 'sp': + $links = $this->link->get_links('infolog',$parent['info_id'],'!'.$this->link->vfs_appname); + foreach($links as $link) + { + $link_id = $this->link->link('infolog',$content['link_to']['to_id'],$link['app'],$link['id'],$link['remark']); + + if ($parent['info_link_id'] == $link['link_id']) + { + $content['info_link_id'] = $link_id; + } + } + break; + + case 'projectmanager': + $pm_links = array($action_id); + case 'addressbook': + case 'projects': + case 'calendar': + default: // to allow other apps to participate + $content['info_link_id'] = $this->link->link('infolog',$content['link_to']['to_id'],$action,$action_id); + $content['blur_title'] = $this->link->title($action,$action_id); + + case '': + if ($info_id) + { + if (!isset($pm_links)) + { + $pm_links = $this->link->get_links('infolog',$info_id,'projectmanager'); + } + break; // normal edit + } + case 'new': // new entry + $content['info_startdate'] = (int) $_GET['startdate'] ? (int) $_GET['startdate'] : $set_startdate; + $content['info_priority'] = 1; // normal $content['info_owner'] = $this->user; - $content['info_id_parent'] = $parent['info_id']; - /* - if ($parent['info_type']=='task' && $parent['info_status']=='offer') + if ($type != '') { - $content['info_type'] = 'confirm'; // confirmation to parent - $content['info_responsible'] = $parent['info_owner']; + $content['info_type'] = $type; } - */ - $content['info_type'] = $parent['info_type']; $content['info_status'] = $this->bo->status['defaults'][$content['info_type']]; $content['info_percent'] = $content['info_status'] == 'done' ? '100%' : '0%'; - $content['info_datecompleted'] =$content['info_status'] == 'done' ? $this->bo->user_time_now : 0; - $content['info_confirm'] = 'not'; - $content['info_subject']=lang($this->messages['re']).' '.$parent['info_subject']; - $content['info_des'] = ''; - $content['info_lastmodified'] = ''; - if ($content['info_startdate'] < $this->bo->user_time_now) // parent-startdate is in the past => today - { - $content['info_startdate'] = $set_startdate; - } - if ($content['info_enddate'] < $this->bo->user_time_now) // parent-enddate is in the past => empty - { - $content['info_enddate'] = ''; - } - } - else - { - if ($info_id && !$this->bo->check_access($info_id,EGW_ACL_EDIT) && !in_array($this->user, (array)$content['info_responsible'])) - { - if ($no_popup) - { - $GLOBALS['egw']->common->egw_header(); - parse_navbar(); - echo '

'.lang('Permission denied')."

\n"; - $GLOBALS['egw']->common->egw_exit(); - } - $js = "alert('".lang('Permission denied')."'); window.close();"; - echo ''; - $GLOBALS['egw']->common->egw_exit(); - } - } - $content['links'] = $content['link_to'] = array( - 'to_id' => $info_id, - 'to_app' => 'infolog', - ); - switch ($action) - { - case 'sp': - $links = $this->link->get_links('infolog',$parent['info_id'],'!'.$this->link->vfs_appname); - foreach($links as $link) - { - $link_id = $this->link->link('infolog',$content['link_to']['to_id'],$link['app'],$link['id'],$link['remark']); - - if ($parent['info_link_id'] == $link['link_id']) - { - $content['info_link_id'] = $link_id; - } - } - break; - - case 'projectmanager': - $pm_links = array($action_id); - case 'addressbook': - case 'projects': - case 'calendar': - default: // to allow other apps to participate - $content['info_link_id'] = $this->link->link('infolog',$content['link_to']['to_id'],$action,$action_id); - $content['blur_title'] = $this->link->title($action,$action_id); - - case '': - if ($info_id) - { - if (!isset($pm_links)) - { - $pm_links = $this->link->get_links('infolog',$info_id,'projectmanager'); - } - break; // normal edit - } - case 'new': // new entry - $content['info_startdate'] = (int) $_GET['startdate'] ? (int) $_GET['startdate'] : $set_startdate; - $content['info_priority'] = 1; // normal - $content['info_owner'] = $this->user; - if ($type != '') - { - $content['info_type'] = $type; - } - $content['info_status'] = $this->bo->status['defaults'][$content['info_type']]; - $content['info_percent'] = $content['info_status'] == 'done' ? '100%' : '0%'; - break; - } - if (!isset($this->bo->enums['type'][$content['info_type']])) - { - $content['info_type'] = 'note'; - } + break; } - // for implizit edit of responsible user make all fields readonly, but status and percent - if ($info_id && !$this->bo->check_access($info_id,EGW_ACL_EDIT) && in_array($this->user, (array)$content['info_responsible'])) + if (!isset($this->bo->enums['type'][$content['info_type']])) { - $content['status_only'] = !in_array('link_to',$this->bo->responsible_edit); - foreach(array_diff(array_merge(array_keys($content),array('pm_id')),$this->bo->responsible_edit) as $name) - { - $readonlys[$name] = true; - } - // need to set all customfields extra, as they are not set if empty - foreach($this->bo->customfields as $name => $value) - { - $readonlys['#'.$name] = true; - } + $content['info_type'] = 'note'; } - // we allways need to set a non-empty/-zero primary, to make the radiobutton appear - $content['link_to']['primary'] = $content['info_link_id'] ? $content['info_link_id'] : '#'; - - if (!($readonlys['button[delete]'] = !$info_id || !$this->bo->check_access($info_id,EGW_ACL_DELETE))) - { - $content['info_anz_subs'] = $this->bo->anzSubs($info_id); // to determine js confirmation of delete or not - } - $GLOBALS['egw_info']['flags']['app_header'] = lang($this->messages[$info_id ? 'edit' : ($action == 'sp' ? 'add_sub' : 'add')]); - - // use a typ-specific template (infolog.edit.xyz), if one exists, otherwise fall back to the generic one - if (!$this->tmpl->read('infolog.edit.'.$content['info_type'])) - { - $this->tmpl->read('infolog.edit'); - } - if ($this->bo->has_customfields($content['info_type'])) - { - $content['customfields'] = $this->bo->customfields; - $content['customfields']['###typ###'] = $content['info_type']; - } - else - { - $readonlys[$tabs] = array('customfields' => true); - } - if (!isset($GLOBALS['egw_info']['user']['apps']['projectmanager'])) - { - $readonlys[$tabs]['project'] = true; // disable the project tab - } - $readonlys[$tabs]['delegation'] = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'none' && - !isset($GLOBALS['egw_info']['user']['apps']['admin']); - - $content['duration_format'] = $this->duration_format; - - // make the content of the first linked address availible to show in a custom template - if ($this->tmpl->name != 'infolog.edit' && - ($addr = $this->link->get_links('infolog',$content['link_to']['to_id'],'addressbook')) && - ($contact_id = array_shift($addr)) && ($addr = ExecMethod('phpgwapi.contacts.read',$contact_id))) - { - foreach($addr as $name => $value) - { - $content['~'.$name] = $value; - } - } - $old_pm_id = is_array($pm_links) ? array_shift($pm_links) : $content['old_pm_id']; - if (!isset($content['pm_id']) && $old_pm_id) $content['pm_id'] = $old_pm_id; - - $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '. - ($content['status_only'] ? lang('Edit Status') : lang('Edit')); - $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => ($info_id ? 'ManualInfologEdit' : 'ManualInfologAdd')); - //echo "

uiinfolog.edit(info_id='$info_id',action='$action',action_id='$action_id') readonlys="; print_r($readonlys); echo ", content = "; _debug_array($content); - $this->tmpl->exec('infolog.uiinfolog.edit',$content,array( - 'info_type' => $this->bo->enums['type'], - 'info_priority' => $this->bo->enums['priority'], - 'info_confirm' => $this->bo->enums['confirm'], - 'info_status' => $this->bo->status[$content['info_type']] - ),$readonlys,array( // preserved values - 'info_id' => $info_id, - 'info_id_parent'=> $content['info_id_parent'], - 'info_link_id' => $content['info_link_id'], - 'info_owner' => $content['info_owner'], - 'info_datemodified' => $content['info_datemodified'], - 'info_modifier' => $content['info_modifier'], - 'action' => $action, - 'action_id' => $action_id, - 'referer' => $referer, - 'no_popup' => $no_popup, - 'link_to' => array('to_id' => $content['link_to']['to_id']), // in case tab gets not viewed - 'blur_title' => $content['blur_title'], - 'old_pm_id' => $old_pm_id, - // preserv project fields, in case project tab is disabled, but user has rights to edit the entry - 'pl_id' => $content['pl_id'], - 'info_price' => $content['info_price'], - 'info_used_time' => $content['info_used_time'], - 'info_planned_time' => $content['info_planned_time'], - ),$no_popup ? 0 : 2); } - - function menuaction($action = 'get_list',$app='infolog') + // for implizit edit of responsible user make all fields readonly, but status and percent + if ($info_id && !$this->bo->check_access($info_id,EGW_ACL_EDIT) && in_array($this->user, (array)$content['info_responsible'])) { - return array( 'menuaction' => "$app.ui$app.$action" ); + $content['status_only'] = !in_array('link_to',$this->bo->responsible_edit); + foreach(array_diff(array_merge(array_keys($content),array('pm_id')),$this->bo->responsible_edit) as $name) + { + $readonlys[$name] = true; + } + // need to set all customfields extra, as they are not set if empty + foreach($this->bo->customfields as $name => $value) + { + $readonlys['#'.$name] = true; + } } + // we allways need to set a non-empty/-zero primary, to make the radiobutton appear +// $content['link_to']['primary'] = $content['info_link_id'] ? $content['info_link_id'] : '#'; + $content['hide_from_css'] = $content['info_custom_from'] ? '' : 'hideFrom'; - function icon($cat,$id,$status='') + if (!($readonlys['button[delete]'] = !$info_id || !$this->bo->check_access($info_id,EGW_ACL_DELETE))) { - if (!$status || !($icon = $this->icons[$cat][$id.'_'.$status])) - { - $icon = $this->icons[$cat][$id]; - } - if ($icon && !is_readable($GLOBALS['egw']->common->get_image_dir() . '/' . $icon)) - { - $icon = False; - } - if (!$status || !($alt = $this->icons[$cat][$id.'_'.$status.'_alt'])) - { - if (!($alt = $this->icons[$cat][$id.'_alt'])) - { - $alt = $id; - } - } - return $icon ? $this->html->image('infolog',$icon,lang($alt),'border=0') : lang($alt); + $content['info_anz_subs'] = $this->bo->anzSubs($info_id); // to determine js confirmation of delete or not } + $GLOBALS['egw_info']['flags']['app_header'] = lang($this->messages[$info_id ? 'edit' : ($action == 'sp' ? 'add_sub' : 'add')]); - function admin( ) + // use a typ-specific template (infolog.edit.xyz), if one exists, otherwise fall back to the generic one + if (!$this->tmpl->read('infolog.edit.'.$content['info_type'])) { - $fields = array( - 'info_cat' => 'Category', - 'info_from' => 'Contact', - 'info_addr' => 'Phone/Email', - 'info_subject' => 'Subject', - 'info_des' => 'Description', - 'link_to' => 'Links', - 'info_priority' => 'Priority', - 'info_location' => 'Location', - 'info_planned_time' => 'Planned time', - 'info_used_time' => 'Used time', - ); - if($_POST['save'] || $_POST['apply']) - { - $this->link_pathes = $this->bo->send_file_ips = array(); - - $valid = get_var('valid',Array('POST')); - $trans = get_var('trans',Array('POST')); - $ip = get_var('ip',Array('POST')); - while(list($key,$val) = each($valid)) - { - if($val = stripslashes($val)) - { - $this->link_pathes[$val] = stripslashes($trans[$key]); - $this->bo->send_file_ips[$val] = stripslashes($ip[$key]); - } - } - $this->bo->responsible_edit = array('info_status','info_percent','info_datecompleted'); - if ($_POST['responsible_edit']) - { - $extra = array_intersect($_POST['responsible_edit'],array_keys($fields)); - $this->bo->responsible_edit = array_merge($this->bo->responsible_edit,$extra); - } - $this->bo->implicit_rights = $_POST['implicit_rights'] == 'edit' ? 'edit' : 'read'; - $this->bo->config->config_data = array( - 'link_pathes' => $this->link_pathes, - 'send_file_ips' => $this->bo->send_file_ips, - 'implicit_rights' => $this->bo->implicit_rights, - 'responsible_edit' => implode(',',$extra), - ); - $this->bo->config->save_repository(True); - } - if($_POST['cancel'] || $_POST['save']) - { - $GLOBALS['egw']->redirect_link('/admin/index.php'); - } - - $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Configuration'); - $GLOBALS['egw']->common->egw_header(); - - $GLOBALS['egw']->template->set_file(array('info_admin_t' => 'admin.tpl')); - $GLOBALS['egw']->template->set_block('info_admin_t', 'admin_line'); - $GLOBALS['egw']->template->set_block('info_admin_t', 'info_admin'); - - $GLOBALS['egw']->template->set_var(Array( - 'lang_responsible_rights' => lang('Rights for the responsible'), - 'lang_implicit_rights' => lang('Which implicit ACL rights should the responsible get?'), - 'implicit_rights' => $this->html->select('implicit_rights',$this->bo->implicit_rights,array( - 'read' => 'read rights (default)', - 'edit' => 'edit rights (full edit rights incl. making someone else responsible!)', - )), - 'lang_responsible_edit' => lang('Which additional fields should the responsible be allowed to edit without having edit rights?
Status, percent and date completed are always allowed.'), - 'responsible_edit' => $this->html->checkbox_multiselect('responsible_edit',$this->bo->responsible_edit,$fields,false,'',11), - 'text' => lang('file-attachments via symlinks instead of uploads and retrieval via file:/path for direct lan-clients'), - 'action_url' => $this->html->link('/index.php',$this->menuaction('admin')), - 'save_button' => $this->html->submit_button('save','Save'), - 'apply_button' => $this->html->submit_button('apply','Apply'), - 'cancel_button' => $this->html->submit_button('cancel','Cancel'), - 'lang_valid' => lang('valid path on clientside
eg. \\\\Server\\Share or e:\\'), - 'lang_trans' => lang('path on (web-)serverside
eg. /var/samba/Share'), - 'lang_ip' => lang('reg. expr. for local IP\'s
eg. ^192\\.168\\.1\\.') - )); - - if (!is_array($this->bo->send_file_ips)) - { - $this->bo->send_file_ips = $this->link_pathes = array(); - } - $i = 0; @reset($this->link_pathes); - do { - list($valid,$trans) = @each($this->link_pathes); - $GLOBALS['egw']->template->set_var(array( - 'tr_color' => $i & 1 ? 'row_off' : 'row_on', - 'num' => $i+1, - 'val_valid' => $this->html->input("valid[$i]",$valid), - 'val_trans' => $this->html->input("trans[$i]",$trans), - 'val_ip' => $this->html->input("ip[$i]",$this->bo->send_file_ips[$valid]) - )); - $GLOBALS['egw']->template->parse('admin_lines','admin_line',True); - ++$i; - } while ($valid); - - if (!$this->tmpl->xslt) - { - echo parse_navbar(); - $GLOBALS['egw']->template->pfp('phpgw_body','info_admin'); - } - else - { - $GLOBALS['egw']->template->fp('phpgw_body','info_admin'); - } + $this->tmpl->read('infolog.edit'); } + if ($this->bo->has_customfields($content['info_type'])) + { + $content['customfields'] = $content['info_type']; + } + else + { + $readonlys[$tabs] = array('customfields' => true); + } + if (!isset($GLOBALS['egw_info']['user']['apps']['projectmanager'])) + { + $readonlys[$tabs]['project'] = true; // disable the project tab + } + $readonlys[$tabs]['delegation'] = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'none' && + !isset($GLOBALS['egw_info']['user']['apps']['admin']); + + $content['duration_format'] = $this->duration_format; - /** - * imports a mail as infolog - * two possible calls: - * 1. with function args set. (we come from send mail) - * 2. with $_GET['uid] = someuid (we come from display mail) - * - * @author Cornelius Weiss - * @param unknown_type $_to_emailAddress - * @param string $_subject - * @param string $_body - * @param array $_attachments - * @param string $_date - */ - function import_mail($_to_emailAddress=false,$_subject=false,$_body=false,$_attachments=false,$_date=false) + // make the content of the first linked address availible to show in a custom template + if ($this->tmpl->name != 'infolog.edit' && + ($addr = $this->link->get_links('infolog',$content['link_to']['to_id'],'addressbook')) && + ($contact_id = array_shift($addr)) && ($addr = ExecMethod('phpgwapi.contacts.read',$contact_id))) { - $uid = $_GET['uid']; - $mailbox = $_GET['mailbox']; - - if (!empty($_to_emailAddress)) + foreach($addr as $name => $value) { - $GLOBALS['egw_info']['flags']['currentapp'] = 'infolog'; - $GLOBALS['egw']->translation->add_app($GLOBALS['egw_info']['flags']['currentapp']); - echo ''; - - if (is_array($_attachments)) - { - foreach ($_attachments as $attachment) - { - $attachments[] = array( - 'name' => $attachment['name'], - 'mimeType' => $attachment['type'], - 'tmp_name' => $attachment['file'], - 'size' => $attachment['size'], - ); - } - } - - $this->edit($this->bo->import_mail( - implode(',',$_to_emailAddress),$_subject,$_body,$attachments,'' - )); - exit; + $content['~'.$name] = $value; } - elseif ($uid && $mailbox) + } + $old_pm_id = is_array($pm_links) ? array_shift($pm_links) : $content['old_pm_id']; + if (!isset($content['pm_id']) && $old_pm_id) $content['pm_id'] = $old_pm_id; + + $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '. + ($content['status_only'] ? lang('Edit Status') : lang('Edit')); + $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => ($info_id ? 'ManualInfologEdit' : 'ManualInfologAdd')); + //echo "

uiinfolog.edit(info_id='$info_id',action='$action',action_id='$action_id') readonlys="; print_r($readonlys); echo ", content = "; _debug_array($content); + $this->tmpl->exec('infolog.uiinfolog.edit',$content,array( + 'info_type' => $this->bo->enums['type'], + 'info_priority' => $this->bo->enums['priority'], + 'info_confirm' => $this->bo->enums['confirm'], + 'info_status' => $this->bo->status[$content['info_type']] + ),$readonlys,array( // preserved values + 'info_id' => $info_id, + 'info_id_parent'=> $content['info_id_parent'], + 'info_link_id' => $content['info_link_id'], + 'info_owner' => $content['info_owner'], + 'info_datemodified' => $content['info_datemodified'], + 'info_modifier' => $content['info_modifier'], + 'action' => $action, + 'action_id' => $action_id, + 'referer' => $referer, + 'no_popup' => $no_popup, + 'link_to' => array('to_id' => $content['link_to']['to_id']), // in case tab gets not viewed + 'blur_title' => $content['blur_title'], + 'old_pm_id' => $old_pm_id, + // preserv project fields, in case project tab is disabled, but user has rights to edit the entry + 'pl_id' => $content['pl_id'], + 'info_price' => $content['info_price'], + 'info_used_time' => $content['info_used_time'], + 'info_planned_time' => $content['info_planned_time'], + ),$no_popup ? 0 : 2); + } + + function menuaction($action = 'get_list',$app='infolog') + { + return array( 'menuaction' => "$app.ui$app.$action" ); + } + + function icon($cat,$id,$status='') + { + if (!$status || !($icon = $this->icons[$cat][$id.'_'.$status])) + { + $icon = $this->icons[$cat][$id]; + } + if ($icon && !is_readable($GLOBALS['egw']->common->get_image_dir() . '/' . $icon)) + { + $icon = False; + } + if (!$status || !($alt = $this->icons[$cat][$id.'_'.$status.'_alt'])) + { + if (!($alt = $this->icons[$cat][$id.'_alt'])) { - $bofelamimail =& CreateObject('felamimail.bofelamimail',$GLOBALS['egw']->translation->charset()); - $bopreferences =& CreateObject('felamimail.bopreferences'); - $bofelamimail->openConnection(); - - $headers = $bofelamimail->getMessageHeader($mailbox,$uid); - $bodyParts = $bofelamimail->getMessageBody($uid,''); - $attachments = $bofelamimail->getMessageAttachments($uid); - - if (isset($headers->senderaddress)) $mailaddress = $bofelamimail->decode_header($headers->senderaddress); - elseif (isset($headers->fromaddress)) $mailaddress = $bofelamimail->decode_header($headers->fromaddress); + $alt = $id; + } + } + return $icon ? $this->html->image('infolog',$icon,lang($alt),'border=0') : lang($alt); + } + + function admin( ) + { + $fields = array( + 'info_cat' => 'Category', + 'info_from' => 'Contact', + 'info_addr' => 'Phone/Email', + 'info_subject' => 'Subject', + 'info_des' => 'Description', + 'link_to' => 'Links', + 'info_priority' => 'Priority', + 'info_location' => 'Location', + 'info_planned_time' => 'Planned time', + 'info_used_time' => 'Used time', + ); + if($_POST['save'] || $_POST['apply']) + { + $this->link_pathes = $this->bo->send_file_ips = array(); + + $valid = get_var('valid',Array('POST')); + $trans = get_var('trans',Array('POST')); + $ip = get_var('ip',Array('POST')); + while(list($key,$val) = each($valid)) + { + if($val = stripslashes($val)) + { + $this->link_pathes[$val] = stripslashes($trans[$key]); + $this->bo->send_file_ips[$val] = stripslashes($ip[$key]); + } + } + $this->bo->responsible_edit = array('info_status','info_percent','info_datecompleted'); + if ($_POST['responsible_edit']) + { + $extra = array_intersect($_POST['responsible_edit'],array_keys($fields)); + $this->bo->responsible_edit = array_merge($this->bo->responsible_edit,$extra); + } + $this->bo->implicit_rights = $_POST['implicit_rights'] == 'edit' ? 'edit' : 'read'; + $this->bo->config->config_data = array( + 'link_pathes' => $this->link_pathes, + 'send_file_ips' => $this->bo->send_file_ips, + 'implicit_rights' => $this->bo->implicit_rights, + 'responsible_edit' => implode(',',$extra), + ); + $this->bo->config->save_repository(True); + } + if($_POST['cancel'] || $_POST['save']) + { + $GLOBALS['egw']->redirect_link('/admin/index.php'); + } + + $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Configuration'); + $GLOBALS['egw']->common->egw_header(); + + $GLOBALS['egw']->template->set_file(array('info_admin_t' => 'admin.tpl')); + $GLOBALS['egw']->template->set_block('info_admin_t', 'admin_line'); + $GLOBALS['egw']->template->set_block('info_admin_t', 'info_admin'); + + $GLOBALS['egw']->template->set_var(Array( + 'lang_responsible_rights' => lang('Rights for the responsible'), + 'lang_implicit_rights' => lang('Which implicit ACL rights should the responsible get?'), + 'implicit_rights' => $this->html->select('implicit_rights',$this->bo->implicit_rights,array( + 'read' => 'read rights (default)', + 'edit' => 'edit rights (full edit rights incl. making someone else responsible!)', + )), + 'lang_responsible_edit' => lang('Which additional fields should the responsible be allowed to edit without having edit rights?
Status, percent and date completed are always allowed.'), + 'responsible_edit' => $this->html->checkbox_multiselect('responsible_edit',$this->bo->responsible_edit,$fields,false,'',11), + 'text' => lang('file-attachments via symlinks instead of uploads and retrieval via file:/path for direct lan-clients'), + 'action_url' => $this->html->link('/index.php',$this->menuaction('admin')), + 'save_button' => $this->html->submit_button('save','Save'), + 'apply_button' => $this->html->submit_button('apply','Apply'), + 'cancel_button' => $this->html->submit_button('cancel','Cancel'), + 'lang_valid' => lang('valid path on clientside
eg. \\\\Server\\Share or e:\\'), + 'lang_trans' => lang('path on (web-)serverside
eg. /var/samba/Share'), + 'lang_ip' => lang('reg. expr. for local IP\'s
eg. ^192\\.168\\.1\\.') + )); + + if (!is_array($this->bo->send_file_ips)) + { + $this->bo->send_file_ips = $this->link_pathes = array(); + } + $i = 0; @reset($this->link_pathes); + do { + list($valid,$trans) = @each($this->link_pathes); + $GLOBALS['egw']->template->set_var(array( + 'tr_color' => $i & 1 ? 'row_off' : 'row_on', + 'num' => $i+1, + 'val_valid' => $this->html->input("valid[$i]",$valid), + 'val_trans' => $this->html->input("trans[$i]",$trans), + 'val_ip' => $this->html->input("ip[$i]",$this->bo->send_file_ips[$valid]) + )); + $GLOBALS['egw']->template->parse('admin_lines','admin_line',True); + ++$i; + } while ($valid); + + if (!$this->tmpl->xslt) + { + echo parse_navbar(); + $GLOBALS['egw']->template->pfp('phpgw_body','info_admin'); + } + else + { + $GLOBALS['egw']->template->fp('phpgw_body','info_admin'); + } + } - $subject = $bofelamimail->decode_header($headers->Subject); - - // this should be a method of felamimail! - // We also need a html2text converter there! - for($i=0; $itranslation->convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); - $newBody = explode("\n",$newBody); - // create it new, with good line breaks - reset($newBody); - while(list($key,$value) = @each($newBody)) - { - $value .= "\n"; - $bodyAppend = $bofelamimail->wordwrap($value,75,"\n"); - $message .= $bodyAppend; - } - } + /** + * imports a mail as infolog + * two possible calls: + * 1. with function args set. (we come from send mail) + * 2. with $_GET['uid] = someuid (we come from display mail) + * + * @author Cornelius Weiss + * @param unknown_type $_to_emailAddress + * @param string $_subject + * @param string $_body + * @param array $_attachments + * @param string $_date + */ + function import_mail($_to_emailAddress=false,$_subject=false,$_body=false,$_attachments=false,$_date=false) + { + $uid = $_GET['uid']; + $mailbox = $_GET['mailbox']; + + if (!empty($_to_emailAddress)) + { + $GLOBALS['egw_info']['flags']['currentapp'] = 'infolog'; + $GLOBALS['egw']->translation->add_app($GLOBALS['egw_info']['flags']['currentapp']); + echo ''; - if (is_array($attachments)) + if (is_array($_attachments)) + { + foreach ($_attachments as $attachment) { - foreach ($attachments as $num => $attachment) - { - $attachments[$num] = array_merge($attachments[$num],$bofelamimail->getAttachment($_uid, $attachment['partID'])); - $attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); - $tmpfile = fopen($attachments[$num]['tmp_name'],'w'); - fwrite($tmpfile,$attachments[$num]['attachment']); - fclose($tmpfile); - unset($attachments[$num]['attachment']); - } + $attachments[] = array( + 'name' => $attachment['name'], + 'mimeType' => $attachment['type'], + 'tmp_name' => $attachment['file'], + 'size' => $attachment['size'], + ); } - - return $this->edit($this->bo->import_mail( - $mailaddress, - $subject, - $message, - $attachments, - strtotime($headers->date) - )); } - $GLOBALS['egw']->common->egw_header(); - echo ""; - $GLOBALS['egw']->common->egw_exit(); + + $this->edit($this->bo->import_mail( + implode(',',$_to_emailAddress),$_subject,$_body,$attachments,'' + )); exit; } - - /** - * writes langfile with all templates and messages registered here - * - * called via [write Langfile] in the etemplate-editor or as http://domain/egroupware/index.php?menuaction=infolog.uiinfolog.writeLangFile - */ - function writeLangFile() + elseif ($uid && $mailbox) { - $extra = $this->messages + $this->filters; - $enums = $this->bo->enums + $this->bo->status; - unset($enums['defaults']); - foreach($enums as $key => $msg_arr) + $bofelamimail =& CreateObject('felamimail.bofelamimail',$GLOBALS['egw']->translation->charset()); + $bopreferences =& CreateObject('felamimail.bopreferences'); + $bofelamimail->openConnection(); + + $headers = $bofelamimail->getMessageHeader($mailbox,$uid); + $bodyParts = $bofelamimail->getMessageBody($uid,''); + $attachments = $bofelamimail->getMessageAttachments($uid); + + if (isset($headers->senderaddress)) $mailaddress = $bofelamimail->decode_header($headers->senderaddress); + elseif (isset($headers->fromaddress)) $mailaddress = $bofelamimail->decode_header($headers->fromaddress); + + $subject = $bofelamimail->decode_header($headers->Subject); + + // this should be a method of felamimail! + // We also need a html2text converter there! + for($i=0; $itranslation->convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); + $newBody = explode("\n",$newBody); + // create it new, with good line breaks + reset($newBody); + while(list($key,$value) = @each($newBody)) + { + $value .= "\n"; + $bodyAppend = $bofelamimail->wordwrap($value,75,"\n"); + $message .= $bodyAppend; + } + } + + if (is_array($attachments)) + { + foreach ($attachments as $num => $attachment) + { + $attachments[$num] = array_merge($attachments[$num],$bofelamimail->getAttachment($_uid, $attachment['partID'])); + $attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); + $tmpfile = fopen($attachments[$num]['tmp_name'],'w'); + fwrite($tmpfile,$attachments[$num]['attachment']); + fclose($tmpfile); + unset($attachments[$num]['attachment']); + } } - return $this->tmpl->writeLangFile('infolog','en',$extra); + + return $this->edit($this->bo->import_mail( + $mailaddress, + $subject, + $message, + $attachments, + strtotime($headers->date) + )); } - - /** - * shows infolog in other applications - * - * @param $args['location'] location des hooks: {addressbook|projects|calendar}_view|infolog - * @param $args['view'] menuaction to view, if location == 'infolog' - * @param $args['app'] app-name, if location == 'infolog' - * @param $args['view_id'] name of the id-var for location == 'infolog' - * @param $args[$args['view_id']] id of the entry - * this function can be called for any app, which should include infolog: \ - * $GLOBALS['egw']->hooks->process(array( \ - * * 'location' => 'infolog', \ - * * 'app' => , \ - * * 'view_id' => , \ - * * => , \ - * * 'view' => \ - * )); - */ - function hook_view($args) - { - switch ($args['location']) - { - case 'addressbook_view': - $app = 'addressbook'; - $view_id = 'ab_id'; - $view_id2 = 'contact_id'; - $view = 'addressbook.uicontacts.view'; - break; - case 'projects_view': - $app = 'projects'; - $view_id = 'project_id'; - $view = 'projects.uiprojects.view'; - break; - default: - $app = $args['app']; - $view_id = $args['view_id']; - $view = $args['view']; - } - if (!is_array($args) || $args['debug']) - { - echo "

uiinfolog::hook_view("; print_r($args); echo "): app='$app', $view_id='$args[$view_id]', view='$view'

\n"; - } - if (!isset($app) || !isset($args[$view_id])) - { - return False; - } - $this->called_by = $app; // for read/save_sessiondata, to have different sessions for the hooks - - $GLOBALS['egw']->translation->add_app('infolog'); - - $GLOBALS['egw_info']['etemplate']['hooked'] = True; - $this->index(0,$app,$args[$view_id],array( - 'menuaction' => $view, - isset($view_id2) ? $view_id2 : $view_id => $args[$view_id] - ),True); - unset($GLOBALS['egw_info']['etemplate']['hooked']); - } + $GLOBALS['egw']->common->egw_header(); + echo ""; + $GLOBALS['egw']->common->egw_exit(); + exit; } + + /** + * writes langfile with all templates and messages registered here + * + * called via [write Langfile] in the etemplate-editor or as http://domain/egroupware/index.php?menuaction=infolog.uiinfolog.writeLangFile + */ + function writeLangFile() + { + $extra = $this->messages + $this->filters; + $enums = $this->bo->enums + $this->bo->status; + unset($enums['defaults']); + foreach($enums as $key => $msg_arr) + { + $extra += $msg_arr; + } + return $this->tmpl->writeLangFile('infolog','en',$extra); + } + + /** + * shows infolog in other applications + * + * @param $args['location'] location des hooks: {addressbook|projects|calendar}_view|infolog + * @param $args['view'] menuaction to view, if location == 'infolog' + * @param $args['app'] app-name, if location == 'infolog' + * @param $args['view_id'] name of the id-var for location == 'infolog' + * @param $args[$args['view_id']] id of the entry + * this function can be called for any app, which should include infolog: \ + * $GLOBALS['egw']->hooks->process(array( \ + * * 'location' => 'infolog', \ + * * 'app' => , \ + * * 'view_id' => , \ + * * => , \ + * * 'view' => \ + * )); + */ + function hook_view($args) + { + switch ($args['location']) + { + case 'addressbook_view': + $app = 'addressbook'; + $view_id = 'ab_id'; + $view_id2 = 'contact_id'; + $view = 'addressbook.uicontacts.view'; + break; + case 'projects_view': + $app = 'projects'; + $view_id = 'project_id'; + $view = 'projects.uiprojects.view'; + break; + default: + $app = $args['app']; + $view_id = $args['view_id']; + $view = $args['view']; + } + if (!is_array($args) || $args['debug']) + { + echo "

uiinfolog::hook_view("; print_r($args); echo "): app='$app', $view_id='$args[$view_id]', view='$view'

\n"; + } + if (!isset($app) || !isset($args[$view_id])) + { + return False; + } + $this->called_by = $app; // for read/save_sessiondata, to have different sessions for the hooks + + $GLOBALS['egw']->translation->add_app('infolog'); + + $GLOBALS['egw_info']['etemplate']['hooked'] = True; + $this->index(0,$app,$args[$view_id],array( + 'menuaction' => $view, + isset($view_id2) ? $view_id2 : $view_id => $args[$view_id] + ),True); + unset($GLOBALS['egw_info']['etemplate']['hooked']); + } +} diff --git a/infolog/index.php b/infolog/index.php index 325f68611f..faad220806 100644 --- a/infolog/index.php +++ b/infolog/index.php @@ -1,22 +1,21 @@ * -* originaly based on todo written by Joseph Engo * -* -------------------------------------------- * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU General Public License as published by the * -* Free Software Foundation; either version 2 of the License, or (at your * -* option) any later version. * -\**************************************************************************/ +/** + * InfoLog + * + * @link http://www.egroupware.org + * @author Ralf Becker + * @package infolog + * @copyright (c) 2003-6 by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ -/* $Id$ */ - -$GLOBALS['egw_info']['flags'] = array( - 'currentapp' => 'infolog', - 'noheader' => True, - 'nonavbar' => True +$GLOBALS['egw_info'] = array( + 'flags' => array( + 'currentapp' => 'infolog', + 'noheader' => True, + 'nonavbar' => True, + ) ); include('../header.inc.php'); @@ -35,4 +34,3 @@ unset($setup_info); ExecMethod('infolog.uiinfolog.index','reset_action_view'); $GLOBALS['egw']->common->egw_exit(); -?> diff --git a/infolog/setup/etemplates.inc.php b/infolog/setup/etemplates.inc.php index 0f0d102874..1e58f1a7e8 100644 --- a/infolog/setup/etemplates.inc.php +++ b/infolog/setup/etemplates.inc.php @@ -2,7 +2,7 @@ /** * eGroupWare - eTemplates for Application infolog * http://www.egroupware.org - * generated by soetemplate::dump4setup() 2006-09-27 16:58 + * generated by soetemplate::dump4setup() 2006-10-04 19:40 * * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @package infolog @@ -14,16 +14,16 @@ $templ_version=1; $templ_data[] = array('name' => 'infolog%','template' => '','lang' => '','group' => '0','version' => '1.0.1.001','data' => 'a:1:{i:0;a:5:{s:4:"type";s:4:"grid";s:4:"data";a:5:{i:0;a:3:{s:1:"A";s:3:"95%";s:2:"h1";s:2:",1";s:2:"h2";s:7:",!@main";}i:1;a:3:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:11:",headertext";s:4:"name";s:9:"appheader";}s:1:"B";a:4:{s:4:"type";s:5:"label";s:4:"span";s:11:",headertext";s:5:"label";s:4:"Add:";s:5:"align";s:5:"right";}s:1:"C";a:5:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"3";i:1;a:6:{s:4:"type";s:6:"button";s:4:"size";s:4:"task";s:5:"label";s:4:"ToDo";s:5:"align";s:5:"right";s:4:"name";s:9:"add[task]";s:4:"help";s:14:"Add a new ToDo";}i:2;a:5:{s:4:"type";s:6:"button";s:4:"size";s:5:"phone";s:5:"label";s:9:"Phonecall";s:4:"name";s:10:"add[phone]";s:4:"help";s:19:"Add a new Phonecall";}i:3;a:5:{s:4:"type";s:6:"button";s:4:"size";s:4:"note";s:5:"label";s:4:"Note";s:4:"name";s:9:"add[note]";s:4:"help";s:14:"Add a new Note";}}}i:2;a:3:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:4:"main";s:4:"span";s:3:"all";s:4:"name";s:27:"infolog.index.rows-noheader";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}}i:3;a:3:{s:1:"A";a:4:{s:4:"type";s:9:"nextmatch";s:4:"size";s:20:"infolog.index.rows,1";s:4:"span";s:3:"all";s:4:"name";s:2:"nm";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}}i:4;a:3:{s:1:"A";a:5:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"2";s:4:"span";s:3:"all";i:1;a:4:{s:4:"type";s:6:"button";s:5:"label";s:3:"Add";s:4:"name";s:9:"add[note]";s:4:"help";s:15:"Add a new Entry";}i:2;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Cancel";s:4:"name";s:6:"cancel";s:4:"help";s:17:"Back to main list";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:4;s:4:"cols";i:3;s:4:"size";s:12:"100%,,0,,0,0";}}','size' => '100%,,0,,0,0','style' => '.headertext { color: black; font-size: 120%; }','modified' => '1121355520',); -$templ_data[] = array('name' => 'infolog.customfields','template' => '','lang' => '','group' => '0','version' => '0.9.15.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:3:{s:1:"F";s:3:"80%";s:2:"c2";s:6:"header";s:2:"c4";s:6:"header";}i:1;a:6:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:3:"Typ";}s:1:"B";a:4:{s:4:"type";s:6:"select";s:4:"name";s:3:"typ";s:8:"onchange";s:1:"1";s:4:"help";s:52:"select a typ to edit it\'s status-values or delete it";}s:1:"C";a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Delete";s:4:"name";s:14:"button[delete]";s:4:"help";s:24:"deletes the selected typ";}s:1:"D";a:5:{s:4:"type";s:4:"text";s:4:"size";s:5:"10,10";s:4:"name";s:8:"new_name";s:4:"help";s:26:"name of new type to create";s:4:"blur";s:8:"new name";}s:1:"E";a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Create";s:4:"name";s:14:"button[create]";s:4:"help";s:37:"creates a new typ with the given name";}s:1:"F";a:5:{s:4:"type";s:5:"label";s:4:"span";s:10:",error_msg";s:7:"no_lang";s:1:"1";s:5:"align";s:6:"center";s:4:"name";s:9:"error_msg";}}i:2;a:6:{s:1:"A";a:4:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";s:5:"label";s:21:"Custom status for typ";s:4:"name";s:3:"typ";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:3;a:6:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:6:"status";s:4:"span";s:3:"all";s:4:"name";s:6:"status";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:4;a:6:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";s:5:"label";s:13:"Custom fields";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:5;a:6:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:6:"fields";s:4:"span";s:3:"all";s:4:"name";s:6:"fields";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:6;a:6:{s:1:"A";a:6:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"3";s:4:"span";s:3:"all";i:1;a:4:{s:4:"type";s:6:"button";s:5:"label";s:4:"Save";s:4:"name";s:12:"button[save]";s:4:"help";s:33:"saves the changes made and leaves";}i:2;a:4:{s:4:"type";s:6:"button";s:5:"label";s:5:"Apply";s:4:"name";s:13:"button[apply]";s:4:"help";s:19:"applies the changes";}i:3;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Cancel";s:4:"name";s:14:"button[cancel]";s:4:"help";s:22:"leaves without saveing";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:6;s:4:"cols";i:6;}}','size' => '','style' => '.header { font-weight: bold; font-size: 120%; } -.error_msg { color: red; font-style: italics; }','modified' => '1061729975',); - $templ_data[] = array('name' => 'infolog.customfields','template' => '','lang' => '','group' => '0','version' => '1.2.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:3:{s:1:"F";s:3:"80%";s:2:"c2";s:6:"header";s:2:"c4";s:6:"header";}i:1;a:6:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:3:"Typ";}s:1:"B";a:4:{s:4:"type";s:6:"select";s:4:"name";s:3:"typ";s:8:"onchange";s:1:"1";s:4:"help";s:52:"select a typ to edit it\'s status-values or delete it";}s:1:"C";a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Delete";s:4:"name";s:14:"button[delete]";s:4:"help";s:24:"deletes the selected typ";}s:1:"D";a:5:{s:4:"type";s:4:"text";s:4:"size";s:5:"10,40";s:4:"name";s:8:"new_name";s:4:"help";s:26:"name of new type to create";s:4:"blur";s:8:"new name";}s:1:"E";a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Create";s:4:"name";s:14:"button[create]";s:4:"help";s:37:"creates a new typ with the given name";}s:1:"F";a:5:{s:4:"type";s:5:"label";s:4:"span";s:10:",error_msg";s:7:"no_lang";s:1:"1";s:5:"align";s:6:"center";s:4:"name";s:9:"error_msg";}}i:2;a:6:{s:1:"A";a:4:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";s:5:"label";s:21:"Custom status for typ";s:4:"name";s:3:"typ";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:3;a:6:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:6:"status";s:4:"span";s:3:"all";s:4:"name";s:6:"status";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:4;a:6:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";s:5:"label";s:13:"Custom fields";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:5;a:6:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:6:"fields";s:4:"span";s:3:"all";s:4:"name";s:6:"fields";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:6;a:6:{s:1:"A";a:6:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"3";s:4:"span";s:3:"all";i:1;a:4:{s:4:"type";s:6:"button";s:5:"label";s:4:"Save";s:4:"name";s:12:"button[save]";s:4:"help";s:33:"saves the changes made and leaves";}i:2;a:4:{s:4:"type";s:6:"button";s:5:"label";s:5:"Apply";s:4:"name";s:13:"button[apply]";s:4:"help";s:19:"applies the changes";}i:3;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Cancel";s:4:"name";s:14:"button[cancel]";s:4:"help";s:22:"leaves without saveing";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:6;s:4:"cols";i:6;}}','size' => '','style' => '.header { font-weight: bold; font-size: 120%; } .error_msg { color: red; font-style: italics; }','modified' => '1061729975',); -$templ_data[] = array('name' => 'infolog.customfields.fields','template' => '','lang' => '','group' => '0','version' => '0.9.15.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:3:{i:0;a:2:{s:2:"c1";s:2:"th";s:2:"c2";s:7:"row,top";}i:1;a:7:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:3:"Typ";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:5:"label";s:4:"Name";}s:1:"C";a:2:{s:4:"type";s:5:"label";s:5:"label";s:5:"Label";}s:1:"D";a:2:{s:4:"type";s:5:"label";s:5:"label";s:20:"Values for selectbox";}s:1:"E";a:2:{s:4:"type";s:5:"label";s:5:"label";s:14:"Length
Rows";}s:1:"F";a:2:{s:4:"type";s:5:"label";s:5:"label";s:5:"Order";}s:1:"G";a:4:{s:4:"type";s:5:"label";s:5:"label";s:6:"Action";s:5:"align";s:6:"center";s:4:"help";s:18:"deletes this field";}}i:2;a:7:{s:1:"A";a:4:{s:4:"type";s:6:"select";s:4:"size";s:3:"All";s:4:"name";s:11:"${row}[typ]";s:4:"help";s:41:"for which types should this field be used";}s:1:"B";a:4:{s:4:"type";s:4:"text";s:4:"size";s:5:"20,32";s:4:"name";s:12:"${row}[name]";s:4:"help";s:83:"the name used internaly (<= 20 chars), changeing it makes existing data unavailible";}s:1:"C";a:4:{s:4:"type";s:4:"vbox";s:4:"size";s:1:"2";i:1;a:4:{s:4:"type";s:4:"text";s:4:"size";s:4:",255";s:4:"name";s:13:"${row}[label]";s:4:"help";s:30:"the text displayed to the user";}i:2;a:2:{s:4:"type";s:5:"label";s:4:"name";s:13:"${row}[label]";}}s:1:"D";a:4:{s:4:"type";s:8:"textarea";s:4:"size";s:4:"2,30";s:4:"name";s:14:"${row}[values]";s:4:"help";s:40:"each value is a line like [=