NOUVELLE VERSION !!! Des nouvelles classes de partout, et des supers procédures SQL.

This commit is contained in:
Mysaa 2021-06-06 13:03:33 +02:00
parent e59898b0bb
commit 3488323439
59 changed files with 2906 additions and 1403 deletions

View File

@ -26,7 +26,7 @@ if ($me->isAdminLevelLowerThan ( 15 )) {
<div class="commanderCommandSelector">
Commande :
<select id="commandSelector">
<option value="get" selected="selected">get</option>
<option value="get" selected="true">get</option>
<option value="set">set</option>
<option value="remove">remove</option>
<option value="add">add</option>
@ -53,7 +53,7 @@ if ($me->isAdminLevelLowerThan ( 15 )) {
<div class="commander" id="addCommander" style="display: none;">
Sujet :
<select id="addClassSelector">
<option value="membre" selected="selected">Membre</option>
<option value="membre" selected="true">Membre</option>
<option value="discussion">Discussion</option>
<option value="message">Message</option>
<option value="projet">Projet</option>
@ -63,10 +63,10 @@ if ($me->isAdminLevelLowerThan ( 15 )) {
<div class="addDivAttribute" id="addDivAttributeMembre" style="display: block;">
<span>Pseudo :<input type="text" class="addCommanderAttribute pseudo" alt="Un pseudonyme valide" title="Un pseudonyme valide"/></span><br/>
<span>Mot de passe :<input type="text" class="addCommanderAttribute mdp" alt="Un mot de passe valide" title="Un mot de passe valide"/></span><br/>
<span>Email :<input type="text" class="addCommanderAttribute email" alt="Une adresse mail valide (outrepasse la v<EFBFBD>rification)" title="Une adresse mail valide (outrepasse la v&eacute;rification)"/></span><br/>
<span>Email :<input type="text" class="addCommanderAttribute email" alt="Une adresse mail valide (outrepasse la vérification)" title="Une adresse mail valide (outrepasse la v&eacute;rification)"/></span><br/>
<span class="facultatif">Date de cr&eacute;ation :<input type="text" class="addCommanderAttribute dateCreation" alt="Une date Mysql valide (AAAA-MM-JJ hh:mm:ss), si vide, la date de r&eacute;ception de la requ&ecirc;te" title="Une date Mysql valide (AAAA-MM-JJ hh:mm:ss), si vide, la date de r&eacute;ception de la requ&ecirc;te"/></span><br/>
<span class="facultatif">Banni&egrave;re :<input type="text" class="addCommanderAttribute banniere" alt="Un chemin vers une image, si vide, alors utilise la banni&egrave;re de base" title="Un chemin vers une image, si vide, alors utilise la banni&egrave;re de base"/></span><br/>
<span class="facultatif">Message :<input type="text" class="addCommanderAttribute message" alt="Une chaine de caract&egrave;res, si vide, aucun message ne sera affich<EFBFBD>" title="Une chaine de caract&egrave;res, si vide, aucun message ne sera affich&eacute;"/></span><br/>
<span class="facultatif">Message :<input type="text" class="addCommanderAttribute message" alt="Une chaine de caract&egrave;res, si vide, aucun message ne sera affiché" title="Une chaine de caract&egrave;res, si vide, aucun message ne sera affich&eacute;"/></span><br/>
</div>
<div class="addDivAttribute" id="addDivAttributeDiscussion" style="display: none;">
@ -113,7 +113,7 @@ if ($me->isAdminLevelLowerThan ( 15 )) {
<div class="commander" id="bddCommander" style="display: none;">
Action :
<select id="bddActionSelector">
<option value="sort" selected="selected">Sort</option>
<option value="sort" selected="true">Sort</option>
<option value="save">Save</option>
<option value="retieve">Retieve</option>
</select><br/>

27
clazz/2/Article.class.php Normal file
View File

@ -0,0 +1,27 @@
<?php
class Article {
public static function getNewest($count){
$req = $GLOBALS['bdd']->prepare('SELECT * FROM articles ORDER BY lastNoticeableChangeDate DESC LIMIT '.intval($count));
$req->execute();
$reps = array();
while($rep = $req->fetch()){
$reps[] = array();
$reps[count($reps)-1]['title'] = $rep['title'];
$reps[count($reps)-1]['short'] = $rep['short'];
$reps[count($reps)-1]['text'] = $rep['text'];
$reps[count($reps)-1]['picPath'] = $rep['picPath'];
}
return $reps;
}
}

View File

@ -0,0 +1,88 @@
<?php
class Discussion{
public static function createDiscussion($sid,$mdp,$name){
$sid = intval($pseudo);
$mdp = PDO::quote(strval($mdp));
$name = PDO::quote(strval($name));
$rep = $GLOBALS['bdd']->exec('CALL `CreateDiscussion`('.$sid.','.$mdp.','.$name.', @p3 , @p4); SELECT @p3 AS ndiscutID , ID AS outputCode , errorMessage AS message , htmlErrorMessage AS htmlMessage FROM errorReturns WHERE ID = @p4;')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode'],$rep['message'],$rep['htmlMessage']);
return $rep['ndiscutId'];
}
public static function getMessages($sid,$mdp,$did){
$GLOBALS['bdd']->exec('CREATE TEMPORARY TABLE smz (ID INT,senderID INT,senderPseudo VARCHAR(255),texte TEXT,sendTime DATETIME,rights INT(1))');
$req = $GLOBALS['bdd']->prepare('CALL `GetDiscutMessages`(:sid,:mdp,:did, @o)');
$req->bindValue(':sid', $sid);
$req->bindValue(':mdp', $mdp);
$req->bindValue(':did', $did);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
$req = $GLOBALS['bdd']->query('SELECT * FROM smz');
$jmsgs = array();
while($rep=$req->fetch()){
$jmsg = array();
$jmsg['messageID'] = $rep['ID'];
$jmsg['senderID'] = $rep['senderID'];
$jmsg['pseudo'] = $rep['senderPseudo'];
$jmsg['texte'] = $rep['texte'];
$jmsg['sendTime'] = $rep['sendTime'];
$jmsg['sendTimestamp'] = strToTime($rep['sendTime']);
$jmsg['rights'] = $rep['rights'] == 1;
$jmsgs[] = $jmsg;
}
return $jmsgs;
}
public static function getVisibleDiscuts($sid,$mdp){
$GLOBALS['bdd']->exec('CREATE TEMPORARY TABLE discuts (ID INT,name VARCHAR(255),creatorPseudo VARCHAR(255))');
//$rep = $GLOBALS['bdd']->exec('INSERT @t');
$req = $GLOBALS['bdd']->prepare('CALL `GetVisibleDiscuts`(:sid, :mdp, @o, @canCreate)');
$req->bindValue(':sid', $sid);
$req->bindValue(':mdp', $mdp);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode, @canCreate AS canCreate')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
$out = array();
$out['canCreate'] = $rep['canCreate'] == 1;
$req = $GLOBALS['bdd']->query('SELECT * FROM discuts');
$out['discuts'] = array();
while($rep = $req->fetch()){
$dout = array();
$dout['ID'] = intval($rep['ID']);
$dout['name'] = $rep['name'];
$dout['creatorPseudo'] = $rep['creatorPseudo'];
$out['discuts'][] = $dout;
}
return $out;
}
public static function getDiscutInfo($sessionID,$sessionPassword,$did){
$req = $GLOBALS['bdd']->prepare('CALL `GetDiscutInfo`(:ssi,:ssp,:did,@o,@c);');
$req->bindValue(':ssi', $sessionID);
$req->bindValue(':ssp', $sessionPassword);
$req->bindValue(':did', $did);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode, @c AS connected')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
$out = array();
$out['connected'] = $rep['connected'] == 1;
$out['ID'] = intval($did);
return $out;
}
const MALFORMED_DATE = 'La date de cr&eacute;ation doit &ecirc;tre de la forme "AAAA:MM:JJ hh:mm:ss"';
const DATE_CREATION_CHANGED = 'La date de cr&eacute;ation a bien &eacute;t&eacute; chang&eacute;e';
}

88
clazz/2/Langage.class.php Normal file
View File

@ -0,0 +1,88 @@
<?php
class Langage{
//FIXME const
public static $java;
public static $vba;
public static $languages = array();
protected $ID;
protected $name;
protected $avalivableFiles;//String "jar xlsx javadoc" in constructor , stored as a string array
public function __construct($ID,$name,$avalivableFiles){
$this->ID = $ID;
$this->name = $name;
$this->avalivableFiles = explode(" ",$avalivableFiles);
Langage::$languages[] = $this;
}
public function getID(){
return $this->ID;
}
public function getName(){
return $this->name;
}
public function getAvalivableFiles(){
return $this->avalivableFiles;
}
public function isJarAvalivable(){
return in_array("jar",$this->avalivableFiles);
}
public function isJavaAvalivable(){
return in_array("java",$this->avalivableFiles);
}
public function isJavadocAvalivable(){
return in_array("javadoc",$this->avalivableFiles);
}
public function isXlsmAvalivable(){
return in_array("xlsm",$this->avalivableFiles);
}
public function isVbAvalivable(){
return in_array("vb",$this->avalivableFiles);
}
public function isJarAccessible($fileAccessibility){
return $this->isJarAvalivable() AND ($fileAccessibility >> array_search("jar",$this->avalivableFiles)) % 2 === 1;
}
public function isJavaAccessible($fileAccessibility){
return $this->isJavaAvalivable() AND ($fileAccessibility >> array_search("java",$this->avalivableFiles)) % 2 === 1;
}
public function isJavadocAccessible($fileAccessibility){
return $this->isJavadocAvalivable() AND ($fileAccessibility >> array_search("javadoc",$this->avalivableFiles)) % 2 === 1;
}
public function isXlsmAccessible($fileAccessibility){
return $this->isXlsmAvalivable() AND ($fileAccessibility >> array_search("xlsm",$this->avalivableFiles)) % 2 === 1;
}
public function isVbAccessible($fileAccessibility){
return $this->isVbAvalivable() AND ($fileAccessibility >> array_search("vb",$this->avalivableFiles)) % 2 === 1;
}
public static function getFromID($ID){
foreach(Langage::$languages AS $language){
if($language->getID() == $ID)
return $language;
}
return NULL;
}
public static function getFromName($name){
foreach(Langage::$languages AS $language){
if($language->getName() == $name)
return $language;
}
return NULL;
}
public static function getLanguagesFromVersions($versions){
$languages = array();
foreach($versions AS $version)
array_push($languages,$version->getLanguage());
$languages = array_unique($languages,SORT_REGULAR);
return $languages;
}
}
Langage::$java = new Langage(0, "Java", "jar java javadoc");
Langage::$vba = new Langage(1, "VBA", "xlsm vb");

View File

@ -0,0 +1,327 @@
<?php
class Membre {
protected $ID;
protected $accountID;
protected $accountPassword;
protected $owner;
protected $liberties;// [ [ read , read ],[ write , write ] ]
protected $path;
protected $size;
protected $valid;
public function __construct($ID) {
$this->ID = $ID;
$req = $GLOBALS['bdd']->prepare('SELECT * FROM megaStockages WHERE ID=?');
$req->execute(array($ID));
if($rep = $req->fetch()){
$this->valid = TRUE;
$this->accountID = $rep['accountID'];
$this->accountPassword = $rep['accountPassword'];
$this->owner = new Membre($rep['owner']);
$this->liberties = /* TODO parse liberties */$rep['liberties'];
$this->path = $rep['path'];
$this->size = $rep['size'];
}else{
$this->valid = FALSE;
}
}
public function __toString(){
$out = 'MegaStockage\n';
$out .= '\tID:' . $this->ID . '\n';
$out .= '\tAccount ID:' . $this->accountID . '\n';
$out .= '\tAccount password' . $this->adminLevel . '\n';
$out .= '\tOwner:' . $this->owner->__toString() . '\n';
$out .= '\tLiberties:' . $this->liberties . '\n';
$out .= '\tPath:' . $this->path . '\n';
$out .= '\tSize:' . $this->size . '\n';
return $out;
}
public function exists(){
return $this->valid;
}
//Getters
//TODO gen getters
//Useful getters
public function canRead($he){
$read = $this->liberties[0];
if($read=='public')
return TRUE;
else if(in_array($he->getID(),$read))
return TRUE;
return FALSE;
}
public function canWrite($he){
$write = $this->liberties[1];
if($write=='public')
return TRUE;
else if(in_array($he->getID(),$write))
return TRUE;
return FALSE;
}
//Setters
public function setAttribute($attribute,$value,$valueType){
//TODO todo
$json=FALSE;
switch ($attribute){
case 'ID':
if($valueType !== '0'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($value);
break;
case 'pseudo':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'hashedPseudo':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'adminLevel':
if($valueType !== '0'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($value);
break;
case 'dateCreation':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.$value.'"';
break;
case 'requiredBanner'://FIXME jsonMysqlProblem
$json=TRUE;
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'personnalMessage':
$json=TRUE;
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
default:
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
exit;
}
$restrictionValues[] = $value;
if($json){
//TODO Set command for json
}else{
$command = 'UPDATE membres SET ' . $attribute . '=' . $value . ' WHERE ID=' . $this->ID;
}
echo $command.'</br>';
$req = $GLOBALS['bdd']->prepare($command);
$req->execute(array());
if($req->errorInfo()[0] != 0){
echo 'Eine MYSQL Exception hat geworft. Einschuldigung';
exit;
}
}
/**
*
* @return Objects which matchs the specified restrictions
*/
public static function getFromAttributes($restrictions){
$whereCommands = array();
$restrictionValues = array();
foreach ($restrictions as $restriction){
$whereCommand = NULL;
$attribute = $restriction[0];
$json = FALSE;
$operator = NULL;
$value = NULL;
try {
switch ($attribute){
case 'ID':
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'pseudo':
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'hashedPseudo':
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'adminLevel':
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'dateCreation':
if($restriction[2][0] !== '"'){//TODO add type date
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.$restriction[2][1].'"';
$operator = Utility::getDateSqlOperator($restriction[1]);
break;
case 'requiredBanner'://FIXME jsonMysqlProblem
$json=TRUE;
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'personnalMessage':
$json=TRUE;
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
default:
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
exit;
}
}catch(InvalidOperatorException $e){
echo $e->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 = "";
if(count($whereCommands) >0)
$wherePart = 'WHERE '.implode(' AND ',$whereCommands);
$command = 'SELECT * FROM membres '.$wherePart;
$req = $GLOBALS['bdd']->prepare($command);
$req->execute($restrictionValues);
echo $command.'</br>';
if($req->errorInfo()[0] != 0)
echo 'Erreur SQL, veuillez verifier les selecteurs';
$out = array();
while($rep = $req->fetch())
$out[] = new Membre($rep['ID']);
//Choose return value
switch(count($out)){
case 0:
return NULL;
case 1:
return $out[0];
default:
return $out;
}
}
public static function getFromPseudo($pseudo){
return Membre::getFromAttributes(array(['pseudo','=',['"',$pseudo]]));
}
public static function getFromAdminLevel($level){
return Membre::getFromAttributes(array(['adminLevel','=',['0',$level]]));
}
public static function getFromDateCreation($date){
return Membre::getFromAttributes(array(['dateCreation','=',['0',$date]]));
}
public static function getCreatedLaterThan($date){
return Membre::getFromAttributes(array(['dateCreation','>',['"',$date]]));
}
public static function getCreatedEarlierThan($date){
return Membre::getFromAttributes(array(['dateCreation','<',['"',$date]]));
}
public static function getAdminGreaterThan($min){
return Membre::getFromAttributes(array(['adminLevel','>',['0',$min]]));
}
public static function getAdminLowerThan($max){
return Membre::getFromAttributes(array(['adminLevel','<',['0',$max]]));
}
public static function me(){
if(!isset($_SESSION['session_id']))
return NULL;
$me = new Membre($_SESSION['session_id']);
if(!$me->exists())
return NULL;
return $me;
}
//Membre creator
public static function registerPerson($pseudo, $mdp) {
if (Membre::getFromPseudo($pseudo))
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::PERSON_REGISTERED;
}
//Operateurs
public function __is_identical($copain){
return $this->getID() == $copain->getID();
}
//Outputs texts
//changePassword
const PASSWORD_TOO_LONG = 'Le mot de passe est trop long ! (Max : 255 caract&egrave;res)';
const PASSWORD_CHANGED = 'Le mot de passe a bien &eacute;t&eacute; chang&eacute;';
//registerPerson
const USED_USERNAME = 'Le pseudonyme est d&eacute;j&agrave; utilis&eacute;';
const PERSON_REGISTERED = 'Le membre a bien &eacute;t&eacute; inscrit !';
}

75
clazz/2/Membre.class.php Normal file
View File

@ -0,0 +1,75 @@
<?php
class Membre {
const DEFAULT_BANNER = "pictures/bande.png";
public static function registerPerson($pseudo,$password){
$req = $GLOBALS['bdd']->prepare('CALL `RegisterPerson`(:ps,:pw,@o);');
$req->bindValue(':ps', $pseudo);
$req->bindValue(':pw', $password);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode, @sid AS membreId')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
}
public static function headerInfos($sessionID,$sessionPassword){
$req = $GLOBALS['bdd']->prepare('CALL `HeaderInfos`(:ssi,:ssp,@o,@c,@p);');
$req->bindValue(':ssi', $sessionID);
$req->bindValue(':ssp', $sessionPassword);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode, @c AS connected, @p AS pseudo')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
$out = array();
$out['connected'] = $rep['connected'] == 1;
$out['pseudo'] = $rep['pseudo'];
return $out;
}
public static function checkLogin($pseudo,$sessionPassword){
$req = $GLOBALS['bdd']->prepare('CALL `CheckLogin`(:ssps,:sspw,@o,@sid);');
$req->bindValue(':ssps', $pseudo);
$req->bindValue(':sspw', $sessionPassword);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode, @sid AS membreId')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
return $rep['membreId'];
}
public static function checkIdLogin($sid,$sessionPassword){
$req = $GLOBALS['bdd']->prepare('CALL `CheckIdLogin`(:sid,:sspw,@o);');
$req->bindValue(':sid', $sid);
$req->bindValue(':sspw', $sessionPassword);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
}
public static function changePassword($sid,$rmdp,$mdp){
var_dump($sid);
var_dump($rmdp);
var_dump($mdp);
$req = $GLOBALS['bdd']->prepare('CALL `ChangePassword`(:ssi,:rmdp,:nmdp,@o);');
$req->bindValue(':ssi', $sid);
$req->bindValue(':rmdp', $rmdp);
$req->bindValue(':nmdp', $mdp);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
}
}

32
clazz/2/Message.class.php Normal file
View File

@ -0,0 +1,32 @@
<?php
class Message{
public static function postMessage($sid,$mdp,$did,$text){
$req = $GLOBALS['bdd']->prepare('CALL `PostMessage`(:sid,:mdp,:did,:text,@o);');
$req->bindValue(':sid', $sid);
$req->bindValue(':mdp', $mdp);
$req->bindValue(':did', $did);
$req->bindValue(':text', $text);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
}
public static function deleteMessage($sid,$mdp,$mid){
$req = $GLOBALS['bdd']->prepare('CALL `DeleteMessage`(:sid,:mdp,:mid,@o);');
$req->bindValue(':sid', $sid);
$req->bindValue(':mdp', $mdp);
$req->bindValue(':mid', $mid);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
}
}

96
clazz/2/Projet.class.php Normal file
View File

@ -0,0 +1,96 @@
<?php
class Projet{
public static function getAuthorizedProjectsForPresentation($sid,$mdp){
$GLOBALS['bdd']->exec('CREATE TEMPORARY TABLE projects (projectID INT,projectName VARCHAR(255),versionID INT,versionName VARCHAR(255))');
//$rep = $GLOBALS['bdd']->exec('INSERT @t');
$req = $GLOBALS['bdd']->prepare('CALL `GetAuthorizedProjectsForPresentation`(:sid, :mdp, @o)');
$req->bindValue(':sid', $sid);
$req->bindValue(':mdp', $mdp);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
$req = $GLOBALS['bdd']->query('SELECT * FROM projects');
$out = array();
while($rep = $req->fetch()){
$pout = array();
$pout['projectID'] = $rep['projectID'];
$pout['projectName'] = $rep['projectName'];
$pout['versionID'] = $rep['versionID'];
$pout['versionName'] = $rep['versionName'];
$out[] = $pout;
}
return $out;
}
public static function getPublicProjectsForPresentation($sid,$mdp){
$GLOBALS['bdd']->exec('CREATE TEMPORARY TABLE projects (projectID INT,projectName VARCHAR(255),versionID INT,versionName VARCHAR(255))');
//$rep = $GLOBALS['bdd']->exec('INSERT @t');
$req = $GLOBALS['bdd']->prepare('CALL `GetPublicProjectsForPresentation`(:sid, :mdp, @o)');
$req->bindValue(':sid', $sid);
$req->bindValue(':mdp', $mdp);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
$req = $GLOBALS['bdd']->query('SELECT * FROM projects');
$out = array();
while($rep = $req->fetch()){
$pout = array();
$pout['projectID'] = $rep['projectID'];
$pout['projectName'] = $rep['projectName'];
$pout['versionID'] = $rep['versionID'];
$pout['versionName'] = $rep['versionName'];
$out[] = $pout;
}
return $out;
}
public static function showProject($sid,$mdp,$pid){
$GLOBALS['bdd']->exec('CREATE TEMPORARY TABLE verzions (language INT,ID INT,name VARCHAR(255));
CREATE TEMPORARY TABLE sowners (pseudo VARCHAR(255));');
$req = $GLOBALS['bdd']->prepare('CALL `PresentProject`(:sid, :mdp, :pid, @o, @public, @name, @ownerID, @ownerPseudo)');
$req->bindValue(':sid', $sid);
$req->bindValue(':mdp', $mdp);
$req->bindValue(':pid', $pid);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode,@public AS public,@name AS name,@ownerPseudo AS ownerPseudo,@ownerID AS ownerID')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
//Output
$out = array();
$out['public'] = $rep['public'] == 1;
$out['name'] = $rep['name'];
$out['ownerID'] = $rep['ownerID'];
$out['ownerPseudo'] = $rep['ownerPseudo'];
$req = $GLOBALS['bdd']->query('SELECT * FROM sowners');
$out['sowners'] = array();
while($rep = $req->fetch()){
$sowner = array();
$sowner['pseudo'] = $rep['pseudo'];
$out['sowners'][] = $sowner;
}
$req = $GLOBALS['bdd']->query('SELECT * FROM verzions');
$out['versions'] = array();
while($rep = $req->fetch()){
$version = array();
$version['language'] = $rep['language'];
$version['ID'] = $rep['ID'];
$version['name'] = $rep['name'];
$out['versions'][] = $version;
}
return $out;
}
}

View File

@ -0,0 +1,30 @@
<?php
class SQLProcessingException extends Exception{
private $errorCode;
private $Dmessage;
private $htmlMessage;
private $preferredRedirection;
public function __construct($errorCode){
$req = $GLOBALS['bdd']->prepare('SELECT errorMessage,htmlErrorMessage,preferredRedirection FROM errorReturns WHERE ID=?');
$req->execute(array(intval($errorCode)));
$rep = $req->fetch();
$this->errorCode = $errorCode;
$this->Dmessage = $rep['errorMessage'];
$this->htmlMessage = $rep['htmlErrorMessage'] ?? $rep['errorMessage'];
$this->preferredRedirection = (empty($rep['preferredRedirection'] != ""))?NULL:$rep['preferredRedirection'];
parent::__construct('Erreur '.$errorCode.' : '.$this->Dmessage);
error_log($this);
}
public function getPreferredRedirection(){
return $this->preferredRedirection;
}
public function getHtmlMessage(){
return $this->htmlMessage;
}
}

153
clazz/2/Utility.class.php Normal file
View File

@ -0,0 +1,153 @@
<?php
class InvalidOperatorException extends Exception{
public $type;
public $operator;
public function __construct ($type,$operator){
parent::__construct('Invalid operator "'.$operator.'" for the type '.$type);
}
}
class Utility{
/*
* <> 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);
}
}
public static function arrayIfNot($var){
if(!is_array($var))
return $var!=NULL?array($var):NULL;
return $var;
}
public static function getHierarchicCouple(){
return array("Pr&eacute;sident","Ministres");
}
public static function sqlProcedure($procedureName,$params,$output){
$Nparams = array();
$Oparams = array();
foreach($params AS $value)
switch(gettype($value)){
case 'boolean':$Nparams[]=($value)?'TRUE':'FALSE';break;
case 'integer':$Nparams[]=strval($value);break;
case 'double':$Nparams[]=strval($value);break;
case 'string':$Nparams[]=PDO::quote($value);break;
default:$Nparams[]='NULL';break;
}
for($i=0;$i<count($output);$i++){
$Nparams[]='@'.strval($i);
$Oparams[]='@'.strval($i).' AS '.PDO::quote($output[$i]);
}
$rep = $GLOBALS['bdd']->exec('CALL '.PDO::quote($procedureName).'('.implode($Nparams,',').'); SELECT @p2 AS `outputCode`;');
}
const SUCESSFULLY_REGISTERED = 'Vous avez d&eacute;j&agrave; &eacute;t&eacute; correctement inscrit sur bernard.com';
const SUCESSFULLY_LOGGED_IN = 'Vous &ecirc;tes bien connect&eacute; (vous l\'avez &eacute;t&eacute; et le serez &eacute;galement)!';
const SUCESSFULLY_CHANGED_PASSWORD = 'Vos dispositifs d\'identification ont &eacute;t&eacute; correctement chang&eacute;s';
const SUCESSFULLY_CREATED_DISCUSSION = 'C\'est fait !!! (la cr&eacute;ation de ta discussion bien s&ucirc;r)';
const LOGIN_NEEDED_FOR_PROJECTS = 'Je veut bien &ecirc;tre un site web parfait, mais j\'aimerai bien qut tu te conn&egrave;cte pour que je puisse te montrer tes projets';
}

58
clazz/2/Version.class.php Normal file
View File

@ -0,0 +1,58 @@
<?php
class Version{
public static function editVersion ($sid,$mdp,$v,$name,$langage,$tags,$insertIndex){
$sid = intval($sid);
$mdp = $GLOBALS['bdd']->quote(strval($mdp));
$v = intval($v);
$name = $name?$GLOBALS['bdd']->quote(strval($name)):'NULL';
$langage = $langage?intval($langage):'NULL';
$tags = $tags?$GLOBALS['bdd']->quote($tags):'NULL';
$insertIndex = $insertIndex?intval($insertIndex):'NULL';
$rep = $GLOBALS['bdd']->exec('CALL `EditVersion`('.$sid.','.$mdp.','.$v.','.$name.','.$langage.','.$tags.','.$insertIndex.', @p8); SELECT ID AS outputCode , errorMessage AS message , htmlErrorMessage AS htmlMessage FROM errorReturns WHERE ID = @p8;')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode'],$rep['message'],$rep['htmlMessage']);
}
public static function showVersion($sid,$mdp,$vid){
$GLOBALS['bdd']->exec('CREATE TEMPORARY TABLE verzions (language INT,ID INT,name VARCHAR(255));');
$req = $GLOBALS['bdd']->prepare('CALL `PresentVersion`(:sid, :mdp, :vid, @o, @su,@ssu,@langageID,@projectName,@name,@fileAccessibility,@projectID,@tags)');
$req->bindValue(':sid', $sid);
$req->bindValue(':mdp', $mdp);
$req->bindValue(':vid', $vid);
$req->execute();
$rep = $GLOBALS['bdd']->query('SELECT @o AS outputCode,@su AS su,@ssu AS ssu,@langageID AS langage,@projectName AS projectName,@name AS name,@fileAccessibility AS fileAccessibility,@projectID AS projectID,@tags AS tags')->fetch();
if($rep['outputCode'] != 42)throw new SQLProcessingException($rep['outputCode']);
//Output
$out = array();
$out['su'] = $rep['su'] == 1;
$out['ssu'] = $rep['ssu'] == 1;
$out['langage'] = $rep['langage'];
$out['projectName'] = $rep['projectName'];
$out['name'] = $rep['name'];
$out['ID'] = $vid;
$out['fileAccessibility'] = $rep['fileAccessibility'];
$out['projectID'] = $rep['projectID'];
$out['alpha'] = ($rep['tags'] >> 0) % 2 === 1;
$out['beta'] = ($rep['tags'] >> 1) % 2 === 1;
$out['release'] = ($rep['tags'] >> 2) % 2 === 1;
$out['bugged'] = ($rep['tags'] >> 3) % 2 === 1;
$req = $GLOBALS['bdd']->query('SELECT * FROM verzions');
$out['brothers'] = array();
while($rep = $req->fetch()){
$version = array();
$version['language'] = $rep['language'];
$version['ID'] = $rep['ID'];
$version['name'] = $rep['name'];
$out['brothers'][] = $version;
}
return $out;
}
}

20
clazz/2/Zincluder.php Normal file
View File

@ -0,0 +1,20 @@
<?php
try{
$link = mysql_connect("localhost", "u890869027", "*******************");
//$GLOBALS['bdd'] = new PDO('mysql:host=localhost;dbname=u890869027_bcom2;charset=utf8', 'u890869027', '*******************', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));error_reporting(E_ALL);
//$GLOBALS['bdd'] = new PDO('mysql:host=mysql.hostinger.fr;dbname=u890869027_bcom;charset=utf8', 'u890869027_bcom', '*******************');
}catch(Exception $e){
die ('Erreur : ' . $e->getMessage());
}
//TODO in the classes , do more test of exists in setters
include_once 'clazz/2/Utility.class.php';
include_once 'clazz/2/Langage.class.php';
include_once 'clazz/2/Membre.class.php';
include_once 'clazz/2/Discussion.class.php';
include_once 'clazz/2/Message.class.php';
include_once 'clazz/2/Projet.class.php';
include_once 'clazz/2/Article.class.php';
//TODO Use class's consts for file names
include_once 'clazz/2/Version.class.php';

View File

@ -1,47 +0,0 @@
<?php
class MegaFile{
protected $ID;
protected $where;
protected $args;
public function __construct($where,$args = array()){
$this->where = $where;
$this->args = $args;
}
public function is(){
$req = $GLOBALS['bdd']->prepare('SELECT COUNT(ID) AS count FROM megaFile WHERE ' . $where);//TODO changeto megaFileSSSSS
$req->execute($args);
return !!$req->fetch();
}
public static function addVersionFile($version,$fileType,$publicy){
try {
$path = '/Root/bernard.com/projets/' .
$version->getProject()->getName() . '/' .
$version->getLanguage()->getName() . '/' .
$version->getName().'/';
$pathFile = MegaFile::getFromPath($path);
if($pathFile->is())
return USED_PATH;
$pathFile = new MegaFile('fileType=? AND ');
if($pathFile->is())
return USED_PATH;
$req = $GLOBALS['bdd']->prepare('INSERT INTO megaFile (fileType,path,publicy) VALUES (?,?,?)');//TODO changeto megaFileSSSSS
$req->execute(array($fileType,$path,$publicy));
}catch(NoneObjectCallException $e){
return NONE_VERSION;
}
}
public static function getFromPath($path){
return new MegaFile('path=?',array($path));
}
public const NONE_VERSION = "sshfzrgh";
}

View File

@ -0,0 +1,327 @@
<?php
class Membre {
protected $ID;
protected $accountID;
protected $accountPassword;
protected $owner;
protected $liberties;// [ [ read , read ],[ write , write ] ]
protected $path;
protected $size;
protected $valid;
public function __construct($ID) {
$this->ID = $ID;
$req = $GLOBALS['bdd']->prepare('SELECT * FROM megaStockages WHERE ID=?');
$req->execute(array($ID));
if($rep = $req->fetch()){
$this->valid = TRUE;
$this->accountID = $rep['accountID'];
$this->accountPassword = $rep['accountPassword'];
$this->owner = new Membre($rep['owner']);
$this->liberties = /* TODO parse liberties */$rep['liberties'];
$this->path = $rep['path'];
$this->size = $rep['size'];
}else{
$this->valid = FALSE;
}
}
public function __toString(){
$out = 'MegaStockage\n';
$out .= '\tID:' . $this->ID . '\n';
$out .= '\tAccount ID:' . $this->accountID . '\n';
$out .= '\tAccount password' . $this->adminLevel . '\n';
$out .= '\tOwner:' . $this->owner->__toString() . '\n';
$out .= '\tLiberties:' . $this->liberties . '\n';
$out .= '\tPath:' . $this->path . '\n';
$out .= '\tSize:' . $this->size . '\n';
return $out;
}
public function exists(){
return $this->valid;
}
//Getters
//TODO gen getters
//Useful getters
public function canRead($he){
$read = $this->liberties[0];
if($read=='public')
return TRUE;
else if(in_array($he->getID(),$read))
return TRUE;
return FALSE;
}
public function canWrite($he){
$write = $this->liberties[1];
if($write=='public')
return TRUE;
else if(in_array($he->getID(),$write))
return TRUE;
return FALSE;
}
//Setters
public function setAttribute($attribute,$value,$valueType){
//TODO todo
$json=FALSE;
switch ($attribute){
case 'ID':
if($valueType !== '0'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($value);
break;
case 'pseudo':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'hashedPseudo':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'adminLevel':
if($valueType !== '0'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($value);
break;
case 'dateCreation':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.$value.'"';
break;
case 'requiredBanner'://FIXME jsonMysqlProblem
$json=TRUE;
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'personnalMessage':
$json=TRUE;
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
default:
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
exit;
}
$restrictionValues[] = $value;
if($json){
//TODO Set command for json
}else{
$command = 'UPDATE membres SET ' . $attribute . '=' . $value . ' WHERE ID=' . $this->ID;
}
echo $command.'</br>';
$req = $GLOBALS['bdd']->prepare($command);
$req->execute(array());
if($req->errorInfo()[0] != 0){
echo 'Eine MYSQL Exception hat geworft. Einschuldigung';
exit;
}
}
/**
*
* @return Objects which matchs the specified restrictions
*/
public static function getFromAttributes($restrictions){
$whereCommands = array();
$restrictionValues = array();
foreach ($restrictions as $restriction){
$whereCommand = NULL;
$attribute = $restriction[0];
$json = FALSE;
$operator = NULL;
$value = NULL;
try {
switch ($attribute){
case 'ID':
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'pseudo':
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'hashedPseudo':
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'adminLevel':
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'dateCreation':
if($restriction[2][0] !== '"'){//TODO add type date
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.$restriction[2][1].'"';
$operator = Utility::getDateSqlOperator($restriction[1]);
break;
case 'requiredBanner'://FIXME jsonMysqlProblem
$json=TRUE;
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'personnalMessage':
$json=TRUE;
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
default:
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
exit;
}
}catch(InvalidOperatorException $e){
echo $e->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 = "";
if(count($whereCommands) >0)
$wherePart = 'WHERE '.implode(' AND ',$whereCommands);
$command = 'SELECT * FROM membres '.$wherePart;
$req = $GLOBALS['bdd']->prepare($command);
$req->execute($restrictionValues);
echo $command.'</br>';
if($req->errorInfo()[0] != 0)
echo 'Erreur SQL, veuillez verifier les selecteurs';
$out = array();
while($rep = $req->fetch())
$out[] = new Membre($rep['ID']);
//Choose return value
switch(count($out)){
case 0:
return NULL;
case 1:
return $out[0];
default:
return $out;
}
}
public static function getFromPseudo($pseudo){
return Membre::getFromAttributes(array(['pseudo','=',['"',$pseudo]]));
}
public static function getFromAdminLevel($level){
return Membre::getFromAttributes(array(['adminLevel','=',['0',$level]]));
}
public static function getFromDateCreation($date){
return Membre::getFromAttributes(array(['dateCreation','=',['0',$date]]));
}
public static function getCreatedLaterThan($date){
return Membre::getFromAttributes(array(['dateCreation','>',['"',$date]]));
}
public static function getCreatedEarlierThan($date){
return Membre::getFromAttributes(array(['dateCreation','<',['"',$date]]));
}
public static function getAdminGreaterThan($min){
return Membre::getFromAttributes(array(['adminLevel','>',['0',$min]]));
}
public static function getAdminLowerThan($max){
return Membre::getFromAttributes(array(['adminLevel','<',['0',$max]]));
}
public static function me(){
if(!isset($_SESSION['session_id']))
return NULL;
$me = new Membre($_SESSION['session_id']);
if(!$me->exists())
return NULL;
return $me;
}
//Membre creator
public static function registerPerson($pseudo, $mdp) {
if (Membre::getFromPseudo($pseudo))
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::PERSON_REGISTERED;
}
//Operateurs
public function __is_identical($copain){
return $this->getID() == $copain->getID();
}
//Outputs texts
//changePassword
const PASSWORD_TOO_LONG = 'Le mot de passe est trop long ! (Max : 255 caract&egrave;res)';
const PASSWORD_CHANGED = 'Le mot de passe a bien &eacute;t&eacute; chang&eacute;';
//registerPerson
const USED_USERNAME = 'Le pseudonyme est d&eacute;j&agrave; utilis&eacute;';
const PERSON_REGISTERED = 'Le membre a bien &eacute;t&eacute; inscrit !';
}

View File

@ -1,720 +0,0 @@
<?php
class Membre {
const DEFAULT_BANNER = "pictures/bande.png";
protected $ID = NULL;
protected $IDLoaded = FALSE;
protected $pseudo = NULL;
protected $pseudoLoaded = FALSE;
protected $hashedPassword = NULL;
protected $hashedPasswordLoaded = FALSE;
protected $adminLevel = NULL;
protected $adminLevelLoaded = FALSE;
protected $dateCreation = NULL;
protected $dateCreationLoaded = FALSE;
protected $requiredBanner = NULL;
protected $requiredBannerLoaded = FALSE;
protected $personnalMessage;
protected $personnalMessageLoaded = FALSE;
protected $count = NULL;
protected $where;
protected $whereArgs;
protected const ATTRIBUTES = array('ID','pseudo','hashedPassword','dateCreation','adminLevel','data');
protected function __construct($where,$whereArgs = array()) {
$this->where = $where;
$this->whereArgs = $whereArgs;
}
public static function me(){
if(!isset($_SESSION['session_id']))
return NO_SESSION_ID;
return new Membre('WHERE ID=?');
}
public static function getFromAttributes($restrictions){
$whereCommands = array();
$restrictionValues = array();
foreach ($restrictions as $restriction){
$whereCommand = NULL;
$attribute = $restriction[0];
$json = FALSE;
$operator = NULL;
$value = NULL;
try {
switch ($attribute){
case 'ID':
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'pseudo':
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'hashedPseudo':
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'adminLevel':
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'dateCreation':
if($restriction[2][0] !== '"'){//TODO add type date
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.$restriction[2][1].'"';
$operator = Utility::getDateSqlOperator($restriction[1]);
break;
case 'requiredBanner'://FIXME jsonMysqlProblem
$json=TRUE;
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'personnalMessage':
$json=TRUE;
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
default:
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
exit;
}
}catch(InvalidOperatorException $e){
echo $e->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 = "";
if(count($whereCommands) >0)
$wherePart = 'WHERE '.implode(' AND ',$whereCommands);
$command = 'SELECT * FROM membres '.$wherePart;
$req = $GLOBALS['bdd']->prepare($command);
$req->execute($restrictionValues);
//echo $command.'</br>';
if($req->errorInfo()[0] != 0)
echo 'Erreur SQL, veuillez verifier les selecteurs';
$out = array();
while($rep = $req->fetch())
$out[] = new Membre($rep['ID']);
//Choose return value
switch(count($out)){
case 0:
return NULL;
case 1:
return $out[0];
default:
return $out;
}
}
public static function with($conditions){//[ { 'adminLevel' , '>=' , 24 } , { requiredBanner , '/home/banner.png' } , { email } ]
$wheres = array();
$whereAttributes = array();
foreach($conditions as $condition){
//TODO support custom conditions (OR, NAND)
//TODO test !is_array()
switch(count($condition)){
case 0:
throw new MalformedConditionException($conditions,'Une condition ne peut pas être NULL , voyons ...'));
break;
case 1:
assert(in_array($condition[0],Membre::ATTRIBUTES),new MalformedConditionException($conditions,'$condition[0] n\'est pas un attribut de la classe membre !'));
$wheres[] = $condition[0] . ' NOT NULL';
break;
case 2:
assert(in_array($condition[0],Membre::ATTRIBUTES),new MalformedConditionException($conditions,'$condition[0] n\'est pas un attribut de la classe membre !'));
$wheres[] = $condition[0] . ' = ?';
$whereAttributes[] = $condition[1];
break;
case 3:
assert(in_array($condition[0],Membre::ATTRIBUTES),new MalformedConditionException($conditions,'$condition[0] n\'est pas un attribut de la classe membre !'));
$operator = Utility::getSqlOperator($condition[2]);
assert($operator !== NULL,new MalformedConditionException($conditions,'$condition[2] n\'est pas un opérateur valide !'));
$wheres[] = $condition[0] . ' ' . $operator . ' ?';
$whereAttributes[] = $condition[1];
break;
default:
throw new MalformedConditionException($conditions,'Cette version du site ne comprends pas encore les conditions avec plus de trois paramètres (' . json_encode($condition); . ')');
}
}
$where = implode(' AND ',$wheres);
return new Membre($where,$whereAttributes);
}
public static function withPseudo($pseudo){
return new Membre('WHERE pseudo=?',array($pseudo));
}
public static function withAdminLevel($level){
return new Membre('WHERE adminLevel=?',array($level));
}
public static function withAdminLevelGreaterThan($level){
return new Membre('WHERE adminLevel>?',array($level));
}
public static function withAdminLevelLowerThan($level){
return new Membre('WHERE adminLevel<?',array($level));
}
public static function withDateCreation($date){
return new Membre('WHERE dateCreation=?',array($pseudo));
}
public static function withDateCreationLaterThan($date){
return new Membre('WHERE dateCreation>?',array($pseudo));
}
public static function withDateCreationEarlierThan($date){
return new Membre('WHERE dateCreation<?',array($pseudo));
}
public function checkPassword($password) {
return password_verify ($password, $this->getHashedPassword() );
}
public function __toString(){
return 'Membre with "' . $where . '" args:{' . $whereArgs . '}';
}
/**
@returns
Si le Membre est unique et que le dernier paramètre est faux (valeur par défaut)
@return [ 'ID' => 12 , 'pseudo' => "Mysaa" ]
Si le Membre est plurier ou si le dernier paramètre est vrai
@return [ { 'ID' => 12 , 'pseudo' => "Mysaa" } , { 'ID' => 11 , 'pseudo' => "Zlopeg" } ]
**/
public function get(){
$objects = func_get_args();
assert(count($objects) < 1, new BadMethodCallException('La methode get requiert au moins un argument'));
$array = end($objects);
if(gettype($array) !== 'boolean')
$array=FALSE;
else
array_pop($objects);
assert(count($objectsCount) < 1, new BadMethodCallException('La methode get requiert au moins un nom de paramètre à retourner !'));
$toAsk = array();
$toGive = array();
foreach($objects as $object){
assert(!is_string($object), new InvalidArgumentException('"$object" n\'est pas une chaine de caractère ... ça devrait'))
assert(in_array($object,Membre::ATTRIBUTES),new InvalidArgumentException('$object n\'est pas un attribut de la classe membre !'));
if($this->{$object . 'Loaded'})
array_push($toGive,$object);
else
array_push($toAsk,$object);
}
$result = array();
if(count($toAsk)>0){
$req = $GLOBALS['bdd']->prepare('SELECT ' . implode(',',$toAsk) . 'FROM membres WHERE ' . $this->where);
$req->execute($this->whereArgs);
$sqlResult = $req->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_GROUP);
foreach($toAsk as $item){
if(!isset($this->count))$this->count = count($item);
$this->$item = $sqlResult[$item];
$this->{$item . 'Loaded'} = TRUE;
$result[$item] = $sqlResult[$item];
}
}
foreach($toGive as $item)
$result[$item] = $this->$item;
/* RETURN */
if(count($result) === 0)
return $array?array():NULL;
$return = array()
if(!$array AND $this->count === 1)
foreach($result as $item => $values)$return[$key] = $values[0];
else
foreach($result as $key=>$res)
for($i=0;$i<$this->count;$i++)
$return[$i][$key] = $res[$i]
return $return;
}
public function count(){
if($this->count)return $this->count;
$req = $GLOBALS['bdd']->prepare('SELECT COUNT(*) AS count FROM membres WHERE ' . $this->where);
$req->execute($this->whereArgs);
return $req->fetch()['count'];
}
public function __call($funcName,$params){
if(preg_match('^get',$funcName)){// TODO Support multi get ("getPseudoAndAdminLevel")
$attributeName = lcfirst(substr($funcName,3))
assert(in_array($attributeName,Membre::ATTRIBUTES), new BadMethodCallException('$attributeName n\'est pas un attribut de la classe membre !'));
$return = call_user_func_array(array($this,'get'),array($attributeName));
return (count($return)===1)?$return[0]:$return;
}
}
public function get(){
$objects = func_get_args();
assert(count($objects) < 2, new BadMethodCallException('La methode set requiert au moins deux argument'));
$objectsCount = count($objects);
assert($objectsCount % 2 === 0, new BadMethodCallException('La methode set requiert un nombre pair d\'arguments'));
foreach($objects as $object){
assert(!is_string($object), new InvalidArgumentException('"$object" n\'est pas une chaine de caractère ... ça devrait'))
assert(in_array($object,Membre::ATTRIBUTES),new InvalidArgumentException('$object n\'est pas un attribut de la classe membre !'));
if($this->{$object . 'Loaded'})//FIXME to complete get -> set
array_push($toGive,$object);
else
array_push($toAsk,$object);
}
$result = array();
if(count($toAsk)>0){
$req = $GLOBALS['bdd']->prepare('SELECT ' . implode(',',$toAsk) . 'FROM membres WHERE ' . $this->where);
$req->execute($this->whereArgs);
$sqlResult = $req->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_GROUP);
foreach($toAsk as $item){
if(!isset($this->count))$this->count = count($item);
$this->$item = $sqlResult[$item];
$this->{$item . 'Loaded'} = TRUE;
$result[$item] = $sqlResult[$item];
}
}
foreach($toGive as $item)
$result[$item] = $this->$item;
/* RETURN */
if(count($result) === 0)
return $array?array():NULL;
$return = array()
if(!$array AND $this->count === 1)
foreach($result as $item => $values)$return[$key] = $values[0];
else
foreach($result as $key=>$res)
for($i=0;$i<$this->count;$i++)
$return[$i][$key] = $res[$i]
return $return;
}
private function decodeData($data) {
$jsonData = json_decode ( $data ,TRUE);
// Set the data's required_banner if it is defined , otherwise sets the DEFAULT_BANNER
$this->requiredBanner = $jsonData ['requiredBanner'] ?? self::DEFAULT_BANNER;
$this->personnalMessage = $jsonData ['personnalMessage'] ?? NULL;
}
//Getters
public function getID(){
return $this->ID;
}
public function getPseudo(){
return $this->pseudo;
}
public function getAdminLevel() {
return $this->adminLevel;
}
public function getDateCreation(){
return $this->dateCreation;
}
public function getRequiredBanner() {
return $this->requiredBanner;
}
public function getPersonnalMessage(){
return $this->personnalMessage;
}
//Useful getters
public function isAdminLevelLowerThan($max){
return $this->adminLevel<$max;
}
public function isAdminLevelGreaterThan($min){
return $this->adminLevel>$min;
}
public function isAdminLevelLowerOrEqualThan($max){
return $this->adminLevel<$max;
}
public function isAdminLevelGreaterOrEqualThan($min){
return $this->adminLevel>$max;
}
public function hasPersonnalMessage() {
return isset ( $this->personnalMessage );
}
public function showPersonnalMessage() {
$msg = $this->personnalMessage;
$this->setPersonnalMessage = NULL;
return $msg;
}
//Setters
public function changePassword($newPassword){
if(strlen($newPassword)>255)
return Membre::PASSWORD_TOO_LONG;
$req = $GLOBALS['bdd']->prepare('UPDATE membres SET hashedPassword=? WHERE ID=?');
$req->execute(array(password_hash ( $newPassword, PASSWORD_DEFAULT ),$this->ID));
return Membre::PASSWORD_CHANGED;
}
public function setAttribute($attribute,$value,$valueType){
$json=FALSE;
switch ($attribute){
case 'ID':
if($valueType !== '0'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($value);
break;
case 'pseudo':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'hashedPseudo':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'adminLevel':
if($valueType !== '0'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($value);
break;
case 'dateCreation':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.$value.'"';
break;
case 'requiredBanner'://FIXME jsonMysqlProblem
$json=TRUE;
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'personnalMessage':
$json=TRUE;
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
default:
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
exit;
}
$restrictionValues[] = $value;
if($json){
//TODO Set command for json
}else{
$command = 'UPDATE membres SET ' . $attribute . '=' . $value . ' WHERE ID=' . $this->ID;
}
echo $command.'</br>';
$req = $GLOBALS['bdd']->prepare($command);
$req->execute(array());
if($req->errorInfo()[0] != 0){
echo 'Eine MYSQL Exception hat geworft. Einschuldigung';
exit;
}
}
/**
*
* @return Objects which matchs the specified restrictions
*/
public static function getFromAttributes($restrictions){
$whereCommands = array();
$restrictionValues = array();
foreach ($restrictions as $restriction){
$whereCommand = NULL;
$attribute = $restriction[0];
$json = FALSE;
$operator = NULL;
$value = NULL;
try {
switch ($attribute){
case 'ID':
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'pseudo':
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'hashedPseudo':
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'adminLevel':
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'dateCreation':
if($restriction[2][0] !== '"'){//TODO add type date
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.$restriction[2][1].'"';
$operator = Utility::getDateSqlOperator($restriction[1]);
break;
case 'requiredBanner'://FIXME jsonMysqlProblem
$json=TRUE;
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'personnalMessage':
$json=TRUE;
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
default:
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
exit;
}
}catch(InvalidOperatorException $e){
echo $e->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 = "";
if(count($whereCommands) >0)
$wherePart = 'WHERE '.implode(' AND ',$whereCommands);
$command = 'SELECT * FROM membres '.$wherePart;
$req = $GLOBALS['bdd']->prepare($command);
$req->execute($restrictionValues);
//echo $command.'</br>';
if($req->errorInfo()[0] != 0)
echo 'Erreur SQL, veuillez verifier les selecteurs';
$out = array();
while($rep = $req->fetch())
$out[] = new Membre($rep['ID']);
//Choose return value
switch(count($out)){
case 0:
return NULL;
case 1:
return $out[0];
default:
return $out;
}
}
public static function getFromPseudo($pseudo){
return Membre::getFromAttributes(array(['pseudo','=',['"',$pseudo]]));
}
public static function getFromAdminLevel($level){
return Membre::getFromAttributes(array(['adminLevel','=',['0',$level]]));
}
public static function getFromDateCreation($date){
return Membre::getFromAttributes(array(['dateCreation','=',['0',$date]]));
}
public static function getCreatedLaterThan($date){
return Membre::getFromAttributes(array(['dateCreation','>',['"',$date]]));
}
public static function getCreatedEarlierThan($date){
return Membre::getFromAttributes(array(['dateCreation','<',['"',$date]]));
}
public static function getAdminGreaterThan($min){
return Membre::getFromAttributes(array(['adminLevel','>',['0',$min]]));
}
public static function getAdminLowerThan($max){
return Membre::getFromAttributes(array(['adminLevel','<',['0',$max]]));
}
//Membre creator
public static function registerPerson($pseudo, $mdp) {
if (Membre::getFromPseudo($pseudo))
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::PERSON_REGISTERED;
}
//Operateurs
public function __is_identical($copain){
return $this->getID() == $copain->getID();
}
//Outputs texts
const NO_SESSION_ID = 0;
//changePassword
const PASSWORD_TOO_LONG = 'Le mot de passe est trop long ! (Max : 255 caract&egrave;res)';
const PASSWORD_CHANGED = 'Le mot de passe a bien &eacute;t&eacute; chang&eacute;';
//registerPerson
const USED_USERNAME = 'Le pseudonyme est d&eacute;j&agrave; utilis&eacute;';
const PERSON_REGISTERED = 'Le membre a bien &eacute;t&eacute; inscrit !';
}

View File

@ -1,18 +0,0 @@
<?php
class NoneObjectCallException extends Exception
{
public function __construct($message, $code = 0)
{
parent::__construct($message, $code);
}
public function __construct($functionName, $className, $code = 0)
{
parent::__construct('You tried to call the function ' . $functionName . ' on a ' . $className . 'pointing on nothing. Try catch me the next time !', $code);
}
public function __toString()
{
return $this->message;
}
}

View File

@ -9,71 +9,57 @@ class InvalidOperatorException extends Exception{
}
class Utility{
public static const PasswordMissmatch = 'Tu auras du rentrer deux fois le m&ecirc;me mot de passe (tu permet aussi de rendre le champs "Recopier le mot de passe" utile)';
public static const InvalidPseudo = 'Le pseudo sera incorrect : Les seuls caract&egrave;res autoris&eacute;s sont :<br/>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
public static const InvalidPassword = 'Le mot de passe fut incorrect : Les seuls caract&egrave;res autoris&eacute;s sont :<br/>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_&&eacute;&egrave;&agrave;&ugrave;&ccedil;&mu;"#\'{}()[]|^@<40>+=$<24><>*!<21>:/;.,?<3F>'
public static function isPseudoValid($pseudo){
return preg_match ( "#^[a-zA-Z0-9\\-_]+$#", $pseudo ) === 1;
}
public static function isPasswordValid($password){
return preg_match ( "#^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\\-_&<26><><EFBFBD><EFBFBD><EFBFBD>\"\\#'{}()[\\]|\\^@<40>+=\$<EFBFBD><EFBFBD>*!<21>:/;.,?<3F>]+$#", $password ) === 1;
}
/*
* <> ou !=
...les deux valeurs ne sont pas égales
...les deux valeurs ne sont pas égales
<
...la valeur de gauche est strictement inférieure à celle de droite
...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 supérieure à celle de droite
<=
...la valeur de gauche est strictement inférieure ou égale à 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
...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
...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
...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
...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
...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
...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
...la valeur de gauche ne correspond pas à l'expression régulière donnée
*/
public static function getSqlOperator($operator){
switch ($operator){
case '=':
return '=';
case '<':
return '<';
case '>':
return '>';
case '<=':
return '<=';
case '>=':
return '>=';
case '=<':
return '<=';
case '<>':
return '<>';
case '!=':
return '!=';
case '!<':
return '!<';
case '!>':
return '!>';
default:
return NULL;
}
}
public static function getIntegerSqlOperator($operator){
switch ($operator){

View File

@ -1,19 +1,19 @@
<?php
try{
$GLOBALS['bdd'] = new PDO('mysql:host=localhost;dbname=u890869027_bcom;charset=utf8', 'u890869027', '*******************', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));error_reporting(E_ALL);
$GLOBALS['bdd'] = new PDO('mysql:host=127.0.0.1;dbname=u890869027_bcom;charset=utf8;port=3306', 'u890869027', '*******************', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));error_reporting(E_ALL);
//$GLOBALS['bdd'] = new PDO('mysql:host=mysql.hostinger.fr;dbname=u890869027_bcom;charset=utf8', 'u890869027_bcom', '*******************');
}catch(Exception $e){
die ('Erreur : ' . $e->getMessage());
}
//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';
include_once 'clazz/Article.class.php';
include_once 'clazz/2/SQLProcessingException.class.php';
include_once 'clazz/2/Utility.class.php';
include_once 'clazz/2/Langage.class.php';
include_once 'clazz/2/Membre.class.php';
include_once 'clazz/2/Discussion.class.php';
include_once 'clazz/2/Message.class.php';
include_once 'clazz/2/Projet.class.php';
include_once 'clazz/2/Article.class.php';
//TODO Use class's consts for file names
include_once 'clazz/Version.class.php';
include_once 'clazz/2/Version.class.php';

19
clazz/Zincluder_old.php Normal file
View File

@ -0,0 +1,19 @@
<?php
try{
$GLOBALS['bdd'] = new PDO('mysql:host=localhost;dbname=u890869027_bcom2;charset=utf8', 'u890869027', '*******************', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));error_reporting(E_ALL);
//$GLOBALS['bdd'] = new PDO('mysql:host=mysql.hostinger.fr;dbname=u890869027_bcom;charset=utf8', 'u890869027_bcom', '*******************');
}catch(Exception $e){
die ('Erreur : ' . $e->getMessage());
}
//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';
include_once 'clazz/Article.class.php';
//TODO Use class's consts for file names
include_once 'clazz/Version.class.php';

View File

@ -1,7 +0,0 @@
<?php session_start();
unset($_SESSION['session_id']);
unset($_SESSION['session_mdp']);
header('Location:index.php');
$_SESSION['current_error'] = 'La d&eacute;connexion se sera correctement pass&eacutee!';
?>

View File

@ -1,5 +1,20 @@
<?php session_start ();
include_once 'clazz/Zincluder.php'; ?>
<?php
session_start();
include_once 'clazz/Zincluder.php';
try{
$discut = Discussion::getDiscutInfo($_SESSION['session_id'] ?? NULL,$_SESSION['session_mdp'] ?? NULL,$_GET['d'] ?? NULL);
}catch(SQLProcessingException $e){
error_log($e);
echo $e->getHtmlMessage();
$_SESSION ['current_error'] = $e->getHtmlMessage();
header ( 'Location:' . $e->getPreferredRedirection() ?? 'discuts.php' );
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
@ -10,25 +25,7 @@ include_once 'clazz/Zincluder.php'; ?>
<?php include 'includes/header.php'; ?>
<?php
//TODO re la fonction exiting
$me = Membre::me();
if(!isset($_GET['d'])){
header ( 'Location:discuts.php');
$_SESSION ['current_error'] = 'Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!';
exit;
}
$discut = new Discussion($_GET['d']);
if(!$discut->exists()){
header ( 'Location:discuts.php');
$_SESSION ['current_error'] = 'Je vais avoir du mal &agrave; afficher les don&eacute;es de la version n&eacute;ant ...';
exit;
}
if($me?!$discut->canAccess($me):!$discut->isPublic()){
header ( 'Location:discuts.php');
$_SESSION ['current_error'] = 'Vous n\'avez pas le droit d\'&ecirc;tre ici ...<br/> DEGAGEZ !!!';
exit;
}
if ($me) {?>
if ($discut['connected']) {?>
<form id="postMessageForm" action="executor.php?action=postMessage&amp;d=<?php echo $_GET['d'];?>" method="post">
<textarea row="5" placeholder="Votre message :" name="msg" autofocus="autofocus" required="required"></textarea>
<input type="submit" value="Poster le message">
@ -36,13 +33,14 @@ include_once 'clazz/Zincluder.php'; ?>
<!-- TODO : Entrée->envoyer le message (dégeulasse) -->
<script type="text/javascript">
function genListener(){
//Entrée -> envoi
$('#postMessageForm textarea').on('keypress',function(e){
if(e.which == 13){
$('#postMessageForm input').trigger('click');
e.stopPropagation();
}
});
//Entrée -> envoi
$('#postMessageForm textarea').on('keypress',function(e){
if(e.which == 13){
$('#postMessageForm input').trigger('click');
e.stopPropagation();
}
});
}
</script>
<?php }else{ ?>
<div>Vous devez vous connecter pour envoyer des messages !</div>
@ -84,8 +82,8 @@ include_once 'clazz/Zincluder.php'; ?>
var currentClock = null;
var askData = function(){
console.log('dataasked<?php echo $discut->getID();?>');
$.post('executor.php?action=getDiscutsMessages&d=<?php echo $discut->getID();?>',{},dataGet);
console.log('dataasked<?php echo $discut['ID'];?>');
$.post('executor.php?action=getDiscutsMessages&did=<?php echo $discut['ID'];?>',{},dataGet);
}
var dataGet = function(data,status){
var newData = eval(data);

View File

@ -1,6 +1,19 @@
<?php
session_start ();
include_once 'clazz/Zincluder.php';?>
include_once 'clazz/Zincluder.php';
try{
$discuts = Discussion::getVisibleDiscuts($_SESSION['session_id'] ?? NULL,$_SESSION['session_mdp'] ?? NULL);
}catch(SQLProcessingException $e){
var_dump($e);
echo $e->getHtmlMessage();
$_SESSION ['current_error'] = $e->getHtmlMessage();
header ( 'Location:' . ($e->getPreferredRedirection() ?? 'index.php') );
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
@ -12,10 +25,8 @@ include_once 'clazz/Zincluder.php';?>
<br />
<?php
$me = Membre::me();
$discs = $me?Discussion::getWhichHeCanAccess($me):Discussion::getPublics();
foreach ($discs as $disc) {
echo '<a href="discut.php?d=' . $disc->getID() . '">' . $disc->getName() . ' par ' . $disc->getCreator()->getPseudo() . '</a><br/>';
foreach ($discuts['discuts'] as $discut) {
echo '<a href="discut.php?d=' . $discut['ID'] . '">' . $discut['name'] . ' par ' . $discut['creatorPseudo'] . '</a><br/>';
}
?>
@ -23,7 +34,7 @@ include_once 'clazz/Zincluder.php';?>
<?php if($me?$me->isAdminLevelGreaterThan(8):FALSE){?>
<?php if($discuts['canCreate']){?>
<span id="createNewDiscBefore">Creer une nouvelle discussion</span>
<form id="createNewDiscForm" action="executor.php?action=createDiscussion" method="post">

View File

@ -1,14 +1,21 @@
<?php
session_start ();
include_once 'clazz/Zincluder.php';
$me = Membre::me();
/*
TODO add $_GET['p'] => should return on $_SESSION ['current_error'] (0) or via echo (1)
*/
function exiting($message,$location='index.php'){
if($message instanceof SQLProcessingException){
echo $message->getMessage();
$_SESSION ['current_error'] = $message->getHtmlMessage();
}else if($message instanceof Exception){
echo $message->getMessage();
$_SESSION ['current_error'] = htmlSpecialChars($message->getMessage());
}else{
$_SESSION ['current_error'] = $message;
}
header ( 'Location:' . $location );
$_SESSION ['current_error'] = $message;
exit;
}
@ -18,406 +25,391 @@ if (! isset ( $_GET ['action'] ))
switch ($_GET ['action']) {
case 'disconnect' :
unset($_SESSION['session_id']);
unset($_SESSION['session_mdp']);
header('Location:index.php');//TODO lastpageredirection
$_SESSION['current_error'] = 'La d&eacute;connexion se sera correctement pass&eacutee!';
exit;
case 'register' :
//Action : register
if (!(isset ( $_POST ['pseudo'] ) && isset ( $_POST ['mdp'] ) && isset ( $_POST ['mdp2'] )))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
if ($_POST ['mdp'] === $_POST ['mdp2'])
exiting('Tu auras du rentrer deux fois le m&ecirc;me mot de passe (tu permet aussi de rendre le champs "Recopier le mot de passe" utile)');
if (preg_match ( "#^[a-zA-Z0-9\\-_]+$#", $_POST ['pseudo'] ))
exiting('Le pseudo sera incorrect : Les seuls caract&egrave;res autoris&eacute;s sont :<br/>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_');
if (preg_match ( "#^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\\-_&<26><><EFBFBD><EFBFBD><EFBFBD>\"\\#'{}()[\\]|\\^@<40>+=\$<EFBFBD><EFBFBD>*!<21>:/;.,?<3F>]+$#", $_POST ['mdp'] ))
exiting('Le mot de passe fut incorrect : Les seuls caract&egrave;res autoris&eacute;s sont :<br/>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_&&eacute;&egrave;&agrave;&ugrave;&ccedil;&mu;"#\'{}()[]|^@<40>+=$<24><>*!<21>:/;.,?<3F>');
$pseudo = $_POST ['pseudo'] ?? NULL;
$mdp = $_POST ['mdp'] ?? NULL;
$mdp2 = $_POST ['mdp2'] ?? NULL;
$out = Membre::registerPerson ($_POST ['pseudo'],$_POST ['mdp']);
if($out ===Membre::USED_USERNAME)
exiting('Le pseudonyme est d&eacute;j&agrave; utilis&eacute; (par une entit&eacute; differente de vous)');
exiting('Vous avez d&eacute;j&agrave; &eacute;t&eacute; correctement inscrit sur bernard.com','login.php');
try{
assert($pseudo,new MissingDataException('pseudo','POST'));
assert($mdp,new MissingDataException('mdp','POST'));
assert($mdp2,new MissingDataException('mdp2','POST'));
assert($mdp===$mdp2,new DataException('mdp and mdp2 should be equal'));
Membre::registerPerson ($pseudo,$mdp);
}catch(Exception $e){
exiting($e);
}
exiting(Utility::SUCESSFULLY_REGISTERED,'login.php');
case 'login' :
//Action : login
if (!( isset ( $_POST ['pseudo'] ) && isset ( $_POST ['mdp'] ) ))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
$me = Membre::getFromPseudo($_POST['pseudo']);
if(!$me)
exiting('Kik&egrave;tvou ? Pseudo inconnu ...');
if(!$me->connect($_POST ['mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$_SESSION['session_id'] = $me->getID();
$_SESSION['session_mdp'] = $_POST['mdp'];
exiting('Vous &ecirc;tes bien connect&eacute; (vous l\'avez &eacute;t&eacute; et le serez &eacute;galement)!');
$pseudo = $_POST ['pseudo'] ?? NULL;
$mdp = $_POST ['mdp'] ?? NULL;
try{
assert($pseudo,new MissingDataException('pseudo','POST'));
assert($mdp,new MissingDataException('mdp','POST'));
$_SESSION['session_id'] = Membre::checkLogin ($pseudo,$mdp);
$_SESSION['session_mdp'] = $mdp;
}catch(Exception $e){
exiting($e);
}
exiting(Utility::SUCESSFULLY_LOGGED_IN,'index.php');//TODO Do a "previousContentPageRedirection"
case 'changePassword' :
//Action : change password
if(!(isset($_POST['rmdp']) && isset($_POST['nmdp']) && isset($_POST['nmdp2'])))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
if(!$me)
exiting('Si tu ne te connectes pas, comment veut tu que je sache quel mot de passe changer !');
if(!$me->connect($_POST['rmdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
if($_POST['nmdp'] !== $_POST['nmdp2'])
exiting('Tu auras du rentrer deux fois le m&ecirc;me mot de passe (tu permet aussi de rendre le champs "Recopier le mot de passe" utile)');
$out = $me->changePassword($_POST['nmdp']);
if($out == Membre::PASSWORD_TOO_LONG)
exiting('Mot de passe &ne; roman (255 caract&egrave;res maximum)');
exiting('Vos dispositifs d\'identification ont &eacute;t&eacute; correctement chang&eacute;s');
$sid = $_SESSION ['session_id'] ?? NULL;
$rmdp = $_POST ['rmdp'] ?? NULL;
$mdp = $_POST ['nmdp'] ?? NULL;
$mdp2 = $_POST ['nmdp2'] ?? NULL;
var_dump($_POST);
try{
assert($rmdp,new MissingDataException('rmdp','POST'));
assert($mdp,new MissingDataException('mdp','POST'));
assert($mdp2,new MissingDataException('mdp2','POST'));
assert($mdp===$mdp2,new DataException('mdp and mdp2 should be equal'));
Membre::changePassword ($sid,$rmdp,$mdp);
}catch(Exception $e){
exiting($e);
}
exiting(Utility::SUCESSFULLY_CHANGED_PASSWORD,'login.php');
case 'createDiscussion' :
//Action : create discussion
if(!isset($_POST['name']))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
if(!$me)
exiting('Veuillez vous identifier pour acceder &agrave; cette section !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
if($me->isAdminLevelLowerThan(2))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 2 ou plus)');
$out = Discussion::createDiscussion($_POST ['name'],$_SESSION ['session_id']);
if($out === Discussion::NAME_ALREADY_USED)
exiting('Mince j\'ai d&eacute;j&agrave; utilis&eacute; l\'&eacute;criteau avec ce nom ... t\'en as pas un autre ?');
if($out === Discussion::ILLEGAL_NAME)
exiting('Y a des trucs qui ne me plaisent pas dans le nom que tu as donn&eacute; &agrave; ta discussion ...<br/>Je n\'accepte que les caract&egrave;res abcdefghijklmnopqrstuvwxyz<wbr/>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<wbr/>&eacute;&egrave;&agrave;&mu;_-\'()[\\]\\\\/<wbr/>,;:.&sect;!&ugrave;%&pound;$&curren;=+-*\\#~"|&ccedil;@');
if($out === Discussion::TOO_LONG_NAME)
exiting('Nom de discussion &ne; roman (255 caract&egrave;res maximum)');
exiting('C\'est fait !!! (la cr&eacute;ation de ta discussion bien s&ucirc;r)');
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$name = $_POST ['name'] ?? NULL;
try{
assert($sid,new LoginNeededException());
assert($rmdp,new MissingDataException('rmdp','POST'));
assert($mdp,new MissingDataException('mdp','POST'));
assert($mdp2,new MissingDataException('mdp2','POST'));
$did = Discussion::createDiscussion ($sid,$mdp,$name);
}catch(Exception $e){
exiting($e);
}
exiting(Utility::SUCESSFULLY_CREATED_DISCUSSION,'discut.php?d='.$did);
case 'postMessage' :
//Action : post message
if(!$me)
exiting('Veuillez vous identifier pour acceder &agrave; cette section !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting($me.'Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$discussion = new Discussion($_GET ['d']);
if(!$discussion->exists())
exiting('Pour des raisons d\'int&eacute;grit&eacute; du site, nous avons d&eacute;cid&eacute; de ne pas autoriser les messages dans les discussions inexistantes (pour les superadmins, c\'est possible en forcant la bdd &128516; )');
if(!$discussion->canAccess($me))
exiting('Tu pensais que tu pouvais &eacute;crire des messages dans une discussion &agrave; laquelle tu n\'as pas acc&egrave;s !!! Tu te crois o&ugrave; ?');
Message::sendMessage($me,$discussion,$_POST ['msg']);
exiting(NULL,'discut.php?d='.$discussion->getID());
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$did = $_GET ['d'] ?? NULL;
$text = $_POST ['msg'] ?? NULL;
var_dump($text);
try{
assert($sid,new LoginNeddedException());
assert($did,new MissingDataException('d','GET'));
assert($text,new MissingDataException('text','POST'));
Message::postMessage ($sid,$mdp,$did,$text);
}catch(Exception $e){
exiting($e);
}
exiting(NULL,'discut.php?d='.$did);
case 'deleteMessage' :
//Action : delete message
if(!isset($_GET ['m']))
exiting('c');
if(!$me)
exiting('Veuillez vous identifier pour supprimer un message !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$message = new Message($_GET['m']);
if(!$message->exists())
exiting('Je vais avoir du mal &agrave; supprimer le message n&ecute;ant ...');
if($me->isAdminLevelLowerThan(6) && $me->getID() !== $message->getSender()->getID())
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 6 ou plus OU etre l\'auteur de ce message');
$message->removeMessage();
exiting(NULL,'discut.php?d='.$message->getDiscussion()->getID());
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$mid = $_GET ['m'] ?? NULL;
try{
assert($sid,new LoginNeddedException());
assert($mid,new MissingDataException('m','GET'));
$did = Message::deleteMessage ($sid,$mdp,$mid);
}catch(Exception $e){
exiting($e);
}
exiting(NULL,'discut.php?d='.$did);
case 'editVersion' :
//Action : edit version
if(!isset($_GET ['v']))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
if(!$me)
exiting('Veuillez vous identifier pour &eacute;diter une version !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$version = new Version($_GET['v']);
if(!$version->exists())
exiting('Je vais avoir du mal &agrave; &eacute;diter la version n&ecute;ant ...');
if($me->isAdminLevelLowerThan(13) && $version->getProject()->haveRights($me))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 6 ou plus OU etre un des pocesseurs du projet');
//TODO concretly modify the version, with all the options (remove included)
exit;
// Data : name langage tags insertIndex -> facultatifs
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$v = $_GET['v'] ?? NULL;
$name = $_POST['name'] ?? NULL;
$langage = $_POST['langage'] ?? NULL;
$tags = $_POST['tags'] ?? NULL;
$insertIndex = $_POST['insertIndex'] ?? NULL;
try{
assert($sid,new LoginNeededException());
assert($v,new MissingDataException('v','GET'));
Version::editVersion ($sid,$mdp,$v,$name,$langage,$tags,$insertIndex);
}catch(Exception $e){
exiting($e);
}
exiting(Utility::SUCESSFULLY_CHANGED_PASSWORD,'login.php');
case 'getDiscutsMessages' :
//Action : get discut's messages
//TODO precise output type (via $_GET)
$query = 'SELECT m.ID AS messageID,u.ID AS senderID, u.pseudo AS pseudo, m.texte AS texte, m.sendTime AS sendTime, UNIX_TIMESTAMP(m.sendTime) AS sendTimestamp FROM users AS u INNER JOIN messages AS m ON u.ID = m.senderID WHERE m.discussion_id=?';
$data = array ();
if(!isset($_GET ['d'])){
echo 'ERROR : NO DISCUSSION PROVIDED';
exit;
}
if($me?!$me->connect($_SESSION['session_mdp']):FALSE){
echo 'Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)';
exit;
}
$discut = new Discussion($_GET ['d']);
if(!$discut->exists()){
echo 'Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!';
exit;
}
$messages = Utility::arrayIfNot(Message::getFromDiscussion($discut));
$jmsgs = array();
foreach($messages as $message){
$jmsg = array();
$jmsg['messageID'] = $message->getID();
$jmsg['senderID'] = $message->getSender()->getID();
$jmsg['pseudo'] = $message->getSender()->getPseudo();
$jmsg['texte'] = $message->getText();
$jmsg['sendTime'] = $message->getSendDate();
$jmsg['sendTimestamp'] = strToTime($message->getSendDate());
$jmsg['rights'] = ($me)? $message->getSender()->getID() == $me->getID() || $me->isAdminLevelGreaterThan(5):FALSE;
array_push($jmsgs,$jmsg);
}
echo json_encode ( $jmsgs );
flush ();
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$did = $_GET ['did'] ?? NULL;
try{
assert($sid,new LoginNeededException());
assert($did,new MissingDataException('did','GET'));
$jmsgs = Discussion::getMessages ($sid,$mdp,$did);
echo json_encode ( $jmsgs );
flush ();
exit;
}catch(Exception $e){
exiting($e);
}
exit;
case 'getPeopleList' :
//Action : get projest's secondary owners
//Action : get project's secondary owners
//TODO precise output type (via $_GET)
$data = array ();
if(!isset($_GET ['p'])){
echo 'ERROR : NO PROJECT PROVIDED';
exit;
}
if($me?!$me->connect($_SESSION['session_mdp']):FALSE){
echo 'Votre empreinte r&eacute;tinale, digitale et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)';
exit;
}
$projet = new Projet($_GET ['p']);
if(!$projet->exists()){
echo 'Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!';
exit;
}
$owners = $projet->getSecondaryOwners();
$jmsgs = array();
foreach($owners as $owner){
$jmsg = array();
$jmsg['ID'] = $owner->getID();
$jmsg['pseudo'] = $owner->getPseudo();
array_push($jmsgs,$jmsg);
}
echo json_encode ( $jmsgs );
flush ();
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$pid = $_GET ['p'] ?? NULL;
try{
assert($sid,new LoginNeededException());
assert($pid,new MissingDataException('pid','GET'));
$secondaryOwners = Projet::getSecondaryOwners ($sid,$mdp,$pid);
$jsowns = array();
foreach($secondaryOwners as $sOwner){
$jsown = array();
$jsown['ID'] = $sOwner['ID'];
$jsown['pseudo'] = $sOwner['pseudo'];
array_push($jsowns,$jsown);
}
echo json_encode ( $jsowns );
flush ();
exit;
}catch(Exception $e){
exiting($e);
}
exit;
case 'removePeople' :
case 'removePeople' :
//Action : remove secodary owner
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['peopleIDs']))
exiting('o');
if(!$me)
exiting('Veuillez vous identifier pour supprimer un secondary owner !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; supprimer un des propri&eacute;taires du projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$todIDs = explode(',',$_POST ['peopleIDs']);
$sowners = $projet->getSecondaryOwners();
$nsowners = array();;
foreach($sowners as $sowner)if(!in_array($sowner->getID(),$todIDs))$nsowners[] = $sowner;
$projet->setSecondaryOwners($nsowners);
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$pid = $_GET ['pid'] ?? NULL;
$peopleIDs = $_POST['peopleIDs'] ?? NULL;
try{
assert($sid,new LoginNeddedException());
assert($pid,new MissingDataException('pid','GET'));
$did = Projet::removeSecondaryOwner ($sid,$mdp,$pid,explode(',',$peopleIDs));
}catch(Exception $e){
exiting($e);
}
exiting(NULL,'projet.php?p='.$pid);
exit;
case 'addPeople' :
//Action : add secodary owner
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['peopleName']))
exiting('o');
if(!$me)
exiting('Veuillez vous identifier pour ajouter un secondary owner !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; ajouter un propri&eacute;taires au projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$membre = Membre::getFromPseudo($_POST ['peopleName']);
if(count($membre) != 1)
exiting('Vous voulez ajouter QUI ?!!');
$projet->addSecondaryOwner($membre);
exit;
case 'setPublicy' :
//Action : set project publicy
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['publicy']))
exiting('o');
if(!$me)
exiting('Veuillez vous connecter pour changer la "publicit&eacute;"d\'un projet !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
//Action : add secondary owner
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; ajouter un propri&eacute;taires au projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$projet->setPublicy($_POST ['publicy'] == 'true');
echo 'ok';
exit;
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$pid = $_GET ['pid'] ?? NULL;
$personName = $_POST['personName'] ?? NULL;
try{
assert($sid,new LoginNeddedException());
assert($pid,new MissingDataException('pid','GET'));
assert($pid,new MissingDataException('personName','POST'));
$did = Projet::addSecondaryOwner ($sid,$mdp,$pid,explode(',',$personName));
}catch(Exception $e){
exiting($e);
}
exiting(NULL,'projet.php?p='.$pid);
case 'nameOwner' :
//Action : name a new Owner
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['nOwnerID']))
exiting('o');
if(!$me)
exiting('Veuillez vous connecter pour changer le propri&eacute;taire d\'un projet !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; changer le propri&eacute;taires au projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$membre = new Membre($_POST ['nOwnerID']);
if(!$membre->exists())
exiting('Nous sommes hereux d\'acceuillir n&eacute;ant , le touveau propri&eacute;taire !!! Euh ...');
$projet->setOwner($membre);
$todIDs = $membre->getID();
$sowners = $projet->getSecondaryOwners();
$nsowners = array();
foreach($sowners as $sowner)if($sowner->getID() != $todIDs)$nsowners[] = $sowner;
$projet->setSecondaryOwners($nsowners);
$projet->addSecondaryOwner($me);
echo 'ok';
exit;
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$pid = $_GET ['pid'] ?? NULL;
$personId = $_POST['personId'] ?? NULL;
try{
assert($sid,new LoginNeddedException());
assert($pid,new MissingDataException('pid','GET'));
assert($personId,new MissingDataException('personId','POST'));
Projet::nameOwner ($sid,$mdp,$pid,explode(',',$personId));
}catch(Exception $e){
exiting($e);
}
exiting(NULL,'projet.php?p='.$pid);
case 'delProject' :
//Action : delete this project
if(!isset($_GET ['p']))
exiting('c');
if(!$me)
exiting('Veuillez vous identifier pour supprimer un projet !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; supprimer le projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$projet->delete();
echo 'ok';
exit;
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$pid = $_GET ['pid'] ?? NULL;
try{
assert($sid,new LoginNeddedException());
assert($pid,new MissingDataException('pid','GET'));
Projet::removeProject ($sid,$mdp,$pid);
}catch(Exception $e){
exiting($e);
}
exiting(NULL,'projets.php');
case 'getVersionList' :
//Action : get project's versions
//TODO precise output type (via $_GET)
$data = array ();
if(!isset($_GET ['p'])){
echo 'ERROR : NO PROJECT PROVIDED';
exit;
}
if($me?!$me->connect($_SESSION['session_mdp']):FALSE){
echo 'Votre empreinte r&eacute;tinale, digitale et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)';
exit;
}
$projet = new Projet($_GET ['p']);
if(!$projet->exists()){
echo 'Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!';
exit;
}
$versions = Version::getFromProject($projet);
$jmsgs = array();
foreach($versions as $version){
$jmsg = array();
$jmsg['id'] = $version->getID();
$jmsg['name'] = $version->getName();
$jmsg['versionAbs'] = $version->getVersionAbs();
array_push($jmsgs,$jmsg);
}
echo json_encode ( $jmsgs );
flush ();
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$pid = $_GET ['p'] ?? NULL;
try{
assert($sid,new LoginNeededException());
assert($pid,new MissingDataException('pid','GET'));
$versions = Version::getFromProject ($sid,$mdp,$pid);
$jvs = array();
foreach($versions as $version){
$jv = array();
$jv['ID'] = $version['ID'];
$jv['name'] = $version['pseudo'];
$jv['versionAbs'] = $version['versionAbs'];
array_push($jvs,$jv);
}
echo json_encode ( $jvs );
flush ();
exit;
}catch(Exception $e){
exiting($e);
}
exit;
case 'createVersion' :
//Action : add secodary owner
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['name']))
exiting('o');
if(!isset($_POST ['langage']))
exiting('q');
if(!isset($_POST ['tags']))
exiting('m');
if(!$me)
exiting('Veuillez vous identifier pour ajouter une version !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; ajouter une version au projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri&eacute;taire du projet');
//Action : add new version
//TODO make auto version_abs sorting according to $_POST ['insertIndex']
//TODO verify tags and langage
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$pid = $_GET ['pid'] ?? NULL;
$name = $_POST ['name'] ?? NULL;
$tags = $_POST ['tags'] ?? NULL;
$language = $_POST ['language'] ?? NULL;
$insertIndex = $_POST ['insertIndex'] ?? NULL;
$projet->newVersion($_POST ['name'],Langage::getFromName($_POST ['langage']),$_POST ['tags'],Version::getHighestFromProject($projet)->getVersionAbs()+1);
try{
assert($sid,new LoginNeddedException());
assert($pid,new MissingDataException('pid','GET'));
assert($text,new MissingDataException('name','POST'));
assert($text,new MissingDataException('tags','POST'));
assert($text,new MissingDataException('language','POST'));
//TODO do a REAL redirection (not to the highest)
echo 'www.bernard.890m.com/version.php?v=' . Version::getHighestFromProject($projet)->getID();
exit;
$vid = Version::createVerion ($sid,$mdp,$pid,$name,$tags,$language,$insertIndex);
}catch(Exception $e){
exiting($e);
}
exiting(NULL,'version.php?v='.$vid);
case 'editVersion' :
//Action : add secodary owner
if(!isset($_GET ['v']))
exiting('c');
if(!isset($_POST ['name']))
exiting('o');
if(!isset($_POST ['langage']))
exiting('q');
if(!isset($_POST ['tags']))
exiting('m');
if(!$me)
exiting('Veuillez vous identifier pour &eacute;diter une version !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$version = new Version($_GET['v']);
if(!$version->exists())
exiting('Je vais avoir du mal &agrave; &eacute;diter la version n&eacute;ant ...');
if(!($me->getID() == $version->getProject()->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri&eacute;taire du projet');
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$vid = $_GET ['vid'] ?? NULL;
$name = $_POST ['name'] ?? NULL;
$tags = $_POST ['tags'] ?? NULL;
$language = $_POST ['language'] ?? NULL;
$insertIndex = $_POST ['insertIndex'] ?? NULL;
try{
assert($sid,new LoginNeddedException());
assert($pid,new MissingDataException('vid','GET'));
assert($text,new MissingDataException('name','POST'));
assert($text,new MissingDataException('tags','POST'));
assert($text,new MissingDataException('language','POST'));
$vid = Version::editVerion ($sid,$mdp,$vid,$name,$tags,$language,$insertIndex);
}catch(Exception $e){
exiting($e);
}
//TODO make auto version_abs sorting according to $_POST ['insertIndex']
//TODO verify tags and langage
$projet->editVersion($version,$_POST ['name'],Langage::getFromName($_POST ['langage']),$_POST ['tags'],Version::getHighestFromProject($projet)->getVersionAbs()+1);
exiting(NULL,'version.php?v='.$vid);
//TODO do a REAL redirection (not to the highest)
echo 'www.bernard.890m.com/version.php?v=' . Version::getHighestFromProject($projet)->getID();
exit;
case 'delVersion' :
//Action : delete this version
if(!isset($_GET ['p']))
exiting('c');
if(!$me)
exiting('Veuillez vous identifier pour supprimer une version !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$version = new Version($_GET['p']);
if(!$version->exists())
exiting('Je vais avoir du mal &agrave; supprimer la version n&eacute;ant ...');
if(!($me->getID() == $version->getProject()->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri&eacute;taire du projet');
$version->delete();
echo 'ok';
exit;
$sid = $_SESSION ['session_id'] ?? NULL;
$mdp = $_SESSION ['session_mdp'] ?? NULL;
$vid = $_GET ['vid'] ?? NULL;
try{
assert($sid,new LoginNeddedException());
assert($pid,new MissingDataException('vid','GET'));
$pid = Version::removeVersion ($sid,$mdp,$vid);
}catch(Exception $e){
exiting($e);
}
exiting(NULL,'projet.php?p=' . $pid);
}

423
extras/Nexecutor.php Normal file
View File

@ -0,0 +1,423 @@
<?php
session_start ();
include_once 'clazz/Zincluder.php';
$me = Membre::me();
/*
TODO add $_GET['p'] => should return on $_SESSION ['current_error'] (0) or via echo (1)
*/
function exiting($message,$location='index.php'){
header ( 'Location:' . $location );
$_SESSION ['current_error'] = $message;
exit;
}
if (! isset ( $_GET ['action'] ))
exiting(NULL,'40A.php');
switch ($_GET ['action']) {
case 'register' :
//Action : register
if (!(isset ( $_POST ['pseudo'] ) && isset ( $_POST ['mdp'] ) && isset ( $_POST ['mdp2'] )))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
if ($_POST ['mdp'] === $_POST ['mdp2'])
exiting('Tu auras du rentrer deux fois le m&ecirc;me mot de passe (tu permet aussi de rendre le champs "Recopier le mot de passe" utile)');
if (preg_match ( "#^[a-zA-Z0-9\\-_]+$#", $_POST ['pseudo'] ))
exiting('Le pseudo sera incorrect : Les seuls caract&egrave;res autoris&eacute;s sont :<br/>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_');
if (preg_match ( "#^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\\-_&<26><><EFBFBD><EFBFBD><EFBFBD>\"\\#'{}()[\\]|\\^@<40>+=\$<EFBFBD><EFBFBD>*!<21>:/;.,?<3F>]+$#", $_POST ['mdp'] ))
exiting('Le mot de passe fut incorrect : Les seuls caract&egrave;res autoris&eacute;s sont :<br/>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_&&eacute;&egrave;&agrave;&ugrave;&ccedil;&mu;"#\'{}()[]|^@<40>+=$<24><>*!<21>:/;.,?<3F>');
$out = Membre::registerPerson ($_POST ['pseudo'],$_POST ['mdp']);
if($out ===Membre::USED_USERNAME)
exiting('Le pseudonyme est d&eacute;j&agrave; utilis&eacute; (par une entit&eacute; differente de vous)');
exiting('Vous avez d&eacute;j&agrave; &eacute;t&eacute; correctement inscrit sur bernard.com','login.php');
case 'login' :
//Action : login
if (!( isset ( $_POST ['pseudo'] ) && isset ( $_POST ['mdp'] ) ))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
$me = Membre::getFromPseudo($_POST['pseudo']);
if(!$me)
exiting('Kik&egrave;tvou ? Pseudo inconnu ...');
if(!$me->connect($_POST ['mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$_SESSION['session_id'] = $me->getID();
$_SESSION['session_mdp'] = $_POST['mdp'];
exiting('Vous &ecirc;tes bien connect&eacute; (vous l\'avez &eacute;t&eacute; et le serez &eacute;galement)!');
case 'changePassword' :
//Action : change password
if(!(isset($_POST['rmdp']) && isset($_POST['nmdp']) && isset($_POST['nmdp2'])))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
if(!$me)
exiting('Si tu ne te connectes pas, comment veut tu que je sache quel mot de passe changer !');
if(!$me->connect($_POST['rmdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
if($_POST['nmdp'] !== $_POST['nmdp2'])
exiting('Tu auras du rentrer deux fois le m&ecirc;me mot de passe (tu permet aussi de rendre le champs "Recopier le mot de passe" utile)');
$out = $me->changePassword($_POST['nmdp']);
if($out == Membre::PASSWORD_TOO_LONG)
exiting('Mot de passe &ne; roman (255 caract&egrave;res maximum)');
exiting('Vos dispositifs d\'identification ont &eacute;t&eacute; correctement chang&eacute;s');
case 'createDiscussion' :
//Action : create discussion
if(!isset($_POST['name']))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
if(!$me)
exiting('Veuillez vous identifier pour acceder &agrave; cette section !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
if($me->isAdminLevelLowerThan(2))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 2 ou plus)');
$out = Discussion::createDiscussion($_POST ['name'],$_SESSION ['session_id']);
if($out === Discussion::NAME_ALREADY_USED)
exiting('Mince j\'ai d&eacute;j&agrave; utilis&eacute; l\'&eacute;criteau avec ce nom ... t\'en as pas un autre ?');
if($out === Discussion::ILLEGAL_NAME)
exiting('Y a des trucs qui ne me plaisent pas dans le nom que tu as donn&eacute; &agrave; ta discussion ...<br/>Je n\'accepte que les caract&egrave;res abcdefghijklmnopqrstuvwxyz<wbr/>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<wbr/>&eacute;&egrave;&agrave;&mu;_-\'()[\\]\\\\/<wbr/>,;:.&sect;!&ugrave;%&pound;$&curren;=+-*\\#~"|&ccedil;@');
if($out === Discussion::TOO_LONG_NAME)
exiting('Nom de discussion &ne; roman (255 caract&egrave;res maximum)');
exiting('C\'est fait !!! (la cr&eacute;ation de ta discussion bien s&ucirc;r)');
case 'postMessage' :
//Action : post message
if(!$me)
exiting('Veuillez vous identifier pour acceder &agrave; cette section !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting($me.'Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$discussion = new Discussion($_GET ['d']);
if(!$discussion->exists())
exiting('Pour des raisons d\'int&eacute;grit&eacute; du site, nous avons d&eacute;cid&eacute; de ne pas autoriser les messages dans les discussions inexistantes (pour les superadmins, c\'est possible en forcant la bdd &128516; )');
if(!$discussion->canAccess($me))
exiting('Tu pensais que tu pouvais &eacute;crire des messages dans une discussion &agrave; laquelle tu n\'as pas acc&egrave;s !!! Tu te crois o&ugrave; ?');
Message::sendMessage($me,$discussion,$_POST ['msg']);
exiting(NULL,'discut.php?d='.$discussion->getID());
case 'deleteMessage' :
//Action : delete message
if(!isset($_GET ['m']))
exiting('c');
if(!$me)
exiting('Veuillez vous identifier pour supprimer un message !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$message = new Message($_GET['m']);
if(!$message->exists())
exiting('Je vais avoir du mal &agrave; supprimer le message n&ecute;ant ...');
if($me->isAdminLevelLowerThan(6) && $me->getID() !== $message->getSender()->getID())
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 6 ou plus OU etre l\'auteur de ce message');
$message->removeMessage();
exiting(NULL,'discut.php?d='.$message->getDiscussion()->getID());
case 'editVersion' :
//Action : edit version
if(!isset($_GET ['v']))
exiting('Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!');
if(!$me)
exiting('Veuillez vous identifier pour &eacute;diter une version !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$version = new Version($_GET['v']);
if(!$version->exists())
exiting('Je vais avoir du mal &agrave; &eacute;diter la version n&ecute;ant ...');
if($me->isAdminLevelLowerThan(13) && $version->getProject()->haveRights($me))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 6 ou plus OU etre un des pocesseurs du projet');
//TODO concretly modify the version, with all the options (remove included)
exit;
case 'getDiscutsMessages' :
//Action : get discut's messages
//TODO precise output type (via $_GET)
$query = 'SELECT m.ID AS messageID,u.ID AS senderID, u.pseudo AS pseudo, m.texte AS texte, m.sendTime AS sendTime, UNIX_TIMESTAMP(m.sendTime) AS sendTimestamp FROM users AS u INNER JOIN messages AS m ON u.ID = m.senderID WHERE m.discussion_id=?';
$data = array ();
if(!isset($_GET ['d'])){
echo 'ERROR : NO DISCUSSION PROVIDED';
exit;
}
if($me?!$me->connect($_SESSION['session_mdp']):FALSE){
echo 'Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)';
exit;
}
$discut = new Discussion($_GET ['d']);
if(!$discut->exists()){
echo 'Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!';
exit;
}
$messages = Utility::arrayIfNot(Message::getFromDiscussion($discut));
$jmsgs = array();
foreach($messages as $message){
$jmsg = array();
$jmsg['messageID'] = $message->getID();
$jmsg['senderID'] = $message->getSender()->getID();
$jmsg['pseudo'] = $message->getSender()->getPseudo();
$jmsg['texte'] = $message->getText();
$jmsg['sendTime'] = $message->getSendDate();
$jmsg['sendTimestamp'] = strToTime($message->getSendDate());
$jmsg['rights'] = ($me)? $message->getSender()->getID() == $me->getID() || $me->isAdminLevelGreaterThan(5):FALSE;
array_push($jmsgs,$jmsg);
}
echo json_encode ( $jmsgs );
flush ();
exit;
case 'getPeopleList' :
//Action : get projest's secondary owners
//TODO precise output type (via $_GET)
$data = array ();
if(!isset($_GET ['p'])){
echo 'ERROR : NO PROJECT PROVIDED';
exit;
}
if($me?!$me->connect($_SESSION['session_mdp']):FALSE){
echo 'Votre empreinte r&eacute;tinale, digitale et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)';
exit;
}
$projet = new Projet($_GET ['p']);
if(!$projet->exists()){
echo 'Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!';
exit;
}
$owners = $projet->getSecondaryOwners();
$jmsgs = array();
foreach($owners as $owner){
$jmsg = array();
$jmsg['ID'] = $owner->getID();
$jmsg['pseudo'] = $owner->getPseudo();
array_push($jmsgs,$jmsg);
}
echo json_encode ( $jmsgs );
flush ();
exit;
case 'removePeople' :
//Action : remove secodary owner
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['peopleIDs']))
exiting('o');
if(!$me)
exiting('Veuillez vous identifier pour supprimer un secondary owner !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; supprimer un des propri&eacute;taires du projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$todIDs = explode(',',$_POST ['peopleIDs']);
$sowners = $projet->getSecondaryOwners();
$nsowners = array();;
foreach($sowners as $sowner)if(!in_array($sowner->getID(),$todIDs))$nsowners[] = $sowner;
$projet->setSecondaryOwners($nsowners);
exit;
case 'addPeople' :
//Action : add secodary owner
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['peopleName']))
exiting('o');
if(!$me)
exiting('Veuillez vous identifier pour ajouter un secondary owner !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; ajouter un propri&eacute;taires au projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$membre = Membre::getFromPseudo($_POST ['peopleName']);
if(count($membre) != 1)
exiting('Vous voulez ajouter QUI ?!!');
$projet->addSecondaryOwner($membre);
exit;
case 'setPublicy' :
//Action : set project publicy
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['publicy']))
exiting('o');
if(!$me)
exiting('Veuillez vous connecter pour changer la "publicit&eacute;"d\'un projet !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; ajouter un propri&eacute;taires au projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$projet->setPublicy($_POST ['publicy'] == 'true');
echo 'ok';
exit;
case 'nameOwner' :
//Action : name a new Owner
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['nOwnerID']))
exiting('o');
if(!$me)
exiting('Veuillez vous connecter pour changer le propri&eacute;taire d\'un projet !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; changer le propri&eacute;taires au projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$membre = new Membre($_POST ['nOwnerID']);
if(!$membre->exists())
exiting('Nous sommes hereux d\'acceuillir n&eacute;ant , le touveau propri&eacute;taire !!! Euh ...');
$projet->setOwner($membre);
$todIDs = $membre->getID();
$sowners = $projet->getSecondaryOwners();
$nsowners = array();
foreach($sowners as $sowner)if($sowner->getID() != $todIDs)$nsowners[] = $sowner;
$projet->setSecondaryOwners($nsowners);
$projet->addSecondaryOwner($me);
echo 'ok';
exit;
case 'delProject' :
//Action : delete this project
if(!isset($_GET ['p']))
exiting('c');
if(!$me)
exiting('Veuillez vous identifier pour supprimer un projet !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; supprimer le projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri<72>taire du projet');
$projet->delete();
echo 'ok';
exit;
case 'getVersionList' :
//Action : get project's versions
//TODO precise output type (via $_GET)
$data = array ();
if(!isset($_GET ['p'])){
echo 'ERROR : NO PROJECT PROVIDED';
exit;
}
if($me?!$me->connect($_SESSION['session_mdp']):FALSE){
echo 'Votre empreinte r&eacute;tinale, digitale et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)';
exit;
}
$projet = new Projet($_GET ['p']);
if(!$projet->exists()){
echo 'Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!';
exit;
}
$versions = Version::getFromProject($projet);
$jmsgs = array();
foreach($versions as $version){
$jmsg = array();
$jmsg['id'] = $version->getID();
$jmsg['name'] = $version->getName();
$jmsg['versionAbs'] = $version->getVersionAbs();
array_push($jmsgs,$jmsg);
}
echo json_encode ( $jmsgs );
flush ();
exit;
case 'createVersion' :
//Action : add secodary owner
if(!isset($_GET ['p']))
exiting('c');
if(!isset($_POST ['name']))
exiting('o');
if(!isset($_POST ['langage']))
exiting('q');
if(!isset($_POST ['tags']))
exiting('m');
if(!$me)
exiting('Veuillez vous identifier pour ajouter une version !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$projet = new Projet($_GET['p']);
if(!$projet->exists())
exiting('Je vais avoir du mal &agrave; ajouter une version au projet n&eacute;ant ...');
if(!($me->getID() == $projet->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri&eacute;taire du projet');
//TODO make auto version_abs sorting according to $_POST ['insertIndex']
//TODO verify tags and langage
$projet->newVersion($_POST ['name'],Langage::getFromName($_POST ['langage']),$_POST ['tags'],Version::getHighestFromProject($projet)->getVersionAbs()+1);
//TODO do a REAL redirection (not to the highest)
echo 'www.bernard.890m.com/version.php?v=' . Version::getHighestFromProject($projet)->getID();
exit;
case 'editVersion' :
//Action : add secodary owner
if(!isset($_GET ['v']))
exiting('c');
if(!isset($_POST ['name']))
exiting('o');
if(!isset($_POST ['langage']))
exiting('q');
if(!isset($_POST ['tags']))
exiting('m');
if(!$me)
exiting('Veuillez vous identifier pour &eacute;diter une version !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$version = new Version($_GET['v']);
if(!$version->exists())
exiting('Je vais avoir du mal &agrave; &eacute;diter la version n&eacute;ant ...');
if(!($me->getID() == $version->getProject()->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri&eacute;taire du projet');
//TODO make auto version_abs sorting according to $_POST ['insertIndex']
//TODO verify tags and langage
$projet->editVersion($version,$_POST ['name'],Langage::getFromName($_POST ['langage']),$_POST ['tags'],Version::getHighestFromProject($projet)->getVersionAbs()+1);
//TODO do a REAL redirection (not to the highest)
echo 'www.bernard.890m.com/version.php?v=' . Version::getHighestFromProject($projet)->getID();
exit;
case 'delVersion' :
//Action : delete this version
if(!isset($_GET ['p']))
exiting('c');
if(!$me)
exiting('Veuillez vous identifier pour supprimer une version !!!');
if(!$me->connect($_SESSION['session_mdp']))
exiting('Votre empreinte r&eacute;tinale, digital et g&eacute;netique ne correspond pas &agrave; celles stoqu&eacute;es dans notre base de donn&eacute;es (Technologie &agrave; venir)');
$version = new Version($_GET['p']);
if(!$version->exists())
exiting('Je vais avoir du mal &agrave; supprimer la version n&eacute;ant ...');
if(!($me->getID() == $version->getProject()->getOwner()->getID() OR $me->isAdminLevelGreaterThan(13)))
exiting('Vous n\'&ecirc;tes pas assez PUISSANT !!!!!!!!!! (Faut un adminLevel de 13 ou plus OU etre propri&eacute;taire du projet');
$version->delete();
echo 'ok';
exit;
}

15
extras/dumpBDD.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
echo $1
if [ $1 = "start" ]
then mysql -uu890869027 -p -D u890869027_bcom < ./bdd.sql ; php -S localhost:8000
echo "\n"
mysqldump --routines -uu890869027 -p u890869027_bcom > ./bdd.sql
echo "Fin du programme";
elif [ "$1" = "stop" ]
then
mysqldump --routines -uu890869027 -p u890869027_bcom > ./bdd.sql
echo "Tadaaaaa !!!"
fi

View File

@ -54,4 +54,4 @@
}
}
}
</script>
</script>

View File

@ -27,7 +27,7 @@ switch($_GET['action']){
$version = new Version($_GET['v']);
if(!$version->exists()){
header('Location:404.php');
echo "v doit &eacute;tre l'ID d'une version existante !";
echo "v doit être l'ID d'une version existante !";
echo 'NO';
exit;
}
@ -72,7 +72,7 @@ switch($_GET['action']){
//IF action=download
//Tester telechargement
//Génerer clé aleatoire de telechargement
//Génerer clé aleatoire de telechargement
//La stoquer
//Rediriger vers megabernard.alwaysdata.net

View File

@ -1,19 +0,0 @@
!!com.bernard.qcminator.quiz.DEVerbenQuiz
author: Mysaa
entryCount: 2
name: Schwach verben
verben:
- aux: 0
infinitiv: [gehen, gaiheun, gaien, geheun]
partizipPerfekt: [gegangen, gegehen, gegeht, gegehet]
prasens2: [gehst, gaist]
prasens3: [geht, gaitte, gait, gétteu, gäht]
prateritum2: [ginget, gingueut]
prateritum3: [ging, gung, gang, gèng]
- aux: 1
infinitiv: [schwimmen, chvimeun, schwimen, schvimmen]
partizipPerfekt: [geschwommen, geschwomen, schwomen, schwommen]
prasens2: [schwimmst, schwimst]
prasens3: [schwimmt, schwimt]
prateritum2: [schwammst, schwamst]
prateritum3: [schwamm, schwamt, schwam, schwammte]

9
extras/test.php Normal file
View File

@ -0,0 +1,9 @@
<?php
include_once 'clazz/Zincluder.php';
$out = Membre::registerPerson ("moi","pwd");
var_dump($out);

View File

@ -12,8 +12,7 @@
</footer>
<?php if(isset($_SESSION['current_error'])){ ?>
<div id="currentErrorPanel" class="fullscreen absent big-background-semi-opaque full-text">
<div id="currentErrorPanel" class="fullscreen big-background-semi-opaque full-text">
<div class="screen-vertical-centered">
<div class="screen-horizontal-centered opaque">
<?php echo $_SESSION['current_error'];?>

View File

@ -18,11 +18,12 @@
-->
<?php
if($me = Membre::me()){
$me = Membre::headerInfos($_SESSION['session_id'] ?? -1,$_SESSION['session_mdp'] ?? '');
if($me['connected']){
?>
<div id="bienvenue">Bienvenue &agrave; toi, <?php echo $me->getPseudo(); ?>
<form id="headDisconnectForm" method="post" action="disconnect.php">
<div id="bienvenue">Bienvenue &agrave; toi, <?php echo $me['pseudo']; ?>
<form id="headDisconnectForm" method="post" action="executor.php?action=disconnect">
<input type="submit" value="Se d&eacute;connecter" />
</form>
</div>

View File

@ -14,10 +14,10 @@
<?php foreach(Article::getNewest(10) as $article){ ?>
<article>
<!-- TODO put class on article node -->
<h2 class="articleTitle"><?php echo $article->getTitle(); ?></h2>
<?php if($article->getPicPath() != ''){?><a class="articlePic" href="<?php echo $article->getPicPath(); ?>"><img src="<?php echo $article->getPicPath(); ?>" width="128" /></a><?php }?>
<h2 class="articleTitle"><?php echo $article['title']; ?></h2>
<?php if($article['picPath'] != ''){?><a class="articlePic" href="<?php echo $article['picPath']; ?>"><img src="<?php echo $article['picPath'] ?>" width="128" /></a><?php }?>
<div class="articleText"><?php echo ($article->getShort() == '')?$article->getText():$article->getShort(); ?></div>
<div class="articleText"><?php echo ($article['short'] == '')?$article['text']:$article['short']; ?></div>
</article>
<?php } ?>

View File

@ -1,6 +1,20 @@
<?php session_start();
include_once 'clazz/Zincluder.php';?>
<?php
session_start();
include_once 'clazz/Zincluder.php';
try{
$projects = Projet::getPublicProjectsForPresentation($_SESSION['session_id'] ?? NULL,$_SESSION['session_mdp'] ?? NULL);
}catch(SQLProcessingException $e){
var_dump($e);
echo $e->getHtmlMessage();
$_SESSION ['current_error'] = $e->getHtmlMessage();
header ( 'Location:' . $e->getPreferredRedirection() );
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
@ -13,17 +27,17 @@ include_once 'clazz/Zincluder.php';?>
<h1>Tous les projets</h1>
<?php
$me = Membre::me();
$projects = Projet::getOthers($me);
if($projects != NULL){
foreach(Utility::arrayIfNot($projects) as $project){
$version = Version::getHighestFromProject($project);
if($version)
echo ('<a href="projet.php?p='. $project->getID() .'">Le projet ' . $project->getName() . '</a> <a href="version.php?v='. $version->getID() .'">en version ' . $version->getName() . '</a><br/>');
try{
foreach($projects as $project){
if($project['versionID'])
echo ('<a href="projet.php?p='. $project['projectID'] .'">Le projet ' . $project['projectName'] . '</a> <a href="version.php?v='. $project['versionID'] .'">en version ' . $project['versionName'] . '</a><br/>');
else
echo ('<a href="projet.php?p='. $project->getID() .'">Le projet ' . $project->getName() . ' sans version </a><br/>');
}
echo ('<a href="projet.php?p='. $project['projectID'] .'">Le projet ' . $project['projectName'] . ' sans version </a><br/>');
}
}catch(SQLProcessingException $e){
$_SESSION ['current_error'] = $e->getHtmlMessage();
}
?>
<br/>

Binary file not shown.

BIN
pictures/discoursB2b2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

View File

@ -1,18 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<?php include 'includes/meta.php'; ?>
</head>
<body>
<?php include 'includes/header.php'; ?>
<canvas id="pieces" width="500" height="500"></canvas>
<script type="text/javascript">
</script>
<?php include 'includes/footer.php'; ?>
</body>
</html>

View File

@ -9,8 +9,9 @@ include_once 'clazz/Zincluder.php' ?>
<?php include 'includes/header.php'; ?>
<?php
$me = Membre::me();
if(!$me){
try{
Membre::checkIdLogin($_SESSION['session_id'],$_SESSION['session_mdp']);
}catch(SQLProcessingException $e){
header('Location:login.php');
$_SESSION['current_error'] = 'Veuillez vous connectez ou vous inscrire pour acc&eacute;der &agrave; votre profil (&ccedil;a semble logique ...)';
exit;
@ -18,7 +19,7 @@ include_once 'clazz/Zincluder.php' ?>
?>
<form method="post" action="executor.php?action=changePassword" id="changePasswordForm">
Changer le mot de passe :<br/>
Changer le mot de passe :<br/><br/>
<label for="real_mdp_ask">Votre ancien mot de passe :</label>
<input type="password" id="real_mdp_ask" name="rmdp" />
<br/>

View File

@ -1,53 +1,44 @@
<?php session_start(); ?>
<?php include_once 'clazz/Zincluder.php';?>
<?php
session_start();
include_once 'clazz/Zincluder.php';
try{
$projet = Projet::showProject($_SESSION['session_id'] ?? NULL,$_SESSION['session_mdp'] ?? NULL,$_GET['p'] ?? NULL);
}catch(SQLProcessingException $e){
error_log($e);
echo $e->getHtmlMessage();
$_SESSION ['current_error'] = $e->getHtmlMessage();
header ( 'Location:' . $e->getPreferredRedirection() ?? 'others.php' );
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<?php include 'includes/meta.php'; ?>
<script>
var projectID = <?php echo $_GET['p']; ?>;
</script>
</head>
<body>
<?php include 'includes/header.php'; ?>
<?php
//TODO re la fonction exiting
$me = Membre::me();
if(!isset($_GET['p'])){
header ( 'Location:projets.php');
$_SESSION ['current_error'] = 'Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!';
exit;
}
$projet = new Projet($_GET['p']);
if(!$projet->exists()){
header ( 'Location:projets.php');
$_SESSION ['current_error'] = 'Je vais avoir du mal &agrave; afficher les don&eacute;es du projet n&eacute;ant ...';
exit;
}
if(!($projet->isPublic() or $me?$me->isAdminLevelGreaterThan(12):FALSE or $me?$projet->haveRights($me):FALSE)){
header ( 'Location:projets.php');
$_SESSION ['current_error'] = 'Vous n\'avez pas le droit d\'&ecirc;tre ici ...<br/> DEGAGEZ !!!';
exit;
}
$su = $me?$projet->haveRights($me):FALSE OR $me?$me->isAdminLevelGreaterThan(12):FALSE;
$ssu = $me?$me->getID() == $projet->getOwner()->getID():FALSE OR $me?$me->isAdminLevelGreaterThan(13):FALSE;
?>
<h1>Mes projets</h1>
<script>
var projectPublic = <?php echo $projet->isPublic()?'true':'false'; ?>;
var projectPublic = <?php echo $projet['public']?'true':'false'; ?>;
</script>
<h1>Le projet <?php echo($projet->getName()); ?></h1>
<h1>Le projet <?php echo($projet['name']); ?></h1>
<br/>
<?php
$ssu = $projet['ownerID'] == ($_POST['session_id'] ?? -1);
$couple = Utility::getHierarchicCouple();
echo $couple[0] . ' : ' . $projet->getOwner()->getPseudo() . '<br/>';
echo $couple[0] . ' : ' . $projet['ownerPseudo'] . '<br/>';
$str = $couple[1] . ' : ';
foreach($projet->getSecondaryOwners() as $sowner)
$str .= $sowner->getPseudo() . ', ';//TODO add link to membre.php
if(count($projet->getSecondaryOwners()) > 0)
foreach($projet['sowners'] as $sowner)
$str .= $sowner['pseudo'] . ', ';//TODO add link to membre.php
if(count($projet['sowners']) > 0)
echo '<span id="sOwnersText">'.substr($str,0,-2).'</span>';
?>
@ -295,7 +286,7 @@
}
function answerCreationRequest(data){
if(!data.startsWith('www.bernard.890m.com')){
if(data != 'ok'){
console.log(data);//TODO la jolie boite de dialogue
}else
window.location.replace(data);
@ -335,18 +326,20 @@
<br/>
<br/>
<?php $versions = Version::getFromProject($projet); ?>
<?php if(is_array($versions)){/* = if count(versions>1) */ ?>
<?php $languages = Langage::getLanguagesFromVersions($versions); ?>
<?php if(count($projet['versions']) > 0){ ?>
<?php $languages = array();
foreach($projet['versions'] AS $version)
array_push($languages,$version['language']);
$languages = array_unique($languages,SORT_REGULAR); ?>
<h3>Toutes les versions :</h3>
<br/>
<?php foreach($languages as $language){ ?>
<table class="versionTable">
<tr>
<th><?php echo $language->getName(); ?></th>
<th><?php echo Langage::getFromId($language)->getName(); ?></th>
</tr>
<?php foreach (Utility::arrayIfNot($versions) as $writingVersion){if($writingVersion->getLanguage() == $language){ ?>
<tr><td><a href = "version.php?v=<?php echo $writingVersion->getID();?>"><?php echo $writingVersion->getName(); ?></a></td></tr>
<?php foreach ($projet['versions'] as $writingVersion){if($writingVersion['language'] == $language){ ?>
<tr><td><a href = "version.php?v=<?php echo $writingVersion['ID'];?>"><?php echo $writingVersion['name']; ?></a></td></tr>
<?php }}?>
</table>
<?php } ?>

View File

@ -1,5 +1,26 @@
<?php session_start();
include_once 'clazz/Zincluder.php';?>
<?php
session_start();
include_once 'clazz/Zincluder.php';
if(!isset($_SESSION['session_id'])){
$_SESSION ['current_error'] = Utility::LOGIN_NEEDED_FOR_PROJECTS;
header ( 'Location:login.php' );
exit;
}
try{
Membre::checkIdLogin($_SESSION['session_id'] ?? NULL,$_SESSION['session_mdp'] ?? NULL);
$projects = Projet::getAuthorizedProjectsForPresentation($_SESSION['session_id'],$_SESSION['session_mdp']);
}catch(SQLProcessingException $e){
var_dump($e);
echo $e->getHtmlMessage();
$_SESSION ['current_error'] = $e->getHtmlMessage();
header ( 'Location:' . $e->getPreferredRedirection() );
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
@ -12,22 +33,17 @@ include_once 'clazz/Zincluder.php';?>
<h1>Mes projets</h1>
<?php
if($me = Membre::me()){//Defini dans le header.php
$projects = Projet::getWhichHeCanAccess($me);
foreach(Utility::arrayIfNot($projects) as $project){
$version = Version::getHighestFromProject($project);
if($version)
echo ('<a href="projet.php?p='. $project->getID() .'">Le projet ' . $project->getName() . '</a> <a href="version.php?v='. $version->getID() .'">en version ' . $version->getName() . '</a><br/>');
try{
foreach($projects as $project){
if($project['versionID'])
echo ('<a href="projet.php?p='. $project['projectID'] .'">Le projet ' . $project['projectName'] . '</a> <a href="version.php?v='. $project['versionID'] .'">en version ' . $project['versionName'] . '</a><br/>');
else
echo ('<a href="projet.php?p='. $project->getID() .'">Le projet ' . $project->getName() . ' sans version </a><br/>');
}
}else{
header ( 'Location:login.php');
$_SESSION ['current_error'] = 'C\'est pas que je veut pas ... mais qui &ecirc;tes vous ?';
exit;
echo ('<a href="projet.php?p='. $project['projectID'] .'">Le projet ' . $project['projectName'] . ' sans version </a><br/>');
}
}catch(SQLProcessingException $e){
$_SESSION ['current_error'] = $e->getHtmlMessage();
}
?>
<br/>
<?php include 'includes/footer.php'; ?>

View File

@ -9,7 +9,7 @@
<body>
<?php include 'includes/header.php'; ?>
<form id="registerForm" method="post" action="registering.php">
<form id="registerForm" method="post" action="executor.php?action=register">
<label for="pseudo">Pseudo :</label>
<input type="text" name="pseudo" id="pseudo" placeholder="Votre pseudo" />
<br/>
@ -25,4 +25,4 @@
<?php include 'includes/footer.php' ?>
</body>
</html>
</html>

24
sql/GetDiscutInfo.sql Normal file
View File

@ -0,0 +1,24 @@
DROP PROCEDURE IF EXISTS GetDiscutInfo;
DELIMITER //
CREATE PROCEDURE GetDiscutInfo
(
IN p_sid TEXT,
IN p_password TEXT,
IN p_did INT,
OUT outputCode INT(11),
OUT o_connected INT(1)
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 OR outputCode=2005 THEN
SET o_connected = 1;
ELSE
SET o_connected = 0;
END IF;
SET outputCode :=( SELECT CASE WHEN (SELECT CheckInGroup(p_sid,authorizedGroupID)=42 OR p_sid=creatorID FROM discussions WHERE ID=p_did) THEN 42 ELSE 2019 END );
END//
DELIMITER ;

22
sql/GetDiscutMessages.sql Normal file
View File

@ -0,0 +1,22 @@
DROP PROCEDURE IF EXISTS GetDiscutMessages;
DELIMITER //
CREATE PROCEDURE GetDiscutMessages
(
IN p_sid INT,
IN p_password TEXT,
IN p_did INT,
OUT outputCode INT(11)
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 OR outputCode = 2005 THEN
SET outputCode :=( SELECT CASE WHEN (SELECT CheckInGroup(p_sid,authorizedGroupID)=42 OR p_sid=creatorID FROM discussions WHERE ID=p_did) THEN 42 ELSE 2019 END );
IF outputCode = 42 THEN
INSERT INTO smz SELECT m.ID AS ID,u.ID AS senderID,u.pseudo AS senderPseudo,m.texte AS texte,m.sendTime AS sendTime, p_sid = senderID AS rights FROM messages AS m INNER JOIN membres AS u ON u.ID = m.senderID WHERE m.discussionID = p_did;
END IF;
END IF;
END//
DELIMITER ;

20
sql/changePassword.sql Normal file
View File

@ -0,0 +1,20 @@
DROP PROCEDURE IF EXISTS ChangePassword;
DELIMITER //
CREATE PROCEDURE ChangePassword
(
IN p_sid INT,
IN p_password TEXT,
IN p_npassword TEXT,
OUT outputCode INT
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 THEN
UPDATE membres SET hashedPassword = MD5(p_npassword) WHERE ID = p_sid;
END IF;
END//
DELIMITER ;

39
sql/checkIdLogin.sql Normal file
View File

@ -0,0 +1,39 @@
DROP PROCEDURE IF EXISTS CheckIdLogin;
DELIMITER //
CREATE PROCEDURE CheckIdLogin
(
IN p_sid INT,
IN p_password TEXT,
OUT outputCode INT
)
READS SQL DATA
BEGIN
SET outputCode :=(
SELECT
(
CASE
WHEN (
SELECT
COUNT(*)
FROM
membres
WHERE
ID = p_sid
) != 1 THEN 2005
WHEN(
SELECT
COUNT(*)
FROM
membres
WHERE
ID = p_sid AND
hashedPassword = MD5(p_password)
) != 1 THEN 2006
ELSE 42
END
)
);
END//
DELIMITER ;

66
sql/checkInGroup.sql Normal file
View File

@ -0,0 +1,66 @@
DROP FUNCTION IF EXISTS CheckInGroup;
DELIMITER //
CREATE FUNCTION CheckInGroup
(
p_sid INT,
p_gid INT
)
RETURNS INT
READS SQL DATA
BEGIN
SET @outputCode :=(
SELECT
(
CASE
WHEN p_gid = 0 THEN 0
WHEN p_gid = 1 THEN 42
ELSE 100
END
)
);
IF @outputCode = 100 THEN
SET @outputCode :=(
SELECT
(
CASE
WHEN(
SELECT
COUNT(*)
FROM
groupes
WHERE
ID = p_gid
) = 1 THEN 42
ELSE 2012
END
)
);
IF @outputCode = 42 THEN
SET @outputCode :=(
SELECT
(
CASE
WHEN(
SELECT
COUNT(*)
FROM
appartenanceAUnGroupe
INNER JOIN groupes
ON groupes.ID = appartenanceAUnGroupe.groupID
WHERE
groupes.ID = p_gid AND appartenanceAUnGroupe.membreID = p_sid
) >= 1 THEN 42
ELSE 0
END
)
);
END IF;
END IF;
RETURN @outputCode;
END//
DELIMITER ;

49
sql/checkLogin.sql Normal file
View File

@ -0,0 +1,49 @@
DROP PROCEDURE IF EXISTS CheckLogin;
DELIMITER //
CREATE PROCEDURE CheckLogin
(
IN p_pseudo TEXT,
IN p_password TEXT,
OUT outputCode INT,
OUT accountID INT
)
READS SQL DATA
BEGIN
SET outputCode :=(
SELECT
(
CASE
WHEN (
SELECT
COUNT(*)
FROM
membres
WHERE
pseudo = p_pseudo
) != 1 THEN 2005
WHEN (
SELECT
COUNT(*)
FROM
membres
WHERE
pseudo = p_pseudo AND
hashedPassword = MD5(p_password)
) != 1 THEN 2006
ELSE 42
END
)
);
SET accountID :=(
SELECT
ID
FROM
membres
WHERE
pseudo = p_pseudo AND
hashedPassword = MD5(p_password)
);
END//
DELIMITER ;

43
sql/createDiscussion.sql Normal file
View File

@ -0,0 +1,43 @@
DROP PROCEDURE IF EXISTS CreateDiscusson;
DELIMITER //
CREATE PROCEDURE CreateDiscusson
(
IN p_sid INT,
IN p_password TEXT,
IN p_name TEXT,
OUT outputCode INT
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password,outputCode);
IF outputCode = 42 THEN
IF (SELECT COUNT(*) FROM membres WHERE ID = p_sid AND adminLevel >= 2) = 1 THEN
SET outputCode :=(
SELECT
(
CASE
WHEN LENGTH(p_name) > 255 THEN 2014
WHEN CAST(p_name AS BINARY) NOT REGEXP BINARY '^[-a-zA-Z0-9\_ ]+$' THEN 2015
WHEN(
SELECT
COUNT(*)
FROM
discussions
WHERE
name = p_name
) > 0 THEN 2016
ELSE 42
END
)
);
END IF;
ELSE
SET outputCode = 2013;
END IF;
IF outputCode = 42 THEN INSERT INTO discussions(name,creatorID,dateCreation,authorizedGroupId) VALUES (CAST(p_name AS CHAR(255)),p_sid,NOW(),0); END IF;
END//
DELIMITER ;

46
sql/deleteMessage.sql Normal file
View File

@ -0,0 +1,46 @@
DROP PROCEDURE IF EXISTS DeleteMessage;
DELIMITER //
CREATE PROCEDURE DeleteMessage
(
IN p_sid INT,
IN p_password TEXT,
IN p_mid INT,
OUT outputCode INT,
OUT did INT
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 THEN
SET outputCode :=(
SELECT
(
CASE
WHEN(
SELECT
COUNT(*)
FROM
messages
WHERE
ID = p_mid
) = 1 THEN 2010
ELSE 42
END
)
);
IF outputCode = 42 THEN
SET did :=(SELECT discussionID FROM messages WHERE ID = p_mid);
SET @authorizedGroupID :=(SELECT authorizedGroupID FROM discussions WHERE ID=did);
CALL `CheckInGroup`(p_sid, @authorizedGroupID, outputCode);
IF outputCode = 42 THEN
DELETE FROM messages WHERE ID = p_mid;
END IF;
END IF;
END IF;
END//
DELIMITER ;

View File

@ -0,0 +1,18 @@
DROP PROCEDURE IF EXISTS GetAuthorizedProjectsForPresentation;
DELIMITER //
CREATE PROCEDURE GetAuthorizedProjectsForPresentation
(
IN p_sid TEXT,
IN p_password TEXT,
OUT outputCode INT(11)
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 THEN
INSERT INTO projects SELECT p.ID AS projectID, p.name AS projectName, v.ID AS versionID , v.name AS versionName FROM projets AS p LEFT JOIN versions AS v ON p.ID = v.projectID WHERE (p.ownerID = p_sid OR CheckInGroup(p_sid,p.secondaryOwnersGroupID) = 42) AND (v.ID IS NULL OR v.versionAbs = (SELECT MAX(versionAbs) FROM versions WHERE projectID = p.ID));
END IF;
END//
DELIMITER ;

View File

@ -0,0 +1,19 @@
DROP PROCEDURE IF EXISTS GetPublicProjectsForPresentation;
DELIMITER //
CREATE PROCEDURE GetPublicProjectsForPresentation
(
IN p_sid TEXT,
IN p_password TEXT,
OUT outputCode INT(11)
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 OR outputCode = 2005 THEN
SET outputCode = 42;
INSERT INTO projects SELECT p.ID AS projectID, p.name AS projectName, v.ID AS versionID , v.name AS versionName FROM projets AS p LEFT JOIN versions AS v ON p.ID = v.projectID WHERE (p.ownerID = 1 OR CheckInGroup(1,p.secondaryOwnersGroupID) = 42 OR CheckInGroup(1,p.authorizedGroupID) = 42) AND (v.ID IS NULL OR v.versionAbs = (SELECT MAX(versionAbs) FROM versions WHERE projectID = p.ID));
END IF;
END//
DELIMITER ;

21
sql/getVisibleDiscuts.sql Normal file
View File

@ -0,0 +1,21 @@
DROP PROCEDURE IF EXISTS GetVisibleDiscuts;
DELIMITER //
CREATE PROCEDURE GetVisibleDiscuts
(
IN p_sid TEXT,
IN p_password TEXT,
OUT outputCode INT(11),
OUT canCreate INT(1)
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 OR outputCode = 2005 THEN
SET outputCode = 42;
SELECT adminLevel > 8 INTO canCreate FROM membres WHERE ID=p_sid;
INSERT INTO discuts SELECT d.ID AS ID, d.name AS Name, m.pseudo AS creatorPseudo FROM discussions AS d LEFT JOIN membres AS m ON d.creatorID = m.ID WHERE CheckInGroup(p_sid,authorizedGroupId) = 42;
END IF;
END//
DELIMITER ;

24
sql/headerInfos.sql Normal file
View File

@ -0,0 +1,24 @@
DROP PROCEDURE IF EXISTS HeaderInfos;
DELIMITER //
CREATE PROCEDURE HeaderInfos
(
IN p_sid TEXT,
IN p_password TEXT,
OUT outputCode INT(11),
OUT o_connected INT(1),
OUT o_pseudo VARCHAR(255)
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 THEN
SELECT pseudo INTO o_pseudo FROM membres WHERE ID = p_sid;
SET o_connected = 1;
ELSE
SET outputCode = 42;
SET o_connected = 0;
END IF;
END//
DELIMITER ;

46
sql/postMessage.sql Normal file
View File

@ -0,0 +1,46 @@
DROP PROCEDURE IF EXISTS PostMessage;
DELIMITER //
CREATE PROCEDURE PostMessage
(
IN p_sid INT,
IN p_password TEXT,
IN p_did INT,
IN p_text TEXT,
OUT outputCode INT,
OUT mid INT
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 THEN
SET outputCode :=(
SELECT
(
CASE
WHEN(
SELECT
COUNT(*)
FROM
discussions
WHERE
ID = p_did
) = 1 THEN 2010
ELSE 42
END
)
);
IF outputCode = 42 THEN
SET @authorizedGroupID :=(SELECT authorizedGroupID FROM discussions WHERE ID=p_did);
CALL `CheckInGroup`(p_sid, @authorizedGroupID, outputCode);
IF outputCode = 42 THEN
INSERT INTO messages(texte,senderID,sendTime,discussionID) VALUES (p_text,p_sid,NOW(),p_did);
SET mid :=(SELECT LAST_INSERT_ID());
END IF;
END IF;
END IF;
END//
DELIMITER ;

30
sql/presentProject.sql Normal file
View File

@ -0,0 +1,30 @@
DROP PROCEDURE IF EXISTS PresentProject;
DELIMITER //
CREATE PROCEDURE PresentProject
(
IN p_sid INT,
IN p_password TEXT,
IN p_pid INT,
OUT outputCode INT(11),
OUT o_public INT(1),
OUT o_name VARCHAR(255),
OUT o_ownerID INT,
OUT o_ownerPseudo VARCHAR(255)
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 OR outputCode = 2005 THEN
SET outputCode := (SELECT (CASE WHEN (SELECT CheckInGroup(p_sid,authorizedGroupId) = 42 OR CheckInGroup(p_sid,secondaryOwnersGroupId) = 42 OR p_sid = ownerID FROM projets WHERE ID = p_pid) THEN 42 ELSE 2017 END));
IF outputCode = 42 THEN
SELECT authorizedGroupId = 1 AS public, name INTO o_public, o_name FROM projets WHERE projets.ID = p_pid;
SELECT membres.pseudo, membres.ID INTO o_ownerPseudo, o_ownerID FROM membres INNER JOIN projets ON projets.ownerID = membres.ID WHERE projets.ID = p_pid;
INSERT INTO verzions SELECT languageID AS language, ID, name FROM versions WHERE projectID = p_pid;
INSERT INTO sowners SELECT pseudo FROM membres INNER JOIN projets ON projets.ownerID != membres.ID AND CheckInGroup(membres.ID,projets.secondaryOwnersGroupID) = 42 WHERE projets.ID = p_pid;
END IF;
END IF;
END//
DELIMITER ;

34
sql/presentVersion.sql Normal file
View File

@ -0,0 +1,34 @@
DROP PROCEDURE IF EXISTS PresentVersion;
DELIMITER //
CREATE PROCEDURE PresentVersion
(
IN p_sid INT,
IN p_password TEXT,
IN p_vid INT,
OUT outputCode INT(11),
OUT o_su INT(1),
OUT o_ssu INT(1),
OUT o_langageID INT,
OUT o_projectName VARCHAR(255),
OUT o_name VARCHAR(255),
OUT o_fileAccessibility INT,
OUT o_projectID INT,
OUT o_tags INT
)
MODIFIES SQL DATA
BEGIN
CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 OR outputCode = 2005 THEN
SET outputCode := (SELECT (CASE WHEN (SELECT CheckInGroup(p_sid,authorizedGroupId) = 42 OR CheckInGroup(p_sid,secondaryOwnersGroupId) = 42 OR p_sid = ownerID FROM projets INNER JOIN versions ON versions.projectID = projets.ID WHERE versions.ID = p_vid) THEN 42 ELSE 2018 END));
IF outputCode = 42 THEN
SELECT CheckInGroup(p_sid,projets.secondaryOwnersGroupId) = 42 OR projets.ownerID = p_sid, projets.ownerID = p_sid, versions.languageID, projets.name,versions.name,versions.fileAccessibility,projets.ID,versions.tags INTO o_su,o_ssu,o_langageID,o_projectName,o_name,o_fileAccessibility,o_projectID,o_tags FROM projets INNER JOIN versions ON versions.projectID = projets.ID WHERE versions.ID = p_vid;
INSERT INTO verzions SELECT languageID AS language, ID, name FROM versions WHERE projectID = o_projectID;
END IF;
END IF;
END//
DELIMITER ;

33
sql/registerPerson.sql Normal file
View File

@ -0,0 +1,33 @@
DROP PROCEDURE IF EXISTS RegisterPerson;
DELIMITER //
CREATE PROCEDURE RegisterPerson
(
IN p_pseudo TEXT,
IN p_password TEXT,
OUT outputCode INT
)
MODIFIES SQL DATA
BEGIN
SET outputCode :=(
SELECT
(
CASE
WHEN LENGTH(p_pseudo) > 255 THEN 2002
WHEN CAST(p_pseudo AS BINARY) NOT REGEXP BINARY '^[-a-zA-Z0-9\_]+$' THEN 2003
WHEN(
SELECT
COUNT(*)
FROM
membres
WHERE
pseudo = p_pseudo
) > 0 THEN 2004
ELSE 42
END
)
);
IF outputCode = 42 THEN INSERT INTO membres(pseudo,hashedPassword,dateCreation) VALUES (CAST(p_pseudo AS CHAR(255)),MD5(p_password),NOW()); END IF;
END//
DELIMITER ;

View File

@ -1,5 +1,20 @@
<?php session_start(); ?>
<?php include_once 'clazz/Zincluder.php';?>
<?php
session_start();
include_once 'clazz/Zincluder.php';
try{
$version = Version::showVersion($_SESSION['session_id'] ?? NULL,$_SESSION['session_mdp'] ?? NULL,$_GET['v'] ?? NULL);
}catch(SQLProcessingException $e){
echo $e->getHtmlMessage();
$_SESSION ['current_error'] = $e->getHtmlMessage();
header ( 'Location:' . ($e->getPreferredRedirection() ?? 'others.php') );
exit;
}
?>
<!DOCTYPE html>
<html>
@ -10,66 +25,49 @@
<body>
<?php include 'includes/header.php'; ?>
<?php
//TODO re la fonction exiting
$me = Membre::me();
if(!isset($_GET['v'])){
header ( 'Location:projets.php');
$_SESSION ['current_error'] = 'Quand on demande des donn&eacute;es, on donne des donn&eacute;es !!!';
exit;
}
$version = new Version($_GET['v']);
if(!$version->exists()){
header ( 'Location:projets.php');
$_SESSION ['current_error'] = 'Je vais avoir du mal &agrave; afficher les don&eacute;es de la version n&eacute;ant ...';
exit;
}
if(count($version->getPublicFiles())<=0 && $me?$me->isAdminLevelLowerThan(12):FALSE && !$version->getProject()->haveRights()){
header ( 'Location:projets.php');
$_SESSION ['current_error'] = 'Vous n\'avez pas le droit d\'&ecirc;tre ici ...<br/> DEGAGEZ !!!';
exit;
}
$su = $me?$version->getProject()->haveRights($me):FALSE OR $me?$me->isAdminLevelGreaterThan(12):FALSE;
$ssu = $me?$me->getID() == $version->getProject()->getOwner()->getID():FALSE OR $me?$me->isAdminLevelGreaterThan(13):FALSE;
$su = $version['su'];
$ssu = $version['ssu'];
$langage = Langage::getFromId($version['langage']);
?>
<h1>Le projet <?php echo($version->getProject()->getName()) ?> en version <?php echo($version->getName()) ?></h1>
<h1>Le projet <?php echo($version['projectName']) ?> en version <?php echo($version['name']) ?></h1>
<br/>
<?php if($version->getLanguage()->isJarAvalivable()){?>
<a class="project_option" href=<?php if($version->isJarPublic() OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=jar&amp;v='.$version->getID() . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($version->isJarPublic() OR $su)){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger le jar" title="T&eacute;l&eacute;charger le jar" src="pictures/download_jar.png"/>
<?php if($langage->isJarAvalivable()){?>
<a class="project_option" href=<?php if($langage->isJarAccessible($version['fileAccessibility']) OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=jar&amp;v='.$version['ID'] . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($langage->isJarAccessible($version['fileAccessibility']) OR $su)){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger le jar" title="T&eacute;l&eacute;charger le jar" src="pictures/download_jar.png"/>
</a>
<?php }if($version->getLanguage()->isJavaAvalivable()){ ?>
<a class="project_option" href=<?php if($version->isJavaPublic() OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=java&amp;v='.$version->getID() . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($version->isJavaPublic() OR $su)){echo(" disabeled");} ?>" alt="Voir la source" title="Voir la source" src="pictures/view_code.png"/>
<?php }if($langage->isJavaAvalivable()){ ?>
<a class="project_option" href=<?php if($langage->isJavaAccessible($version['fileAccessibility']) OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=java&amp;v='.$version['ID'] . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($langage->isJavaAccessible($version['fileAccessibility']) OR $su)){echo(" disabeled");} ?>" alt="Voir la source" title="Voir la source" src="pictures/view_code.png"/>
</a>
<?php }if($version->getLanguage()->isJavaAvalivable()){ ?>
<a class="project_option" href=<?php if($version->isJavaPublic() OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=java&amp;v='.$version->getID() . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($version->isJavaPublic() OR $su)){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger la source" title="T&eacute;l&eacute;charger la source" src="pictures/download_code.png"/>
<?php }if($langage->isJavaAvalivable()){ ?>
<a class="project_option" href=<?php if($langage->isJavaAccessible($version['fileAccessibility']) OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=java&amp;v='.$version['ID'] . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($langage->isJavaAccessible($version['fileAccessibility']) OR $su)){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger la source" title="T&eacute;l&eacute;charger la source" src="pictures/download_code.png"/>
</a>
<?php }if($version->getLanguage()->isJavadocAvalivable()){ ?>
<a class="project_option" href=<?php if($version->isJavadocPublic() OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=javadoc&amp;v='.$version->getID() . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($version->isJavadocPublic() OR $su)){echo(" disabeled");} ?>" alt="Voir la doc" title="Voir la doc" src="pictures/view_javadoc.png"/>
<?php }if($langage->isJavadocAvalivable()){ ?>
<a class="project_option" href=<?php if($langage->isJavadocAccessible($version['fileAccessibility']) OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=javadoc&amp;v='.$version['ID'] . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($langage->isJavadocAccessible($version['fileAccessibility']) OR $su)){echo(" disabeled");} ?>" alt="Voir la doc" title="Voir la doc" src="pictures/view_javadoc.png"/>
</a>
<?php }if($version->getLanguage()->isJavadocAvalivable()){ ?>
<a class="project_option" href=<?php if($version->isJavadocPublic() OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=javadoc&amp;v='.$version->getID() . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($version->isJavadocPublic() OR $su)){echo(" disabeled");} ?>" alt="T&eacute;lecharger la doc" title="T&eacute;lecharger la doc" src="pictures/download_javadoc.png"/>
<?php }if($langage->isJavadocAvalivable()){ ?>
<a class="project_option" href=<?php if($langage->isJavadocAccessible($version['fileAccessibility']) OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=javadoc&amp;v='.$version['ID'] . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($langage->isJavadocAccessible($version['fileAccessibility']) OR $su)){echo(" disabeled");} ?>" alt="T&eacute;lecharger la doc" title="T&eacute;lecharger la doc" src="pictures/download_javadoc.png"/>
</a>
<?php }if($version->getLanguage()->isXlsmAvalivable()){ ?>
<a class="project_option" href=<?php if($version->isXlsmPublic() OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=xlsm&amp;v='.$version->getID() . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($version->isXlsmPublic() OR $su)){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger le xlsm" title="T&eacute;l&eacute;charger le xlsm" src="pictures/download_xlsm.png"/>
<?php }if($langage->isXlsmAvalivable()){ ?>
<a class="project_option" href=<?php if($langage->isXlsmAccessible($version['fileAccessibility']) OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=xlsm&amp;v='.$version['ID'] . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($langage->isXlsmAccessible($version['fileAccessibility']) OR $su)){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger le xlsm" title="T&eacute;l&eacute;charger le xlsm" src="pictures/download_xlsm.png"/>
</a>
<?php }if($version->getLanguage()->isVbAvalivable()){ ?>
<a class="project_option" href=<?php if($version->isVbPublic() OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=vb&amp;v='.$version->getID() . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($version->isVbPublic() OR $su)){echo(" disabeled");} ?>" alt="Voir la source" title="Voir la source" src="pictures/voir_vb.png"/>
<?php }if($langage->isVbAvalivable()){ ?>
<a class="project_option" href=<?php if($langage->isVbAccessible($version['fileAccessibility']) OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=vb&amp;v='.$version['ID'] . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($langage->isVbAccessible($version['fileAccessibility']) OR $su)){echo(" disabeled");} ?>" alt="Voir la source" title="Voir la source" src="pictures/voir_vb.png"/>
</a>
<?php }if($version->getLanguage()->isVbAvalivable()){ ?>
<a class="project_option" href=<?php if($version->isVbPublic() OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=vb&amp;v='.$version->getID() . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($version->isVbPublic() OR $su)){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger la source" title="T&eacute;l&eacute;charger la source" src="pictures/download_vb.png"/>
<?php }if($langage->isVbAvalivable()){ ?>
<a class="project_option" href=<?php if($langage->isVbAccessible($version['fileAccessibility']) OR $su){ echo( '"http://megabernard.alwaysdata.net/megaDownload.php?t=vb&amp;v='.$version['ID'] . '"');}else{ echo( "\"#\"");} ?>>
<img class="project_option_img<?php if(!($langage->isVbAccessible($version['fileAccessibility']) OR $su)){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger la source" title="T&eacute;l&eacute;charger la source" src="pictures/download_vb.png"/>
</a>
<?php } ?>
<script>
var projectID = <?php echo $version->getProject()->getID(); ?>;
var versionID = <?php echo $version->getID(); ?>;
var projectID = <?php echo $version['projectID']; ?>;
var versionID = <?php echo $version['ID']; ?>;
</script>
<?php if($ssu){ ?>
@ -83,20 +81,20 @@
<div class="screen-horizontal-centered" id="editVersionPan">
<form id="eVersionForm">
<label for="nVersionName">Nom de la version</label>
<input type="text" id="nVersionName"><?php echo $version->getName(); ?></input><br/>
<input type="text" id="nVersionName"><?php echo $version['name'] ?></input><br/>
<label for="languageSelect">Langage :</label>
<select id="languageSelect">
<option value="Java" <?php if($version->getLanguage() == Langage::$java)echo 'selected=""'; ?>>Java</option>
<option value="VBA"<?php if($version->getLanguage() == Langage::$vba)echo 'selected=""'; ?>>VBA</option>
<option value="Java" <?php if($version['langage'] == Langage::$java->getID())echo 'selected=""'; ?>>Java</option>
<option value="VBA"<?php if($version['langage'] == Langage::$vba->getID())echo 'selected=""'; ?>>VBA</option>
</select><br/>
<label for="VAlphaCheck">Alpha : </label>
<input type="checkbox" id="VAlphaCheck" value="alpha" <?php if($version->isAlpha())echo 'checked=""'; ?>/><br/>
<input type="checkbox" id="VAlphaCheck" value="alpha" <?php if($version['alpha'])echo 'checked=""'; ?>/><br/>
<label for="VBetaCheck">Beta : </label>
<input type="checkbox" id="VBetaCheck" value="beta" <?php if($version->isBeta())echo 'checked=""'; ?>/><br/>
<input type="checkbox" id="VBetaCheck" value="beta" <?php if($version['beta'])echo 'checked=""'; ?>/><br/>
<label for="VReleaseCheck">Release : </label>
<input type="checkbox" id="VReleaseCheck" value="release" <?php if($version->isRelease())echo 'checked=""'; ?>/><br/>
<input type="checkbox" id="VReleaseCheck" value="release" <?php if($version['release'])echo 'checked=""'; ?>/><br/>
<label for="VBuggedCheck">Bogu&eacute; : </label>
<input type="checkbox" id="VBuggedCheck" value="bugged" <?php if($version->isBugged())echo 'checked=""'; ?>/><br/>
<input type="checkbox" id="VBuggedCheck" value="bugged" <?php if($version['bugged'])echo 'checked=""'; ?>/><br/>
</form><br/>
<ul class="gray-bordered fast-full-width gone-puce">
Mise a jour de la liste
@ -331,18 +329,20 @@
<br/>
<br/>
<?php $versions = Version::getFromProject($version->getProject()); ?>
<?php if(is_array($versions)){/* = if count(versions>1) */ ?>
<?php $languages = Langage::getLanguagesFromVersions($versions); ?>
<?php if(count($version['brothers']) > 0){ ?>
<?php $languages = array();
foreach($version['brothers'] AS $v)
array_push($languages,$v['language']);
$languages = array_unique($languages,SORT_REGULAR); ?>
<h3>Toutes les versions :</h3>
<br/>
<?php foreach($languages as $language){ ?>
<table class="versionTable">
<tr>
<th><?php echo $language->getName(); ?></th>
<th><?php echo Langage::getFromId($language)->getName(); ?></th>
</tr>
<?php foreach (Utility::arrayIfNot($versions) as $writingVersion){if($writingVersion->getLanguage() == $language){ ?>
<tr><td><a href = "version.php?v=<?php echo $writingVersion->getID();?>"><?php echo $writingVersion->getName(); ?></a></td></tr>
<?php foreach ($version['brothers'] as $writingVersion){if($writingVersion['language'] == $language){ ?>
<tr><td><a href = "version.php?v=<?php echo $writingVersion['ID'];?>"><?php echo $writingVersion['name']; ?></a></td></tr>
<?php }}?>
</table>
<?php } ?>