grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Supplier class (suppliers) **/ class Supplier extends CommonDBTM { // From CommonDBTM public $dohistory = true; static $rightname = 'contact_enterprise'; protected $usenotepad = true; /** * Name of the type * * @param $nb : number of item in the type **/ static function getTypeName($nb=0) { return _n('Supplier', 'Suppliers', $nb); } function cleanDBonPurge() { global $DB; $supplierjob = new Supplier_Ticket(); $supplierjob->cleanDBonItemDelete($this->getType(), $this->fields['id']); $ps = new Problem_Supplier(); $ps->cleanDBonItemDelete($this->getType(), $this->fields['id']); $cs = new Change_Supplier(); $cs->cleanDBonItemDelete($this->getType(), $this->fields['id']); $query1 = "DELETE FROM `glpi_projecttaskteams` WHERE `items_id` = '".$this->fields['id']."' AND `itemtype` = '".__CLASS__."'"; $DB->query($query1); $query1 = "DELETE FROM `glpi_projectteams` WHERE `items_id` = '".$this->fields['id']."' AND `itemtype` = '".__CLASS__."'"; $DB->query($query1); $cs = new Contract_Supplier(); $cs->cleanDBonItemDelete($this->getType(), $this->fields['id']); $cs = new Contact_Supplier(); $cs->cleanDBonItemDelete($this->getType(), $this->fields['id']); // Ticket rules use suppliers_id_assign Rule::cleanForItemAction($this, 'suppliers_id%'); } function defineTabs($options=array()) { $ong = array(); $this->addDefaultFormTab($ong); $this->addStandardTab('Contact_Supplier', $ong, $options); $this->addStandardTab('Contract_Supplier', $ong, $options); $this->addStandardTab('Infocom', $ong, $options); $this->addStandardTab('Document_Item', $ong, $options); $this->addStandardTab('Ticket', $ong, $options); $this->addStandardTab('Item_Problem', $ong, $options); $this->addStandardTab('Change_Item', $ong, $options); $this->addStandardTab('Link', $ong, $options); $this->addStandardTab('Notepad', $ong, $options); $this->addStandardTab('Log', $ong, $options); return $ong; } /** * Print the enterprise form * * @param $ID Integer : Id of the computer or the template to print * @param $options array * - target form target * - withtemplate boolean : template or basic item * *@return Nothing (display) **/ function showForm($ID, $options=array()) { $this->initForm($ID, $options); $this->showFormHeader($options); echo ""; echo "".__('Name').""; echo ""; Html::autocompletionTextField($this, "name"); echo ""; echo "".__('Third party type').""; echo ""; SupplierType::dropdown(array('value' => $this->fields["suppliertypes_id"])); echo ""; echo ""; echo "". __('Phone').""; echo ""; Html::autocompletionTextField($this, "phonenumber"); echo ""; echo "".__('Comments').""; echo ""; echo ""; echo ""; echo ""; echo "".__('Fax').""; echo ""; Html::autocompletionTextField($this, "fax"); echo ""; echo ""; echo "".__('Website').""; echo ""; Html::autocompletionTextField($this, "website"); echo ""; echo ""; echo ""._n('Email', 'Emails', 1).""; echo ""; Html::autocompletionTextField($this, "email"); echo ""; echo ""; echo "".__('Address').""; echo ""; echo ""; echo ""; echo ""; echo "".__('Postal code').""; echo ""; Html::autocompletionTextField($this, "postcode", array('size' => 10)); echo "  ". __('City'). " "; Html::autocompletionTextField($this, "town", array('size' => 23)); echo ""; echo ""; echo ""._x('location','State').""; echo ""; Html::autocompletionTextField($this, "state"); echo ""; echo ""; echo "".__('Country').""; echo ""; Html::autocompletionTextField($this, "country"); echo ""; $this->showFormButtons($options); return true; } /** * @see CommonDBTM::getSpecificMassiveActions() **/ function getSpecificMassiveActions($checkitem=NULL) { $isadmin = static::canUpdate(); $actions = parent::getSpecificMassiveActions($checkitem); if ($isadmin) { $actions['Contact_Supplier'.MassiveAction::CLASS_ACTION_SEPARATOR.'add'] = _x('button', 'Add a contact'); MassiveAction::getAddTransferList($actions); } return $actions; } function getSearchOptions() { $tab = array(); $tab['common'] = __('Characteristics'); $tab[1]['table'] = $this->getTable(); $tab[1]['field'] = 'name'; $tab[1]['name'] = __('Name'); $tab[1]['datatype'] = 'itemlink'; $tab[1]['massiveaction'] = false; $tab[2]['table'] = $this->getTable(); $tab[2]['field'] = 'id'; $tab[2]['name'] = __('ID'); $tab[2]['massiveaction'] = false; $tab[2]['datatype'] = 'number'; $tab[3]['table'] = $this->getTable(); $tab[3]['field'] = 'address'; $tab[3]['name'] = __('Address'); $tab[3]['datatype'] = 'text'; $tab[10]['table'] = $this->getTable(); $tab[10]['field'] = 'fax'; $tab[10]['name'] = __('Fax'); $tab[10]['datatype'] = 'string'; $tab[11]['table'] = $this->getTable(); $tab[11]['field'] = 'town'; $tab[11]['name'] = __('City'); $tab[11]['datatype'] = 'string'; $tab[14]['table'] = $this->getTable(); $tab[14]['field'] = 'postcode'; $tab[14]['name'] = __('Postal code'); $tab[14]['datatype'] = 'string'; $tab[12]['table'] = $this->getTable(); $tab[12]['field'] = 'state'; $tab[12]['name'] = _x('location','State'); $tab[12]['datatype'] = 'string'; $tab[13]['table'] = $this->getTable(); $tab[13]['field'] = 'country'; $tab[13]['name'] = __('Country'); $tab[13]['datatype'] = 'string'; $tab[4]['table'] = $this->getTable(); $tab[4]['field'] = 'website'; $tab[4]['name'] = __('Website'); $tab[4]['datatype'] = 'weblink'; $tab[5]['table'] = $this->getTable(); $tab[5]['field'] = 'phonenumber'; $tab[5]['name'] = __('Phone'); $tab[5]['datatype'] = 'string'; $tab[6]['table'] = $this->getTable(); $tab[6]['field'] = 'email'; $tab[6]['name'] = _n('Email', 'Emails', 1); $tab[6]['datatype'] = 'email'; $tab[9]['table'] = 'glpi_suppliertypes'; $tab[9]['field'] = 'name'; $tab[9]['name'] = __('Third party type'); $tab[9]['datatype'] = 'dropdown'; $tab[19]['table'] = $this->getTable(); $tab[19]['field'] = 'date_mod'; $tab[19]['name'] = __('Last update'); $tab[19]['datatype'] = 'datetime'; $tab[19]['massiveaction'] = false; $tab[121]['table'] = $this->getTable(); $tab[121]['field'] = 'date_creation'; $tab[121]['name'] = __('Creation date'); $tab[121]['datatype'] = 'datetime'; $tab[121]['massiveaction'] = false; if ($_SESSION["glpinames_format"] == User::FIRSTNAME_BEFORE) { $name1 = 'firstname'; $name2 = 'name'; } else { $name1 = 'name'; $name2 = 'firstname'; } $tab[8]['table'] = 'glpi_contacts'; $tab[8]['field'] = 'completename'; $tab[8]['name'] = _n('Associated contact', 'Associated contacts', Session::getPluralNumber()); $tab[8]['forcegroupby'] = true; $tab[8]['datatype'] = 'itemlink'; $tab[8]['massiveaction'] = false; $tab[8]['computation'] = "CONCAT(TABLE.`$name1`, ' ', TABLE.`$name2`)"; $tab[8]['computationgroupby'] = true; $tab[8]['joinparams'] = array('beforejoin' => array('table' => 'glpi_contacts_suppliers', 'joinparams' => array('jointype' => 'child'))); $tab[16]['table'] = $this->getTable(); $tab[16]['field'] = 'comment'; $tab[16]['name'] = __('Comments'); $tab[16]['datatype'] = 'text'; $tab[80]['table'] = 'glpi_entities'; $tab[80]['field'] = 'completename'; $tab[80]['name'] = __('Entity'); $tab[80]['massiveaction'] = false; $tab[80]['datatype'] = 'dropdown'; $tab[86]['table'] = $this->getTable(); $tab[86]['field'] = 'is_recursive'; $tab[86]['name'] = __('Child entities'); $tab[86]['datatype'] = 'bool'; $tab[29]['table'] = 'glpi_contracts'; $tab[29]['field'] = 'name'; $tab[29]['name'] = _n('Associated contract', 'Associated contracts', Session::getPluralNumber()); $tab[29]['forcegroupby'] = true; $tab[29]['datatype'] = 'itemlink'; $tab[29]['massiveaction'] = false; $tab[29]['joinparams'] = array('beforejoin' => array('table' => 'glpi_contracts_suppliers', 'joinparams' => array('jointype' => 'child'))); // add objectlock search options $tab += ObjectLock::getSearchOptionsToAdd( get_class($this) ) ; $tab += Notepad::getSearchOptionsToAdd(); return $tab; } /** * Get links for an enterprise (website / edit) * * @param $withname boolean : also display name ? (false by default) **/ function getLinks($withname=false) { global $CFG_GLPI; $ret = '    '; if ($withname) { $ret .= $this->fields["name"]; $ret .= "  "; } if (!empty($this->fields['website'])) { $ret .= " \"".  "; } if ($this->can($this->fields['id'], READ)) { $ret .= " \""."; } return $ret; } /** * Print the HTML array for infocoms linked * *@return Nothing (display) * **/ function showInfocoms() { global $DB, $CFG_GLPI; $instID = $this->fields['id']; if (!$this->can($instID, READ)) { return false; } $query = "SELECT DISTINCT `itemtype` FROM `glpi_infocoms` WHERE `suppliers_id` = '$instID' AND `itemtype` NOT IN ('ConsumableItem', 'CartridgeItem', 'Software') ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $num = 0; for ($i=0 ; $i < $number ; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $linktype = $itemtype; $linkfield = 'id'; $itemtable = getTableForItemType($itemtype); $query = "SELECT `glpi_infocoms`.`entities_id`, `NAME_FIELD`, `$itemtable`.* FROM `glpi_infocoms` INNER JOIN `$itemtable` ON (`$itemtable`.`id` = `glpi_infocoms`.`items_id`) "; // Set $linktype for entity restriction AND link to search engine if ($itemtype == 'Cartridge') { $query .= "INNER JOIN `glpi_cartridgeitems` ON (`glpi_cartridgeitems`.`id`=`glpi_cartridges`.`cartridgeitems_id`) "; $linktype = 'CartridgeItem'; $linkfield = 'cartridgeitems_id'; } if ($itemtype == 'Consumable' ) { $query .= "INNER JOIN `glpi_consumableitems` ON (`glpi_consumableitems`.`id`=`glpi_consumables`.`consumableitems_id`) "; $linktype = 'ConsumableItem'; $linkfield = 'consumableitems_id'; } if ($itemtype == 'Item_DeviceControl') { $query .= "INNER JOIN `glpi_devicecontrols` ON (`glpi_items_devicecontrols`.`devicecontrols_id`=`glpi_devicecontrols`.`id`)"; $linktype = 'DeviceControl'; $linkfield = 'devicecontrols_id'; } $linktable = getTableForItemType($linktype); $query = str_replace('NAME_FIELD', $linktype::getNameField(), $query); $query .= "WHERE `glpi_infocoms`.`itemtype` = '$itemtype' AND `glpi_infocoms`.`suppliers_id` = '$instID'". getEntitiesRestrictRequest(" AND", $linktable) ." ORDER BY `glpi_infocoms`.`entities_id`, `$linktable`.`" . $linktype::getNameField() . "`"; $result_linked = $DB->query($query); $nb = $DB->numrows($result_linked); if ($nb > $_SESSION['glpilist_limit']) { echo ""; $title = $item->getTypeName($nb); if ($nb > 0) { $title = sprintf(__('%1$s: %2$s'), $title, $nb); } echo ""; echo ""; echo ""; } else if ($nb) { for ($prem=true ; $data=$DB->fetch_assoc($result_linked) ; $prem=false) { $name = $data[$linktype::getNameField()]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]); } $link = $linktype::getFormURLWithID($data[$linkfield]); $name = "".$name.""; echo ""; if ($prem) { $title = $item->getTypeName($nb); if ($nb > 0) { $title = sprintf(__('%1$s: %2$s'), $title, $nb); } echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; } } $num += $nb; } } echo ""; echo ""; echo " "; echo "
"; Html::printPagerForm(); echo ""; if ($DB->numrows($result) == 0) { _e('No associated item'); } else { echo _n('Associated item', 'Associated items', $DB->numrows($result)); } echo "
".__('Type')."".__('Entity')."".__('Name')."".__('Serial number')."".__('Inventory number')."
".$title.""; $opt = array('order' => 'ASC', 'is_deleted' => 0, 'reset' => 'reset', 'start' => 0, 'sort' => 80, 'criteria' => array(0 => array('value' => '$$$$'.$instID, 'searchtype' => 'contains', 'field' => 53))); $link = $linktype::getSearchURL(); $link.= (strpos($link,'?') ? '&':'?'); echo "" . __('Device list')."--
".$title."".Dropdown::getDropdownName("glpi_entities", $data["entities_id"]).""; echo $name."". (isset($data["serial"])?"".$data["serial"]."":"-")."". (isset($data["otherserial"])? "".$data["otherserial"]."" :"-")."
".(($num > 0) ? sprintf(__('%1$s = %2$s'), __('Total'), $num) : " ")." 
"; } }