. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } use Sabre\VObject; /** * Contact class **/ class Contact extends CommonDBTM{ // From CommonDBTM public $dohistory = true; static $rightname = 'contact_enterprise'; protected $usenotepad = true; static function getTypeName($nb = 0) { return _n('Contact', 'Contacts', $nb); } function cleanDBonPurge() { $this->deleteChildrenAndRelationsFromDb( [ Contact_Supplier::class, ProjectTaskTeam::class, ProjectTeam::class, ] ); } function defineTabs($options = []) { $ong = []; $this->addDefaultFormTab($ong); $this->addStandardTab('Contact_Supplier', $ong, $options); $this->addStandardTab('Document_Item', $ong, $options); $this->addStandardTab('Link', $ong, $options); $this->addStandardTab('Notepad', $ong, $options); $this->addStandardTab('Log', $ong, $options); return $ong; } /** * Get address of the contact (company one) * *@return string containing the address **/ function getAddress() { global $DB; $iterator = $DB->request([ 'SELECT' => [ 'glpi_suppliers.name', 'glpi_suppliers.address', 'glpi_suppliers.postcode', 'glpi_suppliers.town', 'glpi_suppliers.state', 'glpi_suppliers.country' ], 'FROM' => 'glpi_suppliers', 'INNER JOIN' => [ 'glpi_contacts_suppliers' => [ 'ON' => [ 'glpi_contacts_suppliers' => 'suppliers_id', 'glpi_suppliers' => 'id' ] ] ], 'WHERE' => ['contacts_id' => $this->fields['id']] ]); if ($data = $iterator->next()) { return $data; } } /** * Get website of the contact (company one) * *@return string containing the website **/ function getWebsite() { global $DB; $iterator = $DB->request([ 'SELECT' => [ 'glpi_suppliers.website AS website' ], 'FROM' => 'glpi_suppliers', 'INNER JOIN' => [ 'glpi_contacts_suppliers' => [ 'ON' => [ 'glpi_contacts_suppliers' => 'suppliers_id', 'glpi_suppliers' => 'id' ] ] ], 'WHERE' => ['contacts_id' => $this->fields['id']] ]); if ($data = $iterator->next()) { return $data['website']; } return ''; } /** * Print the contact form * * @param $ID integer ID of the item * @param $options array * - target filename : where to go when done. * - withtemplate boolean : template or basic item * * @return true **/ function showForm($ID, $options = []) { $this->initForm($ID, $options); $this->showFormHeader($options); echo ""; echo "".__('Surname').""; echo ""; Html::autocompletionTextField($this, "name"); echo ""; echo "".__('Comments').""; echo ""; echo ""; echo ""; echo ""; echo "".__('First name').""; echo ""; Html::autocompletionTextField($this, "firstname"); echo ""; echo ""; echo "". Phone::getTypeName(1).""; echo ""; Html::autocompletionTextField($this, "phone"); echo ""; echo ""; echo "". __('Phone 2').""; echo ""; Html::autocompletionTextField($this, "phone2"); echo ""; echo ""; echo "".__('Mobile phone').""; echo ""; Html::autocompletionTextField($this, "mobile"); echo ""; echo "".__('Address').""; echo ""; echo ""; echo ""; echo ""; echo "".__('Fax').""; echo ""; Html::autocompletionTextField($this, "fax"); echo ""; echo "".__('Postal code').""; echo ""; Html::autocompletionTextField($this, "postcode", ['size' => 10]); echo "  ". __('City'). " "; Html::autocompletionTextField($this, "town", ['size' => 23]); echo ""; echo ""; echo ""._n('Email', 'Emails', 1).""; echo ""; Html::autocompletionTextField($this, "email"); echo ""; echo ""._x('location', 'State').""; echo ""; Html::autocompletionTextField($this, "state"); echo ""; echo ""; echo ""._n('Type', 'Types', 1).""; echo ""; ContactType::dropdown(['value' => $this->fields["contacttypes_id"]]); echo ""; echo "".__('Country').""; echo ""; Html::autocompletionTextField($this, "country"); echo ""; echo "" . _x('person', 'Title') . ""; UserTitle::dropdown(['value' => $this->fields["usertitles_id"]]); echo " "; if ($ID > 0) { echo "".__('Vcard').""; } echo ""; $this->showFormButtons($options); return true; } 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 supplier'); } return $actions; } protected function computeFriendlyName() { if (isset($this->fields["id"]) && ($this->fields["id"] > 0)) { return formatUserName('', '', (isset($this->fields["name"]) ? $this->fields["name"] : ''), (isset($this->fields["firstname"]) ? $this->fields["firstname"] : '')); } return ''; } function rawSearchOptions() { $tab = []; $tab[] = [ 'id' => 'common', 'name' => __('Characteristics') ]; $tab[] = [ 'id' => '1', 'table' => $this->getTable(), 'field' => 'name', 'name' => __('Last name'), 'datatype' => 'itemlink', 'massiveaction' => false, 'autocomplete' => true, ]; $tab[] = [ 'id' => '11', 'table' => $this->getTable(), 'field' => 'firstname', 'name' => __('First name'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '2', 'table' => $this->getTable(), 'field' => 'id', 'name' => __('ID'), 'massiveaction' => false, 'datatype' => 'number' ]; $tab[] = [ 'id' => '3', 'table' => $this->getTable(), 'field' => 'phone', 'name' => Phone::getTypeName(1), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '4', 'table' => $this->getTable(), 'field' => 'phone2', 'name' => __('Phone 2'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '10', 'table' => $this->getTable(), 'field' => 'mobile', 'name' => __('Mobile phone'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '5', 'table' => $this->getTable(), 'field' => 'fax', 'name' => __('Fax'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '6', 'table' => $this->getTable(), 'field' => 'email', 'name' => _n('Email', 'Emails', 1), 'datatype' => 'email', 'autocomplete' => true, ]; $tab[] = [ 'id' => '82', 'table' => $this->getTable(), 'field' => 'address', 'name' => __('Address') ]; $tab[] = [ 'id' => '83', 'datatype' => 'string', 'table' => $this->getTable(), 'field' => 'postcode', 'name' => __('Postal code'), 'autocomplete' => true, ]; $tab[] = [ 'id' => '84', 'table' => $this->getTable(), 'field' => 'town', 'name' => __('City'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '85', 'table' => $this->getTable(), 'field' => 'state', 'name' => _x('location', 'State'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '87', 'table' => $this->getTable(), 'field' => 'country', 'name' => __('Country'), 'datatype' => 'string', 'autocomplete' => true, ]; $tab[] = [ 'id' => '9', 'table' => 'glpi_contacttypes', 'field' => 'name', 'name' => _n('Type', 'Types', 1), 'datatype' => 'dropdown' ]; $tab[] = [ 'id' => '81', 'table' => 'glpi_usertitles', 'field' => 'name', 'name' => __('Title'), 'datatype' => 'dropdown' ]; $tab[] = [ 'id' => '8', 'table' => 'glpi_suppliers', 'field' => 'name', 'name' => _n('Associated supplier', 'Associated suppliers', Session::getPluralNumber()), 'forcegroupby' => true, 'datatype' => 'itemlink', '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' => '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 ]; // add objectlock search options $tab = array_merge($tab, ObjectLock::rawSearchOptionsToAdd(get_class($this))); $tab = array_merge($tab, Notepad::rawSearchOptionsToAdd()); return $tab; } /** * Generate the Vcard for the current Contact * * @return void */ function generateVcard() { if (!$this->can($this->fields['id'], READ)) { return; } // build the Vcard $vcard = new VObject\Component\VCard([ 'N' => [$this->fields["name"], $this->fields["firstname"]], 'EMAIL' => $this->fields["email"], 'NOTE' => $this->fields["comment"], ]); $vcard->add('TEL', $this->fields["phone"], ['type' => 'PREF;WORK;VOICE']); $vcard->add('TEL', $this->fields["phone2"], ['type' => 'HOME;VOICE']); $vcard->add('TEL', $this->fields["mobile"], ['type' => 'WORK;CELL']); $vcard->add('URL', $this->GetWebsite(), ['type' => 'WORK']); $addr = $this->GetAddress(); if (is_array($addr)) { $addr_string = implode(";", array_filter($addr)); $vcard->add('ADR', $addr_string, ['type' => 'WORK;POSTAL']); } // send the VCard $output = $vcard->serialize(); $filename = $this->fields["name"]."_".$this->fields["firstname"].".vcf"; @header("Content-Disposition: attachment; filename=\"$filename\""); @header("Content-Length: ".Toolbox::strlen($output)); @header("Connection: close"); @header("content-type: text/x-vcard; charset=UTF-8"); echo $output; } static function getIcon() { return "fas fa-user-tie"; } }