canApplyOn() статический публичный Метод

Check if given object can have Document
static public canApplyOn ( $item ) : true
$item an object or a string
Результат true if $object is an object that can have InfoCom
Пример #1
0
 /**
  * transfer an item to another item (may be the same) in the new entity
  *
  * @param $itemtype     item type to transfer
  * @param $ID           ID of the item to transfer
  * @param $newID        new ID of the ite
  *
  * Transfer item to a new Item if $ID==$newID : only update entities_id field :
  *                                $ID!=$new ID -> copy datas (like template system)
  * @return nothing (diplays)
  **/
 function transferItem($itemtype, $ID, $newID)
 {
     global $CFG_GLPI, $DB;
     if (!($item = getItemForItemtype($itemtype))) {
         return;
     }
     // Is already transfer ?
     if (!isset($this->already_transfer[$itemtype][$ID])) {
         // Check computer exists ?
         if ($item->getFromDB($newID)) {
             // Network connection ? keep connected / keep_disconnected / delete
             if (in_array($itemtype, array('Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer'))) {
                 $this->transferNetworkLink($itemtype, $ID, $newID);
             }
             // Device : keep / delete : network case : delete if net connection delete in import case
             if (in_array($itemtype, Item_Devices::getConcernedItems())) {
                 $this->transferDevices($itemtype, $ID, $newID);
             }
             // Reservation : keep / delete
             if (in_array($itemtype, $CFG_GLPI["reservation_types"])) {
                 $this->transferReservations($itemtype, $ID, $newID);
             }
             // History : keep / delete
             $this->transferHistory($itemtype, $ID, $newID);
             // Ticket : delete / keep and clean ref / keep and move
             $this->transferTickets($itemtype, $ID, $newID);
             // Infocoms : keep / delete
             if (InfoCom::canApplyOn($itemtype)) {
                 $this->transferInfocoms($itemtype, $ID, $newID);
             }
             if ($itemtype == 'Software') {
                 $this->transferSoftwareLicensesAndVersions($ID);
             }
             // Connected item is transfered
             if (in_array($itemtype, $CFG_GLPI["directconnect_types"])) {
                 $this->manageConnectionComputer($itemtype, $ID);
             }
             // Computer Direct Connect : delete link if it is the initial transfer item (no recursion)
             if ($this->inittype == $itemtype && in_array($itemtype, array('Monitor', 'Phone', 'Peripheral', 'Printer'))) {
                 $this->deleteDirectConnection($itemtype, $ID);
             }
             // Contract : keep / delete + clean unused / keep unused
             if (in_array($itemtype, $CFG_GLPI["contract_types"])) {
                 $this->transferContracts($itemtype, $ID, $newID);
             }
             // Contact / Supplier : keep / delete + clean unused / keep unused
             if ($itemtype == 'Supplier') {
                 $this->transferSupplierContacts($ID, $newID);
             }
             // Document : keep / delete + clean unused / keep unused
             if (Document::canApplyOn($itemtype)) {
                 $this->transferDocuments($itemtype, $ID, $newID);
             }
             // Transfer compatible printers
             if ($itemtype == 'CartridgeItem') {
                 $this->transferCompatiblePrinters($ID, $newID);
             }
             // Cartridges  and cartridges items linked to printer
             if ($itemtype == 'Printer') {
                 $this->transferPrinterCartridges($ID, $newID);
             }
             // Transfer Item
             $input = array('id' => $newID, 'entities_id' => $this->to);
             // Manage Location dropdown
             if (isset($item->fields['locations_id'])) {
                 $input['locations_id'] = $this->transferDropdownLocation($item->fields['locations_id']);
             }
             if (in_array($itemtype, array('Ticket', 'Problem', 'Change'))) {
                 $input2 = $this->transferHelpdeskAdditionalInformations($item->fields);
                 $input = array_merge($input, $input2);
                 $this->transferTaskCategory($itemtype, $ID, $newID);
                 $this->transferLinkedSuppliers($itemtype, $ID, $newID);
             }
             $item->update($input);
             $this->addToAlreadyTransfer($itemtype, $ID, $newID);
             // Do it after item transfer for entity checks
             if ($itemtype == 'Computer') {
                 // Monitor Direct Connect : keep / delete + clean unused / keep unused
                 $this->transferDirectConnection($itemtype, $ID, 'Monitor');
                 // Peripheral Direct Connect : keep / delete + clean unused / keep unused
                 $this->transferDirectConnection($itemtype, $ID, 'Peripheral');
                 // Phone Direct Connect : keep / delete + clean unused / keep unused
                 $this->transferDirectConnection($itemtype, $ID, 'Phone');
                 // Printer Direct Connect : keep / delete + clean unused / keep unused
                 $this->transferDirectConnection($itemtype, $ID, 'Printer');
                 // License / Software :  keep / delete + clean unused / keep unused
                 $this->transferComputerSoftwares($ID);
                 // Computer Disks :  delete them or not ?
                 $this->transferComputerDisks($ID);
             }
             Plugin::doHook("item_transfer", array('type' => $itemtype, 'id' => $ID, 'newID' => $newID, 'entities_id' => $this->to));
         }
     }
 }
