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 ""; }
/** * Permet l'affichage dynamique des ressources avec info bulle * * @static * @param array ($myname,$value,$entity_restrict) */ static function dropdown($options = array()) { global $DB, $CFG_GLPI; // Default values $p['name'] = 'plugin_resources_resources_id'; $p['value'] = ''; $p['all'] = 0; $p['on_change'] = ''; $p['comments'] = 1; $p['entity'] = -1; $p['entity_sons'] = false; $p['used'] = array(); $p['toupdate'] = ''; $p['rand'] = mt_rand(); $p['plugin_resources_contracttypes_id'] = 0; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } if (!($p['entity'] < 0) && $p['entity_sons']) { if (is_array($p['entity'])) { echo "entity_sons options is not available with array of entity"; } else { $p['entity'] = getSonsOf('glpi_entities', $p['entity']); } } // Make a select box with all glpi users $use_ajax = false; if ($CFG_GLPI["use_ajax"]) { $res = self::getSqlSearchResult(true, $p['entity'], $p['value'], $p['used'], '', $p['plugin_resources_contracttypes_id']); $nb = $res ? $DB->result($res, 0, "cpt") : 0; if ($nb > $CFG_GLPI["ajax_limit_count"]) { $use_ajax = true; } } $user = self::getResourceName($p['value'], 2); $default_display = "<select id='dropdown_" . $p['name'] . $p['rand'] . "' name='" . $p['name'] . "'>"; $default_display .= "<option value='" . $p['value'] . "'>"; $default_display .= Toolbox::substr($user["name"], 0, $_SESSION["glpidropdown_chars_limit"]); $default_display .= "</option></select>"; //$view_users = (Session::haveRight("user", "r")); $params = array('searchText' => '__VALUE__', 'value' => $p['value'], 'myname' => $p['name'], 'all' => $p['all'], 'comment' => $p['comments'], 'rand' => $p['rand'], 'on_change' => $p['on_change'], 'entity_restrict' => $p['entity'], 'used' => $p['used'], 'update_item' => $p['toupdate'], 'plugin_resources_contracttypes_id' => $p['plugin_resources_contracttypes_id']); $default = ""; if (!empty($p['value']) && $p['value'] > 0) { $default = $default_display; } else { $default = "<select name='" . $p['name'] . "' id='dropdown_" . $p['name'] . $p['rand'] . "'>"; if ($p['all']) { $default .= "<option value='0'>[ " . __('All') . " ]</option></select>"; } else { $default .= "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>\n"; } } Ajax::dropdown($use_ajax, "/plugins/resources/ajax/dropdownResources.php", $params, $default, $p['rand']); if (class_exists('PluginPositionsPosition')) { PluginPositionsPosition::showGeolocLink('PluginResourcesResource', $params["value"]); } // Display comment if ($p['comments']) { if (empty($user["link"])) { $user["link"] = $CFG_GLPI['root_doc'] . "/plugins/resources/front/resource.php"; } Html::showToolTip($user["comment"], array('contentid' => "comment_" . $p['name'] . $p['rand'], 'link' => $user["link"], 'linkid' => "comment_link_" . $p["name"] . $p['rand'])); } return $p['rand']; }