grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026start_date = $start_date; $this->end_date = $end_date; $this->tasks = $tasks; $this->projects = $projects; $this->users = $users; $this->contacts = $contacts; $this->chart_type = $chart_type; //draw the grid $this->draw($this->start_date, $this->end_date, $this->projects, $this->users, $this->contacts, $this->tasks, $this->chart_type); } public function draw($start_date, $end_date, $sel_projects, $sel_users, $sel_contacts, $resources, $chart_type) { global $current_user, $mod_strings; $db = DBManagerFactory::getInstance(); if ($chart_type == "monthly") { list($time_span, $day_count) = $this->year_week($start_date, $end_date); } else { if ($chart_type == "quarterly") { list($time_span, $day_count) = $this->year_quarter($start_date, $end_date); } else { $time_span = $this->year_month($start_date, $end_date); $day_count = $this->count_days($start_date, $end_date) + 1; } } $weeks = $this->get_weeks($start_date, $end_date); //Get projects. This is for the Select box values $projects_query = "SELECT DISTINCT id, name FROM project WHERE deleted =0"; $projects_list = $db->query($projects_query); $project_list = array(); while ($row = $db->fetchByAssoc($projects_list)) { //create array of user objects $project_list[] = (object)$row; } //Get users that are associated to any project. This is for the Select box values $users_query = "SELECT DISTINCT project_users_1users_idb AS id, first_name, last_name, 'project_users_1_c' AS type FROM project_users_1_c JOIN users ON users.id = project_users_1users_idb WHERE project_users_1_c.deleted =0"; $users_list = $db->query($users_query); $user_list = array(); while ($row = $db->fetchByAssoc($users_list)) { //create array of user objects $user_list[] = (object)$row; } //Get contacts that are associated to any project. This is for the Select box values $contacts_query = "SELECT DISTINCT project_contacts_1contacts_idb AS id, first_name, last_name, 'project_contacts_1_c' AS type FROM project_contacts_1_c JOIN contacts ON contacts.id = project_contacts_1contacts_idb WHERE project_contacts_1_c.deleted =0"; $contacts_list = $db->query($contacts_query); $contact_list = array(); while ($row = $db->fetchByAssoc($contacts_list)) { //create array of user objects $contact_list[] = (object)$row; } //Generate main table and the first row containing the months echo '

' . $mod_strings["LBL_RESOURCE_CHART"] . '

'; echo ''; echo ''; echo ''; echo '


'; if (empty($project_list)) { echo ''.$mod_strings['LBL_RESOURCE_CHART_WARNING'].'

'; } echo '


'; if (empty($user_list)) { echo ''.$mod_strings['LBL_RESOURCE_CHART_WARNING'].'

'; } echo '


'; if (empty($contact_list)) { echo ''.$mod_strings['LBL_RESOURCE_CHART_WARNING'].'

'; } echo '


'; echo '
 '.$mod_strings['LBL_RESOURCE_CHART_SEARCH_BUTTON'].'
