3 require_once('include/bbcode.php');
4 require_once('include/datetime.php');
5 require_once('include/event.php');
6 require_once('include/items.php');
8 function events_post(&$a) {
13 $event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0);
14 $cid = ((x($_POST,'cid')) ? intval($_POST['cid']) : 0);
16 $startyear = intval($_POST['startyear']);
17 $startmonth = intval($_POST['startmonth']);
18 $startday = intval($_POST['startday']);
19 $starthour = intval($_POST['starthour']);
20 $startminute = intval($_POST['startminute']);
22 $finishyear = intval($_POST['finishyear']);
23 $finishmonth = intval($_POST['finishmonth']);
24 $finishday = intval($_POST['finishday']);
25 $finishhour = intval($_POST['finishhour']);
26 $finishminute = intval($_POST['finishminute']);
28 $adjust = intval($_POST['adjust']);
29 $nofinish = intval($_POST['nofinish']);
32 $start = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute);
34 $finish = '0000-00-00 00:00:00';
36 $finish = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute);
39 $start = datetime_convert(date_default_timezone_get(),'UTC',$start);
41 $finish = datetime_convert(date_default_timezone_get(),'UTC',$finish);
44 $start = datetime_convert('UTC','UTC',$start);
46 $finish = datetime_convert('UTC','UTC',$finish);
49 // Don't allow the event to finish before it begins.
50 // It won't hurt anything, but somebody will file a bug report
51 // and we'll waste a bunch of time responding to it. Time that
52 // could've been spent doing something else.
54 if(strcmp($finish,$start) < 0)
57 $desc = escape_tags(trim($_POST['desc']));
58 $location = escape_tags(trim($_POST['location']));
61 if((! $desc) || (! $start)) {
62 notice( t('Event description and start time are required.') . EOL);
63 goaway($a->get_baseurl() . '/events/new');
66 $share = ((intval($_POST['share'])) ? intval($_POST['share']) : 0);
69 $str_group_allow = perms2str($_POST['group_allow']);
70 $str_contact_allow = perms2str($_POST['contact_allow']);
71 $str_group_deny = perms2str($_POST['group_deny']);
72 $str_contact_deny = perms2str($_POST['contact_deny']);
75 $str_contact_allow = '<' . local_user() . '>';
76 $str_group_allow = $str_contact_deny = $str_group_deny = '';
81 $datarray['start'] = $start;
82 $datarray['finish'] = $finish;
83 $datarray['desc'] = $desc;
84 $datarray['location'] = $location;
85 $datarray['type'] = $type;
86 $datarray['adjust'] = $adjust;
87 $datarray['nofinish'] = $nofinish;
88 $datarray['uid'] = $uid;
89 $datarray['cid'] = $cid;
90 $datarray['allow_cid'] = $str_contact_allow;
91 $datarray['allow_gid'] = $str_group_allow;
92 $datarray['deny_cid'] = $str_contact_deny;
93 $datarray['deny_gid'] = $str_group_deny;
94 $datarray['id'] = $event_id;
95 $datarray['created'] = $created;
96 $datarray['edited'] = $edited;
98 $item_id = event_store($datarray);
101 proc_run('php',"include/notifier.php","event","$item_id");
107 function events_content(&$a) {
110 notice( t('Permission denied.') . EOL);
115 $htpl = get_markup_template('event_head.tpl');
116 $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
120 $tabs = profile_tabs($a, True);
129 if($a->argc > 2 && $a->argv[1] == 'event') {
131 $event_id = intval($a->argv[2]);
133 if($a->argv[1] === 'new') {
137 if($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
139 $y = intval($a->argv[1]);
140 $m = intval($a->argv[2]);
144 if($mode == 'view') {
147 $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
148 $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
150 $y = intval($thisyear);
152 $m = intval($thismonth);
154 // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
155 // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
164 if($nextmonth > 12) {
177 $dim = get_dim($y,$m);
178 $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
179 $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
182 if ($a->argv[1] === 'json'){
183 if (x($_GET,'start')) $start = date("Y-m-d h:i:s", $_GET['start']);
184 if (x($_GET,'end')) $finish = date("Y-m-d h:i:s", $_GET['end']);
187 $start = datetime_convert('UTC','UTC',$start);
188 $finish = datetime_convert('UTC','UTC',$finish);
190 $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
191 $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
195 $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
196 `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id`
197 WHERE `event`.`uid` = %d AND `event`.`id` = %d",
198 intval(local_user()),
202 $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
203 `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id`
204 WHERE `event`.`uid` = %d
205 AND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' )
206 OR ( `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ",
207 intval(local_user()),
210 dbesc($adjust_start),
211 dbesc($adjust_finish)
218 $r = sort_by_date($r);
220 $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
222 $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
233 $r = sort_by_date($r);
237 $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
238 $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt));
239 $d = day_translate($d);
241 $start = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'c') : datetime_convert('UTC','UTC',$rr['start'],'c'));
242 if ($rr['nofinish']){
245 $end = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['finish'], 'c') : datetime_convert('UTC','UTC',$rr['finish'],'c'));
249 $is_first = ($d !== $last_date);
252 $edit = ((! $rr['cid']) ? array($a->get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null);
254 list($title, $_trash) = explode("<br",bbcode($rr['desc']),2);
255 $title = strip_tags($title);
256 $html = format_event_html($rr);
257 $rr['desc'] = bbcode($rr['desc']);
258 $rr['location'] = bbcode($rr['location']);
269 'is_first'=>$is_first,
272 'plink' => array($rr['plink'],t('link to source'),'',''),
279 if ($a->argv[1] === 'json'){
280 echo json_encode($events); killme();
283 // links: array('href', 'text', 'extra css classes', 'title')
285 $tpl = get_markup_template("event.tpl");
287 if (get_config('experimentals','new_calendar')==1){
288 $tpl = get_markup_template("events-js.tpl");
290 $tpl = get_markup_template("events.tpl");
293 $o = replace_macros($tpl, array(
294 '$baseurl' => $a->get_baseurl(),
296 '$title' => t('Events'),
297 '$new_event'=> array($a->get_baseurl().'/events/new',t('Create New Event'),'',''),
298 '$previus' => array($a->get_baseurl()."/events/$prevyear/$prevmonth",t('Previous'),'',''),
299 '$next' => array($a->get_baseurl()."/events/$nextyear/$nextmonth",t('Next'),'',''),
300 '$calendar' => cal($y,$m,$links, ' eventcal'),
302 '$events' => $events,
307 if (x($_GET,'id')){ echo $o; killme(); }
313 if($mode === 'edit' && $event_id) {
314 $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1",
322 if($mode === 'edit' || $mode === 'new') {
324 $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : '');
325 $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : '');
326 $d_orig = ((x($orig_event)) ? $orig_event['desc'] : '');
327 $l_orig = ((x($orig_event)) ? $orig_event['location'] : '');
328 $eid = ((x($orig_event)) ? $orig_event['id'] : 0);
329 $cid = ((x($orig_event)) ? $orig_event['cid'] : 0);
330 $uri = ((x($orig_event)) ? $orig_event['uri'] : '');
336 $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ' );
339 $sh_checked .= ' disabled="disabled" ';
343 $tpl = get_markup_template('event_form.tpl');
345 $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now');
346 $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now');
348 $tz = date_default_timezone_get();
350 $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC');
352 $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
353 $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
354 $sday = datetime_convert('UTC', $tz, $sdt, 'd');
356 $shour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0);
357 $sminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0);
359 $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
360 $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
361 $fday = datetime_convert('UTC', $tz, $fdt, 'd');
363 $fhour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0);
364 $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0);
366 $f = get_config('system','event_input_format');
370 $dateformat = datesel_format($f);
371 $timeformat = t('hour:minute');
373 require_once('include/acl_selectors.php');
375 $o .= replace_macros($tpl,array(
376 '$post' => $a->get_baseurl() . '/events',
380 '$title' => t('Event details'),
381 '$desc' => sprintf( t('Format is %s %s. Starting date and Description are required.'),$dateformat,$timeformat),
383 '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ',
384 '$s_dsel' => datesel($f,'start',$syear+5,$syear,false,$syear,$smonth,$sday),
385 '$s_tsel' => timesel('start',$shour,$sminute),
386 '$n_text' => t('Finish date/time is not known or not relevant'),
387 '$n_checked' => $n_checked,
388 '$f_text' => t('Event Finishes:'),
389 '$f_dsel' => datesel($f,'finish',$fyear+5,$fyear,false,$fyear,$fmonth,$fday),
390 '$f_tsel' => timesel('finish',$fhour,$fminute),
391 '$a_text' => t('Adjust for viewer timezone'),
392 '$a_checked' => $a_checked,
393 '$d_text' => t('Description:') . ' <span class="required">*</span>',
394 '$d_orig' => $d_orig,
395 '$l_text' => t('Location:'),
396 '$l_orig' => $l_orig,
397 '$sh_text' => t('Share this event'),
398 '$sh_checked' => $sh_checked,
399 '$acl' => (($cid) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $a->user),false)),
400 '$submit' => t('Submit')