tiki-admin_calendars.php 10.1 KB
Newer Older
1
<?php
2 3
// (c) Copyright 2002-2009 by authors of the Tiki Wiki/CMS/Groupware Project
// 
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: /cvsroot/tikiwiki/tiki/tiki-admin_calendars.php,v 1.34.2.2 2008-02-12 19:20:11 sylvieg Exp $
7
$section = 'calendar';
8
require_once ('tiki-setup.php');
9
require_once ('lib/categories/categlib.php');
10
include_once ('lib/calendar/calendarlib.php');
11
if ($prefs['feature_groupalert'] == 'y') {
12
	include_once ('lib/groupalert/groupalertlib.php');
13
}
mose's avatar
mose committed
14
if ($tiki_p_admin_calendar != 'y' and $tiki_p_admin != 'y') {
15 16 17 18
	$smarty->assign('errortype', 401);
	$smarty->assign('msg', tra("You do not have permission to use this feature"));
	$smarty->display("error.tpl");
	die;
19
}
20
if (!isset($_REQUEST["calendarId"])) {
21
	$_REQUEST["calendarId"] = 0;
22
} else {
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
	// Check if calendar belongs to perspective
	$category_jails = $categlib->get_jail();
	if(!isset($filter['categId']) && !empty($category_jails))
	{
		$categories = $categlib->get_object_categories('calendar', $_REQUEST["calendarId"]);
		if (empty ($categories))
			$smarty->assign('individual', $userlib->object_has_one_permission($_REQUEST["calendarId"], 'calendar'));
		else
		{
			$intersection = array_intersect($category, $category_jails);
			if (!empty ($intersection))
				$smarty->assign('individual', $userlib->object_has_one_permission($_REQUEST["calendarId"], 'calendar'));
			else
			{
					$smarty->assign('errortype', 404);
					$smarty->assign('msg',tra("Object doesn't exists"));
					$smarty->display("error.tpl");
					die;
			}
		}
	}
	
45
}
46
if (isset($_REQUEST["drop"])) {
47 48 49 50 51 52 53 54
	$area = "delcalendar";
	if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
		key_check($area);
		$calendarlib->drop_calendar($_REQUEST["drop"]);
		$_REQUEST["calendarId"] = 0;
	} else {
		key_get($area);
	}
55
}
56
if (isset($_REQUEST["save"])) {
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
	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'] = '';
	$options['startday'] = $_REQUEST['startday_Hour'] * 60 * 60;
	$options['endday'] = $_REQUEST['endday_Hour'] * 60 * 60 - 1;
	$extra = array(
		'calname',
		'description',
		'location',
		'description',
		'language',
		'category',
		'participants',
		'url',
		'status',
		'status_calview'
	);
	foreach($extra as $ex) {
		if (isset($_REQUEST['show'][$ex]) and $_REQUEST['show'][$ex] == 'on') {
			$options["show_$ex"] = 'y';
		} else {
			$options["show_$ex"] = 'n';
		}
	}
	$_REQUEST["calendarId"] = $calendarlib->set_calendar($_REQUEST["calendarId"], $user, $_REQUEST["name"], $_REQUEST["description"], $customflags, $options);
	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"];
		include_once ("categorize.php");
	}
115
}
116
if (isset($_REQUEST['clean']) && isset($_REQUEST['days'])) {
117 118
	check_ticket('admin-calendars');
	$calendarlib->cleanEvents($_REQUEST['calendarId'], $_REQUEST['days']);
119
}
120
if ($prefs['feature_categories'] == 'y') {
121 122 123 124 125 126 127 128 129 130 131
	$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';
			}
		}
	}
