tiki-calendar_edit_item.php 22.2 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3
// 
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.
changi67's avatar
changi67 committed
6
// $Id$
7 8 9 10

$section = 'calendar';
require_once ('tiki-setup.php');

11 12
$access->check_feature('feature_calendar');

13 14
include_once ('lib/calendar/calendarlib.php');
include_once ('lib/newsletters/nllib.php');
15
include_once ('lib/calendar/calrecurrence.php');
16 17 18
if ($prefs['feature_groupalert'] == 'y') {
	include_once ('lib/groupalert/groupalertlib.php');
}
19 20
$auto_query_args = array('calitemId');

21
$daysnames = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Satursday");
22
$daysnames_abr = array("Su","Mo","Tu","We","Th","Fr","Sa");
23 24
$monthnames = array("","January","February","March","April","May","June","July","August","September","October","November","December");
$smarty->assign('daysnames',$daysnames);
25
$smarty->assign('daysnames_abr',$daysnames_abr);
26 27
$smarty->assign('monthnames',$monthnames);

28
$smarty->assign('edit',false);
29
$smarty->assign('recurrent', '');
30
$hours_minmax = '';
31

32 33
$caladd = array();
$rawcals = $calendarlib->list_calendars();
34
if ($rawcals['cant'] == 0 && $tiki_p_admin_calendar == 'y') {
35
	$smarty->assign('msg', tra('You need to <a href="tiki-admin_calendars.php?cookietab=2">create a calendar</a>'));
36 37 38
	$smarty->display("error.tpl");
	die;
}
39 40 41

$rawcals['data'] = Perms::filter( array( 'type' => 'calendar' ), 'object', $rawcals['data'], array( 'object' => 'calendarId' ), 'view_calendar' );

42 43
foreach ($rawcals["data"] as $cal_data) {
  $cal_id = $cal_data['calendarId'];
44 45
  $calperms = Perms::get( array( 'type' => 'calendar', 'object' => $cal_id ) );
  if ($cal_data["personal"] == "y") {
46
    if ($user) {
47
      $cal_data["tiki_p_view_calendar"] = 'y';
48
    	$cal_data["tiki_p_view_events"] = 'y';
49 50 51 52
      $cal_data["tiki_p_add_events"] = 'y';
      $cal_data["tiki_p_change_events"] = 'y';
    } else {
      $cal_data["tiki_p_view_calendar"] = 'n';
53
    	$cal_data["tiki_p_view_events"] = 'y';
54 55 56 57
      $cal_data["tiki_p_add_events"] = 'n';
      $cal_data["tiki_p_change_events"] = 'n';
    }
  } else {
58 59 60 61
      $cal_data["tiki_p_view_calendar"] = $calperms->view_calendar ? "y" : "n";
      $cal_data["tiki_p_view_events"] = $calperms->view_events ? "y" : "n";
      $cal_data["tiki_p_add_events"] = $calperms->add_events ? "y" : "n";
      $cal_data["tiki_p_change_events"] = $calperms->change_events ? "y" : "n";
62 63
  }
	$caladd["$cal_id"] = $cal_data;
64 65 66
	if ($cal_data['tiki_p_add_events'] == 'y' && empty($calID)) {
		$calID = $cal_id;
	}
67 68 69
}
$smarty->assign('listcals',$caladd);

sylvieg's avatar
sylvieg committed
70 71 72
if ( ! isset($_REQUEST["calendarId"]) ) {
	if (isset($_REQUEST['calitemId'])) {
		$calID = $calendarlib->get_calendarid($_REQUEST['calitemId']);
sylvieg's avatar
oops  
sylvieg committed
73
	} elseif (isset($_REQUEST['viewcalitemId'])) {
sylvieg's avatar
sylvieg committed
74 75 76
		$calID = $calendarlib->get_calendarid($_REQUEST['viewcalitemId']);
	}
} elseif (isset($_REQUEST['calendarId'])) {
77 78
	$calID = $_REQUEST['calendarId'];
} elseif (isset($_REQUEST['save']) && isset($_REQUEST['save']['calendarId'])) {
79
	$calID = $_REQUEST['save']['calendarId'];
sylvieg's avatar
sylvieg committed
80
}
81

