/** * @see CommonGLPI::getTabNameForItem() **/ function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch ($item->getType()) { case 'User': if (!$withtemplate) { $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForUserLicense($item->getID()); } return array(1 => self::createTabEntry(SoftwareLicense::getTypeName(2), $nb)); } break; } return ''; }
/** * Display form to unlock fields and links * * @param CommonDBTM $item the source item **/ static function showForItem(CommonDBTM $item) { global $DB; $ID = $item->getID(); $itemtype = $item->getType(); $header = false; //If user doesn't have write right on the item, lock form must not be displayed if (!$item->canCreate()) { return false; } echo "<div width='50%'>"; echo "<form method='post' id='lock_form'\n name='lock_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<input type='hidden' name='id' value='{$ID}'>\n"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2''>" . __('Locked items') . "</th></tr>"; //Use a hook to allow external inventory tools to manage per field lock $results = Plugin::doHookFunction('display_locked_fields', array('item' => $item, 'header' => $header)); $header |= $results['header']; //Special locks for computers only if ($itemtype == 'Computer') { //Locks for items recorded in glpi_computers_items table $types = array('Monitor', 'Peripheral', 'Printer'); foreach ($types as $type) { $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID, 'itemtype' => $type); $params['FIELDS'] = array('id', 'items_id'); $first = true; foreach ($DB->request('glpi_computers_items', $params) as $line) { $tmp = new $type(); $tmp->getFromDB($line['items_id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='Computer_Item[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $tmp->getName() . "</td>"; echo "</tr>\n"; } } $types = array('ComputerDisk', 'ComputerVirtualMachine'); foreach ($types as $type) { $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID); $params['FIELDS'] = array('id', 'name'); $first = true; foreach ($DB->request(getTableForItemType($type), $params) as $line) { $header = true; if ($first) { echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='" . $type . "[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $line['name'] . "</td>"; echo "</tr>\n"; } } //Software versions $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID); $first = true; $query = "SELECT `csv`.`id` AS `id`,\n `sv`.`name` AS `version`,\n `s`.`name` AS `software`\n FROM `glpi_computers_softwareversions` AS csv\n LEFT JOIN `glpi_softwareversions` AS sv\n ON (`csv`.`softwareversions_id` = `sv`.`id`)\n LEFT JOIN `glpi_softwares` AS s\n ON (`sv`.`softwares_id` = `s`.`id`)\n WHERE `csv`.`is_deleted` = '1'\n AND `csv`.`is_dynamic` = '1'\n AND `csv`.`computers_id` = '{$ID}'"; foreach ($DB->request($query) as $line) { $header = true; if ($first) { echo "<tr><th colspan='2'>" . Software::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='Computer_SoftwareVersion[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>"; echo "</tr>\n"; } //Software licenses $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID); $first = true; $query = "SELECT `csv`.`id` AS `id`,\n `sv`.`name` AS `version`,\n `s`.`name` AS `software`\n FROM `glpi_computers_softwarelicenses` AS csv\n LEFT JOIN `glpi_softwarelicenses` AS sv\n ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n LEFT JOIN `glpi_softwares` AS s\n ON (`sv`.`softwares_id` = `s`.`id`)\n WHERE `csv`.`is_deleted` = '1'\n AND `csv`.`is_dynamic` = '1'\n AND `csv`.`computers_id` = '{$ID}'"; foreach ($DB->request($query) as $line) { $header = true; if ($first) { echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>"; echo "</tr>\n"; } } $first = true; $item = new NetworkPort(); $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype); $params['FIELDS'] = array('id'); foreach ($DB->request('glpi_networkports', $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $first = true; $item = new NetworkName(); $params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype); $params['FIELDS'] = array('glpi_networknames' => 'id'); foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $first = true; $item = new IPAddress(); $params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype); $params['FIELDS'] = array('glpi_ipaddresses' => 'id'); foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $types = Item_Devices::getDeviceTypes(); $nb = 0; foreach ($types as $old => $type) { $nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n AND `itemtype`='{$itemtype}'\n AND `is_dynamic`='1'\n AND `is_deleted`='1'"); } if ($nb) { $header = true; echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n"; foreach ($types as $old => $type) { $associated_type = str_replace('Item_', '', $type); $associated_table = getTableForItemType($associated_type); $fk = getForeignKeyFieldForTable($associated_table); $query = "SELECT `i`.`id`,\n `t`.`designation` AS `name`\n FROM `" . getTableForItemType($type) . "` AS i\n LEFT JOIN `{$associated_table}` AS t\n ON (`t`.`id` = `i`.`{$fk}`)\n WHERE `itemtype` = '{$itemtype}'\n AND `items_id` = '{$ID}'\n AND `is_dynamic` = '1'\n AND `is_deleted` = '1'"; foreach ($DB->request($query) as $data) { echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>"; echo "<td class='left' width='95%'>"; printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']); echo "</td></tr>\n"; } } } if ($header) { echo "</table>"; Html::openArrowMassives('lock_form', true); Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock'))); } else { echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>"; echo "</table>"; } Html::closeForm(); echo "</div>\n"; }
if ($license->restore($_POST)) { Event::log($_POST["id"], "software", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"])); } $license->redirectToList(); } else { if (isset($_POST["delete"])) { $license->check($_POST['id'], DELETE); $license->delete($_POST, 0); Event::log($license->fields['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s deletes the license %2$s'), $_SESSION["glpiname"], $_POST["id"])); $license->redirectToList(); } else { if (isset($_POST["purge"])) { $license->check($_POST['id'], PURGE); $license->delete($_POST, 1); Event::log($license->fields['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s purges the license %2$s'), $_SESSION["glpiname"], $_POST["id"])); $license->redirectToList(); } else { if (isset($_POST["update"])) { $license->check($_POST['id'], UPDATE); $license->update($_POST); Event::log($license->fields['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s updates the license %2$s'), $_SESSION["glpiname"], $_POST["id"])); Html::back(); } else { Html::header(SoftwareLicense::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "management", "softwarelicense"); $license->display($_REQUEST); Html::footer(); } } } } }
if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["softwares_id"])) { $_GET["softwares_id"] = ""; } $license = new SoftwareLicense(); if (isset($_POST["add"])) { $license->check(-1, 'w', $_POST); $newID = $license->add($_POST); Event::log($_POST['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s adds the license %2$s'), $_SESSION["glpiname"], $newID)); Html::back(); } else { if (isset($_POST["delete"])) { $license->check($_POST['id'], 'd'); $license->delete($_POST); Event::log($license->fields['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s deletes the license %2$s'), $_SESSION["glpiname"], $_POST["id"])); $license->redirectToList(); } else { if (isset($_POST["update"])) { $license->check($_POST['id'], 'w'); $license->update($_POST); Event::log($license->fields['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s updates the license %2$s'), $_SESSION["glpiname"], $_POST["id"])); Html::back(); } else { Html::header(SoftwareLicense::getTypeName(2), $_SERVER['PHP_SELF'], "inventory", "software"); $license->showForm($_GET["id"], array('softwares_id' => $_GET["softwares_id"])); Html::footer(); } } }
/** * Get search function for the class * * @since version 0.85 * * @return array of search option **/ function getSearchOptions() { $tab = parent::getSearchOptions(); $tab[21]['table'] = $this->getTable(); $tab[21]['field'] = 'is_visible_computer'; $tab[21]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Computer::getTypeName(Session::getPluralNumber())); $tab[21]['datatype'] = 'bool'; $tab[22]['table'] = $this->getTable(); $tab[22]['field'] = 'is_visible_softwareversion'; $tab[22]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), SoftwareVersion::getTypeName(Session::getPluralNumber())); $tab[22]['datatype'] = 'bool'; $tab[23]['table'] = $this->getTable(); $tab[23]['field'] = 'is_visible_monitor'; $tab[23]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Monitor::getTypeName(Session::getPluralNumber())); $tab[23]['datatype'] = 'bool'; $tab[24]['table'] = $this->getTable(); $tab[24]['field'] = 'is_visible_printer'; $tab[24]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Printer::getTypeName(Session::getPluralNumber())); $tab[24]['datatype'] = 'bool'; $tab[25]['table'] = $this->getTable(); $tab[25]['field'] = 'is_visible_peripheral'; $tab[25]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Peripheral::getTypeName(Session::getPluralNumber())); $tab[25]['datatype'] = 'bool'; $tab[26]['table'] = $this->getTable(); $tab[26]['field'] = 'is_visible_phone'; $tab[26]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Phone::getTypeName(Session::getPluralNumber())); $tab[26]['datatype'] = 'bool'; $tab[27]['table'] = $this->getTable(); $tab[27]['field'] = 'is_visible_networkequipment'; $tab[27]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), NetworkEquipment::getTypeName(Session::getPluralNumber())); $tab[27]['datatype'] = 'bool'; $tab[28]['table'] = $this->getTable(); $tab[28]['field'] = 'is_visible_softwarelicense'; $tab[28]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), SoftwareLicense::getTypeName(Session::getPluralNumber())); $tab[28]['datatype'] = 'bool'; return $tab; }
$_GET["softwares_id"] = ""; } $license = new SoftwareLicense(); if (isset($_POST["add"])) { $license->check(-1, CREATE, $_POST); if ($newID = $license->add($_POST)) { Event::log($_POST['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s adds the license %2$s'), $_SESSION["glpiname"], $newID)); if ($_SESSION['glpibackcreated']) { Html::redirect($license->getFormURL() . "?id=" . $newID); } } Html::back(); } else { if (isset($_POST["purge"])) { $license->check($_POST['id'], PURGE); $license->delete($_POST, 1); Event::log($license->fields['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s purges the license %2$s'), $_SESSION["glpiname"], $_POST["id"])); $license->redirectToList(); } else { if (isset($_POST["update"])) { $license->check($_POST['id'], UPDATE); $license->update($_POST); Event::log($license->fields['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s updates the license %2$s'), $_SESSION["glpiname"], $_POST["id"])); Html::back(); } else { Html::header(SoftwareLicense::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "assets", "software"); $license->display(array('id' => $_GET["id"], 'softwares_id' => $_GET["softwares_id"])); Html::footer(); } } }
/** * @see CommonGLPI::getTabNameForItem() **/ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($withtemplate || !self::isSoftwareTabActive($item)) { return ''; } $recordsCount = $_SESSION['glpishow_count_on_tabs'] ? self::countLicenses($item) : 0; return self::createTabEntry(SoftwareLicense::getTypeName(2) . ' - ' . User::getTypeName(2), $recordsCount); }