-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_employee.php
More file actions
155 lines (127 loc) · 5.17 KB
/
edit_employee.php
File metadata and controls
155 lines (127 loc) · 5.17 KB
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
146
147
148
149
150
151
152
153
154
155
<?php
session_start(); // Start the session.
// If no session value is present, redirect the user:
if (!isset($_SESSION['employee_id'])) {
require_once ('includes/login_functions.inc.php');
$url = absolute_url('login.php');
header("Location: $url");
exit();
}
$page_title = 'Edit a User';
include ('includes/header.html');
echo '<div id="content">
<div class="container">
<div class="inside">
<!-- box begin -->
<div class="box alt">
<div class="left-top-corner">
<div class="right-top-corner">
<div class="border-top"></div>
</div>
</div>
<div class="border-left">
<div class="border-right">
<div class="inner">
<div class="wrapper">
<h3>Edit Employees</h3>';
// Check for a valid user ID, through GET or POST:
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) {
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission.
$id = $_POST['id'];
} else { // No valid ID, kill the script.
echo '<p class="error">This page has been accessed in error.</p>';
include ('includes/footer.html');
exit();
}
require_once ('../mysqli_connect.php');
// Check if the form has been submitted:
if (isset($_POST['submitted'])) {
$errors = array();
// Check for a first name:
if (empty($_POST['first_name'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['first_name']));
}
// Check for a last name:
if (empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = mysqli_real_escape_string($dbc, trim($_POST['last_name']));
}
// Check for an email address:
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = mysqli_real_escape_string($dbc, trim($_POST['email']));
}
if (empty($errors)) { // If everything's OK.
// Test for unique email address:
$q = "SELECT employee_id FROM employees WHERE email='$e' AND employee_id != $id";
$r = @mysqli_query($dbc, $q);
if (mysqli_num_rows($r) == 0) {
// Make the query:
$q = "UPDATE contactus SET first_name='$fn', last_name='$ln', email='$e', pass=SHA1('$p') WHERE employee_id=$id LIMIT 1";
$r = @mysqli_query ($dbc, $q);
if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
// Print a message:
echo '<p>The employee has been edited.</p>';
} else { // If it did not run OK.
echo '<p class="error">The user could not be edited due to a system error. We apologize for any inconvenience.</p>'; // Public message.
echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.
}
} else { // Already registered.
echo '<p class="error">The email address has already been registered.</p>';
}
} else { // Report the errors.
echo '<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p>';
} // End of if (empty($errors)) IF.
} // End of submit conditional.
// Always show the form...
// Retrieve the user's information:
$q = "SELECT first_name, last_name, email, pass FROM employees WHERE employee_id=$id";
$r = @mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form.
// Get the user's information:
$row = mysqli_fetch_array ($r, MYSQLI_ASSOC);
//pass=SHA1('$p')
// Create the form:
echo '<form action="edit_employee.php" method="post">
<p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="' . $row['first_name'] . '" /></p>
<p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="' . $row['last_name'] . '" /></p>
<p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="' . $row['email'] . '" /> </p>
<p>Password: <input type="password" name="pass" size="20" maxlength="40" value="' . $row['pass'] . '" /> </p>
<p> <a href="employees.php"> Return to all employees
</a> * <a href="delete_employeee.php?id=' . $row['employee_id'] . '">Delete</a> *
<a href="logout.php"> LogOut </a></p>
<p><input type="submit" name="submit" value="update" /></p>
<input type="hidden" name="submitted" value="TRUE" />
<input type="hidden" name="id" value="' . $id . '" />
</form>';
} else { // Not a valid user ID.
echo '<p class="error">This page has been accessed in error.</p>';
}
mysqli_close($dbc);
echo ' <dl class="special fright">
</div>
</div>
</div>
</div>
<div class="left-bot-corner">
<div class="right-bot-corner">
<div class="border-bot"></div>
</div>
</div>
</div>
<!-- box end -->
<!--Recent articles list ends -->
</div>
</div>
</div>';
include ('includes/footer.html');
?>