tiki-minical.php 7.96 KB
Newer Older
lrargerich's avatar
Stuff  
lrargerich committed
1
<?php
2

3
// $Id: /cvsroot/tikiwiki/tiki/tiki-minical.php,v 1.26.2.1 2007-11-04 21:49:20 nyloth Exp $
4

5
// Copyright (c) 2002-2007, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
6 7
// 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.
8
$section = 'calendar';
lrargerich's avatar
Stuff  
lrargerich committed
9
require_once('tiki-setup.php');
10
if ($prefs['feature_ajax'] == "y") {
tombombadilom's avatar
tombombadilom committed
11 12
require_once ('lib/ajax/ajaxlib.php');
}
lrargerich's avatar
Stuff  
lrargerich committed
13 14
include_once('lib/minical/minicallib.php');

15
if ($prefs['feature_minical'] != 'y') {
16
	$smarty->assign('msg', tra("This feature is disabled").": feature_minical");
lrargerich's avatar
Stuff  
lrargerich committed
17

18
	$smarty->display("error.tpl");
19
	die;
lrargerich's avatar
Stuff  
lrargerich committed
20 21
}

22 23 24
if (!$user) {
	$smarty->assign('msg', tra("Must be logged to use this feature"));

25
	$smarty->display("error.tpl");
26 27
	die;
}
lrargerich's avatar
Stuff  
lrargerich committed
28

29
if ($tiki_p_minical != 'y') {
30
	$smarty->assign('errortype', 401);
31 32 33 34 35 36 37
	$smarty->assign('msg', tra("Permission denied"));

	$smarty->display("error.tpl");
	die;
}


38 39
if (!isset($_REQUEST["eventId"]))
	$_REQUEST["eventId"] = 0;
lrargerich's avatar
Stuff  
lrargerich committed
40

41
if (isset($_REQUEST['remove'])) {
mose's avatar
mose committed
42
  $area = 'delminicalevent';
43
  if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
mose's avatar
mose committed
44 45 46 47 48
    key_check($area);
		$minicallib->minical_remove_event($user, $_REQUEST['remove']);
  } else {
    key_get($area);
  }
lrargerich's avatar
Stuff  
lrargerich committed
49 50
}

51
if (isset($_REQUEST['remove2'])) {
mose's avatar
mose committed
52
  $area = 'delminicalevent2';
53
  if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
mose's avatar
mose committed
54
    key_check($area);
55
	$minicallib->minical_remove_event($user, $_REQUEST['eventId']);
mose's avatar
mose committed
56 57
  } else {
    key_get($area);
58
  }
59
}
lrargerich's avatar
stuff  
lrargerich committed
60

61
if (isset($_REQUEST['delete'])) {
mose's avatar
mose committed
62
  $area = 'delminical';
63
  if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
mose's avatar
mose committed
64
    key_check($area);
65 66 67
	foreach (array_keys($_REQUEST["event"])as $ev) {
		$minicallib->minical_remove_event($user, $ev);
	}
mose's avatar
mose committed
68 69 70
  } else {
    key_get($area);
  }
lrargerich's avatar
Stuff  
lrargerich committed
71 72
}

73
if (isset($_REQUEST['day']) && isset($_REQUEST['mon']) && isset($_REQUEST['year'])) {
74
	$pdate = mktime(0, 0, 0, $_REQUEST['mon'], $_REQUEST['day'], $_REQUEST['year']);
lrargerich's avatar
Stuff  
lrargerich committed
75
} else {
76
	if (isset($_SESSION['thedate'])) {
77
		$pdate = mktime(0, 0, 0, date("m", $_SESSION['thedate']), date("d", $_SESSION['thedate']), date("Y", $_SESSION['thedate']));
78
	} else {
79
		$pdate = date("U");
80
	}
lrargerich's avatar
Stuff  
lrargerich committed
81
}
82 83 84 85 86

$yesterday = $pdate - 60 * 60 * 24;
$tomorrow = $pdate + 60 * 60 * 24;
$smarty->assign('yesterday', $yesterday);
$smarty->assign('tomorrow', $tomorrow);
87 88 89 90
$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));
91 92 93 94
$smarty->assign('pdate', $pdate);
$smarty->assign('pdate_h', $pdate_h);

if (isset($_REQUEST['removeold'])) {
mose's avatar
mose committed
95
  $area = 'delminicaloldevents';
96
  if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
mose's avatar
mose committed
97 98 99 100 101
    key_check($area);
		$minicallib->minical_remove_old($user, $pdate_h);
  } else {
    key_get($area);
  }
lrargerich's avatar
Stuff  
lrargerich committed
102
}
103 104 105 106 107

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
108
} else {
109 110 111 112 113
	$info = array();

	$info['title'] = '';
	$info['topicId'] = 0;
	$info['description'] = '';
114
	$info['start'] = mktime(date("H"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate));
115
	$info['duration'] = 60 * 60;
lrargerich's avatar
Stuff  
lrargerich committed
116 117
}

