2015-12-06 19:08:28 +00:00
|
|
|
<?php require_once __ROOT__.'/manager/security.php';
|
|
|
|
|
2015-10-22 16:55:26 +00:00
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* *
|
|
|
|
* MANAGER DES UTILISATEURS *
|
|
|
|
* *
|
|
|
|
************************************************************
|
|
|
|
* *
|
|
|
|
* [0] Constantes *
|
|
|
|
* [1] ROUTAGE de niveau 1 *
|
|
|
|
* [2] Création d'un groupe *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
***********************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-06 19:08:28 +00:00
|
|
|
class groupsManager{
|
2015-10-22 16:55:26 +00:00
|
|
|
|
|
|
|
/* [1] ROUTAGE DE NIVEAU 1
|
|
|
|
============================================================*/
|
2015-12-06 19:08:28 +00:00
|
|
|
public static function switch_level_1($request, $answer){
|
2015-10-22 16:55:26 +00:00
|
|
|
|
|
|
|
switch( $request->level_1 ){
|
|
|
|
|
|
|
|
/************************/
|
|
|
|
/* création d'un groupe */
|
|
|
|
/************************/
|
2015-11-30 18:46:10 +00:00
|
|
|
case 'create': if( false && permission('admin') ){
|
2015-11-08 21:30:23 +00:00
|
|
|
|
2015-12-30 16:21:10 +00:00
|
|
|
$areSetParam = isset($request->nom) ; // l'argument existe
|
|
|
|
$nomCheck = $areSetParam && checkParam($request->nom, 'groupe.nom'); // nom bon format
|
2015-11-08 21:30:23 +00:00
|
|
|
|
|
|
|
if( $nomCheck ){ // si tout les paramètres sont bons
|
|
|
|
$answer->request = DataBase::getInstance()->creerGroupe($request->nom);
|
|
|
|
}else
|
|
|
|
$answer->request = 'param_error';
|
|
|
|
|
2015-10-22 16:55:26 +00:00
|
|
|
}else
|
2015-11-08 21:30:23 +00:00
|
|
|
$answer->request = 'permission_error';
|
2015-10-22 19:19:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*****************************************/
|
|
|
|
/* retourne les utilisateurs d'un groupe */
|
|
|
|
/*****************************************/
|
2015-11-19 22:32:54 +00:00
|
|
|
case 'userlist': if( permission('student') ){
|
2015-11-08 21:30:23 +00:00
|
|
|
|
2016-01-02 13:21:31 +00:00
|
|
|
$areSetParam = isset($request->etudiant) && isset($request->semestre); // les arguments existent
|
2015-12-30 16:21:10 +00:00
|
|
|
$etudiantCheck = $areSetParam && checkParam($request->etudiant, 'utilisateur.identifiant'); // etudiant (username) bon format
|
2016-01-02 13:21:31 +00:00
|
|
|
// $formationCheck = $etudiantCheck && checkParam($request->formation, 'auto_increment_id'); // formation (formation) bon format
|
|
|
|
$semestreCheck = $etudiantCheck && checkParam($request->semestre, 'auto_increment_id'); // semestre (rang) bon format
|
|
|
|
// $anneeCheck = $semestreCheck && checkParam($request->annee, 'semestre.annee'); // semestre (annee) bon format
|
2015-11-08 21:30:23 +00:00
|
|
|
|
2016-01-02 13:21:31 +00:00
|
|
|
if( $semestreCheck ){ // si tout les paramètres sont bons
|
|
|
|
$userlist = DataBase::getInstance()->listeEtudiantsGroupe($request->etudiant, $request->semestre);
|
2015-11-08 21:30:23 +00:00
|
|
|
|
|
|
|
if( is_array($userlist) ){ // si on a récupéré la liste des utilisateurs
|
|
|
|
$answer->userlist = $userlist;
|
|
|
|
$answer->request = 'success';
|
|
|
|
}else // si on a pas récupéré de liste, alors c'est que $userlist est un message d'erreur
|
2015-11-19 07:58:15 +00:00
|
|
|
$answer->request = $userlist;
|
2015-11-08 21:30:23 +00:00
|
|
|
|
|
|
|
}else
|
|
|
|
$answer->request = 'param_error';
|
|
|
|
|
2015-10-22 19:19:52 +00:00
|
|
|
}else
|
2015-11-08 21:30:23 +00:00
|
|
|
$answer->request = 'permission_error';
|
2015-10-22 19:19:52 +00:00
|
|
|
break;
|
|
|
|
|
2015-11-10 09:50:43 +00:00
|
|
|
/**************************************/
|
|
|
|
/* retourne le semestre d'un étudiant */
|
|
|
|
/**************************************/
|
2015-11-19 22:32:54 +00:00
|
|
|
case 'getSemestre': if( permission('student') ){
|
2015-11-10 09:50:43 +00:00
|
|
|
|
2015-12-30 16:21:10 +00:00
|
|
|
$areSetParam = isset($request->etudiant); // les arguments existent
|
|
|
|
$etudiantCheck = $areSetParam && checkParam($request->etudiant, 'utilisateur.identifiant'); // etudiant (username) bon format
|
2015-11-10 09:50:43 +00:00
|
|
|
|
|
|
|
if( $etudiantCheck ){ // si tout les paramètres sont bons
|
|
|
|
|
|
|
|
$semestre = DataBase::getInstance()->studentCurrent($request->etudiant, $_SESSION['semestre_pair'], $_SESSION['annee']);
|
|
|
|
|
|
|
|
if( is_numeric($semestre) ){ // si c'est un nombre, c'est que c'est bon
|
|
|
|
$answer->request = 'success';
|
|
|
|
$answer->semestre = $semestre;
|
|
|
|
}else
|
|
|
|
$answer->request = $semestre;
|
|
|
|
|
|
|
|
}else
|
|
|
|
$answer->request = 'param_error';
|
|
|
|
|
|
|
|
}else
|
|
|
|
$answer->request = 'permission_error';
|
|
|
|
break;
|
|
|
|
|
2015-10-22 19:19:52 +00:00
|
|
|
|
2015-11-04 08:15:35 +00:00
|
|
|
/*******************************************************************/
|
|
|
|
/* retourne les utilisateurs de tous les groupes du semestre donné */
|
|
|
|
/*******************************************************************/
|
2016-01-02 17:43:33 +00:00
|
|
|
case 'grouplist': if( permission('student') || permission('master') || permission('admin') ){
|
2015-10-23 08:04:26 +00:00
|
|
|
|
2016-01-02 13:21:31 +00:00
|
|
|
$areSetParam = isset($request->semestre); // les arguments existent
|
|
|
|
// $formationCheck = $areSetParam && checkParam($request->formation, 'auto_increment_id'); // formation (formation) bon format
|
|
|
|
$semestreCheck = $areSetParam && checkParam($request->semestre, 'auto_increment_id'); // semestre (rang) bon format
|
|
|
|
// $anneeCheck = $semestreCheck && checkParam($request->annee, 'semestre.annee'); // semestre (annee) bon format
|
2015-10-28 17:08:12 +00:00
|
|
|
|
2016-01-02 13:21:31 +00:00
|
|
|
if( $semestreCheck ){
|
2015-11-04 08:15:35 +00:00
|
|
|
|
2016-01-02 13:21:31 +00:00
|
|
|
$grouplist = DataBase::getInstance()->listeEtudiantsTousGroupesSemestre($request->semestre);
|
2015-11-08 21:30:23 +00:00
|
|
|
|
|
|
|
if( is_array($grouplist) ){ // si on a récupéré la liste des utilisateurs
|
|
|
|
$answer->grouplist = $grouplist;
|
|
|
|
$answer->request = 'success';
|
|
|
|
}else // si on a pas récupéré de liste, alors c'est que $grouplist est un message d'erreur
|
2015-11-11 17:23:37 +00:00
|
|
|
$answer->request = $grouplist;
|
2015-11-08 21:30:23 +00:00
|
|
|
|
|
|
|
}else
|
2015-11-11 17:23:37 +00:00
|
|
|
$answer->request = 'param_error';
|
2015-11-04 08:15:35 +00:00
|
|
|
|
|
|
|
}else
|
2015-11-08 21:30:23 +00:00
|
|
|
$answer->request = 'permission_error';
|
2015-11-04 08:15:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* retourne les utilisateurs de tous les groupes des modules d'un enseignant */
|
|
|
|
/*****************************************************************************/
|
2015-11-08 21:30:23 +00:00
|
|
|
case 'grouplistForTeacher': if( permission('teacher') || permission('admin') ){
|
2015-11-04 08:15:35 +00:00
|
|
|
|
2015-12-30 16:21:10 +00:00
|
|
|
$areSetParam = isset($request->annee) && isset($request->enseignant); // les arguments existent
|
|
|
|
$anneeCheck = $areSetParam && checkParam($request->annee, 'semestre.annee'); // semestre (annee) bon format
|
|
|
|
$enseignantCheck = $anneeCheck && checkParam($request->enseignant, 'utilisateur.identifiant'); // enseignant (annee) bon format
|
2015-11-06 13:05:14 +00:00
|
|
|
|
2015-11-08 21:30:23 +00:00
|
|
|
if( $enseignantCheck ){
|
2015-11-04 08:15:35 +00:00
|
|
|
|
2015-11-17 07:46:39 +00:00
|
|
|
$grouplist = DataBase::getInstance()->listeEtudiantsTousGroupesEnseignant($request->annee, $_SESSION['semestre_pair'], $request->enseignant);
|
2015-11-08 21:30:23 +00:00
|
|
|
|
|
|
|
if( is_array($grouplist) ){ // si on a récupéré la liste des utilisateurs
|
|
|
|
$answer->grouplist = $grouplist;
|
|
|
|
$answer->request = 'success';
|
|
|
|
}else // si on a pas récupéré de liste, alors c'est que $grouplist est un message d'erreur
|
2015-11-11 17:23:37 +00:00
|
|
|
$answer->request = $grouplist;
|
2015-11-04 08:15:35 +00:00
|
|
|
|
2015-11-08 21:30:23 +00:00
|
|
|
}else
|
2015-11-11 17:23:37 +00:00
|
|
|
$answer->request = 'param_error';
|
2015-11-08 21:30:23 +00:00
|
|
|
|
2015-11-04 08:15:35 +00:00
|
|
|
}else
|
2015-11-08 21:30:23 +00:00
|
|
|
$answer->request = 'permission_error';
|
2015-11-04 08:15:35 +00:00
|
|
|
break;
|
|
|
|
|
2015-11-08 21:30:23 +00:00
|
|
|
/********************************************************************/
|
|
|
|
/* retourne les utilisateurs de tous les groupes d'une année donnée */
|
|
|
|
/********************************************************************/
|
2015-11-26 15:40:04 +00:00
|
|
|
case 'grouplistForYear': if( permission('master') || permission('teacher') || permission('admin') ){
|
2015-11-04 08:15:35 +00:00
|
|
|
|
2015-12-30 16:21:10 +00:00
|
|
|
$areSetParam = isset($request->annee); // les arguments existent
|
|
|
|
$anneeCheck = $areSetParam && checkParam($request->annee, 'semestre.annee'); // semestre (annee) bon format
|
2015-11-06 13:05:14 +00:00
|
|
|
|
2015-11-08 21:30:23 +00:00
|
|
|
if( $anneeCheck ){
|
2015-10-28 17:08:12 +00:00
|
|
|
|
2015-11-17 07:46:39 +00:00
|
|
|
// $grouplist = DataBase::getInstance()->listeEtudiantsTousGroupesAnnee($request->annee, $_SESSION['semestre_pair']);
|
|
|
|
$grouplist = DataBase::getInstance()->listeEtudiantsTousGroupesAnnee($request->annee, null);
|
2015-11-08 21:30:23 +00:00
|
|
|
|
|
|
|
if( is_array($grouplist) ){ // si on a récupéré la liste des utilisateurs
|
|
|
|
$answer->grouplist = $grouplist;
|
|
|
|
$answer->request = 'success';
|
|
|
|
}else // si on a pas récupéré de liste, alors c'est que $grouplist est un message d'erreur
|
2015-11-11 17:23:37 +00:00
|
|
|
$answer->request = $grouplist;
|
2015-10-28 17:08:12 +00:00
|
|
|
|
2015-11-08 21:30:23 +00:00
|
|
|
}else
|
2015-11-11 17:23:37 +00:00
|
|
|
$answer->request = 'param_error';
|
2015-11-08 21:30:23 +00:00
|
|
|
|
2015-10-28 17:08:12 +00:00
|
|
|
}else
|
2015-11-08 21:30:23 +00:00
|
|
|
$answer->request = 'permission_error';
|
2015-10-23 08:04:26 +00:00
|
|
|
break;
|
|
|
|
|
2015-11-19 13:08:40 +00:00
|
|
|
/****************************************************************/
|
|
|
|
/* retourne la liste des semestres/années présentes dans la BDD */
|
|
|
|
/****************************************************************/
|
2015-11-26 15:40:04 +00:00
|
|
|
case 'getSemestres': if( permission('master') || permission('admin') ){
|
2015-11-19 13:08:40 +00:00
|
|
|
|
|
|
|
$answer->yearList = DataBase::getInstance()->getListeSemestres();
|
|
|
|
$answer->request = 'success';
|
|
|
|
|
|
|
|
}else
|
|
|
|
$answer->request = 'permission_error';
|
|
|
|
break;
|
|
|
|
|
2015-12-06 14:05:22 +00:00
|
|
|
|
|
|
|
/************************************************************/
|
|
|
|
/* déplace une liste d'étudiants de leurs groupe à un autre */
|
|
|
|
/************************************************************/
|
|
|
|
case 'move_multiple': if( permission('admin') && $_SESSION['annee'] >= getCurrentYear() ){
|
|
|
|
|
|
|
|
$areSetParam = isset($request->etudiants) && isset($request->groupe) && isset($request->semestre); // les arguments existent
|
|
|
|
$typeOkParam = $areSetParam && is_array($request->etudiants) && is_numeric($request->groupe); // si c'est des strings
|
|
|
|
$nEmptyParam = $typeOkParam && count($request->etudiants) > 0 && is_numeric($request->semestre); // d'au moins 1 caractère
|
|
|
|
|
|
|
|
|
|
|
|
if( $nEmptyParam ){ // si param ok
|
|
|
|
$answer->request = DataBase::getInstance()->deplacerEtudiantMultiple($request->etudiants, $request->groupe, $request->semestre);
|
2015-11-08 21:30:23 +00:00
|
|
|
}else
|
2015-11-11 17:23:37 +00:00
|
|
|
$answer->request = 'param_error';
|
2015-11-08 21:30:23 +00:00
|
|
|
|
2015-10-31 16:25:19 +00:00
|
|
|
}else
|
2015-11-08 21:30:23 +00:00
|
|
|
$answer->request = 'permission_error';
|
2015-10-31 16:25:19 +00:00
|
|
|
break;
|
|
|
|
|
2015-11-24 23:04:02 +00:00
|
|
|
|
|
|
|
|
2015-11-25 23:18:50 +00:00
|
|
|
/******************************************/
|
|
|
|
/* la liste de TOUS les groupes de la BDD */
|
|
|
|
/******************************************/
|
2015-11-26 15:40:04 +00:00
|
|
|
case 'exhaustiveList': if( permission('master') || permission('admin') ){
|
2015-11-25 23:18:50 +00:00
|
|
|
|
|
|
|
$answer->grouplist = DataBase::getInstance()->getExhaustiveGroupList();
|
|
|
|
$answer->request = 'success';
|
|
|
|
|
|
|
|
}else
|
|
|
|
$answer->request = 'permission_error';
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-24 23:04:02 +00:00
|
|
|
/*******************************************/
|
|
|
|
/* intégration des élèves pour un semestre */
|
|
|
|
/*******************************************/
|
|
|
|
case 'addUserlist': if( permission('admin') ){
|
2015-11-30 18:46:10 +00:00
|
|
|
$areSetParam = isset($request->formationList) && isset($request->rang) && isset($request->annee);
|
|
|
|
$typeOkParam = $areSetParam && is_numeric($request->rang) && is_numeric($request->annee);
|
|
|
|
$verifiParam = $typeOkParam && $request->annee >= getCurrentYear();
|
2015-11-24 23:04:02 +00:00
|
|
|
|
2015-11-30 18:46:10 +00:00
|
|
|
if( $verifiParam ){ // si tout les paramètres sont bons
|
2015-11-24 23:04:02 +00:00
|
|
|
DataBase::getInstance()->addUserlist($request->rang, $request->annee, $request->formationList);
|
|
|
|
$answer->request = 'success';
|
|
|
|
}else
|
|
|
|
$answer->request = 'param_error';
|
|
|
|
|
|
|
|
}else
|
|
|
|
$answer->request = 'permission_error';
|
|
|
|
break;
|
|
|
|
|
2015-11-25 23:18:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-22 16:55:26 +00:00
|
|
|
/***********/
|
|
|
|
/* DEFAULT */
|
|
|
|
/***********/
|
|
|
|
default:
|
|
|
|
$answer->request = 'unknown_level_1';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-06 19:08:28 +00:00
|
|
|
}
|
2015-10-22 16:55:26 +00:00
|
|
|
?>
|