3 require_once('include/datetime.php');
4 require_once('include/event.php');
5 require_once('include/items.php');
7 function events_post(&$a) {
12 $event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0);
13 $cid = ((x($_POST,'cid')) ? intval($_POST['cid']) : 0);
15 $startyear = intval($_POST['startyear']);
16 $startmonth = intval($_POST['startmonth']);
17 $startday = intval($_POST['startday']);
18 $starthour = intval($_POST['starthour']);
19 $startminute = intval($_POST['startminute']);
21 $finishyear = intval($_POST['finishyear']);
22 $finishmonth = intval($_POST['finishmonth']);
23 $finishday = intval($_POST['finishday']);
24 $finishhour = intval($_POST['finishhour']);
25 $finishminute = intval($_POST['finishminute']);
27 $adjust = intval($_POST['adjust']);
28 $nofinish = intval($_POST['nofinish']);
31 $start = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute);
33 $finish = '0000-00-00 00:00:00';
35 $finish = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute);
38 $start = datetime_convert(date_default_timezone_get(),'UTC',$start);
40 $finish = datetime_convert(date_default_timezone_get(),'UTC',$finish);
43 $start = datetime_convert('UTC','UTC',$start);
45 $finish = datetime_convert('UTC','UTC',$finish);
49 $desc = escape_tags(trim($_POST['desc']));
50 $location = escape_tags(trim($_POST['location']));
53 if((! $desc) || (! $start)) {
54 notice('Event description and start time are required.');
55 goaway($a->get_baseurl() . '/events/new');
58 $share = ((intval($_POST['share'])) ? intval($_POST['share']) : 0);
61 $str_group_allow = perms2str($_POST['group_allow']);
62 $str_contact_allow = perms2str($_POST['contact_allow']);
63 $str_group_deny = perms2str($_POST['group_deny']);
64 $str_contact_deny = perms2str($_POST['contact_deny']);
67 $str_contact_allow = '<' . local_user() . '>';
68 $str_group_allow = $str_contact_deny = $str_group_deny = '';
73 $datarray['start'] = $start;
74 $datarray['finish'] = $finish;
75 $datarray['desc'] = $desc;
76 $datarray['location'] = $location;
77 $datarray['type'] = $type;
78 $datarray['adjust'] = $adjust;
79 $datarray['nofinish'] = $nofinish;
80 $datarray['uid'] = $uid;
81 $datarray['cid'] = $cid;
82 $datarray['allow_cid'] = $str_contact_allow;
83 $datarray['allow_gid'] = $str_group_allow;
84 $datarray['deny_cid'] = $str_contact_deny;
85 $datarray['deny_gid'] = $str_group_deny;
86 $datarray['id'] = $event_id;
87 $datarray['created'] = $created;
88 $datarray['edited'] = $edited;
90 $item_id = event_store($datarray);
93 proc_run('php',"include/notifier.php","event","$item_id");
99 function events_content(&$a) {
102 notice( t('Permission denied.') . EOL);
108 $tpl = get_markup_template('profile_tabs.tpl');
109 $o .= replace_macros($tpl,array(
110 '$url' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
111 '$phototab' => $a->get_baseurl() . '/photos/' . $a->user['nickname'],
112 '$status' => t('Status'),
113 '$profile' => t('Profile'),
114 '$photos' => t('Photos'),
115 '$events' => t('Events') ,
116 '$notes' => t('Personal Notes'),
117 '$activetab' => "events",
120 $o .= '<h2>' . t('Events') . '</h2>';
128 if($a->argc > 2 && $a->argv[1] == 'event') {
130 $event_id = intval($a->argv[2]);
132 if($a->argv[1] === 'new') {
136 if($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
138 $y = intval($a->argv[1]);
139 $m = intval($a->argv[2]);
143 if($mode == 'view') {
144 $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
145 $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
147 $y = intval($thisyear);
149 $m = intval($thismonth);
151 // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
152 // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
161 if($nextmonth > 12) {
175 $dim = get_dim($y,$m);
176 $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
177 $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
179 $start = datetime_convert('UTC','UTC',$start);
180 $finish = datetime_convert('UTC','UTC',$finish);
182 $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
183 $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
186 $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
187 `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id`
188 WHERE `event`.`uid` = %d
189 AND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' )
190 OR ( `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ",
191 intval(local_user()),
194 dbesc($adjust_start),
195 dbesc($adjust_finish)
201 $r = sort_by_date($r);
203 $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
205 $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
210 $o .= '<div id="new-event-link"><a href="' . $a->get_baseurl() . '/events/new' . '" >' . t('Create New Event') . '</a></div>';
211 $o .= '<div id="event-calendar-wrapper">';
213 $o .= '<a href="' . $a->get_baseurl() . '/events/' . $prevyear . '/' . $prevmonth . '" class="prevcal"><div id="event-calendar-prev" class="icon prev" title="' . t('Previous') . '"></div></a>';
214 $o .= cal($y,$m,$links, ' eventcal');
216 $o .= '<a href="' . $a->get_baseurl() . '/events/' . $nextyear . '/' . $nextmonth . '" class="nextcal"><div id="event-calendar-next" class="icon next" title="' . t('Next') . '"></div></a>';
218 $o .= '<div class="event-calendar-end"></div>';
226 $r = sort_by_date($r);
228 $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
229 $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt));
230 $d = day_translate($d);
231 if($d !== $last_date)
232 $o .= '<hr /><a name="link-' . $j . '" ><div class="event-list-date">' . $d . '</div></a>';
234 $o .= format_event_html($rr);
235 $o .= (($rr['cid']) ? '<a href="' . $a->get_baseurl() . '/events/event/' . $rr['id'] . '" title="' . t('Edit event') . '" class="edit-event-link icon pencil"></a>' : '');
237 $o .= '<a href="' . $rr['plink'] . '" title="' . t('link to source') . '" target="external-link" class="plink-event-link icon remote-link"></a></div>';
239 $o .= '<div class="clear"></div>';
246 if($mode === 'edit' && $event_id) {
247 $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1",
255 if($mode === 'edit' || $mode === 'new') {
257 $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : '');
258 $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : '');
259 $d_orig = ((x($orig_event)) ? $orig_event['desc'] : '');
260 $l_orig = ((x($orig_event)) ? $orig_event['location'] : '');
261 $eid = ((x($orig_event)) ? $orig_event['id'] : 0);
262 $cid = ((x($orig_event)) ? $orig_event['cid'] : 0);
263 $uri = ((x($orig_event)) ? $orig_event['uri'] : '');
269 $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ' );
272 $sh_checked .= ' disabled="disabled" ';
274 $htpl = get_markup_template('event_head.tpl');
275 $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
277 $tpl = get_markup_template('event_form.tpl');
279 $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now');
280 $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now');
282 $tz = ((x($orig_event) && $orig_event['adjust']) ? date_default_timezone_get() : 'UTC');
286 $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
287 $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
288 $sday = datetime_convert('UTC', $tz, $sdt, 'd');
290 $shour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0);
291 $sminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0);
293 $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
294 $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
295 $fday = datetime_convert('UTC', $tz, $fdt, 'd');
297 $fhour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0);
298 $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0);
301 require_once('include/acl_selectors.php');
303 $o .= replace_macros($tpl,array(
304 '$post' => $a->get_baseurl() . '/events',
308 '$e_text' => t('Event details'),
309 '$e_desc' => t('Format is year-month-day hour:minute. Starting date and Description are required.'),
310 '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ',
311 '$s_dsel' => datesel('start',$syear+5,$syear,false,$syear,$smonth,$sday),
312 '$s_tsel' => timesel('start',$shour,$sminute),
313 '$n_text' => t('Finish date/time is not known or not relevant'),
314 '$n_checked' => $n_checked,
315 '$f_text' => t('Event Finishes:'),
316 '$f_dsel' => datesel('finish',$fyear+5,$fyear,false,$fyear,$fmonth,$fday),
317 '$f_tsel' => timesel('finish',$fhour,$fminute),
318 '$a_text' => t('Adjust for viewer timezone'),
319 '$a_checked' => $a_checked,
320 '$d_text' => t('Description:') . ' <span class="required">*</span>',
321 '$d_orig' => $d_orig,
322 '$l_text' => t('Location:'),
323 '$l_orig' => $l_orig,
324 '$sh_text' => t('Share this event'),
325 '$sh_checked' => $sh_checked,
326 '$acl' => (($cid) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $a->user),false)),
327 '$submit' => t('Submit')