Пример #1
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;
     }
 }
Пример #2
0
 function genSetNewBatch()
 {
     $this->db = Staple_DB::get();
     $user = new userModel();
     $userId = $user->getId();
     $oldKey = $user->getBatchId();
     $key = sha1(time() . $user->getUsername() . rand(999, 9999999999.0));
     //Check if key exists
     $sql = "SELECT id FROM accounts WHERE batchId = '" . $this->db->real_escape_string($key) . "'";
     if ($this->db->query($sql)->fetch_row() > 0) {
         //Key already in use
         return false;
     } else {
         //Set new key in user account
         $sql = "UPDATE accounts SET batchId='" . $this->db->real_escape_string($key) . "' WHERE id={$userId}";
         if ($this->db->query($sql)) {
             //Log Audit
             $audit = new auditModel();
             $audit->setAction('Timesheet Validation');
             $audit->setUserId($userId);
             $audit->setItem('Batch: ' . $oldKey);
             $audit->save();
             return true;
         } else {
             return false;
         }
     }
 }
Пример #3
0
 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();
     }
 }