Esempio n. 1
0
 function showForm($ID, $options = array())
 {
     if (!$this->canView()) {
         return false;
     }
     $plugin_resources_resources_id = -1;
     if (isset($options['plugin_resources_resources_id'])) {
         $plugin_resources_resources_id = $options['plugin_resources_resources_id'];
     }
     $item = new PluginResourcesResource();
     if ($item->getFromDB($plugin_resources_resources_id)) {
         $entities_id = $item->fields["entities_id"];
     }
     if ($ID > 0) {
         $this->check($ID, 'r');
         $plugin_resources_resources_id = $this->fields["plugin_resources_resources_id"];
     } else {
         // Create item
         $input = array('plugin_resources_resources_id' => $plugin_resources_resources_id, 'entities_id' => $entities_id);
         $this->check(-1, 'w', $input);
     }
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<input type='hidden' name='plugin_resources_resources_id' value='{$plugin_resources_resources_id}'>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . PluginResourcesResource::getTypeName(2) . "&nbsp;</td><td>";
     $user = PluginResourcesResource::getResourceName($plugin_resources_resources_id, 2);
     $out = "<a href='" . $user['link'] . "'>";
     $out .= $user["name"];
     if ($_SESSION["glpiis_ids_visible"]) {
         $out .= " (" . $plugin_resources_resources_id . ")";
     }
     $out .= "</a>";
     echo $out;
     echo "</td>";
     echo "<td colspan='2'>";
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "name", array('size' => "50"));
     echo "</td>";
     echo "<td>" . PluginResourcesTaskType::getTypeName(1) . "</td><td>";
     Dropdown::show('PluginResourcesTaskType', array('value' => $this->fields["plugin_resources_tasktypes_id"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Technician') . "</td><td>";
     User::dropdown(array('name' => "users_id", 'value' => $this->fields["users_id"], 'right' => 'interface'));
     echo "</td>";
     echo "<td>" . __('Planning') . "</td>";
     echo "<td>";
     $plan = new PluginResourcesTaskPlanning();
     $plan->showFormForTask($plugin_resources_resources_id, $this);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Group') . "</td><td>";
     Dropdown::show('Group', array('value' => $this->fields["groups_id"]));
     echo "</td>";
     echo "<td>" . __('Carried out task', 'resources') . "</td><td>";
     Dropdown::showYesNo("is_finished", $this->fields["is_finished"]);
     echo "</td>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Effective duration', 'resources') . "</td><td>";
     $toadd = array();
     for ($i = 9; $i <= 100; $i++) {
         $toadd[] = $i * HOUR_TIMESTAMP;
     }
     Dropdown::showTimeStamp("actiontime", array('min' => 0, 'max' => 8 * HOUR_TIMESTAMP, 'value' => $this->fields["actiontime"], 'addfirstminutes' => true, 'inhours' => true, 'toadd' => $toadd));
     echo "</td><td colspan='2'></td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='4'>" . __('Comments') . "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'><td colspan='4'>";
     echo "<textarea cols='130' rows='4' name='comment' >" . $this->fields["comment"] . "</textarea>";
     echo "<input type='hidden' name='withtemplate' value=\"" . $options['withtemplate'] . "\" >";
     echo "</td></tr>";
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
Esempio n. 2
0
function plugin_resources_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 'PluginResourcesResource':
            switch ($table . '.' . $field) {
                case "glpi_plugin_resources_resources.name":
                    if (!empty($data["ITEM_" . $num . "_2"])) {
                        $link = Toolbox::getItemTypeFormURL('PluginResourcesResource');
                        $out = "";
                        if ($output_type == Search::HTML_OUTPUT) {
                            $out = "<a href=\"" . $link . "?id=" . $data["ITEM_" . $num . "_2"] . "\">";
                        }
                        $out .= $data["META_{$num}"];
                        if ($output_type == Search::HTML_OUTPUT) {
                            if ($_SESSION["glpiis_ids_visible"] || empty($data["META_{$num}"])) {
                                $out .= " (" . $data["ITEM_" . $num . "_2"] . ")";
                            }
                            $out .= "</a>";
                        }
                        if (plugin_resources_haveRight("task", "r") && $output_type == Search::HTML_OUTPUT) {
                            $query_tasks = "SELECT COUNT(`id`) AS nb_tasks,SUM(`is_finished`) AS is_finished\n                                 FROM `glpi_plugin_resources_tasks`\n                                 WHERE `plugin_resources_resources_id` = '" . $data['id'] . "'\n                                 AND `is_deleted` = '0'";
                            $result_tasks = $DB->query($query_tasks);
                            $nb_tasks = $DB->result($result_tasks, 0, "nb_tasks");
                            $is_finished = $DB->result($result_tasks, 0, "is_finished");
                            $out .= "&nbsp;(<a href=\"" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.php?plugin_resources_resources_id=" . $data["id"] . "\">";
                            if ($nb_tasks - $is_finished > 0) {
                                $out .= "<span class='plugin_resources_date_over_color'>";
                                $out .= $nb_tasks - $is_finished . "</span></a>)";
                            } else {
                                $out .= "<span class='plugin_resources_date_day_color'>";
                                $out .= $nb_tasks . "</span></a>)";
                            }
                        }
                    }
                    return $out;
                    break;
                case "glpi_plugin_resources_resources.date_end":
                    if ($data["ITEM_{$num}"] <= date('Y-m-d') && !empty($data["ITEM_{$num}"])) {
                        $out = "<span class='plugin_resources_date_color'>" . Html::convDate($data["ITEM_{$num}"]) . "</span>";
                    } else {
                        if (empty($data["ITEM_{$num}"])) {
                            $out = __('Not defined', 'resources');
                        } else {
                            $out = Html::convDate($data["ITEM_{$num}"]);
                        }
                    }
                    return $out;
                    break;
                case "glpi_plugin_resources_resources_items.items_id":
                    $restrict = "`plugin_resources_resources_id` = '" . $data['id'] . "'\n                           ORDER BY `itemtype`, `items_id`";
                    $items = getAllDatasFromTable("glpi_plugin_resources_resources_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;
                case "glpi_plugin_resources_resources.quota":
                    if (!empty($data["ITEM_{$num}"])) {
                        $out = floatval($data["ITEM_{$num}"]);
                    }
                    return $out;
                    break;
            }
            return "";
            break;
        case 'PluginResourcesTask':
            switch ($table . '.' . $field) {
                case "glpi_plugin_resources_resources.name":
                    $out = "";
                    if (!empty($data["ITEM_" . $num . "_2"])) {
                        $user = PluginResourcesResource::getResourceName($data["ITEM_" . $num . "_2"], 2);
                        $out = "<a href='" . $user['link'] . "'>";
                        $out .= $user["name"];
                        if ($_SESSION["glpiis_ids_visible"] || empty($user["name"])) {
                            $out .= " (" . $data["ITEM_" . $num . "_2"] . ")";
                        }
                        $out .= "</a>";
                    }
                    return $out;
                    break;
                case 'glpi_plugin_resources_tasks.is_finished':
                    $status = PluginResourcesTask::getStatus($data["ITEM_{$num}"]);
                    return "<img src=\"" . $CFG_GLPI["root_doc"] . "/plugins/resources/pics/" . $data["ITEM_{$num}"] . ".png\"\n                        alt='{$status}' title='{$status}'>&nbsp;{$status}";
                    break;
                case "glpi_plugin_resources_tasks_items.items_id":
                    $restrict = "`plugin_resources_tasks_id` = '" . $data['id'] . "'\n                           ORDER BY `itemtype`, `items_id`";
                    $items = getAllDatasFromTable("glpi_plugin_resources_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_plugin_resources_taskplannings.id":
                    if (!empty($data["ITEM_{$num}"])) {
                        $plan = new PluginResourcesTaskPlanning();
                        $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;
        case 'User':
            switch ($table . '.' . $field) {
                case "glpi_plugin_resources_recipients.name":
                    $out = getUserName($data["ITEM_" . $num . "_2"]);
                    return $out;
                    break;
                case "glpi_plugin_resources_recipients_leaving.name":
                    $out = getUserName($data["ITEM_" . $num . "_2"]);
                    return $out;
                    break;
                case "glpi_plugin_resources_managers.name":
                    $out = getUserName($data["ITEM_" . $num . "_2"]);
                    return $out;
                    break;
            }
            return "";
            break;
        case 'PluginResourcesResourceResting':
            switch ($table . '.' . $field) {
                case "glpi_plugin_resources_resources.name":
                    if (!empty($data["id"])) {
                        $link = Toolbox::getItemTypeFormURL('PluginResourcesResourceResting');
                        $out = "<a href=\"" . $link . "?id=" . $data["id"] . "\">";
                        $out .= $data["ITEM_{$num}"];
                        if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_{$num}"])) {
                            $out .= " (" . $data["id"] . ")";
                        }
                        $out .= "</a>";
                    }
                    return $out;
                    break;
            }
            return "";
            break;
        case 'PluginResourcesResourceHoliday':
            switch ($table . '.' . $field) {
                case "glpi_plugin_resources_resources.name":
                    if (!empty($data["id"])) {
                        $link = Toolbox::getItemTypeFormURL('PluginResourcesResourceHoliday');
                        $out = "<a href=\"" . $link . "?id=" . $data["id"] . "\">";
                        $out .= $data["ITEM_{$num}"];
                        if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_{$num}"])) {
                            $out .= " (" . $data["id"] . ")";
                        }
                        $out .= "</a>";
                    }
                    return $out;
                    break;
            }
            return "";
            break;
        case 'PluginResourcesDirectory':
            switch ($table . '.' . $field) {
                case "glpi_plugin_resources_managers.name":
                    $out = "";
                    if (!empty($data["ITEM_" . $num . "_2"])) {
                        $out = getUserName($data["ITEM_" . $num . "_2"]);
                    }
                    return $out;
                    break;
            }
            return "";
            break;
        case 'PluginResourcesEmployment':
            switch ($table . '.' . $field) {
                case "glpi_plugin_resources_resources.name":
                    $out = "";
                    if (!empty($data["ITEM_" . $num . "_2"])) {
                        $user = PluginResourcesResource::getResourceName($data["ITEM_" . $num . "_2"], 2);
                        $out = "<a href='" . $user['link'] . "'>";
                        $out .= $user["name"];
                        if ($_SESSION["glpiis_ids_visible"] || empty($user["name"])) {
                            $out .= " (" . $data["ITEM_" . $num . "_2"] . ")";
                        }
                        $out .= "</a>";
                    }
                    return $out;
                    break;
            }
            return "";
            break;
    }
    return "";
}