From 4b715a88c0a179762db92a105a2022432081086e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Aug 2010 22:12:05 +0000 Subject: [PATCH] Prepare code and database for a notifications module using other stream than emails. --- .../install/mysql/migration/2.9.0-3.0.0.sql | 8 +++ htdocs/install/mysql/tables/llx_notify.sql | 3 +- .../install/mysql/tables/llx_notify_def.sql | 4 +- htdocs/lib/functions.lib.php | 6 +-- htdocs/societe/notify/fiche.php | 52 ++++++++++++++----- 5 files changed, 55 insertions(+), 18 deletions(-) diff --git a/htdocs/install/mysql/migration/2.9.0-3.0.0.sql b/htdocs/install/mysql/migration/2.9.0-3.0.0.sql index 1eaa4514129..b2f665cc7de 100644 --- a/htdocs/install/mysql/migration/2.9.0-3.0.0.sql +++ b/htdocs/install/mysql/migration/2.9.0-3.0.0.sql @@ -26,3 +26,11 @@ alter table llx_product_price change column envente tosell tinyint DEFAULT 1; ALTER TABLE llx_boxes_def DROP INDEX uk_boxes_def; ALTER TABLE llx_boxes_def MODIFY note varchar(255); ALTER TABLE llx_boxes_def ADD UNIQUE INDEX uk_boxes_def (file, entity, note); + +ALTER TABLE llx_notify_def MODIFY fk_contact integer NULL; +ALTER TABLE llx_notify_def ADD COLUMN fk_user integer NULL after fk_contact; +ALTER TABLE llx_notify_def ADD COLUMN type varchar(16) DEFAULT 'email'; + +ALTER TABLE llx_notify MODIFY fk_contact integer NULL; +ALTER TABLE llx_notify ADD COLUMN fk_user integer NULL after fk_contact; +ALTER TABLE llx_notify ADD COLUMN type varchar(16) DEFAULT 'email'; diff --git a/htdocs/install/mysql/tables/llx_notify.sql b/htdocs/install/mysql/tables/llx_notify.sql index 6cc84524b37..8c3d917aabc 100644 --- a/htdocs/install/mysql/tables/llx_notify.sql +++ b/htdocs/install/mysql/tables/llx_notify.sql @@ -25,7 +25,8 @@ create table llx_notify tms timestamp, daten datetime, -- date de la notification fk_action integer NOT NULL, - fk_contact integer NOT NULL, + fk_contact integer NULL, + fk_user integer NULL, objet_type varchar(24) NOT NULL, objet_id integer NOT NULL, email varchar(255) diff --git a/htdocs/install/mysql/tables/llx_notify_def.sql b/htdocs/install/mysql/tables/llx_notify_def.sql index 6d0716548bc..a4f19a5acc0 100644 --- a/htdocs/install/mysql/tables/llx_notify_def.sql +++ b/htdocs/install/mysql/tables/llx_notify_def.sql @@ -25,5 +25,7 @@ create table llx_notify_def datec date, -- date de creation fk_action integer NOT NULL, fk_soc integer NOT NULL, - fk_contact integer NOT NULL + fk_contact integer, + fk_user integer, + type varchar(16) DEFAULT 'email'; )type=innodb; diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 9cff7342f14..dcd7c345d34 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -928,9 +928,9 @@ function dol_print_ip($ip,$mode=0) } /** - * \brief Return true if email syntax is ok - * \param address email (Ex: "toto@titi.com", "John Do ") - * \return boolean true if email syntax is OK, false if KO + * Return true if email syntax is ok + * @param address email (Ex: "toto@titi.com", "John Do ") + * @return boolean true if email syntax is OK, false if KO */ function isValidEmail($address) { diff --git a/htdocs/societe/notify/fiche.php b/htdocs/societe/notify/fiche.php index a802a99b03d..4e8800ce6bb 100644 --- a/htdocs/societe/notify/fiche.php +++ b/htdocs/societe/notify/fiche.php @@ -153,15 +153,17 @@ if ( $soc->fetch($soc->id) ) // Ligne de titres print ''; print ''; - print_liste_field_titre($langs->trans("Contact"),"fiche.php","c.name",'',"&socid=$socid",'"width="45%"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Action"),"fiche.php","a.titre",'',"&socid=$socid",'"width="45%"',$sortfield,$sortorder); + $param="&socid=".$socid; + print_liste_field_titre($langs->trans("Contact"),"fiche.php","c.name",'',$param,'"width="45%"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Action"),"fiche.php","a.titre",'',$param,'"width="35%"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Type"),"fiche.php","",'',$param,'"width="10%"',$sortfield,$sortorder); print ''; print ''; $var=false; if (count($soc->contact_email_array()) > 0) { - // Charge tableau $actions + // Load array of notifications type available $sql = "SELECT a.rowid, a.code, a.titre"; $sql.= " FROM ".MAIN_DB_PREFIX."action_def as a"; @@ -192,6 +194,10 @@ if ( $soc->fetch($soc->id) ) print ''; + print ''; print ''; print ''; } @@ -215,15 +221,19 @@ if ( $soc->fetch($soc->id) ) // Ligne de titres print '
 
'; print $html->selectarray("actionid",$actions); print ''; + $type=array('email'=>$langs->trans("EMail")); + print $html->selectarray("typeid",$type); + print '
'; print ''; - print_liste_field_titre($langs->trans("Contact"),"fiche.php","c.name",'',"&socid=$socid",'"width="45%"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Action"),"fiche.php","a.titre",'',"&socid=$socid",'"width="45%"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Contact"),"fiche.php","c.name",'',$param,'"width="45%"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Action"),"fiche.php","a.titre",'',$param,'"width="35%"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Type"),"fiche.php","",'',$param,'"width="10%"',$sortfield,$sortorder); print_liste_field_titre('','',''); print ''; - // Liste - $sql = "SELECT c.rowid as id, c.name, c.firstname, c.email, a.code, a.titre, n.rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n"; - $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action AND n.fk_soc = ".$soc->id; + // List of notifications for contacts + $sql = "SELECT n.rowid, n.type,"; + $sql.= " a.code, a.titre,"; + $sql.= " c.rowid as id, c.name, c.firstname, c.email"; + $sql.= " FROM ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n,"; + $sql.= " ".MAIN_DB_PREFIX."socpeople c"; + $sql.= " WHERE a.rowid = n.fk_action AND c.rowid = n.fk_contact AND c.fk_soc = ".$soc->id; $resql=$db->query($sql); if ($resql) @@ -243,13 +253,28 @@ if ( $soc->fetch($soc->id) ) $contactstatic->name=$obj->name; $contactstatic->firstname=$obj->firstname; print ''; print ''; - print ''; + print ''; + print ''; print ''; $i++; } @@ -280,8 +305,9 @@ if ( $soc->fetch($soc->id) ) $sql = "SELECT n.rowid, n.daten, n.email, n.objet_type, n.objet_id,"; $sql.= " c.rowid as id, c.name, c.firstname, c.email,"; $sql.= " a.code, a.titre"; - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify as n"; - $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; + $sql.= " FROM ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify as n, "; + $sql.= " ".MAIN_DB_PREFIX."socpeople as c"; + $sql.= " WHERE a.rowid = n.fk_action AND c.rowid = n.fk_contact AND c.fk_soc = ".$soc->id; $resql=$db->query($sql); if ($resql)
'.$contactstatic->getNomUrl(1); - print $obj->email?' <'.$obj->email.'>':$langs->trans("NoMail"); + if ($obj->type == 'email') + { + if (isValidEmail($obj->email)) + { + print ' <'.$obj->email.'>'; + } + else + { + $langs->load("errors"); + print '   '.img_warning().' '.$langs->trans("ErrorBadEMail",$obj->email); + } + } print ''; $libelle=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->titre); print $libelle; print ''.img_delete().''; + if ($obj->type == 'email') print $langs->trans("Email"); + if ($obj->type == 'sms') print $langs->trans("SMS"); + print ''.img_delete().'