function importRecords() { $csvPath = APPLICATION_PATH . "/../data/imports.csv"; $contents = file_get_contents($csvPath); $lines = explode("\n", $contents); $i = 0; $recordsModel = new Records(); foreach ($lines as $line) { if ($i > 0) { $data = explode(",", $line); $substitutesModel = new Substitutes(); $substitute = $substitutesModel->getBySecondaryId($data[13]); $locationsModel = new Locations(); $location = $locationsModel->getByName($data[4]); $nameSegments = explode("|", $data[3]); $lastName = $nameSegments[0]; $firstName = $nameSegments[1]; $employeesModel = new Employees(); $employee = $employeesModel->getByName($firstName, $lastName); if ($data[9] == 'FALSE' || $data[9] == FALSE) { $leaveForm = 0; } else { $leaveForm = 1; } if (!$substitute) { $subid = '129'; } else { $subid = $substitute->id; } $recordData = array('date' => date('Y-m-d', strtotime($data[1])), 'employee' => @$employee->id, 'location' => @$location->id, 'substitute' => $subid, 'reason' => $data[6], 'notes' => $data[7], 'percent' => str_replace("%", "", $data[8]), 'leave_form' => $leaveForm, 'user' => 6, 'acct' => $data[14]); try { $recordsModel->insert($recordData); } catch (Exception $e) { echo $e->getMessage(); } print_r($recordData); } $i++; } }
public function lend() { $inputs = $this->input->post(); $bid = $inputs['bid']; // HARD CODE HERE $uid = $inputs['uid'] ? $insputs['uid'] : 2; $this->load->model('books'); $book = Books::findByIds($bid); if ($book->inventory > 0) { $book->inventory -= 1; $book->borrow_times += 1; $book->save(); $bt = time(); $due = $bt + 7 * 24 * 60 * 60; $bt = date("Y-m-d H:i:s", $bt); $due = date("Y-m-d H:i:s", $due); $data = array('user_id' => $uid, 'book_id' => $bid, 'book_name' => $book->name, 'borrow_time' => $bt, 'due' => $due, 'is_returned' => 0); $this->load->model('records'); Records::insert($data); echo "success"; } else { echo "failed"; } }
public function trackAction() { $locationsModel = new Locations(); $this->view->locations = $locationsModel->getAll(); $employeesModel = new Employees(); if ($this->_me->admin == 1) { $this->view->employees = $employeesModel->getAll(); } else { $this->view->employees = $employeesModel->getAllByLocation($this->_me->location); } $substitutesModel = new Substitutes(); if ($this->_me->admin == 1) { $this->view->substitutes = $substitutesModel->getAll(); } else { //$this->view->substitutes = $substitutesModel->getAllByLocation($this->_me->location); $this->view->substitutes = $substitutesModel->getAll(); } if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost(); if ($this->_me->admin == 1) { $emp = $employeesModel->getById($data['employee']); $data['location'] = $emp->location; } $data['user'] = $this->_me->id; $data['date_created'] = date('Y-m-d h:i:s', strtotime('now')); $start_day = date('l', strtotime($data['date'])); if ($start_day != 'Saturday' && $start_day != 'Sunday') { $days = $data['days']; unset($data['days']); // payrate $subs = $substitutesModel->getById($data['substitute']); if ($subs) { $data['payrate'] = $subs->payrate; } $recordsModel = new Records(); if ($recordsModel->insert($data)) { if ($days > 1) { $i = 1; $cnt_day = 0; $startdate = $data['date']; while ($i < $days) { $dayName = date('l', strtotime($startdate . " + {$i} days")); $c_day = 0; //omit weekends if ($dayName == 'Saturday') { // + 2 dias $cnt_day = 2; } if ($dayName == 'Sunday') { // + 1 dias $cnt_day = 2; } $c_day = $cnt_day + $i; $data['date'] = date('Y-m-d', strtotime($startdate . " + {$c_day} days")); $recordsModel->insert($data); $i++; } } $this->view->success = "Leave Record Saved."; } else { $this->view->error = "An Error Occurred."; } } else { $this->view->error = "Saturday and Sunday are not working days, please select other day."; } } }
function insert() { $this->records = array(array('id' => 1, 'username' => 'admin', 'password' => Security::hash('password', null, true), 'active' => 1, 'flagged' => 0, 'group_id' => 1, 'reset_password' => 1)); parent::insert(); }