Exemple #1
0
 /**
  * @throws ProjectIDMissingException
  * @throws ProjectSecuriyAccessDeniedException
  */
 public static function gantt_view()
 {
     global $project_security;
     if ($_GET['project_id']) {
         if ($project_security->is_access(1, false) == true) {
             $project_task_array = ProjectTask::list_tasks($_GET['project_id']);
             $left_limit = 0;
             $right_limit = 0;
             if (is_array($project_task_array) and count($project_task_array) >= 1) {
                 foreach ($project_task_array as $key => $value) {
                     $project_task = new ProjectTask($value);
                     if ($project_task->get_start_date()) {
                         $begin_timestamp = $project_task->get_start_date() . " 00:00:00";
                         if ($project_task->get_uf_end_time() != "-1") {
                             $end_timestamp = $project_task->get_end_date() . " " . $project_task->get_end_time();
                         } else {
                             $end_timestamp = $project_task->get_end_date() . " 00:00:00";
                         }
                         $begin_datetime_handler = new DatetimeHandler($begin_timestamp);
                         $end_datetime_handler = new DatetimeHandler($end_timestamp);
                         $begin_mktime = $begin_datetime_handler->get_mktime();
                         $end_mktime = $end_datetime_handler->get_mktime();
                         if ($left_limit == 0 or $left_limit > $begin_mktime) {
                             $left_limit = $begin_mktime;
                         }
                         if ($right_limit == 0 or $right_limit < $end_mktime) {
                             $right_limit = $end_mktime;
                         }
                     }
                 }
                 $left_limit_handler = new DatetimeHandler($left_limit);
                 $right_limit_handler = new DatetimeHandler($right_limit);
                 $day_distance = $left_limit_handler->day_distance($right_limit_handler);
                 $date_range = $right_limit - $left_limit;
                 if ($day_distance < 30) {
                     if ($day_distance < 15) {
                         if ($day_distance < 7) {
                             $date_range_addition = ceil($date_range / ($day_distance * 4));
                             $date_mktime = $left_limit;
                             $number_of_rows = $day_distance * 4 + 4;
                         } else {
                             $date_range_addition = ceil($date_range / ($day_distance * 2));
                             $date_mktime = $left_limit;
                             $number_of_rows = $day_distance * 2 + 2;
                         }
                     } else {
                         $date_range_addition = ceil($date_range / $day_distance);
                         $date_mktime = $left_limit;
                         $number_of_rows = $day_distance + 1;
                     }
                 } else {
                     $date_range_addition = ceil($date_range / 29);
                     $date_mktime = $left_limit;
                     $number_of_rows = 30;
                 }
                 $width_of_row = 705 / $number_of_rows;
                 $gantt_array = array();
                 for ($i = 0; $i <= $number_of_rows - 1; $i++) {
                     $day = date("d", $date_mktime);
                     $month = date("M", $date_mktime);
                     $gantt_array[$i]['title'] = $day . "<br />" . $month;
                     $gantt_array[$i]['mktime'] = $date_mktime;
                     $date_mktime = $date_mktime + $date_range_addition;
                 }
                 $template = new HTMLTemplate("project/tasks/gantt_view.html");
                 $table_view_paramquery = $_GET;
                 $table_view_paramquery['show'] = "table";
                 $table_view_params = http_build_query($table_view_paramquery, '', '&#38;');
                 $template->set_var("table_view_params", $table_view_params);
                 $gantt_view_paramquery = $_GET;
                 $gantt_view_paramquery['show'] = "gantt";
                 $gantt_view_params = http_build_query($gantt_view_paramquery, '', '&#38;');
                 $template->set_var("gantt_view_params", $gantt_view_params);
                 $cal_view_paramquery = $_GET;
                 $cal_view_paramquery['show'] = "cal";
                 $cal_view_params = http_build_query($cal_view_paramquery, '', '&#38;');
                 $template->set_var("cal_view_params", $cal_view_params);
                 $table = "<table class='ProjectTaskGanttTable'>";
                 $table .= "<tr>";
                 foreach ($gantt_array as $key => $value) {
                     $table .= "<th width='" . $width_of_row . "px'>" . $value['title'] . "</th>";
                 }
                 $table .= "</tr>";
                 foreach ($project_task_array as $key => $value) {
                     $project_task = new ProjectTask($value);
                     $begin_timestamp = $project_task->get_start_date() . " 00:00:00";
                     if ($project_task->get_uf_end_time() != "-1") {
                         $end_timestamp = $project_task->get_end_date() . " " . $project_task->get_end_time();
                     } else {
                         $end_timestamp = $project_task->get_end_date() . " 23:59:59";
                     }
                     $begin_datetime_handler = new DatetimeHandler($begin_timestamp);
                     $end_datetime_handler = new DatetimeHandler($end_timestamp);
                     $begin_mktime = $begin_datetime_handler->get_mktime();
                     $end_mktime = $end_datetime_handler->get_mktime();
                     $table .= "<tr>";
                     $paramquery = $_GET;
                     $paramquery['run'] = "task_detail";
                     $paramquery['id'] = $value;
                     $params = http_build_query($paramquery, '', '&#38;');
                     $table .= "<td colspan='30'><span class='smallText'><a href='index.php?" . $params . "'>" . $project_task->get_name() . " (" . $begin_datetime_handler->get_formatted_string("j/n/Y") . " - " . $end_datetime_handler->get_formatted_string("j/n/Y") . ")</a></span></td>";
                     $table .= "</tr><tr class='ProjectTaskGanttBlockEnd'>";
                     $begin_key = -1;
                     $end_key = -1;
                     foreach ($gantt_array as $fe_key => $fe_value) {
                         if ($fe_value['mktime'] >= $begin_mktime) {
                             if ($begin_key == -1) {
                                 $begin_key = $fe_key;
                             }
                         }
                         if ($begin_key != -1 and $fe_value['mktime'] <= $end_mktime) {
                             $end_key = $fe_key;
                         }
                     }
                     $key_range = $end_key - $begin_key + 1;
                     $in_task = false;
                     for ($i = 0; $i <= $number_of_rows - 1; $i++) {
                         if ($i == $begin_key) {
                             $in_task = true;
                             $width = $key_range * ($width_of_row + 1);
                             if ($project_task->get_type() == 3) {
                                 $table .= "<td colspan='" . $key_range . "' style='text-align: center;'><img src='images/icons/milestone.png' alt='' /></td>";
                             } else {
                                 $table .= "<td colspan='" . $key_range . "'><img src='core/images/status_bar.php?length=" . $width . "&height=15&linecolor=A0A0A0&bgcolor=EAEAEA&color=" . $project_task->get_color() . "&value=" . $project_task->get_progress() . "' /></td>";
                             }
                         }
                         if ($in_task == false) {
                             $table .= "<td></td>";
                         }
                         if ($i == $end_key) {
                             $in_task = false;
                         }
                     }
                     $table .= "</tr>";
                 }
                 $table .= "</table>";
                 $template->set_var("table", $table);
                 $template->output();
             } else {
                 $template = new HTMLTemplate("project/tasks/gantt_view.html");
                 $table_view_paramquery = $_GET;
                 $table_view_paramquery['show'] = "table";
                 $table_view_params = http_build_query($table_view_paramquery, '', '&#38;');
                 $template->set_var("table_view_params", $table_view_params);
                 $gantt_view_paramquery = $_GET;
                 $gantt_view_paramquery['show'] = "gantt";
                 $gantt_view_params = http_build_query($gantt_view_paramquery, '', '&#38;');
                 $template->set_var("gantt_view_params", $gantt_view_params);
                 $cal_view_paramquery = $_GET;
                 $cal_view_paramquery['show'] = "cal";
                 $cal_view_params = http_build_query($cal_view_paramquery, '', '&#38;');
                 $template->set_var("cal_view_params", $cal_view_params);
                 $template->set_var("table", "<span class='italic'>No Entries Found</span>");
                 $template->output();
             }
         } else {
             throw new ProjectSecuriyAccessDeniedException();
         }
     } else {
         throw new ProjectIDMissingException();
     }
 }