* Copyright (C) 2004-2006 Laurent Destailleur * Copyright (C) 2005-2012 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 3 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 thirdparty */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/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 = 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 if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe', $socid); $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->zip = $_POST["zipcode"]; $object->town = $_POST["town"]; $object->country_id = $_POST["country_id"]; $object->phone = $_POST["phone"]; $object->fax = $_POST["fax"]; $object->note = $_POST["note"]; // Add new address if ($action == 'add') { $result = $object->create($socid, $user); if ($result >= 0) { if (! empty($backtopage)) { header("Location: ".$backtopage); exit; } else if ($origin == 'commande') { header("Location: ../commande/contact.php?action=editdelivery_adress&socid=".$socid."&id=".$originid); exit; } elseif ($origin == 'propal') { header("Location: ../comm/propal/contact.php?action=editdelivery_adress&socid=".$socid."&id=".$originid); exit; } elseif ($origin == 'shipment') { header("Location: ../expedition/card.php?id=".$originid); exit; } else { header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); exit; } } else { setEventMessage($object->error, 'errors'); $action='create'; } } // Update address else if ($action == 'update') { $result = $object->update($id, $socid, $user); if ($result >= 0) { if (! empty($backtopage)) { header("Location: ".$backtopage); exit; } else if ($origin == 'commande') { header("Location: ../commande/contact.php?id=".$originid); exit; } elseif ($origin == 'propal') { header("Location: ../comm/propal/contact.php?id=".$originid); exit; } elseif ($origin == 'shipment') { header("Location: ../expedition/card.php?id=".$originid); exit; } else { header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); exit; } } else { $reload = 0; setEventMessage($object->error, 'errors'); $action= "edit"; } } } else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) { $result = $object->delete($id, $socid); if ($result == 0) { header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); exit ; } else { $reload = 0; $action=''; } } /** * * */ llxHeader(); $form = new Form($db); $formcompany = new FormCompany($db); $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; if ($action == 'create') { if ($user->rights->societe->creer) { /* * Creation */ if ($_POST["label"] && $_POST["name"]) { $object->socid = $socid; $object->label = $_POST["label"]; $object->name = $_POST["name"]; $object->address = $_POST["address"]; $object->zip = $_POST["zipcode"]; $object->town = $_POST["town"]; $object->phone = $_POST["phone"]; $object->fax = $_POST["fax"]; $object->note = $_POST["note"]; } // On positionne country_id, country_code and label of the chosen country $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->country_code = $tmparray['code']; $object->country = $tmparray['label']; } print_fiche_titre($langs->trans("AddAddress")); print "
\n"; // 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 ''; print ''; // Zip print ''; // Town print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('Label').'
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id'),6); print '
'.$langs->trans('Town').''; 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('Fax').'
'.$langs->trans('Note').'
'."\n"; print '
'; print ''; if (! empty($backtopage)) { print '     '; print ''; } print '
'."\n"; print '
'."\n"; } } elseif ($action == 'edit') { /* * Fiche societe en mode edition */ $societe=new Societe($db); $societe->fetch($socid); $head = societe_prepare_head($societe); dol_fiche_head($head, 'card', $societe->name); print_titre($langs->trans("EditAddress")); print "
\n"; if ($socid) { if ($reload || ! $_POST["name"]) { $object->socid = $socid; $object->fetch_address($id); } else { $object->id = $id; $object->socid = $socid; $object->label = $_POST["label"]; $object->name = $_POST["name"]; $object->address = $_POST["address"]; $object->zip = $_POST["zipcode"]; $object->town = $_POST["town"]; $object->country_id = $_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id; $object->phone = $_POST["phone"]; $object->fax = $_POST["fax"]; $object->note = $_POST["note"]; // On positionne country_id, country_code and label of the chosen country if ($object->country_id) { $tmparray=getCountry($object->country_id,'all'); $object->country_code = $tmparray['code']; $object->country = $tmparray['label']; } } print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Zip print ''; // Town print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('AddressLabel').'
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id'),6); print '
'.$langs->trans('Town').''; 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('Fax').'
'.$langs->trans('Note').'

'; print '
'; print ''; print '     '; print ''; print '
'; print '
'; } } else { /* * Fiche societe en mode visu */ $result=$object->fetch_lines($socid); if ($result < 0) { dol_print_error($db,$object->error); exit; } $societe=new Societe($db); $societe->fetch($object->socid); $head = societe_prepare_head($societe); dol_fiche_head($head, 'customer', $societe->name); // Confirmation delete if ($action == 'delete') { print $form->formconfirm($_SERVER['PHP_SELF']."?socid=".$object->socid."&id=".$id,$langs->trans("DeleteAddress"),$langs->trans("ConfirmDeleteAddress"),"confirm_delete"); } $nblines = count($object->lines); if ($nblines) { for ($i = 0 ; $i < $nblines ; $i++) { print ''; print ''; print ''; print ''; print ""; print '"; print '"; print ''; print ''; print ''; print ''; print '
'.$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($object->lines[$i]->address)."
'.$langs->trans('Zip').''.$object->lines[$i]->zip."
'.$langs->trans('Town').''.$object->lines[$i]->town."
'.$langs->trans('Country').''.$object->lines[$i]->country.'
'.$langs->trans('Phone').''.dol_print_phone($object->lines[$i]->phone,$object->lines[$i]->country_code,0,$object->socid,'AC_TEL').'
'.$langs->trans('Fax').''.dol_print_phone($object->lines[$i]->fax,$object->lines[$i]->country_code,0,$object->socid,'AC_FAX').'
'; /* * */ print '
'; if ($user->rights->societe->creer) { print ''; } if ($user->rights->societe->supprimer) { print ''; } print '
'; print '
'; } } else { print $langs->trans("None"); } print ''; /* * Bouton actions */ if ($action == '') { print '
'; if ($user->rights->societe->creer) { print ''; } print '
'; } } // End of page llxFooter(); $db->close();