2005-11-09 00:15:14 +01:00
< ? php
2007-03-09 12:30:59 +01:00
/**
* eGroupWare - Calendar ' s Listview and Search
*
* @ link http :// www . egroupware . org
* @ package calendar
* @ author Ralf Becker < RalfBecker - AT - outdoor - training . de >
2009-10-03 09:32:05 +02:00
* @ copyright ( c ) 2005 - 9 by RalfBecker - At - outdoor - training . de
2007-03-09 12:30:59 +01:00
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
* @ version $Id $
*/
2005-11-09 00:15:14 +01:00
/**
* Class to generate the calendar listview and the search
*
* The new UI , BO and SO classes have a strikt definition , in which time - zone they operate :
* UI only operates in user - time , so there have to be no conversation at all !!!
* BO ' s functions take and return user - time only ( ! ), they convert internaly everything to servertime , because
* SO operates only on server - time
*
* The state of the UI elements is managed in the uical class , which all UI classes extend .
*
* All permanent debug messages of the calendar - code should done via the debug - message method of the bocal class ! ! !
*/
2008-06-07 19:45:33 +02:00
class calendar_uilist extends calendar_ui
2005-11-09 00:15:14 +01:00
{
var $public_functions = array (
'listview' => True ,
);
/**
2007-03-09 12:30:59 +01:00
* integer level or string function - or widget - name
2008-06-07 19:45:33 +02:00
*
2007-03-09 12:30:59 +01:00
* @ var mixed
2005-11-09 00:15:14 +01:00
*/
var $debug = false ;
2007-03-09 12:30:59 +01:00
/**
* Filternames
2008-06-07 19:45:33 +02:00
*
2007-03-09 12:30:59 +01:00
* @ var array
*/
var $date_filters = array (
'after' => 'After current date' ,
'before' => 'Before current date' ,
'all' => 'All events' ,
'custom' => 'Selected range' ,
);
2005-11-09 00:15:14 +01:00
/**
* Constructor
*
* @ param array $set_states = null to manualy set / change one of the states , default NULL = use $_REQUEST
*/
2008-06-07 19:45:33 +02:00
function __construct ( $set_states = null )
2005-11-09 00:15:14 +01:00
{
2008-06-07 19:45:33 +02:00
parent :: __construct ( true , $set_states ); // call the parent's constructor
2005-11-09 00:15:14 +01:00
2006-03-03 19:51:46 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = $GLOBALS [ 'egw_info' ][ 'apps' ][ 'calendar' ][ 'title' ] . ' - ' . lang ( 'Listview' ) .
// for a single owner we add it's name to the app-header
( count ( explode ( ',' , $this -> owner )) == 1 ? ': ' . $this -> bo -> participant_name ( $this -> owner ) : '' );
2008-06-07 19:45:33 +02:00
2007-03-09 12:30:59 +01:00
foreach ( $this -> date_filters as $name => $label )
{
$this -> date_filters [ $name ] = lang ( $label );
}
2008-06-07 19:45:33 +02:00
2006-03-03 19:51:46 +01:00
$this -> check_owners_access ();
2005-11-09 00:15:14 +01:00
}
2008-06-07 19:45:33 +02:00
2005-11-09 00:15:14 +01:00
/**
* Show the calendar on the home page
*
* @ return string with content
*/
function & home ()
{
// set the defaults for the home-page
2008-08-15 07:09:05 +02:00
$this -> __construct ( array (
2005-11-09 00:15:14 +01:00
'date' => $this -> bo -> date2string ( $this -> bo -> now_su ),
'cat_id' => 0 ,
'filter' => 'all' ,
'owner' => $this -> user ,
'multiple' => 0 ,
2010-10-12 11:49:17 +02:00
'view' => $this -> bo -> cal_prefs [ 'mainscreen_showevents' ],
2005-11-09 00:15:14 +01:00
));
2009-10-03 09:32:05 +02:00
egw_session :: appsession ( 'calendar_list' , 'calendar' , '' ); // in case there's already something set
2005-11-09 00:15:14 +01:00
return $this -> listview ( null , '' , true );
2008-06-07 19:45:33 +02:00
}
2005-11-09 00:15:14 +01:00
/**
* Show the listview
*/
function listview ( $content = null , $msg = '' , $home = false )
{
2006-03-04 10:54:31 +01:00
if ( $_GET [ 'msg' ]) $msg .= $_GET [ 'msg' ];
if ( $this -> group_warning ) $msg .= $this -> group_warning ;
2005-11-09 00:15:14 +01:00
2009-10-03 09:32:05 +02:00
$etpl = new etemplate ( 'calendar.list' );
2006-03-01 10:15:58 +01:00
if ( is_array ( $content ) && $content [ 'nm' ][ 'rows' ][ 'delete' ])
{
2010-04-05 20:28:41 +02:00
// handle a single delete like delete with the checkboxes
list ( $id ) = @ each ( $content [ 'nm' ][ 'rows' ][ 'delete' ]);
$content [ 'action' ] = 'delete' ;
$content [ 'nm' ][ 'rows' ][ 'checked' ] = array ( $id );
2006-03-01 10:15:58 +01:00
}
2010-04-26 23:41:07 +02:00
if ( is_array ( $content ) && $content [ 'nm' ][ 'rows' ][ 'timesheet' ])
{
// handle a single timesheet like timesheet with the checkboxes
list ( $id ) = @ each ( $content [ 'nm' ][ 'rows' ][ 'timesheet' ]);
$content [ 'action' ] = 'timesheet-add' ;
$content [ 'nm' ][ 'rows' ][ 'checked' ] = array ( $id );
}
2011-02-09 16:58:06 +01:00
if ( is_array ( $content ) && isset ( $content [ 'nm' ][ 'rows' ][ 'document' ])) // handle insert in default document button like an action
{
list ( $id ) = @ each ( $content [ 'nm' ][ 'rows' ][ 'document' ]);
$content [ 'action' ] = 'document' ;
$content [ 'nm' ][ 'rows' ][ 'checked' ] = array ( $id );
}
2010-04-26 23:41:07 +02:00
2010-04-05 20:28:41 +02:00
// Handle actions
if ( $content [ 'action' ] != '' )
2008-02-05 16:50:54 +01:00
{
2011-02-10 20:19:52 +01:00
// Allow merge using the date range filter
if ( strpos ( $content [ 'action' ], 'document' ) !== false && ! count ( $content [ 'nm' ][ 'rows' ][ 'checked' ]) && ! $content [ 'use_all' ]) {
$content [ 'nm' ][ 'rows' ][ 'checked' ][] = $this -> get_merge_range ( $content [ 'nm' ]);
}
2010-04-05 20:28:41 +02:00
if ( ! count ( $content [ 'nm' ][ 'rows' ][ 'checked' ]) && ! $content [ 'use_all' ]) {
$msg = lang ( 'You need to select some events first' );
}
else
2008-02-05 16:50:54 +01:00
{
2010-04-05 20:28:41 +02:00
if ( $this -> action ( $content [ 'action' ], $content [ 'nm' ][ 'rows' ][ 'checked' ], $content [ 'use_all' ],
2011-03-09 18:42:52 +01:00
$success , $failed , $action_msg , 'calendar_list' , $msg , $content [ 'no_notifications' ]))
2008-02-05 16:50:54 +01:00
{
2010-04-05 20:28:41 +02:00
$msg .= lang ( '%1 event(s) %2' , $success , $action_msg );
}
elseif ( is_null ( $msg ))
{
$msg .= lang ( '%1 event(s) %2, %3 failed because of insufficent rights !!!' , $success , $action_msg , $failed );
2008-02-05 16:50:54 +01:00
}
}
2010-04-26 23:41:07 +02:00
$content [ 'nm' ][ 'rows' ][ 'checked' ] = array ();
2008-02-05 16:50:54 +01:00
}
2005-11-09 00:15:14 +01:00
$content = array (
2009-10-03 09:32:05 +02:00
'nm' => egw_session :: appsession ( 'calendar_list' , 'calendar' ),
2006-03-01 10:15:58 +01:00
'msg' => $msg ,
2005-11-09 00:15:14 +01:00
);
if ( ! is_array ( $content [ 'nm' ]))
{
$content [ 'nm' ] = array (
2008-06-07 19:45:33 +02:00
'get_rows' => 'calendar.calendar_uilist.get_rows' ,
2005-11-09 00:15:14 +01:00
'filter_no_lang' => True , // I set no_lang for filter (=dont translate the options)
'no_filter2' => True , // I disable the 2. filter (params are the same as for filter)
'no_cat' => True , // I disable the cat-selectbox
// 'bottom_too' => True,// I show the nextmatch-line (arrows, filters, search, ...) again after the rows
'filter' => 'after' ,
'order' => 'cal_start' , // IO name of the column to sort after (optional for the sortheaders)
'sort' => 'ASC' , // IO direction of the sort: 'ASC' or 'DESC'
2008-02-05 16:50:54 +01:00
'default_cols' => '!week,weekday,cal_title,cal_description,recure,cal_location,cal_owner,cat_id,pm_id' ,
2008-07-22 10:54:40 +02:00
'filter_onchange' => " set_style_by_class('table','custom_hide','visibility',this.value == 'custom' ? 'visible' : 'hidden'); if (this.value != 'custom') this.form.submit(); " ,
2007-03-09 12:30:59 +01:00
'header_left' => 'calendar.list.dates' ,
2005-11-09 00:15:14 +01:00
);
}
2009-12-08 23:41:49 +01:00
if ( $_GET [ 'search' ]) {
$content [ 'nm' ][ 'search' ] = $_GET [ 'search' ];
}
2005-11-09 00:15:14 +01:00
if ( isset ( $_REQUEST [ 'keywords' ])) // new search => set filters so every match is shown
{
$this -> adjust_for_search ( $_REQUEST [ 'keywords' ], $content [ 'nm' ]);
}
2010-04-05 20:28:41 +02:00
$sel_options = array (
'action' => array (
'delete' => array ( 'label' => 'Delete' , 'title' => 'Delete this event' ),
'ical' => array ( 'label' => 'Export (iCal)' , 'title' => 'Download this event as iCal' ),
),
'filter' => & $this -> date_filters
);
2010-04-06 21:01:17 +02:00
// More actions
if ( $GLOBALS [ 'egw_info' ][ 'apps' ][ 'timesheet' ]) {
$sel_options [ 'action' ][ 'timesheet-add' ] = array ( 'label' => 'Create timesheet' , 'title' => 'Create a timesheet entry from this event' );
}
2010-08-24 18:59:13 +02:00
// Add in deleted for admins
$config = config :: read ( 'phpgwapi' );
2010-11-22 17:19:28 +01:00
if ( $config [ 'calendar_delete_history' ])
2010-08-24 18:59:13 +02:00
{
$sel_options [ 'action' ][ 'undelete' ] = array ( 'label' => 'Un-Delete' , 'title' => 'Recover this event' );
2010-11-22 17:19:28 +01:00
if ( ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ] && $config [ 'calendar_delete_history' ] != 'user_purge' )
{
unset ( $sel_options [ 'action' ][ 'delete' ]);
$content [ 'nm' ][ 'no_delete' ] = true ;
}
2010-08-24 18:59:13 +02:00
}
2010-04-05 20:28:41 +02:00
foreach ( $this -> bo -> verbose_status as $key => $value )
{
if ( $key == 'G' ) continue ;
$sel_options [ 'action' ][ lang ( 'Change your participant status' )][ 'status-' . $key ] = $value ;
}
2011-02-09 16:58:06 +01:00
// Merge print
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'calendar' ][ 'document_dir' ])
{
$sel_options [ 'action' ][ lang ( 'Insert in document' ) . ':' ] = calendar_merge :: get_documents ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'calendar' ][ 'document_dir' ]);
}
2010-04-27 21:12:42 +02:00
// add scrollbar to long describtion, if user choose so in his prefs
if ( $this -> prefs [ 'limit_des_lines' ] > 0 || ( string ) $this -> prefs [ 'limit_des_lines' ] == '' )
{
$content [ 'css' ] .= '<style type="text/css">@media screen { .listDescription { max-height: ' .
(( $this -> prefs [ 'limit_des_lines' ] ? $this -> prefs [ 'limit_des_lines' ] : 5 ) * 1.35 ) . // dono why em is not real lines
'em; overflow: auto; }}</style>' ;
}
2010-04-05 20:28:41 +02:00
unset ( $sel_options [ 'action' ][ lang ( 'Change your participant status' )][ 'G' ]);
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ] .= $this -> get_javascript ();
2010-04-22 18:40:18 +02:00
$html = $etpl -> exec ( 'calendar.calendar_uilist.listview' , $content , $sel_options , $readonlys , '' , $home ? - 1 : 0 );
// Not sure why this has to be echoed instead of appended, but that's what works.
echo calendar_uiviews :: edit_series ();
return $html ;
2005-11-09 00:15:14 +01:00
}
2008-06-07 19:45:33 +02:00
2005-11-09 00:15:14 +01:00
/**
* set filter for search , so that everything is shown
*/
function adjust_for_search ( $keywords , & $params )
{
$params [ 'search' ] = $keywords ;
$params [ 'start' ] = 0 ;
$params [ 'order' ] = 'cal_start' ;
if ( $keywords )
{
$params [ 'filter' ] = 'all' ;
$params [ 'sort' ] = 'DESC' ;
unset ( $params [ 'col_filter' ][ 'participant' ]);
}
else
{
$params [ 'filter' ] = 'after' ;
$params [ 'sort' ] = 'ASC' ;
}
}
/**
* query calendar for nextmatch in the listview
*
2008-06-07 19:45:33 +02:00
* @ internal
2005-11-09 00:15:14 +01:00
* @ param array & $params parameters
* @ param array & $rows returned rows / events
* @ param array & $readonlys eg . to disable buttons based on acl
*/
function get_rows ( & $params , & $rows , & $readonlys )
{
//echo "uilist::get_rows() params="; _debug_array($params);
2007-03-09 12:30:59 +01:00
if ( isset ( $_GET [ 'listview_days' ]) && is_numeric ( $_GET [ 'listview_days' ]))
{
$params [ 'filter' ] = 'fixed' ;
}
if ( $params [ 'filter' ] == 'custom' )
{
if ( ! $params [ 'startdate' ] && ! $params [ 'enddate' ])
{
$params [ 'filter' ] = 'all' ;
}
elseif ( ! $params [ 'startdate' ])
{
$params [ 'filter' ] = 'before' ;
$this -> manage_states ( array ( 'date' => $this -> bo -> date2string ( $params [ 'enddate' ])));
}
elseif ( ! $params [ 'enddate' ])
{
$params [ 'filter' ] = 'after' ;
$this -> manage_states ( array ( 'date' => $this -> bo -> date2string ( $params [ 'startdate' ])));
}
}
2009-10-03 09:32:05 +02:00
$old_params = egw_session :: appsession ( 'calendar_list' , 'calendar' );
2005-11-09 00:15:14 +01:00
if ( $old_params [ 'filter' ] && $old_params [ 'filter' ] != $params [ 'filter' ]) // filter changed => order accordingly
{
$params [ 'order' ] = 'cal_start' ;
$params [ 'sort' ] = $params [ 'filter' ] == 'after' ? 'ASC' : 'DESC' ;
}
if ( $old_params [ 'search' ] != $params [ 'search' ])
{
$this -> adjust_for_search ( $params [ 'search' ], $params );
}
2009-11-10 21:18:35 +01:00
if ( ! $params [ 'csv_export' ]) egw_session :: appsession ( 'calendar_list' , 'calendar' , $params );
2008-06-07 19:45:33 +02:00
2009-10-03 09:32:05 +02:00
// do we need to query custom fields and which
$select_cols = explode ( ',' , $params [ 'selectcols' ]);
if ( in_array ( 'cfs' , $select_cols ))
{
$cfs = array ();
foreach ( $select_cols as $col )
{
if ( $col [ 0 ] == '#' ) $cfs [] = substr ( $col , 1 );
}
}
2005-11-09 00:15:14 +01:00
$search_params = array (
'cat_id' => $this -> cat_id ,
'filter' => $this -> filter ,
'query' => $params [ 'search' ],
'offset' => ( int ) $params [ 'start' ],
2009-10-22 15:41:44 +02:00
'num_rows' => $params [ 'num_rows' ],
2005-11-09 00:15:14 +01:00
'order' => $params [ 'order' ] ? $params [ 'order' ] . ' ' . $params [ 'sort' ] : 'cal_start' ,
2009-11-14 10:13:37 +01:00
'cfs' => $params [ 'csv_export' ] ? array () : $cfs ,
2005-11-09 00:15:14 +01:00
);
switch ( $params [ 'filter' ])
{
case 'all' :
break ;
case 'before' :
$search_params [ 'end' ] = $this -> date ;
2007-03-09 12:30:59 +01:00
$label = lang ( 'Before %1' , $this -> bo -> long_date ( $this -> date ));
break ;
case 'custom' :
2008-07-22 10:54:40 +02:00
$GLOBALS [ 'egw' ] -> js -> set_onload ( " set_style_by_class('table','custom_hide','visibility','visible'); " );
2007-03-09 12:30:59 +01:00
$this -> first = $search_params [ 'start' ] = $params [ 'startdate' ];
$this -> last = $search_params [ 'end' ] = $params [ 'enddate' ];
$label = $this -> bo -> long_date ( $this -> first , $this -> last );
2005-11-09 00:15:14 +01:00
break ;
2007-03-09 12:30:59 +01:00
case 'fixed' :
if ( $this -> listview_days == 5 || $this -> listview_days == 7 ) // weekview
{
$this -> first = $this -> datetime -> get_weekday_start ( $this -> year , $this -> month , $this -> day );
$this -> last = $this -> bo -> date2array ( $this -> first );
2008-01-21 14:22:47 +01:00
$this -> last [ 'day' ] += ( int ) $this -> listview_days - 1 ;
2007-03-09 12:30:59 +01:00
$this -> last [ 'hour' ] = 23 ; $this -> last [ 'minute' ] = $this -> last [ 'sec' ] = 59 ;
unset ( $this -> last [ 'raw' ]);
$this -> last = $this -> bo -> date2ts ( $this -> last );
$this -> date_filters [ 'fixed' ] = $label = lang ( 'Week' ) . ' ' . adodb_date ( 'W' , $this -> first ) . ': ' . $this -> bo -> long_date ( $this -> first , $this -> last );
2011-02-10 20:19:52 +01:00
$params [ 'startdate' ] = $search_params [ 'start' ] = $this -> first ;
$params [ 'enddate' ] = $search_params [ 'end' ] = $this -> last ;
2007-03-09 12:30:59 +01:00
break ;
}
elseif (( string ) $this -> listview_days === '0' ) // monthview
{
$this -> first = $this -> bo -> date2array ( $this -> date );
$this -> first [ 'day' ] = 1 ;
unset ( $this -> first [ 'raw' ]);
$this -> last = $this -> first ;
$this -> last [ 'month' ] += 1 ;
$this -> first = $this -> bo -> date2ts ( $this -> first );
$this -> last = $this -> bo -> date2ts ( $this -> last );
$this -> last -- ;
$this -> date_filters [ 'fixed' ] = $label = lang ( adodb_date ( 'F' , $this -> bo -> date2ts ( $this -> date ))) . ' ' . $this -> year ;
2011-02-10 20:19:52 +01:00
$params [ 'startdate' ] = $search_params [ 'start' ] = $this -> first ;
$params [ 'enddate' ] = $search_params [ 'end' ] = $this -> last ;
2007-03-09 12:30:59 +01:00
break ;
}
// fall through to after given date
2005-11-09 00:15:14 +01:00
case 'after' :
default :
2007-03-09 12:30:59 +01:00
$label = lang ( 'After %1' , $this -> bo -> long_date ( $this -> date ));
2005-11-09 00:15:14 +01:00
$search_params [ 'start' ] = $this -> date ;
break ;
}
2007-03-09 12:30:59 +01:00
if ( $label )
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] .= ': ' . $label ;
2011-02-10 20:19:52 +01:00
$params [ 'options-filter' ][ $params [ 'filter' ]] = $label ; // Add it in, or it will be cleared
2007-03-09 12:30:59 +01:00
}
2005-11-09 00:15:14 +01:00
if (( int ) $params [ 'col_filter' ][ 'participant' ])
{
$search_params [ 'users' ] = ( int ) $params [ 'col_filter' ][ 'participant' ];
}
elseif ( empty ( $params [ 'search' ])) // active search displays entries from all users
{
2006-03-03 19:51:46 +01:00
$search_params [ 'users' ] = explode ( ',' , $this -> owner );
2005-11-09 00:15:14 +01:00
}
$rows = array ();
foreach (( array ) $this -> bo -> search ( $search_params ) as $event )
{
2007-01-02 15:55:24 +01:00
$readonlys [ 'view[' . $event [ 'id' ] . ']' ] = ! ( $readonlys [ 'edit[' . $event [ 'id' ] . ']' ] = ! $this -> bo -> check_perms ( EGW_ACL_EDIT , $event ));
2010-04-26 23:41:07 +02:00
// Delete disabled for other applications
2010-11-22 17:19:28 +01:00
$readonlys [ 'delete[' . $event [ 'id' ] . ']' ] = ! $this -> bo -> check_perms ( EGW_ACL_DELETE , $event ) || ! is_numeric ( $event [ 'id' ]) || $params [ 'no_delete' ];
2010-04-27 20:36:18 +02:00
// Filemanager disabled for other applications
$readonlys [ 'filemanager[' . $event [ 'id' ] . ']' ] = ! is_numeric ( $event [ 'id' ]);
2005-11-09 00:15:14 +01:00
2005-12-02 16:34:45 +01:00
$event [ 'recure' ] = $this -> bo -> recure2string ( $event );
2009-11-10 21:18:35 +01:00
if ( $params [ 'csv_export' ])
{
$event [ 'participants' ] = implode ( " , \n " , $this -> bo -> participants ( $event , true ));
}
else
{
$event [ 'parts' ] = implode ( " , \n " , $this -> bo -> participants ( $event , true ));
$event [ 'date' ] = $this -> bo -> date2string ( $event [ 'start' ]);
}
2005-11-09 00:15:14 +01:00
if ( empty ( $event [ 'description' ])) $event [ 'description' ] = ' ' ; // no description screws the titles horz. alignment
if ( empty ( $event [ 'location' ])) $event [ 'location' ] = ' ' ; // no location screws the owner horz. alignment
2009-11-26 09:28:06 +01:00
// respect category permissions
if ( ! empty ( $event [ 'category' ]))
{
$event [ 'category' ] = $this -> categories -> check_list ( EGW_ACL_READ , $event [ 'category' ]);
}
2009-10-03 09:32:05 +02:00
2010-04-26 18:47:13 +02:00
if ( ! ( int ) $event [ 'id' ] && preg_match ( '/^([a-z_-]+)([0-9]+)$/i' , $event [ 'id' ], $matches ))
{
$app = $matches [ 1 ];
$app_id = $matches [ 2 ];
$icons = array ();
if (( $is_private = calendar_bo :: integration_get_private ( $app , $app_id , $event )))
{
$icons [] = html :: image ( 'calendar' , 'private' );
}
else
{
2010-04-27 20:36:18 +02:00
$icons = calendar_uiviews :: integration_get_icons ( $app , $app_id , $event );
2010-04-26 18:47:13 +02:00
}
}
2010-04-06 18:58:47 +02:00
2010-04-27 20:36:18 +02:00
$event [ 'app' ] = 'calendar' ;
$event [ 'app_id' ] = $event [ 'id' ];
2010-04-26 18:47:13 +02:00
// Edit link
if ( $app && $app_id )
{
$popup = calendar_uiviews :: integration_get_popup ( $app , $app_id );
// Need to strip off 'onclick'
$event [ 'edit_link' ] = preg_replace ( '/ ?onclick="(.+)"/i' , '$1' , $popup );
2010-04-27 20:36:18 +02:00
$event [ 'app' ] = $app ;
$event [ 'app_id' ] = $app_id ;
2010-04-26 18:47:13 +02:00
}
2010-04-30 11:29:21 +02:00
elseif ( $event [ 'recur_type' ] != MCAL_RECUR_NONE )
{
$event [ 'edit_link' ] = " edit_series( { $event [ 'id' ] } , { $event [ 'start' ] } );return false; " ;
2010-04-30 17:41:32 +02:00
$event [ 'app_id' ] .= ':' . $event [ 'recur_date' ];
2010-04-30 11:29:21 +02:00
}
else
{
2010-04-26 18:47:13 +02:00
$view_link = egw :: link ( '/index.php' , array ( 'menuaction' => 'calendar.calendar_uiforms.edit' , 'cal_id' => $event [ 'id' ], 'date' => $this -> bo -> date2string ( $event [ 'start' ])));
2010-04-06 18:58:47 +02:00
$event [ 'edit_link' ] = $this -> popup ( $view_link ) . '; return false;' ;
2010-04-30 11:29:21 +02:00
}
2010-04-06 18:58:47 +02:00
2005-11-09 00:15:14 +01:00
$rows [] = $event ;
2010-04-30 11:29:21 +02:00
unset ( $app );
unset ( $app_id );
2005-11-09 00:15:14 +01:00
}
2008-02-05 16:50:54 +01:00
$wv = 0 ;
$dv = 0 ;
2007-03-09 12:30:59 +01:00
$params [ 'options-selectcols' ][ 'week' ] = lang ( 'Week' );
2008-02-05 16:50:54 +01:00
$params [ 'options-selectcols' ][ 'weekday' ] = lang ( 'Weekday' );
if (( substr ( $this -> cal_prefs [ 'nextmatch-calendar.list.rows' ], 0 , 4 ) == 'week' && strlen ( $this -> cal_prefs [ 'nextmatch-calendar.list.rows' ]) == 4 ) || substr ( $this -> cal_prefs [ 'nextmatch-calendar.list.rows' ], 0 , 5 ) == 'week,' )
2007-03-09 12:30:59 +01:00
{
$rows [ 'format' ] = '32' ; // prefix date with week-number
2008-02-05 16:50:54 +01:00
$wv = 1 ;
}
if ( ! ( strpos ( $this -> cal_prefs [ 'nextmatch-calendar.list.rows' ], 'weekday' ) === FALSE ))
{
$rows [ 'format' ] = '16' ;
$dv = 1 ;
}
2009-10-03 09:32:05 +02:00
if ( $wv && $dv )
2008-02-05 16:50:54 +01:00
{
$rows [ 'format' ] = '64' ;
2007-03-09 12:30:59 +01:00
}
if ( $this -> cat_id ) $rows [ 'no_cat_id' ] = true ;
if ( ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'projectmanager' ])
{
$params [ 'options-selectcols' ][ 'pm_id' ] = false ;
}
2005-11-09 00:15:14 +01:00
//_debug_array($rows);
return $this -> bo -> total ;
}
2010-04-05 20:28:41 +02:00
/**
* apply an action to multiple events
*
* @ param string / int $action 'delete' , 'ical' , 'print' , 'email'
* @ param array $checked event id ' s to use if ! $use_all
* @ param boolean $use_all if true use all events 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 events 'deleted'
* @ param string / array $session_name 'calendar_list'
* @ return boolean true if all actions succeded , false otherwise
*/
2011-03-09 18:42:52 +01:00
function action ( $action , $checked , $use_all , & $success , & $failed , & $action_msg , $session_name , & $msg , $skip_notification = false )
2010-04-05 20:28:41 +02:00
{
//echo '<p>' . __METHOD__ . "('$action',".print_r($checked,true).','.(int)$use_all.",...)</p>\n";
$success = $failed = 0 ;
// Split out combined values
if ( strpos ( $action , 'status' ) !== false ) {
list ( $action , $status ) = explode ( '-' , $action );
2011-02-09 16:58:06 +01:00
} elseif ( strpos ( $action , '_' ) !== false ) {
list ( $action , $settings ) = explode ( '_' , $action , 2 );
2010-04-05 20:28:41 +02:00
}
if ( $use_all )
{
// get the whole selection
$query = is_array ( $session_name ) ? $session_name : egw_session :: appsession ( $session_name , 'calendar' );
@ set_time_limit ( 0 ); // switch off the execution time limit, as for big selections it's too small
$query [ 'num_rows' ] = - 1 ; // all
$this -> get_rows ( $query , $checked , $readonlys ,( $action != 'ical' )); // true = only return the id's
} else {
// Pull the date for recurring events
$split = array ();
foreach ( $checked as $key ) {
2011-02-10 20:19:52 +01:00
if ( ! is_array ( $key ) && strpos ( $key , ':' ) !== false ) {
list ( $id , $recur_date ) = explode ( ':' , $key );
$split [] = array (
'id' => $id ,
'recur_date' => $recur_date
);
} else {
$split [] = $key ;
}
2010-04-05 20:28:41 +02:00
}
$checked = $split ;
}
// Actions where one action is done to the group
switch ( $action )
{
case 'ical' :
$boical = new calendar_ical ();
$ical =& $boical -> exportVCal ( $checked , '2.0' , 'PUBLISH' , false );
html :: content_header ( $content [ 'file' ] ? $content [ 'file' ] : 'event.ics' , 'text/calendar' , bytes ( $ical ));
echo $ical ;
common :: egw_exit ();
break ;
2011-02-09 16:58:06 +01:00
case 'document' :
$msg = $this -> download_document ( $checked , $settings );
$failed = count ( $checked );
return false ;
2010-04-05 20:28:41 +02:00
}
// Actions where the action is applied to each entry
2010-04-06 21:01:17 +02:00
if ( strpos ( $action , 'timesheet' ) !== false ) {
$timesheet_bo = new timesheet_bo ();
}
2010-04-05 20:28:41 +02:00
foreach ( $checked as $event )
{
2010-04-26 23:41:07 +02:00
if ( ! ( int ) $event [ 'id' ] && preg_match ( '/^([a-z_-]+)([0-9]+)$/i' , $event [ 'id' ], $matches ))
{
$app = $matches [ 1 ];
$app_id = $matches [ 2 ];
} else {
$id = $event [ 'id' ];
$recur_date = $event [ 'recur_date' ];
}
2010-04-05 20:28:41 +02:00
switch ( $action )
{
case 'delete' :
$action_msg = lang ( 'deleted' );
2010-04-26 23:41:07 +02:00
if ( $id && $this -> bo -> check_perms ( EGW_ACL_DELETE , $id ))
2010-04-05 20:28:41 +02:00
{
2011-03-09 18:42:52 +01:00
if ( $this -> bo -> delete ( $id , $recur_date , false , $skip_notification ))
2010-04-05 20:28:41 +02:00
{
$success ++ ;
}
}
else
{
$failure ++ ;
}
break ;
2010-08-24 18:59:13 +02:00
case 'undelete' :
$action_msg = lang ( 'recovered' );
if ( $id && ( $event = $this -> bo -> read ( $id , $recur_date )) && $this -> bo -> check_perms ( EGW_ACL_EDIT , $id ) &&
is_array ( $event ) && $event [ 'deleted' ])
{
$event [ 'deleted' ] = false ;
if ( $this -> bo -> save ( $event ))
{
$success ++ ;
break ;
}
}
$failure ++ ;
break ;
2010-04-05 20:28:41 +02:00
case 'status' :
2010-04-26 23:41:07 +02:00
if ( $id && $event = $this -> bo -> read ( $id , $recur_date ))
2010-04-05 20:28:41 +02:00
{
2010-04-26 23:41:07 +02:00
$old_status = $event [ 'participants' ][ $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ]];
calendar_so :: split_status ( $old_status , $quantity , $role );
if ( $old_status != $status )
2010-04-05 20:28:41 +02:00
{
2010-04-26 23:41:07 +02:00
//echo "<p>$uid: status changed '$data[old_status]' --> '$status<'/p>\n";
$new_status = calendar_so :: combine_status ( $status , $quantity , $role );
2011-03-09 18:42:52 +01:00
if ( $this -> bo -> set_status ( $id , $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ], $new_status , $recur_date ,
false , true , $skip_notification ))
2010-04-26 23:41:07 +02:00
{
$success ++ ;
$msg = lang ( 'Status changed' );
}
2010-04-05 20:28:41 +02:00
}
2010-04-26 23:41:07 +02:00
} else {
$failure ++ ;
2010-04-05 20:28:41 +02:00
}
break ;
2010-04-06 21:01:17 +02:00
case 'timesheet-add' :
2010-04-26 23:41:07 +02:00
if ( $id && ! $app )
{
$event = $this -> bo -> read ( $id , $recur_date );
}
elseif ( $app )
{
$query = egw_session :: appsession ( 'calendar_list' , 'calendar' );
$query [ 'query' ] = $app_id ;
$query [ 'search' ] = $app_id ;
$result = $this -> bo -> search ( $query );
$event = $result [ $app . $app_id ];
}
if ( ! $event )
{
$failure ++ ;
continue ;
}
2010-04-06 21:01:17 +02:00
$timesheet = array (
'ts_title' => $event [ 'title' ],
'ts_description' => $event [ 'description' ],
'ts_start' => $event [ 'start' ],
'ts_duration' => ( $event [ 'end' ] - $event [ 'start' ]) / 60 ,
'ts_quantity' => ( $event [ 'end' ] - $event [ 'start' ]) / 3600 ,
'ts_owner' => $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ],
'cat_id' => null ,
'pl_id' => null
);
2010-04-21 21:02:55 +02:00
// Add global categories
$categories = explode ( ',' , $event [ 'category' ]);
$global_categories = array ();
foreach ( $categories as $cat_id )
{
if ( $GLOBALS [ 'egw' ] -> categories -> is_global ( $cat_id ))
{
$global_categories [] = $cat_id ;
}
}
if ( count ( $global_categories ))
{
$timesheet [ 'cat_id' ] = implode ( ',' , $global_categories );
}
2010-04-06 21:01:17 +02:00
$timesheet_bo -> data = array ();
$err = $timesheet_bo -> save ( $timesheet );
if ( ! $err ) {
$success ++ ;
2010-04-22 23:41:35 +02:00
// Can't link to just one of a recurring series of events
2010-04-26 23:41:07 +02:00
if ( ! $recur_date || $app ) {
2010-04-22 23:41:35 +02:00
// Create link
2010-04-26 23:41:07 +02:00
$link_id = $app ? $app_id : $id ;
egw_link :: link ( $app ? $app : 'calendar' , $link_id , 'timesheet' , $timesheet_bo -> data [ 'ts_id' ]);
2010-04-22 23:41:35 +02:00
}
2010-04-06 21:01:17 +02:00
}
else
{
$failure ++ ;
}
$msg = lang ( 'Timesheet entries created for ' );
break ;
2010-04-05 20:28:41 +02:00
}
2010-04-30 11:29:21 +02:00
unset ( $app );
unset ( $app_id );
2010-04-05 20:28:41 +02:00
}
2010-04-06 21:01:17 +02:00
return ( $failure == 0 );
2010-04-05 20:28:41 +02:00
}
public function get_javascript ()
{
return ' < script LANGUAGE = " JavaScript " >
function do_action ( selbox )
{
if ( selbox . value != " " )
{
if ( selbox . value == " delete " )
{
if ( confirm ( " ' . lang('Delete') . ' " )) selbox . form . submit ();
}
else
{
selbox . form . submit ();
}
}
selbox . value = " " ;
}
</ script > ' ;
}
2011-02-09 16:58:06 +01:00
2011-02-10 20:19:52 +01:00
/**
* Get date ranges to select for merging instead of individual events
*
* @ param $nm nextmatch array from submit
*
* @ return array of ranges
*/
protected function get_merge_range ( $nm )
{
$checked = array ();
if ( $nm [ 'filter' ] == 'fixed' )
{
$checked [ 'start' ] = $nm [ 'startdate' ];
$last = $this -> bo -> date2array ( $nm [ 'enddate' ]);
$last [ 'hour' ] = '23' ; $last [ 'minute' ] = $last [ 'sec' ] = '59' ;
$checked [ 'end' ] = $this -> bo -> date2ts ( $last );
} else {
switch ( $nm [ 'filter' ]) {
case 'after' :
$checked [ 'start' ] = $nm [ 'startdate' ] ? $nm [ 'startdate' ] : strtotime ( 'today' );
break ;
case 'before' :
$checked [ 'end' ] = $nm [ 'enddate' ] ? $nm [ 'enddate' ] : strtotime ( 'tomorrow' );
break ;
case 'custom' :
$checked [ 'start' ] = $nm [ 'startdate' ];
$checked [ 'end' ] = $nm [ 'enddate' ];
break ;
}
}
return $checked ;
}
2011-02-09 16:58:06 +01:00
/**
* Download a document with inserted entries
*
* @ param array $ids timesheet - ids
* @ param string $document vfs - path of document
* @ return string error - message or error , otherwise the function does NOT return !
*/
function download_document ( $ids , $document = '' )
{
if ( ! $document )
{
$document = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'calendar' ][ 'default_document' ];
}
else
{
$document = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'calendar' ][ 'document_dir' ] . '/' . $document ;
}
if ( !@ egw_vfs :: stat ( $document ))
{
return lang ( " Document '%1' does not exist or is not readable for you! " , $document );
}
require_once ( EGW_INCLUDE_ROOT . '/calendar/inc/class.calendar_merge.inc.php' );
$document_merge = new calendar_merge ();
return $document_merge -> download ( $document , $ids );
}
2005-11-09 00:15:14 +01:00
}