Encore plus de nouvelles classes

Tests sur les nombres univers
This commit is contained in:
Mysaa 2021-06-06 12:24:05 +02:00
parent c9589d2cf6
commit fba5123944
12 changed files with 692 additions and 332 deletions

175
admin.php
View File

@ -1 +1,176 @@
<?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&eacute;l&eacute;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&eacute;l&eacute;ctionner</button>
</form>
</div>
<button id="send">Envoyer la requ&ecirc;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">&lt;</option>
<option value="gt">&gt;</option>
<option value="ge">&ge;</option>
<option value="le">&le;</option>
<option value="ne">&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&eacute;</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">&lt;</option><option value="gt">&gt;</option><option value="ge">&ge;</option><option value="le">&le;</option><option value="ne">&ne;</option></select>')
else if(array)
span.append('<select><option value="in">&isin;</option><option value="nn">&notin;</option></select>')
else
span.append('<select><option value="ee">=</option><option value="ne">&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>

View File

@ -1,52 +1,241 @@
<?php
include_once 'clazz/Membre.class.php';
include_once 'includes/bdd.php';
include_once 'clazz/Zincluder.php';
/*
$me = new Membre();
$me->connect();
if($me->getAdminLevel()<15){
if($me->isAdminLevelLowerThan(15)){
echo 'Your admin level is too low (15 or more required)';
exit;
}elseif(!isset($_GET['action'])){
echo 'Please set an action in the URL (GET method ,name:"action")';
}elseif(!isset($_POST['command'])){
echo 'Please set an command in the URL (POST method ,name:"command")';
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;
}
switch ($_GET['action']){
case 'set_discutionVisibility' :
if(!isset($_POST['discutionVisibility'])){
echo 'You must give a discution visibility (POST method,name:"discutionVisibility")';
exit;
function readAlphabetic($command){
global $pos;
$out = "";
while (isAlphaNumeric($command[$pos])) {
$out .= $command[$pos];
$pos+=1;
}
if(!isset($_POST['discutionID'])){
echo 'You must give a discution ID (POST method,name:"discutionID")';
exit;
return $out;
}
function readNumeric($command){
//TODO Add non-integer support (virgule , puissance , autres bases ...)
global $pos;
$out = "";
while (isNumeric($command[$pos])) {
$out .= $command[$pos];
$pos+=1;
}
$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 ){
echo 'Your discution visibility is not well-formed : it should have been formed like ("p" or "x31;41;59;26;53" or "a42")';
exit;
return intval($out);
}
function readString($command,$startChar='\"'){
global $pos;
$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;
}
$req = $GLOBALS['bdd']->prepare('UPDATE discussions SET autorized=? WHERE ID=?');
$req->execute(array($discutionVisibility,$discution));
exit;
$pos +=1;
return $out;
}
$operators = array('=','!=','>','<','>=','=>','<=','=<','&has;','&nhas;');
$operatorsChars = array('=','!','<','>','&');
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+4);
$tPos = $pos;
while ($tPos<$maxPos) {
//echo $reading;
$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>';
default :
echo 'Unknown action : '+$_GET['action'];
function exception($reason){
echo 'An exception occurred : '.$reason;
exit;
}
function getObjects($selector){
}
}
if($nommes[0][0] == 'a'){
//Command
$fonction = strtoupper($nommes[0][1]);
switch ($fonction){
case 'SET':
/*
SET selector attributeName value
*/
if(count($nommes) !== 4)
exception('La fonction n\'a pas recu le bon nombre d\'arguments (4)');
if($nommes[1][0] !== '@')
exception('Le deuxième argument doit etre un selecteur');
$objectsToSet=NULL;
switch ($nommes[1][1][0]){
case 'Membre':
$objectsToSet = Membre::getFromAttributes($nommes[1][1][1]);
break;
case 'Projet':
break;
case 'Version':
break;
case 'Discussion':
break;
case 'Message':
break;
default:
exception('Unknown selector class : '.$nommes[1][1][0]);
}
if($objectsToSet === NULL)
exception('Not any object match the specified selector');
echo '<pre>';
print_r($objectsToSet);
echo '</pre>';
break;
case 'DELETE':
break;
default:
exception('Unknown function '.$fonction);
}
}

