Prepare code and database for a notifications module using other stream than emails.

This commit is contained in:
Laurent Destailleur 2010-08-20 22:12:05 +00:00
parent 1e8eb81ec4
commit 4b715a88c0
5 changed files with 55 additions and 18 deletions

View File

@ -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';

View File

@ -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)

View File

@ -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;

View File

@ -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 <johndo@titi.com>")
* \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 <johndo@titi.com>")
* @return boolean true if email syntax is OK, false if KO
*/
function isValidEmail($address)
{

View File

@ -153,15 +153,17 @@ if ( $soc->fetch($soc->id) )
// Ligne de titres
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
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 '<td>&nbsp;</td>';
print '</tr>';
$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 '<td>';
print $html->selectarray("actionid",$actions);
print '</td>';
print '<td>';
$type=array('email'=>$langs->trans("EMail"));
print $html->selectarray("typeid",$type);
print '</td>';
print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
}
@ -215,15 +221,19 @@ if ( $soc->fetch($soc->id) )
// Ligne de titres
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
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 '</tr>';
// 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 '<tr '.$bc[$var].'><td>'.$contactstatic->getNomUrl(1);
print $obj->email?' &lt;'.$obj->email.'&gt;':$langs->trans("NoMail");
if ($obj->type == 'email')
{
if (isValidEmail($obj->email))
{
print ' &lt;'.$obj->email.'&gt;';
}
else
{
$langs->load("errors");
print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail",$obj->email);
}
}
print '</td>';
print '<td>';
$libelle=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->titre);
print $libelle;
print '</td>';
print '<td align="right"><a href="fiche.php?socid='.$socid.'&action=delete&actid='.$obj->rowid.'">'.img_delete().'</a></td>';
print '<td>';
if ($obj->type == 'email') print $langs->trans("Email");
if ($obj->type == 'sms') print $langs->trans("SMS");
print '</td>';
print '<td align="right"><a href="fiche.php?socid='.$socid.'&action=delete&actid='.$obj->rowid.'">'.img_delete().'</a></td>';
print '</tr>';
$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)