From 9821a2d9be876ed6b90437127b9f9398525a5781 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Mar 2012 09:51:35 +0100 Subject: [PATCH] Fix: uniformize code again --- htdocs/comm/address.php | 227 +++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 117 deletions(-) diff --git a/htdocs/comm/address.php b/htdocs/comm/address.php index ce06caced86..b85da09d0ed 100644 --- a/htdocs/comm/address.php +++ b/htdocs/comm/address.php @@ -20,7 +20,7 @@ /** * \file htdocs/comm/address.php * \ingroup societe - * \brief Tab address of customer + * \brief Tab address of thirdparty */ require("../main.inc.php"); @@ -33,6 +33,7 @@ $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'); @@ -42,6 +43,8 @@ if (! $socid && ($action != 'create' && $action != 'add' && $action != 'update') if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe', $socid); +$object = new Address($db); + /* * Actions @@ -49,28 +52,24 @@ $result = restrictedArea($user, 'societe', $socid); if ($action == 'add' || $action == 'update') { - $address = new Address($db); - - $address->socid = $socid; - $address->label = ($_POST["label"]!=$langs->trans('RequiredField')?$_POST["label"]:''); - $address->name = ($_POST["name"]!=$langs->trans('RequiredField')?$_POST["name"]:''); - $address->address = $_POST["address"]; - $address->cp = $_POST["zipcode"]; - $address->ville = $_POST["town"]; - $address->zip = $_POST["zipcode"]; - $address->town = $_POST["town"]; - $address->pays_id = $_POST["country_id"]; - $address->country_id= $_POST["country_id"]; - $address->tel = $_POST["tel"]; - $address->fax = $_POST["fax"]; - $address->note = $_POST["note"]; - + $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->fax = $_POST["fax"]; + $object->note = $_POST["note"]; + + // Add new address if ($action == 'add') { - $socid = $socid; - $origin = $origin; - $originid = $originid; - $result = $address->create($socid, $user); + $result = $object->create($socid, $user); if ($result >= 0) { @@ -97,17 +96,15 @@ if ($action == 'add' || $action == 'update') } else { - $mesg = $address->error; + $mesg = $object->error; $action='create'; } } - - if ($action == 'update') + + // Update address + else if ($action == 'update') { - $socid = $_POST["socid"]; - $origin = $_POST["origin"]; - $originid = $_POST["originid"]; - $result = $address->update($_POST["id"], $socid, $user); + $result = $object->update($_POST["id"], $socid, $user); if ($result >= 0) { @@ -135,17 +132,16 @@ if ($action == 'add' || $action == 'update') else { $reload = 0; - $mesg = $address->error; + $mesg = $object->error; $actino= "edit"; } } } -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) +else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) { - $address = new Address($db); - $result = $address->delete($id, $socid); + $result = $object->delete($id, $socid); if ($result == 0) { @@ -155,7 +151,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe-> else { $reload = 0; - $_GET["action"]=''; + $action=''; } } @@ -181,8 +177,6 @@ if ($action == 'create') * Creation */ - $address = new Address($db); - $societe=new Societe($db); $societe->fetch($socid); $head = societe_prepare_head($societe); @@ -191,35 +185,35 @@ if ($action == 'create') if ($_POST["label"] && $_POST["name"]) { - $address->socid = $_POST["socid"]; - $address->label = $_POST["label"]; - $address->name = $_POST["name"]; - $address->address = $_POST["address"]; - $address->cp = $_POST["zipcode"]; - $address->ville = $_POST["town"]; - $address->tel = $_POST["tel"]; - $address->fax = $_POST["fax"]; - $address->note = $_POST["note"]; + $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->fax = $_POST["fax"]; + $object->note = $_POST["note"]; } // On positionne pays_id, pays_code et libelle du pays choisi - $address->country_id=$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id; - if ($address->country_id) + $object->country_id=$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id; + if ($object->country_id) { - $tmparray=getCountry($address->country_id,'all'); - $address->pays_code = $tmparray['code']; - $address->pays = $tmparray['label']; - $address->country_code = $tmparray['code']; - $address->country = $tmparray['label']; + $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_titre($langs->trans("AddAddress")); print "
\n"; - if ($address->error) + if ($object->error) { print '
'; - print nl2br($address->error); + print nl2br($object->error); print '
'; } @@ -257,33 +251,33 @@ if ($action == 'create') print ''; - print ''; - print ''; + print ''; + print ''; print ''; // Zip print ''; // Town print ''; print ''; - print ''; + print ''; - print ''; + print ''; print ''; print '
'.$langs->trans('Label').'
'.$langs->trans('Name').'
'.$langs->trans('Label').'
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; - print $formcompany->select_ziptown($address->cp,'zipcode',array('town','selectcountry_id'),6); + print $formcompany->select_ziptown($object->cp,'zipcode',array('town','selectcountry_id'),6); print '
'.$langs->trans('Town').''; - print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectcountry_id')); + print $formcompany->select_ziptown($object->ville,'town',array('zipcode','selectcountry_id')); print '
'.$langs->trans('Country').''; - print $form->select_country($address->country_id,'selectcountry_id'); + print $form->select_country($object->country_id,'selectcountry_id'); print '
'.$langs->trans('Phone').'
'.$langs->trans('Phone').'
'.$langs->trans('Fax').'
'.$langs->trans('Fax').'
'.$langs->trans('Note').'
'."\n"; @@ -300,10 +294,9 @@ elseif ($action == 'edit') /* * Fiche societe en mode edition */ - $address = new Address($db); $societe=new Societe($db); - $societe->fetch($_GET["socid"]); + $societe->fetch($socid); $head = societe_prepare_head($societe); dol_fiche_head($head, 'customer', $societe->nom); @@ -315,78 +308,78 @@ elseif ($action == 'edit') { if ($reload || ! $_POST["name"]) { - $address->socid = $socid; - $address->fetch_address($id); + $object->socid = $socid; + $object->fetch_address($id); } else { - $address->id = $id; - $address->socid = $socid; - $address->label = $_POST["label"]; - $address->name = $_POST["name"]; - $address->address = $_POST["address"]; - $address->cp = $_POST["zipcode"]; - $address->ville = $_POST["town"]; - $address->country_id = $_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id; - $address->tel = $_POST["tel"]; - $address->fax = $_POST["fax"]; - $address->note = $_POST["note"]; + $object->id = $id; + $object->socid = $socid; + $object->label = $_POST["label"]; + $object->name = $_POST["name"]; + $object->address = $_POST["address"]; + $object->cp = $_POST["zipcode"]; + $object->ville = $_POST["town"]; + $object->country_id = $_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id; + $object->tel = $_POST["tel"]; + $object->fax = $_POST["fax"]; + $object->note = $_POST["note"]; // On positionne country_id, pays_code et libelle du pays choisi - if ($address->country_id) + if ($object->country_id) { - $tmparray=getCountry($address->country_id,'all'); - $address->pays_code = $tmparray['code']; - $address->pays = $tmparray['label']; - $address->country_code = $tmparray['code']; - $address->country = $tmparray['label']; + $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 ($address->error) + if ($object->error) { print '
'; - print $address->error; + print $object->error; print '
'; } - print '
'; + print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; - print ''; - print ''; + print ''; + print ''; print ''; // Zip print ''; // Town print ''; print ''; - print ''; + print ''; - print ''; + print ''; print ''; print ''; @@ -400,16 +393,16 @@ else /* * Fiche societe en mode visu */ - $address = new Address($db); - $result=$address->fetch_lines($socid); + + $result=$object->fetch_lines($socid); if ($result < 0) { - dol_print_error($db,$address->error); + dol_print_error($db,$object->error); exit; } $societe=new Societe($db); - $societe->fetch($address->socid); + $societe->fetch($object->socid); $head = societe_prepare_head($societe); dol_fiche_head($head, 'customer', $societe->nom); @@ -419,18 +412,18 @@ else if ($_GET["action"] == 'delete') { $form = new Form($db); - $ret=$form->form_confirm($_SERVER['PHP_SELF']."?socid=".$address->socid."&id=".$_GET["id"],$langs->trans("DeleteAddress"),$langs->trans("ConfirmDeleteAddress"),"confirm_delete"); + $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 ($address->error) + if ($object->error) { print '
'; - print $address->error; + print $object->error; print '
'; } - $nblines = count($address->lines); + $nblines = count($object->lines); if ($nblines) { for ($i = 0 ; $i < $nblines ; $i++) @@ -438,20 +431,20 @@ else print '
'.$langs->trans('AddressLabel').'
'.$langs->trans('Name').'
'.$langs->trans('AddressLabel').'
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; - print $formcompany->select_ziptown($address->cp,'zipcode',array('town','selectcountry_id'),6); + print $formcompany->select_ziptown($object->cp,'zipcode',array('town','selectcountry_id'),6); print '
'.$langs->trans('Town').''; - print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectcountry_id')); + print $formcompany->select_ziptown($object->ville,'town',array('zipcode','selectcountry_id')); print '
'.$langs->trans('Country').''; - print $form->select_country($address->country_id,'country_id'); + print $form->select_country($object->country_id,'country_id'); print '
'.$langs->trans('Phone').'
'.$langs->trans('Phone').'
'.$langs->trans('Fax').'
'.$langs->trans('Fax').'
'.$langs->trans('Note').'
'; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; - print ""; + print ""; - print '"; - print '"; + print '"; + print '"; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; print ''; @@ -466,12 +459,12 @@ else if ($user->rights->societe->creer) { - print ''.$langs->trans("Modify").''; + print ''.$langs->trans("Modify").''; } if ($user->rights->societe->supprimer) { - print ''.$langs->trans("Delete").''; + print ''.$langs->trans("Delete").''; } @@ -496,7 +489,7 @@ else if ($user->rights->societe->creer) { - print ''.$langs->trans("Add").''; + print ''.$langs->trans("Add").''; } print ''; }
'.$langs->trans('AddressLabel').''.$address->lines[$i]->label.''.$langs->trans('Note').' :
'.nl2br($address->lines[$i]->note).'
'.$langs->trans('Name').''.$address->lines[$i]->name.'
'.$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($address->lines[$i]->address)."
".$langs->trans('Address')."".nl2br($object->lines[$i]->address)."
'.$langs->trans('Zip').''.$address->lines[$i]->cp."
'.$langs->trans('Town').''.$address->lines[$i]->ville."
'.$langs->trans('Zip').''.$object->lines[$i]->cp."
'.$langs->trans('Town').''.$object->lines[$i]->ville."
'.$langs->trans('Country').''.$address->lines[$i]->pays.'
'.$langs->trans('Country').''.$object->lines[$i]->pays.'
'.$langs->trans('Phone').''.dol_print_phone($address->lines[$i]->tel,$address->lines[$i]->country_code,0,$address->socid,'AC_TEL').'
'.$langs->trans('Phone').''.dol_print_phone($object->lines[$i]->tel,$object->lines[$i]->country_code,0,$object->socid,'AC_TEL').'
'.$langs->trans('Fax').''.dol_print_phone($address->lines[$i]->fax,$address->lines[$i]->country_code,0,$address->socid,'AC_FAX').'
'.$langs->trans('Fax').''.dol_print_phone($object->lines[$i]->fax,$object->lines[$i]->country_code,0,$object->socid,'AC_FAX').'