From 7c3d79e4ec7371a25ac75d598b17634f18d42929 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 19 Jul 2016 18:59:56 +0200 Subject: [PATCH] minmod --- manager/Database.php | 19 ++++++++++++++----- manager/module/machineDefault.php | 8 ++++---- test/client/interface.php | 21 ++++----------------- test/client/lib-min.js | 2 +- test/client/lib.js | 1 + 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/manager/Database.php b/manager/Database.php index 605c2fb..9d8c1bb 100755 --- a/manager/Database.php +++ b/manager/Database.php @@ -180,12 +180,12 @@ if( !is_array($autotyped) ){ /* (1) Si Numérique Entier -> INT */ - if( is_numeric($autotyped) && intval($autotyped) == $autotyped ) + if( preg_match('/^(0|([1-9][0-9]*))$/i', $autotyped) ) return intval($autotyped); /* (2) Si Numérique Décimal -> FLOAT */ - else if( is_numeric($autotyped) && floatval($autotyped) == $autotyped ) - return floatval($autotyped); + else if( preg_match('/^(0|(?:[1-9][0-9]*))[\.\,]([0-9]+)$/i', $autotyped, $m) ) + return floatval("${m[1]}.${m[2]}"); /* (3) Sinon on retourne la même chose */ else @@ -195,12 +195,21 @@ =========================================================*/ }else{ - // Pour chaque valeur, on applique récursivement - foreach($autotyped as $k=>$v) + /* (1) Pour chaque valeur, on applique récursivement */ + foreach($autotyped as $k=>$v){ + + // Si on met '_nomColonne', on ne le traite pas + if( is_string($k) && $k[0] == '_' ) continue; + $autotyped[$k] = self::autotype($v); + } + } + + /* [2] On retourne le résultat auto-typé + =========================================================*/ return $autotyped; } diff --git a/manager/module/machineDefault.php b/manager/module/machineDefault.php index 52bb351..5a7396e 100755 --- a/manager/module/machineDefault.php +++ b/manager/module/machineDefault.php @@ -453,10 +453,10 @@ /* [N] Retourne les données =========================================================*/ return [ - 'actions' => $sorted_actions, - 'states' => $globalStates, - 'chips' => $chips, - 'permissions' => $indexed_permissions + 'actions' => Database::autotype( $sorted_actions ), + 'states' => Database::autotype( $globalStates ), + 'chips' => Database::autotype( $chips ), + 'permissions' => Database::autotype( $indexed_permissions ) ]; } diff --git a/test/client/interface.php b/test/client/interface.php index fb2c184..efb81a9 100644 --- a/test/client/interface.php +++ b/test/client/interface.php @@ -363,25 +363,12 @@ for( var a in Object.keys(ACTIONS[COUNT]) ){ /* (3) On vérifie que l'utilisateur a la permissions d'effectuer l'action */ - var hasPermission = false; - - // On vérifie parmis toutes les permissions de cette CARTE - if( PERMISSIONS.hasOwnProperty(CARD) ) - for( var i = 0 ; i < PERMISSIONS[CARD].length ; i++ ) - if( PERMISSIONS[CARD][i] == ACTIONS[COUNT][a].id_action ){ - hasPermission = true; - break; - } - - // Si on a pas la permission, on quitte - if( !hasPermission ) return; - - - - console.log( CARD, PERMISSIONS[CARD], ACTIONS[COUNT][a].id_action); + var hasPermission = PERMISSIONS.hasOwnProperty(CARD) && PERMISSIONS[CARD].indexOf(ACTIONS[COUNT][a].id_action) > -1; + console.log( CARD, PERMISSIONS[CARD], ACTIONS[COUNT][a].id_action, hasPermission); // Si pas la permission, on fait rien - if( !hasPermission ) break; + if( !hasPermission ) continue; + /* (4) Si la condition est correcte, On applique la modification de l'état */ if( previous(ACTIONS[COUNT][a].previous, STATE) ){ diff --git a/test/client/lib-min.js b/test/client/lib-min.js index f5f20ec..9a3a51e 100644 --- a/test/client/lib-min.js +++ b/test/client/lib-min.js @@ -5,4 +5,4 @@ a};Board.prototype.set=function(a,b){if(!(parseInt(a)!=a||a>this.maxPin)&&this.p b=parseInt(b);this.values[a].set(b)}};Chip.prototype.setPins=function(a){for(var b=0;b