static public unglobalizeItem ( CommonDBTM $item ) | ||
$item | CommonDBTM | CommonDBTM object to unglobalize |
static function unglobalizeItem(CommonDBTM $item)
{
global $DB;
// Update item to unit management :
if ($item->getField('is_global')) {
$input = array('id' => $item->fields['id'], 'is_global' => 0);
$item->update($input);
// Get connect_wire for this connection
$query = "SELECT `glpi_computers_items`.`id`\n FROM `glpi_computers_items`\n WHERE `glpi_computers_items`.`items_id` = '" . $item->fields['id'] . "'\n AND `glpi_computers_items`.`itemtype` = '" . $item->getType() . "'";
$result = $DB->query($query);
if ($data = $DB->fetch_assoc($result)) {
// First one, keep the existing one
// The others = clone the existing object
unset($input['id']);
$conn = new self();
while ($data = $DB->fetch_assoc($result)) {
$temp = clone $item;
unset($temp->fields['id']);
if ($newID = $temp->add($temp->fields)) {
$conn->update(array('id' => $data['id'], 'items_id' => $newID));
}
}
}
}
}
$monitor->restore($_POST); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"])); $monitor->redirectToList(); } else { if (isset($_POST["purge"])) { $monitor->check($_POST["id"], 'd'); $monitor->delete($_POST, 1); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"])); $monitor->redirectToList(); } else { if (isset($_POST["update"])) { $monitor->check($_POST["id"], 'w'); $monitor->update($_POST); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s updates an item'), $_SESSION["glpiname"])); Html::back(); } else { if (isset($_POST["unglobalize"])) { $monitor->check($_POST["id"], 'w'); Computer_Item::unglobalizeItem($monitor); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s sets unitary management'), $_SESSION["glpiname"])); Html::redirect($CFG_GLPI["root_doc"] . "/front/monitor.form.php?id=" . $_POST["id"]); } else { Html::header(Monitor::getTypeName(2), $_SERVER['PHP_SELF'], "inventory", "monitor"); $monitor->showForm($_GET["id"], array('withtemplate' => $_GET["withtemplate"])); Html::footer(); } } } } } }