diff --git a/TODO b/TODO index fcd4028..8b99dd7 100755 --- a/TODO +++ b/TODO @@ -1,8 +1,16 @@ * i18n * Vérification des variables dans les classes + throw exception * tokens + ban system +* remember me +* Display names 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) +* Edit user +* Create user diff --git a/inc/User.class.php b/inc/User.class.php index cc3d727..801ffdc 100644 --- a/inc/User.class.php +++ b/inc/User.class.php @@ -70,7 +70,7 @@ class User extends Storage { return serialize(array('id'=>$this->id, 'login'=>$this->login, 'password'=>$this->password, 'admin'=>$this->admin)); } - public function sessionRestore($data, $serialized) { + public function sessionRestore($data, $serialized = false) { if($serialized) $user_data = unserialize($serialized_data); else @@ -81,4 +81,31 @@ class User extends Storage { $this->setPassword($user_data['password']); $this->setAdmin($user_data['admin']); } + + public function load_users() { + $return = array(); + $users = $this->load(); + + foreach($users as $user) { + $return[0] = new User(); + $return[0]->sessionRestore($user); + } + return $return; + } + + public function load_user($fields = NULL) { + $fetch = $this->load($fields); + + if(count($fetch) > 0) { + $this->setId($fetch[0]['id']); + $this->setLogin($fetch[0]['login']); + $this->setPassword($fetch[0]['password']); + $this->setAdmin($fetch[0]['admin']); + + return true; + } + else { + return false; + } + } } diff --git a/index.php b/index.php index 6af54a0..88ddca5 100644 --- a/index.php +++ b/index.php @@ -68,11 +68,42 @@ $tpl->assign('error', 'The content of the two password fields doesn\'t match.'); } } + $tpl->assign('view', 'password'); $tpl->draw('edit_users'); break; + case 'edit_users': + case 'add_user': + if(!$current_user['admin']) { + header('location: index.php'); + } + + if(!empty($_GET['user_id']) || $_GET['do'] == 'add_user') { + if(!empty($_GET['user_id'])) { + $user_id = (int) $_GET['user_id']; + $user = new User(); + $user->load_user(array('id'=>$user_id)); + $tpl->assign('user_data', $user); + } + $tpl->assign('user_id', (!empty($user_id) ? $user_id : -1)); + $tpl->assign('view', 'edit_user'); + } + else { + $users_list = new User(); + $users_list = $users_list->load_users(); + $tpl->assign('users', $users_list); + $tpl->assign('view', 'list_users'); + } + $tpl->draw('edit_users'); + break; + + case 'delete_user': + break; + default: - $tpl->assign('users', array(0=>array("name"=>"truc"))); + $users_list = new User(); + $users_list = $users_list->load_users(); + $tpl->assign('users', $users_list); $tpl->assign('bill', array(0=>array())); $tpl->draw('index'); break; diff --git a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php index ddedea3..4452ac4 100644 --- a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php +++ b/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php @@ -9,14 +9,14 @@
{$error}
{/if} +{if condition="$view == 'list_users'"} +You can also add a user.
+Id | +Login | +Is admin ? | +Edit | +Delete | +
---|---|---|---|---|
{$value->getId()} | +{$value->getLogin()} | +{$value->getAdmin() ? "Yes" : "No"} | +Edit | +Delete | +