grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026start_date = $start_date; $this->end_date = $end_date; $this->tasks = $tasks; //draw the grid $this->draw($this->start_date, $this->end_date, $this->tasks); } public function draw($start_date, $end_date, $tasks) { $day_count = $this->count_days($start_date, $end_date); $diff_interval = 30 - $day_count; if ($diff_interval <= 0) { $time_span = $this->year_month($start_date, $end_date); } else { $time_span = $this->year_month($start_date, $end_date, $diff_interval); } // $project_length = $this->time_range($start_date, $end_date); //Generate main table and the first row containing the months echo ''; foreach ($time_span as $months) { foreach ($months as $month => $days) { echo ''; } } //end the month row and start the days row echo ''; $month_count = 0;//start month count foreach ($time_span as $months) { $m=0; foreach ($months as $days) { echo '';//end table containing the days in each month $m++; } $month_count += $m; //total month count } //for each task generate a row of empty days $i=1; if (!is_null($tasks)) { foreach ($tasks as $task) { echo ''; echo ''; $i++; } } echo '
'.$month.'
'; //Generate a table containing the days in each month echo ''; foreach ($days as $day => $d) { echo '';//day number shown } echo ''; foreach ($days as $d) { echo '';//First letter of the days name shown } echo '
'.$day.'
'.$this->substr_unicode($d, 0, 1).'
'; $task_start_day = $this->count_days($start_date, $task->date_start); $task_end_day = $this->count_days($start_date, $task->date_finish); $task_duration = $this->count_days($task->date_start, $task->date_finish); $task->predecessors = $task->predecessors == '' ? 0 : $task->predecessors; for ($x=1; $x<= $day_count; $x++) { if ($x==1 && $x != $task_start_day) { echo ''; } else { if ($x==1 && $x == $task_start_day) { if ($task->milestone_flag == '1' && ($task_duration == 0 || $task_duration == 1)) { echo ''; } else { if ($task_duration == 0 || $task_duration == 1) { echo ''; } else { echo ''; } } } else { if ($x == $task_start_day && $x == $day_count) { if ($task->milestone_flag == '1' && ($task_duration == 0 || $task_duration == 1)) { echo ''; } else { if ($task_duration == 0 || $task_duration == 1) { echo ''; } else { echo ''; } } } else { if ($x == $task_start_day) { if ($task->milestone_flag == '1' && ($task_duration == 0 || $task_duration == 1)) { echo ''; } else { if ($task_duration == 0 || $task_duration == 1) { echo ''; } else { echo ''; } } } else { if ($x == $day_count) { } else { if ($x > $task_start_day && $x < $task_end_day) { //leave blank } else { echo ''; } } } } } } } echo '
'; } //Returns an array containing the years, months and days between two dates public function year_month($start_date, $end_date, $diff_interval=1) { $begin = new DateTime($start_date); $end = new DateTime($end_date); $end->add(new DateInterval('P'. $diff_interval .'D')); //Add 1 day to include the end date as a day $interval = new DateInterval('P1D'); // 1 month interval $period = new DatePeriod($begin, $interval, $end); $aResult = array(); foreach ($period as $dt) { $y = $dt->format('Y'); $m = $GLOBALS['app_list_strings']['dom_cal_month_short'][$dt->format('n')]; $j = $dt->format('j'); $d = $GLOBALS['app_list_strings']['dom_cal_day_short'][$dt->format('w')+1]; $aResult[$y][$m][$j] = $d; } return $aResult; } //Returns the total number of days between two dates public function count_days($start_date, $end_date) { $d1 = new DateTime($start_date); $d2 = new DateTime($end_date); //If the task's end date is before chart's start date return 1 to make sure task starts on first day of the chart if ($d2 < $d1) { return 1; } $d2->add(new DateInterval('P1D')); //Add 1 day to include the end date as a day $difference = $d1->diff($d2); return $difference->days; } //Returns the time span between two dates in years months and days public function time_range($start_date, $end_date) { $datetime1 = new DateTime($start_date); $datetime2 = new DateTime($end_date); $datetime2->add(new DateInterval('P1D')); //Add 1 day to include the end date as a day $interval = $datetime1->diff($datetime2); return $interval->format('%y years %m months and %d days'); } public function substr_unicode($str, $s, $l = null) { return join("", array_slice( preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY), $s, $l )); } // Function for basic field validation (present and neither empty nor only white space public function IsNullOrEmptyString($question) { return (!isset($question) || trim($question)===''); } }