Inheritance: extends CommonDBTM
コード例 #1
0
 static function pdfForSoftware(PluginPdfSimplePDF $pdf, Software $software, $infocom = false)
 {
     global $DB;
     $sID = $software->getField('id');
     $license = new SoftwareLicense();
     $query = "SELECT `id`\n                FROM `glpi_softwarelicenses`\n                WHERE `softwares_id` = '" . $sID . "' " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n                ORDER BY `name`";
     $pdf->setColumnsSize(100);
     $pdf->displayTitle('<b>' . _n('License', 'Licenses', 2) . '</b>');
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result)) {
             for ($tot = 0; $data = $DB->fetch_assoc($result);) {
                 if ($license->getFromDB($data['id'])) {
                     self::pdfMain($pdf, $license, false);
                     if ($infocom) {
                         PluginPdfInfocom::pdfForItem($pdf, $license);
                     }
                 }
             }
         } else {
             $pdf->displayLine(__('No item found'));
         }
     } else {
         $pdf->displayLine(__('No item found'));
     }
     $pdf->displaySpace();
 }
コード例 #2
0
 static function pdfForLicenseByComputer(PluginPdfSimplePDF $pdf, SoftwareLicense $license)
 {
     global $DB;
     $ID = $license->getField('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` = '" . $ID . "'" . 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);
     }
     $pdf->setColumnsSize(100);
     $pdf->setColumnsAlign('center');
     $title = '<b>' . __('Affected computers') . '</b>';
     if ($number) {
         if ($number > $_SESSION['glpilist_limit']) {
             $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number);
         } else {
             $title = sprintf(__('%1$s: %2$s'), $title, $number);
         }
         $pdf->displayTitle($title);
         $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`.`name` 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`\n                        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` = '" . $ID . "') " . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                         AND `glpi_computers`.`is_deleted` = '0'\n                         AND `glpi_computers`.`is_template` = '0'\n                   ORDER BY `entity`, `compname`\n                   LIMIT 0," . intval($_SESSION['glpilist_limit']);
         $result = $DB->query($query);
         $showEntity = $license->isRecursive();
         if ($showEntity) {
             $pdf->setColumnsSize(12, 12, 12, 12, 16, 12, 12, 12);
             $pdf->displayTitle('<b><i>' . __('Entity'), __('Name'), __('Serial number'), __('Inventory number'), __('Location'), __('Status'), __('Group'), __('User') . '</i></b>');
         } else {
             $pdf->setColumnsSize(14, 14, 14, 18, 14, 13, 13);
             $pdf->displayTitle('<b><i>' . __('Name'), __('Serial number'), __('Inventory number'), __('Location'), __('Status'), __('Group'), __('User') . '</i></b>');
         }
         while ($data = $DB->fetch_assoc($result)) {
             $compname = $data['compname'];
             if (empty($compname) || $_SESSION['glpiis_ids_visible']) {
                 $compname = sprintf(__('%1$s (%2$s)'), $compname, $data['cID']);
             }
             $entname = empty($data['entity']) ? __('Root entity') : $data['entity'];
             if ($showEntity) {
                 $pdf->displayLine($entname, $compname, $data['serial'], $data['otherserial'], $data['location'], $data['state'], $data['groupe'], $data['username']);
             } else {
                 $pdf->displayLine($compname, $data['serial'], $data['otherserial'], $data['location'], $data['state'], $data['groupe'], $data['username']);
             }
         }
     } else {
         $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item found')));
     }
     $pdf->displaySpace();
 }
コード例 #3
0
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     switch ($item->getType()) {
         case 'User':
             if (!$withtemplate) {
                 $nb = 0;
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     $nb = self::countForUserLicense($item->getID());
                 }
                 return array(1 => self::createTabEntry(SoftwareLicense::getTypeName(2), $nb));
             }
             break;
     }
     return '';
 }
コード例 #4
0
    exit;
}
if (!isset($_REQUEST['glpi_tab'])) {
    exit;
}
if (!isset($_POST["sort"])) {
    $_POST["sort"] = "";
}
if (!isset($_POST["order"])) {
    $_POST["order"] = "";
}
if (!isset($_POST["withtemplate"])) {
    $_POST["withtemplate"] = "";
}
checkRight("software", "r");
$license = new SoftwareLicense();
if ($_POST["id"] > 0 && $license->can($_POST["id"], 'r')) {
    switch ($_REQUEST['glpi_tab']) {
        case -1:
            Infocom::showForItem($license);
            Document::showAssociated($license);
            Plugin::displayAction($license, $_REQUEST['glpi_tab']);
            break;
        case 2:
            Computer_SoftwareLicense::showForLicense($license);
            break;
        case 4:
            Infocom::showForItem($license);
            break;
        case 5:
            Document::showAssociated($license);
コード例 #5
0
ファイル: link.class.php プロジェクト: pluginsGLPI/order
 public function deleteLinkWithItem($detailID, $itemtype, $plugin_order_orders_id)
 {
     global $DB;
     if ($itemtype == 'SoftWareLicense') {
         $detail = new PluginOrderOrder_Item();
         $detail->getFromDB($detailID);
         $license = $detail->fields["items_id"];
         $this->removeInfoComRelatedToOrder($itemtype, $license);
         $result = $PluginOrderOrder_Item->queryRef($detail->fields["plugin_order_orders_id"], $detail->fields["plugin_order_references_id"], $detail->fields["price_taxfree"], $detail->fields["discount"], PluginOrderOrder::ORDER_DEVICE_DELIVRED);
         $nb = $DB->numrows($result);
         if ($nb) {
             for ($i = 0; $i < $nb; $i++) {
                 $ID = $DB->result($result, $i, 'id');
                 $input["id"] = $ID;
                 $input["items_id"] = 0;
                 $detail->update($input);
                 $lic = new SoftwareLicense();
                 $lic->getFromDB($license);
                 $values["id"] = $lic->fields["id"];
                 $values["number"] = $lic->fields["number"] - 1;
                 $lic->update($values);
             }
             $order = new PluginOrderOrder();
             $order->getFromDB($detail->fields["plugin_order_orders_id"]);
             $new_value = __("Item unlink form order", "order") . ' : ' . $order->fields["name"];
             $order->addHistory($itemtype, '', $new_value, $license);
             $item = new $itemtype();
             $item->getFromDB($license);
             $new_value = __("Item unlink form order", "order") . ' : ' . $item->getField("name");
             $order->addHistory('PluginOrderOrder', '', $new_value, $order->fields["id"]);
         }
     } else {
         $order = new PluginOrderOrder();
         $order->getFromDB($plugin_order_orders_id);
         $detail = new PluginOrderOrder_Item();
         $detail->getFromDB($detailID);
         $items_id = $detail->fields["items_id"];
         $this->removeInfoComRelatedToOrder($itemtype, $items_id);
         if ($items_id != 0) {
             $input = $detail->fields;
             $input["items_id"] = 0;
             $detail->update($input);
         } else {
             Session::addMessageAfterRedirect(__("One or several selected rows haven't linked items", "order"), TRUE, ERROR);
         }
         $new_value = __("Item unlink form order", "order") . ' : ' . $order->fields["name"];
         $order->addHistory($itemtype, '', $new_value, $items_id);
         $item = new $itemtype();
         $item->getFromDB($items_id);
         $new_value = __("Item unlink form order", "order") . ' : ' . $item->getField("name");
         $order->addHistory('PluginOrderOrder', '', $new_value, $order->fields["id"]);
     }
 }
コード例 #6
0
ファイル: softwarelicense.form.php プロジェクト: btry/glpi
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkRight("license", READ);
if (!isset($_REQUEST["id"])) {
    $_REQUEST["id"] = "";
}
if (!isset($_REQUEST["softwares_id"])) {
    $_REQUEST["softwares_id"] = "";
}
if (!isset($_REQUEST["withtemplate"])) {
    $_REQUEST["withtemplate"] = "";
}
$license = new SoftwareLicense();
if (isset($_POST["add"])) {
    $license->check(-1, CREATE, $_POST);
    if ($newID = $license->add($_POST)) {
        Event::log($_POST['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s adds the license %2$s'), $_SESSION["glpiname"], $newID));
        if ($_SESSION['glpibackcreated']) {
            Html::redirect($license->getFormURL() . "?id=" . $newID);
        }
    }
    Html::back();
} else {
    if (isset($_POST["restore"])) {
        $license->check($_POST['id'], DELETE);
        if ($license->restore($_POST)) {
            Event::log($_POST["id"], "software", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
        }
コード例 #7
0
 /**
  * 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;
 }
コード例 #8
0
 /**
  * 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";
 }
コード例 #9
0
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// ----------------------------------------------------------------------
define('GLPI_ROOT', '..');
include GLPI_ROOT . "/inc/includes.php";
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (!isset($_GET["softwares_id"])) {
    $_GET["softwares_id"] = "";
}
$license = new SoftwareLicense();
if (isset($_POST["add"])) {
    $license->check(-1, 'w', $_POST);
    $newID = $license->add($_POST);
    Event::log($_POST['softwares_id'], "software", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][85] . " {$newID}.");
    glpi_header($_SERVER['HTTP_REFERER']);
} else {
    if (isset($_POST["delete"])) {
        $license->check($_POST['id'], 'd');
        $license->delete($_POST);
        Event::log($license->fields['softwares_id'], "software", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][87] . " " . $_POST["id"]);
        $license->redirectToList();
    } else {
        if (isset($_POST["update"])) {
            $license->check($_POST['id'], 'w');
            $license->update($_POST);
コード例 #10
0
                break;
            case 5:
                Document::showAssociated($soft);
                break;
            case 6:
                Ticket::showListForItem('Software', $_POST["id"]);
                break;
            case 7:
                Link::showForItem('Software', $_POST["id"]);
                break;
            case 10:
                showNotesForm($_POST['target'], 'Software', $_POST["id"]);
                break;
            case 11:
                Reservation::showForItem('Software', $_POST["id"]);
                break;
            case 12:
                Log::showForItem($soft);
                break;
            case 21:
                $soft->showMergeCandidates();
                break;
            default:
                if (!Plugin::displayAction($soft, $_REQUEST['glpi_tab'])) {
                    SoftwareVersion::showForSoftware($soft);
                    SoftwareLicense::showForSoftware($soft);
                }
        }
    }
}
ajaxFooter();
コード例 #11
0
ファイル: order.form.php プロジェクト: geldarr/hack-space
     Html::redirect($_SERVER['HTTP_REFERER']);
 } else {
     if (isset($_POST["delete_item"])) {
         if (isset($_POST["plugin_order_orders_id"]) && $_POST["plugin_order_orders_id"] > 0 && isset($_POST["item"])) {
             foreach ($_POST["item"] as $ID => $val) {
                 if ($val == 1) {
                     $pluginOrderOrder_Item->getFromDB($ID);
                     if ($pluginOrderOrder_Item->fields["itemtype"] == 'SoftwareLicense') {
                         $result = $pluginOrderOrder_Item->queryRef($_POST["plugin_order_orders_id"], $pluginOrderOrder_Item->fields["plugin_order_references_id"], $pluginOrderOrder_Item->fields["price_taxfree"], $pluginOrderOrder_Item->fields["discount"]);
                         $nb = $DB->numrows($result);
                         if ($nb) {
                             for ($i = 0; $i < $nb; $i++) {
                                 $ID = $DB->result($result, $i, 'id');
                                 $items_id = $DB->result($result, $i, 'items_id');
                                 if ($items_id) {
                                     $lic = new SoftwareLicense();
                                     $lic->getFromDB($items_id);
                                     $values["id"] = $lic->fields["id"];
                                     $values["number"] = $lic->fields["number"] - 1;
                                     $lic->update($values);
                                 }
                                 $input["id"] = $ID;
                                 $pluginOrderOrder_Item->delete(array('id' => $input["id"]));
                             }
                             $new_value = __("Remove reference", "order") . " ";
                             $new_value .= Dropdown::getDropdownName("glpi_plugin_order_references", $ID);
                             $pluginOrderOrder->addHistory("PluginOrderOrder", "", $new_value, $_POST["plugin_order_orders_id"]);
                         }
                     } else {
                         $new_value = __("Remove reference", "order") . " ";
                         $new_value .= Dropdown::getDropdownName("glpi_plugin_order_references", $ID);
コード例 #12
0
/** Generate bigdump : generate items for an entity
 *
 * @param $ID_entity entity ID
**/
function generate_entity($ID_entity) {
   global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK,
         $DOCUMENTS, $NET_PORT, $NET_LOC;

   regenerateTreeCompleteName("glpi_entities");

   $current_year = date("Y");


   // DOMAIN
   $items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine");
   $dp    = new Domain();
   $FIRST["domain"] = getMaxItem("glpi_domains")+1;

   for ($i=0 ; $i<$MAX['domain'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "domain $ID_entity '$i";
      }
      $dp->add(toolbox::addslashes_deep(array('name'         => $val,
                                              'entities_id'  => $ID_entity,
                                              'is_recursive' => 1,
                                              'comment'      => "comment $val")));
   }
   $LAST["domain"] = getMaxItem("glpi_domains");


   // STATUS
   $items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'");
   $dp    = new State();
   $FIRST["state"] = getMaxItem("glpi_states")+1;
   for ($i=0 ; $i<$MAX['state'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "State $ID_entity '$i";
      }
      $state_id = $dp->add(toolbox::addslashes_deep(array('name'         => $val,
                                                          'entities_id'  => $ID_entity,
                                                          'is_recursive' => 1,
                                                          'comment'      => "comment $val")));

      // generate sub status
      for ($j=0 ; $j<$MAX['state'] ; $j++) {
         $val2 = "Sub $val $j";

         $dp->add(toolbox::addslashes_deep(array('name'         => $val2,
                                                 'entities_id'  => $ID_entity,
                                                 'is_recursive' => 1,
                                                 'states_id'    => $state_id,
                                                 'comment'      => "comment $val")));
      }

   }
   $LAST["state"]      = getMaxItem("glpi_states");


   // glpi_groups
   $FIRST["groups"] = getMaxItem("glpi_groups")+1;
   $group           = new Group();
   for ($i=0 ; $i<$MAX['groups'] ; $i++) {
      $gID = $group->add(toolbox::addslashes_deep(
                         array('entities_id'  => $ID_entity,
                               'name'         => "group d'$i",
                               'comment'      => "comment group d'$i",
                               'is_assign'    => 0)));

      // Generate sub group
      for ($j=0 ; $j<$MAX['groups'] ; $j++) {
         $group->add(toolbox::addslashes_deep(
                     array('entities_id'  => $ID_entity,
                           'name'         => "subgroup d'$j",
                           'comment'      => "comment subgroup d'$j of group $i",
                           'groups_id'    => $gID,
                           'is_assign'    => 0)));
      }
   }

   $LAST["groups"]      = getMaxItem("glpi_groups");

   $FIRST["techgroups"] = $LAST["groups"]+1;

   for ($i=0 ; $i<$MAX['groups'] ; $i++) {
         $group->add(toolbox::addslashes_deep(
                     array('entities_id'  => $ID_entity,
                           'name'         => "tech group d'$i",
                           'comment'      => "comment tech group d'$i")));
   }

   $LAST["techgroups"] = getMaxItem("glpi_groups");
   regenerateTreeCompleteName("glpi_groups");


   // glpi_users
   $FIRST["users_sadmin"] = getMaxItem("glpi_users")+1;
   $user                  = new User();
   $gu                    = new Group_User();
   for ($i=0 ; $i<$MAX['users_sadmin'] ; $i++) {
      $users_id = $user->add(toolbox::addslashes_deep(
                             array('name'               => "sadmin$i-$ID_entity",
                                   'password'           => "sadmin'$i",
                                   'password2'          => "sadmin'$i",
                                   'phone'              => "tel $i",
                                   'phone2'             => "tel2 $i",
                                   'mobile'             => "mobile $i",
                                   'realname'           => "sadmin '$i name",
                                   'firstname'          => "sadmin '$i firstname",
                                   'comment'            => "comment' $i",
                                   'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                   'usercategories_id'  => mt_rand(0,$MAX['user_type']),
                                   '_profiles_id'       => 4,
                                   '_entities_id'       => $ID_entity,
                                   '_is_recursive'      => 1
                                   )));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['groups'], $LAST['groups'])));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['techgroups'], $LAST['techgroups'])));
   }
   $LAST["users_sadmin"] = getMaxItem("glpi_users");
   $FIRST["users_admin"] = getMaxItem("glpi_users")+1;

   for ($i=0 ; $i<$MAX['users_admin'] ; $i++) {

      $users_id = $user->add(toolbox::addslashes_deep(
                             array('name'               => "admin$i-$ID_entity",
                                   'password'           => "admin'$i",
                                   'password2'          => "admin'$i",
                                   'phone'              => "tel $i",
                                   'phone2'             => "tel2 $i",
                                   'mobile'             => "mobile $i",
                                   'realname'           => "admin$i 'name",
                                   'firstname'          => "admin$i 'firstname",
                                   'comment'            => "comment '$i",
                                   'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                   'usercategories_id'  => mt_rand(0,$MAX['user_type']),
                                   '_profiles_id'       => 3,
                                   '_entities_id'       => $ID_entity,
                                   '_is_recursive'      => 1)));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['groups'], $LAST['groups']),
                     'is_manager'   => 1,
                     'is_delegate'  => 1));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['techgroups'], $LAST['techgroups']),
                     'is_manager'   => 1,
                     'is_delegate'  => 1));
   }

   $LAST["users_admin"]   = getMaxItem("glpi_users");
   $FIRST["users_normal"] = getMaxItem("glpi_users")+1;

   for ($i=0 ; $i<$MAX['users_normal'] ; $i++) {
      $users_id = $user->add(toolbox::addslashes_deep(
                             array('name'               => "normal$i-$ID_entity",
                                   'password'           => "normal'$i",
                                   'password2'          => "normal'$i",
                                   'phone'              => "tel $i",
                                   'phone2'             => "tel2 $i",
                                   'mobile'             => "mobile $i",
                                   'realname'           => "normal$i 'name",
                                   'firstname'          => "normal$i 'firstname",
                                   'comment'            => "comment '$i",
                                   'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                   'usercategories_id'  => mt_rand(0,$MAX['user_type']),
                                   '_profiles_id'       => 2,
                                   '_entities_id'       => $ID_entity,
                                   '_is_recursive'      => 1)));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['groups'], $LAST['groups'])));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['techgroups'], $LAST['techgroups'])));
   }

   $LAST["users_normal"]    = getMaxItem("glpi_users");
   $FIRST["users_postonly"] = getMaxItem("glpi_users")+1;

   for ($i=0 ; $i<$MAX['users_postonly'] ; $i++) {
      $users_id = $user->add(toolbox::addslashes_deep(
                             array('name'               => "postonly$i-$ID_entity",
                                   'password'           => "postonly'$i",
                                   'password2'          => "postonly'$i",
                                   'phone'              => "tel $i",
                                   'phone2'             => "tel2 $i",
                                   'mobile'             => "mobile $i",
                                   'realname'           => "postonly$i 'name",
                                   'firstname'          => "postonly$i 'firstname",
                                   'comment'            => "comment' $i",
                                   'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                   'usercategories_id'  => mt_rand(0,$MAX['user_type']),
                                   '_profiles_id'       => 1,
                                   '_entities_id'       => $ID_entity,
                                   '_is_recursive'      => 1)));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['groups'], $LAST['groups'])));
   }

   $LAST["users_postonly"] = getMaxItem("glpi_users");


   $FIRST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories")+1;
   $kbc                   = new KnowbaseItemCategory();

   for ($i=0 ; $i<max(1,pow($MAX['kbcategories'],1/3)) ; $i++) {
      $newID = $kbc->add(toolbox::addslashes_deep(
                         array('entities_id'     => $ID_entity,
                               'is_recursive'    => 1,
                               'name'            => "entity ' categorie $i",
                               'comment'         => "comment ' categorie $i")));

      for ($j=0 ; $j<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $j++) {
         $newID2 = $kbc->add(toolbox::addslashes_deep(
                             array('entities_id'                 => $ID_entity,
                                   'is_recursive'                => 1,
                                   'name'                        => "entity s-categorie '$j",
                                   'comment'                     => "comment s-categorie '$j",
                                   'knowbaseitemcategories_id'   => $newID)));

         for ($k=0 ; $k<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $k++) {
            $newID2 = $kbc->add(toolbox::addslashes_deep(
                                array('entities_id'               => $ID_entity,
                                      'is_recursive'              => 1,
                                      'name'                      => "entity ss-categorie' $k",
                                      'comment'                   => "comment ss-categorie' $k",
                                      'knowbaseitemcategories_id' => $newID2)));
         }
      }
   }

   $query = "OPTIMIZE TABLE `glpi_knowbaseitemcategories`";
   $DB->query($query) or die("PB REQUETE ".$query);

   regenerateTreeCompleteName("glpi_knowbaseitemcategories");
   $LAST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories");


   // LOCATIONS
   $added              = 0;
   $FIRST["locations"] = getMaxItem("glpi_locations")+1;
   $loc                = new Location();
   for ($i=0 ; $i<pow($MAX['locations'],1/5)&&$added<$MAX['locations'] ; $i++) {
      $added++;
      $newID = $loc->add(toolbox::addslashes_deep(
                         array('entities_id'     => $ID_entity,
                               'is_recursive'    => 1,
                               'name'            => "location' $i",
                               'comment'         => "comment 'location $i",
                               'building'        => "building $i")));

      for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) {
         $added++;
         $newID2 = $loc->add(toolbox::addslashes_deep(
                             array('entities_id'     => $ID_entity,
                                   'is_recursive'    => 1,
                                   'name'            => "s-location '$j",
                                   'comment'         => "comment s-location '$j",
                                   'building'        => "building $i",
                                   'room'            => "stage '$j",
                                   'locations_id'    => $newID)));

         for ($k=0 ; $k<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $k++) {
            $added++;
            $newID3 = $loc->add(toolbox::addslashes_deep(
                                array('entities_id'     => $ID_entity,
                                      'is_recursive'    => 1,
                                      'name'            => "ss-location '$k",
                                      'comment'         => "comment ss-location' $k",
                                      'building'        => "building $i",
                                      'room'            => "part' $k",
                                      'locations_id'    => $newID2)));

            for ($l=0 ; $l<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $l++) {
               $added++;
               $newID4 = $loc->add(toolbox::addslashes_deep(
                                   array('entities_id'     => $ID_entity,
                                         'is_recursive'    => 1,
                                         'name'            => "sss-location' $l",
                                         'comment'         => "comment sss-location' $l",
                                         'building'        => "building $i",
                                         'room'            => "room' $l",
                                         'locations_id'    => $newID3)));

               for ($m=0 ; $m<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $m++) {
                  $added++;
                  $newID5 = $loc->add(toolbox::addslashes_deep(
                                      array('entities_id'     => $ID_entity,
                                            'is_recursive'    => 1,
                                            'name'            => "ssss-location' $m",
                                            'comment'         => "comment ssss-location' $m",
                                            'building'        => "building $i",
                                            'room'            => "room' $l-$m",
                                            'locations_id'    => $newID4)));
               }
            }
         }
      }
   }

   $query = "OPTIMIZE TABLE `glpi_locations`";
   $DB->query($query) or die("PB REQUETE ".$query);

   regenerateTreeCompleteName("glpi_locations");
   $LAST["locations"]=getMaxItem("glpi_locations");


   // Task categories
   $added                 = 0;
   $FIRST["taskcategory"] = getMaxItem("glpi_taskcategories")+1;
   $tc                    = new TaskCategory();
   for ($i=0 ; $i<pow($MAX['taskcategory'],1/5)&&$added<$MAX['taskcategory'] ; $i++) {
      $added++;
      $newID = $tc->add(toolbox::addslashes_deep(
                        array('entities_id'     => $ID_entity,
                              'is_recursive'    => 1,
                              'name'            => "ent$ID_entity taskcategory' $i",
                              'comment'         => "comment ent$ID_entity taskcategory' $i")));

      for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) {
         $newID2 = $tc->add(toolbox::addslashes_deep(
                            array('entities_id'        => $ID_entity,
                                  'is_recursive'       => 1,
                                  'name'               => "ent$ID_entity taskcategory' $i",
                                  'comment'            => "comment ent$ID_entity taskcategory' $i",
                                  'taskcategories_id'  => $newID)));
         $added++;
      }
   }

   $query = "OPTIMIZE TABLE `glpi_taskcategories`";
   $DB->query($query) or die("PB REQUETE ".$query);

   regenerateTreeCompleteName("glpi_taskcategories");
   $LAST["taskcategory"] = getMaxItem("glpi_taskcategories");

   $ic = new ItilCategory();
   // Specific ticket categories
   $newID = $ic->add(toolbox::addslashes_deep(
                     array('entities_id'     => $ID_entity,
                           'is_recursive'    => 1,
                           'name'            => "category for entity' $ID_entity",
                           'comment'         => "comment category for entity' $ID_entity",
                           'users_id'        => mt_rand($FIRST['users_sadmin'],$LAST['users_admin']),
                           'groups_id'       => mt_rand($FIRST['techgroups'],$LAST['techgroups']),
                           'tickettemplates_id_incident' => 1,
                           'tickettemplates_id_demand'   => 1)));

   for ($i=0 ; $i<max(1,pow($MAX['tracking_category'],1/3)) ; $i++) {
      $ic->add(toolbox::addslashes_deep(
               array('entities_id'                 => $ID_entity,
                     'is_recursive'                => 1,
                     'name'                        => "scategory for entity' $ID_entity",
                     'comment'                     => "comment scategory for entity' $ID_entity",
                     'users_id'                    => mt_rand($FIRST['users_sadmin'],
                                                              $LAST['users_admin']),
                     'groups_id'                   => mt_rand($FIRST['techgroups'],
                                                              $LAST['techgroups']),
                     'tickettemplates_id_incident' => 1,
                     'tickettemplates_id_demand'   => 1,
                     'itilcategories_id'           => $newID)));
   }

   regenerateTreeCompleteName("glpi_itilcategories");

   $FIRST["solutiontypes"] = getMaxItem("glpi_solutiontypes")+1;

   $items = array("d'après KB");
   $st    = new SolutionType();
   for ($i=0 ; $i<$MAX['solutiontypes'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "type de solution ' $i";
      }
      $st->add(toolbox::addslashes_deep(array('name'         => $val,
                                              'comment'      => "comment $val",
                                              'entities_id'  => $ID_entity,
                                              'is_recursive' => 1)));
   }
   $LAST["solutiontypes"] = getMaxItem("glpi_solutiontypes");


   $FIRST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates")+1;
   $nb_items                   = mt_rand(0,$MAX['solutiontemplates']);
   $st                         = new SolutionTemplate();
   for ($i=0 ; $i<$nb_items ; $i++) {
      $st-> add(toolbox::addslashes_deep(
                array('entities_id'        => $ID_entity,
                      'is_recursive'       => 1,
                      'name'               => "solution' $i-$ID_entity",
                      'content'            => "content solution' $i-$ID_entity",
                      'solutiontypes_id'   => mt_rand(0,$MAX['solutiontypes']),
                      'comment'            => "comment solution' $i-$ID_entity")));
   }

   $LAST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates");

   // Add Specific questions
   $k                = 0;
   $FIRST["kbitems"] = getMaxItem("glpi_knowbaseitems")+1;
   $ki               = new KnowbaseItem();
   $eki              = new Entity_KnowbaseItem();
   for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) {
      $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT);
      for ($j=0 ; $j<$nb ; $j++) {
         $k++;
         $newID = $ki->add(toolbox::addslashes_deep(
                           array('knowbaseitemcategories_id'   => $i,
                                 'name'      => "Entity' $ID_entity Question $k",
                                 'answer'    => "Answer' $k".Toolbox::getRandomString(50),
                                 'is_faq'    => mt_rand(0,1),
                                 'users_id'  => mt_rand($FIRST['users_sadmin'],
                                                        $LAST['users_admin']))));

         $eki->add(array('entities_id'       => $ID_entity,
                        'knowbaseitems_id'   => $newID,
                        'is_recursive'       => 0));
      }
   }


   // Add global questions
   for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) {
      $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT);
      for ($j=0 ; $j<$nb ; $j++) {
         $k++;
         $newID = $ki->add(toolbox::addslashes_deep(
                           array('knowbaseitemcategories_id'   => $i,
                                 'name'      => "Entity' $ID_entity Recursive Question $k",
                                 'answer'    => "Answer' $k".Toolbox::getRandomString(50),
                                 'is_faq'    => mt_rand(0,1),
                                 'users_id'  => mt_rand($FIRST['users_sadmin'],
                                                        $LAST['users_admin']))));

         $eki->add(array('entities_id'       => $ID_entity,
                        'knowbaseitems_id'   => $newID,
                        'is_recursive'       => 1));
      }
   }

   $LAST["kbitems"] = getMaxItem("glpi_knowbaseitems");


   // Ajout documents  specific
   $FIRST["document"] = getMaxItem("glpi_documents")+1;
   $doc               = new Document();
   for ($i=0 ; $i<$MAX['document'] ; $i++) {
      $link = "";
      if (mt_rand(0,100)<50) {
         $link = "http://linktodoc/doc$i";
      }

      $docID = $doc->add(toolbox::addslashes_deep(
                         array('entities_id'           => $ID_entity,
                               'is_recursive'          => 0,
                               'name'                  => "document' $i-$ID_entity",
                               'documentcategories_id' => mt_rand(1,$MAX['rubdocs']),
                               'comment'               => "commen't $i",
                               'link'                  => $link,
                               'notepad'               => "notes document' $i")));

      $DOCUMENTS[$docID] = $ID_entity."-0";
   }


   // Global ones
   for ($i=0 ; $i<$MAX['document']/2 ; $i++) {
      $link = "";
      if (mt_rand(0,100)<50) {
         $link = "http://linktodoc/doc$i";
      }

      $docID = $doc->add(toolbox::addslashes_deep(
                         array('entities_id'           => $ID_entity,
                               'is_recursive'          => 1,
                               'name'                  => "Recursive document' $i-$ID_entity",
                               'documentcategories_id' => mt_rand(1,$MAX['rubdocs']),
                               'comment'               => "comment' $i",
                               'link'                  => $link,
                               'notepad'               => "notes document' $i")));

      $DOCUMENTS[$docID] = $ID_entity."-1";
   }

   $LAST["document"] = getMaxItem("glpi_documents");


   // Ajout budgets  specific
   $FIRST["budget"] = getMaxItem("glpi_budgets")+1;
   $b               = new Budget();
   for ($i=0 ; $i<$MAX['budget'] ; $i++) {
      $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
      $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans

      $b->add(toolbox::addslashes_deep(
              array('name'         => "budget' $i-$ID_entity",
                    'entities_id'  => $ID_entity,
                    'is_recusive'  => 0,
                    'comment'      => "comment' $i-$ID_entity",
                    'begin_date'   => date("Y-m-d",intval($date1)),
                    'end_date'     => date("Y-m-d",intval($date2)))));
   }
   $LAST["budget"] = getMaxItem("glpi_budgets");

   // GLobal ones
   for ($i=0 ; $i<$MAX['document']/2 ; $i++) {
      $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
      $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans

      $b->add(toolbox::addslashes_deep(
              array('name'         => "Recursive budget' $i-$ID_entity",
                    'entities_id'  => $ID_entity,
                    'is_recusive'  => 1,
                    'comment'      => "comment' $i-$ID_entity",
                    'begin_date'   => date("Y-m-d",intval($date1)),
                    'end_date'     => date("Y-m-d",intval($date2)))));

   }
   $LAST["document"] = getMaxItem("glpi_documents");


   // glpi_suppliers
   $items                = array("DELL", "IBM", "ACER", "Microsoft", "Epson", "Xerox",
                                 "Hewlett Packard", "Nikon", "Targus", "LG", "Samsung", "Lexmark");
   $FIRST["enterprises"] = getMaxItem("glpi_suppliers")+1;
   $ent                  = new Supplier();

   // Global ones
   for ($i=0 ; $i<$MAX['enterprises']/2 ; $i++) {
      if (isset($items[$i])) {
         $val = "Recursive ".$items[$i];
      } else {
         $val = "Recursive enterprise_".$i."_ID_entity";
      }
      $entID = $ent->add(toolbox::addslashes_deep(
                         array('entities_id'        => $ID_entity,
                               'is_recursive'       => 1,
                               'name'               => "Recursive' $val-$ID_entity",
                               'suppliertypes_id'   => mt_rand(1,$MAX['enttype']),
                               'address'            => "address' $i",
                               'postcode'           => "postcode $i",
                               'town'               => "town' $i",
                               'state'              => "state' $i",
                               'country'            => "country $i",
                               'website'            => "http://www.$val.com/",
                               'fax'                => "fax $i",
                               'email'              => "info@ent$i.com",
                               'notepad'            => "notes enterprises' $i")));

      addDocuments('Supplier', $entID);
   }


   // Specific ones
   for ($i=0 ; $i<$MAX['enterprises'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "enterprise_".$i."_ID_entity";
      }

      $entID = $ent->add(toolbox::addslashes_deep(
                         array('entities_id'        => $ID_entity,
                               'is_recursive'       => 0,
                               'name'               => "'$val-$ID_entity",
                               'suppliertypes_id'   => mt_rand(1,$MAX['enttype']),
                               'address'            => "address' $i",
                               'postcode'           => "postcode $i",
                               'town'               => "town' $i",
                               'state'              => "state' $i",
                               'country'            => "country $i",
                               'website'            => "http://www.$val.com/",
                               'fax'                => "fax $i",
                               'email'              => "info@ent$i.com",
                               'notepad'            => "notes supplier' $i",
                               'comment'            => "comment supplier' $i")));

      addDocuments('Supplier', $entID);
   }
   $LAST["enterprises"] = getMaxItem("glpi_suppliers");


   // Ajout contracts
   $FIRST["contract"] = getMaxItem("glpi_contracts")+1;
   $c                 = new Contract();
   $cs                = new Contract_Supplier();
   $cc                = new ContractCost();
   // Specific
   for ($i=0 ; $i<$MAX['contract'] ; $i++) {
      $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28);
      $contractID = $c->add(toolbox::addslashes_deep(
                            array('entities_id'        => $ID_entity,
                                  'is_recursive'       => 0,
                                  'name'               => "contract' $i-$ID_entity",
                                  'num'                => "num' $i",
                                  'contracttypes_id'   => mt_rand(1,$MAX['contract_type']),
                                  'begin_date'         => $date,
                                  'duration'           => mt_rand(1,36),
                                  'notice'             => mt_rand(1,3),
                                  'periodicity'        => mt_rand(1,36),
                                  'billing'            => mt_rand(1,36),
                                  'comment'            => "comment' $i",
                                  'accounting_number'  => "compta num' $i",
                                  'renewal'            => 1)));

      addDocuments('Contract', $contractID);

      // Add an enterprise
      $cs->add(array('contracts_id' => $contractID,
                     'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"])));
      // Add a cost
      $cc->add(toolbox::addslashes_deep(
               array('contracts_id' => $contractID,
                     'cost'         => mt_rand(100,10000),
                     'name'         => "Initial 'cost",
                     'begin_date'   => $date,
                     'budgets_id'   => mt_rand($FIRST['budget'], $LAST['budget']))));
   }

   for ($i=0 ; $i<$MAX['contract']/2 ; $i++) {
      $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28);

      $contractID = $c->add(toolbox::addslashes_deep(
                            array('entities_id'        => $ID_entity,
                                  'is_recursive'       => 1,
                                  'name'               => "Recursive contract' $i-$ID_entity",
                                  'num'                => "num' $i",
                                  'cost'               => mt_rand(100,10000),
                                  'contracttypes_id'   => mt_rand(1,$MAX['contract_type']),
                                  'begin_date'         => $date,
                                  'duration'           => mt_rand(1,36),
                                  'notice'             => mt_rand(1,3),
                                  'periodicity'        => mt_rand(1,36),
                                  'billing'            => mt_rand(1,36),
                                  'comment'            => "comment' $i",
                                  'accounting_number'  => "compta num' $i",
                                  'renewal'            => 1)));

      addDocuments('Contract', $contractID);

      // Add an enterprise
      $cs->add(array('contracts_id' => $contractID,
                     'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"])));
   }
   $LAST["contract"] = getMaxItem("glpi_contracts");


   // Ajout contacts
   $prenoms = array("Jean", "John", "Louis", "Pierre", "Auguste",
                    "Albert", "Julien", "Guillaume", "Bruno",
                    "Maurice", "Francois", "Laurent", "Richard",
                    "Henri", "Clement", "d'avy");
   $noms    = array("Dupont", "Smith", "Durand", "Martin", "Dubois",
                    "Dufour", "Dupin", "Duval", "Petit", "Grange",
                    "Bernard", "Bonnet", "Richard", "Leroy",
                    "Dumont", "Fontaine", "d'orleans");


   $FIRST["contacts"] = getMaxItem("glpi_contacts")+1;
   $c                 = new Contact();
   $cs                = new Contact_Supplier();
   for ($i=0 ; $i<$MAX['contacts'] ; $i++) {
      if (isset($noms[$i])) {
         $val = $noms[$i];
      } else {
         $val = "name $i";
      }
      if (isset($prenoms[$i])) {
         $val2 = $prenoms[$i];
      } else {
         $val2 = "firstname $i";
      }

      $contactID = $c->add(toolbox::addslashes_deep(
                           array('entities_id'        => $ID_entity,
                                 'is_recursive'       => 0,
                                 'name'               => "$val-$ID_entity",
                                 'firstname'          => $val2,
                                 'contacttypes_id'    => mt_rand(1,$MAX['contact_type']),
                                 'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                 'phone'              => "phone $i",
                                 'phone2'             => "phone2 $i",
                                 'mobile'             => "mobile $i",
                                 'fax'                => "fax $i",
                                 'email'              => "email $i",
                                 'address'            => "address' $i",
                                 'postcode'           => "postcode $i",
                                 'town'               => "town' $i",
                                 'state'              => "state' $i",
                                 'country'            => "country $i",
                                 'comment'            => "Comment' $i")));

      // Link with enterprise
      $cs->add(array('contacts_id'  => $contactID,
                     'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises'])));
   }

   for ($i=0 ; $i<$MAX['contacts']/2 ; $i++) {
      if (isset($items[$i])) {
         $val = "Recursive ".$items[$i];
      } else {
         $val = "Recursive contact $i";
      }
      $contactID = $c->add(toolbox::addslashes_deep(
                           array('entities_id'        => $ID_entity,
                                 'is_recursive'       => 0,
                                 'name'               => "$val'-$ID_entity",
                                 'contacttypes_id'    => mt_rand(1,$MAX['contact_type']),
                                 'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                 'phone'              => "phone $i",
                                 'phone2'             => "phone2 $i",
                                 'mobile'             => "mobile $i",
                                 'fax'                => "fax $i",
                                 'email'              => "email $i",
                                 'address'            => "address' $i",
                                 'postcode'           => "postcode $i",
                                 'town'               => "town' $i",
                                 'state'              => "state' $i",
                                 'country'            => "country $i",
                                 'comment'            => "Comment' $i")));

      // Link with enterprise
      $cs->add(array('contacts_id'  => $contactID,
                     'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises'])));
   }
   $LAST["contacts"] = getMaxItem("glpi_contacts");


   // TYPE DE CONSOMMABLES
   $FIRST["type_of_consumables"] = getMaxItem("glpi_consumableitems")+1;
   $ci                           = new Consumableitem();

   for ($i=0 ; $i<$MAX['type_of_consumables'] ; $i++) {
      $consID = $ci->add(toolbox::addslashes_deep(
                         array('entities_id'             => $ID_entity,
                               'is_recursive'            => mt_rand(0,1),
                               'name'                    => "consumable type' $i",
                               'ref'                     => "ref d' $i",
                               'locations_id'            => mt_rand($FIRST["locations"],
                                                                    $LAST['locations']),
                               'consumableitemtypes_id'  => mt_rand(0,$MAX['consumable_type']),
                               'manufacturers_id'        => mt_rand(1,$MAX['manufacturer']),
                               'users_id_tech'           => mt_rand($FIRST['users_sadmin'],
                                                                    $LAST['users_admin']),
                               'groups_id_tech'          => mt_rand($FIRST["groups"], $LAST["groups"]),
                               'comment'                 => "comment' $i",
                               'notepad'                 => "notes consumableitem' $i",
                               'alarm_threshold'         => mt_rand(0,10))));

      addDocuments('ConsumableItem', $consID);


      // AJOUT INFOCOMS
      addInfocoms('ConsumableItem', $consID, $ID_entity);

      // Ajout consommable en stock
      $c = new Consumable();
      for ($j=0 ; $j<mt_rand(0,$MAX['consumables_stock']) ; $j++) {
         $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28);

         $ID = $c->add(array('entities_id'        => $ID_entity,
                             'consumableitems_id' => $consID,
                             'date_in'            => $date));

         // AJOUT INFOCOMS
         addInfocoms('Consumable', $ID, $ID_entity);
      }


      // Ajout consommable donne
      for ($j=0 ; $j<mt_rand(0,$MAX['consumables_given']) ; $j++) {
         $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28);

         $ID = $c->add(array('entities_id'        => $ID_entity,
                             'consumableitems_id' => $consID,
                             'date_in'            => $date,
                             'date_out'           => date("Y-m-d")));

         // AJOUT INFOCOMS
         addInfocoms('Consumable', $ID, $ID_entity);

      }

   }
   $LAST["type_of_consumables"] = getMaxItem("glpi_consumableitems");


   // TYPE DE CARTOUCHES
   $FIRST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems")+1;
   $ct                          = new CartridgeItem();

   for ($i=0 ; $i<$MAX['type_of_cartridges'] ; $i++) {
      $cartID = $ct->add(toolbox::addslashes_deep(
                         array('entities_id'       => $ID_entity,
                               'is_recursive'      => mt_rand(0,1),
                               'name'              => "cartridge ' type $i",
                               'ref'               => "ref '$i",
                               'locations_id'      => mt_rand($FIRST["locations"], $LAST['locations']),
                               'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                               'users_id_tech'     => mt_rand($FIRST['users_sadmin'],
                                                              $LAST['users_admin']),
                               'groups_id_tech'    => mt_rand($FIRST["groups"], $LAST["groups"]),
                               'comment'           => "comment '$i",
                               'notepad'           => "notes cartridgeitem '$i",
                               'alarm_threshold'   => mt_rand(0,10))));

      addDocuments('CartridgeItem', $cartID);


      // AJOUT INFOCOMS
      addInfocoms('CartridgeItem', $cartID, $ID_entity);

      $c    = new Cartridge();
      $cipm = new CartridgeItem_PrinterModel();
      // Ajout cartouche en stock
      for ($j=0 ; $j<mt_rand(0,$MAX['cartridges_stock']) ; $j++) {
         $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28);

         $ID = $c->add(array('entities_id'         => $ID_entity,
                             'cartridgeitems_id'   => $cartID,
                             'date_in'             => $date));

         // AJOUT INFOCOMS
         addInfocoms('Cartridge', $ID, $ID_entity);

      }

      // Assoc printer type to cartridge type
      $cipm->add(array('cartridgeitems_id'  => $cartID,
                       'printermodels_id'   => mt_rand(1,$MAX['type_printers']),
                     ));
   }
   $LAST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems");


   // Networking
   $NET_LOC             = array();
   $FIRST["networking"] = getMaxItem("glpi_networkequipments")+1;
   $FIRST["printers"]   = getMaxItem("glpi_printers")+1;
   $ne                  = new NetworkEquipment();
   $p                   = new Printer();
   $np                  = new Netpoint();
   $c                   = new Cartridge();

   foreach ($DB->request('glpi_locations') as $data) {
      $i          = $data["id"];
      $techID     = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']);
      $gtechID    = mt_rand($FIRST["techgroups"],$LAST["techgroups"]);
      $infoIP     = getNextIP();
      $domainID   = mt_rand($FIRST['domain'],$LAST['domain']);
      $networkID  = mt_rand(1,$MAX['network']);

      // insert networking

      $netwID = $ne->add(toolbox::addslashes_deep(
                         array('entities_id'                   => $ID_entity,
                               'name'                          => "networking '$i-$ID_entity",
                               'ram'                           => mt_rand(32,256),
                               'serial'                        => Toolbox::getRandomString(10),
                               'otherserial'                   => Toolbox::getRandomString(10),
                               'contact'                       => "contact '$i",
                               'contact_num'                   => "num '$i",
                               'users_id_tech'                 => $techID,
                               'groups_id_tech'                => $gtechID,
                               'comment'                       => "comment '$i",
                               'locations_id'                  => $i,
                               'domains_id'                    => $domainID,
                               'networks_id'                   => $networkID,
                               'networkequipmenttypes_id'      => mt_rand(1,$MAX['type_networking']),
                               'networkequipmentmodels_id'     => mt_rand(1,$MAX['model_networking']),
                               'networkequipmentfirmwares_id'  => mt_rand(1,$MAX['firmware']),
                               'manufacturers_id'              => mt_rand(1,$MAX['enterprises']),
                               'mac'                           => getNextMAC(),
                               'ip'                            => $infoIP["ip"],
                               'notepad'                       => "notes networking '$i",
                               'users_id'                      => mt_rand($FIRST['users_sadmin'],
                                                                          $LAST['users_admin']),
                               'groups_id'                     => mt_rand($FIRST["groups"],
                                                                          $LAST["groups"]),
                               'states_id'                     => (mt_rand(0,100)<$percent['state']
                                                                     ?mt_rand($FIRST['state'],$LAST['state']):0)
                           )));
      $NET_LOC[$data['id']] = $netwID;
      addDocuments('NetworkEquipment', $netwID);
      addContracts('NetworkEquipment', $netwID);

      // AJOUT INFOCOMS
      addInfocoms('NetworkEquipment', $netwID, $ID_entity);

      // Link with father
      addNetworkEthernetPort('NetworkEquipment', $netwID, $ID_entity, $i);

      // Ajout imprimantes reseaux : 1 par loc + connexion d un matos reseau + ajout de cartouches
      // Add trackings
      addTracking('NetworkEquipment', $netwID, $ID_entity);

      $typeID  = mt_rand(1,$MAX['type_printers']);
      $modelID = mt_rand(1,$MAX['model_printers']);
      $recur   = mt_rand(0,1);

      $printID = $p->add(toolbox::addslashes_deep(
                         array('entities_id'      => $ID_entity,
                                'is_recursive'     => $recur,
                                'name'             => "printer of loc '$i",
                                'serial'           => Toolbox::getRandomString(10),
                                'otherserial'      => Toolbox::getRandomString(10),
                                'contact'          => "contact '$i",
                                'contact_num'      => "num' $i",
                                'users_id_tech'    => $techID,
                                'groups_id_tech'   => $gtechID,
                                'have_serial'      => mt_rand(0,1),
                                'have_parallel'    => mt_rand(0,1),
                                'have_usb'         => mt_rand(0,1),
                                'have_wifi'        => mt_rand(0,1),
                                'have_ethernet'    => mt_rand(0,1),
                                'comment'          => "comment' $i",
                                'memory_size'      => mt_rand(0,128),
                                'locations_id'     => $i,
                                'domains_id'       => $domainID,
                                'networks_id'      => $networkID,
                                'printertypes_id'  => $typeID,
                                'printermodels_id' => $modelID,
                                'manufacturers_id' => mt_rand(1,$MAX['enterprises']),
                                'is_global'        => 1,
                                'notepad'          => "notes printers '$i",
                                'users_id'         => mt_rand($FIRST['users_sadmin'],
                                                              $LAST['users_admin']),
                                'groups_id'        => mt_rand($FIRST["groups"], $LAST["groups"]),
                                'states_id'        => (mt_rand(0,100)<$percent['state']
                                                         ?mt_rand($FIRST['state'],$LAST['state']):0)
                           )));

      addDocuments('Printer', $printID);
      addContracts('Printer', $printID);

      // Add trackings
      addTracking('Printer', $printID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Printer', $printID, $ID_entity, $recur);

      // Add Cartouches
      // Get compatible cartridge
      $query = "SELECT `cartridgeitems_id`
                FROM `glpi_cartridgeitems_printermodels`
                WHERE `printermodels_id` = '$typeID'";
      $result2 = $DB->query($query) or die("PB REQUETE ".$query);

      if ($DB->numrows($result2)>0) {
         $ctypeID = $DB->result($result2,0,0) or die (" PB RESULT ".$query);
         $printed = 0;
         $oldnb   = mt_rand(1,$MAX['cartridges_by_printer']);
         $date1   = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
         $date2   = time();
         $inter   = abs(round(($date2-$date1)/$oldnb));

         // Add old cartridges
         for ($j=0 ; $j<$oldnb ; $j++) {
            $printed += mt_rand(0,5000);
            $c->add(array('entities_id'        => $ID_entity,
                          'cartridgeitems_id'  => $ctypeID,
                          'printers_id'        => $printID,
                          'date_in'            => date("Y-m-d",$date1),
                          'date_use'           => date("Y-m-d",$date1+$j*$inter),
                          'date_out'           => date("Y-m-d",$date1+($j+1)*$inter),
                          'pages'              => $printed));
         }

         // Add current cartridges
         $c->add(array('entities_id'        => $ID_entity,
                       'cartridgeitems_id'  => $ctypeID,
                       'printers_id'        => $printID,
                       'date_in'            => $date,
                       'date_use'           => date("Y-m-d",$date2)));
      }

      $iface = mt_rand(1,$MAX['iface']);

      // Add networking ports
      addNetworkEthernetPort('Printer', $printID, $ID_entity, $i);
   }
   unset($NET_LOC);
   $LAST["networking"] = getMaxItem("glpi_networkequipments");


   //////////// INVENTORY

   // glpi_computers
   $FIRST["computers"]   = getMaxItem("glpi_computers")+1;
   $FIRST["monitors"]    = getMaxItem("glpi_monitors")+1;
   $FIRST["phones"]      = getMaxItem("glpi_phones")+1;
   $FIRST["peripherals"] = getMaxItem("glpi_peripherals")+1;
   $c       = new Computer();
   $mon     = new Monitor();

   $cdevmb    = new Item_DeviceMotherBoard();
   $cdevproc  = new Item_DeviceProcessor();
   $cdevmem   = new Item_DeviceMemory();
   $cdevhd    = new Item_DeviceHardDrive();
   $cdevnc    = new Item_DeviceNetworkCard();
   $cdevdr    = new Item_DeviceDrive();
   $cdevcon   = new Item_DeviceControl();
   $cdevgc    = new Item_DeviceGraphicCard();
   $cdevsc    = new Item_DeviceSoundCard();
   $cdevpci   = new Item_DevicePci();
   $cdevcase  = new Item_DeviceCase();
   $cdevps    = new Item_DevicePowerSupply();

   $cdisk   = new ComputerDisk();
   $np      = new Netpoint();
   $ci      = new Computer_Item();
   $phone   = new Phone();
   $print   = new Printer();
   $periph  = new Peripheral();
   $cart    = new Cartridge();
   for ($i=0 ; $i<$MAX['computers'] ; $i++) {
      $loc       = mt_rand($FIRST["locations"],$LAST['locations']);
      $techID    = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']);
      $userID    = mt_rand($FIRST['users_normal'],$LAST['users_postonly']);
      $groupID   = mt_rand($FIRST["groups"],$LAST["groups"]);
      $gtechID   = mt_rand($FIRST["techgroups"],$LAST["techgroups"]);
      $domainID  = mt_rand($FIRST['domain'],$LAST['domain']);
      $networkID = mt_rand(1,$MAX['network']);

      $compID = $c->add(toolbox::addslashes_deep(
                        array('entities_id'                    => $ID_entity,
                              'name'                           => "computer ' $i-$ID_entity",
                              'serial'                         => Toolbox::getRandomString(10),
                              'otherserial'                    => Toolbox::getRandomString(10),
                              'contact'                        => "contact' $i",
                              'contact_num'                    => "num' $i",
                              'users_id_tech'                  => $techID,
                              'groups_id_tech'                 => $gtechID,
                              'comment'                        => "comment' $i",
                              'operatingsystems_id'            => mt_rand(1,$MAX['os']),
                              'operatingsystemversions_id'     => mt_rand(1,$MAX['os_version']),
                              'operatingsystemservicepacks_id' => mt_rand(1,$MAX['os_sp']),
                              'os_license_number'              => "os sn $i",
                              'os_licenseid'                   => "os id $i",
                              'autoupdatesystems_id'           => mt_rand(1,$MAX['os_sp']),
                              'locations_id'                   => $loc,
                              'domains_id'                     => $domainID,
                              'networks_id'                    => $networkID,
                              'computertypes_id'               => mt_rand(1,$MAX['type_computers']),
                              'computermodels_id'              => mt_rand(1,$MAX['model']),
                              'manufacturers_id'               => mt_rand(1,$MAX['manufacturer']),
                              'is_global'                      => 1,
                              'notepad'                        => "notes computer '$i",
                              'users_id'                       => $userID,
                              'groups_id'                      => $groupID,
                              'states_id'                      => (mt_rand(0,100)<$percent['state']
                                                                     ?mt_rand($FIRST['state'],$LAST['state']):0),
                              'uuid'                           => Toolbox::getRandomString(30)
                           )));

      addDocuments('Computer', $compID);
      addContracts('Computer', $compID);

      $NET_PORT['Computer'][$compID] = 0;

      // Add trackings
      addTracking('Computer', $compID, $ID_entity);

      // Add reservation
      addReservation('Computer', $compID, $ID_entity);


      // AJOUT INFOCOMS
      addInfocoms('Computer', $compID, $ID_entity);

      // ADD DEVICE
      $cdevmb->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15)));

      $max   = mt_rand(1,4);
      $devid = mt_rand(1,$MAX['device']);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevproc->addDevices(1, 'Computer', $compID, $devid,
                               array('serial' => Toolbox::getRandomString(15)));
      }
      $max   = mt_rand(1,4);
      $devid = mt_rand(1,$MAX['device']);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevmem->addDevices(1, 'Computer', $compID, $devid,
                              array('serial' => Toolbox::getRandomString(15)));
      }

      $max = mt_rand(1,2);
      $devid = mt_rand(1,$MAX['device']);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevhd->addDevices(1, 'Computer', $compID, $devid,
                             array('serial' => Toolbox::getRandomString(15)));
      }

      $cdevnc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15),
                                'mac'    => getNextMAC()));

      $cdevdr->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15)));

      $cdevcon->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                           array('serial' => Toolbox::getRandomString(15)));

      $cdevgc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15)));

      $cdevsc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15)));

      $max = mt_rand(1,4);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevpci->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                              array('serial' => Toolbox::getRandomString(15)));
      }

      $cdevcase->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                            array('serial'=> Toolbox::getRandomString(15)));

      $max   = mt_rand(1,2);
      $devid = mt_rand(1,$MAX['device']);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevps->addDevices(1, 'Computer', $compID, $devid,
                             array('serial' => Toolbox::getRandomString(15)));
      }

      // insert disk
      $nb_disk = mt_rand(1,$MAX_DISK);
      for ($j=1 ; $j<=$nb_disk ; $j++) {
         $totalsize = mt_rand(10000,1000000);
         $freesize  = mt_rand(0,$totalsize);

         $cdisk->add(toolbox::addslashes_deep(
                      array('entities_id'     => $ID_entity,
                            'computers_id'    => $compID,
                            'name'            => "disk '$j",
                            'device'          => "/dev/disk$j",
                            'mountpoint'      => "/mnt/disk$j",
                            'filesystems_id'  => mt_rand(1,10),
                            'totalsize'       => $totalsize,
                            'freesize'        => $freesize)));
      }


      // Add networking ports
      addNetworkEthernetPort('Computer', $compID, $ID_entity, $loc);

      // Ajout d'un ecran sur l'ordi
      $monID = $mon->add(toolbox::addslashes_deep(
                         array('entities_id'       => $ID_entity,
                               'name'              => "monitor' $i-$ID_entity",
                               'serial'            => Toolbox::getRandomString(10),
                               'otherserial'       => Toolbox::getRandomString(10),
                               'contact'           => "contact' $i",
                               'contact_num'       => "num' $i",
                               'users_id_tech'     => $techID,
                               'groups_id_tech'    => $gtechID,
                               'comment'           => "comment' $i",
                               'size'              => mt_rand(14,22),
                               'have_micro'        => mt_rand(0,1),
                               'have_speaker'      => mt_rand(0,1),
                               'have_subd'         => mt_rand(0,1),
                               'have_bnc'          => mt_rand(0,1),
                               'have_dvi'          => mt_rand(0,1),
                               'have_pivot'        => mt_rand(0,1),
                               'have_hdmi'         => mt_rand(0,1),
                               'have_displayport'  => mt_rand(0,1),
                               'locations_id'      => $loc,
                               'monitortypes_id'   => mt_rand(1,$MAX['type_monitors']),
                               'monitormodels_id'  => mt_rand(1,$MAX['model_monitors']),
                               'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                               'notepad'           => "notes monitor' $i",
                               'users_id'          => $userID,
                               'groups_id'         => $groupID,
                               'states_id'         => (mt_rand(0,100)<$percent['state']
                                                         ?mt_rand($FIRST['state'],$LAST['state']):0)
                           )));

      addDocuments('Monitor', $monID);
      addContracts('Monitor', $monID);

      // Add trackings
      addTracking('Monitor', $monID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Monitor', $monID, $ID_entity);

      $ci->add(array('itemtype'     => 'Monitor',
                     'items_id'     => $monID,
                     'computers_id' => $compID,
      ));

      // Ajout d'un telephhone avec l'ordi
      $telID = $phone->add(toolbox::addslashes_deep(
                           array('entities_id'           => $ID_entity,
                                 'name'                  => "phone' $i-$ID_entity",
                                 'serial'                => Toolbox::getRandomString(10),
                                 'otherserial'           => Toolbox::getRandomString(10),
                                 'contact'               => "contact' $i",
                                 'contact_num'           => "num' $i",
                                 'users_id_tech'         => $techID,
                                 'groups_id_tech'        => $gtechID,
                                 'comment'               => "comment' $i",
                                 'firmware'              => Toolbox::getRandomString(10),
                                 'brand'                 => "brand' $i",
                                 'phonepowersupplies_id' => mt_rand(0,$MAX['phone_power']),
                                 'number_line'           => Toolbox::getRandomString(10),
                                 'have_headset'          => mt_rand(0,1),
                                 'have_hp'               => mt_rand(0,1),
                                 'locations_id'          => $loc,
                                 'phonetypes_id'         => mt_rand(1,$MAX['type_phones']),
                                 'phonemodels_id'        => mt_rand(1,$MAX['model_phones']),
                                 'manufacturers_id'      => mt_rand(1,$MAX['manufacturer']),
                                 'notepad'               => "notes phone' $i",
                                 'users_id'              => $userID,
                                 'groups_id'             => $groupID,
                                 'states_id'             => (mt_rand(0,100)<$percent['state']
                                                               ?mt_rand($FIRST['state'],$LAST['state']):0)
                           )));

      addDocuments('Phone', $telID);
      addContracts('Phone', $telID);

      // Add trackings
      addTracking('Phone', $telID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Phone', $telID, $ID_entity);

      $ci->add(array('itemtype'     => 'Phone',
                     'items_id'     => $telID,
                     'computers_id' => $compID));

      // Ajout des periphs externes en connection directe
      while (mt_rand(0,100)<$percent['peripherals']) {

         $periphID = $periph->add(toolbox::addslashes_deep(
                                  array('entities_id'       => $ID_entity,
                                        'name'              => "periph of comp' $i-$ID_entity",
                                        'serial'            => Toolbox::getRandomString(10),
                                        'otherserial'       => Toolbox::getRandomString(10),
                                        'contact'           => "contact' $i",
                                        'contact_num'       => "num' $i",
                                        'users_id_tech'     => $techID,
                                        'groups_id_tech'    => $gtechID,
                                        'comment'           => "comment' $i",
                                        'brand'             => "brand' $i",
                                        'locations_id'      => $loc,
                                        'phonetypes_id'     => mt_rand(1,$MAX['type_peripherals']),
                                        'phonemodels_id'    => mt_rand(1,$MAX['model_peripherals']),
                                        'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                                        'notepad'           => "notes peripheral' $i",
                                        'users_id'          => $userID,
                                        'groups_id'         => $groupID,
                                        'states_id'         => (mt_rand(0,100)<$percent['state']
                                                                  ?mt_rand($FIRST['state'],$LAST['state']):0)
                                    )));

         addDocuments('Peripheral', $periphID);
         addContracts('Peripheral', $periphID);

         // Add trackings
         addTracking('Peripheral', $periphID, $ID_entity);

         // Add connection
         $ci->add(array('itemtype'     => 'Peripheral',
                        'items_id'     => $periphID,
                        'computers_id' => $compID));
      }


      // Ajout d'une imprimante connection directe pour X% des computers + ajout de cartouches
      if (mt_rand(0,100)<=$percent['printer']) {
         // Add printer
         $typeID  = mt_rand(1,$MAX['type_printers']);
         $modelID = mt_rand(1,$MAX['model_printers']);

         $printID = $p->add(toolbox::addslashes_deep(
                            array('entities_id'       => $ID_entity,
                                  'name'              => "printer of comp' $i-$ID_entity",
                                  'serial'            => Toolbox::getRandomString(10),
                                  'otherserial'       => Toolbox::getRandomString(10),
                                  'contact'           => "contact' $i",
                                  'contact_num'       => "num' $i",
                                  'users_id_tech'     => $techID,
                                  'groups_id_tech'    => $gtechID,
                                  'have_serial'       => mt_rand(0,1),
                                  'have_parallel'     => mt_rand(0,1),
                                  'have_usb'          => mt_rand(0,1),
                                  'have_wifi'         => mt_rand(0,1),
                                  'have_ethernet'     => mt_rand(0,1),
                                  'comment'           => "comment' $i",
                                  'memory_size'       => mt_rand(0,128),
                                  'locations_id'      => $loc,
                                  'domains_id'        => $domainID,
                                  'networks_id'       => $networkID,
                                  'printertypes_id'   => $typeID,
                                  'printermodels_id'  => $modelID,
                                  'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                                  'notepad'           => "notes printers '$i",
                                  'users_id'          => mt_rand($FIRST['users_postonly'],
                                                                 $LAST['users_postonly']),
                                  'groups_id'         => mt_rand($FIRST["groups"], $LAST["groups"]),
                                  'states_id'         => (mt_rand(0,100)<$percent['state']
                                                            ?mt_rand($FIRST['state'],$LAST['state']):0)
                              )));

         addDocuments('Printer', $printID);
         addContracts('Printer', $printID);

         // Add trackings
         addTracking('Printer', $printID, $ID_entity);

         // Add connection
         $ci->add(array('itemtype'     => 'Printer',
                        'items_id'     => $printID,
                        'computers_id' => $compID));

         // AJOUT INFOCOMS
         addInfocoms('Printer', $printID, $ID_entity);

         // Add Cartouches
         // Get compatible cartridge
         $query = "SELECT `cartridgeitems_id`
                   FROM `glpi_cartridgeitems_printermodels`
                   WHERE `printermodels_id` = '$typeID'";
         $result = $DB->query($query) or die("PB REQUETE ".$query);

         if ($DB->numrows($result)>0) {
            $ctypeID = $DB->result($result,0,0) or die (" PB RESULT ".$query);
            $printed = 0;
            $oldnb   = mt_rand(1,$MAX['cartridges_by_printer']);
            $date1   = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
            $date2   = time();
            $inter   = round(($date2-$date1)/$oldnb);

            // Add old cartridges
            for ($j=0 ; $j<$oldnb ; $j++) {
               $printed += mt_rand(0,5000);
               $cart->add(array('entities_id'        => $ID_entity,
                                'cartridgeitems_id'  => $ctypeID,
                                'printers_id'        => $printID,
                                'date_in'            => date("Y-m-d",$date1),
                                'date_use'           => date("Y-m-d",$date1+$j*$inter),
                                'date_out'           => date("Y-m-d",$date1+($j+1)*$inter),
                                'pages'              => $printed));
            }

            // Add current cartridges
            $cart->add(array('entities_id'        => $ID_entity,
                             'cartridgeitems_id'  => $ctypeID,
                             'printers_id'        => $printID,
                             'date_in'            => date("Y-m-d",$date1),
                             'date_use'           => date("Y-m-d",$date2)));
         }
      }
   }

   $LAST["computers"] = getMaxItem("glpi_computers");
   $LAST["monitors"]  = getMaxItem("glpi_monitors");
   $LAST["phones"]    = getMaxItem("glpi_phones");


   // Add global peripherals
   $periph = new Peripheral();
   $ci     = new Computer_Item();
   for ($i=0 ; $i<$MAX['global_peripherals'] ; $i++) {
      $techID  = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']);
      $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]);

      $periphID = $periph->add(toolbox::addslashes_deep(
                               array('entities_id'       => $ID_entity,
                                     'name'              => "periph '$i-$ID_entity",
                                     'serial'            => Toolbox::getRandomString(10),
                                     'otherserial'       => Toolbox::getRandomString(10),
                                     'contact'           => "contact' $i",
                                     'contact_num'       => "num' $i",
                                     'users_id_tech'     => $techID,
                                     'groups_id_tech'    => $gtechID,
                                     'comment'           => "comment' $i",
                                     'brand'             => "brand' $i",
                                     'locations_id'      => $loc,
                                     'phonetypes_id'     => mt_rand(1,$MAX['type_peripherals']),
                                     'phonemodels_id'    => mt_rand(1,$MAX['model_peripherals']),
                                     'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                                     'is_global'         => 1,
                                     'notepad'           => "notes peripheral' $i",
                                     'users_id'          => mt_rand($FIRST['users_normal'],
                                                                    $LAST['users_normal']),
                                     'groups_id'         => mt_rand($FIRST["groups"], $LAST["groups"]),
                                     'states_id'         => (mt_rand(0,100)<$percent['state']
                                                               ?mt_rand($FIRST['state'],$LAST['state']):0)
                                 )));

      addDocuments('Peripheral', $periphID);
      addContracts('Peripheral', $periphID);

      // Add trackings
      addTracking('Peripheral', $periphID, $ID_entity);

      // Add reservation
      addReservation('Peripheral', $periphID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Peripheral', $periphID, $ID_entity);

      // Add connections
      $val = mt_rand(1,$MAX['connect_for_peripherals']);
      for ($j=1 ; $j<$val ; $j++) {
         $ci->add(array('itemtype'     => 'Peripheral',
                        'items_id'     => $periphID,
                        'computers_id' => mt_rand($FIRST["computers"],$LAST['computers'])));
      }
   }

   $LAST["peripherals"] = getMaxItem("glpi_peripherals");

   $FIRST["software"]   = getMaxItem("glpi_softwares")+1;

   // Ajout logiciels + licences associees a divers PCs
   $items = array(array("Open'Office", "1.1.4", "2.0", "2.0.1"),
                  array("Microsoft Office", "95", "97", "XP", "2000", "2003", "2007"),
                  array("Acrobat Reader", "6.0", "7.0", "7.04"),
                  array("Gimp", "2.0", "2.2"),
                  array("InkScape", "0.4"));
   $soft       = new Software();
   $softvers   = new SoftwareVersion();
   $softlic    = new SoftwareLicense();
   $csv        = new Computer_SoftwareVersion();
   $csl        = new Computer_SoftwareLicense();
   for ($i=0 ; $i<$MAX['software'] ; $i++) {

      if (isset($items[$i])) {
         $name = $items[$i][0];
      } else {
         $name = "software '$i";
      }

      $loc       = mt_rand(1,$MAX['locations']);
      $techID    = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']);
      $gtechID   = mt_rand($FIRST["techgroups"],$LAST["techgroups"]);
      $recursive = mt_rand(0,1);

      $softID = $soft->add(toolbox::addslashes_deep(
                           array('entities_id'           => $ID_entity,
                                 'is_recursive'          => $recursive,
                                 'name'                  => $name,
                                 'comment'               => "comment '$i",
                                 'locations_id'          => $loc,
                                 'users_id_tech'         => $techID,
                                 'groups_id_tech'        => $gtechID,
                                 'manufacturers_id'      => mt_rand(1,$MAX['manufacturer']),
                                 'notepad'               => "notes software '$i",
                                 'users_id'              => mt_rand($FIRST['users_admin'],
                                                                    $LAST['users_admin']),
                                 'groups_id'             => mt_rand($FIRST["groups"], $LAST["groups"]),
                                 'is_helpdesk_visible'   => 1,
                                 'softwarecategories_id' => mt_rand(1,$MAX['softwarecategory'])
                              )));

      addDocuments('Software', $softID);
      addContracts('Software', $softID);

      // Add trackings
      addTracking('Software', $softID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Software', $softID, $ID_entity);

      // Add versions
      $FIRST["version"] = getMaxItem("glpi_softwareversions")+1;

      if (isset($items[$i])) {
         $val2 = count($items[$i]);
      } else {
         $val2 = mt_rand(1,$MAX['softwareversions']+1);
      }

      for ($j=1 ; $j<=$val2 ; $j++) {
         if (isset($items[$i])) {
            $version = $items[$i][mt_rand(1,count($items[$i])-1)];
         } else {
            $version = "$j.0";
         }
         $os = mt_rand(1,$MAX['os']);

         $versID = $softvers->add(toolbox::addslashes_deep(
                                  array('entities_id'          => $ID_entity,
                                        'is_recursive'         => $recursive,
                                        'softwares_id'         => $softID,
                                        'name'                 => $version,
                                        'comment'              => "comment '$version",
                                        'states_id'            => (mt_rand(0,100)<$percent['state']
                                                                     ?mt_rand($FIRST['state'],$LAST['state']):0),
                                        'operatingsystems_id'  => $os)));

         $val3    = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall']));
         $comp_id = mt_rand($FIRST["computers"], $LAST['computers']);

         for ($k=0 ; $k<$val3 ; $k++) {
            $comp_id++;
            if ($comp_id>$LAST["computers"]) {
               $comp_id = $FIRST["computers"];
            }
            $csv->add(array('computers_id'        => $comp_id,
                            'softwareversions_id' => $versID));
         }
      }
      $LAST["version"] = getMaxItem("glpi_softwareversions");


      // Add licenses
      $val2 = mt_rand(1,$MAX['softwarelicenses']);

      for ($j=0 ; $j<$val2 ; $j++) {
         $softwareversions_id_buy = mt_rand($FIRST["version"],$LAST["version"]);
         $softwareversions_id_use = mt_rand($softwareversions_id_buy,$LAST["version"]);

         $nbused = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall']));

         $licID = $softlic->add(toolbox::addslashes_deep(
                                array('entities_id'               => $ID_entity,
                                      'is_recursive'              => $recursive,
                                      'softwares_id'              => $softID,
                                      'number'                    => $nbused,
                                      'softwarelicensetypes_id'   => mt_rand(1,$MAX['licensetype']),
                                      'name'                      => "license '$j",
                                      'serial'                    => "serial $j",
                                      'otherserial'               => "otherserial $j",
                                      'comment'                   => "comment license '$j",
                                      'softwareversions_id_buy'   => $softwareversions_id_buy,
                                      'softwareversions_id_use'   => $softwareversions_id_use)));

         $comp_id = mt_rand($FIRST["computers"], $LAST['computers']);

         for ($k=0 ; $k<$nbused ; $k++) {
            $comp_id++;
            if ($comp_id>$LAST["computers"]) {
               $comp_id = $FIRST["computers"];
            }
            $csl->add(array('computers_id'          => $comp_id,
                            'softwarelicenses_id'   => $licID));
         }
      }
   }
   $LAST["software"] = getMaxItem("glpi_softwares");
}
コード例 #13
0
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkRight("software", READ);
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (!isset($_GET["softwares_id"])) {
    $_GET["softwares_id"] = "";
}
$license = new SoftwareLicense();
if (isset($_POST["add"])) {
    $license->check(-1, CREATE, $_POST);
    if ($newID = $license->add($_POST)) {
        Event::log($_POST['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s adds the license %2$s'), $_SESSION["glpiname"], $newID));
        if ($_SESSION['glpibackcreated']) {
            Html::redirect($license->getFormURL() . "?id=" . $newID);
        }
    }
    Html::back();
} else {
    if (isset($_POST["purge"])) {
        $license->check($_POST['id'], PURGE);
        $license->delete($_POST, 1);
        Event::log($license->fields['softwares_id'], "software", 4, "inventory", sprintf(__('%1$s purges the license %2$s'), $_SESSION["glpiname"], $_POST["id"]));
        $license->redirectToList();
コード例 #14
0
 /**
  * Show softwares candidates to be merged with the current
  *
  * @return nothing
  **/
 function showMergeCandidates()
 {
     global $DB, $CFG_GLPI, $LANG;
     $ID = $this->getField('id');
     $this->check($ID, "w");
     $rand = mt_rand();
     echo "<div class='center'>";
     $sql = "SELECT `glpi_softwares`.`id`,\n                     `glpi_softwares`.`name`,\n                     `glpi_entities`.`completename` AS entity\n              FROM `glpi_softwares`\n              LEFT JOIN `glpi_entities` ON (`glpi_softwares`.`entities_id` = `glpi_entities`.`id`)\n              WHERE (`glpi_softwares`.`id` != '{$ID}'\n                     AND `glpi_softwares`.`name` = '" . addslashes($this->fields["name"]) . "'\n                     AND `glpi_softwares`.`is_deleted` = '0'\n                     AND `glpi_softwares`.`is_template` = '0' " . getEntitiesRestrictRequest('AND', 'glpi_softwares', 'entities_id', getSonsOf("glpi_entities", $this->fields["entities_id"]), false) . ")\n              ORDER BY `entity`";
     $req = $DB->request($sql);
     if ($req->numrows()) {
         $link = getItemTypeFormURL('Software');
         echo "<form method='post' name='mergesoftware_form{$rand}' id='mergesoftware_form{$rand}'\n                action='" . $link . "'>";
         echo "<table class='tab_cadre_fixehov'><tr><th>&nbsp;</th>";
         echo "<th>" . $LANG['common'][16] . "</th>";
         echo "<th>" . $LANG['entity'][0] . "</th>";
         echo "<th>" . $LANG['software'][19] . "</th>";
         echo "<th>" . $LANG['software'][11] . "</th></tr>";
         foreach ($req as $data) {
             echo "<tr class='tab_bg_2'>";
             echo "<td><input type='checkbox' name='item[" . $data["id"] . "]' value='1'></td>";
             echo "<td<a href='" . $link . "?id=" . $data["id"] . "'>" . $data["name"] . "</a></td>";
             echo "<td>" . $data["entity"] . "</td>";
             echo "<td class='right'>" . Computer_SoftwareVersion::countForSoftware($data["id"]) . "</td>";
             echo "<td class='right'>" . SoftwareLicense::countForSoftware($data["id"]) . "</td></tr>\n";
         }
         echo "</table>\n";
         openArrowMassive("mergesoftware_form{$rand}", true);
         echo "<input type='hidden' name='id' value='{$ID}'>";
         closeArrowMassive('mergesoftware', $LANG['software'][48]);
         echo "</form>";
     } else {
         echo $LANG['search'][15];
     }
     echo "</div>";
 }
コード例 #15
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";
 }
コード例 #16
0
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if ($withtemplate || !self::isSoftwareTabActive($item)) {
         return '';
     }
     $recordsCount = $_SESSION['glpishow_count_on_tabs'] ? self::countLicenses($item) : 0;
     return self::createTabEntry(SoftwareLicense::getTypeName(2) . ' - ' . User::getTypeName(2), $recordsCount);
 }
コード例 #17
0
 /**
  * Show software installed on a computer
  *
  * @param $comp            Computer object
  * @param $withtemplate    template case of the view process (default '')
  *
  * @return nothing
  **/
 static function showForComputer(Computer $comp, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRight("software", "r")) {
         return false;
     }
     $computers_id = $comp->getField('id');
     $rand = mt_rand();
     $canedit = Session::haveRight("software", "w");
     $entities_id = $comp->fields["entities_id"];
     $add_dynamic = '';
     if (Plugin::haveImport()) {
         $add_dynamic = "`glpi_computers_softwareversions`.`is_dynamic`,";
     }
     $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n                       `glpi_softwares`.`name` AS softname,\n                       `glpi_computers_softwareversions`.`id`,\n                       {$add_dynamic}\n                       `glpi_states`.`name` AS state,\n                       `glpi_softwareversions`.`id` AS verid,\n                       `glpi_softwareversions`.`softwares_id`,\n                       `glpi_softwareversions`.`name` AS version\n                FROM `glpi_computers_softwareversions`\n                LEFT JOIN `glpi_softwareversions`\n                     ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                           = `glpi_softwareversions`.`id`)\n                LEFT JOIN `glpi_states`\n                     ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n                LEFT JOIN `glpi_softwares`\n                     ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n                WHERE `glpi_computers_softwareversions`.`computers_id` = '{$computers_id}'\n                      AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n                ORDER BY `softwarecategories_id`, `softname`, `version`";
     $result = $DB->query($query);
     $i = 0;
     if ((empty($withtemplate) || $withtemplate != 2) && $canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwareversion.form.php'>";
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><td class='center'>";
         echo _n('Software', 'Software', 2) . "&nbsp;&nbsp;";
         echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         Software::dropdownSoftwareToInstall("softwareversions_id", $entities_id);
         echo "</td><td width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Install') . "\"\n                class='submit'>";
         echo "</td>";
         echo "</tr>\n";
         echo "</table></div>\n";
         Html::closeForm();
     }
     echo "<div class='spaced'>";
     $cat = -1;
     Session::initNavigateListItems('Software', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
     Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
     $installed = array();
     if ($number = $DB->numrows($result)) {
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $paramsma = array('num_displayed' => $number, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
             Html::showMassiveActions(__CLASS__, $paramsma);
         }
         echo "<table class='tab_cadre_fixe'>";
         while ($data = $DB->fetch_assoc($result)) {
             if ($data["softwarecategories_id"] != $cat) {
                 self::displayCategoryFooter($cat, $rand, $canedit);
                 $cat = self::displayCategoryHeader($computers_id, $data, $rand, $canedit);
             }
             $licids = self::displaySoftsByCategory($data, $computers_id, $withtemplate, $canedit);
             Session::addToNavigateListItems('Software', $data["softwares_id"]);
             foreach ($licids as $licid) {
                 Session::addToNavigateListItems('SoftwareLicense', $licid);
                 $installed[] = $licid;
             }
         }
         self::displayCategoryFooter($cat, $rand, $canedit);
         echo "</table>";
         if ($canedit) {
             $paramsma['ontop'] = false;
             Html::showMassiveActions(__CLASS__, $paramsma);
             Html::closeForm();
         }
     }
     echo "</div>\n";
     if ((empty($withtemplate) || $withtemplate != 2) && $canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>";
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         echo _n('License', 'Licenses', 2) . "&nbsp;&nbsp;";
         echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         Software::dropdownLicenseToInstall("softwarelicenses_id", $entities_id);
         echo "</td><td width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>\n";
         echo "</table></div>\n";
         Html::closeForm();
     }
     echo "<div class='spaced'>";
     // Affected licenses NOT installed
     $query = "SELECT `glpi_softwarelicenses`.*,\n                       `glpi_computers_softwarelicenses`.`id` AS linkID,\n                       `glpi_softwares`.`name` AS softname,\n                       `glpi_softwareversions`.`name` AS version,\n                       `glpi_states`.`name` AS state\n                FROM `glpi_softwarelicenses`\n                LEFT JOIN `glpi_computers_softwarelicenses`\n                      ON (`glpi_computers_softwarelicenses`.softwarelicenses_id\n                              = `glpi_softwarelicenses`.`id`)\n                INNER JOIN `glpi_softwares`\n                      ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n                LEFT JOIN `glpi_softwareversions`\n                      ON (`glpi_softwarelicenses`.`softwareversions_id_use`\n                              = `glpi_softwareversions`.`id`\n                           OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n                               AND `glpi_softwarelicenses`.`softwareversions_id_buy`\n                                       = `glpi_softwareversions`.`id`))\n                LEFT JOIN `glpi_states`\n                     ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n                WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$computers_id}'\n                      AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'";
     if (count($installed)) {
         $query .= " AND `glpi_softwarelicenses`.`id` NOT IN (" . implode(',', $installed) . ")";
     }
     $req = $DB->request($query);
     if ($number = $req->numrows()) {
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('massSoftwareLicense' . $rand);
             $actions = array('install' => _x('button', 'Install'));
             if (SoftwareLicense::canUpdate()) {
                 $actions['purge'] = _x('button', 'Delete permanently');
             }
             $paramsma = array('num_displayed' => $number, 'specific_actions' => $actions);
             Html::showMassiveActions('Computer_SoftwareLicense', $paramsma);
             echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         }
         echo "<table class='tab_cadre_fixe'>";
         $cat = true;
         foreach ($req as $data) {
             if ($cat) {
                 self::displayCategoryHeader($computers_id, $data, $rand, $canedit);
                 $cat = false;
             }
             self::displaySoftsByLicense($data, $computers_id, $withtemplate, $canedit);
             Session::addToNavigateListItems('SoftwareLicense', $data["id"]);
         }
         self::displayCategoryFooter(NULL, $rand, $canedit);
         echo "</table>";
         if ($canedit) {
             $paramsma['ontop'] = false;
             Html::showMassiveActions('Computer_SoftwareLicense', $paramsma);
             Html::closeForm();
         }
     }
     echo "</div>\n";
 }
コード例 #18
0
 /**
  * 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";
 }
コード例 #19
0
ファイル: softwarelicense.php プロジェクト: glpi-project/glpi
based on GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2014 by the INDEPNET Development Team.

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

LICENSE

This file is part of GLPI.

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

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

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkRight("license", READ);
Html::header(SoftwareLicense::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "management", "softwarelicense");
Search::show('SoftwareLicense');
Html::footer();
コード例 #20
0
 /**
  * Print the Software / version form
  *
  * @param $ID        integer  Id of the version or the template to print
  * @param $options   array    of possible options:
  *     - 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;
     if ($ID > 0) {
         $this->check($ID, READ);
         $softwares_id = $this->fields['softwares_id'];
     } else {
         $softwares_id = $options['softwares_id'];
         $this->check(-1, CREATE, $options);
     }
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'><td>" . _n('Software', 'Software', Session::getPluralNumber()) . "</td>";
     echo "<td>";
     if ($this->isNewID($ID)) {
         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'>" . __('Comments') . "</td>";
     echo "<td class='center middle' rowspan='4'>";
     echo "<textarea cols='45' rows='3' name='comment' class='form-control'>" . $this->fields["comment"];
     echo "</textarea></td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "name");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . __('Operating system') . "</td><td>";
     OperatingSystem::dropdown(array('value' => $this->fields["operatingsystems_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . __('Status') . "</td><td>";
     State::dropdown(array('value' => $this->fields["states_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_visible_softwareversion`"));
     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);
     return true;
 }
