forked from science-ation/science-ation
Update the date editor.
- Dates are always displayed in the same order, which is somewhat logical. - It detects some errors. It's not perfect, but it'll detect when a date is invalid, and when pairs of dates are bad (eg. the reg. system closes before it opens.). All dates are still saved to the database but the user is alerted of any date errors.
This commit is contained in:
parent
372c2a55c7
commit
dc60c9f652
@ -27,13 +27,16 @@
|
|||||||
send_header("Configuration - Dates");
|
send_header("Configuration - Dates");
|
||||||
echo "<a href=\"index.php\"><< ".i18n("Back to Configuration")."</a><br />";
|
echo "<a href=\"index.php\"><< ".i18n("Back to Configuration")."</a><br />";
|
||||||
|
|
||||||
|
$error_ids = array();
|
||||||
|
|
||||||
if($_POST['action']=="save")
|
if($_POST['action']=="save")
|
||||||
{
|
{
|
||||||
if($_POST['savedates'])
|
if($_POST['savedates'])
|
||||||
{
|
{
|
||||||
foreach($_POST['savedates'] as $key=>$val)
|
foreach($_POST['savedates'] as $key=>$val)
|
||||||
{
|
{
|
||||||
mysql_query("UPDATE dates SET date='".mysql_escape_string(stripslashes($val))."' WHERE year='".$config['FAIRYEAR']."' AND id='$key'");
|
$v = mysql_escape_string(stripslashes($val));
|
||||||
|
mysql_query("UPDATE dates SET date='$v' WHERE year='".$config['FAIRYEAR']."' AND id='$key'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo happy(i18n("Dates successfully saved"));
|
echo happy(i18n("Dates successfully saved"));
|
||||||
@ -45,13 +48,70 @@
|
|||||||
echo "<table>";
|
echo "<table>";
|
||||||
echo "<tr><td colspan=\"3\"><h3>".i18n("Dates for fair year %1",array($config['FAIRYEAR']),array("fair year"))."</h3></td></tr>";
|
echo "<tr><td colspan=\"3\"><h3>".i18n("Dates for fair year %1",array($config['FAIRYEAR']),array("fair year"))."</h3></td></tr>";
|
||||||
|
|
||||||
|
/* List the dates in the order we would like them to appear */
|
||||||
|
$dates = array('fairdate' => array() ,
|
||||||
|
'regopen' => array(),
|
||||||
|
'regclose' => array(),
|
||||||
|
'postparticipants' => array(),
|
||||||
|
'postwinners' => array(),
|
||||||
|
'judgeregopen' => array(),
|
||||||
|
'judgeregclose' => array(),
|
||||||
|
'specawardregopen' => array(),
|
||||||
|
'specawardregclose' => array());
|
||||||
|
|
||||||
|
/* Now copy the SQL data into the above array */
|
||||||
$q=mysql_query("SELECT * FROM dates WHERE year='".$config['FAIRYEAR']."' ORDER BY date");
|
$q=mysql_query("SELECT * FROM dates WHERE year='".$config['FAIRYEAR']."' ORDER BY date");
|
||||||
while($r=mysql_fetch_object($q))
|
while($r=mysql_fetch_object($q))
|
||||||
{
|
{
|
||||||
echo "<tr><td>".i18n($r->description)."</td><td><input type=\"text\" name=\"savedates[$r->id]\" value=\"$r->date\" /></td></tr>";
|
$dates[$r->name]['description'] = $r->description;
|
||||||
|
$dates[$r->name]['id'] = $r->id;
|
||||||
|
$dates[$r->name]['date'] = $r->date;
|
||||||
|
|
||||||
|
$v = $r->date;
|
||||||
|
/* See if $v is something resembling a valid date */
|
||||||
|
if(!ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $v, $d)) {
|
||||||
|
$error_ids[$r->id] = "Invalid date format";
|
||||||
|
} else if($d[3]==0 || $d[2]==0 || $d[1]==0) {
|
||||||
|
$error_ids[$r->id] = "Invalid date";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function chkafter($d1, $d2)
|
||||||
|
{
|
||||||
|
global $dates;
|
||||||
|
global $error_ids;
|
||||||
|
|
||||||
|
$id2 = $dates[$d2]['id'];
|
||||||
|
|
||||||
|
/* Parse both dates 1, 2, 3, 4, 5, 6 */
|
||||||
|
ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})",$dates[$d1]['date'], $p1);
|
||||||
|
ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})",$dates[$d2]['date'], $p2);
|
||||||
|
|
||||||
|
// int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
|
||||||
|
$u1 = mktime($p1[4], $p1[5], $p1[6], $p1[2], $p1[3], $p1[1]);
|
||||||
|
$u2 = mktime($p2[4], $p2[5], $p2[6], $p2[2], $p2[3], $p2[1]);
|
||||||
|
|
||||||
|
if($u1 > $u2) {
|
||||||
|
/* Insert an error for $u2 */
|
||||||
|
$error_ids[$id2] = i18n("Must come after \"%1\"", array($dates[$d1]['description']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chkafter('regopen','regclose');
|
||||||
|
chkafter('judgeregopen','judgeregclose');
|
||||||
|
chkafter('specawardregopen','specawardregclose');
|
||||||
|
chkafter('fairdate','postwinners');
|
||||||
|
|
||||||
|
/* And print the table with all the info in the correct order */
|
||||||
|
foreach($dates as $d) {
|
||||||
|
$e = '';
|
||||||
|
if($error_ids[$d['id']]) {
|
||||||
|
$e = "<font color=red size=-1>* ".i18n($error_ids[$d['id']])."</font>";
|
||||||
|
}
|
||||||
|
echo "<tr><td>".i18n($d['description'])."</td><td><input type=\"text\" name=\"savedates[{$d['id']}]\" value=\"{$d['date']}\" />{$e}</td></tr>";
|
||||||
|
}
|
||||||
|
|
||||||
echo "</table>";
|
echo "</table>";
|
||||||
echo "<input type=\"submit\" value=\"".i18n("Save Dates")."\" />\n";
|
echo "<input type=\"submit\" value=\"".i18n("Save Dates")."\" />\n";
|
||||||
echo "</form>";
|
echo "</form>";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user