From e20c738264841d8410ca1b9db286e2d7d9931a1e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 6 Jun 2010 14:30:28 +0000 Subject: [PATCH] New: Support "Department/State" field on contact card. --- htdocs/contact/class/contact.class.php | 24 ++- htdocs/contact/fiche.php | 203 ++++++++++++------ htdocs/core/class/html.formcompany.class.php | 11 +- .../install/mysql/migration/2.8.0-2.9.0.sql | 3 + htdocs/install/mysql/tables/llx_socpeople.sql | 1 + htdocs/soc.php | 23 +- 6 files changed, 187 insertions(+), 78 deletions(-) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 3ab6428336b..ba47b2a2304 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -22,12 +22,11 @@ */ /** - * \file htdocs/contact/contact.class.php + * \file htdocs/contact/class/contact.class.php * \ingroup societe * \brief File of contacts class * \version $Id$ */ - require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); @@ -49,8 +48,15 @@ class Contact extends CommonObject var $address; var $cp; var $ville; + + var $fk_departement; // Id of department + var $departement_code; // Code of department + var $departement; // Label of department + var $fk_pays; // Id of country var $pays_code; // Code of country + var $pays; // Label of country + var $socid; // fk_soc var $status; // 0=brouillon, 1=4=actif, 5=inactif @@ -84,7 +90,7 @@ class Contact extends CommonObject } /** - * \brief Add a contact in database + * \brief Add a contact into database * \param user Object user that create * \return int <0 if KO, >0 if OK */ @@ -92,13 +98,15 @@ class Contact extends CommonObject { global $conf, $langs; + $now=dol_now(); + // Clean parameters $this->name=trim($this->name); if (! $this->socid) $this->socid = 0; if (! $this->priv) $this->priv = 0; $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (datec, fk_soc, name, fk_user_creat, priv)"; - $sql.= " VALUES (".$this->db->idate(mktime()).","; + $sql.= " VALUES ('".$this->db->idate($now)."',"; if ($this->socid > 0) $sql.= " ".$this->socid.","; else $sql.= "null,"; $sql.= "'".addslashes($this->name)."',"; @@ -173,6 +181,7 @@ class Contact extends CommonObject $sql .= ", cp='".addslashes($this->cp)."'"; $sql .= ", ville='".addslashes($this->ville)."'"; $sql .= ", fk_pays=".($this->fk_pays>0?$this->fk_pays:'NULL'); + $sql .= ", fk_departement=".($this->fk_departement>0?$this->fk_departement:'NULL'); $sql .= ", poste='".addslashes($this->poste)."'"; $sql .= ", fax='".addslashes($this->fax)."'"; $sql .= ", email='".addslashes($this->email)."'"; @@ -390,6 +399,7 @@ class Contact extends CommonObject $sql = "SELECT c.rowid, c.fk_soc, c.civilite as civilite_id, c.name, c.firstname,"; $sql.= " c.address, c.cp, c.ville,"; $sql.= " c.fk_pays, p.libelle as pays, p.code as pays_code,"; + $sql.= " c.fk_departement, d.nom as departement, d.code_departement as departement_code,"; $sql.= " c.birthday,"; $sql.= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid,"; $sql.= " c.priv, c.note, c.default_lang,"; @@ -397,6 +407,7 @@ class Contact extends CommonObject $sql.= " s.nom as socname, s.address as socaddress, s.cp as soccp, s.ville as soccity, s.default_lang as socdefault_lang"; $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON c.fk_pays = p.rowid"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid"; $sql.= " WHERE c.rowid = ". $id; @@ -422,6 +433,11 @@ class Contact extends CommonObject $this->cp = $obj->cp?$obj->cp:$obj->soccp; $this->ville = $obj->ville?$obj->ville:$obj->soccity; $this->fk_pays = $obj->fk_pays; + + $this->fk_departement = $obj->fk_departement; + $this->departement_code = $obj->fk_departement?$obj->departement_code:''; + $this->departement = $obj->fk_departement?$obj->departement:''; + $this->pays_code = $obj->fk_pays?$obj->pays_code:''; $this->pays = ($obj->fk_pays > 0)?$langs->transnoentities("Country".$obj->pays_code):$langs->transnoentities("SelectCountry"); diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 335d901aeef..07bd3cad99c 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -37,7 +37,7 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php"); $langs->load("companies"); $langs->load("users"); -$error = array(); +$errors = array(); $socid=$_GET["socid"]?$_GET["socid"]:$_POST["socid"]; // If socid provided by ajax company selector @@ -98,6 +98,7 @@ if ($_POST["action"] == 'add' && $user->rights->societe->contact->creer) $contact->cp = $_POST["cp"]; $contact->ville = $_POST["ville"]; $contact->fk_pays = $_POST["pays_id"]; + $contact->fk_departement = $_POST["departement_id"]; $contact->email = $_POST["email"]; $contact->phone_pro = $_POST["phone_pro"]; $contact->phone_perso = $_POST["phone_perso"]; @@ -110,8 +111,10 @@ if ($_POST["action"] == 'add' && $user->rights->societe->contact->creer) if (! $_POST["name"]) { - array_push($error,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"))); - $_GET["action"]="create"; + array_push($errors,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"))); + $_GET["action"] = 'create'; + $_POST["action"] = 'create'; + $_REQUEST["action"] = 'create'; } if ($_POST["name"]) @@ -124,8 +127,10 @@ if ($_POST["action"] == 'add' && $user->rights->societe->contact->creer) } else { - $error=array($contact->error); + $errors=array($contact->error); $_GET["action"] = 'create'; + $_POST["action"] = 'create'; + $_REQUEST["action"] = 'create'; } } } @@ -152,45 +157,58 @@ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer) { - $contact = new Contact($db); - $contact->fetch($_POST["contactid"]); - - $contact->oldcopy=dol_clone($contact); - - $contact->old_name = $_POST["old_name"]; - $contact->old_firstname = $_POST["old_firstname"]; - - $contact->socid = $_POST["socid"]; - $contact->name = $_POST["name"]; - $contact->firstname = $_POST["firstname"]; - $contact->civilite_id = $_POST["civilite_id"]; - $contact->poste = $_POST["poste"]; - - $contact->address = $_POST["address"]; - $contact->cp = $_POST["cp"]; - $contact->ville = $_POST["ville"]; - $contact->fk_pays = $_POST["pays_id"]; - - $contact->email = $_POST["email"]; - $contact->phone_pro = $_POST["phone_pro"]; - $contact->phone_perso = $_POST["phone_perso"]; - $contact->phone_mobile = $_POST["phone_mobile"]; - $contact->fax = $_POST["fax"]; - $contact->jabberid = $_POST["jabberid"]; - $contact->priv = $_POST["priv"]; - - $contact->note = $_POST["note"]; - - $result = $contact->update($_POST["contactid"], $user); - - if ($result > 0) + if (empty($_POST["name"])) { - $contact->old_name=''; - $contact->old_firstname=''; + $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label"))); + $error++; + $_GET["action"] = 'edit'; + $_POST["action"] = 'edit'; + $_REQUEST["action"] = 'edit'; } - else + + if (! sizeof($errors)) { - $error = $contact->error; + $contact = new Contact($db); + $contact->fetch($_POST["contactid"]); + + $contact->oldcopy=dol_clone($contact); + + $contact->old_name = $_POST["old_name"]; + $contact->old_firstname = $_POST["old_firstname"]; + + $contact->socid = $_POST["socid"]; + $contact->name = $_POST["name"]; + $contact->firstname = $_POST["firstname"]; + $contact->civilite_id = $_POST["civilite_id"]; + $contact->poste = $_POST["poste"]; + + $contact->address = $_POST["address"]; + $contact->cp = $_POST["cp"]; + $contact->ville = $_POST["ville"]; + $contact->fk_departement= $_POST["departement_id"]; + $contact->fk_pays = $_POST["pays_id"]; + + $contact->email = $_POST["email"]; + $contact->phone_pro = $_POST["phone_pro"]; + $contact->phone_perso = $_POST["phone_perso"]; + $contact->phone_mobile = $_POST["phone_mobile"]; + $contact->fax = $_POST["fax"]; + $contact->jabberid = $_POST["jabberid"]; + $contact->priv = $_POST["priv"]; + + $contact->note = $_POST["note"]; + + $result = $contact->update($_POST["contactid"], $user); + + if ($result > 0) + { + $contact->old_name=''; + $contact->old_firstname=''; + } + else + { + $mesg=$contact->error; + } } } @@ -204,6 +222,8 @@ llxHeader('',$langs->trans("Contacts"),'EN:Module_Third_Parties|FR:Module_Tiers| $form = new Form($db); $formcompany = new FormCompany($db); +$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; + if ($socid) { $objsoc = new Societe($db); @@ -248,23 +268,40 @@ if ($user->rights->societe->contact->supprimer) if ($user->rights->societe->contact->creer) { - if ($_GET["action"] == 'create') + if ($_GET["action"] == 'create' || $_POST["action"] == 'create') { /* * Fiche en mode creation */ + $contact->fk_departement = $_POST["departement_id"]; + + // We set pays_id, pays_code and label for the selected country + $contact->fk_pays=$_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS; + if ($contact->fk_pays) + { + $sql = "SELECT code, libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_pays"; + $sql.= " WHERE rowid = ".$contact->fk_pays; + $resql=$db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + } + else + { + dol_print_error($db); + } + $contact->pays_code=$obj->code; + $contact->pays=$obj->libelle; + } + print_fiche_titre($langs->trans("AddContact")); // Affiche les erreurs - if (sizeof($error)) - { - print "
"; - print join("
",$error); - print "
\n"; - } + dol_htmloutput_errors($mesg,$errors); print '
'; - print '
'; + print ''; print ''; print ''; print ''; @@ -274,10 +311,10 @@ if ($user->rights->societe->contact->creer) print ''; // Company - if ($socid) + if ($socid > 0) { print ''; - print ''; + print ''; print ''; print ''; } @@ -300,17 +337,32 @@ if ($user->rights->societe->contact->creer) if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->address)) == 0) $contact->address = $objsoc->address; // Predefined with third party print ''; + // Zip / Town if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->cp)) == 0) $contact->cp = $objsoc->cp; // Predefined with third party if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->ville)) == 0) $contact->ville = $objsoc->ville; // Predefined with third party print ''; + // Country if (strlen(trim($contact->fk_pays)) == 0) $contact->fk_pays = $objsoc->pays_id; // Predefined with third party print ''; + // State + print ''; + + // Phone / Fax if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->phone_pro)) == 0) $contact->phone_pro = $objsoc->tel; // Predefined with third party print ''; print ''; @@ -340,24 +392,35 @@ if ($user->rights->societe->contact->creer) print ""; } - elseif ($_GET["action"] == 'edit' && $_GET["id"]) + elseif ($_REQUEST["action"] == 'edit' && $_REQUEST["id"]) { /* * Fiche en mode edition - * */ - // Affiche les erreurs - if (sizeof($error)) + // We set pays_id, and pays_code label of the chosen country + if ($contact->fk_pays) { - print "
"; - print join("
",$error); - print "
\n"; + $sql = "SELECT code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$contact->fk_pays; + $resql=$db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + } + else + { + dol_print_error($db); + } + $contact->pays_code=$obj->code; + $contact->pays=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle; } - print ''; + // Affiche les erreurs + dol_htmloutput_errors($mesg,$errors); + + print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -370,7 +433,7 @@ if ($user->rights->societe->contact->creer) print ''; // Name - print ''; + print ''; print ''; // Company @@ -390,14 +453,22 @@ if ($user->rights->societe->contact->creer) // Address print ''; + // Zip / Town print ''; + // Country print ''; + // Department + print ''; + + // Phone print ''; print ''; @@ -484,7 +555,7 @@ if ($user->rights->societe->contact->creer) } } -if ($_GET["id"] && $_GET["action"] != 'edit') +if ($_REQUEST["id"] && $_REQUEST["action"] != 'edit') { $objsoc = new Societe($db); @@ -544,13 +615,19 @@ if ($_GET["id"] && $_GET["action"] != 'edit') // Address print ''; + // Zip Town print ''; + // Country print ''; + // Department + print ''; + + // Phone print ''; print ''; diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 267ffb3302b..7f629562f47 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -182,10 +182,11 @@ class FormCompany * \remarks La cle de la liste est le code (il peut y avoir plusieurs entree pour * un code donnee mais dans ce cas, le champ pays differe). * Ainsi les liens avec les departements se font sur un departement independemment de son nom. - * \param selected code forme juridique a preselectionne - * \param pays_code 0=liste tous pays confondus, sinon code du pays a afficher + * \param selected Code forme juridique a preselectionne + * \param pays_code 0=liste tous pays confondus, sinon code du pays a afficher + * \param departement_id Id of department */ - function select_departement($selected='',$pays_code=0) + function select_departement($selected='',$pays_code=0, $htmlname='departement_id') { global $conf,$langs,$user; @@ -193,9 +194,7 @@ class FormCompany $langs->load("dict"); - $htmlname='departement_id'; - - // On recherche les d�partements/cantons/province active d'une region et pays actif + // On recherche les departements/cantons/province active d'une region et pays actif $sql = "SELECT d.rowid, d.code_departement as code , d.nom, d.active, p.libelle as libelle_pays, p.code as code_pays FROM"; $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_pays as p"; $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=p.rowid"; diff --git a/htdocs/install/mysql/migration/2.8.0-2.9.0.sql b/htdocs/install/mysql/migration/2.8.0-2.9.0.sql index c7b52f1b0f6..5f20b4a214a 100755 --- a/htdocs/install/mysql/migration/2.8.0-2.9.0.sql +++ b/htdocs/install/mysql/migration/2.8.0-2.9.0.sql @@ -11,6 +11,9 @@ -- V4.1 UPDATE llx_projet_task set fk_user_creat=NULL WHERE fk_user_creat IS NOT NULL AND fk_user_creat NOT IN (SELECT rowid from llx_user); -- V4.1 UPDATE llx_projet_task set fk_user_valid=NULL WHERE fk_user_valid IS NOT NULL AND fk_user_valid NOT IN (SELECT rowid from llx_user); + +ALTER TABLE llx_socpeople ADD COLUMN fk_departement integer DEFAULT 0 after ville; + -- rename llx_product_det ALTER TABLE llx_product_det RENAME TO llx_product_lang; ALTER TABLE llx_product_lang ADD UNIQUE INDEX uk_product_lang (fk_product, lang); diff --git a/htdocs/install/mysql/tables/llx_socpeople.sql b/htdocs/install/mysql/tables/llx_socpeople.sql index 504754c3670..016fc0a5d42 100644 --- a/htdocs/install/mysql/tables/llx_socpeople.sql +++ b/htdocs/install/mysql/tables/llx_socpeople.sql @@ -33,6 +33,7 @@ create table llx_socpeople address varchar(255), cp varchar(25), ville varchar(255), + fk_departement integer DEFAULT 0, fk_pays integer DEFAULT 0, birthday date, poste varchar(80), diff --git a/htdocs/soc.php b/htdocs/soc.php index d6fcf2eaf19..606f8f03218 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -59,13 +59,13 @@ $soc = new Societe($db); if ($_POST["getcustomercode"]) { // We defined value code_client - $_POST["code_client"]="aa"; + $_POST["code_client"]="Acompleter"; } if ($_POST["getsuppliercode"]) { // We defined value code_fournisseur - $_POST["code_fournisseur"]="aa"; + $_POST["code_fournisseur"]="Acompleter"; } // Add new third party @@ -426,11 +426,13 @@ $_GET["action"] == 'create' || $_POST["action"] == 'create') $soc->commercial_id=$_POST["commercial_id"]; $soc->default_lang=$_POST["default_lang"]; - // We set pays_id, pays_code and libel the selected country + // We set pays_id, pays_code and label for the selected country $soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS; if ($soc->pays_id) { - $sql = "SELECT code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$soc->pays_id; + $sql = "SELECT code, libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_pays"; + $sql.= " WHERE rowid = ".$soc->pays_id; $resql=$db->query($sql); if ($resql) { @@ -551,20 +553,24 @@ $_GET["action"] == 'create' || $_POST["action"] == 'create') print ''; } + // Address print ''; + // Zip / Town print ''; print ''; + // Country print ''; + // State print ''; + // Phone / Fax print ''; print ''; @@ -947,28 +954,33 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') print ''; } + // Address print ''; + // Zip / Town print ''; - print ''; + // Country print ''; + // Department print ''; + // Phone / Fax print ''; print ''; + // EMail / Web print ''; print ''; @@ -1186,6 +1198,7 @@ else else print $soc->pays; print ''; + // Department print ''; print '';
'.$langs->trans("Firstname").'
'.$langs->trans("Company").''.$objsoc->nom.''.$objsoc->nom.'
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; print '
'.$langs->trans("Country").''; - $form->select_pays($contact->fk_pays); + $form->select_pays($contact->fk_pays,'pays_id',$conf->use_javascript_ajax?' onChange="company_save_refresh_create()"':''); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); print '
'.$langs->trans('State').''; + if ($contact->fk_pays) + { + $formcompany->select_departement($contact->fk_departement,$contact->pays_code); + } + else + { + print $countrynotdefined; + } + print '
'.$langs->trans("PhonePro").''.$langs->trans("PhonePerso").'
'.$langs->trans("Lastname").'
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$langs->trans("Firstname").'
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; print '
'.$langs->trans("Country").''; - $form->select_pays($contact->fk_pays); + $form->select_pays($contact->fk_pays,'pays_id',$conf->use_javascript_ajax?' onChange="company_save_refresh_edit()"':''); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); print '
'.$langs->trans('State').''; + $formcompany->select_departement($contact->fk_departement,$contact->pays_code); + print '
'.$langs->trans("PhonePro").''.$langs->trans("PhonePerso").'
'.$langs->trans("Address").''.nl2br($contact->address).'
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$contact->cp.' '; print $contact->ville.'
'.$langs->trans("Country").''; print $contact->pays; print '
'.$langs->trans('State').''.$contact->departement.'
'.$langs->trans("PhonePro").''.dol_print_phone($contact->phone_pro,$contact->pays_code,$contact->id,$contact->socid,'AC_TEL').''.$langs->trans("PhonePerso").''.dol_print_phone($contact->phone_perso,$contact->pays_code,$contact->id,$contact->socid,'AC_TEL').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print ''.$langs->trans('Town').'
'.$langs->trans('Country').''; $form->select_pays($soc->pays_id,'pays_id',$conf->use_javascript_ajax?' onChange="company_save_refresh_create()"':''); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); print '
'.$langs->trans('State').''; if ($soc->pays_id) { @@ -576,6 +582,7 @@ $_GET["action"] == 'create' || $_POST["action"] == 'create') } print '
'.$langs->trans('Phone').''.$langs->trans('Fax').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print ''.$langs->trans('Town').'
'.$langs->trans('Country').''; $form->select_pays($soc->pays_id,'pays_id',$conf->use_javascript_ajax?' onChange="company_save_refresh_edit()"':''); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); print '
'.$langs->trans('State').''; $formcompany->select_departement($soc->departement_id,$soc->pays_code); print '
'.$langs->trans('Phone').''.$langs->trans('Fax').'
'.$langs->trans('EMail').($conf->global->SOCIETE_MAIL_REQUIRED?'*':'').''.$langs->trans('Web').'
'.$langs->trans('State').''.$soc->departement.'
'.$langs->trans('Phone').''.dol_print_phone($soc->tel,$soc->pays_code,0,$soc->id,'AC_TEL').'