diff --git a/automate.php b/automate.php index a7601d1..bfb188f 100755 --- a/automate.php +++ b/automate.php @@ -63,9 +63,13 @@ // var_dump($response); + // var_dump( Database::delNumeric( Database::getPDO()->query("SHOW COLUMNS FROM users")->fetchAll() ) ); - var_dump( \manager\repo\user::getByLogin('xdrm') ); - // var_dump( \manager\repo\user::getByLogin('xdrm') ); - // var_dump( \manager\repo\subject::getByPseudo('jeannot') ); + $req_users = new ModuleRequest('user/getAll'); + $answer_users = $req_users->dispatch(); + var_dump($answer_users->get('users')); + // var_dump( \manager\repo\user::getById(1) ); + // // var_dump( \manager\repo\user::getByLogin('xdrm') ); + // // var_dump( \manager\repo\subject::getById(1) ); ?> diff --git a/config/modules.json b/config/modules.json index c57a69d..3562f0c 100755 --- a/config/modules.json +++ b/config/modules.json @@ -87,7 +87,6 @@ } }, - "call_log": { "unserialize": { "description": "Recupere le contenu d'un fichier XML de journal d'appel.", @@ -129,11 +128,11 @@ "generate": { - "description": "Creation d'un token de nom et de duree donnee", + "description": "Création d'un token de nom et de durée donnée", "permissions": ["admin"], "parameters": { - "name": { "description": "Nom attribue au token", "type": "varchar(3,50)" }, - "duration": { "description": "Duree du token en nombre de jours", "type": "numeric" } + "name": { "description": "Nom attribué au token", "type": "varchar(3,50)" }, + "duration": { "description": "Durée du token en nombre de jours", "type": "id" } } } }, diff --git a/js/lib/api.js b/js/lib/api.js index d0fa097..d476a3e 100755 --- a/js/lib/api.js +++ b/js/lib/api.js @@ -56,7 +56,7 @@ APIClass.prototype = { /* DEBUG : affiche la réponse BRUTE de http://host/api/ */ // console.log('http://host/api/ => '+ptrAPI.xhr[i].responseText); - // console.log( JSON.parse(ptrAPI.xhr[i].responseText) ); + console.log( JSON.parse(ptrAPI.xhr[i].responseText) ); /* si success de requête */ if( [0,200].indexOf(ptrAPI.xhr[i].status) > -1 ){ // si fichier existe et reçu diff --git a/manager/module/user.php b/manager/module/user.php index 68df0c9..d6c04cd 100755 --- a/manager/module/user.php +++ b/manager/module/user.php @@ -58,6 +58,41 @@ + + /* RETOURNE L'UTILISATEUR D'ID DONNE + * + * @id_user UID de l'utilisateur en question + * + * @return user Tableau contenant les informations de l'utilisateur + * + */ + public static function getById($params){ + extract($params); + + /* [1] On recupere les donnees de l'utilisateur + =========================================================*/ + $getUser = new Repo('user/getById', array($id_user)); + $user_data = $getUser->answer(); + + // Si aucun utilisateur n'est trouve + if( $user_data === false ) return array('ModuleError' => ManagerError::ModuleError); + + + /* [2] On met les permissions au bon format (string -> array) + =========================================================*/ + $user_data['permission'] = explode( ',', str_replace(' ', '', $user_data['permission']) ); + + /* [3] Gestion du retour + =========================================================*/ + return array( + 'ModuleError' => ManagerError::Success, + 'user' => $user_data + ); + } + + + + /* RETOURNE LA LISTE DE TOUS LES UTILISATEURS * * @return users Tableau contenant les informations de tous les utilisateurs diff --git a/manager/repo/parentRepo.php b/manager/repo/parentRepo.php index 752235f..d1a9c84 100644 --- a/manager/repo/parentRepo.php +++ b/manager/repo/parentRepo.php @@ -31,30 +31,42 @@ /* [2] On charge la liste des colonnes de la table =========================================================*/ $getColumns = Database::getPDO()->query('SHOW COLUMNS FROM '.static::table_name()); - $cols = $getColumns->fetchAll(); + $cols = Database::delNumeric( $getColumns->fetchAll() ); - $table_columns = array(); + $table_columns = array( + '_PRIMARY_' => array() // Contiendra les champs de la clé primaire + ); // On ajoute la liste des colonnes - foreach($cols as $column) + foreach($cols as $column){ + // On enregistre la clé primaire (si elle l'est) + if( $column['Key'] == 'PRI' ) array_push($table_columns['_PRIMARY_'], $column['Field']); + array_push($table_columns, $column['Field']); + } /* [3] On vérifie que la valeur après 'get' est dans $table_columns =========================================================*/ $columnName = strtolower($matches[1]); $getAll = count($matches) > 2; // Si 'getAll' + $getById = $columnName == 'id'; $getSomething = count($args) > 0 && in_array($columnName, $table_columns); // Si 'getX', et 'X' dans la liste des colonnes // Si ni 'getAll' ni 'getSomething' -> erreur - if( !$getAll && !$getSomething ) return false; + if( !$getById && !$getAll && !$getSomething ) return false; /* [4] On rédige la requête =========================================================*/ $getRequestString = 'SELECT * FROM '.static::table_name(); + // Si c'est 'getById', on ajoute une condition + if( $getById ){ + $getRequestString .= ' WHERE '.$table_columns['_PRIMARY_'][0].' = :value'; + // Si c'est 'getSomething', on ajoute une condition - if( $getSomething ) $getRequestString .= ' WHERE '.$columnName.' = :value'; + }else if( $getSomething ) + $getRequestString .= ' WHERE '.$columnName.' = :value'; $getRequestString .= ' ORDER BY 1 ASC'; @@ -65,7 +77,7 @@ =========================================================*/ // Si 'getSomething', on ajoute le champ $getRequest->execute(array( - ':value' => $getSomething ? $args[0] : null + ':value' => ($getSomething||$getById) ? $args[0] : null )); diff --git a/manager/repo/subject.php b/manager/repo/subject.php index 1802e5d..de23214 100644 --- a/manager/repo/subject.php +++ b/manager/repo/subject.php @@ -6,7 +6,7 @@ class subject extends parentRepo{ - protected static function table_name(){ static $table_name = 'Personnes'; return $table_name; } + protected static function table_name(){ static $table_name = 'sujets'; return $table_name; } @@ -21,9 +21,9 @@ public static function getById($id_subject){ /* [1] On effectue la requete =========================================================*/ - $getSubject = Database::getPDO()->prepare("SELECT idPersonne, pseudo, prenom, nom, id_facebook, telephone - FROM Personnes - WHERE idPersonne = :id_subject"); + $getSubject = Database::getPDO()->prepare("SELECT idSujet, pseudo, prenom, nom, id_facebook, telephone + FROM sujets + WHERE idSujet = :id_subject"); $getSubject->execute(array( ':id_subject' => $id_subject )); @@ -51,9 +51,9 @@ public static function getAll(){ /* [1] On effectue la requete =========================================================*/ - $getSubjects = Database::getPDO()->query("SELECT idPersonne, pseudo, prenom, nom, id_facebook, telephone - FROM Personnes - ORDER BY idPersonne ASC"); + $getSubjects = Database::getPDO()->query("SELECT idSujet, pseudo, prenom, nom, id_facebook, telephone + FROM sujets + ORDER BY idSujet ASC"); /* [2] On recupere le resultat de la requete @@ -97,7 +97,7 @@ /* [1] On écrit la requête =========================================================*/ - $request_create = 'INSERT INTO Personnes(idPersonne, pseudo, nom, prenom, id_facebook, telephone) '; + $request_create = 'INSERT INTO sujets(idSujet, pseudo, nom, prenom, id_facebook, telephone) '; $request_create .= 'VALUES ('; $request_create .= 'DEFAULT, '; // idPersone $request_create .= strlen($username) ? ':pseudo, ' : 'NULL, '; // pseudo diff --git a/manager/repo/token.php b/manager/repo/token.php index 8222446..83eaa00 100644 --- a/manager/repo/token.php +++ b/manager/repo/token.php @@ -47,32 +47,6 @@ - /* RETOURNE LE TOKEN D'ID SPECIFIE OU FALSE - * - * @id_token UID du token en question - * - * @return token Retourne les donnees du token ou FALSE si erreur - * - */ - public static function getById($id_token){ - /* [0] Verification des INPUT - =========================================================*/ - if( !Database::check('id', $id_token) ) return false; - - - /* [1] On cherche dans la bdd - =========================================================*/ - $get_token = Database::getPDO()->prepare("SELECT id_token FROM api_token WHERE id_token = :id_token"); - $get_token->execute( array( ':id_token' => $id_token ) ); - - - /* [2] On renvoie la valeur ou FALSE - =========================================================*/ - return $get_token->fetch(); - } - - - /* VERIFIE SI UN TOKEN EST VALIDE * * @token Token en question diff --git a/phpunit/coverage/Database.php.html b/phpunit/coverage/Database.php.html index 8f67e86..0fb6780 100755 --- a/phpunit/coverage/Database.php.html +++ b/phpunit/coverage/Database.php.html @@ -612,7 +612,7 @@ Dead Code

- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 20:36:30 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Tue Apr 19 12:25:45 UTC 2016.

diff --git a/phpunit/coverage/ManagerError.php.html b/phpunit/coverage/ManagerError.php.html index 6051d52..94ce055 100755 --- a/phpunit/coverage/ManagerError.php.html +++ b/phpunit/coverage/ManagerError.php.html @@ -247,7 +247,7 @@ Dead Code

- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 20:36:30 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Tue Apr 19 12:25:45 UTC 2016.

diff --git a/phpunit/coverage/ResourceDispatcher.php.html b/phpunit/coverage/ResourceDispatcher.php.html index 9bb2f42..83ef269 100755 --- a/phpunit/coverage/ResourceDispatcher.php.html +++ b/phpunit/coverage/ResourceDispatcher.php.html @@ -517,7 +517,7 @@ Dead Code

- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 20:36:30 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Tue Apr 19 12:25:45 UTC 2016.

diff --git a/phpunit/coverage/autoloader.php.html b/phpunit/coverage/autoloader.php.html index eb4efed..c66182a 100755 --- a/phpunit/coverage/autoloader.php.html +++ b/phpunit/coverage/autoloader.php.html @@ -214,7 +214,7 @@ Dead Code

- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 20:36:30 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Tue Apr 19 12:25:45 UTC 2016.