82
if ($prefs['feature_groupalert'] == 'y' && !empty($calID) ) {
83
	$groupforalert=$groupalertlib->GetGroup ('calendar',$calID);
84
	$showeachuser = '';
85 86 87 88 89 90 91
	if ( $groupforalert != '' ) {
		$showeachuser=$groupalertlib->GetShowEachUser('calendar',$calID, $groupforalert) ;
		$listusertoalert=$userlib->get_users(0,-1,'login_asc','','',false,$groupforalert,'') ;
		$smarty->assign_by_ref('listusertoalert',$listusertoalert['data']);
	}
	$smarty->assign_by_ref('groupforalert',$groupforalert);
	$smarty->assign_by_ref('showeachuser',$showeachuser);
92
}
93

94
$tikilib->get_perm_object( $calID, 'calendar' );
95
$access->check_permission('tiki_p_view_calendar');
96

97 98 99
if (isset($_REQUEST['save']) && !isset($_REQUEST['preview']) && !isset($_REQUEST['act'])) {
	$_REQUEST['changeCal'] = 'y';
}
100

101
if (isset($_REQUEST['act']) || isset($_REQUEST['preview']) || isset($_REQUEST['changeCal'])) {
102

103
	$save = $_POST['save'];
104 105 106 107 108 109 110 111 112
	// Take care of timestamps dates coming from jscalendar
	if ( isset($save['date_start']) || isset($save['date_end']) ) {
		$_REQUEST['start_date_Month'] = TikiLib::date_format("%m", $save['date_start']);
		$_REQUEST['start_date_Day'] = TikiLib::date_format("%d", $save['date_start']);
		$_REQUEST['start_date_Year'] = TikiLib::date_format("%Y", $save['date_start']);
		$_REQUEST['end_date_Month'] = TikiLib::date_format("%m", $save['date_end']);
		$_REQUEST['end_date_Day'] = TikiLib::date_format("%d", $save['date_end']);
		$_REQUEST['end_date_Year'] = TikiLib::date_format("%Y", $save['date_end']);
	}
113 114
	
	$save['allday'] = (isset($_REQUEST['allday']) && $_REQUEST['allday'] == 'true') ? 1 : 0;
sylvieg's avatar
sylvieg committed
115
	if (isset($_REQUEST['allday']) && $_REQUEST['allday'] == 'true') {
116 117 118 119 120 121 122 123
		$save['start'] = TikiLib::make_time(
			0,
			0,
			0,
			$_REQUEST['start_date_Month'],
			$_REQUEST['start_date_Day'],
			$_REQUEST['start_date_Year']
		);
124

125 126 127 128 129 130 131 132 133 134 135 136 137 138
		if ($save['end_or_duration'] == 'duration') {
			$save['duration'] = 86399;
			$save['end'] = $save['start'] + $save['duration'];
		} else {
			$save['end'] = TikiLib::make_time(
				23,
				59,
				59,
				$_REQUEST['end_date_Month'],
				$_REQUEST['end_date_Day'],
				$_REQUEST['end_date_Year']
			);
			$save['duration'] = max(0, $save['end'] - $save['start']);
		}
139
	} else {
140 141
		//Convert 12-hour clock hours to 24-hour scale to compute time
		if (!empty($_REQUEST['start_Meridian'])) {
142
			$_REQUEST['start_Hour'] = date('H', strtotime($_REQUEST['start_Hour'] . ':00 ' . $_REQUEST['start_Meridian']));
143
		}
144 145 146
		$save['start'] = TikiLib::make_time(
			$_REQUEST['start_Hour'],
			$_REQUEST['start_Minute'],
147
			0,
148 149 150
			$_REQUEST['start_date_Month'],
			$_REQUEST['start_date_Day'],
			$_REQUEST['start_date_Year']
151
		);
152 153 154 155 156

		if ($save['end_or_duration'] == 'duration') {
			$save['duration'] = max(0, $_REQUEST['duration_Hour']*60*60 + $_REQUEST['duration_Minute']*60);
			$save['end'] = $save['start'] + $save['duration'];
		} else {
157 158
			//Convert 12-hour clock hours to 24-hour scale to compute time
			if (!empty($_REQUEST['end_Meridian'])) {
159
				$_REQUEST['end_Hour'] = date('H', strtotime($_REQUEST['end_Hour'] . ':00 ' . $_REQUEST['end_Meridian']));
160
			}
161 162 163 164 165 166 167 168 169 170
			$save['end'] = TikiLib::make_time(
				$_REQUEST['end_Hour'],
				$_REQUEST['end_Minute'],
				0,
				$_REQUEST['end_date_Month'],
				$_REQUEST['end_date_Day'],
				$_REQUEST['end_date_Year']
			);
			$save['duration'] = max(0, $save['end'] - $save['start']);
		}
171 172
	}
}
173