コード例 #21
0
ファイル: state.class.php プロジェクト: stweil/glpi
 /**
  * Get search function for the class
  *
  * @since version 0.85
  *
  * @return array of search option
  **/
 function getSearchOptions()
 {
     $tab = parent::getSearchOptions();
     $tab[21]['table'] = $this->getTable();
     $tab[21]['field'] = 'is_visible_computer';
     $tab[21]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Computer::getTypeName(Session::getPluralNumber()));
     $tab[21]['datatype'] = 'bool';
     $tab[22]['table'] = $this->getTable();
     $tab[22]['field'] = 'is_visible_softwareversion';
     $tab[22]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), SoftwareVersion::getTypeName(Session::getPluralNumber()));
     $tab[22]['datatype'] = 'bool';
     $tab[23]['table'] = $this->getTable();
     $tab[23]['field'] = 'is_visible_monitor';
     $tab[23]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Monitor::getTypeName(Session::getPluralNumber()));
     $tab[23]['datatype'] = 'bool';
     $tab[24]['table'] = $this->getTable();
     $tab[24]['field'] = 'is_visible_printer';
     $tab[24]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Printer::getTypeName(Session::getPluralNumber()));
     $tab[24]['datatype'] = 'bool';
     $tab[25]['table'] = $this->getTable();
     $tab[25]['field'] = 'is_visible_peripheral';
     $tab[25]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Peripheral::getTypeName(Session::getPluralNumber()));
     $tab[25]['datatype'] = 'bool';
     $tab[26]['table'] = $this->getTable();
     $tab[26]['field'] = 'is_visible_phone';
     $tab[26]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Phone::getTypeName(Session::getPluralNumber()));
     $tab[26]['datatype'] = 'bool';
     $tab[27]['table'] = $this->getTable();
     $tab[27]['field'] = 'is_visible_networkequipment';
     $tab[27]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), NetworkEquipment::getTypeName(Session::getPluralNumber()));
     $tab[27]['datatype'] = 'bool';
     $tab[28]['table'] = $this->getTable();
     $tab[28]['field'] = 'is_visible_softwarelicense';
     $tab[28]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), SoftwareLicense::getTypeName(Session::getPluralNumber()));
     $tab[28]['datatype'] = 'bool';
     return $tab;
 }
