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); }
function getAll($uid = null, $page, $items) { $pager = new Staple_Pager(); //Get total rows if ($uid == null) { $sql = "SELECT COUNT(id) as count FROM audit"; } else { $sql = "SELECT COUNT(id) as count FROM audit WHERE userId = '" . $this->db->real_escape_string($uid) . "'"; } $result = $this->db->query($sql)->fetch_assoc(); $total = $result['count']; $pager->setTotal($total); $pager->setItemsPerPage($items); $pager->setPage($page); if ($uid == null) { $sql = "\n SELECT * FROM audit ORDER BY timestamp DESC LIMIT " . $pager->getStartingItem() . ", " . $pager->getItemsPerPage() . "\n "; } else { $sql = "\n SELECT * FROM audit WHERE userId = '" . $this->db->real_escape_string($uid) . "' ORDER BY timestamp DESC LIMIT " . $pager->getStartingItem() . ", " . $pager->getItemsPerPage() . "\n "; } $this->pager = $pager; if ($this->db->query($sql)->num_rows > 0) { $query = $this->db->query($sql); $data = array(); $i = 0; while ($result = $query->fetch_assoc()) { $data[$i]['timestamp'] = $result['timestamp']; $account = new userModel(); $data[$i]['account'] = $account->userInfo($result['userId']); $data[$i]['action'] = $result['action']; $data[$i]['item'] = $result['item']; $i++; } return $data; } else { return array(); } }
function calculatedTotals($code, $startDate, $endDate, $uid = null) { //Get user ID from Auth $user = new userModel(); if ($uid == null) { $userId = $user->getId(); } else { $account = $user->userInfo($uid); $userId = $account['id']; } $sql = "SELECT codeId, inTime, outTime, lessTime FROM timeEntries WHERE inTime > UNIX_TIMESTAMP('{$startDate} 00:00:00') AND outTime < UNIX_TIMESTAMP('{$endDate} 23:59:59') AND userId = {$userId} AND codeId = {$code};"; if ($this->db->query($sql)->fetch_row() > 0) { $query = $this->db->query($sql); $total = 0; while ($result = $query->fetch_assoc()) { $inTime = $result['inTime']; $outTime = $result['outTime']; switch ($result['lessTime']) { case 60: $lessTime = 1; break; case 30: $lessTime = 0.5; break; case 15: $lessTime = 0.25; break; default: $lessTime = 0; } $roundedInTime = $this->nearestQuarterHour($inTime); $roundedOutTime = $this->nearestQuarterHour($outTime); $lapse = $roundedOutTime - $roundedInTime; $lapseHours = gmdate('H:i', $lapse); $decimalHours = $this->timeToDecimal($lapseHours); $total = $total + $decimalHours; $total = $total - $lessTime; $code = new codeModel(); $codeId = $code->getIdFor("Unpaid Leave"); if ($codeId['id'] == $result['codeId']) { $total = -1 * $total; } } return $total; } else { return 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; } }
function save() { if (isset($this->accountId) && isset($this->payPeriodYear) && isset($this->payPeriodMonth)) { //Get current users ID. $user = new userModel(); $supervisorId = $user->getId(); $supervisorName = $user->getUsername(); $sql = "INSERT INTO timesheetReview (accountId, payPeriodMonth, payPeriodYear, supervisorId) VALUES ('" . $this->db->real_escape_string($this->accountId) . "','" . $this->db->real_escape_string($this->payPeriodMonth) . "','" . $this->db->real_escape_string($this->payPeriodYear) . "','" . $this->db->real_escape_string($supervisorId) . "')"; if ($this->db->query($sql)) { $employeeUser = new userModel(); $details = $employeeUser->userInfo($this->accountId); $month = $this->payPeriodMonth; $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); $audit = new auditModel(); $audit->setUserId($this->accountId); $audit->setAction('Timesheet Review'); $audit->setItem($supervisorName . " reviewed " . $details['username'] . " timesheet for " . $monthName . " " . $this->payPeriodYear); $audit->save(); return true; } } }
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; } }
public function printpreview($id = null, $year = null, $month = null) { $this->_setLayout('print'); //Set year and month variables if undefined. if ($year == null) { $date = new DateTime(); $year = $date->format('Y'); } if ($month == null) { $date = new DateTime(); if ($date->format("j") >= 26) { $month = $date->modify('+1 month')->format('m'); } else { $month = $date->format('m'); } } //Load timesheet for user. $timesheet = new timesheetModel($year, $month); $user = new userModel(); $user->userInfo($this->userId); $this->view->firstName = $user->getFirstName(); $this->view->lastName = $user->getLastName(); $this->view->batchId = $user->getBatchId(); //Pass timesheet object to view if ($id == $this->userId) { $this->view->timesheet = $timesheet; } else { header("location: " . $this->_link(array('timesheet')) . ""); } }
function resetPin($id) { $pin = $this->generatePin(); $this->tempPin = $pin; $sql = "UPDATE accounts SET pin='" . $this->db->real_escape_string(sha1($pin)) . "' WHERE id = '" . $this->db->real_escape_string($id) . "'"; if ($this->db->query($sql)) { $account = new userModel(); $userInfo = $account->userInfo($id); $audit = new auditModel(); $audit->setUserId($userInfo['id']); $audit->setAction('PIN Reset'); $audit->setItem($account->getUsername() . " reset users PIN."); $audit->save(); return true; } }
public function printpreview($year, $month, $uid) { $this->_setLayout('print'); $user = new userModel(); $account = $user->userInfo($uid); $this->view->firstName = $account['firstName']; $this->view->lastName = $account['lastName']; $this->view->batchId = $account['batchId']; $this->view->year = $year; $this->view->month = date('F', $month); $timesheet = new timesheetModel($year, $month, $uid); $this->view->timesheet = $timesheet; }
function loadExpired() { $user = new userModel(); $uid = $user->getId(); $sql = "SELECT * FROM privateMessages WHERE sentId = '" . $this->db->real_escape_string($uid) . "' AND expireDate <= CURRENT_TIMESTAMP ORDER BY postDate DESC"; $query = $this->db->query($sql); $data = array(); while ($row = $query->fetch_assoc()) { $message = array(); $message['id'] = $row['id']; $message['message'] = $row['message']; $message['expireDate'] = $row['expireDate']; $message['postDate'] = $row['postDate']; $user = new userModel(); $message['sendId'] = $user->getUsername(); $sentTo = $user->userInfo($row['userId']); $message['sentTo'] = $sentTo['firstName'] . " " . $sentTo['lastName']; $message['reviewDate'] = $row['reviewDate']; $message['reviewed'] = $row['reviewed']; $data[] = $message; } return $data; }