Пример #2
0
 /**
  * Get the SEARCH_OPTION array
  *
  * @param $itemtype
  * @param $withplugins boolean get search options from plugins (true by default)
  *
  * @return the reference to  array of search options for the given item type
  **/
 static function &getOptions($itemtype, $withplugins = true)
 {
     global $CFG_GLPI;
     static $search = array();
     $item = NULL;
     if (!isset($search[$itemtype])) {
         // standard type first
         switch ($itemtype) {
             case 'Internet':
                 $search[$itemtype]['common'] = __('Characteristics');
                 $search[$itemtype][1]['table'] = 'networkport_types';
                 $search[$itemtype][1]['field'] = 'name';
                 $search[$itemtype][1]['name'] = __('Name');
                 $search[$itemtype][1]['datatype'] = 'itemlink';
                 $search[$itemtype][1]['searchtype'] = 'contains';
                 $search[$itemtype][2]['table'] = 'networkport_types';
                 $search[$itemtype][2]['field'] = 'id';
                 $search[$itemtype][2]['name'] = __('ID');
                 $search[$itemtype][2]['searchtype'] = 'contains';
                 $search[$itemtype][31]['table'] = 'glpi_states';
                 $search[$itemtype][31]['field'] = 'completename';
                 $search[$itemtype][31]['name'] = __('Status');
                 $search[$itemtype] += NetworkPort::getSearchOptionsToAdd('networkport_types');
                 break;
             case 'AllAssets':
                 $search[$itemtype]['common'] = __('Characteristics');
                 $search[$itemtype][1]['table'] = 'asset_types';
                 $search[$itemtype][1]['field'] = 'name';
                 $search[$itemtype][1]['name'] = __('Name');
                 $search[$itemtype][1]['datatype'] = 'itemlink';
                 $search[$itemtype][1]['searchtype'] = 'contains';
                 $search[$itemtype][2]['table'] = 'asset_types';
                 $search[$itemtype][2]['field'] = 'id';
                 $search[$itemtype][2]['name'] = __('ID');
                 $search[$itemtype][2]['searchtype'] = 'contains';
                 $search[$itemtype][31]['table'] = 'glpi_states';
                 $search[$itemtype][31]['field'] = 'completename';
                 $search[$itemtype][31]['name'] = __('Status');
                 $search[$itemtype] += Location::getSearchOptionsToAdd();
                 $search[$itemtype][5]['table'] = 'asset_types';
                 $search[$itemtype][5]['field'] = 'serial';
                 $search[$itemtype][5]['name'] = __('Serial number');
                 $search[$itemtype][6]['table'] = 'asset_types';
                 $search[$itemtype][6]['field'] = 'otherserial';
                 $search[$itemtype][6]['name'] = __('Inventory number');
                 $search[$itemtype][16]['table'] = 'asset_types';
                 $search[$itemtype][16]['field'] = 'comment';
                 $search[$itemtype][16]['name'] = __('Comments');
                 $search[$itemtype][16]['datatype'] = 'text';
                 $search[$itemtype][70]['table'] = 'glpi_users';
                 $search[$itemtype][70]['field'] = 'name';
                 $search[$itemtype][70]['name'] = __('User');
                 $search[$itemtype][7]['table'] = 'asset_types';
                 $search[$itemtype][7]['field'] = 'contact';
                 $search[$itemtype][7]['name'] = __('Alternate username');
                 $search[$itemtype][7]['datatype'] = 'string';
                 $search[$itemtype][8]['table'] = 'asset_types';
                 $search[$itemtype][8]['field'] = 'contact_num';
                 $search[$itemtype][8]['name'] = __('Alternate username number');
                 $search[$itemtype][8]['datatype'] = 'string';
                 $search[$itemtype][71]['table'] = 'glpi_groups';
                 $search[$itemtype][71]['field'] = 'completename';
                 $search[$itemtype][71]['name'] = __('Group');
                 $search[$itemtype][19]['table'] = 'asset_types';
                 $search[$itemtype][19]['field'] = 'date_mod';
                 $search[$itemtype][19]['name'] = __('Last update');
                 $search[$itemtype][19]['datatype'] = 'datetime';
                 $search[$itemtype][19]['massiveaction'] = false;
                 $search[$itemtype][23]['table'] = 'glpi_manufacturers';
                 $search[$itemtype][23]['field'] = 'name';
                 $search[$itemtype][23]['name'] = __('Manufacturer');
                 $search[$itemtype][24]['table'] = 'glpi_users';
                 $search[$itemtype][24]['field'] = 'name';
                 $search[$itemtype][24]['linkfield'] = 'users_id_tech';
                 $search[$itemtype][24]['name'] = __('Technician in charge of the hardware');
                 $search[$itemtype][80]['table'] = 'glpi_entities';
                 $search[$itemtype][80]['field'] = 'completename';
                 $search[$itemtype][80]['name'] = __('Entity');
                 break;
             default:
                 if ($item = getItemForItemtype($itemtype)) {
                     $search[$itemtype] = $item->getSearchOptions();
                 }
                 break;
         }
         if (Session::getLoginUserID() && in_array($itemtype, $CFG_GLPI["ticket_types"])) {
             $search[$itemtype]['tracking'] = __('Assistance');
             $search[$itemtype][60]['table'] = 'glpi_tickets';
             $search[$itemtype][60]['field'] = 'id';
             $search[$itemtype][60]['datatype'] = 'count';
             $search[$itemtype][60]['name'] = _x('quantity', 'Number of tickets');
             $search[$itemtype][60]['forcegroupby'] = true;
             $search[$itemtype][60]['usehaving'] = true;
             $search[$itemtype][60]['massiveaction'] = false;
             $search[$itemtype][60]['joinparams'] = array('beforejoin' => array('table' => 'glpi_items_tickets', 'joinparams' => array('jointype' => 'itemtype_item')), 'condition' => getEntitiesRestrictRequest('AND', 'NEWTABLE'));
             $search[$itemtype][140]['table'] = 'glpi_problems';
             $search[$itemtype][140]['field'] = 'id';
             $search[$itemtype][140]['datatype'] = 'count';
             $search[$itemtype][140]['name'] = _x('quantity', 'Number of problems');
             $search[$itemtype][140]['forcegroupby'] = true;
             $search[$itemtype][140]['usehaving'] = true;
             $search[$itemtype][140]['massiveaction'] = false;
             $search[$itemtype][140]['joinparams'] = array('beforejoin' => array('table' => 'glpi_items_problems', 'joinparams' => array('jointype' => 'itemtype_item')), 'condition' => getEntitiesRestrictRequest('AND', 'NEWTABLE'));
         }
         if (in_array($itemtype, $CFG_GLPI["networkport_types"]) || $itemtype == 'AllAssets') {
             $search[$itemtype] += NetworkPort::getSearchOptionsToAdd($itemtype);
         }
         if (in_array($itemtype, $CFG_GLPI["contract_types"]) || $itemtype == 'AllAssets') {
             $search[$itemtype] += Contract::getSearchOptionsToAdd();
         }
         if (Document::canApplyOn($itemtype) || $itemtype == 'AllAssets') {
             $search[$itemtype] += Document::getSearchOptionsToAdd();
         }
         if (InfoCom::canApplyOn($itemtype) || $itemtype == 'AllAssets') {
             $search[$itemtype] += Infocom::getSearchOptionsToAdd($itemtype);
         }
         if (in_array($itemtype, $CFG_GLPI["link_types"])) {
             $search[$itemtype]['link'] = _n('External link', 'External links', Session::getPluralNumber());
             $search[$itemtype] += Link::getSearchOptionsToAdd($itemtype);
         }
         if ($withplugins) {
             // Search options added by plugins
             $plugsearch = Plugin::getAddSearchOptions($itemtype);
             if (count($plugsearch)) {
                 $search[$itemtype] += array('plugins' => _n('Plugin', 'Plugins', Session::getPluralNumber()));
                 $search[$itemtype] += $plugsearch;
             }
         }
         // Complete linkfield if not define
         if (is_null($item)) {
             // Special union type
             $itemtable = $CFG_GLPI['union_search_type'][$itemtype];
         } else {
             if ($item = getItemForItemtype($itemtype)) {
                 $itemtable = $item->getTable();
             }
         }
         foreach ($search[$itemtype] as $key => $val) {
             if (!is_array($val)) {
                 // skip sub-menu
                 continue;
             }
             // Compatibility before 0.80 : Force massive action to false if linkfield is empty :
             if (isset($val['linkfield']) && empty($val['linkfield'])) {
                 $search[$itemtype][$key]['massiveaction'] = false;
             }
             // Set default linkfield
             if (!isset($val['linkfield']) || empty($val['linkfield'])) {
                 if (strcmp($itemtable, $val['table']) == 0 && (!isset($val['joinparams']) || count($val['joinparams']) == 0)) {
                     $search[$itemtype][$key]['linkfield'] = $val['field'];
                 } else {
                     $search[$itemtype][$key]['linkfield'] = getForeignKeyFieldForTable($val['table']);
                 }
             }
             // Set default datatype
             //             if (!isset($val['datatype']) || empty($val['datatype'])) {
             //                if ((strcmp($itemtable,$val['table']) != 0)
             //                    && ($val['field'] == 'name' || $val['field'] == 'completename')) {
             //                   $search[$itemtype][$key]['datatype'] = 'dropdown';
             //                } else {
             //                   $search[$itemtype][$key]['datatype'] = 'string';
             //                }
             //             }
             // Add default joinparams
             if (!isset($val['joinparams'])) {
                 $search[$itemtype][$key]['joinparams'] = array();
             }
         }
     }
     return $search[$itemtype];
 }
