Beispiel #1
0
 public function indexAction($boardroom = null)
 {
     $currentBoardroom = isset($boardroom) && !empty($boardroom) ? $boardroom : 1;
     $boardrooms = Config::get('calendar/boardrooms');
     $context = ['currentBoardroom' => $currentBoardroom, 'boardrooms' => $boardrooms, 'flash' => Session::flash('home')];
     $employee = new Employee();
     if ($employee->hasPermission('admin')) {
         $context['admin'] = true;
     }
     echo $this->view('home/index', $context);
 }
Beispiel #2
0
 public function buildCalendar($month, $year, $boardroom)
 {
     $offsetModifier = Config::get('calendar/first_weekday');
     $dayCount = cal_days_in_month(CAL_GREGORIAN, $month, $year);
     $fillBefore = date('w', mktime(0, 0, 0, $month, 1, $year)) - $offsetModifier;
     $fillAfter = 6 - date('w', mktime(0, 0, 0, $month, $dayCount, $year)) + $offsetModifier;
     // a lazy fix for excessive number of filler blocks in some scenarios where $offsetModifier is set to 1
     if ($offsetModifier == 1) {
         if ($dayCount + $fillAfter == 36 && $fillBefore <= 0 || $dayCount == 28 && $fillAfter == 1) {
             $fillAfter -= 1;
         }
     }
     $timestamp = $offsetModifier == 1 ? strtotime('next Monday') : strtotime('next Sunday');
     $daysOfTheWeek = [];
     for ($i = 0; $i < 7; $i++) {
         $daysOfTheWeek[] = date('D', $timestamp);
         $timestamp = strtotime('+1 day', $timestamp);
     }
     $monthNames = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
     $stmt = 'SELECT id, start_time, end_time FROM appointment WHERE MONTH(start_time) = ? AND boardroom = ?;';
     $appointments = Database::getInstance()->query($stmt, [$month, $boardroom])->results();
     $context = ['month' => $monthNames[$month], 'year' => $year, 'dayCount' => $dayCount, 'fillBefore' => $fillBefore, 'fillAfter' => $fillAfter, 'daysOfTheWeek' => $daysOfTheWeek, 'appointments' => $appointments, 'clock' => Config::get('calendar/clock')];
     return $context;
 }
Beispiel #3
0
 private function __construct()
 {
     try {
         $host = Config::get('mysql/host');
         $dbname = Config::get('mysql/dbname');
         $username = Config::get('mysql/user');
         $password = Config::get('mysql/pass');
         $errorMode = Config::get('mysql/error_mode');
         $this->pdo = new PDO("mysql:host={$host};dbname={$dbname}", $username, $password);
         switch ($errorMode) {
             case 1:
                 $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
                 break;
             case 2:
                 $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                 break;
             default:
                 $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
         }
         $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
     } catch (PDOException $e) {
         die($e->getMessage());
     }
 }
 public function getAction($id = null)
 {
     if (isset($id) && !empty($id)) {
         $appointment = $this->model()->getAppointment($id);
         if (!$appointment) {
             http_response_code(404);
             exit("No appointment was found by specified id");
         }
         $context = [];
         $creator = new Employee($appointment->employee_id);
         $context['creator'] = $creator->data();
         if ($appointment->employee_id == $this->employee->data()->id || $this->employee->hasPermission('admin')) {
             $context['rightToModify'] = true;
             $context['urlBase'] = URL_BASE;
         }
         $context['token'] = Token::generate();
         $context['values'] = $appointment;
         $context['clock'] = Config::get('calendar/clock');
         echo $this->view('reservation/get', $context);
     } else {
         http_response_code(404);
         exit("Dude, I think you're lost");
     }
 }
Beispiel #5
0
if (Config::get('general/environment') == 'development') {
    /**
     *
     * Nice looking and informative error reporting
     *
     **/
    $whoops = new Run();
    $whoops->pushHandler(new PrettyPageHandler());
    $whoops->register();
} else {
    ini_set("display_errors", 0);
}
$loader = new Twig_Loader_Filesystem(APP . 'view');
$options = ['cache' => APP . 'storage/twig', 'auto_reload' => true];
$twig = new Twig_Environment($loader, $options);
header('Content-Type: text/html; charset=UTF-8');
/**
*
* "Remember me" functionality for login system
*
**/
$rememberCookieExists = Cookie::exists(Config::get('cookie_to_remember_employee_session/name'));
$employeeSessionExists = Session::exists(Config::get('session/name'));
if ($rememberCookieExists === true && $employeeSessionExists === false) {
    $hash = Cookie::get(Config::get('cookie_to_remember_employee_session/name'));
    $hashCheck = Database::getInstance()->get('employee_session', ['hash', '=', $hash]);
    if ($hashCheck->count()) {
        $employee = new Employee($hashCheck->first()->employee_id);
        $employee->login();
    }
}
Beispiel #6
0
 public function validateNewPasswordLink($id, $code)
 {
     $employee = new Employee($id);
     $timestamp = substr($code, -10);
     $expirationTime = Config::get('email_code/exptime');
     $timeCheck = $timestamp + $expirationTime >= time();
     if ($timeCheck === true) {
         if ($code === $employee->data()->email_code) {
             // View here
             return true;
         } else {
             exit('Your code either doesn\'t match the one in a database or has already been used.');
         }
     } else {
         exit('The link is expired');
     }
 }
Beispiel #7
0
 public function pickadatePrepTime($time)
 {
     if (!empty($time) && Config::get('calendar/clock') == '12') {
         return date('h:i A', strtotime($time));
     } else {
         return $time;
     }
 }