getTypeName() static public method

static public getTypeName ( $nb )
 static function pdfMain(PluginPdfSimplePDF $pdf, SoftwareLicense $license, $main = true, $cpt = true)
 {
     global $DB;
     $ID = $license->getField('id');
     $pdf->setColumnsSize(100);
     $entity = '';
     if (Session::isMultiEntitiesMode() && !$main) {
         $entity = ' (' . Html::clean(Dropdown::getDropdownName('glpi_entities', $license->fields['entities_id'])) . ')';
     }
     $pdf->displayTitle('<b><i>' . sprintf(__('%1$s: %2$s'), __('ID') . "</i>", $ID . "</b>" . $entity));
     $pdf->setColumnsSize(50, 50);
     $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), Software::getTypeName(1) . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_softwares', $license->fields['softwares_id']))), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Type') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_softwarelicensetypes', $license->fields['softwarelicensetypes_id']))));
     $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Name') . '</i></b>', $license->fields['name']), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Serial number') . '</i></b>', $license->fields['serial']));
     $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Purchase version') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_softwareversions', $license->fields['softwareversions_id_buy']))), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Inventory number') . '</i></b>', $license->fields['otherserial']));
     $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Version in use') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_softwareversions', $license->fields['softwareversions_id_use']))), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Expiration') . '</i></b>', Html::convDate($license->fields['expire'])));
     $col2 = '';
     if ($cpt) {
         $col2 = '<b><i>' . sprintf(__('%1$s: %2$s'), __('Affected computers') . '</i></b>', Computer_SoftwareLicense::countForLicense($ID));
     }
     $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), _x('quantity', 'Number') . '</i></b>', $license->fields['number'] > 0 ? $license->fields['number'] : __('Unlimited')), $col2);
     $pdf->setColumnsSize(100);
     PluginPdfCommon::mainLine($pdf, $license, 'comment');
     if ($main) {
         $pdf->displaySpace();
     }
 }
 /**
  * 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}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;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>&nbsp;</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>";
 }
Esempio n. 3
0
 /**
  * Make a select box for Ticket my devices
  *
  * @param $userID          User ID for my device section (default 0)
  * @param $entity_restrict restrict to a specific entity (default -1)
  * @param $itemtype        of selected item (default 0)
  * @param $items_id        of selected item (default 0)
  *
  * @return nothing (print out an HTML select box)
  **/
 static function dropdownMyDevices($userID = 0, $entity_restrict = -1, $itemtype = 0, $items_id = 0)
 {
     global $DB, $CFG_GLPI;
     if ($userID == 0) {
         $userID = Session::getLoginUserID();
     }
     $rand = mt_rand();
     $already_add = array();
     if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, self::HELPDESK_MY_HARDWARE)) {
         $my_devices = "";
         $my_item = $itemtype . '_' . $items_id;
         // My items
         foreach ($CFG_GLPI["linkuser_types"] as $itemtype) {
             if (($item = getItemForItemtype($itemtype)) && parent::isPossibleToAssignType($itemtype)) {
                 $itemtable = getTableForItemType($itemtype);
                 $query = "SELECT *\n                             FROM `{$itemtable}`\n                             WHERE `users_id` = '{$userID}'";
                 if ($item->maybeDeleted()) {
                     $query .= " AND `is_deleted` = '0' ";
                 }
                 if ($item->maybeTemplate()) {
                     $query .= " AND `is_template` = '0' ";
                 }
                 if (in_array($itemtype, $CFG_GLPI["helpdesk_visible_types"])) {
                     $query .= " AND `is_helpdesk_visible` = '1' ";
                 }
                 $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive()) . "\n                         ORDER BY `name` ";
                 $result = $DB->query($query);
                 $nb = $DB->numrows($result);
                 if ($DB->numrows($result) > 0) {
                     $type_name = $item->getTypeName($nb);
                     while ($data = $DB->fetch_assoc($result)) {
                         $output = $data["name"];
                         if (empty($output) || $_SESSION["glpiis_ids_visible"]) {
                             $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']);
                         }
                         $output = sprintf(__('%1$s - %2$s'), $type_name, $output);
                         if ($itemtype != 'Software') {
                             if (!empty($data['serial'])) {
                                 $output = sprintf(__('%1$s - %2$s'), $output, $data['serial']);
                             }
                             if (!empty($data['otherserial'])) {
                                 $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']);
                             }
                         }
                         $my_devices .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
                         $already_add[$itemtype][] = $data["id"];
                     }
                 }
             }
         }
         if (!empty($my_devices)) {
             $my_devices = "<optgroup label=\"" . __s('My devices') . "\">" . $my_devices . "</optgroup>";
         }
         // My group items
         if (Session::haveRight("show_group_hardware", "1")) {
             $group_where = "";
             $query = "SELECT `glpi_groups_users`.`groups_id`, `glpi_groups`.`name`\n                            FROM `glpi_groups_users`\n                            LEFT JOIN `glpi_groups`\n                              ON (`glpi_groups`.`id` = `glpi_groups_users`.`groups_id`)\n                            WHERE `glpi_groups_users`.`users_id` = '{$userID}' " . getEntitiesRestrictRequest("AND", "glpi_groups", "", $entity_restrict, true);
             $result = $DB->query($query);
             $first = true;
             if ($DB->numrows($result) > 0) {
                 while ($data = $DB->fetch_assoc($result)) {
                     if ($first) {
                         $first = false;
                     } else {
                         $group_where .= " OR ";
                     }
                     $a_groups = getAncestorsOf("glpi_groups", $data["groups_id"]);
                     $a_groups[$data["groups_id"]] = $data["groups_id"];
                     $group_where .= " `groups_id` IN (" . implode(',', $a_groups) . ") ";
                 }
                 $tmp_device = "";
                 foreach ($CFG_GLPI["linkgroup_types"] as $itemtype) {
                     if (($item = getItemForItemtype($itemtype)) && parent::isPossibleToAssignType($itemtype)) {
                         $itemtable = getTableForItemType($itemtype);
                         $query = "SELECT *\n                                    FROM `{$itemtable}`\n                                    WHERE ({$group_where}) " . getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive());
                         if ($item->maybeDeleted()) {
                             $query .= " AND `is_deleted` = '0' ";
                         }
                         if ($item->maybeTemplate()) {
                             $query .= " AND `is_template` = '0' ";
                         }
                         $result = $DB->query($query);
                         if ($DB->numrows($result) > 0) {
                             $type_name = $item->getTypeName();
                             if (!isset($already_add[$itemtype])) {
                                 $already_add[$itemtype] = array();
                             }
                             while ($data = $DB->fetch_assoc($result)) {
                                 if (!in_array($data["id"], $already_add[$itemtype])) {
                                     $output = '';
                                     if (isset($data["name"])) {
                                         $output = $data["name"];
                                     }
                                     if (empty($output) || $_SESSION["glpiis_ids_visible"]) {
                                         $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']);
                                     }
                                     $output = sprintf(__('%1$s - %2$s'), $type_name, $output);
                                     if (isset($data['serial'])) {
                                         $output = sprintf(__('%1$s - %2$s'), $output, $data['serial']);
                                     }
                                     if (isset($data['otherserial'])) {
                                         $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']);
                                     }
                                     $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
                                     $already_add[$itemtype][] = $data["id"];
                                 }
                             }
                         }
                     }
                 }
                 if (!empty($tmp_device)) {
                     $my_devices .= "<optgroup label=\"" . __s('Devices own by my groups') . "\">" . $tmp_device . "</optgroup>";
                 }
             }
         }
         // Get linked items to computers
         if (isset($already_add['Computer']) && count($already_add['Computer'])) {
             $search_computer = " XXXX IN (" . implode(',', $already_add['Computer']) . ') ';
             $tmp_device = "";
             // Direct Connection
             $types = array('Monitor', 'Peripheral', 'Phone', 'Printer');
             foreach ($types as $itemtype) {
                 if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]) && ($item = getItemForItemtype($itemtype))) {
                     $itemtable = getTableForItemType($itemtype);
                     if (!isset($already_add[$itemtype])) {
                         $already_add[$itemtype] = array();
                     }
                     $query = "SELECT DISTINCT `{$itemtable}`.*\n                            FROM `glpi_computers_items`\n                            LEFT JOIN `{$itemtable}`\n                                 ON (`glpi_computers_items`.`items_id` = `{$itemtable}`.`id`)\n                            WHERE `glpi_computers_items`.`itemtype` = '{$itemtype}'\n                                  AND  " . str_replace("XXXX", "`glpi_computers_items`.`computers_id`", $search_computer);
                     if ($item->maybeDeleted()) {
                         $query .= " AND `{$itemtable}`.`is_deleted` = '0' ";
                     }
                     if ($item->maybeTemplate()) {
                         $query .= " AND `{$itemtable}`.`is_template` = '0' ";
                     }
                     $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict) . "\n                            ORDER BY `{$itemtable}`.`name`";
                     $result = $DB->query($query);
                     if ($DB->numrows($result) > 0) {
                         $type_name = $item->getTypeName();
                         while ($data = $DB->fetch_assoc($result)) {
                             if (!in_array($data["id"], $already_add[$itemtype])) {
                                 $output = $data["name"];
                                 if (empty($output) || $_SESSION["glpiis_ids_visible"]) {
                                     $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']);
                                 }
                                 $output = sprintf(__('%1$s - %2$s'), $type_name, $output);
                                 if ($itemtype != 'Software') {
                                     $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']);
                                 }
                                 $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
                                 $already_add[$itemtype][] = $data["id"];
                             }
                         }
                     }
                 }
             }
             if (!empty($tmp_device)) {
                 $my_devices .= "<optgroup label=\"" . __s('Connected devices') . "\">" . $tmp_device . "</optgroup>";
             }
             // Software
             if (in_array('Software', $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) {
                 $query = "SELECT DISTINCT `glpi_softwareversions`.`name` AS version,\n                                `glpi_softwares`.`name` AS name, `glpi_softwares`.`id`\n                         FROM `glpi_computers_softwareversions`, `glpi_softwares`,\n                              `glpi_softwareversions`\n                         WHERE `glpi_computers_softwareversions`.`softwareversions_id` =\n                                   `glpi_softwareversions`.`id`\n                               AND `glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`\n                               AND " . str_replace("XXXX", "`glpi_computers_softwareversions`.`computers_id`", $search_computer) . "\n                               AND `glpi_softwares`.`is_helpdesk_visible` = '1' " . getEntitiesRestrictRequest("AND", "glpi_softwares", "", $entity_restrict) . "\n                         ORDER BY `glpi_softwares`.`name`";
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     $tmp_device = "";
                     $item = new Software();
                     $type_name = $item->getTypeName();
                     if (!isset($already_add['Software'])) {
                         $already_add['Software'] = array();
                     }
                     while ($data = $DB->fetch_assoc($result)) {
                         if (!in_array($data["id"], $already_add['Software'])) {
                             $output = sprintf(__('%1$s - %2$s'), $type_name, $data["name"]);
                             $output = sprintf(__('%1$s (%2$s)'), $output, sprintf(__('%1$s: %2$s'), __('version'), $data["version"]));
                             if ($_SESSION["glpiis_ids_visible"]) {
                                 $output = sprintf(__('%1$s (%2$s)'), $output, $data["id"]);
                             }
                             $tmp_device .= "<option title=\"{$output}\" value='Software_" . $data["id"] . "' " . ($my_item == 'Software' . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
                             $already_add['Software'][] = $data["id"];
                         }
                     }
                     if (!empty($tmp_device)) {
                         $my_devices .= "<optgroup label=\"" . _sn('Installed software', 'Installed software', 2) . "\">";
                         $my_devices .= $tmp_device . "</optgroup>";
                     }
                 }
             }
         }
         echo "<div id='tracking_my_devices'>";
         echo "<select id='my_items' name='_my_items'>";
         echo "<option value=''>--- ";
         echo __('General') . " ---</option>{$my_devices}</select></div>";
         // Auto update summary of active or just solved tickets
         $params = array('my_items' => '__VALUE__');
         Ajax::updateItemOnSelectEvent("my_items", "item_ticket_selection_information", $CFG_GLPI["root_doc"] . "/ajax/ticketiteminformation.php", $params);
     }
 }
