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 = '';
72 $datarray['start'] = $start;
73 $datarray['finish'] = $finish;
74 $datarray['desc'] = $desc;
75 $datarray['location'] = $location;
76 $datarray['type'] = $type;
77 $datarray['adjust'] = $adjust;
78 $datarray['nofinish'] = $nofinish;
79 $datarray['uid'] = $uid;
81 $datarray['allow_cid'] = $str_contact_allow;
82 $datarray['allow_gid'] = $str_group_allow;
83 $datarray['deny_cid'] = $str_contact_deny;
84 $datarray['deny_gid'] = $str_group_deny;
85 $datarray['id'] = $event_id;
86 $datarray['created'] = $created;
87 $datarray['edited'] = $edited;
89 $item_id = event_store($datarray);
90 proc_run('php',"include/notifier.php","event","$item_id");
96 function events_content(&$a) {
99 notice( t('Permission denied.') . EOL);
103 $o .= '<h2>' . t('Events') . '</h2>';
110 if($a->argc > 2 && $a->argv[1] == 'event') {
112 $event_id = intval($a->argv[2]);
114 if($a->argv[1] === 'new') {
118 if($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
120 $y = intval($a->argv[1]);
121 $m = intval($a->argv[2]);
125 if($mode == 'view') {
126 $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
127 $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
129 $y = intval($thisyear);
131 $m = intval($thismonth);
135 if($nextmonth > 12) {
148 $o .= '<div id="new-event-link"><a href="' . $a->get_baseurl() . '/events/new' . '" >' . t('Create New Event') . '</a></div>';
149 $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>';
150 $o .= cal($y,$m,false, ' eventcal');
152 $dim = get_dim($y,$m);
153 $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
154 $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
156 $start = datetime_convert('UTC','UTC',$start);
157 $finish = datetime_convert('UTC','UTC',$finish);
159 $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
160 $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
163 $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id`
164 WHERE `event`.`uid` = %d
165 AND (( `adjust` = 0 AND `start` >= '%s' AND `finish` <= '%s' )
166 OR ( `adjust` = 1 AND `start` >= '%s' AND `finish` <= '%s' )) ",
167 intval(local_user()),
170 dbesc($adjust_start),
171 dbesc($adjust_finish)
179 $r = sort_by_date($r);
182 $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt));
183 $d = day_translate($d);
184 if($d !== $last_date)
185 $o .= '<hr /><div class="event-list-date">' . $d . '</div>';
187 $o .= format_event_html($rr);
189 $o .= get_plink($rr) . '<br />';
195 if($mode === 'edit' || $mode === 'new') {
196 $htpl = get_markup_template('event_head.tpl');
197 $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
199 $tpl = get_markup_template('event_form.tpl');
201 $year = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
202 $month = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
203 $day = datetime_convert('UTC', date_default_timezone_get(), 'now', 'd');
205 require_once('include/acl_selectors.php');
207 $o .= replace_macros($tpl,array(
208 '$post' => $a->get_baseurl() . '/events',
209 '$e_text' => t('Event details'),
210 '$e_desc' => t('Format is year-month-day hour:minute. Starting date and Description are required.'),
211 '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ',
212 '$s_dsel' => datesel('start',$year+5,$year,false,$year,$month,$day),
213 '$s_tsel' => timesel('start',0,0),
214 '$n_text' => t('Finish date/time is not known or not relevant'),
216 '$f_text' => t('Event Finishes:'),
217 '$f_dsel' => datesel('finish',$year+5,$year,false,$year,$month,$day),
218 '$f_tsel' => timesel('finish',0,0),
219 '$a_text' => t('Adjust for viewer timezone'),
221 '$d_text' => t('Description:') . ' <span class="required">*</span>',
223 '$l_text' => t('Location:'),
225 '$sh_text' => t('Share this event'),
227 '$acl' => populate_acl($a->user,false),
228 '$submit' => t('Submit')