2001-07-12 01:17:32 +02:00
< ? php
2006-10-04 19:40:33 +02:00
/**
* InfoLog - User interface
*
* @ link http :// www . egroupware . org
* @ author Ralf Becker < RalfBecker - AT - outdoor - training . de >
* @ package infolog
2014-05-24 12:59:03 +02:00
* @ copyright ( c ) 2003 - 14 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
2006-10-04 19:40:33 +02:00
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
* @ version $Id $
*/
2001-07-12 01:17:32 +02:00
2006-10-04 19:40:33 +02:00
/**
* This class is the UI - layer ( user interface ) of InfoLog
*/
2008-10-07 14:50:14 +02:00
class infolog_ui
2006-10-04 19:40:33 +02:00
{
2008-10-07 14:50:14 +02:00
var $public_functions = array (
2006-10-04 19:40:33 +02:00
'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
2008-04-18 13:53:55 +02:00
*
2011-04-12 13:53:34 +02:00
* @ var infolog_bo
2006-10-04 19:40:33 +02:00
*/
var $bo ;
/**
* instance of the etemplate class
*
* @ var etemplate
*/
var $tmpl ;
/**
* allowed units and hours per day , can be overwritten by the projectmanager configuration , default all units , 8 h
2008-04-18 13:53:55 +02:00
*
2006-10-04 19:40:33 +02:00
* @ var string
*/
var $duration_format = ',' ; // comma is necessary!
2008-04-18 13:53:55 +02:00
2006-10-04 19:40:33 +02:00
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' ,
2009-04-23 16:47:26 +02:00
'close' => 'done.gif' , 'close_alt' => 'Close' ,
'close_all' => 'done_all.gif' , 'close_all_alt' => 'Close' ),
2006-10-04 19:40:33 +02:00
'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' )
);
2009-05-05 14:48:38 +02:00
var $filters ;
2006-10-04 19:40:33 +02:00
var $messages = array (
'edit' => 'InfoLog - Edit' ,
'add' => 'InfoLog - New' ,
'add_sub' => 'InfoLog - New Subproject' ,
'sp' => '- Subprojects from' ,
);
2006-10-20 15:13:00 +02:00
/**
* Constructor
*
2008-10-07 14:50:14 +02:00
* @ return infolog_ui
2006-10-20 15:13:00 +02:00
*/
2008-10-07 14:50:14 +02:00
function __construct ()
2001-07-12 01:17:32 +02:00
{
2011-05-02 21:41:21 +02:00
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] != 'infolog' ) translation :: add_app ( 'infolog' );
2013-03-19 00:22:51 +01:00
// Make sure Global category is infolog - on first load, it may not be
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] == 'infolog' && ! $GLOBALS [ 'egw' ] -> categories -> app_name )
{
$GLOBALS [ 'egw' ] -> categories = new categories ();
}
2009-06-08 18:21:14 +02:00
$this -> bo = new infolog_bo ();
2006-10-04 19:40:33 +02:00
2013-08-26 11:19:47 +02:00
$this -> tmpl = new etemplate_new ();
2001-07-12 01:17:32 +02:00
2006-10-04 19:40:33 +02:00
$this -> user = $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ];
2008-04-18 13:53:55 +02:00
2006-10-04 19:40:33 +02:00
$this -> prefs =& $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'infolog' ];
2008-04-18 13:53:55 +02:00
2006-10-04 19:40:33 +02:00
// read the duration format from project-manager
if ( $GLOBALS [ 'egw_info' ][ 'apps' ][ 'projectmanager' ])
2001-07-14 23:44:01 +02:00
{
2008-01-19 06:36:20 +01:00
$pm_config = config :: read ( 'projectmanager' );
2013-11-19 22:59:42 +01:00
$this -> duration_format = str_replace ( ',' , '' , implode ( '' , ( array ) $pm_config [ 'duration_units' ]));
2014-01-15 15:34:28 +01:00
//error_log(__METHOD__."() ".__LINE__." duration_format=$this->duration_format, duration_unit=".array2string($pm_config['duration_units']));
2013-11-12 22:38:25 +01:00
$this -> hours_per_workday = $pm_config [ 'hours_per_workday' ];
2006-10-04 19:40:33 +02:00
unset ( $pm_config );
2002-10-14 02:39:47 +02:00
}
2009-05-05 14:48:38 +02:00
$this -> filters =& $this -> bo -> filters ;
2007-06-10 11:21:04 +02:00
/* these are just for testing of the notifications
for ( $i = - 1 ; $i <= 3 ; ++ $i )
{
$this -> filters [ 'delegated-open-enddate' . date ( 'Y-m-d' , time () + $i * 24 * 60 * 60 )] = " delegated due in $i day(s) " ;
}
for ( $i = - 1 ; $i <= 3 ; ++ $i )
{
$this -> filters [ 'responsible-open-enddate' . date ( 'Y-m-d' , time () + $i * 24 * 60 * 60 )] = " responsible due in $i day(s) " ;
}
for ( $i = - 1 ; $i <= 3 ; ++ $i )
{
$this -> filters [ 'delegated-open-date' . date ( 'Y-m-d' , time () + $i * 24 * 60 * 60 )] = " delegated starting in $i day(s) " ;
}
for ( $i = - 1 ; $i <= 3 ; ++ $i )
{
$this -> filters [ 'responsible-open-date' . date ( 'Y-m-d' , time () + $i * 24 * 60 * 60 )] = " responsible starting in $i day(s) " ;
}
*/
2008-10-07 14:50:14 +02:00
$GLOBALS [ 'infolog_ui' ] =& $this ; // make ourself availible for ExecMethod of get_rows function
2012-02-22 13:31:00 +01:00
// can be removed for next release / infolog update
if ( ! $GLOBALS [ 'egw' ] -> hooks -> hook_exists ( 'calendar_set' , 'infolog' ))
{
$GLOBALS [ 'egw' ] -> hooks -> register_single_app_hook ( 'infolog' , 'calendar_set' );
}
2006-10-04 19:40:33 +02:00
}
2002-10-14 02:39:47 +02:00
2006-10-20 15:13:00 +02:00
/**
* Sets additional fields for one infolog entry , which are not persistent in the DB
*
* @ param array $info infolog entry read from the db
* @ param array & $readonlys ACL specific settings for the buttons
* @ param string $action
* @ param string / int $action_id
* @ param boolean $show_links
* @ param int $details
* @ return array
*/
2006-10-04 19:40:33 +02:00
function get_info ( $info , & $readonlys , $action = '' , $action_id = '' , $show_links = false , $details = 1 )
{
if ( ! is_array ( $info ))
2002-10-14 02:39:47 +02:00
{
2006-10-04 19:40:33 +02:00
$info = $this -> bo -> read ( $info );
}
$id = $info [ 'info_id' ];
2009-04-23 16:47:26 +02:00
$done = $info [ 'info_status' ] == 'done' || $info [ 'info_status' ] == 'billed' || $info [ 'info_status' ] == 'cancelled' ; //cancelled is regarded as a completed status as well in bo
// regard an infolog as done/billed/cancelled if its percentage is 100% when there is to status like the above for that type
if ( ! $done && ! isset ( $this -> bo -> status [ $info [ 'info_type' ]][ 'done' ]) && ! isset ( $this -> bo -> status [ $info [ 'info_type' ]][ 'billed' ]) &&
2009-05-05 14:48:38 +02:00
! isset ( $this -> bo -> status [ $info [ 'info_type' ]][ 'cancelled' ]) && ( int ) $info [ 'info_percent' ] == 100 ) $done = true ;
2006-10-04 19:40:33 +02:00
$info [ 'sub_class' ] = $this -> bo -> enums [ 'priority' ][ $info [ 'info_priority' ]] . ( $done ? '_done' : '' );
if ( ! $done && $info [ 'info_enddate' ] < $this -> bo -> user_time_now )
{
2013-09-19 14:52:50 +02:00
$info [ 'end_class' ] = 'infolog_overdue' ;
2006-10-04 19:40:33 +02:00
}
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' ] . '%' ;
2009-04-23 16:47:26 +02:00
$editrights = $this -> bo -> check_access ( $info , EGW_ACL_EDIT );
$isresposible = $this -> bo -> is_responsible ( $info );
2014-02-27 21:53:14 +01:00
if (( ! ( $editrights || // edit rights or more then standard responsible rights
2011-05-02 21:41:21 +02:00
$isresposible && array_diff ( $this -> bo -> responsible_edit , array ( 'info_status' , 'info_percent' , 'info_datecompleted' )))))
{
$info [ 'class' ] .= 'rowNoEdit ' ;
}
2011-05-05 12:18:38 +02:00
if ( $info [ 'status' ] == 'deleted' && ! $this -> bo -> check_access ( $info , EGW_ACL_UNDELETE ))
{
$info [ 'class' ] .= 'rowNoUndelete ' ;
}
2014-02-27 21:53:14 +01:00
if (( $done || ( ! ( $editrights || $isresposible ))))
2011-05-03 09:26:32 +02:00
{
$info [ 'class' ] .= 'rowNoClose ' ;
}
// this one is supressed, when you are not allowed to edit, or not responsible, or the entry is closed
// and has no children. If you want that this one is shown if there are children regardless of the status of the current or its childs,
// then modify ($done) to ($done && !$info['info_anz_subs'])
2014-02-27 21:53:14 +01:00
if ( $done || ! $info [ 'info_anz_subs' ] || ( ! ( $editrights || $isresposible )))
2011-05-03 09:26:32 +02:00
{
$info [ 'class' ] .= 'rowNoCloseAll ' ;
}
2014-02-26 17:47:48 +01:00
if ( ! $this -> bo -> check_access ( $info , EGW_ACL_DELETE ))
2011-05-02 21:41:21 +02:00
{
$info [ 'class' ] .= 'rowNoDelete ' ;
}
2014-02-27 21:53:14 +01:00
if ( ! $this -> bo -> check_access ( $info , EGW_ACL_ADD ))
2011-05-02 21:41:21 +02:00
{
$info [ 'class' ] .= 'rowNoSubs ' ;
}
2013-09-19 14:52:50 +02:00
if ( $info [ 'info_id_parent' ]) $info [ 'class' ] .= 'infolog_rowHasParent ' ;
if ( $info [ 'info_anz_subs' ] > 0 ) $info [ 'class' ] .= 'infolog_rowHasSubs ' ;
2011-05-02 21:41:21 +02:00
2014-05-27 11:53:09 +02:00
$info [ 'row_mod' ] = $info [ 'info_datemodified' ];
2014-05-24 12:59:03 +02:00
2006-10-04 19:40:33 +02:00
if ( ! $show_links ) $show_links = $this -> prefs [ 'show_links' ];
2008-04-18 13:53:55 +02:00
if (( $show_links != 'none' && $show_links != 'no_describtion' ||
$this -> prefs [ 'show_times' ] || isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'timesheet' ])) &&
2014-05-24 12:59:03 +02:00
( isset ( $info [ 'links' ]) || ( $info [ 'links' ] = egw_link :: get_links ( 'infolog' , $info [ 'info_id' ], '' , 'link_lastmod DESC' , true , true ))))
2006-10-04 19:40:33 +02:00
{
$timesheets = array ();
2008-03-08 22:43:13 +01:00
foreach ( $info [ 'links' ] as $link )
2003-06-29 19:03:47 +02:00
{
2014-05-24 12:59:03 +02:00
// incl. link modification time into row_mod (link's lastmod is always in server-time!)
$link_mod = egw_time :: server2user ( $link [ 'lastmod' ]);
if ( $info [ 'row_mod' ] < $link_mod ) $info [ 'row_mod' ] = $link_mod ;
if ( $link [ 'deleted' ]) continue ; // skip deleted links, but incl. them in row_mod!
2006-10-04 19:40:33 +02:00
if ( $show_links != 'none' && $show_links != 'no_describtion' &&
$link [ 'link_id' ] != $info [ 'info_link_id' ] &&
( $link [ 'app' ] != $action || $link [ 'id' ] != $action_id ) &&
2008-03-08 22:43:13 +01:00
( $show_links == 'all' || ( $show_links == 'links' ) === ( $link [ 'app' ] != egw_link :: VFS_APPNAME )))
2003-06-29 19:03:47 +02:00
{
2006-10-04 19:40:33 +02:00
$info [ 'filelinks' ][] = $link ;
2006-03-21 14:52:49 +01:00
}
2006-10-04 19:40:33 +02:00
if ( ! $info [ 'pm_id' ] && $link [ 'app' ] == 'projectmanager' )
2006-03-21 14:52:49 +01:00
{
2006-10-04 19:40:33 +02:00
$info [ 'pm_id' ] = $link [ 'id' ];
2003-06-29 19:03:47 +02:00
}
2006-10-04 19:40:33 +02:00
if ( $link [ 'app' ] == 'timesheet' ) $timesheets [] = $link [ 'id' ];
2006-03-24 17:10:09 +01:00
}
2006-10-04 19:40:33 +02:00
if ( $this -> prefs [ 'show_times' ] && isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'timesheet' ]) && $timesheets )
2006-03-24 17:10:09 +01:00
{
2008-10-08 10:13:17 +02:00
$sum = ExecMethod ( 'timesheet.timesheet_bo.sum' , $timesheets );
2006-10-04 19:40:33 +02:00
$info [ 'info_sum_timesheets' ] = $sum [ 'duration' ];
2014-05-24 12:59:03 +02:00
// incl. max timesheet modification in row_mod
if ( $info [ 'row_mod' ] < $sum [ 'max_modified' ]) $info [ 'row_mod' ] = $sum [ 'max_modified' ];
2006-03-24 17:10:09 +01:00
}
2006-10-04 19:40:33 +02:00
}
$info [ 'info_type_label' ] = $this -> bo -> enums [ 'type' ][ $info [ 'info_type' ]];
2008-04-18 13:53:55 +02:00
$info [ 'info_status_label' ] = isset ( $this -> bo -> status [ $info [ 'info_type' ]][ $info [ 'info_status' ]]) ?
2007-06-13 23:37:05 +02:00
$this -> bo -> status [ $info [ 'info_type' ]][ $info [ 'info_status' ]] : $info [ 'info_status' ];
2008-04-18 13:53:55 +02:00
2006-10-04 19:40:33 +02:00
if ( ! $this -> prefs [ 'show_percent' ] || $this -> prefs [ 'show_percent' ] == 2 && ! $details )
{
if ( $info [ 'info_status' ] == 'ongoing' && $info [ 'info_type' ] != 'phone' )
2006-03-24 17:10:09 +01:00
{
2006-10-04 19:40:33 +02:00
$info [ 'info_status' ] = $info [ 'info_status_label' ] = $info [ 'info_percent' ];
2006-03-24 17:10:09 +01:00
}
2006-10-04 19:40:33 +02:00
$readonlys [ " edit_percent[ $id ] " ] = true ;
2002-10-14 02:39:47 +02:00
}
2006-10-04 19:40:33 +02:00
elseif ( $readonlys [ " edit_percent[ $id ] " ]) // show percent, but button is switched off
2002-10-14 02:39:47 +02:00
{
2006-10-04 19:40:33 +02:00
$info [ 'info_percent2' ] = $info [ 'info_percent' ];
2003-12-09 01:08:31 +01:00
}
2006-10-04 19:40:33 +02:00
if ( $this -> prefs [ 'show_id' ] == 1 || $this -> prefs [ 'show_id' ] == 2 && $details )
2004-02-28 15:58:44 +01:00
{
2006-10-04 19:40:33 +02:00
$info [ 'info_number' ] = $info [ 'info_id' ];
2004-02-28 15:58:44 +01:00
}
2013-10-10 13:29:31 +02:00
//error_log(__METHOD__."() returning ".array2string($info));
2006-10-04 19:40:33 +02:00
return $info ;
}
2006-10-20 15:13:00 +02:00
/**
* Callback for nextmatch widget
*
* @ param array & $query
* @ param array & $rows
* @ param array & $readonlys
* @ return int
*/
function get_rows ( & $query , & $rows , & $readonlys )
2006-10-04 19:40:33 +02:00
{
2013-10-10 13:29:31 +02:00
//error_log(__METHOD__."() query[csv_export]=".array2string($query['csv_export']).", query[filter]=".array2string($query['filter']).", query[col_filter]=".array2string(array_diff($query['col_filter'],array('',0))).' '.function_backtrace());
2011-05-02 21:41:21 +02:00
if ( ! $query [ 'csv_export' ])
{
2011-05-03 08:26:56 +02:00
unset ( $query [ 'no_actions' ]);
2012-03-30 14:28:31 +02:00
$parent_id = $query [ 'col_filter' ][ 'parent_id' ];
unset ( $query [ 'col_filter' ][ 'parent_id' ]);
2014-03-26 20:36:54 +01:00
if ( ! $query [ 'action' ])
{
egw_cache :: setSession ( 'infolog' , $query [ 'session_for' ] . 'session_data' , $query );
}
2011-05-02 21:41:21 +02:00
$query [ 'actions' ] = $this -> get_actions ( $query );
2011-05-03 09:26:32 +02:00
$query [ 'row_id' ] = 'info_id' ;
2014-05-24 12:59:03 +02:00
$query [ 'row_modified' ] = 'row_mod' ;
2012-03-30 14:28:31 +02:00
$query [ 'parent_id' ] = 'info_id_parent' ;
$query [ 'is_parent' ] = 'info_anz_subs' ;
2011-05-06 20:13:10 +02:00
$query [ 'action_var' ] = 'multi_action' ; // as 'action' is already used in infolog
2011-05-02 21:41:21 +02:00
}
2009-11-10 09:11:41 +01:00
$orginal_colfilter = $query [ 'col_filter' ];
2012-03-30 14:28:31 +02:00
if ( isset ( $parent_id )) $query [ 'col_filter' ][ 'info_id_parent' ] = ( int ) $parent_id ;
2009-11-10 09:11:41 +01:00
2008-10-22 08:51:01 +02:00
//echo "<p>infolog_ui.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).",sort=$query[sort],order=$query[order])</p>\n";
2006-10-04 19:40:33 +02:00
if ( ! isset ( $query [ 'start' ])) $query [ 'start' ] = 0 ;
2014-03-26 20:36:54 +01:00
// handle action and linked filter (show only entries linked to a certain other entry)
$link_filters = array ();
$links = array ();
2009-09-25 10:03:01 +02:00
if ( $query [ 'col_filter' ][ 'linked' ])
2009-09-19 15:58:24 +02:00
{
2014-03-26 20:36:54 +01:00
$link_filters [ 'linked' ] = $query [ 'col_filter' ][ 'linked' ];
$links [ 'linked' ] = array ();
unset ( $query [ 'col_filter' ][ 'linked' ]);
}
if ( $query [ 'action' ] && in_array ( $query [ 'action' ], array_keys ( $GLOBALS [ 'egw_info' ][ 'apps' ])) && $query [ 'action_id' ])
{
$link_filters [ 'action' ] = array ( 'app' => $query [ 'action' ], 'id' => $query [ 'action_id' ]);
$links [ 'action' ] = array ();
}
foreach ( $link_filters as $key => $link )
{
if ( ! is_array ( $link ))
2014-03-13 20:09:33 +01:00
{
// Legacy string style
2014-03-26 20:36:54 +01:00
list ( $app , $id ) = explode ( ':' , $link );
2014-03-13 20:09:33 +01:00
}
else
{
// Full info
2014-03-26 20:36:54 +01:00
$app = $link [ 'app' ];
$id = $link [ 'id' ];
2014-03-13 20:09:33 +01:00
}
if ( ! is_array ( $id )) $id = explode ( ',' , $id );
2014-04-28 22:25:40 +02:00
if ( ! ( $linked = egw_link :: get_links_multiple ( $app , $id , true , 'infolog' , '' , $query [ 'col_filter' ][ 'info_status' ] == 'deleted' )))
2009-09-25 10:03:01 +02:00
{
2014-03-26 20:36:54 +01:00
$rows = array (); // no infologs linked to selected link --> no rows to return
2009-09-25 10:03:01 +02:00
return 0 ;
}
2014-03-13 20:09:33 +01:00
2014-03-26 20:36:54 +01:00
foreach ( $linked as $infos )
2014-03-13 20:09:33 +01:00
{
2014-03-26 20:36:54 +01:00
$links [ $key ] = array_merge ( $links [ $key ], $infos );
2014-03-13 20:09:33 +01:00
}
2014-03-26 20:36:54 +01:00
$links [ $key ] = array_unique ( $links [ $key ]);
if ( $key == 'linked' )
{
$linked = array ( 'app' => $app , 'id' => $id , 'title' => ( count ( $id ) == 1 ? egw_link :: title ( $app , $id ) : lang ( 'multiple' )));
}
}
if ( count ( $links ))
{
$query [ 'col_filter' ][ 'info_id' ] = count ( $links ) > 1 ? call_user_func_array ( 'array_intersect' , $links ) : $links [ $key ];
2009-09-19 15:58:24 +02:00
}
2009-09-25 10:03:01 +02:00
2006-10-21 15:07:32 +02:00
// check if we have a custom, type-specific template
unset ( $query [ 'template' ]);
unset ( $query [ 'custom_fields' ]);
if ( $query [ 'col_filter' ][ 'info_type' ])
{
2013-08-26 11:19:47 +02:00
$tpl = new etemplate_new ;
2006-10-21 15:07:32 +02:00
if ( $tpl -> read ( 'infolog.index.rows.' . $query [ 'col_filter' ][ 'info_type' ]))
{
$query [ 'template' ] =& $tpl ;
$query [ 'custom_fields' ] = true ; // read the custom fields too
}
//echo "<p align=right>template ='".'infolog.index.rows.'.$query['col_filter']['info_type']."'".(!$query['template'] ? ' not' : '')." found</p>\n";
2012-05-14 18:53:35 +02:00
// If status is not valid for selected type, clear status filter
2012-07-17 00:42:15 +02:00
if ( $query [ 'col_filter' ][ 'info_status' ] && $query [ 'col_filter' ][ 'info_status' ] != 'deleted' &&
2012-05-14 18:53:35 +02:00
! in_array ( $query [ 'col_filter' ][ 'info_status' ], $this -> bo -> status [ $query [ 'col_filter' ][ 'info_type' ]]))
{
$query [ 'col_filter' ][ 'info_status' ] = '' ;
}
2006-10-21 15:07:32 +02:00
}
2007-12-14 14:11:51 +01:00
// do we need to read the custom fields, depends on the column is enabled and customfields exist, prefs are filter specific
// so we have to check that as well
2009-07-13 12:33:26 +02:00
$details = $query [ 'filter2' ] == 'all' ;
2007-12-14 14:11:51 +01:00
$columselection = $this -> prefs [ 'nextmatch-infolog.index.rows' . ( $details ? '-details' : '' )];
//_debug_array($columselection);
2008-04-18 13:53:55 +02:00
if ( $columselection )
2007-12-14 14:11:51 +01:00
{
2014-05-22 18:38:22 +02:00
$columselection = is_array ( $columselection ) ? $columselection : explode ( ',' , $columselection );
2008-04-18 13:53:55 +02:00
}
else
2007-12-14 14:11:51 +01:00
{
2014-03-24 17:31:30 +01:00
$columselection = $query [ 'selectcols' ] ? ( is_array ( $query [ 'selectcols' ]) ? $query [ 'selectcols' ] : explode ( ',' , $query [ 'selectcols' ])) : array ();
2007-12-14 14:11:51 +01:00
}
2008-01-19 06:36:20 +01:00
// do we need to query the cf's
$query [ 'custom_fields' ] = $this -> bo -> customfields && ( ! $columselection || in_array ( 'customfields' , $columselection ));
2008-03-08 22:43:13 +01:00
$infos = $this -> bo -> search ( $query );
2009-11-10 09:11:41 +01:00
$query [ 'col_filter' ] = $orginal_colfilter ;
2008-03-08 22:43:13 +01:00
if ( ! is_array ( $infos ))
2006-10-04 19:40:33 +02:00
{
2008-03-08 22:43:13 +01:00
$infos = array ( );
2006-10-04 19:40:33 +02:00
}
2007-03-07 13:31:48 +01:00
// add a '-details' to the name of the columnselection pref
if ( $details )
{
2014-06-04 20:43:21 +02:00
$query [ 'columnselection_pref' ] = 'nextmatch-' . ( is_object ( $query [ 'template' ]) ? $query [ 'template' ] -> name : 'infolog.index.rows' ) . '-details' ;
2011-06-07 11:26:07 +02:00
$query [ 'default_cols' ] = '!cat_id,info_used_time_info_planned_time,info_used_time_info_planned_time_info_replanned_time,info_id,actions' ;
2007-03-07 13:31:48 +01:00
}
else
{
2014-06-04 20:43:21 +02:00
$query [ 'columnselection_pref' ] = 'nextmatch-infolog.index.rows' ;
2011-06-07 11:26:07 +02:00
$query [ 'default_cols' ] = '!cat_id,info_datemodified,info_used_time_info_planned_time,info_used_time_info_planned_time_info_replanned_time,info_id,actions' ;
2007-03-07 13:31:48 +01:00
}
2009-08-25 15:17:29 +02:00
// set old show_times pref, that get_info calculates the cumulated time of the timesheets (we only check used&planned to work for both time cols)
2014-06-04 20:43:21 +02:00
$this -> prefs [ 'show_times' ] = strpos ( $this -> prefs [ $query [ 'columnselection_pref' ]], 'info_used_time_info_planned_time' ) !== false ;
2007-05-22 15:36:32 +02:00
2008-10-19 13:34:12 +02:00
// query all links and sub counts in one go
2013-10-10 13:29:31 +02:00
if ( $infos && ( ! $query [ 'csv_export' ] || ! is_array ( $query [ 'csv_export' ])))
2008-03-08 22:43:13 +01:00
{
2014-05-24 12:59:03 +02:00
$links = egw_link :: get_links_multiple ( 'infolog' , array_keys ( $infos ), true , '' , 'link_lastmod DESC' , true ); // true=incl. deleted
2008-10-19 13:34:12 +02:00
$anzSubs = $this -> bo -> anzSubs ( array_keys ( $infos ));
2008-03-08 22:43:13 +01:00
}
2014-02-27 21:53:14 +01:00
$rows = array ();
2013-10-10 13:29:31 +02:00
2013-11-07 18:28:49 +01:00
// Don't add parent in if info_id_parent (expanding to show subs)
if ( $query [ 'action_id' ] && ! $query [ 'col_filter' ][ 'info_id_parent' ])
2011-05-05 12:18:38 +02:00
{
2013-10-10 13:29:31 +02:00
$parents = $query [ 'action' ] == 'sp' && $query [ 'action_id' ] ? ( array ) $query [ 'action_id' ] : array ();
if ( count ( $parents ) == 1 && is_array ( $query [ 'action_id' ]))
{
$query [ 'action_id' ] = array_shift ( $query [ 'action_id' ]); // display single parent as app_header
}
2011-05-05 12:18:38 +02:00
}
2013-11-19 22:59:42 +01:00
2013-06-06 15:15:02 +02:00
$parent_first = count ( $parents ) == 1 ;
$parent_index = 0 ;
2013-11-06 19:43:47 +01:00
// et2 nextmatch listens to total, and only displays that many rows, so add parent in or we'll lose the last row
2014-03-26 20:36:54 +01:00
if ( $parent_first || $query [ 'action' ] == 'sp' && is_array ( $query [ 'action_id' ])) $query [ 'total' ] ++ ;
2013-11-19 22:59:42 +01:00
2013-11-06 19:43:47 +01:00
// Check to see if we need to remove description
2008-03-08 22:43:13 +01:00
foreach ( $infos as $id => $info )
2006-10-04 19:40:33 +02:00
{
2010-06-28 17:25:27 +02:00
if ( ! ( strpos ( $info [ 'info_addr' ], ',' ) === false ) && strpos ( $info [ 'info_addr' ], ', ' ) === false ) $info [ 'info_addr' ] = str_replace ( ',' , ', ' , $info [ 'info_addr' ]);
2013-10-10 13:29:31 +02:00
if ( ! $query [ 'csv_export' ] || ! is_array ( $query [ 'csv_export' ]))
2002-10-14 02:39:47 +02:00
{
2008-03-08 22:43:13 +01:00
$info [ 'links' ] =& $links [ $id ];
2008-10-19 13:34:12 +02:00
$info [ 'info_anz_subs' ] = ( int ) $anzSubs [ $id ];
2014-08-21 16:42:17 +02:00
$info = $this -> get_info ( $info , $readonlys , null , null , false , $details );
2002-10-14 02:39:47 +02:00
}
2011-05-05 12:18:38 +02:00
// for subs view ('sp') add parent(s) in front of subs once(!)
2013-11-07 18:28:49 +01:00
if ( $parent_first && ( $main = $this -> bo -> read ( $query [ 'action_id' ])) ||
2013-06-06 15:15:02 +02:00
$parents && ( $parent_index = array_search ( $info [ 'info_id_parent' ], $parents )) !== false &&
2011-05-05 12:18:38 +02:00
( $main = $this -> bo -> read ( $info [ 'info_id_parent' ])))
2011-05-03 02:14:44 +02:00
{
2011-05-05 12:18:38 +02:00
$main = $this -> get_info ( $main , $readonlys );
$main [ 'class' ] .= 'th ' ;
2012-05-08 11:43:22 +02:00
// if only certain custom-fields are to be displayed, we need to unset the not displayed ones manually
// as read() always read them all, while search() only reads the selected ones
if ( $query [ 'custom_fields' ])
{
foreach ( $columselection as $col )
{
if ( $col [ 0 ] == '#' )
{
2014-01-28 10:22:12 +01:00
foreach ( array_keys ( $main ) as $n )
2012-05-08 11:43:22 +02:00
{
if ( $n [ 0 ] == '#' && ! in_array ( $n , $columselection )) unset ( $main [ $n ]);
}
break ;
}
}
}
2013-06-06 15:15:02 +02:00
$parent_first = false ;
2013-11-06 19:43:47 +01:00
if ( $query [ 'start' ] == 0 )
{
array_splice ( $rows , $id , 0 , array ( $main ));
unset ( $parents [ $parent_index ]);
}
2011-05-03 02:14:44 +02:00
}
2009-09-25 10:03:01 +02:00
$rows [] = $info ;
2006-10-04 19:40:33 +02:00
}
2008-03-08 22:43:13 +01:00
unset ( $links );
2007-03-07 13:31:48 +01:00
if ( $query [ 'cat_id' ]) $rows [ 'no_cat_id' ] = true ;
2006-10-04 19:40:33 +02:00
if ( $query [ 'no_actions' ]) $rows [ 'no_actions' ] = true ;
$rows [ 'no_timesheet' ] = ! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'timesheet' ]);
$rows [ 'duration_format' ] = ',' . $this -> duration_format . ',,1' ;
2008-04-18 13:53:55 +02:00
2008-01-19 06:36:20 +01:00
// switch cf column off, if we have no cf's
if ( ! $query [ 'custom_fields' ]) $rows [ 'no_customfields' ] = true ;
2007-03-07 13:31:48 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'account_selection' ] == 'none' &&
! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ]))
{
$rows [ 'no_info_owner_info_responsible' ] = true ;
// dont show owner, responsible in the columnselection
$query [ 'options-selectcols' ][ 'info_owner' ] = $query [ 'options-selectcols' ][ 'info_responsible' ] = false ;
}
2008-04-18 13:53:55 +02:00
2008-01-15 05:18:17 +01:00
// if filtered by type, show only the stati of the filtered type
2012-05-22 19:39:28 +02:00
$rows [ 'sel_options' ][ 'info_status' ] = $this -> bo -> get_status ( $query [ 'col_filter' ][ 'info_type' ]);
2008-01-15 05:18:17 +01:00
if ( $this -> bo -> history )
{
$rows [ 'sel_options' ][ 'info_status' ][ 'deleted' ] = 'deleted' ;
}
2014-04-07 18:49:42 +02:00
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] == 'infolog' && ! $this -> called_by )
2006-10-04 19:40:33 +02:00
{
2006-10-23 13:50:30 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Infolog' );
2014-03-04 16:38:56 +01:00
if ( $query [ 'filter' ] != '' && ! empty ( $this -> filters [ $query [ 'filter' ]]))
2006-10-23 13:50:30 +02:00
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] .= ' - ' . lang ( $this -> filters [ $query [ 'filter' ]]);
}
2011-05-05 12:18:38 +02:00
if ( $query [ 'action' ] && ( $title = $query [ 'action_title' ] || is_array ( $query [ 'action_id' ]) ?
$query [ 'action_title' ] : egw_link :: title ( $query [ 'action' ] == 'sp' ? 'infolog' : $query [ 'action' ], $query [ 'action_id' ])))
2006-10-23 13:50:30 +02:00
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] .= ': ' . $title ;
}
2006-10-04 19:40:33 +02:00
}
2009-09-25 10:03:01 +02:00
if ( isset ( $linked )) $query [ 'col_filter' ][ 'linked' ] = $linked ; // add linked back to the colfilter
2014-03-24 17:31:30 +01:00
2006-10-04 19:40:33 +02:00
return $query [ 'total' ];
}
2011-05-30 16:21:27 +02:00
/**
* Hook for timesheet to set some extra data and links
*
* @ param array $data
* @ param int $data [ id ] info_id
* @ return array with key => value pairs to set in new timesheet and link_app / link_id arrays
*/
function timesheet_set ( $data )
{
$set = array ();
if (( int ) $data [ 'id' ] && ( $info = $this -> bo -> read ( $data [ 'id' ])))
{
if ( $info [ 'info_cat' ]) $set [ 'cat_id' ] = $info [ 'info_cat' ];
foreach ( egw_link :: get_links ( 'infolog' , $info [ 'info_id' ], '' , 'link_lastmod DESC' , true ) as $link )
{
if ( $link [ 'app' ] != 'timesheet' && $link [ 'app' ] != egw_link :: VFS_APPNAME )
{
$set [ 'link_app' ][] = $link [ 'app' ];
$set [ 'link_id' ][] = $link [ 'id' ];
}
}
}
return $set ;
}
2012-02-22 13:31:00 +01:00
/**
* Hook for calendar to set some extra data and links
*
* @ param array $data event - array preset by calendar plus
* @ param int $data [ entry_id ] info_id
* @ return array with key => value pairs to set in new event and link_app / link_id arrays
*/
function calendar_set ( $data )
{
if ( ! ( $infolog = $this -> bo -> read ( $data [ 'entry_id' ])))
{
return $data ;
}
$event = array_merge ( $data , array (
'category' => $GLOBALS [ 'egw' ] -> categories -> check_list ( EGW_ACL_READ , $infolog [ 'info_cat' ]),
'priority' => $infolog [ 'info_priority' ] + 1 ,
'public' => $infolog [ 'info_access' ] != 'private' ,
'title' => $infolog [ 'info_subject' ],
'description' => $infolog [ 'info_des' ],
'location' => $infolog [ 'info_location' ],
'start' => $infolog [ 'info_startdate' ],
'end' => $infolog [ 'info_enddate' ] ? $infolog [ 'info_enddate' ] : $infolog [ 'info_datecompleted' ]
));
unset ( $event [ 'entry_id' ]);
if ( ! $event [ 'end' ]) $event [ 'end' ] = $event [ 'start' ] + ( int ) $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'calendar' ][ 'defaultlength' ] * 60 ;
// Match categories by name
$event [ 'category' ] = $GLOBALS [ 'egw' ] -> categories -> name2id ( categories :: id2name ( $infolog [ 'info_cat' ]));
// make current user the owner of the new event, not the selected calendar, if current user has rights for it
$event [ 'owner' ] = $user = $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ];
// add/modify participants according to prefs
$prefs = explode ( ',' , $this -> prefs [ 'calendar_set' ] ? $this -> prefs [ 'calendar_set' ] : 'responsible,contact,user' );
// if no default participants (selected calendars) --> remove all
if ( ! in_array ( 'selected' , $prefs ))
{
$event [ 'participants' ] = $event [ 'participant_types' ] = array ();
}
// Add responsible as participant
if ( in_array ( 'responsible' , $prefs ))
{
foreach ( $infolog [ 'info_responsible' ] as $responsible )
{
$event [ 'participants' ][ $responsible ] = $event [ 'participant_types' ][ 'u' ][ $responsible ] =
calendar_so :: combine_status ( $user == $responsible ? 'A' : 'U' );
}
}
// Add linked contact as participant
if ( in_array ( 'contact' , $prefs ) && $infolog [ 'info_link' ][ 'app' ] == 'addressbook' )
{
$event [ 'participants' ][ calendar_so :: combine_user ( 'c' , $infolog [ 'info_link' ][ 'id' ])] =
$event [ 'participant_types' ][ 'c' ][ $infolog [ 'info_link' ][ 'id' ]] = calendar_so :: combine_status ( 'U' );
}
if ( in_array ( 'owner' , $prefs ))
{
$event [ 'participants' ][ $infolog [ 'info_owner' ]] = $event [ 'participant_types' ][ 'u' ][ $infolog [ 'info_owner' ]] =
calendar_so :: combine_status ( 'A' , 1 , 'CHAIR' );
}
// Add current user, if set or no other participants, which is not allowed
if ( in_array ( 'user' , $prefs ))
{
$event [ 'participants' ][ $user ] = $event [ 'participant_types' ][ 'u' ][ $user ] =
calendar_so :: combine_status ( 'A' , 1 , 'CHAIR' );
}
// Add infolog link to calendar entry
$event [ 'link_app' ][] = $infolog [ 'info_link' ][ 'app' ];
$event [ 'link_id' ][] = $infolog [ 'info_link' ][ 'id' ];
// Copy infolog's links
foreach ( egw_link :: get_links ( 'infolog' , $infolog [ 'info_id' ], '' , 'link_lastmod DESC' , true ) as $link )
{
if ( $link [ 'app' ] != egw_link :: VFS_APPNAME )
{
$event [ 'link_app' ][] = $link [ 'app' ];
$event [ 'link_id' ][] = $link [ 'id' ];
}
}
// Copy same custom fields
2014-01-28 10:22:12 +01:00
foreach ( array_keys ( config :: get_customfields ( 'calendar' )) as $name )
2012-02-22 13:31:00 +01:00
{
if ( $this -> bo -> customfields [ $name ]) $event [ '#' . $name ] = $infolog [ '#' . $name ];
}
//error_log(__METHOD__.'('.array2string($data).') infolog='.array2string($infolog).' returning '.array2string($event));
return $event ;
}
2006-10-04 19:40:33 +02:00
/**
* Shows the infolog list
*
2014-06-12 14:34:50 +02:00
* @ param array / string $values 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
2014-08-21 16:40:42 +02:00
* @ param mixed $called_as is how we got called , for a hook eg . the call - params of that page containing the hook
2014-06-12 14:34:50 +02:00
* @ param boolean $e $extra_app_header * @ param boolean $return_html = false
2006-10-04 19:40:33 +02:00
* @ param string $own_referer = '' this is our own referer
2006-10-23 13:50:30 +02:00
* @ param string $action_title = '' app_header for the action , if '' we try the link - title
2006-10-04 19:40:33 +02:00
*/
2006-10-23 13:50:30 +02:00
function index ( $values = null , $action = '' , $action_id = '' , $called_as = 0 , $extra_app_header = False , $return_html = False , $own_referer = '' , $action_title = '' )
2006-10-04 19:40:33 +02:00
{
2014-01-28 10:22:12 +01:00
unset ( $extra_app_header ); // not used, but dont want to change signature
2006-10-04 19:40:33 +02:00
if ( is_array ( $values ))
{
$called_as = $values [ 'called_as' ];
$own_referer = $values [ 'own_referer' ];
}
elseif ( $own_referer === '' )
{
2010-06-07 16:43:34 +02:00
$own_referer = common :: get_referer ();
2008-10-07 14:50:14 +02:00
if ( strpos ( $own_referer , 'menuaction=infolog.infolog_ui.edit' ) !== false )
2002-10-14 02:39:47 +02:00
{
2006-10-04 19:40:33 +02:00
$own_referer = $GLOBALS [ 'egw' ] -> session -> appsession ( 'own_session' , 'infolog' );
2002-10-14 02:39:47 +02:00
}
2006-10-04 19:40:33 +02:00
else
2006-04-05 18:16:33 +02:00
{
2006-10-04 19:40:33 +02:00
$GLOBALS [ 'egw' ] -> session -> appsession ( 'own_session' , 'infolog' , $own_referer );
2006-04-05 18:16:33 +02:00
}
2002-10-14 02:39:47 +02:00
}
2011-03-10 13:51:45 +01:00
2011-05-04 01:31:40 +02:00
// Handle legacy buttons like actions
if ( is_array ( $values ))
2011-01-26 21:16:18 +01:00
{
2011-05-04 01:31:40 +02:00
foreach ( array ( 'document' , 'view' , 'delete' ) as $button )
{
if ( isset ( $values [ 'nm' ][ 'rows' ][ $button ]))
{
list ( $id ) = @ each ( $values [ 'nm' ][ 'rows' ][ $button ]);
2011-05-06 20:13:10 +02:00
$values [ 'nm' ][ 'multi_action' ] = $button ;
2011-05-04 01:31:40 +02:00
$values [ 'nm' ][ 'selected' ] = array ( $id );
break ; // Only one can come per submit
}
}
2011-05-03 02:14:44 +02:00
}
2011-05-06 20:13:10 +02:00
if ( is_array ( $values ) && ! empty ( $values [ 'nm' ][ 'multi_action' ]))
2010-11-22 23:28:46 +01:00
{
2011-05-02 21:41:21 +02:00
if ( ! count ( $values [ 'nm' ][ 'selected' ]) && ! $values [ 'nm' ][ 'select_all' ])
2010-11-22 23:28:46 +01:00
{
$msg = lang ( 'You need to select some entries first' );
}
else
{
// Some processing to add values in for links and cats
2011-05-06 20:13:10 +02:00
$multi_action = $values [ 'nm' ][ 'multi_action' ];
2010-12-08 20:01:13 +01:00
// Action has an additional action - add / delete, etc. Buttons named <multi-action>_action[action_name]
if ( in_array ( $multi_action , array ( 'link' , 'responsible' )))
2010-11-22 23:28:46 +01:00
{
2012-06-06 22:44:39 +02:00
// eTemplate ignores the _popup namespace, but et2 doesn't
if ( $values [ $multi_action . '_popup' ])
2010-12-08 20:01:13 +01:00
{
2012-06-06 22:44:39 +02:00
$popup =& $values [ $multi_action . '_popup' ];
2010-12-08 20:01:13 +01:00
}
2012-06-06 22:44:39 +02:00
else
{
$popup =& $values ;
}
$values [ 'nm' ][ 'multi_action' ] .= '_' . key ( $popup [ $multi_action . '_action' ]);
2013-11-22 00:30:57 +01:00
if ( $multi_action == 'link' )
{
$popup [ $multi_action ] = $popup [ 'link' ][ 'app' ] . ':' . $popup [ 'link' ][ 'id' ];
}
else if ( is_array ( $popup [ $multi_action ]))
2012-06-06 22:44:39 +02:00
{
$popup [ $multi_action ] = implode ( ',' , $popup [ $multi_action ]);
}
$values [ 'nm' ][ 'multi_action' ] .= '_' . $popup [ $multi_action ];
2013-06-03 21:58:52 +02:00
unset ( $values [ $multi_action . '_popup' ]);
unset ( $values [ $multi_action ]);
2010-11-23 18:56:56 +01:00
}
2014-01-28 10:22:12 +01:00
$success = $failed = $action_msg = null ;
2011-05-06 20:13:10 +02:00
if ( $this -> action ( $values [ 'nm' ][ 'multi_action' ], $values [ 'nm' ][ 'selected' ], $values [ 'nm' ][ 'select_all' ],
2011-05-02 21:41:21 +02:00
$success , $failed , $action_msg , $values [ 'nm' ], $msg , $values [ 'nm' ][ 'checkboxes' ][ 'no_notifications' ]))
2010-11-22 23:28:46 +01:00
{
$msg .= lang ( '%1 entries %2' , $success , $action_msg );
2014-02-06 00:36:01 +01:00
egw_framework :: message ( $msg );
2010-11-22 23:28:46 +01:00
}
elseif ( is_null ( $msg ))
{
$msg .= lang ( '%1 entries %2, %3 failed because of insufficent rights !!!' , $success , $action_msg , $failed );
2014-02-06 00:36:01 +01:00
egw_framework :: message ( $msg , 'error' );
2010-11-22 23:28:46 +01:00
}
2011-06-08 01:01:49 +02:00
elseif ( $msg )
{
$msg .= " \n " . lang ( '%1 entries %2, %3 failed.' , $success , $action_msg , $failed );
2014-02-06 00:36:01 +01:00
egw_framework :: message ( $msg , 'error' );
2011-06-08 01:01:49 +02:00
}
2011-05-06 20:13:10 +02:00
unset ( $values [ 'nm' ][ 'multi_action' ]);
2011-05-02 21:41:21 +02:00
unset ( $values [ 'nm' ][ 'select_all' ]);
2010-11-22 23:28:46 +01:00
}
}
2006-10-04 19:40:33 +02:00
if ( ! $action )
2002-10-14 02:39:47 +02:00
{
2012-03-04 14:33:10 +01:00
$action = is_array ( $values ) && $values [ 'action' ] ? $values [ 'action' ] : get_var ( 'action' , array ( 'POST' , 'GET' ));
$action_id = is_array ( $values ) && $values [ 'action_id' ] ? $values [ 'action_id' ] : get_var ( 'action_id' , array ( 'POST' , 'GET' ));
$action_title = is_array ( $values ) && $values [ 'action_title' ] ? $values [ 'action_title' ] : get_var ( 'action_title' , array ( 'POST' , 'GET' ));
2006-10-04 19:40:33 +02:00
}
2008-10-22 08:51:01 +02:00
//echo "<p>".__METHOD__."(action='$action/$action_id',called_as='$called_as/$values[referer]',own_referer='$own_referer') values=\n"; _debug_array($values);
2006-10-04 19:40:33 +02:00
if ( ! is_array ( $values ))
{
2011-05-02 21:41:21 +02:00
$nm = egw_cache :: getSession ( 'infolog' , $this -> called_by . 'session_data' );
2013-11-13 23:44:28 +01:00
unset ( $nm [ 'rows' ]);
2013-11-27 01:17:08 +01:00
if ( $values === 'reset_action_view' )
2011-05-02 21:41:21 +02:00
{
2013-11-27 01:17:08 +01:00
$action = '' ;
$action_id = 0 ;
$action_title = '' ;
}
if ( $_GET [ 'ajax' ] === 'true' )
{
$nm [ 'action' ] = '' ;
$nm [ 'action_id' ] = 0 ;
$nm [ 'action_title' ] = '' ;
2012-04-04 13:57:06 +02:00
// check if action-view reset filter and restore it
if (( $filter = egw_cache :: getSession ( 'infolog' , 'filter_reset_from' )))
{
$nm [ 'filter' ] = $filter ;
egw_cache :: unsetSession ( 'infolog' , 'filter_reset_from' );
}
2011-05-02 21:41:21 +02:00
}
$values = array ( 'nm' => $nm );
2006-10-04 19:40:33 +02:00
if ( isset ( $_GET [ 'filter' ]) && $_GET [ 'filter' ] != 'default' || ! isset ( $values [ 'nm' ][ 'filter' ]) && ! $this -> called_by )
2005-11-12 14:25:59 +01:00
{
2006-10-04 19:40:33 +02:00
$values [ 'nm' ][ 'filter' ] = $_GET [ 'filter' ] && $_GET [ 'filter' ] != 'default' ? $_GET [ 'filter' ] :
$this -> prefs [ 'defaultFilter' ];
2005-07-13 10:34:38 +02:00
}
2006-10-04 19:40:33 +02:00
if ( ! isset ( $values [ 'nm' ][ 'order' ]) || ! $values [ 'nm' ][ 'order' ])
2002-10-14 02:39:47 +02:00
{
2006-10-04 19:40:33 +02:00
$values [ 'nm' ][ 'order' ] = 'info_datemodified' ;
$values [ 'nm' ][ 'sort' ] = 'DESC' ;
2002-10-18 00:02:44 +02:00
}
2011-05-02 21:41:21 +02:00
if ( ! $values [ 'nm' ][ 'session_for' ] && $this -> called_by ) $values [ 'nm' ][ 'session_for' ] = $this -> called_by ;
2012-06-14 14:06:33 +02:00
$action_id = $values [ 'action_id' ] = $action ? $action_id : $nm [ 'action_id' ];
$action_title = $values [ 'action_title' ] = $action ? $action_title : $nm [ 'action_title' ];
$action = $values [ 'action' ] = $action ? $action : $nm [ 'action' ];
2006-10-04 19:40:33 +02:00
}
2011-05-02 21:41:21 +02:00
if ( $_GET [ 'search' ]) $values [ 'nm' ][ 'search' ] = $_GET [ 'search' ];
2006-10-04 19:40:33 +02:00
if ( $values [ 'nm' ][ 'add' ])
{
$values [ 'add' ] = $values [ 'nm' ][ 'add' ];
unset ( $values [ 'nm' ][ 'add' ]);
}
2011-05-02 21:41:21 +02:00
unset ( $values [ 'nm' ][ 'rows' ][ 'checked' ]); // not longer used, but hides button actions
2014-04-28 22:25:40 +02:00
if ( $values [ 'add' ] || $values [ 'cancel' ] || isset ( $values [ 'main' ]))
2006-10-04 19:40:33 +02:00
{
if ( $values [ 'add' ])
2003-07-06 10:56:21 +02:00
{
2006-10-04 19:40:33 +02:00
list ( $type ) = each ( $values [ 'add' ]);
return $this -> edit ( 0 , $action , $action_id , $type , $called_as );
2003-07-06 10:56:21 +02:00
}
2006-10-04 19:40:33 +02:00
elseif ( $values [ 'cancel' ] && $own_referer )
2002-10-16 02:23:39 +02:00
{
2011-05-06 20:13:10 +02:00
unset ( $values [ 'nm' ][ 'multi_action' ]);
2011-05-02 21:41:21 +02:00
unset ( $values [ 'nm' ][ 'action_id' ]);
egw_cache :: setSession ( 'infolog' , $values [ 'nm' ][ 'session_for' ] . 'session_data' , $values [ 'nm' ]);
2008-04-18 13:53:55 +02:00
$this -> tmpl -> location ( $own_referer );
2002-10-14 02:39:47 +02:00
}
2006-10-04 19:40:33 +02:00
else
2002-10-14 02:39:47 +02:00
{
2014-04-28 22:25:40 +02:00
list ( $do , $do2 ) = each ( $values [ 'main' ]);
2014-01-28 10:22:12 +01:00
list ( $do_id ) = @ each ( $do2 );
2013-11-13 23:44:28 +01:00
switch (( string ) $do )
2006-10-04 19:40:33 +02:00
{
case 'close' :
2009-04-23 16:47:26 +02:00
$closesingle = true ;
case 'close_all' :
$this -> close ( $do_id , $called_as , $closesingle );
2007-04-26 14:53:03 +02:00
break ;
2006-10-04 19:40:33 +02:00
case 'view' :
$value = array ();
$action = 'sp' ;
$action_id = $do_id ;
break ;
default :
$value = array ();
2002-10-16 02:23:39 +02:00
$action = '' ;
2002-10-14 02:39:47 +02:00
$action_id = 0 ;
break ;
2006-10-04 19:40:33 +02:00
}
2002-10-14 02:39:47 +02:00
}
2006-10-04 19:40:33 +02:00
}
switch ( $action )
{
case 'sp' :
2013-06-06 14:17:33 +02:00
if ( ! is_array ( $action_id ) && strpos ( $action_id , 'infolog:' ) === 0 ) $action_id = ( int ) substr ( $action_id , 8 );
2011-05-03 02:14:44 +02:00
if (( is_array ( $action_id ) && ! $this -> bo -> read ( current ( $action_id ))) || ! $this -> bo -> read ( $action_id ))
2006-10-04 19:40:33 +02:00
{
$action = '' ;
$action_id = 0 ;
break ;
}
2013-11-06 19:43:47 +01:00
else
{
$values [ 'nm' ][ 'col_filter' ][ 'info_id_parent' ] = $action_id ;
}
2006-10-04 19:40:33 +02:00
break ;
2013-11-13 23:44:28 +01:00
default :
2014-03-26 20:36:54 +01:00
// Nothing
2006-10-04 19:40:33 +02:00
}
$readonlys [ 'cancel' ] = $action != 'sp' ;
2002-10-14 02:39:47 +02:00
2006-10-04 19:40:33 +02:00
$this -> tmpl -> read ( 'infolog.index' );
$values [ 'nm' ][ 'options-filter' ] = $this -> filters ;
2008-10-07 14:50:14 +02:00
$values [ 'nm' ][ 'get_rows' ] = 'infolog.infolog_ui.get_rows' ;
2006-10-04 19:40:33 +02:00
$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' ];
2012-05-08 19:06:53 +02:00
2013-08-26 11:19:47 +02:00
//apply infolog_filter_change javascript method (hide/show of date filter form) over onchange filter
2013-08-27 12:46:42 +02:00
$values [ 'nm' ][ 'filter_onchange' ] = " app.infolog.filter_change(); " ;
2013-08-26 11:19:47 +02:00
//apply infolog_filter2_change javascript method (show/hide details each rows) over onchange filter2
2013-08-27 12:46:42 +02:00
$values [ 'nm' ][ 'filter2_onchange' ] = " app.infolog.filter2_change(); " ;
2013-10-04 14:48:11 +02:00
2014-03-10 20:47:09 +01:00
// disable favories dropdown button, if not running as infolog
if ( $called_as && $called_as != 'infolog' )
{
$values [ 'nm' ][ 'favorites' ] = false ;
}
else
{
// Allow saving parent ID into favorites
$values [ 'nm' ][ 'favorites' ] = array ( 'action' , 'action_id' );
}
2013-11-19 22:59:42 +01:00
2013-10-01 09:46:24 +02:00
// Allow add actions even when there's no rows
$values [ 'nm' ][ 'placeholder_actions' ] = array ( 'new' );
2012-05-15 18:24:06 +02:00
2007-03-07 13:31:48 +01:00
// disable columns for main entry as set in the pref for details or no details
if ( $action == 'sp' )
{
$pref = 'nextmatch-infolog.index.rows' . ( $values [ 'nm' ][ 'filter2' ] == 'all' ? '-details' : '' );
2008-10-08 11:40:23 +02:00
foreach ( array ( 'info_used_time_info_planned_time_info_replanned_time' , 'info_datemodified' , 'info_owner_info_responsible' , 'customfields' ) as $name )
2007-03-07 13:31:48 +01:00
{
2007-05-08 10:36:06 +02:00
$values [ 'main' ][ 'no_' . $name ] = strpos ( $this -> prefs [ $pref ], $name ) === false ;
2007-03-07 13:31:48 +01:00
}
2008-04-18 13:53:55 +02:00
if ( ! $values [ 'main' ][ 'no_customfields' ])
2007-12-14 14:11:51 +01:00
{
// set the column-header of the main table for the customfields.
2014-01-28 10:22:12 +01:00
foreach ( array_keys ( $this -> bo -> customfields ) as $lname )
2007-12-14 14:11:51 +01:00
{
$values [ 'main' ][ 'customfields' ] .= $lname . " \n " ;
}
}
2007-03-07 13:31:48 +01:00
}
2014-03-12 11:12:29 +01:00
$values [ 'nm' ][ 'header_row' ] = 'infolog.index.header_right' ;
2009-11-10 09:11:41 +01:00
if ( $values [ 'nm' ][ 'filter' ] == 'bydate' )
{
2014-01-28 10:22:12 +01:00
foreach ( array_keys ( $values [ 'nm' ][ 'col_filter' ]) as $colfk )
{
if ( is_int ( $colfk )) unset ( $values [ 'nm' ][ 'col_filter' ]);
}
2012-04-30 22:29:34 +02:00
}
2006-10-04 19:40:33 +02:00
$values [ 'action' ] = $persist [ 'action' ] = $values [ 'nm' ][ 'action' ] = $action ;
$values [ 'action_id' ] = $persist [ 'action_id' ] = $values [ 'nm' ][ 'action_id' ] = $action_id ;
2006-10-23 13:50:30 +02:00
$values [ 'action_title' ] = $persist [ 'action_title' ] = $values [ 'nm' ][ 'action_title' ] = $action_title ;
2006-10-04 19:40:33 +02:00
$persist [ 'called_as' ] = $called_as ;
$persist [ 'own_referer' ] = $own_referer ;
2011-05-02 21:41:21 +02:00
// store whole $values[nm] in etemplate request
unset ( $values [ 'nm' ][ 'rows' ]);
$persist [ 'nm' ] = $values [ 'nm' ];
2006-10-04 19:40:33 +02:00
if ( ! $called_as )
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'params' ][ 'manual' ] = array ( 'page' => 'ManualInfologIndex' );
}
else
{
$values [ 'css' ] = '<style type="text/css">@import url(' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . '/infolog/templates/default/app.css);' . " </style> " ;
2013-11-27 01:17:08 +01:00
// Avoid DOM conflicts
$this -> tmpl -> set_dom_id ( " { $this -> tmpl -> name } - $action - $action_id " );
2006-10-04 19:40:33 +02:00
}
2011-01-05 16:45:27 +01:00
// add scrollbar to long description, if user choose so in his prefs
2014-01-28 10:22:12 +01:00
if ( $this -> prefs [ 'limit_des_lines' ] > 0 || ( string ) $this -> prefs [ 'limit_des_lines' ] == '' )
2009-05-08 18:01:33 +02:00
{
2011-01-05 16:45:27 +01:00
$values [ 'css' ] .= '<style type="text/css">@media screen { .infoDes { ' .
2014-01-14 16:05:23 +01:00
' max-height: ' .
2009-05-08 18:01:33 +02:00
(( $this -> prefs [ 'limit_des_lines' ] ? $this -> prefs [ 'limit_des_lines' ] : 5 ) * 1.35 ) . // dono why em is not real lines
'em; overflow: auto; }}</style>' ;
}
2011-01-05 16:45:27 +01:00
2009-09-19 15:58:24 +02:00
$sel_options = array (
2011-04-27 18:33:23 +02:00
'info_type' => $this -> bo -> enums [ 'type' ],
'pm_id' => array ( lang ( 'No project' )),
2012-01-09 10:35:30 +01:00
'info_priority' => $this -> bo -> enums [ 'priority' ],
2009-09-19 15:58:24 +02:00
);
2010-11-22 23:28:46 +01:00
2012-04-24 12:15:47 +02:00
// remove group-types user has not any rights to as filter
// does not take implicit rights as delegated into account, so they will not be available as filters
foreach ( $this -> bo -> group_owners as $type => $group )
{
if ( ! isset ( $this -> bo -> grants [ $group ])) unset ( $sel_options [ 'info_type' ][ $type ]);
}
2011-05-02 21:41:21 +02:00
return $this -> tmpl -> exec ( 'infolog.infolog_ui.index' , $values , $sel_options , $readonlys , $persist , $return_html ? - 1 : 0 );
}
2011-11-10 14:44:57 +01:00
/**
* Get valid types
*
* @ return array - array of valid types
*/
private function get_validtypes ()
2011-05-02 21:41:21 +02:00
{
2010-11-22 23:28:46 +01:00
// Types
2011-05-02 21:41:21 +02:00
$types = $this -> bo -> enums [ 'type' ];
2010-11-23 18:56:56 +01:00
if ( $this -> bo -> group_owners )
{
// remove types owned by groups the user has no edit grant
foreach ( $this -> bo -> group_owners as $type => $group )
{
if ( ! ( $this -> bo -> grants [ $group ] & EGW_ACL_EDIT ))
{
2011-05-02 21:41:21 +02:00
unset ( $types [ $type ]);
2010-11-23 18:56:56 +01:00
}
}
2010-11-22 23:28:46 +01:00
}
2011-11-10 14:38:23 +01:00
return $types ;
}
/**
* Get actions / context menu items
*
* @ param array $query
* @ return array see nextmatch_widget :: get_actions ()
*/
private function get_actions ( array $query )
{
2014-01-28 10:22:12 +01:00
for ( $i = 0 ; $i <= 100 ; $i += 10 )
{
$percent [ $i ] = $i . '%' ;
}
2011-11-10 14:38:23 +01:00
// Types
$types = $this -> get_validtypes ();
2011-05-02 21:41:21 +02:00
$types_add = array ();
foreach ( $types as $type => & $data )
{
2013-09-16 13:54:43 +02:00
if ( $type == 'email' ) continue ; //requirement by sales that it should not be shown in right - click - action dialog
2011-05-02 21:41:21 +02:00
$data = array (
'caption' => $data ,
'icon' => $type ,
);
$types_add [ $type ] = $data + array (
'url' => 'menuaction=infolog.infolog_ui.edit&type=' . $type ,
'popup' => egw_link :: get_registry ( 'infolog' , 'add_popup' ),
);
}
2010-11-22 23:28:46 +01:00
2014-01-28 10:22:12 +01:00
$icons = null ;
2012-05-22 19:39:28 +02:00
$statis = $this -> bo -> get_status ( $query [ 'col_filter' ][ 'info_type' ], $icons );
2011-05-02 21:41:21 +02:00
foreach ( $statis as $type => & $data )
2010-11-22 23:28:46 +01:00
{
2011-05-02 21:41:21 +02:00
$data = array (
'caption' => $data ,
2012-05-15 18:24:06 +02:00
'icon' => $icons [ $type ],
2011-05-02 21:41:21 +02:00
);
2010-11-22 23:28:46 +01:00
}
2011-01-26 21:16:18 +01:00
2011-05-02 21:41:21 +02:00
$actions = array (
'open' => array (
'caption' => 'Open' ,
'default' => true ,
'allowOnMultiple' => false ,
'url' => 'menuaction=infolog.infolog_ui.edit&info_id=$id' ,
'popup' => egw_link :: get_registry ( 'infolog' , 'add_popup' ),
'group' => $group = 1 ,
),
2011-05-03 09:26:32 +02:00
'view' => array (
2011-05-02 21:41:21 +02:00
'caption' => 'View subs' ,
2012-03-20 12:18:33 +01:00
'icon' => 'egw_action/arrow_left' ,
2011-05-02 21:41:21 +02:00
'group' => $group ,
'hint' => 'View all subs of this entry' ,
2013-09-19 14:52:50 +02:00
'enableClass' => 'infolog_rowHasSubs' ,
2013-09-24 11:16:06 +02:00
'enabled' => true ,
2011-05-02 21:41:21 +02:00
),
'parent' => array (
'caption' => 'View parent' ,
2012-03-20 12:18:33 +01:00
'icon' => 'egw_action/arrow_up' ,
2011-05-02 21:41:21 +02:00
'group' => $group ,
'hideOnDisabled' => true ,
'hint' => 'View the parent of this entry and all his subs' ,
2013-09-24 11:16:06 +02:00
'enabled' => true ,
2013-09-19 14:52:50 +02:00
'enableClass' => 'infolog_rowHasParent'
2011-05-02 21:41:21 +02:00
),
'add' => array (
'caption' => 'Add' ,
'group' => $group ,
'children' => array (
'new' => array (
'caption' => 'New' ,
'children' => $types_add ,
'icon' => 'task' ,
),
'sub' => array (
'caption' => 'Sub-entry' ,
'url' => 'menuaction=infolog.infolog_ui.edit&action=sp&action_id=$id' ,
'popup' => egw_link :: get_registry ( 'infolog' , 'add_popup' ),
'allowOnMultiple' => false ,
'hint' => 'Add a new sub-task, -note, -call to this entry' ,
'icon' => 'new' ,
),
'copy' => array (
'caption' => 'Copy' ,
'url' => 'menuaction=infolog.infolog_ui.edit&action=copy&info_id=$id' ,
'popup' => egw_link :: get_registry ( 'infolog' , 'add_popup' ),
'allowOnMultiple' => false ,
'icon' => 'copy' ,
),
),
),
'no_notifications' => array (
'caption' => 'Do not notify' ,
'checkbox' => true ,
'hint' => 'Do not notify of these changes' ,
'group' => $group ,
),
// modifying content of one or multiple infolog(s)
'change' => array (
'caption' => 'Change' ,
'group' => ++ $group ,
'icon' => 'edit' ,
'disableClass' => 'rowNoEdit' ,
'children' => array (
'type' => array (
'caption' => 'Type' ,
'prefix' => 'type_' ,
'children' => $types ,
'group' => $group ,
'icon' => 'task' ,
),
'status' => array (
'caption' => 'Status' ,
'prefix' => 'status_' ,
'children' => $statis ,
'group' => $group ,
'icon' => 'ongoing' ,
),
'completion' => array (
'caption' => 'Completed' ,
'prefix' => 'completion_' ,
'children' => $percent ,
'group' => $group ,
'icon' => 'completed' ,
),
'cat' => nextmatch_widget :: category_action (
'infolog' , $group , 'Change category' , 'cat_'
),
'responsible' => array (
'caption' => 'Delegation' ,
'group' => $group ,
'icon' => 'users' ,
2011-05-07 10:51:35 +02:00
'nm_action' => 'open_popup' ,
2011-05-02 21:41:21 +02:00
),
'link' => array (
'caption' => 'Links' ,
'group' => $group ,
2011-05-07 10:51:35 +02:00
'nm_action' => 'open_popup' ,
2011-05-02 21:41:21 +02:00
),
),
),
'close' => array (
'caption' => 'Close' ,
'icon' => 'done' ,
'group' => $group ,
2011-05-03 09:26:32 +02:00
'disableClass' => 'rowNoClose' ,
2011-05-02 21:41:21 +02:00
),
'close_all' => array (
'caption' => 'Close all' ,
'icon' => 'done_all' ,
'group' => $group ,
'hint' => 'Sets the status of this entry and its subs to done' ,
'allowOnMultiple' => false ,
2011-05-03 09:26:32 +02:00
'disableClass' => 'rowNoCloseAll' ,
2011-05-02 21:41:21 +02:00
),
2014-05-20 12:51:37 +02:00
'print' => array (
'caption' => 'Print' ,
'icon' => 'print' ,
'group' => $group ,
'onExecute' => 'javaScript:app.infolog.infolog_menu_print'
)
2011-05-02 21:41:21 +02:00
);
++ $group ; // integration with other apps
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'filemanager' ])
{
$actions [ 'filemanager' ] = array (
'icon' => 'filemanager/navbar' ,
'caption' => 'Filemanager' ,
2014-01-16 18:23:39 +01:00
'url' => 'menuaction=filemanager.filemanager_ui.index&path=/apps/infolog/$id&ajax=true' ,
2011-05-02 21:41:21 +02:00
'allowOnMultiple' => false ,
'group' => $group ,
);
}
2011-12-09 00:20:49 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'calendar' ])
{
$actions [ 'calendar' ] = array ( // interactive add for a single event
'icon' => 'calendar/navbar' ,
2012-02-22 13:31:00 +01:00
'caption' => 'Schedule appointment' ,
2011-12-09 00:20:49 +01:00
'group' => $group ,
2011-12-12 22:51:12 +01:00
'url' => 'menuaction=calendar.calendar_uiforms.edit&' .
egw_link :: get_registry ( 'calendar' , 'add_app' ) . '[]=infolog&' . egw_link :: get_registry ( 'calendar' , 'add_id' ) . '[]=$id' ,
2011-12-09 00:20:49 +01:00
'allowOnMultiple' => false ,
2011-12-12 22:51:12 +01:00
'popup' => egw_link :: get_registry ( 'calendar' , 'add_popup' ),
2011-12-09 00:20:49 +01:00
);
}
2011-05-02 21:41:21 +02:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'timesheet' ])
2011-04-27 18:33:23 +02:00
{
2011-05-02 21:41:21 +02:00
$actions [ 'timesheet' ] = array ( // interactive add for a single event
'icon' => 'timesheet/navbar' ,
'caption' => 'Timesheet' ,
'url' => 'menuaction=timesheet.timesheet_ui.edit&link_app[]=infolog&link_id[]=$id' ,
'group' => $group ,
'allowOnMultiple' => false ,
'popup' => egw_link :: get_registry ( 'timesheet' , 'add_popup' ),
);
2011-04-27 18:33:23 +02:00
}
2011-12-13 19:25:08 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'tracker' ])
{
2012-01-26 02:43:14 +01:00
$actions [ 'tracker' ] = array (
2011-12-13 19:25:08 +01:00
'icon' => 'tracker/navbar' ,
'caption' => 'Tracker' ,
2013-10-25 10:18:59 +02:00
'hint' => 'Convert to a ticket' ,
2011-12-13 19:25:08 +01:00
'group' => $group ,
'url' => 'menuaction=tracker.tracker_ui.edit&' .
egw_link :: get_registry ( 'tracker' , 'add_app' ) . '[]=infolog&' . egw_link :: get_registry ( 'tracker' , 'add_id' ) . '[]=$id' ,
'allowOnMultiple' => false ,
'popup' => egw_link :: get_registry ( 'tracker' , 'add_popup' ),
);
}
2010-11-22 23:28:46 +01:00
2011-05-02 21:41:21 +02:00
$actions [ 'documents' ] = infolog_merge :: document_action (
$this -> prefs [ 'document_dir' ], ++ $group , 'Insert in document' , 'document_' ,
$this -> prefs [ 'default_document' ]
);
2012-04-03 01:08:20 +02:00
$actions [ 'ical' ] = array (
2014-02-20 12:07:12 +01:00
'icon' => 'ical' ,
2012-04-03 01:08:20 +02:00
'caption' => 'Export iCal' ,
2013-10-04 14:48:11 +02:00
'postSubmit' => true , // download needs post submit to work
2012-04-03 01:08:20 +02:00
'group' => $group ,
'allowOnMultiple' => true ,
);
2011-05-02 21:41:21 +02:00
$actions [ 'delete' ] = array (
'caption' => 'Delete' ,
'group' => ++ $group ,
'disableClass' => 'rowNoDelete' ,
2013-09-16 19:53:20 +02:00
'onExecute' => 'javaScript:app.infolog.confirm_delete' ,
2011-05-02 21:41:21 +02:00
);
2011-05-05 12:18:38 +02:00
if ( $query [ 'col_filter' ][ 'info_status' ] == 'deleted' )
{
$actions [ 'undelete' ] = array (
'caption' => 'Un-Delete' ,
'group' => $group ,
2011-06-01 17:52:47 +02:00
'icon' => 'revert' ,
2011-05-05 12:18:38 +02:00
'disableClass' => 'rowNoUndelete' ,
);
}
2011-05-02 21:41:21 +02:00
//echo "<p>".__METHOD__."($do_email, $tid_filter, $org_view)</p>\n"; _debug_array($actions);
return $actions ;
2006-10-04 19:40:33 +02:00
}
2002-10-14 02:39:47 +02:00
2010-11-22 23:28:46 +01:00
/**
* Handles actions on multiple infologs
*
2011-03-10 13:51:45 +01:00
* @ param action
2010-11-22 23:28:46 +01:00
* @ param array $checked contact id ' s to use if ! $use_all
2010-12-10 10:10:39 +01:00
* @ param boolean $use_all if true use all entries of the current selection ( in the session )
* @ param int & $success number of succeded actions
* @ param int & $failed number of failed actions ( not enought permissions )
* @ param string & $action_msg translated verb for the actions , to be used in a message like '%1 entries deleted'
2011-05-02 21:41:21 +02:00
* @ param array $query get_rows parameter
* @ param string & $msg on return user feedback
2014-06-12 14:34:50 +02:00
* @ param boolean $skip_notifications true to NOT notify users about changes
2010-12-10 10:10:39 +01:00
* @ return boolean true if all actions succeded , false otherwise
*/
2011-05-02 21:41:21 +02:00
function action ( $action , $checked , $use_all , & $success , & $failed , & $action_msg ,
array $query , & $msg , $skip_notifications = false )
2010-11-22 23:28:46 +01:00
{
2011-05-03 09:26:32 +02:00
//echo '<p>'.__METHOD__."('$action',".array2string($checked).','.(int)$use_all.",...)</p>\n";
2010-11-22 23:28:46 +01:00
$success = $failed = 0 ;
if ( $use_all )
{
2011-05-02 21:41:21 +02:00
@ set_time_limit ( 0 ); // switch off the execution time limit, as it's for big selections to small
$query [ 'num_rows' ] = - 1 ; // all
2014-01-28 10:22:12 +01:00
$result = $readonlys = null ;
2011-05-02 21:41:21 +02:00
$this -> get_rows ( $query , $result , $readonlys );
$checked = array ();
foreach ( $result as $key => $info )
2010-11-22 23:28:46 +01:00
{
2011-05-02 21:41:21 +02:00
if ( is_numeric ( $key ))
2010-11-23 18:56:56 +01:00
{
2011-05-02 21:41:21 +02:00
$checked [] = $info [ 'info_id' ];
2010-11-23 18:56:56 +01:00
}
2010-11-22 23:28:46 +01:00
}
}
2011-03-10 13:51:45 +01:00
2010-11-22 23:28:46 +01:00
// Actions with options in the selectbox
list ( $action , $settings ) = explode ( '_' , $action , 2 );
// Actions that can handle a list of IDs
switch ( $action )
{
case 'link' :
list ( $add_remove , $link ) = explode ( '_' , $settings , 2 );
2012-04-18 17:33:20 +02:00
list ( $app , $link_id ) = explode ( strpos ( $link , ':' ) !== false ? ':' : ',' , $link );
2010-11-22 23:28:46 +01:00
if ( ! $link_id )
{
$action_msg = 'linked' ;
2011-05-02 21:41:21 +02:00
$msg = lang ( 'You need to select an entry for linking.' );
2010-11-22 23:28:46 +01:00
break ;
}
$title = egw_link :: title ( $app , $link_id );
foreach ( $checked as $id )
{
2011-05-02 21:41:21 +02:00
if ( ! $this -> bo -> check_access ( $id , EGW_ACL_EDIT ))
{
2010-11-23 18:56:56 +01:00
$failed ++ ;
continue ;
}
2011-05-02 21:41:21 +02:00
if ( $add_remove == 'add' )
{
2010-11-22 23:28:46 +01:00
$action_msg = lang ( 'linked to %1' , $title );
if ( egw_link :: link ( 'infolog' , $id , $app , $link_id ))
{
$success ++ ;
}
else
{
$failed ++ ;
}
2011-05-02 21:41:21 +02:00
}
else
{
2010-11-22 23:28:46 +01:00
$action_msg = lang ( 'unlinked from %1' , $title );
$count = egw_link :: unlink ( 0 , 'infolog' , $id , '' , $app , $link_id );
$success += $count ;
}
}
2011-05-02 21:41:21 +02:00
return $failed == 0 ;
2011-01-26 21:16:18 +01:00
case 'document' :
2011-06-14 12:48:15 +02:00
if ( ! $settings ) $settings = $this -> prefs [ 'default_document' ];
$document_merge = new infolog_merge ();
$msg = $document_merge -> download ( $settings , $checked , '' , $this -> prefs [ 'document_dir' ]);
2011-01-26 21:16:18 +01:00
$failed = count ( $checked );
2011-05-02 21:41:21 +02:00
return false ;
2011-05-03 02:14:44 +02:00
case 'parent' :
$parent_query = array ( 'col_filter' => array ( 'info_id' => $checked ));
$result = $this -> bo -> search ( $parent_query );
$parents = array ();
foreach ( $result as $key => $info )
{
if ( is_numeric ( $key ))
{
$parents [] = $info [ 'info_id_parent' ];
}
}
$checked = array_unique ( $parents );
// Fall through
2011-05-03 08:26:56 +02:00
2011-05-02 21:41:21 +02:00
case 'view' :
2012-04-04 13:57:06 +02:00
// remember filter to restore it, if infolog icon get's clicked next time
if ( $query [ 'filter' ]) egw_cache :: setSession ( 'infolog' , 'filter_reset_from' , $query [ 'filter' ]);
2012-06-18 20:52:05 +02:00
$this -> index ( array (), 'sp' , $checked , 0 );
common :: egw_exit ();
2012-04-03 01:08:20 +02:00
case 'ical' :
2012-04-05 17:57:06 +02:00
// infolog_ical lets horde be auto-loaded, so it must go first
2012-04-03 01:08:20 +02:00
$boical = new infolog_ical ();
2014-01-19 10:30:33 +01:00
html :: content_header ( 'todo.ics' , 'text/calendar' );
2012-04-11 18:51:23 +02:00
echo $boical -> exportvCalendar ( $checked );
2012-04-03 01:08:20 +02:00
common :: egw_exit ();
2012-04-11 18:51:23 +02:00
2010-11-22 23:28:46 +01:00
}
// Actions that need to loop
foreach ( $checked as $id )
2011-05-02 21:41:21 +02:00
{
2010-11-22 23:28:46 +01:00
if ( ! $entry = $this -> bo -> read ( $id ))
{
continue ;
}
2011-05-02 21:41:21 +02:00
switch ( $action )
{
2010-11-22 23:28:46 +01:00
case 'close' :
$action_msg = lang ( 'closed' );
2010-12-08 23:09:59 +01:00
$this -> close ( $id , '' , false , $skip_notifications );
2010-11-22 23:28:46 +01:00
$success ++ ;
break ;
2011-05-02 21:41:21 +02:00
2010-11-22 23:28:46 +01:00
case 'delete' :
2011-05-04 01:31:40 +02:00
$action_msg = $settings == 'sub' ? lang ( ' (and children) deleted' ) : lang ( 'deleted' );
2011-05-05 08:30:44 +02:00
$result = $this -> bo -> delete ( $id , $settings == 'sub' , false , $skip_notifications );
2011-05-04 01:31:40 +02:00
if ( $result == true )
2010-12-09 20:56:05 +01:00
{
$success ++ ;
}
else
{
$failed ++ ;
}
2010-11-22 23:28:46 +01:00
break ;
2011-05-02 21:41:21 +02:00
2010-11-22 23:28:46 +01:00
case 'type' :
$action_msg = lang ( 'changed type' );
2010-12-08 18:27:56 +01:00
// Dont allow to change the type, if user has no delete rights from the group-owner
if ( $id && ! ( $this -> bo -> grants [ $entry [ 'info_owner' ]] & EGW_ACL_DELETE ))
{
$failed ++ ;
break ;
}
2010-11-22 23:28:46 +01:00
$entry [ 'info_type' ] = $settings ;
2011-06-08 01:01:49 +02:00
try {
$this -> bo -> write ( $entry , true , true , true , $skip_notifications , true ); // Throw exceptions
2012-11-13 13:07:10 +01:00
}
catch ( egw_exception_wrong_userinput $e )
{
2011-06-08 01:01:49 +02:00
$msg .= " \n " . $e -> getMessage ();
$failed ++ ;
break ;
}
2010-11-22 23:28:46 +01:00
$success ++ ;
break ;
2010-11-23 18:56:56 +01:00
case 'completion' :
$action_msg = lang ( 'changed completion to %1%' , $settings );
$entry [ 'info_percent' ] = $settings ;
// Done entries will get changed right back if we don't change the status too
2011-05-02 21:41:21 +02:00
if ( $entry [ 'info_status' ] == 'done' )
{
2010-11-23 18:56:56 +01:00
$entry [ 'info_status' ] = 'ongoing' ;
}
2010-12-08 23:09:59 +01:00
if ( $this -> bo -> write ( $entry , true , true , true , $skip_notifications ))
2010-11-23 18:56:56 +01:00
{
$success ++ ;
}
2011-03-10 13:51:45 +01:00
else
2010-11-23 18:56:56 +01:00
{
$failed ++ ;
}
break ;
2011-05-05 12:18:38 +02:00
case 'undelete' : // set it to valid status != 'deleted' for that type
$settings = isset ( $this -> bo -> status [ $entry [ 'info_type' ]][ 'done' ]) ?
$this -> bo -> status [ $entry [ 'info_type' ]][ 'done' ] :
$this -> bo -> status [ 'defaults' ][ $entry [ 'info_type' ]];
// fall-through
2010-11-22 23:28:46 +01:00
case 'status' :
2012-05-15 18:24:06 +02:00
if ( isset ( $this -> bo -> status [ $entry [ 'info_type' ]][ $settings ]))
2011-05-03 09:26:32 +02:00
{
2010-11-22 23:28:46 +01:00
$action_msg = lang ( 'changed status to %1' , lang ( $this -> bo -> status [ $entry [ 'info_type' ]][ $settings ]));
2010-11-23 22:45:00 +01:00
if ( $settings != 'done' && $entry [ 'info_status' ] == 'done' && $entry [ 'info_percent' ] == 100 )
{
// Done entries will get changed right back if we don't change the completion too
2010-11-23 22:50:36 +01:00
$entry [ 'info_percent' ] = 99 ;
2010-11-23 22:45:00 +01:00
}
2010-11-22 23:28:46 +01:00
$entry [ 'info_status' ] = $settings ;
2010-12-08 23:09:59 +01:00
if ( $this -> bo -> write ( $entry , true , true , true , $skip_notifications ))
{
2010-11-22 23:28:46 +01:00
$success ++ ;
}
2011-05-02 21:41:21 +02:00
}
else
{
2011-05-07 10:51:35 +02:00
$msg .= lang ( 'Invalid status for entry type %1.' , lang ( $this -> bo -> enums [ 'type' ][ $entry [ 'info_type' ]]));
2010-11-22 23:28:46 +01:00
$failed ++ ;
}
break ;
2011-05-02 21:41:21 +02:00
2010-11-22 23:28:46 +01:00
case 'cat' :
2012-10-15 19:57:58 +02:00
if ( $settings )
{
$cat_name = categories :: id2name ( $settings );
$action_msg = lang ( 'changed category to %1' , $cat_name );
}
else
{
$action_msg = lang ( 'removed category' );
}
2010-11-22 23:28:46 +01:00
$entry [ 'info_cat' ] = $settings ;
2010-12-08 23:09:59 +01:00
if ( $this -> bo -> write ( $entry , true , true , true , $skip_notifications ))
2010-11-22 23:28:46 +01:00
{
$success ++ ;
}
else
{
$failed ++ ;
}
break ;
2011-05-02 21:41:21 +02:00
2010-12-08 20:01:13 +01:00
case 'responsible' :
2014-01-28 10:22:12 +01:00
list ( $add_remove , $user_str ) = explode ( '_' , $settings , 2 );
2011-05-07 10:51:35 +02:00
$action_msg = ( $add_remove == 'add' ? lang ( 'added' ) : lang ( 'removed' )) . ' ' ;
2010-12-08 20:01:13 +01:00
$names = array ();
2014-01-28 10:22:12 +01:00
$users = explode ( ',' , $user_str );
2011-05-07 10:51:35 +02:00
foreach ( $users as $account_id )
2011-05-03 09:26:32 +02:00
{
$names [] = common :: grab_owner_name ( $account_id );
2010-12-08 20:01:13 +01:00
}
$action_msg .= implode ( ', ' , $names );
$function = $add_remove == 'add' ? 'array_merge' : 'array_diff' ;
2011-05-07 10:51:35 +02:00
$entry [ 'info_responsible' ] = array_unique ( $function ( $entry [ 'info_responsible' ], ( array ) $users ));
2010-12-08 23:09:59 +01:00
if ( $this -> bo -> write ( $entry , true , true , true , $skip_notifications ))
2010-12-08 20:01:13 +01:00
{
$success ++ ;
}
else
{
$failed ++ ;
}
break ;
2010-11-22 23:28:46 +01:00
}
}
2011-05-02 21:41:21 +02:00
return $failed == 0 ;
2010-11-22 23:28:46 +01:00
}
2008-10-22 08:51:01 +02:00
/**
* Closes an infolog
*
* @ param int | array $values = 0 info_id ( default _GET [ info_id ])
* @ param string $referer = ''
2009-07-15 22:04:17 +02:00
* @ param boolean $closesingle = false
2008-10-22 08:51:01 +02:00
*/
2010-12-08 23:09:59 +01:00
function close ( $values = 0 , $referer = '' , $closesingle = false , $skip_notification = false )
2006-10-04 19:40:33 +02:00
{
2009-04-23 16:47:26 +02:00
//echo "<p>".__METHOD__."($values,$referer,$closeall)</p>\n";
2006-10-04 19:40:33 +02:00
$info_id = ( int ) ( is_array ( $values ) ? $values [ 'info_id' ] : ( $values ? $values : $_GET [ 'info_id' ]));
$referer = is_array ( $values ) ? $values [ 'referer' ] : $referer ;
2008-04-18 13:53:55 +02:00
2006-10-04 19:40:33 +02:00
if ( $info_id )
2005-10-05 09:50:47 +02:00
{
2009-04-23 16:47:26 +02:00
$info = $this -> bo -> read ( $info_id );
#_debug_array($info);
$status = $info [ 'info_status' ];
// closed stati assumed array('done','billed','cancelled')
if ( isset ( $this -> bo -> status [ $info [ 'info_type' ]][ 'done' ])) {
$status = 'done' ;
} elseif ( isset ( $this -> bo -> status [ $info [ 'info_type' ]][ 'billed' ])) {
$status = 'billed' ;
} elseif ( isset ( $this -> bo -> status [ $info [ 'info_type' ]][ 'cancelled' ])) {
$status = 'cancelled' ;
}
#_debug_array($status);
2006-10-04 19:40:33 +02:00
$values = array (
'info_id' => $info_id ,
2009-04-23 16:47:26 +02:00
'info_type' => $info [ 'info_type' ],
'info_status' => $status ,
2006-10-04 19:40:33 +02:00
'info_percent' => 100 ,
'info_datecompleted' => $this -> bo -> now_su ,
);
2010-12-08 23:09:59 +01:00
$this -> bo -> write ( $values , true , true , true , $skip_notification );
2008-04-18 13:53:55 +02:00
2006-10-04 19:40:33 +02:00
$query = array ( 'action' => 'sp' , 'action_id' => $info_id );
2009-04-23 16:47:26 +02:00
if ( ! $closesingle ) {
foreach (( array ) $this -> bo -> search ( $query ) as $info )
2005-12-06 08:11:14 +01:00
{
2009-04-23 16:47:26 +02:00
if ( $info [ 'info_id_parent' ] == $info_id ) // search also returns linked entries!
{
2014-01-28 10:22:12 +01:00
$this -> close ( $info [ 'info_id' ], $referer , $closesingle , $skip_notification ); // we call ourselfs recursive to process subs from subs too
2009-04-23 16:47:26 +02:00
}
2005-12-06 08:11:14 +01:00
}
2005-10-05 09:50:47 +02:00
}
}
2007-04-26 14:53:03 +02:00
if ( $referer ) $this -> tmpl -> location ( $referer );
2006-10-04 19:40:33 +02:00
}
2005-10-05 09:50:47 +02:00
2008-10-22 08:51:01 +02:00
/**
* Deletes an InfoLog entry
*
2014-06-12 14:34:50 +02:00
* @ param array | int $values info_id ( default _GET [ info_id ])
* @ param string $referer
* @ param string $called_by
2010-12-08 23:09:59 +01:00
* @ param boolean $skip_notification Do not send notification of deletion
2008-10-22 08:51:01 +02:00
*/
2010-12-08 23:09:59 +01:00
function delete ( $values = 0 , $referer = '' , $called_by = '' , $skip_notification = False )
2006-10-04 19:40:33 +02:00
{
$info_id = ( int ) ( is_array ( $values ) ? $values [ 'info_id' ] : ( $values ? $values : $_GET [ 'info_id' ]));
$referer = is_array ( $values ) ? $values [ 'referer' ] : $referer ;
2008-04-18 13:53:55 +02:00
2006-10-04 19:40:33 +02:00
if ( ! is_array ( $values ) && $info_id > 0 && ! $this -> bo -> anzSubs ( $info_id )) // entries without subs get confirmed by javascript
2002-10-16 02:23:39 +02:00
{
2006-10-04 19:40:33 +02:00
$values = array ( 'delete' => true );
}
2008-10-07 14:50:14 +02:00
//echo "<p>infolog_ui::delete(".print_r($values,true).",'$referer','$called_by') info_id=$info_id</p>\n";
2006-10-04 19:40:33 +02:00
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 ))
2005-11-12 14:25:59 +01:00
{
2010-12-08 23:09:59 +01:00
$deleted = $this -> bo -> delete ( $info_id , $values [ 'delete_subs' ], $values [ 'info_id_parent' ], $skip_notification );
2005-11-12 14:25:59 +01:00
}
2006-10-04 19:40:33 +02:00
if ( $called_by ) // direct call from the same request
2002-10-16 02:23:39 +02:00
{
2006-10-04 19:40:33 +02:00
return $deleted ? lang ( 'InfoLog entry deleted' ) : '' ;
2002-10-16 02:23:39 +02:00
}
2006-10-04 19:40:33 +02:00
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' ]);
2002-10-16 02:23:39 +02:00
2006-10-04 19:40:33 +02:00
$this -> tmpl -> read ( 'infolog.delete' );
2002-10-16 02:23:39 +02:00
2006-10-04 19:40:33 +02:00
$values [ 'nm' ] = array (
'action' => 'sp' ,
'action_id' => $info_id ,
'options-filter' => $this -> filters ,
2008-10-07 14:50:14 +02:00
'get_rows' => 'infolog.infolog_ui.get_rows' ,
2014-01-14 16:05:23 +01:00
'no_filter2' => True
2006-10-04 19:40:33 +02:00
);
$values [ 'main' ][ 'no_actions' ] = $values [ 'nm' ][ 'no_actions' ] = True ;
2005-11-12 14:25:59 +01:00
2006-10-04 19:40:33 +02:00
$persist [ 'info_id' ] = $info_id ;
$persist [ 'referer' ] = $referer ;
2008-04-18 13:53:55 +02:00
$persist [ 'info_id_parent' ] = $values [ 'main' ][ 1 ][ 'info_id_parent' ];
2006-10-04 19:40:33 +02:00
$persist [ 'called_by' ] = $called_by ;
2003-12-09 01:08:31 +01:00
2006-10-04 19:40:33 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'InfoLog' ) . ' - ' . lang ( 'Delete' );
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'params' ][ 'manual' ] = array ( 'page' => 'ManualInfologDelete' );
2002-10-16 02:23:39 +02:00
2013-12-05 21:58:48 +01:00
$this -> tmpl -> exec ( 'infolog.infolog_ui.delete' , $values , array (), $readonlys , $persist , $called_by == 'edit' ? 2 : 0 );
2006-10-04 19:40:33 +02:00
}
2008-04-18 13:53:55 +02:00
2006-10-04 19:40:33 +02:00
/**
* Edit / Create an InfoLog Entry
*
2014-06-12 14:34:50 +02:00
* @ param array $content 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 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
2006-10-04 19:40:33 +02:00
*/
function edit ( $content = null , $action = '' , $action_id = 0 , $type = '' , $referer = '' )
{
2012-02-24 10:29:27 +01:00
if (( $submit = is_array ( $content )))
2002-10-14 02:39:47 +02:00
{
2008-10-07 14:50:14 +02:00
//echo "infolog_ui::edit: content="; _debug_array($content);
2006-10-04 19:40:33 +02:00
$info_id = $content [ 'info_id' ];
2007-04-26 13:34:46 +02:00
$action = $content [ 'action' ]; unset ( $content [ 'action' ]);
$action_id = $content [ 'action_id' ]; unset ( $content [ 'action_id' ]);
$referer = $content [ 'referer' ]; unset ( $content [ 'referer' ]);
$no_popup = $content [ 'no_popup' ]; unset ( $content [ 'no_popup' ]);
2006-02-04 08:49:47 +01:00
2006-10-04 19:40:33 +02:00
list ( $button ) = @ each ( $content [ 'button' ]);
2009-12-11 09:34:47 +01:00
if ( ! $button && $action ) $button = $action ; // action selectbox
2014-03-31 14:40:20 +02:00
//info_cc expects an comma separated string
//error_log(__METHOD__.__LINE__.array2string($content));
if ( empty ( $content [ 'info_cc' ])) $content [ 'info_cc' ] = " " ;
if ( is_array ( $content [ 'info_cc' ]))
{
foreach ( $content [ 'info_cc' ] as $i => $value )
{
//imap_rfc822 should not be used, but it works reliable here, until we have some regex solution or use horde stuff
$addresses = imap_rfc822_parse_adrlist ( $value , '' );
//error_log(__METHOD__.__LINE__.$value.'->'.array2string($addresses[0]));
$content [ 'info_cc' ][ $i ] = $addresses [ 0 ] -> host ? $addresses [ 0 ] -> mailbox . '@' . $addresses [ 0 ] -> host : $addresses [ 0 ] -> mailbox ;
}
if ( ! empty ( $content [ 'info_cc' ])) $content [ 'info_cc' ] = implode ( ',' , $content [ 'info_cc' ]);
}
2006-10-04 19:40:33 +02:00
unset ( $content [ 'button' ]);
if ( $button )
{
2012-02-24 10:29:27 +01:00
// Copy or schedule Infolog
2013-10-25 10:18:59 +02:00
if ( in_array ( $button , array ( 'copy' , 'schedule' , 'ical' , 'tracker' )))
2012-02-24 10:29:27 +01:00
{
$action = $button ;
2012-04-23 14:01:37 +02:00
if ( ! $info_id || $this -> bo -> check_access ( $info_id , EGW_ACL_EDIT ))
{
$button = 'apply' ; // need to store infolog first
}
2012-02-24 10:29:27 +01:00
}
2013-09-12 13:56:33 +02:00
//Validate the enddate must be grather than startdate
2014-06-11 12:47:23 +02:00
if ( ! empty ( $content [ 'info_enddate' ]) && ! empty ( $content [ 'info_startdate' ]))
2013-09-12 13:56:33 +02:00
{
$duration_date = $content [ 'info_enddate' ] - $content [ 'info_startdate' ];
2014-06-11 12:47:23 +02:00
if ( $duration_date < 0 )
2013-09-12 13:56:33 +02:00
{
$this -> tmpl -> set_validation_error ( 'info_startdate' , lang ( 'Startdate must be before Enddate!!!' ));
$button = $action = '' ; // stop save or apply
}
}
2008-10-07 14:50:14 +02:00
//echo "<p>infolog_ui::edit(info_id=$info_id) '$button' button pressed, content="; _debug_array($content);
2006-11-15 11:24:58 +01:00
if (( $button == 'save' || $button == 'apply' ) && isset ( $content [ 'info_subject' ]) && empty ( $content [ 'info_subject' ]))
2002-10-18 00:02:44 +02:00
{
2006-10-04 19:40:33 +02:00
$this -> tmpl -> set_validation_error ( 'info_subject' , lang ( 'Field must not be empty !!!' ));
2012-02-24 10:29:27 +01:00
$button = $action = '' ; // stop save or apply
2002-10-18 00:02:44 +02:00
}
2006-10-04 19:40:33 +02:00
if (( $button == 'save' || $button == 'apply' ) && $info_id )
2002-10-14 02:39:47 +02:00
{
2014-03-26 17:54:09 +01:00
$old = $this -> bo -> read ( $info_id );
2006-10-04 19:40:33 +02:00
if ( ! ( $edit_acl = $this -> bo -> check_access ( $info_id , EGW_ACL_EDIT )))
2004-02-05 14:37:29 +01:00
{
2006-10-24 12:08:21 +02:00
$status_only = $this -> bo -> is_responsible ( $old );
2007-06-13 23:37:05 +02:00
$undelete = $this -> bo -> check_access ( $old , EGW_ACL_UNDELETE );
2004-02-05 14:37:29 +01:00
}
2006-10-04 19:40:33 +02:00
}
2007-06-13 23:37:05 +02:00
if (( $button == 'save' || $button == 'apply' ) && ( ! $info_id || $edit_acl || $status_only || $undelete ))
2006-10-04 19:40:33 +02:00
{
2014-04-07 22:27:57 +02:00
$operation = $info_id ? 'edit' : 'add' ;
2006-10-04 19:40:33 +02:00
if ( $content [ 'info_contact' ])
2002-10-14 02:39:47 +02:00
{
2006-10-04 19:40:33 +02:00
$old_link_id = ( int ) $content [ 'info_link_id' ];
2013-11-28 18:34:28 +01:00
if ( is_array ( $content [ 'info_contact' ]))
2013-02-08 14:46:08 +01:00
{
2013-11-28 18:34:28 +01:00
// eTemplate2 returns the array all ready
2013-02-08 14:46:08 +01:00
$app = $content [ 'info_contact' ][ 'app' ];
$id = $content [ 'info_contact' ][ 'id' ];
}
2012-04-16 23:53:19 +02:00
if ( $app && $id )
{
2012-05-08 19:06:53 +02:00
if ( ! is_array ( $content [ 'link_to' ]))
{
$content [ 'link_to' ] = array ();
}
2012-04-16 23:53:19 +02:00
$content [ 'info_link_id' ] = ( int )( $info_link_id = egw_link :: link ( 'infolog' , $content [ 'link_to' ][ 'to_id' ], $app , $id ));
}
2011-04-12 13:53:34 +02:00
if ( $old_link_id && $old_link_id != $content [ 'info_link_id' ]) egw_link :: unlink ( $old_link_id );
2006-10-04 19:40:33 +02:00
}
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
}
2012-05-08 11:58:45 +02:00
$active_tab = $content [ 'tabs' ];
2010-10-08 19:48:36 +02:00
if ( ! ( $info_id = $this -> bo -> write ( $content , true , true , true , $content [ 'no_notifications' ])))
2006-10-04 19:40:33 +02:00
{
$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!' ) . '<br />' .
lang ( 'Copy your changes to the clipboard, %1reload the entry%2 and merge them.' , '<a href="' .
2010-06-07 16:43:34 +02:00
htmlspecialchars ( egw :: link ( '/index.php' , array (
2008-10-07 14:50:14 +02:00
'menuaction' => 'infolog.infolog_ui.edit' ,
2006-10-04 19:40:33 +02:00
'info_id' => $content [ 'info_id' ],
'no_popup' => $no_popup ,
'referer' => $referer ,
))) . '">' , '</a>' );
2012-02-24 10:29:27 +01:00
$button = $action = '' ; // not exiting edit
2006-10-04 19:40:33 +02:00
$info_id = $content [ 'info_id' ];
}
else
{
2014-07-03 15:44:04 +02:00
$GLOBALS [ 'egw' ] -> preferences -> add ( 'infolog' , 'preferred_type' , $content [ 'info_type' ]);
$GLOBALS [ 'egw' ] -> preferences -> save_repository ( false , 'user' , false );
2006-10-04 19:40:33 +02:00
$content [ 'msg' ] = lang ( 'InfoLog entry saved' );
2013-08-26 11:19:47 +02:00
egw_framework :: refresh_opener ( $content [ 'msg' ], 'infolog' , $info_id , $operation );
2006-10-04 19:40:33 +02:00
}
2012-05-08 11:58:45 +02:00
$content [ 'tabs' ] = $active_tab ;
2006-10-04 19:40:33 +02:00
if (( int ) $content [ 'pm_id' ] != ( int ) $content [ 'old_pm_id' ])
{
//echo "<p>pm_id changed: $content[old_pm_id] -> $content[pm_id]</p>\n";
// update links accordingly, if selected project changed
if ( $content [ 'pm_id' ])
2005-11-12 14:25:59 +01:00
{
2006-10-04 19:40:33 +02:00
//echo "<p>this->link->link('infolog',{$content['link_to']['to_id']},'projectmanager',{$content['pm_id']});</p>";
2008-03-08 22:43:13 +01:00
egw_link :: link ( 'infolog' , $content [ 'link_to' ][ 'to_id' ], 'projectmanager' , $content [ 'pm_id' ]);
2006-10-04 19:40:33 +02:00
// making the project the selected link, if no other link selected
if ( ! $info_link_id || $info_link_id == 'projectmanager:' . $content [ 'old_pm_id' ])
2006-02-04 08:49:47 +01:00
{
2006-10-04 19:40:33 +02:00
$info_link_id = 'projectmanager:' . $content [ 'pm_id' ];
2006-02-04 08:49:47 +01:00
}
}
2006-10-04 19:40:33 +02:00
if ( $content [ 'old_pm_id' ])
2006-02-04 08:49:47 +01:00
{
2006-10-04 19:40:33 +02:00
//echo "<p>this->link->unlink2(0,infolog,{$content['link_to']['to_id']},0,'projectmanager',{$content['old_pm_id']});</p>\n";
2008-03-08 22:43:13 +01:00
egw_link :: unlink2 ( 0 , infolog , $content [ 'link_to' ][ 'to_id' ], 0 , 'projectmanager' , $content [ 'old_pm_id' ]);
2006-10-04 19:40:33 +02:00
$content [ 'old_pm_id' ] = $content [ 'pm_id' ];
2006-02-04 08:49:47 +01:00
}
2005-11-12 14:25:59 +01:00
}
2006-10-04 19:40:33 +02:00
// writing links for a new entry
2008-04-18 13:53:55 +02:00
if ( $info_id && is_array ( $content [ 'link_to' ][ 'to_id' ]) && count ( $content [ 'link_to' ][ 'to_id' ]))
2005-11-12 14:25:59 +01:00
{
2006-10-27 12:50:08 +02:00
//echo "<p>writing links for new entry $info_id</p>\n"; _debug_array($content['link_to']['to_id']);
2008-03-08 22:43:13 +01:00
egw_link :: link ( 'infolog' , $info_id , $content [ 'link_to' ][ 'to_id' ]);
2006-10-04 19:40:33 +02:00
$content [ 'link_to' ][ 'to_id' ] = $info_id ;
2002-10-14 02:39:47 +02:00
}
2007-05-08 10:36:06 +02:00
if ( $info_link_id && strpos ( $info_link_id , ':' ) !== false ) // updating info_link_id if necessary
2005-11-12 14:25:59 +01:00
{
2006-10-04 19:40:33 +02:00
list ( $app , $id ) = explode ( ':' , $info_link_id );
2008-03-08 22:43:13 +01:00
$link = egw_link :: get_link ( 'infolog' , $info_id , $app , $id );
2006-10-04 19:40:33 +02:00
if (( int ) $content [ 'info_link_id' ] != ( int ) $link [ 'link_id' ])
2005-11-12 14:25:59 +01:00
{
2006-10-04 19:40:33 +02:00
$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' ],
2010-09-03 13:34:39 +02:00
'info_type' => $content [ 'info_type' ],
2006-10-04 19:40:33 +02:00
'info_owner' => $content [ 'info_owner' ],
);
2006-10-27 12:50:08 +02:00
//echo "<p>updating info_link_id: ".print_r($to_write,true)."</p>\n";
2010-05-05 17:53:34 +02:00
$this -> bo -> write ( $to_write , False , true , true , true ); // last true = no notifications, as no real change
2006-10-04 19:40:33 +02:00
// we need eg. the new modification date, for further updates
$content = array_merge ( $content , $to_write );
2005-11-12 14:25:59 +01:00
}
}
2002-10-14 02:39:47 +02:00
}
2006-10-04 19:40:33 +02:00
elseif ( $button == 'delete' && $info_id > 0 )
2006-04-05 18:16:33 +02:00
{
2006-10-04 19:40:33 +02:00
if ( ! $referer && $action ) $referer = array (
2008-10-07 14:50:14 +02:00
'menuaction' => 'infolog.infolog_ui.index' ,
2006-10-04 19:40:33 +02:00
'action' => $action ,
'action_id' => $action_id
);
if ( ! ( $content [ 'msg' ] = $this -> delete ( $info_id , $referer , 'edit' ))) return ; // checks ACL first
2013-08-26 11:19:47 +02:00
egw_framework :: refresh_opener ( $content [ 'msg' ], 'infolog' , $info_id , 'delete' );
2006-10-04 19:40:33 +02:00
}
// called again after delete confirmation dialog
elseif ( $button == 'deleted' && $content [ 'msg' ])
{
2013-08-26 11:19:47 +02:00
egw_framework :: refresh_opener ( $content [ 'msg' ], 'infolog' , $info_id , 'delete' );
2006-10-04 19:40:33 +02:00
}
if ( $button == 'save' || $button == 'cancel' || $button == 'delete' || $button == 'deleted' )
{
if ( $no_popup )
{
2010-06-07 16:43:34 +02:00
egw :: redirect_link ( $referer , array ( 'msg' => $content [ 'msg' ]));
2006-10-04 19:40:33 +02:00
}
2013-08-26 11:19:47 +02:00
egw_framework :: window_close ();
2006-04-05 18:16:33 +02:00
}
2002-10-14 02:39:47 +02:00
}
2006-10-04 19:40:33 +02:00
// 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
2010-07-30 12:19:06 +02:00
if ( ! array_key_exists ( $content [ 'info_status' ], $this -> bo -> status [ $content [ 'info_type' ]]))
2002-10-14 02:39:47 +02:00
{
2006-10-04 19:40:33 +02:00
$content [ 'info_status' ] = $this -> bo -> status [ 'defaults' ][ $content [ 'info_type' ]];
if ( $content [ 'info_status' ] != 'done' ) $content [ 'info_datecompleted' ] = '' ;
}
}
2012-02-24 10:29:27 +01:00
else // new call via GET
2006-10-04 19:40:33 +02:00
{
2008-10-07 14:50:14 +02:00
//echo "<p>infolog_ui::edit: info_id=$info_id, action='$action', action_id='$action_id', type='$type', referer='$referer'</p>\n";
2006-10-04 19:40:33 +02:00
$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' ));
2014-01-28 10:22:12 +01:00
$referer = $referer !== '' ? $referer : ( $_GET [ 'referer' ] ? $_GET [ 'referer' ] :
2010-06-07 16:43:34 +02:00
common :: get_referer ( '/index.php?menuaction=infolog.infolog_ui.index' ));
2014-01-28 10:22:12 +01:00
if ( strpos ( $referer , 'msg=' ) !== false ) $referer = preg_replace ( '/([&?]{1})msg=[^&]+&?/' , '\\1' , $referer ); // remove previou/old msg from referer
2006-10-04 19:40:33 +02:00
$no_popup = $_GET [ 'no_popup' ];
2009-12-13 14:36:09 +01:00
$print = ( int ) $_REQUEST [ 'print' ];
2008-10-07 14:50:14 +02:00
//echo "<p>infolog_ui::edit: info_id=$info_id, action='$action', action_id='$action_id', type='$type', referer='$referer'</p>\n";
2003-09-08 02:40:42 +02:00
2006-10-04 19:40:33 +02:00
$content = $this -> bo -> read ( $info_id || $action != 'sp' ? $info_id : $action_id );
2010-06-28 17:25:27 +02:00
if ( ! ( strpos ( $content [ 'info_addr' ], ',' ) === false ) && strpos ( $content [ 'info_addr' ], ', ' ) === false ) $content [ 'info_addr' ] = str_replace ( ',' , ', ' , $content [ 'info_addr' ]);
2014-02-04 14:52:12 +01:00
foreach ( array ( 'info_subject' , 'info_des' ) as $key )
2010-07-16 11:13:32 +02:00
{
if ( ! isset ( $content [ $key ]) || strlen ( $content [ $key ]) < 75 )
{
continue ;
}
2012-11-07 08:52:59 +01:00
$contlines = explode ( " \n " , $content [ $key ]);
$clarray = array ();
foreach ( $contlines as & $line )
2010-07-16 11:13:32 +02:00
{
2012-11-07 08:52:59 +01:00
if ( strlen ( $line ) < 75 )
2010-07-16 11:13:32 +02:00
{
2012-11-07 08:52:59 +01:00
$clarray [] = $line ;
continue ;
}
$cont = explode ( ' ' , $line );
$ckarray = array ();
foreach ( $cont as & $word )
{
// set blank behind all , and . if words are too long, apply wordwrap afterwards to make sure we get
if ( strlen ( $word ) > 75 )
2011-03-21 17:12:55 +01:00
{
2012-11-07 08:52:59 +01:00
$buff = html :: activate_links ( $word );
if ( strlen ( $buff ) == strlen ( $word )) // no links -> try to break overlong words
{
if ( ! ( strpos ( $word , ',' ) === false ) && strpos ( $word , ', ' ) === false ) $word = str_replace ( ',' , ', ' , $word );
if ( ! ( strpos ( $word , '.' ) === false ) && strpos ( $word , '. ' ) === false ) $word = str_replace ( '.' , '. ' , $word );
$word = wordwrap ( $word , 75 , ' ' , true );
}
2011-03-21 17:12:55 +01:00
}
2012-11-07 08:52:59 +01:00
$ckarray [] = $word ;
2010-07-16 11:13:32 +02:00
}
2012-11-07 08:52:59 +01:00
$line = join ( ' ' , $ckarray );
unset ( $ckarray );
$clarray [] = $line ;
2010-07-16 11:13:32 +02:00
}
2012-11-07 08:52:59 +01:00
$content [ $key ] = join ( " \n " , $clarray );
unset ( $clarray );
2014-02-04 14:52:12 +01:00
}
2006-10-04 19:40:33 +02:00
if ( is_numeric ( $_REQUEST [ 'cat_id' ]))
{
$content [ 'info_cat' ] = ( int ) $_REQUEST [ 'cat_id' ];
}
2008-04-18 13:53:55 +02:00
if ( ! $content )
2008-03-04 13:50:16 +01:00
{
$content [ 'info_cat' ] = $this -> prefs [ 'cat_add_default' ];
}
2010-02-05 04:34:17 +01:00
if ( $_GET [ 'msg' ]) $content [ 'msg' ] = strip_tags ( $_GET [ 'msg' ]); // dont allow HTML!
2006-10-04 19:40:33 +02:00
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 ;
}
2008-03-08 22:43:13 +01:00
if (( int ) $content [ 'info_link_id' ] > 0 && ! egw_link :: get_link ( $content [ 'info_link_id' ]))
2006-10-04 19:40:33 +02:00
{
$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 ))
2005-12-06 08:11:14 +01:00
{
2006-10-04 19:40:33 +02:00
return $referer ? $this -> tmpl -> location ( $referer ) : $this -> index ( 0 , $action , $action_id );
2005-12-06 08:11:14 +01:00
}
2006-10-04 19:40:33 +02:00
}
else
{
2011-05-18 16:18:37 +02:00
$undelete = $this -> bo -> check_access ( $info_id , EGW_ACL_UNDELETE );
2006-10-04 19:40:33 +02:00
}
$content [ 'links' ] = $content [ 'link_to' ] = array (
'to_id' => $info_id ,
'to_app' => 'infolog' ,
);
2012-02-24 10:29:27 +01:00
}
// new call via GET or some actions handled here, as they can happen both ways ($_GET[action] or button/action in GUI)
2013-10-25 10:18:59 +02:00
if ( ! $submit || in_array ( $action , array ( 'sp' , 'copy' , 'schedule' , 'ical' , 'tracker' )))
2012-02-24 10:29:27 +01:00
{
2011-05-02 21:41:21 +02:00
switch ( $action )
2006-10-04 19:40:33 +02:00
{
2012-02-24 10:29:27 +01:00
case 'schedule' :
egw :: redirect_link ( '/index.php' , array (
'menuaction' => 'calendar.calendar_uiforms.edit' ,
'link_app' => 'infolog' ,
'link_id' => $info_id ,
));
break ;
2012-04-03 01:08:20 +02:00
case 'ical' :
$boical = new infolog_ical ();
$result = $boical -> exportVTODO ( $content , '2.0' , 'PUBLISH' , false );
2013-10-25 10:18:59 +02:00
html :: content_header ( 'todo.ics' , 'text/calendar' );
2012-04-03 01:08:20 +02:00
echo $result ;
common :: egw_exit ();
2012-02-24 10:29:27 +01:00
case 'sp' :
case 'copy' :
$info_id = 0 ;
$this -> create_copy ( $content , $action == 'sp' );
2012-06-14 14:06:33 +02:00
if ( $action == 'sp' ) // for sub-entries use type or category, like for new entries
{
if ( $type ) $content [ 'info_type' ] = $type ;
if ( is_numeric ( $_REQUEST [ 'cat_id' ])) $content [ 'info_cat' ] = ( int ) $_REQUEST [ 'cat_id' ];
}
2012-02-24 10:29:27 +01:00
unset ( $action ); // it get stored in $content and will cause an other copy after [apply]
2006-10-04 19:40:33 +02:00
break ;
2013-10-25 10:18:59 +02:00
case 'tracker' :
egw :: redirect_link ( '/index.php' , array (
'menuaction' => 'tracker.tracker_ui.edit' ,
egw_link :: get_registry ( 'tracker' , 'add_app' ) . '[]' => 'infolog' ,
egw_link :: get_registry ( 'tracker' , 'add_id' ) . '[]' => $info_id ,
));
break ;
2006-10-04 19:40:33 +02:00
case 'projectmanager' :
$pm_links = array ( $action_id );
default : // to allow other apps to participate
2013-05-10 12:54:36 +02:00
$content [ 'info_subject' ] = egw_link :: title ( $action , $id );
$content [ 'info_contact' ] = $action . ':' . $action_id ;
foreach ( explode ( ',' , $action_id ) as $n => $id )
2012-02-24 10:29:27 +01:00
{
2013-05-10 12:54:36 +02:00
egw_link :: link ( 'infolog' , $content [ 'link_to' ][ 'to_id' ], $action , $id );
// calling "infolog_set" hook for first, in case app wants to set some more values
if ( ! $n && ( $set = $GLOBALS [ 'egw' ] -> hooks -> single ( array ( 'location' => 'infolog_set' , 'id' => $action_id ), $action )))
2012-02-24 10:29:27 +01:00
{
2013-05-10 12:54:36 +02:00
foreach (( array ) $set [ 'link_app' ] as $i => $l_app )
{
if (( $l_id = $set [ 'link_id' ][ $i ])) egw_link :: link ( 'infolog' , $content [ 'link_to' ][ 'to_id' ], $l_app , $l_id );
}
unset ( $set [ 'link_app' ]);
unset ( $set [ 'link_id' ]);
$content = array_merge ( $content , $set );
2008-07-04 13:16:33 +02:00
}
2008-04-23 10:27:49 +02:00
}
2013-05-10 12:54:36 +02:00
// fall through
2006-10-04 19:40:33 +02:00
case '' :
if ( $info_id )
{
if ( ! isset ( $pm_links ))
2002-10-18 00:02:44 +02:00
{
2008-03-08 22:43:13 +01:00
$pm_links = egw_link :: get_links ( 'infolog' , $info_id , 'projectmanager' );
2002-10-18 00:02:44 +02:00
}
2006-10-04 19:40:33 +02:00
break ; // normal edit
}
2013-05-10 12:54:36 +02:00
case 'new' : // new entry, set some defaults, if not set by infolog_set hook
if ( empty ( $content [ 'info_startdate' ])) $content [ 'info_startdate' ] = ( int ) $_GET [ 'startdate' ] ? ( int ) $_GET [ 'startdate' ] : $set_startdate ;
if ( empty ( $content [ 'info_priority' ])) $content [ 'info_priority' ] = 1 ; // normal
2006-10-04 19:40:33 +02:00
$content [ 'info_owner' ] = $this -> user ;
2013-05-10 12:54:36 +02:00
if ( $type != '' && empty ( $content [ 'info_type' ]))
2006-10-04 19:40:33 +02:00
{
$content [ 'info_type' ] = $type ;
2014-07-03 15:44:04 +02:00
}
else if ( $type == '' && empty ( $content [ 'info_type' ]) && isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'infolog' ][ 'preferred_type' ]))
{
$content [ 'info_type' ] = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'infolog' ][ 'preferred_type' ];
2006-10-04 19:40:33 +02:00
}
2013-05-10 12:54:36 +02:00
if ( empty ( $content [ 'info_status' ])) $content [ 'info_status' ] = $this -> bo -> status [ 'defaults' ][ $content [ 'info_type' ]];
if ( empty ( $content [ 'info_percent' ])) $content [ 'info_percent' ] = $content [ 'info_status' ] == 'done' ? '100%' : '0%' ;
2006-10-04 19:40:33 +02:00
break ;
2003-08-28 16:31:11 +02:00
}
2006-10-04 19:40:33 +02:00
if ( ! isset ( $this -> bo -> enums [ 'type' ][ $content [ 'info_type' ]]))
2003-08-28 16:31:11 +02:00
{
2006-10-04 19:40:33 +02:00
$content [ 'info_type' ] = 'note' ;
2003-08-28 16:31:11 +02:00
}
2006-10-04 19:40:33 +02:00
}
2007-03-12 12:27:33 +01:00
// group owners
$types = $this -> bo -> enums [ 'type' ];
if ( $this -> bo -> group_owners )
{
// remove types owned by groups the user has no edit grant (current type is made readonly)
foreach ( $this -> bo -> group_owners as $type => $group )
{
if ( ! ( $this -> bo -> grants [ $group ] & EGW_ACL_EDIT ))
{
if ( $type == $content [ 'info_type' ])
{
//echo "<p>setting type to r/o as user has no edit rights from group #$group</p>\n";
$readonlys [ 'info_type' ] = true ;
}
else
{
unset ( $types [ $type ]);
}
}
}
// set group as owner if type has a group-owner set
if ( isset ( $this -> bo -> group_owners [ $content [ 'info_type' ]]))
{
$content [ 'info_owner' ] = $this -> bo -> group_owners [ $content [ 'info_type' ]];
// Dont allow to change the type, if user has no delete rights from the group-owner
if ( $info_id && ! ( $this -> bo -> grants [ $content [ 'info_owner' ]] & EGW_ACL_DELETE ))
{
//echo "<p>setting type to r/o as user has no delete rights from group #$group</p>\n";
$readonlys [ 'info_type' ] = true ;
}
2012-11-13 13:07:10 +01:00
// disable info_access for group-owners
$readonlys [ 'info_access' ] = true ;
2007-03-12 12:27:33 +01:00
}
elseif ( $GLOBALS [ 'egw' ] -> accounts -> get_type ( $content [ 'info_owner' ]) == 'g' )
{
$content [ 'info_owner' ] = $this -> user ;
}
}
2007-04-26 13:34:46 +02:00
$preserv = $content ;
2014-02-12 12:07:33 +01:00
2014-03-04 01:27:21 +01:00
// Don't preserve message or links
2014-02-12 00:18:24 +01:00
unset ( $preserv [ 'msg' ]);
2014-03-04 01:27:21 +01:00
unset ( $preserv [ 'links' ]); unset ( $preserv [ 'link_to' ]);
2014-02-12 00:18:24 +01:00
2011-05-18 16:18:37 +02:00
// for no edit rights or implizit edit of responsible user make all fields readonly, but status and percent
2012-01-26 02:43:14 +01:00
if ( $info_id && ! $this -> bo -> check_access ( $info_id , EGW_ACL_EDIT ) && ! $undelete )
2006-10-04 19:40:33 +02:00
{
2011-05-18 16:18:37 +02:00
$readonlys [ '__ALL__' ] = true ; // make all fields not explicitly set readonly
if ( $this -> bo -> is_responsible ( $content ))
2006-02-04 08:49:47 +01:00
{
2011-05-18 16:18:37 +02:00
foreach ( $this -> bo -> responsible_edit as $name )
{
$readonlys [ $name ] = false ;
}
2012-01-26 02:43:14 +01:00
$readonlys [ 'button[edit]' ] = $readonlys [ 'button[save]' ] = $readonlys [ 'button[apply]' ] = $readonlys [ 'no_notifications' ] = false ;
2006-09-20 09:13:44 +02:00
}
2011-05-18 16:18:37 +02:00
$readonlys [ 'action' ] = $readonlys [ 'button[cancel]' ] = false ; // always allowed
2006-10-04 19:40:33 +02:00
}
2012-02-22 13:31:00 +01:00
elseif ( ! $info_id )
{
$readonlys [ 'action' ] = true ;
}
2007-06-13 23:37:05 +02:00
// ToDo: use the old status before the delete
2014-03-26 15:33:03 +01:00
if ( $info_id && $undelete )
2014-03-25 19:53:07 +01:00
{
$content [ 'info_status' ] = $this -> bo -> status [ 'defaults' ][ $content [ 'info_type' ]];
$this -> tmpl -> setElementAttribute ( 'button[save]' , 'label' , 'Un-Delete' );
}
2006-02-04 08:49:47 +01:00
2006-10-04 19:40:33 +02:00
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
2001-07-12 01:17:32 +02:00
}
2006-10-04 19:40:33 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( $this -> messages [ $info_id ? 'edit' : ( $action == 'sp' ? 'add_sub' : 'add' )]);
2001-10-03 23:29:32 +02:00
2006-10-04 19:40:33 +02:00
// 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' ]))
{
2009-12-13 14:36:09 +01:00
$this -> tmpl -> read ( $print ? 'infolog.edit.print' : 'infolog.edit' );
2006-10-04 19:40:33 +02:00
}
if ( $this -> bo -> has_customfields ( $content [ 'info_type' ]))
2001-07-14 23:44:01 +02:00
{
2006-10-04 19:40:33 +02:00
$content [ 'customfields' ] = $content [ 'info_type' ];
2001-07-12 01:17:32 +02:00
}
2006-10-04 19:40:33 +02:00
else
{
2012-05-08 11:58:45 +02:00
$readonlys [ 'tabs' ][ 'customfields' ] = true ;
2006-10-04 19:40:33 +02:00
}
if ( ! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'projectmanager' ]))
{
2012-05-08 11:58:45 +02:00
$readonlys [ 'tabs' ][ 'project' ] = true ; // disable the project tab
2006-10-04 19:40:33 +02:00
}
2012-05-08 11:58:45 +02:00
$readonlys [ 'tabs' ][ 'delegation' ] = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'account_selection' ] == 'none' &&
2006-10-04 19:40:33 +02:00
! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ]);
2001-07-12 01:17:32 +02:00
2006-10-04 19:40:33 +02:00
$content [ 'duration_format' ] = $this -> duration_format ;
2013-11-12 22:38:25 +01:00
$content [ 'hours_per_workday' ] = $this -> hours_per_workday ;
2007-03-12 12:27:33 +01:00
if ( $this -> prefs [ 'show_id' ]) $content [ 'info_number' ] = $info_id ;
2014-02-11 16:22:21 +01:00
$content [ 'info_anz_subs' ] = ( int ) $content [ 'info_anz_subs' ]; // gives javascript error if empty!
2006-10-04 19:40:33 +02:00
$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 ;
2007-06-13 23:37:05 +02:00
if ( $info_id && $this -> bo -> history )
{
$content [ 'history' ] = array (
'id' => $info_id ,
'app' => 'infolog' ,
'status-widgets' => array (
'Ty' => $types ,
//'Li', // info_link_id
2012-07-09 18:57:53 +02:00
'parent' => 'link-entry:infolog' ,
2007-06-13 23:37:05 +02:00
'Ca' => 'select-cat' ,
'Pr' => $this -> bo -> enums [ 'priority' ],
'Ow' => 'select-account' ,
2008-04-18 13:53:55 +02:00
//'Ac', // info_access: private||public
2007-06-13 23:37:05 +02:00
'St' => $this -> bo -> status [ $content [ 'info_type' ]] + array ( 'deleted' => 'deleted' ),
'Pe' => 'select-percent' ,
'Co' => 'date-time' ,
'st' => 'date-time' ,
2011-02-17 01:10:51 +01:00
'Mo' => 'date-time' ,
2007-06-13 23:37:05 +02:00
'En' => 'date' ,
'Re' => 'select-account' ,
// PM fields, ToDo: access control!!!
'pT' => 'date-duration' ,
'uT' => 'date-duration' ,
2012-10-10 17:27:43 +02:00
'replanned' => 'date-duration' ,
2007-06-13 23:37:05 +02:00
// 'pL' => 'projectmanager-pricelist',
'pr' => 'float' ,
),
);
$history_stati = array ();
$tracking = new infolog_tracking ( $this );
foreach ( $tracking -> field2history as $field => $history )
{
$history_stati [ $history ] = $tracking -> field2label [ $field ];
}
2011-02-17 01:10:51 +01:00
// Modified date removed from field2history, we don't need that in the history
$history_stati [ 'Mo' ] = $tracking -> field2label [ 'info_datemodified' ];
2007-06-13 23:37:05 +02:00
unset ( $tracking );
}
else
{
2012-05-08 11:58:45 +02:00
$readonlys [ 'tabs' ][ 'history' ] = true ;
2007-06-13 23:37:05 +02:00
}
2012-02-24 10:29:27 +01:00
$sel_options = array (
2007-03-12 12:27:33 +01:00
'info_type' => $types ,
2006-10-04 19:40:33 +02:00
'info_priority' => $this -> bo -> enums [ 'priority' ],
'info_confirm' => $this -> bo -> enums [ 'confirm' ],
2007-06-13 23:37:05 +02:00
'info_status' => $this -> bo -> status [ $content [ 'info_type' ]],
'status' => $history_stati ,
2012-02-24 10:29:27 +01:00
'action' => array (
'copy' => array ( 'label' => 'Copy' , 'title' => 'Copy this Infolog' ),
'sp' => 'Sub-entry' ,
2009-12-13 14:36:09 +01:00
'print' => array ( 'label' => 'Print' , 'title' => 'Print this Infolog' ),
2012-04-03 01:08:20 +02:00
'ical' => array ( 'label' => 'Export iCal' , 'title' => 'Export iCal' ),
2013-10-25 10:18:59 +02:00
'tracker' => array ( 'label' => 'Tracker' , 'title' => 'Convert to a ticket' ),
2009-12-11 09:34:47 +01:00
),
2012-02-24 10:29:27 +01:00
);
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'calendar' ])
{
$sel_options [ 'action' ][ 'schedule' ] = array ( 'label' => 'Schedule' , 'title' => 'Schedule appointment' );
}
egw_framework :: validate_file ( '.' , 'edit' , 'infolog' );
$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' ));
//error_log(substr($content['info_des'],1793,10));
//$content['info_des'] = substr($content['info_des'],0,1793);
//echo "<p>infolog_ui.edit(info_id='$info_id',action='$action',action_id='$action_id') readonlys="; print_r($readonlys); echo ", content = "; _debug_array($content);
2014-03-31 14:40:20 +02:00
//$content['info_cc'] is expected (by the widget) to be an array of emailaddresses, but is stored as comma separated string
2014-03-25 12:22:34 +01:00
if ( ! empty ( $content [ 'info_cc' ]) &&! is_array ( $content [ 'info_cc' ])) $content [ 'info_cc' ] = explode ( ',' , $content [ 'info_cc' ]);
2012-02-24 10:29:27 +01:00
$this -> tmpl -> exec ( 'infolog.infolog_ui.edit' , $content , $sel_options , $readonlys , $preserv + array ( // preserved values
2006-10-04 19:40:33 +02:00
'info_id' => $info_id ,
'action' => $action ,
'action_id' => $action_id ,
'referer' => $referer ,
'no_popup' => $no_popup ,
'old_pm_id' => $old_pm_id ,
), $no_popup ? 0 : 2 );
}
2012-02-24 10:29:27 +01:00
/**
* Create copy or sub - entry from an entry currently read into $content
*
* Taking into account prefs and config about what to copy
*
* @ param array & $content
2014-06-12 14:34:50 +02:00
* @ param boolean $create_sub true : create a sub - entry instead of a copy , default false to create a copy
2012-02-24 10:29:27 +01:00
*/
private function create_copy ( array & $content , $create_sub = false )
{
$info_id = $content [ 'info_id' ]; // it will be unset by exclude-fields
// empty fields configured to be excluded (also contains id, uid, ...)
$exclude_fields = $create_sub ? $this -> bo -> sub_excludefields : $this -> bo -> copy_excludefields ;
foreach ( $exclude_fields as $field )
{
unset ( $content [ $field ]);
if ( $field == 'info_from' ) unset ( $content [ 'info_link_id' ]); // both together is called contact in UI
}
if ( $create_sub )
{
$content [ 'info_id_parent' ] = $info_id ;
}
// no startdate or startdate in the past --> set startdate from pref
if ( ! isset ( $content [ 'info_startdate' ]) || $content [ 'info_startdate' ] < $this -> bo -> user_time_now )
{
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 ;
}
$content [ 'info_startdate' ] = $set_startdate ;
}
// enddate in the past --> uset it
if ( isset ( $content [ 'info_enddate' ]) || $content [ 'info_enddate' ] < $this -> bo -> user_time_now )
{
unset ( $content [ 'info_enddate' ]);
}
if ( ! isset ( $content [ 'info_type' ]))
{
$types = array_keys ( $this -> get_validtypes ());
$content [ 'info_type' ] = $types [ 0 ];
}
// get a consistent status, percent and date-completed
if ( ! isset ( $content [ 'info_status' ])) $content [ 'info_status' ] = $this -> bo -> status [ 'defaults' ][ $content [ 'info_type' ]];
if ( ! isset ( $content [ 'info_percent' ])) $content [ 'info_percent' ] = $content [ 'info_status' ] == 'done' ? '100%' : '0%' ;
$content [ 'info_datecompleted' ] = $content [ 'info_status' ] == 'done' ? $this -> bo -> user_time_now : 0 ;
if ( ! isset ( $content [ 'info_cat' ])) $content [ 'info_cat' ] = $this -> prefs [ 'cat_add_default' ];
2012-04-25 18:50:15 +02:00
if ( ! is_array ( $content [ 'link_to' ])) $content [ 'link_to' ] = array ();
2012-02-24 10:29:27 +01:00
$content [ 'link_to' ][ 'to_app' ] = 'infolog' ;
$content [ 'link_to' ][ 'to_id' ] = 0 ;
// Get links to be copied, if not excluded
2012-03-22 16:33:20 +01:00
if ( ! in_array ( 'link_to' , $exclude_fields ) || ! in_array ( 'attachments' , $exclude_fields ))
2012-02-24 10:29:27 +01:00
{
2014-01-28 10:22:12 +01:00
foreach ( egw_link :: get_links ( $content [ 'link_to' ][ 'to_app' ], $info_id ) as $link )
2012-02-24 10:29:27 +01:00
{
2012-03-22 16:33:20 +01:00
if ( $link [ 'app' ] != egw_link :: VFS_APPNAME && ! in_array ( 'link_to' , $exclude_fields ))
2012-02-24 10:29:27 +01:00
{
2012-03-22 16:33:20 +01:00
egw_link :: link ( 'infolog' , $content [ 'link_to' ][ 'to_id' ], $link [ 'app' ], $link [ 'id' ], $link [ 'remark' ]);
}
elseif ( $link [ 'app' ] == egw_link :: VFS_APPNAME && ! in_array ( 'attachments' , $exclude_fields ))
{
egw_link :: link ( 'infolog' , $content [ 'link_to' ][ 'to_id' ], egw_link :: VFS_APPNAME , array (
2012-02-24 10:29:27 +01:00
'tmp_name' => egw_link :: vfs_path ( $link [ 'app2' ], $link [ 'id2' ]) . '/' . $link [ 'id' ],
'name' => $link [ 'id' ],
2012-03-22 16:33:20 +01:00
), $link [ 'remark' ]);
2012-02-24 10:29:27 +01:00
}
}
}
$content [ 'links' ] = $content [ 'link_to' ];
if ( $content [ 'info_link_id' ])
{
$info_link_id = $content [ 'info_link_id' ];
// we need this if copy is triggered via context menu action
if ( ! isset ( $content [ 'info_contact' ]) || empty ( $content [ 'info_contact' ]) || $content [ 'info_contact' ] === 'copy:' )
{
$linkinfos = egw_link :: get_link ( $info_link_id );
$content [ 'info_contact' ] = $linkinfos [ 'link_app1' ] == 'infolog' ? $linkinfos [ 'link_app2' ] . ':' . $linkinfos [ 'link_id2' ] : $linkinfos [ 'link_app1' ] . ':' . $linkinfos [ 'link_id1' ];
if ( stripos ( $content [ 'info_contact' ], 'projectmanager' ) !== false ) $content [ 'pm_id' ] = $linkinfos [ 'link_app1' ] == 'projectmanager' ? $linkinfos [ 'link_id1' ] : $linkinfos [ 'link_id2' ];
}
unset ( $content [ 'info_link_id' ]);
}
$content [ 'info_owner' ] = ! ( int ) $this -> owner || ! $this -> bo -> check_perms ( EGW_ACL_ADD , 0 , $this -> owner ) ? $this -> user : $this -> owner ;
if ( ! empty ( $content [ 'info_subject' ]))
{
if ( $create_sub )
{
$config = config :: read ( 'infolog' );
$prefix = lang ( empty ( $config [ 'sub_prefix' ]) ? 'Re:' : $config [ 'sub_prefix' ]);
}
else
{
$prefix = lang ( 'Copy of:' );
}
$content [ 'info_subject' ] = $prefix . ' ' . $content [ 'info_subject' ];
}
if ( ! $create_sub )
{
$content [ 'msg' ] .= ( $content [ 'msg' ] ? " \n " : '' ) . lang ( 'Infolog copied - the copy can now be edited' );
}
}
2006-10-04 19:40:33 +02:00
function icon ( $cat , $id , $status = '' )
{
if ( ! $status || ! ( $icon = $this -> icons [ $cat ][ $id . '_' . $status ]))
{
$icon = $this -> icons [ $cat ][ $id ];
}
2010-06-07 16:43:34 +02:00
if ( $icon && ! is_readable ( common :: get_image_dir () . '/' . $icon ))
2006-10-04 19:40:33 +02:00
{
$icon = False ;
}
if ( ! $status || ! ( $alt = $this -> icons [ $cat ][ $id . '_' . $status . '_alt' ]))
{
if ( ! ( $alt = $this -> icons [ $cat ][ $id . '_alt' ]))
2001-07-14 23:44:01 +02:00
{
2006-10-04 19:40:33 +02:00
$alt = $id ;
2001-07-14 23:44:01 +02:00
}
2001-07-12 01:17:32 +02:00
}
2008-03-09 15:46:02 +01:00
return $icon ? html :: image ( 'infolog' , $icon , lang ( $alt ), 'border=0' ) : lang ( $alt );
2006-10-04 19:40:33 +02:00
}
2001-10-03 23:29:32 +02:00
2007-06-13 23:37:05 +02:00
/**
* stripping slashes from an array
*
2008-04-18 13:53:55 +02:00
* @ static
2007-06-13 23:37:05 +02:00
* @ param array $arr
* @ return array
*/
function array_stripslashes ( $arr )
{
foreach ( $arr as $key => $val )
{
if ( is_array ( $val ))
{
2014-01-28 10:22:12 +01:00
$arr [ $key ] = self :: array_stripslashes ( $val );
2007-06-13 23:37:05 +02:00
}
else
{
$arr [ $key ] = stripslashes ( $val );
}
}
return $arr ;
}
/**
* Infolog ' s site configuration
*
*/
2013-01-31 20:39:01 +01:00
public function admin ( $content = array ())
2006-10-04 19:40:33 +02:00
{
2012-03-22 16:33:20 +01:00
$fields = array (
2006-10-04 19:40:33 +02:00
'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' ,
);
2012-03-22 16:33:20 +01:00
$excludefields = array (
'info_cat' => 'Category' ,
'info_from' => 'Contact' ,
'info_addr' => 'Phone/Email' ,
'info_subject' => 'Subject' ,
'info_des' => 'Description' ,
'link_to' => 'Links' ,
'attachments' => 'Attachments' ,
'info_priority' => 'Priority' ,
'info_location' => 'Location' ,
'info_planned_time' => 'Planned time' ,
'info_used_time' => 'Used time' ,
2011-11-10 13:17:35 +01:00
'info_type' => 'Type' ,
'info_owner' => 'Owner' ,
'info_responsible' => 'Responsible' ,
'info_access' => 'Access' ,
'info_startdate' => 'Startdate' ,
'info_enddate' => 'Enddate' ,
'info_id_parent' => 'Parent' ,
'info_status' => 'Status' ,
'info_confirm' => 'Confirm' ,
'pl_id' => 'pricelist' ,
'info_price' => 'price' ,
'info_percent' => 'completed' ,
'info_datecompleted' => 'date completed' ,
'info_replanned_time' => 're-planned time' ,
'info_cc' => 'CC' ,
2012-03-22 16:33:20 +01:00
);
2011-11-10 13:17:35 +01:00
// add customfields to field list
foreach ( config :: get_customfields ( 'infolog' ) as $name => $data )
{
$excludefields [ '#' . $name ] = $data [ 'label' ];
}
2012-02-24 10:29:27 +01:00
$sub_excludefields = $excludefields ;
unset ( $sub_excludefields [ 'info_id_parent' ]); // always set to parent!
2013-01-31 20:39:01 +01:00
$config = config :: read ( 'infolog' );
2011-11-10 13:17:35 +01:00
2013-01-31 20:39:01 +01:00
if ( $content )
2001-10-07 22:11:32 +02:00
{
2013-01-31 20:39:01 +01:00
// Save
$button = key ( $content [ 'button' ]);
if ( $button == 'save' || $button == 'apply' )
2007-06-13 23:37:05 +02:00
{
2013-01-31 20:39:01 +01:00
$this -> bo -> responsible_edit = array ( 'info_status' , 'info_percent' , 'info_datecompleted' );
2012-02-24 11:31:43 +01:00
2013-01-31 20:39:01 +01:00
if ( $content [ 'responsible_edit' ])
2012-02-24 11:01:40 +01:00
{
2013-10-01 09:59:23 +02:00
$extra = array_intersect ( $content [ 'responsible_edit' ], array_keys ( $fields ));
2013-03-19 16:44:38 +01:00
$this -> bo -> responsible_edit = array_unique ( array_merge ( $this -> bo -> responsible_edit , $extra ));
2012-02-24 11:01:40 +01:00
}
2013-10-01 09:59:23 +02:00
config :: save_value ( 'copy_excludefields' , $content [ 'copy_excludefields' ] ? $content [ 'copy_excludefields' ] : null , 'infolog' );
config :: save_value ( 'sub_excludefields' , $content [ 'sub_excludefields' ] ? $content [ 'sub_excludefields' ] : array ( '*NONE*' ), 'infolog' );
2013-07-04 17:49:06 +02:00
config :: save_value ( 'responsible_edit' , $this -> bo -> responsible_edit , 'infolog' );
config :: save_value ( 'implicit_rights' , $this -> bo -> implicit_rights = $content [ 'implicit_rights' ] == 'edit' ? 'edit' : 'read' , 'infolog' );
config :: save_value ( 'history' , $this -> bo -> history = $content [ 'history' ], 'infolog' );
config :: save_value ( 'index_load_cfs' , implode ( ',' , ( array ) $content [ 'index_load_cfs' ]), 'infolog' );
config :: save_value ( 'sub_prefix' , $content [ 'sub_prefix' ], 'infolog' );
2013-01-31 20:39:01 +01:00
// Notifications
$notifications =& $config [ infolog_tracking :: CUSTOM_NOTIFICATION ];
$notifications [ $content [ 'notification_type' ]] = $content [ 'notification' ];
config :: save_value ( infolog_tracking :: CUSTOM_NOTIFICATION , $notifications , 'infolog' );
}
2013-05-10 12:54:36 +02:00
2013-01-31 20:39:01 +01:00
if ( $button == 'save' || $button == 'cancel' )
{
2014-07-08 15:52:48 +02:00
egw :: redirect_link ( '/admin/index.php' , null , 'admin' );
2011-11-10 13:17:35 +01:00
}
2006-10-04 19:40:33 +02:00
}
2013-01-31 20:39:01 +01:00
else
2006-10-04 19:40:33 +02:00
{
2013-01-31 20:39:01 +01:00
// Load
$content = $config ;
$content [ 'implicit_rights' ] = $this -> bo -> implicit_rights ;
$content [ 'responsible_edit' ] = $this -> bo -> responsible_edit ;
$content [ 'copy_excludefields' ] = $this -> bo -> copy_excludefields ;
$content [ 'sub_excludefields' ] = $this -> bo -> sub_excludefields ;
$content [ 'history' ] = $this -> bo -> history ;
2006-10-04 19:40:33 +02:00
}
2001-10-07 22:11:32 +02:00
2013-01-31 20:39:01 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'InfoLog' ) . ' - ' . lang ( 'Site configuration' );
2001-10-07 22:11:32 +02:00
2013-01-31 20:39:01 +01:00
// Load selected custom notification
if ( ! $content [ 'notification_type' ])
{
$content [ 'notification_type' ] = '~global~' ;
}
$content [ 'notification' ] = $config [ infolog_tracking :: CUSTOM_NOTIFICATION ][ $content [ 'notification_type' ]];
$sel_options = array (
'implicit_rights' => array (
2006-10-04 19:40:33 +02:00
'read' => 'read rights (default)' ,
'edit' => 'edit rights (full edit rights incl. making someone else responsible!)' ,
2013-01-31 20:39:01 +01:00
),
'responsible_edit' => $fields ,
'copy_excludefields' => $excludefields ,
'sub_excludefields' => $sub_excludefields ,
'history' => array (
2007-06-13 23:37:05 +02:00
'' => lang ( 'No' ),
'history' => lang ( 'Yes, with purging of deleted items possible' ),
'history_admin_delete' => lang ( 'Yes, only admins can purge deleted items' ),
'history_no_delete' => lang ( 'Yes, noone can purge deleted items' ),
2013-01-31 20:39:01 +01:00
),
'index_load_cfs' => $this -> bo -> enums [ 'type' ],
'notification_type' => array ( '~global~' => 'all' ) + $this -> bo -> enums [ 'type' ]
);
$preserve [ 'notification_old_type' ] = $content [ 'notification_type' ];
$this -> tmpl -> read ( 'infolog.config' );
2014-01-28 10:22:12 +01:00
$this -> tmpl -> exec ( 'infolog.infolog_ui.admin' , $content , $sel_options , array (), $preserve );
2006-10-04 19:40:33 +02:00
}
2008-04-18 13:53:55 +02:00
2006-10-04 19:40:33 +02:00
/**
* imports a mail as infolog
2008-04-18 13:53:55 +02:00
* two possible calls :
2006-10-04 19:40:33 +02:00
* 1. with function args set . ( we come from send mail )
* 2. with $_GET [ ' uid ] = someuid ( we come from display mail )
2008-04-18 13:53:55 +02:00
*
2006-10-04 19:40:33 +02:00
* @ author Cornelius Weiss < nelius @ cwtech . de >
2007-04-26 13:34:46 +02:00
* @ param string $_to_emailAddress
2006-10-04 19:40:33 +02:00
* @ param string $_subject
* @ param string $_body
* @ param array $_attachments
* @ param string $_date
2011-11-17 17:05:36 +01:00
* @ param string $_rawMailHeader
* @ param string $_rawMailBody
2006-10-04 19:40:33 +02:00
*/
2011-11-17 17:05:36 +01:00
function import_mail ( $_to_emailAddress = false , $_subject = false , $_body = false , $_attachments = false , $_date = false , $_rawMailHeader = null , $_rawMailBody = null )
2006-10-04 19:40:33 +02:00
{
$uid = $_GET [ 'uid' ];
2008-05-23 12:51:54 +02:00
$partid = $_GET [ 'part' ];
2008-06-04 08:53:24 +02:00
$mailbox = base64_decode ( $_GET [ 'mailbox' ]);
2014-04-10 16:33:24 +02:00
$mailClass = 'mail_bo' ;
$sessionLocation = 'mail' ;
2013-03-05 15:47:00 +01:00
// if rowid is set, we are called from new mail module.
if ( method_exists ( 'mail_ui' , 'splitRowID' ) && isset ( $_GET [ 'rowid' ]) && ! empty ( $_GET [ 'rowid' ]))
{
// rowid holds all needed information: server, folder, uid, etc.
$rowID = $_GET [ 'rowid' ];
$hA = mail_ui :: splitRowID ( $rowID );
$sessionLocation = $hA [ 'app' ]; // THIS is part of the row ID, we may use this for validation
if ( $sessionLocation != 'mail' ) throw new egw_exception_assertion_failed ( lang ( 'Application mail expected but got: %1' , $sessionLocation ));
$uid = $hA [ 'msgUID' ];
$mailbox = $hA [ 'folder' ];
$icServerID = $hA [ 'profileID' ];
$mailClass = 'mail_bo' ;
}
2009-12-15 17:05:48 +01:00
if ( $_date == false || empty ( $_date )) $_date = $this -> bo -> user_time_now ;
2006-10-04 19:40:33 +02:00
if ( ! empty ( $_to_emailAddress ))
2006-08-23 21:03:25 +02:00
{
2009-07-13 12:47:19 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] = 'infolog' ;
2006-08-23 21:03:25 +02:00
2014-01-07 13:58:35 +01:00
if ( ! ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ $sessionLocation ][ 'saveAsOptions' ] === 'text_only' ) && is_array ( $_attachments ))
2006-10-04 19:40:33 +02:00
{
2009-11-28 19:16:18 +01:00
//echo __METHOD__.'<br>';
2009-08-13 12:07:34 +02:00
//_debug_array($_attachments);
2013-03-05 15:47:00 +01:00
if ( ! isset ( $icServerID )) $icServerID =& egw_cache :: getSession ( $sessionLocation , 'activeProfileID' );
$mailobject = $mailClass :: getInstance ( true , $icServerID );
$mailobject -> openConnection ();
2006-10-04 19:40:33 +02:00
foreach ( $_attachments as $attachment )
2006-08-23 21:03:25 +02:00
{
2013-10-15 12:44:42 +02:00
//error_log(__METHOD__.__LINE__.array2string($attachment));
if ( trim ( strtoupper ( $attachment [ 'type' ])) == 'MESSAGE/RFC822' && ! empty ( $attachment [ 'uid' ]) && ! empty ( $attachment [ 'folder' ]))
2009-08-13 12:07:34 +02:00
{
2014-01-20 14:14:18 +01:00
$mailobject -> reopen (( $attachment [ 'folder' ] ? $attachment [ 'folder' ] : $mailbox ));
2009-08-13 12:07:34 +02:00
2013-10-15 12:44:42 +02:00
// get the message itself, and attach it, as we are able to display it in egw
// instead of fetching only the attachments attached files (as we did previously)
2014-01-20 14:14:18 +01:00
$message = $mailobject -> getMessageRawBody ( $attachment [ 'uid' ], $attachment [ 'partID' ],( $attachment [ 'folder' ] ? $attachment [ 'folder' ] : $mailbox ));
$headers = $mailobject -> getMessageHeader ( $attachment [ 'uid' ], $attachment [ 'partID' ], true , false ,( $attachment [ 'folder' ] ? $attachment [ 'folder' ] : $mailbox ));
2013-10-15 12:44:42 +02:00
$subject = str_replace ( '$$' , '__' ,( $headers [ 'SUBJECT' ] ? $headers [ 'SUBJECT' ] : lang ( '(no subject)' )));
$attachment_file = tempnam ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'temp_dir' ], $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] . " _ " );
$tmpfile = fopen ( $attachment_file , 'w' );
fwrite ( $tmpfile , $message );
fclose ( $tmpfile );
$size = filesize ( $attachment_file );
$attachments [] = array (
'name' => trim ( $subject ) . '.eml' ,
'mimeType' => 'message/rfc822' ,
2014-07-03 12:16:23 +02:00
'type' => 'message/rfc822' ,
2013-10-15 12:44:42 +02:00
'tmp_name' => $attachment_file ,
'size' => $size ,
);
2009-08-19 15:56:35 +02:00
}
2009-08-13 12:07:34 +02:00
else
{
2009-11-28 19:16:18 +01:00
if ( ! empty ( $attachment [ 'folder' ]))
{
$is_winmail = $_GET [ 'is_winmail' ] ? $_GET [ 'is_winmail' ] : 0 ;
2013-03-05 15:47:00 +01:00
$mailobject -> reopen ( $attachment [ 'folder' ]);
$attachmentData = $mailobject -> getAttachment ( $attachment [ 'uid' ], $attachment [ 'partID' ], $is_winmail );
2009-11-28 19:16:18 +01:00
$attachment [ 'file' ] = tempnam ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'temp_dir' ], $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] . " _ " );
$tmpfile = fopen ( $attachment [ 'file' ], 'w' );
fwrite ( $tmpfile , $attachmentData [ 'attachment' ]);
fclose ( $tmpfile );
}
2009-08-13 12:07:34 +02:00
$attachments [] = array (
'name' => $attachment [ 'name' ],
'mimeType' => $attachment [ 'type' ],
2014-07-03 12:16:23 +02:00
'type' => $attachment [ 'type' ],
2009-08-13 12:07:34 +02:00
'tmp_name' => $attachment [ 'file' ],
'size' => $attachment [ 'size' ],
);
}
2006-08-23 21:03:25 +02:00
}
2013-03-05 15:47:00 +01:00
$mailobject -> closeConnection ();
2006-08-23 21:03:25 +02:00
}
2011-11-17 17:05:36 +01:00
// this one adds the mail itself (as message/rfc822 (.eml) file) to the infolog as additional attachment
// this is done to have a simple archive functionality (ToDo: opening .eml in email module)
2013-03-05 15:47:00 +01:00
if ( $_rawMailHeader && $_rawMailBody && $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ $sessionLocation ][ 'saveAsOptions' ] === 'add_raw' )
2011-11-17 17:05:36 +01:00
{
$message = ltrim ( str_replace ( " \n " , " \r \n " , $_rawMailHeader )) . str_replace ( " \n " , " \r \n " , $_rawMailBody );
$subject = str_replace ( '$$' , '__' ,( $_subject ? $_subject : lang ( '(no subject)' )));
$attachment_file = tempnam ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'temp_dir' ], $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] . " _ " );
$tmpfile = fopen ( $attachment_file , 'w' );
fwrite ( $tmpfile , $message );
fclose ( $tmpfile );
$size = filesize ( $attachment_file );
$attachments [] = array (
'name' => trim ( $subject ) . '.eml' ,
'mimeType' => 'message/rfc822' ,
2014-07-03 12:16:23 +02:00
'type' => 'message/rfc822' ,
2011-11-17 17:05:36 +01:00
'tmp_name' => $attachment_file ,
'size' => $size ,
);
}
2010-09-20 11:31:32 +02:00
//_debug_array($_to_emailAddress);
$toaddr = array ();
2014-01-28 10:22:12 +01:00
foreach ( array ( 'to' , 'cc' , 'bcc' ) as $x )
{
if ( is_array ( $_to_emailAddress [ $x ]) && ! empty ( $_to_emailAddress [ $x ]))
{
$toaddr = array_merge ( $toaddr , $_to_emailAddress [ $x ]);
}
}
2009-08-13 12:07:34 +02:00
//_debug_array($attachments);
2014-01-28 10:22:12 +01:00
$body_striped = strip_tags ( $mailClass :: htmlspecialchars ( $_body )); //we need to fix broken tags (or just stuff like "<800 USD/p" )
$body_decoded = htmlspecialchars_decode ( $body_striped , ENT_QUOTES );
2013-03-05 15:47:00 +01:00
$body = $mailClass :: createHeaderInfoSection ( array ( 'FROM' => $_to_emailAddress [ 'from' ],
2010-09-20 11:42:44 +02:00
'TO' => ( ! empty ( $_to_emailAddress [ 'to' ]) ? implode ( ',' , $_to_emailAddress [ 'to' ]) : null ),
'CC' => ( ! empty ( $_to_emailAddress [ 'cc' ]) ? implode ( ',' , $_to_emailAddress [ 'cc' ]) : null ),
'BCC' => ( ! empty ( $_to_emailAddress [ 'bcc' ]) ? implode ( ',' , $_to_emailAddress [ 'bcc' ]) : null ),
2010-09-20 11:31:32 +02:00
'SUBJECT' => $_subject ,
2014-01-28 10:22:12 +01:00
'DATE' => $mailClass :: _strtotime ( $_date ))) . $body_decoded ;
2006-10-04 19:40:33 +02:00
$this -> edit ( $this -> bo -> import_mail (
2010-09-20 11:31:32 +02:00
implode ( ',' , $toaddr ), $_subject , $body , $attachments , $_date
2006-10-04 19:40:33 +02:00
));
exit ;
}
elseif ( $uid && $mailbox )
{
2013-03-05 15:47:00 +01:00
if ( ! isset ( $icServerID )) $icServerID =& egw_cache :: getSession ( $sessionLocation , 'activeProfileID' );
$mailobject = $mailClass :: getInstance ( true , $icServerID );
$mailobject -> openConnection ();
$mailobject -> reopen ( $mailbox );
2008-04-18 13:53:55 +02:00
2014-01-07 13:58:35 +01:00
$mailcontent = $mailClass :: get_mailcontent ( $mailobject , $uid , $partid , $mailbox , false , true ,( ! ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ $sessionLocation ][ 'saveAsOptions' ] === 'text_only' )));
2011-11-17 17:05:36 +01:00
// this one adds the mail itself (as message/rfc822 (.eml) file) to the infolog as additional attachment
// this is done to have a simple archive functionality (ToDo: opening .eml in email module)
2013-03-05 15:47:00 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ $sessionLocation ][ 'saveAsOptions' ] === 'add_raw' )
2011-11-17 17:05:36 +01:00
{
2014-01-20 14:14:18 +01:00
$message = $mailobject -> getMessageRawBody ( $uid , $partid , $mailbox );
$headers = $mailobject -> getMessageHeader ( $uid , $partid , true , false , $mailbox );
2011-11-17 17:05:36 +01:00
$subject = str_replace ( '$$' , '__' ,( $headers [ 'SUBJECT' ] ? $headers [ 'SUBJECT' ] : lang ( '(no subject)' )));
$attachment_file = tempnam ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'temp_dir' ], $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] . " _ " );
$tmpfile = fopen ( $attachment_file , 'w' );
fwrite ( $tmpfile , $message );
fclose ( $tmpfile );
$size = filesize ( $attachment_file );
$mailcontent [ 'attachments' ][] = array (
'name' => trim ( $subject ) . '.eml' ,
'mimeType' => 'message/rfc822' ,
2014-07-03 12:16:23 +02:00
'type' => 'message/rfc822' ,
2011-11-17 17:05:36 +01:00
'tmp_name' => $attachment_file ,
'size' => $size ,
);
}
2014-07-03 12:16:23 +02:00
//_debug_array($mailcontent);
2009-08-13 12:07:34 +02:00
return $this -> edit ( $this -> bo -> import_mail (
$mailcontent [ 'mailaddress' ],
$mailcontent [ 'subject' ],
$mailcontent [ 'message' ],
$mailcontent [ 'attachments' ],
strtotime ( $mailcontent [ 'headers' ][ 'DATE' ])
));
}
2013-08-26 12:24:11 +02:00
egw_framework :: window_close ( lang ( 'Error: no mail (Mailbox / UID) given!' ));
2009-08-13 12:07:34 +02:00
}
2006-10-04 19:40:33 +02:00
/**
* 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' => < your app > , \
* * 'view_id' => < id name > , \
* * < id name > => < id value > , \
* * 'view' => < menuaction to view an entry in your app > \
* ));
*/
function hook_view ( $args )
{
2014-02-12 12:07:33 +01:00
// Load JS for infolog actions
egw_framework :: validate_file ( '.' , 'app' , 'infolog' );
2006-10-04 19:40:33 +02:00
switch ( $args [ 'location' ])
2003-04-28 00:35:39 +02:00
{
2006-10-04 19:40:33 +02:00
case 'addressbook_view' :
$app = 'addressbook' ;
$view_id = 'ab_id' ;
$view_id2 = 'contact_id' ;
2008-08-27 14:31:33 +02:00
$view = 'addressbook.addressbook_ui.view' ;
2006-10-04 19:40:33 +02:00
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' ])
{
2008-10-07 14:50:14 +02:00
echo " <p>infolog_ui::hook_view( " ; print_r ( $args ); echo " ): app=' $app ', $view_id =' $args[$view_id] ', view=' $view '</p> \n " ;
2006-10-04 19:40:33 +02:00
}
if ( ! isset ( $app ) || ! isset ( $args [ $view_id ]))
{
return False ;
}
$this -> called_by = $app ; // for read/save_sessiondata, to have different sessions for the hooks
2013-11-13 23:44:28 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] = 'infolog' ;
2011-05-02 21:41:21 +02:00
translation :: add_app ( 'infolog' );
2003-04-28 00:35:39 +02:00
2013-11-13 23:44:28 +01:00
$this -> index ( null , $app , $args [ $view_id ], array (
2006-10-04 19:40:33 +02:00
'menuaction' => $view ,
isset ( $view_id2 ) ? $view_id2 : $view_id => $args [ $view_id ]
), True );
2007-09-22 16:58:10 +02:00
}
2008-04-18 13:53:55 +02:00
2007-09-22 16:58:10 +02:00
/**
* Defines the fields for the csv export
*
2014-06-12 14:34:50 +02:00
* @ param string $type infolog type to include only the matching custom fields if set
2007-09-22 16:58:10 +02:00
* @ return array
*/
function csv_export_fields ( $type = null )
{
$fields = array (
'info_type' => lang ( 'Type' ),
'info_from' => lang ( 'Contact' ),
'info_addr' => lang ( 'Phone/Email' ),
// 'info_link_id' => lang('primary link'),
'info_cat' => array ( 'label' => lang ( 'Category' ), 'type' => 'select-cat' ),
'info_priority' => lang ( 'Priority' ),
'info_owner' => array ( 'label' => lang ( 'Owner' ), 'type' => 'select-account' ),
'info_access' => lang ( 'Access' ),
'info_status' => lang ( 'Status' ),
'info_percent' => lang ( 'Completed' ),
'info_datecompleted' => lang ( 'Date completed' ),
2010-04-23 14:10:36 +02:00
'info_datemodified' => lang ( 'Last modified' ),
'info_modifier' => array ( 'label' => lang ( 'Modifier' ), 'type' => 'select-account' ),
2007-09-22 16:58:10 +02:00
'info_location' => lang ( 'Location' ),
'info_startdate' => lang ( 'Startdate' ),
'info_enddate' => lang ( 'Enddate' ),
'info_responsible' => array ( 'label' => lang ( 'Responsible' ), 'type' => 'select-account' ),
'info_subject' => lang ( 'Subject' ),
'info_des' => lang ( 'Description' ),
2010-04-23 14:10:36 +02:00
'info_id' => lang ( 'Id' ),
2007-09-22 16:58:10 +02:00
// PM fields
'info_planned_time' => lang ( 'planned time' ),
'info_used_time' => lang ( 'used time' ),
'pl_id' => lang ( 'pricelist' ),
'info_price' => lang ( 'price' ),
);
foreach ( $this -> bo -> timestamps as $name )
{
$fields [ $name ] = array ( 'label' => $fields [ $name ], 'type' => 'date-time' );
}
foreach ( $this -> bo -> customfields as $name => $data )
{
2010-04-23 14:10:36 +02:00
if ( $data [ 'type2' ] && $type && ! in_array ( $type , explode ( ',' , $data [ 'type2' ]))) continue ;
2007-09-22 16:58:10 +02:00
$fields [ '#' . $name ] = array (
'label' => $data [ 'label' ],
'type' => $data [ 'type' ],
);
}
return $fields ;
}
2006-10-04 19:40:33 +02:00
}