diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index 0911cc53d48..29e8bfb0b7e 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -23,7 +23,8 @@ * */ -/** \file htdocs/contact.class.php +/** + \file htdocs/contact.class.php \ingroup societe \brief Fichier de la classe des contacts \version $Revision$ @@ -33,127 +34,139 @@ require_once (DOL_DOCUMENT_ROOT."/lib/ldap.lib.php"); -/** \class Contact +/** + \class Contact \brief Classe permettant la gestion des contacts */ class Contact { - var $db; - var $error; - - var $id; - var $fullname; - var $nom; - var $prenom; - var $code; - var $email; - var $birthday; + var $db; + var $error; + + var $id; + var $fullname; + var $nom; + var $prenom; + var $name; + var $firstname; + var $address; + var $cp; + var $ville; + var $fk_pays; + + var $code; + var $email; + var $birthday; - /** - * \brief Constructeur de l'objet contact - * - */ - function Contact($DB, $id=0) + /** + * \brief Constructeur de l'objet contact + * \param DB Habler d'accès base + * \param id Id contact + */ + function Contact($DB, $id=0) { - $this->db = $DB; - $this->id = $id; - - return 1; + $this->db = $DB; + $this->id = $id; + + return 1; } - /** - * \brief Ajout d'un contact en base - * \param user Utilisateur qui effectue l'ajout - */ - function create($user) - { - if (!$this->socid) - { - $this->socid = 0; - } + /** + * \brief Ajout d'un contact en base + * \param user Utilisateur qui effectue l'ajout + * \return int <0 si ko, >0 si ok + */ + function create($user) + { + $this->name=trim($this->name); + if (! $this->socid) + { + $this->socid = 0; + } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (datec, fk_soc, name, fk_user) "; - $sql .= " VALUES (now(),$this->socid,'$this->name',$user->id)"; - - if ($this->db->query($sql) ) - { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople"); - - $this->update($id, $user); - - return $id; - } - else - { - $this->error='Echec sql='.$sql; - } - } - - /* - * \brief Mise à jour des infos - * \param id id du contact à mettre à jour - * \param user Utilisateur qui effectue la mise à jour - * - */ - function update($id, $user=0) - { - dolibarr_syslog("Contact::Update id=".$id,LOG_DEBUG); - $this->id = $id; - $this->error = array(); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (datec, fk_soc, name, fk_user)"; + $sql.= " VALUES (now(),$this->socid,'$this->name',$user->id)"; - $this->email = trim($this->email); + if ($this->db->query($sql) ) + { + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople"); - //commenté suite a la nouvell fonction dolibarr_print_phone - //$this->phone_pro = ereg_replace(" ","",$this->phone_pro); - //$this->phone_perso = ereg_replace(" ","",$this->phone_perso); - - if (strlen($this->phone_pro) == 0 && $this->socid > 0) - { - $soc = new Societe($this->db); - $soc->fetch($this->socid); - $this->phone_pro = $soc->tel; - } + $ret=$this->update($id, $user); + if ($ret < 0) + { + $this->error=$this->db->error(); + return -2; + } + return $id; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } - $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET "; - $sql .= " civilite='$this->civilite_id'"; - $sql .= ", name='".trim($this->name)."'"; - $sql .= ", firstname='".trim($this->firstname)."'"; - $sql .= ", address='$this->address'"; - $sql .= ", cp='$this->cp'"; - $sql .= ", ville='$this->ville'"; - $sql .= ", poste='$this->poste'"; - $sql .= ", fax='$this->fax'"; - $sql .= ", email='$this->email'"; - $sql .= ", note='$this->note'"; - $sql .= ", phone = '$this->phone_pro'"; - $sql .= ", phone_perso = '$this->phone_perso'"; - $sql .= ", phone_mobile = '$this->phone_mobile'"; - $sql .= ", jabberid = '$this->jabberid'"; + /* + * \brief Mise à jour des infos + * \param id id du contact à mettre à jour + * \param user Utilisateur qui effectue la mise à jour + * \return int <0 si erreur, >0 si ok + */ + function update($id, $user=0) + { + dolibarr_syslog("Contact::Update id=".$id,LOG_DEBUG); - if ($user) - { - $sql .= ", fk_user_modif='".$user->id."'"; - } - $sql .= " WHERE idp=$id"; + $this->id = $id; - $result = $this->db->query($sql); + $this->name=trim($this->name); + $this->firstname=trim($this->firstname); + $this->email=trim($this->email); + $this->phone_pro=trim($this->phone_pro); - if (!$result) - { - $this->error='Echec sql='.$sql; - } + if ($this->phone_pro && $this->socid > 0) + { + $soc = new Societe($this->db); + $soc->fetch($this->socid); + $this->phone_pro = $soc->tel; + } - if (defined('MAIN_MODULE_LDAP') && MAIN_MODULE_LDAP) - { - if (defined('LDAP_CONTACT_ACTIVE') && LDAP_CONTACT_ACTIVE == 1) - { - $this->update_ldap($user); - } - - } - return $result; - } + $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET "; + $sql .= " civilite='$this->civilite_id'"; + $sql .= ", name='$this->name'"; + $sql .= ", firstname='$this->firstname'"; + $sql .= ", address='$this->address'"; + $sql .= ", cp='$this->cp'"; + $sql .= ", ville='$this->ville'"; + $sql .= ", fk_pays='$this->fk_pays'"; + $sql .= ", poste='$this->poste'"; + $sql .= ", fax='$this->fax'"; + $sql .= ", email='$this->email'"; + $sql .= ", note='$this->note'"; + $sql .= ", phone = '$this->phone_pro'"; + $sql .= ", phone_perso = '$this->phone_perso'"; + $sql .= ", phone_mobile = '$this->phone_mobile'"; + $sql .= ", jabberid = '$this->jabberid'"; + if ($user) $sql .= ", fk_user_modif='".$user->id."'"; + $sql .= " WHERE idp=".$id; + + $result = $this->db->query($sql); + if (! $result) + { + $this->error=$this->db->error(); + return -1; + } + + if ($conf->ldap->enabled) + { + if ($conf->global->LDAP_CONTACT_ACTIVE) + { + $this->update_ldap($user); + } + + } + return 1; + } /** * \brief Mise à jour de l'arbre ldap @@ -421,13 +434,14 @@ class Contact */ function fetch($id, $user=0) { - $sql = "SELECT c.idp, c.fk_soc, c.civilite civilite_id, c.name, c.firstname"; - $sql .= ", c.address, c.cp, c.ville"; - $sql .= ", c.birthday as birthday, poste"; - $sql .= ", phone, phone_perso, phone_mobile, fax, c.email, jabberid, c.note"; - - $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; - $sql .= " WHERE c.idp = ". $id; + $sql = "SELECT c.idp, c.fk_soc, c.civilite 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.birthday as birthday, c.poste,"; + $sql.= " c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid, c.note"; + $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.= " WHERE c.idp = ". $id; $resql=$this->db->query($sql); if ($resql) @@ -446,6 +460,9 @@ class Contact $this->address = $obj->address; $this->cp = $obj->cp; $this->ville = $obj->ville; + $this->fk_pays = $obj->fk_pays; + $this->pays_code = $obj->fk_pays?$obj->pays_code:''; + $this->pays = $obj->fk_pays?$obj->pays:''; $this->societeid = $obj->fk_soc; $this->socid = $obj->fk_soc; @@ -489,7 +506,7 @@ class Contact else { dolibarr_syslog("Error in Contact::fetch() selectuser sql=$sql"); - $this->error="Error in Contact::fetch() selectuser sql=$sql"; + $this->error="Error in Contact::fetch() selectuser - ".$this->db->error()." - ".$sql; return -1; } @@ -514,7 +531,7 @@ class Contact else { dolibarr_syslog("Error in Contact::fetch() selectcontactfacture sql=$sql"); - $this->error="Error in Contact::fetch() selectcontactfacture sql=$sql"; + $this->error="Error in Contact::fetch() selectcontactfacture - ".$this->db->error()." - ".$sql; return -1; } @@ -538,7 +555,7 @@ class Contact else { dolibarr_syslog("Error in Contact::fetch() selectuseralert sql=$sql"); - $this->error="Error in Contact::fetch() selectuseralert sql=$sql"; + $this->error="Error in Contact::fetch() selectuseralert - ".$this->db->error()." - ".$sql; return -1; } } @@ -548,7 +565,7 @@ class Contact else { dolibarr_syslog("Error in Contact::fetch() selectsocpeople sql=$sql"); - $this->error="Error in Contact::fetch() selectsocpeople sql=$sql"; + $this->error="Error in Contact::fetch() selectsocpeople - ".$this->db->error()." - ".$sql; return -1; } } diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 667aa266165..e45456f79fa 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -53,55 +53,62 @@ if ($_GET["action"] == 'create_user' && $user->admin) $nuser->create_from_contact($contact); } -if ($_POST["action"] == 'add') +if ($_POST["action"] == 'add') { - if (! $_POST["name"]) + if (! $_POST["name"]) { - array_push($error,$langs->trans("ErrorFieldRequired",$langs->trans("Lastname"))); - $_GET["action"]="create"; + array_push($error,$langs->trans("ErrorFieldRequired",$langs->trans("Lastname"))); + $_GET["action"]="create"; } - if (! $_POST["firstname"]) + if (! $_POST["firstname"]) { - array_push($error,$langs->trans("ErrorFieldRequired",$langs->trans("Firstname"))); - $_GET["action"]="create"; + array_push($error,$langs->trans("ErrorFieldRequired",$langs->trans("Firstname"))); + $_GET["action"]="create"; } - if ($_POST["name"] && $_POST["firstname"]) + if ($_POST["name"] && $_POST["firstname"]) { - $contact = new Contact($db); - - $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->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->note = $_POST["note"]; - - $_GET["id"] = $contact->create($user); + $contact = new Contact($db); + + $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->note = $_POST["note"]; + + $id = $contact->create($user); + if ($id > 0) + { + Header("Location: fiche.php?id=".$id); + } + + $error=array($contact->error); } } if ($_POST["action"] == 'confirm_delete' AND $_POST["confirm"] == 'yes') { - $contact = new Contact($db); - - $contact->old_name = $_POST["old_name"]; - $contact->old_firstname = $_POST["old_firstname"]; - - $result = $contact->delete($_GET["id"]); - - Header("Location: index.php"); + $contact = new Contact($db); + + $contact->old_name = $_POST["old_name"]; + $contact->old_firstname = $_POST["old_firstname"]; + + $result = $contact->delete($_GET["id"]); + + Header("Location: index.php"); } @@ -121,6 +128,7 @@ if ($_POST["action"] == 'update') $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"]; @@ -157,9 +165,9 @@ if ($socid) // Affiche les erreurs if (sizeof($error)) { - print "
"; - print join("
",$error); - print "
\n"; + print "
"; + print join("
",$error); + print "
\n"; } @@ -210,136 +218,139 @@ if ($_GET["action"] == 'delete') if ($_GET["action"] == 'create') { - /* - * Fiche en mode creation - * - */ - print_fiche_titre($langs->trans("AddContact")); - - print '
'; + /* + * Fiche en mode creation + * + */ + print_fiche_titre($langs->trans("AddContact")); + print '
'; - print '
'; - print ''; - print ''; + print ''; + print ''; + print '
'; - if ($socid) + if ($socid) { - // On remplit avec le numéro de la société par défaut - if (strlen(trim($contact->phone_pro)) == 0) - { - $contact->phone_pro = $objsoc->tel; - } - - print ''; - print ''; - print ''; - print ''; + // On remplit avec le numéro de la société par défaut + if (strlen(trim($contact->phone_pro)) == 0) + { + $contact->phone_pro = $objsoc->tel; + } + + print ''; + print ''; + print ''; + print ''; } - else { - print ''; + } + + print ''; - } - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; - print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; + print "
'.$langs->trans("Company").''.$objsoc->nom.'
'.$langs->trans("Company").''.$objsoc->nom.'
'.$langs->trans("Company").''; - print $form->select_societes('','socid',''); + else { + print '
'.$langs->trans("Company").''; + print $form->select_societes('','socid',''); + print '
'.$langs->trans("UserTitle").''; + print $form->select_civilite($obj->civilite); print '
'.$langs->trans("UserTitle").''; - print $form->select_civilite($obj->civilite); - print '
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
Poste/Fonction
'.$langs->trans("Address").'
Poste/Fonction
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; + print '
'.$langs->trans("Address").'
'.$langs->trans("Country").''; + $form->select_pays($contact->fk_pays); + print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; + print '
Tel ProTel Perso
'.$langs->trans("Fax").'Portable
Tel ProTel Perso
'.$langs->trans("Email").'
'.$langs->trans("Fax").'Portable
Jabberid
'.$langs->trans("Email").'
'.$langs->trans("Note").'
Jabberid
'.$langs->trans("BillingContact").''; + print $form->selectyesno("facturation",$contact->facturation); + print '
'.$langs->trans("Note").'

