tiki-minical.php 6.93 KB
Newer Older
lrargerich's avatar
Stuff  
lrargerich committed
1
<?php
2
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3
// 
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6
// $Id$
changi67's avatar
changi67 committed
7

8
$section = 'calendar';
changi67's avatar
changi67 committed
9 10
require_once ('tiki-setup.php');
include_once ('lib/minical/minicallib.php');
11 12 13
$access->check_feature('feature_minical');
$access->check_user($user);
$access->check_permission('tiki_p_minical');
changi67's avatar
changi67 committed
14
if (!isset($_REQUEST["eventId"])) $_REQUEST["eventId"] = 0;
15
if (isset($_REQUEST['remove'])) {
16 17
	$access->check_authenticity();
	$minicallib->minical_remove_event($user, $_REQUEST['remove']);
lrargerich's avatar
Stuff  
lrargerich committed
18
}
19
if (isset($_REQUEST['remove2'])) {
20 21
	$access->check_authenticity();
	$minicallib->minical_remove_event($user, $_REQUEST['eventId']);
22 23
}
if (isset($_REQUEST['delete'])) {
24
	$access->check_authenticity();
25
	foreach (array_keys($_REQUEST["event"]) as $ev) {
26
		$minicallib->minical_remove_event($user, $ev);
27
	}
lrargerich's avatar
Stuff  
lrargerich committed
28
}
29
if (isset($_REQUEST['day']) && isset($_REQUEST['mon']) && isset($_REQUEST['year'])) {
30
	$pdate = mktime(0, 0, 0, $_REQUEST['mon'], $_REQUEST['day'], $_REQUEST['year']);
lrargerich's avatar
Stuff  
lrargerich committed
31
} else {
32
	if (isset($_SESSION['thedate'])) {
33
		$pdate = mktime(0, 0, 0, date("m", $_SESSION['thedate']), date("d", $_SESSION['thedate']), date("Y", $_SESSION['thedate']));
34
	} else {
35
		$pdate = date("U");
36
	}
lrargerich's avatar
Stuff  
lrargerich committed
37
}
38 39 40 41
$yesterday = $pdate - 60 * 60 * 24;
$tomorrow = $pdate + 60 * 60 * 24;
$smarty->assign('yesterday', $yesterday);
$smarty->assign('tomorrow', $tomorrow);
42 43 44 45
$smarty->assign('day', date("d", $pdate));
$smarty->assign('mon', date("m", $pdate));
$smarty->assign('year', date("Y", $pdate));
$pdate_h = mktime(date("G"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate));
46 47 48
$smarty->assign('pdate', $pdate);
$smarty->assign('pdate_h', $pdate_h);
if (isset($_REQUEST['removeold'])) {
49 50
	$access->check_authenticity();
	$minicallib->minical_remove_old($user, $pdate_h);
lrargerich's avatar
Stuff  
lrargerich committed
51
}
52 53 54 55
if ($_REQUEST["eventId"]) {
	$info = $minicallib->minical_get_event($user, $_REQUEST["eventId"]);
	$ev_pdate = $info['start'];
	$ev_pdate_h = $info['start'];
lrargerich's avatar
Stuff  
lrargerich committed
56
} else {
57 58 59 60
	$info = array();
	$info['title'] = '';
	$info['topicId'] = 0;
	$info['description'] = '';
61
	$info['start'] = mktime(date("H"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate));
62
	$info['duration'] = 60 * 60;
lrargerich's avatar
Stuff  
lrargerich committed
63
}
64 65
$smarty->assign('ev_pdate', $ev_pdate);
$smarty->assign('ev_pdate_h', $ev_pdate_h);
66

