xref: /web-master/entry/event.php (revision 3f5dc40d)
1<?php
2
3require_once __DIR__ . '/../include/functions.inc';
4
5$mailto = 'php-webmaster@lists.php.net';
6#$mailto = 'jimw@apache.org';
7
8$re = [
9        1 => 'First',
10        2 => 'Second',
11        3 => 'Third',
12        4 => 'Fourth',
13       -1 => 'Last',
14       -2 => 'Second to Last',
15       -3 => 'Third to Last'
16];
17$cat = ["unknown", "User Group Event", "Conference", "Training"];
18
19function day($in) {
20  return strftime('%A',mktime(12,0,0,4,$in,2001));
21}
22
23db_connect();
24
25$valid_vars = ['sdesc','ldesc','email','country','category','type','url','sane','smonth','sday','syear','emonth','eday','eyear','recur','recur_day'];
26foreach($valid_vars as $k) {
27  $$k = isset($_REQUEST[$k]) ? $_REQUEST[$k] : false;
28}
29
30if (empty($sdesc) || empty($email) || empty($country) || empty($category) || empty($type) || empty($url))
31  die("missing some parameters.");
32
33// The answer to the "spam question"
34if ($sane != 3) {
35	die("I feel for you");
36}
37
38// utf8 safe truncate, while php not compile with mb_string
39$l = 32; while (strlen($sdesc) > 32) { $sdesc = iconv_substr($sdesc, 0, $l--, 'UTF-8'); }
40
41switch($type) {
42  case 'single':
43    if (!checkdate($smonth, $sday, $syear))
44      die("invalid start date");
45
46    $query = "INSERT INTO phpcal SET tipo=1, sdato=?, sdesc=?, url=?, email=?, ldesc=?, country=?, category=?";
47    db_query_safe($query, ["$syear-$smonth-$sday", $sdesc, $url, $email, $ldesc, $country, $category]);
48    $msg = "Date: $syear-$smonth-$sday\n";
49    break;
50  case 'multi':
51    if (!checkdate($smonth, $sday, $syear))
52      die("invalid start date");
53    if (!checkdate($emonth, $eday, $eyear))
54      die("invalid end date");
55
56    $sd = mktime(0,0,0,$smonth,$sday,$syear);
57    $ed = mktime(0,0,59,$emonth,$eday,$eyear);
58    if ($sd > $ed)
59      die("end date is after start date");
60
61    if ($smonth == $emonth && $sday == $eday && $syear == $eyear)
62      die("start and end dates are identical");
63
64    $query = "INSERT INTO phpcal SET tipo=2,"
65           . "sdato=?, edato=?, sdesc=?, url=?, email=?, ldesc=?, country=?, category=?";
66    db_query_safe($query, [
67      "$syear-$smonth-$sday", "$eyear-$emonth-$eday", $sdesc, $url, $email, $ldesc, $country, $category
68    ]);
69
70    $msg = "Start Date: $syear-$smonth-$sday\n"
71         . "End Date: $eyear-$emonth-$eday\n";
72    break;
73  case 'recur':
74    if (!is_numeric($recur) || !is_numeric($recur_day))
75      die("recurring event sequence is invalid");
76
77    $query = "INSERT INTO phpcal SET tipo=3,"
78           . "recur=?, sdesc=?, url=?, email=?, ldesc=?, country=?, category=?";
79    db_query_safe($query, ["$recur:$recur_day", $sdesc, $url, $email, $ldesc, $country, $category]);
80
81    $msg = "Recurs Every: $re[$recur] ".day($recur_day)."\n";
82
83    break;
84  default:
85    die("invalid type");
86}
87
88$new_id = mysql_insert_id();
89
90$msg .= "Country: ".$country."\n"
91      . "Category: ".$cat[$category]."\n"
92      . ($url ? "URL: ".$url."\n" : "")
93      . "\n".wordwrap($ldesc,72);
94
95# add signature/actions
96$msg .= "\n-- \n"
97      . "https://master.php.net/manage/event.php?id=$new_id&action=approve\n"
98      . "https://master.php.net/manage/event.php?id=$new_id&action=reject\n"
99      . "https://master.php.net/manage/event.php?id=$new_id\n";
100