コード例 #22
0
ファイル: lock.class.php プロジェクト: geldarr/hack-space
 /**
  * Display form to unlock fields and links
  *
  * @param CommonDBTM $item the source item
  **/
 static function showForItem(CommonDBTM $item)
 {
     global $DB;
     $ID = $item->getID();
     $itemtype = $item->getType();
     $header = false;
     //If user doesn't have write right on the item, lock form must not be displayed
     if (!$item->canCreate()) {
         return false;
     }
     echo "<div width='50%'>";
     echo "<form method='post' id='lock_form'\n             name='lock_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<input type='hidden' name='id' value='{$ID}'>\n";
     echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2''>" . __('Locked items') . "</th></tr>";
     //Use a hook to allow external inventory tools to manage per field lock
     $results = Plugin::doHookFunction('display_locked_fields', array('item' => $item, 'header' => $header));
     $header |= $results['header'];
     //Special locks for computers only
     if ($itemtype == 'Computer') {
         //Locks for items recorded in glpi_computers_items table
         $types = array('Monitor', 'Peripheral', 'Printer');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID, 'itemtype' => $type);
             $params['FIELDS'] = array('id', 'items_id');
             $first = true;
             foreach ($DB->request('glpi_computers_items', $params) as $line) {
                 $tmp = new $type();
                 $tmp->getFromDB($line['items_id']);
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='Computer_Item[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $tmp->getName() . "</td>";
                 echo "</tr>\n";
             }
         }
         $types = array('ComputerDisk', 'ComputerVirtualMachine');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
             $params['FIELDS'] = array('id', 'name');
             $first = true;
             foreach ($DB->request(getTableForItemType($type), $params) as $line) {
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $line['name'] . "</td>";
                 echo "</tr>\n";
             }
         }
         //Software versions
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwareversions` AS csv\n                    LEFT JOIN `glpi_softwareversions` AS sv\n                       ON (`csv`.`softwareversions_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . Software::getTypeName(2) . "</th></tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareVersion[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
         //Software licenses
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwarelicenses` AS csv\n                    LEFT JOIN `glpi_softwarelicenses` AS sv\n                       ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
     }
     $first = true;
     $item = new NetworkPort();
     $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype);
     $params['FIELDS'] = array('id');
     foreach ($DB->request('glpi_networkports', $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new NetworkName();
     $params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_networknames' => 'id');
     foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new IPAddress();
     $params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_ipaddresses' => 'id');
     foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $types = Item_Devices::getDeviceTypes();
     $nb = 0;
     foreach ($types as $old => $type) {
         $nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n                                         AND `itemtype`='{$itemtype}'\n                                         AND `is_dynamic`='1'\n                                         AND `is_deleted`='1'");
     }
     if ($nb) {
         $header = true;
         echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n";
         foreach ($types as $old => $type) {
             $associated_type = str_replace('Item_', '', $type);
             $associated_table = getTableForItemType($associated_type);
             $fk = getForeignKeyFieldForTable($associated_table);
             $query = "SELECT `i`.`id`,\n                             `t`.`designation` AS `name`\n                      FROM `" . getTableForItemType($type) . "` AS i\n                      LEFT JOIN `{$associated_table}` AS t\n                         ON (`t`.`id` = `i`.`{$fk}`)\n                      WHERE `itemtype` = '{$itemtype}'\n                            AND `items_id` = '{$ID}'\n                            AND `is_dynamic` = '1'\n                            AND `is_deleted` = '1'";
             foreach ($DB->request($query) as $data) {
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>";
                 printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']);
                 echo "</td></tr>\n";
             }
         }
     }
     if ($header) {
         echo "</table>";
         Html::openArrowMassives('lock_form', true);
         Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock')));
     } else {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>";
         echo "</table>";
     }
     Html::closeForm();
     echo "</div>\n";
 }
コード例 #23
0
 /**
  * Show software installed on a computer
  *
  * @param $comp            Computer object
  * @param $withtemplate    template case of the view process (default '')
  *
  * @return nothing
  **/
 static function showForComputer(Computer $comp, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (!Software::canView()) {
         return false;
     }
     $computers_id = $comp->getField('id');
     $rand = mt_rand();
     $canedit = Session::haveRightsOr("software", array(CREATE, UPDATE, DELETE, PURGE));
     $entities_id = $comp->fields["entities_id"];
     $crit = Session::getSavedOption(__CLASS__, 'criterion', -1);
     $where = '';
     if ($crit > -1) {
         $where = " AND `glpi_softwares`.`softwarecategories_id` = {$crit}";
     }
     $add_dynamic = '';
     if (Plugin::haveImport()) {
         $add_dynamic = "`glpi_computers_softwareversions`.`is_dynamic`,";
     }
     $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n                       `glpi_softwares`.`name` AS softname,\n                       `glpi_computers_softwareversions`.`id`,\n                       {$add_dynamic}\n                       `glpi_states`.`name` AS state,\n                       `glpi_softwareversions`.`id` AS verid,\n                       `glpi_softwareversions`.`softwares_id`,\n                       `glpi_softwareversions`.`name` AS version,\n                       `glpi_softwares`.`is_valid` AS softvalid\n                FROM `glpi_computers_softwareversions`\n                LEFT JOIN `glpi_softwareversions`\n                     ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                           = `glpi_softwareversions`.`id`)\n                LEFT JOIN `glpi_states`\n                     ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n                LEFT JOIN `glpi_softwares`\n                     ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n                WHERE `glpi_computers_softwareversions`.`computers_id` = '{$computers_id}'\n                      AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n                      {$where}\n                ORDER BY `softname`, `version`";
     $result = $DB->query($query);
     $i = 0;
     if ((empty($withtemplate) || $withtemplate != 2) && $canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwareversion.form.php'>";
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><td class='center'>";
         echo _n('Software', 'Software', Session::getPluralNumber()) . "&nbsp;&nbsp;";
         echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         Software::dropdownSoftwareToInstall("softwareversions_id", $entities_id);
         echo "</td><td width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Install') . "\"\n                class='submit'>";
         echo "</td>";
         echo "</tr>\n";
         echo "</table></div>\n";
         Html::closeForm();
     }
     echo "<div class='spaced'>";
     $cat = -1;
     Session::initNavigateListItems('Software', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
     Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
     // Mini Search engine
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'><th colspan='2'>" . Software::getTypeName(Session::getPluralNumber()) . "</th></tr>";
     echo "<tr class='tab_bg_1'><td class='center'>";
     echo __('Category') . "</td><td>";
     SoftwareCategory::dropdown(array('value' => $crit, 'toadd' => array('-1' => __('All categories')), 'emptylabel' => __('Uncategorized software'), 'on_change' => 'reloadTab("start=0&criterion="+this.value)'));
     echo "</td></tr></table></div>";
     $number = $DB->numrows($result);
     $start = isset($_REQUEST['start']) ? intval($_REQUEST['start']) : 0;
     if ($start >= $number) {
         $start = 0;
     }
     $installed = array();
     if ($number) {
         echo "<div class='spaced'>";
         Html::printAjaxPager('', $start, $number);
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixehov'>";
         $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>";
         }
         $header_end .= "<th>" . __('Name') . "</th><th>" . __('Status') . "</th>";
         $header_end .= "<th>" . __('Version') . "</th><th>" . __('License') . "</th>";
         if (Plugin::haveImport()) {
             $header_end .= "<th>" . __('Automatic inventory') . "</th>";
         }
         $header_end .= "<th>" . SoftwareCategory::getTypeName(1) . "</th>";
         $header_end .= "<th>" . __('Valid license') . "</th>";
         $header_end .= "</tr>\n";
         echo $header_begin . $header_top . $header_end;
         for ($row = 0; $data = $DB->fetch_assoc($result); $row++) {
             if ($row >= $start && $row < $start + $_SESSION['glpilist_limit']) {
                 $licids = self::softsByCategory($data, $computers_id, $withtemplate, $canedit, true);
             } else {
                 $licids = self::softsByCategory($data, $computers_id, $withtemplate, $canedit, false);
             }
             Session::addToNavigateListItems('Software', $data["softwares_id"]);
             foreach ($licids as $licid) {
                 Session::addToNavigateListItems('SoftwareLicense', $licid);
                 $installed[] = $licid;
             }
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
     } else {
         echo "<p class='center b'>" . __('No item found') . "</p>";
     }
     echo "</div>\n";
     if ((empty($withtemplate) || $withtemplate != 2) && $canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>";
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         echo _n('License', 'Licenses', Session::getPluralNumber()) . "&nbsp;&nbsp;";
         echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         Software::dropdownLicenseToInstall("softwarelicenses_id", $entities_id);
         echo "</td><td width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>\n";
         echo "</table></div>\n";
         Html::closeForm();
     }
     echo "<div class='spaced'>";
     // Affected licenses NOT installed
     $query = "SELECT `glpi_softwarelicenses`.*,\n                       `glpi_computers_softwarelicenses`.`id` AS linkID,\n                       `glpi_softwares`.`name` AS softname,\n                       `glpi_softwareversions`.`name` AS version,\n                       `glpi_states`.`name` AS state\n                FROM `glpi_softwarelicenses`\n                LEFT JOIN `glpi_computers_softwarelicenses`\n                      ON (`glpi_computers_softwarelicenses`.softwarelicenses_id\n                              = `glpi_softwarelicenses`.`id`)\n                INNER JOIN `glpi_softwares`\n                      ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n                LEFT JOIN `glpi_softwareversions`\n                      ON (`glpi_softwarelicenses`.`softwareversions_id_use`\n                              = `glpi_softwareversions`.`id`\n                           OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n                               AND `glpi_softwarelicenses`.`softwareversions_id_buy`\n                                       = `glpi_softwareversions`.`id`))\n                LEFT JOIN `glpi_states`\n                     ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n                WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$computers_id}'\n                      AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'\n                      {$where}";
     if (count($installed)) {
         $query .= " AND `glpi_softwarelicenses`.`id` NOT IN (" . implode(',', $installed) . ")";
     }
     $query .= " ORDER BY `softname`, `version`;";
     $req = $DB->request($query);
     if ($number = $req->numrows()) {
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('massSoftwareLicense' . $rand);
             $actions = array('Computer_SoftwareLicense' . MassiveAction::CLASS_ACTION_SEPARATOR . 'install' => _x('button', 'Install'));
             if (SoftwareLicense::canUpdate()) {
                 $actions['purge'] = _x('button', 'Delete permanently');
             }
             $massiveactionparams = array('num_displayed' => $number, 'container' => 'massSoftwareLicense' . $rand, 'specific_actions' => $actions);
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixehov'>";
         $header_begin = "<tr>";
         $header_top = '';
         $header_bottom = '';
         $header_end = '';
         if ($canedit) {
             $header_begin .= "<th width='10'>";
             $header_top .= Html::getCheckAllAsCheckbox('massSoftwareLicense' . $rand);
             $header_bottom .= Html::getCheckAllAsCheckbox('massSoftwareLicense' . $rand);
             $header_end .= "</th>";
         }
         $header_end .= "<th>" . __('Name') . "</th><th>" . __('Status') . "</th>";
         $header_end .= "<th>" . __('Version') . "</th><th>" . __('License') . "</th>";
         $header_end .= "</tr>\n";
         echo $header_begin . $header_top . $header_end;
         $cat = true;
         foreach ($req as $data) {
             self::displaySoftsByLicense($data, $computers_id, $withtemplate, $canedit);
             Session::addToNavigateListItems('SoftwareLicense', $data["id"]);
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
     }
     echo "</div>\n";
 }
コード例 #24
0
ファイル: software.class.php プロジェクト: geldarr/hack-space
 /**
  * Show softwares candidates to be merged with the current
  *
  * @return nothing
  **/
 function showMergeCandidates()
 {
     global $DB, $CFG_GLPI;
     $ID = $this->getField('id');
     $this->check($ID, "w");
     $rand = mt_rand();
     echo "<div class='center'>";
     $sql = "SELECT `glpi_softwares`.`id`,\n                     `glpi_softwares`.`name`,\n                     `glpi_entities`.`completename` AS entity\n              FROM `glpi_softwares`\n              LEFT JOIN `glpi_entities` ON (`glpi_softwares`.`entities_id` = `glpi_entities`.`id`)\n              WHERE (`glpi_softwares`.`id` != '{$ID}'\n                     AND `glpi_softwares`.`name` = '" . addslashes($this->fields["name"]) . "'\n                     AND `glpi_softwares`.`is_deleted` = '0'\n                     AND `glpi_softwares`.`is_template` = '0' " . getEntitiesRestrictRequest('AND', 'glpi_softwares', 'entities_id', getSonsOf("glpi_entities", $this->fields["entities_id"]), false) . ")\n              ORDER BY `entity`";
     $req = $DB->request($sql);
     if ($nb = $req->numrows()) {
         $link = Toolbox::getItemTypeFormURL('Software');
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $paramsma = array('num_displayed' => $nb, 'specific_actions' => array('mergesoftware' => __('Merge')));
         Html::showMassiveActions(__CLASS__, $paramsma);
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th width='10'>";
         echo Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
         echo "</th>";
         echo "<th>" . __('Name') . "</th>";
         echo "<th>" . __('Entity') . "</th>";
         echo "<th>" . _n('Installation', 'Installations', 2) . "</th>";
         echo "<th>" . _n('License', 'Licenses', 2) . "</th></tr>";
         foreach ($req as $data) {
             echo "<tr class='tab_bg_2'>";
             echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
             echo "<td><a href='" . $link . "?id=" . $data["id"] . "'>" . $data["name"] . "</a></td>";
             echo "<td>" . $data["entity"] . "</td>";
             echo "<td class='right'>" . Computer_SoftwareVersion::countForSoftware($data["id"]) . "</td>";
             echo "<td class='right'>" . SoftwareLicense::countForSoftware($data["id"]) . "</td></tr>\n";
         }
         echo "</table>\n";
         echo "<input type='hidden' name='id' value='{$ID}'>";
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     } else {
         _e('No item found');
     }
     echo "</div>";
 }
コード例 #25
0
 /**
  * Show Licenses of a software
  *
  * @param $software software object
  *
  * @return nothing
  **/
 static function showForSoftware($software)
 {
     global $DB, $CFG_GLPI, $LANG;
     $softwares_id = $software->getField('id');
     $license = new SoftwareLicense();
     $computer = new Computer();
     if (!$software->can($softwares_id, "r")) {
         return false;
     }
     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"])) {
         $sort = "`" . $_REQUEST["sort"] . "`";
     } else {
         $sort = "`entity` {$order}, `name`";
     }
     // Righ type is enough. Can add a License on a software we have Read access
     $canedit = haveRight("software", "w");
     // Total Number of events
     $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true));
     echo "<div class='spaced'>";
     if ($number < 1) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . $LANG['search'][15] . "</th></tr>\n";
         if ($canedit) {
             echo "<tr class='tab_bg_2'><td class='center'>";
             echo "<a href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][8] . "</a>";
             echo "</td></tr>\n";
         }
         echo "</table></div>\n";
         return;
     }
     // Display the pager
     printAjaxPager($LANG['software'][11], $start, $number);
     $rand = mt_rand();
     $query = "SELECT `glpi_softwarelicenses`.*,\n                       `buyvers`.`name` AS buyname,\n                       `usevers`.`name` AS usename,\n                       `glpi_entities`.`completename` AS entity,\n                       `glpi_softwarelicensetypes`.`name` AS typename\n                FROM `glpi_softwarelicenses`\n                LEFT JOIN `glpi_softwareversions` AS buyvers\n                     ON (`buyvers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_buy`)\n                LEFT JOIN `glpi_softwareversions` AS usevers\n                     ON (`usevers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_use`)\n                LEFT JOIN `glpi_entities`\n                     ON (`glpi_entities`.`id` = `glpi_softwarelicenses`.`entities_id`)\n                LEFT JOIN `glpi_softwarelicensetypes`\n                     ON (`glpi_softwarelicensetypes`.`id`\n                          = `glpi_softwarelicenses`.`softwarelicensetypes_id`)\n                WHERE (`glpi_softwarelicenses`.`softwares_id` = '{$softwares_id}') " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n                ORDER BY {$sort} {$order}\n                LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
     initNavigateListItems('SoftwareLicense', $LANG['help'][31] . " = " . $software->fields["name"]);
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result)) {
             if ($canedit) {
                 echo "<form method='post' name='massiveactionlicense_form{$rand}' id='" . "massiveactionlicense_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php\">";
             }
             $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'><tr>";
             echo "<th>&nbsp;</th>";
             echo "<th>" . ($sort == "`name`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=name&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['common'][16] . "</a></th>";
             if ($software->isRecursive()) {
                 // Ereg to search entity in string for match default order
                 echo "<th>" . (strstr($sort, "entity") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=entity&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 == "`number`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=number&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['tracking'][29] . "</a></th>";
             echo "<th>" . $LANG['software'][9] . "</th>";
             echo "<th>" . ($sort == "`typename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=typename&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['common'][17] . "</a></th>";
             echo "<th>" . ($sort == "`buyname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=buyname&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['software'][1] . "</a></th>";
             echo "<th>" . ($sort == "`usename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=usename&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['software'][2] . "</a></th>";
             echo "<th>" . ($sort == "`expire`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=expire&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>" . $LANG['software'][32] . "</a></th>";
             echo "</tr>\n";
             $tot_assoc = 0;
             for ($tot = 0; $data = $DB->fetch_assoc($result);) {
                 addToNavigateListItems('SoftwareLicense', $data['id']);
                 echo "<tr class='tab_bg_2'>";
                 if ($license->can($data['id'], "w")) {
                     echo "<td><input type='checkbox' name='item[" . $data["id"] . "]' value='1'></td>";
                 } else {
                     echo "<td>&nbsp;</td>";
                 }
                 echo "<td><a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? $data['id'] : "") . "</a></td>";
                 if ($software->isRecursive()) {
                     echo "<td>" . $data['entity'] . "</td>";
                 }
                 echo "<td>" . $data['serial'] . "</td>";
                 echo "<td class='right'>" . ($data['number'] > 0 ? $data['number'] . "&nbsp;&nbsp;" : $LANG['software'][4]) . "</td>";
                 $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']);
                 $tot_assoc += $nb_assoc;
                 echo "<td class='right'>{$nb_assoc}&nbsp;&nbsp;</td>";
                 echo "<td>" . $data['typename'] . "</td>";
                 echo "<td>" . $data['buyname'] . "</td>";
                 echo "<td>" . $data['usename'] . "</td>";
                 echo "<td class='center'>" . convDate($data['expire']) . "</td>";
                 echo "</tr>";
                 if ($data['number'] < 0) {
                     // One illimited license, total is illimited
                     $tot = -1;
                 } else {
                     if ($tot >= 0) {
                         // Not illimited, add the current number
                         $tot += $data['number'];
                     }
                 }
             }
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . $LANG['common'][33] . "</td>";
             echo "<td class='right b'>" . ($tot > 0 ? $tot . "&nbsp;&nbsp;" : $LANG['software'][4]) . "</td>";
             echo "<td class='right b'>{$tot_assoc}&nbsp;&nbsp;</td>";
             echo "<td colspan='4' class='center'>";
             if ($canedit) {
                 echo "<a href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][8] . "</a>";
             }
             echo "</td></tr>";
             echo "</table>\n";
             if ($canedit) {
                 openArrowMassive("massiveactionlicense_form{$rand}", true);
                 Dropdown::showForMassiveAction('SoftwareLicense', 0, array('softwares_id' => $softwares_id));
                 closeArrowMassive();
                 echo "</form>";
             }
         } else {
             echo $LANG['search'][15];
         }
     }
     echo "</div>";
 }
