Exemple #1
0
 static function showTaskGantt($options = array())
 {
     global $gdata;
     $restrict = " `plugin_projet_projets_id` = '" . $options["plugin_projet_projets_id"] . "' ";
     if ($options["plugin_projet_tasks_id"]) {
         $restrict .= " AND `id` = '" . $options["plugin_projet_tasks_id"] . "' ";
     }
     $restrict .= " AND `is_deleted` = '0'";
     $restrict .= " AND `is_template` = '0'";
     $restrict .= " AND `show_gantt` = '1'";
     $tasks = getAllDatasFromTable("glpi_plugin_projet_tasks", $restrict);
     $prefix = $options["prefix"];
     if (!empty($tasks)) {
         foreach ($tasks as $task) {
             $prefix .= "-";
             //nom
             $gantt_t_name = $prefix . " " . $task["name"];
             //color
             $int = hexdec(PluginProjetTaskState::getStatusColor($task["plugin_projet_taskstates_id"]));
             $gantt_t_bgcolor = array(0xff & $int >> 0x10, 0xff & $int >> 0x8, 0xff & $int);
             $projet = new PluginProjetProjet();
             if ($projet->getFromDB($options["plugin_projet_projets_id"])) {
                 $gantt_t_date_begin = $projet->fields["date_begin"];
                 $gantt_t_date_end = $projet->fields["date_end"];
             } else {
                 $gantt_t_date_begin = date("Y-m-d");
                 $gantt_t_date_end = date("Y-m-d");
             }
             $plan = new PluginProjetTaskPlanning();
             $plan->getFromDBbyTask($task["id"]);
             if (!empty($plan->fields["begin"])) {
                 $gantt_t_date_begin = $plan->fields["begin"];
             }
             if (!empty($plan->fields["end"])) {
                 $gantt_t_date_end = $plan->fields["end"];
             }
             $gdata[] = array("type" => 'phase', "task" => $task["id"], "projet" => $options["plugin_projet_projets_id"], "name" => $gantt_t_name, "begin" => $gantt_t_date_begin, "end" => $gantt_t_date_end, "advance" => $task["advance"], "bg_color" => $gantt_t_bgcolor);
             if ($task["depends"] == 1) {
                 $gdata[] = array("type" => 'dependency', "projet" => $options["plugin_projet_projets_id"], "name" => $gantt_t_name, "date_begin" => $gantt_t_date_begin);
             }
             $restrictchild = " `plugin_projet_projets_id` = '" . $options["plugin_projet_projets_id"] . "'";
             $condition = " `plugin_projet_tasks_id_2` = '" . $task["id"] . "' ";
             $tasks_tasks = getAllDatasFromTable("glpi_plugin_projet_tasks_tasks", $condition);
             $tab = array();
             if (!empty($tasks_tasks)) {
                 foreach ($tasks_tasks as $tasks_task) {
                     $tab[] = $tasks_task['plugin_projet_tasks_id_1'];
                 }
             }
             if (!empty($tab)) {
                 $restrictchild .= " AND `id` IN (" . implode(',', $tab) . ")";
             }
             $restrictchild .= " AND `is_deleted` = '0'";
             $restrictchild .= " AND `is_template` = '0'";
             $restrictchild .= " AND `show_gantt` = '1'";
             $restrictchild .= " ORDER BY `plugin_projet_taskstates_id` DESC";
             $childs = getAllDatasFromTable("glpi_plugin_projet_tasks", $restrictchild);
             if (!empty($childs) && !empty($tab)) {
                 foreach ($childs as $child) {
                     $params = array('plugin_projet_projets_id' => $options["plugin_projet_projets_id"], 'plugin_projet_tasks_id' => $child["id"], 'parent' => 1, 'prefix' => $prefix);
                     self::showTaskGantt($params);
                 }
             }
         }
     }
 }
