cvs: phpweb / submit-event.php
| From: | Gabor Hojtsy | Date: | Sat, 09 Aug 2003 13:30:49 +0000 |
| Subject: | cvs: phpweb / submit-event.php | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-20067@lists.php.net to get a copy of this message | ||
goba Sat Aug 9 09:30:49 2003 EDT
Modified files:
/phpweb submit-event.php
Log:
Submit event page remake
- use new base page and include methods
- use $_POST instead of $in for incoming vars,
thus dropping the need of register_globals
- reuse already written code ($MQ)
Index: phpweb/submit-event.php diff -u phpweb/submit-event.php:1.21 phpweb/submit-event.php:1.22 --- phpweb/submit-event.php:1.21 Sat Jun 14 15:00:59 2003 +++ phpweb/submit-event.php Sat Aug 9 09:30:49 2003 @@ -1,221 +1,225 @@ <?php -/* $Id: submit-event.php,v 1.21 2003/06/14 19:00:59 goba Exp $ */ - -require_once './include/prepend.inc'; -require_once './include/posttohost.inc'; -require_once './include/email-validation.inc'; - +// $Id: submit-event.php,v 1.22 2003/08/09 13:30:49 goba Exp $ +$_SERVER['BASE_PAGE'] = 'anoncvs.php'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/include/posttohost.inc'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/include/email-validation.inc'; commonHeader("Submit an Event"); +// No errors, processing depends on POST data $errors = array(); -$process = FALSE; +$process = (boolean) count($_POST); + +// Avoid E_NOTICE errors on incoming vars if not set +$vars = array( + 'type', 'sday', 'smonth', 'syear', 'eday', + 'emonth', 'eyear', 'recur', 'recur_day', 'country', + 'category', 'email', 'url', 'ldesc', 'sdesc' +); +foreach ($vars as $varname) { + if (!isset($_POST[$varname])) { + $_POST[$varname] = ''; + } +} -if (isset($in)) { $process = TRUE; } +// We need to process some form data +if ($process) { -if (!isset($in['type'])) { $in['type'] = ""; } -if (!isset($in['sday'])) { $in['sday'] = ""; } -if (!isset($in['smonth'])) { $in['smonth'] = ""; } -if (!isset($in['syear'])) { $in['syear'] = ""; } -if (!isset($in['eday'])) { $in['eday'] = ""; } -if (!isset($in['emonth'])) { $in['emonth'] = ""; } -if (!isset($in['eyear'])) { $in['eyear'] = ""; } -if (!isset($in['recur'])) { $in['recur'] = ""; } -if (!isset($in['recur_day'])) { $in['recur_day'] = ""; } -if (!isset($in['country'])) { $in['country'] = ""; } -if (!isset($in['category'])) { $in['category'] = ""; } -if (!isset($in['email'])) { $in['email'] = ""; } -if (!isset($in['url'])) { $in['url'] = ""; } -if (!isset($in['ldesc'])) { $in['ldesc'] = ""; } -if (!isset($in['sdesc'])) { $in['sdesc'] = ""; } - -if (isset($in) && $process) { - # clean up magic quotes, if they were inserted - if (get_magic_quotes_gpc()) { - foreach ($in as $k => $v) { - $in[$k] = stripslashes($v); + // Clean up magic quotes, if they were inserted + if ($MQ) { + foreach ($_POST as $k => $v) { + $_POST[$k] = stripslashes($v); + } } - } - # clean and validate data - - if(preg_match("/\btest\b/i", $in['sdesc'])) { - $errors[] = 'We know this works. Please do not test the system.'; - } - - if(preg_match("/\btest\b/i", $in['ldesc'])) { - $errors[] = 'We know this works. Please do not test the system.'; - } - - if (!is_emailable_address($in['email'])) { - $errors[] = 'You must supply a valid email address.'; - } + // Clean and validate data + if (preg_match("/\btest\b/i", $_POST['sdesc'])) { + $errors[] = 'We know this works. Please do not test the system.'; + } + + if (preg_match("/\btest\b/i", $_POST['ldesc'])) { + $errors[] = 'We know this works. Please do not test the system.'; + } + + if (!is_emailable_address($_POST['email'])) { + $errors[] = 'You must supply a valid email address.'; + } - $in['sdesc'] = trim($in['sdesc']); - if (!$in['sdesc']) { - $errors[] = "You must supply a short description of the event."; - } - - $in['ldesc'] = trim(strip_tags($in['ldesc'],'<a><i><b><br /><p>')); - $in['ldesc'] = preg_replace("/(style|on\\w+?)\s*=\s*(\"|').+?\\2/i","",$in['ldesc']); - if (!$in['ldesc']) { - $errors[] = "You must supply a long description of the event."; - } - - $in['url'] = trim($in['url']); - if (!$in['url']) { - $errors[] = "You must supply a URL with more information about the event."; - } - elseif (!preg_match('/^\w+:/',$in['url'])) { - $errors[] = "The URL you supplied was incomplete."; - } - - if (!$in['country']) { - $errors[] = 'You must specify a country for the event.'; - } - - if (!$in['category']) { - $errors[] = 'You must specify a category for the event.'; - } - - if (!checkdate($in['smonth'], $in['sday'], $in['syear'])) { - $errors[] = "You must specify a valid start date."; - } - else { - $sdate = mktime(0,0,1,$in['smonth'], $in['sday'], $in['syear']); - if ($sdate < time()) { - $errors[] = "You must specify a start date that is in the future."; - } - } - - if ($in['type'] == 'multi' && !checkdate($in['emonth'], $in['eday'], $in['eyear'])) { - $errors[] = "You must specify a valid end date for a multi-day event."; - } - elseif ($in['type'] == 'multi' && checkdate($in['smonth'], $in['sday'], $in['syear'])) { - $sdate = mktime(0,0,1,$in['smonth'], $in['sday'], $in['syear']); - $edate = mktime(0,0,1,$in['emonth'], $in['eday'], $in['eyear']); - if ($edate < time()) { - $errors[] = "You must specify an end date that is in the future."; - } - elseif ($edate < $sdate) { - $errors[] = "You must specify an end date that is after the start date."; - } - } - - if ($in['type'] == 'recur' && !($in['recur'] && $in['recur_day'])) { - $errors[] = "You must specify a valid day of the month for a recurring event."; - } - - if (preg_match("/submit/i", $action)) { - # submit to master.php.net - $result = posttohost("http://master.php.net/entry/event.php", $in); - if ($result) { - $errors[] = "There was an error processing your submission: $result"; - } - if (!$errors) {?> -<p>Thank you for your submission! You should hear back soon as to whether your -event has been accepted for inclusion in our calendar.</p> -<?php - commonFooter(); - exit; + $_POST['sdesc'] = trim($_POST['sdesc']); + if (!$_POST['sdesc']) { + $errors[] = "You must supply a short description of the event."; } - } - if (!$errors) {?> -<p>The following is a preview of your event submission. Please double-check it -to make sure all of the information is correct.</p> -<?php - } + $_POST['ldesc'] = trim(strip_tags($_POST['ldesc'], '<a><i><b><br /><p>')); + $_POST['ldesc'] = preg_replace("/(style|on\\w+?)\s*=\s*(\"|').+?\\2/i", "", $_POST['ldesc']); + if (!$_POST['ldesc']) { + $errors[] = "You must supply a long description of the event."; + } + + $_POST['url'] = trim($_POST['url']); + if (!$_POST['url']) { + $errors[] = "You must supply a URL with more information about the event."; + } + elseif (!preg_match('/^\w+:/', $_POST['url'])) { + $errors[] = "The URL you supplied was incomplete."; + } + + if (!$_POST['country']) { + $errors[] = 'You must specify a country for the event.'; + } + + if (!$_POST['category']) { + $errors[] = 'You must specify a category for the event.'; + } + + if (!checkdate($_POST['smonth'], $_POST['sday'], $_POST['syear'])) { + $errors[] = "You must specify a valid start date."; + } + else { + $sdate = mktime(0, 0, 1, $_POST['smonth'], $_POST['sday'], $_POST['syear']); + if ($sdate < time()) { + $errors[] = "You must specify a start date that is in the future."; + } + } + + if ($_POST['type'] == 'multi' && !checkdate($_POST['emonth'], $_POST['eday'], $_POST['eyear'])) { + $errors[] = "You must specify a valid end date for a multi-day event."; + } + elseif ($_POST['type'] == 'multi' && checkdate($_POST['smonth'], $_POST['sday'], $_POST['syear'])) { + $sdate = mktime(0, 0, 1, $_POST['smonth'], $_POST['sday'], $_POST['syear']); + $edate = mktime(0, 0, 1, $_POST['emonth'], $_POST['eday'], $_POST['eyear']); + if ($edate < time()) { + $errors[] = "You must specify an end date that is in the future."; + } + elseif ($edate < $sdate) { + $errors[] = "You must specify an end date that is after the start date."; + } + } + + if ($_POST['type'] == 'recur' && !($_POST['recur'] && $_POST['recur_day'])) { + $errors[] = "You must specify a valid day of the month for a recurring event."; + } + + if (preg_match("/submit/i", $action)) { + // Submit to master.php.net + $result = posttohost("http://master.php.net/entry/event.php", $_POST); + if ($result) { + $errors[] = "There was an error processing your submission: $result"; + } + if (!$errors) { + echo "<p>\n Thank you for your submission! You should hear back soon\n" . + " as to whether your event has been accepted for inclusion in\n" . + " our calendar.\n</p>"; + commonFooter(); + exit; + } + } + + if (!$errors) { + echo "<p>\n The following is a preview of your event submission.\n" . + " Please double-check it to make sure all of the information is correct.\n</p>"; + } } -else {?> -<p>Have an upcoming PHP user group meeting? Holding a PHP training session? -Submit your event here, and after it has been approved, it will be listed on -the PHP.net homepage and appear in our full event listings.</p> -<?php + +// No form data to process +else { + echo "<p>\n Have an upcoming PHP user group meeting? Holding a PHP training session?\n" . + " Submit your event here, and after it has been approved, it will be listed on\n" . + " the PHP.net homepage and appear in our full event listings.\n</p>"; } -if ($errors) display_errors($errors); +// Display errors if found +if ($errors) { display_errors($errors); } +// Generate days and months arrays for form for ($i = 1; $i <= 7; $i++) { - $days[$i] = strftime('%A',mktime(12,0,0,4,$i,2001)); + $days[$i] = strftime('%A', mktime(12, 0, 0, 4, $i, 2001)); } - for ($i = 1; $i <= 12; $i++) { - $months[$i] = strftime('%B',mktime(12,0,0,$i,1,2001)); + $months[$i] = strftime('%B', mktime(12, 0, 0, $i, 1, 2001)); } -$re = array(1=>'First',2=>'Second',3=>'Third',4=>'Fourth',-1=>'Last',-2=>'2nd Last',-3=>'3rd Last'); - -if (isset($in) && $process) { - echo "<p><b>Preview:</b></p>\n"; - - display_event($in); -?> -<p><b>Change:</b></p> -<?php +// Possibilities to recur +$re = array( + 1 => 'First', + 2 => 'Second', + 3 => 'Third', + 4 => 'Fourth', + -1 => 'Last', + -2 => '2nd Last', + -3 => '3rd Last' +); + +// If we have data, display preview +if ($process) { + echo "<p><strong>Preview:</strong></p>\n"; + display_event($_POST); + echo "<p><strong>Change:</strong></p>\n"; } + ?> -<form action="<?php echo $PHP_SELF?>" method="post"> +<form action="/submit_event.php" method="post"> <table bgcolor="#eeeeee" border="0" cellspacing="0" cellpadding="3" width="100%"> <tr> <th>Start Date</th> <td> - <select name="in[smonth]"><option></option><?php display_options($months,$in['smonth'])?></select> - <input type="text" name="in[sday]" size="2" maxlength="2" value="<?php echo htmlentities($in['sday'])?>" /> - <input type="text" name="in[syear]" size="4" maxlength="4" value="<?php echo $in['syear'] ? htmlentities($in['syear']) : date("Y")?>" /> - <input type="radio" id="single" name="in[type]" value="single"<?php if ($in['type'] == 'single' || !$in['type']) echo ' checked="checked"';?> /> + <select name="smonth"><option></option><?php display_options($months, $_POST['smonth'])?></select> + <input type="text" name="sday" size="2" maxlength="2" value="<?php echo htmlentities($_POST['sday'])?>" /> + <input type="text" name="syear" size="4" maxlength="4" value="<?php echo $_POST['syear'] ? htmlentities($_POST['syear']) : date("Y")?>" /> + <input type="radio" id="single" name="type" value="single"<?php if ($_POST['type'] == 'single' || !$_POST['type']) echo ' checked="checked"';?> /> <label for="single">One day (no end-date required)</label> </td> </tr> <tr> <th>End Date</th> <td> - <select name="in[emonth]"><option></option><?php display_options($months,$in['emonth'])?></select> - <input type="text" name="in[eday]" size="2" maxlength="2" value="<?php echo htmlentities($in['eday'])?>" /> - <input type="text" name="in[eyear]" size="4" maxlength="4" value="<?php echo $in['eyear'] ? htmlentities($in['eyear']) : date("Y")?>" /> - <input type="radio" id="multi" name="in[type]" value="multi"<?php if ($in['type'] == 'multi') echo ' checked="checked"';?> /> + <select name="emonth"><option></option><?php display_options($months, $_POST['emonth'])?></select> + <input type="text" name="eday" size="2" maxlength="2" value="<?php echo htmlentities($_POST['eday'])?>" /> + <input type="text" name="eyear" size="4" maxlength="4" value="<?php echo $_POST['eyear'] ? htmlentities($_POST['eyear']) : date("Y")?>" /> + <input type="radio" id="multi" name="type" value="multi"<?php if ($_POST['type'] == 'multi') echo ' checked="checked"';?> /> <label for="multi">Multi-day event</label> </td> </tr> <tr> <th>OR<br />Recurring</th> <td> - <select name="in[recur]"><option></option><?php display_options($re,$in['recur'])?></select> - <select name="in[recur_day]"><option></option><?php display_options($days,$in['recur_day'])?></select> - <input type="radio" id="recur" name="in[type]" value="recur"<?php if ($in['type'] == 'recur') echo ' checked="checked"';?> /> + <select name="recur"><option></option><?php display_options($re, $_POST['recur'])?></select> + <select name="recur_day"><option></option><?php display_options($days, $_POST['recur_day'])?></select> + <input type="radio" id="recur" name="type" value="recur"<?php if ($_POST['type'] == 'recur') echo ' checked="checked"';?> /> <label for="recur">Recurring (every month)</label> </td> </tr> <tr> <th>Short<br />Description</th> - <td><input type="text" name="in[sdesc]" value="<?php echo htmlentities($in['sdesc'])?>" size="32" maxlength="32" /></td> + <td><input type="text" name="sdesc" value="<?php echo htmlentities($_POST['sdesc'])?>" size="32" maxlength="32" /></td> </tr> <tr> <th>URL</th> - <td><input type="text" name="in[url]" size="40" maxlength="128" value="<?php echo htmlentities($in['url'])?>" /></td> + <td><input type="text" name="url" size="40" maxlength="128" value="<?php echo htmlentities($_POST['url'])?>" /></td> </tr> <tr> <th>Country</th> <td> - <select name="in[country]"> + <select name="country"> <option value="">- Select a country -</option> - <?php display_options($COUNTRIES,$in['country']);?> + <?php display_options($COUNTRIES, $_POST['country']);?> </select> </td> </tr> <tr> <th>Event Category</th> <td> - <select name="in[category]"> + <select name="category"> <?php $cat = array("- Select a category -", "User Group Event", "Conference", "Training"); - display_options($cat,$in['category']); + display_options($cat, $_POST['category']); ?> </select> </td> </tr> <tr> <th>Email</th> - <td><input type="text" name="in[email]" size="40" maxlength="128" value="<?php echo htmlentities($in['email'])?>" /></td> + <td><input type="text" name="email" size="40" maxlength="128" value="<?php echo htmlentities($_POST['email'])?>" /></td> </tr> <tr> <th> </th> @@ -225,12 +229,12 @@ <th colspan="2" align="left">Long Description</th> </tr> <tr> - <td colspan="2"><textarea name="in[ldesc]" cols="60" rows="10" wrap="virtual"><?php echo htmlentities($in['ldesc']);?></textarea></td> + <td colspan="2"><textarea name="ldesc" cols="60" rows="10" wrap="virtual"><?php echo htmlentities($_POST['ldesc']);?></textarea></td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" name="action" value="Preview" /> -<?php if (isset($in) && $process && !$errors) {?> +<?php if ($process && count($errors) == 0) {?> <input type="submit" name="action" value="Submit" /> <?php }?> </td> @@ -240,12 +244,15 @@ <?php commonFooter(); -function display_options($options,$current) { - foreach ($options as $k => $v) { - echo '<option value="', $k, '"', - ($k == $current ? ' selected="selected"' : ''), - '>', htmlentities($v), "</option>\n"; - } +// Display an option list with one selected +function display_options($options, $current) +{ + foreach ($options as $k => $v) { + echo '<option value="', $k, '"', + ($k == $current ? ' selected="selected"' : ''), + '>', htmlentities($v), "</option>\n"; + } } /* vim: set noet ts=4 sw=4 ft=php: : */ +?> \ No newline at end of file
Index: phpweb/submit-event.php diff -u phpweb/submit-event.php:1.21 phpweb/submit-event.php:1.22 --- phpweb/submit-event.php:1.21 Sat Jun 14 15:00:59 2003 +++ phpweb/submit-event.php Sat Aug 9 09:30:49 2003 @@ -1,221 +1,225 @@ <?php -/* $Id: submit-event.php,v 1.21 2003/06/14 19:00:59 goba Exp $ */ - -require_once './include/prepend.inc'; -require_once './include/posttohost.inc'; -require_once './include/email-validation.inc'; - +// $Id: submit-event.php,v 1.22 2003/08/09 13:30:49 goba Exp $ +$_SERVER['BASE_PAGE'] = 'anoncvs.php'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/include/posttohost.inc'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/include/email-validation.inc'; commonHeader("Submit an Event"); +// No errors, processing depends on POST data $errors = array(); -$process = FALSE; +$process = (boolean) count($_POST); + +// Avoid E_NOTICE errors on incoming vars if not set +$vars = array( + 'type', 'sday', 'smonth', 'syear', 'eday', + 'emonth', 'eyear', 'recur', 'recur_day', 'country', + 'category', 'email', 'url', 'ldesc', 'sdesc' +); +foreach ($vars as $varname) { + if (!isset($_POST[$varname])) { + $_POST[$varname] = ''; + } +} -if (isset($in)) { $process = TRUE; } +// We need to process some form data +if ($process) { -if (!isset($in['type'])) { $in['type'] = ""; } -if (!isset($in['sday'])) { $in['sday'] = ""; } -if (!isset($in['smonth'])) { $in['smonth'] = ""; } -if (!isset($in['syear'])) { $in['syear'] = ""; } -if (!isset($in['eday'])) { $in['eday'] = ""; } -if (!isset($in['emonth'])) { $in['emonth'] = ""; } -if (!isset($in['eyear'])) { $in['eyear'] = ""; } -if (!isset($in['recur'])) { $in['recur'] = ""; } -if (!isset($in['recur_day'])) { $in['recur_day'] = ""; } -if (!isset($in['country'])) { $in['country'] = ""; } -if (!isset($in['category'])) { $in['category'] = ""; } -if (!isset($in['email'])) { $in['email'] = ""; } -if (!isset($in['url'])) { $in['url'] = ""; } -if (!isset($in['ldesc'])) { $in['ldesc'] = ""; } -if (!isset($in['sdesc'])) { $in['sdesc'] = ""; } - -if (isset($in) && $process) { - # clean up magic quotes, if they were inserted - if (get_magic_quotes_gpc()) { - foreach ($in as $k => $v) { - $in[$k] = stripslashes($v); + // Clean up magic quotes, if they were inserted + if ($MQ) { + foreach ($_POST as $k => $v) { + $_POST[$k] = stripslashes($v); + } } - } - # clean and validate data - - if(preg_match("/\btest\b/i", $in['sdesc'])) { - $errors[] = 'We know this works. Please do not test the system.'; - } - - if(preg_match("/\btest\b/i", $in['ldesc'])) { - $errors[] = 'We know this works. Please do not test the system.'; - } - - if (!is_emailable_address($in['email'])) { - $errors[] = 'You must supply a valid email address.'; - } + // Clean and validate data + if (preg_match("/\btest\b/i", $_POST['sdesc'])) { + $errors[] = 'We know this works. Please do not test the system.'; + } + + if (preg_match("/\btest\b/i", $_POST['ldesc'])) { + $errors[] = 'We know this works. Please do not test the system.'; + } + + if (!is_emailable_address($_POST['email'])) { + $errors[] = 'You must supply a valid email address.'; + } - $in['sdesc'] = trim($in['sdesc']); - if (!$in['sdesc']) { - $errors[] = "You must supply a short description of the event."; - } - - $in['ldesc'] = trim(strip_tags($in['ldesc'],'<a><i><b><br /><p>')); - $in['ldesc'] = preg_replace("/(style|on\\w+?)\s*=\s*(\"|').+?\\2/i","",$in['ldesc']); - if (!$in['ldesc']) { - $errors[] = "You must supply a long description of the event."; - } - - $in['url'] = trim($in['url']); - if (!$in['url']) { - $errors[] = "You must supply a URL with more information about the event."; - } - elseif (!preg_match('/^\w+:/',$in['url'])) { - $errors[] = "The URL you supplied was incomplete."; - } - - if (!$in['country']) { - $errors[] = 'You must specify a country for the event.'; - } - - if (!$in['category']) { - $errors[] = 'You must specify a category for the event.'; - } - - if (!checkdate($in['smonth'], $in['sday'], $in['syear'])) { - $errors[] = "You must specify a valid start date."; - } - else { - $sdate = mktime(0,0,1,$in['smonth'], $in['sday'], $in['syear']); - if ($sdate < time()) { - $errors[] = "You must specify a start date that is in the future."; - } - } - - if ($in['type'] == 'multi' && !checkdate($in['emonth'], $in['eday'], $in['eyear'])) { - $errors[] = "You must specify a valid end date for a multi-day event."; - } - elseif ($in['type'] == 'multi' && checkdate($in['smonth'], $in['sday'], $in['syear'])) { - $sdate = mktime(0,0,1,$in['smonth'], $in['sday'], $in['syear']); - $edate = mktime(0,0,1,$in['emonth'], $in['eday'], $in['eyear']); - if ($edate < time()) { - $errors[] = "You must specify an end date that is in the future."; - } - elseif ($edate < $sdate) { - $errors[] = "You must specify an end date that is after the start date."; - } - } - - if ($in['type'] == 'recur' && !($in['recur'] && $in['recur_day'])) { - $errors[] = "You must specify a valid day of the month for a recurring event."; - } - - if (preg_match("/submit/i", $action)) { - # submit to master.php.net - $result = posttohost("http://master.php.net/entry/event.php", $in); - if ($result) { - $errors[] = "There was an error processing your submission: $result"; - } - if (!$errors) {?> -<p>Thank you for your submission! You should hear back soon as to whether your -event has been accepted for inclusion in our calendar.</p> -<?php - commonFooter(); - exit; + $_POST['sdesc'] = trim($_POST['sdesc']); + if (!$_POST['sdesc']) { + $errors[] = "You must supply a short description of the event."; } - } - if (!$errors) {?> -<p>The following is a preview of your event submission. Please double-check it -to make sure all of the information is correct.</p> -<?php - } + $_POST['ldesc'] = trim(strip_tags($_POST['ldesc'], '<a><i><b><br /><p>')); + $_POST['ldesc'] = preg_replace("/(style|on\\w+?)\s*=\s*(\"|').+?\\2/i", "", $_POST['ldesc']); + if (!$_POST['ldesc']) { + $errors[] = "You must supply a long description of the event."; + } + + $_POST['url'] = trim($_POST['url']); + if (!$_POST['url']) { + $errors[] = "You must supply a URL with more information about the event."; + } + elseif (!preg_match('/^\w+:/', $_POST['url'])) { + $errors[] = "The URL you supplied was incomplete."; + } + + if (!$_POST['country']) { + $errors[] = 'You must specify a country for the event.'; + } + + if (!$_POST['category']) { + $errors[] = 'You must specify a category for the event.'; + } + + if (!checkdate($_POST['smonth'], $_POST['sday'], $_POST['syear'])) { + $errors[] = "You must specify a valid start date."; + } + else { + $sdate = mktime(0, 0, 1, $_POST['smonth'], $_POST['sday'], $_POST['syear']); + if ($sdate < time()) { + $errors[] = "You must specify a start date that is in the future."; + } + } + + if ($_POST['type'] == 'multi' && !checkdate($_POST['emonth'], $_POST['eday'], $_POST['eyear'])) { + $errors[] = "You must specify a valid end date for a multi-day event."; + } + elseif ($_POST['type'] == 'multi' && checkdate($_POST['smonth'], $_POST['sday'], $_POST['syear'])) { + $sdate = mktime(0, 0, 1, $_POST['smonth'], $_POST['sday'], $_POST['syear']); + $edate = mktime(0, 0, 1, $_POST['emonth'], $_POST['eday'], $_POST['eyear']); + if ($edate < time()) { + $errors[] = "You must specify an end date that is in the future."; + } + elseif ($edate < $sdate) { + $errors[] = "You must specify an end date that is after the start date."; + } + } + + if ($_POST['type'] == 'recur' && !($_POST['recur'] && $_POST['recur_day'])) { + $errors[] = "You must specify a valid day of the month for a recurring event."; + } + + if (preg_match("/submit/i", $action)) { + // Submit to master.php.net + $result = posttohost("http://master.php.net/entry/event.php", $_POST); + if ($result) { + $errors[] = "There was an error processing your submission: $result"; + } + if (!$errors) { + echo "<p>\n Thank you for your submission! You should hear back soon\n" . + " as to whether your event has been accepted for inclusion in\n" . + " our calendar.\n</p>"; + commonFooter(); + exit; + } + } + + if (!$errors) { + echo "<p>\n The following is a preview of your event submission.\n" . + " Please double-check it to make sure all of the information is correct.\n</p>"; + } } -else {?> -<p>Have an upcoming PHP user group meeting? Holding a PHP training session? -Submit your event here, and after it has been approved, it will be listed on -the PHP.net homepage and appear in our full event listings.</p> -<?php + +// No form data to process +else { + echo "<p>\n Have an upcoming PHP user group meeting? Holding a PHP training session?\n" . + " Submit your event here, and after it has been approved, it will be listed on\n" . + " the PHP.net homepage and appear in our full event listings.\n</p>"; } -if ($errors) display_errors($errors); +// Display errors if found +if ($errors) { display_errors($errors); } +// Generate days and months arrays for form for ($i = 1; $i <= 7; $i++) { - $days[$i] = strftime('%A',mktime(12,0,0,4,$i,2001)); + $days[$i] = strftime('%A', mktime(12, 0, 0, 4, $i, 2001)); } - for ($i = 1; $i <= 12; $i++) { - $months[$i] = strftime('%B',mktime(12,0,0,$i,1,2001)); + $months[$i] = strftime('%B', mktime(12, 0, 0, $i, 1, 2001)); } -$re = array(1=>'First',2=>'Second',3=>'Third',4=>'Fourth',-1=>'Last',-2=>'2nd Last',-3=>'3rd Last'); - -if (isset($in) && $process) { - echo "<p><b>Preview:</b></p>\n"; - - display_event($in); -?> -<p><b>Change:</b></p> -<?php +// Possibilities to recur +$re = array( + 1 => 'First', + 2 => 'Second', + 3 => 'Third', + 4 => 'Fourth', + -1 => 'Last', + -2 => '2nd Last', + -3 => '3rd Last' +); + +// If we have data, display preview +if ($process) { + echo "<p><strong>Preview:</strong></p>\n"; + display_event($_POST); + echo "<p><strong>Change:</strong></p>\n"; } + ?> -<form action="<?php echo $PHP_SELF?>" method="post"> +<form action="/submit_event.php" method="post"> <table bgcolor="#eeeeee" border="0" cellspacing="0" cellpadding="3" width="100%"> <tr> <th>Start Date</th> <td> - <select name="in[smonth]"><option></option><?php display_options($months,$in['smonth'])?></select> - <input type="text" name="in[sday]" size="2" maxlength="2" value="<?php echo htmlentities($in['sday'])?>" /> - <input type="text" name="in[syear]" size="4" maxlength="4" value="<?php echo $in['syear'] ? htmlentities($in['syear']) : date("Y")?>" /> - <input type="radio" id="single" name="in[type]" value="single"<?php if ($in['type'] == 'single' || !$in['type']) echo ' checked="checked"';?> /> + <select name="smonth"><option></option><?php display_options($months, $_POST['smonth'])?></select> + <input type="text" name="sday" size="2" maxlength="2" value="<?php echo htmlentities($_POST['sday'])?>" /> + <input type="text" name="syear" size="4" maxlength="4" value="<?php echo $_POST['syear'] ? htmlentities($_POST['syear']) : date("Y")?>" /> + <input type="radio" id="single" name="type" value="single"<?php if ($_POST['type'] == 'single' || !$_POST['type']) echo ' checked="checked"';?> /> <label for="single">One day (no end-date required)</label> </td> </tr> <tr> <th>End Date</th> <td> - <select name="in[emonth]"><option></option><?php display_options($months,$in['emonth'])?></select> - <input type="text" name="in[eday]" size="2" maxlength="2" value="<?php echo htmlentities($in['eday'])?>" /> - <input type="text" name="in[eyear]" size="4" maxlength="4" value="<?php echo $in['eyear'] ? htmlentities($in['eyear']) : date("Y")?>" /> - <input type="radio" id="multi" name="in[type]" value="multi"<?php if ($in['type'] == 'multi') echo ' checked="checked"';?> /> + <select name="emonth"><option></option><?php display_options($months, $_POST['emonth'])?></select> + <input type="text" name="eday" size="2" maxlength="2" value="<?php echo htmlentities($_POST['eday'])?>" /> + <input type="text" name="eyear" size="4" maxlength="4" value="<?php echo $_POST['eyear'] ? htmlentities($_POST['eyear']) : date("Y")?>" /> + <input type="radio" id="multi" name="type" value="multi"<?php if ($_POST['type'] == 'multi') echo ' checked="checked"';?> /> <label for="multi">Multi-day event</label> </td> </tr> <tr> <th>OR<br />Recurring</th> <td> - <select name="in[recur]"><option></option><?php display_options($re,$in['recur'])?></select> - <select name="in[recur_day]"><option></option><?php display_options($days,$in['recur_day'])?></select> - <input type="radio" id="recur" name="in[type]" value="recur"<?php if ($in['type'] == 'recur') echo ' checked="checked"';?> /> + <select name="recur"><option></option><?php display_options($re, $_POST['recur'])?></select> + <select name="recur_day"><option></option><?php display_options($days, $_POST['recur_day'])?></select> + <input type="radio" id="recur" name="type" value="recur"<?php if ($_POST['type'] == 'recur') echo ' checked="checked"';?> /> <label for="recur">Recurring (every month)</label> </td> </tr> <tr> <th>Short<br />Description</th> - <td><input type="text" name="in[sdesc]" value="<?php echo htmlentities($in['sdesc'])?>" size="32" maxlength="32" /></td> + <td><input type="text" name="sdesc" value="<?php echo htmlentities($_POST['sdesc'])?>" size="32" maxlength="32" /></td> </tr> <tr> <th>URL</th> - <td><input type="text" name="in[url]" size="40" maxlength="128" value="<?php echo htmlentities($in['url'])?>" /></td> + <td><input type="text" name="url" size="40" maxlength="128" value="<?php echo htmlentities($_POST['url'])?>" /></td> </tr> <tr> <th>Country</th> <td> - <select name="in[country]"> + <select name="country"> <option value="">- Select a country -</option> - <?php display_options($COUNTRIES,$in['country']);?> + <?php display_options($COUNTRIES, $_POST['country']);?> </select> </td> </tr> <tr> <th>Event Category</th> <td> - <select name="in[category]"> + <select name="category"> <?php $cat = array("- Select a category -", "User Group Event", "Conference", "Training"); - display_options($cat,$in['category']); + display_options($cat, $_POST['category']); ?> </select> </td> </tr> <tr> <th>Email</th> - <td><input type="text" name="in[email]" size="40" maxlength="128" value="<?php echo htmlentities($in['email'])?>" /></td> + <td><input type="text" name="email" size="40" maxlength="128" value="<?php echo htmlentities($_POST['email'])?>" /></td> </tr> <tr> <th> </th> @@ -225,12 +229,12 @@ <th colspan="2" align="left">Long Description</th> </tr> <tr> - <td colspan="2"><textarea name="in[ldesc]" cols="60" rows="10" wrap="virtual"><?php echo htmlentities($in['ldesc']);?></textarea></td> + <td colspan="2"><textarea name="ldesc" cols="60" rows="10" wrap="virtual"><?php echo htmlentities($_POST['ldesc']);?></textarea></td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" name="action" value="Preview" /> -<?php if (isset($in) && $process && !$errors) {?> +<?php if ($process && count($errors) == 0) {?> <input type="submit" name="action" value="Submit" /> <?php }?> </td> @@ -240,12 +244,15 @@ <?php commonFooter(); -function display_options($options,$current) { - foreach ($options as $k => $v) { - echo '<option value="', $k, '"', - ($k == $current ? ' selected="selected"' : ''), - '>', htmlentities($v), "</option>\n"; - } +// Display an option list with one selected +function display_options($options, $current) +{ + foreach ($options as $k => $v) { + echo '<option value="', $k, '"', + ($k == $current ? ' selected="selected"' : ''), + '>', htmlentities($v), "</option>\n"; + } } /* vim: set noet ts=4 sw=4 ft=php: : */ +?> \ No newline at end of file