diff --git a/admin.php b/admin.php index b3d9bbc..0b8346f 100644 --- a/admin.php +++ b/admin.php @@ -1 +1,176 @@ connect ( $_SESSION ['session_mdp'] ); +if ($me->isAdminLevelLowerThan ( 15 )) { + header ( 'Location:401.php' ); + exit (); +} +?> + + +
+ + +'; + print_r($objectsToSet); + echo ''; + + break; + case 'DELETE': + + break; + default: + exception('Unknown function '.$fonction); + + } + +} + + diff --git a/clazz/Langage.class.php b/clazz/Langage.class.php index ed882e8..08aaf9c 100644 --- a/clazz/Langage.class.php +++ b/clazz/Langage.class.php @@ -1,8 +1,9 @@ getMessage().' when reading attribute "'.$attribute.'"'; + exit; + } + + $restrictionValues[] = $value; + + if($json){ + $whereCommand = '((data->"$.'.$attribute.'" IS NOT NULL) AND (data->"$.'.$attribute.'" '.$operator.' ? ))'; + }else{ + $whereCommand = $attribute . ' ' . $operator . ' ' . $value; + } + $whereCommands[] = $whereCommand; + } + $wherePart = 'WHERE '.implode(' AND ',$whereCommands); + + + $req = $GLOBALS['bdd']->prepare('SELECT * FROM membres '.$wherePart); + $req->execute($restrictionValues); + if($req->errorInfo()[0] == 0) + echo 'A SQL exception occured ...'; $out = array(); while($rep = $req->fetch()) $out[] = new Membre($rep['ID']); - switch(count($out)){ - case 0: - return NULL; - case 1: - return $out[0]; - default: - return $out; - } + + //Choose return value + switch(count($out)){ + case 0: + return NULL; + case 1: + return $out[0]; + default: + return $out; + } } public static function getFromPseudo($pseudo){ - $req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE pseudo=?'); - $req->execute(array($pseudo)); - return membreGetterOutput($req); + return getFromAttributes(array(['pseudo','=',$pseudo])); } public static function getFromAdminLevel($level){ - $req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE adminLevel=?'); - $req->execute(array($level)); - return membreGetterOutput($req); + return getFromAttributes(array(['adminLevel','=',$level])); } public static function getFromDateCreation($date){ - $req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE dateCreation=?'); - $req->execute(array($date)); - return membreGetterOutput($req); + return getFromAttributes(array(['dateCreation','=',$date])); } public static function getCreatedLaterThan($date){ - $req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE dateCreation>?'); - $req->execute(array($date)); - return membreGetterOutput($req); + return getFromAttributes(array(['dateCreation','>',$date])); } public static function getCreatedEarlierThan($date){ - $req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE dateCreation'); - $req->execute(array($date)); - return membreGetterOutput($req); + return getFromAttributes(array(['dateCreation','<',$date])); } public static function getAdminGreaterThan($min){ - $req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE adminLevel>?'); - $req->execute(array($min)); - return membreGetterOutput($req); + return getFromAttributes(array(['adminLevel','>',$min])); } public static function getAdminLowerThan($max){ - $req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE adminLevel'); - $req->execute(array($max)); - return membreGetterOutput($req); + return getFromAttributes(array(['adminLevel','<',$max])); } @@ -191,7 +247,7 @@ class Membre { return Membre::USED_USERNAME; $req = $GLOBALS ['bdd']->prepare ('INSERT INTO membres(pseudo,mdp,date_creation) VALUES (?,?,NOW())'); $req->execute (array($pseudo,password_hash( $mdp, PASSWORD_DEFAULT))); - return Membre::USERNAME_CHANGED; + return Membre::PERSON_REGISTERED; } diff --git a/clazz/Projet.class.php b/clazz/Projet.class.php index b00d17c..eb7e2d0 100644 --- a/clazz/Projet.class.php +++ b/clazz/Projet.class.php @@ -1,5 +1,6 @@ ou != + +...les deux valeurs ne sont pas égales +< + +...la valeur de gauche est strictement inférieure à celle de droite +> + +...la valeur de gauche est strictement supérieure à celle de droite +<= + +...la valeur de gauche est strictement inférieure ou égale à celle de droite +>= + +...la valeur de gauche est strictement supérieure ou égale à celle de droite +BETWEEN..AND + +...la valeur testée est située entre deux valeurs données +IN + +...la valeur testée se situe dans une liste valeurs données +NOT IN + +...la valeur testée ne se situe pas dans une liste de valeurs données +LIKE + +...la valeur de gauche correspond à celle de droite (celle de droite peux utiliser le caractère % pour simuler n'importe quel nombre de caractère, et _ pour un seul caractère +NOT LIKE + +...les deux valeurs ne correspondent pas +REGEXP ou RLIKE + +...la valeur de gauche correspond à l'expression régulière donnée +NOT REGEXP + +...la valeur de gauche ne correspond pas à l'expression régulière donnée + */ + + public static function getIntegerSqlOperator($operator){ + switch ($operator){ + case '=': + return '='; + case '<': + return '<'; + case '>': + return '>'; + case '<=': + return '<='; + case '>=': + return '>='; + case '=<': + return '<='; + case '<>': + return '<>'; + case '!=': + return '!='; + case '!<': + return '!<'; + case '!>': + return '!>'; + default: + throw new InvalidOperatorException('integer',$operator); + } + } + + public static function getStringSqlOperator($operator){ + switch ($operator){ + case '=': + return '='; + case '&like;': + return 'LIKE'; + default: + throw new InvalidOperatorException('string',$operator); + } + } + + public static function getDateSqlOperator($operator){ + switch ($operator){ + case '=': + return '='; + case '<': + return '<'; + case '>': + return '>'; + case '<=': + return '<='; + case '>=': + return '>='; + case '=<': + return '<='; + case '<>': + return '<>'; + case '!=': + return '!='; + case '!<': + return '!<'; + case '!>': + return '!>'; + default: + throw new InvalidOperatorException('date',$operator); + } + } + +} \ No newline at end of file diff --git a/clazz/Zincluder.php b/clazz/Zincluder.php index 71918e8..45004e2 100644 --- a/clazz/Zincluder.php +++ b/clazz/Zincluder.php @@ -7,10 +7,11 @@ try{ } //TODO in the classes , do more test of exists in setters +include_once 'clazz/Utility.class.php'; include_once 'clazz/Langage.class.php'; include_once 'clazz/Membre.class.php'; include_once 'clazz/Discussion.class.php'; include_once 'clazz/Message.class.php'; include_once 'clazz/Projet.class.php'; -//Use class's consts for file names +//TODO Use class's consts for file names include_once 'clazz/Version.class.php'; diff --git a/css/adminStyle.css b/css/adminStyle.css new file mode 100644 index 0000000..b4e9bf4 --- /dev/null +++ b/css/adminStyle.css @@ -0,0 +1,62 @@ +#adminDialogAnswer{ + display:block; + background-color:black; + color:white; + height: 150px; + overflow:scroll; +} +#setFormObject , #setChampsForm{ + display:inline-block; + text-align: center; + height: inherit; +} + +#setFormObject{ + width:25%; +} + +#setChampsForm{ + width:75%; +} + +#setDiv{ + border:5px double grey; +} + +#send{ + width:100%; +} + +.fullscreen{ + position:fixed; + top:0; + right:0; + width:100%; + height:100%; + vertical-align:middle; + background-color: #222; + opacity:0.97; +} + +.screen-vertical-centered{ + text-align:center; + margin-top: 50vh; + transform: translateY(-50%); +} +.screen-horizontal-centered{ + display:inline; + opacity:1; + font-size:42px; + overflow-wrap: break-word; + word-wrap: break-word; + -ms-word-break: break-all; + /* This is the dangerous one in WebKit, as it breaks things wherever */ + word-break: break-all; + /* Instead use this non-standard one: */ + word-break: break-word; + /* Adds a hyphen where the word breaks, if supported (No Blink) */ + -ms-hyphens: auto; + -moz-hyphens: auto; + -webkit-hyphens: auto; + hyphens: auto; +} \ No newline at end of file diff --git a/form.php b/form.php new file mode 100644 index 0000000..85f39ec --- /dev/null +++ b/form.php @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/includes/inter.php b/includes/inter.php index f0f0e36..4c8d6cb 100644 --- a/includes/inter.php +++ b/includes/inter.php @@ -155,7 +155,6 @@ function getVersions($pid = NULL) { $req->execute ( array ( $pid ) ); - // ADDPOINT langage $versions = array ( array (), array () @@ -217,6 +216,7 @@ function getMessages($discut = NULL) { $req->closeCursor (); return array_slice ( $rep, 0, - 1, TRUE ); } + function getDiscuts() { $req = $GLOBALS ['bdd']->query ( "SELECT * FROM discussions ORDER BY date_creation DESC" ); $rep = array (); diff --git a/inter.php b/inter.php deleted file mode 100644 index 60487ea..0000000 --- a/inter.php +++ /dev/null @@ -1,262 +0,0 @@ -prepare ( 'SELECT * FROM users WHERE ID=?' ); - $req->execute ( array ( - $sid - ) ); - if ($rep = $req->fetch ()) { - $connected = password_verify ( $mdp, $rep ['mdp'] ); - } else { - $connected = FALSE; - } - $req->closeCursor (); - return $connected; -} -function getAdminLevel($sid = NULL, $mdp = NULL) { - if (! isset ( $sid ) or ! isset ( $mdp )) { - $sid = $_SESSION ['session_id']; - $mdp = $_SESSION ['session_mdp']; - } - if (! isConnected ( $sid, $mdp )) - return - 1; - $req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' ); - $req->execute ( array ( - $sid - ) ); - if ($result = $req->fetch ()) { - $adminLevel = $result ['administration']; - } else { - $adminLevel = - 1; - } - $req->closeCursor (); - return $adminLevel; -} -function getPseudo($sid = NULL, $mdp = NULL) { - if (! isset ( $sid ) or ! isset ( $mdp )) { - $sid = $_SESSION ['session_id']; - $mdp = $_SESSION ['session_mdp']; - } - if (! isConnected ( $sid, $mdp )) - return "neant"; - $req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' ); - $req->execute ( array ( - $sid - ) ); - $pseudo = $req->fetch () ['pseudo']; - $req->closeCursor (); - return $pseudo; -} -function getPseudoOf($sid) { - $req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' ); - $req->execute ( array ( - $sid - ) ); - $pseudo = $req->fetch () ['pseudo']; - $req->closeCursor (); - return $pseudo; -} -function tryToConnect($pseudo = NULL, $mdp = NULL) { - if (! isset ( $pseudo ) or ! isset ( $mdp )) { - $pseudo = $_POST ['pseudo']; - $mdp = $_POST ['mdp']; - } - $req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE pseudo=?' ); - $req->execute ( array ( - $pseudo - ) ); - $reponce = $req->fetch (); - if ($reponce != NULL) { - if (password_verify ( $mdp, $reponce ['mdp'] )) { - $req->closeCursor (); - return $reponce ['ID']; - } else { - $req->closeCursor (); - return 'errormdp'; - } - } else { - $req->closeCursor (); - return 'errorpseudo'; - } -} -function getProjectVersionData($project = NULL, $version = NULL) { - if (! isset ( $project ) or ! isset ( $version )) { - $project = $_GET ['id']; - $version = $_GET ['v']; - } - $req = $GLOBALS ['bdd']->prepare ( 'SELECT p.ID AS pID ,' . ' ' . 'v.versionAbs AS versionAbs , ' . ' ' . 'p.name AS name ,' . ' ' . 'v.version AS version ,' . ' ' . 'v.language AS language ,' . ' ' . 'p.permissions AS permissions ,' . ' ' . 'p.ownersID AS owners' . ' ' . 'FROM projets AS p' . ' ' . 'INNER JOIN versions AS v' . ' ' . 'ON v.project_id = p.ID' . ' ' . 'WHERE v.project_id = ? AND v.versionAbs = ?' ); - $req->execute ( array ( - $project, - $version - ) ); - if (($data = $req->fetch ())) { - $req->closeCursor (); - return $data; - } else { - $req->closeCursor (); - return NULL; - } -} -function getProjectData($project = NULL) { - if (! isset ( $project )) { - $project = $_GET ['id']; - } - $req = $GLOBALS ['bdd']->prepare ( 'SELECT p.ID AS ID ,' . ' ' . 'p.name AS name ,' . ' ' . 'p.permissions AS permissions ,' . ' ' . 'p.ownersID AS owners' . ' ' . 'FROM projets AS p' . ' ' . 'WHERE p.ID = ?' ); - $req->execute ( array ( - $project - ) ); - if (($data = $req->fetch ())) { - $req->closeCursor (); - return $data; - } else { - $req->closeCursor (); - return NULL; - } -} -function getPermissions($data) { - $permissions = array ( - FALSE, - FALSE, - FALSE, - FALSE - ); - $permissions [0] = preg_match ( '#^1#', $data ['permissions'] ); - $permissions [1] = preg_match ( '#^(0|1)1#', $data ['permissions'] ); - $permissions [2] = preg_match ( '#^(0|1){2}1#', $data ['permissions'] ); - $permissions [3] = preg_match ( '#^(0|1){3}1#', $data ['permissions'] ); - return $permissions; -} -function getProjectsWithFirstPermission() { - $requete = 'SELECT p.ID AS projectID , v.versionAbs AS versionAbs , p.name AS projectName , v.version AS versionName ' . 'FROM projets AS p ' . 'INNER JOIN versions AS v ' . 'ON v.project_id = p.ID ' . 'WHERE p.permissions LIKE "1%" '; - $req = $GLOBALS ['bdd']->query ( $requete ); - $projects = array (); - - while ( $rep = $req->fetch () ) { - if (! isset ( $projects [$rep ['projectID']] )) { - $projects [$rep ['projectID']] = $rep; - } else if ($projects [$rep ['projectID']] ['versionAbs'] < $rep ['versionAbs']) { - $projects [$rep ['projectID']] = $rep; - } - } - $req->closeCursor (); - return $projects; -} -function getVersions($pid = NULL) { - if (! isset ( $pid )) { - $pid = $_GET ['id']; - } - - $requete = 'SELECT * FROM versions WHERE project_id = ?'; - $req = $GLOBALS ['bdd']->prepare ( $requete ); - $req->execute ( array ( - $pid - ) ); - // ADDPOINT langage - $versions = array ( - array (), - array () - ); - while ( $rep = $req->fetch () ) { - $versions [$rep ['language']] [] = array ( - 'versionAbs' => $rep ['versionAbs'], - 'versionName' => $rep ['version'] - ); - } - $req->closeCursor (); - return $versions; -} -function getOwnersisProjects($sid = NULL) { - if (! isset ( $sid )) { - $sid = $_SESSION ['session_id']; - } - $requete = 'SELECT p.ownersID AS ownersID , p.ID AS projectID , v.versionAbs AS versionAbs , p.name AS projectName , v.version AS versionName ' . 'FROM projets AS p ' . 'INNER JOIN versions AS v ' . 'ON v.project_id = p.ID ' . 'WHERE p.ownersID REGEXP \'[^0-9]?' . $sid . '[^0-9]?\' '; - $req = $GLOBALS ['bdd']->query ( $requete ); - $projects = array (); - while ( $rep = $req->fetch () ) { - if (! isset ( $projects [$rep ['projectID']] )) { - $projects [$rep ['projectID']] = $rep; - } else if ($projects [$rep ['projectID']] ['versionAbs'] < $rep ['versionAbs']) { - $projects [$rep ['projectID']] = $rep; - } - } - return $projects; -} -function registerPerson($pseudo, $mdp) { - $req = $GLOBALS ['bdd']->prepare ( "SELECT * FROM users WHERE pseudo=?" ); - $req->execute ( array ( - $_POST ['pseudo'] - ) ); - if ($req->fetch ()) { - return 'usedPseudo'; - } else { - $req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO users(pseudo,mdp,date_creation) VALUES (?,?,NOW())' ); - $req->execute ( array ( - $_POST ['pseudo'], - password_hash ( $_POST ['mdp'], PASSWORD_DEFAULT ) - ) ); - return 'ok'; - } -} -function getMessages($discut = NULL) { - if (! isset ( $discut )) { - $discut = $_GET ['d']; - } - $req = $GLOBALS ['bdd']->prepare ( "SELECT * FROM messages WHERE discussion_id=? ORDER BY sendTime DESC" ); - $req->execute ( array ( - $discut - ) ); - $rep = array (); - while ( $rep [] = $req->fetch () ) - ; - if (count ( $rep ) <= 0) - $rep = NULL; - $req->closeCursor (); - return array_slice ( $rep, 0, - 1, TRUE ); -} -function getDiscuts() { - $req = $GLOBALS ['bdd']->query ( "SELECT * FROM discussions ORDER BY date_creation DESC" ); - $rep = array (); - while ( $rep [] = $req->fetch () ) - ; - if (count ( $rep ) <= 1) - $rep = NULL; - $req->closeCursor (); - return array_slice ( $rep, 0, - 1, TRUE ); -} -function getDiscutInfos($did = NULL) { - if(!isset($did)){ - $did = $_GET['d']; - } - $req = $GLOBALS ['bdd']->query ( "SELECT * FROM discussions WHERE ID=?" ); - return $req->fetch(); -} -function sendMessage($discut = NULL, $text = NULL, $sender = NULL) { - if (! isset ( $discut ) || ! isset ( $text ) || ! isset ( $sender )) { - $discut = $_GET ['d']; - $text = $_POST ['msg']; - $sender = $_SESSION ['session_id']; - } - $req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO messages(discussion_id,texte,senderID,sendTime) VALUES (?,?,?,NOW())' ); - $req->execute ( array ( - $discut, - htmlspecialchars ( $text ), - $sender - ) ); - return 'ok'; -} -function createDiscut($name = NULL, $owner = NULL) { - if (! isset ( $name ) || ! isset ( $owner )) { - $name = $_POST ['name']; - $owner = $_SESSION ['session_id']; - } - $req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO discussions(name,creator_id,date_creation) VALUES (?,?,NOW())' ); - $req->execute ( array ( - $name, - $owner - ) ); - return 'ok'; -} diff --git a/nombre univers.cpp b/nombre univers.cpp new file mode 100644 index 0000000..fc91cef --- /dev/null +++ b/nombre univers.cpp @@ -0,0 +1,11 @@ +#include