コード例 #26
0
 /**
  * Transfer affected licenses to a computer
  *
  * @param $ID ID of the License
  **/
 function transferAffectedLicense($ID)
 {
     global $DB;
     $computer_softwarelicense = new Computer_SoftwareLicense();
     $license = new SoftwareLicense();
     if ($computer_softwarelicense->getFromDB($ID)) {
         if ($license->getFromDB($computer_softwarelicense->getField('softwarelicenses_id'))) {
             //// Update current : decrement number by 1 if valid
             if ($license->getField('number') > 1) {
                 $license->update(array('id' => $license->getID(), 'number' => $license->getField('number') - 1));
             }
             // Create new license : need to transfer softwre and versions before
             $input = array();
             $newsoftID = $this->copySingleSoftware($license->fields['softwares_id']);
             if ($newsoftID > 0) {
                 //// If license already exists : increment number by one
                 $query = "SELECT *\n                         FROM `glpi_softwarelicenses`\n                         WHERE `softwares_id` = '{$newsoftID}'\n                               AND `name` = '" . addslashes($license->fields['name']) . "'\n                               AND `serial` = '" . addslashes($license->fields['serial']) . "'";
                 $newlicID = -1;
                 if ($result = $DB->query($query)) {
                     //// If exists : increment number by 1
                     if ($DB->numrows($result) > 0) {
                         $data = $DB->fetch_array($result);
                         $newlicID = $data['id'];
                         $license->update(array('id' => $data['id'], 'number' => $data['number'] + 1));
                     } else {
                         //// If not exists : create with number = 1
                         $input = $license->fields;
                         foreach (array('softwareversions_id_buy', 'softwareversions_id_use') as $field) {
                             if ($license->fields[$field] > 0) {
                                 $newversID = $this->copySingleVersion($license->fields[$field]);
                                 if ($newversID > 0 && $newversID != $license->fields[$field]) {
                                     $input[$field] = $newversID;
                                 }
                             }
                         }
                         unset($input['id']);
                         $input['number'] = 1;
                         $input['entities_id'] = $this->to;
                         $input['softwares_id'] = $newsoftID;
                         $newlicID = $license->add($input);
                     }
                 }
                 if ($newlicID > 0) {
                     $input = array('id' => $ID, 'softwarelicenses_id' => $newlicID);
                     $computer_softwarelicense->update($input);
                 }
             }
         }
     }
     // getFromDB
 }
