2014-11-27 22:21:47 +01:00
|
|
|
<?php
|
2016-04-28 20:06:46 +02:00
|
|
|
/**
|
|
|
|
* Egroupware - Calendar - A portlet for displaying a list of entries
|
|
|
|
*
|
2014-11-27 22:21:47 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2016-04-28 20:06:46 +02:00
|
|
|
* @package calendar
|
2014-11-27 22:21:47 +01:00
|
|
|
* @subpackage home
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-28 20:06:46 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Framework;
|
|
|
|
use EGroupware\Api\Etemplate;
|
|
|
|
|
2014-11-27 22:21:47 +01:00
|
|
|
/**
|
2023-03-06 22:47:48 +01:00
|
|
|
* The list uses a nextmatch / favorite
|
|
|
|
* to display a list of entries, but other views do their own things
|
2014-11-27 22:21:47 +01:00
|
|
|
*/
|
|
|
|
class calendar_favorite_portlet extends home_favorite_portlet
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the portlet
|
|
|
|
* Calendar complicates things...
|
|
|
|
*/
|
|
|
|
public function __construct(Array &$context = array(), &$need_reload = false)
|
|
|
|
{
|
|
|
|
$context['appname'] = 'calendar';
|
2015-08-05 23:24:07 +02:00
|
|
|
// Reload is NULL when changing properties via AJAX
|
|
|
|
$reload = !is_null($need_reload);
|
2014-11-27 22:21:47 +01:00
|
|
|
|
|
|
|
// Let parent handle the basic stuff
|
|
|
|
parent::__construct($context,$need_reload);
|
|
|
|
|
|
|
|
if($this->favorite['state']['view'] == 'listview')
|
|
|
|
{
|
|
|
|
$this->context['template'] = 'calendar.list.rows';
|
|
|
|
$this->context['sel_options'] = array();
|
|
|
|
$this->nm_settings += array(
|
2014-12-03 01:20:57 +01:00
|
|
|
'csv_export' => True,
|
2014-11-27 22:21:47 +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
|
|
|
|
'filter' => 'after',
|
|
|
|
'row_id' => 'row_id', // set in get rows "$event[id]:$event[recur_date]"
|
|
|
|
'row_modified' => 'modified',
|
|
|
|
'get_rows' => 'calendar_favorite_portlet::get_rows',
|
|
|
|
// Use a different template so it can be accessed from client side
|
2014-12-03 01:20:57 +01:00
|
|
|
'template' => 'calendar.list.rows',
|
|
|
|
// Default to fewer columns
|
2015-01-12 20:59:25 +01:00
|
|
|
'default_cols' => 'cal_start_cal_end,cal_title'
|
2014-11-27 22:21:47 +01:00
|
|
|
);
|
|
|
|
}
|
2015-08-05 23:24:07 +02:00
|
|
|
|
|
|
|
// Checking against NULL allows us to skip the reload for resizing
|
|
|
|
$need_reload = $reload && $need_reload;
|
2014-11-27 22:21:47 +01:00
|
|
|
}
|
|
|
|
|
2016-04-28 20:06:46 +02:00
|
|
|
public function exec($id = null, Etemplate &$etemplate = null)
|
2014-11-27 22:21:47 +01:00
|
|
|
{
|
|
|
|
|
2016-02-23 22:29:13 +01:00
|
|
|
// Always load app's javascript, so most actions have a chance of working
|
2016-04-28 20:06:46 +02:00
|
|
|
Framework::includeJS('.','app',$this->context['appname']);
|
2016-02-23 22:29:13 +01:00
|
|
|
|
2014-11-27 22:21:47 +01:00
|
|
|
// Always load app's css
|
2016-04-28 20:06:46 +02:00
|
|
|
Framework::includeCSS('calendar', 'app-'.$GLOBALS['egw_info']['user']['preferences']['common']['theme']) ||
|
|
|
|
Framework::includeCSS('calendar','app');
|
|
|
|
|
2014-12-03 01:20:57 +01:00
|
|
|
if($this->favorite['state']['view'] == 'listview' || is_array($this->favorite) && !$this->favorite['state']['view'])
|
2014-11-27 22:21:47 +01:00
|
|
|
{
|
|
|
|
$ui = new calendar_uilist();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ui = new calendar_uiviews();
|
2015-05-04 17:26:18 +02:00
|
|
|
if ($this->favorite)
|
|
|
|
{
|
|
|
|
if($this->favorite['state']['start']) $ui->search_params['start'] = $this->favorite['state']['start'];
|
|
|
|
if($this->favorite['state']['cat_id']) $ui->search_params['cat_id'] = $this->favorite['state']['cat_id'];
|
|
|
|
// Owner can be 0 for current user
|
2016-01-27 18:35:25 +01:00
|
|
|
if(array_key_exists('owner',$this->favorite['state'])) $ui->search_params['users'] = $this->favorite['state']['owner'];
|
|
|
|
if($ui->search_params['users'] && !is_array($ui->search_params['users']))
|
|
|
|
{
|
|
|
|
$ui->search_params['users'] = explode(',',$ui->search_params['users']);
|
|
|
|
}
|
2015-05-04 17:26:18 +02:00
|
|
|
if($this->favorite['state']['filter']) $ui->search_params['filter'] = $this->favorite['state']['filter'];
|
|
|
|
if($this->favorite['state']['sortby']) $ui->search_params['sortby'] = $this->favorite['state']['sortby'];
|
2016-02-22 23:45:48 +01:00
|
|
|
$ui->search_params['weekend'] = $this->favorite['state']['weekend'];
|
2015-05-04 17:26:18 +02:00
|
|
|
}
|
2014-11-27 22:21:47 +01:00
|
|
|
$etemplate->read('home.legacy');
|
|
|
|
|
|
|
|
$etemplate->set_dom_id($id);
|
|
|
|
}
|
|
|
|
|
2014-12-03 01:20:57 +01:00
|
|
|
$content = array('legacy' => '');
|
2015-05-04 22:11:52 +02:00
|
|
|
|
2014-11-27 22:21:47 +01:00
|
|
|
switch($this->favorite['state']['view'])
|
|
|
|
{
|
|
|
|
case 'listview':
|
|
|
|
$this->context['sel_options']['filter'] = &$ui->date_filters;
|
|
|
|
$this->nm_settings['actions'] = $ui->get_actions($this->nm_settings['col_filter']['tid'], $this->nm_settings['org_view']);
|
|
|
|
// Early exit
|
|
|
|
return parent::exec($id, $etemplate);
|
|
|
|
|
|
|
|
case 'planner_user':
|
|
|
|
case 'planner_cat':
|
|
|
|
case 'planner':
|
2015-08-05 23:24:07 +02:00
|
|
|
$content = array();
|
|
|
|
$etemplate->read('calendar.planner');
|
|
|
|
$etemplate->set_dom_id($id);
|
2024-10-24 21:25:20 +02:00
|
|
|
$this->actions =& $etemplate->setElementAttribute('planner', 'actions');
|
2015-08-05 23:24:07 +02:00
|
|
|
// Don't notify the calendar app of date changes
|
|
|
|
$etemplate->setElementAttribute('planner','onchange',false);
|
2016-02-03 19:27:52 +01:00
|
|
|
$ui->planner_view = $this->favorite['state']['planner_view'];
|
2015-08-05 23:24:07 +02:00
|
|
|
$ui->planner(array(), $etemplate);
|
|
|
|
return;
|
2014-11-27 22:21:47 +01:00
|
|
|
case 'month':
|
|
|
|
case 'weekN':
|
2016-02-22 23:45:48 +01:00
|
|
|
$etemplate->read('calendar.view');
|
|
|
|
$etemplate->set_dom_id($id);
|
2024-10-24 21:25:20 +02:00
|
|
|
$this->actions =& $etemplate->setElementAttribute('view', 'actions');
|
2016-04-28 20:06:46 +02:00
|
|
|
|
2016-02-22 23:45:48 +01:00
|
|
|
$ui->month($this->favorite['state']['view'] == 'month' ?
|
|
|
|
0 :
|
|
|
|
(int)$ui->cal_prefs['multiple_weeks'],
|
|
|
|
$etemplate
|
|
|
|
);
|
|
|
|
return;
|
2014-11-27 22:21:47 +01:00
|
|
|
case 'week':
|
2015-07-15 18:29:10 +02:00
|
|
|
$etemplate->read('calendar.view');
|
|
|
|
$etemplate->set_dom_id($id);
|
2024-10-24 21:25:20 +02:00
|
|
|
$this->actions =& $etemplate->setElementAttribute('view', 'actions');
|
2015-08-05 23:24:07 +02:00
|
|
|
// Don't notify the calendar app of date changes
|
|
|
|
$etemplate->setElementAttribute('view[0]','onchange',false);
|
2015-05-25 16:57:35 +02:00
|
|
|
$ui->week(array(), $etemplate);
|
2015-07-15 18:29:10 +02:00
|
|
|
return;
|
2014-11-27 22:21:47 +01:00
|
|
|
case 'day':
|
|
|
|
case 'day4':
|
2015-08-05 23:24:07 +02:00
|
|
|
$etemplate->read('calendar.view');
|
|
|
|
$etemplate->set_dom_id($id);
|
|
|
|
$days = $this->favorite['state']['days'] ? $this->favorite['state']['days'] : (
|
|
|
|
$this->favorite['state']['view'] == 'day' ? 1 : 4
|
|
|
|
);
|
2024-10-24 21:25:20 +02:00
|
|
|
$this->actions =& $etemplate->setElementAttribute('view', 'actions');
|
2016-02-23 22:29:13 +01:00
|
|
|
$ui->week($days, $etemplate);
|
2015-08-05 23:24:07 +02:00
|
|
|
return;
|
2014-11-27 22:21:47 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 22:34:46 +01:00
|
|
|
unset($GLOBALS['egw_info']['flags']['app_header']);
|
2014-12-03 01:20:57 +01:00
|
|
|
// Force loading of CSS
|
2016-04-28 20:06:46 +02:00
|
|
|
Framework::include_css_js_response();
|
2014-12-09 18:55:00 +01:00
|
|
|
|
|
|
|
// Set this to calendar so app.js gets initialized
|
|
|
|
$old_app = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
$GLOBALS['egw_info']['flags']['currentapp'] = 'calendar';
|
|
|
|
|
2014-11-27 22:21:47 +01:00
|
|
|
$etemplate->exec(get_called_class() .'::process',$content);
|
2014-12-09 18:55:00 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['currentapp'] = $old_app;
|
2014-11-27 22:21:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override from calendar list to clear the app header
|
|
|
|
*
|
|
|
|
* @param type $query
|
|
|
|
* @param type $rows
|
|
|
|
* @param type $readonlys
|
|
|
|
* @return integer Total rows found
|
|
|
|
*/
|
|
|
|
public static function get_rows(&$query, &$rows, &$readonlys)
|
|
|
|
{
|
|
|
|
$ui = new calendar_uilist();
|
2014-12-03 01:20:57 +01:00
|
|
|
$old_owner = $ui->owner;
|
|
|
|
$ui->owner = $query['owner'];
|
2014-11-27 22:21:47 +01:00
|
|
|
$total = $ui->get_rows($query, $rows, $readonlys);
|
2014-12-03 01:20:57 +01:00
|
|
|
$ui->owner = $old_owner;
|
2014-11-27 22:21:47 +01:00
|
|
|
unset($GLOBALS['egw_info']['flags']['app_header']);
|
2015-01-12 20:59:25 +01:00
|
|
|
unset($query['selectcols']);
|
2014-11-27 22:21:47 +01:00
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Here we need to handle any incoming data. Setup is done in the constructor,
|
|
|
|
* output is handled by parent.
|
|
|
|
*
|
2016-04-28 20:06:46 +02:00
|
|
|
* @param $values =array()
|
2014-11-27 22:21:47 +01:00
|
|
|
*/
|
|
|
|
public static function process($values = array())
|
|
|
|
{
|
|
|
|
parent::process($values);
|
|
|
|
$ui = new calendar_uilist();
|
|
|
|
if (is_array($values) && !empty($values['nm']['action']))
|
|
|
|
{
|
|
|
|
if (!count($values['nm']['selected']) && !$values['nm']['select_all'])
|
|
|
|
{
|
2016-04-28 20:06:46 +02:00
|
|
|
Framework::message(lang('You need to select some entries first'));
|
2014-11-27 22:21:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-28 20:06:46 +02:00
|
|
|
$success = $failed = $action_msg = $msg = null;
|
2014-12-03 01:20:57 +01:00
|
|
|
if ($ui->action($values['nm']['action'],$values['nm']['selected'],$values['nm']['select_all'],
|
|
|
|
$success,$failed,$action_msg,'calendar_list',$msg, $values['nm']['checkboxes']['no_notifications']))
|
2014-11-27 22:21:47 +01:00
|
|
|
{
|
|
|
|
$msg .= lang('%1 event(s) %2',$success,$action_msg);
|
2016-04-28 20:06:46 +02:00
|
|
|
Api\Json\Response::get()->apply('egw.message',array($msg,'success'));
|
2014-11-27 22:21:47 +01:00
|
|
|
foreach($values['nm']['selected'] as &$id)
|
|
|
|
{
|
|
|
|
$id = 'calendar::'.$id;
|
|
|
|
}
|
|
|
|
// Directly request an update - this will get addressbook tab too
|
2016-04-28 20:06:46 +02:00
|
|
|
Api\Json\Response::get()->apply('egw.dataRefreshUIDs',array($values['nm']['selected']));
|
2014-11-27 22:21:47 +01:00
|
|
|
}
|
|
|
|
elseif(is_null($msg))
|
|
|
|
{
|
|
|
|
$msg .= lang('%1 entries %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed);
|
2016-04-28 20:06:46 +02:00
|
|
|
Api\Json\Response::get()->apply('egw.message',array($msg,'error'));
|
2014-11-27 22:21:47 +01:00
|
|
|
}
|
|
|
|
elseif($msg)
|
|
|
|
{
|
|
|
|
$msg .= "\n".lang('%1 entries %2, %3 failed.',$success,$action_msg,$failed);
|
2016-04-28 20:06:46 +02:00
|
|
|
Api\Json\Response::get()->apply('egw.message',array($msg,'error'));
|
2014-11-27 22:21:47 +01:00
|
|
|
}
|
|
|
|
unset($values['nm']['action']);
|
|
|
|
unset($values['nm']['select_all']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-28 20:06:46 +02:00
|
|
|
|
2015-05-04 22:11:52 +02:00
|
|
|
/**
|
|
|
|
* No filters default favorite causes problems with calendar's special state handling,
|
|
|
|
* so just remove it.
|
|
|
|
* @return type
|
|
|
|
*/
|
|
|
|
public function get_properties()
|
|
|
|
{
|
|
|
|
$properties = parent::get_properties();
|
|
|
|
foreach($properties as &$property)
|
|
|
|
{
|
|
|
|
if($property['name'] == 'favorite')
|
|
|
|
{
|
|
|
|
unset($property['select_options']['blank']);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $properties;
|
|
|
|
}
|
2015-08-05 23:24:07 +02:00
|
|
|
|
2023-03-06 22:47:48 +01:00
|
|
|
public function get_actions()
|
|
|
|
{
|
2015-08-05 23:24:07 +02:00
|
|
|
if($this->favorite['state']['view'] == 'listview' || !$this->actions)
|
|
|
|
{
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $this->actions;
|
|
|
|
}
|
|
|
|
}
|
2023-03-06 22:47:48 +01:00
|
|
|
|
|
|
|
public function get_type()
|
|
|
|
{
|
|
|
|
return 'et2-portlet-calendar';
|
|
|
|
}
|
2024-10-24 21:25:20 +02:00
|
|
|
}
|