<?php

$action_readonly = false;

if (!empty($_SESSION['user_id']) && empty($$class->employee_id)) {
 $user_details = ino_user::find_by_id($_SESSION['user_id']);
 $$class->hr_employee_id = $user_details->hr_employee_id;
}

if (!empty($$class->hr_employee_id)) {
 $emp_details = hr_employee::find_by_id($$class->hr_employee_id);
 $$class->identification_id = $emp_details->identification_id;
 $$class->employee_name = $emp_details->first_name . ' ' . $emp_details->last_name;
 if (empty($$class->approver_employee_id)) {
  $employee_details = hr_employee::find_by_id($$class->hr_employee_id);
  $$class->approver_employee_id = $employee_details->supervisor_employee_id;
 }
}

if (!empty($$class->approver_employee_id)) {
 $supr_employee_details = hr_employee::find_by_id($$class->approver_employee_id);
 if ($supr_employee_details) {
  $$class->approver_employee_name = $supr_employee_details->first_name . ' ' . $supr_employee_details->last_name;
 }
}


if (empty($$class->hr_timesheet_header_id)) {
 if (empty($$class->entered_on)) {
  $$class->entered_on = current_time(true);
 }
 if (empty($$class->status)) {
  $$class->status = 'ENTERED';
 }

 if (empty($_GET['hr_timesheet_period_id'])) {
  $first_monday = new DateTime("monday this week");
  $ts_per = hr_timesheet_period::find_by_fromDate($first_monday->format('Y-m-d'));
  if ($ts_per) {
   $$class->hr_timesheet_period_id = $ts_per->hr_timesheet_period_id;
  }
 } else {
  $ts_per = hr_timesheet_period::find_by_id($_GET['hr_timesheet_period_id']);
  $$class->hr_timesheet_period_id = !empty($ts_per->hr_timesheet_period_id )? $ts_per->hr_timesheet_period_id  : '';
 }
} else {
 $ts_per = hr_timesheet_period::find_by_id($$class->hr_timesheet_period_id);
}

if (!empty($ts_per)) {
 $day = new DateTime($ts_per->from_date);
 for ($i = 1; $i <= 7; $i++) {
  $day_i = 'day' . $i;
  $$day_i = $day->format('d - M (D)');
  $day->add(new DateInterval('P1D'));
 }
} else {
 
 for ($i = 1; $i <= 7; $i++) {
  $day_i = 'day' . $i;
  $$day_i = 'Day ' . $i;
 }
}


if ((!empty($$class->status)) && (!in_array($$class->status, ['ENTERED', 'APPR_HOLD']))) {
 $mode = 2;
 $readonly = 1;
}
?>