From 4dd0954d71181368098c7a2e77f8f422039ec55f Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 16 Feb 2016 19:59:55 +0100 Subject: [PATCH] - [x] [machineDefaut][machineRepo] Gestion des parametres optionnels pour la modification --- manager/module/machineDefault.php | 58 ++++++++++++++++++++----------- manager/module/userDefault.php | 21 ++++++----- manager/repo/machine.php | 2 +- todo.md | 2 +- view/js/users.js | 1 + 5 files changed, 50 insertions(+), 34 deletions(-) diff --git a/manager/module/machineDefault.php b/manager/module/machineDefault.php index 0cc662d..2aa4c61 100755 --- a/manager/module/machineDefault.php +++ b/manager/module/machineDefault.php @@ -267,34 +267,50 @@ * */ public static function edit($id_machine=null, $code=null, $name=null){ - /* [1] Normalisation + verification des donnees - =========================================================*/ - $correct_param = Database::check('auto_increment_id', $id_machine); - $correct_param = $correct_param && Database::check('machine.code', $code); - $correct_param = $correct_param && Database::check('machine.name', $name); - - // Si les parametres ne sont pas corrects, on retourne une erreur - if( !$correct_param ) - return array('ModuleError' => ManagerError::ParamError); - - - /* [2] On verifie l'existence de la machine - =========================================================*/ - $machine_exists = new Repo('machine/getById', array($id_machine)); - $machine_exists = $machine_exists->answer(); - - // Si on a recupere aucun utilisateur, on retourne une erreur - if( !is_array($machine_exists) ) + // Si @id_machine n'est pas au bon format, on retourne une erreur + if( !Database::check('auto_increment_id', $id_machine) ) return array('ModuleError' => ManagerError::ModuleError); + /* [1] On verifie l'existence de la machine + =========================================================*/ + $machine_exists = new Repo('machine/getById', array($id_machine)); + $machine_data = $machine_exists->answer(); + + // Si on a recupere aucune machine, on retourne une erreur + if( !is_array($machine_data) ) + return array('ModuleError' => ManagerError::ModuleError); + + + + + /* [2] Normalisation + verification des donnees + =========================================================*/ + + /* (1) Verification des parametres (si correct et different)*/ + $correct_param = array( + 'code' => Database::check('machine.code', $code ) && $machine_data['code'] != $code, + 'name' => Database::check('machine.name', $name ) && $machine_data['name'] != $name + ); + + /* (2) Gestion des parametres optionnels */ + $opt_data = array( + 'code' => ($correct_param['code']) ? $code : $machine_data['code'], + 'name' => ($correct_param['name']) ? $name : $machine_data['name'] + ); + + /* [3] Modification de la machine =========================================================*/ - $request = new Repo('machine/edit', array($id_machine, $code, $name)); - $answer = $request->answer(); + $request = new Repo('machine/edit', array( + $id_machine, + $opt_data['code'], + $opt_data['name'] + )); + return array( - 'status' => $answer + 'status' => $request->answer() ); } diff --git a/manager/module/userDefault.php b/manager/module/userDefault.php index 8f2acb4..dcbdf15 100755 --- a/manager/module/userDefault.php +++ b/manager/module/userDefault.php @@ -318,7 +318,7 @@ /* [1] On verifie l'existence de l'utilisateur =========================================================*/ $user_exists = new Repo('user/getById', array($id_user)); - $user_data = $user_data->answer(); + $user_data = $user_exists->answer(); // Si on a recupere aucun utilisateur, on retourne une erreur if( !is_array($user_data) ) @@ -337,19 +337,19 @@ 'firstname' => Database::check('user.firstname', $firstname ) && $user_data['firstname'] != $firstname, 'lastname' => Database::check('user.lastname', $lastname ) && $user_data['lastname'] != $lastname, 'mail' => Database::check('user.mail', $mail ) && $user_data['mail'] != $mail, - 'password' => Database::check('user.password', $password_hash ) && $user_data['password'] != $password, + 'password' => Database::check('user.password', $password_hash ) && $user_data['password'] != $password_hash, 'status' => Database::check('user.status', $status ) && $user_data['status'] != $status ); /* (2) Gestion des parametres optionnels */ $opt_data = array( - 'code' => ($correct_param['code']) ? $code : $user_data['code'], - 'username' => ($correct_param['username']) ? $username : $user_data['username'], + 'code' => ($correct_param['code']) ? $code : $user_data['code'], + 'username' => ($correct_param['username']) ? $username : $user_data['username'], 'firstname' => ($correct_param['firstname']) ? $firstname : $user_data['firstname'], - 'lastname' => ($correct_param['lastname']) ? $lastname : $user_data['lastname'], - 'mail' => ($correct_param['mail']) ? $mail : $user_data['mail'], - 'password' => ($correct_param['password']) ? $password : $user_data['password'], - 'status' => ($correct_param['status']) ? $status : $user_data['status'], + 'lastname' => ($correct_param['lastname']) ? $lastname : $user_data['lastname'], + 'mail' => ($correct_param['mail']) ? $mail : $user_data['mail'], + 'password' => ($correct_param['password']) ? $password : $user_data['password'], + 'status' => ($correct_param['status']) ? $status : $user_data['status'], ); @@ -364,14 +364,13 @@ $opt_data['firstname'], $opt_data['lastname'], $opt_data['mail'], - $opt_data['password_hash'], + $opt_data['password'], $opt_data['status']) ); - $answer = $request->answer(); return array( - 'status' => $answer + 'status' => $request->answer() ); } diff --git a/manager/repo/machine.php b/manager/repo/machine.php index c5ef7ca..2255185 100644 --- a/manager/repo/machine.php +++ b/manager/repo/machine.php @@ -251,7 +251,7 @@ * @return status Renvoie si oui ou non tout s'est bien passe * */ - public static function edit($id_machine, $code, $name){ + public static function edit($id_machine=null, $code=null, $name=null){ /* [1] Verification de l'unicite de code+name (si differents) =========================================================*/ // On recupere les machine ayant le meme code ou name (si existent) diff --git a/todo.md b/todo.md index 26e9503..d53cfff 100755 --- a/todo.md +++ b/todo.md @@ -7,7 +7,6 @@ ############ # EN COURS # ############ -- [ ] [machineDefaut][machineRepo] Gestion des parametres optionnels pour la modification - [ ] [view/js/machines] Recherche instantanee @@ -18,6 +17,7 @@ ######## # FAIT # ######## +- [x] [machineDefaut][machineRepo] Gestion des parametres optionnels pour la modification - [x] [userDefault][userRepo] Gestion des parametres optionnels pour la modification - [x] [machines.js][machineDefault][machineRepo] Gestion de la nouvelle modification (avec recherche) - [x] [machineDefault] Implementer la modification diff --git a/view/js/users.js b/view/js/users.js index 12ab599..ff727ec 100644 --- a/view/js/users.js +++ b/view/js/users.js @@ -360,6 +360,7 @@ if( section.edit.element != null ){ }; api.send(request, function(answer){ + console.log( answer ); if( answer.ModuleError == 0 && answer.status == true ) // Tout s'est bien deroule console.log('Utilisateur modifie!'); else // Erreur