Beispiel #1
0
function plugin_positions_giveItem($type, $ID, $data, $num)
{
    global $CFG_GLPI, $DB;
    $searchopt =& Search::getOptions($type);
    $table = $searchopt[$ID]["table"];
    $field = $searchopt[$ID]["field"];
    switch ($type) {
        case 'PluginPositionsPosition':
            switch ($table . '.' . $field) {
                case "glpi_plugin_positions_positions.items_id":
                    $query_device = "SELECT DISTINCT `itemtype`\n                           FROM `glpi_plugin_positions_positions`\n                           WHERE `id` = '" . $data['id'] . "'\n                           ORDER BY `itemtype`";
                    $result_device = $DB->query($query_device);
                    $number_device = $DB->numrows($result_device);
                    $y = 0;
                    $out = '';
                    $positions_id = $data['id'];
                    if ($number_device > 0) {
                        for ($i = 0; $i < $number_device; $i++) {
                            $column = "name";
                            $itemtype = $DB->result($result_device, $i, "itemtype");
                            if (!class_exists($itemtype)) {
                                continue;
                            }
                            $item = new $itemtype();
                            if ($item->canView()) {
                                $table_item = getTableForItemType($itemtype);
                                $query = "SELECT `" . $table_item . "`.*, `glpi_plugin_positions_positions`.`id` AS items_id, `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_positions_positions`, `" . $table_item . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $table_item . "`.`entities_id`) " . " WHERE `" . $table_item . "`.`id` = `glpi_plugin_positions_positions`.`items_id`\n                        AND `glpi_plugin_positions_positions`.`itemtype` = '{$itemtype}'\n                        AND `glpi_plugin_positions_positions`.`id` = '" . $positions_id . "' " . getEntitiesRestrictRequest(" AND ", $table_item, '', '', $item->maybeRecursive());
                                if ($item->maybeTemplate()) {
                                    $query .= " AND `" . $table_item . "`.`is_template` = '0'";
                                }
                                $query .= " ORDER BY `glpi_entities`.`completename`, `" . $table_item . "`.`{$column}`";
                                if ($result_linked = $DB->query($query)) {
                                    if ($DB->numrows($result_linked)) {
                                        $item = new $itemtype();
                                        while ($data = $DB->fetch_assoc($result_linked)) {
                                            if ($item->getFromDB($data['id'])) {
                                                $out .= $item->getTypeName() . " - " . $item->getLink() . "<br>";
                                            }
                                        }
                                    } else {
                                        $out .= ' ';
                                    }
                                }
                            } else {
                                $out .= ' ';
                            }
                        }
                    }
                    return $out;
                    break;
            }
            break;
    }
    if (in_array($type, PluginPositionsPosition::getTypes(true))) {
        switch ($table . '.' . $field) {
            case "glpi_plugin_positions_positions.name":
                $out = '';
                $pos = new PluginPositionsPosition();
                if ($pos->getFromDB($data["ITEM_{$num}"])) {
                    $out .= $pos->getLink();
                    $split = explode("\$\$", $data["ITEM_{$num}"]);
                    $out .= PluginPositionsPosition::showGeolocLink($type, $data['id'], $split[1]);
                    $out .= "<br>";
                } else {
                    $out .= ' ';
                }
                return $out;
                break;
        }
    }
    return "";
}