174 175 176 177 178
$impossibleDates = false;
if (isset($save['start']) && isset($save['end'])) {
	if (($save['end'] - $save['start']) < 0)
		$impossibleDates = true;
}
179 180

if (isset($_POST['act'])) {
181
	// Check antibot code if anonymous and allowed
sampaioprimo's avatar
sampaioprimo committed
182
	if (empty($user) && $prefs['feature_antibot'] == 'y' && (!$captchalib->validate())) {
sampaioprimo's avatar
sampaioprimo committed
183
		$smarty->assign('msg', $captchalib->getErrors());
184 185 186 187
		$smarty->assign('errortype', 'no_redirect_login');
		$smarty->display("error.tpl");
		die;
	}
188 189
	if (empty($save['user'])) $save['user'] = $user;
	$newcalid = $save['calendarId'];
190 191
	if ((empty($save['calitemId']) and $caladd["$newcalid"]['tiki_p_add_events'] == 'y')
	or (!empty($save['calitemId']) and $caladd["$newcalid"]['tiki_p_change_events'] == 'y')) {
192
		if (empty($save['name'])) $save['name'] = tra("event without name");
193
		if (empty($save['priority'])) $save['priority'] = 1;
194
		if (!isset($save['status'])) {
195 196 197 198 199 200
			if (empty($calendar['defaulteventstatus'])) {
				$save['status'] = 1; // Confirmed
			} else {
				$save['status'] = $calendar['defaulteventstatus'];
			}
		}
201
		
202
		if (array_key_exists('recurrent',$_POST) && ($_POST['recurrent'] == 1) && $_POST['affect']!='event') {
203 204 205 206 207 208 209 210
			$impossibleDates = false;
			if ($_POST['end_Hour'] < $_POST['start_Hour']) {
				$impossibleDates = true;
			} elseif (($_POST['end_Hour'] == $_POST['start_Hour']) && ($_POST['end_Minute'] < $_POST['start_Minute'])) {
				$impossibleDates = true;
			} else
				$impossibleDates = false;
			if (!$impossibleDates) {
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
				$calRecurrence = new CalRecurrence($_POST['recurrenceId'] ? $_POST['recurrenceId'] : -1);
				$calRecurrence->setCalendarId($save['calendarId']);
				$calRecurrence->setStart($_POST['start_Hour'] . str_pad($_POST['start_Minute'],2,'0',STR_PAD_LEFT));
				$calRecurrence->setEnd($_POST['end_Hour'] . str_pad($_POST['end_Minute'],2,'0',STR_PAD_LEFT));
				$calRecurrence->setAllday($save['allday'] == 1);
				$calRecurrence->setLocationId($save['locationId']);
				$calRecurrence->setCategoryId($save['categoryId']);
				$calRecurrence->setNlId(0); //TODO : What id nlId ?
				$calRecurrence->setPriority($save['priority']);
				$calRecurrence->setStatus($save['status']);
				$calRecurrence->setUrl($save['url']);
				$calRecurrence->setLang(strLen($save['lang']) > 0 ? $save['lang'] : 'en');
				$calRecurrence->setName($save['name']);
				$calRecurrence->setDescription($save['description']);
				switch($_POST['recurrenceType']) {
					case "weekly":
						$calRecurrence->setWeekly(true);
228 229 230 231
						$calRecurrence->setWeekday($_POST['weekday']);
						$calRecurrence->setMonthly(false);
						$calRecurrence->setYearly(false);
						break;
232 233
					case "monthly":
						$calRecurrence->setWeekly(false);
234 235 236 237
						$calRecurrence->setMonthly(true);
						$calRecurrence->setDayOfMonth($_POST['dayOfMonth']);
						$calRecurrence->setYearly(false);
						break;
238 239
					case "yearly":
						$calRecurrence->setWeekly(false);
240 241 242 243
						$calRecurrence->setMonthly(false);
						$calRecurrence->setYearly(true);
						$calRecurrence->setDateOfYear(str_pad($_POST['dateOfYear_month'],2,'0',STR_PAD_LEFT) . str_pad($_POST['dateOfYear_day'],2,'0',STR_PAD_LEFT));
						break;
244 245 246 247 248 249 250 251 252
				}
				$calRecurrence->setStartPeriod($_POST['startPeriod']);
				if ($_POST['endType'] == "dt")
					$calRecurrence->setEndPeriod($_POST['endPeriod']);
				else {
					$calRecurrence->setNbRecurrences($_POST['nbRecurrences']);
				}
				$calRecurrence->setUser($save['user']);
				$calRecurrence->save($_POST['affect'] == 'all');
253 254 255 256 257 258 259
					// Save the ip at the log for the addition of new calendar items when done by anonymous users
					if (empty($user) && empty($save['calitemId']) && $caladd["$newcalid"]['tiki_p_add_events']) { 
						$logslib->add_log('calendar','Recurrent calendar item starting on '.$_POST['startPeriod'].' added to calendar '.$save['calendarId']);
					}
					if (empty($user) && !empty($save['calitemId']) and $caladd["$newcalid"]['tiki_p_change_events']) { 
						$logslib->add_log('calendar','Recurrent calendar item starting on '.$_POST['startPeriod'].' changed in calendar '.$save['calendarId']);
					}
260
				header('Location: tiki-calendar.php?todate='.$save['start']);
261
				die;
262
			}
263
		} else {
264
			if (!$impossibleDates) {
265 266 267 268 269
				if (array_key_exists('recurrenceId',$_POST)) {
					$save['recurrenceId'] = $_POST['recurrenceId'];
					$save['changed'] = true;
				}
				$calitemId = $calendarlib->set_item($user,$save['calitemId'],$save);
270 271 272 273 274 275 276
					// Save the ip at the log for the addition of new calendar items when done by anonymous users
					if (empty($user) && empty($save['calitemId']) && $caladd["$newcalid"]['tiki_p_add_events']) { 
						$logslib->add_log('calendar','Calendar item '.$calitemId.' added to calendar '.$save['calendarId']);
					}
					if (empty($user) && !empty($save['calitemId']) and $caladd["$newcalid"]['tiki_p_change_events']) { 
						$logslib->add_log('calendar','Calendar item '.$calitemId.' changed in calendar '.$save['calendarId']);
					}
277 278 279 280 281
            if ($prefs['feature_groupalert'] == 'y') {
              $groupalertlib->Notify($_REQUEST['listtoalert'],"tiki-calendar_edit_item.php?viewcalitemId=".$calitemId);
            }
            header('Location: tiki-calendar.php?todate='.$save['start']);
            die;
282
			}
283
		}
284 285 286
	}
}

