Return to the Demonstration.

<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Site Header Management</title>
<style> <!--
    body {font-family: 'Trebuchet MS'; color: black; background-color: #DDDDFF;}
    ul {list-style-type: none; margin: 0; padding: 0;}
    li {margin: 0; padding: 0;}
    form {text-align: center; width: 25em;}
    select.start_day {margin-right: 2em;}
    div.heading {font-weight: bold;}
    .error {color: #CC0000; font-weight: bold;}
    a:link {font-weight: bold; color: #999999;}
    a:visited {font-weight: bold; color: #999999;}
    a:hover {font-weight: bold; color: #333300;}
    
    a:active {font-weight: bold; color: #FFFFFF;}
-->
</style>
</head>
<body>
<?php
require_once ('Sorry, but it's a private path/dev_ini_settings.php');
require_once (
'Sorry, but it's a private path/lib.php');
require_once (
'Sorry, but it's a private path/dbconn.php');

/* initialize variables used throughout the program */
$valid_months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
$valid_seasons = array();
$season_codes = array();
$query = 'SELECT sort_order, season FROM valid_seasons ORDER BY sort_order';
if (
$result = mysql_query($query)) {
    while (
$row = mysql_fetch_assoc($result)) {
        
$valid_seasons[(int)$row['sort_order']] = $row['season'];
        
$season_codes[$row['season']] = (int) $row['sort_order'];
    }
    
mysql_free_result($result);
}

$flash_header_file = $flash_header_name = '';
/* get today's date and figure out what seasonal header should be displayed */
$today = getdate();
$this_year = $today['year'];
/* 'file' column name is also a MySQL keyword, so need the backquotes */
$today = mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year'], -1);
$query = 'SELECT start_month, start_day, end_month, end_day, `file` ' .
    
'FROM site_header_sched, valid_seasons WHERE sort_order=season_code';
$result = mysql_query($query);
if (
FALSE !== $result) {
    if (
mysql_num_rows($result)) { /* at least one row in the result set? */
        
while ($row = mysql_fetch_assoc($result)) {
            
/* unix timestamp for the end date - always assume current year */
            
$te = mktime(0,0,0, 1+array_search($row['end_month'], $valid_months), $row['end_day'], $this_year, -1);
            
/* account for year-end crossovers */
            
$year = ('Dec' === $row['start_month'] && 'Jan' === $row['end_month']) ? $this_year-1 : $this_year;
            
/* note that this will cause no error even for Feb 29 */
            
$ts = mktime(0,0,0, 1+array_search($row['start_month'], $valid_months), $row['start_day'], $year, -1);
            
/* see if today is within this row's range */
            
if ($today >= $ts && $today <= $te) {
                
$flash_header_file = $row['file'];
                
$flash_header_name = substr($flash_header_file, 0, strrpos($flash_header_file, '.'));
                break;
            }
        }
    }
    
mysql_free_result($result);
} else {
/* for debug ONLY - never leave this kind of stuff in production code! */
echo mysql_errno() . ": " . mysql_error();
exit (
$query);
}
/* use default header if no records found or a db error occurred */
if ('' === $flash_header_file) {
    
$flash_header_file= 'CBO_flashHeader.swf';
    
$flash_header_name = 'CBO_flashHeader';
}
?>

<!-- Display the Appropriate Seasonal Site Header based on today's date - The whole point of this program. -->

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" style="width: 800px; height: 96px" id="<?php echo $flash_header_name; ?>">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="movie" value="../wfbrn3vdl/graphics/<?php echo $flash_header_file; ?>" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
    <embed src="../wfbrn3vdl/graphics/<?php echo $flash_header_file; ?>" style="width: 800px; height: 96px" quality="high" bgcolor="#ffffff" name="<?php echo $flash_header_name; ?>" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<br />
Status:
<?php

function show_form_header () {
$ret_str = '<form action="header_mgt.php" method="POST" enctype="application/x-www-form-urlencoded">' .
    
'<div class="heading"><span title="Season for Header" style="padding-left: 3em;">Season</span><span title="First Date Header will Appear" style="padding-left: 3.5em; padding-right: 4em">Start Date</span><span title="Final Date Header will Appear" style="padding-right: 1em;">End Date</span><br /></div>(\'Standard\' Header need never be specified.)<br />';
return
$ret_str;
}

function
show_form_footer() {
$ret_str = '</ul><input type="submit" name="change" value="Save All Changes" title="Save all changes you\'ve made." />' .
    
'<input type="submit" name="delete" value="Remove Selected Headers" title="Remove Seasonal Header(s)" /><hr />' .
    
'<ul>' . show_add_li() . '</ul>' .
    
'<input type="submit" name="add" value="Add Header" title="Add Seasonal Header" />' .
    
'</form><hr />' .
    
'<a href="header_mgt.php" title="Refresh Screen to see changes">See Changes</a> after a Schedule Update ' .
    
'(refreshes the page without submitting the form\'s POST data.)<br />Remember that if your schedule changes ' .
    
'do not involve today\'s date, you won\'t notice any difference.<br /><br />' .
    
'<a href="/demo-center.php" title="Return to Demonstration Center">Return to Demo Center</a>';
return
$ret_str;
}

function
show_default_li () {
$out_str = '<li><select size="1" name="season[]" id="season" />';
global
$valid_seasons, $valid_months;
foreach (
$valid_seasons as $s) {
    if (
'Standard' !== $s) {
        
$out_str .= '<option value="' .$s. '">'. $s;
    } else {
        
$out_str .= '<option selected="selected" value="' .$s. '">'. $s;
    }
}
$out_str .= '</select><select size="1" name="start_month[]" id="start_month" />';

foreach (
$valid_months as $m) {
    if (
'Jan' !== $m) {
        
$out_str .= '<option value="' .$m. '">'. $m;
    } else {
        
$out_str .= '<option selected="selected" value="' .$m. '">'. $m;
    }
}
$out_str .= '</select><select size="1" class="start_day" name="start_day[]" id="start_day" />';

$out_str .= '<option selected="selected" value="1">1';
for (
$i=2; $i<=31; $i++) {
    
$out_str .= sprintf('<option value="%d">%d', $i, $i);
}
$out_str .= '</select><select size="1" name="end_month[]" id="end_month" />';

foreach (
$valid_months as $m) {
    if (
'Jan' !== $m) {
        
$out_str .= '<option value="' .$m. '">'. $m;
    } else {
        
$out_str .= '<option selected="selected" value="' .$m. '">'. $m;
    }
}
$out_str .= '</select><select size="1" name="end_day[]" id="end_day" />';

$out_str .= '<option selected="selected" value="1">1';
for (
$i=2; $i<=31; $i++) {
    
$out_str .= sprintf('<option value="%d">%d', $i, $i);
}
return (
$out_str .'</select></li>');
}

function
show_current_li ($season, $start_month, $start_day, $end_month, $end_day) {
$start_day = (int) $start_day;
$end_day = (int) $end_day;
static
$index = 0;
$ret_str = '<li><input type="checkbox" name="del_mark[' .$index++. ']" /><select size="1" name="season[]" id="season" />';
global
$valid_seasons, $valid_months;
foreach (
$valid_seasons as $s) {
    if (
$season !== $s) {
        
$ret_str .= '<option value="' .$s. '">'. $s;
    } else {
        
$ret_str .= '<option selected="selected" value="' .$s. '">'. $s;
    }
}
$ret_str .= '</select><select size="1" name="start_month[]" id="start_month" />';

foreach (
$valid_months as $s) {
    if (
$start_month !== $s) {
        
$ret_str .= '<option value="' .$s. '">'. $s;
    } else {
        
$ret_str .= '<option selected="selected" value="' .$s. '">'. $s;
    }
}
$ret_str .= '</select><select size="1" class="start_day" name="start_day[]" id="start_day" />';

for (
$i=1; $i<=31; $i++) {
    if (
$start_day !== $i) {
        
$ret_str .= sprintf('<option value="%d">%d', $i, $i);
    } else {
        
$ret_str .= sprintf('<option selected="selected" value="%d">%d', $i, $i);
    }
}
$ret_str .= '</select><select size="1" name="end_month[]" id="end_month" />';

foreach (
$valid_months as $s) {
    if (
$end_month !== $s) {
        
$ret_str .= '<option value="' .$s. '">'. $s;
    } else {
        
$ret_str .= '<option selected="selected" value="' .$s. '">'. $s;
    }
}
$ret_str .= '</select><select size="1" name="end_day[]" id="end_day" />';

for (
$i=1; $i<=31; $i++) {
    if (
$end_day !== $i) {
        
$ret_str .= sprintf('<option value="%d">%d', $i, $i);
    } else {
        
$ret_str .= sprintf('<option selected="selected" value="%d">%d', $i, $i);
    }
}
return (
$ret_str .'</select></li>');
}

function
show_add_li () {
$out_str = '<li><select size="1" name="add_season" id="add_season" />';
global
$valid_seasons, $valid_months;
foreach (
$valid_seasons as $s) {
    if (
'Standard' !== $s) {
        
$out_str .= '<option value="' .$s. '">'. $s;
    } else {
        
$out_str .= '<option selected="selected" value="' .$s. '">'. $s;
    }
}
$out_str .= '</select><select size="1" name="add_start_month" id="add_start_month" />';

foreach (
$valid_months as $m) {
    if (
'Jan' !== $m) {
        
$out_str .= '<option value="' .$m. '">'. $m;
    } else {
        
$out_str .= '<option selected="selected" value="' .$m. '">'. $m;
    }
}
$out_str .= '</select><select size="1" class="start_day" name="add_start_day" id="add_start_day" />';

$out_str .= '<option selected="selected" value="1">1';
for (
$i=2; $i<=31; $i++) {
    
$out_str .= sprintf('<option value="%d">%d', $i, $i);
}
$out_str .= '</select><select size="1" name="add_end_month" id="add_end_month" />';

foreach (
$valid_months as $m) {
    if (
'Jan' !== $m) {
        
$out_str .= '<option value="' .$m. '">'. $m;
    } else {
        
$out_str .= '<option selected="selected" value="' .$m. '">'. $m;
    }
}
$out_str .= '</select><select size="1" name="add_end_day" id="add_end_day" />';

$out_str .= '<option selected="selected" value="1">1';
for (
$i=2; $i<=31; $i++) {
    
$out_str .= sprintf('<option value="%d">%d', $i, $i);
}
return (
$out_str .'</select></li>');
}

function
get_table_contents() {
    global
$action_result;
    
$ret_str = '';
    
$query = 'SELECT season, start_month, start_day, end_month, end_day ' .
        
'FROM site_header_sched, valid_seasons WHERE sort_order=season_code ORDER BY end_month, end_day';
    if (
$result = mysql_query($query)) {
        
$ret_str = show_form_header() . '<ul>';
        if (
mysql_num_rows($result)) { /* at least one row in the result set? */
            
while ($row = mysql_fetch_assoc($result)) {
                
$ret_str .= show_current_li($row['season'], $row['start_month'], $row['start_day'], $row['end_month'], $row['end_day']);
            }
            
$action_result = 'Current seasonal headers.<br />';
        } else {
            
$action_result = '<span class="error">No headers defined. Only standard header will be displayed.</span><br />';
            
$ret_str .= show_default_li();
        }
        
mysql_free_result($result); /* not really needed since result set is tiny */
        
$ret_str .= show_form_footer();
    } else {
        
$action_result = '<span class="error"> No resultset from query. Contact database administrator</span><br />';
    }
    return
$ret_str;
}

function
show_default_form() {
    echo
show_form_header();
    echo
'<ul>';
    
show_default_li();
    echo
show_form_footer();
}

function
validate_update() {
/* validate all rows in the input form, in preparation for full table update */
global $valid_months, $action_result;
$rtn = TRUE;

/* don't validate deletion checkbox since it is ignored for update */
/* use the key into season to index corresponding columns in the same row */
if (isset($_POST['season']) && is_array($_POST['season'])) {
    
/* loop through form arrays, validating each column */
    
foreach ($_POST['season'] as $k => $v) {
        
/* validate season */
        
if (!preg_match("!^[a-zA-Z0-9\/\-\'\040]{1,30}$!", $v)) {
            
$rtn = FALSE;
            
$action_result = '<span class="error"> Invalid Season Name</span><br />';
            break;
        }
        
/* validate start_month */
        
if (isset($_POST['start_month'][$k])) {
            if (!
in_array($_POST['start_month'][$k], $valid_months, TRUE)) {
                
/* somebody modified the form */
                
$rtn = FALSE;
                
$action_result = '<span class="error"> Not a valid month</span><br />';
                break;
            }
        } else {
/* should never not be set when attempting to validate, but if it isn't, say so */
            
$rtn = FALSE;
            
$action_result = '<span class="error"> No start month specified. Contact system admin.</span><br />';
            break;
        }
        
/* validate start_day */
        
if (isset($_POST['start_day'][$k])) {
            
$r = array_search(substr($_POST['start_month'][$k], 0, 3), $valid_months);
            if (
FALSE !== $r) {
                
$m = 1 + $r;
                
$d = (int) substr($_POST['start_day'][$k], 0, 2);
                
$y = (int) date('Y');
                if (!
checkdate($m, $d, $y)) {
                    
$rtn = FALSE;
                    
$action_result = "<span class=\"error\"> {$m}-{$d}-{$y} is not a valid date.</span><br />";
                    break;
                }
            } else {
                
$rtn = FALSE;
                
$action_result = "<span class=\"error\"> {$_POST['start_month'][$k]} is not a valid month.</span><br />";
                break;
            }
        } else {
/* should never not be set when attempting to validate, but if it isn't, say so */
            
$rtn = FALSE;
            
$action_result = '<span class="error"> No start day specified. Contact system admin.</span><br />';
            break;
        }
        
/* validate end_month */
        
if (isset($_POST['end_month'][$k])) {
            
/* could save time by grabbing the key at this point */
            
if (!in_array($_POST['end_month'][$k], $valid_months, TRUE)) {
                
/* somebody modified the form */
                
$rtn = FALSE;
                
$action_result = '<span class="error"> Invalid end month specified.</span><br />';
                break;
            }
        } else {
/* should never not be set when attempting to validate, but if it isn't, say so */
            
$rtn = FALSE;
            
$action_result = '<span class="error"> No end month specified. Contact system admin.</span><br />';
            break;
        }
        
/* month name is valid, make sure it does not precede the start month */
        /* starting month */
        
$r = array_search(substr($_POST['start_month'][$k], 0, 3), $valid_months);
        if (
FALSE !== $r) {
            
$ms = 1 + $r; /* adjust for zero base indexing */
            /* ending month */
            
$r = array_search(substr($_POST['end_month'][$k], 0, 3), $valid_months);
            if (
FALSE !== $r) {
                
$me = 1 + $r;
                
/* okay for Dec start to precede Jan end */
                
if ($me < $ms && ($ms !== 12 || $me !== 1)) {
                    
$rtn = FALSE;
                    
$action_result = "<span class=\"error\"> Ending month {$_POST['end_month'][$k]} cannot precede starting month {$_POST['start_month'][$k]}.</span><br />";
                    break;
                }
            } else {
                
$rtn = FALSE;
                
$action_result = '<span class="error"> Invalid end month specified.</span><br />';
                break;
            }
        } else {
            
$rtn = FALSE;
            
$action_result = '<span class="error"> Invalid start month specified.</span><br />';
            break;
        }
        
/* validate end_day */
        
if (isset($_POST['end_day'][$k])) {
            
$r = array_search(substr($_POST['end_month'][$k], 0, 3), $valid_months);
            if (
FALSE !== $r) {
                
$me = 1 + $r; /* adjust for zero base index */
                
$de = (int) substr($_POST['end_day'][$k], 0, 2);
                
$ye = (int) date('Y'); /* assume this year, but actually could be next */
                
if (!checkdate($me, $de, $ye)) {
                    
$rtn = FALSE;
                    
$action_result = "<span class=\"error\"> {$me}/{$de} is not a valid date in {$ye}.</span><br />";
                    break;
                }
                
$r = array_search(substr($_POST['start_month'][$k], 0, 3), $valid_months);
                if (
FALSE !== $r) {
                    
$ms = 1 + $r; /* adjust for zero base index */
                    
$ds = (int) substr($_POST['start_day'][$k], 0, 2);
                    
$ys = (int) date('Y'); /* again, assuming this year */
                    
if (!checkdate($ms, $ds, $ys)) {
                        
$rtn = FALSE;
                        
$action_result = "<span class=\"error\"> {$ms}/{$ds} is not a valid date in {$ys}.</span><br />";
                        break;
                    }
                } else {
                    
$rtn = FALSE;
                    
$action_result = '<span class="error"> Invalid start month specified.</span><br />';
                    break;
                }
            } else {
                
$rtn = FALSE;
                
$action_result = '<span class="error"> Invalid end month specified.</span><br />';
                break;
            }
            
/* convert to unix timestamps for easy comparison */
            /* technically, should think about dates in the next year */
            
$s = mktime(0, 0, 0, $ms, $ds, $ys, -1);
            
$e = mktime(0, 0, 0, $me, $de, $ye, -1);
            
/* make sure end does not precede start; okay for Dec start to precede Jan end */
            
if ($e < $s && ($ms !== 12 || $me !== 1)) {
                
$rtn = FALSE;
                
$action_result = "<span class=\"error\"> End date {$me}/{$de} cannot precede start date {$ms}/{$ds}.</span><br />";
                break;
            }
            
/* make sure this period does not overlap with any other periods in the form */
            
if (!($rtn = form_no_overlap($k, $ms, $ds, $me, $de))) { /* function sets $action_result in case of error */
                
echo 'There is an overlap<br />';
                break;
            }
        } else {
            
$rtn = FALSE;
            
$action_result = '<span class="error"> No end day specified.</span><br />';
        }
    }
/* end foreach */
} else {
    
$rtn = FALSE;
    
$action_result = '<span class="error"> Problem with form structure. Contact system administrator.</span><br />';
}
/* end if */
return $rtn;
}
/* end function */

/* checks the date range against header info in the form (NOT the database), looking for overlapping periods */
/* the arguments are numeric representations of their respective values */
/* the $key is used to prevent comparing the argument record against itself */
function form_no_overlap($key, $m_start, $d_start, $m_end, $d_end) {
global
$action_result, $valid_months;
$rtn = TRUE;
foreach (
$_POST['season'] as $k => $v) {
    
/* do not compare this record to itself */
    
if ($key != $k) {
        
$tms = 1 + array_search(substr($_POST['start_month'][$k], 0, 3), $valid_months);
        
$tme = 1 + array_search(substr($_POST['end_month'][$k], 0, 3), $valid_months);
        
/* simple month/day checking */
        
if (($tms === $m_start && (int) $_POST['start_day'][$k] === $d_start) ||
            (
$tme === $m_end && (int) $_POST['end_day'][$k] === $d_end)) {
            
$rtn = FALSE;
            
$action_result = "<span class=\"error\"> Date range {$m_start}/{$d_start} - {$m_end}/{$d_end} overlaps another period in the form:" .
                
" {$_POST['start_month'][$k]}/{$_POST['start_day'][$k]} - {$_POST['end_month'][$k]}/{$_POST['end_day'][$k]}. Cannot have two headers displaying at the same time.</span><br />";
            break;
        }
        
/* more complicated checking accounting for year-end crossovers */
        /* assumes current year unless a year crossover is implied (start in Dec, end not in Dec) */
        
$ys = (int) date('Y');
        
$ye = ((12 !== $m_start) || (12 === $m_end)) ? $ys : ($ys+1);
        
/* convert range passed in arguments to unix timestamps for easy comparison */
        
$s = mktime(0,0,0, $m_start, $d_start, $ys, -1);
        
$e = mktime(0,0,0, $m_end, $d_end, $ye, -1);
        
/* convert range specified by current form row to unix timestamps */
        
$ye = (12 !== $tms) || (12 === $tme) ? $ys : $ys+1;
        
$ts = mktime(0, 0, 0, $tms, (int) $_POST['start_day'][$k], $ys, -1);
        
$te = mktime(0, 0, 0, $tme, (int) $_POST['end_day'][$k], $ye, -1);
        
/* see if periods overlap */
        
if (!(($s > $ts && $s > $te) || ($e < $ts && $e < $te))) {
            
$rtn = FALSE;
            
$action_result = "<span class=\"error\"> Date range {$m_start}/{$d_start} - {$m_end}/{$d_end} overlaps another period:" .
                
" {$_POST['start_month'][$k]}/{$_POST['start_day'][$k]} - {$_POST['end_month'][$k]}/{$_POST['end_day'][$k]}. Cannot have two headers displaying at the same time.</span><br />";
            break;
        }
        
/* the following is a bit hokey, but it's all I can come up with at the moment - will have to revisit when I have time to think */
        /* the following depends on the fact that months/days have already been validated in terms of Dec/Jan crossovers */
        /* it adjusts the years in the timestamps if there is a crossover from one year to the next */
        
if ((int) date('Y', $ts) < (int) date('Y', $te)) {
            
$ye = (int) date('Y', $ts);
            
$ys = $ye-1;
            
$ts = mktime(0, 0, 0, $tme, (int) $_POST['start_day'][$k], $ys, -1);
            
$te = mktime(0, 0, 0, $tme, (int) $_POST['end_day'][$k], $ye, -1);
            
/* now see if periods overlap */
            
if (!(($s > $ts && $s > $te) || ($e < $ts && $e < $te))) {
                
$rtn = FALSE;
                
$action_result = "<span class=\"error\"> Date range {$m_start}/{$d_start} - {$m_end}/{$d_end} overlaps another period:" .
                    
" {$_POST['start_month'][$k]}/{$_POST['start_day'][$k]} - {$_POST['end_month'][$k]}/{$_POST['end_day'][$k]}. Cannot have two headers displaying at the same time.</span><br />";
                break;
            }
        }
    }
}
/* end foreach */
return $rtn;
}
/* end function */

function validate_fld ($fld_name) {
/* bug waiting to manifest if called with $_POST vars not set */
/* validate field values */
global $valid_months, $action_result;
$rtn = TRUE;

switch (
$fld_name) {
case
'add_season':
    
$_POST['add_season'] = (string) $_POST['add_season']; // this is probably useless
    
if (isset($_POST['add_season']) && !preg_match("!^[a-zA-Z0-9\/\-\'\040]{1,30}$!", $_POST['add_season'])) {
        
$rtn = FALSE;
        
$action_result = '<span class="error"> Invalid Season Name</span><br />';
    }
    break;
case
'add_start_month':
    
$_POST['add_start_month'] = (string) $_POST['add_start_month'];
    if (isset(
$_POST['add_start_month'])) {
        if (!
in_array($_POST['add_start_month'], $valid_months, TRUE)) {
            
/* somebody modified the form */
            
$rtn = FALSE;
            
$action_result = '<span class="error"> Not a valid month</span><br />';
        }
    } else {
/* should never not be set when attempting to validate, but if it isn't, say so */
        
$rtn = FALSE;
        
$action_result = '<span class="error"> No start month specified. Contact system admin.</span><br />';
    }
    break;
case
'add_start_day': /* validate start date */
    
if (isset($_POST['add_start_day'])) {
        
$r = array_search(substr($_POST['add_start_month'], 0, 3), $valid_months);
        if (
FALSE !== $r) {
            
$m = 1 + $r;
            
$d = (int) substr($_POST['add_start_day'], 0, 2);
            
$y = (int) date('Y');
            if (!
checkdate($m, $d, $y)) {
                
$rtn = FALSE;
                
$action_result = "<span class=\"error\"> {$m}-{$d}-{$y} is not a valid date.</span><br />";
            }
        } else {
            
$rtn = FALSE;
            
$action_result = "<span class=\"error\"> {$_POST['add_start_month']} is not a valid month.</span><br />";
        }
    } else {
/* should never not be set when attempting to validate, but if it isn't, say so */
        
$rtn = FALSE;
        
$action_result = '<span class="error"> No start day specified. Contact system admin.</span><br />';
    }
    break;
case
'add_end_month':
    
$_POST['add_end_month'] = (string) $_POST['add_end_month'];
    if (isset(
$_POST['add_end_month'])) {
    
/* could save time by grabbing the key at this point */
        
if (!in_array($_POST['add_end_month'], $valid_months, TRUE)) {
            
/* somebody modified the form */
            
$rtn = FALSE;
            
$action_result = '<span class="error"> Invalid end month specified.</span><br />';
            break;
        }
    } else {
/* should never not be set when attempting to validate, but if it isn't, say so */
        
$rtn = FALSE;
        
$action_result = '<span class="error"> No end month specified. Contact system admin.</span><br />';
        break;
    }
    
/* month name is valid, make sure it does not precede the start month */
    /* starting month */
    
$r = array_search(substr($_POST['add_start_month'], 0, 3), $valid_months);
    if (
FALSE !== $r) {
        
$ms = 1 + $r; /* adjust for zero base indexing */
        /* ending month */
        
$r = array_search(substr($_POST['add_end_month'], 0, 3), $valid_months);
        if (
FALSE !== $r) {
            
$me = 1 + $r;
            
/* okay for Dec start to precede Jan end */
            
if ($me < $ms && ($ms !== 12 || $me !== 1)) {
                
$rtn = FALSE;
                
$action_result = "<span class=\"error\"> Ending month {$_POST['add_end_month']} cannot precede starting month {$_POST['add_start_month']}.</span><br />";
            }
        } else {
            
$rtn = FALSE;
            
$action_result = '<span class="error"> Invalid end month specified.</span><br />';
        }
    } else {
        
$rtn = FALSE;
        
$action_result = '<span class="error"> Invalid start month specified.</span><br />';
    }
    break;
case
'add_end_day':
    if (isset(
$_POST['add_end_day'])) {
        
$r = array_search(substr(