Added deletion of user ability

This commit is contained in:
Phyks 2013-08-11 22:34:39 +02:00
parent 4beabd5df3
commit 7226890aa1
3 changed files with 25 additions and 5 deletions

4
TODO
View File

@ -9,7 +9,3 @@ install.php :
=============
* Link beside password field to toggle visible / not visible
* TRUNCATE before CREATE TABLE in install.php
index.php :
===========
* Delete user (+ check if not you)

View File

@ -165,4 +165,27 @@ class Storage {
$this->id = (!isset($this->id) ? $this->connection->lastInsertId() : $this->id);
}
public function delete() {
$query = 'DELETE FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' WHERE ';
$i = false;
foreach($this->fields as $field=>$type) {
if(!empty($this->$field)) {
if($i) { $query .= ' AND '; } else { $i = true; }
$query .= $field.'=:'.$field;
}
}
$query = $this->connection->prepare($query);
foreach($this->fields as $field=>$type) {
if(!empty($this->$field)) {
$query->bindParam(':'.$field, $this->$field);
}
}
$query->execute();
}
}

View File

@ -127,9 +127,10 @@
case 'delete_user':
if($_GET['user_id'] != $current_user->getId()) {
$user = new User();
$user->setId($_GET['user_id']);
$user->delete();
header('location: index.php');
header('location: index.php?do=edit_users');
exit();
}
break;