287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
if (!empty($_REQUEST['viewcalitemId']) && isset($_REQUEST['del_me']) && $tiki_p_calendar_add_my_particip == 'y') {
	$calendarlib->update_participants($_REQUEST['viewcalitemId'], null, array($user));
}

if (!empty($_REQUEST['viewcalitemId']) && isset($_REQUEST['add_me']) && $tiki_p_calendar_add_my_particip == 'y') {
	$calendarlib->update_participants($_REQUEST['viewcalitemId'], array(array('name'=>$user)), null);
}

if (!empty($_REQUEST['viewcalitemId']) && !empty($_REQUEST['guests']) && isset($_REQUEST['add_guest']) && $tiki_p_calendar_add_guest_particip == 'y') {
	$guests = preg_split('/ *, */', $_REQUEST['guests']);
	foreach ($guests as $i=>$guest) {
		$guests[$i] = array('name'=>$guest);
	}
	$calendarlib->update_participants($_REQUEST['viewcalitemId'], $guests);
}

303
if (isset($_REQUEST["delete"]) and ($_REQUEST["delete"]) and isset($_REQUEST["calitemId"]) and $tiki_p_change_events == 'y') {
304
	// There is no check for valid antibot code if anonymous allowed to delete events since this comes from a JS button at the tpl and bots are not know to use JS
305
	$access->check_authenticity();
306
	$calitem = $calendarlib->get_item($_REQUEST['calitemId']);
307
	$calendarlib->drop_item($user, $_REQUEST["calitemId"]);
308 309 310
	if (empty($user)) { 
		$logslib->add_log('calendar','Calendar item '.$_REQUEST['calitemId'].' deleted');
	}
311 312 313
	$_REQUEST["calitemId"] = 0;
	header('Location: tiki-calendar.php?todate='.$calitem['start']);
	exit;
314
} elseif (isset($_REQUEST["delete"]) and ($_REQUEST["delete"]) and isset($_REQUEST["recurrenceId"]) and $tiki_p_change_events == 'y') {
315
	// There is no check for valid antibot code if anonymous allowed to delete events since this comes from a JS button at the tpl and bots are not know to use JS
316 317
	$calRec = new CalRecurrence($_REQUEST['recurrenceId']);
	$calRec->delete();
318 319 320
	if (empty($user)) { 
		$logslib->add_log('calendar','Recurrent calendar items (recurrenceId = '.$_REQUEST["recurrenceId"].') deleted');
	}
321 322 323 324
    $_REQUEST["recurrenceTypeId"] = 0;
    $_REQUEST["calitemId"] = 0;
	header('Location: tiki-calendar.php');
	die;
325
} elseif (isset($_REQUEST['drop']) and $tiki_p_change_events == 'y') {
326 327 328 329
  check_ticket('calendar');
  if (is_array($_REQUEST['drop'])) {
    foreach ($_REQUEST['drop'] as $dropme) {
      $calendarlib->drop_item($user, $dropme);
330
    }
331 332
  } else {
    $calendarlib->drop_item($user, $_REQUEST['drop']);
333
  }
334 335 336
	if (empty($user)) { 
		$logslib->add_log('calendar','Calendar item/s '.$_REQUEST['calitemId'].' droped');
	}
337 338 339
	header('Location: tiki-calendar.php');
	die;
}  elseif (isset($_REQUEST['duplicate']) and $tiki_p_add_events == 'y') {
340
	// Check antibot code if anonymous and allowed
sampaioprimo's avatar
sampaioprimo committed
341
	if (empty($user) && $prefs['feature_antibot'] == 'y' && (!$captchalib->validate())) {
sampaioprimo's avatar
sampaioprimo committed
342
		$smarty->assign('msg', $captchalib->getErrors());
343 344 345 346
		$smarty->assign('errortype', 'no_redirect_login');
		$smarty->display("error.tpl");
		die;
	}
347
	$calitem = $calendarlib->get_item($_REQUEST['calitemId']);
348
	$calitem['calendarId'] = $calID;
349 350
	$calitem['calitemId'] = 0;
	$calendarlib->set_item($user,0,$calitem);
351 352 353 354 355 356
	$id = 0;
	if (isset($_REQUEST['calId'])) {
		$calendar = $calendarlib->get_calendar($_REQUEST['calId']);
  } else {
		$calendar = $calendarlib->get_calendar($calitem['calendarId']);
  }
357
	$smarty->assign('edit',true);
358
	$hour_minmax = abs(ceil(($calendar['startday']-1)/(60*60))) . '-' . ceil(($calendar['endday'])/(60*60));
359
} elseif (isset($_REQUEST['preview']) || $impossibleDates) {
360 361 362 363
	$save['parsed'] = $tikilib->parse_data($save['description']);
	$save['parsedName'] = $tikilib->parse_data($save['name']);
	$id = $save['calitemId'];
	$calitem = $save;
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381

	$recurrence = array(
		'weekly' => isset($_POST['recurrenceType']) && $_POST['recurrenceType'] = 'weekly',
		'weekday' => isset($_POST['weekday']) ? $_POST['weekday'] : '',
		'monthly' => isset($_POST['recurrenceType']) && $_POST['recurrenceType'] = 'monthly',
		'dayOfMonth' => isset($_POST['dayOfMonth']) ? $_POST['dayOfMonth'] : '',
		'yearly' => isset($_POST['recurrenceType']) && $_POST['recurrenceType'] = 'yearly',
		'dateOfYear_day' => isset($_POST['dateOfYear_day']) ? $_POST['dateOfYear_day'] : '',
		'dateOfYear_month' => isset($_POST['dateOfYear_month']) ? $_POST['dateOfYear_month'] : '',
		'startPeriod' => isset($_POST['startPeriod']) ? $_POST['startPeriod'] : '',
		'nbRecurrences' => isset($_POST['nbRecurrences']) ? $_POST['nbRecurrences'] : '',
		'endPeriod' => isset($_POST['endPeriod']) ? $_POST['endPeriod'] : ''
	);	
	if ( isset($_POST['recurrent']) && $_POST['recurrent'] == 1 ) {
		$smarty->assign('recurrent', $_POST['recurrent']);
	}
	$smarty->assign_by_ref('recurrence', $recurrence);
	
382
	$calendar = $calendarlib->get_calendar($calitem['calendarId']);
383
	$smarty->assign('edit',true);
384
	$smarty->assign('preview', isset($_REQUEST['preview']));
385 386
} elseif (isset($_REQUEST['changeCal'])) {
	$calitem = $save;
387
	$calendar = $calendarlib->get_calendar($calitem['calendarId']);
388
	$smarty->assign('edit',true);
389 390
	$id = isset($save['calitemId'])?$save['calitemId']: 0;
	$hour_minmax = ceil(($calendar['startday'])/(60*60)).'-'. ceil(($calendar['endday'])/(60*60));
391
	$smarty->assign('changeCal', isset($_REQUEST['changeCal']));
392
} elseif (isset($_REQUEST['viewcalitemId']) and $tiki_p_view_events == 'y') {
393 394 395
	$calitem = $calendarlib->get_item($_REQUEST['viewcalitemId']);
	$id = $_REQUEST['viewcalitemId'];
	$calendar = $calendarlib->get_calendar($calitem['calendarId']);
396
	$hour_minmax = ceil(($calendar['startday'])/(60*60)).'-'. ceil(($calendar['endday'])/(60*60));
397
} elseif (isset($_REQUEST['calitemId']) and ($tiki_p_change_events == 'y' or $tiki_p_view_events == 'y')) {
398 399 400
	$calitem = $calendarlib->get_item($_REQUEST['calitemId']);
	$id = $_REQUEST['calitemId'];
	$calendar = $calendarlib->get_calendar($calitem['calendarId']);
401
	$smarty->assign('edit',true);
402
	$hour_minmax = ceil(($calendar['startday'])/(60*60)).'-'. ceil(($calendar['endday'])/(60*60));
403
//Add event buttons - either button on top of page or one of the buttons on a specific day
404
} elseif (isset($calID) and $tiki_p_add_events == 'y') {
405
	$calendar = $calendarlib->get_calendar($calID);
406 407 408
	if (isset($_REQUEST['todate'])) {
		$now = $_REQUEST['todate'];
	} else {
mose's avatar
mose committed
409
		$now = $tikilib->now;
410
	}
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
	//if current time of day is within the calendar day (between startday and endday), then use now as start, otherwise use beginning of calendar day
	$now_start = TikiLib::make_time(
		abs(ceil($calendar['startday']/(60*60))),
		0,
		0,
		TikiLib::date_format('%m', $now),
		TikiLib::date_format('%d', $now),
		TikiLib::date_format('%Y', $now)
	);
	$now_end = TikiLib::make_time(
		abs(ceil($calendar['endday']/(60*60))),
		0,
		0,
		TikiLib::date_format('%m', $now),
		TikiLib::date_format('%d', $now),
		TikiLib::date_format('%Y', $now)
	);
	$now_start = ($now_start <= $now && ($now_start + (60*60)) < $now_end) ? $now : $now_start;
	
	//if $now_end is midnight, make it one second before
	$now_end = TikiLib::date_format('%H%M%s', $now_start + (60*60)) == '000000' ? $now_start + (60*60) -1 : $now_start + (60*60);
	
433 434 435 436 437 438
	$calitem = array(
		'calitemId'=>0,
		'user'=>$user,
		'name'=>'',
		'url'=>'',
		'description'=>'',
439
		'status'=>$calendar['defaulteventstatus'],
440 441 442 443
		'priority'=>0,
		'locationId'=>0,
		'categoryId'=>0,
		'nlId'=>0,
444 445
		'start'=>$now_start,
		'end'=>$now_end,
446 447
		'duration'=>(60*60),
		'recurrenceId'=>0,
448
		);
449
	$hour_minmax = abs(ceil(($calendar['startday']-1)/(60*60))). '-' . ceil(($calendar['endday'])/(60*60));
450
	$id = 0;
451
	$smarty->assign('edit',true);
452
} else {
453
  $smarty->assign('errortype', 401);
454
  $smarty->assign('msg', tra("You do not have permission to view this page"));
455 456 457
  $smarty->display("error.tpl");
  die;
}
458 459 460 461 462 463
if (!empty($id) && $calendar['personal'] == 'y' && $calitem['user'] != $user) {
	$smarty->assign('errortype', 401);
	$smarty->assign('msg', tra("You do not have permission to view this page"));
	$smarty->display("error.tpl");
	die;
}
464

