1<?php 2/** 3 * @package tikiwiki 4 */ 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$section = 'calendar'; 12require_once('tiki-setup.php'); 13$categlib = TikiLib::lib('categ'); 14$calendarlib = TikiLib::lib('calendar'); 15if ($prefs['feature_groupalert'] == 'y') { 16 $groupalertlib = TikiLib::lib('groupalert'); 17} 18$auto_query_args = ['calendarId', 'sort_mode', 'find', 'offset']; 19if (! isset($_REQUEST["calendarId"])) { 20 $access->check_permission(['tiki_p_admin_calendar']); 21 $_REQUEST['calendarId'] = 0; 22} else { 23 $info = $calendarlib->get_calendar($_REQUEST['calendarId']); 24 if (empty($info)) { 25 $smarty->assign('msg', tra('Incorrect param')); 26 $smarty->display('error.tpl'); 27 die; 28 } 29 $objectperms = Perms::get('calendar', $_REQUEST['calendarId']); 30 if (! $objectperms->admin_calendar) { 31 $access->display_error('', tra('Permission denied') . ": " . 'tiki_p_admin_calendar', '403'); 32 } 33} 34if (isset($_REQUEST["drop"]) && $access->checkCsrfForm(tra('Delete calendar?'))) { 35 $result = $calendarlib->drop_calendar($_REQUEST['calendarId']); 36 if ($result->numRows()) { 37 Feedback::success(tr('Calendar %0 deleted', (int) $_REQUEST['calendarId'])); 38 } else { 39 Feedback::error(tr('Calendar %0 not deleted', (int) $_REQUEST['calendarId'])); 40 } 41 $_REQUEST["calendarId"] = 0; 42} 43if (isset($_REQUEST["save"]) && $access->checkCsrf()) { 44 $customflags["customlanguages"] = $_REQUEST["customlanguages"]; 45 $customflags["customlocations"] = $_REQUEST["customlocations"]; 46 $customflags["customparticipants"] = $_REQUEST["customparticipants"]; 47 $customflags["customcategories"] = $_REQUEST["customcategories"]; 48 $customflags["custompriorities"] = $_REQUEST["custompriorities"]; 49 $customflags["customsubscription"] = isset($_REQUEST["customsubscription"]) ? $_REQUEST["customsubscription"] : 'n'; 50 $customflags["personal"] = $_REQUEST["personal"]; 51 $customflags['customstatus'] = isset($_REQUEST['customstatus']) ? $_REQUEST['customstatus'] : 'y'; 52 $options = $_REQUEST['options']; 53 if (array_key_exists('customcolors', $options) && strPos($options['customcolors'], '-') > 0) { 54 $customColors = explode('-', $options['customcolors']); 55 if (! preg_match('/^[0-9a-fA-F]{3,6}$/', $customColors[0])) { 56 $options['customfgcolor'] = '000000'; 57 } else { 58 $options['customfgcolor'] = $customColors[0]; 59 } 60 if (! preg_match('/^[0-9a-fA-F]{3,6}$/', $customColors[1])) { 61 $options['custombgcolor'] = 'ffffff'; 62 } else { 63 $options['custombgcolor'] = $customColors[1]; 64 } 65 } 66 if (! preg_match('/^[0-9a-fA-F]{3,6}$/', $options['customfgcolor'])) { 67 $options['customfgcolor'] = ''; 68 } 69 if (! preg_match('/^[0-9a-fA-F]{3,6}$/', $options['custombgcolor'])) { 70 $options['custombgcolor'] = ''; 71 } 72 //Convert 12-hour clock hours to 24-hour scale to compute time 73 if (! empty($_REQUEST['startday_Meridian'])) { 74 $_REQUEST['startday_Hour'] = date('H', strtotime($_REQUEST['startday_Hour'] . ':00 ' . $_REQUEST['startday_Meridian'])); 75 } 76 if (! empty($_REQUEST['endday_Meridian'])) { 77 $_REQUEST['endday_Hour'] = date('H', strtotime($_REQUEST['endday_Hour'] . ':00 ' . $_REQUEST['endday_Meridian'])); 78 } 79 $options['startday'] = $_REQUEST['startday_Hour'] * 60 * 60; 80 $options['endday'] = $_REQUEST['endday_Hour'] == 0 ? (24 * 60 * 60) - 1 : ($_REQUEST['endday_Hour'] * 60 * 60); 81 $extra = [ 82 'calname', 83 'description', 84 'location', 85 'description', 86 'language', 87 'category', 88 'participants', 89 'url', 90 'status', 91 'status_calview' 92 ]; 93 foreach ($extra as $ex) { 94 if (isset($_REQUEST['show'][$ex]) and $_REQUEST['show'][$ex] == 'on') { 95 $options["show_$ex"] = 'y'; 96 } else { 97 $options["show_$ex"] = 'n'; 98 } 99 } 100 if (isset($_REQUEST['viewdays'])) { 101 $options['viewdays'] = $_REQUEST['viewdays']; 102 } 103 $options['allday'] = isset($_REQUEST['allday']) ? 'y' : 'n'; 104 $options['nameoneachday'] = isset($_REQUEST['nameoneachday']) ? 'y' : 'n'; 105 $_REQUEST["calendarId"] = $calendarlib->set_calendar($_REQUEST["calendarId"], $user, $_REQUEST["name"], $_REQUEST["description"], $customflags, $options); 106 $info = $calendarlib->get_calendar($_REQUEST['calendarId']); 107 if ($prefs['feature_groupalert'] == 'y') { 108 $groupalertlib->AddGroup('calendar', $_REQUEST["calendarId"], $_REQUEST['groupforAlert'], ! empty($_REQUEST['showeachuser']) ? $_REQUEST['showeachuser'] : 'n'); 109 } 110 if ($_REQUEST['personal'] == 'y') { 111 $userlib->assign_object_permission("Registered", $_REQUEST["calendarId"], "calendar", "tiki_p_view_calendar"); 112 $userlib->assign_object_permission("Registered", $_REQUEST["calendarId"], "calendar", "tiki_p_view_events"); 113 $userlib->assign_object_permission("Registered", $_REQUEST["calendarId"], "calendar", "tiki_p_add_events"); 114 $userlib->assign_object_permission("Registered", $_REQUEST["calendarId"], "calendar", "tiki_p_change_events"); 115 } 116 if ($prefs['feature_categories'] == 'y') { 117 $cat_type = 'calendar'; 118 $cat_objid = $_REQUEST["calendarId"]; 119 $cat_desc = $_REQUEST["description"]; 120 $cat_name = $_REQUEST["name"]; 121 $cat_href = "tiki-calendar.php?calIds[]=" . $_REQUEST["calendarId"]; 122 include_once("categorize.php"); 123 } 124 $cookietab = 1; 125 $_REQUEST['calendarId'] = 0; 126} 127if (isset($_REQUEST['clean']) && isset($_REQUEST['days']) && $access->checkCsrfForm(tra('Delete old events?'))) { 128 $result = $calendarlib->cleanEvents($_REQUEST['calendarId'], $_REQUEST['days']); 129 if ($result->numRows() === 1) { 130 Feedback::success(tra('One calendar event deleted')); 131 } elseif ($result->numRows() === 0) { 132 Feedback::note(tra('No calendar events deleted')); 133 } else { 134 Feedback::success(tr('%0 calendar events deleted', $result->numRows())); 135 } 136} 137if ($prefs['feature_categories'] == 'y') { 138 $cat_type = 'calendar'; 139 $cat_objid = $_REQUEST["calendarId"]; 140 include_once("categorize_list.php"); 141 $cs = $categlib->get_object_categories('calendar', $cat_objid); 142 if (! empty($cs)) { 143 for ($i = count($categories) - 1; $i >= 0; --$i) { 144 if (in_array($categories[$i]['categId'], $cs)) { 145 $categories[$i]['incat'] = 'y'; 146 } 147 } 148 } 149} 150if ($_REQUEST['calendarId'] != 0) { 151 $cookietab = 2; 152} else { 153 $info = []; 154 $info["name"] = ''; 155 $info["description"] = ''; 156 $info["customlanguages"] = 'n'; 157 $info["customlocations"] = 'n'; 158 $info["customparticipants"] = 'n'; 159 $info["customcategories"] = 'n'; 160 $info["custompriorities"] = 'n'; 161 $info["customsubscription"] = 'n'; 162 $info['customstatus'] = 'n'; 163 $info["customurl"] = 'n'; 164 $info["customfgcolor"] = ''; 165 $info["custombgcolor"] = ''; 166 $info["show_calname"] = 'y'; 167 $info["show_description"] = 'y'; 168 $info["show_category"] = 'n'; 169 $info["show_location"] = 'n'; 170 $info["show_language"] = 'n'; 171 $info["show_participants"] = 'n'; 172 $info["show_url"] = 'n'; 173 $info['show_status'] = 'n'; 174 $info['show_status_calview'] = ''; 175 $info["user"] = "$user"; 176 $info["personal"] = 'n'; 177 $info["startday"] = '25200'; 178 $info["endday"] = '72000'; 179 $info["allday"] = ''; 180 $info["nameoneachday"] = ''; 181 $info["defaulteventstatus"] = 1; 182 $info['viedays'] = $prefs['calendar_view_days']; 183 if (! empty($_REQUEST['show']) && $_REQUEST['show'] == 'mod') { 184 $cookietab = 2; 185 } else { 186 if (! isset($cookietab)) { 187 $cookietab = 1; 188 } 189 } 190} 191if ($prefs['feature_groupalert'] == 'y') { 192 $info["groupforAlertList"] = []; 193 $info["groupforAlert"] = $groupalertlib->GetGroup('calendar', $_REQUEST["calendarId"]); 194 $all_groups = $userlib->list_all_groups(); 195 if (is_array($all_groups)) { 196 foreach ($all_groups as $g) { 197 $groupforAlertList[$g] = ($g == $info['groupforAlert']) ? 'selected' : ''; 198 } 199 } 200 $showeachuser = $groupalertlib->GetShowEachUser('calendar', $_REQUEST['calendarId'], $info['groupforAlert']); 201 $smarty->assign('groupforAlert', $info['groupforAlert']); 202 $smarty->assign_by_ref('groupforAlertList', $groupforAlertList); 203 $smarty->assign_by_ref('showeachuser', $showeachuser); 204} 205 206 207$smarty->assign('name', $info["name"]); 208$smarty->assign('description', $info["description"]); 209$smarty->assign('owner', $info["user"]); 210$smarty->assign('customlanguages', $info["customlanguages"]); 211$smarty->assign('customlocations', $info["customlocations"]); 212$smarty->assign('customparticipants', $info["customparticipants"]); 213$smarty->assign('customcategories', $info["customcategories"]); 214$smarty->assign('custompriorities', $info["custompriorities"]); 215$smarty->assign('customsubscription', $info["customsubscription"]); 216$smarty->assign('customurl', $info["customurl"]); 217$smarty->assign('customfgcolor', $info["customfgcolor"]); 218$smarty->assign('custombgcolor', $info["custombgcolor"]); 219$smarty->assign('customColors', $info["customfgcolor"] . "-" . $info["custombgcolor"]); 220$smarty->assign('show_calname', $info["show_calname"]); 221$smarty->assign('show_description', $info["show_description"]); 222$smarty->assign('show_category', $info["show_category"]); 223$smarty->assign('show_location', $info["show_location"]); 224$smarty->assign('show_language', $info["show_language"]); 225$smarty->assign('show_participants', $info["show_participants"]); 226$smarty->assign('show_url', $info["show_url"]); 227$smarty->assign('calendarId', $_REQUEST["calendarId"]); 228$smarty->assign('personal', $info["personal"]); 229$smarty->assign('startday', $info["startday"] < 0 ? 0 : $info['startday']); 230$smarty->assign('endday', $info["endday"] < 0 ? 0 : $info['endday']); 231//Use 12- or 24-hour clock for $publishDate time selector based on admin and user preferences 232$userprefslib = TikiLib::lib('userprefs'); 233$smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user)); 234 235$smarty->assign('defaulteventstatus', $info['defaulteventstatus']); 236$smarty->assign( 237 'eventstatus', 238 [ 239 0 => tra('Tentative') , 240 1 => tra('Confirmed') , 241 2 => tra('Cancelled') 242 ] 243); 244$smarty->assign_by_ref('info', $info); 245if (! isset($_REQUEST["sort_mode"])) { 246 $sort_mode = 'name_asc'; 247} else { 248 $sort_mode = $_REQUEST["sort_mode"]; 249} 250$smarty->assign_by_ref('sort_mode', $sort_mode); 251if (isset($_REQUEST["find"])) { 252 $find = $_REQUEST["find"]; 253} else { 254 $find = ''; 255} 256$smarty->assign('find', $find); 257if (! isset($_REQUEST["offset"])) { 258 $offset = 0; 259} else { 260 $offset = $_REQUEST["offset"]; 261} 262$smarty->assign_by_ref('offset', $offset); 263$calendars = $calendarlib->list_calendars($offset, $maxRecords, $sort_mode, $find); 264foreach (array_keys($calendars["data"]) as $i) { 265 $calendars["data"][$i]["individual"] = $userlib->object_has_one_permission($i, 'calendar'); 266} 267$smarty->assign_by_ref('cant', $calendars['cant']); 268$smarty->assign_by_ref('calendars', $calendars["data"]); 269$days_names = [ 270 tra("Sunday"), 271 tra("Monday"), 272 tra("Tuesday"), 273 tra("Wednesday"), 274 tra("Thursday"), 275 tra("Friday"), 276 tra("Saturday") 277]; 278$smarty->assign('days_names', $days_names); 279include_once('tiki-section_options.php'); 280// disallow robots to index page: 281$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW'); 282// Display the template 283$smarty->assign('mid', 'tiki-admin_calendars.tpl'); 284$smarty->display("tiki.tpl"); 285