Make a select box for all items
static public showAllItems ( $myname, $value_type, $value, $entity_restrict, $types = '', $onlyglobal = false, $checkright = false, $itemtypename = 'itemtype' ) : nothing | ||
$myname | select name | |
$value_type | default value for the device type (default 0) | |
$value | default value (default 0) | |
$entity_restrict | Restrict to a defined entity (default -1) | |
$types | Types used (default '') | |
$onlyglobal | Restrict to global items (false by default) | |
$checkright | Restrict to items with read rights (false by default) | |
$itemtypename | name used for itemtype select | |
return | nothing | (print out an HTML select box) |
function showForm($ID) { global $CFG_GLPI; echo "<form name='form' method='post' action='" . $CFG_GLPI["root_doc"] . "/plugins/immobilizationsheets/front/immobilizationsheet.php'>"; echo "<div align=\"center\">"; echo "<table class=\"tab_cadre\" cellspacing=\"2\" cellpadding=\"2\">"; echo "<tr><th>" . __('Generation of immobilization sheet', 'immobilizationsheets') . "</th></tr>"; echo "<tr>"; echo "<td class='tab_bg_2 center'>"; $immo_item = new PluginImmobilizationsheetsItem(); Dropdown::showAllItems("item_item", 0, 0, -1, $immo_item->getTypes()); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . __s('Post') . "\" >"; echo "</td>"; echo "</tr>"; echo "</table></div>"; Html::closeForm(); }
function plugin_appliances_MassiveActionsDisplay($options) { switch ($options['itemtype']) { case 'PluginAppliancesAppliance': switch ($options['action']) { // No case for add_document : use GLPI core one case "plugin_appliances_install": Dropdown::showAllItems("item_item", 0, 0, -1, PluginAppliancesAppliance::getTypes()); echo "<input type='submit' name='massiveaction' class='submit' " . "value='" . _x('button', 'Post') . "'>"; break; case "plugin_appliances_desinstall": Dropdown::showAllItems("item_item", 0, 0, -1, PluginAppliancesAppliance::getTypes()); echo "<input type='submit' name='massiveaction' class='submit' " . "value='" . _x('button', 'Post') . "'>"; break; case "plugin_appliances_transfert": Entity::dropdown(); echo " <input type='submit' name='massiveaction' class='submit' " . "value='" . _x('button', 'Post') . "'>"; break; } break; default: if (in_array($options['itemtype'], PluginAppliancesAppliance::getTypes(true))) { Dropdown::show('PluginAppliancesAppliance'); echo "<input type='submit' name='massiveaction' class='submit\\' " . "value='" . _x('button', 'Post') . "'>"; } } return ""; }
function showSpecificMassiveActionsParameters($input = array()) { switch ($input['action']) { case "Install": Dropdown::showAllItems("item_item", 0, 0, -1, self::getTypes()); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value='" . _sx('button', 'Post') . "'>"; return true; break; case "Desinstall": Dropdown::showAllItems("item_item", 0, 0, -1, self::getTypes()); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value='" . _sx('button', 'Post') . "'>"; return true; break; case "Duplicate": Dropdown::show('Entity'); echo " <input type=\"submit\" name=\"massiveaction\" class=\"submit\" value='" . _sx('button', 'Post') . "'>"; return true; break; case "Transfert": Dropdown::show('Entity'); echo " <input type=\"submit\" name=\"massiveaction\" class=\"submit\" value='" . _sx('button', 'Post') . "'>"; return true; break; default: return parent::showSpecificMassiveActionsParameters($input); break; } return false; }
function configureNodesLinks($weathermaps_id) { global $DB,$CFG_GLPI; $networkPort = new NetworkPort(); $this->getFromDB($weathermaps_id); $style = ''; if ($this->fields['width'] > 950) { $style = ";position:relative;left:-".(($this->fields['width'] - 950) / 2)."px"; } echo "<table class='tab_cadre' style='width:". $this->fields['width']."px;height:".$this->fields['height']."px". $style."'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='2'>"; echo __('Nodes and links', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td valign='top'>"; echo "<div>"; PluginMonitoringToolbox::loadLib(); $this->drawMap($weathermaps_id, 100, 1); echo "</div>"; echo "</td>"; echo "<td valign='top'>"; echo "<div style='position: fixed;top: 30px;right: 0;z-index:999;' >"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<td>"; echo "<a onClick='Ext.get(\"weathermapform\").toggle();'> <img src='".$CFG_GLPI["root_doc"]."/pics/deplier_down.png' /> ".__('Display weathermap form', 'monitoring')." <img src='".$CFG_GLPI["root_doc"]."/pics/deplier_down.png' /></a>"; echo "</td>"; echo "</tr>"; echo"</table>"; echo "</div>"; echo "<div style='position: fixed;top: 50px;right: 0;z-index:1000;' id='weathermapform' >"; echo '<form name="pointform" method="post" action="'.$CFG_GLPI['root_doc'].'/plugins/monitoring/front/weathermapnode.form.php">'; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<th colspan='2'>"; echo "x : "; echo '<input type="text" name="x" size="4" value="50" />'; echo " "; echo "y : "; echo '<input type="text" name="y" size="4" value="50"/>'; echo "</th>"; echo "</tr>"; // * Add node echo "<tr>"; echo "<th colspan='2'>"; echo "<input type='hidden' name='plugin_monitoring_weathermaps_id' value='".$weathermaps_id."' />"; echo __('Add a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Node', 'monitoring')." :"; echo "</td>"; echo "<td>"; Dropdown::showAllItems("items_id"); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Name')." :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='name' value='' />"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Position of label', 'monitoring')." :"; echo "</td>"; echo "<td>"; $positions = array( 'middle' => __('Center', 'monitoring'), 'start' => __('Right', 'monitoring'), 'end' => __('Left', 'monitoring') ); Dropdown::showFromArray('position', $positions); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"".__('Add')."\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Change node position echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $query = "SELECT * FROM `".getTableForItemType("PluginMonitoringWeathermapnode")."` WHERE `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $itemtype = $data['itemtype']; if ($itemtype == '0') { $pmWeathermapnode->delete($data); } else { $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update$rand", "show_updatenode$rand", $CFG_GLPI["root_doc"]."/plugins/monitoring/ajax/dropdownWnode.php", $params, TRUE); echo "<span id='show_updatenode$rand'></span>\n"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='update' value=\"".__('Save')."\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Delete node echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "</td>"; echo "<td>"; $query = "SELECT * FROM `".getTableForItemType("PluginMonitoringWeathermapnode")."` WHERE `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"".__('Delete permanently')."\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo '<form name="formlink" method="post" action="'.$CFG_GLPI['root_doc'].'/plugins/monitoring/front/weathermaplink.form.php">'; echo "<table class='tab_cadre' width='100%'>"; // *Add Link echo "<tr>"; echo "<th colspan='2'>"; echo __('Add a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Source', 'monitoring')."* :"; echo "</td>"; echo "<td>"; $query = "SELECT `glpi_plugin_monitoring_weathermapnodes`.`id` as `id`, `glpi_plugin_monitoring_weathermapnodes`.`name` as `name`, `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`, `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`, `glpi_plugin_monitoring_services`.`id` as `services_id`, `glpi_plugin_monitoring_components`.`name` as `components_name`, `plugin_monitoring_commands_id`, `glpi_plugin_monitoring_components`.`arguments`, `glpi_plugin_monitoring_services`.`networkports_id` FROM `glpi_plugin_monitoring_weathermapnodes` LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts` ON (`glpi_plugin_monitoring_weathermapnodes`.`items_id`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` AND `glpi_plugin_monitoring_weathermapnodes`.`itemtype`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`) LEFT JOIN `glpi_plugin_monitoring_services` ON `plugin_monitoring_componentscatalogs_hosts_id`= `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` LEFT JOIN `glpi_plugin_monitoring_components` ON `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id` WHERE `is_weathermap` = '1' AND `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' ORDER BY `itemtype`,`items_id`,`glpi_plugin_monitoring_components`.`name`"; $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $elements2 = array(); $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } // Try to get device/node connected on this port $device_connected = ''; if ($data['arguments'] != '') { $arguments = importArrayFromDB($data['arguments']); foreach ($arguments as $argument) { if (!is_numeric($argument)) { if (strstr($argument, "[[NETWORKPORTDESCR]]")){ if (class_exists("PluginFusinvsnmpNetworkPort")) { $pfNetworkPort = new PluginFusinvsnmpNetworkPort(); $pfNetworkPort->loadNetworkport($data['networkports_id']); $argument = $pfNetworkPort->getValue("ifdescr"); } } elseif (strstr($argument, "[[NETWORKPORTNUM]]")){ $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $argument = $pfNetworkPort->fields['logical_number']; } elseif (strstr($argument, "[[NETWORKPORTNAME]]")){ $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $argument = $pfNetworkPort->fields['name']; } // Search networkport have this name or description $a_ports = $networkPort->find("`itemtype`='".$itemtype."' AND `items_id`='".$data['items_id']."' AND `name`='".$argument."'"); foreach ($a_ports as $pdata) { if ($device_connected == '') { $oppositeports_id = $networkPort->getContact($pdata['id']); if ($oppositeports_id) { $networkPort->getFromDB($oppositeports_id); $a_nodes = $pmWeathermapnode->find(" `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' AND `itemtype`='".$networkPort->fields['itemtype']."' AND `items_id`='".$networkPort->fields['items_id']."'", "", 1); if (count($a_nodes) > 0) { $a_node = current($a_nodes); $device_connected = $pmWeathermapnode->getNodeName($a_node['id']); } } } } if ($device_connected == '' AND class_exists("PluginFusinvsnmpNetworkPort")) { $queryn = "SELECT `glpi_networkports`.`id` FROM `glpi_plugin_fusinvsnmp_networkports` LEFT JOIN `glpi_networkports` ON `glpi_networkports`.`id`=`networkports_id` WHERE `itemtype`='".$itemtype."' AND `items_id`='".$data['items_id']."' AND `ifdescr`='".$argument."'"; $resultn = $DB->query($queryn); while ($pdata=$DB->fetch_array($resultn)) { if ($device_connected == '') { $oppositeports_id = $networkPort->getContact($pdata['id']); if ($oppositeports_id) { $networkPort->getFromDB($oppositeports_id); $a_nodes = $pmWeathermapnode->find(" `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' AND `itemtype`='".$networkPort->fields['itemtype']."' AND `items_id`='".$networkPort->fields['items_id']."'", "", 1); if (count($a_nodes) > 0) { $a_node = current($a_nodes); $queryl = "SELECT `plugin_monitoring_weathermapnodes_id_1` FROM `glpi_plugin_monitoring_weathermaplinks` LEFT JOIN `glpi_plugin_monitoring_weathermapnodes` ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1` WHERE ((`plugin_monitoring_weathermapnodes_id_1`='".$data['id']."' AND `plugin_monitoring_weathermapnodes_id_2`='".$a_node['id']."') OR (`plugin_monitoring_weathermapnodes_id_1`='".$a_node['id']."' AND `plugin_monitoring_weathermapnodes_id_2`='".$data['id']."')) AND `plugin_monitoring_weathermaps_id` = '".$weathermaps_id."'"; $resultl = $DB->query($queryl); if ($DB->numrows($resultl) == '0') { $device_connected = $pmWeathermapnode->getNodeName($a_node['id']); } } } } } } } } } if ($device_connected == '') { $networkPort->getFromDB($data['networkports_id']); $elements2[$data['id']."-".$data['services_id']] = $name." [".$networkPort->getfield('name')."] (".$data['components_name'].")"; } else { $networkPort->getFromDB($data['networkports_id']); $elements[$data['id']."-".$data['services_id']] = $name." [".$networkPort->getfield('name')."] (".$data['components_name'].") > ".$device_connected; } } if (count($elements) > 1 AND count($elements2) > 0) { $elements = array_merge($elements,array('0'=>Dropdown::EMPTY_VALUE)); $elements = array_merge($elements, $elements2); } else { $elements = array_merge($elements, $elements2); } Dropdown::showFromArray('linksource', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Destination', 'monitoring')." :"; echo "</td>"; echo "<td>"; echo "<div id='nodedestination'>"; $query = "SELECT * FROM `".getTableForItemType("PluginMonitoringWeathermapnode")."` WHERE `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('plugin_monitoring_weathermapnodes_id_2', $elements); echo "</div>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth input', 'monitoring')." :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_in' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth output', 'monitoring')." :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_out' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"".__('Add')."\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Edit link echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $query = "SELECT `glpi_plugin_monitoring_weathermaplinks`.`id` as `id`, `itemtype`, `items_id`, `name`, `plugin_monitoring_weathermapnodes_id_2` FROM `glpi_plugin_monitoring_weathermaplinks` LEFT JOIN `glpi_plugin_monitoring_weathermapnodes` ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1` WHERE `plugin_monitoring_weathermaps_id` = '".$weathermaps_id."'"; $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name1 = $data['name']; if ($name1 == '') { $name1 = $item->getName(); } $pmWeathermapnode->getFromDB($data['plugin_monitoring_weathermapnodes_id_2']); $itemtype = $pmWeathermapnode->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmWeathermapnode->fields['items_id']); $name2 = $pmWeathermapnode->fields['name']; if ($name2 == '') { $name2 = $item->getName(); } $elements[$data['id']] = $name1." - ".$name2; } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update$rand", "show_updatelink$rand", $CFG_GLPI["root_doc"]."/plugins/monitoring/ajax/dropdownWlink.php", $params, TRUE); echo "<span id='show_updatelink$rand'></span>\n"; echo "</td>"; echo "</tr>"; // * Delete link echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Link', 'monitoring')." :"; echo "</td>"; echo "<td>"; Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"".__('Delete permanently')."\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "</td>"; echo "</tr>"; echo "</table>"; }
public function showItemFromPlugin($instID, $search = '') { global $DB, $CFG_GLPI; if (!$this->canView()) { return false; } $rand = mt_rand(); $PluginConnectionsConnection = new PluginConnectionsConnection(); if ($PluginConnectionsConnection->getFromDB($instID)) { $canedit = $PluginConnectionsConnection->can($instID, UPDATE); $query = "SELECT DISTINCT `itemtype`\n FROM `" . $this->getTable() . "`\n WHERE `plugin_connections_connections_id` = '" . (int) $instID . "'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } echo "<form method='post' name='connections_form{$rand}' id='connections_form{$rand}'\n action=\"" . $CFG_GLPI["root_doc"] . "/plugins/connections/front/connection.form.php\">"; echo "<div class='center'><table class='tab_cadrehov'>"; echo "<tr><th colspan='" . ($canedit ? 5 + $colsup : 4 + $colsup) . "'>" . __('Associated element') . ":</th></tr><tr>"; if ($canedit) { echo "<th> </th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Serial Number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $type = $DB->result($result, $i, "itemtype"); if (!class_exists($type)) { continue; } $item = new $type(); if ($item->canView()) { $column = "name"; $table = getTableForItemType($type); $itemTable = $this->getTable(); $entitiesRestrict = getEntitiesRestrictRequest(" AND ", 't', '', '', $item->maybeRecursive()); $mayBeTemplate = $item->maybeTemplate() ? " AND t.`is_template` = '0'" : ''; $query = "SELECT t.*, it.`id` AS items_id, `glpi_entities`.`ID` AS entity\n FROM `{$itemTable}` it, `{$table}` t\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = t.`entities_id`)\n WHERE t.`id` = it.`items_id`\n AND it.`itemtype` = '{$type}'\n AND it.`plugin_connections_connections_id` = '{$instID}'\n {$entitiesRestrict}\n {$mayBeTemplate}\n ORDER BY `glpi_entities`.`completename`, t.`{$column}`;"; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { Session::initNavigateListItems($type, __('Connections', 'connections') . " = " . $PluginConnectionsConnection->fields['name']); while ($data = $DB->fetch_assoc($result_linked)) { $item->getFromDB($data["id"]); Session::addToNavigateListItems($type, $data["id"]); $ID = $_SESSION["glpiis_ids_visible"] || empty($data["name"]) ? " (" . $data["id"] . ")" : ""; $link = Toolbox::getItemTypeFormURL($type); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $data["name"] . $ID . "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; $sel = isset($_GET["select"]) && "all" == $_GET["select"] ? "checked" : ""; echo "<input type='checkbox' name='item[" . $data["items_id"] . "]' value='1' " . $sel . ">"; echo "</td>"; } echo "<td class='center'>" . $item->getTypeName() . "</td>"; $is_deleted = isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : ""; echo "<td class='center' " . $is_deleted . ">" . $name . "</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_entities", $data['entity']); echo "</td>"; } echo "<td class='center'>"; echo isset($data["serial"]) ? $data["serial"] : "-"; echo "</td>"; echo "<td class='center'>"; echo isset($data["otherserial"]) ? $data["otherserial"] : "-"; echo "</td>"; echo "</tr>"; } } } } } if ($canedit) { echo "<tr class='tab_bg_1'><td colspan='" . (3 + $colsup) . "' class='center'>"; echo "<input type='hidden' name='plugin_connections_connections_id' value='{$instID}'>"; Dropdown::showAllItems("items_id", 0, 0, $PluginConnectionsConnection->fields['is_recursive'] ? -1 : $PluginConnectionsConnection->fields['entities_id'], $this->getClasses()); echo "</td>"; echo "<td colspan='2' class='center' class='tab_bg_2'>"; echo "<input type='submit' name='additem' value=\"" . __('Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table></div>"; Html::openArrowMassives("connections_form{$rand}"); Html::closeArrowMassives(array('deleteitem' => __('Delete'))); } else { echo "</table></div>"; } echo Html::closeForm(false); } }
/** * Show items links to a certificate * * @since version 0.84 * * @param $certificate PluginCertificatesCertificate object * * @return nothing (HTML display) **/ public static function showForCertificate(PluginCertificatesCertificate $certificate) { global $DB,$CFG_GLPI; // $certif=new PluginCertificatesCertificate(); $instID = $certificate->fields['id']; if (!$certificate->can($instID, READ)){ return false; } $canedit=$certificate->can($instID, UPDATE); $rand=mt_rand(); $query = "SELECT DISTINCT `itemtype` FROM `glpi_plugin_certificates_certificates_items` WHERE `plugin_certificates_certificates_id` = '".$instID."' ORDER BY `itemtype` LIMIT ".count(PluginCertificatesCertificate::getTypes(true)); $result = $DB->query($query); $number = $DB->numrows($result); if (Session::isMultiEntitiesMode()) { $colsup=1; } else { $colsup=0; } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form method='post' name='certificates_form$rand' id='certificates_form$rand' action='".Toolbox::getItemTypeFormURL("PluginCertificatesCertificate")."'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='".($canedit?(5+$colsup):(4+$colsup))."'>". __('Add an item')."</th></tr>"; echo "<tr class='tab_bg_1'><td colspan='".(3+$colsup)."' class='center'>"; Dropdown::showAllItems("items_id",0,0,($certificate->fields['is_recursive']?-1:$certificate->fields['entities_id']), PluginCertificatesCertificate::getTypes()); echo "</td><td colspan='2' class='center' class='tab_bg_1'>"; echo "<input type='hidden' name='plugin_certificates_certificates_id' value='$instID'>"; echo "<input type='submit' name='additem' value=\""._sx('button','Add')."\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>" ; } echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = array(); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number) { echo "<th width='10'>".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand)."</th>"; } echo "<th>".__('Type')."</th>"; echo "<th>".__('Name')."</th>"; if (Session::isMultiEntitiesMode()) echo "<th>".__('Entity')."</th>"; echo "<th>".__('Serial number')."</th>"; echo "<th>".__('Inventory number')."</th>"; echo "</tr>"; for ($i=0 ; $i < $number ; $i++) { $itemtype=$DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $column="name"; $itemTable = getTableForItemType($itemtype); $query = " SELECT `".$itemTable."`.*, `glpi_plugin_certificates_certificates_items`.`id` AS items_id, `glpi_entities`.id AS entity " ." FROM `glpi_plugin_certificates_certificates_items`, `".$itemTable ."` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `".$itemTable."`.`entities_id`) " ." WHERE `".$itemTable."`.`id` = `glpi_plugin_certificates_certificates_items`.`items_id` AND `glpi_plugin_certificates_certificates_items`.`itemtype` = '$itemtype' AND `glpi_plugin_certificates_certificates_items`.`plugin_certificates_certificates_id` = '$instID' " . getEntitiesRestrictRequest(" AND ",$itemTable,'','',$item->maybeRecursive()); if ($item->maybeTemplate()) { $query.=" AND ".$itemTable.".is_template='0'"; } $query.=" ORDER BY `glpi_entities`.`completename`, `".$itemTable."`.`$column` "; if ($result_linked=$DB->query($query)){ if ($DB->numrows($result_linked)) { Session::initNavigateListItems($itemtype,PluginCertificatesCertificate::getTypeName(2)." = ".$certificate->fields['name']); while ($data=$DB->fetch_assoc($result_linked)) { $item->getFromDB($data["id"]); Session::addToNavigateListItems($itemtype,$data["id"]); $ID=""; if ($_SESSION["glpiis_ids_visible"]||empty($data["name"])) $ID= " (".$data["id"].")"; $link=Toolbox::getItemTypeFormURL($itemtype); $name= "<a href=\"".$link."?id=".$data["id"]."\">" .$data["name"]."$ID</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["items_id"]); echo "</td>"; } echo "<td class='center'>".$item->getTypeName(1)."</td>"; echo "<td class='center' ".(isset($data['is_deleted'])&&$data['is_deleted']?"class='tab_bg_2_2'":""). ">".$name."</td>"; if (Session::isMultiEntitiesMode()) echo "<td class='center'>".Dropdown::getDropdownName("glpi_entities",$data['entity'])."</td>"; echo "<td class='center'>".(isset($data["serial"])? "".$data["serial"]."" :"-")."</td>"; echo "<td class='center'>".(isset($data["otherserial"])? "".$data["otherserial"]."" :"-")."</td>"; echo "</tr>"; } } } } } echo "</table>"; if ($canedit && $number) { $paramsma['ontop'] =false; Html::showMassiveActions($paramsma); Html::closeForm(); } echo "</div>"; }
function plugin_connections_MassiveActionsDisplay($options = array()) { $PluginConnectionsConnection = new PluginConnectionsConnection(); switch ($options['itemtype']) { case 'PluginConnectionsConnection': switch ($options['action']) { // No case for add_document : use GLPI core one case "plugin_connections_install": Dropdown::showAllItems("item_item", 0, 0, -1, PluginConnectionsConnection_Item::getClasses(true)); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . __('Post') . "\" >"; break; case "plugin_connections_desinstall": Dropdown::showAllItems("item_item", 0, 0, -1, PluginConnectionsConnection_Item::getClasses(true)); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . __('Post') . "\" >"; break; case "plugin_connections_transfert": Entity::dropdown(); echo " <input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . __('Post') . "\" >"; break; } break; } if (in_array($options['itemtype'], PluginConnectionsConnection_Item::getClasses(true))) { $PluginConnectionsConnection->dropdownConnections("plugin_connections_connections_id"); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . __('Post') . "\" >"; } return ""; }
case "unlock_ocsng_software": case "unlock_ocsng_printer": case "unlock_ocsng_disk": case "unlock_ocsng_ip": echo "<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>"; break; case "install": Software::dropdownSoftwareToInstall("softwareversions_id", $_SESSION["glpiactive_entity"], 1); echo " <input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][4] . "'>"; break; case "connect": Computer_Item::dropdownConnect('Computer', $_POST["itemtype"], "connect_item"); echo " <input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>"; break; case "connect_to_computer": Dropdown::showAllItems("connect_item", 0, 0, $_SESSION["glpiactive_entity"], array('Monitor', 'Peripheral', 'Phone', 'Printer'), true); echo " <input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>"; break; case "disconnect": echo "<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>"; break; case "add_group": Dropdown::show('Group'); echo " <input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>"; break; case "add_userprofile": Dropdown::show('Entity', array('entity' => $_SESSION['glpiactiveentities'])); echo ". " . $LANG['profiles'][22] . " : "; Profile::dropdownUnder(); echo ". " . $LANG['profiles'][28] . " : "; Dropdown::showYesNo("is_recursive", 0);
/** * Print the form for devices linked to a computer or a template * * @param $computer Computer object * @param $withtemplate='' boolean : template or basic computer * * @return Nothing (display) **/ static function showForComputer(Computer $computer, $withtemplate = '') { global $DB, $LANG; $devtypes = self::getDeviceTypes(); $ID = $computer->getField('id'); if (!$computer->can($ID, 'r')) { return false; } $canedit = $withtemplate != 2 && $computer->can($ID, 'w'); echo "<div class='spaced'>"; if ($canedit) { echo "<form name='form_device_action' action='" . getItemTypeFormURL(__CLASS__) . "' method='post'>"; echo "<input type='hidden' name='computers_id' value='{$ID}'>"; } echo "<table class='tab_cadre_fixe' >"; echo "<tr><th colspan='63'>" . $LANG['title'][30] . "</th></tr>"; $nb = 0; $specificity_units = array('DeviceProcessor' => $LANG['setup'][35], 'DeviceMemory' => $LANG['common'][82], 'DeviceHardDrive' => $LANG['common'][82], 'DeviceGraphicCard' => $LANG['common'][82]); foreach ($devtypes as $itemtype) { initNavigateListItems($itemtype, $computer->getTypeName() . " = " . $computer->getName()); $device = new $itemtype(); $specificities = $device->getSpecifityLabel(); $specif_fields = array_keys($specificities); $specif_text = implode(',', $specif_fields); if (!empty($specif_text)) { $specif_text = " ," . $specif_text . " "; } $linktable = getTableForItemType('Computer_' . $itemtype); $fk = getForeignKeyFieldForTable(getTableForItemType($itemtype)); $query = "SELECT COUNT(*) AS NB,\n `id`,\n `{$fk}`\n {$specif_text}\n FROM `{$linktable}`\n WHERE `computers_id` = '{$ID}'\n GROUP BY `{$fk}` {$specif_text}"; $prev = ''; foreach ($DB->request($query) as $data) { addToNavigateListItems($itemtype, $data[$fk]); if ($device->getFromDB($data[$fk])) { echo "<tr class='tab_bg_2'>"; echo "<td class='center'>"; Dropdown::showInteger("quantity_" . $itemtype . "_" . $data['id'], $data['NB']); echo "</td><td>"; if ($device->canCreate()) { echo "<a href='" . $device->getSearchURL() . "'>" . $device->getTypeName() . "</a>"; } else { echo $device->getTypeName(); } echo "</td><td>" . $device->getLink() . "</td>"; $spec = $device->getFormData(); if (isset($spec['label']) && count($spec['label'])) { $colspan = 60 / count($spec['label']); foreach ($spec['label'] as $i => $label) { if (isset($spec['value'][$i])) { echo "<td colspan='{$colspan}'>" . $spec['label'][$i] . " : "; echo $spec['value'][$i] . "</td>"; } else { if ($canedit) { // Specificity echo "<td class='right' colspan='{$colspan}'>" . $spec['label'][$i] . " : "; echo "<input type='text' name='value_" . $itemtype . "_" . $data['id'] . "' value='" . $data['specificity'] . "' size='" . $spec['size'] . "'>"; if (isset($specificity_units[$device->getType()])) { echo ' ' . $specificity_units[$device->getType()]; } echo "</td>"; } else { echo "<td colspan='{$colspan}'>" . $spec['label'][$i] . " : "; echo $data['specificity']; if (isset($specificity_units[$device->getType()])) { echo ' ' . $specificity_units[$device->getType()]; } echo "</td>"; } } } } else { echo "<td colspan='60'> </td>"; } echo "</tr>"; $nb++; } } } if ($canedit) { if ($nb > 0) { echo "<tr><td colspan='63' class='tab_bg_1 center'>"; echo "<input type='submit' class='submit' name='updateall' value='" . $LANG['buttons'][7] . "'></td></tr>"; } echo "<tr><td colspan='63' class='tab_bg_1 center'>"; echo $LANG['devices'][0] . " : "; Dropdown::showAllItems('items_id', '', 0, -1, $devtypes); echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</tr></table></form>"; } else { echo "</table>"; } echo "</div>"; }
static function showForSimcard(PluginSimcardSimcard $simcard) { global $DB, $LANG; if (!$simcard->can($simcard->getID(), 'r')) { return false; } $results = getAllDatasFromTable(getTableForItemType(__CLASS__), "`plugin_simcard_simcards_id` = '" . $simcard->getID() . "'"); echo "<div class='spaced'>"; echo "<form id='items' name='items' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='6'>" . $LANG['document'][19] . "</th></tr>"; if (!empty($results)) { echo "<tr><th></th>"; echo "<th>" . $LANG['common'][17] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['common'][19] . "</th>"; echo "<th>" . $LANG['common'][20] . "</th>"; echo "</tr>"; foreach ($results as $data) { $item = new $data['itemtype'](); $item->getFromDB($data['items_id']); echo "<tr>"; echo "<td>"; if (Session::haveRight('simcard', 'w')) { echo "<input type='checkbox' name='todelete[" . $data['id'] . "]'>"; } echo "</td>"; echo "<td>"; echo call_user_func(array($data['itemtype'], 'getTypeName')); echo "</td>"; echo "<td>"; echo Dropdown::getDropdownName('glpi_entities', $item->fields['entities_id']); echo "</td>"; echo "<td>"; echo $item->getLink(); echo "</td>"; echo "<td>"; echo $item->fields['serial']; echo "</td>"; echo "<td>"; echo $item->fields['otherserial']; echo "</td>"; echo "</tr>"; } } if (Session::haveRight('simcard', 'w')) { echo "<tr class='tab_bg_1'><td colspan='4' class='center'>"; if (empty($results)) { echo "<input type='hidden' name='plugin_simcard_simcards_id' value='" . $simcard->getID() . "'>"; Dropdown::showAllItems("items_id", 0, 0, $simcard->fields['entities_id'], self::getClasses()); echo "</td>"; echo "<td colspan='2' class='center' class='tab_bg_2'>"; echo "<input type='submit' name='additem' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td></tr>"; } if (!empty($results)) { Html::openArrowMassives('items'); Html::closeArrowMassives(array('delete_items' => $LANG['buttons'][10])); } } echo "</table>"; Html::closeForm(); echo "</div>"; }
/** * @see CommonDBTM::showSpecificMassiveActionsParameters() **/ function showSpecificMassiveActionsParameters($input = array()) { switch ($input['action']) { case "connect": if ($input['itemtype'] == 'Computer') { Dropdown::showAllItems("items_id", 0, 0, $_SESSION["glpiactive_entity"], array('Monitor', 'Peripheral', 'Phone', 'Printer'), true, true, 'item_itemtype'); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . __s('Connect') . "'>"; } else { Computer_Item::dropdownConnect('Computer', $input["itemtype"], "computers_id"); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . __s('Connect') . "'>"; } return true; case "disconnect": echo "<input type='submit' name='massiveaction' class='submit' value='" . __s('Disconnect') . "'>"; return true; default: return parent::showSpecificMassiveActionsParameters($input); } return false; }
/** * Display options add action button for massive actions * * @since version 0.84 * * This must not be overloaded in Class * * @param $input array of input datas * * @return nothing display **/ function showMassiveActionsParameters($input = array()) { global $CFG_GLPI; switch ($input['action']) { case "add_contract_item": if ($input['itemtype'] == 'Contract') { Dropdown::showAllItems("items_id", 0, 0, 1, $CFG_GLPI["contract_types"], false, true, 'item_itemtype'); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Add') . "'>"; } else { Contract::dropdown(array('name' => "contracts_id")); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Add') . "'>"; } break; case "remove_contract_item": if ($input['itemtype'] == 'Contract') { Dropdown::showAllItems("items_id", 0, 0, 1, $CFG_GLPI["contract_types"], false, true, 'item_itemtype'); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Delete permanently') . "'>"; } else { Contract::dropdown(array('name' => "contracts_id")); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Delete permanently') . "'>"; } break; case "add_document": Document::dropdown(array('name' => 'documents_id')); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Add') . "'>"; break; case "remove_document": Document::dropdown(array('name' => 'documents_id')); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Delete permanently') . "'>"; break; case "update": // Specific options for update fields if (isset($input['options'])) { $input['options'] = Toolbox::decodeArrayFromInput($input['options']); } else { $input['options'] = array(); } $first_group = true; $newgroup = ""; $items_in_group = 0; $show_all = true; $show_infocoms = true; if (in_array($input["itemtype"], $CFG_GLPI["infocom_types"]) && (!static::canUpdate() || !Infocom::canUpdate())) { $show_all = false; $show_infocoms = Infocom::canUpdate(); } $searchopt = Search::getCleanedOptions($input["itemtype"], 'w'); echo "<select name='id_field' id='massiveaction_field'>"; echo "<option value='0' selected>" . Dropdown::EMPTY_VALUE . "</option>"; foreach ($searchopt as $key => $val) { if (!is_array($val)) { if (!empty($newgroup) && $items_in_group > 0) { echo $newgroup; $first_group = false; } $items_in_group = 0; $newgroup = ""; if (!$first_group) { $newgroup .= "</optgroup>"; } $newgroup .= "<optgroup label=\"{$val}\">"; } else { // No id and no entities_id massive action and no first item if ($val["field"] != 'id' && $key != 1 && ($val["linkfield"] != 'entities_id' || isset($val['massiveaction']) && $val['massiveaction'])) { if (!isset($val['massiveaction']) || $val['massiveaction']) { if ($show_all) { $newgroup .= "<option value='{$key}'>" . $val["name"] . "</option>"; $items_in_group++; } else { // Do not show infocom items if ($show_infocoms && Search::isInfocomOption($input["itemtype"], $key) || !$show_infocoms && !Search::isInfocomOption($input["itemtype"], $key)) { $newgroup .= "<option value='{$key}'>" . $val["name"] . "</option>"; $items_in_group++; } } } } } } if (!empty($newgroup) && $items_in_group > 0) { echo $newgroup; } if (!$first_group) { echo "</optgroup>"; } echo "</select>"; $paramsmassaction = array('id_field' => '__VALUE__', 'itemtype' => $input["itemtype"], 'options' => $input['options']); foreach ($input as $key => $val) { if (preg_match("/extra_/", $key, $regs)) { $paramsmassaction[$key] = $val; } } Ajax::updateItemOnSelectEvent("massiveaction_field", "show_massiveaction_field", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveActionField.php", $paramsmassaction); echo "<br><br><span id='show_massiveaction_field'> </span>\n"; break; default: if (!$this->showSpecificMassiveActionsParameters($input)) { echo "<input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Post') . "'>\n"; } } return false; }
/** * @see CommonDBTM::showSpecificMassiveActionsParameters() **/ function showSpecificMassiveActionsParameters($input = array()) { global $CFG_GLPI; switch ($input['action']) { case "add_document_item": Dropdown::showAllItems("items_id", 0, 0, -1, $CFG_GLPI["document_types"], false, true, 'item_itemtype'); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Add') . "'>"; return true; case "remove_document_item": Dropdown::showAllItems("items_id", 0, 0, -1, $CFG_GLPI["document_types"], false, true, 'item_itemtype'); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Delete permanently') . "'>"; return true; default: return parent::showSpecificMassiveActionsParameters($input); } return false; }
function addHost($componentscatalogs_id) { global $DB, $LANG; $this->getEmpty(); $this->showFormHeader(); echo "<tr>"; echo "<td colspan='2'>"; echo $LANG['plugin_monitoring']['component'][1] . " :"; echo "<input type='hidden' name='plugin_monitoring_componentscalalog_id' value='" . $componentscatalogs_id . "'/>"; echo "<input type='hidden' name='is_static' value='1'/>"; echo "</td>"; echo "<td colspan='2'>"; Dropdown::showAllItems('items_id'); echo "</td>"; echo "</tr>"; $this->showFormButtons(); }
/** * Print the HTML array for Items linked to current contract * * @since version 0.84 * * @param $contract Contract object * * @return Nothing (display) **/ static function showForContract(Contract $contract) { global $DB, $CFG_GLPI; $instID = $contract->fields['id']; if (!$contract->can($instID, 'r')) { return false; } $canedit = $contract->can($instID, 'w'); $rand = mt_rand(); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_contracts_items`\n WHERE `glpi_contracts_items`.`contracts_id` = '{$instID}'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); $data = array(); $totalnb = 0; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $itemtable = getTableForItemType($itemtype); $query = "SELECT `{$itemtable}`.*,\n `glpi_contracts_items`.`id` AS IDD,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contracts_items`,\n `{$itemtable}`"; if ($itemtype != 'Entity') { $query .= " LEFT JOIN `glpi_entities`\n ON (`{$itemtable}`.`entities_id`=`glpi_entities`.`id`) "; } $query .= " WHERE `{$itemtable}`.`id` = `glpi_contracts_items`.`items_id`\n AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'\n AND `glpi_contracts_items`.`contracts_id` = '{$instID}'"; if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } $query .= getEntitiesRestrictRequest(" AND", $itemtable, '', '', $item->maybeRecursive()) . "\n ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`name`"; $result_linked = $DB->query($query); $nb = $DB->numrows($result_linked); if ($nb > $_SESSION['glpilist_limit']) { $link = "<a href='" . Toolbox::getItemTypeSearchURL($itemtype) . "?" . rawurlencode("contains[0]") . "=" . rawurlencode('$$$$' . $instID) . "&" . rawurlencode("field[0]") . "=29&sort=80&order=ASC&is_deleted=0" . "&start=0" . "'>" . __('Device list') . "</a>"; $data[$itemtype] = array('longlist' => true, 'name' => sprintf(__('%1$s: %2$s'), $item->getTypeName($nb), $nb), 'link' => $link); } else { if ($nb > 0) { for ($prem = true; $objdata = $DB->fetch_assoc($result_linked); $prem = false) { $data[$itemtype][$objdata['id']] = $objdata; } } } $totalnb += $nb; } } if ($canedit && ($contract->fields['max_links_allowed'] == 0 || $contract->fields['max_links_allowed'] > $totalnb)) { echo "<div class='firstbloc'>"; echo "<form name='contract_form{$rand}' id='contract_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='right'>"; Dropdown::showAllItems("items_id", 0, 0, $contract->fields['is_recursive'] ? -1 : $contract->fields['entities_id'], $CFG_GLPI["contract_types"], false, true); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "<input type='hidden' name='contracts_id' value='{$instID}'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $totalnb) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array(); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $totalnb) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "<th>" . __('Status') . "</th>"; echo "</tr>"; $totalnb = 0; foreach ($data as $itemtype => $datas) { if (isset($datas['longlist'])) { echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td> </td>"; } echo "<td class='center'>" . $datas['name'] . "</td>"; echo "<td class='center' colspan='2'>" . $datas['link'] . "</td>"; echo "<td class='center'>-</td><td class='center'>-</td></tr>"; } else { $prem = true; $nb = count($datas); foreach ($datas as $id => $objdata) { $name = $objdata["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $name = sprintf(__('%1$s (%2$s)'), $name, $objdata["id"]); } $link = Toolbox::getItemTypeFormURL($itemtype); $name = "<a href=\"" . $link . "?id=" . $objdata["id"] . "\">" . $name . "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $objdata["IDD"]); echo "</td>"; } if ($prem) { $item = new $itemtype(); $typename = $item->getTypeName($nb); echo "<td class='center top' rowspan='{$nb}'>" . ($nb > 1 ? sprintf(__('%1$s: %2$s'), $typename, $nb) : $typename) . "</td>"; $prem = false; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_entities", $objdata['entity']) . "</td>"; echo "<td class='center" . (isset($objdata['is_deleted']) && $objdata['is_deleted'] ? " tab_bg_2_2'" : "'"); echo ">" . $name . "</td>"; echo "<td class='center'>" . (isset($objdata["serial"]) ? "" . $objdata["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($objdata["otherserial"]) ? "" . $objdata["otherserial"] . "" : "-") . "</td>"; echo "<td class='center'>"; if (isset($objdata["states_id"])) { echo Dropdown::getDropdownName("glpi_states", $objdata['states_id']); } else { echo ' '; } echo "</td></tr>"; } } } echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='2'>" . ($totalnb > 0 ? sprintf(__('%1$s = %2$s'), __('Total'), $totalnb) : " "); echo "</td><td colspan='5'> </td></tr> "; echo "</table>"; if ($canedit && $number) { $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); Html::closeForm(); } echo "</div>"; }
function configureNodesLinks($weathermaps_id) { global $DB, $CFG_GLPI; $networkPort = new NetworkPort(); $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $this->getFromDB($weathermaps_id); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='2'>"; echo __('Nodes and links', 'monitoring'); echo "</th>"; echo "</tr>"; $this->generateWeathermap($weathermaps_id, 1, 1); $map = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=weathermap-" . $weathermaps_id . ".png'/>"; echo "<tr class='tab_bg_1'>"; echo "<td valign='top' width='10'>"; if ($this->fields['background'] == '') { echo '<script language="JavaScript" type="text/JavaScript"> function FindPosition(oElement) { if(typeof( oElement.offsetParent ) != "undefined") { for(var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) { posX += oElement.offsetLeft; posY += oElement.offsetTop; } return [ posX, posY ]; } else { return [ oElement.x, oElement.y ]; } } function GetCoordinates(e) { var PosX = 0; var PosY = 0; var ImgPos; ImgPos = FindPosition(myImg); if (!e) var e = window.event; if (e.pageX || e.pageY) { PosX = e.pageX; PosY = e.pageY; } else if (e.clientX || e.clientY) { PosX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; PosY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } PosX = PosX - ImgPos[0]; PosY = PosY - ImgPos[1]; document.pointform.x.value = PosX; document.pointform.y.value = PosY; } var myImg = document.getElementById("myImgId"); myImg.onmousedown = GetCoordinates; </script>'; echo "<div><img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=weathermap-" . $weathermaps_id . ".png'/>"; echo "<div style='position: absolute; top:40px;' id='myImgId' >\n <table class='gridweathermap' width='" . $this->fields['width'] . "' \n height='" . $this->fields['height'] . "'>"; $line = ''; $nbcol = ceil($this->fields['width'] / 15); for ($num = 0; $num < $nbcol; $num++) { $line .= "<td></td>"; } $line = '<tr>' . $line . '</tr>'; $nbline = ceil($this->fields['height'] / 15); for ($num = 0; $num < $nbline; $num++) { echo $line; } echo "</table></div></div>"; } else { echo '<div id="pointer_div" onclick="point_it(event)" style = "background-image:url(\'' . $this->fields['background'] . '\');"> <img id="cross" style="position:relative;visibility:hidden;z-index:2;"> ' . $map . '</div>'; echo '<script language="JavaScript"> function point_it(event){ pos_x = event.offsetX?(event.offsetX):event.pageX; pos_y = event.offsetY?(event.offsetY):event.pageY; document.getElementById("cross").style.left = (pos_x-1) ; document.getElementById("cross").style.top = (pos_y-15) ; var topValue= 0; var leftValue= 0; var obj = document.getElementById("pointer_div"); while(obj){ leftValue+= obj.offsetLeft; topValue+= obj.offsetTop; obj= obj.offsetParent; } document.pointform.x.value = pos_x-leftValue; document.pointform.y.value = pos_y-topValue; } </script>'; } echo "</td>"; echo "<td valign='top'>"; echo "<div style='position: fixed;top: 30px;right: 0;z-index:999;' >"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<td>"; echo "<a onClick='Ext.get(\"weathermapform\").toggle();'>\n <img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' /> \n " . __('Display weathermap form', 'monitoring') . "\n <img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' /></a>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "<div style='position: fixed;top: 50px;right: 0;z-index:1000;' id='weathermapform' >"; echo '<form name="pointform" method="post" action="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/weathermapnode.form.php">'; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<th colspan='2'>"; echo "x : "; echo '<input type="text" name="x" size="4" />'; echo " "; echo "y : "; echo '<input type="text" name="y" size="4" />'; echo "</th>"; echo "</tr>"; // * Add node echo "<tr>"; echo "<th colspan='2'>"; echo "<input type='hidden' name='plugin_monitoring_weathermaps_id' value='" . $weathermaps_id . "' />"; echo __('Add a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Node', 'monitoring') . " :"; echo "</td>"; echo "<td>"; Dropdown::showAllItems("items_id"); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Name') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='name' value='' />"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Change node position echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; if ($itemtype == '0') { $pmWeathermapnode->delete($data); } else { $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update{$rand}", "show_updatenode{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownWnode.php", $params, false); echo "<span id='show_updatenode{$rand}'></span>\n"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='update' value=\"" . __('Save') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Delete node echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "</td>"; echo "<td>"; $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"" . __('Delete permanently') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo '<form name="formlink" method="post" action="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/weathermaplink.form.php">'; echo "<table class='tab_cadre' width='100%'>"; // *Add Link echo "<tr>"; echo "<th colspan='2'>"; echo __('Add a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Source', 'monitoring') . "* :"; echo "</td>"; echo "<td>"; $query = "SELECT `glpi_plugin_monitoring_weathermapnodes`.`id` as `id`,\n `glpi_plugin_monitoring_weathermapnodes`.`name` as `name`,\n `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`, \n `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`,\n `glpi_plugin_monitoring_services`.`id` as `services_id`,\n `glpi_plugin_monitoring_components`.`name` as `components_name`,\n `plugin_monitoring_commands_id`, `glpi_plugin_monitoring_components`.`arguments`,\n `glpi_plugin_monitoring_services`.`networkports_id`\n FROM `glpi_plugin_monitoring_weathermapnodes`\n \n LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`\n ON (`glpi_plugin_monitoring_weathermapnodes`.`items_id`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`\n AND `glpi_plugin_monitoring_weathermapnodes`.`itemtype`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`)\n \n LEFT JOIN `glpi_plugin_monitoring_services` \n ON `plugin_monitoring_componentscatalogs_hosts_id`= `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n\n LEFT JOIN `glpi_plugin_monitoring_components` \n ON `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n \n\n WHERE `is_weathermap` = '1'\n AND `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `itemtype`,`items_id`,`glpi_plugin_monitoring_components`.`name`"; $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $elements2 = array(); $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } // Try to get device/node connected on this port $device_connected = ''; if ($data['arguments'] != '') { $arguments = importArrayFromDB($data['arguments']); foreach ($arguments as $argument) { if (!is_numeric($argument)) { if (strstr($argument, "[[NETWORKPORTDESCR]]")) { if (class_exists("PluginFusinvsnmpNetworkPort")) { $pfNetworkPort = new PluginFusinvsnmpNetworkPort(); $pfNetworkPort->loadNetworkport($data['networkports_id']); $argument = $pfNetworkPort->getValue("ifdescr"); } } elseif (strstr($argument, "[[NETWORKPORTNUM]]")) { $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $argument = $pfNetworkPort->fields['logical_number']; } elseif (strstr($argument, "[[NETWORKPORTNAME]]")) { $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $argument = $pfNetworkPort->fields['name']; } // Search networkport have this name or description $a_ports = $networkPort->find("`itemtype`='" . $itemtype . "'\n AND `items_id`='" . $data['items_id'] . "'\n AND `name`='" . $argument . "'"); foreach ($a_ports as $pdata) { if ($device_connected == '') { $oppositeports_id = $networkPort->getContact($pdata['id']); if ($oppositeports_id) { $networkPort->getFromDB($oppositeports_id); $a_nodes = $pmWeathermapnode->find("\n `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n AND `itemtype`='" . $networkPort->fields['itemtype'] . "'\n AND `items_id`='" . $networkPort->fields['items_id'] . "'", "", 1); if (count($a_nodes) > 0) { $a_node = current($a_nodes); $device_connected = $pmWeathermapnode->getNodeName($a_node['id']); } } } } if ($device_connected == '' and class_exists("PluginFusinvsnmpNetworkPort")) { $queryn = "SELECT `glpi_networkports`.`id` FROM `glpi_plugin_fusinvsnmp_networkports`\n \n LEFT JOIN `glpi_networkports`\n ON `glpi_networkports`.`id`=`networkports_id`\n \n WHERE `itemtype`='" . $itemtype . "'\n AND `items_id`='" . $data['items_id'] . "'\n AND `ifdescr`='" . $argument . "'"; $resultn = $DB->query($queryn); while ($pdata = $DB->fetch_array($resultn)) { if ($device_connected == '') { $oppositeports_id = $networkPort->getContact($pdata['id']); if ($oppositeports_id) { $networkPort->getFromDB($oppositeports_id); $a_nodes = $pmWeathermapnode->find("\n `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n AND `itemtype`='" . $networkPort->fields['itemtype'] . "'\n AND `items_id`='" . $networkPort->fields['items_id'] . "'", "", 1); if (count($a_nodes) > 0) { $a_node = current($a_nodes); $queryl = "SELECT `plugin_monitoring_weathermapnodes_id_1`\n FROM `glpi_plugin_monitoring_weathermaplinks`\n\n LEFT JOIN `glpi_plugin_monitoring_weathermapnodes`\n ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1`\n\n WHERE ((`plugin_monitoring_weathermapnodes_id_1`='" . $data['id'] . "'\n AND `plugin_monitoring_weathermapnodes_id_2`='" . $a_node['id'] . "')\n OR (`plugin_monitoring_weathermapnodes_id_1`='" . $a_node['id'] . "'\n AND `plugin_monitoring_weathermapnodes_id_2`='" . $data['id'] . "'))\n AND `plugin_monitoring_weathermaps_id` = '" . $weathermaps_id . "'"; $resultl = $DB->query($queryl); if ($DB->numrows($resultl) == '0') { $device_connected = $pmWeathermapnode->getNodeName($a_node['id']); } } } } } } } } } if ($device_connected == '') { $networkPort->getFromDB($data['networkports_id']); $elements2[$data['id'] . "-" . $data['services_id']] = $name . " [" . $networkPort->getfield('name') . "] (" . $data['components_name'] . ")"; } else { $networkPort->getFromDB($data['networkports_id']); $elements[$data['id'] . "-" . $data['services_id']] = $name . " [" . $networkPort->getfield('name') . "] (" . $data['components_name'] . ") > " . $device_connected; } } if (count($elements) > 1 and count($elements2) > 0) { $elements = array_merge($elements, array('0' => Dropdown::EMPTY_VALUE)); $elements = array_merge($elements, $elements2); } else { $elements = array_merge($elements, $elements2); } Dropdown::showFromArray('linksource', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Destination', 'monitoring') . " :"; echo "</td>"; echo "<td>"; echo "<div id='nodedestination'>"; $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('plugin_monitoring_weathermapnodes_id_2', $elements); echo "</div>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth input', 'monitoring') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_in' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth output', 'monitoring') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_out' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Edit link echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $query = "SELECT `glpi_plugin_monitoring_weathermaplinks`.`id` as `id`,\n `itemtype`, `items_id`, `name`, `plugin_monitoring_weathermapnodes_id_2`\n FROM `glpi_plugin_monitoring_weathermaplinks`\n \n LEFT JOIN `glpi_plugin_monitoring_weathermapnodes`\n ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1`\n\n WHERE `plugin_monitoring_weathermaps_id` = '" . $weathermaps_id . "'"; $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name1 = $data['name']; if ($name1 == '') { $name1 = $item->getName(); } $pmWeathermapnode->getFromDB($data['plugin_monitoring_weathermapnodes_id_2']); $itemtype = $pmWeathermapnode->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmWeathermapnode->fields['items_id']); $name2 = $pmWeathermapnode->fields['name']; if ($name2 == '') { $name2 = $item->getName(); } $elements[$data['id']] = $name1 . " - " . $name2; } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update{$rand}", "show_updatelink{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownWlink.php", $params, false); echo "<span id='show_updatelink{$rand}'></span>\n"; echo "</td>"; echo "</tr>"; // * Delete link echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "Link :"; echo "</td>"; echo "<td>"; Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"" . __('Delete permanently') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "</td>"; echo "</tr>"; }
/** * * Note : can separe code of view list * @param PluginTagTag $tag * @return boolean */ static function showForTag(PluginTagTag $tag) { global $DB; $instID = $tag->fields['id']; if (!$tag->can($instID, READ)) { return false; } $canedit = $tag->can($instID, UPDATE); $table = getTableForItemType(__CLASS__); $result = $DB->query("SELECT DISTINCT `itemtype`\n FROM `{$table}`\n WHERE `plugin_tag_tags_id` = '{$instID}'"); $result2 = $DB->query("SELECT `itemtype`, items_id\n FROM `{$table}`\n WHERE `plugin_tag_tags_id` = '{$instID}'"); $number = $DB->numrows($result); $rand = mt_rand(); if ($canedit) { echo "<div class='firstbloc'>"; //can use standart GLPI function $target = Toolbox::getItemTypeFormURL('PluginTagTag'); echo "<form name='tagitem_form{$rand}' id='tagitem_form{$rand}' method='post' action='" . $target . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='right'>"; //Note : this function is deprecated (and replace by an other) $itemtypes_to_show = self::getItemtypes($tag->fields['type_menu']); Dropdown::showAllItems("items_id", 0, 0, $tag->fields['is_recursive'] ? -1 : $tag->fields['entities_id'], $itemtypes_to_show, false, true); echo "<style>.select2-container { text-align: left; } </style>"; //minor echo "</td><td class='center'>"; echo "<input type='hidden' name='plugin_tag_tags_id' value='{$instID}'>"; //Note : can use standart GLPI method echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); Html::showMassiveActions(); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } $item_id = $DB->result($result2, $i, "items_id"); if ($item->canView()) { $column = strtolower(substr($itemtype, 0, 6)) == "device" ? "designation" : "name"; // For rules itemtypes (example : ruledictionnaryphonemodel) if (strtolower(substr($itemtype, 0, 4)) == 'rule' || $itemtype == "PluginResourcesRulechecklist") { $itemtable = getTableForItemType('Rule'); } else { $itemtable = getTableForItemType($itemtype); } $obj = new $itemtype(); $obj->getFromDB($item_id); $query = "SELECT `{$itemtable}`.*, `glpi_plugin_tag_tagitems`.`id` AS IDD, "; switch ($itemtype) { case 'KnowbaseItem': $query .= "-1 AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n " . KnowbaseItem::addVisibilityJoins() . "\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; break; case 'Profile': case 'RSSFeed': case 'Reminder': case 'Entity': //Possible to add (in code) condition to visibility : $query .= "-1 AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; break; default: if (isset($obj->fields['entities_id'])) { $query .= "`glpi_entities`.`id` AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`)\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; } else { $query .= "-1 AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; } break; } $query .= "`glpi_plugin_tag_tagitems`.`itemtype` = '{$itemtype}'\n AND `glpi_plugin_tag_tagitems`.`plugin_tag_tags_id` = '{$instID}' "; $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive()); if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } switch ($itemtype) { case 'KnowbaseItem': case 'Profile': case 'RSSFeed': case 'Reminder': case 'Entity': $query .= " ORDER BY `{$itemtable}`.`{$column}`"; break; default: if (isset($obj->fields['entities_id'])) { $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`"; } else { $query .= " ORDER BY `{$itemtable}`.`{$column}`"; } break; } if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { while ($data = $DB->fetch_assoc($result_linked)) { if ($itemtype == 'Softwarelicense') { $soft = new Software(); $soft->getFromDB($data['softwares_id']); $data["name"] .= ' - ' . $soft->getName(); //This add name of software } elseif ($itemtype == "PluginResourcesResource") { $data["name"] = formatUserName($data["id"], "", $data["name"], $data["firstname"]); } $linkname = $data[$column]; if ($_SESSION["glpiis_ids_visible"] || empty($data[$column])) { $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]); } $name = "<a href=\"" . Toolbox::getItemTypeFormURL($itemtype) . "?id=" . $data["id"] . "\">" . $linkname . "</a>"; if ($itemtype == 'PluginProjetProjet' || $itemtype == 'PluginResourcesResource') { $pieces = preg_split('/(?=[A-Z])/', $itemtype); $plugin_name = $pieces[2]; $datas = array("entities_id" => $data["entity"], "ITEM_0" => $data["name"], "ITEM_0_2" => $data["id"], "id" => $data["id"], "META_0" => $data["name"]); //for PluginResourcesResource if (isset($data["is_recursive"])) { $datas["is_recursive"] = $data["is_recursive"]; } Plugin::load(strtolower($plugin_name), true); $function_giveitem = 'plugin_' . strtolower($plugin_name) . '_giveItem'; if (function_exists($function_giveitem)) { // For security $name = call_user_func($function_giveitem, $itemtype, 1, $datas, 0); } } echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; if ($item->canUpdate()) { Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]); } echo "</td>"; } echo "<td class='center'>"; // Show plugin name (is to delete remove any ambiguity) : $pieces = preg_split('/(?=[A-Z])/', $itemtype); if ($pieces[1] == 'Plugin') { $plugin_name = $pieces[2]; if (function_exists("plugin_version_" . $plugin_name)) { // For security $tab = call_user_func("plugin_version_" . $plugin_name); echo $tab["name"] . " : "; } } echo $item->getTypeName(1) . "</td>"; echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; echo "<td class='center'>"; $entity = $data['entity']; //for Plugins : if ($data["entity"] == -1) { $item->getFromDB($data['id']); if (isset($item->fields["entities_id"])) { $entity = $item->fields["entities_id"]; } } echo Dropdown::getDropdownName("glpi_entities", $entity); echo "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } } } echo "</table>"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * @since version 0.84 * * @see CommonDBTM::showSpecificMassiveActionsParameters() **/ function showSpecificMassiveActionsParameters($input = array()) { global $CFG_GLPI; switch ($input['action']) { case "give": if (isset($input["entities_id"])) { Dropdown::showAllItems("give_items_id", 0, 0, $input["entities_id"], $CFG_GLPI["consumables_types"], false, false, 'give_itemtype'); echo "<br><br><input type='submit' class='submit' name='massiveaction' value='" . _sx('button', 'Give') . "'>"; return true; } default: return parent::showSpecificMassiveActionsParameters($input); } return false; }
/** * Display all the linked computers of a defined typology * *@param $typoID = typo ID. * *@return Nothing (displays) **/ public static function showForTypology(PluginTypologyTypology $typo) { global $DB, $CFG_GLPI; $typoID = $typo->fields['id']; if (!$typo->can($typoID, 'r')) { return false; } $canedit = $typo->can($typoID, 'w'); $canview = $typo->can($typoID, 'r'); $rand = mt_rand(); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_plugin_typology_typologies_items`\n WHERE `plugin_typology_typologies_id` = '{$typoID}'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form method='post' name='typologies_form{$rand}' id='typologies_form{$rand}' action='" . $CFG_GLPI["root_doc"] . "/plugins/typology/front/typology.form.php'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th colspan='7'>" . __('Add an item') . "</th></tr>"; echo "<tr class='tab_bg_1'><td colspan='4' class='center'>"; echo "<input type='hidden' name='plugin_typology_typologies_id' value='{$typoID}'>"; Dropdown::showAllItems("items_id", 0, 0, $typo->fields['is_recursive'] ? -1 : $typo->fields['entities_id'], PluginTypologyTypology::getTypes()); echo "</td>"; echo "<td colspan='3' class='center' class='tab_bg_2'>"; echo "<input type='submit' name='add_item' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array(); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th colspan='" . ($canedit ? 7 + $colsup : 6 + $colsup) . "'>"; if ($DB->numrows($result) == 0) { _e('No linked element', 'typology'); } else { _e('Linked elements', 'typology'); } echo "</th></tr><tr>"; if ($canedit && $number) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "<th>" . __('Responding to typology\'s criteria', 'typology') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($canview) { $column = "name"; $itemtable = getTableForItemType($itemtype); $query = "SELECT `" . $itemtable . "`.*,\n `glpi_plugin_typology_typologies_items`.`id` AS IDP,\n `glpi_plugin_typology_typologies_items`.`is_validated`,\n `glpi_plugin_typology_typologies_items`.`error`,\n `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_typology_typologies_items`, `" . $itemtable . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemtable . "`.`entities_id`) " . " WHERE `" . $itemtable . "`.`id` = `glpi_plugin_typology_typologies_items`.`items_id`\n AND `glpi_plugin_typology_typologies_items`.`itemtype` = '{$itemtype}'\n AND `glpi_plugin_typology_typologies_items`.`plugin_typology_typologies_id` = '{$typoID}'"; if ($itemtype != 'User') { $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive()); } if ($item->maybeTemplate()) { $query .= " AND " . $itemtable . ".is_template='0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $itemtable . "`.`{$column}` "; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { Session::initNavigateListItems($itemtype, PluginTypologyTypology::getTypeName(1) . " = " . $typo->fields['name']); while ($data = $DB->fetch_assoc($result_linked)) { $ID = ""; $item->getFromDB($data["id"]); Session::addToNavigateListItems($itemtype, $data["id"]); if ($itemtype == 'User') { $format = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], 1); } else { $format = $data["name"]; } if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $link = Toolbox::getItemTypeFormURL($itemtype); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $format; if ($itemtype != 'User') { $name .= " " . $ID; } $name .= "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["IDP"]); echo "</td>"; } echo "<input type='hidden' name='plugin_typology_typologies_id' value='{$typoID}'>"; echo "<td class='center'>" . $item->getTypeName() . "</td>"; echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; if (Session::isMultiEntitiesMode()) { if ($itemtype != 'User') { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>"; } else { echo "<td class='center'>-</td>"; } } echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; if ($data["is_validated"] > 0) { $critTypOK = __('Yes'); } else { $critTypOK = "<font color='red'>" . __('No') . " " . __('for the criteria', 'typology') . " "; $i = 0; $critTypOK .= self::displayErrors($data["error"]); $critTypOK .= "</font>"; } echo "<td class ='center'><b>" . $critTypOK . "</b></td>"; echo "</tr>"; } } } } } echo "</table>"; if ($canedit && $number) { $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); Html::closeForm(); } echo "</div>"; }
/** * Show items links to a document * * @return nothing (HTML display) **/ function showItems() { global $DB, $CFG_GLPI, $LANG; $instID = $this->fields['id']; if (!$this->can($instID, "r")) { return false; } $canedit = $this->can($instID, 'w'); // for a document, // don't show here others documents associated to this one, // it's done for both directions in self::showAssociated $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_documents_items`\n WHERE `glpi_documents_items`.`documents_id` = '{$instID}'\n AND `glpi_documents_items`.`itemtype` != 'Document'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); $rand = mt_rand(); echo "<form method='post' name='document_form{$rand}' id='document_form{$rand}' action='" . $CFG_GLPI["root_doc"] . "/front/document.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='" . ($canedit ? 6 : 5) . "'>"; if ($DB->numrows($result) == 0) { echo $LANG['document'][13]; } else { if ($DB->numrows($result) == 1) { echo $LANG['document'][14]; } else { echo $LANG['document'][19]; } } echo "</th></tr><tr>"; if ($canedit) { echo "<th> </th>"; } echo "<th>" . $LANG['common'][17] . "</th>"; echo "<th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['common'][19] . "</th>"; echo "<th>" . $LANG['common'][20] . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!class_exists($itemtype)) { continue; } $item = new $itemtype(); if ($item->canView()) { $column = "name"; if ($itemtype == 'Ticket') { $column = "id"; } if ($itemtype == 'KnowbaseItem') { $column = "question"; } $itemtable = getTableForItemType($itemtype); $query = "SELECT `{$itemtable}`.*,\n `glpi_documents_items`.`id` AS IDD, "; if ($itemtype == 'Entity') { // Left join because root entity not storeed $query .= "`glpi_documents_items`.`items_id` AS entity\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `glpi_documents_items`.`items_id`)\n WHERE "; } else { $query .= "`glpi_entities`.`id` AS entity\n FROM `glpi_documents_items`, `{$itemtable}`\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`)\n WHERE `{$itemtable}`.`id` = `glpi_documents_items`.`items_id`\n AND "; } $query .= "`glpi_documents_items`.`itemtype` = '{$itemtype}'\n AND `glpi_documents_items`.`documents_id` = '{$instID}' " . getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive()); if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`"; if ($itemtype == 'SoftwareLicense') { $soft = new Software(); } if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { while ($data = $DB->fetch_assoc($result_linked)) { $ID = ""; if ($itemtype == 'Entity' && !$data['entity']) { $data['id'] = 0; $data['name'] = $LANG['entity']['2']; } if ($itemtype == 'Ticket') { $data["name"] = $LANG['job'][38] . " " . $data["id"]; } if ($itemtype == 'KnowbaseItem') { $data["name"] = $data["question"]; } if ($itemtype == 'SoftwareLicense') { $soft->getFromDB($data['softwares_id']); $data["name"] = $data["name"] . ' - ' . $soft->fields['name']; } if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $link = getItemTypeFormURL($itemtype); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $data["name"] . "{$ID}</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } echo "<input type='checkbox' name='item[" . $data["IDD"] . "]' value='1' {$sel}>"; echo "</td>"; } echo "<td class='center'>" . $item->getTypeName() . "</td>"; echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']); echo "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } } } if ($canedit) { echo "<tr class='tab_bg_1'><td colspan='4' class='center'>"; echo "<input type='hidden' name='documents_id' value='{$instID}'>"; Dropdown::showAllItems("items_id", 0, 0, $this->fields['is_recursive'] ? -1 : $this->fields['entities_id'], $CFG_GLPI["document_types"]); echo "</td>"; echo "<td colspan='2' class='center'>"; echo "<input type='submit' name='adddocumentitem' value='" . $LANG['buttons'][8] . "' class='submit'>"; echo "</td></tr>"; echo "</table>"; openArrowMassive("document_form{$rand}", true); closeArrowMassive('deletedocumentitem', $LANG['buttons'][6]); } else { echo "</table>"; } echo "</div></form>"; }
/** * Form for Followup on Massive action **/ static function showFormMassiveAction($ma) { global $CFG_GLPI; switch ($ma->getAction()) { case 'add_item': Dropdown::showAllItems("items_id", 0, 0, $_SESSION['glpiactive_entity'], $CFG_GLPI["ticket_types"], false, true, 'item_itemtype'); echo "<br><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; break; case 'delete_item': Dropdown::showAllItems("items_id", 0, 0, $_SESSION['glpiactive_entity'], $CFG_GLPI["ticket_types"], false, true, 'item_itemtype'); echo "<br><input type='submit' name='delete' value=\"" . __('Delete permanently') . "\" class='submit'>"; break; } }
function addHost($componentscatalogs_id) { global $DB; if (!Session::haveRight("plugin_monitoring_componentscatalog", UPDATE)) { return; } $this->getEmpty(); $this->showFormHeader(); echo "<tr>"; echo "<td colspan='2'>"; echo __('Add a new component', 'monitoring') . " :"; echo "<input type='hidden' name='plugin_monitoring_componentscalalog_id' value='" . $componentscatalogs_id . "'/>"; echo "<input type='hidden' name='is_static' value='1'/>"; echo "</td>"; echo "<td colspan='2'>"; Dropdown::showAllItems('items_id'); echo "</td>"; echo "</tr>"; $this->showFormButtons(); }
/** * @since version 0.85 * * @see CommonDBTM::showMassiveActionsSubForm() **/ static function showMassiveActionsSubForm(MassiveAction $ma) { switch ($ma->getAction()) { case 'plugin_certificates_add_item': self::dropdownCertificate(array()); echo " " . Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')); return true; case "install": Dropdown::showAllItems("item_item", 0, 0, -1, self::getTypes(true), false, false, 'typeitem'); echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')); return true; break; case "uninstall": Dropdown::showAllItems("item_item", 0, 0, -1, self::getTypes(true), false, false, 'typeitem'); echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')); return true; break; case "transfer": Dropdown::show('Entity'); echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')); return true; break; } return parent::showMassiveActionsSubForm($ma); }
static function showForItem(CommonGLPI $item, $withtemplate = 0) { $ID = $item->getField('id'); if (!$item->can($ID, 'r')) { return false; } $canedit = $withtemplate != 2 && $item->can($ID, 'w'); echo "<div class='spaced'>"; $rand = mt_rand(); if ($canedit) { echo "\n<form id='form_device_action{$rand}' name='form_device_action{$rand}'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "' method='post'>\n"; echo "\t<input type='hidden' name='items_id' value='{$ID}'>\n"; echo "\t<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n"; } $table = new HTMLTableMain(); $table->setTitle(_n('Component', 'Components', 2)); if ($canedit) { $delete_all_column = $table->addHeader('delete all', Html::getCheckAllAsCheckbox("form_device_action{$rand}", '__RAND__')); $delete_all_column->setHTMLClass('center'); } else { $delete_all_column = NULL; } $common_column = $table->addHeader('common', __('Type of component')); $specific_column = $table->addHeader('specificities', __('Specificities')); $specific_column->setHTMLClass('center'); $dynamic_column = ''; if ($item->isDynamic()) { $dynamic_column = $table->addHeader('is_dynamic', __('Automatic inventory')); $dynamic_column->setHTMLClass('center'); } if ($canedit) { $content = "<input type='submit' class='submit' name='delete' value='" . _sx('button', 'Delete permanently') . "'>"; $delete_column = $table->addHeader('delete one', $content); $delete_column->setHTMLClass('center'); } else { $delete_column = NULL; } $table_options = array('canedit' => $canedit); $devtypes = array(); foreach (self::getDeviceTypes() as $link_type) { $devtypes[] = $link_type::getDeviceType(); $link_type::getTableGroup($item, $table, $table_options, $delete_all_column, $common_column, $specific_column, $delete_column, $dynamic_column); } if ($canedit) { echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><td>"; echo __('Add a new component') . "</td><td class=left width='70%'>"; Dropdown::showAllItems('devices_id', '', 0, -1, $devtypes, false, false, 'devicetype'); echo "</td><td>"; echo "<input type='submit' class='submit' name='add' value='" . _sx('button', 'Add') . "'>"; echo "</td></tr></table>"; } $table->display(array('display_super_for_each_group' => false, 'display_title_for_each_group' => false)); if ($canedit) { echo "<input type='submit' class='submit' name='updateall' value='" . _sx('button', 'Save') . "'>"; Html::closeForm(); } echo "</div>"; }
/** * Show items links to a webapplication * * @since version 0.84 * * @param $PluginWebapplicationsWebapplication PluginWebapplicationsWebapplication object * * @return nothing (HTML display) **/ static function showForWebapplication(PluginWebapplicationsWebapplication $webapplication) { global $DB, $CFG_GLPI; $instID = $webapplication->fields['id']; if (!$webapplication->can($instID, READ)) { return false; } $canedit = $webapplication->can($instID, UPDATE); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_plugin_webapplications_webapplications_items`\n WHERE `plugin_webapplications_webapplications_id` = '{$instID}'\n ORDER BY `itemtype` "; $result = $DB->query($query); $number = $DB->numrows($result); $rand = mt_rand(); if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='webapplicationitem_form{$rand}' id='webapplicationitem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL("PluginWebapplicationsWebapplication") . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='right'>"; Dropdown::showAllItems("items_id", 0, 0, $webapplication->fields['is_recursive'] ? -1 : $webapplication->fields['entities_id'], PluginWebapplicationsWebapplication::getTypes(), false, true); echo "</td><td class='center'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "<input type='hidden' name='plugin_webapplications_webapplications_id' value='{$instID}'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array(); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $column = "name"; if ($itemtype == 'Ticket') { $column = "id"; } $itemtable = getTableForItemType($itemtype); $query = "SELECT `{$itemtable}`.*,\n `glpi_plugin_webapplications_webapplications_items`.`id` AS IDD, "; if ($itemtype == 'KnowbaseItem') { $query .= "-1 AS entity\n FROM `glpi_plugin_webapplications_webapplications_items`, `{$itemtable}`\n " . KnowbaseItem::addVisibilityJoins() . "\n WHERE `{$itemtable}`.`id` = `glpi_plugin_webapplications_webapplications_items`.`items_id`\n AND "; } else { $query .= "`glpi_entities`.`id` AS entity\n FROM `glpi_plugin_webapplications_webapplications_items`, `{$itemtable}` "; if ($itemtype != 'Entity') { $query .= "LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`) "; } $query .= "WHERE `{$itemtable}`.`id` = `glpi_plugin_webapplications_webapplications_items`.`items_id`\n AND "; } $query .= "`glpi_plugin_webapplications_webapplications_items`.`itemtype` = '{$itemtype}'\n AND `glpi_plugin_webapplications_webapplications_items`.`plugin_webapplications_webapplications_id` = '{$instID}' "; if ($itemtype == 'KnowbaseItem') { if (Session::getLoginUserID()) { $where = "AND " . KnowbaseItem::addVisibilityRestrict(); } else { // Anonymous access if (Session::isMultiEntitiesMode()) { $where = " AND (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')"; } } } else { $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive()); } if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } if ($itemtype == 'KnowbaseItem') { $query .= " ORDER BY `{$itemtable}`.`{$column}`"; } else { $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`"; } if ($itemtype == 'SoftwareLicense') { $soft = new Software(); } if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { while ($data = $DB->fetch_assoc($result_linked)) { if ($itemtype == 'Ticket') { $data["name"] = sprintf(__('%1$s: %2$s'), __('Ticket'), $data["id"]); } if ($itemtype == 'SoftwareLicense') { $soft->getFromDB($data['softwares_id']); $data["name"] = sprintf(__('%1$s - %2$s'), $data["name"], $soft->fields['name']); } $linkname = $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]); } $link = Toolbox::getItemTypeFormURL($itemtype); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $linkname . "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]); echo "</td>"; } echo "<td class='center'>" . $item->getTypeName(1) . "</td>"; echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']); echo "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } } } echo "</table>"; if ($canedit && $number) { $paramsma['ontop'] = false; Html::showMassiveActions($paramsma); Html::closeForm(); } echo "</div>"; }
function showForm($ID, $options = array()) { $this->initForm($ID, $options); $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Name') . ": </td>"; echo "<td>"; Html::autocompletionTextField($this, "name"); echo "</td>"; echo "<td>" . __('Coordinate x', 'positions') . ": </td>"; echo "<td>"; if ($ID > 0) { Html::autocompletionTextField($this, "x_coordinates", array('size' => "10")); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Associated element') . ": </td>"; echo "<td>"; if ($ID < 0 || !$this->fields['itemtype'] && !$this->fields['items_id']) { $types = self::getTypes(); Dropdown::showAllItems("items_id", 0, 0, $this->fields['is_recursive'] ? -1 : $this->fields['entities_id'], self::getTypes()); } else { if ($this->fields['itemtype'] && $this->fields['items_id']) { if (class_exists($this->fields['itemtype'])) { $item = new $this->fields['itemtype'](); $item->getFromDB($this->fields['items_id']); echo $item->getTypeName() . " - "; echo $item->getLink() . " - "; echo Dropdown::getDropdownName("glpi_locations", $item->fields['locations_id']); } } } echo "</td>"; echo "<td>" . __('Coordinate y', 'positions') . ": </td>"; echo "<td>"; if ($ID > 0) { Html::autocompletionTextField($this, "y_coordinates", array('size' => "10")); } echo "</td>"; echo "</tr>"; $this->showFormButtons($options); return true; }
static function showForSimcard(PluginSimcardSimcard $simcard) { global $DB, $LANG; if (!$simcard->canView()) { return false; } $results = getAllDatasFromTable(getTableForItemType(__CLASS__), "`plugin_simcard_simcards_id` = '" . $simcard->getID() . "'"); echo "<div class='spaced'>"; echo "<form id='items' name='items' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='6'>" . __("Associated item") . "</th></tr>"; if (!empty($results)) { echo "<tr><th></th>"; echo "<th>" . __s("Type") . "</th>"; echo "<th>" . __s("Entity") . "</th>"; echo "<th>" . __s("Name") . "</th>"; echo "<th>" . __s("Serial number") . "</th>"; echo "<th>" . __s("Inventory number") . "</th>"; echo "</tr>"; foreach ($results as $data) { $item = new $data['itemtype'](); $item->getFromDB($data['items_id']); echo "<tr>"; echo "<td>"; if (PluginSimcardSimcard::canUpdate()) { echo "<input type='checkbox' name='todelete[" . $data['id'] . "]'>"; } echo "</td>"; echo "<td>"; echo call_user_func(array($data['itemtype'], 'getTypeName')); echo "</td>"; echo "<td>"; echo Dropdown::getDropdownName('glpi_entities', $item->fields['entities_id']); echo "</td>"; echo "<td>"; echo $item->getLink(); echo "</td>"; echo "<td>"; echo $item->fields['serial']; echo "</td>"; echo "<td>"; echo $item->fields['otherserial']; echo "</td>"; echo "</tr>"; } } if (PluginSimcardsimcard::canUpdate()) { echo "<tr class='tab_bg_1'><td colspan='4' class='center'>"; if (empty($results)) { echo "<input type='hidden' name='plugin_simcard_simcards_id' value='" . $simcard->getID() . "'>"; // TODO : Dropdown::showAllItems is deprecated, use Dropdown::showSelectItemFromItemtypes instead Dropdown::showAllItems("items_id", 0, 0, $simcard->fields['entities_id'], self::getClasses()); echo "</td>"; echo "<td colspan='2' class='center' class='tab_bg_2'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; } if (!empty($results)) { Html::openArrowMassives('items', true); Html::closeArrowMassives(array('delete_items' => _sx('button', 'Disconnect'))); } } echo "</table>"; Html::closeForm(); echo "</div>"; }
/** * Show the Device associated with an applicatif * * Called from the applicatif form **/ static function showForAppliance(PluginAppliancesAppliance $appli) { global $DB, $CFG_GLPI; $instID = $appli->fields['id']; if (!$appli->can($instID, "r")) { return false; } $rand = mt_rand(); $canedit = $appli->can($instID, 'w'); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_plugin_appliances_appliances_items`\n WHERE `plugin_appliances_appliances_id` = '" . $instID . "'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } echo "<form method='post' name='appliances_form{$rand}' id='appliances_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/appliances/front/appliance.form.php\">"; echo "<div class='center'><table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='" . ($canedit ? 6 + $colsup : 5 + $colsup) . "'>" . __('Associated items', 'appliances') . "</th></tr><tr>"; if ($canedit) { echo "<th> </th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } if ($appli->fields["relationtype"]) { echo "<th>" . __('Item to link', 'appliances') . "<br>" . __('User fields', 'appliances') . "</th>"; } echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $type = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($type))) { continue; } if ($item->canView()) { $column = "name"; if ($type == 'Ticket') { $column = "id"; } if ($type == 'KnowbaseItem') { $column = "question"; } $query = "SELECT `" . $item->getTable() . "`.*,\n `glpi_plugin_appliances_appliances_items`.`id` AS IDD,\n `glpi_entities`.`id` AS entity\n FROM `glpi_plugin_appliances_appliances_items`, " . getTableForItemType($type) . "\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `" . $item->getTable() . "`.`entities_id`)\n WHERE `" . $item->getTable() . "`.`id`\n = `glpi_plugin_appliances_appliances_items`.`items_id`\n AND `glpi_plugin_appliances_appliances_items`.`itemtype` = '" . $type . "'\n AND `glpi_plugin_appliances_appliances_items`.`plugin_appliances_appliances_id`\n = '" . $instID . "' " . getEntitiesRestrictRequest(" AND ", $item->getTable()); if ($item->maybeTemplate()) { $query .= " AND `" . $item->getTable() . "`.`is_template` = '0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $item->getTable() . "`.{$column}"; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { Session::initNavigateListItems($type, _n('Appliance', 'Appliances', 2, 'appliances') . "\n = " . $appli->getNameID()); while ($data = $DB->fetch_assoc($result_linked)) { $item->getFromDB($data["id"]); Session::addToNavigateListItems($type, $data["id"]); //TODO $ID never user - why this part ? $ID = ""; if ($type == 'Ticket') { $data["name"] = sprintf(__('%1$s %2$s'), __('Ticket'), $data["id"]); } if ($type == 'KnowbaseItem') { $data["name"] = $data["question"]; } if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $name = $item->getLink(); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } echo "<input type='checkbox' name='item[" . $data["IDD"] . "]' value='1' {$sel}>"; echo "</td>"; } echo "<td class='center'>" . $item->getTypeName() . "</td>"; echo "<td class='center' " . (isset($data['deleted']) && $data['deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>"; } if ($appli->fields["relationtype"]) { echo "<td class='center'>" . PluginAppliancesRelation::getTypeName($appli->fields["relationtype"]) . " : "; PluginAppliancesRelation::showList($appli->fields["relationtype"], $data["IDD"], $item->fields["entities_id"], false); PluginAppliancesOptvalue_Item::showList($type, $data["id"], $instID, false); echo "</td>"; } echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } } } if ($canedit) { echo "<tr class='tab_bg_1'><td colspan='" . (3 + $colsup) . "' class='center'>"; echo "<input type='hidden' name='conID' value='{$instID}'>"; Dropdown::showAllItems("item", 0, 0, $appli->fields['is_recursive'] ? -1 : $appli->fields['entities_id'], $appli->getTypes()); echo "</td>"; echo "<td colspan='3' class='center' class='tab_bg_2'>"; echo "<input type='submit' name='additem' value='" . __('Add') . "' class='submit'>"; echo "</td></tr>"; echo "</table></div>"; Html::openArrowMassives("appliances_form{$rand}", true); Html::closeArrowMassives(array('deleteitem' => __('Delete permanently'))); } else { echo "</table></div>"; } Html::closeForm(); }
/** * Print the HTML array for Items linked to a problem * * @param $problem Problem object * * @return Nothing (display) **/ static function showForProblem(Problem $problem) { global $DB, $CFG_GLPI; $instID = $problem->fields['id']; if (!$problem->can($instID, 'r')) { return false; } $canedit = $problem->can($instID, 'w'); $rand = mt_rand(); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_items_problems`\n WHERE `glpi_items_problems`.`problems_id` = '{$instID}'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='problemitem_form{$rand}' id='problemitem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='right'>"; $types = array(); foreach ($problem->getAllTypesForHelpdesk() as $key => $val) { $types[] = $key; } Dropdown::showAllItems("items_id", 0, 0, $problem->fields['is_recursive'] ? -1 : $problem->fields['entities_id'], $types); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "<input type='hidden' name='problems_id' value='{$instID}'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array(); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th></tr>"; $totalnb = 0; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $itemtable = getTableForItemType($itemtype); $query = "SELECT `{$itemtable}`.*,\n `glpi_items_problems`.`id` AS IDD,\n `glpi_entities`.`id` AS entity\n FROM `glpi_items_problems`,\n `{$itemtable}`"; if ($itemtype != 'Entity') { $query .= " LEFT JOIN `glpi_entities`\n ON (`{$itemtable}`.`entities_id`=`glpi_entities`.`id`) "; } $query .= " WHERE `{$itemtable}`.`id` = `glpi_items_problems`.`items_id`\n AND `glpi_items_problems`.`itemtype` = '{$itemtype}'\n AND `glpi_items_problems`.`problems_id` = '{$instID}'"; if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } $query .= getEntitiesRestrictRequest(" AND", $itemtable, '', '', $item->maybeRecursive()) . "\n ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`name`"; $result_linked = $DB->query($query); $nb = $DB->numrows($result_linked); for ($prem = true; $data = $DB->fetch_assoc($result_linked); $prem = false) { $name = $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]); } $link = Toolbox::getItemTypeFormURL($itemtype); $namelink = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $name . "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]); echo "</td>"; } if ($prem) { $typename = $item->getTypeName($nb); echo "<td class='center top' rowspan='{$nb}'>" . ($nb > 1 ? sprintf(__('%1$s: %2$s'), $typename, $nb) : $typename) . "</td>"; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>"; echo "<td class='center" . (isset($data['is_deleted']) && $data['is_deleted'] ? " tab_bg_2_2'" : "'"); echo ">" . $namelink . "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } $totalnb += $nb; } } echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='2'>" . ($totalnb > 0 ? sprintf(__('%1$s = %2$s'), __('Total'), $totalnb) : " "); echo "</td><td colspan='4'> </td></tr> "; echo "</table>"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show items links to a projet * * @since version 0.84 * * @param $projet PluginProjetProjet object * * @return nothing (HTML display) **/ public static function showForProjet(PluginProjetProjet $projet, $withtemplate = '', $material = false) { global $DB; $instID = $projet->fields['id']; if (!$projet->can($instID, 'r')) { return false; } $rand = mt_rand(); $canedit = $projet->can($instID, 'w'); if (empty($withtemplate)) { $withtemplate = 0; } if ($material) { $select = "'User','Group','Supplier','Contract'"; $in = "NOT IN"; } else { $select = "'User','Group','Supplier'"; $in = "IN"; } $query = "SELECT DISTINCT `itemtype` \n FROM `glpi_plugin_projet_projets_items` \n WHERE `plugin_projet_projets_id` = '{$instID}' \n AND `itemtype` {$in} (" . $select . ")\n ORDER BY `itemtype` \n LIMIT " . count(PluginProjetProjet::getTypes(true)); $result = $DB->query($query); $number = $DB->numrows($result); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($canedit && $withtemplate < 2) { echo "<div class='firstbloc'>"; echo "<form method='post' name='projet_form{$rand}' id='projet_form{$rand}'\n action='" . Toolbox::getItemTypeFormURL("PluginProjetProjet") . "'>"; echo "<table class='tab_cadre_fixe'>"; if ($material) { echo "<tr class='tab_bg_2'><th colspan='" . ($canedit ? 5 + $colsup : 4 + $colsup) . "'>" . __('Add an item') . "</th></tr>"; } else { echo "<tr class='tab_bg_2'><th colspan='" . ($canedit ? 5 + $colsup : 4 + $colsup) . "'>" . __('Add a participant', 'projet') . "</th></tr>"; } echo "<tr class='tab_bg_1'><td colspan='" . (3 + $colsup) . "' class='center'>"; echo "<input type='hidden' name='plugin_projet_projets_id' value='{$instID}'>"; if ($material) { $types = PluginProjetProjet::getTypes(); $trans = array_flip($types); unset($trans['User']); unset($trans['Group']); unset($trans['Supplier']); unset($trans['Contract']); $types = array_flip($trans); } else { $types[] = 'User'; $types[] = 'Group'; $types[] = 'Supplier'; } Dropdown::showAllItems("items_id", 0, 0, $projet->fields['is_recursive'] ? -1 : $projet->fields['entities_id'], $types); echo "</td>"; echo "<td colspan='2' class='tab_bg_2'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array(); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } if ($material) { echo "<th>" . __('Serial Number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; } echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemType = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemType))) { continue; } if ($item->canView()) { $column = "name"; $itemTable = getTableForItemType($itemType); $query = "SELECT `" . $itemTable . "`.*,\n `glpi_plugin_projet_projets_items`.`id` AS items_id,\n `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_projet_projets_items`, `" . $itemTable . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemTable . "`.`entities_id`) " . " WHERE `" . $itemTable . "`.`id` = `glpi_plugin_projet_projets_items`.`items_id`\n AND `glpi_plugin_projet_projets_items`.`itemtype` = '{$itemType}'\n AND `glpi_plugin_projet_projets_items`.`plugin_projet_projets_id` = '{$instID}' "; if ($itemType != 'User') { $query .= getEntitiesRestrictRequest(" AND ", $itemTable, '', '', $item->maybeRecursive()); } if ($item->maybeTemplate()) { $query .= " AND `" . $itemTable . "`.`is_template` = '0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $itemTable . "`.`{$column}`"; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { Session::initNavigateListItems($itemType, PluginProjetProjet::getTypeName(2) . " = " . $projet->fields['name']); while ($data = $DB->fetch_assoc($result_linked)) { $item->getFromDB($data["id"]); Session::addToNavigateListItems($itemType, $data["id"]); $ID = ""; if ($itemType == 'User') { $format = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], 1); } else { $format = $data["name"]; } if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $link = Toolbox::getItemTypeFormURL($itemType); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $format; if ($itemType != 'User') { $name .= " " . $ID; } $name .= "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["items_id"]); echo "</td>"; } echo "<td class='center'>" . $item::getTypeName(1) . "</td>"; echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; if (Session::isMultiEntitiesMode()) { if ($itemType != 'User') { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>"; } else { echo "<td class='center'>-</td>"; } } if ($material) { echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; } echo "</tr>"; } } } } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); Html::closeForm(); } echo "</div>"; }