getFromDBforDevice() public method

Retrieve an item from the database for a device
public getFromDBforDevice ( $itemtype, $ID ) : true
$itemtype type of the device to retrieve infocom
$ID ID of the device to retrieve infocom
return true if succeed else false
コード例 #1
0
ファイル: infocom.class.php プロジェクト: geldarr/hack-space
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     global $CFG_GLPI;
     $ID = $item->getField('id');
     if (!Session::haveRight("infocom", "r")) {
         return false;
     }
     $ic = new Infocom();
     $pdf->setColumnsSize(100);
     if ($ic->getFromDBforDevice(get_class($item), $ID)) {
         $pdf->displayTitle("<b>" . __('Financial and administrative information') . "</b>");
         $pdf->setColumnsSize(50, 50);
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Supplier') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Budget') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_budgets", $ic->fields["budgets_id"]))));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Order number') . "</i></b>", $ic->fields["order_number"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Order date') . "</i></b>", Html::convDate($ic->fields["order_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Immobilization number') . "</i></b>", $ic->fields["immo_number"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Date of purchase') . "</i></b>", Html::convDate($ic->fields["buy_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Invoice number') . "</i></b>", $ic->fields["bill"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Delivery date') . "</i></b>", Html::convDate($ic->fields["delivery_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Delivery form') . "</i></b>", $ic->fields["delivery_number"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Startup date') . "</i></b>", Html::convDate($ic->fields["use_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Value') . "</i></b>", Html::clean(Html::formatNumber($ic->fields["value"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), _('Date of last physical inventory') . "</i></b>", Html::convDate($ic->fields["inventory_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Warranty extension value') . "</i></b>", Html::clean(Html::formatNumber($ic->fields["warranty_value"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Amortization duration') . "</i></b>", sprintf(__('%1$s (%2$s)'), sprintf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]), Infocom::getAmortTypeName($ic->fields["sink_type"]))));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Account net value') . "</i></b>", Infocom::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $CFG_GLPI['date_tax'], "n")), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Amortization coefficient') . "</i></b>", $ic->fields["sink_coeff"]));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('TCO (value + tracking cost)') . "</i></b>", Html::clean(Infocom::showTco($item->getField('ticket_tco'), $ic->fields["value"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Monthly TCO') . "</i></b>", Html::clean(Infocom::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]))));
         PluginPdfCommon::mainLine($pdf, $ic, 'comment');
         $pdf->setColumnsSize(100);
         $pdf->displayTitle("<b>" . __('Warranty information') . "</b>");
         $pdf->setColumnsSize(50, 50);
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Start date of warranty') . "</i></b>", Html::convDate($ic->fields["warranty_date"])), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Warranty duration') . "</i></b>", sprintf(__('%1$s - %2$s'), sprintf(_n('%d month', '%d months', $ic->fields["warranty_duration"]), $ic->fields["warranty_duration"]), sprintf(__('Valid to %s'), Infocom::getWarrantyExpir($ic->fields["buy_date"], $ic->fields["warranty_duration"])))));
         $col1 = "<b><i>" . __('Alarms on financial and administrative information') . "</i></b>";
         if ($ic->fields["alert"] == 0) {
             $col1 = sprintf(__('%1$s: %2$s'), $col1, __('No'));
         } else {
             if ($ic->fields["alert"] == 4) {
                 $col1 = sprintf(__('%1$s: %2$s'), $col1, __('Warranty expiration date'));
             }
         }
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Warranty information') . "</i></b>", $ic->fields["warranty_info"]), $col1);
     } else {
         $pdf->displayTitle("<b>" . __('No financial information', 'pdf') . "</b>");
     }
     $pdf->displaySpace();
 }
コード例 #2
0
ファイル: bill.form.php プロジェクト: equinoxefr/order
}
if (isset($_POST['action'])) {
    // Retrieve configuration for generate assets feature
    $order_item = new PluginOrderOrder_Item();
    switch ($_POST['chooseAction']) {
        case 'bill':
        case 'state':
            if (isset($_POST["item"])) {
                foreach ($_POST["item"] as $key => $val) {
                    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']);
コード例 #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;
         }
     }
 }
コード例 #4
0
ファイル: commonglpi.class.php プロジェクト: korial29/glpi
 /**
  * to list infos in debug tab
  **/
 function showDebugInfo()
 {
     global $CFG_GLPI;
     $class = $this->getType();
     if (method_exists($class, 'showDebug')) {
         $this->showDebug();
     }
     if (InfoCom::canApplyOn($class)) {
         $infocom = new Infocom();
         if ($infocom->getFromDBforDevice($class, $this->fields['id'])) {
             $infocom->showDebug();
         }
     }
     if (in_array($class, $CFG_GLPI["reservation_types"])) {
         $resitem = new ReservationItem();
         if ($resitem->getFromDBbyItem($class, $this->fields['id'])) {
             $resitem->showDebugResa();
         }
     }
 }
コード例 #5
0
ファイル: order.class.php プロジェクト: pluginsGLPI/order
 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']));
         }
     }
 }
コード例 #6
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>";
 }
