tiki-admin_calendars.php 10.3 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// 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.
9
// $Id$
changi67's avatar
changi67 committed
10

11
$section = 'calendar';
12
require_once ('tiki-setup.php');
13
$categlib = TikiLib::lib('categ');
14
$calendarlib = TikiLib::lib('calendar');
15
if ($prefs['feature_groupalert'] == 'y') {
16
	$groupalertlib = TikiLib::lib('groupalert');
17
}
18
$auto_query_args = array('calendarId', 'sort_mode', 'find', 'offset');
19
if (!isset($_REQUEST["calendarId"])) {
20 21
	$access->check_permission(array('tiki_p_admin_calendar'));
	$_REQUEST['calendarId'] = 0;
22
} else {
23 24 25 26 27 28
	$info = $calendarlib->get_calendar($_REQUEST['calendarId']);
	if (empty($info)) {
		$smarty->assign('msg', tra('Incorrect param'));
		$smarty->display('error.tpl');
		die;
	}
29
	$objectperms = Perms::get('calendar', $_REQUEST['calendarId']);
30 31
	if (!$objectperms->admin_calendar) {
		$access->display_error('', tra('Permission denied').": ". 'tiki_p_admin_calendar', '403');
32
	}
33
}
34
if (isset($_REQUEST["drop"])) {
35
	$access->check_authenticity();
36
	$calendarlib->drop_calendar($_REQUEST['calendarId']);
37
	$_REQUEST["calendarId"] = 0;
38
}
39
if (isset($_REQUEST["save"])) {
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
	check_ticket('admin-calendars');
	$customflags["customlanguages"] = $_REQUEST["customlanguages"];
	$customflags["customlocations"] = $_REQUEST["customlocations"];
	$customflags["customparticipants"] = $_REQUEST["customparticipants"];
	$customflags["customcategories"] = $_REQUEST["customcategories"];
	$customflags["custompriorities"] = $_REQUEST["custompriorities"];
	$customflags["customsubscription"] = isset($_REQUEST["customsubscription"]) ? $_REQUEST["customsubscription"] : 'n';
	$customflags["personal"] = $_REQUEST["personal"];
	$customflags['customstatus'] = isset($_REQUEST['customstatus']) ? $_REQUEST['customstatus'] : 'y';
	$options = $_REQUEST['options'];
	if (array_key_exists('customcolors', $options) && strPos($options['customcolors'], '-') > 0) {
		$customColors = explode('-', $options['customcolors']);
		if (!preg_match('/^[0-9a-fA-F]{3,6}$/', $customColors[0])) $options['customfgcolor'] = '000000';
		else $options['customfgcolor'] = $customColors[0];
		if (!preg_match('/^[0-9a-fA-F]{3,6}$/', $customColors[1])) $options['custombgcolor'] = 'ffffff';
		else $options['custombgcolor'] = $customColors[1];
	}
	if (!preg_match('/^[0-9a-fA-F]{3,6}$/', $options['customfgcolor'])) $options['customfgcolor'] = '';
	if (!preg_match('/^[0-9a-fA-F]{3,6}$/', $options['custombgcolor'])) $options['custombgcolor'] = '';
59 60 61 62 63 64 65
	//Convert 12-hour clock hours to 24-hour scale to compute time
	if (!empty($_REQUEST['startday_Meridian'])) {
		$_REQUEST['startday_Hour'] = date('H', strtotime($_REQUEST['startday_Hour'] . ':00 ' . $_REQUEST['startday_Meridian']));
	}
	if (!empty($_REQUEST['endday_Meridian'])) {
		$_REQUEST['endday_Hour'] = date('H', strtotime($_REQUEST['endday_Hour'] . ':00 ' . $_REQUEST['endday_Meridian']));
	}
66
	$options['startday'] = $_REQUEST['startday_Hour'] * 60 * 60;
67
	$options['endday'] = $_REQUEST['endday_Hour'] == 0 ? (24 * 60 * 60) - 1 : ($_REQUEST['endday_Hour'] * 60 * 60);
68 69 70 71 72 73 74 75 76 77 78 79
	$extra = array(
		'calname',
		'description',
		'location',
		'description',
		'language',
		'category',
		'participants',
		'url',
		'status',
		'status_calview'
	);
80
	foreach ($extra as $ex) {
81 82 83 84 85 86
		if (isset($_REQUEST['show'][$ex]) and $_REQUEST['show'][$ex] == 'on') {
			$options["show_$ex"] = 'y';
		} else {
			$options["show_$ex"] = 'n';
		}
	}
87
	if (isset($_REQUEST['viewdays'])) $options['viewdays'] = $_REQUEST['viewdays'];
88 89
	$options['allday'] = isset($_REQUEST['allday'])? 'y':'n';
	$options['nameoneachday'] = isset($_REQUEST['nameoneachday'])? 'y': 'n';
90
	$_REQUEST["calendarId"] = $calendarlib->set_calendar($_REQUEST["calendarId"], $user, $_REQUEST["name"], $_REQUEST["description"], $customflags, $options);
91
	$info = $calendarlib->get_calendar($_REQUEST['calendarId']);
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
	if ($prefs['feature_groupalert'] == 'y') {
		$groupalertlib->AddGroup('calendar', $_REQUEST["calendarId"], $_REQUEST['groupforAlert'], !empty($_REQUEST['showeachuser']) ? $_REQUEST['showeachuser'] : 'n');
	}
	if ($_REQUEST['personal'] == 'y') {
		$userlib->assign_object_permission("Registered", $_REQUEST["calendarId"], "calendar", "tiki_p_view_calendar");
		$userlib->assign_object_permission("Registered", $_REQUEST["calendarId"], "calendar", "tiki_p_view_events");
		$userlib->assign_object_permission("Registered", $_REQUEST["calendarId"], "calendar", "tiki_p_add_events");
		$userlib->assign_object_permission("Registered", $_REQUEST["calendarId"], "calendar", "tiki_p_change_events");
	}
	if ($prefs['feature_categories'] == 'y') {
		$cat_type = 'calendar';
		$cat_objid = $_REQUEST["calendarId"];
		$cat_desc = $_REQUEST["description"];
		$cat_name = $_REQUEST["name"];
		$cat_href = "tiki-calendar.php?calIds[]=" . $_REQUEST["calendarId"];
107
		include_once("categorize.php");
108
	}
109 110
	$cookietab=1;
	$_REQUEST['calendarId'] = 0;
111
}
112
if (isset($_REQUEST['clean']) && isset($_REQUEST['days'])) {
113 114
	check_ticket('admin-calendars');
	$calendarlib->cleanEvents($_REQUEST['calendarId'], $_REQUEST['days']);
115
}
116
if ($prefs['feature_categories'] == 'y') {
117 118 119 120 121 122 123 124 125 126 127
	$cat_type = 'calendar';
	$cat_objid = $_REQUEST["calendarId"];
	include_once ("categorize_list.php");
	$cs = $categlib->get_object_categories('calendar', $cat_objid);
	if (!empty($cs)) {
		for ($i = count($categories) - 1; $i >= 0; --$i) {
			if (in_array($categories[$i]['categId'], $cs)) {
				$categories[$i]['incat'] = 'y';
			}
		}
	}
128
}
129
if ($_REQUEST['calendarId'] != 0) {
130
	$cookietab = 2;
131
} else {
132 133 134 135 136 137 138 139 140
	$info = array();
	$info["name"] = '';
	$info["description"] = '';
	$info["customlanguages"] = 'n';
	$info["customlocations"] = 'n';
	$info["customparticipants"] = 'n';
	$info["customcategories"] = 'n';
	$info["custompriorities"] = 'n';
	$info["customsubscription"] = 'n';
141
	$info['customstatus'] = 'n';
142 143 144 145 146 147 148 149 150 151
	$info["customurl"] = 'n';
	$info["customfgcolor"] = '';
	$info["custombgcolor"] = '';
	$info["show_calname"] = 'y';
	$info["show_description"] = 'y';
	$info["show_category"] = 'n';
	$info["show_location"] = 'n';
	$info["show_language"] = 'n';
	$info["show_participants"] = 'n';
	$info["show_url"] = 'n';
sylvieg's avatar
sylvieg committed
152
	$info['show_status'] = 'n';
153
	$info['show_status_calview'] = '';
154 155 156 157
	$info["user"] = "$user";
	$info["personal"] = 'n';
	$info["startday"] = '25200';
	$info["endday"] = '72000';
158 159
	$info["allday"] = '';
	$info["nameoneachday"] = '';
160
	$info["defaulteventstatus"] = 1;
161
	$info['viedays'] = $prefs['calendar_view_days'];
162
	if (!empty($_REQUEST['show']) && $_REQUEST['show'] == 'mod') {
163
		$cookietab = 2;
164
	} else {
165
		if (!isset($cookietab)) {
166
			$cookietab = 1;
167
		}
168
	}
169
}
170
if ($prefs['feature_groupalert'] == 'y') {
171 172 173 174
	$info["groupforAlertList"] = array();
	$info["groupforAlert"] = $groupalertlib->GetGroup('calendar', $_REQUEST["calendarId"]);
	$all_groups = $userlib->list_all_groups();
	if (is_array($all_groups)) {
175
		foreach ($all_groups as $g) {
176 177 178 179 180 181 182
			$groupforAlertList[$g] = ($g == $info['groupforAlert']) ? 'selected' : '';
		}
	}
	$showeachuser = $groupalertlib->GetShowEachUser('calendar', $_REQUEST['calendarId'], $info['groupforAlert']);
	$smarty->assign('groupforAlert', $info['groupforAlert']);
	$smarty->assign_by_ref('groupforAlertList', $groupforAlertList);
	$smarty->assign_by_ref('showeachuser', $showeachuser);
183
}
184 185
setcookie('tab', $cookietab);
$smarty->assign_by_ref('cookietab', $cookietab);
186 187
$smarty->assign('name', $info["name"]);
$smarty->assign('description', $info["description"]);
188
$smarty->assign('owner', $info["user"]);
189 190
$smarty->assign('customlanguages', $info["customlanguages"]);
$smarty->assign('customlocations', $info["customlocations"]);
191
$smarty->assign('customparticipants', $info["customparticipants"]);
192 193
$smarty->assign('customcategories', $info["customcategories"]);
$smarty->assign('custompriorities', $info["custompriorities"]);
194
$smarty->assign('customsubscription', $info["customsubscription"]);
195
$smarty->assign('customurl', $info["customurl"]);
196 197
$smarty->assign('customfgcolor', $info["customfgcolor"]);
$smarty->assign('custombgcolor', $info["custombgcolor"]);
changi67's avatar
changi67 committed
198
$smarty->assign('customColors', $info["customfgcolor"] . "-" . $info["custombgcolor"]);
199 200 201 202 203 204
$smarty->assign('show_calname', $info["show_calname"]);
$smarty->assign('show_description', $info["show_description"]);
$smarty->assign('show_category', $info["show_category"]);
$smarty->assign('show_location', $info["show_location"]);
$smarty->assign('show_language', $info["show_language"]);
$smarty->assign('show_participants', $info["show_participants"]);
205
$smarty->assign('show_url', $info["show_url"]);
206
$smarty->assign('calendarId', $_REQUEST["calendarId"]);
207
$smarty->assign('personal', $info["personal"]);
208 209 210
$smarty->assign('startday', $info["startday"] < 0 ? 0 : $info['startday']);
$smarty->assign('endday', $info["endday"] < 0 ? 0 : $info['endday']);
//Use 12- or 24-hour clock for $publishDate time selector based on admin and user preferences
211
$userprefslib = TikiLib::lib('userprefs');
212
$smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user));
213

