From 6bf5132edbe994f4192b913db8a9b0a00943af5a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Mar 2012 12:14:28 +0100 Subject: [PATCH] Works on alternative addresses management --- htdocs/comm/address.php | 2 +- htdocs/comm/fiche.php | 36 ---------- htdocs/core/lib/company.lib.php | 98 ++++++++++++++++++++++++++ htdocs/societe/class/address.class.php | 61 +++++++++------- htdocs/societe/soc.php | 6 ++ 5 files changed, 141 insertions(+), 62 deletions(-) diff --git a/htdocs/comm/address.php b/htdocs/comm/address.php index b85da09d0ed..da525367d7a 100644 --- a/htdocs/comm/address.php +++ b/htdocs/comm/address.php @@ -61,7 +61,7 @@ if ($action == 'add' || $action == 'update') $object->zip = $_POST["zipcode"]; $object->town = $_POST["town"]; $object->pays_id = $_POST["country_id"]; - $object->country_id= $_POST["country_id"]; + $object->country_id = $_POST["country_id"]; $object->tel = $_POST["tel"]; $object->fax = $_POST["fax"]; $object->note = $_POST["note"]; diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index 13b401da34d..1a8d0987e3b 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -365,42 +365,6 @@ if ($id > 0) print ''; } - // Old way to define delivery address (deprecated). - // Now all addresses types (like delivery addresses, invoices addresses,...) are saved as contacts. - if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS) // Hidden deprecated feature. - { - print ''; - print '
'; - print $langs->trans("DeliveriesAddress"); - print ''; - if ($user->rights->societe->creer) - { - print ''.img_edit($langs->trans("Modify")).''; - } - print '
'; - print ''; - - // TODO move to DAO class - $sql = "SELECT count(rowid) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe_address"; - $sql.= " WHERE fk_soc =".$object->id; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $objal = $db->fetch_object($resql); - print $objal->nb?($objal->nb):$langs->trans("NoOtherDeliveryAddress"); - } - else - { - dol_print_error($db); - } - - print ''; - print ''; - } - // Module Adherent if ($conf->adherent->enabled) { diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 2f3c70ee723..5a3e62c61dc 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -593,6 +593,104 @@ 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 Object $object Third party object + * @param string $backtopage Url to go once address is created + * @return void + */ +function show_addresses($conf,$langs,$db,$object,$backtopage='') +{ + global $user; + global $bc; + + require_once(DOL_DOCUMENT_ROOT."/societe/class/address.class.php"); + + $addressstatic = new Address($db); + $num = $addressstatic->fetch_lines($object->id); + + $buttoncreate=''; + if ($user->rights->societe->creer) + { + $buttoncreate=''.$langs->trans("AddAddress").' '.img_picto($langs->trans("AddAddress"),'filenew').''."\n"; + } + + print "\n"; + print_fiche_titre($langs->trans("AddressesForCompany"),$buttoncreate,''); + + print "\n".''."\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + //print ''; + print ""; + print ""; + + if ($num > 0) + { + $var=true; + + foreach ($addressstatic->lines as $address) + { + $var = !$var; + + print ""; + + print ''; + + print ''; + + print ''; + + print ''; + + // Lien click to dial + print ''; + 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("Tel").''.$langs->trans("Fax").''.$langs->trans("EMail").' 
'; + print $address->label; + //print $addressstatic->getNomUrl(1); + print ''.$address->name.''.$address->town.''.$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 dol_print_email($address->email,$address->id,$object->id,'AC_EMAIL'); + 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 index 5dc38d4ab0c..31c42f2fa5e 100644 --- a/htdocs/societe/class/address.class.php +++ b/htdocs/societe/class/address.class.php @@ -38,11 +38,16 @@ class Address var $socid; var $name; var $address; - var $cp; - var $ville; - var $pays_id; - var $pays_code; - var $tel; + var $cp; // deprecated + var $zip; + var $ville; // deprecated + var $town; + var $pays_id; // deprecated + var $country_id; + var $pays_code; // deprecated + var $country_code; + var $tel; // deprecated + var $phone; var $fax; var $note; @@ -290,7 +295,7 @@ class Address { $objp = $this->db->fetch_object($resql); - $line = new AddressLine(); + $line = new AddressLine($this->db); $line->id = $objp->id; $line->date_creation = $this->db->jdate($objp->dc); @@ -298,36 +303,39 @@ class Address $line->label = $objp->label; $line->name = $objp->name; $line->address = $objp->address; - $line->cp = $objp->zip; - $line->ville = $objp->town; $line->zip = $objp->zip; $line->town = $objp->town; - $line->pays_id = $objp->country_id; - $line->pays_code = $objp->country_id?$objp->country_code:''; - $line->pays = $objp->country_id?($langs->trans('Country'.$objp->country_code)!='Country'.$objp->country_code?strtoupper($langs->trans('Country'.$objp->country_code)):$objp->country):''; $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?strtoupper($langs->trans('Country'.$objp->country_code)):$objp->country):''; - $line->tel = $objp->tel; + $line->phone = $objp->tel; $line->fax = $objp->fax; $line->note = $objp->note; + + // deprecated + $line->cp = $line->zip; + $line->ville = $line->town; + $line->pays_id = $line->country_id; + $line->pays_code = $line->country_code; + $line->pays = $line->country; + $line->tel = $line->phone; $this->lines[$i] = $line; $i++; } $this->db->free($resql); - return 1; + return $num; } else { dol_syslog('Address::Fetch Erreur: aucune adresse'); - return -1; + return 0; } } else { dol_syslog('Address::Fetch Erreur: societe inconnue'); - return -2; + return -1; } } else @@ -372,21 +380,24 @@ class Address $this->label = $obj->label; $this->name = $obj->name; $this->address = $obj->address; - $this->cp = $obj->zip; - $this->ville = $obj->town; $this->zip = $obj->zip; $this->town = $obj->town; - $this->pays_id = $obj->country_id; - $this->pays_code = $obj->country_id?$obj->country_code:''; - $this->pays = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):''; - $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->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->tel = $obj->tel; + $this->phone = $obj->tel; $this->fax = $obj->fax; $this->note = $obj->note; + + // deprecated + $line->cp = $line->zip; + $line->ville = $line->town; + $line->pays_id = $line->country_id; + $line->pays_code = $line->country_code; + $line->pays = $line->country; + $line->tel = $line->phone; $result = 1; } @@ -513,7 +524,7 @@ class AddressLine * * @param DoliDB $db Database handler */ - function AddressLine($db) + function __construct($db) { $this->db = $db; } diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index ec22772fab2..a33d0b9b0c8 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -1918,6 +1918,12 @@ else { $result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id); } + + // Addresses list + if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT)) + { + $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id); + } // Projects list $result=show_projects($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);