. * --------------------------------------------------------------------- */ 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() { $this->deleteChildrenAndRelationsFromDb( [ Change_Supplier::class, Contact_Supplier::class, Contract_Supplier::class, Problem_Supplier::class, ProjectTaskTeam::class, ProjectTeam::class, Supplier_Ticket::class, ] ); // Ticket rules use suppliers_id_assign Rule::cleanForItemAction($this, 'suppliers_id%'); } function defineTabs($options = []) { $ong = []; $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('KnowbaseItem_Item', $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 void **/ function showForm($ID, $options = []) { $this->initForm($ID, $options); $this->showFormHeader($options); echo ""; echo "".__('Name').""; echo ""; Html::autocompletionTextField($this, "name"); echo ""; echo "".SupplierType::getTypeName(1).""; echo ""; SupplierType::dropdown(['value' => $this->fields["suppliertypes_id"]]); echo ""; echo ""; echo "". Phone::getTypeName(1).""; 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", ['size' => 10]); echo "  ". __('City'). " "; Html::autocompletionTextField($this, "town", ['size' => 23]); echo ""; echo ""; echo ""._x('location', 'State').""; echo ""; Html::autocompletionTextField($this, "state"); echo ""; echo ""; echo "".__('Country').""; echo ""; Html::autocompletionTextField($this, "country"); echo ""; echo "".__('Active').""; echo ""; Dropdown::showYesNo('is_active', $this->fields['is_active']); echo ""; $this->showFormButtons($options); return true; } static function dropdown($options = []) { $condition = ['is_active' => true]; $options['condition'] = (isset($options['condition']) ? $options['condition'] + $condition : $condition); return Dropdown::show(get_called_class(), $options); } /** * @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'); } return $actions; } function rawSearchOptions() { global $DB; $tab = []; $tab[] = [ 'id' => 'common', 'name' => __('Characteristics') ]; $tab[] = [ 'id' => '1', 'table' => $this->getTable(), 'field' => 'name', 'name' => __('Name'), 'datatype' => 'itemlink', 'massiveaction' => false, 'autocomplete' => true, ]; $tab[] = [ 'id' => '2', 'table' => $this->getTable(), 'field' => 'id', 'name' => __('ID'), 'massiveaction' => false, 'datatype' => 'number' ]; $tab[] = [ 'id' => '3', 'table' => $this->getTable(), 'field' => 'address', 'name' => __('Address'), 'datatype' => 'text' ]; $tab[] = [ 'id' => '10', 'table' => $this->getTable(), 'field' => 'fax', 'name' => __('Fax'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '11', 'table' => $this->getTable(), 'field' => 'town', 'name' => __('City'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '14', 'table' => $this->getTable(), 'field' => 'postcode', 'name' => __('Postal code'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '12', 'table' => $this->getTable(), 'field' => 'state', 'name' => _x('location', 'State'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '13', 'table' => $this->getTable(), 'field' => 'country', 'name' => __('Country'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '4', 'table' => $this->getTable(), 'field' => 'website', 'name' => __('Website'), 'datatype' => 'weblink', 'autocomplete' => true, ]; $tab[] = [ 'id' => '5', 'table' => $this->getTable(), 'field' => 'phonenumber', 'name' => Phone::getTypeName(1), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '6', 'table' => $this->getTable(), 'field' => 'email', 'name' => _n('Email', 'Emails', 1), 'datatype' => 'email', 'autocomplete' => true, ]; $tab[] = [ 'id' => '9', 'table' => 'glpi_suppliertypes', 'field' => 'name', 'name' => SupplierType::getTypeName(1), 'datatype' => 'dropdown' ]; $tab[] = [ 'id' => '19', 'table' => $this->getTable(), 'field' => 'date_mod', 'name' => __('Last update'), 'datatype' => 'datetime', 'massiveaction' => false ]; $tab[] = [ 'id' => '121', 'table' => $this->getTable(), 'field' => 'date_creation', 'name' => __('Creation date'), 'datatype' => 'datetime', 'massiveaction' => false ]; if ($_SESSION["glpinames_format"] == User::FIRSTNAME_BEFORE) { $name1 = 'firstname'; $name2 = 'name'; } else { $name1 = 'name'; $name2 = 'firstname'; } $tab[] = [ 'id' => '8', 'table' => 'glpi_contacts', 'field' => 'completename', 'name' => _n('Associated contact', 'Associated contacts', Session::getPluralNumber()), 'forcegroupby' => true, 'datatype' => 'itemlink', 'massiveaction' => false, 'computation' => "CONCAT(".$DB->quoteName("TABLE.$name1").", ' ', ".$DB->quoteName("TABLE.$name2").")", 'computationgroupby' => true, 'joinparams' => [ 'beforejoin' => [ 'table' => 'glpi_contacts_suppliers', 'joinparams' => [ 'jointype' => 'child' ] ] ] ]; $tab[] = [ 'id' => '16', 'table' => $this->getTable(), 'field' => 'comment', 'name' => __('Comments'), 'datatype' => 'text' ]; $tab[] = [ 'id' => '80', 'table' => 'glpi_entities', 'field' => 'completename', 'name' => Entity::getTypeName(1), 'massiveaction' => false, 'datatype' => 'dropdown' ]; $tab[] = [ 'id' => '86', 'table' => $this->getTable(), 'field' => 'is_recursive', 'name' => __('Child entities'), 'datatype' => 'bool' ]; $tab[] = [ 'id' => '29', 'table' => 'glpi_contracts', 'field' => 'name', 'name' => _n('Associated contract', 'Associated contracts', Session::getPluralNumber()), 'forcegroupby' => true, 'datatype' => 'itemlink', 'massiveaction' => false, 'joinparams' => [ 'beforejoin' => [ 'table' => 'glpi_contracts_suppliers', 'joinparams' => [ 'jointype' => 'child' ] ] ] ]; // add objectlock search options $tab = array_merge($tab, ObjectLock::rawSearchOptionsToAdd(get_class($this))); $tab = array_merge($tab, Notepad::rawSearchOptionsToAdd()); 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 void * **/ function showInfocoms() { global $DB; $instID = $this->fields['id']; if (!$this->can($instID, READ)) { return false; } $types_iterator = Infocom::getTypes(['suppliers_id' => $instID]); $number = count($types_iterator); echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $num = 0; while ($row = $types_iterator->next()) { $itemtype = $row['itemtype']; if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $linktype = $itemtype; $linkfield = 'id'; $itemtable = getTableForItemType($itemtype); $criteria = [ 'SELECT' => [], 'FROM' => 'glpi_infocoms', 'INNER JOIN' => [ $itemtable => [ 'ON' => [ 'glpi_infocoms' => 'items_id', $itemtable => 'id' ] ] ] ]; // Set $linktype for entity restriction AND link to search engine if ($itemtype == 'Cartridge') { $criteria['INNER JOIN']['glpi_cartridgeitems'] = [ 'ON' => [ 'glpi_cartridgeitems' => 'id', 'glpi_cartridges' => 'cartridgeitems_id' ] ]; $linktype = 'CartridgeItem'; $linkfield = 'cartridgeitems_id'; } if ($itemtype == 'Consumable') { $criteria['INNER JOIN']['glpi_consumableitems'] = [ 'ON' => [ 'glpi_consumableitems' => 'id', 'glpi_consumables' => 'cartridgeitems_id' ] ]; $linktype = 'ConsumableItem'; $linkfield = 'consumableitems_id'; } if ($itemtype == 'Item_DeviceControl') { $criteria['INNER JOIN']['glpi_devicecontrols'] = [ 'ON' => [ 'glpi_items_devicecontrols' => 'devicecontrols_id', 'glpi_devicecontrols' => 'id' ] ]; $linktype = 'DeviceControl'; $linkfield = 'devicecontrols_id'; } $linktable = getTableForItemType($linktype); $criteria['SELECT'] = [ 'glpi_infocoms.entities_id', $linktype::getNameField(), "$itemtable.*" ]; $criteria['WHERE'] = [ 'glpi_infocoms.itemtype' => $itemtype, 'glpi_infocoms.suppliers_id' => $instID, ] + getEntitiesRestrictCriteria($linktable); $criteria['ORDERBY'] = [ 'glpi_infocoms.entities_id', "$linktable." . $linktype::getNameField() ]; $iterator = $DB->request($criteria); $nb = count($iterator); 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) { $prem = true; while ($data = $iterator->next()) { $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) { $prem = false; $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 ($number == 0) { echo __('No associated item'); } else { echo _n('Associated item', 'Associated items', $number); } echo "
"._n('Type', 'Types', 1)."".Entity::getTypeName(1)."".__('Name')."".__('Serial number')."".__('Inventory number')."
".$title.""; $opt = ['order' => 'ASC', 'is_deleted' => 0, 'reset' => 'reset', 'start' => 0, 'sort' => 80, 'criteria' => [0 => ['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) : " ")." 
"; } /** * Get suppliers matching a given email * * @since 9.5 * * @param $email boolean : also display name ? (false by default) **/ public static function getSuppliersByEmail($email) { global $DB; $suppliers = $DB->request([ 'SELECT' => ["id"], 'FROM' => 'glpi_suppliers', 'WHERE' => ['email' => $email] ]); return $suppliers; } static function getIcon() { return "fas fa-dolly"; } }