View File

@ -1,8 +1,9 @@
<?php
class Langage{
const java = new Langage(0, "Java", "jar java javadoc");
const vba = new Langage(1, "VBA", "xlsm vb");
//FIXME const
static $java = new Langage(0, "Java", "jar java javadoc");
static $vba = new Langage(1, "VBA", "xlsm vb");
protected static $languages = array();

View File

@ -126,62 +126,118 @@ class Membre {
return Membre::PASSWORD_CHANGED;
}
//Membre getters
private static function memberGetterOutput($req){
/**
*
* @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':
$value = intval($restriction[2]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'pseudo':
$value = '"'.strval($restriction[2]).'"';//FIXME escaped chars (',",\n,\t ...)
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'hashedPseudo':
$value = '"'.strval($restriction[2]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'adminLevel':
$value = intval($restriction[2]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'dateCreation':
//FIXME y ä pâs là vàlüè
$value=""
$operator = 'convert(datetime, "'.Utility::getDateSqlOperator($restriction[1]).'")';
break;
case 'requiredBanner':
$json=TRUE;
$value = "'".strval($restriction[2])."'";
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'personnalMessage':
$json=TRUE;
$value = "'".strval($restriction[2])."'";
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
default:
echo 'Unknown 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 = 'WHERE '.implode(' AND ',$whereCommands);
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres '.$wherePart);
$req->execute($restrictionValues);
if($req->errorInfo()[0] == 0)
echo 'A SQL exception occured ...';
$out = array();
while($rep = $req->fetch())
$out[] = new Membre($rep['ID']);
switch(count($out)){
case 0:
return NULL;
case 1:
return $out[0];
default:
return $out;
}
//Choose return value
switch(count($out)){
case 0:
return NULL;
case 1:
return $out[0];
default:
return $out;
}
}
public static function getFromPseudo($pseudo){
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE pseudo=?');
$req->execute(array($pseudo));
return membreGetterOutput($req);
return getFromAttributes(array(['pseudo','=',$pseudo]));
}
public static function getFromAdminLevel($level){
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE adminLevel=?');
$req->execute(array($level));
return membreGetterOutput($req);
return getFromAttributes(array(['adminLevel','=',$level]));
}
public static function getFromDateCreation($date){
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE dateCreation=?');
$req->execute(array($date));
return membreGetterOutput($req);
return getFromAttributes(array(['dateCreation','=',$date]));
}
public static function getCreatedLaterThan($date){
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE dateCreation>?');
$req->execute(array($date));
return membreGetterOutput($req);
return getFromAttributes(array(['dateCreation','>',$date]));
}
public static function getCreatedEarlierThan($date){
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE dateCreation<?');
$req->execute(array($date));
return membreGetterOutput($req);
return getFromAttributes(array(['dateCreation','<',$date]));
}
public static function getAdminGreaterThan($min){
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE adminLevel>?');
$req->execute(array($min));
return membreGetterOutput($req);
return getFromAttributes(array(['adminLevel','>',$min]));
}
public static function getAdminLowerThan($max){
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres WHERE adminLevel<?');
$req->execute(array($max));
return membreGetterOutput($req);
return getFromAttributes(array(['adminLevel','<',$max]));
}
@ -191,7 +247,7 @@ class Membre {
return Membre::USED_USERNAME;
$req = $GLOBALS ['bdd']->prepare ('INSERT INTO membres(pseudo,mdp,date_creation) VALUES (?,?,NOW())');
$req->execute (array($pseudo,password_hash( $mdp, PASSWORD_DEFAULT)));
return Membre::USERNAME_CHANGED;
return Membre::PERSON_REGISTERED;
}

View File

@ -1,5 +1,6 @@
<?php
class Projet{
protected $ID;
protected $name;
protected $dateCreation;

117
clazz/Utility.class.php Normal file
View File

@ -0,0 +1,117 @@
<?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);
}
}
}

View File

@ -7,10 +7,11 @@ try{
}
//TODO in the classes , do more test of exists in setters
include_once 'clazz/Utility.class.php';
include_once 'clazz/Langage.class.php';
include_once 'clazz/Membre.class.php';
include_once 'clazz/Discussion.class.php';
include_once 'clazz/Message.class.php';
include_once 'clazz/Projet.class.php';
//Use class's consts for file names
//TODO Use class's consts for file names
include_once 'clazz/Version.class.php';

62
css/adminStyle.css Normal file
View File

@ -0,0 +1,62 @@
#adminDialogAnswer{
display:block;
background-color:black;
color:white;
height: 150px;
overflow:scroll;
}
#setFormObject , #setChampsForm{
display:inline-block;
text-align: center;
height: inherit;
}
#setFormObject{
width:25%;
}
#setChampsForm{
width:75%;
}
#setDiv{
border:5px double grey;
}
#send{
width:100%;
}
.fullscreen{
position:fixed;
top:0;
right:0;
width:100%;
height:100%;
vertical-align:middle;
background-color: #222;
opacity:0.97;
}
.screen-vertical-centered{
text-align:center;
margin-top: 50vh;
transform: translateY(-50%);
}
.screen-horizontal-centered{
display:inline;
opacity:1;
font-size:42px;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
/* This is the dangerous one in WebKit, as it breaks things wherever */
word-break: break-all;
/* Instead use this non-standard one: */
word-break: break-word;
/* Adds a hyphen where the word breaks, if supported (No Blink) */
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}

9
form.php Normal file
View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="admindialog.php" method="post"><input name="command" type="text"/><input type="submit"/></form>
<div id="div1"></div>
</body>
</html>

View File

@ -155,7 +155,6 @@ function getVersions($pid = NULL) {
$req->execute ( array (
$pid
) );
// ADDPOINT langage
$versions = array (
array (),
array ()
@ -217,6 +216,7 @@ function getMessages($discut = NULL) {
$req->closeCursor ();
return array_slice ( $rep, 0, - 1, TRUE );
}
function getDiscuts() {
$req = $GLOBALS ['bdd']->query ( "SELECT * FROM discussions ORDER BY date_creation DESC" );
$rep = array ();

262
inter.php
View File

@ -1,262 +0,0 @@
<?php
include_once 'includes/bdd.php';
function isConnected($sid = NULL, $mdp = NULL) {
if (! isset ( $sid ) or ! isset ( $mdp )) {
$sid = $_SESSION ['session_id'];
$mdp = $_SESSION ['session_mdp'];
}
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' );
$req->execute ( array (
$sid
) );
if ($rep = $req->fetch ()) {
$connected = password_verify ( $mdp, $rep ['mdp'] );
} else {
$connected = FALSE;
}
$req->closeCursor ();
return $connected;
}
function getAdminLevel($sid = NULL, $mdp = NULL) {
if (! isset ( $sid ) or ! isset ( $mdp )) {
$sid = $_SESSION ['session_id'];
$mdp = $_SESSION ['session_mdp'];
}
if (! isConnected ( $sid, $mdp ))
return - 1;
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' );
$req->execute ( array (
$sid
) );
if ($result = $req->fetch ()) {
$adminLevel = $result ['administration'];
} else {
$adminLevel = - 1;
}
$req->closeCursor ();
return $adminLevel;
}
function getPseudo($sid = NULL, $mdp = NULL) {
if (! isset ( $sid ) or ! isset ( $mdp )) {
$sid = $_SESSION ['session_id'];
$mdp = $_SESSION ['session_mdp'];
}
if (! isConnected ( $sid, $mdp ))
return "neant";
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' );
$req->execute ( array (
$sid
) );
$pseudo = $req->fetch () ['pseudo'];
$req->closeCursor ();
return $pseudo;
}
function getPseudoOf($sid) {
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' );
$req->execute ( array (
$sid
) );
$pseudo = $req->fetch () ['pseudo'];
$req->closeCursor ();
return $pseudo;
}
function tryToConnect($pseudo = NULL, $mdp = NULL) {
if (! isset ( $pseudo ) or ! isset ( $mdp )) {
$pseudo = $_POST ['pseudo'];
$mdp = $_POST ['mdp'];
}
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE pseudo=?' );
$req->execute ( array (
$pseudo
) );
$reponce = $req->fetch ();
if ($reponce != NULL) {
if (password_verify ( $mdp, $reponce ['mdp'] )) {
$req->closeCursor ();
return $reponce ['ID'];
} else {
$req->closeCursor ();
return 'errormdp';
}
} else {
$req->closeCursor ();
return 'errorpseudo';
}
}
function getProjectVersionData($project = NULL, $version = NULL) {
if (! isset ( $project ) or ! isset ( $version )) {
$project = $_GET ['id'];
$version = $_GET ['v'];
}
$req = $GLOBALS ['bdd']->prepare ( 'SELECT p.ID AS pID ,' . ' ' . 'v.versionAbs AS versionAbs , ' . ' ' . 'p.name AS name ,' . ' ' . 'v.version AS version ,' . ' ' . 'v.language AS language ,' . ' ' . 'p.permissions AS permissions ,' . ' ' . 'p.ownersID AS owners' . ' ' . 'FROM projets AS p' . ' ' . 'INNER JOIN versions AS v' . ' ' . 'ON v.project_id = p.ID' . ' ' . 'WHERE v.project_id = ? AND v.versionAbs = ?' );
$req->execute ( array (
$project,
$version
) );
if (($data = $req->fetch ())) {
$req->closeCursor ();
return $data;
} else {
$req->closeCursor ();
return NULL;
}
}
function getProjectData($project = NULL) {
if (! isset ( $project )) {
$project = $_GET ['id'];
}
$req = $GLOBALS ['bdd']->prepare ( 'SELECT p.ID AS ID ,' . ' ' . 'p.name AS name ,' . ' ' . 'p.permissions AS permissions ,' . ' ' . 'p.ownersID AS owners' . ' ' . 'FROM projets AS p' . ' ' . 'WHERE p.ID = ?' );
$req->execute ( array (
$project
) );
if (($data = $req->fetch ())) {
$req->closeCursor ();
return $data;
} else {
$req->closeCursor ();
return NULL;
}
}
function getPermissions($data) {
$permissions = array (
FALSE,
FALSE,
FALSE,
FALSE
);
$permissions [0] = preg_match ( '#^1#', $data ['permissions'] );
$permissions [1] = preg_match ( '#^(0|1)1#', $data ['permissions'] );
$permissions [2] = preg_match ( '#^(0|1){2}1#', $data ['permissions'] );
$permissions [3] = preg_match ( '#^(0|1){3}1#', $data ['permissions'] );
return $permissions;
}
function getProjectsWithFirstPermission() {
$requete = 'SELECT p.ID AS projectID , v.versionAbs AS versionAbs , p.name AS projectName , v.version AS versionName ' . 'FROM projets AS p ' . 'INNER JOIN versions AS v ' . 'ON v.project_id = p.ID ' . 'WHERE p.permissions LIKE "1%" ';
$req = $GLOBALS ['bdd']->query ( $requete );
$projects = array ();
while ( $rep = $req->fetch () ) {
if (! isset ( $projects [$rep ['projectID']] )) {
$projects [$rep ['projectID']] = $rep;
} else if ($projects [$rep ['projectID']] ['versionAbs'] < $rep ['versionAbs']) {
$projects [$rep ['projectID']] = $rep;
}
}
$req->closeCursor ();
return $projects;
}
function getVersions($pid = NULL) {
if (! isset ( $pid )) {
$pid = $_GET ['id'];
}
$requete = 'SELECT * FROM versions WHERE project_id = ?';
$req = $GLOBALS ['bdd']->prepare ( $requete );
$req->execute ( array (
$pid
) );
// ADDPOINT langage
$versions = array (
array (),
array ()
);
while ( $rep = $req->fetch () ) {
$versions [$rep ['language']] [] = array (
'versionAbs' => $rep ['versionAbs'],
'versionName' => $rep ['version']
);
}
$req->closeCursor ();
return $versions;
}
function getOwnersisProjects($sid = NULL) {
if (! isset ( $sid )) {
$sid = $_SESSION ['session_id'];
}
$requete = 'SELECT p.ownersID AS ownersID , p.ID AS projectID , v.versionAbs AS versionAbs , p.name AS projectName , v.version AS versionName ' . 'FROM projets AS p ' . 'INNER JOIN versions AS v ' . 'ON v.project_id = p.ID ' . 'WHERE p.ownersID REGEXP \'[^0-9]?' . $sid . '[^0-9]?\' ';
$req = $GLOBALS ['bdd']->query ( $requete );
$projects = array ();
while ( $rep = $req->fetch () ) {
if (! isset ( $projects [$rep ['projectID']] )) {
$projects [$rep ['projectID']] = $rep;
} else if ($projects [$rep ['projectID']] ['versionAbs'] < $rep ['versionAbs']) {
$projects [$rep ['projectID']] = $rep;
}
}
return $projects;
}
function registerPerson($pseudo, $mdp) {
$req = $GLOBALS ['bdd']->prepare ( "SELECT * FROM users WHERE pseudo=?" );
$req->execute ( array (
$_POST ['pseudo']
) );
if ($req->fetch ()) {
return 'usedPseudo';
} else {
$req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO users(pseudo,mdp,date_creation) VALUES (?,?,NOW())' );
$req->execute ( array (
$_POST ['pseudo'],
password_hash ( $_POST ['mdp'], PASSWORD_DEFAULT )
) );
return 'ok';
}
}
function getMessages($discut = NULL) {
if (! isset ( $discut )) {
$discut = $_GET ['d'];
}
$req = $GLOBALS ['bdd']->prepare ( "SELECT * FROM messages WHERE discussion_id=? ORDER BY sendTime DESC" );
$req->execute ( array (
$discut
) );
$rep = array ();
while ( $rep [] = $req->fetch () )
;
if (count ( $rep ) <= 0)
$rep = NULL;
$req->closeCursor ();
return array_slice ( $rep, 0, - 1, TRUE );
}
function getDiscuts() {
$req = $GLOBALS ['bdd']->query ( "SELECT * FROM discussions ORDER BY date_creation DESC" );
$rep = array ();
while ( $rep [] = $req->fetch () )
;
if (count ( $rep ) <= 1)
$rep = NULL;
$req->closeCursor ();
return array_slice ( $rep, 0, - 1, TRUE );
}
function getDiscutInfos($did = NULL) {
if(!isset($did)){
$did = $_GET['d'];
}
$req = $GLOBALS ['bdd']->query ( "SELECT * FROM discussions WHERE ID=?" );
return $req->fetch();
}
function sendMessage($discut = NULL, $text = NULL, $sender = NULL) {
if (! isset ( $discut ) || ! isset ( $text ) || ! isset ( $sender )) {
$discut = $_GET ['d'];
$text = $_POST ['msg'];
$sender = $_SESSION ['session_id'];
}
$req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO messages(discussion_id,texte,senderID,sendTime) VALUES (?,?,?,NOW())' );
$req->execute ( array (
$discut,
htmlspecialchars ( $text ),
$sender
) );
return 'ok';
}
function createDiscut($name = NULL, $owner = NULL) {
if (! isset ( $name ) || ! isset ( $owner )) {
$name = $_POST ['name'];
$owner = $_SESSION ['session_id'];
}
$req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO discussions(name,creator_id,date_creation) VALUES (?,?,NOW())' );
$req->execute ( array (
$name,
$owner
) );
return 'ok';
}

11
nombre univers.cpp Normal file
View File

@ -0,0 +1,11 @@
#include <iostream>
using namespace std;
int main(){
long long int a=1;
cout << "0.";
while(1){
cout << a;
a++;
}
return 0;
}