Пример #3
0
 /**
  * Clean the date in the relation tables for the deleted item
  * Clear N/N Relation
  **/
 function cleanRelationTable()
 {
     global $CFG_GLPI, $DB;
     // If this type have INFOCOM, clean one associated to purged item
     if (Infocom::canApplyOn($this)) {
         $infocom = new Infocom();
         if ($infocom->getFromDBforDevice($this->getType(), $this->fields['id'])) {
             $infocom->delete(array('id' => $infocom->fields['id']));
         }
     }
     // If this type have NETPORT, clean one associated to purged item
     if (in_array($this->getType(), $CFG_GLPI['networkport_types'])) {
         // If we don't use delete, then cleanDBonPurge() is not call and the NetworkPorts are not
         // clean properly
         $networkPortObject = new NetworkPort();
         $networkPortObject->cleanDBonItemDelete($this->getType(), $this->getID());
         // Manage networkportmigration if exists
         if (TableExists('glpi_networkportmigrations')) {
             $networkPortMigObject = new NetworkPortMigration();
             $networkPortMigObject->cleanDBonItemDelete($this->getType(), $this->getID());
         }
     }
     // If this type is RESERVABLE clean one associated to purged item
     if (in_array($this->getType(), $CFG_GLPI['reservation_types'])) {
         $rr = new ReservationItem();
         if ($rr->getFromDBbyItem($this->getType(), $this->fields['id'])) {
             $rr->delete(array('id' => $infocom->fields['id']));
         }
     }
     // If this type have CONTRACT, clean one associated to purged item
     if (in_array($this->getType(), $CFG_GLPI['contract_types'])) {
         $ci = new Contract_Item();
         $ci->cleanDBonItemDelete($this->getType(), $this->fields['id']);
     }
     // If this type have DOCUMENT, clean one associated to purged item
     if (Document::canApplyOn($this)) {
         $di = new Document_Item();
         $di->cleanDBonItemDelete($this->getType(), $this->fields['id']);
     }
     // If this type have NOTEPAD, clean one associated to purged item
     if ($this->usenotepad) {
         $note = new Notepad();
         $note->cleanDBonItemDelete($this->getType(), $this->fields['id']);
     }
 }