Skip to content

Commit 0d5cfde

Browse files
committedApr 19, 2014
Added methods to edit user
-List all users -Remove user -Fetch data user -Edit user
1 parent a51d55e commit 0d5cfde

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
 

Diff for: ‎admin/include/user.class.php

+70
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function __construct(){
1717
$this->login();
1818
$this->register();
1919
$this->logout();
20+
$this->remove();
2021

2122
}
2223

@@ -67,11 +68,80 @@ public function login(){
6768
}
6869
}
6970

71+
public static function manage_list(){
72+
global $mysqli;
73+
74+
$query = "SELECT id, username, fullname, registered FROM users";
75+
$result = $mysqli->query($query);
76+
77+
echo '<table border="1" class="manage-article">';
78+
echo '<thead>';
79+
echo '<tr>';
80+
echo '<th>ID</th>';
81+
echo '<th>Username</th>';
82+
echo '<th>Full name</th>';
83+
echo '<th>Registered</th>';
84+
echo '<th>Actions</th>';
85+
echo '</tr>';
86+
echo '</thead>';
87+
echo '<tbody>';
88+
while($row = $result->fetch_assoc()){
89+
echo '<tr>';
90+
echo '<td>' . $row['id'] . '</td>';
91+
echo '<td>' . $row['username'] . '</td>';
92+
echo '<td>' . $row['fullname'] . '</td>';
93+
echo '<td>' . $row['registered'] . '</td>';
94+
echo '<td>
95+
<a href="edit-user.php?user=edit&id='.$row['id'].'">Edit</a>
96+
<a href="manage-user.php?user=remove&id='.$row['id'].'">Delete</a>
97+
</td>';
98+
echo '</tr>';
99+
}
100+
echo '</tbody>';
101+
echo '</table>';
102+
}
103+
104+
public static function remove(){
105+
if(isset($_GET['user']) && $_GET['user'] == 'remove'){
106+
global $mysqli;
107+
108+
$query = "DELETE FROM users WHERE id='".$_GET['id']."'";
109+
$mysqli->query($query);
110+
header("Location: manage-user.php");
111+
}
112+
}
113+
70114
public function logout(){
71115
if(isset($_GET['action']) && $_GET['action'] == 'logout'){
72116
session_destroy();
73117
header("Location: index.php");
74118
}
75119
}
76120

121+
public static function edit_fetch(){
122+
if(isset($_GET['user']) && $_GET['user'] == 'edit'){
123+
global $mysqli;
124+
125+
$query = "SELECT id, username, fullname, email, access FROM users WHERE id='".$_GET['id']."'";
126+
$result = $mysqli->query($query);
127+
return $result->fetch_assoc();
128+
}
129+
}
130+
131+
public static function edit(){
132+
if(isset($_GET['user']) && $_GET['user'] == 'edit_save'){
133+
global $mysqli;
134+
135+
$id = $_POST['id'];
136+
$username = $_POST['username'];
137+
$email = $_POST['email'];
138+
$fullname = $_POST['fullname'];
139+
$access = $_POST['access'];
140+
141+
$query = "UPDATE users SET username='".$username."', email='".$email."', fullname='".$fullname."', access='".$access."' WHERE id='".$id."'";
142+
$mysqli->query($query);
143+
header("Location: manage-user.php");
144+
}
145+
}
146+
77147
}

0 commit comments

Comments
 (0)
Please sign in to comment.