コード例 #7
0
ファイル: api.class.php プロジェクト: glpi-project/glpi
 /**
  * Return the instance fields of itemtype identified by id
  *
  * @param $itemtype    string  itemtype (class) of object
  * @param $id          integer identifier of object
  * @param $params      array   with theses options :
  *    - 'expand_dropdowns': Show dropdown's names instead of id. default: false. Optionnal
  *    - 'get_hateoas':      Show relation of current item in a links attribute. default: true. Optionnal
  *    - 'get_sha1':         Get a sha1 signature instead of the full answer. default: false. Optionnal
  *    - 'with_components':  Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal.
  *    - 'with_disks':       Only for Computer, retrieve the associated filesystems. Optionnal.
  *    - 'with_softwares':   Only for Computer, retrieve the associated softwares installations. Optionnal.
  *    - 'with_connections': Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal.
  *    - 'with_networkports':Retrieve all network connections and advanced network informations. Optionnal.
  *    - 'with_infocoms':    Retrieve financial and administrative informations. Optionnal.
  *    - 'with_contracts':   Retrieve associated contracts. Optionnal.
  *    - 'with_documents':   Retrieve associated external documents. Optionnal.
  *    - 'with_tickets':     Retrieve associated itil tickets. Optionnal.
  *    - 'with_problems':    Retrieve associated itil problems. Optionnal.
  *    - 'with_changes':     Retrieve associated itil changes. Optionnal.
  *    - 'with_notes':       Retrieve Notes (if exists, not all itemtypes have notes). Optionnal.
  *    - 'with_logs':        Retrieve historical. Optionnal.
  *
  * @return     array    fields of found object
  **/
 protected function getItem($itemtype, $id, $params = array())
 {
     global $CFG_GLPI, $DB;
     $this->initEndpoint();
     // default params
     $default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'get_sha1' => false, 'with_components' => false, 'with_disks' => false, 'with_softwares' => false, 'with_connections' => false, 'with_networkports' => false, 'with_infocoms' => false, 'with_contracts' => false, 'with_documents' => false, 'with_tickets' => false, 'with_problems' => false, 'with_changes' => false, 'with_notes' => false, 'with_logs' => false);
     $params = array_merge($default, $params);
     $item = new $itemtype();
     if (!$item->getFromDB($id)) {
         return $this->messageNotfoundError();
     }
     if (!$item->can($id, READ)) {
         return $this->messageRightError();
     }
     $fields = $item->fields;
     // avoid disclosure of critical fields
     $item::unsetUndisclosedFields($fields);
     // retrieve devices
     if (isset($params['with_devices']) && $params['with_devices'] && in_array($itemtype, Item_Devices::getConcernedItems())) {
         $all_devices = array();
         foreach (Item_Devices::getItemAffinities($item->getType()) as $device_type) {
             $found_devices = getAllDatasFromTable($device_type::getTable(), "`items_id` = '" . $item->getID() . "'\n                                                   AND `itemtype` = '" . $item->getType() . "'\n                                                   AND `is_deleted` = '0'", true);
             foreach ($found_devices as $devices_id => &$device) {
                 unset($device['items_id']);
                 unset($device['itemtype']);
                 unset($device['is_deleted']);
             }
             if (!empty($found_devices)) {
                 $all_devices[$device_type] = $found_devices;
             }
         }
         $fields['_devices'] = $all_devices;
     }
     // retrieve computer disks
     if (isset($params['with_disks']) && $params['with_disks'] && $itemtype == "Computer") {
         // build query to retrive filesystems
         $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n                          `glpi_computerdisks`.*\n                   FROM `glpi_computerdisks`\n                   LEFT JOIN `glpi_filesystems`\n                             ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n                   WHERE `computers_id` = '{$id}'\n                         AND `is_deleted` = '0'";
         $fields['_disks'] = array();
         if ($result = $DB->query($query)) {
             while ($data = $DB->fetch_assoc($result)) {
                 unset($data['computers_id']);
                 unset($data['is_deleted']);
                 $fields['_disks'][] = array('name' => $data);
             }
         }
     }
     // retrieve computer softwares
     if (isset($params['with_softwares']) && $params['with_softwares'] && $itemtype == "Computer") {
         $fields['_softwares'] = array();
         if (!Software::canView()) {
             $fields['_softwares'] = self::arrayRightError();
         } else {
             $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n                             `glpi_softwares`.`id` AS softwares_id,\n                             `glpi_softwareversions`.`id` AS softwareversions_id,\n                             `glpi_computers_softwareversions`.`is_dynamic`,\n                             `glpi_softwareversions`.`states_id`,\n                             `glpi_softwares`.`is_valid`\n                      FROM `glpi_computers_softwareversions`\n                      LEFT JOIN `glpi_softwareversions`\n                           ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                                 = `glpi_softwareversions`.`id`)\n                      LEFT JOIN `glpi_softwares`\n                           ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n                      WHERE `glpi_computers_softwareversions`.`computers_id` = '{$id}'\n                            AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n                      ORDER BY `glpi_softwares`.`name`, `glpi_softwareversions`.`name`";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_softwares'][] = $data;
                 }
             }
         }
     }
     // retrieve item connections
     if (isset($params['with_connections']) && $params['with_connections'] && $itemtype == "Computer") {
         $fields['_connections'] = array();
         foreach ($CFG_GLPI["directconnect_types"] as $connect_type) {
             $connect_item = new $connect_type();
             if ($connect_item->canView()) {
                 $query = "SELECT `glpi_computers_items`.`id` AS assoc_id,\n                         `glpi_computers_items`.`computers_id` AS assoc_computers_id,\n                         `glpi_computers_items`.`itemtype` AS assoc_itemtype,\n                         `glpi_computers_items`.`items_id` AS assoc_items_id,\n                         `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic,\n                         " . getTableForItemType($connect_type) . ".*\n                         FROM `glpi_computers_items`\n                         LEFT JOIN `" . getTableForItemType($connect_type) . "`\n                           ON (`" . getTableForItemType($connect_type) . "`.`id`\n                                 = `glpi_computers_items`.`items_id`)\n                         WHERE `computers_id` = '{$id}'\n                               AND `itemtype` = '" . $connect_type . "'\n                               AND `glpi_computers_items`.`is_deleted` = '0'";
                 if ($result = $DB->query($query)) {
                     while ($data = $DB->fetch_assoc($result)) {
                         $fields['_connections'][$connect_type][] = $data;
                     }
                 }
             }
         }
     }
     // retrieve item networkports
     if (isset($params['with_networkports']) && $params['with_networkports']) {
         $fields['_networkports'] = array();
         if (!NetworkEquipment::canView()) {
             $fields['_networkports'] = self::arrayRightError();
         } else {
             foreach (NetworkPort::getNetworkPortInstantiations() as $networkport_type) {
                 $netport_table = $networkport_type::getTable();
                 $query = "SELECT\n                           netp.`id` as netport_id,\n                           netp.`entities_id`,\n                           netp.`is_recursive`,\n                           netp.`logical_number`,\n                           netp.`name`,\n                           netp.`mac`,\n                           netp.`comment`,\n                           netp.`is_dynamic`,\n                           netp_subtable.*\n                         FROM glpi_networkports AS netp\n                         LEFT JOIN `{$netport_table}` AS netp_subtable\n                           ON netp_subtable.`networkports_id` = netp.`id`\n                         WHERE netp.`instantiation_type` = '{$networkport_type}'\n                           AND netp.`items_id` = '{$id}'\n                           AND netp.`itemtype` = '{$itemtype}'\n                           AND netp.`is_deleted` = '0'";
                 if ($result = $DB->query($query)) {
                     while ($data = $DB->fetch_assoc($result)) {
                         if (isset($data['netport_id'])) {
                             // append network name
                             $query_netn = "SELECT\n                              GROUP_CONCAT(CONCAT(ipadr.`id`, '" . Search::SHORTSEP . "' , ipadr.`name`)\n                                           SEPARATOR '" . Search::LONGSEP . "') as ipadresses,\n                              netn.`id` as networknames_id,\n                              netn.`name` as networkname,\n                              netn.`fqdns_id`,\n                              fqdn.`name` as fqdn_name,\n                              fqdn.`fqdn`\n                           FROM `glpi_networknames` AS netn\n                           LEFT JOIN `glpi_ipaddresses` AS ipadr\n                              ON ipadr.`itemtype` = 'NetworkName' AND ipadr.`items_id` = netn.`id`\n                           LEFT JOIN `glpi_fqdns` AS fqdn\n                              ON fqdn.`id` = netn.`fqdns_id`\n                           LEFT JOIN `glpi_ipaddresses_ipnetworks` ipadnet\n                              ON ipadnet.`ipaddresses_id` = ipadr.`id`\n                           LEFT JOIN `glpi_ipnetworks` `ipnet`\n                              ON ipnet.`id` = ipadnet.`ipnetworks_id`\n                           WHERE netn.`itemtype` = 'NetworkPort'\n                             AND netn.`items_id` = " . $data['netport_id'] . "\n                           GROUP BY netn.`id`, netn.`name`, netn.fqdns_id, fqdn.name, fqdn.fqdn";
                             if ($result_netn = $DB->query($query_netn)) {
                                 $data_netn = $DB->fetch_assoc($result_netn);
                                 $raw_ipadresses = explode(Search::LONGSEP, $data_netn['ipadresses']);
                                 $ipadresses = array();
                                 foreach ($raw_ipadresses as $ipadress) {
                                     $ipadress = explode(Search::SHORTSEP, $ipadress);
                                     //find ip network attached to these ip
                                     $ipnetworks = array();
                                     $query_ipnet = "SELECT\n                                    ipnet.`id`,\n                                    ipnet.`completename`,\n                                    ipnet.`name`,\n                                    ipnet.`address`,\n                                    ipnet.`netmask`,\n                                    ipnet.`gateway`,\n                                    ipnet.`ipnetworks_id`,\n                                    ipnet.`comment`\n                                 FROM `glpi_ipnetworks` ipnet\n                                 INNER JOIN `glpi_ipaddresses_ipnetworks` ipadnet\n                                    ON ipnet.`id` = ipadnet.`ipnetworks_id`\n                                    AND ipadnet.`ipaddresses_id` = " . $ipadress[0];
                                     if ($result_ipnet = $DB->query($query_ipnet)) {
                                         while ($data_ipnet = $DB->fetch_assoc($result_ipnet)) {
                                             $ipnetworks[] = $data_ipnet;
                                         }
                                     }
                                     $ipadresses[] = array('id' => $ipadress[0], 'name' => $ipadress[1], 'IPNetwork' => $ipnetworks);
                                 }
                                 $data['NetworkName'] = array('id' => $data_netn['networknames_id'], 'name' => $data_netn['networkname'], 'fqdns_id' => $data_netn['fqdns_id'], 'FQDN' => array('id' => $data_netn['fqdns_id'], 'name' => $data_netn['fqdn_name'], 'fqdn' => $data_netn['fqdn']), 'IPAddress' => $ipadresses);
                             }
                         }
                         $fields['_networkports'][$networkport_type][] = $data;
                     }
                 }
             }
         }
     }
     // retrieve item infocoms
     if (isset($params['with_infocoms']) && $params['with_infocoms']) {
         $fields['_infocoms'] = array();
         if (!Infocom::canView()) {
             $fields['_infocoms'] = self::arrayRightError();
         } else {
             $ic = new Infocom();
             if ($ic->getFromDBforDevice($itemtype, $id)) {
                 $fields['_infocoms'] = $ic->fields;
             }
         }
     }
     // retrieve item contracts
     if (isset($params['with_contracts']) && $params['with_contracts']) {
         $fields['_contracts'] = array();
         if (!Contract::canView()) {
             $fields['_contracts'] = self::arrayRightError();
         } else {
             $query = "SELECT `glpi_contracts_items`.*\n                     FROM `glpi_contracts_items`,\n                          `glpi_contracts`\n                     LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n                     WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n                           AND `glpi_contracts_items`.`items_id` = '{$id}'\n                           AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n                     ORDER BY `glpi_contracts`.`name`";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_contracts'][] = $data;
                 }
             }
         }
     }
     // retrieve item contracts
     if (isset($params['with_documents']) && $params['with_documents']) {
         $fields['_documents'] = array();
         if (!$itemtype != 'Ticket' && $itemtype != 'KnowbaseItem' && $itemtype != 'Reminder' && !Document::canView()) {
             $fields['_documents'] = self::arrayRightError();
         } else {
             $query = "SELECT `glpi_documents_items`.`id` AS assocID,\n                             `glpi_documents_items`.`date_mod` AS assocdate,\n                             `glpi_entities`.`id` AS entityID,\n                             `glpi_entities`.`completename` AS entity,\n                             `glpi_documentcategories`.`completename` AS headings,\n                             `glpi_documents`.*\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_documents`\n                                ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n                      LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n                      LEFT JOIN `glpi_documentcategories`\n                              ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n                      WHERE `glpi_documents_items`.`items_id` = '{$id}'\n                            AND `glpi_documents_items`.`itemtype` = '{$itemtype}' ";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_documents'][] = $data;
                 }
             }
         }
     }
     // retrieve item tickets
     if (isset($params['with_tickets']) && $params['with_tickets']) {
         $fields['_tickets'] = array();
         if (!Ticket::canView()) {
             $fields['_tickets'] = self::arrayRightError();
         } else {
             $query = "SELECT " . Ticket::getCommonSelect() . "\n                      FROM `glpi_tickets` " . Ticket::getCommonLeftJoin() . "\n                      WHERE `glpi_items_tickets`.`items_id` = '{$id}'\n                             AND `glpi_items_tickets`.`itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                      ORDER BY `glpi_tickets`.`date_mod` DESC";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_tickets'][] = $data;
                 }
             }
         }
     }
     // retrieve item problems
     if (isset($params['with_problems']) && $params['with_problems']) {
         $fields['_problems'] = array();
         if (!Problem::canView()) {
             $fields['_problems'] = self::arrayRightError();
         } else {
             $query = "SELECT " . Problem::getCommonSelect() . "\n                            FROM `glpi_problems`\n                            LEFT JOIN `glpi_items_problems`\n                              ON (`glpi_problems`.`id` = `glpi_items_problems`.`problems_id`) " . Problem::getCommonLeftJoin() . "\n                            WHERE `items_id` = '{$id}'\n                                  AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_problems") . "\n                            ORDER BY `glpi_problems`.`date_mod` DESC";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_problems'][] = $data;
                 }
             }
         }
     }
     // retrieve item changes
     if (isset($params['with_changes']) && $params['with_changes']) {
         $fields['_changes'] = array();
         if (!Change::canView()) {
             $fields['_changes'] = self::arrayRightError();
         } else {
             $query = "SELECT " . Change::getCommonSelect() . "\n                            FROM `glpi_changes`\n                            LEFT JOIN `glpi_changes_items`\n                              ON (`glpi_changes`.`id` = `glpi_changes_items`.`problems_id`) " . Change::getCommonLeftJoin() . "\n                            WHERE `items_id` = '{$id}'\n                                  AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n                            ORDER BY `glpi_changes`.`date_mod` DESC";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_changes'][] = $data;
                 }
             }
         }
     }
     // retrieve item notes
     if (isset($params['with_notes']) && $params['with_notes']) {
         $fields['_notes'] = array();
         if (!Session::haveRight($itemtype::$rightname, READNOTE)) {
             $fields['_notes'] = self::arrayRightError();
         } else {
             $fields['_notes'] = Notepad::getAllForItem($item);
         }
     }
     // retrieve item logs
     if (isset($params['with_logs']) && $params['with_logs']) {
         $fields['_logs'] = array();
         if (!Session::haveRight($itemtype::$rightname, READNOTE)) {
             $fields['_logs'] = self::arrayRightError();
         } else {
             $fields['_logs'] = getAllDatasFromTable("glpi_logs", "`items_id` = '" . $item->getID() . "'\n                                                    AND `itemtype` = '" . $item->getType() . "'");
         }
     }
     // expand dropdown (retrieve name of dropdowns) and get hateoas from foreign keys
     $fields = self::parseDropdowns($fields, $params);
     // get hateoas from children
     if ($params['get_hateoas']) {
         $hclasses = self::getHatoasClasses($itemtype);
         foreach ($hclasses as $hclass) {
             $fields['links'][] = array('rel' => $hclass, 'href' => self::$api_url . "/{$itemtype}/" . $item->getID() . "/{$hclass}/");
         }
     }
     // get sha1 footprint if needed
     if ($params['get_sha1']) {
         $fields = sha1(json_encode($fields, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK));
     }
     return $fields;
 }
