*
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
/**
* shared base-class of all calendar UserInterfaces
*
* It manages eg. the state of the controls in the UI and generated the calendar navigation (sidebox-menu)
*
* @package calendar
* @author RalfBecker@outdoor-training.de
* @license GPL
*/
class uical
{
/**
* @var $debug mixed integer level or string function-name
*/
var $debug=False;
/**
* @var $bo class bocal
*/
var $bo;
/**
* Constructor
*/
function uical()
{
foreach(array(
'bo' => 'calendar.bocal',
'jscal' => 'phpgwapi.jscalendar', // for the sidebox-menu
'html' => 'phpgwapi.html',
'datetime' => 'phpgwapi.datetime',
'cats' => 'phpgwapi.categories',
'accountsel' => 'phpgwapi.uiaccountsel',
) as $my => $app_class)
{
list(,$class) = explode('.',$app_class);
if (!is_object($GLOBALS['phpgw']->$class))
{
$GLOBALS['phpgw']->$class = CreateObject($app_class);
}
$this->$my = &$GLOBALS['phpgw']->$class;
}
$this->common_prefs = &$GLOBALS['phpgw_info']['user']['preferences']['common'];
$this->cal_prefs = &$GLOBALS['phpgw_info']['user']['preferences']['calendar'];
$this->wd_start = 60*$this->cal_prefs['workdaystarts'];
$this->wd_end = 60*$this->cal_prefs['workdayends'];
$this->interval_m = $this->cal_prefs['interval'];
$this->user = $GLOBALS['phpgw_info']['user']['account_id'];
$this->manage_states();
$GLOBALS['uical'] = &$this; // make us available for ExecMethod, else it creates a new instance
// calendar does not work with hidden sidebox atm.
unset($GLOBALS['phpgw_info']['user']['preferences']['common']['auto_hide_sidebox']);
}
/**
* Manages the states of certain controls in the UI: date shown, category selected, ...
*
* The state of all these controls is updated if they are set in $_REQUEST or $set_states and saved in the session.
* The following states are used:
* - date or year, month, day: the actual date of the period displayed
* - cat_id: the selected category
* - owner: the owner of the displayed calendar
* - save_owner: the overriden owner of the planner
* - filter: the used filter: no filter / all or only privat
* - num_month: number of month shown in the planner
* - sortby: category or user of planner
* - return_to: the view the dialogs should return to
* @param set_states array to manualy set / change one of the states, default NULL = use $_REQUEST
*/
function manage_states($set_states=NULL)
{
$states = $states_session = $GLOBALS['phpgw']->session->appsession('session_data','calendar');
if (is_null($set_states))
{
$set_states = $_REQUEST;
}
if (!$states['date'] && $states['year'] && $states['month'] && $states['day'])
{
$states['date'] = $this->bo->date2string($states);
}
foreach(array(
'date' => $this->bo->date2string($this->bo->now_su),
'cat_id' => 0,
'filter' => 'all',
'owner' => $this->user,
'num_month' => 1,
'save_owner' => 0,
'sortby' => 'category',
'multiple' => 0,
) as $state => $default)
{
if (isset($set_states[$state]))
{
$states[$state] = $set_states[$state];
}
elseif (!is_array($states) || !isset($states[$state]))
{
$states[$state] = $default;
}
if ($state == 'date')
{
$date_arr = $this->bo->date2array($states['date']);
foreach(array('year','month','day') as $name)
{
$this->$name = $states[$name] = $date_arr[$name];
}
}
$this->$state = $states[$state];
}
// set the actual view as return_to
list($app,$class,$func) = explode('.',$_GET['menuaction']);
if ($class == 'uiviews' && $func)
{
$states['return_to'] = $_GET['menuaction'];
}
// deal with group-owners
if (substr($this->owner,0,2) == 'g_' || $GLOBALS['phpgw']->accounts->get_type($this->owner) == 'g')
{
$this->set_owner_to_group($this->owner);
$states['owner'] = $this->owner;
}
$states['multiple'] = $this->multiple = $_GET['multiple'] || count(explode(',',$this->owner)) > 1;
if ($this->debug > 0 || $this->debug == 'menage_states') $this->bo->debug_message('uical::manage_states(%1) session was %2, states now %3, is_group=%4, g_owner=%5',True,$set_states,$states_session,$states,$this->is_group,$this->g_owner);
// save the states in the session
$GLOBALS['phpgw']->session->appsession('session_data','calendar',$states);
}
/**
* Sets a group as owner (of the events to show)
*
* It set $this->is_group and $this->g_owner - array with user-id's of the group-members who gave read-grants
* @param group-id or 'g_'+group-id
*/
function set_owner_to_group($owner)
{
$this->owner = (int) (substr($owner,0,2) == 'g_' ? substr($owner,2) : $owner);
$this->is_group = True;
$this->g_owner = Array();
$members = $GLOBALS['phpgw']->accounts->member($this->owner);
if (is_array($members))
{
foreach($members as $user)
{
// use only members which gave the user a read-grant
if ($this->bo->check_perms(PHPGW_ACL_READ,0,$user['account_id']))
{
$this->g_owner[] = $user['account_id'];
}
}
}
if ($this->debug > 2 || $this->debug == 'set_owner_to_group') $this->bo->debug_message('uical::set_owner_to_group(%1): owner=%2, g_owner=%3',True,$owner,$this->owner,$this->g_owner);
}
/**
* gets the icons displayed for a given event
*
* @param $event array
* @return array of 'img' / 'title' pairs
*/
function event_icons($event)
{
$is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
$viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
if (!$is_private)
{
if($event['priority'] == 3)
{
$icons[] = $this->html->image('calendar','high',lang('high priority'));
}
if($event['recur_type'] == MCAL_RECUR_NONE)
{
//$icons[] = $this->html->image('calendar','circle',lang('single event'));
}
else
{
$icons[] = $this->html->image('calendar','recur',lang('recurring event'));
}
$icons[] = $this->html->image('calendar',count($event['participants']) > 1 ? 'multi_3' : 'single',
implode(",\n",$this->bo->participants($event['participants'])));
}
if($event['public'] == 0)
{
$icons[] = $this->html->image('calendar','private',lang('private'));
}
if(isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
{
$icons[] = $this->html->image('calendar','alarm',lang('alarm'));
}
return $icons;
}
/**
* Create a select-box item in the sidebox-menu
* @privat used only by sidebox_menu !
*/
function _select_box($title,$name,$options,$baseurl='')
{
if ($baseurl) // we append the value to the baseurl
{
$baseurl .= strstr($baseurl,'?') === False ? '?' : '&';
$onchange="location='$baseurl'+this.value;";
}
else // we add $name=value to the actual location
{
$onchange="location=location+(location.search.length ? '&' : '?')+'".$name."='+this.value;";
}
$select = ' \n";
return array(
'text' => $select,
'no_lang' => True,
'link' => False
);
}
/**
* creates the content for the sidebox-menu, called as hook
*/
function sidebox_menu()
{
$base_hidden_vars = $link_vars = array();
if (@$_POST['keywords'])
{
$base_hidden_vars['keywords'] = $_POST['keywords'];
}
$n = 0; // index for file-array
// Toolbar with the views
$views = '