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']);
31 // The default setting for the `private` field in event_store() is false, so mirror that
32 $private_event = false;
35 $start = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute);
37 $finish = '0000-00-00 00:00:00';
39 $finish = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute);
42 $start = datetime_convert(date_default_timezone_get(),'UTC',$start);
44 $finish = datetime_convert(date_default_timezone_get(),'UTC',$finish);
47 $start = datetime_convert('UTC','UTC',$start);
49 $finish = datetime_convert('UTC','UTC',$finish);
52 // Don't allow the event to finish before it begins.
53 // It won't hurt anything, but somebody will file a bug report
54 // and we'll waste a bunch of time responding to it. Time that
55 // could've been spent doing something else.
57 if(strcmp($finish,$start) < 0)
60 $summary = escape_tags(trim($_POST['summary']));
61 $desc = escape_tags(trim($_POST['desc']));
62 $location = escape_tags(trim($_POST['location']));
65 if((! $summary) || (! $start)) {
66 notice( t('Event title and start time are required.') . EOL);
67 goaway($a->get_baseurl() . '/events/new');
70 $share = ((intval($_POST['share'])) ? intval($_POST['share']) : 0);
72 $c = q("select id from contact where uid = %d and self = 1 limit 1",
82 $str_group_allow = perms2str($_POST['group_allow']);
83 $str_contact_allow = perms2str($_POST['contact_allow']);
84 $str_group_deny = perms2str($_POST['group_deny']);
85 $str_contact_deny = perms2str($_POST['contact_deny']);
87 // Undo the pseudo-contact of self, since there are real contacts now
88 if( strpos($str_contact_allow, '<' . $self . '>') !== false )
90 $str_contact_allow = str_replace('<' . $self . '>', '', $str_contact_allow);
92 // Make sure to set the `private` field as true. This is necessary to
93 // have the posts show up correctly in Diaspora if an event is created
94 // as visible only to self at first, but then edited to display to others.
95 if( strlen($str_group_allow) or strlen($str_contact_allow) or strlen($str_group_deny) or strlen($str_contact_deny) )
97 $private_event = true;
101 // Note: do not set `private` field for self-only events. It will
102 // keep even you from seeing them!
103 $str_contact_allow = '<' . $self . '>';
104 $str_group_allow = $str_contact_deny = $str_group_deny = '';
109 $datarray['start'] = $start;
110 $datarray['finish'] = $finish;
111 $datarray['summary'] = $summary;
112 $datarray['desc'] = $desc;
113 $datarray['location'] = $location;
114 $datarray['type'] = $type;
115 $datarray['adjust'] = $adjust;
116 $datarray['nofinish'] = $nofinish;
117 $datarray['uid'] = $uid;
118 $datarray['cid'] = $cid;
119 $datarray['allow_cid'] = $str_contact_allow;
120 $datarray['allow_gid'] = $str_group_allow;
121 $datarray['deny_cid'] = $str_contact_deny;
122 $datarray['deny_gid'] = $str_group_deny;
123 $datarray['private'] = (($private_event) ? 1 : 0);
124 $datarray['id'] = $event_id;
125 $datarray['created'] = $created;
126 $datarray['edited'] = $edited;
128 $item_id = event_store($datarray);
131 proc_run('php',"include/notifier.php","event","$item_id");
137 function events_content(&$a) {
140 notice( t('Permission denied.') . EOL);
144 if(($a->argc > 2) && ($a->argv[1] === 'ignore') && intval($a->argv[2])) {
145 $r = q("update event set ignore = 1 where id = %d and uid = %d limit 1",
151 if(($a->argc > 2) && ($a->argv[1] === 'unignore') && intval($a->argv[2])) {
152 $r = q("update event set ignore = 0 where id = %d and uid = %d limit 1",
159 $htpl = get_markup_template('event_head.tpl');
160 $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
162 $etpl = get_markup_template('event_end.tpl');
163 $a->page['end'] .= replace_macros($etpl,array('$baseurl' => $a->get_baseurl()));
167 $tabs = profile_tabs($a, True);
174 $ignored = ((x($_REQUEST,'ignored')) ? intval($_REQUEST['ignored']) : 0);
177 if($a->argc > 2 && $a->argv[1] == 'event') {
179 $event_id = intval($a->argv[2]);
181 if($a->argv[1] === 'new') {
185 if($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
187 $y = intval($a->argv[1]);
188 $m = intval($a->argv[2]);
192 if($mode == 'view') {
195 $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
196 $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
198 $y = intval($thisyear);
200 $m = intval($thismonth);
202 // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
203 // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
212 if($nextmonth > 12) {
225 $dim = get_dim($y,$m);
226 $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
227 $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
230 if ($a->argv[1] === 'json'){
231 if (x($_GET,'start')) $start = date("Y-m-d h:i:s", $_GET['start']);
232 if (x($_GET,'end')) $finish = date("Y-m-d h:i:s", $_GET['end']);
235 $start = datetime_convert('UTC','UTC',$start);
236 $finish = datetime_convert('UTC','UTC',$finish);
238 $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
239 $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
243 $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
244 `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id`
245 WHERE `event`.`uid` = %d AND `event`.`id` = %d",
246 intval(local_user()),
250 $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
251 `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id`
252 WHERE `event`.`uid` = %d and event.ignore = %d
253 AND (( `adjust` = 0 AND `finish` >= '%s' AND `start` <= '%s' )
254 OR ( `adjust` = 1 AND `finish` >= '%s' AND `start` <= '%s' )) ",
255 intval(local_user()),
259 dbesc($adjust_start),
260 dbesc($adjust_finish)
267 $r = sort_by_date($r);
269 $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
271 $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
282 $r = sort_by_date($r);
286 $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
287 $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt));
288 $d = day_translate($d);
290 $start = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'c') : datetime_convert('UTC','UTC',$rr['start'],'c'));
291 if ($rr['nofinish']){
294 $end = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['finish'], 'c') : datetime_convert('UTC','UTC',$rr['finish'],'c'));
298 $is_first = ($d !== $last_date);
301 $edit = ((! $rr['cid']) ? array($a->get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null);
302 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
304 list($title, $_trash) = explode("<br",bbcode($rr['desc']),2);
305 $title = strip_tags(html_entity_decode($title,ENT_QUOTES,'UTF-8'));
307 $html = format_event_html($rr);
308 $rr['desc'] = bbcode($rr['desc']);
309 $rr['location'] = bbcode($rr['location']);
320 'is_first'=>$is_first,
323 'plink' => array($rr['plink'],t('link to source'),'',''),
330 if ($a->argv[1] === 'json'){
331 echo json_encode($events); killme();
334 // links: array('href', 'text', 'extra css classes', 'title')
336 $tpl = get_markup_template("event.tpl");
338 // if (get_config('experimentals','new_calendar')==1){
339 $tpl = get_markup_template("events-js.tpl");
341 // $tpl = get_markup_template("events.tpl");
344 $o = replace_macros($tpl, array(
345 '$baseurl' => $a->get_baseurl(),
347 '$title' => t('Events'),
348 '$new_event'=> array($a->get_baseurl().'/events/new',t('Create New Event'),'',''),
349 '$previus' => array($a->get_baseurl()."/events/$prevyear/$prevmonth",t('Previous'),'',''),
350 '$next' => array($a->get_baseurl()."/events/$nextyear/$nextmonth",t('Next'),'',''),
351 '$calendar' => cal($y,$m,$links, ' eventcal'),
353 '$events' => $events,
358 if (x($_GET,'id')){ echo $o; killme(); }
364 if($mode === 'edit' && $event_id) {
365 $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1",
373 if($mode === 'edit' || $mode === 'new') {
375 $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : '');
376 $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : '');
377 $t_orig = ((x($orig_event)) ? $orig_event['summary'] : '');
378 $d_orig = ((x($orig_event)) ? $orig_event['desc'] : '');
379 $l_orig = ((x($orig_event)) ? $orig_event['location'] : '');
380 $eid = ((x($orig_event)) ? $orig_event['id'] : 0);
381 $cid = ((x($orig_event)) ? $orig_event['cid'] : 0);
382 $uri = ((x($orig_event)) ? $orig_event['uri'] : '');
388 $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ' );
391 $sh_checked .= ' disabled="disabled" ';
395 $tpl = get_markup_template('event_form.tpl');
397 $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now');
398 $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now');
400 $tz = date_default_timezone_get();
402 $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC');
404 $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
405 $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
406 $sday = datetime_convert('UTC', $tz, $sdt, 'd');
408 $shour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0);
409 $sminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0);
411 $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
412 $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
413 $fday = datetime_convert('UTC', $tz, $fdt, 'd');
415 $fhour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0);
416 $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0);
418 $f = get_config('system','event_input_format');
422 $dateformat = datesel_format($f);
423 $timeformat = t('hour:minute');
425 require_once('include/acl_selectors.php');
427 $o .= replace_macros($tpl,array(
428 '$post' => $a->get_baseurl() . '/events',
433 '$title' => t('Event details'),
434 '$desc' => sprintf( t('Format is %s %s. Starting date and Title are required.'),$dateformat,$timeformat),
436 '$s_text' => t('Event Starts:') . ' <span class="required" title="' . t('Required') . '">*</span>',
437 '$s_dsel' => datesel($f,'start',$syear+5,$syear,false,$syear,$smonth,$sday),
438 '$s_tsel' => timesel('start',$shour,$sminute),
439 '$n_text' => t('Finish date/time is not known or not relevant'),
440 '$n_checked' => $n_checked,
441 '$f_text' => t('Event Finishes:'),
442 '$f_dsel' => datesel($f,'finish',$fyear+5,$fyear,false,$fyear,$fmonth,$fday),
443 '$f_tsel' => timesel('finish',$fhour,$fminute),
444 '$a_text' => t('Adjust for viewer timezone'),
445 '$a_checked' => $a_checked,
446 '$d_text' => t('Description:'),
447 '$d_orig' => $d_orig,
448 '$l_text' => t('Location:'),
449 '$l_orig' => $l_orig,
450 '$t_text' => t('Title:') . ' <span class="required" title="' . t('Required') . '">*</span>',
451 '$t_orig' => $t_orig,
452 '$sh_text' => t('Share this event'),
453 '$sh_checked' => $sh_checked,
454 '$acl' => (($cid) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $a->user),false)),
455 '$submit' => t('Submit')