* Copyright (C) 2004-2006 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/comm/address.php * \ingroup societe * \brief Tab address of customer */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php"); require_once(DOL_DOCUMENT_ROOT."/societe/class/address.class.php"); $langs->load("companies"); $langs->load("commercial"); $id = isset($_GET["id"])?$_GET["id"]:''; $origin = isset($_GET["origin"])?$_GET["origin"]:''; $originid = isset($_GET["originid"])?$_GET["originid"]:''; $socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; if (! $socid && ($_REQUEST["action"] != 'create' && $_REQUEST["action"] != 'add' && $_REQUEST["action"] != 'update')) accessforbidden(); // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe', $socid); /* * Actions */ if ($_POST["action"] == 'add' || $_POST["action"] == 'update') { $address = new Address($db); $address->socid = $_POST["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->pays_id = $_POST["pays_id"]; $address->tel = $_POST["tel"]; $address->fax = $_POST["fax"]; $address->note = $_POST["note"]; if ($_POST["action"] == 'add') { $socid = $_POST["socid"]; $origin = $_POST["origin"]; $originid = $_POST["originid"]; $result = $address->create($socid, $user); if ($result >= 0) { if ($origin == 'commande') { Header("Location: ../commande/fiche.php?action=editdelivery_adress&socid=".$socid."&id=".$originid); exit; } elseif ($origin == 'propal') { Header("Location: ../comm/propal.php?action=editdelivery_adress&socid=".$socid."&id=".$originid); exit; } else { Header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); exit; } } else { $mesg = $address->error; $_GET["action"]='create'; } } if ($_POST["action"] == 'update') { $socid = $_POST["socid"]; $origin = $_POST["origin"]; $originid = $_POST["originid"]; $result = $address->update($_POST["id"], $socid, $user); if ($result >= 0) { if ($origin == 'commande') { Header("Location: ../commande/fiche.php?id=".$originid); exit; } elseif ($origin == 'propal') { Header("Location: ../comm/propal.php?id=".$originid); exit; } elseif ($origin == 'shipment') { Header("Location: ../expedition/fiche.php?id=".$originid); exit; } else { Header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); exit; } } else { $reload = 0; $mesg = $address->error; $_GET["action"]= "edit"; } } } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->societe->supprimer) { $address = new Address($db); $result = $address->delete($_GET["id"], $socid); if ($result == 0) { Header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); exit ; } else { $reload = 0; $_GET["action"]=''; } } /** * * */ llxHeader(); $form = new Form($db); $formcompany = new FormCompany($db); $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; dol_htmloutput_errors($mesg); if ($_GET["action"] == 'create' || $_POST["action"] == 'create') { if ($user->rights->societe->creer) { /* * Creation */ $address = new Address($db); $societe=new Societe($db); $societe->fetch($socid); $head = societe_prepare_head($societe); dol_fiche_head($head, 'customer', $societe->nom); 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"]; } // On positionne pays_id, pays_code et libelle du pays choisi $address->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id; if ($address->pays_id) { $sql = "SELECT code, libelle"; $sql.= " FROM ".MAIN_DB_PREFIX."c_pays"; $sql.= " WHERE rowid = ".$address->pays_id; $resql=$db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); } else { dol_print_error($db); } $address->pays_code = $obj->code; $address->pays = $obj->libelle; } print_titre($langs->trans("NewAddress")); print "
\n"; if ($address->error) { print '
'; print nl2br($address->error); print '
'; } // If javascript enabled, we add interactivity on mandatory fields if ($conf->use_javascript_ajax) { print "\n".''."\n"; } print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Zip print ''; // Town print ''; print ''; print ''; print ''; print ''; print ''."\n"; print '
'.$langs->trans('AddressLabel').'
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; print $formcompany->select_ziptown($address->cp,'zipcode',array('town','selectpays_id'),6); print '
'.$langs->trans('Town').''; print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectpays_id')); print '
'.$langs->trans('Country').''; $form->select_pays($address->pays_id,'pays_id'); print '
'.$langs->trans('Phone').'
'.$langs->trans('Fax').'
'.$langs->trans('Note').'
'; print '
'."\n"; print '
'."\n"; } } elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') { /* * Fiche societe en mode edition */ $address = new Address($db); $societe=new Societe($db); $societe->fetch($_GET["socid"]); $head = societe_prepare_head($societe); dol_fiche_head($head, 'customer', $societe->nom); print_titre($langs->trans("EditAddress")); print "
\n"; if ($socid) { if ($reload || ! $_POST["name"]) { $address->socid = $socid; $address->fetch_address($id); } else { $address->id = $_POST["id"]; $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->pays_id = $_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id; $address->tel = $_POST["tel"]; $address->fax = $_POST["fax"]; $address->note = $_POST["note"]; // On positionne pays_id, pays_code et libelle du pays choisi if ($address->pays_id) { $sql = "SELECT code, libelle"; $sql.= " FROM ".MAIN_DB_PREFIX."c_pays"; $sql.= "WHERE rowid = ".$address->pays_id; $resql=$db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); } else { dol_print_error($db); } $address->pays_code = $obj->code; $address->pays = $langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle; } } if ($address->error) { print '
'; print $address->error; print '
'; } print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Zip print ''; // Town print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('AddressLabel').'
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; print $formcompany->select_ziptown($address->cp,'zipcode',array('town','selectpays_id'),6); print '
'.$langs->trans('Town').''; print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectpays_id')); print '
'.$langs->trans('Country').''; $form->select_pays($address->pays_id,'pays_id'); print '
'.$langs->trans('Phone').'
'.$langs->trans('Fax').'
'.$langs->trans('Note').'
'; print '
'; } } else { /* * Fiche societe en mode visu */ $address = new Address($db); $result=$address->fetch($socid); if ($result < 0) { dol_print_error($db,$address->error); exit; } $societe=new Societe($db); $societe->fetch($address->socid); $head = societe_prepare_head($societe); dol_fiche_head($head, 'customer', $societe->nom); // Confirmation delete if ($_GET["action"] == 'delete') { $html = new Form($db); $ret=$html->form_confirm($_SERVER['PHP_SELF']."?socid=".$address->socid."&id=".$_GET["id"],$langs->trans("DeleteAddress"),$langs->trans("ConfirmDeleteAddress"),"confirm_delete"); if ($ret == 'html') print '
'; } if ($address->error) { print '
'; print $address->error; print '
'; } $nblines = count($address->lines); if ($nblines) { for ($i = 0 ; $i < $nblines ; $i++) { print ''; print ''; print ''; print ''; print ""; print '"; print '"; print ''; print ''; print ''; print ''; 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('Address')."".nl2br($address->lines[$i]->address)."
'.$langs->trans('Zip').''.$address->lines[$i]->cp."
'.$langs->trans('Town').''.$address->lines[$i]->ville."
'.$langs->trans('Country').''.$address->lines[$i]->pays.'
'.$langs->trans('Phone').''.dol_print_phone($address->lines[$i]->tel,$address->lines[$i]->pays_code,0,$address->socid,'AC_TEL').'
'.$langs->trans('Fax').''.dol_print_phone($address->lines[$i]->fax,$address->lines[$i]->pays_code,0,$address->socid,'AC_FAX').'
'; /* * */ print '
'; if ($user->rights->societe->creer) { print ''.$langs->trans("Modify").''; } if ($user->rights->societe->supprimer) { print ''.$langs->trans("Delete").''; } print '
'; print '
'; } } else { print $langs->trans("None"); } print ''; /* * Bouton actions */ if ($_GET["action"] == '') { print '
'; if ($user->rights->societe->creer) { print ''.$langs->trans("Add").''; } print '
'; } } $db->close(); llxFooter(); ?>