NEW Module notification should details of emails into confirm box, not

only number.
This commit is contained in:
Laurent Destailleur 2015-04-13 17:04:18 +02:00
parent d7ef1e7da0
commit 97cdc55839
4 changed files with 115 additions and 55 deletions

View File

@ -174,8 +174,8 @@ if ($conf->societe->enabled)
print '<td>'.$notifiedevent['code'].'</td>';
print '<td>'.$label.'</td>';
print '<td align="right">';
$nb = $notify->countDefinedNotifications($notifiedevent['code'], 0);
print $nb;
$tmparray = $notify->getNotificationsArray($notifiedevent['code'], 0);
print count($tmparray);
print '</td>';
print '</tr>';
}

View File

@ -56,8 +56,8 @@ class Notify
/**
* Return message that say how many notification will occurs on requested event.
* This is to show confirmation messages before event is done.
* Return message that say how many notification (and to which email) will occurs on requested event.
* This is to show confirmation messages before event is recorded.
*
* @param string $action Id of action in llx_c_action_trigger
* @param int $socid Id of third party
@ -69,10 +69,23 @@ class Notify
global $langs;
$langs->load("mails");
$nb=$this->countDefinedNotifications($action,$socid,$object);
$listofnotiftodo=$this->getNotificationsArray($action,$socid,$object);
$nb=count($listofnotiftodo);
if ($nb <= 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
$i=0;
foreach ($listofnotiftodo as $key => $val)
{
if ($i) $texte.=', ';
else $texte.=' (';
if ($val['isemailvalid']) $texte.=$val['email'];
else $texte.=$val['emaildesc'];
$i++;
}
if ($i) $texte.=')';
return $texte;
}
@ -81,22 +94,22 @@ class Notify
*
* @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
* @param int $socid Id of third party or 0 for all thirdparties
* @param Object $object Object the notification is about
* @return int <0 if KO, nb of notifications sent if OK
* @param Object $object Object the notification is about (need it to check threshold value of some notifications)
* @return array|int <0 if KO, array of notifications to send if OK
*/
function countDefinedNotifications($notifcode,$socid,$object=null)
function getNotificationsArray($notifcode,$socid,$object=null)
{
global $conf;
global $conf, $user;
$error=0;
$num=0;
$resarray=array();
$valueforthreshold = 0;
if (is_object($object)) $valueforthreshold = $object->total_ht;
if (! $error)
{
$sql = "SELECT COUNT(n.rowid) as nb";
$sql = "SELECT a.code, c.email, c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
$sql.= " ".MAIN_DB_PREFIX."socpeople as c,";
$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
@ -112,13 +125,23 @@ class Notify
$sql.= " AND s.entity IN (".getEntity('societe', 1).")";
if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
dol_syslog(get_class($this)."::countDefinedNotifications ".$notifcode.", ".$socid."", LOG_DEBUG);
dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$obj = $this->db->fetch_object($resql);
if ($obj) $num = $obj->nb;
$num = $this->db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($obj)
{
$isvalid=isValidEmail($newval2);
$resarray[] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>trim($obj->email), 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
}
$i++;
}
}
else
{
@ -129,7 +152,6 @@ class Notify
if (! $error)
{
// List of notifications enabled for fixed email
foreach($conf->global as $key => $val)
{
@ -146,12 +168,33 @@ class Notify
if ($valueforthreshold < $threshold) continue;
$tmpemail=explode(',',$val);
$num+=count($tmpemail);
foreach($tmpemail as $key2 => $val2)
{
$newval2=trim($val2);
if ($newval2 == '__SUPERVISOREMAIL__')
{
if ($user->fk_user > 0)
{
$tmpuser=new User($this->db);
$tmpuser->fetch($user->fk_user);
if ($tmpuser->email) $newval2=$tmpuser->email;
else $newval2='';
}
else $newval2='';
}
if ($newval2)
{
$isvalid=isValidEmail($newval2, 0);
$resarray[]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>trim($newval2), 'isemailvalid'=>$isvalid);
}
}
}
}
if ($error) return -1;
return $num;
//var_dump($resarray);
return $resarray;
}
/**

View File

@ -203,6 +203,7 @@ NewKeyWillBe=Your new key to login to software will be
ClickHereToGoTo=Click here to go to %s
YouMustClickToChange=You must however first click on the following link to validate this password change
ForgetIfNothing=If you didn't request this change, just forget this email. Your credentials are kept safe.
IfAmountHigherThan=If amount higher than <strong>%s</strong>
##### Calendar common #####
AddCalendarEntry=Add entry in calendar %s

View File

@ -175,8 +175,8 @@ if ($result > 0)
print '<tr><td>'.$langs->trans("NbOfActiveNotifications").'</td>';
print '<td colspan="3">';
$notify=new Notify($db);
$nb = $notify->countDefinedNotifications('', $object->id);
print $nb;
$tmparray = $notify->getNotificationsArray('', $object->id);
print count($tmparray);
print '</td></tr>';
print '</table>';
@ -258,42 +258,8 @@ if ($result > 0)
print_liste_field_titre('','','');
print '</tr>';
// List of notifications enabled for fixed email
foreach($conf->global as $key => $val)
{
if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue;
$var = ! $var;
print '<tr '.$bc[$var].'><td>';
$listtmp=explode(',',$val);
$first=1;
foreach($listtmp as $keyemail => $valemail)
{
if (! $first) print ', ';
$first=0;
$valemail=trim($valemail);
//print $keyemail.' - '.$valemail.' - '.$reg[1].'<br>';
if (isValidEmail($valemail, 1))
{
if ($valemail == '__SUPERVISOREMAIL__') print $valemail;
else print ' &lt;'.$valemail.'&gt;';
}
else
{
$langs->load("errors");
print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail);
}
}
print '</td>';
print '<td>';
$label=($langs->trans("Notify_".$reg[1])!="Notify_".$reg[1]?$langs->trans("Notify_".$reg[1]):$reg[1]);
print $label;
print '</td>';
print '<td>';
print $langs->trans("Email");
print '</td>';
print '<td align="right">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</td>';
print '</tr>';
}
$langs->load("errors");
$langs->load("other");
// List of notifications enabled for contacts
$sql = "SELECT n.rowid, n.type,";
@ -356,6 +322,56 @@ if ($result > 0)
dol_print_error($db);
}
// List of notifications enabled for fixed email
/*
foreach($conf->global as $key => $val)
{
if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue;
$var = ! $var;
print '<tr '.$bc[$var].'><td>';
$listtmp=explode(',',$val);
$first=1;
foreach($listtmp as $keyemail => $valemail)
{
if (! $first) print ', ';
$first=0;
$valemail=trim($valemail);
//print $keyemail.' - '.$valemail.' - '.$reg[1].'<br>';
if (isValidEmail($valemail, 1))
{
if ($valemail == '__SUPERVISOREMAIL__') print $valemail;
else print ' &lt;'.$valemail.'&gt;';
}
else
{
print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail);
}
}
print '</td>';
print '<td>';
$notifcode=preg_replace('/_THRESHOLD_.*$/','',$reg[1]);
$notifcodecond=preg_replace('/^.*_(THRESHOLD_)/','$1',$reg[1]);
$label=($langs->trans("Notify_".$notifcode)!="Notify_".$notifcode?$langs->trans("Notify_".$notifcode):$notifcode);
print $label;
if (preg_match('/^THRESHOLD_HIGHER_(.*)$/',$notifcodecond,$regcond) && ($regcond[1] > 0))
{
print ' - '.$langs->trans("IfAmountHigherThan",$regcond[1]);
}
print '</td>';
print '<td>';
print $langs->trans("Email");
print '</td>';
print '<td align="right">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</td>';
print '</tr>';
}*/
if ($user->admin)
{
$var = ! $var;
print '<tr '.$bc[$var].'><td colspan="4">';
print '+ <a href="'.DOL_URL_ROOT.'/admin/notification.php">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</a>';
print '</td></tr>';
}
print '</table>';
print '<br>';