/**
  * @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;
 }
Exemplo n.º 2
0
                    if ($val == 1) {
                        $tmp = $_POST;
                        $tmp['id'] = $key;
                        $order_item->update($tmp);
                        // Update infocom
                        $ic = new Infocom();
                        $ic->getFromDBforDevice($order_item->fields['itemtype'], $order_item->fields['items_id']);
                        $config = PluginOrderConfig::getConfig();
                        if ($config->canAddBillDetails()) {
                            if ($bill->getFromDB($_POST["plugin_order_bills_id"])) {
                                $fields['id'] = $ic->fields['id'];
                                $fields['bill'] = $bill->fields['number'];
                                $fields['warranty_date'] = $bill->fields['billdate'];
                            }
                        }
                        $ic->update($fields);
                    }
                }
            }
            break;
    }
    PluginOrderOrder::updateBillState($order_item->fields['plugin_order_orders_id']);
    Html::back();
}
$dropdown = new PluginOrderBill();
Session::checkRight("plugin_order_bill", READ);
Html::header(PluginOrderBill::getTypeName(1), $_SERVER['PHP_SELF'], "management", "PluginOrderMenu", "bill");
if (isset($_REQUEST['id'])) {
    $bill->display($_REQUEST);
} else {
    $bill->show();
Exemplo n.º 3
0
 /**
  * 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;
         }
     }
 }
Exemplo n.º 4
0
 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>";
 }
Exemplo n.º 5
0
$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 {
            Session::checkRight("infocom", READ);
            Html::popHeader(Infocom::getTypeName(), $_SERVER['PHP_SELF']);
            if (isset($_GET["id"])) {
                $ic->getFromDB($_GET["id"]);
                $_GET["itemtype"] = $ic->fields["itemtype"];
                $_GET["items_id"] = $ic->fields["items_id"];
            }
            $item = false;
            if (isset($_GET["itemtype"]) && ($item = getItemForItemtype($_GET["itemtype"]))) {
                if (!isset($_GET["items_id"]) || !$item->getFromDB($_GET["items_id"])) {
                    $item = false;
                }
Exemplo n.º 6
0
 public function post_updateItem($history = 1)
 {
     global $DB;
     $config = PluginOrderConfig::getConfig();
     if ($config->fields['transmit_budget_change'] && in_array('budgets_id', $this->updates)) {
         $infocom = new Infocom();
         $query = "SELECT `items_id`, `itemtype`\n                   FROM `glpi_plugin_order_orders_items`\n                   WHERE `plugin_order_orders_id`='" . $this->getID() . "'";
         foreach ($DB->request($query) as $infos) {
             $infocom->getFromDBforDevice($infos['itemtype'], $infos['items_id']);
             $infocom->update(array('id' => $infocom->getID(), 'budgets_id' => $this->fields['budgets_id']));
         }
     }
 }
Exemplo n.º 7
0
 /**
  * @param $type
  * @param $model_id
  * @param $tab_ids
  * @param $location
  **/
 static function replace($type, $model_id, $tab_ids, $location)
 {
     global $DB, $CFG_GLPI, $PLUGIN_HOOKS;
     $model = new PluginUninstallModel();
     $model->getConfig($model_id);
     $overwrite = $model->fields["overwrite"];
     echo "<div class='center'>";
     echo "<table class='tab_cadre_fixe'><tr><th>" . __('Replacement', 'uninstall') . "</th></tr>";
     echo "<tr class='tab_bg_2'><td>";
     $count = 0;
     $tot = count($tab_ids);
     Html::createProgressBar(__('Please wait, replacement is running...', 'uninstall'));
     foreach ($tab_ids as $olditem_id => $newitem_id) {
         $count++;
         $olditem = new $type();
         $olditem->getFromDB($olditem_id);
         $newitem = new $type();
         $newitem->getFromDB($newitem_id);
         //Hook to perform actions before item is being replaced
         $olditem->fields['_newid'] = $newitem_id;
         $olditem->fields['_uninstall_event'] = $model_id;
         $olditem->fields['_action'] = 'replace';
         Plugin::doHook("plugin_uninstall_replace_before", $olditem);
         // Retrieve informations
         //States
         if ($model->fields['states_id'] != 0) {
             $olditem->update(array('id' => $olditem_id, 'states_id' => $model->fields['states_id']), false);
         }
         // METHOD REPLACEMENT 1 : Archive
         if ($model->fields['replace_method'] == self::METHOD_PURGE) {
             $name_out = str_shuffle(Toolbox::getRandomString(5) . time());
             $plugin = new Plugin();
             if ($plugin->isActivated('PDF')) {
                 // USE PDF EXPORT
                 $plugin->load('pdf', true);
                 include_once GLPI_ROOT . "/lib/ezpdf/class.ezpdf.php";
                 //Get all item's tabs
                 $tab = array_keys($olditem->defineTabs());
                 //Tell PDF to also export item's main tab, and in first position
                 array_unshift($tab, "_main_");
                 $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($olditem);
                 $out = $itempdf->generatePDF(array($olditem_id), $tab, 1, false);
                 $name_out .= ".pdf";
             } else {
                 //TODO Which datas ? Add Defaults...
                 $out = __('Replacement', 'uninstall') . "\r\n";
                 $datas = $olditem->fields;
                 unset($datas['comment']);
                 foreach ($datas as $k => $v) {
                     $out .= $k . ";";
                 }
                 $out .= "\r\n";
                 foreach ($datas as $k => $v) {
                     $out .= $v . ";";
                 }
                 // USE CSV EXPORT
                 $name_out .= ".csv";
             }
             // Write document
             $out_file = GLPI_DOC_DIR . "/_uploads/" . $name_out;
             $open_file = fopen($out_file, 'a');
             fwrite($open_file, $out);
             fclose($open_file);
             // Compute comment text
             $comment = __('This document is the archive of this replaced item', 'uninstall') . " " . self::getCommentsForReplacement($olditem, false, false);
             // Create & Attach new document to current item
             $doc = new Document();
             $input = array('name' => addslashes(__('Archive of old material', 'uninstall')), 'upload_file' => $name_out, 'comment' => addslashes($comment), 'add' => __('Add'), 'entities_id' => $newitem->getEntityID(), 'is_recursive' => $newitem->isRecursive(), 'link' => "", 'documentcategories_id' => 0, 'items_id' => $olditem_id, 'itemtype' => $type);
             //Attached the document to the old item, to generate an accurate name
             $document_added = $doc->add($input);
             //Attach the document to the new item, once the document's name is correct
             $docItem = new Document_Item();
             $docItemId = $docItem->add(array('documents_id' => $document_added, 'itemtype' => $type, 'items_id' => (int) $newitem_id));
         }
         // General Informations - NAME
         if ($model->fields["replace_name"]) {
             if ($overwrite || empty($newitem->fields['name'])) {
                 $newitem->update(array('id' => $newitem_id, 'name' => $olditem->getField('name')), false);
             }
         }
         $data['id'] = $newitem->getID();
         // General Informations - SERIAL
         if ($model->fields["replace_serial"]) {
             if ($overwrite || empty($newitem->fields['serial'])) {
                 $newitem->update(array('id' => $newitem_id, 'serial' => $olditem->getField('serial')), false);
             }
         }
         // General Informations - OTHERSERIAL
         if ($model->fields["replace_otherserial"]) {
             if ($overwrite || empty($newitem->fields['otherserial'])) {
                 $newitem->update(array('id' => $newitem_id, 'otherserial' => $olditem->getField('otherserial')), false);
             }
         }
         // Documents
         if ($model->fields["replace_documents"] && in_array($type, $CFG_GLPI["document_types"])) {
             $doc_item = new Document_Item();
             foreach (self::getAssociatedDocuments($olditem) as $document) {
                 $doc_item->update(array('id' => $document['assocID'], 'itemtype' => $type, 'items_id' => $newitem_id), false);
             }
         }
         // Contracts
         if ($model->fields["replace_contracts"] && in_array($type, $CFG_GLPI["contract_types"])) {
             $contract_item = new Contract_Item();
             foreach (self::getAssociatedContracts($olditem) as $contract) {
                 $contract_item->update(array('id' => $contract['id'], 'itemtype' => $type, 'items_id' => $newitem_id), false);
             }
         }
         // Infocoms
         if ($model->fields["replace_infocoms"] && in_array($type, $CFG_GLPI["infocom_types"])) {
             $infocom = new Infocom();
             if ($overwrite) {
                 // Delete current Infocoms of new item
                 if ($infocom->getFromDBforDevice($type, $newitem_id)) {
                     //Do not log infocom deletion in the new item's history
                     $infocom->dohistory = false;
                     $infocom->deleteFromDB(1);
                 }
             }
             // Update current Infocoms of old item
             if ($infocom->getFromDBforDevice($type, $olditem_id)) {
                 $infocom->update(array('id' => $infocom->getID(), 'itemtype' => $type, 'items_id' => $newitem_id), false);
             }
         }
         // Reservations
         if ($model->fields["replace_reservations"] && in_array($type, $CFG_GLPI["reservation_types"])) {
             $resaitem = new ReservationItem();
             if ($overwrite) {
                 // Delete current reservation of new item
                 $resa_new = new Reservation();
                 $resa_new->getFromDB($newitem_id);
                 if ($resa_new->is_reserved()) {
                     $resa_new = new ReservationItem();
                     $resa_new->getFromDBbyItem($type, $newitem_id);
                     if (count($resa_new->fields)) {
                         $resa_new->deleteFromDB(1);
                     }
                 }
             }
             // Update old reservation for attribute to new item
             $resa_old = new Reservation();
             $resa_old->getFromDB($olditem_id);
             if ($resa_old->is_reserved()) {
                 $resa_old = new ReservationItem();
                 $resa_old->getFromDBbyItem($type, $olditem_id);
                 if (count($resa_old->fields)) {
                     $resa_old->update(array('id' => $resa_old->getID(), 'itemtype' => $type, 'items_id' => $newitem_id), false);
                 }
             }
         }
         // User
         if ($model->fields["replace_users"] && in_array($type, $CFG_GLPI["linkuser_types"])) {
             $data = array();
             $data['id'] = $newitem->getID();
             if ($newitem->isField('users_id') && ($overwrite || empty($data['users_id']))) {
                 $data['users_id'] = $olditem->getField('users_id');
             }
             if ($newitem->isField('contact') && ($overwrite || empty($data['contact']))) {
                 $data['contact'] = $olditem->getField('contact');
             }
             if ($newitem->isField('contact_num') && ($overwrite || empty($data['contact_num']))) {
                 $data['contact_num'] = $olditem->getField('contact_num');
             }
             $newitem->update($data, false);
         }
         // Group
         if ($model->fields["replace_groups"] && in_array($type, $CFG_GLPI["linkgroup_types"])) {
             if ($newitem->isField('groups_id') && ($overwrite || empty($data['groups_id']))) {
                 $newitem->update(array('id' => $newitem_id, 'groups_id' => $olditem->getField('groups_id')), false);
             }
         }
         // Tickets
         if ($model->fields["replace_tickets"] && in_array($type, $CFG_GLPI["ticket_types"])) {
             $ticket_item = new Item_Ticket();
             foreach (self::getAssociatedTickets($type, $olditem_id) as $ticket) {
                 $ticket_item->update(array('id' => $ticket['id'], 'items_id' => $newitem_id), false);
             }
         }
         //Array netport_types renamed in networkport_types in GLPI 0.80
         if (isset($CFG_GLPI["netport_types"])) {
             $netport_types = $CFG_GLPI["netport_types"];
         } else {
             $netport_types = $CFG_GLPI["networkport_types"];
         }
         // NetPorts
         if ($model->fields["replace_netports"] && in_array($type, $netport_types)) {
             $netport_item = new NetworkPort();
             foreach (self::getAssociatedNetports($type, $olditem_id) as $netport) {
                 $netport_item->update(array('id' => $netport['id'], 'itemtype' => $type, 'items_id' => $newitem_id), false);
             }
         }
         // Directs connections
         if ($model->fields["replace_direct_connections"] && in_array($type, array('Computer'))) {
             $comp_item = new Computer_Item();
             foreach (self::getAssociatedItems($olditem) as $itemtype => $connections) {
                 foreach ($connections as $connection) {
                     $comp_item->update(array('id' => $connection['id'], 'computers_id' => $newitem_id, 'itemtype' => $itemtype), false);
                 }
             }
         }
         // Location
         if ($location != 0 && $olditem->isField('locations_id')) {
             $olditem->getFromDB($olditem_id);
             switch ($location) {
                 case -1:
                     break;
                 default:
                     $olditem->update(array('id' => $olditem_id, 'locations_id' => $location), false);
                     break;
             }
         }
         $plug = new Plugin();
         if ($plug->isActivated('ocsinventoryng')) {
             //Delete computer from OCS
             if ($model->fields["remove_from_ocs"] == 1) {
                 PluginUninstallUninstall::deleteComputerInOCSByGlpiID($olditem_id);
             }
             //Delete link in glpi_ocs_link
             if ($model->fields["delete_ocs_link"] || $model->fields["remove_from_ocs"]) {
                 PluginUninstallUninstall::deleteOcsLink($olditem_id);
             }
         }
         if ($plug->isActivated('fusioninventory')) {
             if ($model->fields['raz_fusioninventory']) {
                 PluginUninstallUninstall::deleteFusionInventoryLink(get_class($olditem), $olditem_id);
             }
         }
         // METHOD REPLACEMENT 1 : Purge
         if ($model->fields['replace_method'] == self::METHOD_PURGE) {
             // Retrieve, Compute && Update NEW comment field
             $comment = self::getCommentsForReplacement($olditem, true);
             $comment .= "\n- " . __('See attached document', 'uninstall');
             $newitem->update(array('id' => $newitem_id, 'comment' => addslashes($comment)), false);
             // If old item is attached in PDF/CSV
             // Delete AND Purge it in DB
             if ($document_added) {
                 $olditem->delete(array('id' => $olditem_id), true);
             }
         }
         // METHOD REPLACEMENT 2 : Delete AND Comment
         if ($model->fields['replace_method'] == self::METHOD_DELETE_AND_COMMENT) {
             //Add comment on the new item first
             $comment = self::getCommentsForReplacement($olditem, true);
             $newitem->update(array('id' => $newitem_id, 'comment' => Toolbox::addslashes_deep($comment)), false);
             // Retrieve, Compute && Update OLD comment field
             $comment = self::getCommentsForReplacement($newitem, false);
             $olditem->update(array('id' => $olditem_id, 'comment' => Toolbox::addslashes_deep($comment)), false);
             // Delete OLD item from DB (not PURGE)
             PluginUninstallUninstall::addUninstallLog($type, $olditem_id, 'replaced_by');
             $olditem->delete(array('id' => $olditem_id), 0, false);
         }
         //Plugin hook after replacement
         Plugin::doHook("plugin_uninstall_replace_after", $olditem);
         //Add history
         PluginUninstallUninstall::addUninstallLog($type, $newitem_id, 'replace');
         Html::changeProgressBarPosition($count, $tot + 1);
     }
     Html::changeProgressBarPosition($count, $tot, __('Replacement successful', 'uninstall'));
     echo "</td></tr>";
     echo "</table></div>";
 }
