-
Notifications
You must be signed in to change notification settings - Fork 0
/
createBranch.php
executable file
·60 lines (51 loc) · 2 KB
/
createBranch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/*
* This file is used to take information from a form and create a branch object
* when the object is created it is added to the database using the BranchTableGateway.php
*/
//files used by this page
require_once 'utils/functions.php';
require_once 'classes/User.php';
require_once 'classes/Branch.php';
require_once 'classes/DB.php';
require_once 'classes/BranchTableGateway.php';
require_once 'validateBranch.php';
start_session();
/*redirects to login if the user is not logged in or if is a hr of customer
as they have no access to this page
*/
if (!is_logged_in() || $_SESSION['role'] === 'hr' || $_SESSION['role'] === 'customer')
{
//loads log on screen
header("Location: login_form.php");
}
//calls the validate function passing in the formadata and errors array
//validate prevents the application moving forward untill the validate citria is meet
validate($formdata, $errors);
if (empty($errors))
{
//sets object properties used to set a branch
$brName = $formdata['name'];
$brAddress = $formdata['address'];
$bropenDate = $formdata['openDate'];
$brPhone = $formdata['phone'];
$brHours = $formdata['opening'];
//cretaes a branch object
$branch = new Branch( -1, $brName, $brAddress, $brPhone, $brHours, $bropenDate);
//creates a connection
$connection = Connection::getInstance();
//uses connection in BranchTableGateway
$gateway = new BranchTableGateway($connection);
//print_r($branch);
//sets the branch no to the return from the new branch created
$branchNo = $gateway->newBranch($branch);
//returns to the home page
//print_r($branchNo);
//returns to the view all branches
header('Location: viewAllBranches.php');
}
else
{
//if any issues remains on this page
require 'createBranchForm.php';
}