/** * Display a list of computers to add or to link * * @param plugin_ocsinventoryng_ocsservers_id the ID of the ocs server * @param advanced display detail about the computer import or not (target entity, matched rules, etc.) * @param check indicates if checkboxes are checked or not * @param start display a list of computers starting at rowX * @param entity a list of entities in which computers can be added or linked * @param tolinked false for an import, true for a link * * @return nothing **/ static function showComputersToAdd($serverId, $advanced, $check, $start, $entity = 0, $tolinked = false) { global $DB, $CFG_GLPI; if (!Session::haveRight("plugin_ocsinventoryng", UPDATE)) { return false; } $title = __('Import new computers', 'ocsinventoryng'); if ($tolinked) { $title = __('Link new OCSNG computers to existing GLPI computers', 'ocsinventoryng'); } $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.import.php'; if ($tolinked) { $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.link.php'; } // Get all links between glpi and OCS $query_glpi = "SELECT ocsid\n FROM `glpi_plugin_ocsinventoryng_ocslinks`\n WHERE `plugin_ocsinventoryng_ocsservers_id` = '{$serverId}'"; $result_glpi = $DB->query($query_glpi); $already_linked = array(); if ($DB->numrows($result_glpi) > 0) { while ($data = $DB->fetch_array($result_glpi)) { $already_linked[] = $data["ocsid"]; } } $cfg_ocs = self::getConfig($serverId); $computerOptions = array('OFFSET' => $start, 'MAX_RECORDS' => $_SESSION['glpilist_limit'], 'ORDER' => 'LASTDATE', 'FILTER' => array('EXCLUDE_IDS' => $already_linked), 'DISPLAY' => array('CHECKSUM' => PluginOcsinventoryngOcsClient::CHECKSUM_BIOS), 'ORDER' => 'NAME'); if ($cfg_ocs["tag_limit"] and $tag_limit = explode("\$", trim($cfg_ocs["tag_limit"]))) { $computerOptions['FILTER']['TAGS'] = $tag_limit; } if ($cfg_ocs["tag_exclude"] and $tag_exclude = explode("\$", trim($cfg_ocs["tag_exclude"]))) { $computerOptions['FILTER']['EXCLUDE_TAGS'] = $tag_exclude; } $ocsClient = self::getDBocs($serverId); $ocsResult = $ocsClient->getComputers($computerOptions); if (isset($ocsResult['COMPUTERS'])) { $computers = $ocsResult['COMPUTERS']; if (count($computers)) { // Get all hardware from OCS DB $hardware = array(); foreach ($computers as $data) { $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data)); $id = $data['META']['ID']; $hardware[$id]["date"] = $data['META']["LASTDATE"]; $hardware[$id]["name"] = $data['META']["NAME"]; $hardware[$id]["TAG"] = $data['META']["TAG"]; $hardware[$id]["id"] = $data['META']["ID"]; if (isset($data['BIOS']) && count($data['BIOS'])) { $hardware[$id]["serial"] = $data['BIOS']["SSN"]; $hardware[$id]["model"] = $data['BIOS']["SMODEL"]; $hardware[$id]["manufacturer"] = $data['BIOS']["SMANUFACTURER"]; } else { $hardware[$id]["serial"] = ''; $hardware[$id]["model"] = ''; $hardware[$id]["manufacturer"] = ''; } } if ($tolinked && count($hardware)) { echo "<div class='center b'>" . __('Caution! The imported data (see your configuration) will overwrite the existing one', 'ocsinventoryng') . "</div>"; } echo "<div class='center'>"; if ($numrows = $ocsResult['TOTAL_COUNT']) { $parameters = "check={$check}"; Html::printPager($start, $numrows, $target, $parameters); //Show preview form only in import even in multi-entity mode because computer import //can be refused by a rule if (!$tolinked) { echo "<div class='firstbloc'>"; echo "<form method='post' name='ocsng_import_mode' id='ocsng_import_mode'\n action='{$target}'>\n"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Manual import mode', 'ocsinventoryng') . "</th></tr>\n"; echo "<tr class='tab_bg_1'><td class='center'>"; if ($advanced) { Html::showSimpleForm($target, 'change_import_mode', __('Disable preview', 'ocsinventoryng'), array('id' => 'false')); } else { Html::showSimpleForm($target, 'change_import_mode', __('Enable preview', 'ocsinventoryng'), array('id' => 'true')); } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td class='center b'>" . __('Check first that duplicates have been correctly managed in OCSNG', 'ocsinventoryng') . "</td>"; echo "</tr></table>"; Html::closeForm(); echo "</div>"; } echo "<form method='post' name='ocsng_form' id='ocsng_form' action='{$target}'>"; if (!$tolinked) { self::checkBox($target); } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">"; echo "</td></tr>\n"; echo "<tr><th>" . __('Name') . "</th>\n"; echo "<th>" . __('Manufacturer') . "</th>\n"; echo "<th>" . __('Model') . "</th>\n"; echo "<th>" . __('Serial number') . "</th>\n"; echo "<th>" . __('Date') . "</th>\n"; echo "<th>" . __('OCSNG TAG', 'ocsinventoryng') . "</th>\n"; if ($advanced && !$tolinked) { echo "<th>" . __('Match the rule ?', 'ocsinventoryng') . "</th>\n"; echo "<th>" . __('Destination entity') . "</th>\n"; echo "<th>" . __('Target location', 'ocsinventoryng') . "</th>\n"; } echo "<th width='20%'> </th></tr>\n"; $rule = new RuleImportEntityCollection(); foreach ($hardware as $ID => $tab) { $comp = new Computer(); $comp->fields["id"] = $tab["id"]; $data = array(); if ($advanced && !$tolinked) { $data = $rule->processAllRules(array('ocsservers_id' => $serverId, '_source' => 'ocsinventoryng'), array(), array('ocsid' => $tab["id"])); } echo "<tr class='tab_bg_2'><td>" . $tab["name"] . "</td>\n"; echo "<td>" . $tab["manufacturer"] . "</td><td>" . $tab["model"] . "</td>"; echo "<td>" . $tab["serial"] . "</td>\n"; echo "<td>" . Html::convDateTime($tab["date"]) . "</td>\n"; echo "<td>" . $tab["TAG"] . "</td>\n"; if ($advanced && !$tolinked) { if (!isset($data['entities_id']) || $data['entities_id'] == -1) { echo "<td class='center'><img src=\"" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png\"></td>\n"; $data['entities_id'] = -1; } else { echo "<td class='center'>"; $tmprule = new RuleImportEntity(); if ($tmprule->can($data['_ruleid'], READ)) { echo "<a href='" . $tmprule->getLinkURL() . "'>" . $tmprule->getName() . "</a>"; } else { echo $tmprule->getName(); } echo "</td>\n"; } echo "<td width='30%'>"; $ent = "toimport_entities[" . $tab["id"] . "]"; Entity::dropdown(array('name' => $ent, 'value' => $data['entities_id'], 'comments' => 0)); echo "</td>\n"; echo "<td width='30%'>"; if (!isset($data['locations_id'])) { $data['locations_id'] = 0; } $loc = "toimport_locations[" . $tab["id"] . "]"; Location::dropdown(array('name' => $loc, 'value' => $data['locations_id'], 'comments' => 0)); echo "</td>\n"; } echo "<td>"; if (!$tolinked) { echo "<input type='checkbox' name='toimport[" . $tab["id"] . "]' " . ($check == "all" ? "checked" : "") . ">"; } else { $tab['entities_id'] = $entity; $rulelink = new RuleImportComputerCollection(); $rulelink_results = array(); $params = array('entities_id' => $entity, 'plugin_ocsinventoryng_ocsservers_id' => $serverId); $rulelink_results = $rulelink->processAllRules(Toolbox::stripslashes_deep($tab), array(), $params); //Look for the computer using automatic link criterias as defined in OCSNG configuration $options = array('name' => "tolink[" . $tab["id"] . "]"); $show_dropdown = true; //If the computer is not explicitly refused by a rule if (!isset($rulelink_results['action']) || $rulelink_results['action'] != self::LINK_RESULT_NO_IMPORT) { if (!empty($rulelink_results['found_computers'])) { $options['value'] = $rulelink_results['found_computers'][0]; $options['entity'] = $entity; } $options['width'] = "100%"; Computer::dropdown($options); } else { echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>"; } } echo "</td></tr>\n"; } echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">\n"; echo "<input type=hidden name='plugin_ocsinventoryng_ocsservers_id' " . "value='{$serverId}'>"; echo "</td></tr>"; echo "</table>\n"; Html::closeForm(); if (!$tolinked) { self::checkBox($target); } Html::printPager($start, $numrows, $target, $parameters); } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $title . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table>"; } echo "</div>"; } else { echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $title . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table></div>"; } } else { echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $title . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table></div>"; } }
/** * @param $info array * @param $option array **/ function showAdditionalInformation($info = array(), $option = array()) { $name = "info[" . $option['linkfield'] . "]"; switch ($option['displaytype']) { case 'computer': Computer::dropdown(array('name' => $name, 'entity' => $_SESSION['glpiactive_entity'], 'entity_sons' => false)); break; case 'software': Software::dropdown(array('name' => $name, 'entity' => $_SESSION['glpiactive_entity'], 'entity_sons' => false)); break; default: break; } }
/** * 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}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&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"; }
/** * Display a list of computers to add or to link * * @param plugin_ocsinventoryng_ocsservers_id the ID of the ocs server * @param advanced display detail about the computer import or not (target entity, matched rules, etc.) * @param check indicates if checkboxes are checked or not * @param start display a list of computers starting at rowX * @param entity a list of entities in which computers can be added or linked * @param tolinked false for an import, true for a link * * @return nothing **/ static function showComputersToAdd($plugin_ocsinventoryng_ocsservers_id, $advanced, $check, $start, $entity = 0, $tolinked = false) { global $DB, $PluginOcsinventoryngDBocs, $CFG_GLPI; if (!plugin_ocsinventoryng_haveRight("ocsng", "w")) { return false; } $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.import.php'; if ($tolinked) { $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.link.php'; } $cfg_ocs = self::getConfig($plugin_ocsinventoryng_ocsservers_id); $WHERE = self::getTagLimit($cfg_ocs); $query_ocs = "SELECT `hardware`.*,\n `accountinfo`.`TAG` AS TAG,\n `bios`.`SSN` AS SERIAL,\n `bios`.`SMODEL`,\n `bios`.`SMANUFACTURER`\n FROM `hardware`\n INNER JOIN `accountinfo` ON (`hardware`.`id` = `accountinfo`.`HARDWARE_ID`)\n INNER JOIN `bios` ON (`hardware`.`id` = `bios`.`HARDWARE_ID`)" . (!empty($WHERE) ? "WHERE {$WHERE}" : "") . "\n ORDER BY `hardware`.`NAME`"; $result_ocs = $PluginOcsinventoryngDBocs->query($query_ocs); // Existing OCS - GLPI link $query_glpi = "SELECT*\n FROM `glpi_plugin_ocsinventoryng_ocslinks`\n WHERE `plugin_ocsinventoryng_ocsservers_id`\n = '{$plugin_ocsinventoryng_ocsservers_id}'"; $result_glpi = $DB->query($query_glpi); if ($PluginOcsinventoryngDBocs->numrows($result_ocs) > 0) { // Get all hardware from OCS DB $hardware = array(); while ($data = $PluginOcsinventoryngDBocs->fetch_array($result_ocs)) { $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data)); $hardware[$data["ID"]]["date"] = $data["LASTDATE"]; $hardware[$data["ID"]]["name"] = $data["NAME"]; $hardware[$data["ID"]]["TAG"] = $data["TAG"]; $hardware[$data["ID"]]["id"] = $data["ID"]; $hardware[$data["ID"]]["serial"] = $data["SERIAL"]; $hardware[$data["ID"]]["model"] = $data["SMODEL"]; $hardware[$data["ID"]]["manufacturer"] = $data["SMANUFACTURER"]; $query_network = "SELECT*\n FROM `networks`\n WHERE `HARDWARE_ID` = '" . $data["ID"] . "'"; //Get network informations for this computer //Ignore informations that contains "??" foreach ($PluginOcsinventoryngDBocs->request($query_network) as $network) { if (isset($network['IPADDRESS']) && $network['IPADDRESS'] != '??') { $hardware[$data["ID"]]['IPADDRESS'][] = $network['IPADDRESS']; } if (isset($network['IPSUBNET']) && $network['IPSUBNET'] != '??') { $hardware[$data["ID"]]['IPSUBNET'][] = $network['IPSUBNET']; } if (isset($network['MACADDRESS']) && $network['MACADDR'] != '??') { $hardware[$data["ID"]]['MACADDRESS'][] = $network['MACADDR']; } } } // Get all links between glpi and OCS $already_linked = array(); if ($DB->numrows($result_glpi) > 0) { while ($data = $PluginOcsinventoryngDBocs->fetch_array($result_glpi)) { $already_linked[$data["ocsid"]] = $data["last_update"]; } } // Clean $hardware from already linked element if (count($already_linked) > 0) { foreach ($already_linked as $ID => $date) { if (isset($hardware[$ID]) && isset($already_linked[$ID])) { unset($hardware[$ID]); } } } if ($tolinked && count($hardware)) { echo "<div class='center b'>" . __('Caution! The imported data (see your configuration) will overwrite the existing one', 'ocsinventoryng') . "</div>"; } echo "<div class='center'>"; if (($numrows = count($hardware)) > 0) { $parameters = "check={$check}"; Html::printPager($start, $numrows, $target, $parameters); // delete end array_splice($hardware, $start + $_SESSION['glpilist_limit']); // delete begin if ($start > 0) { array_splice($hardware, 0, $start); } //Show preview form only in import even in multi-entity mode because computer import //can be refused by a rule if (!$tolinked) { echo "<div class='firstbloc'>"; echo "<form method='post' name='ocsng_import_mode' id='ocsng_import_mode'\n action='{$target}'>\n"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Manual import mode', 'ocsinventoryng') . "</th></tr>\n"; echo "<tr class='tab_bg_1'><td class='center'>"; if ($advanced) { Html::showSimpleForm($target, 'change_import_mode', __('Disable preview', 'ocsinventoryng'), array('id' => 'false')); } else { Html::showSimpleForm($target, 'change_import_mode', __('Enable preview', 'ocsinventoryng'), array('id' => 'true')); } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td class='center b'>" . __('Check first that duplicates have been correctly managed in OCSNG', 'ocsinventoryng') . "</td>"; echo "</tr></table>"; Html::closeForm(); echo "</div>"; } echo "<form method='post' name='ocsng_form' id='ocsng_form' action='{$target}'>"; if (!$tolinked) { self::checkBox($target); } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">"; echo "</td></tr>\n"; echo "<tr><th>" . __('Name') . "</th>\n"; echo "<th>" . __('Manufacturer') . "</th>\n"; echo "<th>" . __('Model') . "</th>\n"; echo "<th>" . __('Serial number') . "</th>\n"; echo "<th>" . __('Date') . "</th>\n"; echo "<th>" . __('OCSNG TAG', 'ocsinventoryng') . "</th>\n"; if ($advanced && !$tolinked) { echo "<th>" . __('Match the rule ?', 'ocsinventoryng') . "</th>\n"; echo "<th>" . __('Destination entity') . "</th>\n"; echo "<th>" . __('Target location', 'ocsinventoryng') . "</th>\n"; } echo "<th> </th></tr>\n"; $rule = new RuleImportEntityCollection(); foreach ($hardware as $ID => $tab) { $comp = new Computer(); $comp->fields["id"] = $tab["id"]; $data = array(); if ($advanced && !$tolinked) { $data = $rule->processAllRules(array('ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id, '_source' => 'ocsinventoryng'), array(), array('ocsid' => $tab["id"])); } echo "<tr class='tab_bg_2'><td>" . $tab["name"] . "</td>\n"; echo "<td>" . $tab["manufacturer"] . "</td><td>" . $tab["model"] . "</td>"; echo "<td>" . $tab["serial"] . "</td>\n"; echo "<td>" . Html::convDateTime($tab["date"]) . "</td>\n"; echo "<td>" . $tab["TAG"] . "</td>\n"; if ($advanced && !$tolinked) { if (!isset($data['entities_id']) || $data['entities_id'] == -1) { echo "<td class='center'><img src=\"" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png\"></td>\n"; $data['entities_id'] = -1; } else { echo "<td class='center'>"; $tmprule = new RuleImportEntity(); if ($tmprule->can($data['_ruleid'], 'r')) { echo "<a href='" . $tmprule->getLinkURL() . "'>" . $tmprule->getName() . "</a>"; } else { echo $tmprule->getName(); } echo "</td>\n"; } echo "<td>"; Entity::dropdown(array('name' => "toimport_entities[" . $tab["id"] . "]=" . $data['entities_id'], 'value' => $data['entities_id'], 'comments' => 0)); echo "</td>\n"; echo "<td>"; if (!isset($data['locations_id'])) { $data['locations_id'] = 0; } Location::dropdown(array('name' => "toimport_locations[" . $tab["id"] . "]=" . $data['locations_id'], 'value' => $data['locations_id'], 'comments' => 0)); echo "</td>\n"; } echo "<td>"; if (!$tolinked) { echo "<input type='checkbox' name='toimport[" . $tab["id"] . "]' " . ($check == "all" ? "checked" : "") . ">"; } else { $rulelink = new RuleImportComputerCollection(); $rulelink_results = array(); $params = array('entities_id' => $entity, 'plugin_ocsinventoryng_ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id); $rulelink_results = $rulelink->processAllRules(Toolbox::stripslashes_deep($tab), array(), $params); //Look for the computer using automatic link criterias as defined in OCSNG configuration $options = array('name' => "tolink[" . $tab["id"] . "]"); $show_dropdown = true; //If the computer is not explicitly refused by a rule if (!isset($rulelink_results['action']) || $rulelink_results['action'] != self::LINK_RESULT_NO_IMPORT) { if (!empty($rulelink_results['found_computers'])) { $options['value'] = $rulelink_results['found_computers'][0]; $options['entity'] = $entity; } Computer::dropdown($options); } else { echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>"; } } echo "</td></tr>\n"; } echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">\n"; echo "<input type=hidden name='plugin_ocsinventoryng_ocsservers_id' " . "value='{$plugin_ocsinventoryng_ocsservers_id}'>"; echo "</td></tr>"; echo "</table>\n"; Html::closeForm(); if (!$tolinked) { self::checkBox($target); } Html::printPager($start, $numrows, $target, $parameters); } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Import new computers') . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table>"; } echo "</div>"; } else { echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Import new computers', 'ocsinventoryng') . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table></div>"; } }
/** * @param $options array */ function plugin_ocsinventoryng_MassiveActionsDisplay($options = array()) { switch ($options['itemtype']) { case 'PluginOcsinventoryngNotimportedcomputer': switch ($options['action']) { case "plugin_ocsinventoryng_import": Entity::dropdown(array('name' => 'entity')); break; case "plugin_ocsinventoryng_link": Computer::dropdown(array('name' => 'computers_id')); break; case "plugin_ocsinventoryng_replayrules": case "plugin_ocsinventoryng_delete": break; } echo " <input type='submit' name='massiveaction' class='submit' " . "value='" . _sx('button', 'Post') . "'>"; break; case 'Computer': switch ($options['action']) { case "plugin_ocsinventoryng_force_ocsng_update": echo "<input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Post') . "'>\n"; break; case "plugin_ocsinventoryng_unlock_ocsng_field": $fields['all'] = __('All'); $fields += PluginOcsinventoryngOcsServer::getLockableFields(); Dropdown::showFromArray("field", $fields); echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Post') . "'>"; break; } } return ""; }