214
$smarty->assign('defaulteventstatus', $info['defaulteventstatus']);
215
$smarty->assign(
216 217 218 219 220 221
	'eventstatus',
	array(
		0 => tra('Tentative') ,
		1 => tra('Confirmed') ,
		2 => tra('Cancelled')
	)
222
);
223
$smarty->assign_by_ref('info', $info);
224
if (!isset($_REQUEST["sort_mode"])) {
225
	$sort_mode = 'name_asc';
226
} else {
227
	$sort_mode = $_REQUEST["sort_mode"];
228 229 230
}
$smarty->assign_by_ref('sort_mode', $sort_mode);
if (isset($_REQUEST["find"])) {
231
	$find = $_REQUEST["find"];
232
} else {
233
	$find = '';
234
}
235
$smarty->assign('find', $find);
236
if (!isset($_REQUEST["offset"])) {
237
	$offset = 0;
238
} else {
239
	$offset = $_REQUEST["offset"];
240 241
}
$smarty->assign_by_ref('offset', $offset);
242
$calendars = $calendarlib->list_calendars($offset, $maxRecords, $sort_mode, $find);
243
foreach (array_keys($calendars["data"]) as $i) {
244
	$calendars["data"][$i]["individual"] = $userlib->object_has_one_permission($i, 'calendar');
245
}
246
$smarty->assign_by_ref('cant', $calendars['cant']);
247
$smarty->assign_by_ref('calendars', $calendars["data"]);
248 249 250 251 252 253 254 255 256
$days_names = array(
	tra("Sunday"),
	tra("Monday"),
	tra("Tuesday"),
	tra("Wednesday"),
	tra("Thursday"),
	tra("Friday"),
	tra("Saturday")
);
257
$smarty->assign('days_names', $days_names);
258
include_once ('tiki-section_options.php');
259
ask_ticket('admin-calendars');
260 261
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
262
// Display the template
263
$smarty->assign('uses_tabs', 'y');
264
$smarty->assign('mid', 'tiki-admin_calendars.tpl');
265
$smarty->display("tiki.tpl");