Esempio n. 4
0
 /**
  * Make a select box for Ticket my devices
  *
  *
  * @param $userID User ID for my device section
  * @param $entity_restrict restrict to a specific entity
  * @param $itemtype of selected item
  * @param $items_id of selected item
  *
  * @return nothing (print out an HTML select box)
  **/
 static function dropdownMyDevices($userID = 0, $entity_restrict = -1, $itemtype = 0, $items_id = 0)
 {
     global $DB, $LANG, $CFG_GLPI;
     if ($userID == 0) {
         $userID = getLoginUserID();
     }
     $rand = mt_rand();
     $already_add = array();
     if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, HELPDESK_MY_HARDWARE)) {
         $my_devices = "";
         $my_item = $itemtype . '_' . $items_id;
         // My items
         foreach ($CFG_GLPI["linkuser_types"] as $itemtype) {
             if (class_exists($itemtype) && self::isPossibleToAssignType($itemtype)) {
                 $itemtable = getTableForItemType($itemtype);
                 $item = new $itemtype();
                 $query = "SELECT *\n                         FROM `{$itemtable}`\n                         WHERE `users_id` = '{$userID}'";
                 if ($item->maybeDeleted()) {
                     $query .= " AND `is_deleted` = '0' ";
                 }
                 if ($item->maybeTemplate()) {
                     $query .= " AND `is_template` = '0' ";
                 }
                 if (in_array($itemtype, $CFG_GLPI["helpdesk_visible_types"])) {
                     $query .= " AND `is_helpdesk_visible` = '1' ";
                 }
                 $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive());
                 "\n                         ORDER BY `name` ";
                 $result = $DB->query($query);
                 $nb = $DB->numrows($result);
                 if ($DB->numrows($result) > 0) {
                     $type_name = $item->getTypeName($nb);
                     while ($data = $DB->fetch_array($result)) {
                         $output = $data["name"];
                         if (empty($output) || $_SESSION["glpiis_ids_visible"]) {
                             $output .= " (" . $data['id'] . ")";
                         }
                         $output = $type_name . " - " . $output;
                         if ($itemtype != 'Software') {
                             if (!empty($data['serial'])) {
                                 $output .= " - " . $data['serial'];
                             }
                             if (!empty($data['otherserial'])) {
                                 $output .= " - " . $data['otherserial'];
                             }
                         }
                         $my_devices .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
                         $already_add[$itemtype][] = $data["id"];
                     }
                 }
             }
         }
         if (!empty($my_devices)) {
             $my_devices = "<optgroup label=\"" . $LANG['tracking'][1] . "\">" . $my_devices . "</optgroup>";
         }
         // My group items
         if (haveRight("show_group_hardware", "1")) {
             $group_where = "";
             $query = "SELECT `glpi_groups_users`.`groups_id`, `glpi_groups`.`name`\n                      FROM `glpi_groups_users`\n                      LEFT JOIN `glpi_groups`\n                           ON (`glpi_groups`.`id` = `glpi_groups_users`.`groups_id`)\n                      WHERE `glpi_groups_users`.`users_id` = '{$userID}' " . getEntitiesRestrictRequest("AND", "glpi_groups", "", $entity_restrict, true);
             $result = $DB->query($query);
             $first = true;
             if ($DB->numrows($result) > 0) {
                 while ($data = $DB->fetch_array($result)) {
                     if ($first) {
                         $first = false;
                     } else {
                         $group_where .= " OR ";
                     }
                     $group_where .= " `groups_id` = '" . $data["groups_id"] . "' ";
                 }
                 $tmp_device = "";
                 foreach ($CFG_GLPI["linkgroup_types"] as $itemtype) {
                     if (class_exists($itemtype) && self::isPossibleToAssignType($itemtype)) {
                         $itemtable = getTableForItemType($itemtype);
                         $item = new $itemtype();
                         $query = "SELECT *\n                               FROM `{$itemtable}`\n                               WHERE ({$group_where}) " . getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive());
                         if ($item->maybeDeleted()) {
                             $query .= " AND `is_deleted` = '0' ";
                         }
                         if ($item->maybeTemplate()) {
                             $query .= " AND `is_template` = '0' ";
                         }
                         $result = $DB->query($query);
                         if ($DB->numrows($result) > 0) {
                             $type_name = $item->getTypeName();
                             if (!isset($already_add[$itemtype])) {
                                 $already_add[$itemtype] = array();
                             }
                             while ($data = $DB->fetch_array($result)) {
                                 if (!in_array($data["id"], $already_add[$itemtype])) {
                                     $output = '';
                                     if (isset($data["name"])) {
                                         $output = $data["name"];
                                     }
                                     if (empty($output) || $_SESSION["glpiis_ids_visible"]) {
                                         $output .= " (" . $data['id'] . ")";
                                     }
                                     $output = $type_name . " - " . $output;
                                     if (isset($data['serial'])) {
                                         $output .= " - " . $data['serial'];
                                     }
                                     if (isset($data['otherserial'])) {
                                         $output .= " - " . $data['otherserial'];
                                     }
                                     $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
                                     $already_add[$itemtype][] = $data["id"];
                                 }
                             }
                         }
                     }
                 }
                 if (!empty($tmp_device)) {
                     $my_devices .= "<optgroup label=\"" . $LANG['tracking'][1] . " - " . $LANG['common'][35] . "\">" . $tmp_device . "</optgroup>";
                 }
             }
         }
         // Get linked items to computers
         if (isset($already_add['Computer']) && count($already_add['Computer'])) {
             $search_computer = " XXXX IN (" . implode(',', $already_add['Computer']) . ') ';
             $tmp_device = "";
             // Direct Connection
             $types = array('Peripheral', 'Monitor', 'Printer', 'Phone');
             foreach ($types as $itemtype) {
                 if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]) && class_exists($itemtype)) {
                     $itemtable = getTableForItemType($itemtype);
                     $item = new $itemtype();
                     if (!isset($already_add[$itemtype])) {
                         $already_add[$itemtype] = array();
                     }
                     $query = "SELECT DISTINCT `{$itemtable}`.*\n                            FROM `glpi_computers_items`\n                            LEFT JOIN `{$itemtable}`\n                                 ON (`glpi_computers_items`.`items_id` = `{$itemtable}`.`id`)\n                            WHERE `glpi_computers_items`.`itemtype` = '{$itemtype}'\n                                  AND  " . str_replace("XXXX", "`glpi_computers_items`.`computers_id`", $search_computer);
                     if ($item->maybeDeleted()) {
                         $query .= " AND `is_deleted` = '0' ";
                     }
                     if ($item->maybeTemplate()) {
                         $query .= " AND `is_template` = '0' ";
                     }
                     $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict) . "\n                            ORDER BY `{$itemtable}`.`name`";
                     $result = $DB->query($query);
                     if ($DB->numrows($result) > 0) {
                         $type_name = $item->getTypeName();
                         while ($data = $DB->fetch_array($result)) {
                             if (!in_array($data["id"], $already_add[$itemtype])) {
                                 $output = $data["name"];
                                 if (empty($output) || $_SESSION["glpiis_ids_visible"]) {
                                     $output .= " (" . $data['id'] . ")";
                                 }
                                 $output = $type_name . " - " . $output;
                                 if ($itemtype != 'Software') {
                                     $output .= " - " . $data['serial'] . " - " . $data['otherserial'];
                                 }
                                 $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
                                 $already_add[$itemtype][] = $data["id"];
                             }
                         }
                     }
                 }
             }
             if (!empty($tmp_device)) {
                 $my_devices .= "<optgroup label=\"" . $LANG['reports'][36] . "\">" . $tmp_device . "</optgroup>";
             }
             // Software
             if (in_array('Software', $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) {
                 $query = "SELECT DISTINCT `glpi_softwareversions`.`name` AS version,\n                                `glpi_softwares`.`name` AS name, `glpi_softwares`.`id`\n                         FROM `glpi_computers_softwareversions`, `glpi_softwares`,\n                              `glpi_softwareversions`\n                         WHERE `glpi_computers_softwareversions`.`softwareversions_id` =\n                                   `glpi_softwareversions`.`id`\n                               AND `glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`\n                               AND " . str_replace("XXXX", "`glpi_computers_softwareversions`.`computers_id`", $search_computer) . "\n                               AND `glpi_softwares`.`is_helpdesk_visible` = '1' " . getEntitiesRestrictRequest("AND", "glpi_softwares", "", $entity_restrict) . "\n                         ORDER BY `glpi_softwares`.`name`";
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     $tmp_device = "";
                     $item = new Software();
                     $type_name = $item->getTypeName();
                     if (!isset($already_add['Software'])) {
                         $already_add['Software'] = array();
                     }
                     while ($data = $DB->fetch_array($result)) {
                         if (!in_array($data["id"], $already_add['Software'])) {
                             $output = "{$type_name} - " . $data["name"] . " (v. " . $data["version"] . ")" . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["id"] . ")" : "");
                             $tmp_device .= "<option title=\"{$output}\" value='Software_" . $data["id"] . "' " . ($my_item == 'Software' . "_" . $data["id"] ? "selected" : "") . ">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
                             $already_add['Software'][] = $data["id"];
                         }
                     }
                     if (!empty($tmp_device)) {
                         $my_devices .= "<optgroup label=\"" . ucfirst($LANG['software'][17]) . "\">";
                         $my_devices .= $tmp_device . "</optgroup>";
                     }
                 }
             }
         }
         echo "<div id='tracking_my_devices'>";
         echo $LANG['tracking'][1] . "&nbsp;:&nbsp;<select id='my_items' name='_my_items'>";
         echo "<option value=''>--- ";
         echo $LANG['help'][30] . " ---</option>{$my_devices}</select></div>";
     }
 }