diff --git a/phpunit/coverage/index.html b/phpunit/coverage/index.html index fc1de51..a02d7ad 100755 --- a/phpunit/coverage/index.html +++ b/phpunit/coverage/index.html @@ -43,13 +43,13 @@ Total
-
- 66.83% covered (warning) +
+ 63.38% covered (warning)
-
66.83%
-
270 / 404
+
63.38%
+
270 / 426
44.44% covered (danger) @@ -59,13 +59,13 @@
44.44%
20 / 45
-
- 11.11% covered (danger) +
+ 10.00% covered (danger)
-
11.11%
-
1 / 9
+
10.00%
+
1 / 10
@@ -99,13 +99,13 @@ repo
-
- 16.28% covered (danger) +
+ 10.77% covered (danger)
-
16.28%
-
7 / 43
+
10.77%
+
7 / 65
20.00% covered (danger) @@ -121,7 +121,7 @@
0.00%
-
0 / 1
+
0 / 2
@@ -350,7 +350,7 @@ High: 90% to 100%

- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 20:36:30 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Tue Apr 19 12:25:45 UTC 2016.

diff --git a/phpunit/coverage/sessionManager.php.html b/phpunit/coverage/sessionManager.php.html index f0d06d6..8f1a8bc 100755 --- a/phpunit/coverage/sessionManager.php.html +++ b/phpunit/coverage/sessionManager.php.html @@ -315,7 +315,7 @@ Dead Code

- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 20:36:30 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Tue Apr 19 12:25:45 UTC 2016.

diff --git a/view/settings.php b/view/settings.php index f22dc5f..59f183c 100755 --- a/view/settings.php +++ b/view/settings.php @@ -27,7 +27,7 @@ if( permission('admin') ){ ?>
Gestion des accès distants

- +
@@ -39,7 +39,7 @@ if( permission('admin') ){
Liste des accès distants actifs. Ils seront automatiquement désactivés a la date d'expiration. Veuillez toutefois les supprimer.
-
+
Nom de l'accès
Duree de vie (jours)
@@ -83,7 +83,7 @@ if( permission('admin') ){ =========================================================*/ // permission: admin //=======================================================// - + /* (1) On recupere la liste des utilisateurs */ $req_users = new ModuleRequest('user/getAll'); $answer_users = $req_users->dispatch(); @@ -96,7 +96,7 @@ if( permission('admin') ){ ?>
Gestion des utilisateurs

- +
@@ -156,4 +156,4 @@ if( permission('admin') ){ - \ No newline at end of file +