Correction et adaptation du module 'userDefault'
This commit is contained in:
parent
999a3f4f22
commit
07c054ef83
|
@ -156,9 +156,7 @@
|
|||
"id_cluster": { "description": "UID du groupe auquel détacher.", "type": "id" },
|
||||
"id_user": { "description": "UID de l'utilisateur à détacher.", "type": "id" }
|
||||
},
|
||||
"output": {
|
||||
|
||||
}
|
||||
"output": {}
|
||||
},
|
||||
|
||||
"search": {
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
debug();
|
||||
/*******************************************/
|
||||
|
||||
$_SESSION['permission'] = array();
|
||||
|
||||
|
||||
/* [0] On initialise le routeur
|
||||
===================================================*/
|
||||
|
|
|
@ -72,8 +72,12 @@
|
|||
// Mauvais format de fichier
|
||||
const FormatError = 18;
|
||||
|
||||
/* Erreur de contenu */
|
||||
// Aucune donnée trouvée
|
||||
const NoMatchFound = 19;
|
||||
|
||||
/* Erreur au niveau javascript */
|
||||
//const JavascriptError = 19; // -> géré en js
|
||||
//const JavascriptError = 20; // -> géré en js
|
||||
|
||||
|
||||
/* EXPLICITE UN CODE D'ERREUR
|
||||
|
@ -110,6 +114,8 @@
|
|||
case self::UploadError: return "Une erreur d'upload est survenue."; break;
|
||||
case self::FormatError: return "Le fichier n'est pas au bon format."; break;
|
||||
|
||||
case self::NoMatchFound: return "Aucun résultat correspondant à la requête."; break;
|
||||
|
||||
default: return "Description d'erreur inconnue..."; break;
|
||||
}
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@
|
|||
/* [1] On verifie que le @path est renseigne
|
||||
=========================================================*/
|
||||
/* (1) Si le path est dans @url */
|
||||
$pathInUrl = is_string($url[0]) && strlen($url[0]) > 0 && preg_match('#^([\w_-]+)/([\w_-]+)/?$#', $url[0], $urlMatches);
|
||||
$pathInUrl = count($url) > 0 && is_string($url[0]) && strlen($url[0]) > 0 && preg_match('#^([\w_-]+)/([\w_-]+)/?$#', $url[0], $urlMatches);
|
||||
|
||||
// On l'utilise pour le chemin
|
||||
if( $pathInUrl )
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
// FORMAT:
|
||||
//
|
||||
// path: "nomModule/nomMethode"
|
||||
// data1: {donnee1}
|
||||
// data2: {donnee2}
|
||||
// params1: {donnee1}
|
||||
// params2: {donnee2}
|
||||
// ...
|
||||
//
|
||||
//
|
||||
|
@ -22,7 +22,7 @@
|
|||
|
||||
// Attributs prives utiles (initialisation)
|
||||
private $path;
|
||||
private $data;
|
||||
private $params; // Paramètres de la requête
|
||||
private $repositories;
|
||||
|
||||
// Contiendra la reponse a la requete
|
||||
|
@ -38,12 +38,12 @@
|
|||
/* CONSTRUCTEUR D'UNE REQUETE DE MODULE
|
||||
*
|
||||
* @path<String> Chemin de delegation ("repo/methode")
|
||||
* @data<Array> Tableau contenant les parametres utiles au traitement
|
||||
* @params<Array> Tableau contenant les parametres utiles au traitement
|
||||
*
|
||||
* @return status<Boolean> Retourne si oui ou non tout s'est bien passe
|
||||
*
|
||||
*/
|
||||
public function __construct($path=null, $data=null){
|
||||
public function __construct($path=null, $params=null){
|
||||
// Si pas parametre manquant, on quitte
|
||||
if( $path == null ){
|
||||
$this->error = ManagerError::MissingPath;
|
||||
|
@ -71,8 +71,8 @@
|
|||
return false; // On retourne FALSE, si erreur
|
||||
}
|
||||
|
||||
// Type de @data (optionnel)
|
||||
$data = (is_array($data)) ? $data : array();
|
||||
// Type de @params (optionnel)
|
||||
$params = (is_array($params)) ? $params : array();
|
||||
|
||||
|
||||
/* [2] Verification du chemin (existence repo+methode)
|
||||
|
@ -84,7 +84,7 @@
|
|||
|
||||
/* [3] Construction de l'objet
|
||||
=========================================================*/
|
||||
$this->data = $data;
|
||||
$this->params = $params;
|
||||
$this->error = ManagerError::Success;
|
||||
|
||||
/* [4] Enregistrement de la reponse
|
||||
|
@ -128,7 +128,7 @@
|
|||
|
||||
/* [3] On amorce la methode
|
||||
=========================================================*/
|
||||
return call_user_func_array( $this->getFunctionCaller(), $this->data );
|
||||
return call_user_func_array( $this->getFunctionCaller(), $this->params );
|
||||
}
|
||||
|
||||
|
||||
|
@ -150,7 +150,7 @@
|
|||
|
||||
// On recupere les donnes de la regex
|
||||
$repository = $matches[1];
|
||||
$method = $matches[2];
|
||||
$method = $matches[2];
|
||||
|
||||
/* [2] Verification de l'existence du repo (conf)
|
||||
=========================================================*/
|
||||
|
|
|
@ -35,13 +35,14 @@
|
|||
$create_user = new Repo('user/create', array($code, $username, $firstname, $lastname, $mail, $password_hash, $status) );
|
||||
$id_user = $create_user->answer();
|
||||
|
||||
var_dump($create_user);
|
||||
|
||||
// Si une erreur est retournee, on retourne une erreur
|
||||
if( $id_user === false )
|
||||
return array('ModuleError' => ManagerError::ModuleError);
|
||||
|
||||
|
||||
|
||||
|
||||
/* [3] Creation du groupe de meme nom que l'username
|
||||
=========================================================*/
|
||||
$create_group = new Repo('cluster/create', array($username) );
|
||||
|
@ -87,7 +88,7 @@
|
|||
*
|
||||
*/
|
||||
public static function link($params){
|
||||
extract($parmas);
|
||||
extract($params);
|
||||
|
||||
/* [1] Creation de l'association
|
||||
=========================================================*/
|
||||
|
@ -127,7 +128,7 @@
|
|||
|
||||
/* RENVOIE UN UTILISATEUR EN FONCTION D'UN MOT CLE
|
||||
*
|
||||
* @keyword<String> Element de recherche
|
||||
* @keywords<String> Element de recherche
|
||||
*
|
||||
* @return users<Array> Retourne la liste des utilisateurs trouves
|
||||
*
|
||||
|
@ -136,7 +137,7 @@
|
|||
extract($params);
|
||||
|
||||
// On recupere les donnees
|
||||
$user = new Repo('user/search', array($keyword));
|
||||
$user = new Repo('user/search', array($keywords));
|
||||
|
||||
return array(
|
||||
'users' => $user->answer()
|
||||
|
@ -181,7 +182,7 @@
|
|||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
if( $answer === false )
|
||||
return array( 'ModuleError' => ManagerError::ModuleError );
|
||||
return array( 'ModuleError' => ManagerError::NoMatchFound );
|
||||
|
||||
|
||||
return array(
|
||||
|
@ -209,7 +210,7 @@
|
|||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
if( $answer === false )
|
||||
return array( 'ModuleError' => ManagerError::ModuleError );
|
||||
return array( 'ModuleError' => ManagerError::NoMatchFound );
|
||||
|
||||
|
||||
return array(
|
||||
|
@ -238,7 +239,7 @@
|
|||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
if( $answer === false )
|
||||
return array( 'ModuleError' => ManagerError::ModuleError );
|
||||
return array( 'ModuleError' => ManagerError::NoMatchFound );
|
||||
|
||||
|
||||
return array(
|
||||
|
@ -267,7 +268,7 @@
|
|||
|
||||
// Si aucun resultat, on retourne une erreur
|
||||
if( $answer === false )
|
||||
return array( 'ModuleError' => ManagerError::ModuleError );
|
||||
return array( 'ModuleError' => ManagerError::NoMatchFound );
|
||||
|
||||
|
||||
return array(
|
||||
|
@ -296,7 +297,6 @@
|
|||
public static function edit($params){
|
||||
extract($params);
|
||||
|
||||
|
||||
/* [1] On verifie l'existence de l'utilisateur
|
||||
=========================================================*/
|
||||
$user_exists = new Repo('user/getById', array($id_user));
|
||||
|
@ -304,7 +304,7 @@
|
|||
|
||||
// Si on a recupere aucun utilisateur, on retourne une erreur
|
||||
if( !is_array($user_data) )
|
||||
return array('ModuleError' => ManagerError::ModuleError);
|
||||
return array('ModuleError' => ManagerError::NoMatchFound);
|
||||
|
||||
|
||||
|
||||
|
@ -314,13 +314,13 @@
|
|||
|
||||
/* (1) Verification des parametres (si non nul + differents)*/
|
||||
$diff_param = array(
|
||||
'code' => !is_null($user_data['code']) && $user_data['code'] != $code,
|
||||
'username' => !is_null($user_data['username']) && $user_data['username'] != $username,
|
||||
'firstname' => !is_null($user_data['firstname']) && $user_data['firstname'] != $firstname,
|
||||
'lastname' => !is_null($user_data['lastname']) && $user_data['lastname'] != $lastname,
|
||||
'mail' => !is_null($user_data['mail']) && $user_data['mail'] != $mail,
|
||||
'password' => !is_null($user_data['password']) && $user_data['password'] != $password_hash,
|
||||
'status' => !is_null($user_data['status']) && $user_data['status'] != $status
|
||||
'code' => !is_null($code) && $user_data['code'] != $code,
|
||||
'username' => !is_null($username) && $user_data['username'] != $username,
|
||||
'firstname' => !is_null($firstname) && $user_data['firstname'] != $firstname,
|
||||
'lastname' => !is_null($lastname) && $user_data['lastname'] != $lastname,
|
||||
'mail' => !is_null($mail) && $user_data['mail'] != $mail,
|
||||
'password' => !is_null($password) && $user_data['password'] != $password_hash,
|
||||
'status' => !is_null($status) && $user_data['status'] != $status
|
||||
);
|
||||
|
||||
/* (2) Gestion des parametres optionnels */
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
if( $class == self::USER_CLASS ){
|
||||
// On verifie si c'est un utilisateur
|
||||
$user_check = userRepo::getById($id_entity);
|
||||
$entity_exists = ( $user_check !== FALSE );
|
||||
$entity_exists = ( $user_check !== FALSE );
|
||||
|
||||
/* (2) Machine */
|
||||
}elseif( $class == self::MACHINE_CLASS ){
|
||||
|
@ -122,7 +122,7 @@
|
|||
$check_cluster_merge = self::getMerge($id_cluster, $id_entity, $class);
|
||||
|
||||
// Si n'existe pas on retourne FALSE
|
||||
if( $check_cluster_merge === false )
|
||||
if( !is_array($check_cluster_merge) )
|
||||
return false;
|
||||
|
||||
// Sinon, on retourne son id
|
||||
|
|
|
@ -124,9 +124,9 @@
|
|||
WHERE id_user = :id");
|
||||
|
||||
// On execute la requete
|
||||
$request->execute(array(
|
||||
$request->execute( array(
|
||||
':id' => $id
|
||||
));
|
||||
) );
|
||||
|
||||
// On recupere 1 seul utilisateur
|
||||
$answer = $request->fetch();
|
||||
|
@ -299,6 +299,7 @@
|
|||
/* [1] Verification de l'unicite de code+username (si differents)
|
||||
=========================================================*/
|
||||
// On recupere les utilisateurs ayant le meme code ou username (si existent)
|
||||
// pour éviter les collisions (car code/username doivent être uniquent)
|
||||
$getbycode = self::getByCode($code);
|
||||
$getbyusername = self::getByUsername($username);
|
||||
|
||||
|
@ -313,12 +314,12 @@
|
|||
=========================================================*/
|
||||
$edit_user = Database::getPDO()->prepare("UPDATE user
|
||||
SET code = :code,
|
||||
username = :username,
|
||||
firstname = :firstname,
|
||||
lastname = :lastname,
|
||||
mail = :mail,
|
||||
password = :password,
|
||||
status = :status
|
||||
username = :username,
|
||||
firstname = :firstname,
|
||||
lastname = :lastname,
|
||||
mail = :mail,
|
||||
password = :password,
|
||||
status = :status
|
||||
WHERE id_user = :id_user");
|
||||
$edit_user->execute(array(
|
||||
':code' => $code,
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
|
||||
// DEFAULT SESSION CREDENTIALS
|
||||
echo '{"data1": "'.session_id().'",';
|
||||
echo '"data2": "'. ( $_SESSION['session_token']==$_COOKIE['session_token'] ? 'YES' : 'NO' ). '"}';
|
||||
echo '{"data1": "'.session_id().'"}';
|
||||
// echo '"data2": "'. ( $_SESSION['session_token']==$_COOKIE['session_token'] ? 'YES' : 'NO' ). '"}';
|
||||
|
||||
|
||||
?>
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
// DEFAULT SESSION CREDENTIALS
|
||||
var_dump( 'SESSID---'.session_id() );
|
||||
var_dump( 'TOKEN----'.( $_SESSION['session_token']==$_COOKIE['session_token'] ? 'YES' : 'NO' ) );
|
||||
// var_dump( 'TOKEN----'.( $_SESSION['session_token']==$_COOKIE['session_token'] ? 'YES' : 'NO' ) );
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<div id=ajax1>NO VALUE</div><br>
|
||||
<div id=ajax2>NO VALUE</div>
|
||||
<!-- <div id=ajax2>NO VALUE</div> -->
|
||||
|
||||
<br><br><br><br>
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
var section={view:{text:'#CONTAINER > section[data-sublink="view"] ',element:document.querySelector('#CONTAINER > section[data-sublink="view"]'),searchbar:document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')},create:{text:'#CONTAINER > section[data-sublink="create"] ',element:document.querySelector('#CONTAINER > section[data-sublink="create"]')},remove:{text:'#CONTAINER > section[data-sublink="remove"] ',element:document.querySelector('#CONTAINER > section[data-sublink="remove"]')},
|
||||
edit:{text:'#CONTAINER > section[data-sublink="edit"] ',element:document.querySelector('#CONTAINER > section[data-sublink="edit"]')}};
|
||||
if(null!=section.view.element){section.view.link={edit:document.querySelectorAll(section.view.text+".link_edit[data-user]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-user]")};section.view.searchbar.addEventListener("keyup",function(b){api.send({path:"userDefault/search",data:[section.view.searchbar.value]},function(a){if(0==a.ModuleError&&(console.log(a.users.length),0==a.ModuleError)){for(var b=[],c=0;c<a.users.length;c++)b.push(a.users[c].id_user);a=document.querySelectorAll(section.view.text+
|
||||
"> article.inline-box[id]");for(c=0;c<a.length;c++)-1<b.indexOf(a[c].id)?a[c].remClass("hidden"):a[c].addClass("hidden")}})},!1);for(var i=0;i<section.view.link.edit.length;i++)section.view.link.edit[i].addEventListener("click",function(b){pageManager.vars[1]=b.target.getData("user");autofill_edit(pageManager.vars[1]);navSubMenu("edit")},!1);for(i=0;i<section.view.link.remove.length;i++)section.view.link.remove[i].addEventListener("click",function(b){pageManager.vars[1]=b.target.getData("user");autofill_remove(pageManager.vars[1]);
|
||||
navSubMenu("remove")},!1)}
|
||||
if(null!=section.create.element){section.create.input={code:document.querySelector(section.create.text+"#create_code"),username:document.querySelector(section.create.text+"#create_username"),firstname:document.querySelector(section.create.text+"#create_firstname"),lastname:document.querySelector(section.create.text+"#create_lastname"),mail:document.querySelector(section.create.text+"#create_mail"),password:document.querySelector(section.create.text+"#create_password"),status:document.querySelector(section.create.text+"#create_status"),
|
||||
submit:document.querySelector(section.create.text+"#create_submit")};var createChecker=new inputChecker;createChecker.append(section.create.input.code,format_code,"01-AB-CD-23");section.create.input.code.addEventListener("keyup",function(b){b.target.value=b.target.value.toUpperCase();createChecker.check(b.target)||createChecker.correct(b.target,!1)},!1);section.create.input.submit.addEventListener("click",function(b){b.preventDefault();api.send({path:"userDefault/create",data:[section.create.input.code.value,
|
||||
section.create.input.username.value,section.create.input.firstname.value,section.create.input.lastname.value,section.create.input.mail.value,section.create.input.password.value,section.create.input.status.value]},function(a){0==a.ModuleError?(console.log("Utilisateur cree!"),section.create.input.submit.anim("active",1500)):console.error("ModuleError::"+a.ModuleError)})},!1)}
|
||||
if(null!=section.remove.element){var autofill_remove=function(b){var a={id_user:"",code:"",username:"",firstname:"",lastname:"",mail:"",status:"",disable_input:!0};api.send({path:"userDefault/getById",data:[b]},function(b){0==b.ModuleError&&(a=b.user,a.disable_input=!1);section.remove.input.search.id.value=a.id_user;section.remove.input.code.value=a.code;section.remove.input.username.value=a.username;section.remove.input.submit.disabled=a.disable_input;section.remove.input.search.num.innerHTML=searchindex_remove+
|
||||
1})};section.remove.input={search:{view:document.querySelector(section.remove.text+".remove_search_view"),num:document.querySelector(section.remove.text+".remove_search_num"),sum:document.querySelector(section.remove.text+".remove_search_sum"),keyword:document.querySelector(section.remove.text+"#remove_search_keyword"),id:document.querySelector(section.remove.text+"#remove_search_id"),submit:document.querySelector(section.remove.text+"#remove_search_submit")},code:document.querySelector(section.remove.text+
|
||||
"#remove_code"),username:document.querySelector(section.remove.text+"#remove_username"),submit:document.querySelector(section.remove.text+"#remove_submit")};var lastsearch_remove=null,searchindex_remove=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&autofill_remove(pageManager.vars[1]);section.remove.input.search.submit.addEventListener("click",function(b){b.preventDefault();""!=section.remove.input.search.keyword.value&&api.send({path:"userDefault/search",data:[section.remove.input.search.keyword.value]},
|
||||
function(a){0==a.ModuleError&&0<a.users.length?(section.remove.input.search.submit.anim("active",1E3),searchindex_remove=lastsearch_remove==a.users[searchindex_remove].id_user?(searchindex_remove+1)%a.users.length:0,lastsearch_remove=a.users[searchindex_remove].id_user,section.remove.input.search.id.value=lastsearch_remove,section.remove.input.search.sum.innerHTML=a.users.length,autofill_remove(lastsearch_remove)):(section.remove.input.search.sum.innerHTML=0,autofill_remove(null))})},!1);section.remove.input.submit.addEventListener("click",
|
||||
function(b){b.preventDefault();""!=section.remove.input.search.id.value&&api.send({path:"userDefault/delete",data:[section.remove.input.search.id.value]},function(a){0==a.ModuleError&&1==a.status?(console.log("Utilisateur supprime!"),section.remove.input.submit.anim("active",1500),autofill_remove(null)):console.error("ModuleError::"+a.ModuleError)})},!1)}
|
||||
if(null!=section.edit.element){var autofill_edit=function(b){var a={id_user:"",code:"",username:"",firstname:"",lastname:"",mail:"",status:"",disable_input:!0};isNaN(b)?section.edit.input.search.num.innerHTML=0:api.send({path:"userDefault/getById",data:[b]},function(b){0==b.ModuleError&&(a=b.user,a.disable_input=!1);section.edit.input.search.id.value=a.id_user;section.edit.input.code.value=a.code;section.edit.input.username.value=a.username;section.edit.input.firstname.value=a.firstname;section.edit.input.lastname.value=
|
||||
a.lastname;section.edit.input.mail.value=a.mail;section.edit.input.password.value="";section.edit.input.status.value=a.status;section.edit.input.submit.disabled=a.disable_input;section.edit.input.search.num.innerHTML=searchindex_edit+1})};section.edit.input={search:{view:document.querySelector(section.edit.text+".edit_search_view"),num:document.querySelector(section.edit.text+".edit_search_num"),sum:document.querySelector(section.edit.text+".edit_search_sum"),keyword:document.querySelector(section.edit.text+
|
||||
"#edit_search_keyword"),id:document.querySelector(section.edit.text+"#edit_search_id"),submit:document.querySelector(section.edit.text+"#edit_search_submit")},code:document.querySelector(section.edit.text+"#edit_code"),username:document.querySelector(section.edit.text+"#edit_username"),firstname:document.querySelector(section.edit.text+"#edit_firstname"),lastname:document.querySelector(section.edit.text+"#edit_lastname"),mail:document.querySelector(section.edit.text+"#edit_mail"),password:document.querySelector(section.edit.text+
|
||||
"#edit_password"),status:document.querySelector(section.edit.text+"#edit_status"),submit:document.querySelector(section.edit.text+"#edit_submit")};var lastsearch_edit=null,searchindex_edit=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&autofill_edit(pageManager.vars[1]);section.edit.input.search.submit.addEventListener("click",function(b){b.preventDefault();""!=section.edit.input.search.keyword.value&&api.send({path:"userDefault/search",data:[section.edit.input.search.keyword.value]},
|
||||
function(a){0==a.ModuleError&&0<a.users.length?(section.edit.input.search.submit.anim("active",1E3),searchindex_edit=lastsearch_edit==a.users[searchindex_edit].id_user?(searchindex_edit+1)%a.users.length:0,lastsearch_edit=a.users[searchindex_edit].id_user,section.edit.input.search.id.value=lastsearch_edit,section.edit.input.search.sum.innerHTML=a.users.length,autofill_edit(lastsearch_edit)):(section.edit.input.search.sum.innerHTML=0,autofill_edit(null))})},!1);section.edit.input.submit.addEventListener("click",
|
||||
function(b){b.preventDefault();""!=section.edit.input.search.id.value&&api.send({path:"userDefault/edit",data:[section.edit.input.search.id.value,section.edit.input.code.value,section.edit.input.username.value,section.edit.input.firstname.value,section.edit.input.lastname.value,section.edit.input.mail.value,section.edit.input.password.value,section.edit.input.status.value]},function(a){console.log(a);0==a.ModuleError&&1==a.status?(console.log("Utilisateur modifie!"),section.edit.input.submit.anim("active",
|
||||
1500),autofill_edit(section.edit.input.search.id.value)):console.error("ModuleError::"+a.ModuleError)})},!1)};
|
|
@ -48,6 +48,8 @@ if( section.view.element != null ){
|
|||
|
||||
// On envoie la requete
|
||||
api.send(search, function(result){
|
||||
if( result.ModuleError != 0 ) return;
|
||||
|
||||
console.log(result.users.length);
|
||||
if( result.ModuleError == 0 ){ // si aucune erreur
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
/* [1] VIEW -> Liste des utilisateurs
|
||||
=========================================================*/
|
||||
$request = new ModuleRequest('userDefault/getAll'); // On utilise la methode 'getAll' du module 'userDefault'
|
||||
$answer = $request->dispatch(); // On recupere la reponse
|
||||
$answer = $request->dispatch(); // On recupere la reponse
|
||||
|
||||
echo "<section data-sublink='view' class='list'>";
|
||||
// echo 'Liste des utilisateurs: <br>';
|
||||
|
|
Loading…
Reference in New Issue