diff --git a/htdocs/comm/address.php b/htdocs/comm/address.php deleted file mode 100644 index 878968478b8..00000000000 --- a/htdocs/comm/address.php +++ /dev/null @@ -1,492 +0,0 @@ - - * Copyright (C) 2004-2006 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/comm/address.php - * \ingroup societe - * \brief Tab address of thirdparty - */ - -require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; -require_once DOL_DOCUMENT_ROOT.'/societe/class/address.class.php'; - -// Load translation files required by the page -$langs->loadLangs(array('companies', 'commercial')); - -$id = GETPOST('id', 'int'); -$action = GETPOST('action', 'alpha'); -$confirm = GETPOST('confirm', 'alpha'); -$backtopage = GETPOST('backtopage', 'alpha'); -$origin = GETPOST('origin', 'alpha'); -$originid = GETPOST('originid', 'int'); -$socid = GETPOST('socid', 'int'); -if (! $socid && ($action != 'create' && $action != 'add' && $action != 'update')) accessforbidden(); - -// Security check -if ($user->societe_id) $socid=$user->societe_id; -$result = restrictedArea($user, 'societe', $socid); - -$object = new Address($db); - - -/* - * Actions - */ - -// Cancel -if (GETPOST('cancel', 'alpha') && ! empty($backtopage)) -{ - header("Location: ".$backtopage); - exit; -} - -if ($action == 'add' || $action == 'update') -{ - $object->socid = $socid; - $object->label = ($_POST["label"]!=$langs->trans('RequiredField')?$_POST["label"]:''); - $object->name = ($_POST["name"]!=$langs->trans('RequiredField')?$_POST["name"]:''); - $object->address = $_POST["address"]; - $object->zip = $_POST["zipcode"]; - $object->town = $_POST["town"]; - $object->country_id = $_POST["country_id"]; - $object->phone = $_POST["phone"]; - $object->fax = $_POST["fax"]; - $object->note = $_POST["note"]; - - // Add new address - if ($action == 'add') - { - $result = $object->create($socid, $user); - - if ($result >= 0) - { - if (! empty($backtopage)) - { - header("Location: ".$backtopage); - exit; - } - elseif ($origin == 'commande') - { - header("Location: ../commande/contact.php?action=editdelivery_adress&socid=".$socid."&id=".$originid); - exit; - } - elseif ($origin == 'propal') - { - header("Location: ../comm/propal/contact.php?action=editdelivery_adress&socid=".$socid."&id=".$originid); - exit; - } - elseif ($origin == 'shipment') - { - header("Location: ../expedition/card.php?id=".$originid); - exit; - } - else - { - header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); - exit; - } - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - $action='create'; - } - } - - // Update address - elseif ($action == 'update') - { - $result = $object->update($id, $socid, $user); - - if ($result >= 0) - { - if (! empty($backtopage)) - { - header("Location: ".$backtopage); - exit; - } - elseif ($origin == 'commande') - { - header("Location: ../commande/contact.php?id=".$originid); - exit; - } - elseif ($origin == 'propal') - { - header("Location: ../comm/propal/contact.php?id=".$originid); - exit; - } - elseif ($origin == 'shipment') - { - header("Location: ../expedition/card.php?id=".$originid); - exit; - } - else - { - header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); - exit; - } - } - else - { - $reload = 0; - setEventMessages($object->error, $object->errors, 'errors'); - $action= "edit"; - } - } -} - -elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) -{ - $result = $object->delete($id, $socid); - - if ($result == 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); - exit ; - } - else - { - $reload = 0; - $action=''; - } -} - -/** - * - * - */ - -llxHeader(); - -$form = new Form($db); -$formcompany = new FormCompany($db); -$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; - -if ($action == 'create') -{ - if ($user->rights->societe->creer) - { - /* - * Creation - */ - - if ($_POST["label"] && $_POST["name"]) - { - $object->socid = $socid; - $object->label = $_POST["label"]; - $object->name = $_POST["name"]; - $object->address = $_POST["address"]; - $object->zip = $_POST["zipcode"]; - $object->town = $_POST["town"]; - $object->phone = $_POST["phone"]; - $object->fax = $_POST["fax"]; - $object->note = $_POST["note"]; - } - - // On positionne country_id, country_code and label of the chosen country - $object->country_id = (GETPOST('country_id', 'int') ? GETPOST('country_id', 'int') : $mysoc->country_id); - if ($object->country_id) - { - $tmparray=getCountry($object->country_id, 'all'); - $object->country_code = $tmparray['code']; - $object->country = $tmparray['label']; - } - - print load_fiche_titre($langs->trans("AddAddress")); - - print "
\n"; - - // If javascript enabled, we add interactivity on mandatory fields - if ($conf->use_javascript_ajax) - { - print "\n".''."\n"; - } - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - - print ''; - print ''; - - print ''; - - // Zip - print ''; - - // Town - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print '
'.$langs->trans('Label').'
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; - print $formcompany->select_ziptown($object->zip, 'zipcode', array('town','selectcountry_id'), 6); - print '
'.$langs->trans('Town').''; - print $formcompany->select_ziptown($object->town, 'town', array('zipcode','selectcountry_id')); - print '
'.$langs->trans('Country').''; - print $form->select_country($object->country_id, 'selectcountry_id'); - print '
'.$langs->trans('Phone').'
'.$langs->trans('Fax').'
'.$langs->trans('Note').'
'."\n"; - - print '
'; - print ''; - if (! empty($backtopage)) - { - print '     '; - print ''; - } - print '
'."\n"; - - print '
'."\n"; - } -} -elseif ($action == 'edit') -{ - /* - * Fiche societe en mode edition - */ - - $societe=new Societe($db); - $societe->fetch($socid); - $head = societe_prepare_head($societe); - - dol_fiche_head($head, 'card', $societe->name); - - print load_fiche_titre($langs->trans("EditAddress")); - print "
\n"; - - if ($socid) - { - if ($reload || ! $_POST["name"]) - { - $object->socid = $socid; - $object->fetch_address($id); - } - else - { - $object->id = $id; - $object->socid = $socid; - $object->label = $_POST["label"]; - $object->name = $_POST["name"]; - $object->address = $_POST["address"]; - $object->zip = $_POST["zipcode"]; - $object->town = $_POST["town"]; - $object->country_id = $_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id; - $object->phone = $_POST["phone"]; - $object->fax = $_POST["fax"]; - $object->note = $_POST["note"]; - - // On positionne country_id, country_code and label of the chosen country - if ($object->country_id) - { - $tmparray=getCountry($object->country_id, 'all'); - $object->country_code = $tmparray['code']; - $object->country = $tmparray['label']; - } - } - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - - print ''; - print ''; - - print ''; - - // Zip - print ''; - - // Town - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print '
'.$langs->trans('AddressLabel').'
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; - print $formcompany->select_ziptown($object->zip, 'zipcode', array('town','selectcountry_id'), 6); - print '
'.$langs->trans('Town').''; - print $formcompany->select_ziptown($object->town, 'town', array('zipcode','selectcountry_id')); - print '
'.$langs->trans('Country').''; - print $form->select_country($object->country_id, 'country_id'); - print '
'.$langs->trans('Phone').'
'.$langs->trans('Fax').'
'.$langs->trans('Note').'

