Author: ralfbecker
New Revision: 55963
URL: http://svn.stylite.de/viewvc/egroupware?rev=55963&view=rev
Log:
move calendar to new api
Removed:
trunk/calendar/inc/gradient.php
trunk/calendar/inc/round_corners.php
trunk/calendar/setup/etemplates.inc.php
Modified:
trunk/calendar/egroupware.org/accept_holiday.php
trunk/calendar/freebusy.php
trunk/calendar/inc/class.boholiday.inc.php
trunk/calendar/inc/class.calendar_bo.inc.php
trunk/calendar/inc/class.calendar_boupdate.inc.php
trunk/calendar/inc/class.calendar_datasource.inc.php
trunk/calendar/inc/class.calendar_egw_record.inc.php
trunk/calendar/inc/class.calendar_export_csv.inc.php
trunk/calendar/inc/class.calendar_export_ical.inc.php
trunk/calendar/inc/class.calendar_groupdav.inc.php
trunk/calendar/inc/class.calendar_hooks.inc.php
trunk/calendar/inc/class.calendar_ical.inc.php
trunk/calendar/inc/class.calendar_import_csv.inc.php
trunk/calendar/inc/class.calendar_import_ical.inc.php
trunk/calendar/inc/class.calendar_merge.inc.php
trunk/calendar/inc/class.calendar_owner_etemplate_widget.inc.php
trunk/calendar/inc/class.calendar_so.inc.php
trunk/calendar/inc/class.calendar_timegrid_etemplate_widget.inc.php
trunk/calendar/inc/class.calendar_timezones.inc.php
trunk/calendar/inc/class.calendar_tracking.inc.php
trunk/calendar/inc/class.calendar_ui.inc.php
trunk/calendar/inc/class.calendar_uiforms.inc.php
trunk/calendar/inc/class.calendar_uilist.inc.php
trunk/calendar/inc/class.calendar_uiviews.inc.php
trunk/calendar/inc/class.calendar_wizard_export_csv.inc.php
trunk/calendar/inc/class.calendar_wizard_import_csv.inc.php
trunk/calendar/inc/class.calendar_zpush.inc.php
trunk/calendar/inc/class.soholiday.inc.php
trunk/calendar/inc/class.uiholiday.inc.php
trunk/calendar/setup/setup.inc.php
trunk/calendar/setup/tables_update.inc.php
trunk/calendar/sitemgr/class.module_calendar_list.inc.php
trunk/calendar/sitemgr/class.module_calendar_month.inc.php
trunk/calendar/sitemgr/class.module_calendar_planner.inc.php
— trunk/calendar/egroupware.org/accept_holiday.php (original)
+++ trunk/calendar/egroupware.org/accept_holiday.php Sun May 1 19:47:59 2016
@@ -8,6 +8,8 @@
+use EGroupware\Api;
die(‘This file is only used on http://www.egroupware.org/ and therefore disabled on local installations!’);
@@ -68,7 +70,7 @@
exit;
}
?>
-
+
eGroupWare.org: There is already a holiday-file for '<?php echo $_POST['locale']; ?>' !!!
— trunk/calendar/freebusy.php (original)
+++ trunk/calendar/freebusy.php Sun May 1 19:47:59 2016
@@ -9,6 +9,8 @@
-
@subpackage export
-
@version $Id$
*/
+use EGroupware\Api;
$GLOBALS[‘egw_info’] = array(
‘flags’ => array(
@@ -28,9 +30,9 @@
function fail_exit($msg)
{
echo "\n\n$msg\n<meta http-equiv=“content-type” content=“text/html; charset=”.
- $GLOBALS[‘egw’]->common->egw_exit();
if (!$loged_in)
@@ -107,6 +109,7 @@
}
else
{
- html::content_header(‘freebusy.ifb’,‘text/calendar’);
- Api\Header\Content::type(‘freebusy.ifb’,‘text/calendar’);
}
-echo ExecMethod2(‘calendar.calendar_ical.freebusy’,$user,$_GET[‘end’]);
+$ical = new calendar_ical();
+echo $ical->freebusy($user, $_GET[‘end’]);
— trunk/calendar/inc/class.boholiday.inc.php (original)
+++ trunk/calendar/inc/class.boholiday.inc.php Sun May 1 19:47:59 2016
@@ -1,502 +1,507 @@
<?php
- /**************************************************************************\
- * eGroupWare - Holiday *
- * http://www.egroupware.org *
- * Written by Mark Peters *
- * -------------------------------------------- *
- * 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$ */
-
- /**
- * Business object for calendar holidays
- *
- * @package calendar
- * @author Mark Peters
- * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
- */
- class boholiday
- {
- var $public_functions = Array(
- 'add' => True,
- 'delete_holiday' => True,
- 'delete_locale' => True,
- 'accept_holiday' => True,
-
- 'read_entries' => True,
- 'read_entry' => True,
- 'add_entry' => True,
- 'update_entry' => True
+/**************************************************************************\
+* eGroupWare - Holiday *
+* http://www.egroupware.org *
+* Written by Mark Peters *
+* -------------------------------------------- *
+* 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. *
+\**************************************************************************/
+
+use EGroupware\Api;
+use EGroupware\Api\Framework;
+
+/* $Id$ */
+
+/**
+ * Business object for calendar holidays
+ *
+ * @package calendar
+ * @author Mark Peters
+ * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
+ */
+class boholiday
+{
+ var $public_functions = Array(
+ 'add' => True,
+ 'delete_holiday' => True,
+ 'delete_locale' => True,
+ 'accept_holiday' => True,
+
+ 'read_entries' => True,
+ 'read_entry' => True,
+ 'add_entry' => True,
+ 'update_entry' => True
+ );
+
+ var $debug = false;
+ var $base_url = '/index.php';
+
+ var $ui;
+ var $so;
+ var $owner;
+ var $year;
+
+ var $id;
+ var $total;
+ var $start;
+ var $query;
+ var $sort;
+
+ var $locales = Array();
+ var $holidays;
+ var $cached_holidays;
+
+ function boholiday()
+ {
+ $this->so =& CreateObject('calendar.soholiday');
+
+ $this->start = (int)get_var('start',array('POST','GET'));
+ $this->query = get_var('query',array('POST','GET'));
+ $this->sort = get_var('sort',array('POST','GET'));
+ $this->order = get_var('order',array('POST','GET'));
+ $this->id = get_var('id',array('POST','GET'));
+ $this->year = get_var('year',array('POST','GET'),date('Y'));
+ $this->locale = get_var('locale',array('POST','GET'));
+ if ($this->locale)
+ {
+ $this->locales[] = $this->locale;
+ }
+
+ if($this->debug)
+ {
+ echo '<-- Locale = '.$this->locales[0].' -->'."\n";
+ }
+
+ $this->total = $this->so->holiday_total($this->locales[0],$this->query,$this->year);
+ }
+
+ /* Begin Calendar functions */
+ function read_entry($id=0)
+ {
+ if($this->debug)
+ {
+ echo "BO : Reading Holiday ID : ".$id."
\n";
+ }
+
+ if(!$id)
+ {
+ if(!$this->id)
+ {
+ return Array();
+ }
+ else
+ {
+ $id = $this->id;
+ }
+ }
+
+ return $this->so->read_holiday($id);
+ }
+
+ function delete_holiday($id=0)
+ {
+ if(!$id)
+ {
+ if($this->id)
+ {
+ $id = $this->id;
+ }
+ }
+
+ $this->ui =& CreateObject('calendar.uiholiday');
+ if($id)
+ {
+ $this->so->delete_holiday($id);
+ $this->ui->edit_locale();
+ }
+ else
+ {
+ $this->ui->admin();
+ }
+ }
+
+ function delete_locale($locale='')
+ {
+ if(!$locale)
+ {
+ if($this->locales[0])
+ {
+ $locale = $this->locales[0];
+ }
+ }
+
+ if($locale)
+ {
+ $this->so->delete_locale($locale);
+ }
+ $this->ui =& CreateObject('calendar.uiholiday');
+ $this->ui->admin();
+ }
+
+ function accept_holiday()
+ {
+ $send_back_to = str_replace('submitlocale','holiday_admin',$_SERVER['HTTP_REFERER']);
+ if(!@$this->locales[0])
+ {
+ Header('Location: '.$send_back_to);
+ }
+
+ $send_back_to = str_replace('&locale='.$this->locales[0],'',$send_back_to);
+ $file = './holidays.'.$this->locales[0];
+ if(!file_exists($file) && count($_POST['name']))
+ {
+ $fp = fopen($file,'w');
+ fwrite($fp,"charset\t".Api\Translation::charset()."\n");
+
+ $holidays = array();
+ foreach($_POST['name'] as $i => $name)
+ {
+ $holiday = array(
+ 'locale' => $_POST['locale'],
+ 'name' => str_replace('\\','',$name),
+ 'day' => $_POST['day'][$i],
+ 'month' => $_POST['month'][$i],
+ 'occurence' => $_POST['occurence'][$i],
+ 'dow' => $_POST['dow'][$i],
+ 'observance' => $_POST['observance'][$i],
+ );
+ }
+ // sort holidays by year / occurence:
+ usort($holidays,'_holiday_cmp');
+
+ $last_year = -1;
+ foreach($holidays as $holiday)
+ {
+ $year = $holiday['occurence'] <= 0 ? 0 : $holiday['occurence'];
+ if ($year != $last_year)
+ {
+ echo "\n".($year ? $year : 'regular (year=0)').":\n";
+ $last_year = $year;
+ }
+ fwrite($fp,"$holiday[locale]\t$holiday[name]\t$holiday[day]\t$holiday[month]\t$holiday[occurence]\t$holiday[dow]\t$holiday[observance_rule]\n");
+ }
+ fclose($fp);
+ }
+ Header('Location: '.$send_back_to);
+ }
+
+ function get_holiday_list($locale='', $sort='', $order='', $query='', $total='', $year=0)
+ {
+ $locale = ($locale?$locale:$this->locales[0]);
+ $sort = ($sort?$sort:$this->sort);
+ $order = ($order?$order:$this->order);
+ $query = ($query?$query:$this->query);
+ $year = ($$year?$$year:$this->year);
+ return $this->so->read_holidays($locale,$query,$order,$year);
+ }
+
+ function get_locale_list($sort='', $order='', $query='')
+ {
+ $sort = ($sort?$sort:$this->sort);
+ $order = ($order?$order:$this->order);
+ $query = ($query?$query:$this->query);
+ return $this->so->get_locale_list($sort,$order,$query);
+ }
+
+ function prepare_read_holidays($year=0,$owner=0)
+ {
+ $this->year = (isset($year) && $year > 0?$year: Api\DateTime::to(time() - $GLOBALS['egw']->datetime->tz_offset,'Y'));
+ $this->owner = ($owner?$owner:$GLOBALS['egw_info']['user']['account_id']);
+
+ if($this->debug)
+ {
+ echo 'Setting Year to : '.$this->year.'
'."\n";
+ }
+
+ if(@$GLOBALS['egw_info']['user']['preferences']['common']['country'])
+ {
+ $this->locales[] = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
+ }
+ elseif(@$GLOBALS['egw_info']['user']['preferences']['calendar']['locale'])
+ {
+ $this->locales[] = $GLOBALS['egw_info']['user']['preferences']['calendar']['locale'];
+ }
+ else
+ {
+ $this->locales[] = 'US';
+ }
+
+ if($this->owner != $GLOBALS['egw_info']['user']['account_id'])
+ {
+ $owner_pref = new Api\Preferences($owner);
+ $owner_prefs = $owner_pref->read_repository();
+ if(@$owner_prefs['common']['country'])
+ {
+ $this->locales[] = $owner_prefs['common']['country'];
+ }
+ elseif(@$owner_prefs['calendar']['locale'])
+ {
+ $this->locales[] = $owner_prefs['calendar']['locale'];
+ }
+ unset($owner_pref);
+ }
+
+ if($GLOBALS['egw_info']['server']['auto_load_holidays'] == True && $this->locales)
+ {
+ foreach($this->locales as $local)
+ {
+ $this->auto_load_holidays($local, $year);
+ }
+ }
+ }
+
+ function auto_load_holidays($locale, $year=0)
+ {
+ //error_log(__METHOD__."('$locale', $year)");
+ if (!Api\Cache::getInstance(__CLASS__, $locale.'-'.$year) && // check if autoload has been tried for this locale and year
+ (!($total_year = $this->so->holiday_total($locale, '', $year)) ||
+ // automatic try load new holidays, if there are no irregular ones for queried year
+ $total_year == $this->so->holiday_total($locale, '', 1901)))
+ {
+ //error_log(__METHOD__."('$locale', $year) attemption autoload ...");
+ Api\Cache::setInstance(__CLASS__, $locale.'-'.$year, true, 864000); // do NOT try again for 10 days
+ @set_time_limit(0);
+
+ /* get the file that contains the calendar events for your locale */
+ /* "http://www.egroupware.org/cal/holidays.US.csv"; */
+ if(isset($GLOBALS['egw_info']['server']['holidays_url_path']) && $GLOBALS['egw_info']['server']['holidays_url_path'] != 'localhost')
+ {
+ $load_from = $GLOBALS['egw_info']['server']['holidays_url_path'];
+ }
+ else
+ {
+ if ($GLOBALS['egw_info']['server']['webserver_url'][0] == '/')
+ {
+ $server_host = ($_SERVER['HTTPS']?'https://':'http://').$_SERVER['HTTP_HOST'].$GLOBALS['egw_info']['server']['webserver_url'];
+ }
+ else
+ {
+ $server_host = $GLOBALS['egw_info']['server']['webserver_url'];
+ }
+ $load_from = $server_host.'/calendar/egroupware.org';
+ }
+// echo 'Loading from: '.$load_from.'/holidays.'.strtoupper($locale).'.csv'."
\n";
+ if($GLOBALS['egw_info']['server']['holidays_url_path'] == 'localhost')
+ {
+ $lines = file(EGW_SERVER_ROOT.'/calendar/egroupware.org/holidays.'.strtoupper($locale).'.csv');
+ }
+ else
+ {
+ $lines = file($url=$load_from.'/holidays.'.strtoupper($locale).'.csv', 0, Framework::proxy_context());
+ //error_log(__METHOD__."('$locale', $year) file('$url')=".array2string($lines));
+ }
+ if (!$lines)
+ {
+ return false;
+ }
+ // reading the holidayfile from egroupware.org via network::gethttpsocketfile contains all the headers!
+ foreach($lines as $line)
+ {
+ $fields = preg_split("/[\t\n ]+/",$line);
+
+ if ($fields[0] == 'charset' && $fields[1])
+ {
+ $lines = Api\Translation::convert($lines,$fields[1]);
+ break;
+ }
+ }
+ foreach ($lines as $line)
+ {
+// echo 'Line #'.$i.' : '.$lines[$i]."
\n";
+ $holiday = explode("\t",$line);
+ if(count($holiday) == 7)
+ {
+ $holiday['locale'] = $holiday[0];
+ $holiday['name'] = $GLOBALS['egw']->db->db_addslashes($holiday[1]);
+ $holiday['mday'] = (int)$holiday[2];
+ $holiday['month_num'] = (int)$holiday[3];
+ $holiday['occurence'] = (int)$holiday[4];
+ $holiday['dow'] = (int)$holiday[5];
+ $holiday['observance_rule'] = (int)$holiday[6];
+ $holiday['hol_id'] = 0;
+ $this->so->save_holiday($holiday);
+ }
+ }
+ }
+ }
+
+ function save_holiday($holiday)
+ {
+ $this->so->save_holiday($holiday);
+ }
+
+ function add()
+ {
+ if(@$_POST['submit'])
+ {
+ $holiday = $_POST['holiday'];
+
+ if(empty($holiday['mday']))
+ {
+ $holiday['mday'] = 0;
+ }
+ if(!isset($this->bo->locales[0]) || $this->bo->locales[0]=='')
+ {
+ $this->bo->locales[0] = $holiday['locale'];
+ }
+ elseif(!isset($holiday['locale']) || $holiday['locale']=='')
+ {
+ $holiday['locale'] = $this->bo->locales[0];
+ }
+ if(!isset($holiday['hol_id']))
+ {
+ $holiday['hol_id'] = $this->bo->id;
+ }
+
+ // some input validation
+
+ if (!$holiday['mday'] == !$holiday['occurence'])
+ {
+ $errors[] = lang('You need to set either a day or a occurence !!!');
+ }
+ if($holiday['year'] && $holiday['occurence'])
+ {
+ $errors[] = lang('You can only set a year or a occurence !!!');
+ }
+ else
+ {
+ $holiday['occurence'] = (int)($holiday['occurence'] ? $holiday['occurence'] : $holiday['year']);
+ unset($holiday['year']);
+ }
+
+// Still need to put some validation in here.....
+
+ $this->ui =& CreateObject('calendar.uiholiday');
+
+ if (is_array($errors))
+ {
+ $holiday['month'] = $holiday['month_num'];
+ $holiday['day'] = $holiday['mday'];
+ $this->ui->edit_holiday($errors,$holiday);
+ }
+ else
+ {
+ $this->so->save_holiday($holiday);
+ $this->ui->edit_locale($holiday['locale']);
+ }
+ }
+ }
+
+ function sort_holidays_by_date($holidays)
+ {
+ $c_holidays = count($holidays);
+ for($outer_loop=0;$outer_loop<($c_holidays - 1);$outer_loop++)
+ {
+ for($inner_loop=$outer_loop;$inner_loop<$c_holidays;$inner_loop++)
+ {
+ if($holidays[$outer_loop]['date'] > $holidays[$inner_loop]['date'])
+ {
+ $temp = $holidays[$inner_loop];
+ $holidays[$inner_loop] = $holidays[$outer_loop];
+ $holidays[$outer_loop] = $temp;
+ }
+ }
+ }
+ return $holidays;
+ }
+
+ function set_holidays_to_date($holidays)
+ {
+ $new_holidays = Array();
+ for($i=0;$i<count($holidays);$i++)
+ {
+// echo "Setting Holidays Date : ".date('Ymd',$holidays[$i]['date'])."
\n";
+ $new_holidays[date('Ymd',$holidays[$i]['date'])][] = $holidays[$i];
+ }
+ return $new_holidays;
+ }
+
+ function read_holiday()
+ {
+ if(isset($this->cached_holidays))
+ {
+ return $this->cached_holidays;
+ }
+ $holidays = $this->so->read_holidays($this->locales,'','',$this->year);
+
+ if(count($holidays) == 0)
+ {
+ return $holidays;
+ }
+
+ $temp_locale = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
+ foreach($holidays as $i => $holiday)
+ {
+ if($i == 0 || $holidays[$i]['locale'] != $holidays[$i - 1]['locale'])
+ {
+ if(is_object($holidaycalc))
+ {
+ unset($holidaycalc);
+ }
+ $GLOBALS['egw_info']['user']['preferences']['common']['country'] = $holidays[$i]['locale'];
+ $holidaycalc =& CreateObject('calendar.holidaycalc');
+ }
+ $holidays[$i]['date'] = $holidaycalc->calculate_date($holiday, $holidays, $this->year);
+ }
+ unset($holidaycalc);
+ $this->holidays = $this->sort_holidays_by_date($holidays);
+ $this->cached_holidays = $this->set_holidays_to_date($this->holidays);
+ $GLOBALS['egw_info']['user']['preferences']['common']['country'] = $temp_locale;
+ return $this->cached_holidays;
+ }
+ /* End Calendar functions */
+
+ function check_admin()
+ {
+ if(!@$GLOBALS['egw_info']['user']['apps']['admin'])
+ {
+ Header('Location: ' . $GLOBALS['egw']->link('/index.php'));
+ }
+ }
+
+ function rule_string($holiday)
+ {
+ if (!is_array($holiday))
+ {
+ return false;
+ }
+ $monthnames = array(
+ '','January','February','March','April','May','June',
+ 'July','August','September','October','November','December'
);
-
- var $debug = false;
- var $base_url = '/index.php';
-
- var $ui;
- var $so;
- var $owner;
- var $year;
-
- var $id;
- var $total;
- var $start;
- var $query;
- var $sort;
-
- var $locales = Array();
- var $holidays;
- var $cached_holidays;
-
- function boholiday()
- {
- $this->so =& CreateObject('calendar.soholiday');
-
- $this->start = (int)get_var('start',array('POST','GET'));
- $this->query = get_var('query',array('POST','GET'));
- $this->sort = get_var('sort',array('POST','GET'));
- $this->order = get_var('order',array('POST','GET'));
- $this->id = get_var('id',array('POST','GET'));
- $this->year = get_var('year',array('POST','GET'),date('Y'));
- $this->locale = get_var('locale',array('POST','GET'));
- if ($this->locale)
- {
- $this->locales[] = $this->locale;
- }
-
- if($this->debug)
- {
- echo '<-- Locale = '.$this->locales[0].' -->'."\n";
- }
-
- $this->total = $this->so->holiday_total($this->locales[0],$this->query,$this->year);
- }
-
- /* Begin Calendar functions */
- function read_entry($id=0)
- {
- if($this->debug)
- {
- echo "BO : Reading Holiday ID : ".$id."
\n";
- }
-
- if(!$id)
- {
- if(!$this->id)
- {
- return Array();
- }
- else
- {
- $id = $this->id;
- }
- }
-
- return $this->so->read_holiday($id);
- }
-
- function delete_holiday($id=0)
- {
- if(!$id)
- {
- if($this->id)
- {
- $id = $this->id;
- }
- }
-
- $this->ui =& CreateObject('calendar.uiholiday');
- if($id)
- {
- $this->so->delete_holiday($id);
- $this->ui->edit_locale();
- }
- else
- {
- $this->ui->admin();
- }
- }
-
- function delete_locale($locale='')
- {
- if(!$locale)
- {
- if($this->locales[0])
- {
- $locale = $this->locales[0];
- }
- }
-
- if($locale)
- {
- $this->so->delete_locale($locale);
- }
- $this->ui =& CreateObject('calendar.uiholiday');
- $this->ui->admin();
- }
-
- function accept_holiday()
- {
- $send_back_to = str_replace('submitlocale','holiday_admin',$_SERVER['HTTP_REFERER']);
- if(!@$this->locales[0])
- {
- Header('Location: '.$send_back_to);
- }
-
- $send_back_to = str_replace('&locale='.$this->locales[0],'',$send_back_to);
- $file = './holidays.'.$this->locales[0];
- if(!file_exists($file) && count($_POST['name']))
- {
- $fp = fopen($file,'w');
- fwrite($fp,"charset\t".$GLOBALS['egw']->translation->charset()."\n");
-
- $holidays = array();
- foreach($_POST['name'] as $i => $name)
- {
- $holiday = array(
- 'locale' => $_POST['locale'],
- 'name' => str_replace('\\','',$name),
- 'day' => $_POST['day'][$i],
- 'month' => $_POST['month'][$i],
- 'occurence' => $_POST['occurence'][$i],
- 'dow' => $_POST['dow'][$i],
- 'observance' => $_POST['observance'][$i],
- );
- }
- // sort holidays by year / occurence:
- usort($holidays,'_holiday_cmp');
-
- $last_year = -1;
- foreach($holidays as $holiday)
- {
- $year = $holiday['occurence'] <= 0 ? 0 : $holiday['occurence'];
- if ($year != $last_year)
- {
- echo "\n".($year ? $year : 'regular (year=0)').":\n";
- $last_year = $year;
- }
- fwrite($fp,"$holiday[locale]\t$holiday[name]\t$holiday[day]\t$holiday[month]\t$holiday[occurence]\t$holiday[dow]\t$holiday[observance_rule]\n");
- }
- fclose($fp);
- }
- Header('Location: '.$send_back_to);
- }
-
- function get_holiday_list($locale='', $sort='', $order='', $query='', $total='', $year=0)
- {
- $locale = ($locale?$locale:$this->locales[0]);
- $sort = ($sort?$sort:$this->sort);
- $order = ($order?$order:$this->order);
- $query = ($query?$query:$this->query);
- $year = ($$year?$$year:$this->year);
- return $this->so->read_holidays($locale,$query,$order,$year);
- }
-
- function get_locale_list($sort='', $order='', $query='')
- {
- $sort = ($sort?$sort:$this->sort);
- $order = ($order?$order:$this->order);
- $query = ($query?$query:$this->query);
- return $this->so->get_locale_list($sort,$order,$query);
- }
-
- function prepare_read_holidays($year=0,$owner=0)
- {
- $this->year = (isset($year) && $year > 0?$year:$GLOBALS['egw']->common->show_date(time() - $GLOBALS['egw']->datetime->tz_offset,'Y'));
- $this->owner = ($owner?$owner:$GLOBALS['egw_info']['user']['account_id']);
-
- if($this->debug)
- {
- echo 'Setting Year to : '.$this->year.'
'."\n";
- }
-
- if(@$GLOBALS['egw_info']['user']['preferences']['common']['country'])
- {
- $this->locales[] = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
- }
- elseif(@$GLOBALS['egw_info']['user']['preferences']['calendar']['locale'])
- {
- $this->locales[] = $GLOBALS['egw_info']['user']['preferences']['calendar']['locale'];
- }
- else
- {
- $this->locales[] = 'US';
- }
-
- if($this->owner != $GLOBALS['egw_info']['user']['account_id'])
- {
- $owner_pref =& CreateObject('phpgwapi.preferences',$owner);
- $owner_prefs = $owner_pref->read_repository();
- if(@$owner_prefs['common']['country'])
- {
- $this->locales[] = $owner_prefs['common']['country'];
- }
- elseif(@$owner_prefs['calendar']['locale'])
- {
- $this->locales[] = $owner_prefs['calendar']['locale'];
- }
- unset($owner_pref);
- }
-
- if($GLOBALS['egw_info']['server']['auto_load_holidays'] == True && $this->locales)
- {
- foreach($this->locales as $local)
- {
- $this->auto_load_holidays($local, $year);
- }
- }
- }
-
- function auto_load_holidays($locale, $year=0)
- {
- //error_log(__METHOD__."('$locale', $year)");
- if (!egw_cache::getInstance(__CLASS__, $locale.'-'.$year) && // check if autoload has been tried for this locale and year
- (!($total_year = $this->so->holiday_total($locale, '', $year)) ||
- // automatic try load new holidays, if there are no irregular ones for queried year
- $total_year == $this->so->holiday_total($locale, '', 1901)))
- {
- //error_log(__METHOD__."('$locale', $year) attemption autoload ...");
- egw_cache::setInstance(__CLASS__, $locale.'-'.$year, true, 864000); // do NOT try again for 10 days
- @set_time_limit(0);
-
- /* get the file that contains the calendar events for your locale */
- /* "http://www.egroupware.org/cal/holidays.US.csv"; */
- if(isset($GLOBALS['egw_info']['server']['holidays_url_path']) && $GLOBALS['egw_info']['server']['holidays_url_path'] != 'localhost')
- {
- $load_from = $GLOBALS['egw_info']['server']['holidays_url_path'];
- }
- else
- {
- if ($GLOBALS['egw_info']['server']['webserver_url'][0] == '/')
- {
- $server_host = ($_SERVER['HTTPS']?'https://':'http://').$_SERVER['HTTP_HOST'].$GLOBALS['egw_info']['server']['webserver_url'];
- }
- else
- {
- $server_host = $GLOBALS['egw_info']['server']['webserver_url'];
- }
- $load_from = $server_host.'/calendar/egroupware.org';
- }
-// echo 'Loading from: '.$load_from.'/holidays.'.strtoupper($locale).'.csv'."
\n";
- if($GLOBALS['egw_info']['server']['holidays_url_path'] == 'localhost')
- {
- $lines = file(EGW_SERVER_ROOT.'/calendar/egroupware.org/holidays.'.strtoupper($locale).'.csv');
- }
- else
- {
- $lines = file($url=$load_from.'/holidays.'.strtoupper($locale).'.csv', 0, egw_framework::proxy_context());
- //error_log(__METHOD__."('$locale', $year) file('$url')=".array2string($lines));
- }
- if (!$lines)
- {
- return false;
- }
- // reading the holidayfile from egroupware.org via network::gethttpsocketfile contains all the headers!
- foreach($lines as $line)
- {
- $fields = preg_split("/[\t\n ]+/",$line);
-
- if ($fields[0] == 'charset' && $fields[1])
- {
- $lines = translation::convert($lines,$fields[1]);
- break;
- }
- }
- foreach ($lines as $line)
- {
-// echo 'Line #'.$i.' : '.$lines[$i]."
\n";
- $holiday = explode("\t",$line);
- if(count($holiday) == 7)
- {
- $holiday['locale'] = $holiday[0];
- $holiday['name'] = $GLOBALS['egw']->db->db_addslashes($holiday[1]);
- $holiday['mday'] = (int)$holiday[2];
- $holiday['month_num'] = (int)$holiday[3];
- $holiday['occurence'] = (int)$holiday[4];
- $holiday['dow'] = (int)$holiday[5];
- $holiday['observance_rule'] = (int)$holiday[6];
- $holiday['hol_id'] = 0;
- $this->so->save_holiday($holiday);
- }
- }
- }
- }
-
- function save_holiday($holiday)
- {
- $this->so->save_holiday($holiday);
- }
-
- function add()
- {
- if(@$_POST['submit'])
- {
- $holiday = $_POST['holiday'];
-
- if(empty($holiday['mday']))
- {
- $holiday['mday'] = 0;
- }
- if(!isset($this->bo->locales[0]) || $this->bo->locales[0]=='')
- {
- $this->bo->locales[0] = $holiday['locale'];
- }
- elseif(!isset($holiday['locale']) || $holiday['locale']=='')
- {
- $holiday['locale'] = $this->bo->locales[0];
- }
- if(!isset($holiday['hol_id']))
- {
- $holiday['hol_id'] = $this->bo->id;
- }
-
- // some input validation
-
- if (!$holiday['mday'] == !$holiday['occurence'])
- {
- $errors[] = lang('You need to set either a day or a occurence !!!');
- }
- if($holiday['year'] && $holiday['occurence'])
- {
- $errors[] = lang('You can only set a year or a occurence !!!');
- }
- else
- {
- $holiday['occurence'] = (int)($holiday['occurence'] ? $holiday['occurence'] : $holiday['year']);
- unset($holiday['year']);
- }
-
- // Still need to put some validation in here.....
-
- $this->ui =& CreateObject('calendar.uiholiday');
-
- if (is_array($errors))
- {
- $holiday['month'] = $holiday['month_num'];
- $holiday['day'] = $holiday['mday'];
- $this->ui->edit_holiday($errors,$holiday);
- }
- else
- {
- $this->so->save_holiday($holiday);
- $this->ui->edit_locale($holiday['locale']);
- }
- }
- }
-
- function sort_holidays_by_date($holidays)
- {
- $c_holidays = count($holidays);
- for($outer_loop=0;$outer_loop<($c_holidays - 1);$outer_loop++)
- {
- for($inner_loop=$outer_loop;$inner_loop<$c_holidays;$inner_loop++)
- {
- if($holidays[$outer_loop]['date'] > $holidays[$inner_loop]['date'])
- {
- $temp = $holidays[$inner_loop];
- $holidays[$inner_loop] = $holidays[$outer_loop];
- $holidays[$outer_loop] = $temp;
- }
- }
- }
- return $holidays;
- }
-
- function set_holidays_to_date($holidays)
- {
- $new_holidays = Array();
- for($i=0;$i<count($holidays);$i++)
- {
-// echo "Setting Holidays Date : ".date('Ymd',$holidays[$i]['date'])."
\n";
- $new_holidays[date('Ymd',$holidays[$i]['date'])][] = $holidays[$i];
- }
- return $new_holidays;
- }
-
- function read_holiday()
- {
- if(isset($this->cached_holidays))
- {
- return $this->cached_holidays;
- }
- $holidays = $this->so->read_holidays($this->locales,'','',$this->year);
-
- if(count($holidays) == 0)
- {
- return $holidays;
- }
-
- $temp_locale = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
- foreach($holidays as $i => $holiday)
- {
- if($i == 0 || $holidays[$i]['locale'] != $holidays[$i - 1]['locale'])
- {
- if(is_object($holidaycalc))
- {
- unset($holidaycalc);
- }
- $GLOBALS['egw_info']['user']['preferences']['common']['country'] = $holidays[$i]['locale'];
- $holidaycalc =& CreateObject('calendar.holidaycalc');
- }
- $holidays[$i]['date'] = $holidaycalc->calculate_date($holiday, $holidays, $this->year);
- }
- unset($holidaycalc);
- $this->holidays = $this->sort_holidays_by_date($holidays);
- $this->cached_holidays = $this->set_holidays_to_date($this->holidays);
- $GLOBALS['egw_info']['user']['preferences']['common']['country'] = $temp_locale;
- return $this->cached_holidays;
- }
- /* End Calendar functions */
-
- function check_admin()
- {
- if(!@$GLOBALS['egw_info']['user']['apps']['admin'])
- {
- Header('Location: ' . $GLOBALS['egw']->link('/index.php'));
- }
- }
-
- function rule_string($holiday)
- {
- if (!is_array($holiday))
- {
- return false;
- }
- $monthnames = array(
- '','January','February','March','April','May','June',
- 'July','August','September','October','November','December'
- );
- $month = $holiday['month'] ? lang($monthnames[$holiday['month']]) : '';
-
- if (!$holiday['day'])
- {
- $occ = $holiday['occurence'] == 99 ? lang('last') : $holiday['occurence'].'.';
-
- $dow_str = Array(lang('Sun'),lang('Mon'),lang('Tue'),lang('Wed'),lang('Thu'),lang('Fri'),lang('Sat'));
- $dow = $dow_str[$holiday['dow']];
-
- $str = lang('%1 %2 in %3',$occ,$dow,$month);
- }
- else
- {
- $str = $GLOBALS['egw']->common->dateformatorder($holiday['occurence']>1900?$holiday['occurence']:'',$month,$holiday[day]);
- }
- if ($holiday['observance_rule'])
- {
- $str .= ' ('.lang('Observance Rule').')';
- }
- return $str;
- }
- }
-
- function _holiday_cmp($a,$b)
- {
- if (($year_diff = ($a['occurence'] <= 0 ? 0 : $a['occurence']) - ($b['occurence'] <= 0 ? 0 : $b['occurence'])))
- {
- return $year_diff;
- }
- return $a['month'] - $b['month'] ? $a['month'] - $b['month'] : $a['day'] - $b['day'];
- }
+ $month = $holiday['month'] ? lang($monthnames[$holiday['month']]) : '';
+
+ if (!$holiday['day'])
+ {
+ $occ = $holiday['occurence'] == 99 ? lang('last') : $holiday['occurence'].'.';
+
+ $dow_str = Array(lang('Sun'),lang('Mon'),lang('Tue'),lang('Wed'),lang('Thu'),lang('Fri'),lang('Sat'));
+ $dow = $dow_str[$holiday['dow']];
+
+ $str = lang('%1 %2 in %3',$occ,$dow,$month);
+ }
+ else
+ {
+ $arr = array($month,$holiday['day']);
+ if ($holiday['occurence']>1900) array_unshift ($arr, $holiday['occurence']);
+ $str = implode('-', $arr);
+ }
+ if ($holiday['observance_rule'])
+ {
+ $str .= ' ('.lang('Observance Rule').')';
+ }
+ return $str;
+ }
+}
+
+function _holiday_cmp($a,$b)
+{
+ if (($year_diff = ($a['occurence'] <= 0 ? 0 : $a['occurence']) - ($b['occurence'] <= 0 ? 0 : $b['occurence'])))
+ {
+ return $year_diff;
+ }
+ return $a['month'] - $b['month'] ? $a['month'] - $b['month'] : $a['day'] - $b['day'];
+}
Modified: trunk/calendar/inc/class.calendar_bo.inc.php
URL: http://svn.stylite.de/viewvc/egroupware/trunk/calendar/inc/class.calendar_bo.inc.php?rev=55963&r1=55962&r2=55963&view=diff
==============================================================================
--- trunk/calendar/inc/class.calendar_bo.inc.php (original)
+++ trunk/calendar/inc/class.calendar_bo.inc.php Sun May 1 19:47:59 2016
@@ -6,10 +6,14 @@
* @package calendar
* @author Ralf Becker
* @author Joerg Lehrke
- * @copyright (c) 2004-15 by RalfBecker-At-outdoor-training.de
+ * @copyright (c) 2004-16 by RalfBecker-At-outdoor-training.de
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
+
+use EGroupware\Api;
+use EGroupware\Api\Link;
+use EGroupware\Api\Acl;
if (!defined('ACL_TYPE_IDENTIFER')) // used to mark ACL-values for the debug_message methode
{
@@ -19,17 +23,6 @@
define('HOUR_s',60*60);
define('DAY_s',24*HOUR_s);
define('WEEK_s',7*DAY_s);
-
-/**
- * Gives read access to the calendar, but all events the user is not participating are private!
- * Used by addressbook.
- */
-define('EGW_ACL_READ_FOR_PARTICIPANTS',EGW_ACL_CUSTOM_1);
-define('EGW_ACL_FREEBUSY',EGW_ACL_CUSTOM_2);
-/**
- * Allows to invite an other user (if configured to be used!)
- */
-define('EGW_ACL_INVITE',EGW_ACL_CUSTOM_3);
/**
* Required (!) include, as we use the MCAL_* constants, BEFORE instanciating (and therefore autoloading) the class
@@ -57,6 +50,20 @@
class calendar_bo
{
/**
+ * Gives read access to the calendar, but all events the user is not participating are private!
+ * Used by addressbook.
+ */
+ const ACL_READ_FOR_PARTICIPANTS = Acl::CUSTOM1;
+ /**
+ * Right to see free/busy data only
+ */
+ const ACL_FREEBUSY = Acl::CUSTOM2;
+ /**
+ * Allows to invite an other user (if configured to be used!)
+ */
+ const ACL_INVITE = Acl::CUSTOM3;
+
+ /**
* @var int $debug name of method to debug or level of debug-messages:
* False=Off as higher as more messages you get ;-)
* 1 = function-calls incl. parameters to general functions like search, read, write, delete
@@ -196,7 +203,7 @@
/**
* Instance of the categories class
*
- * @var categories
+ * @var Api\Categories
*/
var $categories;
@@ -228,16 +235,16 @@
$this->cal_prefs =& $GLOBALS['egw_info']['user']['preferences']['calendar'];
$this->now = time();
- $this->now_su = egw_time::server2user($this->now,'ts');
+ $this->now_su = Api\DateTime::server2user($this->now,'ts');
$this->user = $GLOBALS['egw_info']['user']['account_id'];
$this->grants = $GLOBALS['egw']->acl->get_grants('calendar');
- if (!is_array($this->resources = $GLOBALS['egw']->session->appsession('resources','calendar')))
+ if (!is_array($this->resources = Api\Cache::getSession('calendar', 'resources')))
{
$this->resources = array();
- foreach($GLOBALS['egw']->hooks->process('calendar_resources') as $app => $data)
+ foreach(Api\Hooks::process('calendar_resources') as $app => $data)
{
if ($data && $data['type'])
{
@@ -253,16 +260,16 @@
'type' => '',
'app' => 'api-accounts',
);
- $GLOBALS['egw']->session->appsession('resources','calendar',$this->resources);
+ Api\Cache::setSession('calendar', 'resources', $this->resources);
}
//echo "registered resources="; _debug_array($this->resources);
- $this->config = config::read('calendar'); // only used for horizont, regular calendar config is under phpgwapi
+ $this->config = Api\Config::read('calendar'); // only used for horizont, regular calendar Api\Config is under phpgwapi
$this->require_acl_invite = $GLOBALS['egw_info']['server']['require_acl_invite'];
- $this->categories = new categories($this->user,'calendar');
-
- $this->customfields = config::get_customfields('calendar');
+ $this->categories = new Api\Categories($this->user,'calendar');
+
+ $this->customfields = Api\Storage\Customfields::get('calendar');
foreach($this->alarms as $secs => &$label)
{
@@ -317,7 +324,7 @@
$data[] = array(
'res_id' => $id,
'email' => $email,
- 'rights' => EGW_ACL_READ_FOR_PARTICIPANTS,
+ 'rights' => self::ACL_READ_FOR_PARTICIPANTS,
'name' => $name,
);
}
@@ -372,7 +379,7 @@
foreach($_users as $user)
{
$user = trim($user);
- if ($ignore_acl || $this->check_perms(EGW_ACL_READ|EGW_ACL_READ_FOR_PARTICIPANTS|($use_freebusy?EGW_ACL_FREEBUSY:0),0,$user))
+ if ($ignore_acl || $this->check_perms(ACL::READ|self::ACL_READ_FOR_PARTICIPANTS|($use_freebusy?self::ACL_FREEBUSY:0),0,$user))
{
if ($user && !in_array($user,$users)) // already added?
{
@@ -398,7 +405,7 @@
{
// use only members which gave the user a read-grant
if (!in_array($member, $users) &&
- ($ignore_acl || $this->check_perms(EGW_ACL_READ|($use_freebusy?EGW_ACL_FREEBUSY:0),0,$member)))
+ ($ignore_acl || $this->check_perms(Acl::READ|($use_freebusy?self::ACL_FREEBUSY:0),0,$member)))
{
$users[] = $member;
}
@@ -443,7 +450,7 @@
* otherwise the original recuring event (with the first start- + enddate) is returned
* num_rows int number of entries to return, default or if 0, max_entries from the prefs
* order column-names plus optional DESC|ASC separted by comma
- * ignore_acl if set and true no check_perms for a general EGW_ACL_READ grants is performed
+ * ignore_acl if set and true no check_perms for a general Acl::READ grants is performed
* enum_groups boolean if set and true, group-members will be added as participants with status 'G'
* cols string|array columns to select, if set an iterator will be returned
* append string to append to the query, eg. GROUP BY
@@ -484,7 +491,7 @@
$params['private_grants'] = array();
foreach($this->grants as $user => $rights)
{
- if ($rights & EGW_ACL_PRIVATE) $params['private_grants'][] = $user;
+ if ($rights & Acl::PRIVAT) $params['private_grants'][] = $user;
}
}
@@ -548,7 +555,7 @@
}
else
{
- $is_private = !$this->check_perms(EGW_ACL_READ,$event);
+ $is_private = !$this->check_perms(Acl::READ,$event);
}
if ($is_private || (!$event['public'] && $filter == 'hideprivate'))
{
@@ -640,7 +647,7 @@
// no method, fall back to link title
if (is_null($app_data))
{
- $is_private = !egw_link::title($app,$id);
+ $is_private = !Link::title($app,$id);
}
// boolean value to make all events of $app public (false) or private (true)
elseif (is_bool($app_data))
@@ -658,7 +665,7 @@
/**
* Clears all non-private info from a privat event
*
- * That function only returns the infos allowed to be viewed by people without EGW_ACL_PRIVATE grants
+ * That function only returns the infos allowed to be viewed by people without Acl::PRIVAT grants
*
* @param array &$event
* @param array $allowed_participants ids of the allowed participants, eg. the ones the search is over or eg. the owner of the calendar
@@ -724,7 +731,7 @@
if ($new_horizont > time()+$maxdays*DAY_s) // some user tries to "look" more then the maximum number of days in the future
{
if ($this->debug == 'check_move_horizont') $this->debug_message('calendar_bo::check_move_horizont(%1) horizont=%2 new horizont more then %3 days from now --> ignoring it',true,$new_horizont,(int)$this->config['horizont'],$maxdays);
- $this->warnings['horizont'] = lang('Requested date %1 outside allowed range of %2 days: recurring events obmitted!', egw_time::to($new_horizont,true), $maxdays);
+ $this->warnings['horizont'] = lang('Requested date %1 outside allowed range of %2 days: recurring events obmitted!', Api\DateTime::to($new_horizont,true), $maxdays);
return;
}
if ($new_horizont < time()+31*DAY_s)
@@ -745,11 +752,11 @@
$this->debug_message('calendar_bo::check_move_horizont(%1): calling set_recurrences(%2,%3)',true,$new_horizont,$event,$old_horizont);
}
// insert everything behind max(cal_start), which can be less then $old_horizont because of bugs in the past
- $this->set_recurrences($event,egw_time::server2user($recuring[$cal_id]+1)); // set_recurences operates in user-time!
+ $this->set_recurrences($event,Api\DateTime::server2user($recuring[$cal_id]+1)); // set_recurences operates in user-time!
}
}
// update the horizont
- config::save_value('horizont',$this->config['horizont'],'calendar');
+ Api\Config::save_value('horizont',$this->config['horizont'],'calendar');
if ($this->debug == 'check_move_horizont') $this->debug_message('calendar_bo::check_move_horizont(%1) new horizont=%2, exiting',true,$new_horizont,(int)$this->config['horizont']);
}
@@ -790,15 +797,15 @@
$exceptions = array();
foreach((array)$event['recur_exception'] as $exception)
{
- $exceptions[] = egw_time::to($exception, true); // true = date
+ $exceptions[] = Api\DateTime::to($exception, true); // true = date
}
foreach($events as $event)
{
- $is_exception = in_array(egw_time::to($event['start'], true), $exceptions);
+ $is_exception = in_array(Api\DateTime::to($event['start'], true), $exceptions);
$start = $this->date2ts($event['start'],true);
if ($event['whole_day'])
{
- $time = $this->so->startOfDay(new egw_time($event['end'], egw_time::$user_timezone));
+ $time = $this->so->startOfDay(new Api\DateTime($event['end'], Api\DateTime::$user_timezone));
$time->setTime(23, 59, 59);
$end = $this->date2ts($time,true);
}
@@ -806,7 +813,7 @@
{
$end = $this->date2ts($event['end'],true);
}
- //error_log(__METHOD__."() start=".egw_time::to($start).", is_exception=".array2string($is_exception));
+ //error_log(__METHOD__."() start=".Api\DateTime::to($start).", is_exception=".array2string($is_exception));
$this->so->recurrence($event['id'], $start, $end, $event['participants'], $is_exception);
}
}
@@ -815,7 +822,7 @@
* Convert data read from the db, eg. convert server to user-time
*
* Also make sure all timestamps comming from DB as string are converted to integer,
- * to avoid misinterpretation by egw_time as Ymd string.
+ * to avoid misinterpretation by Api\DateTime as Ymd string.
*
* @param array &$events array of event-arrays (reference)
* @param $date_format ='ts' date-formats: 'ts'=timestamp, 'server'=timestamp in server-time, 'array'=array or string with date-format
@@ -828,32 +835,32 @@
// convert timezone id of event to tzid (iCal id like 'Europe/Berlin')
if (empty($event['tzid']) && (!$event['tz_id'] || !($event['tzid'] = calendar_timezones::id2tz($event['tz_id']))))
{
- $event['tzid'] = egw_time::$server_timezone->getName();
+ $event['tzid'] = Api\DateTime::$server_timezone->getName();
}
// database returns timestamps as string, convert them to integer
- // to avoid misinterpretation by egw_time as Ymd string
+ // to avoid misinterpretation by Api\DateTime as Ymd string
// (this will fail on 32bit systems for times > 2038!)
- $event['start'] = (int)$event['start']; // this is for isWholeDay(), which also calls egw_time
+ $event['start'] = (int)$event['start']; // this is for isWholeDay(), which also calls Api\DateTime
$event['end'] = (int)$event['end'];
$event['whole_day'] = self::isWholeDay($event);
if ($event['whole_day'] && $date_format != 'server')
{
// Adjust dates to user TZ
- $stime =& $this->so->startOfDay(new egw_time((int)$event['start'], egw_time::$server_timezone), $event['tzid']);
- $event['start'] = egw_time::to($stime, $date_format);
- $time =& $this->so->startOfDay(new egw_time((int)$event['end'], egw_time::$server_timezone), $event['tzid']);
+ $stime =& $this->so->startOfDay(new Api\DateTime((int)$event['start'], Api\DateTime::$server_timezone), $event['tzid']);
+ $event['start'] = Api\DateTime::to($stime, $date_format);
+ $time =& $this->so->startOfDay(new Api\Da