Example #1
0
 /**
  * @param $db
  * @throws Exception
  */
 public static function retrieve()
 {
     $query = "SELECT id, email, f_name, l_name, mobile, ci, credits\n\t\t         FROM `" . App::getDbName() . "`.student";
     try {
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->execute();
         $rows = $query->fetchAll(PDO::FETCH_ASSOC);
         return $rows;
     } catch (PDOException $e) {
         throw new Exception("Something terrible happened. Could not retrieve students data from database.: ");
     }
     // end catch
 }
 private function __construct()
 {
     try {
         // connects to database
         $this->dbConnection = new PDO("mysql:host=" . App::getDbHost() . ";dbname=" . App::getDbName() . ";port=" . App::getDbPort(), App::getDbUsername(), App::getDbPassword());
         $this->dbConnection->setAttribute(PDO::ATTR_ERRMODE, App::getPDOErrorMode());
         // CHANGE THE ERROR MODE, THROW AN EXCEPTION WHEN AN ERROR IS FOUND
         $this->dbConnection->exec("SET NAMES 'utf8'");
     } catch (PDOException $e) {
         // program ends if exception is found
         throw new Exception("Could not connect to the database." . $e->getMessage());
     }
     // end
 }
 public static function disconnectServiceType($serviceType)
 {
     try {
         $query = "DELETE\n\t\t\tFROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n\t\t\tWHERE `" . self::DB_COLUMN_SERVICE_TYPE . "` = :service_type";
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':service_type', $serviceType, PDO::PARAM_STR);
         $query->execute();
         return true;
     } catch (Exception $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not access database. <br/>Please try again.");
     }
 }
 public static function updateMailSent()
 {
     date_default_timezone_set('Europe/Athens');
     $dateNow = new DateTime();
     $dateNow = $dateNow->format(Dates::DATE_FORMAT_IN);
     try {
         $query = "INSERT INTO `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n\t\t\t\tVALUES(\n\t\t\t\t\t:now\n\t\t\t\t)";
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':now', $dateNow, PDO::PARAM_STR);
         $query->execute();
         return true;
     } catch (Exception $e) {
         throw new Exception("Could not data into database.");
     }
 }
 public static function retrieveCurrTermAllTeachingCourses()
 {
     $query = "SELECT `" . UserFetcher::DB_TABLE . "`.`" . UserFetcher::DB_COLUMN_FIRST_NAME . "`,\n\t\t\t\t\t\t `" . UserFetcher::DB_TABLE . "`.`" . UserFetcher::DB_COLUMN_LAST_NAME . "`,\n\t\t\t\t\t\t `" . CourseFetcher::DB_TABLE . "`.`" . CourseFetcher::DB_COLUMN_CODE . "`,\n\t\t\t\t\t\t `" . CourseFetcher::DB_TABLE . "`.`" . CourseFetcher::DB_COLUMN_NAME . "`,\n\t\t\t\t\t\t `" . TermFetcher::DB_TABLE . "`.`" . TermFetcher::DB_COLUMN_NAME . "` AS\n\t\t\t\t\t\t" . TermFetcher::DB_TABLE . "_" . TermFetcher::DB_COLUMN_NAME . "\n\t\t\tFROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n\t\t\tINNER JOIN `" . App::getDbName() . "`.`" . UserFetcher::DB_TABLE . "`\n\t\t\t\tON `" . Tutor_has_course_has_termFetcher::DB_TABLE . "`.`" . Tutor_has_course_has_termFetcher::DB_COLUMN_TUTOR_USER_ID . "` = `" . UserFetcher::DB_TABLE . "`.`" . UserFetcher::DB_COLUMN_ID . "`\n\t\t\tINNER JOIN `" . TermFetcher::DB_TABLE . "`\n\t\t\t\tON `" . Tutor_has_course_has_termFetcher::DB_TABLE . "`.`" . Tutor_has_course_has_termFetcher::DB_COLUMN_TERM_ID . "` = `" . TermFetcher::DB_TABLE . "`.`" . TermFetcher::DB_COLUMN_ID . "`\n\t\t\tINNER JOIN `" . CourseFetcher::DB_TABLE . "`\n\t\t\t\tON `" . Tutor_has_course_has_termFetcher::DB_TABLE . "`.`" . Tutor_has_course_has_termFetcher::DB_COLUMN_COURSE_ID . "` = `" . CourseFetcher::DB_TABLE . "`.`" . CourseFetcher::DB_COLUMN_ID . "`\n\t\t\tWHERE (:now BETWEEN `" . TermFetcher::DB_TABLE . "`.`" . TermFetcher::DB_COLUMN_START_DATE . "` AND `" . TermFetcher::DB_TABLE . "`.`" . TermFetcher::DB_COLUMN_END_DATE . "`)";
     try {
         date_default_timezone_set('Europe/Athens');
         $now = new DateTime();
         $now = $now->format(Dates::DATE_FORMAT_IN);
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':now', $now, PDO::PARAM_STR);
         $query->execute();
         return $query->fetchAll(PDO::FETCH_ASSOC);
     } catch (PDOException $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not retrieve teaching courses from current terms from database.");
     }
 }