'; - - print '
'; - print ''; - print '     '; - print ''; - print '
'; - - print '
'; - } -} -else -{ - /* - * Fiche societe en mode visu - */ - - $result=$object->fetch_lines($socid); - if ($result < 0) - { - dol_print_error($db, $object->error); - exit; - } - - $societe=new Societe($db); - $societe->fetch($object->socid); - $head = societe_prepare_head($societe); - - dol_fiche_head($head, 'customer', $societe->name); - - - // Confirmation delete - if ($action == 'delete') - { - print $form->formconfirm($_SERVER['PHP_SELF']."?socid=".$object->socid."&id=".$id, $langs->trans("DeleteAddress"), $langs->trans("ConfirmDeleteAddress"), "confirm_delete"); - } - - $nblines = count($object->lines); - if ($nblines) - { - for ($i = 0 ; $i < $nblines ; $i++) - { - - print ''; - - print ''; - print ''; - print ''; - - print ""; - - print '"; - print '"; - - print ''; - - print ''; - - print ''; - - print ''; - - print '
'.$langs->trans('AddressLabel').''.$object->lines[$i]->label.''.$langs->trans('Note').' :
'.nl2br($object->lines[$i]->note).'
'.$langs->trans('Name').''.$object->lines[$i]->name.'
".$langs->trans('Address')."".nl2br($object->lines[$i]->address)."
'.$langs->trans('Zip').''.$object->lines[$i]->zip."
'.$langs->trans('Town').''.$object->lines[$i]->town."
'.$langs->trans('Country').''.$object->lines[$i]->country.'
'.$langs->trans('Phone').''.dol_print_phone($object->lines[$i]->phone, $object->lines[$i]->country_code, 0, $object->socid, 'AC_TEL').'
'.$langs->trans('Fax').''.dol_print_phone($object->lines[$i]->fax, $object->lines[$i]->country_code, 0, $object->socid, 'AC_FAX').'
'; - - - /* - * - */ - - print '
'; - - if ($user->rights->societe->creer) - { - print ''; - } - - if ($user->rights->societe->supprimer) - { - print ''; - } - - - print '
'; - print '
'; - } - } - else - { - print $langs->trans("None"); - } - print ''; - - - /* - * Bouton actions - */ - - if ($action == '') - { - print '
'; - - if ($user->rights->societe->creer) - { - print ''; - } - print '
'; - } -} - - -// End of page -llxFooter(); -$db->close(); diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index b60c7d50b02..97beb2464ad 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -956,52 +956,6 @@ class FormOther return $out; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * Show form to select address - * - * @param int $page Page - * @param string $selected Id condition pre-selectionne - * @param int $socid Id of third party - * @param string $htmlname Nom du formulaire select - * @param string $origin Origine de l'appel pour pouvoir creer un retour - * @param int $originid Id de l'origine - * @return void - */ - function form_address($page, $selected, $socid, $htmlname = 'address_id', $origin = '', $originid = '') - { - // phpcs:enable - global $langs,$conf; - global $form; - - if ($htmlname != "none") - { - print '
'; - print ''; - print ''; - $form->select_address($selected, $socid, $htmlname, 1); - print ''; - $langs->load("companies"); - print '   '.$langs->trans("AddAddress").''; - print '
'; - } - else - { - if ($selected) - { - require_once DOL_DOCUMENT_ROOT .'/societe/class/address.class.php'; - $address=new Address($this->db); - $result=$address->fetch_address($selected); - print ''.$address->label.''; - } - else - { - print " "; - } - } - } - - /** * Get array with HTML tabs with boxes of a particular area including personalized choices of user. diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 94a819cee93..be9c660a499 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1166,97 +1166,6 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') return $i; } -/** - * Show html area for list of addresses - * - * @param Conf $conf Object conf - * @param Translate $langs Object langs - * @param DoliDB $db Database handler - * @param Societe $object Third party object - * @param string $backtopage Url to go once address is created - * @return int - */ -function show_addresses($conf, $langs, $db, $object, $backtopage = '') -{ - global $user; - - require_once DOL_DOCUMENT_ROOT.'/societe/class/address.class.php'; - - $addressstatic = new Address($db); - $num = $addressstatic->fetch_lines($object->id); - - $newcardbutton=''; - if ($user->rights->societe->creer) - { - $newcardbutton=''.$langs->trans("AddAddress").''; - $newcardbutton.= ''; - $newcardbutton.= ''; - } - - print "\n"; - print load_fiche_titre($langs->trans("AddressesForCompany"), $newcardbutton, ''); - - print "\n".''."\n"; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ""; - print ""; - - if ($num > 0) - { - foreach ($addressstatic->lines as $address) - { - print ''; - - print ''; - - print ''; - - print ''; - - $img=picto_from_langcode($address->country_code); - print ''; - - // Lien click to dial - print ''; - print ''; - - if ($user->rights->societe->creer) - { - print ''; - } - - print "\n"; - } - } - //else - //{ - //print ''; - //print ''; - //print "\n"; - //} - print "\n
'.$langs->trans("Label").''.$langs->trans("CompanyName").''.$langs->trans("Town").''.$langs->trans("Country").''.$langs->trans("Phone").''.$langs->trans("Fax").' 
'; - $addressstatic->id = $address->id; - $addressstatic->label = $address->label; - print $addressstatic->getNomUrl(1); - print ''.$address->name.''.$address->town.''.($img?$img.' ':'').$address->country.''; - print dol_print_phone($address->phone, $address->country_code, $address->id, $object->id, 'AC_TEL'); - print ''; - print dol_print_phone($address->fax, $address->country_code, $address->id, $object->id, 'AC_FAX'); - print ''; - print ''; - print img_edit(); - print '
'.$langs->trans("NoAddressYetDefined").'
\n"; - - print "
\n"; - - return $num; -} /** * Show html area with actions to do diff --git a/htdocs/societe/class/address.class.php b/htdocs/societe/class/address.class.php deleted file mode 100644 index 9122cdca1e9..00000000000 --- a/htdocs/societe/class/address.class.php +++ /dev/null @@ -1,553 +0,0 @@ - - * Copyright (C) 2004-2014 Laurent Destailleur - * Copyright (C) 2005-2011 Regis Houssin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/societe/class/address.class.php - * \ingroup societe - * \brief File of class to manage addresses. This class is deprecated. - */ - - -/** - * Class to manage addresses - * - * @deprecated This class is dedicated to a not supported and deprecated feature. - */ -class Address -{ - protected $db; - - /** - * @var int ID - */ - public $id; - - public $type; - - /** - * @var string Address label - */ - public $label; - - public $socid; - public $name; - - /** - * @var string Address - */ - public $address; - - public $zip; - public $town; - public $country_id; - public $country_code; - public $phone; - public $fax; - public $note; - - /** - * Adresses liees a la societe - * @var array - */ - public $lines; - - /** - * Constructor - * - * @param DoliDB $db Database handler - * @deprecated - */ - function __construct($db) - { - $this->db = $db; - } - - /** - * Create address into database - * - * @param int $socid Company socid - * @param User $user Object user making creation - * @return int 0 if OK, < 0 if KO - */ - function create($socid, $user = '') - { - global $langs,$conf; - - // Nettoyage parametres - $this->name = trim($this->name); - $this->label = trim($this->label); - - dol_syslog(get_class($this)."::create label=".$this->label); - - $this->db->begin(); - - $result = $this->verify(); - - if ($result >= 0) - { - $now=dol_now(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_address (label, fk_soc, name, datec, fk_user_creat) "; - $sql .= " VALUES ('".$this->db->escape($this->label)."', '".$socid."', '".$this->db->escape($this->name)."', '".$this->db->idate($now)."', '".$user->id."')"; - - $result=$this->db->query($sql); - if ($result) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_address"); - - $ret = $this->update($this->id, $socid, $user); - - if ($ret >= 0) - { - dol_syslog(get_class($this)."::create success id=".$this->id); - $this->db->commit(); - return 0; - } - else - { - dol_syslog(get_class($this)."::create echec update"); - $this->db->rollback(); - return -3; - } - } - else - - { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - - $this->error=$langs->trans("ErrorCompanyNameAlreadyExists", $this->name); - } - - $this->db->rollback(); - return -2; - } - } - else - { - $this->db->rollback(); - dol_syslog(get_class($this)."::create echec verify sql=$sql"); - return -1; - } - } - - - /** - * Verification lors de la modification de l'adresse - * - * @return int 0 if OK, <0 if KO - */ - function verify() - { - $this->label = trim($this->label); - $this->name = trim($this->name); - $result = 0; - if (!$this->name || !$this->label) - { - $this->error = "The name of company and the label can not be empty.\n"; - $result = -2; - } - return $result; - } - - - /** - * Mise a jour des parametres de l'adresse - * - * @param int $id id address - * @param int $socid id third party - * @param User $user Utilisateur qui demande la mise a jour - * @return int <0 if KO, >=0 if OK - */ - function update($id, $socid, $user = '') - { - global $langs; - - // Clean parameters - $this->fk_soc = $socid; - $this->label = trim($this->label); - $this->name = trim($this->name); - $this->address = trim($this->address); - $this->zip = trim($this->zip); - $this->town = trim($this->town); - $this->country_id = trim($this->country_id); - $this->phone = trim($this->phone); - $this->phone = preg_replace("/\s/", "", $this->phone); - $this->phone = preg_replace("/\./", "", $this->phone); - $this->fax = trim($this->fax); - $this->fax = preg_replace("/\s/", "", $this->fax); - $this->fax = preg_replace("/\./", "", $this->fax); - $this->note = trim($this->note); - - $result = $this->verify(); // Verifie que name et label obligatoire - - if ($result >= 0) - { - dol_syslog(get_class($this)."::Update verify ok"); - - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_address"; - $sql.= " SET label = '" . $this->db->escape($this->label) ."'"; // Champ obligatoire - $sql.= ", name = '" . $this->db->escape($this->name) ."'"; // Champ obligatoire - $sql.= ", address = ".($this->address?"'".$this->db->escape($this->address)."'":"null"); - $sql.= ", zip = ".($this->zip?"'".$this->db->escape($this->zip)."'":"null"); - $sql.= ", town = ".($this->town?"'".$this->db->escape($this->town)."'":"null"); - $sql.= ", fk_pays = '" . ($this->country_id?$this->db->escape($this->country_id):'0') ."'"; - $sql.= ", note = ".($this->note?"'".$this->db->escape($this->note)."'":"null"); - $sql.= ", phone = ".($this->phone?"'".$this->db->escape($this->phone)."'":"null"); - $sql.= ", fax = ".($this->fax?"'".$this->db->escape($this->fax)."'":"null"); - if ($user) $sql .= ",fk_user_modif = '".$user->id."'"; - $sql .= " WHERE fk_soc = '" . $socid ."' AND rowid = '" . $this->db->escape($id) ."'"; - - dol_syslog(get_class($this)."::Update", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - dol_syslog(get_class($this)."::Update success"); - $this->db->commit(); - return 1; - } - else - { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - - $this->error=$langs->trans("ErrorDuplicateField", $this->name); - $result=-1; - } - else - { - $this->error=$this->db->lasterror(); - $result=-2; - } - $this->db->rollback(); - return $result; - } - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * Charge depuis la base toutes les adresses d'une societe - * - * @param int $socid Id de la societe a charger en memoire - * @param User $user Objet de l'utilisateur - * @return int >0 si ok, <0 si ko - */ - function fetch_lines($socid, $user = null) - { - // phpcs:enable - global $langs, $conf; - - $sql = 'SELECT rowid, nom as name, client, fournisseur'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe'; - $sql .= ' WHERE rowid = '.$socid; - - $resqlsoc=$this->db->query($sql); - if ($resqlsoc) - { - if ($this->db->num_rows($resqlsoc)) - { - $obj = $this->db->fetch_object($resqlsoc); - - $this->socname = $obj->name; - $this->socid = $obj->rowid; - $this->id = $obj->rowid; - $this->client = $obj->client; - $this->fournisseur = $obj->fournisseur; - } - - $this->db->free($resqlsoc); - - $this->lines = array(); - - // Adresses liees a la societe - if ($this->socid) - { - $sql = 'SELECT a.rowid as id, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification, a.fk_soc'; - $sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax'; - $sql .= ', c.code as country_code, c.label as country'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid'; - $sql .= ' WHERE a.fk_soc = '.$this->socid; - - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $objp = $this->db->fetch_object($resql); - - $line = new AddressLine($this->db); - - $line->id = $objp->id; - $line->date_creation = $this->db->jdate($objp->date_creation); - $line->date_modification = $this->db->jdate($objp->date_modification); - $line->label = $objp->label; - $line->name = $objp->name; - $line->address = $objp->address; - $line->zip = $objp->zip; - $line->town = $objp->town; - $line->country_id = $objp->country_id; - $line->country_code = $objp->country_id?$objp->country_code:''; - $line->country = $objp->country_id?($langs->trans('Country'.$objp->country_code)!='Country'.$objp->country_code?$langs->trans('Country'.$objp->country_code):$objp->country):''; - $line->phone = $objp->phone; - $line->fax = $objp->fax; - $line->note = $objp->note; - - $this->lines[$i] = $line; - $i++; - } - $this->db->free($resql); - return $num; - } - else - { - dol_syslog(get_class($this).'::Fetch Erreur: aucune adresse', LOG_ERR); - return 0; - } - } - else - { - dol_syslog(get_class($this).'::Fetch Erreur: societe inconnue', LOG_ERR); - return -1; - } - } - else - { - $this->error=$this->db->error(); - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * Charge depuis la base l'objet adresse - * - * @param int $id Id de l'adresse a charger en memoire - * @param User $user Objet de l'utilisateur - * @return int >0 si ok, <0 si ko - */ - function fetch_address($id, $user = null) - { - // phpcs:enable - global $langs; - global $conf; - - $sql = 'SELECT a.rowid, a.fk_soc, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification'; - $sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax'; - $sql .= ', c.code as country_code, c.label as country'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid'; - $sql .= ' WHERE a.rowid = '.$id; - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->socid = $obj->fk_soc; - - $this->date_modification = $this->db->jdate($obj->date_modification); - $this->date_creation = $this->db->jdate($obj->date_creation); - - $this->label = $obj->label; - $this->name = $obj->name; - $this->address = $obj->address; - $this->zip = $obj->zip; - $this->town = $obj->town; - - $this->country_id = $obj->country_id; - $this->country_code = $obj->country_id?$obj->country_code:''; - $this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):''; - - $this->phone = $obj->phone; - $this->fax = $obj->fax; - $this->note = $obj->note; - - $result = 1; - } - else - { - dol_syslog('Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql); - $this->error='Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql; - $result = -2; - } - - $this->db->free($resql); - } - else - { - dol_syslog('Erreur Societe::Fetch echec', LOG_DEBUG); - dol_syslog('Erreur Societe::Fetch '.$this->db->error()); - $this->error=$this->db->error(); - $result = -3; - } - - return $result; - } - - - /** - * Suppression d'une adresse - * - * @param int $id id de la societe a supprimer - * @param int $socid id third party - * @return <0 KO >0 OK - */ - function delete($id, $socid) - { - dol_syslog("Address::Delete"); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_address"; - $sql.= " WHERE rowid = ".$id; - $sql.= " AND fk_soc = ".$socid; - - $result = $this->db->query($sql); - - if (!$result) { - return -1; - } - - return 1; - } - - /** - * Return name of address with link (and eventually picto) - * Use $this->id, $this->label, $this->socid - * - * @param int $withpicto Include picto with link - * @param string $option Where the link point to - * @return string String with URL - */ - function getNomUrl($withpicto = 0, $option = '') - { - global $langs; - - $result=''; - $label = $langs->trans("ShowAddress").': '.$this->label; - - $link = ''; - $linkend=''; - - if ($withpicto) $result.=($link.img_object($langs->trans("ShowAddress").': '.$this->label, 'address', 'class="classfortooltip"').$linkend.' '); - $result.=$link.$this->label.$linkend; - return $result; - } - - - /** - * Charge les informations d'ordre info dans l'objet societe - * - * @param int $id id de la societe a charger - * @return void - */ - function info($id) - { - $sql = "SELECT s.rowid, s.nom as name, datec as date_creation, tms as date_modification,"; - $sql.= " fk_user_creat, fk_user_modif"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= " WHERE s.rowid = ".$id; - - $result=$this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - - if ($obj->fk_user_creat) { - $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_creat); - $this->user_creation = $cuser; - } - - if ($obj->fk_user_modif) { - $muser = new User($this->db); - $muser->fetch($obj->fk_user_modif); - $this->user_modification = $muser; - } - $this->ref = $obj->name; - $this->date_creation = $this->db->jdate($obj->date_creation); - $this->date_modification = $this->db->jdate($obj->date_modification); - } - - $this->db->free($result); - } - else - { - dol_print_error($this->db); - } - } -} - - -/** - * Class to manage one address line - */ -class AddressLine -{ - protected $db; - - /** - * @var int ID - */ - public $id; - - public $date_creation; - public $date_modification; - - /** - * @var string stock movements label - */ - public $label; - - public $name; - - /** - * @var string Address - */ - public $address; - - public $zip; - public $town; - public $country_id; - public $country_code; - public $country; - public $phone; - public $fax; - public $note; - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - } -} diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 7f24713913f..38e6bb59ef4 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -61,12 +61,13 @@ class Contacts extends DolibarrApi * * Return an array with contact informations * - * @param int $id ID of contact + * @param int $id ID of contact + * @param int $includecount Count and return also number of elements the contact is used as a link for * @return array|mixed data without useless information * * @throws RestException */ - function get($id) + function get($id, $includecount = 0) { if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { @@ -74,7 +75,7 @@ class Contacts extends DolibarrApi } $result = $this->contact->fetch($id); - $this->contact->load_ref_elements(); + if (!$result) { throw new RestException(404, 'Contact not found'); @@ -85,6 +86,11 @@ class Contacts extends DolibarrApi throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); } + if ($includecount) + { + $this->contact->load_ref_elements(); + } + return $this->_cleanObjectDatas($this->contact); }