Exemplo n.º 8
0
 /**
  * @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;
     }
 }
Exemplo n.º 9
0
 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);
         }
     }
 }
Exemplo n.º 10
0
     }
     foreach ($_POST["item"] as $key => $val) {
         if ($val == 1) {
             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()))) {
                     // Add infocom if not exists
                     if (!$ic->getFromDBforDevice($_POST["itemtype"], $key)) {
                         $input2["items_id"] = $key;
                         $input2["itemtype"] = $_POST["itemtype"];
                         unset($ic->fields);
                         $ic->add($input2);
                         $ic->getFromDBforDevice($_POST["itemtype"], $key);
                     }
                     $id = $ic->fields["id"];
                     unset($ic->fields);
                     $ic->update(array('id' => $id, $_POST["field"] => $_POST[$_POST["field"]]));
                 }
             }
         }
     }
 } else {
     /// Not infocoms
     $link_entity_type = array();
     /// Specific entity item
     $itemtable = getTableForItemType($_POST["itemtype"]);
     $itemtype2 = getItemTypeForTable($searchopt[$_POST["id_field"]]["table"]);
     if (class_exists($itemtype2)) {
         $item2 = new $itemtype2();
         if ($searchopt[$_POST["id_field"]]["table"] != $itemtable && $item2->isEntityAssign() && $item->isEntityAssign()) {
             if ($item2->getFromDB($_POST[$_POST["field"]])) {
                 if (isset($item2->fields["entities_id"]) && $item2->fields["entities_id"] >= 0) {
Exemplo n.º 11
0
 /**
  * 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;
 }