Exemple #2
0
function plugin_projet_giveItem($type, $ID, $data, $num)
{
    global $CFG_GLPI, $DB;
    $searchopt =& Search::getOptions($type);
    $table = $searchopt[$ID]["table"];
    $field = $searchopt[$ID]["field"];
    $output_type = Search::HTML_OUTPUT;
    if (isset($_GET['display_type'])) {
        $output_type = $_GET['display_type'];
    }
    switch ($type) {
        case 'PluginProjetProjet':
            switch ($table . '.' . $field) {
                case "glpi_plugin_projet_projets_projets.plugin_projet_projets_id_1":
                    $out = " ";
                    $split = explode("\$\$\$\$", $data["ITEM_" . $num]);
                    $split2 = explode("\$\$\$\$", $data["ITEM_" . $num . "_2"]);
                    $displayed = array();
                    for ($k = 0; $k < count($split); $k++) {
                        //$linkid = $split2[$k];
                        $linkid = $split[$k] == $data['id'] ? $split2[$k] : $split2[$k];
                        if ($linkid > 0 && $linkid != $data['id'] && !isset($displayed[$linkid])) {
                            $text = $linkid . " - " . Dropdown::getDropdownName('glpi_plugin_projet_projets', $linkid);
                            if (count($displayed)) {
                                $out .= "<br>";
                            }
                            $displayed[$linkid] = $linkid;
                            $out .= $text;
                        }
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_projets.name":
                    $out = "";
                    if (!empty($data["ITEM_" . $num . "_2"])) {
                        $link = Toolbox::getItemTypeFormURL('PluginProjetProjet');
                        if ($output_type == Search::HTML_OUTPUT) {
                            $out = "<a href=\"" . $link . "?id=" . $data["ITEM_" . $num . "_2"] . "\">";
                        }
                        $out .= $data["ITEM_{$num}"];
                        if ($output_type == Search::HTML_OUTPUT) {
                            if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_{$num}"])) {
                                $out .= " (" . $data["ITEM_" . $num . "_2"] . ")";
                            }
                            $out .= "</a>";
                        }
                        if (plugin_projet_haveRight("task", "r") && $output_type == Search::HTML_OUTPUT) {
                            $query_tasks = "SELECT COUNT(`id`) AS nb_tasks\n                                 FROM `glpi_plugin_projet_tasks`\n                                 WHERE `plugin_projet_projets_id` = '" . $data['id'] . "' ";
                            $query_tasks .= "AND `is_deleted` = '0'";
                            $result_tasks = $DB->query($query_tasks);
                            $nb_tasks = $DB->result($result_tasks, 0, "nb_tasks");
                            //select finished tasks
                            $query_states = "SELECT COUNT(`id`) AS nb_tasks\n                                 FROM `glpi_plugin_projet_tasks`\n                                 WHERE `plugin_projet_projets_id` = '" . $data['id'] . "' ";
                            $query_states .= "AND `is_deleted` = '0'";
                            $finished = " `for_dependency` = '1' ";
                            $states = getAllDatasFromTable("glpi_plugin_projet_taskstates", $finished);
                            $tab = array();
                            if (!empty($states)) {
                                foreach ($states as $state) {
                                    $tab[] = $state['id'];
                                }
                            }
                            if (!empty($tab)) {
                                $query_states .= "AND `plugin_projet_taskstates_id` IN (" . implode(',', $tab) . ")";
                            }
                            $result_states = $DB->query($query_states);
                            $is_finished = $DB->result($result_states, 0, "nb_tasks");
                            $out .= "&nbsp;(<a href=\"" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/task.php?plugin_projet_projets_id=" . $data["id"] . "\">";
                            if ($nb_tasks - $is_finished > 0) {
                                $out .= "<span class='red'>";
                                $out .= $nb_tasks - $is_finished . "</span></a>)";
                            } else {
                                $out .= "<span class='green'>";
                                $out .= $nb_tasks . "</span></a>)";
                            }
                        }
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_projets.date_end":
                    if (!empty($data["ITEM_{$num}"])) {
                        if ($data["ITEM_{$num}"] <= date('Y-m-d') && !empty($data["ITEM_{$num}"])) {
                            $out = "<span class='red'>" . Html::convdate($data["ITEM_{$num}"]) . "</span>";
                        } else {
                            $out = "<span class='green'>" . Html::convdate($data["ITEM_{$num}"]) . "</span>";
                        }
                    } else {
                        $out = "--";
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_projets.advance":
                    $out = PluginProjetProjet::displayProgressBar('100', $data["ITEM_{$num}"]);
                    return $out;
                    break;
                case "glpi_plugin_projet_projets_items.items_id":
                    $restrict = "`plugin_projet_projets_id` = '" . $data['id'] . "' \n                           ORDER BY `itemtype`, `items_id`";
                    $items = getAllDatasFromTable("glpi_plugin_projet_projets_items", $restrict);
                    $out = '';
                    if (!empty($items)) {
                        foreach ($items as $device) {
                            if (!class_exists($device["itemtype"])) {
                                continue;
                            }
                            $item = new $device["itemtype"]();
                            $item->getFromDB($device["items_id"]);
                            $out .= $item->getTypeName() . " - ";
                            if ($device["itemtype"] == 'User') {
                                if ($output_type == Search::HTML_OUTPUT) {
                                    $link = Toolbox::getItemTypeFormURL('User');
                                    $out .= "<a href=\"" . $link . "?id=" . $device["items_id"] . "\">";
                                }
                                $out .= getUserName($device["items_id"]);
                                if ($output_type == Search::HTML_OUTPUT) {
                                    $out .= "</a>";
                                }
                            } else {
                                $out .= $item->getLink();
                            }
                            $out .= "<br>";
                        }
                    } else {
                        $out = ' ';
                    }
                    return $out;
                    break;
            }
            return "";
            break;
        case 'PluginProjetTask':
            switch ($table . '.' . $field) {
                case "glpi_plugin_projet_tasks_tasks.plugin_projet_tasks_id_1":
                    $out = " ";
                    $split = explode("\$\$\$\$", $data["ITEM_" . $num]);
                    $split2 = explode("\$\$\$\$", $data["ITEM_" . $num . "_2"]);
                    $displayed = array();
                    for ($k = 0; $k < count($split); $k++) {
                        //$linkid = $split2[$k];
                        $linkid = $split[$k] == $data['id'] ? $split2[$k] : $split2[$k];
                        if ($linkid > 0 && $linkid != $data['id'] && !isset($displayed[$linkid])) {
                            $text = $linkid . " - " . Dropdown::getDropdownName('glpi_plugin_projet_tasks', $linkid);
                            if (count($displayed)) {
                                $out .= "<br>";
                            }
                            $displayed[$linkid] = $linkid;
                            $out .= $text;
                        }
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_tasks.advance":
                    $out = PluginProjetProjet::displayProgressBar('100', $data["ITEM_{$num}"]);
                    return $out;
                    break;
                case "glpi_plugin_projet_tasks.priority":
                    $out = Ticket::getPriorityName($data["ITEM_{$num}"]);
                    return $out;
                    break;
                case 'glpi_plugin_projet_tasks.depends':
                    $out = "";
                    if ($data["ITEM_{$num}"] == 1) {
                        $out .= "<span class='red'>";
                    }
                    $out .= Dropdown::getYesNo($data["ITEM_{$num}"]);
                    if ($data["ITEM_{$num}"] == 1) {
                        $out .= "</span>";
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_tasks.plugin_projet_projets_id":
                    $out = Dropdown::getdropdownname("glpi_plugin_projet_projets", $data["ITEM_{$num}"]);
                    $out .= " (" . $data["ITEM_{$num}"] . ")";
                    return $out;
                    break;
                case "glpi_plugin_projet_tasks_items.items_id":
                    $restrict = "`plugin_projet_tasks_id` = '" . $data['id'] . "' \n                           ORDER BY `itemtype`, `items_id`";
                    $items = getAllDatasFromTable("glpi_plugin_projet_tasks_items", $restrict);
                    $out = '';
                    if (!empty($items)) {
                        foreach ($items as $device) {
                            $item = new $device["itemtype"]();
                            $item->getFromDB($device["items_id"]);
                            $out .= $item->getTypeName() . " - " . $item->getLink() . "<br>";
                        }
                    }
                    return $out;
                    break;
                case "glpi_contacts.name":
                    if (!empty($data["ITEM_{$num}"])) {
                        $link = Toolbox::getItemTypeFormURL('Contact');
                        $out = "<a href=\"" . $link . "?id=" . $data["ITEM_{$num}"] . "\">";
                        $temp = $data["contacts_name"];
                        $firstname = $data["contacts_firstname"];
                        if (strlen($firstname) > 0) {
                            if ($CFG_GLPI["names_format"] == FIRSTNAME_BEFORE) {
                                $temp = $firstname . " " . $temp;
                            } else {
                                $temp .= " " . $firstname;
                            }
                        }
                        $out .= $temp;
                        if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_{$num}"])) {
                            $out .= " (" . $data["ITEM_{$num}"] . ")";
                        }
                        $out .= "</a>";
                    } else {
                        $out = "";
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_taskplannings.id":
                    if (!empty($data["ITEM_{$num}"])) {
                        $plan = new PluginProjetTaskPlanning();
                        $plan->getFromDB($data["ITEM_{$num}"]);
                        $out = Html::convDateTime($plan->fields["begin"]) . "<br>&nbsp;->&nbsp;" . Html::convDateTime($plan->fields["end"]);
                    } else {
                        $out = __('None');
                    }
                    return $out;
                    break;
            }
            return "";
            break;
    }
    return "";
}