]> git.mxchange.org Git - friendica.git/blob - mod/events.php
Admin users page. some fix to template processor.
[friendica.git] / mod / events.php
1 <?php
2
3 require_once('include/datetime.php');
4 require_once('include/event.php');
5 require_once('include/items.php');
6
7 function events_post(&$a) {
8
9         if(! local_user())
10                 return;
11
12         $event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0);
13         $uid      = local_user();
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']);
19
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']);
25
26         $adjust   = intval($_POST['adjust']);
27         $nofinish = intval($_POST['nofinish']);
28
29
30         $start    = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute);
31         if($nofinish)
32                 $finish = '0000-00-00 00:00:00';
33         else
34                 $finish    = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute);
35
36         if($adjust) {
37                 $start = datetime_convert(date_default_timezone_get(),'UTC',$start);
38                 if(! $nofinish)
39                         $finish = datetime_convert(date_default_timezone_get(),'UTC',$finish);
40         }
41         else {
42                 $start = datetime_convert('UTC','UTC',$start);
43                 if(! $nofinish)
44                         $finish = datetime_convert('UTC','UTC',$finish);
45         }
46
47
48         $desc     = escape_tags(trim($_POST['desc']));
49         $location = escape_tags(trim($_POST['location']));
50         $type     = 'event';
51
52         if((! $desc) || (! $start)) {
53                 notice('Event description and start time are required.');
54                 goaway($a->get_baseurl() . '/events/new');
55         }
56
57         $share = ((intval($_POST['share'])) ? intval($_POST['share']) : 0);
58
59         if($share) {
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']);
64         }
65         else {
66                 $str_contact_allow = '<' . local_user() . '>';
67                 $str_group_allow = $str_contact_deny = $str_group_deny = '';
68         }
69
70
71         $datarray = array();
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;
80         $datarray['cid'] = 0;
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;
88
89         $item_id = event_store($datarray);
90         proc_run('php',"include/notifier.php","event","$item_id");
91
92 }
93
94
95
96 function events_content(&$a) {
97
98         if(! local_user()) {
99                 notice( t('Permission denied.') . EOL);
100                 return;
101         }
102
103         $o .= '<h2>' . t('Events') . '</h2>';
104
105         $mode = 'view';
106         $y = 0;
107         $m = 0;
108
109         if($a->argc > 1) {
110                 if($a->argc > 2 && $a->argv[1] == 'event') {
111                         $mode = 'edit';
112                         $event_id = intval($a->argv[2]);
113                 }
114                 if($a->argv[1] === 'new') {
115                         $mode = 'new';
116                         $event_id = 0;
117                 }
118                 if($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
119                         $mode = 'view';
120                         $y = intval($a->argv[1]);
121                         $m = intval($a->argv[2]);
122                 }
123         }
124
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');
128                 if(! $y)
129                         $y = intval($thisyear);
130                 if(! $m)
131                         $m = intval($thismonth);
132
133                 // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
134                 // An upper limit was chosen to keep search engines from exploring links endlessly. 
135
136                 if($y < 1901)
137                         $y = 1900;
138                 if($y > 2099)
139                         $y = 2100;
140
141                 $nextyear = $y;
142                 $nextmonth = $m + 1;
143                 if($nextmonth > 12) {
144                                 $nextmonth = 1;
145                         $nextyear ++;
146                 }
147
148                 $prevyear = $y;
149                 if($m > 1)
150                         $prevmonth = $m - 1;
151                 else {
152                         $prevmonth = 12;
153                         $prevyear --;
154                 }
155
156                         
157                 $o .= '<div id="new-event-link"><a href="' . $a->get_baseurl() . '/events/new' . '" >' . t('Create New Event') . '</a></div>';
158                 $o .= '<div id="event-calendar-wrapper">';
159
160                 $o .= '<a href="' . $a->get_baseurl() . '/events/' . $prevyear . '/' . $prevmonth . '" class="prevcal"><div id="event-calendar-prev" class="icon prev" title="' . t('Previous') . '"></div></a>';
161                 $o .= cal($y,$m,false, ' eventcal');
162
163                 $o .= '<a href="' . $a->get_baseurl() . '/events/' . $nextyear . '/' . $nextmonth . '" class="nextcal"><div id="event-calendar-next" class="icon next" title="' . t('Next') . '"></div></a>';
164                 $o .= '</div>';
165                 $o .= '<div class="event-calendar-end"></div>';
166
167                 $dim    = get_dim($y,$m);
168                 $start  = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
169                 $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
170         
171                 $start  = datetime_convert('UTC','UTC',$start);
172                 $finish = datetime_convert('UTC','UTC',$finish);
173
174                 $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
175                 $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
176
177
178                 $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` 
179                         WHERE `event`.`uid` = %d
180                         AND (( `adjust` = 0 AND `start` >= '%s' AND `finish` <= '%s' ) 
181                         OR  (  `adjust` = 1 AND `start` >= '%s' AND `finish` <= '%s' )) ",
182                         intval(local_user()),
183                         dbesc($start),
184                         dbesc($finish),
185                         dbesc($adjust_start),
186                         dbesc($adjust_finish)
187                 );
188
189                 $last_date = '';
190
191                 $fmt = t('l, F j');
192
193                 if(count($r)) {
194                         $r = sort_by_date($r);
195                         foreach($r as $rr) {
196
197                                 $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt));
198                                 $d = day_translate($d);
199                                 if($d !== $last_date) 
200                                         $o .= '<hr /><div class="event-list-date">' . $d . '</div>';
201                                 $last_date = $d;
202                                 $o .= format_event_html($rr);
203                                 if($rr['plink'])
204                                         $o .= get_plink($rr) . '<br />';
205                         }
206                 }
207                 return $o;
208         }
209
210         if($mode === 'edit' || $mode === 'new') {
211                 $htpl = get_markup_template('event_head.tpl');
212                 $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
213
214                 $tpl = get_markup_template('event_form.tpl');
215
216                 $year = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
217                 $month = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
218                 $day = datetime_convert('UTC', date_default_timezone_get(), 'now', 'd');
219
220                 require_once('include/acl_selectors.php');
221
222                 $o .= replace_macros($tpl,array(
223                         '$post' => $a->get_baseurl() . '/events',
224                         '$e_text' => t('Event details'),
225                         '$e_desc' => t('Format is year-month-day hour:minute. Starting date and Description are required.'),
226                         '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ',
227                         '$s_dsel' => datesel('start',$year+5,$year,false,$year,$month,$day),
228                         '$s_tsel' => timesel('start',0,0),
229                         '$n_text' => t('Finish date/time is not known or not relevant'),
230                         '$n_checked' => '',
231                         '$f_text' => t('Event Finishes:'),
232                         '$f_dsel' => datesel('finish',$year+5,$year,false,$year,$month,$day),
233                         '$f_tsel' => timesel('finish',0,0),
234                         '$a_text' => t('Adjust for viewer timezone'),
235                         '$a_checked' => '',
236                         '$d_text' => t('Description:') . ' <span class="required">*</span>',
237                         '$d_orig' => '',
238                         '$l_text' => t('Location:'),
239                         '$l_orig' => '',
240                         '$sh_text' => t('Share this event'),
241                         '$sh_checked' => '',
242                         '$acl' => populate_acl($a->user,false),
243                         '$submit' => t('Submit')
244
245                 ));
246
247                 return $o;
248         }
249 }