コード例 #27
0
 /**
  *
  * Update config of a new software office
  *
  * This function create a officepack in GLPI with some general data.
  *
  * @param type $computers_id
  * @param $entity
  * @param type $ocsComputer
  * @param type $cfg_ocs
  *
  * @internal param \type $ocsservers_id
  */
 static function updateOfficePack($computers_id, $entity, $ocsComputer, $cfg_ocs)
 {
     global $DB;
     $software = new Software();
     $ocsOfficePacks = $ocsComputer;
     // Read imported software in last sync
     $query = "SELECT `glpi_computers_softwarelicenses`.`id` as id,\n                          `glpi_softwares`.`name` as sname,\n                          `glpi_softwarelicenses`.`name` as lname,\n                          `glpi_softwareversions`.`name` as vname\n                   FROM `glpi_computers_softwarelicenses`\n                   INNER JOIN `glpi_softwarelicenses`\n                           ON `glpi_softwarelicenses`.`id`= `glpi_computers_softwarelicenses`.`softwarelicenses_id`\n                   INNER JOIN `glpi_softwares`\n                           ON `glpi_softwares`.`id`= `glpi_softwarelicenses`.`softwares_id`\n                   INNER JOIN `glpi_softwareversions`\n                           ON `glpi_softwarelicenses`.`softwareversions_id_use` = `glpi_softwareversions`.`id`\n                   WHERE `glpi_computers_softwarelicenses`.`computers_id`='{$computers_id}'\n                         AND `is_dynamic`";
     $imported = array();
     foreach ($DB->request($query) as $data) {
         $imported[$data['id']] = strtolower($data['vname']);
     }
     if (count($ocsOfficePacks) > 0) {
         foreach ($ocsOfficePacks as $ocsOfficePack) {
             $ocsOfficePack = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($ocsOfficePack));
             $query1 = "SELECT `glpi_softwares`.`id` AS softwares_id,\n                              `glpi_softwareversions`.`id` AS softwareversions_id,\n                              `glpi_softwareversions`.`name` AS softwareversions_name\n                     FROM `glpi_softwares`\n                     LEFT JOIN `glpi_softwareversions` ON `glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`\n                     LEFT JOIN `glpi_computers_softwareversions` ON `glpi_computers_softwareversions`.softwareversions_id = `glpi_softwareversions`.`id`\n                     WHERE `glpi_computers_softwareversions`.`computers_id` = '" . $computers_id . "'\n                      AND `is_dynamic` \n                      AND `glpi_softwares`.`name` = '" . $ocsOfficePack['PRODUCT'] . "'\n                      AND `glpi_softwareversions`.`name` = '" . $ocsOfficePack['OFFICEVERSION'] . "'";
             $result = $DB->query($query1);
             if ($DB->numrows($result) > 0) {
                 $softwares_id = $DB->result($result, 0, 'softwares_id');
                 $softwareversions_id = $DB->result($result, 0, 'softwareversions_id');
                 $soft_l['softwares_id'] = $softwares_id;
                 $soft_l['softwareversions_id_use'] = $softwareversions_id;
                 $soft_l['entities_id'] = $entity;
                 $soft_l['name'] = $ocsOfficePack['OFFICEKEY'];
                 $soft_l['serial'] = $ocsOfficePack['OFFICEKEY'];
                 $soft_l['comment'] = $ocsOfficePack['NOTE'];
                 $id = array_search(strtolower(stripslashes($ocsOfficePack['OFFICEVERSION'])), $imported);
                 $software_licenses = new SoftwareLicense();
                 $computer_softwarelicenses = new Computer_SoftwareLicense();
                 if ($id) {
                     //-------------------------------------------------------------------------//
                     //---- The software exists in this license for this computer --------------//
                     //---------------------------- Update comments ----------------------------//
                     //---------------------------------------------------- --------------------//
                     if ($software_licenses->getFromDBByQuery("WHERE `softwares_id` = " . $softwares_id . " \n                                                         AND `serial` = '" . $ocsOfficePack['OFFICEKEY'] . "'\n                                                         AND `softwareversions_id_use` = " . $softwareversions_id)) {
                         $software_licenses->update(array('id' => $software_licenses->getID(), 'comment' => $ocsOfficePack['NOTE']));
                         if (!$computer_softwarelicenses->getFromDBByQuery("WHERE `computers_id` = " . $computers_id . "\n                           AND `softwarelicenses_id` = " . $software_licenses->getID())) {
                             $computer_soft_l['computers_id'] = $computers_id;
                             $computer_soft_l['softwarelicenses_id'] = $software_licenses->getID();
                             $computer_soft_l['is_dynamic'] = -1;
                             $computer_softwarelicenses->add($computer_soft_l);
                         }
                     }
                     unset($imported[$id]);
                 } else {
                     //------------------------------------------------------------------------//
                     //---- The software doesn't exists in this license for this computer -----//
                     //------------------------------------------------------------------------//
                     if ($software_licenses->getFromDBByQuery("WHERE `softwares_id` = " . $softwares_id . " \n                                                         AND `serial` = '" . $ocsOfficePack['OFFICEKEY'] . "'\n                                                         AND `softwareversions_id_use` = " . $softwareversions_id)) {
                         $id_software_licenses = $software_licenses->getID();
                     } else {
                         $software_licenses->fields['softwares_id'] = $softwares_id;
                         $id_software_licenses = $software_licenses->add($soft_l, array(), $cfg_ocs['history_software']);
                     }
                     if ($id_software_licenses) {
                         $computer_soft_l['computers_id'] = $computers_id;
                         $computer_soft_l['softwarelicenses_id'] = $id_software_licenses;
                         $computer_soft_l['is_dynamic'] = 1;
                         $computer_soft_l['number'] = -1;
                         $computer_softwarelicenses->add($computer_soft_l);
                     }
                 }
             }
         }
     }
     foreach ($imported as $id => $unused) {
         $computer_softwarelicenses->delete(array('id' => $id), true, $cfg_ocs['history_software']);
         // delete cause a getFromDB, so fields contains values
         $verid = $computer_softwarelicenses->getField('softwareversions_id');
         if (countElementsInTable('glpi_computers_softwarelicenses', "softwarelicenses_id = '{$verid}'") == 0) {
             $vers = new SoftwareVersion();
             if ($vers->getFromDB($verid) && countElementsInTable('glpi_softwarelicenses', "softwares_id = '" . $vers->fields['softwares_id'] . "'") == 0) {
                 $soft = new Software();
                 $soft->delete(array('id' => $vers->fields['softwares_id']), 1);
             }
             $vers->delete(array("id" => $verid));
         }
     }
 }