forked from jonathanirvings/AutoResto
/
customer_new_admin.php
137 lines (123 loc) · 4.95 KB
/
customer_new_admin.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<html>
<head>
<title>AutoResto - Create New Admin</title>
<?php
include "htmlHeaderLogin.php";
?>
<script>
$(document).ready(function() {
$("#datepicker").datepicker({
dateFormat: 'yy-mm-dd'
});
})
</script>
</head>
<body class="homepage">
<?php
include "headerPage.php";
global $eventHandler;
global $customer_is_admin;
$ic_number = $_SESSION["ic_number"];
$customer_details = $eventHandler->getCustomerDetails($ic_number);
if($customer_details[$customer_is_admin] == 0){
echo "<script>
window.location.href = \"no_permission.php\";
</script>";
}
?>
<script>$(".manage_account").addClass("active")</script>
<?php
$ic_number = "";
$name = "";
$email = "";
$contact_no = "";
$password = "";
$password_confirm = "";
function checkContactNo($contact_no) {
for ($i = 0; $i < strlen($contact_no); ++$i) {
if ($contact_no[$i] < '0' || $contact_no[$i] > '9') {
?><script>
alert("Contact Number must only consist of numbers");
</script><?php
return false;
}
}
return true;
}
function checkPassword($password,$password_confirm) {
if ($password != $password_confirm) {
?><script>
alert("Password does not match");
</script><?php
return false;
}
return true;
}
function addUser() {
global $eventHandler;
$ic_number = $_POST["ic_number"];
$name = $_POST["name"];
$email = $_POST["email"];
$contact_no = $_POST["contact_no"];
$password = $_POST["password"];
$password_confirm = $_POST["password_confirm"];
if (!checkPassword($password,$password_confirm)) {
return false;
}
if (!checkContactNo($contact_no)) {
return false;
}
$newArray = array();
$newArray["ic_no"] = $ic_number;
$newArray["name"] = $name;
$newArray["email"] = $email;
$newArray["contact_no"] = $contact_no;
$newArray["password"] = $password;
$newArray["active"] = 1;
$newArray["isAdmin"] = 1;
$error_message = $eventHandler->addCustomer($newArray);
?><script>
alert("<?php echo $error_message; ?>");
window.location.href = "index.php";
</script><?php
return true;
}
if (isset($_POST["hidden_add"])) {
addUser();
}
?>
<!-- Main -->
<div id="page">
<div class="container">
<div class="row">
<div class="15u">
<section>
<header>
<span class="byline">Admin Sign Up</span>
</header>
<div id="bookingoptions" class="container">
<form method="post" action="">
<input type="hidden" name="hidden_add" value=true>
<h3>IC Number</h3>
<h3><input type="text" id="ic_number" name="ic_number" size="20" value="<?php echo $ic_number;?>"/></h3>
<h3>Name</h3>
<h3><input type="text" id="name" name="name" size="20" value="<?php echo $name;?>"/></h3>
<h3>Email</h3>
<h3><input type="text" id="email" name="email" size="20" value="<?php echo $email;?>"/></h3>
<h3>Contact Number</h3>
<h3><input type="text" id="contact_no" name="contact_no" size="20" value="<?php echo $contact_no;?>"/></h3>
<h3>Password</h3>
<h3><input type="password" id="password" name="password" size="20" value="<?php echo $password;?>"/></h3>
<h3>Confirm Password</h3>
<h3><input type="password" id="password_confirm" name="password_confirm" size="20" value="<?php echo $password_confirm;?>"/></h3>
<input type="submit" name="save" id="save" class="button" value="Sign Up"/>
</form>
</div>
</section>
</div>
</div>
</div>
<!-- Main -->
</div>
</body>
</html>