465 466
if (!empty($calendar['eventstatus'])) {
    $calitem['status'] = $calendar['eventstatus'];
467
}
468

469
if ($calendar['customlocations'] == 'y') {
470
	$listlocs = $calendarlib->list_locations($calID);
471 472 473 474 475
} else {
	$listlocs = array();
}
$smarty->assign('listlocs', $listlocs);

476 477
include_once ('lib/userprefs/userprefslib.php');
$smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user));
478

479
if ($calendar['customcategories'] == 'y') {
480
	$listcats = $calendarlib->list_categories($calID);
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
} else {
	$listcats = array();
}
$smarty->assign('listcats', $listcats);

if ($calendar["customsubscription"] == 'y') {
	$subscrips = $nllib->list_avail_newsletters();
} else {
	$subscrips = array();
}
$smarty->assign('subscrips', $subscrips);

if ($calendar["customlanguages"] == 'y') {
	$languages = $tikilib->list_languages();
} else {
	$languages = array();
}
$smarty->assign('listlanguages', $languages);

$smarty->assign('listpriorities',array('0','1','2','3','4','5','6','7','8','9'));
$smarty->assign('listprioritycolors',array('fff','fdd','fcc','fbb','faa','f99','e88','d77','c66','b66','a66'));
502
$smarty->assign('listroles',array('0'=>'','1'=>tra('required'),'2'=>tra('optional'),'3'=>tra('non participant')));
503 504


