3 require_once('include/datetime.php');
4 require_once('include/event.php');
6 function events_post(&$a) {
11 $event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0);
13 $startyear = intval($_POST['startyear']);
14 $startmonth = intval($_POST['startmonth']);
15 $startday = intval($_POST['startday']);
16 $starthour = intval($_POST['starthour']);
17 $startminute = intval($_POST['startminute']);
19 $finishyear = intval($_POST['finishyear']);
20 $finishmonth = intval($_POST['finishmonth']);
21 $finishday = intval($_POST['finishday']);
22 $finishhour = intval($_POST['finishhour']);
23 $finishminute = intval($_POST['finishminute']);
25 $adjust = intval($_POST['adjust']);
26 $nofinish = intval($_POST['nofinish']);
29 $start = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute);
31 $finish = '0000-00-00 00:00:00';
33 $finish = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute);
36 $start = datetime_convert(date_default_timezone_get(),'UTC',$start);
38 $finish = datetime_convert(date_default_timezone_get(),'UTC',$finish);
41 $start = datetime_convert('UTC','UTC',$start);
43 $finish = datetime_convert('UTC','UTC',$finish);
47 $desc = escape_tags($_POST['desc']);
48 $location = escape_tags($_POST['location']);
51 $str_group_allow = perms2str($_POST['group_allow']);
52 $str_contact_allow = perms2str($_POST['contact_allow']);
53 $str_group_deny = perms2str($_POST['group_deny']);
54 $str_contact_deny = perms2str($_POST['contact_deny']);
58 $r = q("UPDATE `event` SET
71 WHERE `id` = %d AND `uid` = %d LIMIT 1",
73 dbesc(datetime_convert()),
81 dbesc($str_contact_allow),
82 dbesc($str_group_allow),
83 dbesc($str_contact_deny),
84 dbesc($str_group_deny),
92 $uri = item_new_uri($a->get_hostname(),local_user());
94 $r = q("INSERT INTO `event` ( `uid`,`uri`,`created`,`edited`,`start`,`finish`,`desc`,`location`,`type`,
95 `adjust`,`nofinish`,`allow_cid`,`allow_gid`,`deny_cid`,`deny_gid`)
96 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' ) ",
99 dbesc(datetime_convert()),
100 dbesc(datetime_convert()),
108 dbesc($str_contact_allow),
109 dbesc($str_group_allow),
110 dbesc($str_contact_deny),
111 dbesc($str_group_deny)
120 function events_content(&$a) {
123 notice( t('Permission denied.') . EOL);
127 $o .= '<h2>' . t('Events') . '</h2>';
134 if($a->argc > 2 && $a->argv[1] == 'event') {
136 $event_id = intval($a->argv[2]);
138 if($a->argv[1] === 'new') {
142 if($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
144 $y = intval($a->argv[1]);
145 $m = intval($a->argv[2]);
149 if($mode == 'view') {
150 $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
151 $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
153 $y = intval($thisyear);
155 $m = intval($thismonth);
159 if($nextmonth > 12) {
172 $o .= '<div id="new-event-link"><a href="' . $a->get_baseurl() . '/events/new' . '" >' . t('Create New Event') . '</a></div>';
173 $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>';
174 $o .= cal($y,$m,false, ' eventcal');
176 $dim = get_dim($y,$m);
177 $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
178 $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
180 $start = datetime_convert('UTC','UTC',$start);
181 $finish = datetime_convert('UTC','UTC',$finish);
183 $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
184 $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
187 $r = q("SELECT * FROM `event` WHERE `uid` = %d
188 AND (( `adjust` = 0 AND `start` >= '%s' AND `finish` <= '%s' )
189 OR ( `adjust` = 1 AND `start` >= '%s' AND `finish` <= '%s' )) ",
190 intval(local_user()),
193 dbesc($adjust_start),
194 dbesc($adjust_finish)
202 $r = sort_by_date($r);
204 $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt));
205 $d = day_translate($d);
206 if($d !== $last_date)
207 $o .= '<hr /><div class="event-list-date">' . $d . '</div>';
209 $o .= format_event_html($rr);
215 if($mode === 'edit' || $mode === 'new') {
216 $htpl = get_markup_template('profed_head.tpl');
217 $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
219 $tpl = get_markup_template('event_form.tpl');
221 $year = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
222 $month = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
223 $day = datetime_convert('UTC', date_default_timezone_get(), 'now', 'd');
225 $o .= replace_macros($tpl,array(
226 '$post' => $a->get_baseurl() . '/events',
227 '$e_text' => t('Event details'),
228 '$e_desc' => t('Format is year-month-day hour:minute. Starting date and Description are required.'),
229 '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ',
230 '$s_dsel' => datesel('start',$year+5,$year,false,$year,$month,$day),
231 '$s_tsel' => timesel('start',0,0),
232 '$n_text' => t('Finish date/time is not known or not relevant'),
234 '$f_text' => t('Event Finishes:'),
235 '$f_dsel' => datesel('finish',$year+5,$year,false,$year,$month,$day),
236 '$f_tsel' => timesel('finish',0,0),
237 '$a_text' => t('Adjust for viewer timezone'),
239 '$d_text' => t('Description:') . ' <span class="required">*</span>',
241 '$l_text' => t('Location:'),
243 '$submit' => t('Submit')