Example #6
0
 /**
  * Returns a single column from the next row of a result set or FALSE if there are no more rows.
  *
  * @param $what
  * @param $field
  * @param $value
  * @param $id
  * @return mixed
  * @throws Exception
  */
 public function updateInfo($what, $field, $value, $id)
 {
     // I have only added few, but you can add more. However do not add 'password' even though the parameters will only be given by you and not the user, in our system.
     $allowed = ['id', 'username', 'f_name', 'l_name', 'email', 'COUNT(mobile)', 'mobile', 'user', 'gen_string', 'COUNT(gen_string)', 'COUNT(id)', 'img_loc'];
     if (!in_array($what, $allowed, true) || !in_array($field, $allowed, true)) {
         throw new InvalidArgumentException();
     } else {
         try {
             $query = "UPDATE `" . App::getDbName() . "`.`" . $field . "` SET `{$what}` = ? WHERE `id`= ?";
             $dbConnection = DatabaseManager::getConnection();
             $query = $dbConnection->prepare($query);
             $query->bindValue(1, $value, PDO::PARAM_STR);
             $query->bindValue(2, $id, PDO::PARAM_INT);
             $query->execute();
             return true;
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
     }
 }
 public static function existsStudentId($studentId)
 {
     try {
         $query = "SELECT COUNT(" . self::DB_COLUMN_STUDENT_ID . ") FROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "` WHERE `" . self::DB_COLUMN_STUDENT_ID . "` = :studentId";
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':studentId', $studentId, PDO::PARAM_INT);
         $query->execute();
         if ($query->fetchColumn() === '0') {
             return false;
         }
     } catch (Exception $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not check if stuent id already exists on database.");
     }
     return true;
 }
 public static function existsUserId($id)
 {
     try {
         $sql = "SELECT COUNT(" . self::DB_COLUMN_USER_ID . ") FROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "` WHERE `" . self::DB_COLUMN_USER_ID . "` = :user_id";
         $dbConnection = DatabaseManager::getConnection();
         $dbConnection = $dbConnection->prepare($sql);
         $dbConnection->bindParam(':user_id', $id, PDO::PARAM_INT);
         $dbConnection->execute();
         if ($dbConnection->fetchColumn() === '0') {
             return false;
         }
     } catch (Exception $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not check if tutor id already exists on database.");
     }
     return true;
 }
 public static function insert($reportId)
 {
     try {
         $queryInsertUser = "INSERT INTO `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n\t\t\t(`" . self::DB_COLUMN_REPORT_ID . "`)\n\t\t\tVALUES(:report_id)";
         $dbConnection = DatabaseManager::getConnection();
         $queryInsertUser = $dbConnection->prepare($queryInsertUser);
         $queryInsertUser->bindParam(':report_id', $reportId, PDO::PARAM_INT);
         $queryInsertUser->execute();
     } catch (Exception $e) {
         throw new Exception("Could not insert report data into database.");
     }
 }
Example #10
0
 public function getMajors()
 {
     $query = "SELECT major.code AS 'Code', major.name AS 'Name', major.id\n\t\t\t\tFROM `" . App::getDbName() . "`.major";
     try {
         $query = $this->db->prepare($query);
         $query->execute();
         return $query->fetchAll(PDO::FETCH_ASSOC);
     } catch (Exception $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not retrieve majors data from database.");
     }
 }
 public static function delete($id)
 {
     try {
         $query = "DELETE FROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "` WHERE `" . self::DB_COLUMN_ID . "` = :id";
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':id', $id, PDO::PARAM_INT);
         $query->execute();
         return true;
     } catch (Exception $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not delete instructor from database.");
     }
 }
 /**
  * NEEDS TESTING
  * @param $dateStart
  * @param $dateEnd
  * @param $tutorId
  * @throws Exception
  * @internal param $db
  * @return bool
  */
 public static function existDatesBetween($dateStart, $dateEnd, $tutorId)
 {
     date_default_timezone_set('Europe/Athens');
     $dateStart = $dateStart->format(Dates::DATE_FORMAT_IN);
     $dateEnd = $dateEnd->format(Dates::DATE_FORMAT_IN);
     $query = "SELECT COUNT(`" . self::DB_TABLE . "`.`" . self::DB_COLUMN_ID . "`),`" . CourseFetcher::DB_TABLE . "`\n\t\t\tFROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n\t\t\tWHERE `" . self::DB_COLUMN_TUTOR_USER_ID . "` = :tutor_id\n\t\t\tAND(`" . self::DB_TABLE . "`.`" . self::DB_COLUMN_START_TIME . "`  BETWEEN {$dateStart} AND {$dateEnd})";
     try {
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':tutor_id', $tutorId, PDO::PARAM_INT);
         $query->execute();
         if ($query->fetchColumn() === '0') {
             return false;
         }
         return $query->fetchAll(PDO::FETCH_ASSOC);
     } catch (PDOException $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not retrieve teaching courses data from database.");
     }
     return true;
 }
 public static function countForTermIds($termIds, $labels = [])
 {
     if (empty($labels)) {
         $labels = self::$labels;
     }
     foreach ($termIds as $key => $termId) {
         $termBindParams[] = ':term_id_' . $key;
     }
     $termBindParams = implode(', ', $termBindParams);
     $labelBindParams = "'" . implode("', '", $labels) . "'";
     $query = "SELECT COUNT(" . self::DB_COLUMN_ID . ") AS total\n\t\t\tFROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n            WHERE `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_TERM_ID . "` in ({$termBindParams})\n            AND `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_LABEL_MESSAGE . "` in ({$labelBindParams})";
     try {
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         foreach ($termIds as $key => $termId) {
             $query->bindValue(":term_id_{$key}", $termId, PDO::PARAM_INT);
         }
         $query->execute();
         return $query->fetch(PDO::FETCH_ASSOC)['total'];
     } catch (PDOException $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not retrieve data from database.");
     }
 }
Example #14
0
 } else {
     if (isset($_POST['disconnect-dropbox-excel-btn'])) {
         DropboxFetcher::disconnectServiceType(DropboxCon::SERVICE_APP_EXCEL_BACKUP);
         header('Location: ' . BASE_URL . "cloud/success");
         exit;
     } else {
         if (isBtnRqstDnldDBKeyPrsd()) {
             date_default_timezone_set('Europe/Athens');
             $curWorkingDate = new DateTime();
             $curWorkingHour = intval($curWorkingDate->format('H'));
             $filePath = ROOT_PATH . 'storage/backups/';
             $fileName = 'sass_app_db_' . date('m_d_Y_Hi') . '.sql';
             $zippedFileName = $fileName . '.gz';
             $fullPathName = $filePath . $fileName;
             $dumpSettings = array('compress' => Ifsnop\Mysqldump\Mysqldump::GZIP, 'no-data' => false, 'add-drop-table' => true, 'single-transaction' => false, 'lock-tables' => true, 'add-locks' => true, 'extended-insert' => true, 'disable-foreign-keys-check' => true, 'skip-triggers' => false, 'add-drop-trigger' => true, 'databases' => false, 'add-drop-database' => false, 'hex-blob' => true);
             $dump = new Ifsnop\Mysqldump\Mysqldump(App::getDbName(), App::getDbUsername(), App::getDbPassword(), App::getDbHost(), 'mysql', $dumpSettings);
             $dump->start($fullPathName);
             // all credits: http://stackoverflow.com/q/22046020/2790481
             header("Content-Description: File Transfer");
             header("Content-Disposition: attachment; filename=\"" . basename($zippedFileName) . "\";");
             header("Content-Type: application/octet-stream");
             header("Content-Encoding: binary");
             header("Content-Length: " . filesize($filePath . $zippedFileName));
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: private");
             header("Pragma: public");
             ob_clean();
             readfile($filePath . $zippedFileName);
         } else {
             if (isBtnRqstDownloadExcelKeyPrsd()) {
Example #15
0
 /**
  * Verifies a user with given email exists. returns true if found; else false
  *
  * @param $email
  * @param $table
  * @throws Exception
  * @internal param $db
  */
 public static function emailExists($email, $table)
 {
     $email = trim($email);
     $query = "SELECT COUNT(id) FROM `" . App::getDbName() . "`.`" . $table . "` WHERE email = :email";
     $dbConnection = DatabaseManager::getConnection();
     $dbConnection = $dbConnection->prepare($query);
     $dbConnection->bindParam(':email', $email, PDO::PARAM_STR);
     try {
         $dbConnection->execute();
         $rows = $dbConnection->fetchColumn();
         if ($rows == 1) {
             return true;
         } else {
             return false;
         }
         // end else if
     } catch (PDOException $e) {
         throw new Exception("Something terrible happened. Could not access database.");
     }
     // end catch
 }
 /**
  * Retrieve pending report give a tutor id for current terms.
  * @param $tutorId
  * @return array
  * @throws Exception
  */
 public function retrievePendingForCurrentTerms($tutorId)
 {
     $query = "SELECT `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_ID . "`, `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_LABEL_MESSAGE . "`,\n\t\t\t`" . self::DB_TABLE . "`.`" . self::DB_COLUMN_LABEL_COLOR . "`, `" . AppointmentFetcher::DB_TABLE . "`.`" . self::DB_COLUMN_ID . "`\n\t\t\tAS " . AppointmentFetcher::DB_TABLE . "_" . AppointmentFetcher::DB_COLUMN_ID . "\n\t\t\tFROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n\t\t\tINNER JOIN `" . App::getDbName() . "`.`" . AppointmentHasStudentFetcher::DB_TABLE . "`\n\t\t\t\tON `" . AppointmentHasStudentFetcher::DB_TABLE . "`.`" . AppointmentHasStudentFetcher::DB_COLUMN_REPORT_ID . "` =\n\t\t\t\t\t`" . self::DB_TABLE . "`.`" . self::DB_COLUMN_ID . "`\n\t\t\tINNER JOIN `" . App::getDbName() . "`.`" . AppointmentFetcher::DB_TABLE . "`\n\t\t\t\tON `" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_ID . "` =\n\t\t\t\t\t`" . AppointmentHasStudentFetcher::DB_TABLE . "`.`" . AppointmentHasStudentFetcher::DB_COLUMN_APPOINTMENT_ID . "`\n\t\t\tINNER JOIN `" . TermFetcher::DB_TABLE . "`\n\t\t\t\tON `" . TermFetcher::DB_TABLE . "`.`" . TermFetcher::DB_COLUMN_ID . "` =\n\t\t\t\t\t`" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_TERM_ID . "`\n\n\t\t\tWHERE (:now BETWEEN `" . TermFetcher::DB_COLUMN_START_DATE . "` AND `" . TermFetcher::DB_COLUMN_END_DATE . "`)\n\t\t\tAND `" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_TUTOR_USER_ID . "`=:tutor_id\n\t\t\tAND `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_LABEL_MESSAGE . "`='" . Report::LABEL_MESSAGE_PENDING_FILL . "'\n\t\t\tORDER BY `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_ID . "` ASC";
     try {
         $now = App::getCurrentTime();
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':now', $now, PDO::PARAM_STR);
         $query->bindParam(':tutor_id', $tutorId, PDO::PARAM_STR);
         $query->execute();
         return $query->fetchAll(PDO::FETCH_ASSOC);
     } catch (PDOException $e) {
         App::storeError($e->getMessage());
         throw new Exception("Could not retrieve data from database.");
     }
 }
 public static function insert($reportId)
 {
     try {
         $query = "INSERT INTO `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n\t\t\t(`" . self::DB_COLUMN_REPORT_ID . "`)\n\t\t\tVALUES(:report_id)";
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':report_id', $reportId, PDO::PARAM_INT);
         $query->execute();
     } catch (Exception $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not insert report data into database.");
     }
     return false;
 }
 public static function retrieveStudentsWithPendingAppointment($appointmentId)
 {
     $query = "SELECT `" . UserFetcher::DB_TABLE . "`.`" . UserFetcher::DB_COLUMN_FIRST_NAME . "` AS\n            " . UserFetcher::DB_TABLE . "_" . UserFetcher::DB_COLUMN_FIRST_NAME . ",\n            `" . UserFetcher::DB_TABLE . "`.`" . UserFetcher::DB_COLUMN_ID . "` AS\n            " . UserFetcher::DB_TABLE . "_" . UserFetcher::DB_COLUMN_ID . ",\n            `" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_START_TIME . "`,\n            `" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_END_TIME . "`,\n            `" . UserFetcher::DB_TABLE . "`.`" . UserFetcher::DB_COLUMN_LAST_NAME . "` AS\n            " . UserFetcher::DB_TABLE . "_" . UserFetcher::DB_COLUMN_LAST_NAME . ",\n            `" . InstructorFetcher::DB_TABLE . "`.`" . InstructorFetcher::DB_COLUMN_ID . "` AS\n            " . InstructorFetcher::DB_TABLE . "_" . InstructorFetcher::DB_COLUMN_ID . ",\n            `" . InstructorFetcher::DB_TABLE . "`.`" . InstructorFetcher::DB_COLUMN_FIRST_NAME . "` AS\n            " . InstructorFetcher::DB_TABLE . "_" . InstructorFetcher::DB_COLUMN_FIRST_NAME . ",\n            `" . InstructorFetcher::DB_TABLE . "`.`" . InstructorFetcher::DB_COLUMN_LAST_NAME . "` AS\n            " . InstructorFetcher::DB_TABLE . "_" . InstructorFetcher::DB_COLUMN_LAST_NAME . ",\n            `" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_COURSE_ID . "`,\n             `" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_TERM_ID . "`,\n            `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_ID . "` , `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_APPOINTMENT_ID . "` ,  `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_STUDENT_ID . "`,\n            `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_REPORT_ID . "`,  `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_INSTRUCTOR_ID . "`, `" . StudentFetcher::DB_TABLE . "`.`" . StudentFetcher::DB_COLUMN_FIRST_NAME . "` AS " . StudentFetcher::DB_TABLE . "_" . StudentFetcher::DB_COLUMN_FIRST_NAME . ", `" . StudentFetcher::DB_TABLE . "`.`" . StudentFetcher::DB_COLUMN_LAST_NAME . "` AS " . StudentFetcher::DB_TABLE . "_" . StudentFetcher::DB_COLUMN_LAST_NAME . ",  `" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_LABEL_MESSAGE . "`,\n\t\t\t`" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_ID . "` AS\n\t\t\t" . AppointmentFetcher::DB_TABLE . "_" . AppointmentFetcher::DB_COLUMN_ID . "\n\t\t\t,  `" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_LABEL_COLOR . "`\n\t\t\tFROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n\t\t\tINNER JOIN  `" . App::getDbName() . "`.`" . StudentFetcher::DB_TABLE . "`\n\t\t\tON `" . App::getDbName() . "`.`" . StudentFetcher::DB_TABLE . "`.`" . StudentFetcher::DB_COLUMN_ID . "`  = `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_STUDENT_ID . "`\n            INNER JOIN  `" . App::getDbName() . "`.`" . AppointmentFetcher::DB_TABLE . "`\n\t\t\tON `" . App::getDbName() . "`.`" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_ID . "`  = `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_APPOINTMENT_ID . "`\n            INNER JOIN  `" . App::getDbName() . "`.`" . UserFetcher::DB_TABLE . "`\n\t\t\tON `" . App::getDbName() . "`.`" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_TUTOR_USER_ID . "`  = `" . UserFetcher::DB_TABLE . "`.`" . UserFetcher::DB_COLUMN_ID . "`\n            INNER JOIN  `" . App::getDbName() . "`.`" . InstructorFetcher::DB_TABLE . "`\n\t\t\tON `" . App::getDbName() . "`.`" . InstructorFetcher::DB_TABLE . "`.`" . InstructorFetcher::DB_COLUMN_ID . "`  = `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_INSTRUCTOR_ID . "`\n\t\t\tWHERE `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_APPOINTMENT_ID . "`=:appointment_id\n\t\t\tAND `" . AppointmentFetcher::DB_TABLE . "`.`" . AppointmentFetcher::DB_COLUMN_LABEL_MESSAGE . "`=" . Appointment::LABEL_MESSAGE_PENDING;
     try {
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':appointment_id', $appointmentId, PDO::PARAM_INT);
         $query->execute();
         return $query->fetchAll(PDO::FETCH_ASSOC);
     } catch (PDOException $e) {
         App::storeError($e->getMessage());
         throw new Exception("Could not retrieve data from database.");
     }
 }
Example #19
0
 public static function existsName($name)
 {
     try {
         $query = "SELECT COUNT(" . self::DB_COLUMN_NAME . ") FROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "` WHERE `" . self::DB_COLUMN_NAME . "` = :name";
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':name', $name, PDO::PARAM_STR);
         $query->execute();
         if ($query->fetchColumn() === '0') {
             return false;
         }
     } catch (Exception $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not check if term name already exists on database. <br/> Aborting process.");
     }
     return true;
 }