Esempio n. 5
0
based on GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2014 by the INDEPNET Development Team.

-------------------------------------------------------------------------

LICENSE

This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkRight("software", READ);
Html::header(Software::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "assets", "software");
Search::show('Software');
Html::footer();
Esempio n. 6
0
 /**
  * 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";
 }
 /**
  * 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 computers linked to a License
  *
  * @param $license SoftwareLicense object
  *
  * @return nothing
  **/
 static function showForLicense(SoftwareLicense $license)
 {
     global $DB, $CFG_GLPI;
     $searchID = $license->getField('id');
     if (!Software::canView() || !$searchID) {
         return false;
     }
     $canedit = Session::haveRightsOr("software", array(CREATE, UPDATE, DELETE, PURGE));
     $canshowcomputer = Computer::canView();
     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"])) {
         // manage several param like location,compname : order first
         $tmp = explode(",", $_GET["sort"]);
         $sort = "`" . implode("` {$order},`", $tmp) . "`";
     } else {
         $sort = "`entity` {$order}, `compname`";
     }
     //SoftwareLicense ID
     $query_number = "SELECT COUNT(*) AS cpt\n                       FROM `glpi_computers_softwarelicenses`\n                       INNER JOIN `glpi_computers`\n                           ON (`glpi_computers_softwarelicenses`.`computers_id`\n                                 = `glpi_computers`.`id`)\n                       WHERE `glpi_computers_softwarelicenses`.`softwarelicenses_id` = '{$searchID}'" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                             AND `glpi_computers`.`is_deleted` = '0'\n                             AND `glpi_computers`.`is_template` = '0'\n                             AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'";
     $number = 0;
     if ($result = $DB->query($query_number)) {
         $number = $DB->result($result, 0, 0);
     }
     echo "<div class='center'>";
     if ($canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>";
         echo "<input type='hidden' name='softwarelicenses_id' value='{$searchID}'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2 center'>";
         echo "<td>";
         Computer::dropdown(array('entity' => $license->fields['entities_id'], 'entity_sons' => $license->fields['is_recursive']));
         echo "</td>";
         echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
     }
     if ($number < 1) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . __('No item found') . "</th></tr>";
         echo "</table></div>\n";
         return;
     }
     // Display the pager
     Html::printAjaxPager(__('Affected computers'), $start, $number);
     $query = "SELECT `glpi_computers_softwarelicenses`.*,\n                       `glpi_computers`.`name` AS compname,\n                       `glpi_computers`.`id` AS cID,\n                       `glpi_computers`.`serial`,\n                       `glpi_computers`.`otherserial`,\n                       `glpi_users`.`name` AS username,\n                       `glpi_users`.`id` AS userid,\n                       `glpi_users`.`realname` AS userrealname,\n                       `glpi_users`.`firstname` AS userfirstname,\n                       `glpi_softwarelicenses`.`name` AS license,\n                       `glpi_softwarelicenses`.`id` AS vID,\n                       `glpi_softwarelicenses`.`name` AS vername,\n                       `glpi_entities`.`completename` AS entity,\n                       `glpi_locations`.`completename` AS location,\n                       `glpi_states`.`name` AS state,\n                       `glpi_groups`.`name` AS groupe,\n                       `glpi_softwarelicenses`.`name` AS lname,\n                       `glpi_softwarelicenses`.`id` AS lID,\n                       `glpi_softwarelicenses`.`softwares_id` AS softid\n                FROM `glpi_computers_softwarelicenses`\n                INNER JOIN `glpi_softwarelicenses`\n                     ON (`glpi_computers_softwarelicenses`.`softwarelicenses_id`\n                          = `glpi_softwarelicenses`.`id`)\n                INNER JOIN `glpi_computers`\n                     ON (`glpi_computers_softwarelicenses`.`computers_id` = `glpi_computers`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_computers`.`entities_id` = `glpi_entities`.`id`)\n                LEFT JOIN `glpi_locations`\n                     ON (`glpi_computers`.`locations_id` = `glpi_locations`.`id`)\n                LEFT JOIN `glpi_states` ON (`glpi_computers`.`states_id` = `glpi_states`.`id`)\n                LEFT JOIN `glpi_groups` ON (`glpi_computers`.`groups_id` = `glpi_groups`.`id`)\n                LEFT JOIN `glpi_users` ON (`glpi_computers`.`users_id` = `glpi_users`.`id`)\n                WHERE (`glpi_softwarelicenses`.`id` = '{$searchID}') " . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                       AND `glpi_computers`.`is_deleted` = '0'\n                       AND `glpi_computers`.`is_template` = '0'\n                       AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'\n                ORDER BY {$sort} {$order}\n                LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
     $rand = mt_rand();
     if ($result = $DB->query($query)) {
         if ($data = $DB->fetch_assoc($result)) {
             if ($canedit) {
                 $rand = mt_rand();
                 Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
                 $massiveactionparams = array('num_displayed' => $_SESSION['glpilist_limit'], 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
                 // show transfer only if multi licenses for this software
                 if (self::countLicenses($data['softid']) > 1) {
                     $massiveactionparams['specific_actions'][__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'move_license'] = _x('button', 'Move');
                 }
                 // Options to update license
                 $massiveactionparams['extraparams']['options']['move']['used'] = array($searchID);
                 $massiveactionparams['extraparams']['options']['move']['softwares_id'] = $license->fields['softwares_id'];
                 Html::showMassiveActions($massiveactionparams);
             }
             $soft = new Software();
             $soft->getFromDB($license->fields['softwares_id']);
             $showEntity = $license->isRecursive();
             $linkUser = User::canView();
             $text = sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->fields["name"]);
             $text = sprintf(__('%1$s - %2$s'), $text, $data["vername"]);
             Session::initNavigateListItems('Computer', $text);
             $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'>";
             $columns = array('compname' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'otherserial' => __('Inventory number'), 'location,compname' => __('Location'), 'state,compname' => __('Status'), 'groupe,compname' => __('Group'), 'username,compname' => __('User'));
             if (!$showEntity) {
                 unset($columns['entity']);
             }
             $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
             $header_begin = "<tr>";
             $header_top = '';
             $header_bottom = '';
             $header_end = '';
             if ($canedit) {
                 $header_begin .= "<th width='10'>";
                 $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                 $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                 $header_end .= "</th>";
             }
             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}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>{$val}</a></th>";
                 }
             }
             $header_end .= "</tr>\n";
             echo $header_begin . $header_top . $header_end;
             do {
                 Session::addToNavigateListItems('Computer', $data["cID"]);
                 echo "<tr class='tab_bg_2'>";
                 if ($canedit) {
                     echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
                 }
                 $compname = $data['compname'];
                 if (empty($compname) || $_SESSION['glpiis_ids_visible']) {
                     $compname = sprintf(__('%1$s (%2$s)'), $compname, $data['cID']);
                 }
                 if ($canshowcomputer) {
                     echo "<td><a href='computer.form.php?id=" . $data['cID'] . "'>{$compname}</a></td>";
                 } else {
                     echo "<td>" . $compname . "</td>";
                 }
                 if ($showEntity) {
                     echo "<td>" . $data['entity'] . "</td>";
                 }
                 echo "<td>" . $data['serial'] . "</td>";
                 echo "<td>" . $data['otherserial'] . "</td>";
                 echo "<td>" . $data['location'] . "</td>";
                 echo "<td>" . $data['state'] . "</td>";
                 echo "<td>" . $data['groupe'] . "</td>";
                 echo "<td>" . formatUserName($data['userid'], $data['username'], $data['userrealname'], $data['userfirstname'], $linkUser) . "</td>";
                 echo "</tr>\n";
             } while ($data = $DB->fetch_assoc($result));
             echo $header_begin . $header_bottom . $header_end;
             echo "</table>\n";
             if ($canedit) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($massiveactionparams);
                 Html::closeForm();
             }
         } else {
             // Not found
             _e('No item found');
         }
     }
     // Query
     Html::printAjaxPager(__('Affected computers'), $start, $number);
     echo "</div>\n";
 }
