public function logout()
 {
     $auth = Staple_Auth::get();
     $auth->clearAuth();
     header('Location: ' . $this->_link(array('account', 'index')));
     exit(0);
 }
Example #2
0
 function getStaffIds($inactive = null)
 {
     $auth = Staple_Auth::get();
     $user = new userModel($auth->getAuthId());
     $userId = $user->getId();
     $authLevel = $user->getAuthLevel();
     $data = array();
     if ($authLevel >= 900) {
         if ($inactive == 1) {
             $sql = "\n                SELECT id, firstName, lastName FROM accounts WHERE status = 0 ORDER BY lastName ASC\n                ";
         } else {
             $sql = "\n                SELECT id, firstName, lastName FROM accounts WHERE status = 1 ORDER BY lastName ASC\n                ";
         }
     } else {
         if ($inactive == 1) {
             $sql = "\n                SELECT id, firstName, lastName FROM accounts WHERE status = 0 AND supervisorId = '" . $this->db->real_escape_string($userId) . "' ORDER BY lastName ASC\n                ";
         } else {
             $sql = "\n                SELECT id, firstName, lastName FROM accounts WHERE status = 1 AND supervisorId = '" . $this->db->real_escape_string($userId) . "' ORDER BY lastName ASC\n                ";
         }
     }
     $query = $this->db->query($sql);
     while ($result = $query->fetch_assoc()) {
         $data[$result['id']] = $result['lastName'] . ", " . $result['firstName'];
     }
     return $data;
 }
 public function _start()
 {
     $auth = Staple_Auth::get();
     $this->authLevel = $auth->getAuthLevel();
     if ($this->authLevel < 500) {
         header("location:" . $this->_link(array('index', 'index')) . "");
     }
 }
Example #4
0
 function allCodes()
 {
     $auth = Staple_Auth::get();
     $uid = $auth->getAuthId();
     $user = new userModel();
     $user->userInfo($uid);
     $type = $user->getType();
     if ($type == 'part') {
         $sql = "SELECT id, name FROM timeCodes WHERE type = 'part' ORDER BY listOrder ASC";
     } else {
         $sql = "SELECT id, name FROM timeCodes WHERE 1 ORDER BY listOrder ASC";
     }
     if ($this->db->query($sql)->fetch_row() > 0) {
         $query = $this->db->query($sql);
         while ($result = $query->fetch_assoc()) {
             $data[$result['id']] = $result['name'];
         }
         return $data;
     }
 }
Example #5
0
 public function _start()
 {
     $auth = Staple_Auth::get();
     $user = new userModel();
     $user->userInfo($auth->getAuthId());
     $this->accountLevel = $user->getAuthLevel();
     $this->setLayout('insertFormLayout');
     $this->setName('insertTimeForm')->setAction($this->link(array('timesheet')));
     $date = new Staple_Form_FoundationTextElement('date', 'Date');
     $date->setRequired()->addValidator(new Staple_Form_Validate_Date())->addAttrib('placeholder', 'mm/dd/yyyy');
     $inTime = new Staple_Form_FoundationTextElement('inTime', 'Time In');
     $inTime->setRequired()->addFilter(new Staple_Form_Filter_Trim())->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/', 'Invalid time format. Expected format: h:mm am/pm.'))->addAttrib('placeholder', 'h:mm am/pm');
     $outTime = new Staple_Form_FoundationTextElement('outTime', 'Time Out');
     $outTime->setRequired()->addFilter(new Staple_Form_Filter_Trim())->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/', 'Invalid time format. Expected format: h:mm am/pm.'))->addAttrib('placeholder', 'h:mm am/pm');
     $lessTime = new Staple_Form_FoundationSelectElement('lessTime', 'Less Time');
     $lessTime->setRequired()->addOptionsArray(array("0" => "None", "60" => "1 Hour", "30" => "30 Minutes"))->addValidator(new Staple_Form_Validate_InArray(array('0', '60', '30')));
     $timeCodes = new codeModel();
     $code = new Staple_Form_FoundationSelectElement('code', 'Code');
     $code->setRequired()->addOption("x", "Select an option")->addOptionsArray($timeCodes->allCodes())->addValidator(new Staple_Form_Validate_InArray(array_keys($timeCodes->allCodes())));
     $code->setValue($timeCodes->getIdFor('Normal')['id']);
     $submit = new Staple_Form_FoundationSubmitElement('submit', 'Submit');
     $submit->addClass('button expand radius');
     $this->addField($date, $inTime, $outTime, $lessTime, $code, $submit);
 }
