1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8$section = 'calendar'; 9require_once('tiki-setup.php'); 10include_once('lib/minical/minicallib.php'); 11$access->check_feature('feature_minical'); 12$access->check_user($user); 13$access->check_permission('tiki_p_minical'); 14if (! isset($_REQUEST["eventId"])) { 15 $_REQUEST["eventId"] = 0; 16} 17if (isset($_REQUEST['remove'])) { 18 $access->check_authenticity(); 19 $minicallib->minical_remove_event($user, $_REQUEST['remove']); 20} 21if (isset($_REQUEST['remove2'])) { 22 $access->check_authenticity(); 23 $minicallib->minical_remove_event($user, $_REQUEST['eventId']); 24} 25if (isset($_REQUEST['delete'])) { 26 $access->check_authenticity(); 27 foreach (array_keys($_REQUEST["event"]) as $ev) { 28 $minicallib->minical_remove_event($user, $ev); 29 } 30} 31if (isset($_REQUEST['day']) && isset($_REQUEST['mon']) && isset($_REQUEST['year'])) { 32 $pdate = mktime(0, 0, 0, $_REQUEST['mon'], $_REQUEST['day'], $_REQUEST['year']); 33} else { 34 if (isset($_SESSION['thedate'])) { 35 $pdate = mktime(0, 0, 0, date("m", $_SESSION['thedate']), date("d", $_SESSION['thedate']), date("Y", $_SESSION['thedate'])); 36 } else { 37 $pdate = date("U"); 38 } 39} 40$yesterday = $pdate - 60 * 60 * 24; 41$tomorrow = $pdate + 60 * 60 * 24; 42$smarty->assign('yesterday', $yesterday); 43$smarty->assign('tomorrow', $tomorrow); 44$smarty->assign('day', date("d", $pdate)); 45$smarty->assign('mon', date("m", $pdate)); 46$smarty->assign('year', date("Y", $pdate)); 47$pdate_h = mktime(date("G"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate)); 48$smarty->assign('pdate', $pdate); 49$smarty->assign('pdate_h', $pdate_h); 50if (isset($_REQUEST['removeold'])) { 51 $access->check_authenticity(); 52 $minicallib->minical_remove_old($user, $pdate_h); 53} 54if ($_REQUEST["eventId"]) { 55 $info = $minicallib->minical_get_event($user, $_REQUEST["eventId"]); 56 $ev_pdate = $info['start']; 57 $ev_pdate_h = $info['start']; 58} else { 59 $info = []; 60 $info['title'] = ''; 61 $info['topicId'] = 0; 62 $info['description'] = ''; 63 $info['start'] = mktime(date("H"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate)); 64 $info['duration'] = 60 * 60; 65} 66$smarty->assign('ev_pdate', $ev_pdate); 67$smarty->assign('ev_pdate_h', $ev_pdate_h); 68 69if (isset($_REQUEST['save'])) { 70 check_ticket('minical'); 71 //Convert 12-hour clock hours to 24-hour scale to compute time 72 if (! empty($_REQUEST['Time_Meridian'])) { 73 $_REQUEST['Time_Hour'] = date('H', strtotime($_REQUEST['Time_Hour'] . ':00 ' . $_REQUEST['Time_Meridian'])); 74 } 75 $start = mktime($_REQUEST['Time_Hour'], $_REQUEST['Time_Minute'], 0, $_REQUEST['Date_Month'], $_REQUEST['Date_Day'], $_REQUEST['Date_Year']); 76 $minicallib->minical_replace_event($user, $_REQUEST["eventId"], $_REQUEST["title"], $_REQUEST["description"], $start, ($_REQUEST['duration_hours'] * 60 * 60) + ($_REQUEST['duration_minutes'] * 60), $_REQUEST['topicId']); 77 $info = []; 78 $info['title'] = ''; 79 $info['topicId'] = 0; 80 $info['description'] = ''; 81 $info['start'] = mktime(date("h"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate)); 82 $info['duration'] = 60 * 60; 83 $_REQUEST["eventId"] = 0; 84} 85$smarty->assign('eventId', $_REQUEST["eventId"]); 86$smarty->assign('info', $info); 87//Check here the interval for the calendar 88if (! isset($_REQUEST['view'])) { 89 $_REQUEST['view'] = 'daily'; 90} 91$smarty->assign('view', $_REQUEST['view']); 92$minical_interval = $tikilib->get_user_preference($user, 'minical_interval', 60 * 60); 93$minical_start_hour = $tikilib->get_user_preference($user, 'minical_start_hour', 9); 94$minical_end_hour = $tikilib->get_user_preference($user, 'minical_end_hour', 20); 95$minical_public = $tikilib->get_user_preference($user, 'minical_public', 'n'); 96$minical_upcoming = $tikilib->get_user_preference($user, 'minical_upcoming', 7); 97// Interval is in hours 98if ($_REQUEST['view'] == 'daily') { 99 $tempdate = $pdate - $pdate % (24 * 60 * 60); /// added by Wells Wang to solve Mini Cal Event List Wrong Time BUG 100 $slot_start = $tempdate + 60 * 60 * $minical_start_hour; 101 $slot_end = $tempdate + 60 * 60 * $minical_end_hour; 102 $interval = $minical_interval; 103} 104// end of modification 105if ($_REQUEST['view'] == 'weekly') { 106 $interval = 24 * 60 * 60; 107 // Determine weekday 108 $wd = date('w', $pdate); 109 if ($wd == 0) { 110 $wd = 7; 111 } 112 $wd = $wd - 1; 113 // Now get the number of days to substract 114 $week_start = $pdate - ($wd * 60 * 60 * 24); 115 $week_end = $week_start + 60 * 60 * 24 * 7 - 1; 116 $smarty->assign('week_start', $week_start); 117 $smarty->assign('week_end', $week_end); 118 $next_week_start = $week_end + 1; 119 $smarty->assign('next_week_start', $next_week_start); 120 $prev_week_start = $week_start - (60 * 60 * 24 * 7); 121 $smarty->assign('prev_week_start', $prev_week_start); 122 $slot_start = $pdate - ($wd * 60 * 60 * 24); 123 $slot_end = $slot_start + 60 * 60 * 24 * 7 - 1; 124} 125if ($_REQUEST['view'] == 'daily' || $_REQUEST['view'] == 'weekly') { 126 $smarty->assign('slot_start', $slot_start); 127 $smarty->assign('slot_end', $slot_end); 128 $events = $minicallib->minical_events_by_slot($user, $slot_start, $slot_end, $interval); 129 $smarty->assign_by_ref('slots', $events); 130} 131// List view 132if ($_REQUEST['view'] == 'list') { 133 if (! isset($_REQUEST["sort_mode"])) { 134 $sort_mode = 'start_asc'; 135 } else { 136 $sort_mode = $_REQUEST["sort_mode"]; 137 } 138 if (! isset($_REQUEST["offset"])) { 139 $offset = 0; 140 } else { 141 $offset = $_REQUEST["offset"]; 142 } 143 $smarty->assign_by_ref('offset', $offset); 144 if (isset($_REQUEST["find"])) { 145 $find = $_REQUEST["find"]; 146 } else { 147 $find = ''; 148 } 149 $smarty->assign('find', $find); 150 $smarty->assign_by_ref('sort_mode', $sort_mode); 151 if (isset($_SESSION['thedate'])) { 152 $pdate = $_SESSION['thedate']; 153 } else { 154 $pdate = date("U"); 155 } 156 $channels = $minicallib->minical_list_events($user, $offset, $maxRecords, $sort_mode, $find); 157 $smarty->assign_by_ref('cant_pages', $channels["cant"]); 158 $smarty->assign('channels', $channels["data"]); 159} 160$upcoming = $minicallib->minical_list_events_from_date($user, 0, $minical_upcoming, 'start_asc', '', $pdate_h); 161$smarty->assign('upcoming', $upcoming['data']); 162//Use 12- or 24-hour clock for $publishDate time selector based on admin and user preferences 163$userprefslib = TikiLib::lib('userprefs'); 164$smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user)); 165 166$hours = range(0, 23); 167$smarty->assign('hours', $hours); 168$minutes = range(0, 59); 169$smarty->assign('minutes', $minutes); 170$duration_hours = $info['duration'] / (60 * 60); 171$duration_minutes = $info['duration'] % (60 * 60); 172$smarty->assign('duration_hours', $duration_hours); 173$smarty->assign('duration_minutes', $duration_minutes); 174$topics = $minicallib->minical_list_topics($user, 0, -1, 'name_asc', ''); 175$smarty->assign('topics', $topics['data']); 176include_once('tiki-section_options.php'); 177include_once('tiki-mytiki_shared.php'); 178ask_ticket('minical'); 179$smarty->assign('mid', 'tiki-minical.tpl'); 180$smarty->display("tiki.tpl"); 181