'; echo ''; echo ''; //weekly view if ($chart_type == "weekly" || $chart_type == "") { echo ''; foreach ($weeks as $week) { echo ''; } echo ''; foreach ($time_span as $year => $months) { foreach ($months as $month => $days) {//count the number of days in each month $daycount=0; foreach ($days as $day) { $daycount++; } $width = $daycount * 26; //used to set width on years row. width needed for css text clipping echo ''; } } echo ''; $month_count = 0;//start month count foreach ($time_span as $year => $months) { foreach ($months as $days) { foreach ($days as $day => $d) { echo '';//day number shown } } } echo ''; foreach ($time_span as $year => $months) { foreach ($months as $days) { foreach ($days as $day => $d) { echo '';//First letter of the days name shown } } } echo ''; foreach ($resources as $resource) { $count = $resource->task_count; if ($resource->type == 'project_users_1_c') { $user_obj = new User(); $user_obj->retrieve($resource->id); echo ''; } else { if ($resource->type == 'project_contacts_1_c') { $contact_obj = new Contact(); $contact_obj->retrieve($resource->id); echo ''; } } $i=0; for ($x=0; $x< $day_count; $x++) { $dateq = $this->get_date($start_date, $i); $class = ''; if ($this->check_weekend($dateq) == 'today') { $class = 'today'; } elseif ($this->check_weekend($dateq) == 'weekend') { $class = 'weekend'; } elseif ($this->check_weekend($dateq) == 'weekend-today') { $class = 'weekend-today'; } $square = ''; $dup = 0; for ($c=0; $c < $count; $c++) { if ($x == $resource->tasks[$c]['start_day']) { $dup++; $square = ''; } else { if ($x > $resource->tasks[$c]['start_day'] && $x <= $resource->tasks[$c]['end_day']) { $dup++; $square = ''; } } } if ($square == '') { $square = ''; } echo $square; $i++; } } }//end weekly view else { if ($chart_type == "monthly") { echo ''; /*foreach ($weeks as $week) { echo ''; }*/ foreach ($time_span as $year => $months) { foreach ($months as $month => $weeks) {//count the number of days in each month echo ''; } } echo ''; foreach ($time_span as $year => $months) { $wcount= 0; foreach ($months as $month => $weeks) {//count the number of weeks in each month /*foreach ($weeks as $week) { $wcount++; }*/ $wcount+= count($weeks); } $width = $wcount * 26; //used to set width on years row. width needed for css text clipping echo ''; } echo ''; $month_count = 0;//start month count foreach ($time_span as $year => $months) { foreach ($months as $weeks) { foreach ($weeks as $week => $w) { echo '';//day number shown } } } echo ''; foreach ($time_span as $year => $months) { foreach ($months as $weeks) { foreach ($weeks as $week => $d) { echo '';//First letter of the days name shown } } } echo ''; foreach ($resources as $resource) { $count = $resource->task_count; if ($resource->type == 'project_users_1_c') { $user_obj = new User(); $user_obj->retrieve($resource->id); echo ''; } else { if ($resource->type == 'project_contacts_1_c') { $contact_obj = new Contact(); $contact_obj->retrieve($resource->id); echo ''; } } $i=0; for ($x=0; $x< $day_count; $x++) { //Get dates for each week $dateq = $this->get_week_dates($start_date, $x); $class = ''; $square = ''; $dup = 0; for ($c=0; $c < $count; $c++) { if ($x == floor($resource->tasks[$c]['start_day'] /7) && ($resource->tasks[$c]['start_day'] /7) > 0) { $dup++; $square = ''; } else { if ($x > floor($resource->tasks[$c]['start_day']/7) && $x <= floor($resource->tasks[$c]['end_day']/7)) { $dup++; $square = ''; } } } if ($square == '') { $square = ''; } echo $square; $i++; } } } //end monthly view else { if ($chart_type == "quarterly") { echo ''; foreach ($time_span as $year => $quarters) { foreach ($quarters as $quarter => $months) {//count the number of days in each month echo ''; } } echo ''; foreach ($time_span as $year => $quarters) { $qcount= 0; foreach ($quarters as $quarter => $months) {//count the number of months in each quarter $qcount+= count($months); } $width = $qcount * 26; //used to set width on years row. width needed for css text clipping echo ''; } echo ''; $month_count = 0;//start month count foreach ($time_span as $year => $quarters) { foreach ($quarters as $quarter) { foreach ($quarter as $month => $m) { echo '';//day number shown } } } echo ''; foreach ($time_span as $year => $quarters) { foreach ($quarters as $quarter) { foreach ($quarter as $month => $m) { echo '';//First letter of the days name shown } } } echo ''; foreach ($resources as $resource) { $count = $resource->task_count; if ($resource->type == 'project_users_1_c') { $user_obj = new User(); $user_obj->retrieve($resource->id); echo ''; } else { if ($resource->type == 'project_contacts_1_c') { $contact_obj = new Contact(); $contact_obj->retrieve($resource->id); echo ''; } } $i=0; for ($x=0; $x< $day_count; $x++) { //Get date for each day $dateq = $this->get_month_dates($start_date, $x); $class = ''; $square = ''; $dup = 0; for ($c=0; $c < $count; $c++) { $ds_month = $this->count_months($start_date, $resource->tasks[$c]['start_day'], $x); $de_month = $this->count_months($start_date, $resource->tasks[$c]['end_day'], $x); if (($ds_month == 0 || $de_month == 0) && $resource->tasks[$c]['start_day'] <= $resource->tasks[$c]['end_day'] && $resource->tasks[$c]['start_day'] >=0 && $resource->tasks[$c]['end_day']>=0) { $dup++; $square = ''; } } if ($square == '') { $square = ''; } echo $square; $i++; } } } } } //end quarterly view echo '
Previous Month '.$mod_strings['LBL_RESOURCE_CHART_PREVIOUS_MONTH'].' '.$mod_strings['LBL_RESOURCE_CHART'].' '.$mod_strings['LBL_RESOURCE_CHART_NEXT_MONTH'].' Next Month
'.$mod_strings['LBL_RESOURCE_CHART_WEEK'].''.$week.'
'.$mod_strings['LBL_RESOURCE_CHART_DAY'].'
'.$month.', '.$year.'
'.$day.'
'.$d.'
'.$user_obj->full_name.'
'.$contact_obj->full_name.'
'.$mod_strings['LBL_RESOURCE_CHART_MONTH'].''.$week.''.$month .'
'.$mod_strings['LBL_RESOURCE_CHART_WEEK'].'
' . $year.'
'.$w.'
'. ($week + 1) .'
'.$user_obj->full_name.'
'.$contact_obj->full_name.'
'.$mod_strings['LBL_RESOURCE_CHART_QUARTER'].''.$quarter .'
'.$mod_strings['LBL_RESOURCE_CHART_MONTH'].'
' . $year.'
'.$month.'
'. $m .'
'.$user_obj->full_name.'
'.$contact_obj->full_name.'
'; } //Returns an array containing the years, months and weeks between two dates public function year_quarter($start_date, $end_date) { $begin = new DateTime($start_date); $end = new DateTime($end_date); $end->add(new DateInterval('P1D')); //Add 1 day to include the end date as a day $interval = new DateInterval('P1M'); // 1 week interval $period = new DatePeriod($begin, $interval, $end); $aResult = array(); $count = 0; foreach ($period as $dt) { $count++; $y = $dt->format('Y'); $c = ceil($dt->format('m')/3); $m = mb_substr($GLOBALS['app_list_strings']['dom_cal_month_short'][$dt->format('n')], 0, 3); $aResult[$y][$c][$count] = $m; } return array($aResult, $count); } //Returns an array containing the years, months and weeks between two dates public function year_week($start_date, $end_date) { $begin = new DateTime($start_date); $end = new DateTime($end_date); $end->add(new DateInterval('P1D')); //Add 1 day to include the end date as a day $interval = new DateInterval('P1W'); // 1 week interval $period = new DatePeriod($begin, $interval, $end); $aResult = array(); $count = 0; foreach ($period as $dt) { $count++; $y = $dt->format('Y'); $m = $GLOBALS['app_list_strings']['dom_cal_month_short'][$dt->format('n')]; $w = $dt->format('W'); $aResult[$y][$m][] = $w; } return array($aResult, $count); } //Returns an array containing the years, months and days between two dates public function year_month($start_date, $end_date) { $begin = new DateTime($start_date); $end = new DateTime($end_date); $end->add(new DateInterval('P1D')); //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 = mb_substr($GLOBALS['app_list_strings']['dom_cal_month_short'][$dt->format('n')], 0, 3); $j = $dt->format('j'); $d = mb_substr($GLOBALS['app_list_strings']['dom_cal_day_short'][$dt->format('w')+1], 0, 1); $aResult[$y][$m][$j] = $d; } return $aResult; } public function get_weeks($start_date, $end_date) { $begin = new DateTime($start_date); $end = new DateTime($end_date); $end->add(new DateInterval('P1D')); //Add 1 day to include the end date as a day $interval = new DateInterval('P1W'); // 1 week interval $period = new DatePeriod($begin, $interval, $end); $aResult = array(); foreach ($period as $dt) { $aResult[] = $dt->format('W'); } return $aResult; } //count number of months between task start day and chart current month public function count_months($start, $day, $x) { $sdate = DateTime::createFromFormat('Y-m-d', $start); $edate = DateTime::createFromFormat('Y-m-d', $start); // $date->setTimezone(new DateTimeZone("Europe/London")); $sdate->modify('+'.$day.' days'); $edate->modify('+'.$x.' months'); if ($sdate->format('Y') != $edate->format('Y')) { return -1; } if ($sdate->format('m') != $edate->format('m')) { return -1; } else { return 0; } } //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; } else { 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 first and last date of a week public function get_week_dates($start, $weeks) { $date = DateTime::createFromFormat('Y-m-d', $start); $date->modify('+'.($weeks + 1).' weeks'); $ts = strtotime($date->format('Y-m-d')); $start = (date('w', $ts) == 0) ? $ts : strtotime('last monday', $ts); return date('Y-m-d', $start) . "|" . date('Y-m-d', strtotime('next sunday', $start)); } //returns first and last date of a month public function get_month_dates($start, $months) { $date = DateTime::createFromFormat('Y-m-d', $start); $date->modify('+'.($months).' months'); return $date->format('Y-m-01') . "|" . $date->format('Y-m-t'); } //get date of passed in day in relation to the charts start date public function get_date($start, $day) { $date = DateTime::createFromFormat('Y-m-d', $start); // $date->setTimezone(new DateTimeZone("Europe/London")); $date->modify('+'.$day.' days'); return $date->format('Y-m-d'); } //checks if the day is a weekend and if the day is today. public function check_weekend($day) { global $current_user; //get users timezone setting $timezone = TimeDate::userTimezone($current_user); $now = new DateTime(); $now->setTimezone(new DateTimeZone($timezone)); $date1 = DateTime::createFromFormat('Y-m-d', $day); $date = $date1->format('Y-m-d'); $now = $now->format('Y-m-d'); // $GLOBALS['log']->fatal("date2 ".$now); if ($date1->format('l') == 'Sunday' && $date == $now) { return 'weekend-today'; } else { if ($date1->format('l') == 'Saturday' && $date == $now) { return 'weekend-today'; } else { if ($date1->format('l') == 'Sunday') { return 'weekend'; } else { if ($date1->format('l') == 'Saturday') { return 'weekend'; } else { if ($date == $now) { return 'today'; } else { return false; } } } } } } //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); $interval = $datetime1->diff($datetime2); echo $interval->format('%y years %m months and %d days'); } //returns the css class for cell color/ h => non duplicate, d =>duplicate public function get_cell_class($days) { if ($days > 1) { return " d"; } else { return " h"; } } }