Example #6
0
 function validated($id, $uid = null)
 {
     if ($uid == null) {
         $auth = Staple_Auth::get();
         $user = new userModel($auth->getAuthId());
         $userId = $user->getId();
         $batchId = $user->getBatchId();
     } else {
         $user = new userModel();
         $info = $user->userInfo($uid);
         $userId = $info['id'];
         $batchId = $info['batchId'];
     }
     $sql = "SELECT id FROM timeEntries WHERE userId = '" . $this->db->real_escape_string($userId) . "' AND batchId = '" . $this->db->real_escape_string($batchId) . "' AND id = '" . $this->db->real_escape_string($id) . "'";
     if ($this->db->query($sql)->num_rows > 0) {
         return true;
     } else {
         return false;
     }
 }
Example #7
0
 function __construct()
 {
     $this->db = Staple_DB::get();
     $auth = Staple_Auth::get();
     $username = $auth->getAuthId();
     $sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId, type FROM accounts WHERE username = '******'";
     if ($this->db->query($sql)->fetch_row() > 0) {
         $query = $this->db->query($sql);
         $result = $query->fetch_assoc();
         $this->setid($result['id']);
         $this->setUsername($result['username']);
         $this->setFirstName($result['firstName']);
         $this->setLastName($result['lastName']);
         $this->setAuthLevel($result['authLevel']);
         $this->setBatchId($result['batchId']);
         $this->setSupervisorId($result['supervisorId']);
         $this->setType($result['type']);
     } else {
         return false;
     }
 }
 public function validate($year, $month)
 {
     $timesheet = new timesheetModel($year, $month);
     //Get Current Batch ID
     $auth = Staple_Auth::get();
     $user = new userModel($auth->getAuthId());
     $batchId = $user->getBatchId();
     //Check for unvalidated entries within the current pay period.
     $i = 0;
     foreach ($timesheet->getEntries() as $entry) {
         if ($entry->inTimeRaw >= $timesheet->getStartDateTimeString() && $entry->inTimeRaw <= $timesheet->getEndDateTimeString()) {
             if ($entry->batchId == $timesheet->getBatch()) {
                 $i++;
             }
         }
     }
     if ($i > 0) {
         $this->view->timesheet = $timesheet;
         $form = new validateTimeSheetForm();
         $form->setAction($this->_link(array('timesheet', 'validate', $timesheet->getCurrentYear(), $timesheet->getCurrentMonth())));
         if ($form->wasSubmitted()) {
             if ($entry->inTimeRaw >= $timesheet->getStartDateTimeString() && $entry->inTimeRaw <= $timesheet->getEndDateTimeString()) {
                 $timesheet->validate($batchId);
                 header("location:" . $this->_link(array('timesheet')) . "");
             }
         } else {
             $this->view->form = $form;
             $this->view->needsValidation = false;
         }
     } else {
         $this->view->needsValidation = false;
         $this->view->timesheet = array();
     }
 }
 public function unlockid($id)
 {
     $auth = Staple_Auth::get();
     $this->authLevel = $auth->getAuthLevel();
     if ($this->authLevel < 900) {
         header("location:" . $this->_link(array('index', 'index')) . "");
     } else {
         $unlock = new unlockModel();
         if ($unlock->unlock($id)) {
             $this->view->message = "<i class='fa fa-check'></i> Time entry unlocked.";
         } else {
             $this->view->message = "<i class='fa fa-close'></i> ERROR: Unable to unlock your own time entries.";
         }
     }
 }
Example #10
0
 /**
  * Returns a boolean true or false whether the method requires authentication
  * before being dispatched from the front controller.
  * @param string $method
  * @return bool
  */
 public function _auth($method)
 {
     $method = (string) $method;
     if (!ctype_alnum($method)) {
         throw new Exception('Authentication Validation Error', Staple_Error::AUTH_ERROR);
     } else {
         if (method_exists($this, $method)) {
             //Is the controller completely open?
             if ($this->open === true) {
                 return true;
             } elseif (array_search($method, $this->openMethods) !== FALSE) {
                 return true;
             } elseif (Staple_Auth::get()->isAuthed() && Staple_Auth::get()->getAuthLevel() >= $this->_authLevel($method)) {
                 return true;
             }
         } else {
             throw new Exception('Authentication Validation Error', Staple_Error::AUTH_ERROR);
         }
     }
     return false;
 }
Example #11
0
 /**
  * 
  * Gets the singleton instance of the object. Checks the session to see if a current auth
  * object already exists. If not a new Auth object is created.
  * @return Staple_Auth
  */
 public static function get()
 {
     if (!self::$instance instanceof Staple_Auth) {
         if (array_key_exists('Staple', $_SESSION)) {
             if (array_key_exists('auth', $_SESSION['Staple'])) {
                 self::$instance = $_SESSION['Staple']['auth'];
             }
         }
         if (!self::$instance instanceof Staple_Auth) {
             self::$instance = new Staple_Auth();
         }
     }
     return self::$instance;
 }
Example #12
0
 function __construct()
 {
     $this->db = Staple_DB::get();
     $auth = Staple_Auth::get();
     $this->username = $auth->getAuthId();
 }