Works on alternative addresses management

This commit is contained in:
Regis Houssin 2012-03-14 18:03:36 +01:00
parent f779c03c6b
commit 9b7afbc29b
6 changed files with 155 additions and 155 deletions

View File

@ -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 "<br>\n";
if ($object->error)
{
print '<div class="error">';
print nl2br($object->error);
print '</div>';
}
// If javascript enabled, we add interactivity on mandatory fields
if ($conf->use_javascript_ajax)
{
@ -243,11 +244,12 @@ if ($action == 'create')
}
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" name="formsoc">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="socid" value="'.$socid.'">';
print '<input type="hidden" name="origin" value="'.$origin.'">';
print '<input type="hidden" name="originid" value="'.$originid.'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'"/>';
print '<input type="hidden" name="socid" value="'.$socid.'"/>';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'"/>';
print '<input type="hidden" name="origin" value="'.$origin.'"/>';
print '<input type="hidden" name="originid" value="'.$originid.'"/>';
print '<input type="hidden" name="action" value="add"/>';
print '<table class="border" width="100%">';
@ -260,19 +262,19 @@ if ($action == 'create')
// Zip
print '<tr><td>'.$langs->trans('Zip').'</td><td>';
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 '</td></tr>';
// Town
print '<tr><td>'.$langs->trans('Town').'</td><td>';
print $formcompany->select_ziptown($object->ville,'town',array('zipcode','selectcountry_id'));
print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id'));
print '</td></tr>';
print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
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="'.$object->tel.'"></td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="phone" value="'.$object->phone.'"></td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td><input type="text" name="fax" value="'.$object->fax.'"></td></tr>';
@ -283,7 +285,13 @@ if ($action == 'create')
print '</table>'."\n";
print '<br><center>';
print '<input type="submit" class="button" value="'.$langs->trans('AddAddress').'"></center>'."\n";
print '<input type="submit" class="button" value="'.$langs->trans('Add').'">';
if (! empty($backtopage))
{
print ' &nbsp; &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
}
print '</center>'."\n";
print '</form>'."\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 "<br>\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 '<div class="error">';
print $object->error;
print '</div>';
}
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="'.$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="'.$object->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'"/>';
print '<input type="hidden" name="action" value="update"/>';
print '<input type="hidden" name="socid" value="'.$object->socid.'"/>';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'"/>';
print '<input type="hidden" name="origin" value="'.$origin.'"/>';
print '<input type="hidden" name="originid" value="'.$originid.'"/>';
print '<input type="hidden" name="id" value="'.$object->id.'"/>';
print '<table class="border" width="100%">';
@ -362,29 +362,34 @@ elseif ($action == 'edit')
// Zip
print '<tr><td>'.$langs->trans('Zip').'</td><td>';
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 '</td></tr>';
// Town
print '<tr><td>'.$langs->trans('Town').'</td><td>';
print $formcompany->select_ziptown($object->ville,'town',array('zipcode','selectcountry_id'));
print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id'));
print '</td></tr>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
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="'.$object->tel.'"></td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="phone" value="'.$object->phone.'"></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 $object->note;
print '</textarea></td></tr>';
print '<tr><td align="center" colspan="4"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td></tr>';
print '</table>';
print '</table><br>';
print '<center>';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</center>';
print '</form>';
}
}
@ -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."&amp;id=".$id,$langs->trans("DeleteAddress"),$langs->trans("ConfirmDeleteAddress"),"confirm_delete");
if ($ret == 'html') print '<br>';
}
if ($object->error)
{
print '<div class="error">';
print $object->error;
print '</div>';
}
$nblines = count($object->lines);
if ($nblines)
{
@ -437,12 +435,12 @@ else
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%">'.$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 width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$object->lines[$i]->zip."</td></tr>";
print '<tr><td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$object->lines[$i]->town."</td></tr>";
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'.$object->lines[$i]->pays.'</td>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'.$object->lines[$i]->country.'</td>';
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('Phone').'</td><td>'.dol_print_phone($object->lines[$i]->phone,$object->lines[$i]->country_code,0,$object->socid,'AC_TEL').'</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>';

View File

@ -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))
{

View File

@ -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;

View File

@ -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))
{

View File

@ -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

View File

@ -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;