Skip to content

Commit

Permalink
Fix preview for import /linking
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmr committed Nov 24, 2022
1 parent 8d7f3bd commit b2ee92a
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 202 deletions.
161 changes: 83 additions & 78 deletions ajax/loadcomputerstoimport.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

$plugin_ocsinventoryng_ocsservers_id = $_POST["plugin_ocsinventoryng_ocsservers_id"];
$entities_id = $_POST["entities_id"];
$advanced = $_POST["advanced"];
$advanced = 0;
$advancedimport = $_POST["importmode"];
$advancedlink = $_POST["linkmode"];

$hardware["data"] = [];

Expand All @@ -57,11 +57,12 @@

$computerOptions = ['COMPLETE' => '0',
'FILTER' => [
'EXCLUDE_IDS' => $already_linked
'EXCLUDE_IDS' => $already_linked
],
'DISPLAY' => [
'CHECKSUM' => PluginOcsinventoryngOcsClient::CHECKSUM_BIOS
| PluginOcsinventoryngOcsClient::CHECKSUM_NETWORK_ADAPTERS
'CHECKSUM' => PluginOcsinventoryngOcsClient::CHECKSUM_HARDWARE
| PluginOcsinventoryngOcsClient::CHECKSUM_BIOS
| PluginOcsinventoryngOcsClient::CHECKSUM_NETWORK_ADAPTERS
],
];

Expand All @@ -74,13 +75,14 @@
}

$ocsClient = PluginOcsinventoryngOcsServer::getDBocs($plugin_ocsinventoryng_ocsservers_id);
// $numrows = $ocsClient->countComputers($computerOptions);
// $numrows = $ocsClient->countComputers($computerOptions);

// if ($start != 0) {
// $computerOptions['OFFSET'] = $start;
// }
// $computerOptions['MAX_RECORDS'] = $_SESSION['glpilist_limit'];
$ocsResult = $ocsClient->getComputers($computerOptions);
// if ($start != 0) {
// $computerOptions['OFFSET'] = $start;
// }
// $computerOptions['MAX_RECORDS'] = $_SESSION['glpilist_limit'];

$ocsResult = $ocsClient->getComputers($computerOptions);

$computers = (isset($ocsResult['COMPUTERS']) ? $ocsResult['COMPUTERS'] : []);

Expand All @@ -89,18 +91,17 @@
// Get all hardware from OCS DB

