ocsinventoryng 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 ocsinventoryng. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include '../../../inc/includes.php'; Session::checkRight("computer", READ); if (isset($_POST["force_ocs_resynch"])) { $computer = new Computer(); $computer->check($_POST['id'], UPDATE); //Get the ocs server id associated with the machine $ocsservers_id = PluginOcsinventoryngOcsServer::getByMachineID($_POST["id"]); //Update the computer $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($ocsservers_id); $dohistory = isset($cfg_ocs['dohistory']) ? $cfg_ocs['dohistory'] : false; PluginOcsinventoryngOcsServer::updateComputer($_POST["resynch_id"], $ocsservers_id, $dohistory, 1); Html::back(); } else { if (isset($_POST["update"])) { $link = new PluginOcsinventoryngOcslink(); $values["id"] = $_POST["link_id"]; $values["use_auto_update"] = $_POST["use_auto_update"]; $link->update($values); Html::back(); } else { if (isset($_POST["delete_link"])) { $comp = new Computer();
echo "Last new computer : " . $data["DEVICEID"] . " ({$maxid}, {$maxti})\n"; if (!$maxid) { die("Bad value\n"); } // Computer from OCS : New, ID Changed, Linked $sql = "SELECT *\n FROM `glpi_logs`\n WHERE `date_mod` >= '{$maxti}'\n AND `itemtype` = 1\n AND `linked_action` IN (8,10,11)\n ORDER BY `id` DESC"; $res = $DB->query($sql); if (!$res) { die("No data from GLPI\n"); } $comp = new Computer(); echo "Start\n"; $tabres = array(); $nb = $nbupd = 0; while ($event = $DB->fetch_array($res)) { if ($event["new_value"] > $maxid && PluginOcsinventoryngOcsServer::getByMachineID($event["items_id"]) == $_GET["server"] && $comp->getFromDB($event["items_id"])) { $nb++; printf("+ %5d : %s : %s (%s > %s)\n", $nb, $event["date_mod"], $comp->fields["name"], $event["old_value"], $event["new_value"]); if (!isset($tabres[$comp->fields["entities_id"]])) { $tabres[$comp->fields["entities_id"]] = array(); } if ($event["linked_action"] == 10) { // ID Changed $tabres[$comp->fields["entities_id"]][] = "ID:" . $comp->fields["id"] . " - " . $comp->fields["name"] . " (" . $comp->fields["serial"] . ") => rollback lien"; // Search the old Device_ID in OCS $sql = "SELECT `DEVICEID`\n FROM `hardware`\n WHERE `ID` = '" . $event["old_value"] . "'"; $resocs = $DBocs->query($sql); $olddevid = ""; if ($hard = $DBocs->fetch_array($resocs)) { $olddevid = $hard["DEVICEID"]; }
/** * if Computer_Item deleted * * @param $comp Computer_Item object **/ static function purgeComputer_Item(Computer_Item $comp) { global $DB; if ($device = getItemForItemtype($comp->fields['itemtype'])) { if ($device->getFromDB($comp->fields['items_id'])) { if (isset($comp->input['_ocsservers_id'])) { $ocsservers_id = $comp->input['_ocsservers_id']; } else { $ocsservers_id = PluginOcsinventoryngOcsServer::getByMachineID($comp->fields['computers_id']); } if ($ocsservers_id > 0) { //Get OCS configuration $ocs_config = PluginOcsinventoryngOcsServer::getConfig($ocsservers_id); //Get the management mode for this device $mode = PluginOcsinventoryngOcsServer::getDevicesManagementMode($ocs_config, $comp->fields['itemtype']); $decoConf = $ocs_config["deconnection_behavior"]; //Change status if : // 1 : the management mode IS NOT global // 2 : a deconnection's status have been defined // 3 : unique with serial if ($mode >= 2 && strlen($decoConf) > 0) { //Delete periph from glpi // if ($decoConf == "delete") { // $tmp["id"] = $comp->fields['items_id']; // $device->delete(array('id' => $tmp['id']), 1); // Put periph in dustbin // } else if ($decoConf == "trash") { // $tmp["id"] = $comp->fields['items_id']; // $device->delete(array('id' => $tmp['id']), 0); // } if ($decoConf == "delete") { $tmp["id"] = $comp->getID(); $query = "DELETE\n FROM `glpi_computers_items`\n WHERE `id`='" . $tmp['id'] . "'"; $result = $DB->query($query); //Put periph in dustbin } else { if ($decoConf == "trash") { $tmp["id"] = $comp->getID(); $query = "UPDATE\n `glpi_computers_items`\n\t\t\t\t\t\t SET `is_deleted` = 1\n WHERE `id`='" . $tmp['id'] . "'"; $result = $DB->query($query); } } } } // $ocsservers_id>0 } } }
/** * if Computer_Item deleted * * @param $comp Computer_Item object **/ static function purgeComputer_Item(Computer_Item $comp) { if ($device = getItemForItemtype($comp->fields['itemtype'])) { if ($device->getFromDB($comp->fields['items_id'])) { if (isset($comp->input['_ocsservers_id'])) { $ocsservers_id = $comp->input['_ocsservers_id']; } else { $ocsservers_id = PluginOcsinventoryngOcsServer::getByMachineID($comp->fields['computers_id']); } if ($ocsservers_id > 0) { //Get OCS configuration $ocs_config = PluginOcsinventoryngOcsServer::getConfig($ocsservers_id); //Get the management mode for this device $mode = PluginOcsinventoryngOcsServer::getDevicesManagementMode($ocs_config, $comp->fields['itemtype']); $decoConf = $ocs_config["deconnection_behavior"]; //Change status if : // 1 : the management mode IS NOT global // 2 : a deconnection's status have been defined // 3 : unique with serial if ($mode >= 2 && strlen($decoConf) > 0) { //Delete periph from glpi if ($decoConf == "delete") { $tmp["id"] = $comp->fields['items_id']; $device->delete($tmp, 1); //Put periph in dustbin } else { if ($decoConf == "trash") { $tmp["id"] = $comp->fields['items_id']; $device->delete($tmp, 0); } } } } // $ocsservers_id>0 } } }