// $Id: StationEditAction.php 2431 2003-01-07 20:24:44Z cross $ Copyright (c) ConSked, LLC. All Rights Reserved.
include 'util/authenticateOrganizer.php';
require_once 'properties/constants.php';
require_once 'db/StationJob.php';
require_once 'db/JobTitle.php';
require_once 'db/Worker.php';
require_once 'db/JobTitle.php';
require_once 'util/log.php';
require_once 'util/session.php';
require_once 'swwat/gizmos/parse.php';
$station = getStationCurrent();
if (isset($_REQUEST['copy'])) {
    $station->stationid = NULL;
}
if (isset($_POST[PARAM_SAVE])) {
    $titleEnums = JobTitle::titleEnums($station->expoid);
    try {
        $station->startTime = swwat_parse_date(html_entity_decode($_POST[PARAM_DATE] . " " . $_POST[PARAM_STARTHOUR]), true);
        $station->stopTime = swwat_parse_date(html_entity_decode($_POST[PARAM_DATE] . " " . $_POST[PARAM_STOPHOUR]), true);
        $station->jobTitle = swwat_parse_enum($_POST[PARAM_JOB], $titleEnums, false);
        $station->maxCrew = swwat_parse_integer(html_entity_decode($_POST[PARAM_MAXCREW]), 11, true);
        $station->minCrew = swwat_parse_integer(html_entity_decode($_POST[PARAM_MINCREW]), 11, true);
        $station->maxSupervisor = swwat_parse_integer(html_entity_decode($_POST[PARAM_MAXSUPERVISOR]), 11, true);
        $station->minSupervisor = swwat_parse_integer(html_entity_decode($_POST[PARAM_MINSUPERVISOR]), 11, true);
        $station->description = swwat_parse_string(html_entity_decode($_POST[PARAM_DESCRIPTION]), true);
        $station->title = swwat_parse_string(html_entity_decode($_POST[PARAM_TITLE]), true);
        $station->location = swwat_parse_string(html_entity_decode($_POST[PARAM_LOCATION]), true);
        $station->instruction = swwat_parse_string(html_entity_decode($_POST[PARAM_INSTRUCTION]), true);
    } catch (Exception $ex) {
        header('Location: WorkerLoginPage.php');
        include 'WorkerLoginPage.php';
function createStationHTMLList($expo, array $stationList)
{
    $jobList = Job::selectExpo($expo->expoid);
    usort($jobList, "JobCompare");
    $date = array();
    foreach ($jobList as $j) {
        $stationDateTime = swwat_format_shift($j->startTime, $j->stopTime);
        list($stationDate, $stationTime, $start) = explode(';', $stationDateTime);
        $date[] = $stationDate;
    }
    $date = array_values(array_unique($date));
    echo "<table width=\"50%\">\n";
    echo "<tr>\n";
    echo "<td>\n";
    echo "Select Date: <select id=\"" . PARAM_DATE . "\" name=\"" . PARAM_DATE . "\" onchange=\"hideDateRows()\">\n";
    for ($k = 0; $k < count($date); $k++) {
        echo "<option value=\"" . $date[$k] . "\">&nbsp;" . $date[$k] . "&nbsp;</option>\n";
    }
    echo "<option value=\"All\">&nbsp;All Dates&nbsp;</option>\n";
    echo "</select>\n";
    echo "</td>\n";
    $jobTitle = JobTitle::titleEnums($expo->expoid);
    echo "<td>\n";
    echo "Select Job: <select id=\"" . PARAM_JOB . "\" name=\"" . PARAM_JOB . "\" onchange=\"hideJobRows()\">\n";
    for ($k = 0; $k < count($jobTitle); $k++) {
        echo "<option value=\"" . $jobTitle[$k] . "\">&nbsp;" . $jobTitle[$k] . "&nbsp;</option>\n";
    }
    echo "<option value=\"All\" selected=\"selected\">&nbsp;All Jobs&nbsp;</option>\n";
    echo "</select>\n";
    echo "</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>\n";
    echo "<p />Search Shift By: <input type=\"text\" id=\"search\" name=\"search\" onkeyup=\"searchRows()\"\\>";
    echo "</td>\n";
    echo "</tr>\n";
    echo "</table>\n";
    echo "<p />\n";
    echo "<div id=\"stationlist_table\">\n";
    echo "<table>\n";
    echo "<tr>\n";
    echo "<th class=\"rowTitle\">Shift</th>\n";
    echo "<th class=\"rowTitle\">Job</th>\n";
    echo "<th class=\"rowTitle\">Location</th>\n";
    echo "<th class=\"rowTitle\">Date</th>\n";
    echo "<th class=\"rowTitle\">Time</th>\n";
    echo "<th class=\"rowTitle\">Crew</th>\n";
    echo "<th class=\"rowTitle\">Supervisors</th>\n";
    echo "<th class=\"rowTitle\">Instructions</th>\n";
    echo "<th class=\"rowTitle\"></th>\n";
    echo "</tr>\n";
    $c = count($stationList);
    if ($c > 0) {
        for ($k = 0; $k < $c; $k++) {
            $s = $stationList[$k];
            makeStationListHTMLRows($s, $k);
        }
    } else {
        echo "<tr><td class=\"fieldError\" colspan=\"5\">No stations for this Expo currently exist.</td></tr>\n";
    }
    echo "</table></div><!-- stationlist_table -->\n";
}