89 lines
3.3 KiB
PHP
89 lines
3.3 KiB
PHP
<?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éation doit être de la forme "AAAA:MM:JJ hh:mm:ss"';
|
|
const DATE_CREATION_CHANGED = 'La date de création a bien été changée';
|
|
}
|