2005-11-09 00:15:14 +01:00
|
|
|
<?php
|
2007-03-09 12:30:59 +01:00
|
|
|
/**
|
2011-04-27 18:53:06 +02:00
|
|
|
* EGroupware - Calendar's Listview and Search
|
2007-03-09 12:30:59 +01:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package calendar
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2016-02-17 20:56:54 +01:00
|
|
|
* @copyright (c) 2005-16 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
|
|
|
|
2016-05-01 19:47:59 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Link;
|
|
|
|
use EGroupware\Api\Framework;
|
|
|
|
use EGroupware\Api\Egw;
|
|
|
|
use EGroupware\Api\Acl;
|
|
|
|
use EGroupware\Api\Etemplate;
|
|
|
|
|
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',
|
2016-03-09 23:38:45 +01:00
|
|
|
'today' => 'Today',
|
2015-11-24 20:45:00 +01:00
|
|
|
'week' => 'Week',
|
|
|
|
'month' => 'Month',
|
2011-04-27 18:53:06 +02:00
|
|
|
'all' => 'All events',
|
2007-03-09 12:30:59 +01:00
|
|
|
'custom' => 'Selected range',
|
|
|
|
);
|
2005-11-09 00:15:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2016-05-01 19:47:59 +02:00
|
|
|
* @param array $set_states =null to manualy set / change one of the states, default NULL = use $_REQUEST
|
2005-11-09 00:15:14 +01:00
|
|
|
*/
|
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
|
|
|
|
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 listview
|
|
|
|
*/
|
2016-05-01 19:47:59 +02:00
|
|
|
function listview($_content=null,$msg='',$home=false)
|
2005-11-09 00:15:14 +01:00
|
|
|
{
|
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
|
|
|
|
2016-05-01 19:47:59 +02:00
|
|
|
$etpl = new Etemplate('calendar.list');
|
2006-03-01 10:15:58 +01:00
|
|
|
|
2011-06-20 20:21:29 +02:00
|
|
|
// Handle merge from sidebox
|
|
|
|
if($_GET['merge'])
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$_content['nm']['action'] = 'document_'.$_GET['merge'];
|
|
|
|
$_content['nm']['select_all'] = true;
|
2011-06-20 20:21:29 +02:00
|
|
|
}
|
|
|
|
|
2016-05-01 19:47:59 +02:00
|
|
|
if (is_array($_content))
|
2006-03-01 10:15:58 +01:00
|
|
|
{
|
2011-04-27 18:53:06 +02:00
|
|
|
// handle a single button like actions
|
|
|
|
foreach(array('delete','timesheet','document') as $button)
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
if ($_content['nm']['rows'][$button])
|
2011-04-27 18:53:06 +02:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
list($id) = each($_content['nm']['rows'][$button]);
|
|
|
|
$_content['nm']['action'] = $button;
|
|
|
|
$_content['nm']['selected'] = array($id);
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
// Handle actions
|
2016-05-01 19:47:59 +02:00
|
|
|
if ($_content['nm']['action'])
|
2008-02-05 16:50:54 +01:00
|
|
|
{
|
2011-04-27 18:53:06 +02:00
|
|
|
// Allow merge using the date range filter
|
2016-05-01 19:47:59 +02:00
|
|
|
if(strpos($_content['nm']['action'],'document') !== false &&
|
|
|
|
!count($_content['nm']['selected']) && !$_content['nm']['select_all']) {
|
|
|
|
$_content['nm']['selected'][] = $this->get_merge_range($_content['nm']);
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
2016-05-01 19:47:59 +02:00
|
|
|
if (!count($_content['nm']['selected']) && !$_content['nm']['select_all'])
|
2008-02-05 16:50:54 +01:00
|
|
|
{
|
2011-04-27 18:53:06 +02:00
|
|
|
$msg = lang('You need to select some events first');
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
else
|
2010-04-05 20:28:41 +02:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$success = $failed = $action_msg = null;
|
|
|
|
if ($this->action($_content['nm']['action'],$_content['nm']['selected'],$_content['nm']['select_all'],
|
|
|
|
$success,$failed,$action_msg,'calendar_list',$msg, $_content['nm']['checkboxes']['no_notifications']))
|
2011-04-27 18:53:06 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-11-09 00:15:14 +01:00
|
|
|
$content = array(
|
2016-05-01 19:47:59 +02:00
|
|
|
'nm' => Api\Cache::getSession('calendar', 'calendar_list'),
|
2005-11-09 00:15:14 +01:00
|
|
|
);
|
|
|
|
if (!is_array($content['nm']))
|
|
|
|
{
|
|
|
|
$content['nm'] = array(
|
2011-04-27 18:53:06 +02:00
|
|
|
'get_rows' => 'calendar.calendar_uilist.get_rows',
|
|
|
|
'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
|
|
|
|
'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'
|
2014-02-26 16:56:55 +01:00
|
|
|
'default_cols' => '!week,weekday,cal_title,cal_description,recure,cal_location,cal_owner,cat_id,pm_id',
|
2013-10-31 15:51:19 +01:00
|
|
|
'filter_onchange' => "app.calendar.filter_change",
|
2011-04-27 18:53:06 +02:00
|
|
|
'row_id' => 'row_id', // set in get rows "$event[id]:$event[recur_date]"
|
2014-03-18 23:55:48 +01:00
|
|
|
'row_modified' => 'modified',
|
2016-04-27 01:11:29 +02:00
|
|
|
'favorites' => true,
|
|
|
|
'placeholder_actions' => array('add')
|
2005-11-09 00:15:14 +01:00
|
|
|
);
|
|
|
|
}
|
2013-11-05 17:14:13 +01:00
|
|
|
$content['nm']['actions'] = $this->get_actions();
|
|
|
|
|
2012-01-08 00:35:17 +01:00
|
|
|
if (isset($_GET['filter']) && in_array($_GET['filter'],array_keys($this->date_filters)))
|
|
|
|
{
|
|
|
|
$content['nm']['filter'] = $_GET['filter'];
|
|
|
|
}
|
|
|
|
if ($_GET['search'])
|
|
|
|
{
|
2009-12-08 23:41:49 +01:00
|
|
|
$content['nm']['search'] = $_GET['search'];
|
|
|
|
}
|
2014-01-24 12:24:14 +01:00
|
|
|
// search via jdots ajax_exec uses $_REQUEST['json_data'] instead of regular GET parameters
|
|
|
|
if (isset($_REQUEST['json_data']) && ($json_data = json_decode($_REQUEST['json_data'], true)) &&
|
|
|
|
!empty($json_data['request']['parameters'][0]))
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$params = null;
|
2014-01-24 12:24:14 +01:00
|
|
|
parse_str(substr($json_data['request']['parameters'][0], 10), $params); // cut off "/index.php?"
|
|
|
|
if (isset($params['keywords'])) // new search => set filters so every match is shown
|
|
|
|
{
|
|
|
|
$this->adjust_for_search($params['keywords'], $content['nm']);
|
|
|
|
}
|
|
|
|
}
|
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']);
|
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
$sel_options['filter'] = &$this->date_filters;
|
2010-04-06 21:01:17 +02:00
|
|
|
|
2014-01-18 10:05:03 +01:00
|
|
|
// Send categories for row styling - calendar uses no_cat, so they don't go automatically
|
2016-05-01 19:47:59 +02:00
|
|
|
$sel_options['category'] = array('' => lang('all')) + Etemplate\Widget\Select::typeOptions('select-cat', ',,calendar');
|
2014-01-18 10:05:03 +01:00
|
|
|
// Prevent double encoding - widget does this on its own, but we're just grabbing the options
|
|
|
|
foreach($sel_options['category'] as &$label)
|
|
|
|
{
|
|
|
|
if(!is_array($label))
|
|
|
|
{
|
|
|
|
$label = html_entity_decode($label, ENT_NOQUOTES,'utf-8');
|
|
|
|
}
|
|
|
|
elseif($label['label'])
|
|
|
|
{
|
|
|
|
$label['label'] = html_entity_decode($label['label'], ENT_NOQUOTES,'utf-8');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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: '.
|
2011-04-27 18:53:06 +02:00
|
|
|
(($this->prefs['limit_des_lines'] ? $this->prefs['limit_des_lines'] : 5) * 1.35). // dono why em is not real lines
|
2010-04-27 21:12:42 +02:00
|
|
|
'em; overflow: auto; }}</style>';
|
|
|
|
}
|
2010-04-05 20:28:41 +02:00
|
|
|
|
2014-02-06 00:36:01 +01:00
|
|
|
if($msg)
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
Framework::message($msg);
|
2014-02-06 00:36:01 +01:00
|
|
|
}
|
2016-05-01 19:47:59 +02:00
|
|
|
$html = $etpl->exec('calendar.calendar_uilist.listview',$content,$sel_options,array(),array(),$home ? -1 : 0);
|
2010-04-22 18:40:18 +02:00
|
|
|
|
|
|
|
// Not sure why this has to be echoed instead of appended, but that's what works.
|
2013-10-31 15:51:19 +01:00
|
|
|
//echo calendar_uiviews::edit_series();
|
2010-04-22 18:40:18 +02:00
|
|
|
|
|
|
|
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
|
2016-05-01 19:47:59 +02:00
|
|
|
* @param array &$readonlys eg. to disable buttons based on Acl
|
2005-11-09 00:15:14 +01:00
|
|
|
*/
|
|
|
|
function get_rows(&$params,&$rows,&$readonlys)
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
unset($readonlys); // not used;
|
2005-11-09 00:15:14 +01:00
|
|
|
//echo "uilist::get_rows() params="; _debug_array($params);
|
2007-03-09 12:30:59 +01:00
|
|
|
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'])));
|
|
|
|
}
|
|
|
|
}
|
2016-05-01 19:47:59 +02:00
|
|
|
$old_params = Api\Cache::getSession('calendar', 'calendar_list');
|
2012-08-14 09:55:05 +02:00
|
|
|
if (is_array($old_params))
|
2005-11-09 00:15:14 +01:00
|
|
|
{
|
2012-08-14 09:55:05 +02:00
|
|
|
if ($old_params['filter'] && $old_params['filter'] != $params['filter']) // filter changed => order accordingly
|
|
|
|
{
|
|
|
|
$params['order'] = 'cal_start';
|
2016-04-20 18:52:52 +02:00
|
|
|
$params['sort'] = $params['filter'] == 'before' ? 'DESC' : 'ASC';
|
2012-08-14 09:55:05 +02:00
|
|
|
}
|
|
|
|
if ($old_params['search'] != $params['search'])
|
|
|
|
{
|
|
|
|
$this->adjust_for_search($params['search'],$params);
|
|
|
|
}
|
2005-11-09 00:15:14 +01:00
|
|
|
}
|
2016-05-01 19:47:59 +02:00
|
|
|
if (!$params['csv_export']) Api\Cache::setSession('calendar', 'calendar_list', $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
|
2013-08-03 17:06:21 +02:00
|
|
|
// Check stored preference if selectcols isn't available (ie: first call)
|
2014-12-11 19:00:14 +01:00
|
|
|
$select_cols = $params['selectcols'] ? $params['selectcols'] : $GLOBALS['egw_info']['user']['preferences']['calendar']['nextmatch-calendar.list.rows'];
|
|
|
|
if(!is_array($params['selectcols']))
|
|
|
|
{
|
|
|
|
$select_cols = explode(',',$select_cols);
|
|
|
|
}
|
2009-10-03 09:32:05 +02:00
|
|
|
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(
|
2015-10-14 16:32:33 +02:00
|
|
|
'cat_id' => $params['cat_id'] ? $params['cat_id'] : 0,
|
2015-06-10 23:51:28 +02:00
|
|
|
'filter' => isset($params['filter']) ? $params['filter'] : $this->filter,
|
2005-11-09 00:15:14 +01:00
|
|
|
'query' => $params['search'],
|
|
|
|
'offset' => (int) $params['start'],
|
2009-10-22 15:41:44 +02:00
|
|
|
'num_rows'=> $params['num_rows'],
|
2016-04-20 18:52:52 +02:00
|
|
|
'order' => $params['order'] ? $params['order'].' '.$params['sort'] : 'cal_start ASC',
|
2011-04-27 18:53:06 +02:00
|
|
|
'cfs' => $params['csv_export'] ? array() : $cfs,
|
2005-11-09 00:15:14 +01:00
|
|
|
);
|
2016-04-20 18:52:52 +02:00
|
|
|
// Non-blocking events above blocking
|
|
|
|
$search_params['order'] .= ', cal_non_blocking DESC';
|
2016-05-01 19:47:59 +02:00
|
|
|
|
2005-11-09 00:15:14 +01:00
|
|
|
switch($params['filter'])
|
|
|
|
{
|
|
|
|
case 'all':
|
|
|
|
break;
|
|
|
|
case 'before':
|
2016-05-01 19:47:59 +02:00
|
|
|
$search_params['end'] = $params['date'] ? Api\DateTime::to($params['date'],'ts') : $this->date;
|
2015-11-24 20:45:00 +01:00
|
|
|
$label = lang('Before %1',$this->bo->long_date($search_params['end']));
|
2007-03-09 12:30:59 +01:00
|
|
|
break;
|
|
|
|
case 'custom':
|
2016-05-01 19:47:59 +02:00
|
|
|
$this->first = $search_params['start'] = Api\DateTime::to($params['startdate'],'ts');
|
2014-11-17 16:47:36 +01:00
|
|
|
$this->last = $search_params['end'] = strtotime('+1 day', $this->bo->date2ts($params['enddate']))-1;
|
2007-03-09 12:30:59 +01:00
|
|
|
$label = $this->bo->long_date($this->first,$this->last);
|
2005-11-09 00:15:14 +01:00
|
|
|
break;
|
2016-03-09 23:38:45 +01:00
|
|
|
case 'today':
|
2016-05-01 19:47:59 +02:00
|
|
|
$today = new Api\DateTime();
|
2016-03-09 23:38:45 +01:00
|
|
|
$today->setTime(0, 0, 0);
|
|
|
|
$this->first = $search_params['start'] = $today->format('ts');
|
|
|
|
$today->setTime(23,59,59);
|
|
|
|
$this->last = $search_params['end'] = $today->format('ts');
|
|
|
|
break;
|
2015-11-24 20:45:00 +01:00
|
|
|
case 'week':
|
2016-05-02 22:22:47 +02:00
|
|
|
$start = new Api\DateTime($params['date'] ? $params['date'] : $this->date);
|
|
|
|
$start->setWeekstart();
|
|
|
|
$this->first = $start->format('ts');
|
2015-11-24 20:45:00 +01:00
|
|
|
$this->last = $this->bo->date2array($this->first);
|
|
|
|
$this->last['day'] += ($params['weekend'] == 'true' ? 7 : 5) - 1;
|
|
|
|
$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['week'] = $label = lang('Week').' '.adodb_date('W',$this->first).': '.$this->bo->long_date($this->first,$this->last);
|
2015-12-11 20:38:52 +01:00
|
|
|
$search_params['start'] = $this->first;
|
|
|
|
$search_params['end'] = $this->last;
|
2016-05-01 19:47:59 +02:00
|
|
|
$params['startdate'] = Api\DateTime::to($this->first, Api\DateTime::ET2);
|
|
|
|
$params['enddate'] = Api\DateTime::to($this->last, Api\DateTime::ET2);
|
2015-11-24 20:45:00 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'month':
|
|
|
|
$this->first = $this->bo->date2array($params['date'] ? $params['date'] : $this->date);
|
|
|
|
$this->first['day'] = 1;
|
|
|
|
unset($this->first['raw']);
|
|
|
|
$this->last = $this->first;
|
|
|
|
$this->last['month'] += 1;
|
|
|
|
$this->date_filters['month'] = $label = lang(adodb_date('F',$this->bo->date2ts($params['date']))).' '.$this->first['year'];
|
|
|
|
$this->first = $this->bo->date2ts($this->first);
|
|
|
|
$this->last = $this->bo->date2ts($this->last);
|
|
|
|
$this->last--;
|
2015-12-11 20:38:52 +01:00
|
|
|
$search_params['start'] = $this->first;
|
|
|
|
$search_params['end'] = $this->last;
|
2016-05-01 19:47:59 +02:00
|
|
|
$params['startdate'] = Api\DateTime::to($this->first, Api\DateTime::ET2);
|
|
|
|
$params['enddate'] = Api\DateTime::to($this->last, Api\DateTime::ET2);
|
2015-11-24 20:45:00 +01:00
|
|
|
break;
|
2016-02-17 20:56:54 +01:00
|
|
|
|
2007-03-09 12:30:59 +01:00
|
|
|
// fall through to after given date
|
2005-11-09 00:15:14 +01:00
|
|
|
case 'after':
|
|
|
|
default:
|
2016-05-01 19:47:59 +02:00
|
|
|
$this->date = $params['startdate'] ? Api\DateTime::to($params['startdate'],'ts') : $this->date;
|
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;
|
|
|
|
}
|
2015-07-15 18:29:10 +02:00
|
|
|
if($params['status_filter'])
|
|
|
|
{
|
|
|
|
$search_params['filter'] = $params['status_filter'];
|
|
|
|
}
|
2015-06-10 23:51:28 +02:00
|
|
|
if ($params['col_filter']['participant'])
|
2005-11-09 00:15:14 +01:00
|
|
|
{
|
2015-12-12 01:07:40 +01:00
|
|
|
$search_params['users'] = is_array($params['col_filter']['participant']) ? $params['col_filter']['participant'] : array( $params['col_filter']['participant']);
|
2005-11-09 00:15:14 +01:00
|
|
|
}
|
2016-05-25 01:13:40 +02:00
|
|
|
elseif (!$params['col_filter'] || !$params['col_filter']['participant'])
|
2005-11-09 00:15:14 +01:00
|
|
|
{
|
2016-05-25 01:13:40 +02:00
|
|
|
$search_params['users'] = $params['owner'] ? $params['owner'] : explode(',',$this->owner);
|
2005-11-09 00:15:14 +01:00
|
|
|
}
|
2015-08-18 11:07:12 +02:00
|
|
|
if ($params['col_filter'])
|
|
|
|
{
|
|
|
|
$col_filter = array();
|
|
|
|
foreach($params['col_filter'] as $name => $val)
|
|
|
|
{
|
2015-08-27 10:22:46 +02:00
|
|
|
if (!in_array($name, array('participant','row_id')) && (string)$val !== '')
|
2015-08-18 11:07:12 +02:00
|
|
|
{
|
|
|
|
$col_filter[$name] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
$rows = $js_integration_data = array();
|
2015-08-27 10:22:46 +02:00
|
|
|
|
2015-10-16 19:32:21 +02:00
|
|
|
// App header is mostly taken care of on the client side, but here we update
|
|
|
|
// it to match changing list filters
|
|
|
|
if($params['view'] && $params['view'] == 'listview')
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
Api\Json\Response::get()->call('app.calendar.set_app_header',
|
2015-11-24 00:18:05 +01:00
|
|
|
(count($search_params['users']) == 1 ? $this->bo->participant_name($search_params['users'][0]).': ' : '') .
|
2016-01-06 19:24:45 +01:00
|
|
|
$label);
|
2015-10-16 19:32:21 +02:00
|
|
|
}
|
2015-08-18 11:07:12 +02:00
|
|
|
foreach((array) $this->bo->search($search_params, !empty($col_filter) ? $col_filter : null) as $event)
|
2005-11-09 00:15:14 +01:00
|
|
|
{
|
2015-06-19 20:35:57 +02:00
|
|
|
|
2009-11-10 21:18:35 +01:00
|
|
|
if ($params['csv_export'])
|
|
|
|
{
|
|
|
|
$event['participants'] = implode(",\n",$this->bo->participants($event,true));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-27 21:10:53 +01:00
|
|
|
$this->to_client($event);
|
2009-11-10 21:18:35 +01:00
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
|
2016-05-01 19:47:59 +02:00
|
|
|
$matches = null;
|
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)))
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$icons[] = Api\Html::image('calendar','private');
|
2010-04-26 18:47:13 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
else
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$is_private = !$this->bo->check_perms(Acl::READ,$event);
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
|
|
|
if ($is_private)
|
|
|
|
{
|
|
|
|
$event['class'] .= 'rowNoView ';
|
|
|
|
}
|
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);
|
2011-04-27 18:53:06 +02:00
|
|
|
|
2010-04-26 18:47:13 +02:00
|
|
|
// 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;
|
2011-04-27 18:53:06 +02:00
|
|
|
|
|
|
|
// populate js_integration_data, if not already set
|
|
|
|
if (!isset($js_integration_data[$app]))
|
|
|
|
{
|
|
|
|
$js_integration_data[$app] = calendar_bo::integration_get_data($app,'edit_link');
|
|
|
|
}
|
2010-04-26 18:47:13 +02:00
|
|
|
}
|
2010-04-30 11:29:21 +02:00
|
|
|
elseif ($event['recur_type'] != MCAL_RECUR_NONE)
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$event['app_id'] .= ':'.Api\DateTime::to($event['recur_date'] ? $event['recur_date'] : $event['start'],'ts');
|
2010-04-30 11:29:21 +02:00
|
|
|
}
|
2010-04-06 18:58:47 +02:00
|
|
|
|
2015-04-09 17:55:55 +02:00
|
|
|
// Format start and end with timezone
|
|
|
|
foreach(array('start','end') as $time)
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$event[$time] = Api\DateTime::to($event[$time],'Y-m-d\TH:i:s\Z');
|
2015-04-09 17:55:55 +02:00
|
|
|
}
|
2011-04-27 18:53:06 +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
|
|
|
}
|
2013-10-31 15:51:19 +01:00
|
|
|
// set js_calendar_integration object, to use it in app.js cal_open() function
|
|
|
|
$params['js_integration_data'] = json_encode($js_integration_data);
|
2011-04-27 18:53:06 +02:00
|
|
|
|
2008-02-05 16:50:54 +01:00
|
|
|
$wv=0;
|
|
|
|
$dv=0;
|
2015-11-11 00:31:55 +01:00
|
|
|
|
2015-10-14 16:32:33 +02:00
|
|
|
// Add in some select options
|
|
|
|
$users = is_array($search_params['users']) ? $search_params['users'] : explode(',',$search_params['users']);
|
2015-11-11 00:31:55 +01:00
|
|
|
|
2015-11-16 20:40:52 +01:00
|
|
|
$this->bo->warnings['groupmembers'] = '';
|
2016-05-01 19:47:59 +02:00
|
|
|
if(($message = $this->check_owners_access($users)))
|
2015-11-11 00:31:55 +01:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
Api\Json\Response::get()->error($message);
|
2015-11-11 00:31:55 +01:00
|
|
|
}
|
2015-11-16 20:40:52 +01:00
|
|
|
else if($this->bo->warnings['groupmembers'])
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
Api\Json\Response::get()->error($this->bo->warnings['groupmembers']);
|
2015-11-16 20:40:52 +01:00
|
|
|
}
|
2015-11-24 01:18:37 +01:00
|
|
|
$rows['sel_options']['filter'] = $this->date_filters;
|
|
|
|
if($label)
|
|
|
|
{
|
|
|
|
$rows['sel_options']['filter'][$params['filter']] = $label;
|
|
|
|
}
|
2015-10-14 16:32:33 +02:00
|
|
|
foreach($users as $owner)
|
|
|
|
{
|
|
|
|
if(!is_int($owner) && $this->bo->resources[$owner[0]])
|
|
|
|
{
|
|
|
|
$app = $this->bo->resources[$owner[0]]['app'];
|
|
|
|
$_owner = substr($owner,1);
|
|
|
|
// Try link first
|
2016-05-01 19:47:59 +02:00
|
|
|
$title = Link::title($app, $_owner );
|
2015-10-14 16:32:33 +02:00
|
|
|
if($title)
|
|
|
|
{
|
|
|
|
$rows['sel_options']['owner'][$owner] = $title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-10 01:40:04 +01:00
|
|
|
$params['options-selectcols']['week'] = lang('Week');
|
|
|
|
$params['options-selectcols']['weekday'] = lang('Weekday');
|
2008-02-05 16:50:54 +01:00
|
|
|
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;
|
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
if (!(strpos($this->cal_prefs['nextmatch-calendar.list.rows'],'weekday')===FALSE))
|
|
|
|
{
|
|
|
|
$rows['format'] = '16';
|
2008-02-05 16:50:54 +01:00
|
|
|
$dv=1;
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
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;
|
2015-12-10 01:40:04 +01:00
|
|
|
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
|
|
|
|
|
|
|
/**
|
2011-04-27 18:53:06 +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
|
|
|
|
*/
|
|
|
|
function action($action,$checked,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg,$skip_notification=false)
|
|
|
|
{
|
2015-06-19 20:35:57 +02:00
|
|
|
//error_log(__METHOD__."('$action', ".array2string($checked).', all='.(int)$use_all.", ...)");
|
2010-04-05 20:28:41 +02:00
|
|
|
$success = $failed = 0;
|
2011-11-09 10:44:28 +01:00
|
|
|
$msg = null;
|
2010-04-05 20:28:41 +02:00
|
|
|
|
|
|
|
// Split out combined values
|
2011-04-27 18:53:06 +02:00
|
|
|
if(strpos($action, 'status') !== false)
|
|
|
|
{
|
2010-04-05 20:28:41 +02:00
|
|
|
list($action, $status) = explode('-', $action);
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
|
|
|
elseif (strpos($action, '_') !== false)
|
|
|
|
{
|
2011-02-09 16:58:06 +01:00
|
|
|
list($action, $settings) = explode('_', $action,2);
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
|
|
|
|
2011-04-27 18:53:06 +02:00
|
|
|
if ($use_all)
|
|
|
|
{
|
|
|
|
// get the whole selection
|
2016-05-01 19:47:59 +02:00
|
|
|
$query = is_array($session_name) ? $session_name : Api\Cache::getSession('calendar', $session_name);
|
2011-05-30 19:12:29 +02:00
|
|
|
@set_time_limit(0); // switch off the execution time limit, as for big selections it's too small
|
2011-04-27 18:53:06 +02:00
|
|
|
$query['num_rows'] = -1; // all
|
2016-05-01 19:47:59 +02:00
|
|
|
$readonlys = null;
|
2011-05-30 19:12:29 +02:00
|
|
|
$this->get_rows($query,$checked,$readonlys,!in_array($action,array('ical','document'))); // true = only return the id's
|
2013-05-09 05:31:01 +02:00
|
|
|
// Get rid of any extras (rows that aren't events)
|
|
|
|
if(in_array($action,array('ical','document')))
|
|
|
|
{
|
|
|
|
foreach($checked as $key => $event)
|
|
|
|
{
|
|
|
|
if(!is_numeric($key))
|
|
|
|
{
|
|
|
|
unset($checked[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
2011-05-30 19:12:29 +02:00
|
|
|
// for calendar integration we have to fetch all rows and unset the not selected ones, as we can not filter by id
|
2015-06-19 20:35:57 +02:00
|
|
|
elseif($action == 'document')
|
2010-04-05 20:28:41 +02:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$query = is_array($session_name) ? $session_name : Api\Cache::getSession('calendar', $session_name);
|
2011-05-30 19:12:29 +02:00
|
|
|
@set_time_limit(0); // switch off the execution time limit, as for big selections it's too small
|
2016-05-01 19:47:59 +02:00
|
|
|
$events = null;
|
2011-05-30 19:12:29 +02:00
|
|
|
$this->get_rows($query,$events,$readonlys);
|
|
|
|
foreach($events as $key => $event)
|
2011-04-27 18:53:06 +02:00
|
|
|
{
|
2011-06-22 19:23:04 +02:00
|
|
|
if (!in_array($event['id'],$checked) && !in_array($event['id'].':'.$event['recur_date'], $checked)) unset($events[$key]);
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
2011-06-22 19:23:04 +02:00
|
|
|
$checked = array_values($events); // Clear keys
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Actions where one action is done to the group
|
2011-04-27 18:53:06 +02:00
|
|
|
switch($action)
|
2010-04-05 20:28:41 +02:00
|
|
|
{
|
|
|
|
case 'ical':
|
2015-06-19 20:35:57 +02:00
|
|
|
// compile list of unique cal_id's, as iCal should contain whole series, not recurrences
|
|
|
|
// calendar_ical->exportVCal needs to read events again, to get them in server-time
|
|
|
|
$ids = array();
|
|
|
|
foreach($checked as $id)
|
|
|
|
{
|
|
|
|
if (is_array($id)) $id = $id['id'];
|
|
|
|
// get rid of recurrences, doublicate series and calendar-integration events
|
|
|
|
if (($id = (int)$id))
|
|
|
|
{
|
|
|
|
$ids[$id] = $id;
|
|
|
|
}
|
|
|
|
}
|
2010-04-05 20:28:41 +02:00
|
|
|
$boical = new calendar_ical();
|
2015-06-19 20:35:57 +02:00
|
|
|
$ical =& $boical->exportVCal($ids, '2.0', 'PUBLISH');
|
2016-05-01 19:47:59 +02:00
|
|
|
Api\Header\Content::type('event.ics', 'text/calendar', bytes($ical));
|
2011-04-27 18:53:06 +02:00
|
|
|
echo $ical;
|
2016-05-01 19:47:59 +02:00
|
|
|
exit();
|
2011-06-14 12:48:15 +02:00
|
|
|
|
2011-02-09 16:58:06 +01:00
|
|
|
case 'document':
|
2011-06-14 12:48:15 +02:00
|
|
|
if (!$settings) $settings = $GLOBALS['egw_info']['user']['preferences']['calendar']['default_document'];
|
|
|
|
$document_merge = new calendar_merge();
|
2012-01-11 23:38:33 +01:00
|
|
|
$msg = $document_merge->download($settings, $checked, '', $GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir']);
|
2011-02-09 16:58:06 +01:00
|
|
|
$failed = count($checked);
|
2015-10-09 21:48:28 +02:00
|
|
|
error_log($msg);
|
2011-04-27 18:53:06 +02:00
|
|
|
return false;
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Actions where the action is applied to each entry
|
2011-04-27 18:53:06 +02:00
|
|
|
if(strpos($action, 'timesheet') !== false)
|
|
|
|
{
|
2010-04-06 21:01:17 +02:00
|
|
|
$timesheet_bo = new timesheet_bo();
|
|
|
|
}
|
2013-01-15 21:06:52 +01:00
|
|
|
foreach($checked as &$id)
|
2010-04-05 20:28:41 +02:00
|
|
|
{
|
2011-05-30 19:12:29 +02:00
|
|
|
$recur_date = $app = $app_id = null;
|
2012-10-22 21:44:04 +02:00
|
|
|
if(is_array($id) && $id['id'])
|
|
|
|
{
|
|
|
|
$id = $id['id'];
|
|
|
|
}
|
2016-05-01 19:47:59 +02:00
|
|
|
$matches = null;
|
2011-05-30 19:12:29 +02:00
|
|
|
if(!(int)$id && preg_match('/^([a-z_-]+)([0-9]+)$/i',$id,$matches))
|
2010-04-26 23:41:07 +02:00
|
|
|
{
|
|
|
|
$app = $matches[1];
|
|
|
|
$app_id = $matches[2];
|
2011-05-30 19:12:29 +02:00
|
|
|
$id = null;
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-30 19:12:29 +02:00
|
|
|
list($id,$recur_date) = explode(':',$id);
|
2010-04-26 23:41:07 +02:00
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
switch($action)
|
2010-04-05 20:28:41 +02:00
|
|
|
{
|
|
|
|
case 'delete':
|
|
|
|
$action_msg = lang('deleted');
|
2013-01-09 22:38:18 +01:00
|
|
|
if($settings == 'series')
|
|
|
|
{
|
|
|
|
// Delete the whole thing
|
|
|
|
$recur_date = 0;
|
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
if ($id && $this->bo->delete($id, $recur_date,false,$skip_notification))
|
2010-04-05 20:28:41 +02:00
|
|
|
{
|
2011-04-27 18:53:06 +02:00
|
|
|
$success++;
|
2013-01-15 21:06:52 +01:00
|
|
|
if(!$recur_date && $settings == 'series')
|
|
|
|
{
|
|
|
|
// If there are multiple events in a series selected, the next one could purge
|
|
|
|
foreach($checked as $key => $c_id)
|
|
|
|
{
|
|
|
|
list($c_id,$recur_date) = explode(':',$c_id);
|
|
|
|
if($c_id == $id)
|
|
|
|
{
|
|
|
|
unset($checked[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-17 22:32:46 +01:00
|
|
|
|
2016-05-01 19:47:59 +02:00
|
|
|
if(Api\Json\Response::isJSONResponse())
|
2015-11-17 22:32:46 +01:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
Api\Json\Response::get()->call('egw.refresh','','calendar',$id,'delete');
|
2015-11-17 22:32:46 +01:00
|
|
|
}
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-09 10:44:28 +01:00
|
|
|
$failed++;
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
|
|
|
break;
|
2010-08-24 18:59:13 +02:00
|
|
|
case 'undelete':
|
|
|
|
$action_msg = lang('recovered');
|
2013-01-15 21:06:52 +01:00
|
|
|
if($settings == 'series')
|
|
|
|
{
|
|
|
|
// unDelete the whole thing
|
|
|
|
$recur_date = 0;
|
|
|
|
}
|
2016-05-01 19:47:59 +02:00
|
|
|
if ($id && ($event = $this->bo->read($id, $recur_date)) && $this->bo->check_perms(Acl::EDIT,$id) &&
|
2012-11-14 17:25:21 +01:00
|
|
|
is_array($event) && $event['deleted'])
|
2010-08-24 18:59:13 +02:00
|
|
|
{
|
2012-11-14 17:25:21 +01:00
|
|
|
$event['deleted'] = null;
|
|
|
|
if($this->bo->save($event))
|
2012-10-31 23:48:12 +01:00
|
|
|
{
|
2012-11-14 17:25:21 +01:00
|
|
|
$success++;
|
2015-11-17 22:32:46 +01:00
|
|
|
|
2016-05-01 19:47:59 +02:00
|
|
|
if(Api\Json\Response::isJSONResponse())
|
2015-11-17 22:32:46 +01:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
Api\Json\Response::get()->call('egw.dataStoreUID','calendar::'.$id,$this->to_client($this->bo->read($id,$recur_date)));
|
|
|
|
Api\Json\Response::get()->call('egw.refresh','','calendar',$id,'edit');
|
2015-11-17 22:32:46 +01:00
|
|
|
}
|
2012-11-14 17:25:21 +01:00
|
|
|
break;
|
2010-08-24 18:59:13 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-09 10:44:28 +01:00
|
|
|
$failed++;
|
2010-08-24 18:59:13 +02:00
|
|
|
break;
|
2010-04-05 20:28:41 +02:00
|
|
|
case 'status':
|
2011-11-09 10:44:28 +01:00
|
|
|
$action_msg = lang('Status changed');
|
2011-04-27 18:53:06 +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']];
|
2016-05-01 19:47:59 +02:00
|
|
|
$quantity = $role = null;
|
2010-04-26 23:41:07 +02:00
|
|
|
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-11-09 10:44:28 +01:00
|
|
|
if ($this->bo->set_status($event,$GLOBALS['egw_info']['user']['account_id'],$new_status,$recur_date,
|
2011-03-09 18:42:52 +01:00
|
|
|
false,true,$skip_notification))
|
2010-04-26 23:41:07 +02:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
if(Api\Json\Response::isJSONResponse())
|
2015-11-17 22:32:46 +01:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
Api\Json\Response::get()->call('egw.dataStoreUID','calendar::'.$id,$this->to_client($this->bo->read($id,$recur_date)));
|
2015-11-17 22:32:46 +01:00
|
|
|
}
|
2010-04-26 23:41:07 +02:00
|
|
|
$success++;
|
2011-11-09 10:44:28 +01:00
|
|
|
//$msg = lang('Status changed');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$failed++;
|
2010-04-26 23:41:07 +02:00
|
|
|
}
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-09 10:44:28 +01:00
|
|
|
$failed++;
|
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)
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$query = Api\Cache::getSession('calendar', 'calendar_list');
|
2010-04-26 23:41:07 +02:00
|
|
|
$query['query'] = $app_id;
|
|
|
|
$query['search'] = $app_id;
|
|
|
|
$result = $this->bo->search($query);
|
|
|
|
$event = $result[$app.$app_id];
|
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
if(!$event)
|
2010-04-26 23:41:07 +02:00
|
|
|
{
|
2011-11-09 10:44:28 +01:00
|
|
|
$failed++;
|
2010-04-26 23:41:07 +02:00
|
|
|
continue;
|
|
|
|
}
|
2010-04-06 21:01:17 +02:00
|
|
|
$timesheet = array(
|
|
|
|
'ts_title' => $event['title'],
|
2011-05-30 19:12:29 +02:00
|
|
|
'ts_description' => $event['description'],
|
2010-04-06 21:01:17 +02:00
|
|
|
'ts_start' => $event['start'],
|
2011-05-30 19:12:29 +02:00
|
|
|
'ts_duration' => ($event['end'] - $event['start']) / 60,
|
|
|
|
'ts_quantity' => ($event['end'] - $event['start']) / 3600,
|
2010-04-06 21:01:17 +02:00
|
|
|
'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();
|
2011-04-27 18:53:06 +02:00
|
|
|
foreach($categories as $cat_id)
|
2010-04-21 21:02:55 +02:00
|
|
|
{
|
|
|
|
if($GLOBALS['egw']->categories->is_global($cat_id))
|
|
|
|
{
|
|
|
|
$global_categories[] = $cat_id;
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
if(count($global_categories))
|
2010-04-21 21:02:55 +02:00
|
|
|
{
|
|
|
|
$timesheet['cat_id'] = implode(',', $global_categories);
|
|
|
|
}
|
2010-04-06 21:01:17 +02:00
|
|
|
$timesheet_bo->data = array();
|
|
|
|
$err = $timesheet_bo->save($timesheet);
|
2013-08-22 14:38:18 +02:00
|
|
|
|
|
|
|
//get the project manager linked to the calnedar entry
|
2016-05-01 19:47:59 +02:00
|
|
|
$calApp_links = Link::get_links('calendar', $event['id']);
|
2013-08-22 14:38:18 +02:00
|
|
|
foreach ($calApp_links as $l_app)
|
|
|
|
{
|
|
|
|
if ($l_app['app'] == 'projectmanager')
|
|
|
|
{
|
|
|
|
$prj_links = $l_app;
|
|
|
|
//Links timesheet to projectmanager
|
2016-05-01 19:47:59 +02:00
|
|
|
Link::link('timesheet', $timesheet_bo->data['ts_id'], 'projectmanager', $prj_links['id']);
|
2013-08-22 14:38:18 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 18:53:06 +02:00
|
|
|
if(!$err)
|
|
|
|
{
|
2010-04-06 21:01:17 +02:00
|
|
|
$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;
|
2016-05-01 19:47:59 +02:00
|
|
|
Link::link($app ? $app : 'calendar', $link_id, 'timesheet', $timesheet_bo->data['ts_id']);
|
2010-04-22 23:41:35 +02:00
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
2010-04-06 21:01:17 +02:00
|
|
|
else
|
|
|
|
{
|
2011-11-09 10:44:28 +01:00
|
|
|
$failed++;
|
2010-04-06 21:01:17 +02:00
|
|
|
}
|
|
|
|
$msg = lang('Timesheet entries created for ');
|
|
|
|
break;
|
2010-04-05 20:28:41 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-09 10:44:28 +01:00
|
|
|
//error_log(__METHOD__."('$action', ".array2string($checked).', '.array2string($use_all).") sucess=$success, failed=$failed, action_msg='$action_msg', msg=".array2string($msg).' returning '.array2string(!$failed));
|
|
|
|
return !$failed;
|
2010-04-05 20:28:41 +02: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
|
|
|
|
*/
|
2011-04-27 18:53:06 +02:00
|
|
|
protected function get_merge_range($nm)
|
2011-02-10 20:19:52 +01:00
|
|
|
{
|
|
|
|
$checked = array();
|
2011-04-27 18:53:06 +02:00
|
|
|
if($nm['filter'] == 'fixed')
|
2011-02-10 20:19:52 +01:00
|
|
|
{
|
|
|
|
$checked['start'] = $nm['startdate'];
|
|
|
|
$last = $this->bo->date2array($nm['enddate']);
|
|
|
|
$last['hour'] = '23'; $last['minute'] = $last['sec'] = '59';
|
|
|
|
$checked['end'] = $this->bo->date2ts($last);
|
2011-04-27 18:53:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch($nm['filter'])
|
|
|
|
{
|
2011-02-10 20:19:52 +01:00
|
|
|
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;
|
2011-06-20 20:21:29 +02:00
|
|
|
default:
|
|
|
|
$date = date_create_from_format('Ymd',$this->date);
|
|
|
|
$checked['start']= $date->format('U');
|
2011-02-10 20:19:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $checked;
|
|
|
|
}
|
|
|
|
|
2011-04-27 18:53:06 +02:00
|
|
|
/**
|
|
|
|
* Get actions / context menu items
|
|
|
|
*
|
|
|
|
* @return array see nextmatch_widget::get_actions()
|
|
|
|
*/
|
2014-11-27 22:21:47 +01:00
|
|
|
public function get_actions()
|
2011-04-27 18:53:06 +02:00
|
|
|
{
|
|
|
|
$actions = array(
|
2014-02-25 00:34:31 +01:00
|
|
|
'add' => array(
|
|
|
|
'caption' => 'Add',
|
2016-03-09 13:31:55 +01:00
|
|
|
'egw_open' => 'add-calendar',
|
|
|
|
'hideOnMobile' => true
|
2014-02-25 00:34:31 +01:00
|
|
|
),
|
2011-04-27 18:53:06 +02:00
|
|
|
'open' => array(
|
|
|
|
'caption' => 'Open',
|
|
|
|
'default' => true,
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'url' => 'menuaction=calendar.calendar_uiforms.edit&cal_id=$id',
|
2016-05-01 19:47:59 +02:00
|
|
|
'popup' => Link::get_registry('calendar', 'view_popup'),
|
2011-04-27 18:53:06 +02:00
|
|
|
'group' => $group=1,
|
2013-10-31 15:51:19 +01:00
|
|
|
'onExecute' => 'javaScript:app.calendar.cal_open',
|
2011-04-27 18:53:06 +02:00
|
|
|
'disableClass' => 'rowNoView',
|
|
|
|
),
|
2012-10-16 00:37:24 +02:00
|
|
|
'copy' => array(
|
|
|
|
'caption' => 'Copy',
|
|
|
|
'group' => $group,
|
|
|
|
'disableClass' => 'rowNoView',
|
|
|
|
'url' => 'menuaction=calendar.calendar_uiforms.edit&cal_id=$id&action=copy',
|
2016-05-01 19:47:59 +02:00
|
|
|
'popup' => Link::get_registry('calendar', 'view_popup'),
|
2012-10-16 00:37:24 +02:00
|
|
|
'allowOnMultiple' => false,
|
|
|
|
),
|
2011-04-27 18:53:06 +02:00
|
|
|
'select_all' => array(
|
|
|
|
'caption' => 'Whole query',
|
|
|
|
'checkbox' => true,
|
|
|
|
'hint' => 'Apply the action on the whole query, NOT only the shown events',
|
|
|
|
'group' => ++$group,
|
|
|
|
),
|
|
|
|
'no_notifications' => array(
|
|
|
|
'caption' => 'Do not notify',
|
|
|
|
'checkbox' => true,
|
|
|
|
'hint' => 'Do not notify of these changes',
|
|
|
|
'group' => $group,
|
|
|
|
),
|
|
|
|
);
|
2012-05-15 15:23:11 +02:00
|
|
|
$status = array_map('lang',$this->bo->verbose_status);
|
2011-04-27 18:53:06 +02:00
|
|
|
unset($status['G']);
|
|
|
|
$actions['status'] = array(
|
|
|
|
'caption' => 'Change your status',
|
|
|
|
'icon' => 'check',
|
|
|
|
'prefix' => 'status-',
|
2012-05-16 11:22:52 +02:00
|
|
|
'children' => $status,
|
2011-04-27 18:53:06 +02:00
|
|
|
'group' => ++$group,
|
|
|
|
);
|
|
|
|
++$group; // integration with other apps: infolog, calendar, filemanager
|
|
|
|
if ($GLOBALS['egw_info']['user']['apps']['filemanager'])
|
|
|
|
{
|
|
|
|
$actions['filemanager'] = array(
|
|
|
|
'icon' => 'filemanager/navbar',
|
|
|
|
'caption' => 'Filemanager',
|
2014-01-16 18:27:32 +01:00
|
|
|
'url' => 'menuaction=filemanager.filemanager_ui.index&path=/apps/calendar/$id&ajax=true',
|
2011-04-27 18:53:06 +02:00
|
|
|
'group' => $group,
|
|
|
|
'allowOnMultiple' => false,
|
2013-10-31 15:51:19 +01:00
|
|
|
'onExecute' => 'javaScript:app.calendar.cal_fix_app_id',
|
2011-04-27 18:53:06 +02:00
|
|
|
'disableClass' => 'rowNoView',
|
|
|
|
);
|
|
|
|
}
|
2013-05-10 12:54:36 +02:00
|
|
|
if ($GLOBALS['egw_info']['user']['apps']['infolog'])
|
|
|
|
{
|
|
|
|
$actions['infolog_app'] = array(
|
|
|
|
'caption' => 'InfoLog',
|
|
|
|
'icon' => 'infolog/navbar',
|
|
|
|
'group' => $group,
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'url' => 'menuaction=infolog.infolog_ui.edit&type=task&action=calendar&action_id=$id',
|
2016-05-01 19:47:59 +02:00
|
|
|
'popup' => Link::get_registry('infolog', 'add_popup'),
|
2013-05-10 12:54:36 +02:00
|
|
|
);
|
|
|
|
}
|
2011-04-27 18:53:06 +02:00
|
|
|
if ($GLOBALS['egw_info']['user']['apps']['timesheet'])
|
|
|
|
{
|
|
|
|
$actions['timesheet'] = array( // interactive add for a single event
|
|
|
|
'icon' => 'timesheet/navbar',
|
|
|
|
'caption' => 'Timesheet',
|
|
|
|
'url' => 'menuaction=timesheet.timesheet_ui.edit&link_app[]=$app&link_id[]=$id',
|
|
|
|
'group' => $group,
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'hideOnDisabled' => true, // show only one timesheet action in context menu
|
2013-10-31 15:51:19 +01:00
|
|
|
'onExecute' => 'javaScript:app.calendar.cal_fix_app_id',
|
2016-05-01 19:47:59 +02:00
|
|
|
'popup' => Link::get_registry('timesheet', 'add_popup'),
|
2011-04-27 18:53:06 +02:00
|
|
|
);
|
|
|
|
$actions['timesheet-add'] = array( // automatic add for multiple events
|
|
|
|
'icon' => 'timesheet/navbar',
|
|
|
|
'caption' => 'Timesheet',
|
|
|
|
'group' => $group,
|
|
|
|
'allowOnMultiple' => 'only',
|
|
|
|
'hideOnDisabled' => true, // show only one timesheet action in context menu
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$actions['ical'] = array(
|
2014-02-20 12:07:12 +01:00
|
|
|
'icon' => 'ical',
|
2013-10-04 14:48:11 +02:00
|
|
|
'caption' => 'Export iCal',
|
2011-04-27 18:53:06 +02:00
|
|
|
'group' => ++$group,
|
|
|
|
'hint' => 'Download this event as iCal',
|
|
|
|
'disableClass' => 'rowNoView',
|
2013-10-04 14:48:11 +02:00
|
|
|
'postSubmit' => true, // download needs post submit (not Ajax) to work
|
2011-04-27 18:53:06 +02:00
|
|
|
);
|
2011-09-16 15:03:46 +02:00
|
|
|
$actions['documents'] = calendar_merge::document_action(
|
2011-04-27 18:53:06 +02:00
|
|
|
$this->bo->cal_prefs['document_dir'], ++$group, 'Insert in document', 'document_',
|
2016-05-01 19:47:59 +02:00
|
|
|
$this->bo->cal_prefs['default_document'],Api\Storage\Merge::getExportLimit('calendar')
|
2011-04-27 18:53:06 +02:00
|
|
|
);
|
|
|
|
++$group;
|
|
|
|
$actions['delete'] = array(
|
|
|
|
'caption' => 'Delete',
|
2013-10-31 15:51:19 +01:00
|
|
|
'onExecute' => 'javaScript:app.calendar.cal_delete',
|
2011-04-27 18:53:06 +02:00
|
|
|
'group' => $group,
|
|
|
|
'disableClass' => 'rowNoDelete',
|
|
|
|
);
|
|
|
|
// Add in deleted for admins
|
|
|
|
if($GLOBALS['egw_info']['server']['calendar_delete_history'])
|
|
|
|
{
|
|
|
|
$actions['undelete'] = array(
|
|
|
|
'caption' => 'Un-delete',
|
2013-10-31 15:51:19 +01:00
|
|
|
'onExecute' => 'javaScript:app.calendar.cal_delete',
|
2012-12-31 23:05:14 +01:00
|
|
|
'icon' => 'revert',
|
2011-04-27 18:53:06 +02:00
|
|
|
'hint' => 'Recover this event',
|
|
|
|
'group' => $group,
|
|
|
|
'enableClass' => 'rowDeleted',
|
|
|
|
'hideOnDisabled' => true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//_debug_array($actions);
|
|
|
|
return $actions;
|
|
|
|
}
|
2005-11-09 00:15:14 +01:00
|
|
|
}
|