From 023d89538df68750a316d825835066331982ec4b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 18 Sep 2005 18:23:12 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20nombre=20de=20mailings=20de=20masse=20r?= =?UTF-8?q?e=E7ues=20sur=20la=20fiche=20contacts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/contact.class.php | 109 +++++++++++++++--------- htdocs/contact/fiche.php | 178 ++++++++++++++++++++++++++++++--------- htdocs/contact/index.php | 32 ++++--- 3 files changed, 222 insertions(+), 97 deletions(-) diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index fc94ae19bdd..ec99dffc827 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -653,47 +653,76 @@ class Contact } } - /* - * \brief Charge les informations sur le contact, depuis la base - * \param id id du contact à charger - */ - function info($id) + /* + * \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"; - if ($this->db->query($sql)) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object(); - - $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(); - } - else - { - print $this->db->error(); - } + $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; + } + } + } ?> diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index abcd1a6c648..120a6146a74 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -269,8 +269,8 @@ if ($_GET["action"] == 'create') print 'Tel Pro'; print 'Tel Perso'; - print ''.$langs->trans("Fax").''; - print 'Portable'; + print 'Portable'; + print ''.$langs->trans("Fax").''; print ''.$langs->trans("Email").''; @@ -339,7 +339,18 @@ elseif ($_GET["action"] == 'edit') print 'Portable'; print ''.$langs->trans("Fax").''; - print ''.$langs->trans("EMail").''; + print ''.$langs->trans("EMail").''; + if ($conf->mailing->enabled) + { + $langs->load("mails"); + print ''.$langs->trans("NbOfEMailingsReceived").''; + print ''.$contact->getNbOfEMailings().''; + } + else + { + print ' '; + } + print ''; print 'Jabberid'; @@ -408,10 +419,10 @@ else print 'Tel Pro'.$contact->phone_pro.''; print 'Tel Perso'.$contact->phone_perso.''; - print 'Portable'.$contact->phone_mobile.''; + print 'Portable'.$contact->phone_mobile.''; print ''.$langs->trans("Fax").''.$contact->fax.''; - print ''.$langs->trans("EMail").''; + print ''.$langs->trans("EMail").''; if ($contact->email && ! ValidEmail($contact->email)) { print '
'.$langs->trans("ErrorBadEMail",$contact->email)."
"; @@ -420,8 +431,19 @@ else { print $contact->email; } - print ''; - + print ''; + if ($conf->mailing->enabled) + { + $langs->load("mails"); + print ''.$langs->trans("NbOfEMailingsReceived").''; + print ''.$contact->getNbOfEMailings().''; + } + else + { + print ' '; + } + print ''; + print 'Jabberid'.$contact->jabberid.''; print ''.$langs->trans("Note").''; @@ -460,26 +482,20 @@ else } - // Historique des actions vers ce contact + // Historique des actions sur ce contact print_titre ($langs->trans("TasksHistoryForThisContact")); + $histo=array(); + $numaction = 0 ; - print ''; - - print ""; - print ""; - print ""; - - $sql = "SELECT a.id, ".$db->pdate("a.datea")." as da, c.libelle, u.code, a.propalrowid, a.fk_user_author, fk_contact, u.rowid "; - $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 "; - - if ($contactid) - { - $sql .= " AND fk_contact = $contactid"; - } - $sql .= " ORDER BY a.datea DESC, a.id DESC"; + // 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) @@ -490,21 +506,10 @@ else while ($i < $num) { $obj = $db->fetch_object($resql); - $var=!$var; - print ""; - - print ""; - if ($obj->propalrowid) - { - print ""; - } - else - { - print ""; - } - - print ""; - print "\n"; + $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++; } } @@ -512,8 +517,101 @@ 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 '
".$langs->trans("Date")."".$langs->trans("Actions")."".$langs->trans("CreatedBy")."
". strftime("%d %b %Y %H:%M", $obj->da) ."propalrowid."\">".$obj->libelle."$obj->libelle$obj->code 
'; + + 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(); diff --git a/htdocs/contact/index.php b/htdocs/contact/index.php index 29c72b86393..c0f0d0dc94b 100644 --- a/htdocs/contact/index.php +++ b/htdocs/contact/index.php @@ -54,7 +54,7 @@ $search_email=isset($_GET["search_email"])?$_GET["search_email"]:$_POST["search_ $type = isset($_GET["type"])?$_GET["type"]:$_POST["type"]; $view=isset($_GET["view"])?$_GET["view"]:$_POST["view"]; -$contactname=isset($_GET["contactname"])?$_GET["contactname"]:$_POST["contactname"]; +$sall=isset($_GET["contactname"])?$_GET["contactname"]:$_POST["contactname"]; $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; $page = isset($_GET["page"])?$_GET["page"]:$_POST["page"]; @@ -72,11 +72,13 @@ if ($view == 'mail') { $text="(Vue EMail)"; } if ($view == 'recent') { $text="(Récents)"; } $titre = $langs->trans("ListOfContacts")." $text"; -if ($_POST["button_removefilter"] == $langs->trans("RemoveFilter")) { +if ($_POST["button_removefilter"]) +{ $search_nom=""; $search_prenom=""; $search_societe=""; $search_email=""; + $sall=""; } @@ -88,7 +90,6 @@ if ($_POST["button_removefilter"] == $langs->trans("RemoveFilter")) { $sql = "SELECT s.idp, s.nom, p.idp as cidp, p.name, p.firstname, p.email, p.phone, p.phone_mobile, p.fax "; $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as p "; $sql .= "LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (s.idp = p.fk_soc) "; - $sql .= "WHERE 1=1 "; if ($_GET["userid"]) // statut commercial @@ -97,21 +98,20 @@ if ($_GET["userid"]) // statut commercial } if ($search_nom) // filtre sur le nom { - $sql .= " AND upper(p.name) like '%".$search_nom."%'"; + $sql .= " AND p.name like '%".$search_nom."%'"; } if ($search_prenom) // filtre sur le prenom { - $sql .= " AND upper(p.firstname) like '%".$search_prenom."%'"; + $sql .= " AND p.firstname like '%".$search_prenom."%'"; } if ($search_societe) // filtre sur la societe { - $sql .= " AND upper(s.nom) like '%".$search_societe."%'"; + $sql .= " AND s.nom like '%".$search_societe."%'"; } if ($search_email) // filtre sur l'email { - $sql .= " AND upper(p.email) like '%".$search_email."%'"; + $sql .= " AND p.email like '%".$search_email."%'"; } - if ($type == "f") // filtre sur type { $sql .= " AND fournisseur = 1"; @@ -120,12 +120,10 @@ if ($type == "c") // filtre sur type { $sql .= " AND client = 1"; } - -if ($contactname) +if ($sall) { - $sql .= " AND (p.name like '%".$contactname."%' OR p.firstname like '%".$contactname."%') "; + $sql .= " AND (p.name like '%".$sall."%' OR p.firstname like '%".$sall."%' OR p.email like '%".$sall."%') "; } - if ($socid) { $sql .= " AND s.idp = $socid"; @@ -144,7 +142,7 @@ $result = $db->query($sql); if ($result) { - $num = $db->num_rows(); + $num = $db->num_rows($result); $i = 0; print_barre_liste($titre ,$page, "index.php", '&begin='.$_GET["begin"].'&view='.$_GET["view"].'&userid='.$_GET["userid"], $sortfield, $sortorder,'',$num); @@ -152,9 +150,9 @@ if ($result) print ''; - if ($contactname) + if ($sall) { - print $langs->trans("Filter")." (".$langs->trans("Lastname")." ".$langs->trans("or")." ".$langs->trans("Firstname")."): $contactname"; + print $langs->trans("Filter")." (".$langs->trans("Lastname").", ".$langs->trans("Firstname")." ".$langs->trans("or")." ".$langs->trans("EMail")."): ".$sall; } // Ligne des titres @@ -212,8 +210,8 @@ if ($result) } print ''; print ''; print '';
'; - print ''; - print '  '; + print ''; + print '  '; print '