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 @@ Owes\To $value1 ){ $counter1++; ?> - + getLogin();?> $value1 ){ $counter1++; ?> - + getLogin();?> diff --git a/tpl/css/style.css b/tpl/css/style.css index 0dfcb94..bb4185c 100644 --- a/tpl/css/style.css +++ b/tpl/css/style.css @@ -72,11 +72,15 @@ input[type=submit] { text-align: center } -#edit_password_form { +#edit_password_form, #edit_user_form { width: 50%; margin-left: 15%; } +#edit_user_admin_rights { + text-align: center; +} + #install { margin: 0; } diff --git a/tpl/edit_users.html b/tpl/edit_users.html index 6955660..3d255ea 100644 --- a/tpl/edit_users.html +++ b/tpl/edit_users.html @@ -4,9 +4,54 @@

{$error}

{/if} +{if condition="$view == 'list_users'"} +

List of users

+

You can also add a user.

+ + + + + + + + + {loop="users"} + + + + + + + + {/loop} +
IdLoginIs admin ?EditDelete
{$value->getId()}{$value->getLogin()}{$value->getAdmin() ? "Yes" : "No"}EditDelete
+{elseif condition="$view == 'edit_user'"} +

Edit a user

+
+

+ +

+

+ + {if condition="$user_id != -1"} +
Note : Leave blank this field if you don't want to edit password. + {/if} +

+

+ Give admin rights to this user ?
+
+ +

+

+ +

+
+ +{elseif condition="$view == 'password'"}

Edit your password

+{/if} diff --git a/tpl/index.html b/tpl/index.html index 1cc2d9c..39ade83 100755 --- a/tpl/index.html +++ b/tpl/index.html @@ -7,12 +7,12 @@ Owes\To {loop="users"} - {$value.name} + {$value->getLogin()} {/loop} {loop="users"} - {$value.name} + {$value->getLogin()} {/loop}