@@ -17,6 +17,7 @@ public function __construct(){
17
17
$ this ->login ();
18
18
$ this ->register ();
19
19
$ this ->logout ();
20
+ $ this ->remove ();
20
21
21
22
}
22
23
@@ -67,11 +68,80 @@ public function login(){
67
68
}
68
69
}
69
70
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
+
70
114
public function logout (){
71
115
if (isset ($ _GET ['action ' ]) && $ _GET ['action ' ] == 'logout ' ){
72
116
session_destroy ();
73
117
header ("Location: index.php " );
74
118
}
75
119
}
76
120
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
+
77
147
}
0 commit comments