bcom/admindialog.php
Mysaa 38ec48c9fc Maintenant, tout dans le executor.php. Fin de tempPreMega.
Ajout d'un super simulateur de tours de Monoï dans la page 404.
2021-06-06 12:48:11 +02:00

284 lines
7.0 KiB
PHP
Raw Blame History

<?php
session_start();
include_once 'clazz/Zincluder.php';
$me = new Membre($_SESSION ['session_id']);
$me->connect($_SESSION ['session_mdp']);
if(!$me->isConnected()){
echo 'Your must being connected to have access to this page';
exit;
}elseif($me->isAdminLevelLowerThan(15)){
echo 'Your admin level is too low (15 or more required)';
exit;
}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;
}
function readAlphabetic($command){
global $pos;
$out = "";
while (isAlphaNumeric($command[$pos])) {
$out .= $command[$pos];
$pos+=1;
}
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;
}
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;
}
$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[$tPos];
$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);
//TODO Add @Selector[]:var type ':' support
}
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;
}
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<78>me argument doit etre un selecteur');
$objectsToSet=NULL;
switch ($nommes[1][1][0]){
case 'Membre':
$objectsToSet = Membre::getFromAttributes($nommes[1][1][1]);
echo '<br/><pre>';
print_r($objectsToSet);
echo '</pre>';
break;
case 'Projet':
//TODO add others class support
break;
case 'Version':
break;
case 'Discussion':
break;
case 'Message':
break;
default:
exception('Unknown selector class :'.$nommes[1][1][0]);
}
if($nommes[2][0] !== 'a')
exception('Le troisi<73>me param<61>tre doit etre une chaine de commande (chaine de caract<63>res alphanum<75>riques commensant par une lettre sans guillemets');
if($nommes[3][0] !== '"' and $nommes[3][0] !== '0' and $nommes[3][0] !== ':')
exception('Le quatri<72>me param<61>tre doit etre une variable (chaine de caract<63>res entre guillemets, nombre ou variable de selecteur');
$attributeToSetName = $nommes[2][1];
$varToSet = $nommes[3];
//TODO add @Selector[]:var support
foreach($objectsToSet as $objectToSet){
$objectToSet->setAttribute($attributeToSetName,$varToSet[1],$varToSet[0]);
}
echo 'SET the value '.$varToSet[1].' at attribute '.$attributeToSetName.' of '.count($objectsToSet).' objects';
break;
case 'GET':
/*
GET selector
*/
if(count($nommes) !== 2)
exception('La fonction n\'a pas recu le bon nombre d\'arguments (2)');
if($nommes[1][0] !== '@')
exception('Le deuxi<78>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':
//TODO add others class support
break;
case 'Version':
break;
case 'Discussion':
break;
case 'Message':
break;
default:
exception('Unknown selector class :'.$nommes[1][1][0]);
}
echo '<br/><pre>';
print_r($objectsToSet);
echo '</pre>';
break;
case 'DELETE':
break;
default:
exception('Unknown function '.$fonction);
}
}