Esempio n. 9
0
        $soft->check($_POST["id"], 'd');
        $soft->delete($_POST);
        Event::log($_POST["id"], "software", 4, "inventory", sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
        $soft->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $soft->check($_POST["id"], 'd');
            $soft->restore($_POST);
            Event::log($_POST["id"], "software", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
            $soft->redirectToList();
        } else {
            if (isset($_POST["purge"])) {
                $soft->check($_POST["id"], 'd');
                $soft->delete($_POST, 1);
                Event::log($_POST["id"], "software", 4, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
                $soft->redirectToList();
            } else {
                if (isset($_POST["update"])) {
                    $soft->check($_POST["id"], 'w');
                    $soft->update($_POST);
                    Event::log($_POST["id"], "software", 4, "inventory", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
                    Html::back();
                } else {
                    Html::header(Software::getTypeName(2), $_SERVER['PHP_SELF'], "inventory", "software");
                    $soft->showForm($_GET["id"], array('withtemplate' => $_GET["withtemplate"]));
                    Html::footer();
                }
            }
        }
    }
}
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     switch ($item->getType()) {
         case 'Software':
             if (!$withtemplate) {
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), self::countForSoftware($item->getID()));
                 }
                 return self::getTypeName(Session::getPluralNumber());
             }
             break;
         case 'SoftwareVersion':
             if (!$withtemplate) {
                 $nb = 0;
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     $nb = self::countForVersion($item->getID());
                 }
                 return array(1 => __('Summary'), 2 => self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb));
             }
             break;
         case 'Computer':
             // Installation allowed for template
             if (Software::canView()) {
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     return self::createTabEntry(Software::getTypeName(Session::getPluralNumber()), countElementsInTable('glpi_computers_softwareversions', "computers_id = '" . $item->getID() . "'\n                                                                      AND `is_deleted`='0'"));
                 }
                 return Software::getTypeName(Session::getPluralNumber());
             }
             break;
     }
     return '';
 }
