diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index 3b1690bf3d1..e375c496257 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -1,752 +1,752 @@ - - * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2004-2005 Laurent Destailleur - * Copyright (C) 2005 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ - */ - -/** - \file htdocs/contact.class.php - \ingroup societe - \brief Fichier de la classe des contacts - \version $Revision$ -*/ - -require_once (DOL_DOCUMENT_ROOT."/lib/ldap.lib.php"); - - - -/** - \class Contact - \brief Classe permettant la gestion des contacts -*/ - -class Contact -{ - 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; - - var $ref_facturation; // Nb de reference facture pour lequel il est contact - var $ref_contrat; // Nb de reference contrat pour lequel il est contact - var $ref_commande; // Nb de reference commande pour lequel il est contact - var $ref_propal; // Nb de reference propal pour lequel il est contact - - /** - * \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; - } - - /** - * \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(),"; - if ($this->socid > 0) $sql.= " $this->socid,"; - else $sql.= "null,"; - $sql.= "'$this->name',$user->id)"; - - if ($this->db->query($sql) ) - { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople"); - - $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; - } - } - - /* - * \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); - - $this->id = $id; - - $this->name=trim($this->name); - $this->firstname=trim($this->firstname); - $this->email=trim($this->email); - $this->phone_pro=trim($this->phone_pro); - - if ($this->phone_pro && $this->socid > 0) - { - $soc = new Societe($this->db); - $soc->fetch($this->socid); - $this->phone_pro = $soc->tel; - } - - $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET "; - $sql .= " civilite='".addslashes($this->civilite_id)."'"; - $sql .= ", name='".addslashes($this->name)."'"; - $sql .= ", firstname='".addslashes($this->firstname)."'"; - $sql .= ", address='".addslashes($this->address)."'"; - $sql .= ", cp='".addslashes($this->cp)."'"; - $sql .= ", ville='".addslashes($this->ville)."'"; - $sql .= ", fk_pays='".addslashes($this->fk_pays)."'"; - $sql .= ", poste='".addslashes($this->poste)."'"; - $sql .= ", fax='".addslashes($this->fax)."'"; - $sql .= ", email='".addslashes($this->email)."'"; - $sql .= ", note='".addslashes($this->note)."'"; - $sql .= ", phone = '".addslashes($this->phone_pro)."'"; - $sql .= ", phone_perso = '".addslashes($this->phone_perso)."'"; - $sql .= ", phone_mobile = '".addslashes($this->phone_mobile)."'"; - $sql .= ", jabberid = '".addslashes($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 - * \param user Utilisateur qui effectue la mise à jour - * - */ - function update_ldap($user) - { - $info = array(); - dolibarr_syslog("Contact::update_ldap",LOG_DEBUG); - - $this->fetch($this->id); - - $ds = dolibarr_ldap_connect(); - - if ($ds) - { - $ldapbind = dolibarr_ldap_bind($ds); - - if ($ldapbind) - { - if (LDAP_SERVER_TYPE == 'activedirectory') //enlever utf8 pour etre compatible Windows - { - $info["objectclass"][0] = "top"; - $info["objectclass"][1] = "person"; - $info["objectclass"][2] = "organizationalPerson"; - //$info["objectclass"][3] = "inetOrgPerson"; - $info["objectclass"][3] = "user"; - - $info["cn"] = $this->firstname." ".$this->name; - $info["sn"] = $this->name; - $info["givenName"] = $this->firstname; - - if ($this->poste) - $info["title"] = $this->poste; - - if ($this->socid > 0) - { - $soc = new Societe($this->db); - $soc->fetch($this->socid); - $info["o"] = $soc->nom; - $info["company"] = $soc->nom; - - if ($soc->client == 1) - $info["businessCategory"] = "Clients"; - elseif ($soc->client == 2) - $info["businessCategory"] = "Prospects"; - - if ($soc->fournisseur == 1) - $info["businessCategory"] = "Fournisseurs"; - - if ($soc->ville) - { - if ($soc->adresse) - $info["streetAddress"] = $soc->adresse; - - if ($soc->cp) - $info["postalCode"] = $soc->cp; - - $info["l"] = $soc->ville; - } - } - - if ($this->phone_pro) - $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro); - - if ($this->phone_perso) - $info["homePhone"] = dolibarr_print_phone($this->phone_perso); - - if ($this->phone_mobile) - $info["mobile"] = dolibarr_print_phone($this->phone_mobile); - - if ($this->fax) - $info["facsimileTelephoneNumber"] = dolibarr_print_phone($this->fax); - - if ($this->note) - $info["description"] = ($this->note); - if ($this->email) - $info["mail"] = $this->email; - - $dn = "cn=".$info["cn"].",".LDAP_CONTACT_DN; - - $r = @ldap_delete($ds, $dn); - - if (! @ldap_add($ds, $dn, $info)) - { - $this->error[0] = ldap_err2str(ldap_errno($ds)); - } - } - else - { - $info["objectclass"][0] = "top"; - $info["objectclass"][1] = "person"; - $info["objectclass"][2] = "organizationalPerson"; - $info["objectclass"][3] = "inetOrgPerson"; - - $info["cn"] = utf8_encode($this->firstname." ".$this->name); - $info["sn"] = utf8_encode($this->name); - $info["givenName"] = utf8_encode($this->firstname); - - if ($this->poste) - $info["title"] = utf8_encode($this->poste); - - if ($this->socid > 0) - { - $soc = new Societe($this->db); - $soc->fetch($this->socid); - $info["o"] = utf8_encode($soc->nom); - - if ($soc->client == 1) - $info["businessCategory"] = utf8_encode("Clients"); - elseif ($soc->client == 2) - $info["businessCategory"] = utf8_encode("Prospects"); - - if ($soc->fournisseur == 1) - $info["businessCategory"] = utf8_encode("Fournisseurs"); - - if ($soc->ville) - { - if ($soc->adresse) - $info["street"] = utf8_encode($soc->adresse); - - if ($soc->cp) - $info["postalCode"] = utf8_encode($soc->cp); - - $info["l"] = utf8_encode($soc->ville); - } - } - - if ($this->phone_pro) - $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro); - - if ($this->phone_perso) - $info["homePhone"] = dolibarr_print_phone($this->phone_perso); - - if ($this->phone_mobile) - $info["mobile"] = dolibarr_print_phone($this->phone_mobile); - - if ($this->fax) - $info["facsimileTelephoneNumber"] = dolibarr_print_phone($this->fax); - - if ($this->note) - $info["description"] = ($this->note); - - if(LDAP_SERVER_TYPE == 'egroupware') - { - $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware - - if ($this->email) - $info["rfc822Mailbox"] = $this->email; - - $info['uidnumber'] = $this->id; - - $info['phpgwTz'] = 0; - $info['phpgwMailType'] = 'INTERNET'; - $info['phpgwMailHomeType'] = 'INTERNET'; - - $info["uid"] = $this->id. ":".$info["sn"]; - $info["phpgwContactTypeId"] = 'n'; - $info["phpgwContactCatId"] = 0; - $info["phpgwContactAccess"] = "public"; - - if (strlen($user->egroupware_id) == 0) - { - $user->egroupware_id = 1; - } - - $info["phpgwContactOwner"] = $user->egroupware_id; - - if ($this->phone_mobile) - $info["phpgwCellTelephoneNumber"] = dolibarr_print_phone($this->phone_mobile); - } - else - { - if ($this->email) - $info["mail"] = $this->email; - } - - $dn = "cn=".$info["cn"].",".LDAP_CONTACT_DN; - - dolibarr_syslog("Contact::update_ldap dn : ".$dn,LOG_DEBUG); - - $r = @ldap_delete($ds, $dn); - - if (! @ldap_add($ds, $dn, $info)) - { - $this->error[0] = ldap_err2str(ldap_errno($ds)); - dolibarr_syslog("Contact::update_ldap error : ".$this->error[0],LOG_ERR); - } - } - } - else - { - dolibarr_syslog("Contact::update_ldap bind failed",LOG_DEBUG); - } - - dolibarr_ldap_unbind($ds); - - } - else - { - dolibarr_syslog("Contact::update_ldap Connexion failed",LOG_DEBUG); - echo "Impossible de se connecter au serveur LDAP !"; - } - } - - - /* - * \brief Mise à jour des alertes - * \param id id du contact - * \param user Utilisateur qui demande l'alerte - */ - function update_perso($id, $user=0) - { - // Mis a jour contact - $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET idp=$id "; - - if ($this->birthday>0) - { - if (eregi('\-',$this->birthday)) - { - // Si date = chaine - $sql .= ", birthday='".$this->birthday."'"; - } - else - { - // Si date = timestamp - $sql .= ", birthday=".$this->db->idate($this->birthday); - } - } - $sql .= " WHERE idp=$id"; - - $result = $this->db->query($sql); - if (!$result) - { - $this->error='Echec sql='.$sql; - } - - // Mis a jour alerte birthday - if ($this->birthday_alert) - { - $sql = "INSERT into ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) "; - $sql.= "values (1,".$id.",".$user->id.")"; - } - else - { - $sql = "DELETE from ".MAIN_DB_PREFIX."user_alert "; - $sql.= "where type=1 AND fk_contact=".$id." AND fk_user=".$user->id; - } - $result = $this->db->query($sql); - if (!$result) - { - $this->error='Echec sql='.$sql; - } - - return $result; - } - - - /* - * \brief Charge l'objet contact - * \param id id du contact - * \param user Utilisateur lié au contact pour une alerte - * \return int 1 si ok, -1 si erreur - */ - 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.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.= " u.rowid as user_id, u.login as user_login"; - $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."user as u ON c.idp = u.fk_socpeople"; - $sql.= " WHERE c.idp = ". $id; - - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->idp; - $this->civilite_id = $obj->civilite_id; - $this->name = $obj->name; - $this->firstname = $obj->firstname; - $this->nom = $obj->name; - $this->prenom = $obj->firstname; - - $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; - $this->poste = $obj->poste; - - $this->fullname = $this->firstname . ' ' . $this->name; - - $this->phone_pro = dolibarr_print_phone($obj->phone); - $this->fax = dolibarr_print_phone($obj->fax); - $this->phone_perso = dolibarr_print_phone($obj->phone_perso); - $this->phone_mobile = dolibarr_print_phone($obj->phone_mobile); - - $this->code = $obj->code; - $this->email = $obj->email; - $this->jabberid = $obj->jabberid; - $this->mail = $obj->email; - - $this->birthday = $obj->birthday; - $this->birthday_alert = $obj->birthday_alert; - $this->note = $obj->note; - - $this->user_id = $obj->user_id; - $this->user_login = $obj->user_login; - } - $this->db->free($resql); - - - // Recherche le user Dolibarr lié à ce contact - $sql = "SELECT u.rowid "; - $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE u.fk_socpeople = ". $id; - - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $uobj = $this->db->fetch_object($resql); - - $this->user_id = $uobj->rowid; - } - $this->db->free($resql); - } - else - { - dolibarr_syslog("Error in Contact::fetch() selectuser sql=$sql"); - $this->error="Error in Contact::fetch() selectuser - ".$this->db->error()." - ".$sql; - return -1; - } - - // Charge alertes du user - if ($user) - { - $sql = "SELECT fk_user"; - $sql .= " FROM ".MAIN_DB_PREFIX."user_alert"; - $sql .= " WHERE fk_user = $user->id AND fk_contact = ".$id; - - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); - - $this->birthday_alert = 1; - } - $this->db->free($resql); - } - else - { - dolibarr_syslog("Error in Contact::fetch() selectuseralert sql=$sql"); - $this->error="Error in Contact::fetch() selectuseralert - ".$this->db->error()." - ".$sql; - return -1; - } - } - - return 1; - } - else - { - dolibarr_syslog("Error in Contact::fetch() selectsocpeople sql=$sql"); - $this->error="Error in Contact::fetch() selectsocpeople - ".$this->db->error()." - ".$sql; - return -1; - } - } - - - /* - * \brief Charge le nombre d'elements auquel est lié ce contact - * ref_facturation - * ref_contrat - * ref_commande - * ref_propale - * \return int 0 si ok, -1 si erreur - */ - function load_ref_elements() - { - // Compte les elements pour lesquels il est contact - $sql ="SELECT tc.element, count(ec.rowid) as nb"; - $sql.=" FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.=" WHERE ec.fk_c_type_contact = tc.rowid"; - $sql.=" AND fk_socpeople = ". $this->id; - $sql.=" GROUP BY tc.element"; - - dolibarr_syslog("Contact::load_ref_elements sql=".$sql); - - $resql=$this->db->query($sql); - if ($resql) - { - while($obj=$this->db->fetch_object($resql)) - { - if ($obj->nb) - { - if ($obj->element=='facture') $this->ref_facturation = $obj->nb; - if ($obj->element=='contrat') $this->ref_contrat = $obj->nb; - if ($obj->element=='commande') $this->ref_commande = $obj->nb; - if ($obj->element=='propal') $this->ref_propal = $obj->nb; - } - } - $this->db->free($resql); - return 0; - } - else - { - $this->error=$this->db->error()." - ".$sql; - dolibarr_syslog("Contact::load_ref_elements Error ".$this->error); - return -1; - } - } - - /* - * \brief Efface le contact de la base et éventuellement de l'annuaire LDAP - * \param id id du contact a effacer - */ - function delete($id) - { - $sql = "SELECT c.name, c.firstname FROM ".MAIN_DB_PREFIX."socpeople as c"; - $sql .= " WHERE c.idp = ". $id; - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); - - $this->old_name = $obj->name; - $this->old_firstname = $obj->firstname; - } - } - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople"; - $sql .= " WHERE idp=$id"; - - $result = $this->db->query($sql); - - if (!$result) - { - print $this->db->error() . '
' . $sql; - } - - if (defined('MAIN_MODULE_LDAP') && MAIN_MODULE_LDAP) - { - if (defined('LDAP_CONTACT_ACTIVE') && LDAP_CONTACT_ACTIVE == 1) - { - - $ds = dolibarr_ldap_connect(); - - if ($ds) - { - $ldapbind = dolibarr_ldap_bind($ds); - - if ($ldapbind) - { - // delete from ldap directory - if (LDAP_SERVER_TYPE == 'activedirectory') - { - $userdn = $this->old_firstname." ".$this->old_name; //enlever utf8 pour etre compatible Windows - } - else - { - $userdn = utf8_encode($this->old_firstname." ".$this->old_name); - } - $dn = "cn=".$userdn.",".LDAP_CONTACT_DN; - - $r = @ldap_delete($ds, $dn); - - } - else - { - echo "LDAP bind failed..."; - } - ldap_close($ds); - - } - else - { - echo "Unable to connect to LDAP server"; - } - - - return $result; - } - } - } - - /* - * \brief Charge les informations sur le contact, depuis la base - * \param id id du contact à charger - */ - function info($id) - { - $sql = "SELECT c.idp, ".$this->db->pdate("datec")." as datec, fk_user"; - $sql .= ", ".$this->db->pdate("tms")." as tms, fk_user_modif"; - $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; - $sql .= " WHERE c.idp = $id"; - - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->idp; - - if ($obj->fk_user) { - $cuser = new User($this->db, $obj->fk_user); - $cuser->fetch(); - $this->user_creation = $cuser; - } - - if ($obj->fk_user_modif) { - $muser = new User($this->db, $obj->fk_user_modif); - $muser->fetch(); - $this->user_modification = $muser; - } - - $this->date_creation = $obj->datec; - $this->date_modification = $obj->tms; - - } - - $this->db->free($resql); - } - else - { - print $this->db->error(); - } - } - - /* - * \brief Renvoi nombre d'emailings reçu par le contact avec son email - * \return int Nombre d'emailings - */ - function getNbOfEMailings() - { - $sql = "SELECT count(mc.email) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; - $sql.= " WHERE mc.email = '".$this->email."'"; - $sql.= " AND mc.statut=1"; // -1 erreur, 0 non envoyé, 1 envoyé avec succès - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - $nb=$obj->nb; - - $this->db->free($resql); - return $nb; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } - -} -?> + + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2005 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/contact.class.php + \ingroup societe + \brief Fichier de la classe des contacts + \version $Revision$ +*/ + +require_once (DOL_DOCUMENT_ROOT."/lib/ldap.lib.php"); + + + +/** + \class Contact + \brief Classe permettant la gestion des contacts +*/ + +class Contact +{ + 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; + + var $ref_facturation; // Nb de reference facture pour lequel il est contact + var $ref_contrat; // Nb de reference contrat pour lequel il est contact + var $ref_commande; // Nb de reference commande pour lequel il est contact + var $ref_propal; // Nb de reference propal pour lequel il est contact + + /** + * \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; + } + + /** + * \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(),"; + if ($this->socid > 0) $sql.= " $this->socid,"; + else $sql.= "null,"; + $sql.= "'$this->name',$user->id)"; + + if ($this->db->query($sql) ) + { + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople"); + + $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; + } + } + + /* + * \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); + + $this->id = $id; + + $this->name=trim($this->name); + $this->firstname=trim($this->firstname); + $this->email=trim($this->email); + $this->phone_pro=trim($this->phone_pro); + + if ($this->phone_pro && $this->socid > 0) + { + $soc = new Societe($this->db); + $soc->fetch($this->socid); + $this->phone_pro = $soc->tel; + } + + $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET "; + $sql .= " civilite='".addslashes($this->civilite_id)."'"; + $sql .= ", name='".addslashes($this->name)."'"; + $sql .= ", firstname='".addslashes($this->firstname)."'"; + $sql .= ", address='".addslashes($this->address)."'"; + $sql .= ", cp='".addslashes($this->cp)."'"; + $sql .= ", ville='".addslashes($this->ville)."'"; + $sql .= ", fk_pays='".addslashes($this->fk_pays)."'"; + $sql .= ", poste='".addslashes($this->poste)."'"; + $sql .= ", fax='".addslashes($this->fax)."'"; + $sql .= ", email='".addslashes($this->email)."'"; + $sql .= ", note='".addslashes($this->note)."'"; + $sql .= ", phone = '".addslashes($this->phone_pro)."'"; + $sql .= ", phone_perso = '".addslashes($this->phone_perso)."'"; + $sql .= ", phone_mobile = '".addslashes($this->phone_mobile)."'"; + $sql .= ", jabberid = '".addslashes($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 + * \param user Utilisateur qui effectue la mise à jour + * + */ + function update_ldap($user) + { + $info = array(); + dolibarr_syslog("Contact::update_ldap",LOG_DEBUG); + + $this->fetch($this->id); + + $ds = dolibarr_ldap_connect(); + + if ($ds) + { + $ldapbind = dolibarr_ldap_bind($ds); + + if ($ldapbind) + { + if (LDAP_SERVER_TYPE == 'activedirectory') //enlever utf8 pour etre compatible Windows + { + $info["objectclass"][0] = "top"; + $info["objectclass"][1] = "person"; + $info["objectclass"][2] = "organizationalPerson"; + //$info["objectclass"][3] = "inetOrgPerson"; + $info["objectclass"][3] = "user"; + + $info["cn"] = $this->firstname." ".$this->name; + $info["sn"] = $this->name; + $info["givenName"] = $this->firstname; + + if ($this->poste) + $info["title"] = $this->poste; + + if ($this->socid > 0) + { + $soc = new Societe($this->db); + $soc->fetch($this->socid); + $info["o"] = $soc->nom; + $info["company"] = $soc->nom; + + if ($soc->client == 1) + $info["businessCategory"] = "Clients"; + elseif ($soc->client == 2) + $info["businessCategory"] = "Prospects"; + + if ($soc->fournisseur == 1) + $info["businessCategory"] = "Fournisseurs"; + + if ($soc->ville) + { + if ($soc->adresse) + $info["streetAddress"] = $soc->adresse; + + if ($soc->cp) + $info["postalCode"] = $soc->cp; + + $info["l"] = $soc->ville; + } + } + + if ($this->phone_pro) + $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro); + + if ($this->phone_perso) + $info["homePhone"] = dolibarr_print_phone($this->phone_perso); + + if ($this->phone_mobile) + $info["mobile"] = dolibarr_print_phone($this->phone_mobile); + + if ($this->fax) + $info["facsimileTelephoneNumber"] = dolibarr_print_phone($this->fax); + + if ($this->note) + $info["description"] = ($this->note); + if ($this->email) + $info["mail"] = $this->email; + + $dn = "cn=".$info["cn"].",".LDAP_CONTACT_DN; + + $r = @ldap_delete($ds, $dn); + + if (! @ldap_add($ds, $dn, $info)) + { + $this->error[0] = ldap_err2str(ldap_errno($ds)); + } + } + else + { + $info["objectclass"][0] = "top"; + $info["objectclass"][1] = "person"; + $info["objectclass"][2] = "organizationalPerson"; + $info["objectclass"][3] = "inetOrgPerson"; + + $info["cn"] = utf8_encode($this->firstname." ".$this->name); + $info["sn"] = utf8_encode($this->name); + $info["givenName"] = utf8_encode($this->firstname); + + if ($this->poste) + $info["title"] = utf8_encode($this->poste); + + if ($this->socid > 0) + { + $soc = new Societe($this->db); + $soc->fetch($this->socid); + $info["o"] = utf8_encode($soc->nom); + + if ($soc->client == 1) + $info["businessCategory"] = utf8_encode("Clients"); + elseif ($soc->client == 2) + $info["businessCategory"] = utf8_encode("Prospects"); + + if ($soc->fournisseur == 1) + $info["businessCategory"] = utf8_encode("Fournisseurs"); + + if ($soc->ville) + { + if ($soc->adresse) + $info["street"] = utf8_encode($soc->adresse); + + if ($soc->cp) + $info["postalCode"] = utf8_encode($soc->cp); + + $info["l"] = utf8_encode($soc->ville); + } + } + + if ($this->phone_pro) + $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro); + + if ($this->phone_perso) + $info["homePhone"] = dolibarr_print_phone($this->phone_perso); + + if ($this->phone_mobile) + $info["mobile"] = dolibarr_print_phone($this->phone_mobile); + + if ($this->fax) + $info["facsimileTelephoneNumber"] = dolibarr_print_phone($this->fax); + + if ($this->note) + $info["description"] = ($this->note); + + if(LDAP_SERVER_TYPE == 'egroupware') + { + $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware + + if ($this->email) + $info["rfc822Mailbox"] = $this->email; + + $info['uidnumber'] = $this->id; + + $info['phpgwTz'] = 0; + $info['phpgwMailType'] = 'INTERNET'; + $info['phpgwMailHomeType'] = 'INTERNET'; + + $info["uid"] = $this->id. ":".$info["sn"]; + $info["phpgwContactTypeId"] = 'n'; + $info["phpgwContactCatId"] = 0; + $info["phpgwContactAccess"] = "public"; + + if (strlen($user->egroupware_id) == 0) + { + $user->egroupware_id = 1; + } + + $info["phpgwContactOwner"] = $user->egroupware_id; + + if ($this->phone_mobile) + $info["phpgwCellTelephoneNumber"] = dolibarr_print_phone($this->phone_mobile); + } + else + { + if ($this->email) + $info["mail"] = $this->email; + } + + $dn = "cn=".$info["cn"].",".LDAP_CONTACT_DN; + + dolibarr_syslog("Contact::update_ldap dn : ".$dn,LOG_DEBUG); + + $r = @ldap_delete($ds, $dn); + + if (! @ldap_add($ds, $dn, $info)) + { + $this->error[0] = ldap_err2str(ldap_errno($ds)); + dolibarr_syslog("Contact::update_ldap error : ".$this->error[0],LOG_ERR); + } + } + } + else + { + dolibarr_syslog("Contact::update_ldap bind failed",LOG_DEBUG); + } + + dolibarr_ldap_unbind($ds); + + } + else + { + dolibarr_syslog("Contact::update_ldap Connexion failed",LOG_DEBUG); + echo "Impossible de se connecter au serveur LDAP !"; + } + } + + + /* + * \brief Mise à jour des alertes + * \param id id du contact + * \param user Utilisateur qui demande l'alerte + */ + function update_perso($id, $user=0) + { + // Mis a jour contact + $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET idp=$id "; + + if ($this->birthday>0) + { + if (eregi('\-',$this->birthday)) + { + // Si date = chaine + $sql .= ", birthday='".$this->birthday."'"; + } + else + { + // Si date = timestamp + $sql .= ", birthday=".$this->db->idate($this->birthday); + } + } + $sql .= " WHERE idp=$id"; + + $result = $this->db->query($sql); + if (!$result) + { + $this->error='Echec sql='.$sql; + } + + // Mis a jour alerte birthday + if ($this->birthday_alert) + { + $sql = "INSERT into ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) "; + $sql.= "values (1,".$id.",".$user->id.")"; + } + else + { + $sql = "DELETE from ".MAIN_DB_PREFIX."user_alert "; + $sql.= "where type=1 AND fk_contact=".$id." AND fk_user=".$user->id; + } + $result = $this->db->query($sql); + if (!$result) + { + $this->error='Echec sql='.$sql; + } + + return $result; + } + + + /* + * \brief Charge l'objet contact + * \param id id du contact + * \param user Utilisateur lié au contact pour une alerte + * \return int 1 si ok, -1 si erreur + */ + 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.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.= " u.rowid as user_id, u.login as user_login"; + $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."user as u ON c.idp = u.fk_socpeople"; + $sql.= " WHERE c.idp = ". $id; + + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->idp; + $this->civilite_id = $obj->civilite_id; + $this->name = $obj->name; + $this->firstname = $obj->firstname; + $this->nom = $obj->name; + $this->prenom = $obj->firstname; + + $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; + $this->poste = $obj->poste; + + $this->fullname = $this->firstname . ' ' . $this->name; + + $this->phone_pro = $obj->phone; + $this->fax = $obj->fax; + $this->phone_perso = $obj->phone_perso; + $this->phone_mobile = $obj->phone_mobile; + + $this->code = $obj->code; + $this->email = $obj->email; + $this->jabberid = $obj->jabberid; + $this->mail = $obj->email; + + $this->birthday = $obj->birthday; + $this->birthday_alert = $obj->birthday_alert; + $this->note = $obj->note; + + $this->user_id = $obj->user_id; + $this->user_login = $obj->user_login; + } + $this->db->free($resql); + + + // Recherche le user Dolibarr lié à ce contact + $sql = "SELECT u.rowid "; + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql .= " WHERE u.fk_socpeople = ". $id; + + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $uobj = $this->db->fetch_object($resql); + + $this->user_id = $uobj->rowid; + } + $this->db->free($resql); + } + else + { + dolibarr_syslog("Error in Contact::fetch() selectuser sql=$sql"); + $this->error="Error in Contact::fetch() selectuser - ".$this->db->error()." - ".$sql; + return -1; + } + + // Charge alertes du user + if ($user) + { + $sql = "SELECT fk_user"; + $sql .= " FROM ".MAIN_DB_PREFIX."user_alert"; + $sql .= " WHERE fk_user = $user->id AND fk_contact = ".$id; + + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->birthday_alert = 1; + } + $this->db->free($resql); + } + else + { + dolibarr_syslog("Error in Contact::fetch() selectuseralert sql=$sql"); + $this->error="Error in Contact::fetch() selectuseralert - ".$this->db->error()." - ".$sql; + return -1; + } + } + + return 1; + } + else + { + dolibarr_syslog("Error in Contact::fetch() selectsocpeople sql=$sql"); + $this->error="Error in Contact::fetch() selectsocpeople - ".$this->db->error()." - ".$sql; + return -1; + } + } + + + /* + * \brief Charge le nombre d'elements auquel est lié ce contact + * ref_facturation + * ref_contrat + * ref_commande + * ref_propale + * \return int 0 si ok, -1 si erreur + */ + function load_ref_elements() + { + // Compte les elements pour lesquels il est contact + $sql ="SELECT tc.element, count(ec.rowid) as nb"; + $sql.=" FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql.=" WHERE ec.fk_c_type_contact = tc.rowid"; + $sql.=" AND fk_socpeople = ". $this->id; + $sql.=" GROUP BY tc.element"; + + dolibarr_syslog("Contact::load_ref_elements sql=".$sql); + + $resql=$this->db->query($sql); + if ($resql) + { + while($obj=$this->db->fetch_object($resql)) + { + if ($obj->nb) + { + if ($obj->element=='facture') $this->ref_facturation = $obj->nb; + if ($obj->element=='contrat') $this->ref_contrat = $obj->nb; + if ($obj->element=='commande') $this->ref_commande = $obj->nb; + if ($obj->element=='propal') $this->ref_propal = $obj->nb; + } + } + $this->db->free($resql); + return 0; + } + else + { + $this->error=$this->db->error()." - ".$sql; + dolibarr_syslog("Contact::load_ref_elements Error ".$this->error); + return -1; + } + } + + /* + * \brief Efface le contact de la base et éventuellement de l'annuaire LDAP + * \param id id du contact a effacer + */ + function delete($id) + { + $sql = "SELECT c.name, c.firstname FROM ".MAIN_DB_PREFIX."socpeople as c"; + $sql .= " WHERE c.idp = ". $id; + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->old_name = $obj->name; + $this->old_firstname = $obj->firstname; + } + } + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople"; + $sql .= " WHERE idp=$id"; + + $result = $this->db->query($sql); + + if (!$result) + { + print $this->db->error() . '
' . $sql; + } + + if (defined('MAIN_MODULE_LDAP') && MAIN_MODULE_LDAP) + { + if (defined('LDAP_CONTACT_ACTIVE') && LDAP_CONTACT_ACTIVE == 1) + { + + $ds = dolibarr_ldap_connect(); + + if ($ds) + { + $ldapbind = dolibarr_ldap_bind($ds); + + if ($ldapbind) + { + // delete from ldap directory + if (LDAP_SERVER_TYPE == 'activedirectory') + { + $userdn = $this->old_firstname." ".$this->old_name; //enlever utf8 pour etre compatible Windows + } + else + { + $userdn = utf8_encode($this->old_firstname." ".$this->old_name); + } + $dn = "cn=".$userdn.",".LDAP_CONTACT_DN; + + $r = @ldap_delete($ds, $dn); + + } + else + { + echo "LDAP bind failed..."; + } + ldap_close($ds); + + } + else + { + echo "Unable to connect to LDAP server"; + } + + + return $result; + } + } + } + + /* + * \brief Charge les informations sur le contact, depuis la base + * \param id id du contact à charger + */ + function info($id) + { + $sql = "SELECT c.idp, ".$this->db->pdate("datec")." as datec, fk_user"; + $sql .= ", ".$this->db->pdate("tms")." as tms, fk_user_modif"; + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; + $sql .= " WHERE c.idp = $id"; + + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->idp; + + if ($obj->fk_user) { + $cuser = new User($this->db, $obj->fk_user); + $cuser->fetch(); + $this->user_creation = $cuser; + } + + if ($obj->fk_user_modif) { + $muser = new User($this->db, $obj->fk_user_modif); + $muser->fetch(); + $this->user_modification = $muser; + } + + $this->date_creation = $obj->datec; + $this->date_modification = $obj->tms; + + } + + $this->db->free($resql); + } + else + { + print $this->db->error(); + } + } + + /* + * \brief Renvoi nombre d'emailings reçu par le contact avec son email + * \return int Nombre d'emailings + */ + function getNbOfEMailings() + { + $sql = "SELECT count(mc.email) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; + $sql.= " WHERE mc.email = '".addslashes($this->email)."'"; + $sql.= " AND mc.statut=1"; // -1 erreur, 0 non envoyé, 1 envoyé avec succès + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + $nb=$obj->nb; + + $this->db->free($resql); + return $nb; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + +} +?> diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index da90478a5ff..72d97fcec92 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -1,651 +1,651 @@ - - * Copyright (C) 2004-2005 Laurent Destailleur - * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ - */ - -/** - \file htdocs/contact/fiche.php - \ingroup societe - \brief Onglet général d'un contact - \version $Revision$ -*/ - -require("./pre.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); -require_once(DOL_DOCUMENT_ROOT."/lib/vcard/vcard.class.php"); - -$langs->load("companies"); -$langs->load("users"); - -$error = array(); -$socid=$_GET["socid"]?$_GET["socid"]:$_POST["socid"]; - - -if ($_GET["action"] == 'create_user' && $user->admin) -{ - // Recuperation contact actuel - $contact = new Contact($db); - $result = $contact->fetch($_GET["id"]); - - // Creation user - $nuser = new User($db); - $nuser->nom = $contact->name; - $nuser->prenom = $contact->firstname; - $nuser->create_from_contact($contact); -} - -if ($_POST["action"] == 'add') -{ - $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"]; - - if (! $_POST["name"]) - { - array_push($error,$langs->trans("ErrorFieldRequired",$langs->trans("Lastname"))); - $_GET["action"]="create"; - } - - if ($_POST["name"]) - { - $id = $contact->create($user); - if ($id > 0) - { - Header("Location: fiche.php?id=".$id); - exit; - } - - $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"); - exit; -} - - -if ($_POST["action"] == 'update') -{ - $contact = new Contact($db); - - $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->note = $_POST["note"]; - - $result = $contact->update($_POST["contactid"], $user); - - if ($contact->error) - { - $error = $contact->error; - } -} - - -/* - * - * - */ - -llxHeader(); -$form = new Form($db); - -if ($socid) -{ - $objsoc = new Societe($db); - $objsoc->fetch($socid); -} - - -/* - * Onglets - */ -if ($_GET["id"] > 0) -{ - // Si edition contact deja existant - $contact = new Contact($db); - $return=$contact->fetch($_GET["id"], $user); - if ($return < 0) - { - dolibarr_print_error('',$contact->error); - } - - $h=0; - $head[$h][0] = DOL_URL_ROOT.'/contact/fiche.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("General"); - $hselected=$h; - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("PersonalInformations"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/contact/exportimport.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("ExportImport"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/contact/info.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("Info"); - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); -} - - -/* - * Confirmation de la suppression du contact - * - */ -if ($_GET["action"] == 'delete') -{ - $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],"Supprimer le contact","Êtes-vous sûr de vouloir supprimer ce contact ?","confirm_delete"); - print '
'; -} - -if ($_GET["action"] == 'create') -{ - /* - * Fiche en mode creation - * - */ - print_fiche_titre($langs->trans("AddContact")); - - // Affiche les erreurs - if (sizeof($error)) - { - print "
"; - print join("
",$error); - print "
\n"; - } - - print '
'; - print '
'; - print ''; - print ''; - - 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 ''; - } - else { - 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").''; - //print $form->select_societes('','socid',''); - print $langs->trans("ContactNotLinkedToCompany"); - print '
'.$langs->trans("UserTitle").''; - print $form->select_civilite($contact->civilite_id); - print '
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
Poste/Fonction
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; - print '
'.$langs->trans("Country").''; - $form->select_pays($contact->fk_pays); - print '
Tel ProTel Perso
Portable'.$langs->trans("Fax").'
'.$langs->trans("Email").'
Jabberid
'.$langs->trans("Note").'

"; - - print "
"; -} -elseif ($_GET["action"] == 'edit' && $_GET["id"]) -{ - /* - * Fiche en mode edition - * - */ - - // Affiche les erreurs - if (sizeof($error)) - { - print "
"; - print join("
",$error); - print "
\n"; - } - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - if ($contact->socid > 0) - { - $objsoc = new Societe($db); - $objsoc->fetch($contact->socid); - - print ''; - } - else - { - print ''; - } - print ''; - - print ''; - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - print ''; - - print ''; - print ''; - - print ''; - if ($conf->mailing->enabled) - { - $langs->load("mails"); - print ''; - print ''; - } - else - { - print ''; - } - print ''; - - print ''; - - print ''; - - $contact->load_ref_elements(); - - if ($conf->facture->enabled) - { - print ''; - } - - if ($conf->contrat->enabled) - { - print ''; - } - - print ''; - - print ''; - print '
'.$langs->trans("Company").''.$objsoc->nom_url.'
'.$langs->trans("Company").''; - print $langs->trans("ContactNotLinkedToCompany"); - print '
'.$langs->trans("UserTitle").''; - print $form->select_civilite($contact->civilite_id); - print '
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
Poste/Fonction
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; - print '
'.$langs->trans("Country").''; - $form->select_pays($contact->fk_pays); - print '
Tel ProTel Perso
Portable'.$langs->trans("Fax").'
'.$langs->trans("EMail").''.$langs->trans("NbOfEMailingsReceived").''.$contact->getNbOfEMailings().' 
Jabberid
'.$langs->trans("Note").''; - print '
'.$langs->trans("ContactForInvoices").''; - print $contact->ref_facturation?$contact->ref_facturation:$langs->trans("NoContactForAnyInvoice"); - print '
'.$langs->trans("ContactForContracts").''; - print $contact->ref_contrat?$contact->ref_contrat:$langs->trans("NoContactForAnyContract"); - print '
'.$langs->trans("DolibarrLogin").''; - if ($contact->user_id) print ''.$contact->user_login.''; - else print $langs->trans("NoDolibarrAccess"); - print '
'; - - print "
"; -} -elseif ($_GET["id"]) -{ - /* - * Fiche en mode visualisation - * - */ - - print ''; - - if ($contact->socid > 0) - { - $objsoc = new Societe($db); - $objsoc->fetch($contact->socid); - - print ''; - } - else - { - print ''; - } - - print ''; - - print ''; - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - print ''; - - print ''; - print ''; - - print ''; - if ($conf->mailing->enabled) - { - $langs->load("mails"); - print ''; - print ''; - } - else - { - print ''; - } - print ''; - - print ''; - - print ''; - - $contact->load_ref_elements(); - - if ($conf->facture->enabled) - { - print ''; - } - - if ($conf->contrat->enabled) - { - print ''; - } - - print ''; - - print "
'.$langs->trans("Company").''.$objsoc->nom_url.'
'.$langs->trans("Company").''; - print $langs->trans("ContactNotLinkedToCompany"); - print '
'.$langs->trans("UserTitle").''; - print $form->civilite_name($contact->civilite_id); - print '
'.$langs->trans("Lastname").''.$contact->name.''.$langs->trans("Firstname").''.$contact->firstname.'
Poste/Fonction'.$contact->poste.'
'.$langs->trans("Address").''.$contact->address.'
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$contact->cp.' '; - print $contact->ville.'
'.$langs->trans("Country").''; - print $contact->pays; - print '
Tel Pro'.$contact->phone_pro.'Tel Perso'.$contact->phone_perso.'
Portable'.$contact->phone_mobile.''.$langs->trans("Fax").''.$contact->fax.'
'.$langs->trans("EMail").''; - if ($contact->email && ! ValidEmail($contact->email)) - { - print ''.$langs->trans("ErrorBadEMail",$contact->email).""; - } - else - { - print $contact->email; - } - print ''.$langs->trans("NbOfEMailingsReceived").''.$contact->getNbOfEMailings().' 
Jabberid'.$contact->jabberid.'
'.$langs->trans("Note").''; - print nl2br($contact->note); - print '
'.$langs->trans("ContactForInvoices").''; - print $contact->ref_facturation?$contact->ref_facturation:$langs->trans("NoContactForAnyInvoice"); - print '
'.$langs->trans("ContactForContracts").''; - print $contact->ref_contrat?$contact->ref_contrat:$langs->trans("NoContactForAnyContract"); - print '
'.$langs->trans("DolibarrLogin").''; - if ($contact->user_id) print ''.$contact->user_login.''; - else print $langs->trans("NoDolibarrAccess"); - print '
"; - - print ""; - - - // Barre d'actions - if (! $user->societe_id) - { - print '
'; - - if ($user->rights->societe->contact->creer) - { - print ''.$langs->trans('Edit').''; - } - - if (! $contact->user_id && $user->admin) - { - print ''.$langs->trans("CreateDolibarrLogin").''; - } - - if ($user->rights->societe->contact->supprimer) - { - print ''.$langs->trans('Delete').''; - } - - print "

"; - } - - - // Historique des actions sur ce contact - print_titre ($langs->trans("TasksHistoryForThisContact")); - $histo=array(); - $numaction = 0 ; - - // Recherche histo sur actioncomm - $sql = "SELECT a.id, ".$db->pdate("a.datea")." as da, a.note, a.percent as percent,"; - $sql.= " c.code as acode, c.libelle,"; - $sql.= " u.rowid as user_id, u.code"; - $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u "; - $sql.= " WHERE fk_contact = ".$contact->id; - $sql.= " AND u.rowid = a.fk_user_author"; - $sql.= " AND c.id=a.fk_action"; - $sql.= " ORDER BY a.datea DESC, a.id DESC"; - - $resql=$db->query($sql); - if ($resql) - { - $i = 0 ; - $num = $db->num_rows($resql); - $var=true; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - $histo[$numaction]=array('type'=>'action','id'=>$obj->id,'date'=>$obj->da,'note'=>$obj->note,'percent'=>$obj->percent, - 'acode'=>$obj->acode,'libelle'=>$obj->libelle, - 'userid'=>$obj->user_id,'code'=>$obj->code); - $numaction++; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - - // Recherche histo sur mailing - $sql = "SELECT m.rowid as id, ".$db->pdate("mc.date_envoi")." as da, m.titre as note, '100' as percent,"; - $sql.= " 'AC_EMAILING' as acode,"; - $sql.= " u.rowid as user_id, u.code"; - $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u "; - $sql.= " WHERE mc.email = '".$contact->email."'"; - $sql.= " AND mc.statut = 1"; - $sql.= " AND u.rowid = m.fk_user_valid"; - $sql.= " AND mc.fk_mailing=m.rowid"; - $sql.= " ORDER BY mc.date_envoi DESC, m.rowid DESC"; - - $resql=$db->query($sql); - if ($resql) - { - $i = 0 ; - $num = $db->num_rows($resql); - $var=true; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - $histo[$numaction]=array('type'=>'mailing','id'=>$obj->id,'date'=>$obj->da,'note'=>$obj->note,'percent'=>$obj->percent, - 'acode'=>$obj->acode,'libelle'=>$obj->libelle, - 'userid'=>$obj->user_id,'code'=>$obj->code); - $numaction++; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - - // Affichage actions sur contact - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - foreach ($histo as $key=>$value) - { - $var=!$var; - print ""; - - // Date - print ""; - - // Status/Percent - if ($histo[$key]['percent'] < 100) { - print ""; - } - else { - print ""; - } - - // Action - print ''; - - // Note - print ''; - - // Author - print '"; - print "\n"; - } - print "
'.$langs->trans("Date").''.$langs->trans("Status").''.$langs->trans("Actions").''.$langs->trans("Comments").''.$langs->trans("Author").'
". dolibarr_print_date($histo[$key]['date'],"%d %b %Y %H:%M") ."".$histo[$key]['percent']."%".$langs->trans("Done")."'; - if ($histo[$key]['type']=='action') - { - print ''.img_object($langs->trans("ShowTask"),"task").' '; - $transcode=$langs->trans("Action".$histo[$key]['acode']); - $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:$histo[$key]['libelle']); - print dolibarr_trunc($libelle,30); - print ''; - } - if ($histo[$key]['type']=='mailing') - { - print ''.img_object($langs->trans("ShowEMailing"),"email").' '; - $transcode=$langs->trans("Action".$histo[$key]['acode']); - $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:'Send mass mailing'); - print dolibarr_trunc($libelle,30); - print ''; - } - print ''.dolibarr_trunc($histo[$key]['note'], 30).''; - if ($histo[$key]['code']) - { - print ''.img_object($langs->trans("ShowUser"),'user').' '.$histo[$key]['code'].''; - } - else print " "; - print "
"; - - print '
'; -} - -$db->close(); - -llxFooter('$Date$ - $Revision$'); - -?> + + * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2005 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/contact/fiche.php + \ingroup societe + \brief Onglet général d'un contact + \version $Revision$ +*/ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/vcard/vcard.class.php"); + +$langs->load("companies"); +$langs->load("users"); + +$error = array(); +$socid=$_GET["socid"]?$_GET["socid"]:$_POST["socid"]; + + +if ($_GET["action"] == 'create_user' && $user->admin) +{ + // Recuperation contact actuel + $contact = new Contact($db); + $result = $contact->fetch($_GET["id"]); + + // Creation user + $nuser = new User($db); + $nuser->nom = $contact->name; + $nuser->prenom = $contact->firstname; + $nuser->create_from_contact($contact); +} + +if ($_POST["action"] == 'add') +{ + $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"]; + + if (! $_POST["name"]) + { + array_push($error,$langs->trans("ErrorFieldRequired",$langs->trans("Lastname"))); + $_GET["action"]="create"; + } + + if ($_POST["name"]) + { + $id = $contact->create($user); + if ($id > 0) + { + Header("Location: fiche.php?id=".$id); + exit; + } + + $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"); + exit; +} + + +if ($_POST["action"] == 'update') +{ + $contact = new Contact($db); + + $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->note = $_POST["note"]; + + $result = $contact->update($_POST["contactid"], $user); + + if ($contact->error) + { + $error = $contact->error; + } +} + + +/* + * + * + */ + +llxHeader(); +$form = new Form($db); + +if ($socid) +{ + $objsoc = new Societe($db); + $objsoc->fetch($socid); +} + + +/* + * Onglets + */ +if ($_GET["id"] > 0) +{ + // Si edition contact deja existant + $contact = new Contact($db); + $return=$contact->fetch($_GET["id"], $user); + if ($return < 0) + { + dolibarr_print_error('',$contact->error); + } + + $h=0; + $head[$h][0] = DOL_URL_ROOT.'/contact/fiche.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("General"); + $hselected=$h; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("PersonalInformations"); + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/contact/exportimport.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("ExportImport"); + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/contact/info.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("Info"); + $h++; + + dolibarr_fiche_head($head, $hselected, $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); +} + + +/* + * Confirmation de la suppression du contact + * + */ +if ($_GET["action"] == 'delete') +{ + $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],"Supprimer le contact","Êtes-vous sûr de vouloir supprimer ce contact ?","confirm_delete"); + print '
'; +} + +if ($_GET["action"] == 'create') +{ + /* + * Fiche en mode creation + * + */ + print_fiche_titre($langs->trans("AddContact")); + + // Affiche les erreurs + if (sizeof($error)) + { + print "
"; + print join("
",$error); + print "
\n"; + } + + print '
'; + print '
'; + print ''; + print ''; + + 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 ''; + } + else { + 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").''; + //print $form->select_societes('','socid',''); + print $langs->trans("ContactNotLinkedToCompany"); + print '
'.$langs->trans("UserTitle").''; + print $form->select_civilite($contact->civilite_id); + print '
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
Poste/Fonction
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; + print '
'.$langs->trans("Country").''; + $form->select_pays($contact->fk_pays); + print '
Tel ProTel Perso
Portable'.$langs->trans("Fax").'
'.$langs->trans("Email").'
Jabberid
'.$langs->trans("Note").'

"; + + print "
"; +} +elseif ($_GET["action"] == 'edit' && $_GET["id"]) +{ + /* + * Fiche en mode edition + * + */ + + // Affiche les erreurs + if (sizeof($error)) + { + print "
"; + print join("
",$error); + print "
\n"; + } + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + if ($contact->socid > 0) + { + $objsoc = new Societe($db); + $objsoc->fetch($contact->socid); + + print ''; + } + else + { + print ''; + } + print ''; + + print ''; + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + if ($conf->mailing->enabled) + { + $langs->load("mails"); + print ''; + print ''; + } + else + { + print ''; + } + print ''; + + print ''; + + print ''; + + $contact->load_ref_elements(); + + if ($conf->facture->enabled) + { + print ''; + } + + if ($conf->contrat->enabled) + { + print ''; + } + + print ''; + + print ''; + print '
'.$langs->trans("Company").''.$objsoc->nom_url.'
'.$langs->trans("Company").''; + print $langs->trans("ContactNotLinkedToCompany"); + print '
'.$langs->trans("UserTitle").''; + print $form->select_civilite($contact->civilite_id); + print '
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
Poste/Fonction
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; + print '
'.$langs->trans("Country").''; + $form->select_pays($contact->fk_pays); + print '
Tel ProTel Perso
Portable'.$langs->trans("Fax").'
'.$langs->trans("EMail").''.$langs->trans("NbOfEMailingsReceived").''.$contact->getNbOfEMailings().' 
Jabberid
'.$langs->trans("Note").''; + print '
'.$langs->trans("ContactForInvoices").''; + print $contact->ref_facturation?$contact->ref_facturation:$langs->trans("NoContactForAnyInvoice"); + print '
'.$langs->trans("ContactForContracts").''; + print $contact->ref_contrat?$contact->ref_contrat:$langs->trans("NoContactForAnyContract"); + print '
'.$langs->trans("DolibarrLogin").''; + if ($contact->user_id) print ''.$contact->user_login.''; + else print $langs->trans("NoDolibarrAccess"); + print '
'; + + print "
"; +} +elseif ($_GET["id"]) +{ + /* + * Fiche en mode visualisation + * + */ + + print ''; + + if ($contact->socid > 0) + { + $objsoc = new Societe($db); + $objsoc->fetch($contact->socid); + + print ''; + } + else + { + print ''; + } + + print ''; + + print ''; + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + if ($conf->mailing->enabled) + { + $langs->load("mails"); + print ''; + print ''; + } + else + { + print ''; + } + print ''; + + print ''; + + print ''; + + $contact->load_ref_elements(); + + if ($conf->facture->enabled) + { + print ''; + } + + if ($conf->contrat->enabled) + { + print ''; + } + + print ''; + + print "
'.$langs->trans("Company").''.$objsoc->nom_url.'
'.$langs->trans("Company").''; + print $langs->trans("ContactNotLinkedToCompany"); + print '
'.$langs->trans("UserTitle").''; + print $form->civilite_name($contact->civilite_id); + print '
'.$langs->trans("Lastname").''.$contact->name.''.$langs->trans("Firstname").''.$contact->firstname.'
Poste/Fonction'.$contact->poste.'
'.$langs->trans("Address").''.$contact->address.'
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$contact->cp.' '; + print $contact->ville.'
'.$langs->trans("Country").''; + print $contact->pays; + print '
Tel Pro'.$contact->phone_pro.'Tel Perso'.$contact->phone_perso.'
Portable'.$contact->phone_mobile.''.$langs->trans("Fax").''.$contact->fax.'
'.$langs->trans("EMail").''; + if ($contact->email && ! ValidEmail($contact->email)) + { + print ''.$langs->trans("ErrorBadEMail",$contact->email).""; + } + else + { + print $contact->email; + } + print ''.$langs->trans("NbOfEMailingsReceived").''.$contact->getNbOfEMailings().' 
Jabberid'.$contact->jabberid.'
'.$langs->trans("Note").''; + print nl2br($contact->note); + print '
'.$langs->trans("ContactForInvoices").''; + print $contact->ref_facturation?$contact->ref_facturation:$langs->trans("NoContactForAnyInvoice"); + print '
'.$langs->trans("ContactForContracts").''; + print $contact->ref_contrat?$contact->ref_contrat:$langs->trans("NoContactForAnyContract"); + print '
'.$langs->trans("DolibarrLogin").''; + if ($contact->user_id) print ''.$contact->user_login.''; + else print $langs->trans("NoDolibarrAccess"); + print '
"; + + print ""; + + + // Barre d'actions + if (! $user->societe_id) + { + print '
'; + + if ($user->rights->societe->contact->creer) + { + print ''.$langs->trans('Edit').''; + } + + if (! $contact->user_id && $user->admin) + { + print ''.$langs->trans("CreateDolibarrLogin").''; + } + + if ($user->rights->societe->contact->supprimer) + { + print ''.$langs->trans('Delete').''; + } + + print "

"; + } + + + // Historique des actions sur ce contact + print_titre ($langs->trans("TasksHistoryForThisContact")); + $histo=array(); + $numaction = 0 ; + + // Recherche histo sur actioncomm + $sql = "SELECT a.id, ".$db->pdate("a.datea")." as da, a.note, a.percent as percent,"; + $sql.= " c.code as acode, c.libelle,"; + $sql.= " u.rowid as user_id, u.code"; + $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u "; + $sql.= " WHERE fk_contact = ".$contact->id; + $sql.= " AND u.rowid = a.fk_user_author"; + $sql.= " AND c.id=a.fk_action"; + $sql.= " ORDER BY a.datea DESC, a.id DESC"; + + $resql=$db->query($sql); + if ($resql) + { + $i = 0 ; + $num = $db->num_rows($resql); + $var=true; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + $histo[$numaction]=array('type'=>'action','id'=>$obj->id,'date'=>$obj->da,'note'=>$obj->note,'percent'=>$obj->percent, + 'acode'=>$obj->acode,'libelle'=>$obj->libelle, + 'userid'=>$obj->user_id,'code'=>$obj->code); + $numaction++; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + + // Recherche histo sur mailing + $sql = "SELECT m.rowid as id, ".$db->pdate("mc.date_envoi")." as da, m.titre as note, '100' as percent,"; + $sql.= " 'AC_EMAILING' as acode,"; + $sql.= " u.rowid as user_id, u.code"; + $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u "; + $sql.= " WHERE mc.email = '".addslashes($contact->email)."'"; + $sql.= " AND mc.statut = 1"; + $sql.= " AND u.rowid = m.fk_user_valid"; + $sql.= " AND mc.fk_mailing=m.rowid"; + $sql.= " ORDER BY mc.date_envoi DESC, m.rowid DESC"; + + $resql=$db->query($sql); + if ($resql) + { + $i = 0 ; + $num = $db->num_rows($resql); + $var=true; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + $histo[$numaction]=array('type'=>'mailing','id'=>$obj->id,'date'=>$obj->da,'note'=>$obj->note,'percent'=>$obj->percent, + 'acode'=>$obj->acode,'libelle'=>$obj->libelle, + 'userid'=>$obj->user_id,'code'=>$obj->code); + $numaction++; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + + // Affichage actions sur contact + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + foreach ($histo as $key=>$value) + { + $var=!$var; + print ""; + + // Date + print ""; + + // Status/Percent + if ($histo[$key]['percent'] < 100) { + print ""; + } + else { + print ""; + } + + // Action + print ''; + + // Note + print ''; + + // Author + print '"; + print "\n"; + } + print "
'.$langs->trans("Date").''.$langs->trans("Status").''.$langs->trans("Actions").''.$langs->trans("Comments").''.$langs->trans("Author").'
". dolibarr_print_date($histo[$key]['date'],"%d %b %Y %H:%M") ."".$histo[$key]['percent']."%".$langs->trans("Done")."'; + if ($histo[$key]['type']=='action') + { + print ''.img_object($langs->trans("ShowTask"),"task").' '; + $transcode=$langs->trans("Action".$histo[$key]['acode']); + $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:$histo[$key]['libelle']); + print dolibarr_trunc($libelle,30); + print ''; + } + if ($histo[$key]['type']=='mailing') + { + print ''.img_object($langs->trans("ShowEMailing"),"email").' '; + $transcode=$langs->trans("Action".$histo[$key]['acode']); + $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:'Send mass mailing'); + print dolibarr_trunc($libelle,30); + print ''; + } + print ''.dolibarr_trunc($histo[$key]['note'], 30).''; + if ($histo[$key]['code']) + { + print ''.img_object($langs->trans("ShowUser"),'user').' '.$histo[$key]['code'].''; + } + else print " "; + print "
"; + + print '
'; +} + +$db->close(); + +llxFooter('$Date$ - $Revision$'); + +?>