Fix: uniformize code again

This commit is contained in:
Regis Houssin 2012-03-14 09:51:35 +01:00
parent 6b54f50dd4
commit 9821a2d9be

View File

@ -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 "<br>\n";
if ($address->error)
if ($object->error)
{
print '<div class="error">';
print nl2br($address->error);
print nl2br($object->error);
print '</div>';
}
@ -257,33 +251,33 @@ if ($action == 'create')
print '<table class="border" width="100%">';
print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td><td><input type="text" size="30" name="label" id="label" value="'.($address->label?$address->label:$langs->trans('RequiredField')).'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans('Name').'</td><td><input type="text" size="30" name="name" id="name" value="'.($address->name?$address->name:$langs->trans('RequiredField')).'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td><td><input type="text" size="30" name="label" id="label" value="'.($object->label?$object->label:$langs->trans('RequiredField')).'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans('Name').'</td><td><input type="text" size="30" name="name" id="name" value="'.($object->name?$object->name:$langs->trans('RequiredField')).'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans('Address').'</td><td colspan="3"><textarea name="address" cols="40" rows="3" wrap="soft">';
print $address->address;
print $object->address;
print '</textarea></td></tr>';
// Zip
print '<tr><td>'.$langs->trans('Zip').'</td><td>';
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 '</td></tr>';
// Town
print '<tr><td>'.$langs->trans('Town').'</td><td>';
print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectcountry_id'));
print $formcompany->select_ziptown($object->ville,'town',array('zipcode','selectcountry_id'));
print '</td></tr>';
print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
print $form->select_country($address->country_id,'selectcountry_id');
print $form->select_country($object->country_id,'selectcountry_id');
print '</td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="tel" value="'.$address->tel.'"></td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="tel" value="'.$object->tel.'"></td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td><input type="text" name="fax" value="'.$address->fax.'"></td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td><input type="text" name="fax" value="'.$object->fax.'"></td></tr>';
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3"><textarea name="note" cols="40" rows="6" wrap="soft">';
print $address->note;
print $object->note;
print '</textarea></td></tr>';
print '</table>'."\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 '<div class="error">';
print $address->error;
print $object->error;
print '</div>';
}
print '<form action="'.$_SERVER['PHP_SELF'].'?socid='.$address->socid.'" method="POST" name="formsoc">';
print '<form action="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'" method="POST" name="formsoc">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="socid" value="'.$address->socid.'">';
print '<input type="hidden" name="socid" value="'.$object->socid.'">';
print '<input type="hidden" name="origin" value="'.$origin.'">';
print '<input type="hidden" name="originid" value="'.$originid.'">';
print '<input type="hidden" name="id" value="'.$address->id.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<table class="border" width="100%">';
print '<tr><td>'.$langs->trans('AddressLabel').'</td><td colspan="3"><input type="text" size="40" name="label" value="'.$address->label.'"></td></tr>';
print '<tr><td>'.$langs->trans('Name').'</td><td colspan="3"><input type="text" size="40" name="name" value="'.$address->name.'"></td></tr>';
print '<tr><td>'.$langs->trans('AddressLabel').'</td><td colspan="3"><input type="text" size="40" name="label" value="'.$object->label.'"></td></tr>';
print '<tr><td>'.$langs->trans('Name').'</td><td colspan="3"><input type="text" size="40" name="name" value="'.$object->name.'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans('Address').'</td><td colspan="3"><textarea name="address" cols="40" rows="3" wrap="soft">';
print $address->address;
print $object->address;
print '</textarea></td></tr>';
// Zip
print '<tr><td>'.$langs->trans('Zip').'</td><td>';
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 '</td></tr>';
// Town
print '<tr><td>'.$langs->trans('Town').'</td><td>';
print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectcountry_id'));
print $formcompany->select_ziptown($object->ville,'town',array('zipcode','selectcountry_id'));
print '</td></tr>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
print $form->select_country($address->country_id,'country_id');
print $form->select_country($object->country_id,'country_id');
print '</td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="tel" value="'.$address->tel.'"></td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="tel" value="'.$object->tel.'"></td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td><input type="text" name="fax" value="'.$address->fax.'"></td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td><input type="text" name="fax" value="'.$object->fax.'"></td></tr>';
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3"><textarea name="note" cols="40" rows="6" wrap="soft">';
print $address->note;
print $object->note;
print '</textarea></td></tr>';
print '<tr><td align="center" colspan="4"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td></tr>';
@ -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."&amp;id=".$_GET["id"],$langs->trans("DeleteAddress"),$langs->trans("ConfirmDeleteAddress"),"confirm_delete");
$ret=$form->form_confirm($_SERVER['PHP_SELF']."?socid=".$object->socid."&amp;id=".$id,$langs->trans("DeleteAddress"),$langs->trans("ConfirmDeleteAddress"),"confirm_delete");
if ($ret == 'html') print '<br>';
}
if ($address->error)
if ($object->error)
{
print '<div class="error">';
print $address->error;
print $object->error;
print '</div>';
}
$nblines = count($address->lines);
$nblines = count($object->lines);
if ($nblines)
{
for ($i = 0 ; $i < $nblines ; $i++)
@ -438,20 +431,20 @@ else
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans('AddressLabel').'</td><td colspan="3">'.$address->lines[$i]->label.'</td>';
print '<td valign="top" colspan="2" width="50%" rowspan="6">'.$langs->trans('Note').' :<br>'.nl2br($address->lines[$i]->note).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans('Name').'</td><td colspan="3">'.$address->lines[$i]->name.'</td></tr>';
print '<tr><td width="20%">'.$langs->trans('AddressLabel').'</td><td colspan="3">'.$object->lines[$i]->label.'</td>';
print '<td valign="top" colspan="2" width="50%" rowspan="6">'.$langs->trans('Note').' :<br>'.nl2br($object->lines[$i]->note).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans('Name').'</td><td colspan="3">'.$object->lines[$i]->name.'</td></tr>';
print "<tr><td valign=\"top\">".$langs->trans('Address')."</td><td colspan=\"3\">".nl2br($address->lines[$i]->address)."</td></tr>";
print "<tr><td valign=\"top\">".$langs->trans('Address')."</td><td colspan=\"3\">".nl2br($object->lines[$i]->address)."</td></tr>";
print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$address->lines[$i]->cp."</td></tr>";
print '<tr><td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$address->lines[$i]->ville."</td></tr>";
print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$object->lines[$i]->cp."</td></tr>";
print '<tr><td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$object->lines[$i]->ville."</td></tr>";
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'.$address->lines[$i]->pays.'</td>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'.$object->lines[$i]->pays.'</td>';
print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($address->lines[$i]->tel,$address->lines[$i]->country_code,0,$address->socid,'AC_TEL').'</td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($object->lines[$i]->tel,$object->lines[$i]->country_code,0,$object->socid,'AC_TEL').'</td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($address->lines[$i]->fax,$address->lines[$i]->country_code,0,$address->socid,'AC_FAX').'</td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($object->lines[$i]->fax,$object->lines[$i]->country_code,0,$object->socid,'AC_FAX').'</td></tr>';
print '</td></tr>';
@ -466,12 +459,12 @@ else
if ($user->rights->societe->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$address->socid.'&amp;id='.$address->lines[$i]->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&amp;id='.$object->lines[$i]->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
}
if ($user->rights->societe->supprimer)
{
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?socid='.$address->socid.'&amp;id='.$address->lines[$i]->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&amp;id='.$object->lines[$i]->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
}
@ -496,7 +489,7 @@ else
if ($user->rights->societe->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$address->socid.'&amp;action=create">'.$langs->trans("Add").'</a>';
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&amp;action=create">'.$langs->trans("Add").'</a>';
}
print '</div>';
}