505
if ($prefs['feature_theme_control'] == 'y') {
506
  $cat_type = "calendar";
507
  $cat_objid = $calID;
508 509 510
  include('tiki-tc.php');
}

511 512
$headerlib->add_cssfile('css/calendar.css',20);

513
$smarty->assign('referer', empty($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'tiki-calendar_edit_item.php') !== false ? 'tiki-calendar.php' : $_SERVER['HTTP_REFERER']);
514 515
$smarty->assign('myurl', 'tiki-calendar_edit_item.php');
$smarty->assign('id', $id);
516
$smarty->assign('hour_minmax', $hour_minmax);
517 518 519 520
if ($calitem['recurrenceId'] > 0) {
	$cr = new CalRecurrence($calitem['recurrenceId']);
	$smarty->assign('recurrence',$cr->toArray());
}
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
$headerlib->add_js('
function checkDateOfYear(day,month) {
	var mName = new Array("-","'.tra('January').'","'.tra('February').'","'.tra('March').'","'.tra('April').'","'.tra('May').'","'.tra('June').'","'.tra('July').'","'.tra('August').'","'.tra('September').'","'.tra('October').'","'.tra('November').'","'.tra('December').'}");
	var error = false;
	if (month == 4 || month == 6 || month == 9 || month == 11)
		if (day == 31)
			error = true;
	if (month == 2)
		if (day > 29)
			error = true;
	if (error) {
		document.getElementById("errorDateOfYear").innerHTML = "<em>'.tra('There\'s no such date as').' " + day + " '.tra('of').' " + mName[month] + "</em>";
	} else {
		document.getElementById("errorDateOfYear").innerHTML = "";
	}
}
');
538 539
$smarty->assign('calitem', $calitem);
$smarty->assign('calendar', $calendar);
540
$smarty->assign('calendarId', $calID);
541 542
if (array_key_exists('CalendarViewGroups',$_SESSION) && count($_SESSION['CalendarViewGroups']) == 1)
	$smarty->assign('calendarView',$_SESSION['CalendarViewGroups'][0]);
543 544 545 546

global $wikilib; include_once('lib/wiki/wikilib.php');
$plugins = $wikilib->list_plugins(true, 'editwiki');
$smarty->assign_by_ref('plugins', $plugins);
sylvieg's avatar
sylvieg committed
547
$smarty->assign('headtitle',tra('Calendar event : ').$calitem['name']);
548
$smarty->assign('impossibleDates',$impossibleDates);
549 550
$smarty->assign('mid', 'tiki-calendar_edit_item.tpl');
$smarty->display("tiki.tpl");