239 lines
		
	
	
		
			8.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			239 lines
		
	
	
		
			8.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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 "text.php";
 | 
						|
 | 
						|
$doc = returnDoc();
 | 
						|
$root = returnRoot($doc);
 | 
						|
 | 
						|
//if (!isset($_SESSION['login']))
 | 
						|
if (!validateSession())
 | 
						|
  if (!isset($_SESSION['cookieMonster']))
 | 
						|
    generateCookieMonster();
 | 
						|
  else
 | 
						|
    generateLoginRedirect();
 | 
						|
else
 | 
						|
  if ($_SESSION['login'] === TRUE)
 | 
						|
  {
 | 
						|
    $root = $doc->appendChild($root);
 | 
						|
    $root->appendChild(generateHead($doc));
 | 
						|
    
 | 
						|
    $body = $doc->createElement('body');
 | 
						|
    $root->appendChild($body);
 | 
						|
    
 | 
						|
    $body->appendChild(generateMastHead($doc, $baseDir));  
 | 
						|
    $body->appendChild(generateSelectedMenuBar($doc));
 | 
						|
    
 | 
						|
    if ($_SERVER['REQUEST_METHOD'] == 'POST')
 | 
						|
    {
 | 
						|
      /*
 | 
						|
       * process class signup
 | 
						|
       * 
 | 
						|
       * check if a seat is available
 | 
						|
       * add a class_registrant record
 | 
						|
       */
 | 
						|
      //print_r($_POST);
 | 
						|
      if (isset($_POST['register']))
 | 
						|
      {
 | 
						|
        if (isset($_POST['class_id']) && ($_POST['register'] === "Register"))
 | 
						|
        {
 | 
						|
          $classID = (int) cleanInput($_POST['class_id']);
 | 
						|
          registerMemberForClass($classID, $_SESSION['MemberID']);
 | 
						|
          $h3 = $doc->createElement('h3');
 | 
						|
          $h3->appendChild($doc->createTextNode("You have been registered for class " . $classID));
 | 
						|
          $body->appendChild($h3);
 | 
						|
 | 
						|
          $p = $doc->createElement('p');
 | 
						|
          $p->appendChild($doc->createTextNode($text7000));
 | 
						|
          $body->appendChild($p);
 | 
						|
        }
 | 
						|
      }
 | 
						|
      else
 | 
						|
        if (isset($_POST['withdraw']))
 | 
						|
        {
 | 
						|
          if (isset($_POST['class_id']))
 | 
						|
          {
 | 
						|
            $classID = (int) cleanInput($_POST['class_id']);
 | 
						|
          }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    else
 | 
						|
      if ($_SERVER['REQUEST_METHOD'] == 'GET')
 | 
						|
      {
 | 
						|
        try
 | 
						|
        {
 | 
						|
          if (isset($_GET['class_id']))
 | 
						|
          {
 | 
						|
            /*
 | 
						|
             * Get with class_id, show class details/signup
 | 
						|
             */
 | 
						|
            $classID = (int) cleanInput($_GET['class_id']);
 | 
						|
            $classDiv = $doc->createElement('div');
 | 
						|
            $classDiv->setAttribute('class', 'FloatLeft50Div');
 | 
						|
            
 | 
						|
            $dbh = returnDatabaseHandel();
 | 
						|
            $sth = $dbh->prepare($statement249);
 | 
						|
            if ($sth->execute(array($classID)))
 | 
						|
            {
 | 
						|
              $count = 0;
 | 
						|
              while ($row = $sth->fetch(PDO::FETCH_ASSOC))
 | 
						|
              {
 | 
						|
                $count++;
 | 
						|
                $h3 = $doc->createElement('h3');
 | 
						|
                $h3->appendChild($doc->createTextNode("Class Number " . $row['id']));
 | 
						|
                $classDiv->appendChild($h3);
 | 
						|
                //$classDiv->appendChild($doc->createElement('br'));
 | 
						|
                $h3 = $doc->createElement('h3');
 | 
						|
                $h3->appendChild($doc->createTextNode($row['name']));
 | 
						|
                $classDiv->appendChild($h3);
 | 
						|
                $h5 = $doc->createElement('h5');
 | 
						|
                $h5->appendChild($doc->createTextNode("Cost: " . money_format('%i', $row['cost'])));
 | 
						|
                $classDiv->appendChild($h5);
 | 
						|
                $h5 = $doc->createElement('h5');
 | 
						|
                $h5->appendChild($doc->createTextNode("Starting at: " . $row['start_datetime']));
 | 
						|
                $classDiv->appendChild($h5);
 | 
						|
                $p = $doc->createElement('p');
 | 
						|
                $p->appendChild($doc->createTextNode($row['description']));
 | 
						|
                $classDiv->appendChild($p);
 | 
						|
                /*
 | 
						|
                 * Register, deregister?
 | 
						|
                 */
 | 
						|
                
 | 
						|
                $form = createForm($doc, "classes.php");
 | 
						|
                $input = createHiddenInput($doc, 'class_id', (string)$row['id']);
 | 
						|
  /*              $input = $doc->createElement('input');
 | 
						|
                $input->setAttribute('type', 'hidden');
 | 
						|
                $input->setAttribute('name', 'class_id');
 | 
						|
                $input->setAttribute('value', $row['id']); */
 | 
						|
                $form->appendChild($input);
 | 
						|
                
 | 
						|
                $status = returnMemberStatusForClass($classID, $_SESSION['MemberID']);
 | 
						|
                
 | 
						|
                if ($status === "Confirmed" || $status === "Registered")
 | 
						|
                {
 | 
						|
                  $input = createSubmitInput($doc, 'withdraw', $text0020);
 | 
						|
  /*                $input = $doc->createElement('input');
 | 
						|
                  $input->setAttribute('type', 'submit');
 | 
						|
                  $input->setAttribute('name', 'withdraw');
 | 
						|
                  $input->setAttribute('value', 'Withdraw');*/
 | 
						|
                  $form->appendChild($input);
 | 
						|
                }
 | 
						|
                else
 | 
						|
                {
 | 
						|
                  $input = createSubmitInput($doc, 'register', $text0021);
 | 
						|
  /*                $input = $doc->createElement('input');
 | 
						|
                  $input->setAttribute('type', 'submit');
 | 
						|
                  $input->setAttribute('name', 'register');
 | 
						|
                  $input->setAttribute('value', 'Register'); */
 | 
						|
                  $form->appendChild($input);
 | 
						|
                }
 | 
						|
                $classDiv->appendChild($form);
 | 
						|
              }
 | 
						|
            }
 | 
						|
            if ($count == 1)
 | 
						|
              $body->appendChild($classDiv);
 | 
						|
            else
 | 
						|
              $body->appendChild(generateTrainingTable($doc, 'classes.php'));
 | 
						|
          }
 | 
						|
          else
 | 
						|
            if (isset($_GET['course_id']))
 | 
						|
            {
 | 
						|
              /*
 | 
						|
               * Get with no class_id, display table
 | 
						|
               */
 | 
						|
              
 | 
						|
              $courseID = (int) cleanInput($_GET['course_id']);
 | 
						|
              $courseDiv = createDiv($doc, 'FloatLeft50Div');
 | 
						|
              
 | 
						|
              $dbh = returnDatabaseHandel();
 | 
						|
              $sth = $dbh->prepare($statement289);
 | 
						|
              if ($sth->execute(array($courseID)))
 | 
						|
              {
 | 
						|
                $count = 0;
 | 
						|
                while ($row = $sth->fetch(PDO::FETCH_ASSOC))
 | 
						|
                {
 | 
						|
                  $count++;
 | 
						|
                  //print ("bonk");
 | 
						|
                  
 | 
						|
                  $h3 = $doc->createElement('h3');
 | 
						|
                  $h3->appendChild($doc->createTextNode("Course ID: " . $row['id']));
 | 
						|
                  $courseDiv->appendChild($h3);
 | 
						|
                  //$body->appendChild(generateTrainingTable($doc, 'classes.php'));
 | 
						|
 | 
						|
                  $h3 = $doc->createElement('h3');
 | 
						|
                  $h3->appendChild($doc->createTextNode("Course Title: " . $row['name']));
 | 
						|
                  $courseDiv->appendChild($h3);
 | 
						|
                  
 | 
						|
                  $h3 = $doc->createElement('h3');
 | 
						|
                  $h3->appendChild($doc->createTextNode("Course Description: " . $row['description']));
 | 
						|
                  $courseDiv->appendChild($h3);
 | 
						|
                  
 | 
						|
                  
 | 
						|
                }
 | 
						|
              }
 | 
						|
              $body->appendChild($courseDiv);
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
              /*
 | 
						|
               * Get with no class_id, display table
 | 
						|
               */
 | 
						|
              $body->appendChild(generateTrainingTable($doc, 'classes.php'));
 | 
						|
            }
 | 
						|
            
 | 
						|
        }
 | 
						|
        catch (Exception $e)
 | 
						|
        {
 | 
						|
          $body->appendChild(generateTrainingTable($doc, 'classes.php'));
 | 
						|
        }
 | 
						|
      }
 | 
						|
      
 | 
						|
    $body->appendChild(generateFooter($doc));
 | 
						|
    if ($prettyPretty)
 | 
						|
      $doc->formatOutput = true;
 | 
						|
    echo $doc->saveXML();
 | 
						|
  }
 | 
						|
 | 
						|
 | 
						|
  
 | 
						|
?>
 |