/** * Show Versions of a software * * @param $soft Software object * * @return nothing **/ static function showForSoftware(Software $soft) { global $DB, $CFG_GLPI; $softwares_id = $soft->getField('id'); if (!$soft->can($softwares_id, READ)) { return false; } $canedit = $soft->canEdit($softwares_id); echo "<div class='spaced'>"; if ($canedit) { echo "<div class='center firstbloc'>"; echo "<a class='vsubmit' href='softwareversion.form.php?softwares_id={$softwares_id}'>" . _x('button', 'Add a version') . "</a>"; echo "</div>"; } $query = "SELECT `glpi_softwareversions`.*,\n `glpi_states`.`name` AS sname\n FROM `glpi_softwareversions`\n LEFT JOIN `glpi_states` ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n WHERE `softwares_id` = '{$softwares_id}'\n ORDER BY `name`"; Session::initNavigateListItems('SoftwareVersion', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->getName())); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { echo "<table class='tab_cadre_fixehov'><tr>"; echo "<th>" . self::getTypeName(Session::getPluralNumber()) . "</th>"; echo "<th>" . __('Status') . "</th>"; echo "<th>" . __('Operating system') . "</th>"; echo "<th>" . _n('Installation', 'Installations', Session::getPluralNumber()) . "</th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>\n"; for ($tot = $nb = 0; $data = $DB->fetch_assoc($result); $tot += $nb) { Session::addToNavigateListItems('SoftwareVersion', $data['id']); $nb = Computer_SoftwareVersion::countForVersion($data['id']); echo "<tr class='tab_bg_2'>"; echo "<td><a href='softwareversion.form.php?id=" . $data['id'] . "'>"; echo $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a></td>"; echo "<td>" . $data['sname'] . "</td>"; echo "<td class='right'>" . Dropdown::getDropdownName('glpi_operatingsystems', $data['operatingsystems_id']); echo "</td>"; echo "<td class='numeric'>{$nb}</td>"; echo "<td>" . $data['comment'] . "</td></tr>\n"; } echo "<tr class='tab_bg_1 noHover'><td class='right b' colspan='3'>" . __('Total') . "</td>"; echo "<td class='numeric b'>{$tot}</td><td></td></tr>"; echo "</table>\n"; } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No item found') . "</th></tr>"; echo "</table>\n"; } } echo "</div>"; }
/** * Show Licenses of a software * * @param $software Software object * * @return nothing **/ static function showForSoftware(Software $software) { global $DB, $CFG_GLPI; $softwares_id = $software->getField('id'); $license = new self(); $computer = new Computer(); if (!$software->can($softwares_id, READ)) { return false; } $columns = array('name' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'number' => _x('quantity', 'Number'), '_affected' => __('Affected computers'), 'typename' => __('Type'), 'buyname' => __('Purchase version'), 'usename' => __('Version in use'), 'expire' => __('Expiration')); if (!$software->isRecursive()) { unset($columns['entity']); } if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) { $sort = "`" . $_GET["sort"] . "`"; } else { $sort = "`entity` {$order}, `name`"; } // Righ type is enough. Can add a License on a software we have Read access $canedit = Software::canUpdate(); $showmassiveactions = $canedit; // Total Number of events $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true)); echo "<div class='spaced'>"; Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $software->getName())); if ($canedit) { echo "<div class='center firstbloc'>"; echo "<a class='vsubmit' href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . _x('button', 'Add a license') . "</a>"; echo "</div>"; } $rand = mt_rand(); $query = "SELECT `glpi_softwarelicenses`.*,\n `buyvers`.`name` AS buyname,\n `usevers`.`name` AS usename,\n `glpi_entities`.`completename` AS entity,\n `glpi_softwarelicensetypes`.`name` AS typename\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_softwareversions` AS buyvers\n ON (`buyvers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_buy`)\n LEFT JOIN `glpi_softwareversions` AS usevers\n ON (`usevers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_use`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `glpi_softwarelicenses`.`entities_id`)\n LEFT JOIN `glpi_softwarelicensetypes`\n ON (`glpi_softwarelicensetypes`.`id`\n = `glpi_softwarelicenses`.`softwarelicensetypes_id`)\n WHERE (`glpi_softwarelicenses`.`softwares_id` = '{$softwares_id}') " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); if ($result = $DB->query($query)) { if ($num_displayed = $DB->numrows($result)) { // Display the pager Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number); if ($showmassiveactions) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $num_displayed, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('options' => array('glpi_softwareversions.name' => array('condition' => "`glpi_softwareversions`.`softwares_id`\n = {$softwares_id}"), 'glpi_softwarelicenses.name' => array('itemlink_as_string' => true)))); Html::showMassiveActions($massiveactionparams); } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr><th>"; $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end = ''; foreach ($columns as $key => $val) { // Non order column if ($key[0] == '_') { $header_end .= "<th>{$val}</th>"; } else { $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>"; } } $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; $tot_assoc = 0; for ($tot = 0; $data = $DB->fetch_assoc($result);) { Session::addToNavigateListItems('SoftwareLicense', $data['id']); $expired = true; if (is_null($data['expire']) || $data['expire'] > date('Y-m-d')) { $expired = false; } echo "<tr class='tab_bg_2" . ($expired ? '_2' : '') . "'>"; if ($license->canEdit($data['id'])) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } else { echo "<td> </td>"; } echo "<td><a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a></td>"; if (isset($columns['entity'])) { echo "<td>"; echo $data['entity']; echo "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td class='numeric'>" . ($data['number'] > 0 ? $data['number'] : __('Unlimited')) . "</td>"; $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']); $tot_assoc += $nb_assoc; $color = $data['is_valid'] ? 'green' : 'red'; echo "<td class='numeric {$color}'>" . $nb_assoc . "</td>"; echo "<td>" . $data['typename'] . "</td>"; echo "<td>" . $data['buyname'] . "</td>"; echo "<td>" . $data['usename'] . "</td>"; echo "<td class='center'>" . Html::convDate($data['expire']) . "</td>"; echo "</tr>"; if ($data['number'] < 0) { // One illimited license, total is illimited $tot = -1; } else { if ($tot >= 0) { // Expire license not count if (!$expired) { // Not illimited, add the current number $tot += $data['number']; } } } } echo "<tr class='tab_bg_1 noHover'>"; echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . __('Total') . "</td>"; echo "<td class='numeric'>" . ($tot > 0 ? $tot . "" : __('Unlimited')) . "</td>"; $color = $software->fields['is_valid'] ? 'green' : 'red'; echo "<td class='numeric {$color}'>" . $tot_assoc . "</td><td></td><td></td><td></td><td></td>"; echo "</tr>"; echo "</table>\n"; if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number); } else { echo "<table class='tab_cadre_fixe'><tr><th>" . __('No item found') . "</th></tr></table>"; } } echo "</div>"; }
/** * * 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>"; }