コード例 #8
0
ファイル: massiveaction.class.php プロジェクト: kipman/glpi
 /**
  * @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;
     }
 }
コード例 #9
0
ファイル: object.class.php プロジェクト: geldarr/hack-space
 function post_addItem()
 {
     global $DB;
     // Manage add from template
     if (isset($this->input["_oldID"])) {
         // ADD Infocoms
         $ic = new Infocom();
         if ($this->canUseInfocoms() && $ic->getFromDBforDevice($this->type, $this->input["_oldID"])) {
             $ic->fields["items_id"] = $this->fields['id'];
             unset($ic->fields["id"]);
             if (isset($ic->fields["immo_number"])) {
                 $ic->fields["immo_number"] = autoName($ic->fields["immo_number"], "immo_number", 1, 'Infocom', $this->input['entities_id']);
             }
             if (empty($ic->fields['use_date'])) {
                 unset($ic->fields['use_date']);
             }
             if (empty($ic->fields['buy_date'])) {
                 unset($ic->fields['buy_date']);
             }
             $ic->addToDB();
         }
         foreach (array('Document_Item' => 'documents_id', 'Contract_Item' => 'contracts_id') as $type => $fk) {
             $item = new $type();
             foreach ($item->find("items_id='" . $this->input["_oldID"] . "'\n                                 AND itemtype='" . $this->type . "'") as $tmpid => $data) {
                 $tmp = array();
                 $tmp['items_id'] = $this->input["_oldID"];
                 $tmp['itemtype'] = $type;
                 $tmp[$fk] = $data[$fk];
                 $item->add($tmp);
             }
         }
         if ($this->canUseNetworkPorts()) {
             // ADD Ports
             $query = "SELECT `id`\n                       FROM `glpi_networkports`\n                       WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                          AND `itemtype` = '" . get_called_class() . "';";
             $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']);
                     }
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: link.class.php プロジェクト: pluginsGLPI/order
 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);
         }
     }
 }
コード例 #11
0
     if ($_POST["itemtype"] == 'Contact') {
         $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();
コード例 #12
0
 /**
  * Have I the right to "delete" the Object
  *
  * Default is calling canCreateItem
  * May be overloaded if needed
  *
  * @return booleen
  * @see canCreate
  **/
 function canDeleteItem()
 {
     global $CFG_GLPI;
     if (!$this->canCreateItem()) {
         return false;
     }
     // Can delete an object with Infocom only if can delete Infocom
     if (in_array($this->getType(), $CFG_GLPI['infocom_types'])) {
         $infocom = new Infocom();
         if ($infocom->getFromDBforDevice($this->getType(), $this->fields['id'])) {
             return $infocom->canDelete();
         }
     }
     return true;
 }
