Make page to setup notification simpler

This commit is contained in:
Laurent Destailleur 2021-02-07 17:40:14 +01:00
parent 5712d255b3
commit 36fbba2ac2

View File

@ -30,7 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/triggers/interface_50_modNotification_Notification.class.php';
$langs->loadLangs(array("companies", "mails", "admin", "other"));
$langs->loadLangs(array("companies", "mails", "admin", "other", "errors"));
$socid = GETPOST("socid", 'int');
$action = GETPOST('action', 'aZ09');
@ -219,64 +219,6 @@ if ($result > 0)
print '<br><br>'."\n";
// Add notification form
print load_fiche_titre($langs->trans("AddNewNotification"), '', '');
print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">';
$param = "&socid=".$socid;
// Line with titles
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, 'width="45%"', $sortfield, $sortorder);
print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, 'width="35%"', $sortfield, $sortorder);
print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, 'width="10%"', $sortfield, $sortorder);
print_liste_field_titre('');
print "</tr>\n";
$var = false;
$listofemails = $object->thirdparty_and_contact_email_array();
if (count($listofemails) > 0)
{
$actions = array();
// Load array of available notifications
$notificationtrigger = new InterfaceNotification($db);
$listofmanagedeventfornotification = $notificationtrigger->getListOfManagedEvents();
foreach ($listofmanagedeventfornotification as $managedeventfornotification)
{
$label = ($langs->trans("Notify_".$managedeventfornotification['code']) != "Notify_".$managedeventfornotification['code'] ? $langs->trans("Notify_".$managedeventfornotification['code']) : $managedeventfornotification['label']);
$actions[$managedeventfornotification['rowid']] = $label;
}
print '<tr class="oddeven nohover"><td class="maxwidthonsmartphone">';
print img_picto('', 'contact', '', false, 0, 0, '', 'paddingright').$form->selectarray("contactid", $listofemails, '', 0, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone');
print '</td>';
print '<td class="maxwidthonsmartphone">';
print img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').$form->selectarray("actionid", $actions, '', 1, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone');
print '</td>';
print '<td>';
$type = array('email'=>$langs->trans("EMail"));
print $form->selectarray("typeid", $type);
print '</td>';
print '<td class="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
} else {
print '<tr class="oddeven"><td colspan="4" class="opacitymedium">';
print $langs->trans("YouMustCreateContactFirst");
print '</td></tr>';
}
print '</table>';
print '</form>';
print '<br>';
// List of notifications enabled for contacts
$sql = "SELECT n.rowid, n.type,";
$sql .= " a.code, a.label,";
@ -296,20 +238,58 @@ if ($result > 0)
dol_print_error($db);
}
// List of active notifications
// Add notification form
print load_fiche_titre($langs->trans("ListOfActiveNotifications").' <span class="opacitymedium colorblack paddingleft">('.$num.')</span>', '', '');
print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">';
$param = "&socid=".$socid;
// Line with titles
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, 'width="45%"', $sortfield, $sortorder);
print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, 'width="35%"', $sortfield, $sortorder);
print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, 'width="10%"', $sortfield, $sortorder);
print_liste_field_titre('', '', '');
print '</tr>';
print_liste_field_titre('');
print "</tr>\n";
// Line to add a new subscription
$listofemails = $object->thirdparty_and_contact_email_array();
if (count($listofemails) > 0)
{
$actions = array();
// Load array of available notifications
$notificationtrigger = new InterfaceNotification($db);
$listofmanagedeventfornotification = $notificationtrigger->getListOfManagedEvents();
foreach ($listofmanagedeventfornotification as $managedeventfornotification)
{
$label = ($langs->trans("Notify_".$managedeventfornotification['code']) != "Notify_".$managedeventfornotification['code'] ? $langs->trans("Notify_".$managedeventfornotification['code']) : $managedeventfornotification['label']);
$actions[$managedeventfornotification['rowid']] = $label;
}
print '<tr class="oddeven nohover"><td class="maxwidthonsmartphone">';
print img_picto('', 'contact', '', false, 0, 0, '', 'paddingright').$form->selectarray("contactid", $listofemails, '', 1, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone');
print '</td>';
print '<td class="maxwidthonsmartphone">';
print img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').$form->selectarray("actionid", $actions, '', 1, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone');
print '</td>';
print '<td>';
$type = array('email'=>$langs->trans("EMail"));
print $form->selectarray("typeid", $type);
print '</td>';
print '<td class="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
} else {
print '<tr class="oddeven"><td colspan="4" class="opacitymedium">';
print $langs->trans("YouMustCreateContactFirst");
print '</td></tr>';
}
$langs->load("errors");
$langs->load("other");
if ($num)
{
@ -358,7 +338,6 @@ if ($result > 0)
foreach($conf->global as $key => $val)
{
if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue;
$var = ! $var;
print '<tr class="oddeven"><td>';
$listtmp=explode(',',$val);
$first=1;
@ -399,7 +378,6 @@ if ($result > 0)
/*if ($user->admin)
{
$var = ! $var;
print '<tr class="oddeven"><td colspan="4">';
print '+ <a href="'.DOL_URL_ROOT.'/admin/notification.php">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</a>';
print '</td></tr>';