67
if (isset($_REQUEST['save'])) {
68
	check_ticket('minical');
69 70 71 72
	//Convert 12-hour clock hours to 24-hour scale to compute time
	if (!empty($_REQUEST['Time_Meridian'])) {
		$_REQUEST['Time_Hour'] = date('H', strtotime($_REQUEST['Time_Hour'] . ':00 ' . $_REQUEST['Time_Meridian']));
	}
changi67's avatar
changi67 committed
73 74
	$start = mktime($_REQUEST['Time_Hour'], $_REQUEST['Time_Minute'], 0, $_REQUEST['Date_Month'], $_REQUEST['Date_Day'], $_REQUEST['Date_Year']);
	$minicallib->minical_replace_event($user, $_REQUEST["eventId"], $_REQUEST["title"], $_REQUEST["description"], $start, ($_REQUEST['duration_hours'] * 60 * 60) + ($_REQUEST['duration_minutes'] * 60), $_REQUEST['topicId']);
75 76 77 78
	$info = array();
	$info['title'] = '';
	$info['topicId'] = 0;
	$info['description'] = '';
79
	$info['start'] = mktime(date("h"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate));
80 81
	$info['duration'] = 60 * 60;
	$_REQUEST["eventId"] = 0;
lrargerich's avatar
Stuff  
lrargerich committed
82
}
83 84
$smarty->assign('eventId', $_REQUEST["eventId"]);
$smarty->assign('info', $info);
lrargerich's avatar
lrargerich committed
85
//Check here the interval for the calendar
86 87
if (!isset($_REQUEST['view'])) {
	$_REQUEST['view'] = 'daily';
lrargerich's avatar
lrargerich committed
88
}
89 90 91 92 93 94
$smarty->assign('view', $_REQUEST['view']);
$minical_interval = $tikilib->get_user_preference($user, 'minical_interval', 60 * 60);
$minical_start_hour = $tikilib->get_user_preference($user, 'minical_start_hour', 9);
$minical_end_hour = $tikilib->get_user_preference($user, 'minical_end_hour', 20);
$minical_public = $tikilib->get_user_preference($user, 'minical_public', 'n');
$minical_upcoming = $tikilib->get_user_preference($user, 'minical_upcoming', 7);
lrargerich's avatar
lrargerich committed
95
// Interval is in hours
96 97 98 99
if ($_REQUEST['view'] == 'daily') {
	$tempdate = $pdate - $pdate % (24 * 60 * 60); /// added by Wells Wang to solve Mini Cal Event List Wrong Time BUG
	$slot_start = $tempdate + 60 * 60 * $minical_start_hour;
	$slot_end = $tempdate + 60 * 60 * $minical_end_hour;
100
	$interval = $minical_interval;
lrargerich's avatar
lrargerich committed
101
}
102
// end of modification
103 104
if ($_REQUEST['view'] == 'weekly') {
	$interval = 24 * 60 * 60;
lrargerich's avatar
lrargerich committed
105
	// Determine weekday
106
	$wd = date('w', $pdate);
changi67's avatar
changi67 committed
107
	if ($wd == 0) $wd = 7;
108
	$wd = $wd - 1;
lrargerich's avatar
lrargerich committed
109
	// Now get the number of days to substract
110 111 112 113 114 115 116 117 118 119
	$week_start = $pdate - ($wd * 60 * 60 * 24);
	$week_end = $week_start + 60 * 60 * 24 * 7 - 1;
	$smarty->assign('week_start', $week_start);
	$smarty->assign('week_end', $week_end);
	$next_week_start = $week_end + 1;
	$smarty->assign('next_week_start', $next_week_start);
	$prev_week_start = $week_start - (60 * 60 * 24 * 7);
	$smarty->assign('prev_week_start', $prev_week_start);
	$slot_start = $pdate - ($wd * 60 * 60 * 24);
	$slot_end = $slot_start + 60 * 60 * 24 * 7 - 1;
lrargerich's avatar
lrargerich committed
120
}
121 122 123 124 125
if ($_REQUEST['view'] == 'daily' || $_REQUEST['view'] == 'weekly') {
	$smarty->assign('slot_start', $slot_start);
	$smarty->assign('slot_end', $slot_end);
	$events = $minicallib->minical_events_by_slot($user, $slot_start, $slot_end, $interval);
	$smarty->assign_by_ref('slots', $events);
lrargerich's avatar
stuff  
lrargerich committed
126 127
}
// List view
128 129 130
if ($_REQUEST['view'] == 'list') {
	if (!isset($_REQUEST["sort_mode"])) {
		$sort_mode = 'start_asc';
lrargerich's avatar
stuff  
lrargerich committed
131
	} else {
132 133 134 135
		$sort_mode = $_REQUEST["sort_mode"];
	}
	if (!isset($_REQUEST["offset"])) {
		$offset = 0;
lrargerich's avatar
stuff  
lrargerich committed
136
	} else {
137
		$offset = $_REQUEST["offset"];
lrargerich's avatar
stuff  
lrargerich committed
138
	}
139 140 141
	$smarty->assign_by_ref('offset', $offset);
	if (isset($_REQUEST["find"])) {
		$find = $_REQUEST["find"];
lrargerich's avatar
stuff  
lrargerich committed
142
	} else {
143
		$find = '';
lrargerich's avatar
stuff  
lrargerich committed
144
	}
145 146 147 148
	$smarty->assign('find', $find);
	$smarty->assign_by_ref('sort_mode', $sort_mode);
	if (isset($_SESSION['thedate'])) {
		$pdate = $_SESSION['thedate'];
lrargerich's avatar
stuff  
lrargerich committed
149
	} else {
150
		$pdate = date("U");
lrargerich's avatar
stuff  
lrargerich committed
151
	}
152
	$channels = $minicallib->minical_list_events($user, $offset, $maxRecords, $sort_mode, $find);
153
	$smarty->assign_by_ref('cant_pages', $channels["cant"]);
154 155 156 157
	$smarty->assign('channels', $channels["data"]);
}
$upcoming = $minicallib->minical_list_events_from_date($user, 0, $minical_upcoming, 'start_asc', '', $pdate_h);
$smarty->assign('upcoming', $upcoming['data']);
158 159 160 161
//Use 12- or 24-hour clock for $publishDate time selector based on admin and user preferences
include_once ('lib/userprefs/userprefslib.php');
$smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user));

162 163 164 165 166 167 168 169 170 171
$hours = range(0, 23);
$smarty->assign('hours', $hours);
$minutes = range(0, 59);
$smarty->assign('minutes', $minutes);
$duration_hours = $info['duration'] / (60 * 60);
$duration_minutes = $info['duration'] % (60 * 60);
$smarty->assign('duration_hours', $duration_hours);
$smarty->assign('duration_minutes', $duration_minutes);
$topics = $minicallib->minical_list_topics($user, 0, -1, 'name_asc', '');
$smarty->assign('topics', $topics['data']);
172
include_once ('tiki-section_options.php');
changi67's avatar
changi67 committed
173
include_once ('tiki-mytiki_shared.php');
174
ask_ticket('minical');
175
$smarty->assign('mid', 'tiki-minical.tpl');
176
$smarty->display("tiki.tpl");