118 119 120 121
$smarty->assign('ev_pdate', $ev_pdate);
$smarty->assign('ev_pdate_h', $ev_pdate_h);

if (isset($_REQUEST['save'])) {
122
	check_ticket('minical');
123
	$start = mktime($_REQUEST['Time_Hour'], $_REQUEST['Time_Minute'],
124 125 126 127 128 129 130 131
		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']);
	$info = array();
	$info['title'] = '';
	$info['topicId'] = 0;
	$info['description'] = '';
132
	$info['start'] = mktime(date("h"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate));
133 134
	$info['duration'] = 60 * 60;
	$_REQUEST["eventId"] = 0;
lrargerich's avatar
Stuff  
lrargerich committed
135
}
136 137 138

$smarty->assign('eventId', $_REQUEST["eventId"]);
$smarty->assign('info', $info);
lrargerich's avatar
Stuff  
lrargerich committed
139

lrargerich's avatar
lrargerich committed
140
//Check here the interval for the calendar
141 142
if (!isset($_REQUEST['view'])) {
	$_REQUEST['view'] = 'daily';
lrargerich's avatar
lrargerich committed
143 144
}

145 146 147 148 149 150 151
$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);
152

lrargerich's avatar
lrargerich committed
153
// Interval is in hours
154 155 156 157 158
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;
159
	$interval = $minical_interval;
lrargerich's avatar
lrargerich committed
160
}
161

162
// end of modification
163 164 165
if ($_REQUEST['view'] == 'weekly') {
	$interval = 24 * 60 * 60;

lrargerich's avatar
lrargerich committed
166
	// Determine weekday
167
	$wd = date('w', $pdate);
168 169 170 171 172

	if ($wd == 0)
		$wd = 7;

	$wd = $wd - 1;
lrargerich's avatar
lrargerich committed
173
	// Now get the number of days to substract
174 175 176 177 178 179 180 181 182 183
	$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
184 185
}

186 187 188 189 190 191
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
192 193 194
}

// List view
195 196 197
if ($_REQUEST['view'] == 'list') {
	if (!isset($_REQUEST["sort_mode"])) {
		$sort_mode = 'start_asc';
lrargerich's avatar
stuff  
lrargerich committed
198
	} else {
199 200 201 202 203
		$sort_mode = $_REQUEST["sort_mode"];
	}

	if (!isset($_REQUEST["offset"])) {
		$offset = 0;
lrargerich's avatar
stuff  
lrargerich committed
204
	} else {
205
		$offset = $_REQUEST["offset"];
lrargerich's avatar
stuff  
lrargerich committed
206
	}
207 208 209 210 211

	$smarty->assign_by_ref('offset', $offset);

	if (isset($_REQUEST["find"])) {
		$find = $_REQUEST["find"];
lrargerich's avatar
stuff  
lrargerich committed
212
	} else {
213
		$find = '';
lrargerich's avatar
stuff  
lrargerich committed
214
	}
215 216 217 218 219 220 221

	$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
222
	} else {
223
		$pdate = date("U");
lrargerich's avatar
stuff  
lrargerich committed
224
	}
225 226

	$channels = $minicallib->minical_list_events($user, $offset, $maxRecords, $sort_mode, $find);
227
	$smarty->assign_by_ref('cant_pages', $channels["cant"]);
lrargerich's avatar
Stuff  
lrargerich committed
228

229 230
	$smarty->assign('channels', $channels["data"]);
}
lrargerich's avatar
Stuff  
lrargerich committed
231

232 233
$upcoming = $minicallib->minical_list_events_from_date($user, 0, $minical_upcoming, 'start_asc', '', $pdate_h);
$smarty->assign('upcoming', $upcoming['data']);
lrargerich's avatar
Stuff  
lrargerich committed
234

235 236 237 238 239 240 241 242
$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);
lrargerich's avatar
Stuff  
lrargerich committed
243

244 245
$topics = $minicallib->minical_list_topics($user, 0, -1, 'name_asc', '');
$smarty->assign('topics', $topics['data']);
246
include_once ('tiki-section_options.php');
lrargerich's avatar
Stuff  
lrargerich committed
247 248

include_once('tiki-mytiki_shared.php');
249
ask_ticket('minical');
250
if ($prefs['feature_ajax'] == "y") {
tombombadilom's avatar
tombombadilom committed
251 252 253 254 255 256 257 258 259
function user_minical_ajax() {
    global $ajaxlib, $xajax;
    $ajaxlib->registerTemplate("tiki-minical.tpl");
    $ajaxlib->registerFunction("loadComponent");
    $ajaxlib->processRequests();
}
user_minical_ajax();
$smarty->assign("mootab",'y');
}
260
$smarty->assign('mid', 'tiki-minical.tpl');
261
$smarty->display("tiki.tpl");