-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathuser_approve.php
127 lines (116 loc) · 4.67 KB
/
user_approve.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
<?php
// Start from getting the hader which contains some settings we need
require_once 'includes/headx.php';
// require the admins class which containes most functions applied to admins
require_once "includes/classes/admin-class.php";
$admins = new Admins($dbh);
// check if the form is submitted
$page = isset($_GET[ 'p' ])?$_GET[ 'p' ]:'';
if($page == 'add'){
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
$fullname = $_POST['fullname'];
$address = $_POST['address'];
$contact = $_POST['contact'];
if (isset($_POST))
{
$errors = array();
// Check if password are the same
if (!$admins->ArePasswordSame($_POST['password'], $_POST['repassword']))
{
session::set('errors', ['The two passwords do not match.']);
}elseif ($admins->adminExists($_POST['username'])) {
session::set('errors', ['This username is already in use by another admin.']);
}elseif (!$admins->addNewAdmin($username, $password, $email, $fullname, $address, $contact)) {
session::set('errors', ['An error occured while saving the new admin.']);
}else{
session::set('confirm', 'New admin added successfully!');
unset($_POST['repassword']);
}
}
}else if($page == 'del'){
$id = $_POST['id'];
if (!$admins->deleteUser($id))
{
echo "Sorry Data could not be deleted !";
}else {
echo "Well! You've successfully deleted a product!";
}
}else if($page == 'edit'){
$username = $_POST['username'];
$email = $_POST['email'];
$full_name = $_POST['full_name'];
$address = $_POST['address'];
$contact = $_POST['contact'];
$user_id = $_POST['user_id'];
if (!$admins->updateAdmin($user_id, $username, $email, $full_name, $address, $contact))
{
//echo "$user_id $username $email $full_name $address $contact";
echo "Sorry Data could not be Updated !";
}else {
$commons->redirectTo(SITE_PATH.'user.php');
}
}else{
$users = $admins->fetchAdmin();
if (isset($users) && sizeof($users) > 0) {
foreach ($users as $user){ ?>
<tr>
<td scope="row"><?=$user->user_id ?></td>
<td>
<button type="button" id="edit" class="btn btn-success btn-sm" data-toggle="modal" data-target="#edit-<?=$user->user_id?>">EDIT</button>
<div class="fade modal" id="edit-<?=$user->user_id?>">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4>Edit Details</h4>
</div>
<form method="POST">
<div class="modal-body">
<!-- The async form to send and replace the modals content with its response -->
<!-- form content -->
<input type="hidden" id="<?=$user->user_id ?>" value="<?=$user->user_id?>">
<div class="form-group has-success">
<label for="name">Full Name</label>
<input type="text" class="form-control" id="fnm-<?=$user->user_id?>" value="<?=$user->full_name?>" required>
</div>
<div class="form-group">
<label for="Username">Username</label>
<input type="text" class="form-control" id="usr-<?=$user->user_id?>" value="<?=$user->user_name?>" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" id="em-<?=$user->user_id?>" value="<?=$user->email?>" required>
</div>
<div class="form-group">
<label for="details">Address</label>
<input type="text" class="form-control" id="ad-<?=$user->user_id?>" value="<?=$user->address?>" required>
</div>
<div class="form-group">
<label for="contact">Contact</label>
<input type="text" class="form-control" id="con-<?=$user->user_id?>" value="<?=$user->contact?>" required>
</div>
</div>
<div class="modal-footer">
<button type="submit" onclick="updateData(<?=$user->user_id?>)" class="btn btn-primary">Update</button>
<a href="#" class="btn btn-warning" data-dismiss="modal">Cancel</a>
</div>
</form>
</div>
</div>
</div>
<button type="submit" id="delete" onclick="delData(<?=$user->user_id ?>)" class="btn btn-warning btn-sm disabled">DELETE</button>
</td>
<td class="search"><?=$user->user_name?></td>
<td class="search"><?=$user->full_name?></td>
<td class="search"><?=$user->email?></td>
<td class="search"><?=$user->contact?></td>
<td class="search"><?=$user->address?></td>
</tr>
<?php
}
}
}
?>