require_once 'bus.php'; //bus class required require_once 'connection.php'; //connect to db require_once 'busTableGateway.php'; //for connection to bus tabkl //start_session(); // //if (!is_logged_in()){ // header("Location: login_form.php"); //} // //$user = $_SESSION['user']; $connection = Connection::getInstance(); //connect to db $gateway = new busTableGateway($connection); //connect ot the bus table using that connection $statement = $gateway->getBuses(); //select all buses from the bus table // //echo "Connected to the database"; ?> <!DOCTYPE html> <html> <head> <title>View all Buses</title> <!--all styles and scripts will be contained in these php scripts--> <?php require 'utilities/styles.php'; ?>
validate($formdata, $errors); //function to validate the formdata // // echo '<pre>'; // print_r($errors); // print_r($formdata); // echo "</pre>"; if (empty($errors)) { // if the errors arry is empty create the bus objct //set varibles to formdata of the respective fields $reg_num = $formdata["regNum"]; $bus_make = $formdata["make"]; $bus_model = $formdata["model"]; $engine = $formdata["engine"]; $bus_id; $bought_date = $formdata["boughtDate"]; $next_service = $formdata['service']; $garage_id = $formdata['gID']; $bus = new Bus($bus_id, $reg_num, $bus_make, $bus_model, $engine, $bought_date, $next_service, $garage_id); $connection = Connection::getInstance(); //get an instance of the connection $gateway = new busTableGateway($connection); //connect to the bus table gateway using the conneciton $id = $gateway->insertBus($bus); //insert the bus object //Redirects the user to the specific page header('Location: viewallbus.php'); exit; } else { require "addbusform.php"; }
<?php /** * Created by IntelliJ IDEA. * User: rorypb * Date: 08/12/2015 * Time: 11:57 AM */ require_once 'Garage.php'; //require the garage class require_once 'Connection.php'; //require the conneciton class require_once 'busTableGateway.php'; //require the bus table gateway if (!isset($_GET['id'])) { //if the id does not match to a valid bus id die("Invalid Bus ID"); // die and output the error } $id = $_GET['id']; //get the id from the form $connection = Connection::getInstance(); //get an instance of the connection $gateway = new busTableGateway($connection); //connect to the bus table $gateway->removeBus($id); //use the remove bus method by passing in the valid id header("Location: viewallbus.php"); //redirect the user back to the view all bus page
<?php require_once 'bustablegateway.php'; require_once 'dbconnection.php'; //If the page is accessed without an id in the get array, die if (!isset($_GET['id'])) { die("Illegal Request"); } $id = $_GET['id']; //establish db connection $dbconnection = dbconnection::getConnection(); //conect to database via gateway using the connection $gateway = new busTableGateway($dbconnection); //execute the delete bus function passing in the id $gateway->deleteBus($id); //redirect user to viewall buses on deletion header('Location: viewallbuses.php');
require_once 'garageTableGateway.php'; //connecting to garage tbal require_once 'busTableGateway.php'; //connection to bus tbale if (!isset($_GET['id'])) { //oif the id is not one from the db die("Halt"); //die } $id = $_GET['id']; //get the id from the databae $connection = Connection::getInstance(); //connect to the db $garageGateway = new garageTableGateway($connection); //connect to the garage table $busGateway = new busTableGateway($connection); //connect to the bus table $garages = $garageGateway->getGarageByGarageId($id); //garage table get garageby id $buses = $busGateway->getBusByID($id); //bus table get bus by id //used in conjunction to view the garage that hioues that bus //$row = $statement->fetch(PDO::FETCH_ASSOC); //if (!$row) { // die("Unable to get Bus By ID"); //} ?> <!DOCTYPE html> <html>
header("Location: login_form.php"); } $formdata = array(); $errors = array(); //validate the data entered using the validate function in the validateBus.php file validate($formdata, $errors); //if the validation is passed (errors array empty) set each variable to the valuye of the coresponding variable in the formdata array if (empty($errors)) { $id = $_POST['id']; $reg = $formdata['reg']; $make = $formdata['make']; $model = $formdata['model']; $capacity = $formdata['capacity']; $engineSize = $formdata['engineSize']; $purchaseDate = $formdata['purchaseDate']; $serviceDate = $formdata['serviceDate']; $gid = $formdata['gid']; //make a new bus object with the data above, set id to -1 becasue it is ai in database $bus = new Bus($id, $reg, $make, $model, $capacity, $engineSize, $purchaseDate, $serviceDate, $gid); //initialize db connection $dbconnection = dbconnection::getConnection(); //connect to the bus table through busTableGateway using the connection above $gateway = new busTableGateway($dbconnection); //execute the update function in the bustablegateway using the object created above $id = $gateway->updateBus($bus); //when completed redirect user to viewall header('Location: viewallbuses.php'); } else { //if an error occurs redisplay the edit form require 'editBusForm.php'; }
require_once 'validateBus.php'; require_once 'loginhelper.php'; require_once 'garagesTableGateway.php'; start_session(); //if user is not logged in, return to log in form if (!is_logged_in()) { header("Location: loginform.php"); } $user = $_SESSION['user']; if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (!isset($_GET['id'])) { die("Illegal Request"); } $id = $_GET['id']; $dbconnection = dbconnection::getConnection(); $gateway = new busTableGateway($dbconnection); $statement = $gateway->getBusById($id); $garageGateway = new garageTableGateway($dbconnection); $garages = $garageGateway->getGarage(); $row = $statement->fetch(PDO::FETCH_ASSOC); if (!$row) { die("Illegal Request"); } } else { if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!isset($_POST['id'])) { die("Illegal request"); } $id = $_POST['id']; $dbconnection = dbconnection::getConnection(); $garageGateway = new garageTableGateway($dbconnection);
require_once 'connection.php'; //connect to db require_once 'garageTableGateway.php'; //connect to garagetable require_once 'busTableGateway.php'; //connect to bus tbale //if (!isset($_GET['id'])) { // die("Halt"); //} $id = $_GET['id']; //id has to be valid $connection = Connection::getInstance(); //conenct to the db $garageGateway = new garageTableGateway($connection); //for conenction to garage table $busGateway = new busTableGateway($connection); //for connection to bus table $garages = $garageGateway->getGarageById($id); //get garagebyid form garages $bus = $busGateway->getBusByGarageId($id); //get busbygarageid from bus //the garage selected will show all buses that is stored by that garage //$row = $statement->fetch(PDO::FETCH_ASSOC); //if (!$row) { // die("Unable to get Garage By ID"); //} ?> <!DOCTYPE html> <html>