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);
14 $startyear = intval($_POST['startyear']);
15 $startmonth = intval($_POST['startmonth']);
16 $startday = intval($_POST['startday']);
17 $starthour = intval($_POST['starthour']);
18 $startminute = intval($_POST['startminute']);
20 $finishyear = intval($_POST['finishyear']);
21 $finishmonth = intval($_POST['finishmonth']);
22 $finishday = intval($_POST['finishday']);
23 $finishhour = intval($_POST['finishhour']);
24 $finishminute = intval($_POST['finishminute']);
26 $adjust = intval($_POST['adjust']);
27 $nofinish = intval($_POST['nofinish']);
30 $start = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute);
32 $finish = '0000-00-00 00:00:00';
34 $finish = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute);
37 $start = datetime_convert(date_default_timezone_get(),'UTC',$start);
39 $finish = datetime_convert(date_default_timezone_get(),'UTC',$finish);
42 $start = datetime_convert('UTC','UTC',$start);
44 $finish = datetime_convert('UTC','UTC',$finish);
48 $desc = escape_tags(trim($_POST['desc']));
49 $location = escape_tags(trim($_POST['location']));
52 if((! $desc) || (! $start)) {
53 notice('Event description and start time are required.');
54 goaway($a->get_baseurl() . '/events/new');
57 $share = ((intval($_POST['share'])) ? intval($_POST['share']) : 0);
60 $str_group_allow = perms2str($_POST['group_allow']);
61 $str_contact_allow = perms2str($_POST['contact_allow']);
62 $str_group_deny = perms2str($_POST['group_deny']);
63 $str_contact_deny = perms2str($_POST['contact_deny']);
66 $str_contact_allow = '<' . local_user() . '>';
67 $str_group_allow = $str_contact_deny = $str_group_deny = '';
71 $r = q("UPDATE `event` SET
84 WHERE `id` = %d AND `uid` = %d LIMIT 1",
86 dbesc(datetime_convert()),
94 dbesc($str_contact_allow),
95 dbesc($str_group_allow),
96 dbesc($str_contact_deny),
97 dbesc($str_group_deny),
105 $uri = item_new_uri($a->get_hostname(),local_user());
107 $r = q("INSERT INTO `event` ( `uid`,`uri`,`created`,`edited`,`start`,`finish`,`desc`,`location`,`type`,
108 `adjust`,`nofinish`,`allow_cid`,`allow_gid`,`deny_cid`,`deny_gid`)
109 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' ) ",
110 intval(local_user()),
112 dbesc(datetime_convert()),
113 dbesc(datetime_convert()),
121 dbesc($str_contact_allow),
122 dbesc($str_group_allow),
123 dbesc($str_contact_deny),
124 dbesc($str_group_deny)
128 $r = q("SELECT * FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
137 $arr['uid'] = local_user();
139 $arr['parent-uri'] = $uri;
140 $arr['type'] = 'activity';
142 $arr['contact-id'] = $a->contact['id'];
143 $arr['owner-name'] = $a->contact['name'];
144 $arr['owner-link'] = $a->contact['url'];
145 $arr['owner-avatar'] = $a->contact['thumb'];
146 $arr['author-name'] = $a->contact['name'];
147 $arr['author-link'] = $a->contact['url'];
148 $arr['author-avatar'] = $a->contact['thumb'];
150 $arr['allow_cid'] = $str_contact_allow;
151 $arr['allow_gid'] = $str_group_allow;
152 $arr['deny_cid'] = $str_contact_deny;
153 $arr['deny_gid'] = $str_group_deny;
154 $arr['last-child'] = 1;
156 $arr['verb'] = ACTIVITY_POST;
157 $arr['object-type'] = ACTIVITY_OBJ_EVENT;
159 $arr['body'] = format_event_bbcode($event);
162 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_EVENT . '</type><title></title><id>' . $uri . '</id>';
163 $arr['object'] .= '<content>' . format_event_bbcode($event) . '</content>';
164 $arr['object'] .= '</object>' . "\n";
166 $item_id = item_store($arr);
168 q("UPDATE `item` SET `plink` = '%s', `event-id` = %d WHERE `uid` = %d AND `id` = %d LIMIT 1",
169 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
170 intval($event['id']),
171 intval(local_user()),
174 proc_run('php',"include/notifier.php","tag","$item_id");
181 function events_content(&$a) {
184 notice( t('Permission denied.') . EOL);
188 $o .= '<h2>' . t('Events') . '</h2>';
195 if($a->argc > 2 && $a->argv[1] == 'event') {
197 $event_id = intval($a->argv[2]);
199 if($a->argv[1] === 'new') {
203 if($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
205 $y = intval($a->argv[1]);
206 $m = intval($a->argv[2]);
210 if($mode == 'view') {
211 $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
212 $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
214 $y = intval($thisyear);
216 $m = intval($thismonth);
220 if($nextmonth > 12) {
233 $o .= '<div id="new-event-link"><a href="' . $a->get_baseurl() . '/events/new' . '" >' . t('Create New Event') . '</a></div>';
234 $o .= '<a href="' . $a->get_baseurl() . '/events/' . $prevyear . '/' . $prevmonth . '" class="prevcal">' . t('<< Previous') . '</a> | <a href="' . $a->get_baseurl() . '/events/' . $nextyear . '/' . $nextmonth . '" class="nextcal">' . t('Next >>') . '</a>';
235 $o .= cal($y,$m,false, ' eventcal');
237 $dim = get_dim($y,$m);
238 $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
239 $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
241 $start = datetime_convert('UTC','UTC',$start);
242 $finish = datetime_convert('UTC','UTC',$finish);
244 $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
245 $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
248 $r = q("SELECT * FROM `event` WHERE `uid` = %d
249 AND (( `adjust` = 0 AND `start` >= '%s' AND `finish` <= '%s' )
250 OR ( `adjust` = 1 AND `start` >= '%s' AND `finish` <= '%s' )) ",
251 intval(local_user()),
254 dbesc($adjust_start),
255 dbesc($adjust_finish)
263 $r = sort_by_date($r);
266 $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt));
267 $d = day_translate($d);
268 if($d !== $last_date)
269 $o .= '<hr /><div class="event-list-date">' . $d . '</div>';
271 $o .= format_event_html($rr);
277 if($mode === 'edit' || $mode === 'new') {
278 $htpl = get_markup_template('event_head.tpl');
279 $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
281 $tpl = get_markup_template('event_form.tpl');
283 $year = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
284 $month = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
285 $day = datetime_convert('UTC', date_default_timezone_get(), 'now', 'd');
287 require_once('include/acl_selectors.php');
289 $o .= replace_macros($tpl,array(
290 '$post' => $a->get_baseurl() . '/events',
291 '$e_text' => t('Event details'),
292 '$e_desc' => t('Format is year-month-day hour:minute. Starting date and Description are required.'),
293 '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ',
294 '$s_dsel' => datesel('start',$year+5,$year,false,$year,$month,$day),
295 '$s_tsel' => timesel('start',0,0),
296 '$n_text' => t('Finish date/time is not known or not relevant'),
298 '$f_text' => t('Event Finishes:'),
299 '$f_dsel' => datesel('finish',$year+5,$year,false,$year,$month,$day),
300 '$f_tsel' => timesel('finish',0,0),
301 '$a_text' => t('Adjust for viewer timezone'),
303 '$d_text' => t('Description:') . ' <span class="required">*</span>',
305 '$l_text' => t('Location:'),
307 '$sh_text' => t('Share this event'),
309 '$acl' => populate_acl($a->user,false),
310 '$submit' => t('Submit')