/** * @param $computers_id * @param $date * @param $computer_updates * @return array */ static function addInfocomsForComputer($computers_id, $date, $computer_updates) { global $DB; $infocom = new Infocom(); $use_date = substr($date, 0, 10); if ($infocom->getFromDBByQuery("WHERE `items_id` = {$computers_id} AND `itemtype` = 'Computer'")) { if (empty($infocom->fields['use_date']) || $infocom->fields['use_date'] == 'NULL') { //add use_date $infocom->update(array('id' => $infocom->fields['id'], 'use_date' => $use_date)); } } else { //add infocom $infocom->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'use_date' => $use_date)); } //Add lock $ocslink = new PluginOcsinventoryngOcslink(); if ($ocslink->getFromDBforComputer($computers_id)) { $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($ocslink->fields["plugin_ocsinventoryng_ocsservers_id"]); if ($cfg_ocs["use_locks"]) { $computer_updates[] = "use_date"; $query = "UPDATE `glpi_plugin_ocsinventoryng_ocslinks`\n SET `computer_update` = '" . addslashes(exportArrayToDB($computer_updates)) . "'\n WHERE `computers_id` = '{$computers_id}'"; $DB->query($query); } } return $computer_updates; }
/** * Transfer infocoms of an item * * @param $itemtype type of the item to transfer * @param $ID original ID of the item * @param $newID new ID of the item **/ function transferInfocoms($itemtype, $ID, $newID) { global $DB; $ic = new Infocom(); if ($ic->getFromDBforDevice($itemtype, $ID)) { switch ($this->options['keep_infocom']) { // delete case 0: // Same item -> delete if ($ID == $newID) { $query = "DELETE\n FROM `glpi_infocoms`\n WHERE `itemtype` = '{$itemtype}'\n AND `items_id` = '{$ID}'"; $result = $DB->query($query); } // Copy : nothing to do break; // Keep // Keep default: // Transfer enterprise $suppliers_id = 0; if ($ic->fields['suppliers_id'] > 0) { $suppliers_id = $this->transferSingleSupplier($ic->fields['suppliers_id']); } // Copy : copy infocoms if ($ID != $newID) { // Copy items $input = $ic->fields; $input['items_id'] = $newID; $input['suppliers_id'] = $suppliers_id; unset($input['id']); unset($ic->fields); $ic->add($input); } else { // Same Item : manage only enterprise move // Update enterprise if ($suppliers_id > 0 && $suppliers_id != $ic->fields['suppliers_id']) { $ic->update(array('id' => $ic->fields['id'], 'suppliers_id' => $suppliers_id)); } } break; } } }
static function saveInfocoms($options) { //valeurs d'origine $warranty_date = ""; $buy_date = ""; $warranty_duration = ""; $suppliers_id = ""; $ic_comments = ""; //nouvelles valeurs $input_infocom = array(); if ($options["supplierId"] != 0) { $input_infocom["suppliers_id"] = $options["supplierId"]; } $input_infocom["warranty_date"] = $options["maDate"]; $input_infocom["warranty_duration"] = $options["warranty"]; $input_infocom["buy_date"] = $options["maDate"]; $input_infocom["items_id"] = $options["ID"]; $input_infocom["itemtype"] = $options["itemtype"]; //add new infocoms $ic = new infocom(); if ($ic->getfromDBforDevice($options["itemtype"], $options["ID"])) { //valeurs d'origine $warranty_date = Html::convdate($ic->fields["warranty_date"]); $warranty_duration = $ic->fields["warranty_duration"]; $buy_date = $ic->fields["buy_date"]; $suppliers_id = Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]); $ic_comment = $ic->fields["comment"]; //nouvelles valeurs $input_infocom["id"] = $ic->fields["id"]; if ($options["addcomments"]) { $input_infocom["comment"] = $ic_comment . "\n" . __('Imported from web site', 'manufacturersimports') . " " . $options["suppliername"] . " " . __('With the manufacturersimports plugin', 'manufacturersimports') . " (" . Html::convdate($options["date"]) . ")"; } $infocom = new Infocom(); $infocom->update($input_infocom); } else { if ($options["addcomments"]) { $input_infocom["comment"] = __('Imported from web site', 'manufacturersimports') . " " . $options["suppliername"] . " " . __('With the manufacturersimports plugin', 'manufacturersimports') . " (" . Html::convdate($options["date"]) . ")"; } $infocom = new Infocom(); $infocom->add($input_infocom); } //post message echo "<td><span class='plugin_manufacturersimports_import_OK'>"; echo __('Import OK', 'manufacturersimports') . " (" . Html::convdate($options["date"]) . ")"; echo "</span></td>"; echo "<td>"; echo _n('Supplier', 'Suppliers', 1) . ": "; echo $suppliers_id . "->" . Dropdown::getDropdownName("glpi_suppliers", $options["supplierId"]) . "<br>"; echo __('Date of purchase') . ": "; echo Html::convdate($buy_date) . "->" . Html::convdate($options["maDate"]) . "<br>"; echo __('Start date of warranty') . ": "; echo $warranty_date . "->" . Html::convdate($options["maDate"]) . "<br>"; if ($warranty_duration == -1) { $warranty_duration = __('Lifelong'); $warranty = __('Lifelong'); } else { $warranty = $options["warranty"]; } echo __('Warranty duration') . ": " . $warranty_duration . "->" . $warranty . "<br>"; echo "</td>"; }
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 GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; $ic = new Infocom(); if (isset($_POST['add'])) { $ic->check(-1, CREATE, $_POST); $newID = $ic->add($_POST, false); Event::log($newID, "infocom", 4, "financial", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $newID)); Html::back(); } else { if (isset($_POST["purge"])) { $ic->check($_POST["id"], PURGE); $ic->delete($_POST, 1); Event::log($_POST["id"], "infocom", 4, "financial", sprintf(__('%s purges an item'), $_SESSION["glpiname"])); Html::back(); } else { if (isset($_POST["update"])) { $ic->check($_POST["id"], UPDATE); $ic->update($_POST); Event::log($_POST["id"], "infocom", 4, "financial", sprintf(__('%s updates an item'), $_SESSION["glpiname"])); Html::back(); } else {
/** Generate bigdump : add infocoms to an item * * @param $type item type * @param $ID item ID * @param $ID_entity entity ID * @param $is_recursive (default 0) **/ function addInfocoms($type, $ID, $ID_entity, $is_recursive=0) { global $DB, $FIRST, $LAST; $current_year = date('Y'); $orderdate = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $buydate = $orderdate+mt_rand(0, 60)*DAY_TIMESTAMP; $deliverydate = $orderdate+mt_rand(0, 60)*DAY_TIMESTAMP; $usedate = $deliverydate+mt_rand(0, 60)*DAY_TIMESTAMP; $warrantydate = $deliverydate; $inventorydate = $deliverydate; $orderdate = date("Y-m-d", intval($orderdate)); $buydate = date("Y-m-d", intval($buydate)); $deliverydate = date("Y-m-d", intval($deliverydate)); $usedate = date("Y-m-d", intval($usedate)); $warrantydate = date("Y-m-d", intval($warrantydate)); $inventorydate = date("Y-m-d", intval($inventorydate)); $i = new Infocom(); $i->add(toolbox::addslashes_deep( array('itemtype' => $type, 'items_id' => $ID, 'entities_id' => $ID_entity, 'is_recursive' => $is_recursive, 'buy_date' => $buydate, 'use_date' => $usedate, 'warranty_duration' => mt_rand(12,36), 'warranty_info' => "infowar ' $type $ID", 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST['enterprises']), 'order_number' => "commande ' $type $ID", 'delivery_number' => "BL ' $type $ID", 'immo_number' => "immo ' $type $ID", 'value' => mt_rand(0,5000), 'warranty_value' => mt_rand(0,500), 'sink_time' => mt_rand(1,7), 'sink_type' => mt_rand(1,2), 'sink_coeff' => mt_rand(2,5), 'comment' => "comment ' $type $ID", 'bill' => "bill ' $type $ID", 'budgets_id' => mt_rand($FIRST['budget'], $LAST['budget']), 'order_date' => $orderdate, 'delivery_date' => $deliverydate, 'inventory_date' => $inventorydate, 'warranty_date' => $warrantydate))); }
/** * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $CFG_GLPI; $action = $ma->getAction(); switch ($action) { case 'delete': foreach ($ids as $id) { if ($item->can($id, DELETE)) { if ($item->delete(array("id" => $id))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } break; case 'restore': foreach ($ids as $id) { if ($item->can($id, PURGE)) { if ($item->restore(array("id" => $id))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } break; case 'purge_item_but_devices': case 'purge_but_item_linked': case 'purge': foreach ($ids as $id) { if ($item->can($id, PURGE)) { $force = 1; // Only mark deletion for if ($item->maybeDeleted() && $item->useDeletedToLockIfDynamic() && $item->isDynamic()) { $force = 0; } $delete_array = array('id' => $id); if ($action == 'purge_item_but_devices') { $delete_array['keep_devices'] = true; } if ($item instanceof CommonDropdown) { if ($item->haveChildren()) { if ($action != 'purge_but_item_linked') { $force = 0; $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage(__("You can't delete that item by massive actions, because it has sub-items")); $ma->addMessage(__("but you can do it by the form of the item")); continue; } } if ($item->isUsed()) { if ($action != 'purge_but_item_linked') { $force = 0; $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage(__("You can't delete that item, because it is used for one or more items")); $ma->addMessage(__("but you can do it by the form of the item")); continue; } } } if ($item->delete($delete_array, $force)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } break; case 'update': if (!isset($ma->POST['search_options']) || !isset($ma->POST['search_options'][$item->getType()])) { return false; } $index = $ma->POST['search_options'][$item->getType()]; $searchopt = Search::getCleanedOptions($item->getType(), UPDATE); $input = $ma->POST; if (isset($searchopt[$index])) { /// Infocoms case if (!isPluginItemType($item->getType()) && Search::isInfocomOption($item->getType(), $index)) { $ic = new Infocom(); $link_entity_type = -1; /// Specific entity item if ($searchopt[$index]["table"] == "glpi_suppliers") { $ent = new Supplier(); if ($ent->getFromDB($input[$input["field"]])) { $link_entity_type = $ent->fields["entities_id"]; } } foreach ($ids as $key) { if ($item->getFromDB($key)) { if ($link_entity_type < 0 || $link_entity_type == $item->getEntityID() || $ent->fields["is_recursive"] && in_array($link_entity_type, getAncestorsOf("glpi_entities", $item->getEntityID()))) { $input2["items_id"] = $key; $input2["itemtype"] = $item->getType(); if ($ic->can(-1, CREATE, $input2)) { // Add infocom if not exists if (!$ic->getFromDBforDevice($item->getType(), $key)) { $input2["items_id"] = $key; $input2["itemtype"] = $item->getType(); unset($ic->fields); $ic->add($input2); $ic->getFromDBforDevice($item->getType(), $key); } $id = $ic->fields["id"]; unset($ic->fields); if ($ic->update(array('id' => $id, $input["field"] => $input[$input["field"]]))) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_COMPAT)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } else { /// Not infocoms $link_entity_type = array(); /// Specific entity item $itemtable = getTableForItemType($item->getType()); $itemtype2 = getItemTypeForTable($searchopt[$index]["table"]); if ($item2 = getItemForItemtype($itemtype2)) { if ($index != 80 && $searchopt[$index]["table"] != $itemtable && $item2->isEntityAssign() && $item->isEntityAssign()) { if ($item2->getFromDB($input[$input["field"]])) { if (isset($item2->fields["entities_id"]) && $item2->fields["entities_id"] >= 0) { if (isset($item2->fields["is_recursive"]) && $item2->fields["is_recursive"]) { $link_entity_type = getSonsOf("glpi_entities", $item2->fields["entities_id"]); } else { $link_entity_type[] = $item2->fields["entities_id"]; } } } } } foreach ($ids as $key) { if ($item->canEdit($key) && $item->canMassiveAction($action, $input['field'], $input[$input["field"]])) { if (count($link_entity_type) == 0 || in_array($item->fields["entities_id"], $link_entity_type)) { if ($item->update(array('id' => $key, $input["field"] => $input[$input["field"]]))) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_COMPAT)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } } } break; case 'add_transfer_list': $itemtype = $item->getType(); if (!isset($_SESSION['glpitransfer_list'])) { $_SESSION['glpitransfer_list'] = array(); } if (!isset($_SESSION['glpitransfer_list'][$itemtype])) { $_SESSION['glpitransfer_list'][$itemtype] = array(); } foreach ($ids as $id) { $_SESSION['glpitransfer_list'][$itemtype][$id] = $id; $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } $ma->setRedirect($CFG_GLPI['root_doc'] . '/front/transfer.action.php'); break; } }
public function generateInfoComRelatedToOrder($entity, $detailID, $itemtype, $items_id, $templateID = 0) { global $CFG_GLPI; //Do not try to generate infocoms if itemtype doesn't support it (ie contracts...) if (in_array($itemtype, $CFG_GLPI["infocom_types"])) { // Retrieve configuration for generate assets feature $config = PluginOrderConfig::getConfig(); $fields = array(); //Create empty infocom, in order to forward entities_id and is_recursive $ic = new Infocom(); $infocomID = !$ic->getFromDBforDevice($itemtype, $items_id) ? false : $ic->fields["id"]; $detail = new PluginOrderOrder_Item(); $detail->getFromDB($detailID); $order = new PluginOrderOrder(); $order->getFromDB($detail->fields["plugin_order_orders_id"]); $order_supplier = new PluginOrderOrder_Supplier(); $order_supplier->getFromDBByOrder($detail->fields["plugin_order_orders_id"]); if ($templateID) { if ($ic->getFromDBforDevice($itemtype, $templateID)) { $fields = $ic->fields; unset($fields["id"]); if (isset($fields["immo_number"])) { $fields["immo_number"] = autoName($fields["immo_number"], "immo_number", 1, 'Infocom', $entity); } if (empty($fields['buy_date'])) { unset($fields['buy_date']); } } } $fields["entities_id"] = $entity; $fields["itemtype"] = $itemtype; $fields["items_id"] = $items_id; $fields["order_number"] = $order->fields["num_order"]; $fields["delivery_number"] = $detail->fields["delivery_number"]; $fields["budgets_id"] = $order->fields["budgets_id"]; $fields["suppliers_id"] = $order->fields["suppliers_id"]; $fields["value"] = $detail->fields["price_discounted"]; $fields["order_date"] = $order->fields["order_date"]; if (!is_null($detail->fields["delivery_date"])) { $fields["delivery_date"] = $detail->fields["delivery_date"]; } // Get bill data if ($config->canAddBillDetails()) { $bill = new PluginOrderBill(); if ($bill->getFromDB($detail->fields["plugin_order_bills_id"])) { $fields['bill'] = $bill->fields['number']; $fields['warranty_date'] = $bill->fields['billdate']; } } foreach (array('warranty_date', 'buy_date', 'inventory_date') as $date) { if (!isset($fields[$date])) { $fields[$date] = 'NULL'; } } $fields['_no_warning'] = true; if ($infocomID) { $fields['id'] = $infocomID; $ic->update($fields); } else { $ic->add($fields); } } }
$contactsupplier = new Contact_Supplier(); foreach ($_POST["item"] as $key => $val) { $input = array('suppliers_id' => $_POST['entID'], 'contacts_id' => $key); if ($contactsupplier->can(-1, 'w', $input)) { $contactsupplier->add($input); } } } break; case "activate_infocoms": $ic = new Infocom(); if ($ic->canCreate()) { foreach ($_POST["item"] as $key => $val) { $input = array('itemtype' => $_POST['itemtype'], 'items_id' => $key); if (!$ic->getFromDBforDevice($_POST['itemtype'], $key)) { $ic->add($input); } } } break; case "change_authtype": foreach ($_POST["item"] as $key => $val) { if ($val == 1) { $ids[] = $key; } } User::changeAuthMethod($ids, $_POST["authtype"], $_POST["auths_id"]); break; case "unlock_ocsng_field": $fields = OcsServer::getLockableFields(); if ($_POST['field'] == 'all' || isset($fields[$_POST['field']])) {
/** * Add an item in the database with all it's items. * * @param $input array : the _POST vars returned by the item form when press add * @param options an array with the insert options * - unicity_message : do not display message if item it a duplicate (default is yes) * @param $history boolean : do history log ? * * @return integer the new ID of the added item (or false if fail) **/ function add($input, $options = array(), $history = true) { global $DB, $CFG_GLPI; if ($DB->isSlave()) { return false; } // Store input in the object to be available in all sub-method / hook $this->input = $input; // Call the plugin hook - $this->input can be altered doHook("pre_item_add", $this); if ($this->input && is_array($this->input)) { if (isset($this->input['add'])) { $this->input['_add'] = $this->input['add']; unset($this->input['add']); } $this->input = $this->prepareInputForAdd($this->input); //Check values to inject $this->filterValues(); } if ($this->input && is_array($this->input)) { $this->fields = array(); $table_fields = $DB->list_fields($this->getTable()); // fill array for add foreach ($this->input as $key => $val) { if ($key[0] != '_' && isset($table_fields[$key])) { $this->fields[$key] = $this->input[$key]; } } // Auto set date_mod if exsist if (isset($table_fields['date_mod'])) { $this->fields['date_mod'] = $_SESSION["glpi_currenttime"]; } if ($this->checkUnicity(true, $options)) { if ($this->addToDB()) { $this->addMessageOnAddAction(); $this->post_addItem(); if ($this->dohistory && $history) { $changes[0] = 0; $changes[1] = $changes[2] = ""; Log::history($this->fields["id"], $this->getType(), $changes, 0, HISTORY_CREATE_ITEM); } // Auto create infocoms if ($CFG_GLPI["auto_create_infocoms"] && in_array($this->getType(), $CFG_GLPI["infocom_types"])) { $ic = new Infocom(); if (!$ic->getFromDBforDevice($this->getType(), $this->fields['id'])) { $ic->add(array('itemtype' => $this->getType(), 'items_id' => $this->fields['id'])); } } // If itemtype is in infocomtype and if states_id field is filled // and item is not a template if (in_array($this->getType(), $CFG_GLPI["infocom_types"]) && isset($this->input['states_id']) && (!isset($this->input['is_template']) || !$this->input['is_template'])) { //Check if we have to automaticall fill dates Infocom::manageDateOnStatusChange($this); } doHook("item_add", $this); return $this->fields['id']; } } } $this->last_status = self::NOTHING_TO_DO; return false; }
/** * Add an item in the database with all it's items. * * @param $input array the _POST vars returned by the item form when press add * @param options array with the insert options * - unicity_message : do not display message if item it a duplicate (default is yes) * @param $history boolean do history log ? (true by default) * * @return integer the new ID of the added item (or false if fail) **/ function add(array $input, $options = array(), $history = true) { global $DB, $CFG_GLPI; if ($DB->isSlave()) { return false; } // Store input in the object to be available in all sub-method / hook $this->input = $input; if (isset($this->input['add'])) { // Input from the interface // Save this data to be available if add fail $this->saveInput(); } // Call the plugin hook - $this->input can be altered // This hook get the data from the form, not yet altered Plugin::doHook("pre_item_add", $this); if ($this->input && is_array($this->input)) { if (isset($this->input['add'])) { $this->input['_add'] = $this->input['add']; unset($this->input['add']); } $this->input = $this->prepareInputForAdd($this->input); } if ($this->input && is_array($this->input)) { // Call the plugin hook - $this->input can be altered // This hook get the data altered by the object method Plugin::doHook("post_prepareadd", $this); } if ($this->input && is_array($this->input)) { //Check values to inject $this->filterValues(!isCommandLine()); } if ($this->input && is_array($this->input)) { $this->fields = array(); $table_fields = $DB->list_fields($this->getTable()); // fill array for add foreach ($this->input as $key => $val) { if ($key[0] != '_' && isset($table_fields[$key])) { $this->fields[$key] = $this->input[$key]; } } // Auto set date_mod if exsist if (isset($table_fields['date_mod'])) { $this->fields['date_mod'] = $_SESSION["glpi_currenttime"]; } if ($this->checkUnicity(true, $options)) { if ($this->addToDB()) { $this->post_addItem(); $this->addMessageOnAddAction(); if ($this->dohistory && $history) { $changes[0] = 0; $changes[1] = $changes[2] = ""; Log::history($this->fields["id"], $this->getType(), $changes, 0, Log::HISTORY_CREATE_ITEM); } // Auto create infocoms if (isset($CFG_GLPI["auto_create_infocoms"]) && $CFG_GLPI["auto_create_infocoms"] && Infocom::canApplyOn($this)) { $ic = new Infocom(); if (!$ic->getFromDBforDevice($this->getType(), $this->fields['id'])) { $ic->add(array('itemtype' => $this->getType(), 'items_id' => $this->fields['id'])); } } // If itemtype is in infocomtype and if states_id field is filled // and item is not a template if (InfoCom::canApplyOn($this) && isset($this->input['states_id']) && (!isset($this->input['is_template']) || !$this->input['is_template'])) { //Check if we have to automatical fill dates Infocom::manageDateOnStatusChange($this); } Plugin::doHook("item_add", $this); // As add have suceed, clean the old input value if (isset($this->input['_add'])) { $this->clearSavedInput(); } if ($this->mailqueueonaction) { QueuedMail::forceSendFor($this->getType(), $this->fields['id']); } return $this->fields['id']; } } } $this->last_status = self::NOTHING_TO_DO; return false; }
/** * Do the standard massive actions * * @since version 0.84 * * This must not be overloaded in Class * @param $input array of input datas * * @return an array of results (ok, ko, noright counts, may include REDIRECT field to set REDIRECT page) **/ function doMassiveActions($input = array()) { global $CFG_GLPI; if (!isset($input["item"]) || count($input["item"]) == 0) { return false; } $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); switch ($input['action']) { case 'add_document': case 'remove_document': $doc = new Document(); return $doc->doSpecificMassiveActions($input); case "add_transfer_list": if (!isset($_SESSION['glpitransfer_list'])) { $_SESSION['glpitransfer_list'] = array(); } if (!isset($_SESSION['glpitransfer_list'][$input["itemtype"]])) { $_SESSION['glpitransfer_list'][$input["itemtype"]] = array(); } foreach ($input["item"] as $key => $val) { if ($val == 1) { $_SESSION['glpitransfer_list'][$input["itemtype"]][$key] = $key; $res['ok']++; } } $res['REDIRECT'] = $CFG_GLPI['root_doc'] . '/front/transfer.action.php'; break; case "delete": foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($this->can($key, 'd')) { if ($this->delete(array("id" => $key))) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } } break; case "purge": foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($this->can($key, 'd')) { $force = 1; // Only mark deletion for if ($this->maybeDeleted() && $this->useDeletedToLockIfDynamic() && $this->isDynamic()) { $force = 0; } if ($this->delete(array("id" => $key), $force)) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } } break; case "restore": foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($this->can($key, 'd')) { if ($this->restore(array("id" => $key))) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } } break; case "update": $searchopt = Search::getCleanedOptions($input["itemtype"], 'w'); if (isset($searchopt[$input["id_field"]])) { /// Infocoms case if (!isPluginItemType($input["itemtype"]) && Search::isInfocomOption($input["itemtype"], $input["id_field"])) { $ic = new Infocom(); $link_entity_type = -1; /// Specific entity item if ($searchopt[$input["id_field"]]["table"] == "glpi_suppliers") { $ent = new Supplier(); if ($ent->getFromDB($input[$input["field"]])) { $link_entity_type = $ent->fields["entities_id"]; } } foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($this->getFromDB($key)) { if ($link_entity_type < 0 || $link_entity_type == $this->getEntityID() || $ent->fields["is_recursive"] && in_array($link_entity_type, getAncestorsOf("glpi_entities", $this->getEntityID()))) { $input2["items_id"] = $key; $input2["itemtype"] = $input["itemtype"]; if ($ic->can(-1, 'w', $input2)) { // Add infocom if not exists if (!$ic->getFromDBforDevice($input["itemtype"], $key)) { $input2["items_id"] = $key; $input2["itemtype"] = $input["itemtype"]; unset($ic->fields); $ic->add($input2); $ic->getFromDBforDevice($input["itemtype"], $key); } $id = $ic->fields["id"]; unset($ic->fields); if ($ic->update(array('id' => $id, $input["field"] => $input[$input["field"]]))) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } else { $res['ko']++; } } else { $res['ko']++; } } } } else { /// Not infocoms $link_entity_type = array(); /// Specific entity item $itemtable = getTableForItemType($input["itemtype"]); $itemtype2 = getItemTypeForTable($searchopt[$input["id_field"]]["table"]); if ($item2 = getItemForItemtype($itemtype2)) { if ($input["id_field"] != 80 && $searchopt[$input["id_field"]]["table"] != $itemtable && $item2->isEntityAssign() && $this->isEntityAssign()) { if ($item2->getFromDB($input[$input["field"]])) { if (isset($item2->fields["entities_id"]) && $item2->fields["entities_id"] >= 0) { if (isset($item2->fields["is_recursive"]) && $item2->fields["is_recursive"]) { $link_entity_type = getSonsOf("glpi_entities", $item2->fields["entities_id"]); } else { $link_entity_type[] = $item2->fields["entities_id"]; } } } } } foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($this->can($key, 'w') && $this->canMassiveAction($input['action'], $input['field'], $input[$input["field"]])) { if (count($link_entity_type) == 0 || in_array($this->fields["entities_id"], $link_entity_type)) { if ($this->update(array('id' => $key, $input["field"] => $input[$input["field"]]))) { $res['ok']++; } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['noright']++; } } } } } break; case "activate_infocoms": $ic = new Infocom(); if ($ic->canCreate()) { foreach ($input["item"] as $key => $val) { $input = array('itemtype' => $input['itemtype'], 'items_id' => $key); if (!$ic->getFromDBforDevice($input['itemtype'], $key)) { if ($ic->can(-1, 'w', $input)) { if ($ic->add($input)) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } else { $res['ko']++; } } } break; case "add_contract_item": $contractitem = new Contract_Item(); foreach ($input["item"] as $key => $val) { if (isset($input['items_id'])) { // Add items to contracts $input = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'contracts_id' => $key); } if (isset($input['contracts_id'])) { // Add contract to item $input = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'contracts_id' => $input['contracts_id']); } else { return false; } if ($contractitem->can(-1, 'w', $input)) { if ($contractitem->add($input)) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } break; case "remove_contract_item": foreach ($input["item"] as $key => $val) { if (isset($input['items_id'])) { // Remove item to contracts $input = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'contracts_id' => $key); } else { // Remove contract to items $input = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'contracts_id' => $input['contracts_id']); } $contractitem = new Contract_Item(); if ($contractitem->can(-1, 'w', $input)) { if ($item = getItemForItemtype($input["itemtype"])) { if ($item->getFromDB($input['items_id'])) { $contract = new Contract(); if ($contract->getFromDB($input['contracts_id'])) { if ($contractitem->getFromDBForItems($contract, $item)) { if ($contractitem->delete(array('id' => $contractitem->getID()))) { $res['ok']++; } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['noright']++; } } break; //Lock management //Lock management case 'unlock_Printer': case 'unlock_Monitor': case 'unlock_NetworkPort': case 'unlock_NetworkName': case 'unlock_IPAddress': case 'unlock_ComputerDisk': case 'unlock_ComputerVirtualMachine': case 'unlock_Peripheral': case 'unlock_SoftwareVersion': $itemtype = Lock::getItemTypeForMassiveAction($input["action"]); if ($itemtype) { $res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]); } break; case 'unlock_Device': foreach (Item_Devices::getDeviceTypes() as $itemtype) { $res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]); } break; default: // Plugin specific actions $split = explode('_', $input["action"]); $res = ''; if ($split[0] == 'plugin' && isset($split[1])) { // Normalized name plugin_name_action // Allow hook from any plugin on any (core or plugin) type $res = Plugin::doOneHook($split[1], 'MassiveActionsProcess', $input); // } else if ($plug=isPluginItemType($input["itemtype"])) { // non-normalized name // hook from the plugin defining the type // $res = Plugin::doOneHook($plug['plugin'], 'MassiveActionsProcess', $input); } else { $res = $this->doSpecificMassiveActions($input); } break; } return $res; }
You should have received a copy of the GNU General Public License along with GLPI; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -------------------------------------------------------------------------- */ // ---------------------------------------------------------------------- // Original Author of file: Julien Dombre // Purpose of file: // ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; $ic = new Infocom(); if (isset($_GET["add"])) { $ic->check(-1, 'w', $_GET); $newID = $ic->add($_GET, false); Event::log($newID, "infocom", 4, "financial", $_SESSION["glpiname"] . " " . $LANG['log'][20]); glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["delete"])) { $ic->check($_POST["id"], 'w'); $ic->delete($_POST); Event::log($_POST["id"], "infocom", 4, "financial", $_SESSION["glpiname"] . " " . $LANG['log'][22]); glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["update"])) { $ic->check($_POST["id"], 'w'); $ic->update($_POST); Event::log($_POST["id"], "infocom", 4, "financial", $_SESSION["glpiname"] . " " . $LANG['log'][21]); glpi_header($_SERVER['HTTP_REFERER']); } else {