Example #20
0
 public function updateAvatarImg($avatar_img_loc)
 {
     $id = $this->getId();
     try {
         $query = "UPDATE `" . App::getDbName() . "`.user SET `img_loc`= :avatar_img WHERE `id`= :user_id";
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':avatar_img', $avatar_img_loc, PDO::PARAM_STR);
         $query->bindParam(':user_id', $id, PDO::PARAM_INT);
         $query->execute();
         return true;
     } catch (PDOException $e) {
         throw new Exception("Something terrible happened. Could not update database.");
     }
     // end try catch
 }
Example #21
0
 public function deleteTeachingCourse($courseId)
 {
     if (!preg_match('/^[0-9]+$/', $courseId)) {
         throw new Exception("Data tempering detected.\n\t\t\t<br/>You&#39;re trying to hack this app.<br/>Developers are being notified about this.<br/>Expect Us.");
     }
     $tutorId = $this->getId();
     try {
         $query = "DELETE FROM `" . App::getDbName() . "`.`" . self::DB_TABLE_TUTOR_HAS_COURSE_HAS_TERM . "` WHERE `tutor_user_id`=:id AND`course_id`=:courseId;";
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':id', $tutorId, PDO::PARAM_INT);
         $query->bindParam(':courseId', $courseId, PDO::PARAM_INT);
         $query->execute();
         return true;
     } catch (Exception $e) {
         throw new Exception("Could not delete course from database.");
     }
 }
Example #22
0
 public static function updateGenString($id, $generatedString)
 {
     try {
         $query = "UPDATE `" . App::getDbName() . "`.`user` SET `gen_string` = :gen_string WHERE `id` = :id";
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':gen_string', $generatedString, PDO::PARAM_STR);
         $query->bindParam(':id', $id, PDO::PARAM_INT);
         $query->execute();
     } catch (Exception $e) {
         Mailer::sendDevelopers($e->getMessage(), __FILE__);
         throw new Exception("Could not update generated string. Please re-send password link to user that was created.");
     }
 }