-
Notifications
You must be signed in to change notification settings - Fork 0
/
editCustomer.php
executable file
·68 lines (56 loc) · 1.93 KB
/
editCustomer.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
61
62
63
64
65
66
67
<?php
/*
* This is used to edit a customer on the database
*/
require_once 'utils/functions.php';
require_once 'classes/User.php';
require_once 'classes/DB.php';
require_once 'classes/CustomerTableGateway.php';
require_once 'validateCustomerEdit.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')
{
//loads log on screen
header("Location: login_form.php");
}
//uses the validate function from validateCustomer
validate($formdata, $errors);
//checks for form errors
if (empty($errors))
{
//gets new values to be updated
$customerNo = $formdata['customerNo'];
$branchNo = $formdata['branchNo'];
$fName = $formdata['fName'];
$lName = $formdata['lName'];
$address = $formdata['address'];
$gender = $formdata['gender'];
$mobileNo = $formdata['mobileNo'];
$email = $formdata['email'];
//creates a branch object with the new values
$cust= new Customer($customerNo, $branchNo, $fName, $lName, $address, $gender, $mobileNo, $email);
//print_r($branch);
$connection = Connection::getInstance();
$gateway = new CustomerTableGateway($connection);
//print_r($gateway);
//uses the customer number to update from the database
$customerNo = $gateway->updateCustomer($cust);
//customer redirect on complete
if($_SESSION['role'] === 'customer')
{
header('Location: myAccount.php');
}
//staff redirect on complete
else
{
header('Location: viewAllCustomers.php');
}
}
else
{
//if errors stay on this page
require 'editCustomerForm.php';
}