From 9b7afbc29b16acb8a0868e48494dba857a0906c7 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Mar 2012 18:03:36 +0100 Subject: [PATCH] Works on alternative addresses management --- htdocs/comm/address.php | 156 ++++++++++++------------- htdocs/comm/fiche.php | 6 + htdocs/core/class/conf.class.php | 1 + htdocs/fourn/fiche.php | 6 + htdocs/langs/fr_FR/companies.lang | 2 +- htdocs/societe/class/address.class.php | 139 ++++++++++------------ 6 files changed, 155 insertions(+), 155 deletions(-) diff --git a/htdocs/comm/address.php b/htdocs/comm/address.php index 67d64507315..b4059a94445 100644 --- a/htdocs/comm/address.php +++ b/htdocs/comm/address.php @@ -31,12 +31,13 @@ require_once(DOL_DOCUMENT_ROOT."/societe/class/address.class.php"); $langs->load("companies"); $langs->load("commercial"); -$id = GETPOST('id','int'); -$action = GETPOST('action','alpha'); -$confirm = GETPOST('confirm','alpha'); -$origin = GETPOST('origin','alpha'); -$originid = GETPOST('originid','int'); -$socid = GETPOST('socid','int'); +$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 @@ -50,19 +51,23 @@ $object = new Address($db); * Actions */ +// Cancel +if (GETPOST("cancel") && ! 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->cp = $_POST["zipcode"]; - $object->ville = $_POST["town"]; $object->zip = $_POST["zipcode"]; $object->town = $_POST["town"]; - $object->pays_id = $_POST["country_id"]; $object->country_id = $_POST["country_id"]; - $object->tel = $_POST["tel"]; + $object->phone = $_POST["phone"]; $object->fax = $_POST["fax"]; $object->note = $_POST["note"]; @@ -73,7 +78,12 @@ if ($action == 'add' || $action == 'update') if ($result >= 0) { - if ($origin == 'commande') + if (! empty($backtopage)) + { + Header("Location: ".$backtopage); + exit; + } + else if ($origin == 'commande') { Header("Location: ../commande/contact.php?action=editdelivery_adress&socid=".$socid."&id=".$originid); exit; @@ -108,7 +118,12 @@ if ($action == 'add' || $action == 'update') if ($result >= 0) { - if ($origin == 'commande') + if (! empty($backtopage)) + { + Header("Location: ".$backtopage); + exit; + } + else if ($origin == 'commande') { Header("Location: ../commande/contact.php?id=".$originid); exit; @@ -177,46 +192,32 @@ if ($action == 'create') * Creation */ - $societe=new Societe($db); - $societe->fetch($socid); - $head = societe_prepare_head($societe); - - dol_fiche_head($head, 'customer', $societe->nom); - if ($_POST["label"] && $_POST["name"]) { $object->socid = $socid; $object->label = $_POST["label"]; $object->name = $_POST["name"]; $object->address = $_POST["address"]; - $object->cp = $_POST["zipcode"]; - $object->ville = $_POST["town"]; - $object->tel = $_POST["tel"]; + $object->zip = $_POST["zipcode"]; + $object->town = $_POST["town"]; + $object->phone = $_POST["phone"]; $object->fax = $_POST["fax"]; $object->note = $_POST["note"]; } // On positionne pays_id, pays_code et libelle du pays choisi - $object->country_id=$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id; + $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->pays_code = $tmparray['code']; - $object->pays = $tmparray['label']; $object->country_code = $tmparray['code']; $object->country = $tmparray['label']; } + + print_fiche_titre($langs->trans("AddAddress")); - print_titre($langs->trans("AddAddress")); print "
\n"; - if ($object->error) - { - print '
'; - print nl2br($object->error); - print '
'; - } - // If javascript enabled, we add interactivity on mandatory fields if ($conf->use_javascript_ajax) { @@ -243,11 +244,12 @@ if ($action == 'create') } print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; @@ -260,19 +262,19 @@ if ($action == 'create') // Zip print ''; // Town print ''; print ''; - print ''; + print ''; print ''; @@ -283,7 +285,13 @@ if ($action == 'create') print '
'.$langs->trans('Zip').''; - print $formcompany->select_ziptown($object->cp,'zipcode',array('town','selectcountry_id'),6); + print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id'),6); print '
'.$langs->trans('Town').''; - print $formcompany->select_ziptown($object->ville,'town',array('zipcode','selectcountry_id')); + 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('Phone').'
'.$langs->trans('Fax').'
'."\n"; print '
'; - print '
'."\n"; + print ''; + if (! empty($backtopage)) + { + print '     '; + print ''; + } + print ''."\n"; print '
'."\n"; @@ -299,7 +307,7 @@ elseif ($action == 'edit') $societe->fetch($socid); $head = societe_prepare_head($societe); - dol_fiche_head($head, 'customer', $societe->nom); + dol_fiche_head($head, 'card', $societe->nom); print_titre($langs->trans("EditAddress")); print "
\n"; @@ -318,10 +326,10 @@ elseif ($action == 'edit') $object->label = $_POST["label"]; $object->name = $_POST["name"]; $object->address = $_POST["address"]; - $object->cp = $_POST["zipcode"]; - $object->ville = $_POST["town"]; + $object->zip = $_POST["zipcode"]; + $object->town = $_POST["town"]; $object->country_id = $_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id; - $object->tel = $_POST["tel"]; + $object->phone = $_POST["phone"]; $object->fax = $_POST["fax"]; $object->note = $_POST["note"]; @@ -329,27 +337,19 @@ elseif ($action == 'edit') if ($object->country_id) { $tmparray=getCountry($object->country_id,'all'); - $object->pays_code = $tmparray['code']; - $object->pays = $tmparray['label']; $object->country_code = $tmparray['code']; $object->country = $tmparray['label']; } } - if ($object->error) - { - print '
'; - print $object->error; - print '
'; - } - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; @@ -362,29 +362,34 @@ elseif ($action == 'edit') // Zip print ''; // Town print ''; print ''; - print ''; + print ''; print ''; print ''; - - print ''; - - print '
'.$langs->trans('Zip').''; - print $formcompany->select_ziptown($object->cp,'zipcode',array('town','selectcountry_id'),6); + print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id'),6); print '
'.$langs->trans('Town').''; - print $formcompany->select_ziptown($object->ville,'town',array('zipcode','selectcountry_id')); + 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('Phone').'
'.$langs->trans('Fax').'
'.$langs->trans('Note').'
'; + + print '
'; + + print '
'; + print ''; + print '   '; + print ''; + print '
'; + print '
'; } } @@ -409,20 +414,13 @@ else // Confirmation delete - if ($_GET["action"] == 'delete') + if ($action == 'delete') { $form = new Form($db); $ret=$form->form_confirm($_SERVER['PHP_SELF']."?socid=".$object->socid."&id=".$id,$langs->trans("DeleteAddress"),$langs->trans("ConfirmDeleteAddress"),"confirm_delete"); if ($ret == 'html') print '
'; } - if ($object->error) - { - print '
'; - print $object->error; - print '
'; - } - $nblines = count($object->lines); if ($nblines) { @@ -437,12 +435,12 @@ else print "".$langs->trans('Address')."".nl2br($object->lines[$i]->address).""; - print ''.$langs->trans('Zip').''.$object->lines[$i]->cp.""; - print ''.$langs->trans('Town').''.$object->lines[$i]->ville.""; + print ''.$langs->trans('Zip').''.$object->lines[$i]->zip.""; + print ''.$langs->trans('Town').''.$object->lines[$i]->town.""; - print ''.$langs->trans('Country').''.$object->lines[$i]->pays.''; + print ''.$langs->trans('Country').''.$object->lines[$i]->country.''; - print ''.$langs->trans('Phone').''.dol_print_phone($object->lines[$i]->tel,$object->lines[$i]->country_code,0,$object->socid,'AC_TEL').''; + print ''.$langs->trans('Phone').''.dol_print_phone($object->lines[$i]->phone,$object->lines[$i]->country_code,0,$object->socid,'AC_TEL').''; print ''.$langs->trans('Fax').''.dol_print_phone($object->lines[$i]->fax,$object->lines[$i]->country_code,0,$object->socid,'AC_FAX').''; diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index bd9b94f9f4a..0787a99c1ad 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -795,6 +795,12 @@ if ($id > 0) // List of contacts show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id); } + + // Addresses list + if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB)) + { + $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id); + } if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB)) { diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index afb1767514e..455ded86c93 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -221,6 +221,7 @@ class Conf // By default, we repeat info on all tabs if (! isset($this->global->MAIN_REPEATCONTACTONEACHTAB)) $this->global->MAIN_REPEATCONTACTONEACHTAB=1; + if (! isset($this->global->MAIN_REPEATADDRESSONEACHTAB)) $this->global->MAIN_REPEATADDRESSONEACHTAB=1; $rootfordata = DOL_DATA_ROOT; $rootforuser = DOL_DATA_ROOT; diff --git a/htdocs/fourn/fiche.php b/htdocs/fourn/fiche.php index 97548155956..c0efba8e80e 100644 --- a/htdocs/fourn/fiche.php +++ b/htdocs/fourn/fiche.php @@ -403,6 +403,12 @@ if ($object->fetch($id)) // List of contacts show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?id='.$object->id); } + + // Addresses list + if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB)) + { + $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id); + } if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB)) { diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index f508a6b351d..4be4314a0b1 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -345,7 +345,7 @@ DeleteDeliveryAddress=Supprimer une adresse de livraison ConfirmDeleteDeliveryAddress=Êtes-vous sûr de vouloir supprimer cette adresse de livraison ? NewDeliveryAddress=Nouvelle adresse de livraison AddDeliveryAddress=Ajouter l'adresse -AddAddress=Ajouter adresse +AddAddress=Créer adresse NoOtherDeliveryAddress=Pas d'adresse alternative définie SupplierCategory=Catégorie du fournisseur CardSupplier=Fiche Fournisseur diff --git a/htdocs/societe/class/address.class.php b/htdocs/societe/class/address.class.php index 31c42f2fa5e..bf6cceabab0 100644 --- a/htdocs/societe/class/address.class.php +++ b/htdocs/societe/class/address.class.php @@ -57,7 +57,7 @@ class Address * * @param DoliDB $db Database handler */ - function Address($db) + function __construct($db) { $this->db = $db; } @@ -77,7 +77,7 @@ class Address $this->name = trim($this->name); $this->label = trim($this->label); - dol_syslog("Address::create label=".$this->label); + dol_syslog(get_class($this)."::create label=".$this->label); $this->db->begin(); @@ -97,13 +97,13 @@ class Address if ($ret >= 0) { - dol_syslog("Address::create success id=".$this->id); + dol_syslog(get_class($this)."::create success id=".$this->id); $this->db->commit(); return 0; } else { - dol_syslog("Address::create echec update"); + dol_syslog(get_class($this)."::create echec update"); $this->db->rollback(); return -3; } @@ -118,7 +118,7 @@ class Address } else { - dol_syslog("Address::create echec insert sql=$sql"); + dol_syslog(get_class($this)."::create echec insert sql=$sql"); } $this->db->rollback(); return -2; @@ -128,7 +128,7 @@ class Address else { $this->db->rollback(); - dol_syslog("Address::create echec verify sql=$sql"); + dol_syslog(get_class($this)."::create echec verify sql=$sql"); return -1; } } @@ -165,80 +165,70 @@ class Address { global $langs; - dol_syslog("Address::Update"); - - // Nettoyage des parametres - - $this->fk_soc = $socid; - $this->label = trim($this->label); - $this->name = trim($this->name); - $this->address = trim($this->address); - $this->cp = trim($this->cp); - $this->ville = trim($this->ville); - $this->pays_id = trim($this->pays_id); + // 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->tel = trim($this->tel); - $this->tel = preg_replace("/\s/","",$this->tel); - $this->tel = preg_replace("/\./","",$this->tel); - $this->fax = trim($this->fax); - $this->fax = preg_replace("/\s/","",$this->fax); - $this->fax = preg_replace("/\./","",$this->fax); - $this->note = trim($this->note); + $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 nom et label obligatoire if ($result >= 0) { - dol_syslog("Address::Update verify ok"); + 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->db->escape($this->address) ."'"; - - if ($this->cp) - { $sql .= ",cp = '" . $this->cp ."'"; } - - if ($this->ville) - { $sql .= ",ville = '" . $this->db->escape($this->ville) ."'"; } - - $sql .= ",fk_pays = '" . ($this->country_id?$this->country_id:'0') ."'"; - $sql.= ",note = '" . $this->db->escape($this->note) ."'"; - - if ($this->tel) - { $sql .= ",tel = '" . $this->tel ."'"; } - - if ($this->fax) - { $sql .= ",fax = '" . $this->fax ."'"; } - + $sql.= ", name = '" . $this->db->escape($this->name) ."'"; // Champ obligatoire + $sql.= ", address = ".($this->address?"'".$this->db->escape($this->address)."'":"null"); + $sql.= ", cp = ".($this->zip?"'".$this->db->escape($this->zip)."'":"null"); + $sql.= ", ville = ".($this->town?"'".$this->db->escape($this->town)."'":"null"); + $sql.= ", fk_pays = '" . ($this->country_id?$this->country_id:'0') ."'"; + $sql.= ", note = ".($this->note?"'".$this->db->escape($this->note)."'":"null"); + $sql.= ", tel = ".($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 = '" . $id ."'"; - + + dol_syslog(get_class($this)."::Update sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); - if ($resql) + if ($resql) + { + dol_syslog(get_class($this)."::Update success"); + $this->db->commit(); + return 1; + } + else { - $result = 1; - } - else - { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - // Doublon - $this->error = $langs->trans("ErrorDuplicateField"); - $result = -1; - } - else - { - - $this->error = $langs->trans("Error sql=$sql"); - dol_syslog("Address::Update echec sql=$sql"); - $result = -2; - } + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + + $this->error=$langs->trans("ErrorDuplicateField",$this->name); + $result=-1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::Update error sql=".$sql, LOG_ERR); + $result=-2; + } + $this->db->rollback(); + return $result; } } - return $result; - } /** @@ -257,7 +247,6 @@ class Address $sql .= ' WHERE rowid = '.$socid; $resqlsoc=$this->db->query($sql); - if ($resqlsoc) { if ($this->db->num_rows($resqlsoc)) @@ -328,19 +317,19 @@ class Address } else { - dol_syslog('Address::Fetch Erreur: aucune adresse'); + dol_syslog(get_class($this).'::Fetch Erreur: aucune adresse', LOG_ERR); return 0; } } else { - dol_syslog('Address::Fetch Erreur: societe inconnue'); + dol_syslog(get_class($this).'::Fetch Erreur: societe inconnue', LOG_ERR); return -1; } } else { - dol_syslog('Societe::Fetch '.$this->db->error()); + dol_syslog(get_class($this).'::Fetch '.$this->db->error(), LOG_ERR); $this->error=$this->db->error(); } } @@ -508,13 +497,13 @@ class AddressLine var $date_update; var $label; var $name; - var $adresse; - var $cp; - var $ville; - var $pays_id; - var $pays_code; - var $pays; - var $tel; + var $address; + var $zip; + var $town; + var $country_id; + var $country_code; + var $country; + var $phone; var $fax; var $note;