-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_admin.php
145 lines (118 loc) · 5.46 KB
/
edit_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
138
139
140
141
142
143
144
145
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/db_connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/validation_functions.php"); ?>
<?php
confirm_logged_in();
?>
<?php
$admin = find_admin_by_id($_GET["id"]);
if (!$admin) {
// admin ID was missing or invalid or
// admin couldn't be found in database
redirect_to("admin.php");
}
?>
<?php
if (isset($_POST['submit'])) {
// Process the form
if (empty($errors)) {
// Perform Update
$id = $admin["id"];
$firstname = mysql_prep($_POST["firstname"]);
$lastname = mysql_prep($_POST["lastname"]);
$phone = mysql_prep($_POST["phone"]);
$username = mysql_prep($_POST["username"]);
$hashed_password = password_encrypt($_POST["hashed_password"]);
$query = "UPDATE admins SET ";
$query .= "firstname = '{$firstname}', ";
$query .= "lastname = '{$lastname}', ";
$query .= "phone = '{$phone}', ";
$query .= "username = '{$username}', ";
$query .= "hashed_password = '{$hashed_password}' ";
$query .= "WHERE id = {$id} ";
$query .= "LIMIT 1";
$result = mysqli_query($connection, $query);
if ($result && mysqli_affected_rows($connection) == 1) {
// Success
$_SESSION["message"] = "Admin updated.";
redirect_to("admin.php");
} else {
// Failure
$_SESSION["message"] = "Admin update failed.";
// redirect_to("index.php");
}
}
} else {
}
?>
<!DOCTYPE>
<html>
<head>
<title>Edit Account</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
<link rel="stylesheet" href="_/css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="_/css/free.css" type="text/css" />
<link href='https://fonts.googleapis.com/css?family=Bree+Serif|Merriweather:400,300,300italic,700,700italic,400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/font-awesome.min.css">
</head>
<body>
<header>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#featured"><h1 style="color:#337ab7">Clinic <span class="subhead">Matters</span></h1></a>
</div><!-- navbar-header -->
<div class="collapse navbar-collapse" id="collapse">
<ul class="nav navbar-nav navbar-right">
<li ><a href="logout.php">Logout</a></li>
</ul>
</div><!-- collapse navbar-collapse -->
</div><!-- container -->
</nav>
</header>
<h1 class="page-header">Edit Admin:<?php echo htmlentities($admin["username"]); ?></h1>
<?php echo message(); ?>
<?php echo form_errors($errors); ?>
<form class="form" action="edit_admin.php?id=<?php echo urlencode($admin["id"]); ?>" method="post" id="registrationForm">
<div class="form-group">
<div class="col-xs-6">
<label for="first_name"><h4>First name</h4></label>
<input class="form-control" name="firstname" id="firstname" placeholder="first name" value="<?php echo htmlentities($admin["firstname"]); ?>" title="enter your first name if any." type="text">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="last_name"><h4>Last name</h4></label>
<input class="form-control" name="lastname" id="lastname" placeholder="last name" value="<?php echo htmlentities($admin["lastname"]); ?>" title="enter your last name if any." type="text">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="phone"><h4>Phone</h4></label>
<input class="form-control" name="phone" id="phone" placeholder="23480xxxxxxxx" value="<?php echo htmlentities($admin["phone"]); ?>" title="enter your phone number if any." type="text">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="username"><h4>Username</h4></label>
<input class="form-control" name="username" id="username" placeholder="[email protected]" value="<?php echo htmlentities($admin["username"]); ?>" title="user" type="text">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="password"><h4>Password</h4></label>
<input class="form-control" name="hashed_password" id="hashed_password" placeholder="password" title="enter your password." type="password">
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<br>
<button type="submit" name="submit" class="btn btn-primary">Edit Admin</button><br><br>
<a href="admin.php">Go back</a>
</div>
</div>
</form>
</div>
</body>
</html>