psportal-murray/training.php

214 lines
7.7 KiB
PHP
Raw Normal View History

2019-02-18 02:40:33 +00:00
<?php
/*
Copyright 2018 Murray Hayes
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
session_start();
include_once "utils.php";
include_once "DOMUtils.php";
include_once "consts.php";
include_once "database.php";
include_once "trainingUtils.php";
$doc = returnDoc();
$root = returnRoot($doc);
//if (!isset($_SESSION['login']) || !isset($_SESSION['MemberID']))
if (!validateSession())
if (!isset($_SESSION['cookieMonster']))
generateCookieMonster();
else
generateLoginRedirect();
else
if (($_SESSION['login'] === TRUE) &&
(returnInstructorStatus($_SESSION['MemberID']) || returnDirectorStatus($_SESSION['MemberID']) ||
returnAdminStatus($_SESSION['MemberID'])))
{
$sort_order = 'Ascending';
$rev_order = 'Descending';
$sort_field = NULL;
if ($_SERVER['REQUEST_METHOD'] === 'GET')
{
if (isset($_GET['Order']))
switch ($_GET['Order'])
{
case 'Decending':
$sort_order = 'Descending';
$rev_order = 'Ascending';
break;
case 'Ascending':
default:
$sort_order = 'Ascending';
$rev_order = 'Descending';
break;
}
if (isset($_GET['Sort']))
switch ($_GET['Sort'])
{
case 'Class':
$sort_field = 'Class';
break;
case 'Title':
$sort_field = 'Title';
break;
case 'Date':
$sort_field = 'Date';
break;
case 'Confirmed':
$sort_field = 'Confirmed';
break;
case 'Open':
$sort_field = 'Open';
break;
default:
$sort_field = NULL;
}
}
else
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
//print_r ($_POST);
if (isset($_POST['newClass']) && isset($_POST['startdate']) && isset($_POST['cost']) && isset($_POST['seats']))
{
$newClass_input = cleanInput($_POST['newClass']);
$startDateTime_input = date($dbDateTimeFormat,
strtotime(cleanInput($_POST['startdate']) . ' ' . cleanInput($_POST['starttime'])));
$cost_input = cleanInput($_POST['cost']);
$seats_input = cleanInput($_POST['seats']);
if (returnAdminStatus($_SESSION['MemberID']) || returnDirectorStatus($_SESSION['MemberID']))
{
if (isset($_POST['instructor']))
$instructor = cleanInput($_POST['instructor']);
else
$instructor = $_SESSION['MemberID'];
}
else
$instructor = $_SESSION['MemberID'];
insertIntoClassesTable($newClass_input, $instructor, $startDateTime_input, $cost_input, $seats_input);
}
else
{
logAccessViolation(1, "Incomplete form data submitted to training.php");
print ("Incomplete form data submitted. Access violation logged.");
}
//print_r ($course_input);
}
$root = $doc->appendChild($root);
$root->appendChild(generateHead($doc));
$body = $doc->createElement('body');
$root->appendChild($body);
$body->appendChild(generateMastHead($doc, $baseDir));
//$body->appendChild($doc->createElement('hr'));
/*
$body->appendChild(generateMemberNavigationBar($doc));
$body->appendChild(generateTrainingNavigationBar($doc)); */
$_SESSION['subNav'] = "0";
$body->appendChild(generateSelectedMenuBar($doc, 0));
$myClassesDiv = createDiv($doc, NULL, 'ClassTableDiv');
$tableTitle = $doc->createElement('H3');
$tableTitle->appendChild($doc->createTextNode("Classes I'm Teaching"));
$myClassesDiv->appendChild($tableTitle);
$myClassesDiv->appendChild(generateTrainingTable($doc, NULL, $sort_order, $sort_field, '', NULL, $_SESSION['MemberID']));
$newClassDiv = createDiv($doc, 'NewClassDiv');
$form = createForm($doc, 'training.php');
$fieldSet = $doc->createElement('fieldset');
$h3 = $doc->createElement('h3');
$h3->appendChild($doc->createTextNode('Configure a New Class'));
$fieldSet->appendChild($h3);
$fieldSet->appendChild(createLabel($doc, "New class: ", 'newClass'));
if (returnAdminStatus($_SESSION['MemberID']) || returnDirectorStatus($_SESSION['MemberID']))
{
$fieldSet->appendChild(generateCourseSelector($doc, 'newClass', NULL));
$fieldSet->appendChild(createBr($doc));
$fieldSet->appendChild(createLabel($doc, 'Instructor: ', 'instructor'));
$fieldSet->appendChild(generateMemberSelector($doc, 'instructor', $_SESSION['MemberID']));
}
else
$fieldSet->appendChild(generateCourseSelector($doc, 'newClass', $_SESSION['MemberID']));
$fieldSet->appendChild(createBr($doc));
$fieldSet->appendChild(createLabel($doc, "Starting at: ", 'startdate'));
$fieldSet->appendChild(createDateInput($doc, 'startdate', (string)date('Y-m-d'), NULL, NULL, date($dbDateFormat)));
$fieldSet->appendChild(createTimeInput($doc, 'starttime', '08:00'));
$fieldSet->appendChild(createBr($doc));
$fieldSet->appendChild(createLabel($doc, 'Cost: ', 'cost'));
$fieldSet->appendChild(createNumberInput($doc, 'cost', '0.00', NULL, NULL, '0'));
$fieldSet->appendChild(createBr($doc));
$fieldSet->appendChild(createLabel($doc, 'Seats: ', 'seats'));
$seats = createNumberInput($doc, 'seats', '12', NULL, NULL, 1, 120);
$seats->setAttribute('step', '1');
$fieldSet->appendChild($seats);
$fieldSet->appendChild(createBr($doc));
$fieldSet->appendChild(createSubmitInput($doc, 'addClass', 'Add A Class'));
$form->appendChild($fieldSet);
$newClassDiv->appendChild($form);
$myClassesDiv->appendChild($newClassDiv);
$body->appendChild($myClassesDiv);
$myClassesDiv = $doc->createElement('div');
$myClassesDiv->setAttribute('id', 'ClassTableDiv');
$tableTitle = $doc->createElement('H3');
$tableTitle->appendChild($doc->createTextNode("Upcoming Classes"));
$myClassesDiv->appendChild($tableTitle);
$myClassesDiv->appendChild(generateTrainingTable($doc, 'training.php', $sort_order, $sort_field));
$body->appendChild($myClassesDiv);
/*
if (isset($_SESSION['FirstName']) && isset($_SESSION['LastName']))
{
}
$myClassesDiv->appendChild(generateBriefTrainingTable($doc, $baseDir));
*/
$body->appendChild(generateFooter($doc));
outputDoc($doc);
}
else
generateIndexRedirect();
?>