"; - print ''.$langs->trans("BillingContact").''; - print $form->selectyesno("facturation",$contact->facturation); - print ''; - - print ''; - print "
"; - - print "
"; + print ""; } -elseif ($_GET["action"] == 'edit') +elseif ($_GET["action"] == 'edit') { - /* - * Fiche en mode edition - * - */ - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + /* + * Fiche en mode edition + * + */ - if ($contact->socid > 0) + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + + if ($contact->socid > 0) { - $objsoc = new Societe($db); - $objsoc->fetch($contact->socid); + $objsoc = new Societe($db); + $objsoc->fetch($contact->socid); - print ''; + print ''; } - print ''; + print ''; - print ''; - print ''; + print ''; + print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; + print "
'.$langs->trans("Company").''.$objsoc->nom_url.'
'.$langs->trans("Company").''.$objsoc->nom_url.'
'.$langs->trans("UserTitle").''; - print $form->select_civilite($contact->civilite_id); - print '
'.$langs->trans("UserTitle").''; + print $form->select_civilite($contact->civilite_id); + print '
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
Poste/Fonction
Poste/Fonction
'.$langs->trans("Address").'
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; + print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; + print '
'.$langs->trans("Country").''; + $form->select_pays($contact->fk_pays); + print '
Tel ProTel Perso
Tel ProTel Perso
Portable'.$langs->trans("Fax").'
Portable'.$langs->trans("Fax").'
'.$langs->trans("EMail").'
'.$langs->trans("EMail").'
Jabberid
Jabberid
'.$langs->trans("Note").''; + print '
'.$langs->trans("Note").''; - print '
'.$langs->trans("BillingContact").''; + print $form->selectyesno("facturation",$contact->facturation); + print '
'.$langs->trans("BillingContact").''; - print $form->selectyesno("facturation",$contact->facturation); - print '

