Skip to content

Commit

Permalink
Add group_id_tech and is_recursive fix #182
Browse files Browse the repository at this point in the history
  • Loading branch information
amma35 committed Sep 25, 2018
1 parent 42722d1 commit 0b2325f
Show file tree
Hide file tree
Showing 76 changed files with 8,835 additions and 8,691 deletions.
22 changes: 21 additions & 1 deletion front/ocsng.import.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,25 @@
$location = -1;
}

if (isset($_SESSION["ocs_import"]["is_recursive"][$key])) {
$recursive = $_SESSION["ocs_import"]["is_recursive"][$key];
} else {
$recursive = -1;
}

if (isset($_SESSION["ocs_import"]["groups_id_tech"][$key])) {
$groupTech = $_SESSION["ocs_import"]["groups_id_tech"][$key];
} else {
$groupTech = -1;
}

$process_params = ['ocsid' => $key,
'plugin_ocsinventoryng_ocsservers_id' => $_SESSION["plugin_ocsinventoryng_ocsservers_id"],
'lock' => 0,
'defaultentity' => $entity,
'defaultlocation' => $location];
'defaultlocation' => $location,
'defaultrecursive' => $recursive,
'defaultgrouptech' => $groupTech];
$action = PluginOcsinventoryngOcsProcess::processComputer($process_params);
PluginOcsinventoryngOcsProcess::manageImportStatistics($_SESSION["ocs_import"]['statistics'],
$action['status']);
Expand Down Expand Up @@ -131,6 +145,12 @@
if (isset($_POST['toimport_locations'])) {
$_SESSION["ocs_import"]["locations_id"][$key] = $_POST['toimport_locations'][$key];
}
if (isset($_POST['toimport_recursive'])) {
$_SESSION["ocs_import"]["is_recursive"][$key] = $_POST['toimport_recursive'][$key];
}
if (isset($_POST['toimport_technician_group'])) {
$_SESSION["ocs_import"]["groups_id_tech"][$key] = $_POST['toimport_technician_group'][$key];
}
$_SESSION["ocs_import_count"]++;
}
}
Expand Down
6 changes: 6 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,8 @@ function plugin_ocsinventoryng_install() {
##lang.checkruleimportentity.entity## : ##checkruleimportentity.entity##
##lang.checkruleimportentity.computer## : ##checkruleimportentity.computer##
##lang.checkruleimportentity.location## : ##checkruleimportentity.location##
##lang.checkruleimportentity.is_recursive## : ##checkruleimportentity.is_recursive##
##lang.checkruleimportentity.groups_id_tech## : ##checkruleimportentity.groups_id_tech##
##lang.checkruleimportentity.error## : ##checkruleimportentity.error##
##lang.checkruleimportentity.dataerror## : ##checkruleimportentity.dataerror##
##lang.checkruleimportentity.name_rule## ##checkruleimportentity.name_rule##
Expand All @@ -995,6 +997,8 @@ function plugin_ocsinventoryng_install() {
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.entity##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.computer##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.location##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.is_recursive##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.groups_id_tech##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.error##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.dataerror##</span></td>
<td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checkruleimportentity.name_rule##</span></td>
Expand All @@ -1004,6 +1008,8 @@ function plugin_ocsinventoryng_install() {
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.entity##</span></td>
<td><a href=\"##checkruleimportentity.url##\" target=\"_blank\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.computer##</span></a></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.location##</span></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.is_recursive##</span></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.groups_id_tech##</span></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.error##</span></td>
<td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.dataerror##</span></td>
<td><a href=\"##checkruleimportentity.url_rule##\" target=\"_blank\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checkruleimportentity.name_rule##</span></a></td>
Expand Down
46 changes: 44 additions & 2 deletions inc/hardware.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,14 @@ static function getRuleLockableFields($plugin_ocsinventoryng_ocsservers_id = 0,
} else if (isset($data['locations_id']) && $data['locations_id'] > 0) {
$locks["locations_id"] = __('Location');
}

if (isset($data['groups_id_tech']) && $data['groups_id_tech'] > 0) {
$locks["groups_id_tech"] = __('Group in charge of the hardware');
}
} else {
$locks = ["locations_id" => __('Location'),
"groups_id" => __('Group')];
$locks = ["locations_id" => __('Location'),
"groups_id" => __('Group'),
"groups_id_tech" => __('Group in charge of the hardware')];
}

return $locks;
Expand Down Expand Up @@ -301,6 +306,43 @@ static function updateComputerFields($line_links, $data, $cfg_ocs) {
}
}

//If there's a recursive to update
if (isset($data['is_recursive'])) {
$computer = new Computer();
$tmp['is_recursive'] = $data['is_recursive'];
$tmp['id'] = $line_links['computers_id'];
$computer->update($tmp, $cfg_ocs['history_hardware']);
}

//If there's a Group Tech to update
if (isset($data['groups_id_tech'])) {
$computer = new Computer();
$computer->getFromDB($line_links['computers_id']);
$ancestors = $dbu->getAncestorsOf('glpi_entities', $computer->fields['entities_id']);

$group = new Group();
if ($group->getFromDB($data['groups_id_tech'])) {
//If group is in the same entity as the computer, or if the group is
//defined in a parent entity, but recursive
if ($group->fields['entities_id'] == $computer->fields['entities_id']
|| (in_array($group->fields['entities_id'], $ancestors)
&& $group->fields['is_recursive'])) {
$ko = 0;
$locks = PluginOcsinventoryngOcslink::getLocksForComputer($line_links['computers_id']);
if (is_array($locks) && count($locks)) {
if (in_array("groups_id_tech", $locks)) {
$ko = 1;
}
}
if ($ko == 0) {
$tmp['groups_id_tech'] = $data['groups_id_tech'];
$tmp['id'] = $line_links['computers_id'];
$computer->update($tmp, $cfg_ocs['history_hardware']);
}
}
}
}

//If there's a Group to update
if (isset($data['groups_id'])) {
$computer = new Computer();
Expand Down
40 changes: 22 additions & 18 deletions inc/notificationtargetruleimportentity.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@ function getEvents() {


/**
* Get all data needed for template processing
* Provides minimum information for alerts
* Can be overridden by each NotificationTartget class if needed
* @see NotificationTarget::getDatasForTemplate()
*
* @param string $event Event name
* @param array $options Options
*
* @return void
**/
function addDataForTemplate($event, $options = []) {
* @param $event
* @param array $options
*/
function getDatasForTemplate($event, $options = []) {
global $CFG_GLPI;

$this->data['##checkruleimportentity.date##'] = Html::convDateTime(date('Y-m-d H:i:s'));
Expand All @@ -73,14 +69,20 @@ function addDataForTemplate($event, $options = []) {
foreach ($options['items'] as $id => $item) {
if (!empty($item)) {
$tmp = [];

$tmp['##checkruleimportentity.entity##'] = Dropdown::getDropdownName('glpi_entities',
$item['entities_id']);
$tmp['##checkruleimportentity.computer##'] = $item['name'];
$url = $CFG_GLPI["url_base"] . "/index.php?redirect=Computer_" . $item['id'];
$tmp['##checkruleimportentity.url##'] = urldecode($url);
$tmp['##checkruleimportentity.location##'] = Dropdown::getDropdownName('glpi_locations',
$item['locations_id']);
if($item['is_recursive']){
$tmp['##checkruleimportentity.is_recursive##'] = __('Recursive');
} else{
$tmp['##checkruleimportentity.is_recursive##'] = __("is not") . " " . __('Recursive');
}
$tmp['##checkruleimportentity.groups_id_tech##'] = Dropdown::getDropdownName('glpi_groups',
$item['groups_id_tech']);

$tmp['##checkruleimportentity.error##'] = "";
$tmp['##checkruleimportentity.dataerror##'] = "";
Expand Down Expand Up @@ -126,14 +128,16 @@ function addDataForTemplate($event, $options = []) {
*/
function getTags() {

$tags = ['checkruleimportentity.date' => __('Date'),
'checkruleimportentity.url' => __('Link'),
'checkruleimportentity.entity' => __('Entity'),
'checkruleimportentity.computer' => __('Computer'),
'checkruleimportentity.location' => __('Location'),
'checkruleimportentity.error' => __('Error'),
'checkruleimportentity.name_rule' => __('Rule'),
'checkruleimportentity.dataerror' => __('Data error', 'ocsinventoryng')];
$tags = ['checkruleimportentity.date' => __('Date'),
'checkruleimportentity.url' => __('Link'),
'checkruleimportentity.entity' => __('Entity'),
'checkruleimportentity.computer' => __('Computer'),
'checkruleimportentity.location' => __('Location'),
'checkruleimportentity.is_recursive' => __('Child entities'),
'checkruleimportentity.groups_id_tech' => __('Group in charge of the hardware'),
'checkruleimportentity.error' => __('Error'),
'checkruleimportentity.name_rule' => __('Rule'),
'checkruleimportentity.dataerror' => __('Data error', 'ocsinventoryng')];

foreach ($tags as $tag => $label) {
$this->addTagToList(['tag' => $tag,
Expand Down
8 changes: 6 additions & 2 deletions inc/notimportedcomputer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,18 @@ static function computerImport($params = []) {
'plugin_ocsinventoryng_ocsservers_id' => $notimported->fields['plugin_ocsinventoryng_ocsservers_id'],
'lock' => 0,
'defaultentity' => $params['entity'],
'defaultlocation' => 0];
'defaultlocation' => 0,
'defaultrecursive' => 0,
'defaultgrouptech' => 0];
$result = PluginOcsinventoryngOcsProcess::processComputer($process_params);
} else {
$process_params = ['ocsid' => $notimported->fields['ocsid'],
'plugin_ocsinventoryng_ocsservers_id' => $notimported->fields['plugin_ocsinventoryng_ocsservers_id'],
'lock' => 0,
'defaultentity' => -1,
'defaultlocation' => -1];
'defaultlocation' => -1,
'defaultrecursive' => 0,
'defaultgrouptech' => -1];
$result = PluginOcsinventoryngOcsProcess::processComputer($process_params);
}

Expand Down
Loading

0 comments on commit 0b2325f

Please sign in to comment.