123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- class timesheetController extends Staple_Controller
- {
- public function _start()
- {
- }
- public function index($year = null, $month = null)
- {
- //Typecast variables
- $month = (int) $month;
- $year = (int) $year;
- //Build new insert form
- $form = new insertTimeForm();
- //Check for form submission
- if($form->wasSubmitted())
- {
- //Add submitted data to the form
- $form->addData($_POST);
- //Check form validation
- if($form->validate())
- {
- //Export form data into an array
- $data = $form->exportFormData();
- //Compare in Times and out Times.
- if(strtotime($data['inTime']) < strtotime($data['outTime']))
- {
- //Create a new entry object
- $entry = new timeEntryModel();
- $entry->setDate($data['date']);
- $entry->setInTime($data['inTime']);
- $entry->setOutTime($data['outTime']);
- $entry->setLessTime($data['lessTime']);
- $entry->setCodeId($data['code']);
- if($entry->save())
- {
- $this->view->message = "Entry saved.";
- $form = new insertTimeForm();
- $this->view->insertTimeForm = $form;
- }
- else
- {
- $this->view->message = "ERROR: Unable to save entry.";
- $this->view->insertTimeForm = $form;
- }
- }
- else
- {
- //Send form with error message back.
- $form->message = array("<b>'Time In'</b> entry cannot be before <b>'Time Out'</b> entry.");
- $this->view->insertTimeForm = $form;
- }
- }
- else
- {
- $this->view->insertTimeForm = $form;
- }
- }
- else
- {
- $this->view->insertTimeForm = $form;
- }
- //Set year and month variables if undefined.
- if($year == null)
- {
- $date = new DateTime();
- $year = $date->format('Y');
- }
- if($month == null)
- {
- $date = new DateTime();
- $month = $date->format('m');
- }
- //Load timesheet for user.
- $timesheet = new timesheetModel($year,$month);
- //Pass timesheet object to view
- $this->view->timesheet = $timesheet;
- $changeYearForm = new changeYearForm();
- $this->view->changeYearForm = $changeYearForm;
- }
- public function remove($id)
- {
- if($id != null)
- {
- //Confirm entry for user
- $timesheet = new timesheetModel();
- if($timesheet->exists($id))
- {
- //Delete Item
- if($timesheet->remove($id))
- {
- $this->view->message = "Entry removed.";
- }
- else
- {
- $this->view->message = "ERROR: Could not remove entry.";
- }
- }
- else
- {
- header("location: ".$this->_link(array('timesheet'))."");
- }
- }
- else
- {
- header("location: ".$this->_link(array('timesheet'))."");
- }
- }
- public function edit($id = null)
- {
- if($id != null)
- {
- $entry = new timeEntryModel($id);
- if($entry)
- {
- $form = new editTimeForm();
- $form->setAction($this->_link(array('timesheet','edit',$id)));
- //$form->addData();
- $this->view->form = $form;
- }
- else
- {
- echo "Entry loaded";
- //header("location: ".$this->_link(array('timesheet'))."");
- }
- }
- else
- {
- echo "ERROR: Unable to load entry";
- //header("location: ".$this->_link(array('timesheet'))."");
- }
- }
- public function changeyear()
- {
- $form = new changeYearForm();
- if($form->wasSubmitted())
- {
- $form->addData($_POST);
- if($form->validate())
- {
- $data = $form->exportFormData();
- header("location: ".$this->_link(array('timesheet',$data['year']))."");
- }
- else
- {
- header("location: ".$this->_link(array('timesheet'))."");
- }
- }
- else
- {
- header("location: ".$this->_link(array('timesheet'))."");
- }
- }
- public function validate($year, $month)
- {
- $timesheet = new timesheetModel($year,$month);
- echo $timesheet->getStartDateTimeString();
- //Get Current Batch ID
- $auth = Staple_Auth::get();
- $user = new userModel($auth->getAuthId());
- $batchId = $user->getBatchId();
- $this->view->timesheet = $timesheet;
- }
- }
- ?>
|