diff --git a/htdocs/admin/mails_templates.php b/htdocs/admin/mails_templates.php
index 2bf6faf2112..69e8f865c19 100644
--- a/htdocs/admin/mails_templates.php
+++ b/htdocs/admin/mails_templates.php
@@ -28,8 +28,8 @@
/**
* \file htdocs/admin/mails_templates.php
- * \ingroup setup
- * \brief Page to administer data tables
+ * \ingroup core
+ * \brief Page to administer emails templates
*/
require '../main.inc.php';
@@ -52,8 +52,13 @@ $confirm=GETPOST('confirm','alpha');
$id=GETPOST('id','int');
$rowid=GETPOST('rowid','alpha');
$search_label=GETPOST('search_label','alpha');
+$search_type_template=GETPOST('search_type_template','alpha');
+$search_topic=GETPOST('search_topic','alpha');
+$search_lang=GETPOST('search_lang','alpha');
+$search_fk_user=GETPOST('search_fk_user','intcoma');
+$search_topic=GETPOST('search_topic','alpha');
-$allowed=$user->admin;
+$allowed=1;
if (! $allowed) accessforbidden();
$acts[0] = "activate";
@@ -86,17 +91,17 @@ $tabsqlsort[25]="label ASC";
// Nom des champs en resultat de select pour affichage du dictionnaire
$tabfield=array();
-$tabfield[25]= "label,type_template,lang,private,position,topic,content";
+$tabfield[25]= "label,type_template,lang,fk_user,private,position,topic,content";
if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfield[25].=',content_lines';
// Nom des champs d'edition pour modification d'un enregistrement
$tabfieldvalue=array();
-$tabfieldvalue[25]= "label,type_template,lang,private,position,topic,content";
+$tabfieldvalue[25]= "label,type_template,fk_user,lang,private,position,topic,content";
if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfieldvalue[25].=',content_lines';
// Nom des champs dans la table pour insertion d'un enregistrement
$tabfieldinsert=array();
-$tabfieldinsert[25]= "label,type_template,lang,private,position,topic,content";
+$tabfieldinsert[25]= "label,type_template,fk_user,lang,private,position,topic,content";
if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfieldinsert[25].=',content_lines';
$tabfieldinsert[25].=',entity'; // Must be at end because not into other arrays
@@ -155,6 +160,8 @@ if ($conf->fournisseur->enabled) $elementList['order_supplier_send']=$lang
if ($conf->fournisseur->enabled) $elementList['invoice_supplier_send']=$langs->trans('MailToSendSupplierInvoice');
if ($conf->societe->enabled) $elementList['thirdparty']=$langs->trans('MailToThirdparty');
if ($conf->contrat->enabled) $elementList['contract']=$langs->trans('MailToSendContract');
+$elementList['other']=$langs->trans('Other');
+
$parameters=array('elementList'=>$elementList);
$reshook=$hookmanager->executeHooks('emailElementlist',$parameters); // Note that $action and $object may have been modified by some hooks
@@ -184,6 +191,10 @@ if (empty($reshook))
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
{
$search_label='';
+ $search_type_template='';
+ $search_lang='';
+ $search_fk_user='';
+ $search_topic='';
$toselect='';
$search_array_options=array();
}
@@ -205,7 +216,7 @@ if (empty($reshook))
if ($value == 'content') $value='content-'.$rowid;
if ($value == 'content_lines') $value='content_lines-'.$rowid;
- if ((! isset($_POST[$value]) || $_POST[$value]=='') && $value != 'lang')
+ if ((! isset($_POST[$value]) || $_POST[$value]=='' || $_POST[$value]=='-1') && $value != 'lang' && $value != 'fk_user')
{
$ok=0;
$fieldnamekey=$listfield[$f];
@@ -214,7 +225,11 @@ if (empty($reshook))
if ($fieldnamekey == 'libelle_facture') $fieldnamekey = 'LabelOnDocuments';
if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
- if ($fieldnamekey == 'type') $fieldnamekey = 'Type';
+ if ($fieldnamekey == 'type_template') $fieldnamekey = 'TypeOfTemplate';
+ if ($fieldnamekey == 'fk_user') $fieldnamekey = 'Owner';
+ if ($fieldnamekey == 'private') $fieldnamekey = 'Private';
+ if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
+ if ($fieldnamekey == 'topic') $fieldnamekey = 'Topic';
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
}
@@ -260,6 +275,7 @@ if (empty($reshook))
//var_dump($i.' - '.$listfieldvalue[$i].' - '.$_POST[$listfieldvalue[$i]].' - '.$value);
if ($value == 'entity') $_POST[$keycode] = $conf->entity;
if ($i) $sql.=",";
+ if ($value == 'fk_user' && ! ($_POST[$keycode] > 0)) $_POST[$keycode]='';
if ($value == 'private' && ! is_numeric($_POST[$keycode])) $_POST[$keycode]='0';
if ($value == 'position' && ! is_numeric($_POST[$keycode])) $_POST[$keycode]='1';
if ($_POST[$keycode] == '' || ($keycode == 'langcode' && empty($_POST[$keycode]))) $sql.="null"; // For vat, we want/accept code = ''
@@ -306,7 +322,8 @@ if (empty($reshook))
$keycode=$listfieldvalue[$i];
if ($field == 'lang') $keycode='langcode';
- if ($field == 'content') $_POST['content']=$_POST['content-'.$rowid];
+ if ($field == 'fk_user' && ! ($_POST['fk_user'] > 0)) $_POST['fk_user']='';
+ if ($field == 'content') $_POST['content']=$_POST['content-'.$rowid];
if ($field == 'content_lines') $_POST['content_lines']=$_POST['content_lines-'.$rowid];
if ($field == 'entity') $_POST[$keycode] = $conf->entity;
if ($i) $sql.=",";
@@ -408,17 +425,21 @@ print load_fiche_titre($titre,$linkback,$titlepicto);
$h = 0;
-$head[$h][0] = DOL_URL_ROOT."/admin/mails.php";
-$head[$h][1] = $langs->trans("OutGoingEmailSetup");
-$head[$h][2] = 'common';
-$h++;
-if ($conf->mailing->enabled)
+if ($user->admin && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates'))
{
- $head[$h][0] = DOL_URL_ROOT."/admin/mails_emailing.php";
- $head[$h][1] = $langs->trans("OutGoingEmailSetupForEmailing");
- $head[$h][2] = 'common_emailing';
+ $head[$h][0] = DOL_URL_ROOT."/admin/mails.php";
+ $head[$h][1] = $langs->trans("OutGoingEmailSetup");
+ $head[$h][2] = 'common';
$h++;
+
+ if (! empty($conf->mailing->enabled))
+ {
+ $head[$h][0] = DOL_URL_ROOT."/admin/mails_emailing.php";
+ $head[$h][1] = $langs->trans("OutGoingEmailSetupForEmailing");
+ $head[$h][2] = 'common_emailing';
+ $h++;
+ }
}
$head[$h][0] = DOL_URL_ROOT."/admin/mails_templates.php";
@@ -437,15 +458,23 @@ if ($action == 'delete')
//var_dump($elementList);
-$sql="SELECT rowid as rowid, label, type_template, lang, private, position, topic, content_lines, content, active";
+$sql="SELECT rowid as rowid, label, type_template, lang, fk_user, private, position, topic, content_lines, content, active";
$sql.=" FROM ".MAIN_DB_PREFIX."c_email_templates";
$sql.=" WHERE entity IN (".getEntity('email_template').")";
-if ($search_label) $sql.=natural_search('label', $search_label);
+if (! $user->admin)
+{
+ $sql.=" AND (private = 0 OR (private = 1 AND fk_user = ".$user->id."))"; // Show only public and private to me
+ $sql.=" AND (active = 1 OR fk_user = ".$user->id.")"; // Show only active or owned by me
+}
if (empty($conf->global->MAIN_MULTILANGS))
{
$sql.= " AND (lang = '".$langs->defaultlang."' OR lang IS NULL)";
}
-
+if ($search_label) $sql.=natural_search('label', $search_label);
+if ($search_type_template != '' && $search_type_template != '-1') $sql.=natural_search('type_template', $search_type_template);
+if ($search_lang) $sql.=natural_search('lang', $search_lang);
+if ($search_fk_user != '' && $search_fk_user != '-1') $sql.=natural_search('fk_user', $search_fk_user, 2);
+if ($search_topic) $sql.=natural_search('topic', $search_topic);
if ($sortfield)
{
// If sort order is "country", we use country_code instead
@@ -473,25 +502,22 @@ $fieldlist=explode(',',$tabfield[$id]);
$alabelisused=0;
$var=false;
-$fieldlist=explode(',',$tabfield[$id]);
+print '
';
+print '';
+
+print '
';
- print '
';
-//}
print '