You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
433 lines
15 KiB
433 lines
15 KiB
<?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 "adminUtils.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) && returnAdminStatus($_SESSION['MemberID'])) |
|
{ |
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') |
|
{ |
|
/* |
|
* validate form data. |
|
*/ |
|
if (isset($_POST['id']) && isset($_POST['name']) && isset($_POST['description'])) |
|
try |
|
{ |
|
$insert = TRUE; |
|
//print_r(PDO::getAvailableDrivers()); |
|
$dbh = returnDatabaseHandel(); |
|
//$dbh->beginTransaction(); |
|
$sth = $dbh->prepare("SELECT * FROM courses"); |
|
$count = 0; |
|
if ($sth->execute()) |
|
{ |
|
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
{ |
|
if ($row['id'] === $_POST['id']) |
|
{ |
|
$insert = FALSE; |
|
} |
|
} |
|
//echo "here"; |
|
if ($insert) |
|
{ |
|
$sth = $dbh->prepare("INSERT INTO courses (id, name, description) values (?, ?, ?)"); |
|
$sth->execute(array($_POST['id'], $_POST['name'], $_POST['description'])); |
|
} |
|
else |
|
{ |
|
$dbh->beginTransaction(); |
|
$sth = $dbh->prepare("UPDATE courses SET name = ?, description = ? WHERE id = ?"); |
|
$sth->execute(array($_POST['name'], $_POST['description'], $_POST['id'])); |
|
//print_r($sth->errorInfo()); |
|
$dbh->commit(); |
|
} |
|
} |
|
} |
|
catch (Exception $e) |
|
{ |
|
print ("Fail! " . $e->getMessage() . "\n"); |
|
} |
|
} |
|
|
|
$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)); |
|
if (returnInstructorStatus($_SESSION['MemberID'])) |
|
if ($_SESSION['sub_nav'] === "Admin") |
|
$body->appendChild(generateAdminNavigationBar($doc)); |
|
else |
|
if ($_SESSION['sub_nav'] === "Director") |
|
$body->appendChild(generateDirectorNavigationBar($doc)); |
|
else |
|
$body->appendChild(generateTrainingNavigationBar($doc)); |
|
else |
|
if (returnAdminStatus($_SESSION['memberID'])) |
|
$body->appendChild(generateAdminNavigationBar($doc)); |
|
*/ |
|
|
|
/* |
|
* do not set session sub nav |
|
*/ |
|
|
|
//$body->appendChild(generateSelectedMenuBar($doc)); |
|
|
|
$body->appendChild(generateTopStickyDiv($doc, $baseDir)); |
|
|
|
/* |
|
* Insert content here. |
|
*/ |
|
|
|
$bodyDiv = $doc->createElement('div'); |
|
$bodyDiv->setAttribute('class', 'BodyDiv'); |
|
|
|
/* |
|
$tableDiv = $doc->createElement('div'); |
|
//$tableDiv->setAttribute('display', 'block'); |
|
$tableDiv->setAttribute('class', 'FloatLeft50Div'); |
|
$table = $doc->createElement('table'); |
|
//$table.setAttribute('class' |
|
//$table->setAttribute('class', 'FloatLeft50Div'); |
|
$thead = $doc->createElement('thead'); |
|
$tr = $doc->createElement('tr'); |
|
|
|
$th = $doc->createElement('th'); |
|
$a = $doc->createElement('a'); |
|
$a->appendChild($doc->createTextNode('ID')); |
|
$th->appendChild($a); |
|
$tr->appendChild($th); |
|
|
|
$th = $doc->createElement('th'); |
|
$a = $doc->createElement('a'); |
|
$a->appendChild($doc->createTextNode('Course Name')); |
|
$th->appendChild($a); |
|
$tr->appendChild($th); |
|
|
|
$th = $doc->createElement('th'); |
|
$a = $doc->createElement('a'); |
|
$a->appendChild($doc->createTextNode('Description')); |
|
$th->appendChild($a); |
|
$tr->appendChild($th); |
|
|
|
$thead->appendChild($tr); |
|
$table->appendChild($thead); |
|
|
|
$tbody = $doc->createElement('tbody'); |
|
|
|
$tint = false; |
|
|
|
$edit = NULL; |
|
$highestID = 0; |
|
|
|
try |
|
{ |
|
//print_r(PDO::getAvailableDrivers()); |
|
$dbh = new PDO($dsn, $dbUserName, $dbPassWord, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); |
|
$dbh->beginTransaction(); |
|
$sth = $dbh->prepare("SELECT * FROM courses"); |
|
$count = 0; |
|
|
|
if ($sth->execute()) |
|
{ |
|
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
{ |
|
if (isset($_GET['id'])) |
|
if ($row['id'] === $_GET['id']) |
|
$edit = $row; |
|
|
|
$count++; |
|
if ($row['id'] > $highestID) |
|
$highestID = $row['id']; |
|
|
|
$tr = $doc->createElement('tr'); |
|
|
|
if ($tint === true) |
|
{ |
|
$tr->setAttribute('class', 'AlternateRow'); |
|
} |
|
|
|
$td = $doc->createElement('td'); |
|
$rr = $doc->createElement('a'); |
|
$rr->setAttribute('href', "courseEditor.php?id=${row['id']}"); |
|
$rr->appendChild($doc->createTextNode($row['id'])); |
|
$td->appendChild($rr); |
|
$tr->appendChild($td); |
|
|
|
$td = $doc->createElement('td'); |
|
$td->appendChild($doc->createTextNode($row['name'])); |
|
$tr->appendChild($td); |
|
|
|
$td = $doc->createElement('td'); |
|
$td->appendChild($doc->createTextNode($row['description'])); |
|
$tr->appendChild($td); |
|
|
|
$tbody->appendChild($tr); |
|
} |
|
} |
|
$table->appendChild($tbody); |
|
$tableDiv->appendChild($table); |
|
} |
|
catch (Exception $e) |
|
{ |
|
echo "Failed!" . $e->getMessage() . "\n"; |
|
}*/ |
|
if (isset($_GET['id'])) |
|
$edit = getCourseRowByID($_GET['id']); |
|
else |
|
$edit = NULL; |
|
$highestID = getHighestCourseID(); |
|
|
|
$bodyDiv->appendChild(generateCourseTable($doc)); |
|
|
|
|
|
if (!($edit === NULL)) |
|
{ |
|
$editorDiv = $doc->createElement('div'); |
|
$editorDiv->setAttribute('id', 'CourseEditorDiv'); |
|
$form = $doc->createElement('form'); |
|
$form->setAttribute('action', 'courseEditor.php'); |
|
$form->setAttribute('method', 'post'); |
|
$label = $doc->createElement('H3'); |
|
$label->appendChild($doc->createTextNode("Course ID: " . $edit['id'])); |
|
$form->appendChild($label); |
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'hidden'); |
|
$input->setAttribute('name', 'id'); |
|
$input->setAttribute('readonly', 'readonly'); |
|
$input->setAttribute('value', $edit['id']); |
|
$form->appendChild($input); |
|
$fieldSet = $doc->createElement('fieldset'); |
|
//$fieldSet->setAttribute('style', 'width:200px; max-width:300px;'); //margin-top:0.5em;'); |
|
$fieldSetDiv = $doc->createElement('div'); |
|
|
|
$label = $doc->createElement('label', 'Course Name:'); |
|
$label->setAttribute('for', 'name'); |
|
$label->setAttribute('class', 'CourseEditorInputLabel'); |
|
$fieldSetDiv->appendChild($label); |
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'text'); |
|
$input->setAttribute('name', 'name'); |
|
$input->setAttribute('autocomplete', 'off'); |
|
$input->setAttribute('required', 'required'); |
|
if (isset($edit['name'])) |
|
$input->setAttribute('value', $edit['name']); |
|
$fieldSetDiv->appendChild($input); |
|
$label = $doc->createElement('br'); |
|
$fieldSetDiv->appendChild($label); |
|
|
|
/* |
|
$label = $doc->createElement('label', 'Description:'); |
|
$label->setAttribute('for', 'description'); |
|
$label->setAttribute('class', 'CourseEditorInputLabel'); |
|
$fieldSetDiv->appendChild($label); |
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'text'); |
|
$input->setAttribute('name', 'description'); |
|
$input->setAttribute('autocomplete', 'off'); |
|
$input->setAttribute('required', 'required'); |
|
if (isset($edit['description'])) |
|
$input->setAttribute('value', $edit['description']); |
|
$fieldSetDiv->appendChild($input); |
|
$label = $doc->createElement('br'); |
|
$fieldSetDiv->appendChild($label); |
|
*/ |
|
|
|
$label = $doc->createElement('label', 'Description:'); |
|
$label->setAttribute('for', 'description'); |
|
$label->setAttribute('class', 'CourseEditorInputLabel'); |
|
$fieldSetDiv->appendChild($label); |
|
$input = $doc->createElement('textarea'); |
|
$input->setAttribute('type', 'text'); |
|
$input->setAttribute('name', 'description'); |
|
$input->setAttribute('autocomplete', 'off'); |
|
$input->setAttribute('rows', '6'); |
|
$input->setAttribute('required', 'required'); |
|
if (isset($edit['description'])) |
|
$input->appendChild($doc->createTextNode($edit['description'])); |
|
$fieldSetDiv->appendChild($input); |
|
$label = $doc->createElement('br'); |
|
$fieldSetDiv->appendChild($label); |
|
|
|
|
|
$fieldSet->appendChild($fieldSetDiv); |
|
|
|
$form->appendChild($fieldSet); |
|
|
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'reset'); |
|
$form->appendChild($input); |
|
|
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'submit'); |
|
$form->appendChild($input); |
|
$editorDiv->appendChild($form); |
|
$bodyDiv->appendChild($editorDiv); |
|
} |
|
else |
|
{ |
|
$nextHighestID = $highestID + 1; |
|
$editorDiv = $doc->createElement('div'); |
|
$editorDiv->setAttribute('id', 'CourseEditorDiv'); |
|
$editorDiv->setAttribute('class', 'sticky'); |
|
$form = $doc->createElement('form'); |
|
$form->setAttribute('action', 'courseEditor.php'); |
|
$form->setAttribute('method', 'POST'); |
|
$form->setAttribute('enctype', 'multipart/form-data'); |
|
$label = $doc->createElement('H3'); |
|
$label->appendChild($doc->createTextNode("Add New Course")); |
|
$form->appendChild($label); |
|
$fieldSet = $doc->createElement('fieldset'); |
|
//$fieldSet->setAttribute('style', 'width:200px; max-width:300px;'); //margin-top:0.5em;'); |
|
$fieldSetDiv = $doc->createElement('div'); |
|
|
|
$fieldSet->appendChild($fieldSetDiv); |
|
|
|
$label = $doc->createElement('label', 'Course ID:'); |
|
$label->setAttribute('for', 'id'); |
|
$label->setAttribute('class', 'CourseEditorInputLabel'); |
|
$fieldSetDiv->appendChild($label); |
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'number'); |
|
$input->setAttribute('name', 'id'); |
|
$input->setAttribute('autocomplete', 'off'); |
|
$input->setAttribute('required', 'required'); |
|
$input->setAttribute('value', "$nextHighestID"); |
|
$input->setAttribute('min', "$nextHighestID"); |
|
$input->setAttribute('step', '1'); |
|
$fieldSetDiv->appendChild($input); |
|
|
|
$label = $doc->createElement('label', 'Course Name:'); |
|
$label->setAttribute('for', 'name'); |
|
$label->setAttribute('class', 'CourseEditorInputLabel'); |
|
$fieldSetDiv->appendChild($label); |
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'text'); |
|
$input->setAttribute('name', 'name'); |
|
$input->setAttribute('autocomplete', 'off'); |
|
$input->setAttribute('required', 'required'); |
|
|
|
$fieldSetDiv->appendChild($input); |
|
$label = $doc->createElement('br'); |
|
$fieldSetDiv->appendChild($label); |
|
|
|
/* |
|
$label = $doc->createElement('label', 'Description:'); |
|
$label->setAttribute('for', 'description'); |
|
$label->setAttribute('class', 'CourseEditorInputLabel'); |
|
$fieldSetDiv->appendChild($label); |
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'text'); |
|
$input->setAttribute('name', 'description'); |
|
$input->setAttribute('autocomplete', 'off'); |
|
$input->setAttribute('required', 'required'); |
|
$fieldSetDiv->appendChild($input); |
|
$label = $doc->createElement('br'); |
|
$fieldSetDiv->appendChild($label); |
|
*/ |
|
|
|
$label = $doc->createElement('label', 'Description:'); |
|
$label->setAttribute('for', 'description'); |
|
$label->setAttribute('class', 'CourseEditorInputLabel'); |
|
$fieldSetDiv->appendChild($label); |
|
$input = $doc->createElement('textarea'); |
|
$input->setAttribute('type', 'text'); |
|
$input->setAttribute('name', 'description'); |
|
$input->setAttribute('autocomplete', 'off'); |
|
$input->setAttribute('rows', '6'); |
|
$input->setAttribute('required', 'required'); |
|
$input->appendChild($doc->createTextNode("")); /* a child node is needed to close the textarea */ |
|
$fieldSetDiv->appendChild($input); |
|
$label = $doc->createElement('br'); |
|
$fieldSetDiv->appendChild($label); |
|
|
|
|
|
$form->appendChild($fieldSet); |
|
|
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'reset'); |
|
$form->appendChild($input); |
|
|
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'submit'); |
|
$form->appendChild($input); |
|
$input = $doc->createElement('input'); |
|
$input->setAttribute('type', 'hidden'); |
|
$input->setAttribute('value', 'Add'); |
|
$input->setAttribute('name', 'action'); |
|
$input->setAttribute('readonly', 'readonly'); |
|
$form->appendChild($input); |
|
|
|
$editorDiv->appendChild($form); |
|
//$bodyDiv->appendChild($editorDiv); |
|
$body->appendChild($editorDiv); // Needs to be in the body for sticky |
|
} |
|
|
|
$body->appendChild($bodyDiv); |
|
$body->appendChild(generateFooter($doc)); |
|
if ($prettyPretty) |
|
$doc->formatOutput = true; |
|
echo $doc->saveXML(); |
|
} |
|
else |
|
generateIndexRedirect(); |
|
|
|
?>
|