function post_addItem() { global $DB; // Manage add from template if (isset($this->input["_oldID"])) { // ADD Devices $compdev = new Computer_Device(); $compdev->cloneComputer($this->input["_oldID"], $this->fields['id']); // ADD Infocoms $ic = new Infocom(); $ic->cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD volumes $query = "SELECT `id`\n FROM `glpi_computerdisks`\n WHERE `computers_id` = '" . $this->input["_oldID"] . "'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_array($result)) { $disk = new ComputerDisk(); $disk->getfromDB($data['id']); unset($disk->fields["id"]); $disk->fields["computers_id"] = $this->fields['id']; $disk->addToDB(); } } // ADD software $inst = new Computer_SoftwareVersion(); $inst->cloneComputer($this->input["_oldID"], $this->fields['id']); $inst = new Computer_SoftwareLicense(); $inst->cloneComputer($this->input["_oldID"], $this->fields['id']); // ADD Contract $query = "SELECT `contracts_id`\n FROM `glpi_contracts_items`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "';"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $contractitem = new Contract_Item(); while ($data = $DB->fetch_array($result)) { $contractitem->add(array('contracts_id' => $data["contracts_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id'])); } } // ADD Documents $query = "SELECT `documents_id`\n FROM `glpi_documents_items`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "';"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $docitem = new Document_Item(); while ($data = $DB->fetch_array($result)) { $docitem->add(array('documents_id' => $data["documents_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id'])); } } // ADD Ports $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "';"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_array($result)) { $np = new NetworkPort(); $npv = new NetworkPort_Vlan(); $np->getFromDB($data["id"]); unset($np->fields["id"]); unset($np->fields["ip"]); unset($np->fields["mac"]); unset($np->fields["netpoints_id"]); $np->fields["items_id"] = $this->fields['id']; $portid = $np->addToDB(); foreach ($DB->request('glpi_networkports_vlans', array('networkports_id' => $data["id"])) as $vlan) { $npv->assignVlan($portid, $vlan['vlans_id']); } } } // Add connected devices $query = "SELECT *\n FROM `glpi_computers_items`\n WHERE `computers_id` = '" . $this->input["_oldID"] . "';"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $conn = new Computer_Item(); while ($data = $DB->fetch_array($result)) { $conn->add(array('computers_id' => $this->fields['id'], 'itemtype' => $data["itemtype"], 'items_id' => $data["items_id"])); } } } }