Esempio n. 11
0
 /**
  * Show users linked to a License
  *
  * @param $license SoftwareLicense object
  *
  * @return nothing
  **/
 static function showForLicense(SoftwareLicense $license)
 {
     global $DB, $CFG_GLPI;
     $searchID = $license->getField('id');
     if (!Software::canView() || !$searchID) {
         return false;
     }
     $canedit = PluginFpsoftwareVersionhelper::checkRights("software", array(CREATE, UPDATE, DELETE, PURGE), "Or");
     $canshowuser = User::canView();
     if (isset($_GET["start"])) {
         $start = $_GET["start"];
     } else {
         $start = 0;
     }
     if (isset($_GET["order"]) && $_GET["order"] == "DESC") {
         $order = "DESC";
     } else {
         $order = "ASC";
     }
     //SoftwareLicense ID
     $query_number = "SELECT COUNT(*) AS cpt\n                       FROM `glpi_users_softwarelicenses`\n                       INNER JOIN `glpi_users`\n                           ON (`glpi_users_softwarelicenses`.`users_id`\n                                 = `glpi_users`.`id`)\n                       WHERE `glpi_users_softwarelicenses`.`softwarelicenses_id` = '{$searchID}'";
     $number = 0;
     if ($result = $DB->query($query_number)) {
         $number = $DB->result($result, 0, 0);
     }
     echo "<div class='center'>";
     if ($canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . self::$front_url . "/front/user_softwarelicense.form.php'>";
         echo "<input type='hidden' name='softwarelicenses_id' value='{$searchID}'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2 center'>";
         echo "<td>";
         //FOR NOW ALL USERS ARE SHOWN, DON'T KNOW IF THERE SHOULD BE ANY RESTRICTION.
         //ALSO IT CAUSES A POSSIBILITY TO ONE USER MANY TIMES.
         User::dropdown(array('right' => 'all'));
         echo "</td>";
         echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
     }
     if ($number < 1) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . __('No item found') . "</th></tr>";
         echo "</table></div>\n";
         return;
     }
     // Display the pager
     Html::printAjaxPager(__('Affected users'), $start, $number);
     $query = "SELECT `glpi_users_softwarelicenses`.*,\n                       `glpi_users`.`name` AS username,\n                       `glpi_users`.`id` AS userid,\n                       `glpi_users`.`realname` AS userrealname,\n                       `glpi_users`.`firstname` AS userfirstname,\n                       `glpi_softwarelicenses`.`name` AS license,\n                       `glpi_softwarelicenses`.`id` AS lID\n                FROM `glpi_users_softwarelicenses`\n                INNER JOIN `glpi_softwarelicenses`\n                     ON (`glpi_users_softwarelicenses`.`softwarelicenses_id`\n                          = `glpi_softwarelicenses`.`id`)\n                INNER JOIN `glpi_users`\n                     ON (`glpi_users_softwarelicenses`.`users_id` = `glpi_users`.`id`)\n                WHERE `glpi_softwarelicenses`.`id` = '{$searchID}'\n                LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
     $rand = mt_rand();
     if ($result = $DB->query($query)) {
         if ($data = $DB->fetch_assoc($result)) {
             if ($canedit) {
                 $rand = mt_rand();
                 Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
                 list($higher_version, $massiveactionparams) = PluginFpsoftwareVersionhelper::massiveActionParams($rand, __CLASS__);
                 // Options to update license
                 $massiveactionparams['extraparams']['options']['move']['used'] = array($searchID);
                 $massiveactionparams['extraparams']['options']['move']['softwares_id'] = $license->fields['softwares_id'];
                 Html::showMassiveActions($higher_version ? $massiveactionparams : __CLASS__, $massiveactionparams);
             }
             $soft = new Software();
             $soft->getFromDB($license->fields['softwares_id']);
             $text = sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->fields["name"]);
             $text = sprintf(__('%1$s - ID %2$s'), $text, $license->fields['softwares_id']);
             Session::initNavigateListItems('User', $text);
             echo "<table class='tab_cadre_fixehov'>";
             $columns = array('username' => __('Username'), 'userrealname' => __('Surname'), 'userfirstname' => __('First name'), 'added' => __('Added'));
             $header_begin = "<tr>";
             $header_top = '';
             $header_bottom = '';
             $header_end = '';
             if ($canedit) {
                 $header_begin .= "<th width='10'>";
                 $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                 $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                 $header_end .= "</th>";
             }
             foreach ($columns as $key => $val) {
                 // Non order column
                 $header_end .= "<th>{$val}</th>";
             }
             $header_end .= "</tr>\n";
             echo $header_begin . $header_top . $header_end;
             do {
                 Session::addToNavigateListItems('User', $data["userid"]);
                 echo "<tr class='tab_bg_2'>";
                 if ($canedit) {
                     echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
                 }
                 if ($canshowuser) {
                     echo "<td><a href='user.form.php?id=" . $data['userid'] . "'>" . $data['username'] . "</a></td>";
                 } else {
                     echo "<td>" . $data['username'] . "</td>";
                 }
                 echo "<td>" . $data['userrealname'] . "</td>";
                 echo "<td>" . $data['userfirstname'] . "</td>";
                 echo "<td style=\"text-align:center;\">" . $data['added'] . "</td>";
                 echo "</tr>\n";
             } while ($data = $DB->fetch_assoc($result));
             echo $header_begin . $header_bottom . $header_end;
             echo "</table>\n";
             if ($canedit) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($massiveactionparams);
                 Html::closeForm();
             }
         } else {
             // Not found
             _e('No item found');
         }
     }
     // Query
     Html::printAjaxPager(__('Affected users'), $start, $number);
     echo "</div>\n";
 }