Découpage du traitement en ercore plus de classes
This commit is contained in:
parent
6c9434e092
commit
c9589d2cf6
175
admin.php
175
admin.php
@ -1,176 +1 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once 'clazz/Zincluder.php;';
|
|
||||||
session_start ();
|
|
||||||
$me = new Membre ( $_SESSION ['session_id'] );
|
|
||||||
$me->connect ( $_SESSION ['session_mdp'] );
|
|
||||||
if ($me->isAdminLevelLowerThan ( 15 )) {
|
|
||||||
header ( 'Location:401.php' );
|
|
||||||
exit ();
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<link rel="stylesheet" href="css/adminStyle.css" />
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>La console d'admin</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script
|
|
||||||
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
|
|
||||||
|
|
||||||
<select id="commandSelector">
|
|
||||||
<option value="get" selected="true">get</option>
|
|
||||||
<option value="set">set</option>
|
|
||||||
<option value="remove">remove</option>
|
|
||||||
<option value="add">add</option>
|
|
||||||
<option value="BDD">BDD</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<div id="setDiv">
|
|
||||||
|
|
||||||
<form id="setFormObject">
|
|
||||||
Objet<br /> <select class="classSelector" id="setClassSelector">
|
|
||||||
<!-- Rempli en JS -->
|
|
||||||
</select><br />
|
|
||||||
<button id="selectFromObject">Séléctionner</button>
|
|
||||||
</form>
|
|
||||||
<!--
|
|
||||||
Pour enlever les vilains whitespace
|
|
||||||
-->
|
|
||||||
<form id="setChampsForm">
|
|
||||||
Valeur<br /> <select id="setChamps">
|
|
||||||
<!-- Rempli en JS -->
|
|
||||||
</select> <select id="arrayOperation">
|
|
||||||
<option value="add" selected="selected">add</option>
|
|
||||||
<option value="set">set</option>
|
|
||||||
<option value="remove">remove</option>
|
|
||||||
</select> <input type="text" id="primitiveValueField" />
|
|
||||||
<button id="selectComplexValue">Séléctionner</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<button id="send">Envoyer la requête</button>
|
|
||||||
<br />
|
|
||||||
<samp id="adminDialogAnswer">
|
|
||||||
Hello !!!<br />
|
|
||||||
</samp>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="fullscreen opaque">
|
|
||||||
<div class="screen-vertical-centered">
|
|
||||||
<form class="screen-horizontal-centered selectorForm">
|
|
||||||
<!-- ID set en JS (bonjour la galère) -->
|
|
||||||
|
|
||||||
<!-- Attributs remplis en JS -->
|
|
||||||
<span>
|
|
||||||
<input type="checkbox" />
|
|
||||||
<h5>Nom du champ</h5>
|
|
||||||
<select>
|
|
||||||
<option value="ee">=</option>
|
|
||||||
<option value="lt"><</option>
|
|
||||||
<option value="gt">></option>
|
|
||||||
<option value="ge">≥</option>
|
|
||||||
<option value="le">≤</option>
|
|
||||||
<option value="ne">≠</option>
|
|
||||||
</select>
|
|
||||||
<input type="text" />
|
|
||||||
<button id="nomDuChampSelector">Selecteur</button>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script type="text/javascript">
|
|
||||||
function done(){
|
|
||||||
var objet = $(this).parent().data('object');//SetObjectSelector-projectSelector
|
|
||||||
var selector = new Array();
|
|
||||||
/*
|
|
||||||
$(this).parent().children('div').each(function() {
|
|
||||||
if($(this).children('input[type="checkbox"]').is(':selected')){
|
|
||||||
var varName = $(this).parent().children('h5').text();
|
|
||||||
var operator = $(this).parent().children('h5').text();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
$(this).parent().children('div').children('input[type="checkbox"]:selected').each(function() {
|
|
||||||
var varName = $(this).parent().children('h5').text();
|
|
||||||
var operator = $(this).parent().children('select').find(':selected').attr('value');
|
|
||||||
var value;
|
|
||||||
if($(this).parent().children('input[type="text"]').length)
|
|
||||||
value = $(this).parent().children('input[type="text"]').val();
|
|
||||||
else
|
|
||||||
value = $(this).parent().children('button').data('selector');
|
|
||||||
selector[varName] = operator+value;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$('#'+objet).data('selector',JSON.stringify(selector));
|
|
||||||
}
|
|
||||||
|
|
||||||
function selector(object,clazz) {
|
|
||||||
var newForm = $('<form></form>');
|
|
||||||
newForm.data('object',object);
|
|
||||||
switch(clazz){
|
|
||||||
case 'membre':
|
|
||||||
newForm.append(selectorNode('pseudo',true,false,false));
|
|
||||||
newForm.append(selectorNode('password',true,false,false));
|
|
||||||
newForm.append(selectorNode('adminLevel',true,false,true));
|
|
||||||
newForm.append(selectorNode('dateCreation',true,false,true));
|
|
||||||
newForm.append(selectorNode('requiredBanner',true,false,false));
|
|
||||||
newForm.append(selectorNode('personnalMessage',true,false,false));
|
|
||||||
break;
|
|
||||||
case 'projet':
|
|
||||||
newForm.append(selectorNode('name',true,false,false));
|
|
||||||
newForm.append(selectorNode('dateCreation',true,false,true));
|
|
||||||
newForm.append(selectorNode('owner',false,false,false));
|
|
||||||
newForm.append(selectorNode('secondaryOwner',false,true,false));
|
|
||||||
break;
|
|
||||||
case 'version':
|
|
||||||
newForm.append(selectorNode('name',true,false,false));
|
|
||||||
newForm.append(selectorNode('sendDate',true,false,true));
|
|
||||||
newForm.append(selectorNode('publicFiles',true,true,false));
|
|
||||||
newForm.append(selectorNode('tags',true,true,false));
|
|
||||||
newForm.append(selectorNode('project',false,false,false));
|
|
||||||
newForm.append(selectorNode('language',true,false,false));
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
newForm.append('<br/>');
|
|
||||||
newForm.append('<button id="selectorAbort">Annuler</button>')
|
|
||||||
newForm.append('<button id="selectorDone">Terminé</button>');
|
|
||||||
$('form.selectorForm').replaceWith(newForm);
|
|
||||||
}
|
|
||||||
function selectorNode(name,primitive,array,number){
|
|
||||||
var span = $('<span></span>');
|
|
||||||
span.append('<input type="checkbox" />')
|
|
||||||
span.append('<h5>'+name+'</h5>')
|
|
||||||
if(number)
|
|
||||||
span.append('<select><option value="ee">=</option><option value="lt"><</option><option value="gt">></option><option value="ge">≥</option><option value="le">≤</option><option value="ne">≠</option></select>')
|
|
||||||
else if(array)
|
|
||||||
span.append('<select><option value="in">∈</option><option value="nn">∉</option></select>')
|
|
||||||
else
|
|
||||||
span.append('<select><option value="ee">=</option><option value="ne">≠</option></select>')
|
|
||||||
if(primitive)
|
|
||||||
span.append('<input type="text" />')
|
|
||||||
else
|
|
||||||
span.append('<button id="'+name+'Selector">Selecteur</button>')
|
|
||||||
}
|
|
||||||
|
|
||||||
function genClassesSelectors{
|
|
||||||
$('select.classSelector')
|
|
||||||
.append('<option value="membre">Membre</option>')
|
|
||||||
.append('<option value="projet">Projet</option>')
|
|
||||||
.append('<option value="version">Version</option>')
|
|
||||||
.append('<option value="discussion">Discussion</option>')
|
|
||||||
.append('<option value="message">Message</option>');
|
|
||||||
}
|
|
||||||
$(window).load(genClassesSelectors);
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
234
admindialog.php
234
admindialog.php
@ -1,224 +1,52 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
include_once 'clazz/Membre.class.php';
|
||||||
include_once 'clazz/Zincluder.php';
|
include_once 'includes/bdd.php';
|
||||||
|
|
||||||
$me = new Membre();
|
$me = new Membre();
|
||||||
$me->connect();
|
$me->connect();
|
||||||
|
|
||||||
if($me->isAdminLevelLowerThan(15)){
|
if($me->getAdminLevel()<15){
|
||||||
echo 'Your admin level is too low (15 or more required)';
|
echo 'Your admin level is too low (15 or more required)';
|
||||||
exit;
|
exit;
|
||||||
}elseif(!isset($_POST['command'])){
|
}elseif(!isset($_GET['action'])){
|
||||||
echo 'Please set an command in the URL (POST method ,name:"command")';
|
echo 'Please set an action in the URL (GET method ,name:"action")';
|
||||||
exit;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
function isAlphaNumeric($char){
|
|
||||||
return isAlphabetic($char) or isNumeric($char);
|
|
||||||
}
|
|
||||||
function isAlphabetic($char){
|
|
||||||
return preg_match('#^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]$#',$char) === 1;
|
|
||||||
}
|
|
||||||
function isNumeric($char){
|
|
||||||
return preg_match('#^[0123456789]$#',$char) === 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function error($pos,$reason){
|
|
||||||
echo 'Error at char '.$pos.' : '.$reason;
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
function readAlphabetic($command){
|
switch ($_GET['action']){
|
||||||
global $pos;
|
|
||||||
$out = "";
|
case 'set_discutionVisibility' :
|
||||||
while (isAlphaNumeric($command[$pos])) {
|
if(!isset($_POST['discutionVisibility'])){
|
||||||
$out .= $command[$pos];
|
echo 'You must give a discution visibility (POST method,name:"discutionVisibility")';
|
||||||
$pos+=1;
|
exit;
|
||||||
}
|
}
|
||||||
return $out;
|
if(!isset($_POST['discutionID'])){
|
||||||
}
|
echo 'You must give a discution ID (POST method,name:"discutionID")';
|
||||||
|
exit;
|
||||||
function readNumeric($command){
|
|
||||||
//TODO Add non-integer support (virgule , puissance , autres bases ...)
|
|
||||||
global $pos;
|
|
||||||
$out = "";
|
|
||||||
while (isNumeric($command[$pos])) {
|
|
||||||
$out .= $command[$pos];
|
|
||||||
$pos+=1;
|
|
||||||
}
|
}
|
||||||
return intval($out);
|
$discutionVisibility = $_POST['discutionVisibility'];
|
||||||
}
|
$discutionID = $_POST['discutionID'];
|
||||||
|
if ($discutionVisibility !== 'p' and preg_match ( "#^a[0-9]+$#",$discutionVisibility ) != 1 and preg_match ( '#^x([0-9]+;)*([0-9]+)?$#', $discutionVisibility ) != 1 ){
|
||||||
function readString($command,$startChar='\"'){
|
echo 'Your discution visibility is not well-formed : it should have been formed like ("p" or "x31;41;59;26;53" or "a42")';
|
||||||
global $pos;
|
exit;
|
||||||
$out = "";
|
|
||||||
$startChar = $command[$pos];
|
|
||||||
$pos+=1;
|
|
||||||
while (TRUE) {
|
|
||||||
$char = $command[$pos];
|
|
||||||
if($char === $startChar)
|
|
||||||
break;
|
|
||||||
if($char === '\\'){
|
|
||||||
$pos+=1;
|
|
||||||
switch ($command[$pos]){
|
|
||||||
case '\\':
|
|
||||||
$char = '\\';
|
|
||||||
break;
|
|
||||||
case $startChar:
|
|
||||||
$char = $startChar;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
error($pos,'Unexpected "'.$command['pos'].'" after "\\"');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$out .= $char;
|
|
||||||
$pos+=1;
|
|
||||||
}
|
}
|
||||||
$pos +=1;
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
$operators = array('=','!=','>','<','>=','=>','<=','=<','&has;','&nhas;');
|
$req = $GLOBALS['bdd']->prepare('UPDATE discussions SET autorized=? WHERE ID=?');
|
||||||
$operatorsChars = array('=','!','<','>','&');
|
$req->execute(array($discutionVisibility,$discution));
|
||||||
|
|
||||||
function readOperator($command,$endChar = 'abcdefghijklmnopqrstuvwxytABCDEFGHIJKLMNOPQRSTUVWZYZ0123456789"\''){
|
|
||||||
global $pos,$operators;
|
|
||||||
if($command[$pos] === '&'){
|
|
||||||
$pos+=1;
|
|
||||||
$inOperator = readAlphabetic($command);
|
|
||||||
if($command[$pos] !== ';'){
|
|
||||||
error($pos, 'Unexepted character at the end of the operator ' . $inOperator);
|
|
||||||
}
|
|
||||||
return '&'.$inOperator.';';
|
|
||||||
}
|
|
||||||
$reading = '';
|
|
||||||
$lastOperator = '';
|
|
||||||
$maxPos=min(strlen($command),$pos+5);
|
|
||||||
$tPos = $pos;
|
|
||||||
while ($tPos<$maxPos) {
|
|
||||||
$reading .= $command[$pos];
|
|
||||||
$tPos+=1;
|
|
||||||
if(in_array($reading,$operators,TRUE))
|
|
||||||
$lastOperator=$reading;
|
|
||||||
}
|
|
||||||
$pos += strLen($lastOperator);
|
|
||||||
if(!in_array($lastOperator,$operators))
|
|
||||||
error($pos, 'Unknown operator : '.$out);
|
|
||||||
return $lastOperator;
|
|
||||||
}
|
|
||||||
|
|
||||||
function readSelector($command){
|
|
||||||
global $pos,$operatorsChars;
|
|
||||||
$out = array();
|
|
||||||
$pos += 1;//@
|
|
||||||
if(!isAlphabetic($command[$pos]))
|
|
||||||
error($pos,'Unexepted non-alphabetic char "'.$command[$pos].'" after @');
|
|
||||||
$className = readAlphabetic($command,'[');
|
|
||||||
$pos += 1;//[ +1
|
|
||||||
$attributes = array();
|
|
||||||
while($command[$pos] !== ']'){
|
|
||||||
if($command[$pos] === ',')
|
|
||||||
$pos+=1;
|
|
||||||
$attributeName = readAlphabetic($command,implode($operatorsChars));
|
|
||||||
$operator = readOperator($command);
|
|
||||||
$data = null;
|
|
||||||
$type = $command[$pos];
|
|
||||||
if(isAlphabetic($type)){
|
|
||||||
$data = array('a',readAlphabetic($command));
|
|
||||||
}elseif (isNumeric($type)){
|
|
||||||
$data = array('0',readNumeric($command));
|
|
||||||
}elseif ($type === '"' or $type === '\''){
|
|
||||||
$data = array('\"',readString($command));
|
|
||||||
}elseif ($type === "@"){
|
|
||||||
$data = array('@',readSelector($command));
|
|
||||||
}
|
|
||||||
$attribute = array();
|
|
||||||
$attribute[0] = $attributeName;
|
|
||||||
$attribute[1] = $operator;
|
|
||||||
$attribute[2] = $data;
|
|
||||||
$attributes[] = $attribute;
|
|
||||||
}
|
|
||||||
$pos+=1;//after "["
|
|
||||||
if($command[$pos] == ':'){
|
|
||||||
$pos+=1;//letter after ":"
|
|
||||||
$selectedAttribute = readAlphabetic($command);
|
|
||||||
return array($className,$attributes,$selectedAttribute);
|
|
||||||
}
|
|
||||||
return array($className,$attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$command=$_POST['command'].' ';
|
|
||||||
$nommes=array();
|
|
||||||
$pos=0;
|
|
||||||
while ($pos<strlen($command)) {
|
|
||||||
echo $pos;
|
|
||||||
$nomme = array();
|
|
||||||
$type=$command[$pos];
|
|
||||||
if(isAlphabetic($type)){
|
|
||||||
$nomme[0] = 'a';
|
|
||||||
$nomme[1] = readAlphabetic($command);
|
|
||||||
}elseif (isNumeric($type)){
|
|
||||||
$nomme[0] = '0';
|
|
||||||
$nomme[1] = readNumeric($command);
|
|
||||||
}elseif ($type === '"' or $type === '\''){
|
|
||||||
$nomme[0] = '"';
|
|
||||||
$nomme[1] = readString($command);
|
|
||||||
}elseif (in_array($type,$operatorsChars,TRUE)){
|
|
||||||
$nomme[0] = "=";
|
|
||||||
$nomme[1] = readOperator($command);
|
|
||||||
}elseif ($type === "@"){
|
|
||||||
$nomme[0] = "@";
|
|
||||||
$nomme[1] = readSelector($command);
|
|
||||||
}
|
|
||||||
elseif ($type === ' ')break;
|
|
||||||
else error($pos, 'Unexpected char "'.$command[$pos].'" , cannot get the term type');
|
|
||||||
$nommes[] = $nomme;
|
|
||||||
$pos+=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo '<pre>';
|
|
||||||
print_r($nommes);
|
|
||||||
echo '</pre>';
|
|
||||||
|
|
||||||
function exception($reason){
|
|
||||||
echo 'An exception occurred : '.$reason;
|
|
||||||
|
|
||||||
|
exit;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
default :
|
||||||
|
echo 'Unknown action : '+$_GET['action'];
|
||||||
exit;
|
exit;
|
||||||
}
|
|
||||||
|
|
||||||
if($nommes[0][0] == 'a'){
|
|
||||||
//Command
|
|
||||||
$fonction = strtoupper($nommes[0][1]);
|
|
||||||
switch ($fonction){
|
|
||||||
case 'SET':
|
|
||||||
if(count($nommes) !== 42)
|
|
||||||
exception('La fonction n\'a pas recu le bon nombre d\'arguments (42)');
|
|
||||||
if($nommes[1][0] !== '@')
|
|
||||||
exception('Le deuxième argument doit etre un selecteur');
|
|
||||||
switch ($nommes[1][0][0]){
|
|
||||||
case 'Membre':
|
|
||||||
break;
|
|
||||||
case 'Projet':
|
|
||||||
break;
|
|
||||||
case 'Membre':
|
|
||||||
break;
|
|
||||||
case 'Projet':
|
|
||||||
break;
|
|
||||||
case 'Membre':
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
exception('Unknown selector class :'.$nommes[1][0][0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'DELETE':
|
|
||||||
|
|
||||||
default:
|
|
||||||
exception('Unknown function '.$fonction);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
199
clazz/Discussion.class.php
Normal file
199
clazz/Discussion.class.php
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
<?php
|
||||||
|
class Discussion{
|
||||||
|
|
||||||
|
protected $ID;
|
||||||
|
protected $name;
|
||||||
|
protected $creator;
|
||||||
|
protected $dateCreation;
|
||||||
|
protected $accessibility;
|
||||||
|
|
||||||
|
protected $valid;
|
||||||
|
|
||||||
|
public function __construct($ID){
|
||||||
|
$this->ID = $ID;
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM discussions WHERE ID=?');
|
||||||
|
$req->execute(array($ID));
|
||||||
|
if($rep = $req->fetch()){
|
||||||
|
$this->valid = TRUE;
|
||||||
|
$this->name = $rep['name'];
|
||||||
|
$this->creatorID = new Membre($rep['creatorID']);
|
||||||
|
$this->dateCreation = $rep['dateCreation'];
|
||||||
|
$this->accessibility = $rep['accessibility'];
|
||||||
|
}else{
|
||||||
|
$this->valid = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exists(){
|
||||||
|
return $this->valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString(){
|
||||||
|
$out = 'Discussion\n';
|
||||||
|
$out .= '\tID:' . $this->ID . '\n';
|
||||||
|
$out .= '\tName:' . $this->name . '\n';
|
||||||
|
$out .= '\tCreator:{' . substr(str_replace('\n\t',';',$this->creator->__toString()),0,-1) . '}\n';
|
||||||
|
$out .= '\tDate of creation:' . $this->dateCreation . '\n';
|
||||||
|
$out .= '\tAccessibility:' . $this->accessibility . '\n';
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Getters
|
||||||
|
public function getID(){
|
||||||
|
return $this->ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(){
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreator(){
|
||||||
|
return $creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDateCreation(){
|
||||||
|
return $this->dateCreation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAccessibility(){
|
||||||
|
return $this->accessibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Useful Getters
|
||||||
|
public function canAccess($membre){
|
||||||
|
$out = $this->accessibility === 'p';
|
||||||
|
$out = $out or $membre->getID() === $this->creator->getID();
|
||||||
|
if(preg_match ( "#^a[0-9]+$#", $this->accessibility ) == 1)
|
||||||
|
$out = $out or intval ( substr ( $this->accessibility, 1 ) ) <= $membre->getAdminLevel();
|
||||||
|
$out = $out or preg_match ( '#^x([0-9]+;)*' . $membre->getID() . '(;[0-9]+)*$#', $disc ['autorized'] ) == 1;
|
||||||
|
$out = $out or $membre->getAdminLevel() >= 14;
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Setters
|
||||||
|
public function rename($newName){
|
||||||
|
if(!exists())
|
||||||
|
return NULL;
|
||||||
|
if(getFromName($newName))
|
||||||
|
return Discussion::NAME_ALREADY_USED;
|
||||||
|
if(strlen($newName)>255)
|
||||||
|
return Discussion::TOO_LONG_NAME;
|
||||||
|
$regex = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.
|
||||||
|
'éèàµ_\\-\'()\\[\\]\\\\/,;:.§!ù%£$¤=+\\-*\\#~"|ç@';
|
||||||
|
$regex = '#^['.$regex.']+$#';
|
||||||
|
if(preg_match($regex,$newName) != 1)
|
||||||
|
return Discussion::ILLEGAL_NAME;
|
||||||
|
$req->$GLOBALS['bdd']->prepare('UPDATE discussions SET name=? WHERE ID=?');
|
||||||
|
$req->execute(array($newName,$this->ID));
|
||||||
|
return Discussion::NAME_CHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function changeAccessibility($newAccessibility){
|
||||||
|
if(!exists())
|
||||||
|
return NULL;
|
||||||
|
if($newAccessibility !== 'p' and
|
||||||
|
preg_match('#x([0-9]+;)*[0-9]+#',$newAccessibility) != 1 and
|
||||||
|
preg_match('#a[0-9]+#',$newAccessibility) != 1)
|
||||||
|
return Discussion::MALFORMED_ACCESIBILITY;
|
||||||
|
$req = $GLOBALS['bdd']->prepare('UPDATE discussions SET accessibility=? WHERE ID=?');
|
||||||
|
$req->execute(array($newAccessibility,$this->ID));
|
||||||
|
return Discussion::ACCESSIBILITY_CHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDateCreation($newDateCreation){
|
||||||
|
if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $date, $matches) != 1)
|
||||||
|
return Discussion::MALFORMED_DATE;
|
||||||
|
if (!checkdate($matches[2], $matches[3], $matches[1]))
|
||||||
|
return Discussion::MALFORMED_DATE;
|
||||||
|
$req = $GLOBALS['bdd']->prepare('UPDATE discussions SET dateCreation=? WHERE ID=?');
|
||||||
|
$req->execute(array($newDateCreation,$this->ID));
|
||||||
|
return Discussion::DATE_CREATION_CHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Discussions getters
|
||||||
|
private static function discussionGetterOutput($req){
|
||||||
|
$out = array();
|
||||||
|
while($rep = $req->fetch())
|
||||||
|
$out[] = new Discussion($rep['ID']);
|
||||||
|
switch(count($out)){
|
||||||
|
case 0:
|
||||||
|
return NULL;
|
||||||
|
case 1:
|
||||||
|
return $out[0];
|
||||||
|
default:
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromName($name){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM discussions WHERE name=?');
|
||||||
|
$req->execute(array($name));
|
||||||
|
return discussionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromCreator($creator){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM discussions WHERE creatorID=?');
|
||||||
|
$req->execute(array($creator->getID()));
|
||||||
|
return discussionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromDateCreation($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM discussions WHERE dateCreation=?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return discussionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromAccessibility($accessibility){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM discussions WHERE creatorID=?');
|
||||||
|
$req->execute(array($accessibility));
|
||||||
|
return discussionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCreatedLaterThan($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM discussions WHERE dateCreation>?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return discussionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCreatedEarlierThan($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM discussions WHERE dateCreation<?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return discussionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getWhichHeCanAccess($he){
|
||||||
|
//TODO utiliser une regex dans la requete SQL pour selectionner les discussions autorisées
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM discussions');
|
||||||
|
$req->execute(array());
|
||||||
|
$out = array();
|
||||||
|
while ( $rep = $req->fetch()) {
|
||||||
|
$disc = new Discussion($rep['ID']);
|
||||||
|
if ($disc->canAccess($membre))
|
||||||
|
$out[] = $disc;
|
||||||
|
}
|
||||||
|
if($out)
|
||||||
|
return $out;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exceptions texts
|
||||||
|
|
||||||
|
//rename()
|
||||||
|
const NAME_ALREADY_USED = 'Nom déjà utilisé';
|
||||||
|
const ILLEGAL_NAME = 'Le nom de la discussion est incorrect : les caractères autorisés sont :'.
|
||||||
|
'<br/> abcdefghijklmnopqrstuvwxyz<wbr/>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<wbr/>'.
|
||||||
|
'éèàμ_-\'()[\\]\\\\/<wbr/>,;:.§!ù%£$¤=+-*\\#~"|ç@';
|
||||||
|
const TOO_LONG_NAME = 'Le nom est trop long : maximum 256 caractères';
|
||||||
|
const NAME_CHANGED = 'Le nom a bien été changé !';
|
||||||
|
|
||||||
|
//changeAccessibility()
|
||||||
|
const MALFORMED_ACCESSIBILITY = 'L\'accessibilité doit être de la forme : "p" ou "x31;41;59;26;53" ou "a42"';
|
||||||
|
const ACCESSIBILITY_CHANGED = 'L\'accessibilité a bien été changée !';
|
||||||
|
|
||||||
|
//setDateCreation()
|
||||||
|
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';
|
||||||
|
}
|
||||||
54
clazz/Langage.class.php
Normal file
54
clazz/Langage.class.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
class Langage{
|
||||||
|
|
||||||
|
const java = new Langage(0, "Java", "jar java javadoc");
|
||||||
|
const vba = new Langage(1, "VBA", "xlsm vb");
|
||||||
|
|
||||||
|
protected static $languages = array();
|
||||||
|
|
||||||
|
protected $ID;
|
||||||
|
protected $name;
|
||||||
|
protected $avalivableFiles;//String "jar xlsx javadoc" in constructor , stored as a string array
|
||||||
|
|
||||||
|
|
||||||
|
protected function __construct($ID,$name,$avalivableFiles){
|
||||||
|
$this->ID = $ID;
|
||||||
|
$this->name = $name;
|
||||||
|
$this->avalivableFiles = explode(" ",$avalivableFiles);
|
||||||
|
$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 static function getFromID($ID){
|
||||||
|
foreach(self::$languages AS $language){
|
||||||
|
if($language->getID() == $ID)
|
||||||
|
return $language;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1 +1,212 @@
|
|||||||
<?phpclass Membre{ const DEFAULT_BANNER = "pictures/bande.png"; protected $id; protected $password; protected $pseudo; protected $adminLevel; protected $dateCreation; protected $requiredBanner; protected $personnalMessage; protected $connected; public function __construct($id = NULL,$pass = NULL){ $this->id = $id ?? $_SESSION['session_id']; $this->password = $pass ?? $_SESSION['session_mdp']; $connected = FALSE; } public function connect(){ $req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' ); $req->execute (array($this->id)); if ($rep = $req->fetch ()){ $connected = password_verify ( $this->pass, $rep ['mdp'] ); $this->adminLevel = $connected?$result ['administration']:-1; $this->pseudo = $connected?$result['pseudo']:NULL; if($connected)decodeData($rep['data']); return $this->connected = $connected; }else{ $req->closeCursor (); return $this->connected = FALSE; } } public function hasPersonnalMessage(){ return isset($this->personnalMessage); } public function showPersonnalMessage(){ $msg = $this->personnalMessage; $this->personnalMessage = NULL; return $msg; } private function decodeData($data) { $jsonData = json_decode($data); //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; } private function encodeData(){ $jsonArray = array(); //Set requiredBanner only if it is different from DEFAULT_BANNER $jsonArray['requiredBanner'] = $this->requiredBanner !== self::DEFAULT_BANNER ? $this->requiredBanner : NULL; $jsonArray['personnalMessage'] = $this->personnalMessage ?? NULL; return json_encode($jsonArray); } public function getAdminLevel(){ return $this->adminLevel; } public function getBanner() { return $this->requiredBanner; } public function isConnected(){ return $connected; } public static function tryToConnect($pseudo = NULL,$mdp = NULL){ $pseudo = $pseudo ?? $_POST ['pseudo']; $mdp = $mdp ?? $_POST ['mdp']; $req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE pseudo=?' ); $req->execute ( array ( $pseudo ) ); $reponce = $req->fetch (); if ($reponce != NULL) { if (password_verify ( $mdp, $reponce ['mdp'] )) { $req->closeCursor (); return $reponce ['ID']; } else { $req->closeCursor (); return 'errormdp'; } } else { $req->closeCursor (); return 'errorpseudo'; } } public static function registerPerson($pseudo, $mdp) { $req = $GLOBALS ['bdd']->prepare ( "SELECT * FROM users WHERE pseudo=?" ); $req->execute (array($_POST ['pseudo'])); if ($req->fetch ()) return 'usedPseudo'; $req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO users(pseudo,mdp,date_creation) VALUES (?,?,NOW())' ); $req->execute(array($_POST ['pseudo'],password_hash ( $_POST ['mdp'], PASSWORD_DEFAULT))); return 'ok'; }}
|
<?php
|
||||||
|
class Membre {
|
||||||
|
const DEFAULT_BANNER = "pictures/bande.png";
|
||||||
|
|
||||||
|
protected $ID;
|
||||||
|
protected $pseudo;
|
||||||
|
protected $hashedPassword;
|
||||||
|
protected $adminLevel;
|
||||||
|
protected $dateCreation;
|
||||||
|
protected $requiredBanner;
|
||||||
|
protected $personnalMessage;
|
||||||
|
|
||||||
|
protected $connected;
|
||||||
|
protected $valid;
|
||||||
|
|
||||||
|
public function __construct($ID) {
|
||||||
|
$this->ID = $ID;
|
||||||
|
$this->connected = FALSE;
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE ID=?');
|
||||||
|
$req->execute(array($ID));
|
||||||
|
if($rep = $req->fetch()){
|
||||||
|
$this->valid = TRUE;
|
||||||
|
$this->pseudo = $rep['pseudo'];
|
||||||
|
$this->adminLevel = $rep['adminLevel'];
|
||||||
|
$this->dateCreation = $rep['dateCreation'];
|
||||||
|
$this->hashedPassword = $rep['hashedPassword'];
|
||||||
|
$this->decodeData($rep['data']);
|
||||||
|
}else{
|
||||||
|
$this->valid = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function connect($password) {
|
||||||
|
$this->connected = password_verify ( $this->pass, $rep ['mdp'] );
|
||||||
|
|
||||||
|
return $this->connected;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString(){
|
||||||
|
$out = 'Membre\n';
|
||||||
|
$out .= '\tID:' . $this->ID . '\n';
|
||||||
|
$out .= '\tPseudo:' . $this->pseudo . '\n';
|
||||||
|
$out .= '\tAdmin level:' . $this->adminLevel . '\n';
|
||||||
|
$out .= '\tDate of creation:' . $this->dateCreation . '\n';
|
||||||
|
$out .= '\tRequired banner:' . $this->requiredBanner . '\n';
|
||||||
|
$out .= '\tPersonnal message:' . $this->personnalMessage . '\n';
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isConnected(){
|
||||||
|
return $this->connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exists(){
|
||||||
|
return $this->valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function decodeData($data) {
|
||||||
|
$jsonData = json_decode ( $data );
|
||||||
|
// 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>$max;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 mdp=? WHERE ID=?');
|
||||||
|
$req->execute(array(password_hash ( $newPassword, PASSWORD_DEFAULT ),$this->ID));
|
||||||
|
return Membre::PASSWORD_CHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Membre getters
|
||||||
|
private static function memberGetterOutput($req){
|
||||||
|
$out = array();
|
||||||
|
while($rep = $req->fetch())
|
||||||
|
$out[] = new Membre($rep['ID']);
|
||||||
|
switch(count($out)){
|
||||||
|
case 0:
|
||||||
|
return NULL;
|
||||||
|
case 1:
|
||||||
|
return $out[0];
|
||||||
|
default:
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromPseudo($pseudo){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE pseudo=?');
|
||||||
|
$req->execute(array($pseudo));
|
||||||
|
return membreGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromAdminLevel($level){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE adminLevel=?');
|
||||||
|
$req->execute(array($level));
|
||||||
|
return membreGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromDateCreation($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE dateCreation=?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return membreGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCreatedLaterThan($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE dateCreation>?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return membreGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCreatedEarlierThan($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE dateCreation<?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return membreGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAdminGreaterThan($min){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE adminLevel>?');
|
||||||
|
$req->execute(array($min));
|
||||||
|
return membreGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAdminLowerThan($max){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE adminLevel<?');
|
||||||
|
$req->execute(array($max));
|
||||||
|
return membreGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//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::USERNAME_CHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Outputs texts
|
||||||
|
|
||||||
|
//changePassword
|
||||||
|
const PASSWORD_TOO_LONG = 'Le mot de passe est trop long ! (Max : 255 caractères)';
|
||||||
|
const PASSWORD_CHANGED = 'Le mot de passe a bien été changé';
|
||||||
|
|
||||||
|
//registerPerson
|
||||||
|
const USED_USERNAME = 'Le pseudonyme est déjà utilisé';
|
||||||
|
const PERSON_REGISTERED = 'Le membre a bien été inscrit !';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
136
clazz/Message.class.php
Normal file
136
clazz/Message.class.php
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
<?php
|
||||||
|
class Message{
|
||||||
|
|
||||||
|
protected $ID;
|
||||||
|
protected $sender;
|
||||||
|
protected $sendDate;
|
||||||
|
protected $text;
|
||||||
|
protected $discussion;
|
||||||
|
|
||||||
|
protected $valid;
|
||||||
|
|
||||||
|
public function __construct($ID){
|
||||||
|
$this->ID = $ID;
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM messages WHERE ID=?');
|
||||||
|
$req->execute(array($ID));
|
||||||
|
if($rep = $req->fetch()){
|
||||||
|
$this->valid = TRUE;
|
||||||
|
$this->sender = new Membre($rep['senderID']);
|
||||||
|
$this->sendDate = $rep['sendDate'];
|
||||||
|
$this->text = $rep['text'];
|
||||||
|
$this->discussion = new Discussion($rep['discussionID']);
|
||||||
|
}else{
|
||||||
|
$this->valid = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exists(){
|
||||||
|
return $this->valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString(){
|
||||||
|
$out = 'Message\n';
|
||||||
|
$out .= '\tID:' . $this->ID . '\n';
|
||||||
|
$out .= '\tSender:{' . substr(str_replace('\n\t',';',$this->sender->__toString()),0,-1) . '}\n';
|
||||||
|
$out .= '\tSend date:' . $this->sendDate . '\n';
|
||||||
|
$out .= '\tText:' . $this->text . '}\n';
|
||||||
|
$out .= '\tDiscussion:' . substr(str_replace('\n\t',';',$this->discussion->__toString()),0,-1) . '\n';
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Getters
|
||||||
|
public function getID(){
|
||||||
|
return $this->ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSender(){
|
||||||
|
return $this->sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSendDate(){
|
||||||
|
return $this->sendDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getText(){
|
||||||
|
return $this->text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDiscussion(){
|
||||||
|
return $this->discussion;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Useful getters
|
||||||
|
public function canEdit($person){
|
||||||
|
return $person->isAdminLevelGreaterOrEqualThan(6) || $person->getID() == $this->sender->getID();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Setters
|
||||||
|
public function editText($newText){
|
||||||
|
$this->text = htmlSepcialChars($newText);
|
||||||
|
$req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO messages(discussion_id,texte,senderID,sendTime) VALUES (?,?,?,NOW())' );
|
||||||
|
$req->execute (array ($this->discussion->getID(),$this->text,$this->sender->getID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Message getter
|
||||||
|
private static function messagesGetterOutput($req){
|
||||||
|
$out = array();
|
||||||
|
while($rep = $req->fetch())
|
||||||
|
$out[] = new Discussion($rep['ID']);
|
||||||
|
switch(count($out)){
|
||||||
|
case 0:
|
||||||
|
return NULL;
|
||||||
|
case 1:
|
||||||
|
return $out[0];
|
||||||
|
default:
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromSender($param) {
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM messages WHERE senderID=?');
|
||||||
|
$req->execute(array($sender->getID()));
|
||||||
|
return messagesGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getFromSendDate($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM messages WHERE sendDate=?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return messagesGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSendedLaterThan($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM messages WHERE sendDate>?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return messagesGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSendedEarlierThan($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM messages WHERE sendDate<?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return messagesGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromText($text) {
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM messages WHERE text=?');
|
||||||
|
$req->execute(array($text));
|
||||||
|
return messagesGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromDiscussion($discut){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM messages WHERE discussionID=?');
|
||||||
|
$req->execute(array($discut->getID()));
|
||||||
|
return messagesGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Message creator
|
||||||
|
public static function sendMessage($sender,$discussion,$text){
|
||||||
|
$req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO messages(discussion_id,texte,senderID,sendTime) VALUES (?,?,?,NOW())' );
|
||||||
|
$req->execute (array($discussion->getID(),htmlspecialchars ($text),$sender->getID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -131,8 +131,6 @@ class Projet{
|
|||||||
default:
|
default:
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectGetterOutput($req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFromDateCreation($date){
|
public static function getFromDateCreation($date){
|
||||||
@ -154,13 +152,14 @@ class Projet{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function getWhichHeCanAccess($he){
|
public static function getWhichHeCanAccess($he){
|
||||||
|
//TODO Faire la selection directement grâce à une requette SQL
|
||||||
$req = $GLOBALS['bdd']->prepare('SELECT * FROM project');
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM project');
|
||||||
$req->execute(array());
|
$req->execute(array());
|
||||||
$out = array();
|
$out = array();
|
||||||
while ( $rep = $req->fetch()) {
|
while ( $rep = $req->fetch()) {
|
||||||
$disc = new Discussion($rep['ID']);
|
$projet = new Projet($rep['ID']);
|
||||||
if ($disc->canAccess($membre))
|
if ($projet->haveRights($membre))
|
||||||
$out[] = $disc;
|
$out[] = $projet;
|
||||||
}
|
}
|
||||||
switch(count($out)){
|
switch(count($out)){
|
||||||
case 0:
|
case 0:
|
||||||
|
|||||||
312
clazz/Version.class.php
Normal file
312
clazz/Version.class.php
Normal file
@ -0,0 +1,312 @@
|
|||||||
|
<?php
|
||||||
|
class Version{
|
||||||
|
|
||||||
|
protected $ID;
|
||||||
|
protected $name;
|
||||||
|
protected $sendDate;
|
||||||
|
protected $publicFiles;//String "jar xlsx javadoc" in bdd , stored as a string array
|
||||||
|
protected $tags;//String "beta bugged" in bdd , stored as a string array
|
||||||
|
protected $project;
|
||||||
|
protected $language;
|
||||||
|
|
||||||
|
public function __construct($ID){
|
||||||
|
$this->ID = $ID;
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE ID=?');
|
||||||
|
$req->execute(array($ID));
|
||||||
|
if($rep = $req->fetch()){
|
||||||
|
$this->valid = TRUE;
|
||||||
|
$this->name = $rem['name'];
|
||||||
|
$this->sendDate = $rep['sendDate'];
|
||||||
|
$this->publicFiles = explode(" ",$rep['publicFiles']);
|
||||||
|
$this->tags = explode(" ",$rep['tags']);
|
||||||
|
$this->project = new Project($rep['projectID']);
|
||||||
|
$this->language = Langage::getFromID($rep['languageID']);
|
||||||
|
}else{
|
||||||
|
$this->valid = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exists(){
|
||||||
|
return $this->valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString(){
|
||||||
|
$out = 'Version\n';
|
||||||
|
$out .= '\tID:' . $this->ID . '\n';
|
||||||
|
$out .= '\tName:{' . $this->name . '}\n';
|
||||||
|
$out .= '\tSend date:' . $this->sendDate . '\n';
|
||||||
|
$out .= '\tPublic files:"' . implode(' ',$this->publicFiles) . '"}\n';
|
||||||
|
$out .= '\tTags:"' . implode(' ',$this->tags) . '"}\n';
|
||||||
|
$out .= '\tProject:' . substr(str_replace('\n\t',';',$this->project->__toString()),0,-1) . '\n';
|
||||||
|
$out .= '\tLanguage:' . $this->language->getName() . '\n';
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Getters
|
||||||
|
public function getID(){
|
||||||
|
return $this->ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(){
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSendDate(){
|
||||||
|
return $this->sendDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPublicFiles(){
|
||||||
|
//returns a string array
|
||||||
|
return $this->publicFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTags(){
|
||||||
|
//returns a string array
|
||||||
|
return $this->tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProject(){
|
||||||
|
return $this->project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLanguage(){
|
||||||
|
return $this->language;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Useful Getters
|
||||||
|
//TODO make all of the following 'is' functions using haveTag
|
||||||
|
public function haveTag($tag){
|
||||||
|
return in_array($tag,$this->tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isJarPublic(){
|
||||||
|
return in_array("jar",$this->publicFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isJavaPublic(){
|
||||||
|
return in_array("java",$this->publicFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isJavadocPublic(){
|
||||||
|
return in_array("javadoc",$this->publicFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isXlsmPublic(){
|
||||||
|
return in_array("xlsm",$this->publicFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isVbPublic(){
|
||||||
|
return in_array("vb",$this->publicFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isAlpha(){
|
||||||
|
return in_array("alpha",$this->tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isBeta(){
|
||||||
|
return in_array("beta",$this->tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isRelease(){
|
||||||
|
return in_array("release",$this->tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isTest(){
|
||||||
|
return in_array("test",$this->tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isBugged(){
|
||||||
|
return in_array("bugged",$this->tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Setters
|
||||||
|
public function storeTags(){
|
||||||
|
$rep = $GLOBALS['bdd']->prepare('UPDATE versions SET tags=? WHERE ID=?');
|
||||||
|
$rep->execute(array(implode(' ',$this->tags),$this->ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addTag($tag,$store = TRUE){
|
||||||
|
$this->deleteTag($tag,FALSE);
|
||||||
|
$this->tags[] = $tag;
|
||||||
|
if($store)$this->storeTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteTag($tag,$store = TRUE){
|
||||||
|
$this->tags = array_diff($this->tags,array($tag));
|
||||||
|
if($store)$this->storeTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setARelease(){
|
||||||
|
$this->deleteTag('alpha',FALSE);
|
||||||
|
$this->deleteTag('beta',FALSE);
|
||||||
|
$this->addTag('release',FALSE);
|
||||||
|
$this->storeTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAnAlpha(){
|
||||||
|
$this->deleteTag('beta',FALSE);
|
||||||
|
$this->deleteTag('release',FALSE);
|
||||||
|
$this->addTag('alpha',FALSE);
|
||||||
|
$this->storeTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setABeta(){
|
||||||
|
$this->deleteTag('alpha',FALSE);
|
||||||
|
$this->deleteTag('release',FALSE);
|
||||||
|
$this->addTag('beta',FALSE);
|
||||||
|
$this->storeTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setATest(){
|
||||||
|
$this->addTag('test');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNotATest(){
|
||||||
|
$this->delTag('test');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBugged(){
|
||||||
|
$this->addTag('bugged');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNotBugged(){
|
||||||
|
$this->delTag('bugged');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storePublicFiles(){
|
||||||
|
$rep = $GLOBALS['bdd']->prepare('UPDATE versions SET publicFiles=? WHERE ID=?');
|
||||||
|
$rep->execute(array(implode(' ',$this->publicFiles),$this->ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addPublicFile($file,$store = TRUE){
|
||||||
|
$this->deletePublicFile($file,FALSE);
|
||||||
|
$this->publicFiles[] = $file;
|
||||||
|
if($store)$this->storePublicFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deletePublicFile($file,$store = TRUE){
|
||||||
|
$this->publicFiles = array_diff($this->publicFiles,array($file));
|
||||||
|
if($store)$this->storePublicFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setJarPublic(){
|
||||||
|
$this->addPublicFile('jar');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setJarNotPublic(){
|
||||||
|
$this->deletePublicFile('jar');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setJavaPublic(){
|
||||||
|
$this->addPublicFile('java');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setJavaNotPublic(){
|
||||||
|
$this->deletePublicFile('java');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setJavadocPublic(){
|
||||||
|
$this->addPublicFile('javadoc');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setJavadocNotPublic(){
|
||||||
|
$this->deletePublicFile('javadoc');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setXlsmPublic(){
|
||||||
|
$this->addPublicFile('xlsm');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setXlsmNotPublic(){
|
||||||
|
$this->deletePublicFile('xlsm');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setVbPublic(){
|
||||||
|
$this->addPublicFile('vb');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setVbNotPublic(){
|
||||||
|
$this->deletePublicFile('vb');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Version Getter
|
||||||
|
private static function versionGetterOutput($req){
|
||||||
|
$out = array();
|
||||||
|
while($rep = $req->fetch())
|
||||||
|
$out[] = new Version($rep['ID']);
|
||||||
|
switch(count($out)){
|
||||||
|
case 0:
|
||||||
|
return NULL;
|
||||||
|
case 1:
|
||||||
|
return $out[0];
|
||||||
|
default:
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromLanguage($language){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE languageID=?');
|
||||||
|
$req->execute(array($language->getID()));
|
||||||
|
return versionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromProject($project){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE projectID=?');
|
||||||
|
$req->execute(array($project->getID()));
|
||||||
|
return versionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromName($name){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE name=?');
|
||||||
|
$req->execute(array($name));
|
||||||
|
return versionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromTag($tag){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions');
|
||||||
|
$req->execute();
|
||||||
|
$out = array();
|
||||||
|
while ($rep = $req->fetch()) {
|
||||||
|
$projet = new Version($rep['ID']);
|
||||||
|
if ($projet->haveTag($tag))
|
||||||
|
$out[] = $projet;
|
||||||
|
}
|
||||||
|
switch(count($out)){
|
||||||
|
case 0:
|
||||||
|
return NULL;
|
||||||
|
case 1:
|
||||||
|
return $out[0];
|
||||||
|
default:
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectGetterOutput($req);
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE languageID=?');
|
||||||
|
$req->execute(array($language->getID()));
|
||||||
|
return versionGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFromSendDate($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE sendDate=?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return versionsGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSendedLaterThan($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE sendDate>?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return versionsGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSendedEarlierThan($date){
|
||||||
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE sendDate<?');
|
||||||
|
$req->execute(array($date));
|
||||||
|
return versionsGetterOutput($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
16
clazz/Zincluder.php
Normal file
16
clazz/Zincluder.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
try{
|
||||||
|
$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/Langage.class.php';
|
||||||
|
include_once 'clazz/Membre.class.php';
|
||||||
|
include_once 'clazz/Discussion.class.php';
|
||||||
|
include_once 'clazz/Message.class.php';
|
||||||
|
include_once 'clazz/Projet.class.php';
|
||||||
|
//Use class's consts for file names
|
||||||
|
include_once 'clazz/Version.class.php';
|
||||||
8
form.php
8
form.php
@ -1,8 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<form action="admindialog.php" method="post"><input name="command" type="text"/><input type="submit"/></form>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -13,6 +13,20 @@
|
|||||||
000000000000000000000000000000000000000000000000000000000000000000000
|
000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
000000000000000000000000000000000000000000000000000000000000000000000
|
000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
000000000000000000000000000000000000000000000000000000000000000000000
|
000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
--><!--
|
||||||
|
3.14159265358979323846264338327950288419716939
|
||||||
|
______________________________________________
|
||||||
|
__________$$$$$$$$$$$$$$$$$$$$$$$$$$__________
|
||||||
|
__________$$$$$$$$$$$$$$$$$$$$$$$$$$__________
|
||||||
|
_______________$$$_________$$$________________
|
||||||
|
_______________$$$_________$$$________________
|
||||||
|
_______________$$$_________$$$________________
|
||||||
|
_______________$$$_________$$$________________
|
||||||
|
_______________$$$_________$$$________________
|
||||||
|
_______________$$$_________$$$________________
|
||||||
|
______________$$$__________$$$________________
|
||||||
|
_____________$$$___________$$$________________
|
||||||
|
______________________________________________
|
||||||
-->
|
-->
|
||||||
<?php
|
<?php
|
||||||
include_once('includes/inter.php');
|
include_once('includes/inter.php');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user