should return on $_SESSION ['current_error'] (0) or via echo (1) */ function exiting($message,$location='index.php'){ if($message instanceof SQLProcessingException){ echo $message->getMessage(); $_SESSION ['current_error'] = $message->getHtmlMessage(); }else if($message instanceof Exception){ echo $message->getMessage(); $_SESSION ['current_error'] = htmlSpecialChars($message->getMessage()); }else{ $_SESSION ['current_error'] = $message; } header ( 'Location:' . $location ); exit; } if (! isset ( $_GET ['action'] )) exiting(NULL,'40A.php'); switch ($_GET ['action']) { case 'disconnect' : unset($_SESSION['session_id']); unset($_SESSION['session_mdp']); header('Location:index.php');//TODO lastpageredirection $_SESSION['current_error'] = 'La déconnexion se sera correctement passée!'; exit; case 'register' : //Action : register $pseudo = $_POST ['pseudo'] ?? NULL; $mdp = $_POST ['mdp'] ?? NULL; $mdp2 = $_POST ['mdp2'] ?? NULL; try{ assert($pseudo,new MissingDataException('pseudo','POST')); assert($mdp,new MissingDataException('mdp','POST')); assert($mdp2,new MissingDataException('mdp2','POST')); assert($mdp===$mdp2,new DataException('mdp and mdp2 should be equal')); Membre::registerPerson ($pseudo,$mdp); }catch(Exception $e){ exiting($e); } exiting(Utility::SUCESSFULLY_REGISTERED,'login.php'); case 'login' : //Action : login $pseudo = $_POST ['pseudo'] ?? NULL; $mdp = $_POST ['mdp'] ?? NULL; try{ assert($pseudo,new MissingDataException('pseudo','POST')); assert($mdp,new MissingDataException('mdp','POST')); $_SESSION['session_id'] = Membre::checkLogin ($pseudo,$mdp); $_SESSION['session_mdp'] = $mdp; }catch(Exception $e){ exiting($e); } exiting(Utility::SUCESSFULLY_LOGGED_IN,'index.php');//TODO Do a "previousContentPageRedirection" case 'changePassword' : //Action : change password $sid = $_SESSION ['session_id'] ?? NULL; $rmdp = $_POST ['rmdp'] ?? NULL; $mdp = $_POST ['nmdp'] ?? NULL; $mdp2 = $_POST ['nmdp2'] ?? NULL; var_dump($_POST); try{ assert($rmdp,new MissingDataException('rmdp','POST')); assert($mdp,new MissingDataException('mdp','POST')); assert($mdp2,new MissingDataException('mdp2','POST')); assert($mdp===$mdp2,new DataException('mdp and mdp2 should be equal')); Membre::changePassword ($sid,$rmdp,$mdp); }catch(Exception $e){ exiting($e); } exiting(Utility::SUCESSFULLY_CHANGED_PASSWORD,'login.php'); case 'createDiscussion' : //Action : create discussion $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $name = $_POST ['name'] ?? NULL; try{ assert($sid,new LoginNeededException()); assert($rmdp,new MissingDataException('rmdp','POST')); assert($mdp,new MissingDataException('mdp','POST')); assert($mdp2,new MissingDataException('mdp2','POST')); $did = Discussion::createDiscussion ($sid,$mdp,$name); }catch(Exception $e){ exiting($e); } exiting(Utility::SUCESSFULLY_CREATED_DISCUSSION,'discut.php?d='.$did); case 'postMessage' : //Action : post message $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $did = $_GET ['d'] ?? NULL; $text = $_POST ['msg'] ?? NULL; var_dump($text); try{ assert($sid,new LoginNeddedException()); assert($did,new MissingDataException('d','GET')); assert($text,new MissingDataException('text','POST')); Message::postMessage ($sid,$mdp,$did,$text); }catch(Exception $e){ exiting($e); } exiting(NULL,'discut.php?d='.$did); case 'deleteMessage' : //Action : delete message $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $mid = $_GET ['m'] ?? NULL; try{ assert($sid,new LoginNeddedException()); assert($mid,new MissingDataException('m','GET')); $did = Message::deleteMessage ($sid,$mdp,$mid); }catch(Exception $e){ exiting($e); } exiting(NULL,'discut.php?d='.$did); case 'editVersion' : //Action : edit version // Data : name langage tags insertIndex -> facultatifs $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $v = $_GET['v'] ?? NULL; $name = $_POST['name'] ?? NULL; $langage = $_POST['langage'] ?? NULL; $tags = $_POST['tags'] ?? NULL; $insertIndex = $_POST['insertIndex'] ?? NULL; try{ assert($sid,new LoginNeededException()); assert($v,new MissingDataException('v','GET')); Version::editVersion ($sid,$mdp,$v,$name,$langage,$tags,$insertIndex); }catch(Exception $e){ exiting($e); } exiting(Utility::SUCESSFULLY_CHANGED_PASSWORD,'login.php'); case 'getDiscutsMessages' : //Action : get discut's messages //TODO precise output type (via $_GET) $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $did = $_GET ['did'] ?? NULL; try{ assert($sid,new LoginNeededException()); assert($did,new MissingDataException('did','GET')); $jmsgs = Discussion::getMessages ($sid,$mdp,$did); echo json_encode ( $jmsgs ); flush (); exit; }catch(Exception $e){ exiting($e); } exit; case 'getPeopleList' : //Action : get project's secondary owners //TODO precise output type (via $_GET) $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $pid = $_GET ['p'] ?? NULL; try{ assert($sid,new LoginNeededException()); assert($pid,new MissingDataException('pid','GET')); $secondaryOwners = Projet::getSecondaryOwners ($sid,$mdp,$pid); $jsowns = array(); foreach($secondaryOwners as $sOwner){ $jsown = array(); $jsown['ID'] = $sOwner['ID']; $jsown['pseudo'] = $sOwner['pseudo']; array_push($jsowns,$jsown); } echo json_encode ( $jsowns ); flush (); exit; }catch(Exception $e){ exiting($e); } exit; case 'removePeople' : //Action : remove secodary owner $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $pid = $_GET ['pid'] ?? NULL; $peopleIDs = $_POST['peopleIDs'] ?? NULL; try{ assert($sid,new LoginNeddedException()); assert($pid,new MissingDataException('pid','GET')); $did = Projet::removeSecondaryOwner ($sid,$mdp,$pid,explode(',',$peopleIDs)); }catch(Exception $e){ exiting($e); } exiting(NULL,'projet.php?p='.$pid); exit; case 'addPeople' : //Action : add secondary owner $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $pid = $_GET ['pid'] ?? NULL; $personName = $_POST['personName'] ?? NULL; try{ assert($sid,new LoginNeddedException()); assert($pid,new MissingDataException('pid','GET')); assert($pid,new MissingDataException('personName','POST')); $did = Projet::addSecondaryOwner ($sid,$mdp,$pid,explode(',',$personName)); }catch(Exception $e){ exiting($e); } exiting(NULL,'projet.php?p='.$pid); case 'nameOwner' : //Action : name a new Owner $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $pid = $_GET ['pid'] ?? NULL; $personId = $_POST['personId'] ?? NULL; try{ assert($sid,new LoginNeddedException()); assert($pid,new MissingDataException('pid','GET')); assert($personId,new MissingDataException('personId','POST')); Projet::nameOwner ($sid,$mdp,$pid,explode(',',$personId)); }catch(Exception $e){ exiting($e); } exiting(NULL,'projet.php?p='.$pid); case 'delProject' : //Action : delete this project $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $pid = $_GET ['pid'] ?? NULL; try{ assert($sid,new LoginNeddedException()); assert($pid,new MissingDataException('pid','GET')); Projet::removeProject ($sid,$mdp,$pid); }catch(Exception $e){ exiting($e); } exiting(NULL,'projets.php'); case 'getVersionList' : //Action : get project's versions //TODO precise output type (via $_GET) $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $pid = $_GET ['p'] ?? NULL; try{ assert($sid,new LoginNeededException()); assert($pid,new MissingDataException('pid','GET')); $versions = Version::getFromProject ($sid,$mdp,$pid); $jvs = array(); foreach($versions as $version){ $jv = array(); $jv['ID'] = $version['ID']; $jv['name'] = $version['pseudo']; $jv['versionAbs'] = $version['versionAbs']; array_push($jvs,$jv); } echo json_encode ( $jvs ); flush (); exit; }catch(Exception $e){ exiting($e); } exit; case 'createVersion' : //Action : add new version $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $pid = $_GET ['pid'] ?? NULL; $name = $_POST ['name'] ?? NULL; $tags = $_POST ['tags'] ?? NULL; $language = $_POST ['language'] ?? NULL; $insertIndex = $_POST ['insertIndex'] ?? NULL; try{ assert($sid,new LoginNeddedException()); assert($pid,new MissingDataException('pid','GET')); assert($text,new MissingDataException('name','POST')); assert($text,new MissingDataException('tags','POST')); assert($text,new MissingDataException('language','POST')); $vid = Version::createVerion ($sid,$mdp,$pid,$name,$tags,$language,$insertIndex); }catch(Exception $e){ exiting($e); } exiting(NULL,'version.php?v='.$vid); case 'editVersion' : //Action : add secodary owner $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $vid = $_GET ['vid'] ?? NULL; $name = $_POST ['name'] ?? NULL; $tags = $_POST ['tags'] ?? NULL; $language = $_POST ['language'] ?? NULL; $insertIndex = $_POST ['insertIndex'] ?? NULL; try{ assert($sid,new LoginNeddedException()); assert($pid,new MissingDataException('vid','GET')); assert($text,new MissingDataException('name','POST')); assert($text,new MissingDataException('tags','POST')); assert($text,new MissingDataException('language','POST')); $vid = Version::editVerion ($sid,$mdp,$vid,$name,$tags,$language,$insertIndex); }catch(Exception $e){ exiting($e); } //TODO make auto version_abs sorting according to $_POST ['insertIndex'] //TODO verify tags and langage exiting(NULL,'version.php?v='.$vid); case 'delVersion' : //Action : delete this version $sid = $_SESSION ['session_id'] ?? NULL; $mdp = $_SESSION ['session_mdp'] ?? NULL; $vid = $_GET ['vid'] ?? NULL; try{ assert($sid,new LoginNeddedException()); assert($pid,new MissingDataException('vid','GET')); $pid = Version::removeVersion ($sid,$mdp,$vid); }catch(Exception $e){ exiting($e); } exiting(NULL,'projet.php?p=' . $pid); }