132
}
133
if ($_REQUEST["calendarId"]) {
134 135
	$info = $calendarlib->get_calendar($_REQUEST["calendarId"]);
	$cookietab = 2;
136
} else {
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
	$info = array();
	$info["name"] = '';
	$info["description"] = '';
	$info["customlanguages"] = 'n';
	$info["customlocations"] = 'n';
	$info["customparticipants"] = 'n';
	$info["customcategories"] = 'n';
	$info["custompriorities"] = 'n';
	$info["customsubscription"] = 'n';
	$info['customstatus'] = 'y';
	$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';
	$info["user"] = "$user";
	$info["personal"] = 'n';
	$info["startday"] = '25200';
	$info["endday"] = '72000';
	$info["defaulteventstatus"] = 0;
	if (!empty($_REQUEST['show']) && $_REQUEST['show'] == 'mod') {
		$cookietab = '2';
	} else {
165
		if (!isset($cookietab)) { $cookietab = '1'; }
166
	}
167
}
168
if ($prefs['feature_groupalert'] == 'y') {
169 170 171 172 173 174 175 176 177 178 179 180
	$info["groupforAlertList"] = array();
	$info["groupforAlert"] = $groupalertlib->GetGroup('calendar', $_REQUEST["calendarId"]);
	$all_groups = $userlib->list_all_groups();
	if (is_array($all_groups)) {
		foreach($all_groups as $g) {
			$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);
181
}
182 183
setcookie('tab', $cookietab);
$smarty->assign_by_ref('cookietab', $cookietab);
184 185
$smarty->assign('name', $info["name"]);
$smarty->assign('description', $info["description"]);
186
$smarty->assign('owner', $info["user"]);
187 188
$smarty->assign('customlanguages', $info["customlanguages"]);
$smarty->assign('customlocations', $info["customlocations"]);
189
$smarty->assign('customparticipants', $info["customparticipants"]);
190 191
$smarty->assign('customcategories', $info["customcategories"]);
$smarty->assign('custompriorities', $info["custompriorities"]);
192
$smarty->assign('customsubscription', $info["customsubscription"]);
193
$smarty->assign('customurl', $info["customurl"]);
194 195
$smarty->assign('customfgcolor', $info["customfgcolor"]);
$smarty->assign('custombgcolor', $info["custombgcolor"]);
changi67's avatar
changi67 committed
196
$smarty->assign('customColors', $info["customfgcolor"] . "-" . $info["custombgcolor"]);
197 198 199 200 201 202
$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"]);
203
$smarty->assign('show_url', $info["show_url"]);
204
$smarty->assign('calendarId', $_REQUEST["calendarId"]);
205
$smarty->assign('personal', $info["personal"]);
changi67's avatar
changi67 committed
206 207 208
$smarty->assign('startday', $info["startday"] < 0 ? 0 : round($info['startday'] / (60 * 60)));
$smarty->assign('endday', $info["endday"] < 0 ? 0 : round($info['endday'] / (60 * 60)));
$smarty->assign('hours', array(
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
	'0',
	'1',
	'2',
	'3',
	'4',
	'5',
	'6',
	'7',
	'8',
	'9',
	'10',
	'11',
	'12',
	'13',
	'14',
	'15',
	'16',
	'17',
	'18',
	'19',
	'20',
	'21',
	'22',
	'23'
changi67's avatar
changi67 committed
233
));
234
$smarty->assign('defaulteventstatus', $info['defaulteventstatus']);
235
$smarty->assign('eventstatus', array(
236 237 238
	0 => tra('Tentative') ,
	1 => tra('Confirmed') ,
	2 => tra('Cancelled')
changi67's avatar
changi67 committed
239
));
240
$smarty->assign_by_ref('info', $info);
241
if (!isset($_REQUEST["sort_mode"])) {
242
	$sort_mode = 'name_desc';
243
} else {
244
	$sort_mode = $_REQUEST["sort_mode"];
245 246 247
}
$smarty->assign_by_ref('sort_mode', $sort_mode);
if (isset($_REQUEST["find"])) {
248
	$find = $_REQUEST["find"];
249
} else {
250
	$find = '';
251
}
252
$smarty->assign('find', $find);
253
if (!isset($_REQUEST["offset"])) {
254
	$offset = 0;
255
} else {
256
	$offset = $_REQUEST["offset"];
257 258
}
$smarty->assign_by_ref('offset', $offset);
259
$calendars = $calendarlib->list_calendars($offset, $maxRecords, $sort_mode, $find);
changi67's avatar
changi67 committed
260
foreach(array_keys($calendars["data"]) as $i) {
261
	$calendars["data"][$i]["individual"] = $userlib->object_has_one_permission($i, 'calendar');
262
}
263
$smarty->assign_by_ref('cant', $calendars['cant']);
264
$smarty->assign_by_ref('calendars', $calendars["data"]);
mose's avatar
mose committed
265 266 267
// $cat_type = 'calendar';
// $cat_objid = $_REQUEST["calendarId"];
// include_once ("categorize_list.php");
268
include_once ('tiki-section_options.php');
269
ask_ticket('admin-calendars');
270 271
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
272
// Display the template
273
$smarty->assign('uses_tabs', 'y');
274
$smarty->assign('mid', 'tiki-admin_calendars.tpl');
275
$smarty->display("tiki.tpl");