"; - print ''; - print "
"; - - print "
"; + print ""; } else { @@ -374,6 +385,10 @@ else print ''.$langs->trans("Zip").' / '.$langs->trans("Town").''.$contact->cp.' '; print $contact->ville.''; + print ''.$langs->trans("Country").''; + print $contact->pays; + print ''; + print 'Tel Pro'.$contact->phone_pro.''; print 'Tel Perso'.$contact->phone_perso.''; diff --git a/mysql/migration/1.1.0-2.0.0.sql b/mysql/migration/1.1.0-2.0.0.sql index 56d53c14b09..2530b91bb89 100644 --- a/mysql/migration/1.1.0-2.0.0.sql +++ b/mysql/migration/1.1.0-2.0.0.sql @@ -238,6 +238,7 @@ alter table llx_cond_reglement add code varchar(16) after rowid; alter table llx_socpeople add cp varchar(25) after address; alter table llx_socpeople add ville varchar(255) after cp; +alter table llx_socpeople add fk_pays integer DEFAULT 0 after ville; alter table llx_paiement add statut smallint DEFAULT 0 NOT NULL ; alter table llx_facturedet add fk_export_compta integer DEFAULT 0 NOT NULL ; diff --git a/mysql/tables/llx_socpeople.sql b/mysql/tables/llx_socpeople.sql index 5162e50d8b8..b492f8d1f1c 100644 --- a/mysql/tables/llx_socpeople.sql +++ b/mysql/tables/llx_socpeople.sql @@ -32,6 +32,7 @@ create table llx_socpeople address varchar(255), cp varchar(25), ville varchar(255), + fk_pays integer DEFAULT 0, birthday date, poste varchar(80), phone varchar(30),