コード例 #13
0
 /**
  * Get comments of the Object
  *
  * @return String: comments of the object in the current language (HTML)
  **/
 function getComments()
 {
     $comment = "";
     $toadd = array();
     if ($this->isField('completename')) {
         $toadd[] = array('name' => __('Complete name'), 'value' => nl2br($this->getField('completename')));
     }
     if ($this->isField('serial')) {
         $toadd[] = array('name' => __('Serial number'), 'value' => nl2br($this->getField('serial')));
     }
     if ($this->isField('otherserial')) {
         $toadd[] = array('name' => __('Inventory number'), 'value' => nl2br($this->getField('otherserial')));
     }
     if ($this->isField('states_id') && $this->getType() != 'State') {
         $tmp = Dropdown::getDropdownName('glpi_states', $this->getField('states_id'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('Status'), 'value' => $tmp);
         }
     }
     if ($this->isField('locations_id') && $this->getType() != 'Location') {
         $tmp = Dropdown::getDropdownName("glpi_locations", $this->getField('locations_id'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('Location'), 'value' => $tmp);
         }
     }
     if ($this->isField('users_id')) {
         $tmp = getUserName($this->getField('users_id'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('User'), 'value' => $tmp);
         }
     }
     if ($this->isField('groups_id') && $this->getType() != 'Group') {
         $tmp = Dropdown::getDropdownName("glpi_groups", $this->getField('groups_id'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('Group'), 'value' => $tmp);
         }
     }
     if ($this->isField('users_id_tech')) {
         $tmp = getUserName($this->getField('users_id_tech'));
         if (strlen($tmp) != 0 && $tmp != '&nbsp;') {
             $toadd[] = array('name' => __('Technician in charge of the hardware'), 'value' => $tmp);
         }
     }
     if ($this->isField('contact')) {
         $toadd[] = array('name' => __('Alternate username'), 'value' => nl2br($this->getField('contact')));
     }
     if ($this->isField('contact_num')) {
         $toadd[] = array('name' => __('Alternate username number'), 'value' => nl2br($this->getField('contact_num')));
     }
     if (InfoCom::canApplyOn($this)) {
         $infocom = new Infocom();
         if ($infocom->getFromDBforDevice($this->getType(), $this->fields['id'])) {
             $toadd[] = array('name' => __('Warranty expiration date'), 'value' => Infocom::getWarrantyExpir($infocom->fields["warranty_date"], $infocom->fields["warranty_duration"], 0, true));
         }
     }
     if ($this instanceof CommonDropdown && $this->isField('comment')) {
         $toadd[] = array('name' => __('Comments'), 'value' => nl2br($this->getField('comment')));
     }
     if (count($toadd)) {
         foreach ($toadd as $data) {
             // Do not use SPAN here
             $comment .= sprintf(__('%1$s: %2$s') . "<br>", "<strong>" . $data['name'], "</strong>" . $data['value']);
         }
     }
     if (!empty($comment)) {
         return Html::showToolTip($comment, array('display' => false));
     }
     return $comment;
 }
