xref: /web-master/manage/event.php (revision 81b302aa)
1<?php
2require __DIR__ . '/../include/login.inc';
3require __DIR__ . '/../include/email-validation.inc';
4
5define('PHP_SELF', hsc($_SERVER['PHP_SELF']));
6
7$mailto = "php-webmaster@lists.php.net";
8#$mailto = "jimw@apache.org";
9
10$days = $months = array();
11
12for ($i = 1; $i <= 7; $i++) {
13  $days[$i] = strftime('%A',mktime(12,0,0,4,$i,2001));
14}
15
16for ($i = 1; $i <= 12; $i++) {
17  $months[$i] = strftime('%B',mktime(12,0,0,$i,1,2001));
18}
19
20$re = [1=>'First',2=>'Second',3=>'Third',4=>'Fourth',-1=>'Last',-2=>'2nd Last',-3=>'3rd Last'];
21$cat = ["unknown", "User Group Event", "Conference", "Training"];
22
23$type = [1=>'single',2=>'multi',3=>'recur'];
24
25head("event administration");
26db_connect();
27
28$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : false;
29$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : false;
30$in = isset($_REQUEST['in']) ? $_REQUEST['in'] : false;
31$begin = isset($_REQUEST['begin']) ? $_REQUEST['begin'] : false;
32$max = isset($_REQUEST['max']) ? $_REQUEST['max'] : false;
33$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : false;
34$order = isset($_REQUEST['order']) ? $_REQUEST['order'] : false;
35$full = isset($_REQUEST['full']) ? $_REQUEST['full'] : false;
36$unapproved = isset($_REQUEST['unapproved']) ? $_REQUEST['unapproved'] : false;
37
38if($id) $id = (int)$id;
39
40if ($id && $action) {
41  switch ($action) {
42  case 'approve':
43    if (db_query_safe("UPDATE phpcal SET approved=1,app_by=? WHERE id=?", [$cuser, $id])
44     && mysql_affected_rows()) {
45      $event = fetch_event($id);
46      $message = "This event has been approved. It will appear on the PHP website shortly.";
47      if ($event['email']) mail($event['email'],"Event #$id Approved: $event[sdesc]",$message,"From: PHP Webmasters <php-webmaster@lists.php.net>", "-fnoreply@php.net -O DeliveryMode=b");
48
49      warn("record $id approved");
50    }
51    else {
52      warn("wasn't able to approve id $id.");
53    }
54    break;
55  case 'reject':
56    $event = fetch_event($id);
57    if (db_query_safe("DELETE FROM phpcal WHERE id=?", [$id])
58     && mysql_affected_rows()) {
59      $message = $event['approved'] ?  "This event has been deleted." : "This event has been rejected.";
60      $did = $event['approved'] ? 'Deleted' : 'Rejected';
61
62      if ($event['email']) mail($event['email'],"Event #$id $did: $event[sdesc]",$message,"From: PHP Webmasters <php-webmaster@lists.php.net>", "-fnoreply@php.net -O DeliveryMode=b");
63
64      warn("record $id ".strtolower($did));
65
66      unset($id);
67    }
68    else {
69      warn("wasn't able to delete id $id.");
70    }
71    break;
72  default:
73    warn("that action ('".html_entity_decode($action,ENT_QUOTES)."') is not understood.");
74  }
75}
76
77if ($id && $in) {
78    $tipo = array_search($in['type'],$type);
79    if ($in['sday'] && $in['smonth'] && $in['syear'])
80      $sdato = "$in[syear]-$in[smonth]-$in[sday]";
81    if ($in['eday'] && $in['emonth'] && $in['eyear'])
82      $edato = "$in[eyear]-$in[emonth]-$in[eday]";
83    if ($in['recur'] && $in['recur_day'])
84      $recur = "$in[recur]:$in[recur_day]";
85    $query = new Query('UPDATE phpcal SET ');
86    if ($sdato) {
87      $query->add('sdato=?, ', [$sdato]);
88    }
89    if ($edato) {
90      $query->add('edato=?, ', [$edato]);
91    }
92    if ($recur) {
93      $query->add('recur=?, ', [$recur]);
94    }
95    $query->add(
96      "tipo=?, ldesc=?, sdesc=?, email=?, url=?, country=?, category=? WHERE id=?",
97      [$tipo, $in['ldesc'], $in['sdesc'], $in['email'], $in['url'], $in['country'], $in['category'], $id]
98    );
99    db_query($query);
100
101    warn("record $id updated");
102    unset($id);
103}
104
105if ($id && !$in) {
106  $in = fetch_event($id);
107  if (!$in) {
108    unset($id);
109  }
110  else {
111    @list($in['syear'],$in['smonth'],$in['sday']) = @explode("-",$in['sdato']);
112    @list($in['eyear'],$in['emonth'],$in['eday']) = @explode("-",$in['edato']);
113    @list($in['recur'],$in['recur_day']) = @explode(':',$in['recur']);
114    $in['type'] = $type[$in['tipo']];
115  }
116}
117elseif ($in) {
118  foreach ($in as $k => $v) {
119    $in[$k] = $v;
120  }
121}
122
123if ($id) {
124?>
125<form action="<?php echo PHP_SELF?>" method="post">
126<input type="hidden" name="id" value="<?php echo $id?>" />
127<table class="useredit">
128 <tr>
129  <th>Start Date</th>
130  <td>
131   <select name="in[smonth]"><option></option><?php display_options($months,$in['smonth'])?></select>
132   <input type="text" name="in[sday]" size="2" maxlength="2" value="<?php echo hsc($in['sday'])?>" />
133   <input type="text" name="in[syear]" size="4" maxlength="4" value="<?php echo $in['syear'] ? hsc($in['syear']) : date("Y")?>" />
134   <input type="radio" id="single" name="in[type]" value="single"<?php if ($in['type'] == 'single' || !$in['type']) echo ' checked="checked"';?> />
135   <label for="single">One day (no end-date required)</label>
136  </td>
137 </tr>
138 <tr>
139  <th>End Date</th>
140  <td>
141   <select name="in[emonth]"><option></option><?php display_options($months,$in['emonth'])?></select>
142   <input type="text" name="in[eday]" size="2" maxlength="2" value="<?php echo hsc($in['eday'])?>" />
143   <input type="text" name="in[eyear]" size="4" maxlength="4" value="<?php echo $in['eyear'] ? hsc($in['eyear']) : date("Y")?>" />
144   <input type="radio" id="multi" name="in[type]" value="multi"<?php if ($in['type'] == 'multi') echo ' checked="checked"';?> />
145   <label for="multi">Multi-day event</label>
146  </td>
147 </tr>
148 <tr>
149  <th>OR<br>Recurring</th>
150  <td>
151   <select name="in[recur]"><option></option><?php display_options($re,$in['recur'])?></select>
152   <select name="in[recur_day]"><option></option><?php display_options($days,$in['recur_day'])?></select>
153   <input type="radio" id="recur" name="in[type]" value="recur"<?php if ($in['type'] == 'recur') echo ' checked="checked"';?> />
154   <label for="recur">Recurring (every month)</label>
155  </td>
156 </tr>
157 <tr>
158  <th>Short<br>Description</th>
159  <td><input type="text" name="in[sdesc]" value="<?php echo html_entity_decode($in['sdesc'],ENT_QUOTES)?>" size="32" maxlength="32" /></td>
160 </tr>
161 <tr>
162  <th>Country</th>
163  <td>
164   <select name="in[country]">
165    <option value="">- Select a country -</option>
166    <?php show_country_options($in['country']);?>
167   </select>
168  </td>
169 </tr>
170 <tr>
171  <th>Event Category</th>
172  <td>
173   <select name="in[category]">
174<?php
175        display_options($cat,$in['category']);
176?>
177   </select>
178  </td>
179 </tr>
180 <tr>
181  <th>Email</th>
182  <td><input type="text" name="in[email]" size="40" maxlength="128" value="<?php echo html_entity_decode($in['email'],ENT_QUOTES)?>" /></td>
183 </tr>
184 <tr>
185  <th>URL</th>
186  <td><input type="text" name="in[url]" size="40" maxlength="128" value="<?php echo html_entity_decode($in['url'],ENT_QUOTES)?>" /></td>
187 </tr>
188 <tr>
189  <th colspan="2" align="left">Long Description</th>
190 </tr>
191 <tr>
192  <td colspan="2"><textarea name="in[ldesc]" cols="60" rows="10" wrap="virtual"><?php echo html_entity_decode($in['ldesc'],ENT_QUOTES);?></textarea></td>
193 </tr>
194 <tr>
195  <td align="center" colspan="2">
196    <input type="submit" value="Submit" />
197  </td>
198 </tr>
199</table>
200</form>
201<table class="useredit">
202<tr>
203 <form method="get" action="<?php echo PHP_SELF;?>">
204  <input type="hidden" name="action" value="reject" />
205  <input type="hidden" name="id" value="<?php echo $id?>" />
206<?php if ($in['approved']) {?>
207  <td><input type="submit" value="Delete" />
208<?php } else {?>
209  <td><input type="submit" value="Reject" />
210<?php }?>
211 </form>
212<?php if (!$in['approved']) {?>
213 <form method="get" action="<?php echo PHP_SELF;?>">
214  <input type="hidden" name="action" value="approve" />
215  <input type="hidden" name="id" value="<?php echo $id?>" />
216  <td><input type="submit" value="Approve" />
217 </form>
218<?php }?>
219</tr>
220</table>
221<?php
222  foot();
223  exit;
224}
225?>
226<table class="useredit">
227 <tr>
228  <td>
229   <a href="<?php echo PHP_SELF?>">see upcoming events</a>
230   | <a href="<?php echo PHP_SELF . "?unapproved=1"?>">see unapproved events</a>
231  </td>
232 </tr>
233</table>
234<?php
235
236$begin = $begin ? (int)$begin : 0;
237$full = $full ? 1 : (!$full && ($search || $unapproved) ? 1 : 0);
238$max = $max ? (int)$max : 20;
239$forward = filter_input(INPUT_GET, "forward", FILTER_VALIDATE_INT) ?: 0;
240
241$searchby = new Query();
242if ($search) {
243  $searchby->add(' WHERE MATCH(sdesc,ldesc,email) AGAINST (?)', [$search]);
244} elseif ($unapproved) {
245  $searchby->add(' WHERE NOT approved');
246} else {
247  $searchby->add(' WHERE NOT (tipo = 1 AND sdato < NOW()) AND NOT (tipo = 2 AND edato < NOW())');
248}
249
250$query = new Query("SELECT COUNT(id) FROM phpcal");
251$query->addQuery($searchby);
252$res = db_query($query);
253$total = (int)mysql_result($res,0);
254
255$query = new Query("SELECT phpcal.*,country.name AS cname FROM phpcal LEFT JOIN country ON phpcal.country = country.id");
256$query->addQuery($searchby);
257if ($order) {
258  if (!in_array($order, ['sdato', 'sdesc', 'email', 'country', 'category'], true)) {
259    $order = 'sdato';
260  }
261  if ($forward) {
262    $ext = "ASC";
263  } else {
264    $ext = "DESC";
265  }
266  // Safe because we checked that $order is part of a fixed set.
267  $query->add(" ORDER BY $order $ext");
268}
269$query->add(' LIMIT ?int, ?int', [$begin, $max]);
270$res = db_query($query);
271
272$extra = [
273  "search" => $search,
274  "order" => $order,
275  "begin" => $begin,
276  "max" => $max,
277  "full" => $full,
278  "unapproved" => $unapproved,
279  "forward"    => $forward,
280];
281
282show_prev_next($begin,mysql_num_rows($res),$max,$total,$extra);
283?>
284<table class="useredit">
285<tr>
286 <th><a href="<?php echo PHP_SELF,'?',array_to_url($extra,["full" => $full ? 0 : 1]);?>"><?php echo $full ? "&otimes;" : "&oplus;";?></a></th>
287 <th><a href="<?php echo PHP_SELF,'?',array_to_url($extra,["order"=>"sdato"]);?>">date</a></th>
288 <th><a href="<?php echo PHP_SELF,'?',array_to_url($extra,["order"=>"sdesc"]);?>">summary</a></th>
289 <th><a href="<?php echo PHP_SELF,'?',array_to_url($extra,["order"=>"email"]);?>">email</a></th>
290 <th><a href="<?php echo PHP_SELF,'?',array_to_url($extra,["order"=>"country"]);?>">country</a></th>
291 <th><a href="<?php echo PHP_SELF,'?',array_to_url($extra,["order"=>"category"]);?>">category</a></th>
292</tr>
293<?php
294while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
295?>
296<tr>
297 <td align="center"><a href="<?php echo PHP_SELF . "?id=$row[id]";?>">edit</a></td>
298 <td><?php echo html_entity_decode($row['sdato'],ENT_QUOTES);?></td>
299 <td><?php echo html_entity_decode($row['sdesc'],ENT_QUOTES);?></td>
300 <td><?php echo html_entity_decode($row['email'],ENT_QUOTES);?></td>
301 <td><?php echo html_entity_decode($row['cname'],ENT_QUOTES);?></td>
302 <td><?php echo html_entity_decode($cat[$row['category']],ENT_QUOTES);?></td>
303</tr>
304<?php
305  if ($full && $row['ldesc']) {?>
306<tr>
307 <td></td><td colspan="5"><?php echo html_entity_decode($row['ldesc'],ENT_QUOTES);?></td>
308</tr>
309<?php
310  }
311}
312?>
313</table>
314<?php
315show_prev_next($begin,mysql_num_rows($res),$max,$total,$extra);
316foot();
317
318