/**
  * @since version 0.84
  *
  * @see CommonDBTM::getPreAdditionalInfosForName
  **/
 function getPreAdditionalInfosForName()
 {
     $soft = new Software();
     if ($soft->getFromDB($this->fields['softwares_id'])) {
         return $soft->getName();
     }
     return '';
 }
 function post_deleteFromDB()
 {
     $vers = new SoftwareVersion();
     if (!$vers->getFromDB($this->fields['softwareversions_id'])) {
         return false;
     }
     /// Could not be possible : because several computers may be linked to a version
     // Update affected licenses
     //       $lic = new SoftwareLicense();
     //       $query = "SELECT `id`
     //                 FROM `glpi_softwarelicenses`
     //                 WHERE `softwares_id` = '".$vers->fields['softwares_id']."'
     //                   AND `computers_id` = '".$this->fields['computers_id']."'
     //                   AND `softwareversions_id_use` = '".$this->fields['softwareversions_id']."'";
     //       foreach ($DB->request($query) as $data) {
     //          $data['softwareversions_id_use'] = 0;
     //          $lic->update($data);
     //       }
     if (isset($this->input['_no_history']) && $this->input['_no_history']) {
         return false;
     }
     $soft = new Software();
     if ($soft->getFromDB($vers->fields['softwares_id'])) {
         $changes[0] = '0';
         $changes[1] = addslashes($soft->fields["name"] . " " . $vers->fields["name"]);
         $changes[2] = "";
         // Log on Computer history
         Log::history($this->fields['computers_id'], 'Computer', $changes, 0, HISTORY_UNINSTALL_SOFTWARE);
     }
     $comp = new Computer();
     if ($comp->getFromDB($this->fields['computers_id'])) {
         $changes[0] = '0';
         $changes[1] = addslashes($comp->fields["name"]);
         $changes[2] = "";
         // Log on SoftwareVersion history
         Log::history($this->fields['softwareversions_id'], 'SoftwareVersion', $changes, 0, HISTORY_UNINSTALL_SOFTWARE);
     }
 }
 /**
  * Show items links to a webapplication
  *
  * @since version 0.84
  *
  * @param $PluginWebapplicationsWebapplication PluginWebapplicationsWebapplication object
  *
  * @return nothing (HTML display)
  **/
 static function showForWebapplication(PluginWebapplicationsWebapplication $webapplication)
 {
     global $DB, $CFG_GLPI;
     $instID = $webapplication->fields['id'];
     if (!$webapplication->can($instID, READ)) {
         return false;
     }
     $canedit = $webapplication->can($instID, UPDATE);
     $query = "SELECT DISTINCT `itemtype`\n         FROM `glpi_plugin_webapplications_webapplications_items`\n         WHERE `plugin_webapplications_webapplications_id` = '{$instID}'\n         ORDER BY `itemtype` ";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $rand = mt_rand();
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='webapplicationitem_form{$rand}' id='webapplicationitem_form{$rand}' method='post'\n               action='" . Toolbox::getItemTypeFormURL("PluginWebapplicationsWebapplication") . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         Dropdown::showAllItems("items_id", 0, 0, $webapplication->fields['is_recursive'] ? -1 : $webapplication->fields['entities_id'], PluginWebapplicationsWebapplication::getTypes(), false, true);
         echo "</td><td class='center'>";
         echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "<input type='hidden' name='plugin_webapplications_webapplications_id' value='{$instID}'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array();
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('Entity') . "</th>";
     echo "<th>" . __('Serial number') . "</th>";
     echo "<th>" . __('Inventory number') . "</th>";
     echo "</tr>";
     for ($i = 0; $i < $number; $i++) {
         $itemtype = $DB->result($result, $i, "itemtype");
         if (!($item = getItemForItemtype($itemtype))) {
             continue;
         }
         if ($item->canView()) {
             $column = "name";
             if ($itemtype == 'Ticket') {
                 $column = "id";
             }
             $itemtable = getTableForItemType($itemtype);
             $query = "SELECT `{$itemtable}`.*,\n                                 `glpi_plugin_webapplications_webapplications_items`.`id` AS IDD, ";
             if ($itemtype == 'KnowbaseItem') {
                 $query .= "-1 AS entity\n                          FROM `glpi_plugin_webapplications_webapplications_items`, `{$itemtable}`\n                          " . KnowbaseItem::addVisibilityJoins() . "\n                          WHERE `{$itemtable}`.`id` = `glpi_plugin_webapplications_webapplications_items`.`items_id`\n                                AND ";
             } else {
                 $query .= "`glpi_entities`.`id` AS entity\n                          FROM `glpi_plugin_webapplications_webapplications_items`, `{$itemtable}` ";
                 if ($itemtype != 'Entity') {
                     $query .= "LEFT JOIN `glpi_entities`\n                              ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`) ";
                 }
                 $query .= "WHERE `{$itemtable}`.`id` = `glpi_plugin_webapplications_webapplications_items`.`items_id`\n                                AND ";
             }
             $query .= "`glpi_plugin_webapplications_webapplications_items`.`itemtype` = '{$itemtype}'\n                       AND `glpi_plugin_webapplications_webapplications_items`.`plugin_webapplications_webapplications_id` = '{$instID}' ";
             if ($itemtype == 'KnowbaseItem') {
                 if (Session::getLoginUserID()) {
                     $where = "AND " . KnowbaseItem::addVisibilityRestrict();
                 } else {
                     // Anonymous access
                     if (Session::isMultiEntitiesMode()) {
                         $where = " AND (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n                                     AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')";
                     }
                 }
             } else {
                 $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive());
             }
             if ($item->maybeTemplate()) {
                 $query .= " AND `{$itemtable}`.`is_template` = '0'";
             }
             if ($itemtype == 'KnowbaseItem') {
                 $query .= " ORDER BY `{$itemtable}`.`{$column}`";
             } else {
                 $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`";
             }
             if ($itemtype == 'SoftwareLicense') {
                 $soft = new Software();
             }
             if ($result_linked = $DB->query($query)) {
                 if ($DB->numrows($result_linked)) {
                     while ($data = $DB->fetch_assoc($result_linked)) {
                         if ($itemtype == 'Ticket') {
                             $data["name"] = sprintf(__('%1$s: %2$s'), __('Ticket'), $data["id"]);
                         }
                         if ($itemtype == 'SoftwareLicense') {
                             $soft->getFromDB($data['softwares_id']);
                             $data["name"] = sprintf(__('%1$s - %2$s'), $data["name"], $soft->fields['name']);
                         }
                         $linkname = $data["name"];
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]);
                         }
                         $link = Toolbox::getItemTypeFormURL($itemtype);
                         $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $linkname . "</a>";
                         echo "<tr class='tab_bg_1'>";
                         if ($canedit) {
                             echo "<td width='10'>";
                             Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]);
                             echo "</td>";
                         }
                         echo "<td class='center'>" . $item->getTypeName(1) . "</td>";
                         echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']);
                         echo "</td>";
                         echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                         echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                         echo "</tr>";
                     }
                 }
             }
         }
     }
     echo "</table>";
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions($paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * 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";
 }
 /**
  * Show installations of a software
  *
  * @param $searchID  value of the ID to search
  * @param $crit      to search : softwares_id (software) or id (version)
  *
  * @return nothing
  **/
 private static function showInstallations($searchID, $crit)
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRight("software", "r") || !$searchID) {
         return false;
     }
     $canedit = Session::haveRight("software", "w");
     $canshowcomputer = Session::haveRight("computer", "r");
     if (isset($_POST["start"])) {
         $start = $_POST["start"];
     } else {
         $start = 0;
     }
     if (isset($_POST["order"]) && $_POST["order"] == "DESC") {
         $order = "DESC";
     } else {
         $order = "ASC";
     }
     if (isset($_POST["sort"]) && !empty($_POST["sort"])) {
         // manage several param like location,compname :  order first
         $tmp = explode(",", $_POST["sort"]);
         $sort = "`" . implode("` {$order},`", $tmp) . "`";
     } else {
         if ($crit == "softwares_id") {
             $sort = "`entity` {$order}, `version`, `compname`";
         } else {
             $sort = "`entity` {$order}, `compname`";
         }
     }
     // Total Number of events
     if ($crit == "softwares_id") {
         // Software ID
         $query_number = "SELECT COUNT(*) AS cpt\n                          FROM `glpi_computers_softwareversions`\n                          INNER JOIN `glpi_softwareversions`\n                              ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                                    = `glpi_softwareversions`.`id`)\n                          INNER JOIN `glpi_computers`\n                              ON (`glpi_computers_softwareversions`.`computers_id`\n                                    = `glpi_computers`.`id`)\n                          WHERE `glpi_softwareversions`.`softwares_id` = '{$searchID}'" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                                AND `glpi_computers`.`is_deleted` = '0'\n                                AND `glpi_computers`.`is_template` = '0'\n                                AND `glpi_computers_softwareversions`.`is_deleted` = '0'";
     } else {
         //SoftwareVersion ID
         $query_number = "SELECT COUNT(*) AS cpt\n                          FROM `glpi_computers_softwareversions`\n                          INNER JOIN `glpi_computers`\n                              ON (`glpi_computers_softwareversions`.`computers_id`\n                                    = `glpi_computers`.`id`)\n                          WHERE `glpi_computers_softwareversions`.`softwareversions_id`\n                                       = '{$searchID}'" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                                AND `glpi_computers`.`is_deleted` = '0'\n                                AND `glpi_computers`.`is_template` = '0'\n                                AND `glpi_computers_softwareversions`.`is_deleted` = '0'";
     }
     $number = 0;
     if ($result = $DB->query($query_number)) {
         $number = $DB->result($result, 0, 0);
     }
     echo "<div class='center'>";
     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(self::getTypeName(2), $start, $number);
     $query = "SELECT DISTINCT `glpi_computers_softwareversions`.*,\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_softwareversions`.`name` AS version,\n                       `glpi_softwareversions`.`id` AS vID,\n                       `glpi_softwareversions`.`softwares_id` AS sID,\n                       `glpi_softwareversions`.`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                FROM `glpi_computers_softwareversions`\n                INNER JOIN `glpi_softwareversions`\n                     ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                           = `glpi_softwareversions`.`id`)\n                INNER JOIN `glpi_computers`\n                     ON (`glpi_computers_softwareversions`.`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_softwareversions`.`{$crit}` = '{$searchID}') " . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                       AND `glpi_computers`.`is_deleted` = '0'\n                       AND `glpi_computers`.`is_template` = '0'\n                       AND `glpi_computers_softwareversions`.`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)) {
             $softwares_id = $data['sID'];
             $soft = new Software();
             $showEntity = $soft->getFromDB($softwares_id) && $soft->isRecursive();
             $linkUser = Session::haveRight('user', 'r');
             $title = $soft->fields["name"];
             if ($crit == "id") {
                 $title = sprintf(__('%1$s - %2$s'), $title, $data["vername"]);
             }
             Session::initNavigateListItems('Computer', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $title));
             $sort_img = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "' alt=''\n                          title=''>";
             if ($canedit) {
                 $rand = mt_rand();
                 Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
                 $paramsma = array('num_displayed' => $_SESSION['glpilist_limit'], 'specific_actions' => array('move_version' => _x('button', 'Move'), 'purge' => _x('button', 'Delete permanently')));
                 // Options to update version
                 $paramsma['extraparams']['options']['move']['softwares_id'] = $softwares_id;
                 if ($crit == 'softwares_id') {
                     $paramsma['extraparams']['options']['move']['used'] = array();
                 } else {
                     $paramsma['extraparams']['options']['move']['used'] = array($searchID);
                 }
                 Html::showMassiveActions(__CLASS__, $paramsma);
             }
             echo "<table class='tab_cadre_fixehov'><tr>";
             if ($canedit) {
                 echo "<th width='10'>";
                 Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
                 echo "</th>";
             }
             if ($crit == "softwares_id") {
                 echo "<th>" . ($sort == "`vername`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=vername&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . _n('Version', 'Versions', 2) . "</a></th>";
             }
             echo "<th>" . ($sort == "`compname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . __('Name') . "</a></th>";
             if ($showEntity) {
                 echo "<th>" . (strstr($sort, "entity") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=entity,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . __('Entity') . "</a></th>";
             }
             echo "<th>" . ($sort == "`serial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=serial&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . __('Serial number') . "</a></th>";
             echo "<th>" . ($sort == "`otherserial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=otherserial&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . __('Inventory number') . "</a></th>";
             echo "<th>" . (strstr($sort, "`location`") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=location,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . __('Location') . "</a></th>";
             echo "<th>" . (strstr($sort, "state") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=state,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . __('Status') . "</a></th>";
             echo "<th>" . (strstr($sort, "groupe") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=groupe,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . __('Group') . "</a></th>";
             echo "<th>" . (strstr($sort, "username") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=username,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . __('User') . "</a></th>";
             echo "<th>" . ($sort == "`lname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=lname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . _n('License', 'Licenses', 2) . "</a></th>";
             echo "</tr>\n";
             do {
                 Session::addToNavigateListItems('Computer', $data["cID"]);
                 echo "<tr class='tab_bg_2'>";
                 if ($canedit) {
                     echo "<td>";
                     Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                     echo "</td>";
                 }
                 if ($crit == "softwares_id") {
                     echo "<td><a href='softwareversion.form.php?id=" . $data['vID'] . "'>" . $data['version'] . "</a></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>";
                 $lics = Computer_SoftwareLicense::GetLicenseForInstallation($data['cID'], $data['vID']);
                 echo "<td>";
                 if (count($lics)) {
                     foreach ($lics as $data) {
                         $serial = $data['serial'];
                         if (!empty($data['type'])) {
                             $serial = sprintf(__('%1$s (%2$s)'), $serial, $data['type']);
                         }
                         echo "<a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'];
                         echo "</a> - " . $serial;
                         echo "<br>";
                     }
                 }
                 echo "</td>";
                 echo "</tr>\n";
             } while ($data = $DB->fetch_assoc($result));
             echo "</table>\n";
             if ($canedit) {
                 $paramsma['ontop'] = false;
                 Html::showMassiveActions(__CLASS__, $paramsma);
                 Html::closeForm();
             }
         } else {
             // Not found
             _e('No item found');
         }
     }
     // Query
     Html::printAjaxPager(self::getTypeName(2), $start, $number);
     echo "</div>\n";
 }
 /**
  * @test
  */
 public function SoftwareORBit2added()
 {
     global $DB;
     $DB->connect();
     $software = new Software();
     $software->getFromDB(3);
     unset($software->fields['date_mod']);
     $a_reference = array('id' => '3', 'name' => 'ORBit2', 'entities_id' => '0', 'is_recursive' => '0', 'comment' => NULL, 'locations_id' => '0', 'users_id_tech' => '0', 'groups_id_tech' => '0', 'is_update' => '0', 'softwares_id' => '0', 'manufacturers_id' => '3', 'is_deleted' => '0', 'is_template' => '0', 'template_name' => NULL, 'users_id' => '0', 'groups_id' => '0', 'ticket_tco' => '0.0000', 'is_helpdesk_visible' => '1', 'softwarecategories_id' => '0', 'is_valid' => '1');
     $this->assertEquals($a_reference, $software->fields);
 }
Ejemplo n.º 7
0
Archivo: Import.php Proyecto: btry/glpi
 /**
  * Test software category Rule and putInTrash / removeFromTrash
  */
 public function testSoftwareCategory()
 {
     global $CFG_GLPI;
     $ent0 = $this->sharedFixture['entity'][0];
     // Clean preload rules
     $tmp = SingletonRuleList::getInstance('RuleSoftwareCategory');
     $tmp->load = 0;
     $this->assertArrayHasKey('softwarecategories_id_ondelete', $CFG_GLPI, "Fail: no softwarecategories_id_ondelete");
     $idcat[0] = Dropdown::import('SoftwareCategory', array('name' => 'Trashed'));
     $this->assertGreaterThan(0, $idcat[0], "Fail: can't create SoftwareCategory");
     $idcat[1] = Dropdown::import('SoftwareCategory', array('name' => 'OpenSource'));
     $this->assertGreaterThan(0, $idcat[1], "Fail: can't create SoftwareCategory");
     $rule = new RuleSoftwareCategory();
     $crit = new RuleCriteria();
     $acte = new RuleAction();
     $idr[0] = $rule->add(array('name' => 'OSS', 'sub_type' => 'RuleSoftwareCategory', 'match' => 'AND', 'is_active' => 1));
     $this->assertGreaterThan(0, $idr[0], "Fail: can't create rule 1");
     $this->assertTrue($rule->getFromDB($idr[0]));
     $this->assertEquals(1, $rule->fields['ranking'], "Fail: ranking not set");
     $idc[0] = $crit->add(array('rules_id' => $idr[0], 'criteria' => 'manufacturer', 'condition' => Rule::PATTERN_IS, 'pattern' => 'Indepnet'));
     $this->assertGreaterThan(0, $idc[0], "Fail: can't create rule 1 criteria");
     $ida[0] = $acte->add(array('rules_id' => $idr[0], 'action_type' => 'assign', 'field' => 'softwarecategories_id', 'value' => $idcat[1]));
     $this->assertGreaterThan(0, $ida[0], "Fail: can't create rule 1 action");
     // Createthe software
     $soft = new Software();
     $id[0] = $soft->addOrRestoreFromTrash('GLPI', 'Indepnet', $ent0);
     $this->assertGreaterThan(0, $id[0], "Fail: can't create software 1");
     // Check name
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $this->assertEquals('GLPI', $soft->getField('name'), "Fail: name not set");
     // Check category
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[1], $catid, "Fail: category not set");
     // Change configuration
     $CFG_GLPI["softwarecategories_id_ondelete"] = $idcat[0];
     // Delete
     $this->assertTrue($soft->putInTrash($id[0]), "Fail: can't put soft in trash");
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[0], $catid, "Fail: category not set");
     $this->assertEquals(1, $soft->getField('is_deleted'), "Fail: soft not deleted");
     // Restore
     $this->assertTrue($soft->removeFromTrash($id[0]), "Fail: can't put soft in trash");
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[1], $catid, "Fail: category not set");
     $this->assertEquals(0, $soft->getField('is_deleted'), "Fail: soft not restored");
     // Clean
     $this->assertTrue($soft->delete(array('id' => $id[0]), true), "Fail: can't delete software 1)");
 }
Ejemplo n.º 8
0
 /**
  * Is the license may be recursive
  *
  * @return boolean
  **/
 function maybeRecursive()
 {
     $soft = new Software();
     if (isset($this->fields["softwares_id"]) && $soft->getFromDB($this->fields["softwares_id"])) {
         return $soft->isRecursive();
     }
     return false;
 }
Ejemplo n.º 9
0
             glpi_header($_SERVER['PHP_SELF'] . '?multiple_actions=1');
         } else {
             $REDIRECT = $_SESSION['glpi_massiveaction']['REDIRECT'];
             unset($_SESSION['glpi_massiveaction']);
             glpi_header($REDIRECT);
         }
     }
     break;
 case "compute_software_category":
     $softcatrule = new RuleSoftwareCategoryCollection();
     $soft = new Software();
     foreach ($_POST["item"] as $key => $val) {
         if ($val == 1) {
             $params = array();
             //Get software name and manufacturer
             $soft->getFromDB($key);
             $params["name"] = $soft->fields["name"];
             $params["manufacturers_id"] = $soft->fields["manufacturers_id"];
             $params["comment"] = $soft->fields["comment"];
             //Process rules
             $soft->update($softcatrule->processAllRules(null, $soft->fields, $params));
         }
     }
     break;
 case "replay_dictionnary":
     $softdictionnayrule = new RuleDictionnarySoftwareCollection();
     $ids = array();
     foreach ($_POST["item"] as $key => $val) {
         if ($val == 1) {
             $ids[] = $key;
         }
Ejemplo n.º 10
0
 /**
  * Show items links to a document
  *
  * @since version 0.84
  *
  * @param $doc Document object
  *
  * @return nothing (HTML display)
  **/
 static function showForDocument(Document $doc)
 {
     global $DB, $CFG_GLPI;
     $instID = $doc->fields['id'];
     if (!$doc->can($instID, READ)) {
         return false;
     }
     $canedit = $doc->can($instID, UPDATE);
     // for a document,
     // don't show here others documents associated to this one,
     // it's done for both directions in self::showAssociated
     $query = "SELECT DISTINCT `itemtype`\n                FROM `glpi_documents_items`\n                WHERE `glpi_documents_items`.`documents_id` = '{$instID}'\n                      AND `glpi_documents_items`.`itemtype` != 'Document'\n                ORDER BY `itemtype`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $rand = mt_rand();
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='documentitem_form{$rand}' id='documentitem_form{$rand}' method='post'\n               action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         Dropdown::showSelectItemFromItemtypes(array('itemtypes' => Document::getItemtypesThatCanHave(), 'entity_restrict' => $doc->fields['is_recursive'] ? getSonsOf('glpi_entities', $doc->fields['entities_id']) : $doc->fields['entities_id'], 'checkright' => true));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "<input type='hidden' name='documents_id' value='{$instID}'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     $header_begin = "<tr>";
     $header_top = '';
     $header_bottom = '';
     $header_end = '';
     if ($canedit && $number) {
         $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_top .= "</th>";
         $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_bottom .= "</th>";
     }
     $header_end .= "<th>" . __('Type') . "</th>";
     $header_end .= "<th>" . __('Name') . "</th>";
     $header_end .= "<th>" . __('Entity') . "</th>";
     $header_end .= "<th>" . __('Serial number') . "</th>";
     $header_end .= "<th>" . __('Inventory number') . "</th>";
     $header_end .= "</tr>";
     echo $header_begin . $header_top . $header_end;
     for ($i = 0; $i < $number; $i++) {
         $itemtype = $DB->result($result, $i, "itemtype");
         if (!($item = getItemForItemtype($itemtype))) {
             continue;
         }
         if ($item->canView()) {
             if ($item instanceof CommonDevice) {
                 $column = "designation";
             } else {
                 if ($item instanceof Item_Devices) {
                     $column = "itemtype";
                 } else {
                     $column = "name";
                 }
             }
             if ($itemtype == 'Ticket') {
                 $column = "id";
             }
             $itemtable = getTableForItemType($itemtype);
             $query = "SELECT `{$itemtable}`.*,\n                                 `glpi_documents_items`.`id` AS IDD, ";
             if ($itemtype == 'KnowbaseItem') {
                 $query .= "-1 AS entity\n                          FROM `glpi_documents_items`, `{$itemtable}`\n                          " . KnowbaseItem::addVisibilityJoins() . "\n                          WHERE `{$itemtable}`.`id` = `glpi_documents_items`.`items_id`\n                                AND ";
             } else {
                 $query .= "`glpi_entities`.`id` AS entity\n                          FROM `glpi_documents_items`, `{$itemtable}`";
                 if ($itemtype != 'Entity') {
                     $query .= " LEFT JOIN `glpi_entities`\n                                 ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`)";
                 }
                 $query .= " WHERE `{$itemtable}`.`id` = `glpi_documents_items`.`items_id`\n                                 AND ";
             }
             $query .= "`glpi_documents_items`.`itemtype` = '{$itemtype}'\n                       AND `glpi_documents_items`.`documents_id` = '{$instID}' ";
             if ($itemtype == 'KnowbaseItem') {
                 if (Session::getLoginUserID()) {
                     $where = "AND " . KnowbaseItem::addVisibilityRestrict();
                 } else {
                     // Anonymous access
                     if (Session::isMultiEntitiesMode()) {
                         $where = " AND (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n                                     AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')";
                     }
                 }
             } else {
                 $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive());
             }
             if ($item->maybeTemplate()) {
                 $query .= " AND `{$itemtable}`.`is_template` = '0'";
             }
             if ($itemtype == 'KnowbaseItem') {
                 $query .= " ORDER BY `{$itemtable}`.`{$column}`";
             } else {
                 $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`";
             }
             if ($itemtype == 'SoftwareLicense') {
                 $soft = new Software();
             }
             if ($result_linked = $DB->query($query)) {
                 if ($DB->numrows($result_linked)) {
                     while ($data = $DB->fetch_assoc($result_linked)) {
                         if ($itemtype == 'Ticket') {
                             $data["name"] = sprintf(__('%1$s: %2$s'), __('Ticket'), $data["id"]);
                         }
                         if ($itemtype == 'SoftwareLicense') {
                             $soft->getFromDB($data['softwares_id']);
                             $data["name"] = sprintf(__('%1$s - %2$s'), $data["name"], $soft->fields['name']);
                         }
                         if ($item instanceof CommonDevice) {
                             $linkname = $data["designation"];
                         } else {
                             if ($item instanceof Item_Devices) {
                                 $linkname = $data["itemtype"];
                             } else {
                                 $linkname = $data["name"];
                             }
                         }
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]);
                         }
                         if ($item instanceof Item_Devices) {
                             $tmpitem = new $item::$itemtype_2();
                             if ($tmpitem->getFromDB($data[$item::$items_id_2])) {
                                 $linkname = $tmpitem->getLink();
                             }
                         }
                         $link = Toolbox::getItemTypeFormURL($itemtype);
                         $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $linkname . "</a>";
                         echo "<tr class='tab_bg_1'>";
                         if ($canedit) {
                             echo "<td width='10'>";
                             Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]);
                             echo "</td>";
                         }
                         echo "<td class='center'>" . $item->getTypeName(1) . "</td>";
                         echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']);
                         echo "</td>";
                         echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                         echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                         echo "</tr>";
                     }
                 }
             }
         }
     }
     if ($number) {
         echo $header_begin . $header_bottom . $header_end;
     }
     echo "</table>";
     if ($canedit && $number) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Ejemplo n.º 11
0
 /**
  * 
  * 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>";
 }
Ejemplo n.º 12
0
 /**
  * Show items links to a document
  *
  * @return nothing (HTML display)
  **/
 function showItems()
 {
     global $DB, $CFG_GLPI, $LANG;
     $instID = $this->fields['id'];
     if (!$this->can($instID, "r")) {
         return false;
     }
     $canedit = $this->can($instID, 'w');
     // for a document,
     // don't show here others documents associated to this one,
     // it's done for both directions in self::showAssociated
     $query = "SELECT DISTINCT `itemtype`\n                FROM `glpi_documents_items`\n                WHERE `glpi_documents_items`.`documents_id` = '{$instID}'\n                      AND `glpi_documents_items`.`itemtype` != 'Document'\n                ORDER BY `itemtype`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $rand = mt_rand();
     echo "<form method='post' name='document_form{$rand}' id='document_form{$rand}' action='" . $CFG_GLPI["root_doc"] . "/front/document.form.php'>";
     echo "<div class='spaced'><table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='" . ($canedit ? 6 : 5) . "'>";
     if ($DB->numrows($result) == 0) {
         echo $LANG['document'][13];
     } else {
         if ($DB->numrows($result) == 1) {
             echo $LANG['document'][14];
         } else {
             echo $LANG['document'][19];
         }
     }
     echo "</th></tr><tr>";
     if ($canedit) {
         echo "<th>&nbsp;</th>";
     }
     echo "<th>" . $LANG['common'][17] . "</th>";
     echo "<th>" . $LANG['common'][16] . "</th>";
     echo "<th>" . $LANG['entity'][0] . "</th>";
     echo "<th>" . $LANG['common'][19] . "</th>";
     echo "<th>" . $LANG['common'][20] . "</th>";
     echo "</tr>";
     for ($i = 0; $i < $number; $i++) {
         $itemtype = $DB->result($result, $i, "itemtype");
         if (!class_exists($itemtype)) {
             continue;
         }
         $item = new $itemtype();
         if ($item->canView()) {
             $column = "name";
             if ($itemtype == 'Ticket') {
                 $column = "id";
             }
             if ($itemtype == 'KnowbaseItem') {
                 $column = "question";
             }
             $itemtable = getTableForItemType($itemtype);
             $query = "SELECT `{$itemtable}`.*,\n                             `glpi_documents_items`.`id` AS IDD, ";
             if ($itemtype == 'Entity') {
                 // Left join because root entity not storeed
                 $query .= "`glpi_documents_items`.`items_id` AS entity\n                          FROM `glpi_documents_items`\n                          LEFT JOIN `glpi_entities`\n                              ON (`glpi_entities`.`id` = `glpi_documents_items`.`items_id`)\n                          WHERE ";
             } else {
                 $query .= "`glpi_entities`.`id` AS entity\n                          FROM `glpi_documents_items`, `{$itemtable}`\n                          LEFT JOIN `glpi_entities`\n                              ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`)\n                          WHERE `{$itemtable}`.`id` = `glpi_documents_items`.`items_id`\n                          AND ";
             }
             $query .= "`glpi_documents_items`.`itemtype` = '{$itemtype}'\n                       AND `glpi_documents_items`.`documents_id` = '{$instID}' " . getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive());
             if ($item->maybeTemplate()) {
                 $query .= " AND `{$itemtable}`.`is_template` = '0'";
             }
             $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`";
             if ($itemtype == 'SoftwareLicense') {
                 $soft = new Software();
             }
             if ($result_linked = $DB->query($query)) {
                 if ($DB->numrows($result_linked)) {
                     while ($data = $DB->fetch_assoc($result_linked)) {
                         $ID = "";
                         if ($itemtype == 'Entity' && !$data['entity']) {
                             $data['id'] = 0;
                             $data['name'] = $LANG['entity']['2'];
                         }
                         if ($itemtype == 'Ticket') {
                             $data["name"] = $LANG['job'][38] . " " . $data["id"];
                         }
                         if ($itemtype == 'KnowbaseItem') {
                             $data["name"] = $data["question"];
                         }
                         if ($itemtype == 'SoftwareLicense') {
                             $soft->getFromDB($data['softwares_id']);
                             $data["name"] = $data["name"] . ' - ' . $soft->fields['name'];
                         }
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $ID = " (" . $data["id"] . ")";
                         }
                         $link = getItemTypeFormURL($itemtype);
                         $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $data["name"] . "{$ID}</a>";
                         echo "<tr class='tab_bg_1'>";
                         if ($canedit) {
                             echo "<td width='10'>";
                             $sel = "";
                             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                                 $sel = "checked";
                             }
                             echo "<input type='checkbox' name='item[" . $data["IDD"] . "]' value='1' {$sel}>";
                             echo "</td>";
                         }
                         echo "<td class='center'>" . $item->getTypeName() . "</td>";
                         echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']);
                         echo "</td>";
                         echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                         echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                         echo "</tr>";
                     }
                 }
             }
         }
     }
     if ($canedit) {
         echo "<tr class='tab_bg_1'><td colspan='4' class='center'>";
         echo "<input type='hidden' name='documents_id' value='{$instID}'>";
         Dropdown::showAllItems("items_id", 0, 0, $this->fields['is_recursive'] ? -1 : $this->fields['entities_id'], $CFG_GLPI["document_types"]);
         echo "</td>";
         echo "<td colspan='2' class='center'>";
         echo "<input type='submit' name='adddocumentitem' value='" . $LANG['buttons'][8] . "' class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         openArrowMassive("document_form{$rand}", true);
         closeArrowMassive('deletedocumentitem', $LANG['buttons'][6]);
     } else {
         echo "</table>";
     }
     echo "</div></form>";
 }
Ejemplo n.º 13
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";
 }
 /**
  * @test
  */
 public function AddComputerStep3()
 {
     global $DB;
     $this->mark_incomplete();
     return;
     // TODO: recode this test
     $DB->connect();
     $DB->query("UPDATE `glpi_entities`\n         SET `entities_id_software` = '-2'\n         WHERE `id`='1'");
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION['glpiactiveentities_string'] = 0;
     $_SESSION['glpishowallentities'] = 1;
     $_SESSION['glpiname'] = 'glpi';
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     $computer = new Computer();
     $software = new Software();
     $input = array('id' => 1, 'is_recursive' => 0);
     $software->update($input);
     $computer->add(array('name' => 'pc2', 'entities_id' => 1));
     $a_inventory = array();
     $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc2');
     $a_inventory['CONTENT']['SOFTWARES'][] = array('COMMENTS' => "Non-interactive tool to get files from FTP, GOPHER, HTTP(S)", 'NAME' => "curl", 'VERSION' => "7.24.0_1");
     // ** Add agent
     $pfAgent = new PluginFusioninventoryAgent();
     $a_agents_id = $pfAgent->add(array('name' => 'pc-2013-02-13', 'device_id' => 'pc-2013-02-13'));
     $_SESSION['plugin_fusioninventory_agents_id'] = $a_agents_id;
     // ** Add
     $pfiComputerInv->import("pc2-2013-02-13", "", $a_inventory);
     // creation
     $computer->getFromDB(2);
     $this->assertEquals(1, $computer->fields['entities_id'], 'Add computer');
     $nbSoftwares = countElementsInTable("glpi_softwares");
     $softs = getAllDatasFromTable("glpi_softwares");
     $this->assertEquals(2, $nbSoftwares, 'Nb softwares ' . print_r($softs, true));
     $software->getFromDB(2);
     $this->assertEquals(1, $software->fields['entities_id'], "May be on entity 1");
     // Software not in same entity as computer, may be recursive
     $this->assertEquals(0, $software->fields['is_recursive'], 'Software may have recursive = 0');
 }
Ejemplo n.º 15
0
 static function getSoftwares($protocol, $params = array(), $original_params = array())
 {
     global $DB, $WEBSERVICE_LINKED_OBJECTS;
     if (!Session::haveRight("software", READ)) {
         return array();
     }
     $item = new $params['options']['itemtype']();
     $resp = array();
     $software = new Software();
     //Store softwares, versions and licenses
     $softwares = array();
     if ($item->can($params['data']['id'], READ) && $software->can(-1, READ)) {
         foreach (array('SoftwareVersion', 'SoftwareLicense') as $itemtype) {
             $link_table = "glpi_computers_" . Toolbox::addslashes_deep(strtolower($itemtype)) . "s";
             $table = getTableForItemType($itemtype);
             $query = "SELECT DISTINCT `gsv`.*\n                           FROM `" . Toolbox::addslashes_deep($link_table) . "` AS gcsv,\n                                `" . Toolbox::addslashes_deep($table) . "` AS gsv\n                           WHERE `gcsv`.`computers_id`\n                                       = '" . Toolbox::addslashes_deep($params['data']['id']) . "'\n                                 AND `gcsv`.`" . getForeignKeyFieldForTable($table) . "` = `gsv`.`id`\n                           GROUP BY `gsv`.`softwares_id`\n                           ORDER BY `gsv`.`softwares_id` ASC";
             foreach ($DB->request($query) as $version_or_license) {
                 //Software is not yet in the list
                 if (!isset($softwares['Software'][$version_or_license['softwares_id']])) {
                     $software->getFromDB($version_or_license['softwares_id']);
                     $toformat = array('data' => $software->fields, 'searchOptions' => Search::getOptions('Software'), 'options' => $params['options']);
                     $tmp = array();
                     parent::formatDataForOutput($toformat, $tmp);
                     $softwares['Software'][$version_or_license['softwares_id']] = $tmp;
                 }
                 $toformat2 = array('data' => $version_or_license, 'searchOptions' => Search::getOptions($itemtype), 'options' => $params['options']);
                 $tmp = array();
                 parent::formatDataForOutput($toformat2, $tmp);
                 $softwares['Software'][$version_or_license['softwares_id']][$itemtype][$version_or_license['id']] = $tmp;
             }
         }
     }
     return $softwares;
 }
 /**
  * Print the Software / version form
  *
  * @param $ID Integer : Id of the version or the template to print
  * @param $options array
  *     - target form target
  *     - softwares_id ID of the software for add process
  *
  * @return true if displayed  false if item not found or not right to display
  *
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI, $LANG;
     $softwares_id = -1;
     if (isset($options['softwares_id'])) {
         $softwares_id = $options['softwares_id'];
     }
     if (!haveRight("software", "r")) {
         return false;
     }
     if ($ID > 0) {
         $this->check($ID, 'r');
     } else {
         $soft = new Software();
         $soft->getFromDB($softwares_id);
         // Create item
         $input = array('entities_id' => $soft->getEntityID(), 'is_recursive' => $soft->isRecursive());
         $this->check(-1, 'w', $input);
     }
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'><td>" . $LANG['help'][31] . "&nbsp;:</td>";
     echo "<td>";
     if ($ID > 0) {
         $softwares_id = $this->fields["softwares_id"];
     } else {
         echo "<input type='hidden' name='softwares_id' value='{$softwares_id}'>";
     }
     echo "<a href='software.form.php?id=" . $softwares_id . "'>" . Dropdown::getDropdownName("glpi_softwares", $softwares_id) . "</a>";
     echo "</td>";
     echo "<td rowspan='4' class='middle'>" . $LANG['common'][25] . "&nbsp;:</td>";
     echo "<td class='center middle' rowspan='4'>";
     echo "<textarea cols='45' rows='3' name='comment' >" . $this->fields["comment"];
     echo "</textarea></td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['common'][16] . "&nbsp;:</td>";
     echo "<td>";
     autocompletionTextField($this, "name");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['setup'][5] . "&nbsp;:</td><td>";
     Dropdown::show('OperatingSystem', array('value' => $this->fields["operatingsystems_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['state'][0] . "&nbsp;:</td><td>";
     Dropdown::show('State', array('value' => $this->fields["states_id"]));
     echo "</td></tr>\n";
     // Only count softwareversions_id_buy (don't care of softwareversions_id_use if no installation)
     if (SoftwareLicense::countForVersion($ID) > 0 || Computer_SoftwareVersion::countForVersion($ID) > 0) {
         $options['candel'] = false;
     }
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
You should have received a copy of the GNU General Public License
along with GLPI; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file: Julien Dombre
// Purpose of file:
// ----------------------------------------------------------------------
define('GLPI_ROOT', '..');
include GLPI_ROOT . "/inc/includes.php";
// COMPUTER ONLY UNDEF CATEGORIES
$ONLY_UNDEFINED = true;
$softcatrule = new RuleSoftwareCategoryCollection();
$soft = new Software();
$query = "SELECT `id`, `softwarecategories_id`\n          FROM `glpi_softwares`";
if ($result = $DB->query($query)) {
    if ($DB->numrows($result) > 0) {
        while ($data = $DB->fetch_array($result)) {
            if (!$ONLY_UNDEFINED || $data['softwarecategories_id'] == 0) {
                $params = array();
                //Get software name and manufacturer
                $soft->getFromDB($data['id']);
                $params["name"] = $soft->fields["name"];
                $params["manufacturers_id"] = $soft->fields["manufacturers_id"];
                //Process rules
                $soft->update($softcatrule->processAllRules(null, $soft->fields, $params));
            }
        }
    }
}
Ejemplo n.º 18
0
 /**
  * Copy (if needed) One software to the destination entity
  *
  * @param $ID of the software
  *
  * @return $ID of the new software (could be the same)
  **/
 function copySingleSoftware($ID)
 {
     global $DB;
     if (isset($this->already_transfer['Software'][$ID])) {
         return $this->already_transfer['Software'][$ID];
     }
     $soft = new Software();
     if ($soft->getFromDB($ID)) {
         if ($soft->fields['is_recursive'] && in_array($soft->fields['entities_id'], getAncestorsOf("glpi_entities", $this->to))) {
             // no need to copy
             $newsoftID = $ID;
         } else {
             $query = "SELECT *\n                      FROM `glpi_softwares`\n                      WHERE `entities_id` = " . $this->to . "\n                            AND `name` = '" . addslashes($soft->fields['name']) . "'";
             if ($data = $DB->request($query)->next()) {
                 $newsoftID = $data["id"];
             } else {
                 // create new item (don't check if move possible => clean needed)
                 unset($soft->fields['id']);
                 $input = $soft->fields;
                 $input['entities_id'] = $this->to;
                 unset($soft->fields);
                 $newsoftID = $soft->add($input);
             }
         }
         $this->addToAlreadyTransfer('Software', $ID, $newsoftID);
         return $newsoftID;
     }
     return -1;
 }
 /**
  * Show computers linked to a License
  *
  * @param $license SoftwareLicense object
  *
  * @return nothing
  **/
 static function showForLicense(SoftwareLicense $license)
 {
     global $DB, $CFG_GLPI, $LANG;
     $searchID = $license->getField('id');
     if (!haveRight("software", "r") || !$searchID) {
         return false;
     }
     $canedit = haveRight("software", "w");
     $canshowcomputer = haveRight("computer", "r");
     if (isset($_REQUEST["start"])) {
         $start = $_REQUEST["start"];
     } else {
         $start = 0;
     }
     if (isset($_REQUEST["order"]) && $_REQUEST["order"] == "DESC") {
         $order = "DESC";
     } else {
         $order = "ASC";
     }
     if (isset($_REQUEST["sort"]) && !empty($_REQUEST["sort"])) {
         // manage several param like location,compname : order first
         $tmp = explode(",", $_REQUEST["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` = `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'";
     $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>";
         Dropdown::show('Computer', array('entity' => $license->fields['entities_id'], 'entity_sons' => $license->fields['is_recursive']));
         echo "</td>";
         echo "<td><input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table></form>";
     }
     if ($number < 1) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . $LANG['search'][15] . "</th></tr>";
         echo "</table></div>\n";
         return;
     }
     // Display the pager
     printAjaxPager($LANG['software'][9], $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_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                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                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)) {
             $soft = new Software();
             $soft->getFromDB($license->fields['softwares_id']);
             $showEntity = $license->isRecursive();
             $title = $LANG['help'][31] . " = " . $soft->fields["name"] . " - " . $data["vername"];
             initNavigateListItems('Computer', $title);
             $sort_img = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "' alt='' title=''>";
             if ($canedit) {
                 echo "<form name='softinstall" . $rand . "' id='softinstall" . $rand . "' method='post'\n                      action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>";
                 echo "<table class='tab_cadre_fixehov'><tr>";
                 echo "<th>&nbsp;</th>";
             } else {
                 echo "<table class='tab_cadre_fixehov'><tr>";
             }
             echo "<th>" . ($sort == "`compname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['common'][16] . "</a></th>";
             if ($showEntity) {
                 echo "<th>" . (strstr($sort, "entity") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=entity,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['entity'][0] . "</a></th>";
             }
             echo "<th>" . ($sort == "`serial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=serial&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['common'][19] . "</a></th>";
             echo "<th>" . ($sort == "`otherserial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=otherserial&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['common'][20] . "</a></th>";
             echo "<th>" . (strstr($sort, "`location`") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=location,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['common'][15] . "</a></th>";
             echo "<th>" . (strstr($sort, "state") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=state,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['state'][0] . "</a></th>";
             echo "<th>" . (strstr($sort, "groupe") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=groupe,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['common'][35] . "</a></th>";
             echo "<th>" . (strstr($sort, "username") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=username,compname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['common'][34] . "</a></th>";
             echo "</tr>\n";
             do {
                 addToNavigateListItems('Computer', $data["cID"]);
                 echo "<tr class='tab_bg_2'>";
                 if ($canedit) {
                     echo "<td><input type='checkbox' name='item[" . $data["id"] . "]' value='1'></td>";
                 }
                 $compname = $data['compname'];
                 if (empty($compname) || $_SESSION['glpiis_ids_visible']) {
                     $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>" . (empty($data['entity']) ? $LANG['entity'][2] : $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>" . $data['username'] . "</td>";
                 echo "</tr>\n";
             } while ($data = $DB->fetch_assoc($result));
             echo "</table>\n";
             if ($canedit) {
                 openArrowMassive("softinstall" . $rand . "", true);
                 Dropdown::show('SoftwareLicense', array('condition' => "`glpi_softwarelicenses`.`softwares_id`\n                                                      = '" . $license->fields['softwares_id'] . "'", 'used' => array($searchID)));
                 echo "&nbsp;<input type='submit' name='move' value=\"" . $LANG['buttons'][20] . "\" class='submit'>&nbsp;";
                 closeArrowMassive('delete', $LANG['buttons'][6]);
                 echo "</form>";
             }
         } else {
             // Not found
             echo $LANG['search'][15];
         }
     }
     // Query
     echo "</div>\n";
 }