コード例 #14
0
ファイル: commondbtm.class.php プロジェクト: gaforeror/glpi
 /**
  * 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;
 }
コード例 #15
0
ファイル: api.class.php プロジェクト: stweil/glpi
 /**
  * Return the instance fields of itemtype identified by id
  *
  * @since version 9.1
  *
  * @param      string   $itemtype  itemtype (class) of object
  * @param      integer  $id        identifier of object
  * @param      array   $params   array with theses options :
  *    - 'expand_dropdowns' : show dropdown's names instead of id. default: false. Optionnal
  *    - 'get_hateoas' :      show relation of current item in a links attribute. default: true. Optionnal
  *    - 'with_components' :  Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal.
  *    - 'with_disks' :       Only for Computer, retrieve the associated filesystems. Optionnal.
  *    - 'with_softwares' :   Only for Computer, retrieve the associated softwares installations. Optionnal.
  *    - 'with_connections' : Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal.
  *    - 'with_networkports' :Retrieve all network connections and advanced network informations. Optionnal.
  *    - 'with_infocoms' :    Retrieve financial and administrative informations. Optionnal.
  *    - 'with_contracts' :   Retrieve associated contracts. Optionnal.
  *    - 'with_documents' :   Retrieve associated external documents. Optionnal.
  *    - 'with_tickets' :     Retrieve associated itil tickets. Optionnal.
  *    - 'with_problems' :    Retrieve associated itil problems. Optionnal.
  *    - 'with_changes' :     Retrieve associated itil changes. Optionnal.
  *    - 'with_notes' :       Retrieve Notes (if exists, not all itemtypes have notes). Optionnal.
  *    - 'with_logs' :        Retrieve historical. Optionnal.
  *
  * @return     array    fields of found object
  */
 protected function getItem($itemtype, $id, $params = array())
 {
     global $CFG_GLPI, $DB;
     $this->initEndpoint();
     // default params
     $default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'with_components' => false, 'with_disks' => false, 'with_softwares' => false, 'with_connections' => false, 'with_networkports' => false, 'with_infocoms' => false, 'with_contracts' => false, 'with_documents' => false, 'with_tickets' => false, 'with_problems' => false, 'with_changes' => false, 'with_notes' => false, 'with_logs' => false);
     $params = array_merge($default, $params);
     $item = new $itemtype();
     if (!$item->getFromDB($id)) {
         return $this->messageNotfoundError();
     }
     if (!$item->can($id, READ)) {
         return $this->messageRightError();
     }
     $fields = $item->fields;
     // retrieve devices
     if (isset($params['with_devices']) && $params['with_devices'] && in_array($itemtype, Item_Devices::getConcernedItems())) {
         $all_devices = array();
         foreach (Item_Devices::getItemAffinities($item->getType()) as $device_type) {
             $found_devices = getAllDatasFromTable($device_type::getTable(), "`items_id` = '" . $item->getID() . "'\n                                                   AND `itemtype` = '" . $item->getType() . "'\n                                                   AND `is_deleted` = '0'", true);
             foreach ($found_devices as $devices_id => &$device) {
                 unset($device['items_id']);
                 unset($device['itemtype']);
                 unset($device['is_deleted']);
             }
             if (!empty($found_devices)) {
                 $all_devices[$device_type] = $found_devices;
             }
         }
         $fields['_devices'] = $all_devices;
     }
     // retrieve computer disks
     if (isset($params['with_disks']) && $params['with_disks'] && $itemtype == "Computer") {
         // build query to retrive filesystems
         $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n                          `glpi_computerdisks`.*\n                   FROM `glpi_computerdisks`\n                   LEFT JOIN `glpi_filesystems`\n                             ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n                   WHERE `computers_id` = '{$id}'\n                         AND `is_deleted` = '0'";
         if ($result = $DB->query($query)) {
             while ($data = $DB->fetch_assoc($result)) {
                 unset($data['computers_id']);
                 unset($data['is_deleted']);
                 $fields['_disks'][] = array('name' => $data);
             }
         }
     }
     // retrieve computer softwares
     if (isset($params['with_softwares']) && $params['with_softwares'] && $itemtype == "Computer") {
         $fields['_softwares'] = array();
         if (!Software::canView()) {
             $fields['_softwares'] = self::arrayRightError();
         } else {
             $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n                             `glpi_softwares`.`id` AS softwares_id,\n                             `glpi_softwareversions`.`id` AS softwareversions_id,\n                             `glpi_computers_softwareversions`.`is_dynamic`,\n                             `glpi_softwareversions`.`states_id`,\n                             `glpi_softwares`.`is_valid`\n                      FROM `glpi_computers_softwareversions`\n                      LEFT JOIN `glpi_softwareversions`\n                           ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                                 = `glpi_softwareversions`.`id`)\n                      LEFT JOIN `glpi_softwares`\n                           ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n                      WHERE `glpi_computers_softwareversions`.`computers_id` = '{$id}'\n                            AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n                      ORDER BY `glpi_softwares`.`name`, `glpi_softwareversions`.`name`";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_softwares'][] = $data;
                 }
             }
         }
     }
     // retrieve item connections
     if (isset($params['with_connections']) && $params['with_connections'] && $itemtype == "Computer") {
         $fields['_connections'] = array();
         foreach ($CFG_GLPI["directconnect_types"] as $connect_type) {
             $connect_item = new $connect_type();
             if ($connect_item->canView()) {
                 $query = "SELECT `glpi_computers_items`.`id` AS assoc_id,\n                         `glpi_computers_items`.`computers_id` AS assoc_computers_id,\n                         `glpi_computers_items`.`itemtype` AS assoc_itemtype,\n                         `glpi_computers_items`.`items_id` AS assoc_items_id,\n                         `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic,\n                         " . getTableForItemType($connect_type) . ".*\n                         FROM `glpi_computers_items`\n                         LEFT JOIN `" . getTableForItemType($connect_type) . "`\n                           ON (`" . getTableForItemType($connect_type) . "`.`id`\n                                 = `glpi_computers_items`.`items_id`)\n                         WHERE `computers_id` = '{$id}'\n                               AND `itemtype` = '" . $connect_type . "'\n                               AND `glpi_computers_items`.`is_deleted` = '0'";
                 if ($result = $DB->query($query)) {
                     while ($data = $DB->fetch_assoc($result)) {
                         $fields['_connections'][$connect_type][] = $data;
                     }
                 }
             }
         }
     }
     // retrieve item networkports
     if (isset($params['with_networkports']) && $params['with_networkports']) {
         $fields['_networkports'] = array();
         if (!NetworkEquipment::canView()) {
             $fields['_networkports'] = self::arrayRightError();
         } else {
             foreach (NetworkPort::getNetworkPortInstantiations() as $networkport_type) {
                 $query = "SELECT\n                           netp.`entities_id`,\n                           netp.`is_recursive`,\n                           netp.`logical_number`,\n                           netp.`name`,\n                           netp.`mac`,\n                           netp.`comment`,\n                           netp.`is_dynamic`,\n                           netp_subtable.*\n                         FROM glpi_networkports AS netp\n                         LEFT JOIN " . $networkport_type::getTable() . " AS netp_subtable\n                           ON netp_subtable.`networkports_id` = netp.`id`\n                         WHERE netp.`instantiation_type` = '{$networkport_type}'\n                               AND netp.`items_id` = '{$id}'\n                               AND netp.`itemtype` = '{$itemtype}'\n                               AND netp.`is_deleted` = '0'";
                 if ($result = $DB->query($query)) {
                     while ($data = $DB->fetch_assoc($result)) {
                         $fields['_networkports'][$networkport_type][] = $data;
                     }
                 }
             }
         }
     }
     // retrieve item infocoms
     if (isset($params['with_infocoms']) && $params['with_infocoms']) {
         $fields['_infocoms'] = array();
         if (!Infocom::canView()) {
             $fields['_infocoms'] = self::arrayRightError();
         } else {
             $ic = new Infocom();
             if ($ic->getFromDBforDevice($itemtype, $id)) {
                 $fields['_infocoms'] = $ic->fields;
             }
         }
     }
     // retrieve item contracts
     if (isset($params['with_contracts']) && $params['with_contracts']) {
         $fields['_contracts'] = array();
         if (!Contract::canView()) {
             $fields['_contracts'] = self::arrayRightError();
         } else {
             $query = "SELECT `glpi_contracts_items`.*\n                     FROM `glpi_contracts_items`,\n                          `glpi_contracts`\n                     LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n                     WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n                           AND `glpi_contracts_items`.`items_id` = '{$id}'\n                           AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n                     ORDER BY `glpi_contracts`.`name`";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_contracts'][] = $data;
                 }
             }
         }
     }
     // retrieve item contracts
     if (isset($params['with_documents']) && $params['with_documents']) {
         $fields['_documents'] = array();
         if (!$itemtype != 'Ticket' && $itemtype != 'KnowbaseItem' && $itemtype != 'Reminder' && !Document::canView()) {
             $fields['_documents'] = self::arrayRightError();
         } else {
             $query = "SELECT `glpi_documents_items`.`id` AS assocID,\n                             `glpi_documents_items`.`date_mod` AS assocdate,\n                             `glpi_entities`.`id` AS entityID,\n                             `glpi_entities`.`completename` AS entity,\n                             `glpi_documentcategories`.`completename` AS headings,\n                             `glpi_documents`.*\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_documents`\n                                ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n                      LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n                      LEFT JOIN `glpi_documentcategories`\n                              ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n                      WHERE `glpi_documents_items`.`items_id` = '{$id}'\n                            AND `glpi_documents_items`.`itemtype` = '{$itemtype}' ";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_documents'][] = $data;
                 }
             }
         }
     }
     // retrieve item tickets
     if (isset($params['with_tickets']) && $params['with_tickets']) {
         $fields['_tickets'] = array();
         if (!Ticket::canView()) {
             $fields['_tickets'] = self::arrayRightError();
         } else {
             $query = "SELECT " . Ticket::getCommonSelect() . "\n                      FROM `glpi_tickets` " . Ticket::getCommonLeftJoin() . "\n                      WHERE `glpi_items_tickets`.`items_id` = '{$id}'\n                             AND `glpi_items_tickets`.`itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                      ORDER BY `glpi_tickets`.`date_mod` DESC";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_tickets'][] = $data;
                 }
             }
         }
     }
     // retrieve item problems
     if (isset($params['with_problems']) && $params['with_problems']) {
         $fields['_problems'] = array();
         if (!Problem::canView()) {
             $fields['_problems'] = self::arrayRightError();
         } else {
             $query = "SELECT " . Problem::getCommonSelect() . "\n                            FROM `glpi_problems`\n                            LEFT JOIN `glpi_items_problems`\n                              ON (`glpi_problems`.`id` = `glpi_items_problems`.`problems_id`) " . Problem::getCommonLeftJoin() . "\n                            WHERE `items_id` = '{$id}'\n                                  AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_problems") . "\n                            ORDER BY `glpi_problems`.`date_mod` DESC";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_problems'][] = $data;
                 }
             }
         }
     }
     // retrieve item changes
     if (isset($params['with_changes']) && $params['with_changes']) {
         $fields['_changes'] = array();
         if (!Change::canView()) {
             $fields['_changes'] = self::arrayRightError();
         } else {
             $query = "SELECT " . Change::getCommonSelect() . "\n                            FROM `glpi_changes`\n                            LEFT JOIN `glpi_changes_items`\n                              ON (`glpi_changes`.`id` = `glpi_changes_items`.`problems_id`) " . Change::getCommonLeftJoin() . "\n                            WHERE `items_id` = '{$id}'\n                                  AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n                            ORDER BY `glpi_changes`.`date_mod` DESC";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_changes'][] = $data;
                 }
             }
         }
     }
     // retrieve item notes
     if (isset($params['with_notes']) && $params['with_notes']) {
         $fields['_notes'] = array();
         if (!Session::haveRight($itemtype::$rightname, READNOTE)) {
             $fields['_notes'] = self::arrayRightError();
         } else {
             $fields['_notes'] = Notepad::getAllForItem($itemtype);
         }
     }
     // retrieve item logs
     if (isset($params['with_logs']) && $params['with_logs']) {
         $fields['_logs'] = array();
         if (!Session::haveRight($itemtype::$rightname, READNOTE)) {
             $fields['_logs'] = self::arrayRightError();
         } else {
             $fields['_logs'] = getAllDatasFromTable("glpi_logs", "`items_id` = '" . $item->getID() . "'\n                                                    AND `itemtype` = '" . $item->getType() . "'");
         }
     }
     // expand dropdown (retrieve name of dropdowns) and get hateoas from foreign keys
     $fields = self::parseDropdowns($fields, $params);
     // get hateoas from children
     if ($params['get_hateoas']) {
         $hclasses = self::getHatoasClasses($itemtype);
         foreach ($hclasses as $hclass) {
             $fields['links'][] = array('rel' => $hclass, 'href' => self::$api_url . "/{$itemtype}/" . $item->getID() . "/{$hclass}/");
         }
     }
     return $fields;
 }