tiki  21.2
About: Tiki Wiki is a Groupware/CMS (Content Management System) solution that has features like Wikis, Forums, Blogs, Articles, Image Gallery, Map Server, Link Directory, Multilingual Support, Bug Tracker, RSS Feeds etc. Latest release 21 with Long Term Support (LTS).
  Fossies Dox: tiki-21.2.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

tiki-calendar_setup.php
Go to the documentation of this file.
1 <?php
5 // (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6 //
7 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
8 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9 // $Id$
10 
11 //this script may only be included - so its better to die if called directly.
12 
13 
21 if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) != false) {
22  header('location: index.php');
23  exit;
24 }
26 $smarty = TikiLib::lib('smarty');
27 global $prefs;
28 
29 if (! ($prefs['feature_calendar'] == 'y' || $prefs['feature_action_calendar'] == 'y')) {
30  if (isset($_SERVER['SCRIPT_NAME'])) {
31  if ($_SERVER['SCRIPT_NAME'] == "tiki-calendar.php") {
32  $smarty->assign('msg', tra("This feature is disabled") . ": feature_calendar");
33  } elseif ($_SERVER['SCRIPT_NAME'] == "tiki-action_calendar.php") {
34  $smarty->assign('msg', tra("This feature is disabled") . ": feature_action_calendar");
35  } else {
36  $smarty->assign('msg', tra("This feature is disabled"));
37  }
38  }
39  $smarty->display("error.tpl");
40  die;
41 }
42 
43 $calendarlib = TikiLib::lib('calendar');
44 
45 $trunc = '40'; // put in a pref, number of chars displayed in cal cells
46 
47 if (! empty($_REQUEST['focus'])) {
48  $_REQUEST['todate'] = $_SESSION['CalendarFocusDate'] = $_REQUEST['focus'];
49 }
50 
51 if (! empty($_REQUEST['day']) && ! empty($_REQUEST['mon']) && ! empty($_REQUEST['year'])) {//can come from the event module
52  $_REQUEST['todate'] = $tikilib->make_time(23, 59, 59, (int)$_REQUEST['mon'], (int)$_REQUEST['day'], (int)$_REQUEST['year']);
53 } elseif (isset($_REQUEST['todate']) && $_REQUEST['todate']) {
54  $_SESSION['CalendarFocusDate'] = $_REQUEST["todate"];
55 } elseif (! isset($_REQUEST['todate']) && isset($_SESSION['CalendarFocusDate']) && $_SESSION['CalendarFocusDate']) {
56  $_REQUEST["todate"] = $_SESSION['CalendarFocusDate'];
57 } else {
58  $_REQUEST["todate"] = $tikilib->now;
59 }
60 
61 $focusdate = $_REQUEST['todate'];
65 // Validate input
66 if ((int)$focusDay <= 0 || ! is_numeric($focusDay) ||
67  (int)$focusMonth <= 0 || ! is_numeric($focusDay) ||
68  (int)$focusYear <= 0 || ! is_numeric($focusDay)) {
69  $_SESSION['CalendarFocusDate'] = $tikilib->now;
70  $smarty->assign('msg', tra('Invalid date format'));
71  $smarty->display('error.tpl');
72  die;
73 }
74 list($focus_day, $focus_month, $focus_year) = [
75  $focusDay,
78 ];
79 
80 $focus = ['day' => $focus_day, 'month' => $focus_month, 'year' => $focus_year];
81 $focuscell = $tikilib->make_time(0, 0, 0, $focus_month, $focus_day, $focus_year);
82 $smarty->assign('focusdate', $focusdate);
83 $smarty->assign('focuscell', $focuscell);
84 $smarty->assign('today', $tikilib->make_time(0, 0, 0, $tikilib->date_format('%m'), $tikilib->date_format('%d'), $tikilib->date_format('%Y')));
85 
86 // Get viewmode from URL, session or prefs if it has not already been defined by the calling script (for example by modules, to force a month view)
87 // ###trebly:B10111:[FIX-ADD-ENH]-> there are several meaning for the same var $calendarViewMode
88 if (! isset($calendarViewMode)) {
89  // ###trebly:B10111:[FIX-ADD-ENH]-> $calendarViewMode become an array, several bugs comes from confusion of global values and parameters by ref
90  // for calendars : (main-)calendar, action_calendar, mod_calendar, mod_action_calendar the changes of values by url request is terrible
91  // for the moment 01/11/2011:11:55 just one value is used with index 'default', but initialisation is done.
92  // The init is actually into two places, tiki-calendar_setup.php and tiki-calendar_export.php will be grouped for clean
93  // $prefs would be added when need, $_SESSION, $PARAMS too this now generates not any change in the behavior.
94  $calendarViewMode = [
95  'casedefault' => 'month',
96  'calgen' => 'month',
97  'calaction' => 'month',
98  'modcalgen' => 'month',
99  'modcalaction' => 'month',
100  'trackercal' => 'month'
101  ];
102 
103  if (! empty($_REQUEST['viewmode'])) {
104  $calendarViewMode['casedefault'] = $_REQUEST['viewmode'];
105  } elseif (! empty($_SESSION['CalendarViewMode'])) {
106  $calendarViewMode['casedefault'] = $_SESSION['CalendarViewMode'];
107  } else {
108  $calendarViewMode['casedefault'] = $prefs['calendar_view_mode'];
109  }
110 }
111 
112 $_SESSION['CalendarViewMode'] = $calendarViewMode['casedefault'];
113 $smarty->assign_by_ref('viewmode', $calendarViewMode['casedefault']);
114 
115 if (isset($_REQUEST["viewlist"])) {
116  $viewlist = $_REQUEST['viewlist'];
117  $_SESSION['CalendarViewList'] = $viewlist;
118 } elseif (isset($_REQUEST["viewlistmodule"])) {
119  $viewlist = $_REQUEST['viewlistmodule'];
120 } elseif (! empty($_SESSION['CalendarViewList'])) {
121  $viewlist = $_SESSION['CalendarViewList'];
122 } else {
123  $viewlist = "";
124 }
125 
126 $smarty->assign_by_ref('viewlist', $viewlist);
127 
128 if (isset($_REQUEST["gbi"])) {
129  $group_by_item = $_REQUEST["gbi"];
130  $_SESSION['CalendarGroupByItem'] = $group_by_item;
131 } else {
132  $group_by_item = "";
133 }
134 
135 $smarty->assign_by_ref('group_by_item', $_SESSION['CalendarGroupByItem']);
136 
137 $calendarViewGroups = (isset($_SESSION['CalendarViewGroups'])) ? $_SESSION['CalendarViewGroups'] : '';
138 $calendarViewList = array_key_exists('CalendarViewList', $_SESSION) ? $_SESSION['CalendarViewList'] : '';
139 $calendarGroupByItem = $_SESSION['CalendarGroupByItem'];
140 
141 $firstDayofWeek = $calendarlib->firstDayofWeek();
142 $smarty->assign('firstDayofWeek', $firstDayofWeek);
143 
144 $strRef = tra("%H:%M %Z");
145 if (strstr($strRef, "%h") || strstr($strRef, "%g")) {
146  $timeFormat12_24 = "12";
147 } else {
148  $timeFormat12_24 = "24";
149 }
150 $smarty->assign('timeFormat12_24', $timeFormat12_24);
151 $smarty->assign('short_format_day', tra('%m/%d'));
152 
153 // To make "previous month" work if the current focus is on, for example, the last day of march.
154 $focus_day_limited = min($focus_day, 28);
155 
156 if (! function_exists('cal_days_in_month')) {
157  $smarty->assign('msg', tra('Your PHP installation does not have calendar enabled.'));
158  $smarty->display('error.tpl');
159  die;
160 }
161 $focus_prev = $calendarlib->focusPrevious($focus, $calendarViewMode['casedefault']);
162 $focus_next = $calendarlib->focusNext($focus, $calendarViewMode['casedefault']);
163 
164 $smarty->assign('focus_prev', $focus_prev['date']);
165 $smarty->assign('focus_next', $focus_next['date']);
166 
167 $smarty->assign('focusday', $focus_day);
168 $smarty->assign('focusmonth', $focus_month);
169 $smarty->assign('focusdate', $focusdate);
170 $smarty->assign('focuscell', $focuscell);
171 
172 $smarty->assign('now', $tikilib->now);
173 $smarty->assign('nowUser', $tikilib->now);
174 
175 $weekdays = range(0, 6);
176 $hours = range(0, 23);
177 
178 $d = 60 * 60 * 24;
181 
182 //prepare for select first day of week (Hausi)
183 if ($firstDayofWeek == 1) {
184  $wd--;
185  if ($wd == -1) {
186  $wd = 6;
187  }
188 }
189 
190 if (isset($request_day)) {
191  $focus_day = $request_day;
192 }
193 if (isset($request_month)) {
194  $focus_month = $request_month;
195 }
196 if (isset($request_year)) {
197  $focus_year = $request_year;
198 }
199 
200 $smarty->assign('viewmonth', $focus_month);
201 $smarty->assign('viewday', $focus_day);
202 $smarty->assign('viewyear', $focus_year);
203 
204 // calculate timespan for sql query
205 if ($viewlist == 'list' && $prefs['calendar_list_begins_focus'] == 'y') {
206  $daystart = $focusdate;
207 } elseif ($calendarViewMode['casedefault'] == 'month'
208  || $calendarViewMode['casedefault'] == 'quarter'
209  || $calendarViewMode['casedefault'] == 'semester'
210 ) {
211  $daystart = $tikilib->make_time(0, 0, 0, $focus_month, 1, $focus_year);
212 } elseif ($calendarViewMode['casedefault'] == 'year') {
213  $daystart = $tikilib->make_time(0, 0, 0, 1, 1, $focus_year);
214 } else {
215  $daystart = $tikilib->make_time(0, 0, 0, $focus_month, $focus_day, $focus_year);
216 }
217 
218 // viewstart is the beginning of the display, daystart is the beginning of the selected period
219 $viewstart = $daystart;
220 
221 if ($calendarViewMode['casedefault'] == 'month' ||
222  $calendarViewMode['casedefault'] == 'quarter' ||
223  $calendarViewMode['casedefault'] == 'semester' ||
224  $calendarViewMode['casedefault'] == 'year' ) {
225  $TmpWeekday = TikiLib::date_format("%w", $viewstart);
226 
227  // prepare for select first day of week (Hausi)
228  if ($firstDayofWeek == 1) {
229  $TmpWeekday--;
230  if ($TmpWeekday == -1) {
231  $TmpWeekday = 6;
232  }
233  }
234 
235  // move viewstart back to first day of week ...
236  if ($viewlist != 'list') {
237  //$viewstart -= $TmpWeekday * $d;
238 
239  if ($TmpWeekday > 0) {
240  $viewstart_m = TikiLib::date_format("%m", $viewstart);
241  $viewstart_y = TikiLib::date_format("%Y", $viewstart);
242 
243  // $tikilib->make_time() used with timezones doesn't support month = 0
244  if ($viewstart_m == 1) {
245  $viewstart_m = 12;
246  $viewstart_y--;
247  } else {
248  $viewstart_m--;
249  }
250 
251  // $tikilib->make_time() used with timezones doesn't support day = 0
252  // This supposes that $viewstart's day == 1, as defined above
253  $viewstart_d = Date_Calc::daysInMonth($viewstart_m, $viewstart_y) - ( $TmpWeekday - 1 );
254 
255  $viewstart = $tikilib->make_time(0, 0, 0, $viewstart_m, $viewstart_d, $viewstart_y);
256  }
257  }
258  // this is the last day of $focus_month
259  if ($viewlist == 'list' && $prefs['calendar_list_begins_focus'] == 'y') {
260  $df = $focus_day;
261  } else {
262  $df = 1;
263  }
264 
265  if ($calendarViewMode['casedefault'] == 'month') {
266  $viewend = $tikilib->make_time(0, 0, 0, $focus_month + 1, $df, $focus_year);
267  } elseif ($calendarViewMode['casedefault'] == 'quarter') {
268  $viewend = $tikilib->make_time(0, 0, 0, $focus_month + 3, $df, $focus_year);
269  } elseif ($calendarViewMode['casedefault'] == 'semester') {
270  $viewend = $tikilib->make_time(0, 0, 0, $focus_month + 6, $df, $focus_year);
271  } elseif ($calendarViewMode['casedefault'] == 'year') {
272  $viewend = $tikilib->make_time(0, 0, 0, 1, $df, $focus_year + 1);
273  } else {
274  $viewend = $tikilib->make_time(0, 0, 0, $focus_month + 1, 0, $focus_year);
275  }
276  $viewend -= 1;
277  $dayend = $viewend;
278  $TmpWeekday = TikiLib::date_format("%w", $viewend);
279  if ($viewlist != 'list') {
280  //$viewend += (6 - $TmpWeekday) * $d;
281  $viewend = $tikilib->make_time(
282  23,
283  59,
284  59,
286  (int) TikiLib::date_format("%d", $viewend) + ( 6 - $TmpWeekday ),
288  );
289  }
290 
291  // ISO weeks --- kinda mangled because ours begin on Sunday...
292  $firstweek = TikiLib::date_format("%U", $viewstart + $d);
294 
295  if ($lastweek <= $firstweek) {
296  $startyear = (int) TikiLib::date_format("%Y", $daystart - 1);
297  $weeksinyear = (int) TikiLib::date_format("%U", $tikilib->make_time(0, 0, 0, 12, 31, $startyear));
298 
299  if ($weeksinyear == 1) {
300  $weeksinyear = (int) TikiLib::date_format("%U", $tikilib->make_time(0, 0, 0, 12, 28, $startyear));
301  }
302 
303  $lastweek += $weeksinyear;
304  }
305 
306  // [BUG FIX] hollmeer 2012-11-01: correct the bug if 1 Jan of the FOCUS YEAR is Sunday,
307  // and $prefs['calendar_firstDayofWeek'] is set to start from Monday.
308  // Original seems to output only two weeks in such case, e.g for 2012:
309  // weeks 52/2011 and 01/2012, as the 1 Jan 2012 is Sunday (i.e., start of focus year).
310  // For 2013 and 2014 all weeks generated as ok, as 1 Jan 2013 is Tuesday, and 1 Jan 2014 is Wednesday etc
311  // The bug is that only one week was added in such case, and actually the focus year was omitted, so add 52 weeks
312  $auxneedtoaddweeks = 0;
313  if ($calendarViewMode['casedefault'] == 'year') {
314  $auxTmpWeekday = TikiLib::date_format("%w", $tikilib->make_time(0, 0, 0, 1, 1, $focus_year));
315  if ($firstDayofWeek == 1 and $auxTmpWeekday == 0) {
316  $auxneedtoaddweeks = 52;
317  }
318  }
319  // ...end add + add below, of course */
320 
321  $numberofweeks = $lastweek - $firstweek + $auxneedtoaddweeks; // [BUG FIX] hollmeer 2012-11-01: add the potentially required 52 weeks here
322 } elseif ($calendarViewMode['casedefault'] == 'week') {
323  $firstweek = $currentweek;
325 
326  // then back up to the preceding Sunday;
327  // $viewstart -= $wd * $d;
328  if ($wd > 0 and $viewlist != 'list') {
329  $viewstart_d = TikiLib::date_format("%d", $viewstart);
330  $viewstart_m = TikiLib::date_format("%m", $viewstart);
331  $viewstart_y = TikiLib::date_format("%Y", $viewstart);
332 
333  // Start in previous month if $wd is greater than the current day (relative to th current month)
334  if ($viewstart_d <= $wd) {
335  // $tikilib->make_time() used with timezones doesn't support month = 0
336  if ($viewstart_m == 1) {
337  $viewstart_m = 12;
338  $viewstart_y--;
339  } else {
340  $viewstart_m--;
341  }
342 
343  // $tikilib->make_time() used with timezones doesn't support day = 0
344  // This supposes that $viewstart's day == 1, as defined above
345  $viewstart_d = Date_Calc::daysInMonth($viewstart_m, $viewstart_y) - ( $wd - $viewstart_d );
346  } else {
347  $viewstart_d -= $wd;
348  }
349 
350  $viewstart = $tikilib->make_time(0, 0, 0, $viewstart_m, $viewstart_d, $viewstart_y);
351  }
352  $daystart = $viewstart;
353  // then go to the end of the week for $viewend
354  // $viewend = $viewstart + (7 * $d) - 1;
355  $viewend = $tikilib->make_time(
356  0,
357  0,
358  0,
359  (int) TikiLib::date_format("%m", $daystart),
360  (int) TikiLib::date_format("%d", $daystart) + 7,
361  (int) TikiLib::date_format("%Y", $daystart)
362  ) - 1;
363 
364  $dayend = $viewend;
365  $numberofweeks = 0;
366 } else {
367  $firstweek = $currentweek;
369 
370  // $viewend = $viewstart + ($d - 1);
371  $viewend = $tikilib->make_time(
372  0,
373  0,
374  0,
375  (int) TikiLib::date_format("%m", $viewstart),
376  (int) TikiLib::date_format("%d", $viewstart) + 1,
377  (int) TikiLib::date_format("%Y", $viewstart)
378  ) - 1;
379 
380  $dayend = $daystart;
383 }
384 
385 $smarty->assign('viewstart', $viewstart);
386 $smarty->assign('viewend', $viewend);
387 $smarty->assign('numberofweeks', $numberofweeks);
388 $smarty->assign('daystart', $daystart);
389 $smarty->assign('dayend', $dayend);
390 
392 
393 $weeks = [];
394 $cell = [];
395 
396 if (! function_exists('correct_start_day')) {
401  function correct_start_day($d)
402  {
403  global $prefs;
404 
405  if ($prefs['calendar_firstDayofWeek'] !== 'user') {
406  $firstDayofWeek = $prefs['calendar_firstDayofWeek'];
407  } else {
408  $firstDayofWeek = 0; // supposed to be set by a translation?
409  }
410 
411  $tmp = $d - $firstDayofWeek;
412  if ($tmp < 0) {
413  $tmp += 7;
414  }
415  return $tmp;
416  }
417 }
418 
419 if (empty($myurl)) {
420  $myurl = 'tiki-calendar.php';
421 }
422 $jscal_url = "$myurl?todate=%s";
423 $smarty->assign('jscal_url', $jscal_url);
tra
tra($content, $lg='', $unused=false, $args=[])
Definition: tra.php:37
$lastweek
$lastweek
Definition: tiki-calendar_setup.php:368
$focusYear
$focusYear
Definition: tiki-calendar_setup.php:64
$_SESSION
if(! isset($calendarViewMode)) $_SESSION['CalendarViewMode']
Definition: tiki-calendar_setup.php:112
$viewstart
$viewstart
Definition: tiki-calendar_setup.php:219
$focusDay
$focusDay
Definition: tiki-calendar_setup.php:62
$focus_day_limited
$focus_day_limited
Definition: tiki-calendar_setup.php:154
$focusdate
$focusdate
Definition: tiki-calendar_setup.php:61
TikiLib\lib
static lib($name)
Definition: tikilib.php:53
$numberofweeks
$numberofweeks
Definition: tiki-calendar_setup.php:382
$hours
$hours
Definition: tiki-calendar_setup.php:176
$smarty
$smarty
Definition: tiki-calendar_setup.php:26
$calendarlib
if(!($prefs['feature_calendar']=='y'|| $prefs['feature_action_calendar']=='y')) $calendarlib
Definition: tiki-calendar_setup.php:43
$daysnames
$daysnames
Definition: tiki-calendar_edit_item.php:24
$dayend
$dayend
Definition: tiki-calendar_setup.php:380
elseif
if(isset($_GET['msg'])) elseif(isset( $_SESSION[ 'msg']))
Definition: tiki-setup.php:370
$_REQUEST
$_REQUEST["fgal_podcast_dir"]
Definition: include_fgal.php:25
php
$calendarViewGroups
$calendarViewGroups
Definition: tiki-calendar_setup.php:137
TikiLib\date_format
static date_format($format, $timestamp=false, $_user=false, $input_format=5, $is_strftime_format=true)
Definition: tikilib.php:5782
$focus_next
$focus_next
Definition: tiki-calendar_setup.php:162
$weekdays
$weekdays
Definition: tiki-calendar_setup.php:175
$myurl
$myurl
Definition: tiki-action_calendar.php:28
$focus
$focus
Definition: tiki-calendar_setup.php:80
$viewend
$viewend
Definition: tiki-calendar_setup.php:371
$trunc
$trunc
Definition: tiki-calendar_setup.php:45
$_SERVER
$_SERVER
Definition: tiki-installer.php:705
$strRef
$strRef
Definition: tiki-calendar_setup.php:144
$currentweek
$currentweek
Definition: tiki-calendar_setup.php:179
$tikilib
if(strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !=false) $tikilib
Definition: tiki-calendar_setup.php:25
$calendarGroupByItem
$calendarGroupByItem
Definition: tiki-calendar_setup.php:139
$focusMonth
$focusMonth
Definition: tiki-calendar_setup.php:63
exit
exit
Definition: reindex_file.php:61
$calendarViewList
$calendarViewList
Definition: tiki-calendar_setup.php:138
$weeks
$weeks
Definition: tiki-calendar_setup.php:393
$firstDayofWeek
$firstDayofWeek
Definition: tiki-calendar_setup.php:141
Date_Calc\daysInMonth
static daysInMonth($month, $year)
Definition: tikidate.php:488
$d
$d
Definition: tiki-calendar_setup.php:178
$focus_prev
if(! function_exists('cal_days_in_month')) $focus_prev
Definition: tiki-calendar_setup.php:161
$daysnames_abr
$daysnames_abr
Definition: tiki-calendar_edit_item.php:25
$cell
$cell
Definition: tiki-calendar_setup.php:394
$focuscell
$focuscell
Definition: tiki-calendar_setup.php:81
$wd
$wd
Definition: tiki-calendar_setup.php:180
$jscal_url
if(! function_exists('correct_start_day')) if(empty($myurl)) $jscal_url
Definition: tiki-calendar_setup.php:422
die
die
Definition: about.php:68
$prefs
global $prefs
Definition: tiki-calendar_setup.php:27