function post_addItem() { global $DB, $LANG; // Get netpoint for $sport and $dport $sport = $this->fields['networkports_id_1']; $dport = $this->fields['networkports_id_2']; $ps = new NetworkPort(); if (!$ps->getFromDB($sport)) { return false; } $pd = new NetworkPort(); if (!$pd->getFromDB($dport)) { return false; } // Check netpoint for copy $source = ""; $destination = ""; if (isset($ps->fields['netpoints_id']) && $ps->fields['netpoints_id'] != 0) { $source = $ps->fields['netpoints_id']; } if (isset($pd->fields['netpoints_id']) && $pd->fields['netpoints_id'] != 0) { $destination = $pd->fields['netpoints_id']; } // Update Item $updates[0] = 'netpoints_id'; if (empty($source) && !empty($destination)) { $ps->fields['netpoints_id'] = $destination; $ps->updateInDB($updates); addMessageAfterRedirect($LANG['connect'][15] . " : " . $LANG['networking'][51]); } else { if (!empty($source) && empty($destination)) { $pd->fields['netpoints_id'] = $source; $pd->updateInDB($updates); addMessageAfterRedirect($LANG['connect'][15] . " : " . $LANG['networking'][51]); } else { if ($source != $destination) { addMessageAfterRedirect($LANG['connect'][16] . " : " . $LANG['networking'][51]); } } } // Manage VLAN : use networkings one as defaults $npnet = -1; $npdev = -1; if ($ps->fields["itemtype"] != 'NetworkEquipment' && $pd->fields["itemtype"] == 'NetworkEquipment') { $npnet = $dport; $npdev = $sport; } if ($pd->fields["itemtype"] != 'NetworkEquipment' && $ps->fields["itemtype"] == 'NetworkEquipment') { $npnet = $sport; $npdev = $dport; } if ($npnet > 0 && $npdev > 0) { // Get networking VLAN // Unset MAC and IP from networking device $query = "SELECT *\n FROM `glpi_networkports_vlans`\n WHERE `networkports_id` = '{$npnet}'"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { // Found VLAN : clean vlan device and add found ones $query = "DELETE\n FROM `glpi_networkports_vlans`\n WHERE `networkports_id` = '{$npdev}' "; $DB->query($query); while ($data = $DB->fetch_array($result)) { $query = "INSERT INTO `glpi_networkports_vlans`\n (`networkports_id`, `vlans_id`)\n VALUES ('{$npdev}', '" . $data['vlans_id'] . "')"; $DB->query($query); } } } } // end manage VLAN // Manage History $sourcename = NOT_AVAILABLE; $destname = NOT_AVAILABLE; $sourcehistory = false; $desthistory = false; if (class_exists($ps->fields['itemtype'])) { $sourceitem = new $ps->fields['itemtype'](); if ($sourceitem->getFromDB($ps->fields['items_id'])) { $sourcename = $sourceitem->getName(); $sourcehistory = $sourceitem->dohistory; } } if (class_exists($pd->fields['itemtype'])) { $destitem = new $pd->fields['itemtype'](); if ($destitem->getFromDB($pd->fields['items_id'])) { $destname = $destitem->getName(); $desthistory = $destitem->dohistory; } } $changes[0] = 0; $changes[1] = ""; if ($sourcehistory) { $changes[2] = $destname; if ($ps->fields["itemtype"] == 'NetworkEquipment') { $changes[2] = "#" . $ps->fields["name"] . " > " . $changes[2]; } if ($pd->fields["itemtype"] == 'NetworkEquipment') { $changes[2] = $changes[2] . " > #" . $pd->fields["name"]; } Log::history($ps->fields["items_id"], $ps->fields["itemtype"], $changes, $pd->fields["itemtype"], HISTORY_CONNECT_DEVICE); } if ($desthistory) { $changes[2] = $sourcename; if ($pd->fields["itemtype"] == 'NetworkEquipment') { $changes[2] = "#" . $pd->fields["name"] . " > " . $changes[2]; } if ($ps->fields["itemtype"] == 'NetworkEquipment') { $changes[2] = $changes[2] . " > #" . $ps->fields["name"]; } Log::history($pd->fields["items_id"], $pd->fields["itemtype"], $changes, $ps->fields["itemtype"], HISTORY_CONNECT_DEVICE); } }