foreach ($computers as $data) {

$computerinput = [];
$data = Glpi\Toolbox\Sanitizer::sanitize($data);
$id = $data['META']['ID'];
$input = [
'itemtype' => "Computer",
'name' => $data['META']["NAME"],
'entities_id' => $entities_id,
'serial' => $data['BIOS']["SSN"] ?? '',
'is_dynamic' => 1,
'ocsid' => $id,
'id' => $id,
$data = Glpi\Toolbox\Sanitizer::sanitize($data);
$id = $data['META']['ID'];
$input = [
'itemtype' => "Computer",
'name' => $data['META']["NAME"],
'entities_id' => $entities_id,
'serial' => $data['BIOS']["SSN"] ?? '',
'is_dynamic' => 1,
'ocsid' => $id,
'id' => $id,
];

$serial = "";
Expand Down Expand Up @@ -168,46 +169,49 @@
}

$valTip = " " . Html::showToolTip(
$msg,
[
'awesome-class' => 'fa-comments',
'display' => false,
'autoclose' => false,
'onclick' => true
$msg,
[
'awesome-class' => 'fa-comments',
'display' => false,
'autoclose' => false,
'onclick' => true
]
);
);

$toimport_disable_unicity_check= "";
$rule_matched = "";
$toimport_entities = "";
$toimport_recursive = "";
$computers_id_founded = "";
$toimport_disable_unicity_check = "";
$rule_matched = "";
$toimport_entities = "";
$toimport_recursive = "";
$computers_id_founded = "";

if ($advanced) {
if ($advancedimport) {
$rec = "disable_unicity_check[" . $id . "]";
$toimport_disable_unicity_check = Dropdown::showYesNo($rec, 0, -1, ['display' => false]);

$rule = new RuleImportEntityCollection();
$rule = new RuleImportEntityCollection();

$values = [];

$recursive = isset($data["is_recursive"]) ? $data["is_recursive"] : 0;

$computerinput = $input;
$computerinput['ip'] = $opt['IPADDRESS'];
$computerinput = $input;
$computerinput['ip'] = $opt['IPADDRESS'];
$computerinput['subnet'] = $opt['IPSUBNET'];
if (isset($data['WORKGROUP'])) {
$computerinput['domain'] = $data["WORKGROUP"];

if (isset($data['HARDWARE']['WORKGROUP'])) {
$computerinput['domain'] = $data['HARDWARE']['WORKGROUP'];
}
if (isset($data['HARDWARE']['OSCOMMENTS'])) {
$computerinput['oscomment'] = $data['HARDWARE']['OSCOMMENTS'];
}
// $computerinput['oscomment'] = $opt['oscomment'];

$computerinput['_source'] = 'ocsinventoryng';

$datar = $rule->processAllRules(
$datar = $rule->processAllRules(
$computerinput + ['ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id,
'_source' => 'ocsinventoryng',
'is_recursive' => $recursive,
],
'_source' => 'ocsinventoryng',
'is_recursive' => $recursive,
],
['is_recursive' => $recursive],
['ocsid' => $id, 'return' => true]
);
Expand Down Expand Up @@ -235,7 +239,7 @@
$toimport_recursive = Dropdown::showYesNo($rec, $datar['is_recursive'], -1, ['display' => false]);
}
//Look for the computer using automatic link criterias as defined in OCSNG configuration
if ($advanced) {
if ($advancedlink) {
$rulelink = new RuleImportAssetCollection();
$params = ['entities_id' => $entities_id,
'itemtype' => 'Computer',
Expand All @@ -247,41 +251,42 @@

if (isset($rulelink_results['found_inventories'][0])
&& $rulelink_results['found_inventories'][0] > 0) {
$options['value'] = $rulelink_results['found_inventories'][0];
$options['entity'] = $entities_id;

$options['width'] = "100%";

// if (isset($options['value']) && $options['value'] > 0) {
//
// $query = "SELECT *
// FROM `glpi_plugin_ocsinventoryng_ocslinks`
// WHERE `computers_id` = '" . $options['value'] . "' ";
// $result = $DB->query($query);
// if ($DB->numrows($result) > 0) {
// $ko = 1;
// }
// }
$options['comments'] = false;
$options['display'] = false;
$computers_id_founded = Computer::dropdown($options);
$options['value'] = $rulelink_results['found_inventories'][0];
}
$options['entity'] = $entities_id;

$options['width'] = "100%";

// if (isset($options['value']) && $options['value'] > 0) {
//
// $query = "SELECT *
// FROM `glpi_plugin_ocsinventoryng_ocslinks`
// WHERE `computers_id` = '" . $options['value'] . "' ";
// $result = $DB->query($query);
// if ($DB->numrows($result) > 0) {
// $ko = 1;
// }
// }
$options['comments'] = false;
$options['display'] = false;
$computers_id_founded = Computer::dropdown($options);
// }
}
$hardware["data"][] = [
'checked' => "",
'id' => $data['META']["ID"],
'name' => $data['META']["NAME"],
'date' => $data['META']["LASTDATE"],
'TAG' => $data['META']["TAG"],
'serial' => $serial,
'model' => $model,
'manufacturer' => $manufacturer,
'infos' => $valTip,
'toimport_disable_unicity_check' => $toimport_disable_unicity_check,
'rule_matched' => $rule_matched,
'toimport_entities' => $toimport_entities,
'toimport_recursive' => $toimport_recursive,
'computers_id_founded' => $computers_id_founded
'checked' => "",
'id' => $data['META']["ID"],
'name' => $data['META']["NAME"],
'date' => $data['META']["LASTDATE"],
'TAG' => $data['META']["TAG"],
'serial' => $serial,
'model' => $model,
'manufacturer' => $manufacturer,
'infos' => $valTip,
'toimport_disable_unicity_check' => $toimport_disable_unicity_check,
'rule_matched' => $rule_matched,
'toimport_entities' => $toimport_entities,
'toimport_recursive' => $toimport_recursive,
'computers_id_founded' => $computers_id_founded
];
}
}
Expand Down
21 changes: 15 additions & 6 deletions front/ocsng.import.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,27 @@

Html::header('OCS Inventory NG', '', "tools", "pluginocsinventoryngmenu", "import");

//$display_list = true;
//First time this screen is displayed : set the import mode to 'basic'
if (!isset($_SESSION["change_import_mode"])) {
$_SESSION["change_import_mode"] = 0;
}

if (!isset($_SESSION["change_link_mode"])) {
$_SESSION["change_link_mode"] = 0;
}

//Changing the import mode
if (isset($_POST["simple_mode"])) {
$_SESSION["change_import_mode"] = 0;
$_SESSION["change_link_mode"] = 0;
}

if (isset($_POST["change_import_mode"])) {
if ($_POST['id'] == "false") {
$_SESSION["change_import_mode"] = 0;
} else {
$_SESSION["change_import_mode"] = 1;
}
$_SESSION["change_import_mode"] = 1;
}

if (isset($_POST["change_link_mode"])) {
$_SESSION["change_link_mode"] = 1;
}

if (isset($_SESSION["ocs_import"]['computers'])) {
Expand Down Expand Up @@ -132,6 +140,7 @@

$show_params = ['plugin_ocsinventoryng_ocsservers_id' => $_SESSION["plugin_ocsinventoryng_ocsservers_id"],
'import_mode' => $_SESSION["change_import_mode"],
'link_mode' => $_SESSION["change_link_mode"],
'entities_id' => $_SESSION['glpiactiveentities']];
PluginOcsinventoryngOcsServer::showComputersToAdd($show_params);
} else {
Expand Down
Loading

0 comments on commit b2ee92a

Please sign in to comment.