Exemplo n.º 1
0
 public function __construct($id = 0, $employees_id = 0, $period = null, $include_activities = true, $sort_order = 'timesheets_start_date desc')
 {
     $database = $_SESSION['database'];
     $this->id = $id;
     $this->activities = array();
     $this->listing = array();
     if ($this->id != 0) {
         // Retrieve timesheet by id
         $this->id = $database->prepare_input($this->id);
         $timesheet_query = $database->query("select timesheets_id, timesheets_start_date, timesheets_end_date, timesheets_locked, employees_id from " . TABLE_TIMESHEETS . " where timesheets_id = '" . (int) $this->id . "'");
     } else {
         if ($employees_id != 0 && tep_not_null($period)) {
             // Timesheet might exist but we do not know the id
             // Try to retrieve the timesheet for the given employee and period
             $this->employees_id = $database->prepare_input($employees_id);
             $this->start_date = $database->prepare_input(tep_periodstartdate($period));
             $timesheet_query = $database->query("select timesheets_id, timesheets_start_date, timesheets_end_date, timesheets_locked, employees_id from " . TABLE_TIMESHEETS . " where employees_id = '" . (int) $this->employees_id . "' and timesheets_start_date = '" . $this->start_date . "'");
         } else {
             // We probably created an empty timesheet object to retrieve the entire timesheet listing for a given employee
             $this->listing = $this->get_array($employees_id, $sort_order);
             // When timesheets_id == 0, $sort_order determines the timesheet listing
         }
     }
     if ($this->id != 0 || $employees_id != 0 && tep_not_null($period)) {
         $timesheet_result = $database->fetch_array($timesheet_query);
         if (tep_not_null($timesheet_result)) {
             // Timesheet exists
             $this->id = $timesheet_result['timesheets_id'];
             $this->fill($timesheet_result['timesheets_start_date'], $timesheet_result['timesheets_end_date'], $timesheet_result['timesheets_locked'] == 1, $timesheet_result['employees_id']);
             // Retrieve all activities for this timesheet (if any exist)
             if ($include_activities) {
                 $this->activities = activity::get_array($this->id, $sort_order);
                 // When timesheets_id != 0 / employees_id and period are set, $sort_order determines the activity listing
             }
         } else {
             // Timesheet does not exist, fill a new one with the given values
             $this->fill(tep_periodstartdate($period), tep_periodenddate($period), false, $employees_id);
         }
     }
 }