public function __construct() { if (file_exists(self::$path)) { self::$databaseFile = fopen(self::$path, "a+"); fclose(self::$databaseFile); } }
/** * Retourne l'objet correspondant à l'id donné. * * @param int $id Identifiant de l'objet à trouver * @return Module */ public static function findById($id) { $data = BaseSingleton::select('SELECT module.id as id, module.bareme_id as bareme_id, module.label as label, module.description as description, ' . 'module.date_creation as date_creation, module.number as number, module.affiche as affiche, assignment.id as assignment_id, exam.id as exam_id ' . 'FROM module, assignment, exam ' . 'WHERE module.id = assignment.module_id AND module.id = exam.module_id AND ' . 'module.id = ? ' . 'GROUP BY module.id', array('i', &$id)); $module = new Module(); // var_dump($data); $module->hydrate($data[0]); $eleves = UserDAL::findAllByModule($module); foreach ($eleves as $eleve) { $module->inscrireEleve($eleve); } return $module; }
public function getUser() { $user = null; if (is_int($this->extUser)) { $user = UserDAL::findById($this->extUser); $this->extUser = $user; } else { if (is_a($this->extUser, "User")) { $user = $this->extUser; } } return $user; }
public function setEnsignant($user) { if (is_string($user)) { $user = (int) $user; $prof = UserDAL::findById($user); //recupère l'user associé à cet id if ($prof->isEnseignant()) { $this->enseignant = $prof; //modifie l'attribut enseignant de ce module } } if (is_int($user)) { $prof = UserDAL::findById($user); //recupère l'user associé à cet id if ($prof->isEnseignant()) { $this->enseignant = $prof; //modifie l'attribut enseignant de ce module } } else { if (is_a($user, "User")) { if ($user->isEnseignant()) { $this->enseignant = $user; //modifie l'attribut enseignant de ce module } } } }
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/UserDAL.php'; $students = UserDAL::findAllStudents(); $result = array(); foreach ($students as $student) { $avatar = '<img src="/WebBristol/images/avatar/' . (!empty($student->getAvatar()) ? $student->getAvatar() : 'avatar-dafault.png') . '" alt="Avatar" class="img-rounded img-responsive small">'; $see = '<a class="btn btn-default" href="see/' . $student->getId() . '" role="button"><span class="glyphicon glyphicon-eye-open"></span></a>'; $edit = '<a class="btn btn-default" href="edit/' . $student->getId() . '" role="button"><span class="glyphicon glyphicon-pencil"></span></a>'; $row = array("avatar" => $avatar, "first_name" => $student->getFirstName(), "last_name" => $student->getLastName(), "birth_date" => $student->getBirthDate(), "email" => $student->getMail(), "address" => $student->getAddress(), "phone" => $student->getPhoneNumber(), "inscription_date" => $student->getInscriptionDate(), "action" => $see . $edit); $result[] = $row; } echo json_encode($result);
//Stores the filename as it was on the client computer. $imagename = $_FILES['avatar']['name']; //Stores the filetype e.g image/jpeg $imagetype = $_FILES['avatar']['type']; //Stores any error codes from the upload. $imageerror = $_FILES['avatar']['error']; //Stores the tempname as it is given by the host when uploaded. $imagetemp = $_FILES['avatar']['tmp_name']; //The path you wish to upload the image to $imagePath = "/WebBristol/images/avatar/"; if (is_uploaded_file($imagetemp)) { if (!move_uploaded_file($imagetemp, $imagePath . $imagename)) { $_SESSION['message']['warning'] = "Failed to move your image."; } else { $user->setAvatar($imagename); } } else { $_SESSION['message']['warning'] = "Failed to upload your image."; } } $user->setRole(1); $idInserted = UserDAL::flush($user); if ($idInserted > 0) { $action = empty($id) ? 'added' : 'edited'; $_SESSION['message']['success'] = "Student {$action} with success!"; header("Location: see/{$idInserted}"); } else { $_SESSION['message']['danger'] = 'Insert failed.'; $redirect = empty($id) ? 'add' : "edit/{$id}"; header('Location: ' . $redirect); }
require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/ComponentDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/LikertDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/ModuleDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/PriceDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/QuestionDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/RoleDAL.php'; // OK require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/ThemeDAL.php'; // OK require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/TypeDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/UserDAL.php'; // OK // Date in a string $now = date('Y-m-d'); // User $user = UserDAL::findById(64); // Theme $theme = ThemeDAL::findById(4); // Question // $question = QuestionDAL::findById(21); $question = new Question(0, 'Do you like ducks ?'); $question->setTheme($theme); $idQuestion = QuestionDAL::flush($question); if ($idAnswer > 0) { $answer->setId($idAnswer); $_SESSION['message']['success'] = 'Ca marche (' . $idAnswer . ')'; } else { $_SESSION['message']['warning'] = 'Ca a rate'; } // Answer $answer = new Answer(0, 'I don\'t care.', $now);
* You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ require_once '../../model/class/User.php'; require_once '../../model/DAL/UserDAL.php'; //Création de l'user à insèrer $user = new User(); //Vérifie ce qui est renvoyer par le POST de /view/phtml/user_create.php //et set de l'objet user u fur et à mesure $validLastName = filter_input(INPUT_POST, 'lastName', FILTER_SANITIZE_STRING); $user->setNom($validLastName); $validFisrtName = filter_input(INPUT_POST, 'firstName', FILTER_SANITIZE_STRING); $user->setPrenom($validFisrtName); $myregex = "~^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}\$~"; $validBirthDate = filter_input(INPUT_POST, 'birthDate', FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => $myregex))); $user->setDateNaissance($validBirthDate); $validAddress = filter_input(INPUT_POST, 'address', FILTER_SANITIZE_STRING); $user->setAdresse($validAddress); $validEmail = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING); $user->setMail($validEmail); $validUserTypeId = filter_input(INPUT_POST, 'userType', FILTER_SANITIZE_NUMBER_INT); $user->setType($validUserTypeId); //Insertion de l'user dans la table $validInsertion = UserDAL::insertOnDuplicate($user); if ($validInsertion != null) { echo "Insertion OK"; } else { echo "ECHEC insertion, good luck"; } echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../../?page=user_list&modification=success">';
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/class/Serie.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/DAL/ModuleDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/DAL/UserDAL.php'; $moduleId = filter_input(INPUT_GET, 'module_id', FILTER_SANITIZE_NUMBER_INT); $module = ModuleDAL::findById($moduleId); $students = UserDAL::findAllByModule($module); $data = array(); $bigdata = array(); foreach ($students as $student) { $nomSerie = new Serie("nom"); $prenomSerie = new Serie("prenom"); $passSerie = new Serie("pass"); $userSerie = new Serie("user"); $nomSerie->data = $student->getNom(); $prenomSerie->data = $student->getPrenom(); $pass = $student->getSuccessModule($moduleId); if ($pass === 1) { $studentPass = '******'; } else { if ($pass === 0) { $studentPass = '******'; } else { $studentPass = '******'; } } $passSerie->data = $studentPass; $userSerie->data = array($nomSerie, $prenomSerie, $passSerie); $data[] = $userSerie; }
<?php // Test the user's level of access $role = $_SESSION['user']->getRole()->getName(); if ($role === 'Professor') { $_SESSION['data']['users'] = UserDAL::findAllStudents(); require_once 'view/menu/menu_student.phtml'; require_once 'view/student/student_all.phtml'; } else { header('Location: ../home'); }
session_start(); // REQUIRES require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/UserDAL.php'; // Accessing the POST var in a safe way to prevent SQL injects. $login = filter_input(INPUT_POST, 'login'); $password = filter_input(INPUT_POST, 'password'); // Checking the input parameters if (empty($login) && empty($password)) { // We redirect the user if they aren't all set // It means that someone is trying to access this page without authorisation. header('Location: ../login'); } // Encrypting the password to compare it later. $encryptedPassword = hash(hash_algos()[7], $password); // We're trying to access to the user with the given login. $user = UserDAL::findByLogin($login); // Case 1 : The login doesn't exist; if ($user->getId() === -1) { // We're saving the error message. $_SESSION["message"]["danger"] = "This login doesn't exist!"; // Redirecting. header('Location: ../login'); } else { if ($user->getPassword() !== $encryptedPassword) { // We're saving the error message. $_SESSION["message"]["danger"] = "Wrong password! Try again."; // Redirecting. header('Location: ../login'); } else { // We're saving the success message. $_SESSION["message"]["success"] = "You are connected. Welcome " . $user->getFirstName() . ' ' . $user->getLastName() . '!';
public function getModelMail() { $modelMail = null; if (is_int($this->modele)) { $modelMail = UserDAL::findById($this->modele); $this->modele = $modelMail; } else { if (is_a($this->modele, "ModelMail")) { $modelMail = $this->modele; } } return $modelMail; }
<?php // Test the user's level of access $role = $_SESSION['user']->getRole()->getName(); $_SESSION['data']['mode'] = 'add'; if ($role === 'Professor') { $_SESSION['data']['users'] = UserDAL::findAll(); require_once 'view/menu/menu_module.phtml'; require_once 'view/module/module_form.phtml'; } else { header('Location: ../home'); }
</ul> </li> </ul> <?php } ?> <?php if (isset($_SESSION['user'])) { ?> <ul class="nav navbar-nav navbar-right"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> <?php $user = UserDAL::findById($_SESSION['user']); echo '<img src=".' . $user->getAvatar()->getType()->getChemin() . '/' . $user->getAvatar()->getNom() . '" class="avatar"/>'; echo $user->getPrenom() . ' ' . $user->getNom(); ?> <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="?page=profile">Profile</a></li> <li role="separator" class="divider"></li> <li><a href="" data-toggle="modal" data-target="#mail-mark">Resend Mark Mail</a></li> <li><a href="" data-toggle="modal" data-target="#mail-payment">Resend payment receipt</a></li> <?php if (isset($_SESSION['user']) && isset($_SESSION['role']) && $_SESSION['role'] === User::TYPE_USER_STUDENT) { ?> <li role="separator" class="divider"></li> <li><a href="?page=pay_fees">Pay retry fees</a></li> <?php
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/UserDAL.php'; $filter = filter_input(INPUT_GET, 'filter'); $students = UserDAL::filterByLastName($filter); $result = array(); foreach ($students as $student) { $avatar = '<img src="/WebBristol/images/avatar/' . (!empty($student->getAvatar()) ? $student->getAvatar() : 'avatar-dafault.png') . '" alt="Avatar" class="img-rounded img-responsive small">'; $see = '<a class="btn btn-default" href="see/' . $student->getId() . '" role="button"><span class="glyphicon glyphicon-eye-open"></span></a>'; $edit = '<a class="btn btn-default" href="edit/' . $student->getId() . '" role="button"><span class="glyphicon glyphicon-pencil"></span></a>'; $row = array("avatar" => $avatar, "first_name" => $student->getFirstName(), "last_name" => $student->getLastName(), "birth_date" => $student->getBirthDate(), "email" => $student->getMail(), "address" => $student->getAddress(), "phone" => $student->getPhoneNumber(), "inscription_date" => $student->getInscriptionDate(), "action" => $see . $edit); $result[] = $row; } echo json_encode($result);
<?php if (isset($_SESSION['user']) && isset($_SESSION['role']) && $_SESSION['role'] > User::TYPE_USER_STUDENT) { ?> <META HTTP-EQUIV="Refresh" Content="0; URL=./?error=403"> <?php } else { ?> <?php require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/DAL/ModuleDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/DAL/UserDAL.php'; $module_id = filter_input(INPUT_GET, 'module_id', FILTER_SANITIZE_NUMBER_INT); $module = ModuleDAL::findById($module_id); $students = UserDAL::findAllByModule($module); $studentCurrent = UserDAL::findById($_SESSION['user']); ?> <div class="row"> <div class="col-lg-6"> <div class="input-group"> <label for="title"> <h4> <?php echo $module->getLabel(); ?> </h4> </label> <p> <?php echo $module->getDescription(); ?>
public function getEnseignant() { $enseignant = null; if (is_int($this->enseignant)) { $enseignant = UserDAL::findById($this->enseignant->getId()); $this->enseignant = $enseignant; } else { if (is_a($this->enseignant, "User")) { $enseignant = $this->enseignant; } } return $enseignant; }
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/ComponentDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/UserDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/UserHasModuleDAL.php'; $idUser = filter_input(INPUT_POST, 'idUser'); $idExam = filter_input(INPUT_POST, 'idExam'); $mark = floatval(filter_input(INPUT_POST, 'mark')); $component = ComponentDAL::findById($idExam); $component->setMark($mark); if (ComponentDAL::flush($component)) { $module = $component->getModule(); $user = UserDAL::findById($idUser); $hasFailed = $user->hasFailed($module); $mustResit = $user->mustResit($module); $finalMark = $user->getFinalMark($module); $userHasModule = UserHasModuleDAL::findByStudentAndModule($idUser, $module->getId()); $userHasModule->setHasFailed($hasFailed); $userHasModule->setMustPay($mustResit); $userHasModule->setFinalMark($finalMark); if ($hasFailed && $mustResit) { UserHasModuleDAL::flush($userHasModule); // Send mail -> Explain which component to resit and how to pay // (Always worst component to resit) } else { if ($hasFailed && !$mustResit) { UserHasModuleDAL::flush($userHasModule); // Send mail -> Tell he has failed the module and that there is no resit } else { if (!$hasFailed && $finalMark > 0) { UserHasModuleDAL::flush($userHasModule);
/** * Methode retourne la note d'un exam d'un eleve, dans un module donnée * @param int $moduleId * @return int (-1 si pas évalué pour cette assignment) */ public function getNoteStudentExam($moduleId) { $noteStdExam; if ($this->isStudent()) { $studentId = $this->getId(); $noteStdExam = UserDAL::noteExam($studentId, $moduleId); return $noteStdExam; } }
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/class/Serie.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/DAL/ModuleDAL.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/DAL/UserDAL.php'; $studentId = filter_input(INPUT_GET, 'student_id', FILTER_SANITIZE_NUMBER_INT); $student = UserDAL::findById($studentId); $modules = ModuleDAL::findAllByEleve($student); $categories = array(); $data = array(); $databaseData = array(); foreach ($modules as $module) { $categories[] = $module->getLabel(); $assignmentMarks = $student->getNoteStudentAssignment($module->getId()); $examMarks = $student->getNoteStudentExam($module->getId()); if ($assignmentMarks === -1) { $assignmentMarks = null; } if ($examMarks === -1) { $examMarks = null; } $databaseData[] = array($assignmentMarks, $examMarks); } $assignmentData = array(); $assignmentReturn = array(); $examData = array(); $examReturn = array(); $finalData = array(); $finalReturn = array(); foreach ($databaseData as $row) { $assignMark = $row[0];
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/WebBristol/model/DAL/UserDAL.php'; // TODO : Si l'user connecte est student, ne pouvoir editer que ses propres info if (isset($_GET['id'])) { $id = filter_input(INPUT_GET, 'id'); } else { header('Location: ../home'); } $student = UserDAL::findStudentById($id); $role = $_SESSION['user']->getRole()->getName(); $_SESSION['data']['mode'] = 'edit'; if ($role === 'Professor') { if ($student->getId() > 0) { $_SESSION['data']['student'] = $student; require_once 'view/menu/menu_student.phtml'; require_once 'view/student/student_form.phtml'; } else { $_SESSION['message']['warning'] = 'This student doesn\'t exist.'; header('Location: ../../home'); } } else { if (intval($id) === $_SESSION['user']->getId()) { $_SESSION['data']['student'] = $_SESSION['user']; require_once 'view/menu/menu_student.phtml'; require_once 'view/student/student_form.phtml'; } else { // 403 $_SESSION['message']['danger'] = 'You can\'t access this page.'; header('Location: ../../home'); }
//et set de l'objet user u fur et à mesure $validLastName = filter_input(INPUT_POST, 'lastName', FILTER_SANITIZE_STRING); $student->setNom($validLastName); $validFisrtName = filter_input(INPUT_POST, 'firstName', FILTER_SANITIZE_STRING); $student->setPrenom($validFisrtName); $myregex = "~^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}\$~"; $validBirthDate = filter_input(INPUT_POST, 'birthDate', FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => $myregex))); $student->setDateNaissance($validBirthDate); $validAddress = filter_input(INPUT_POST, 'address', FILTER_SANITIZE_STRING); $student->setAdresse($validAddress); $validEmail = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING); $student->setMail($validEmail); $student->setType(4); //place l'user type à 4 (correspond à l'id de student) //Insertion du student dans la table user $validInsertion = UserDAL::insertOnDuplicate($student); if ($validInsertion != null) { echo "Insertion Etudiant OK"; } else { echo "ECHEC insertion Etudiant, good luck"; } //Gestion des module selectionner $unModule = $_POST['module']; if (empty($unModule)) { echo "You didn't select any module."; } $N = count($unModule); $module = new Module(); $moduleId = 0; for ($i = 0; $i < $N; $i++) { $moduleId = (int) $unModule[$i];
</select> <span class="input-group-addon" id="sizing-addon1">Items per page</span> </div> </div> <div class="col-lg-6"> <div class="input-group"> <input type="text" class="form-control" placeholder="Search for..."> <span class="input-group-btn"> <button class="btn btn-default" type="button">Go!</button> </span> </div> </div> </div> <?php $users = UserDAL::findAll(); ?> <div class="panel panel-default"> <div class="panel-heading">User list</div> <table class="table"> <tr><th>Last Name</th><th>First Name</th><th>Birth date</th><th>User Type</th><th></th></tr> <?php foreach ($users as $user) { ?> <tr> <td><?php echo $user->getNom(); ?> </td> <td><?php
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/class/SerieStack.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/DAL/UserDAL.php'; if (isset($_COOKIE['user_id']) && isset($_COOKIE['user_role']) && $_COOKIE['user_role'] == User::TYPE_USER_TEACHER) { $enseignantId = (int) $_COOKIE['user_id']; //recupe l'id de l'enseignant logguer $enseignant = UserDAL::findById($enseignantId); //recup l'objet User liier a cette enseignant $mesModules = ModuleDAL::findAllByEnseignant($enseignant); //recupère les module de l'enseignant } if (isset($_COOKIE['user_id']) && isset($_COOKIE['user_role']) && $_COOKIE['user_role'] == User::TYPE_USER_ROOT) { $mesModules = ModuleDAL::findAll(); //recupère TOUS les modules } $categories = array(); $data = array(); $databaseData = array(); foreach ($mesModules as $module) { if ($module->getPourcentageHaveModule() >= 0) { $categories[] = $module->getLabel(); $databaseData[] = $module->getPourcentageHaveModule() * 100.0; } } $passFinalData = array(); $failFinalData = array(); foreach ($databaseData as $passFinalDatabaseData) { $passFinal = $passFinalDatabaseData; $passFinalData[] = $passFinal; $failFinalData[] = 100 - $passFinal;
<?php require_once '../model/DAL/UserDAL.php'; UserDAL::insertOnDuplicate(new User());
echo $module->getLabel(); ?> </option> <?php } ?> </select> </div> </div> <div class="col-lg-6"> <button type="button" class="btn btn-default btn-right hidden"><span class="glyphicon glyphicon-print"></span></button> </div> </div> <?php $mesStudents = UserDAL::findAllStudent(); ?> <div class="panel panel-default"> <div class="panel-heading"> <h3 id="panel-title-module" class="panel-title"> <?php echo $modules[0]->getLabel(); ?> </h3> </div> <table id="table-module-students" class="table"> <tbody> <tr> <th>Last Name</th><th>First Name</th><th>Result</th> </tr> </tbody>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/SERS/SERS/model/DAL/UserDAL.php'; $moduleId = filter_input(INPUT_GET, 'module_id', FILTER_SANITIZE_NUMBER_INT); $module = ModuleDAL::findById($moduleId); $users = UserDAL::findAllStudent(); $userData = array(); $usersData = array(); foreach ($users as $user) { $userData["id"] = $user->getId(); $userData["lastName"] = $user->getNom(); $userData["firtName"] = $user->getPrenom(); $inscrit = false; if ($module->isInscrit($user)) { $inscrit = true; } $userData["inscrit"] = $inscrit; $usersData[] = $userData; } $usersJson = json_encode($usersData); echo $usersJson;