diff --git a/htdocs/admin/mails_templates.php b/htdocs/admin/mails_templates.php
index d0f6b032bc1..20c88c3479a 100644
--- a/htdocs/admin/mails_templates.php
+++ b/htdocs/admin/mails_templates.php
@@ -109,21 +109,21 @@ $tabname[25] = MAIN_DB_PREFIX."c_email_templates";
// Nom des champs en resultat de select pour affichage du dictionnaire
$tabfield = array();
-$tabfield[25] = "label,lang,type_template,fk_user,private,position,module,topic,joinfiles,content";
+$tabfield[25] = "label,lang,type_template,fk_user,private,position,module,topic,joinfiles,defaultfortype,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,lang,type_template,fk_user,private,position,topic,joinfiles,content";
+$tabfieldvalue[25] = "label,lang,type_template,fk_user,private,position,topic,joinfiles,defaultfortype,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,lang,type_template,fk_user,private,position,topic,joinfiles,content";
+$tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,joinfiles,defaultfortype,content";
if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
$tabfieldinsert[25] .= ',content_lines';
}
@@ -164,13 +164,14 @@ if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
$tabhelp = array();
$tabhelp[25] = array(
'label'=>$langs->trans('EnterAnyCode'),
- 'topic'=>''.$helpsubstit.' ',
- 'joinfiles'=>$langs->trans('AttachMainDocByDefault'),
- 'content'=>''.$helpsubstit.' ',
- 'content_lines'=>''.$helpsubstitforlines.' ',
'type_template'=>$langs->trans("TemplateForElement"),
'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"),
- 'position'=>$langs->trans("PositionIntoComboList")
+ 'position'=>$langs->trans("PositionIntoComboList"),
+ 'topic'=>''.$helpsubstit.' ',
+ 'joinfiles'=>$langs->trans('AttachMainDocByDefault'),
+ 'defaultfortype'=>$langs->trans("DefaultForTypeDesc"),
+ 'content'=>''.$helpsubstit.' ',
+ 'content_lines'=>''.$helpsubstitforlines.' '
);
@@ -307,7 +308,7 @@ if (empty($reshook)) {
$ok = 1;
foreach ($listfield as $f => $value) {
// Not mandatory fields
- if (in_array($value, ['joinfiles', 'content', 'content_lines', 'module'])) {
+ if (in_array($value, ['joinfiles', 'defaultfortype', 'content', 'content_lines', 'module'])) {
continue;
}
@@ -383,6 +384,9 @@ if (empty($reshook)) {
if ($value == 'position' && !is_numeric($_POST[$keycode])) {
$_POST[$keycode] = '1';
}
+ if ($value == 'defaultfortype' && !is_numeric($_POST[$keycode])) {
+ $_POST[$keycode] = '0';
+ }
//var_dump($keycode.' '.$value);
if ($i) {
@@ -400,7 +404,7 @@ if (empty($reshook)) {
}
} elseif ($keycode == 'content') {
$sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
- } elseif (in_array($keycode, array('joinfiles', 'private', 'position', 'entity'))) {
+ } elseif (in_array($keycode, array('joinfiles', 'defaultfortype', 'private', 'position', 'entity'))) {
$sql .= (int) GETPOST($keycode, 'int');
} else {
$sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
@@ -430,7 +434,7 @@ if (empty($reshook)) {
// Modify entry
$sql = "UPDATE ".$tabname[$id]." SET ";
- // Modifie valeur des champs
+ // Modify value of fields
$i = 0;
foreach ($listfieldmodify as $field) {
if ($field == 'entity') {
@@ -449,20 +453,20 @@ if (empty($reshook)) {
}
// Rename some POST variables into a generic name
- if ($field == 'fk_user' && !($_POST['fk_user'] > 0)) {
+ if ($field == 'fk_user' && !(GETPOST('fk_user', 'int') > 0)) {
$_POST['fk_user'] = '';
}
if ($field == 'topic') {
- $_POST['topic'] = $_POST['topic-'.$rowid];
+ $_POST['topic'] = GETPOST('topic-'.$rowid);
}
if ($field == 'joinfiles') {
- $_POST['joinfiles'] = $_POST['joinfiles-'.$rowid];
+ $_POST['joinfiles'] = GETPOST('joinfiles-'.$rowid);
}
if ($field == 'content') {
- $_POST['content'] = $_POST['content-'.$rowid];
+ $_POST['content'] = GETPOST('content-'.$rowid);
}
if ($field == 'content_lines') {
- $_POST['content_lines'] = $_POST['content_lines-'.$rowid];
+ $_POST['content_lines'] = GETPOST('content_lines-'.$rowid);
}
if ($i) {
@@ -470,7 +474,7 @@ if (empty($reshook)) {
}
$sql .= $field."=";
- if (GETPOST($keycode) == '' || ($keycode != 'langcode' && $keycode != 'position' && $keycode != 'private' && !GETPOST($keycode))) {
+ if (GETPOST($keycode) == '' || (!in_array($keycode, array('langcode', 'position', 'private', 'defaultfortype')) && !GETPOST($keycode))) {
$sql .= "null"; // langcode,... must be '' if not defined so the unique key that include lang will work
} elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') {
$sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
@@ -482,12 +486,11 @@ if (empty($reshook)) {
}
} elseif ($keycode == 'content') {
$sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
- } elseif (in_array($keycode, array('joinfiles', 'private', 'position'))) {
+ } elseif (in_array($keycode, array('joinfiles', 'defaultfortype', 'private', 'position'))) {
$sql .= (int) GETPOST($keycode, 'int');
} else {
$sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
}
-
$i++;
}
@@ -572,7 +575,7 @@ if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu
$morejs = array();
$morecss = array();
-$sql = "SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, joinfiles, content_lines, content, enabled, active";
+$sql = "SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, joinfiles, defaultfortype, content_lines, content, enabled, active";
$sql .= " FROM ".MAIN_DB_PREFIX."c_email_templates";
$sql .= " WHERE entity IN (".getEntity('email_template').")";
if (!$user->admin) {
@@ -693,6 +696,7 @@ if ($action == 'create') {
$obj->position = GETPOST('position');
$obj->topic = GETPOST('topic');
$obj->joinfiles = GETPOST('joinfiles');
+ $obj->defaultfortype = GETPOST('defaultfortype') ? 1 : 0;
$obj->content = GETPOST('content', 'restricthtml');
// Form to add a new line
@@ -711,9 +715,9 @@ if ($action == 'create') {
// dans les dictionnaires de donnees
$valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
$valuetoshow = $langs->trans($valuetoshow); // try to translate
- $align = "left";
+ $css = "left";
if ($fieldlist[$field] == 'module') {
- $valuetoshow = '';
+ $valuetoshow = ' ';
}
if ($fieldlist[$field] == 'fk_user') {
$valuetoshow = $langs->trans("Owner");
@@ -724,20 +728,20 @@ if ($action == 'create') {
if ($fieldlist[$field] == 'type') {
$valuetoshow = $langs->trans("Type");
}
+ if ($fieldlist[$field] == 'position') {
+ $css = 'center';
+ }
if ($fieldlist[$field] == 'code') {
$valuetoshow = $langs->trans("Code");
}
- if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
+ if ($fieldlist[$field] == 'label') {
$valuetoshow = $langs->trans("Code");
}
if ($fieldlist[$field] == 'type_template') {
- $valuetoshow = $langs->trans("TypeOfTemplate"); $align = "center";
+ $valuetoshow = $langs->trans("TypeOfTemplate"); $css = "center";
}
- if ($fieldlist[$field] == 'private') {
- $align = 'center';
- }
- if ($fieldlist[$field] == 'position') {
- $align = 'center';
+ if (in_array($fieldlist[$field], array('private', 'private', 'defaultfortype'))) {
+ $css = 'center';
}
if ($fieldlist[$field] == 'topic') {
@@ -753,7 +757,7 @@ if ($action == 'create') {
$valuetoshow = '';
}
if ($valuetoshow != '') {
- print '
';
+ print ' ';
if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
print ''.$valuetoshow.' '.img_help(1, $valuetoshow).' ';
} elseif (!empty($tabhelp[$id][$value])) {
@@ -793,18 +797,18 @@ if ($action == 'create') {
fieldList($fieldlist, $obj, $tabname[$id], 'add');
}
}
-
+ // Action column
print ' ';
print ' ';
print "";
// Show fields for topic, join files and body
- $fieldsforcontent = array('topic', 'joinfiles', 'content');
+ $fieldsforcontent = array('topic', 'joinfiles', 'defaultfortype', 'content');
if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
- $fieldsforcontent = array('topic', 'joinfiles', 'content', 'content_lines');
+ $fieldsforcontent = array('topic', 'joinfiles', 'defaultfortype', 'content', 'content_lines');
}
foreach ($fieldsforcontent as $tmpfieldlist) {
- print '';
+ print ' ';
// Topic of email
if ($tmpfieldlist == 'topic') {
@@ -911,7 +915,6 @@ if ($num > $listlimit) {
// Title line with search boxes
print ' ';
-
foreach ($fieldlist as $field => $value) {
if ($value == 'module') {
print ' ';
@@ -935,13 +938,13 @@ foreach ($fieldlist as $field => $value) {
print ' ';
}
}
-
-if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
+/*if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
print ' ';
-}
-
+}*/
+// Status
+print ' ';
// Action column
-print '';
+print ' ';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print ' ';
@@ -951,7 +954,7 @@ print ' ';
print '';
foreach ($fieldlist as $field => $value) {
$showfield = 1; // By defaut
- $align = "left";
+ $css = "left";
$sortable = 1;
$valuetoshow = '';
$forcenowrap = 1;
@@ -959,13 +962,13 @@ foreach ($fieldlist as $field => $value) {
$tmparray=getLabelOfField($fieldlist[$field]);
$showfield=$tmp['showfield'];
$valuetoshow=$tmp['valuetoshow'];
- $align=$tmp['align'];
+ $css=$tmp['align'];
$sortable=$tmp['sortable'];
*/
$valuetoshow = ucfirst($fieldlist[$field]); // By defaut
$valuetoshow = $langs->trans($valuetoshow); // try to translate
if ($fieldlist[$field] == 'module') {
- $align = 'tdoverflowmax100';
+ $css = 'tdoverflowmax100';
}
if ($fieldlist[$field] == 'fk_user') {
$valuetoshow = $langs->trans("Owner");
@@ -980,18 +983,20 @@ foreach ($fieldlist as $field => $value) {
$valuetoshow = $langs->trans("Code");
}
if ($fieldlist[$field] == 'type_template') {
- $align = 'center';
+ $css = 'center';
$valuetoshow = $langs->trans("TypeOfTemplate");
}
if ($fieldlist[$field] == 'private') {
- $align = 'center';
+ $css = 'center';
}
if ($fieldlist[$field] == 'position') {
- $align = 'center';
+ $css = 'center';
}
if ($fieldlist[$field] == 'joinfiles') {
- $valuetoshow = $langs->trans("FilesAttachedToEmail"); $align = 'center'; $forcenowrap = 0;
+ $valuetoshow = $langs->trans("FilesAttachedToEmail");
+ $css = 'center';
+ $forcenowrap = 0;
}
if ($fieldlist[$field] == 'content') {
$valuetoshow = $langs->trans("Content"); $showfield = 0;
@@ -1013,7 +1018,7 @@ foreach ($fieldlist as $field => $value) {
if ($sortfieldtouse == 'type_template') {
$sortfieldtouse.= 'type_template,lang,position,label';
}
- print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], $sortfieldtouse, ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $align.' ');
+ print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], $sortfieldtouse, ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $css.' ');
}
}
@@ -1042,7 +1047,6 @@ if ($num) {
fieldList($fieldlist, $obj, $tabname[$id], 'edit');
}
- print ' ';
print '';
print ' ';
print ' ';
@@ -1057,7 +1061,7 @@ if ($num) {
}
foreach ($fieldsforcontent as $tmpfieldlist) {
$showfield = 1;
- $align = "left";
+ $css = "left";
$valuetoshow = $obj->$tmpfieldlist;
$class = 'tddict';
@@ -1065,7 +1069,7 @@ if ($num) {
if ($showfield) {
// Show line for topic, joinfiles and content
print ' ';
- print '';
+ print ' ';
if ($tmpfieldlist == 'topic') {
print ''.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).' ';
print ' ';
@@ -1139,7 +1143,7 @@ if ($num) {
continue;
}
$showfield = 1;
- $align = "";
+ $css = "";
$class = "tddict";
$title = '';
$tmpvar = $fieldlist[$field];
@@ -1158,7 +1162,7 @@ if ($num) {
}
if ($value == 'type_template') {
$valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
- $align = "center";
+ $css = "center";
}
if ($value == 'lang' && $valuetoshow) {
$valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
@@ -1171,7 +1175,7 @@ if ($num) {
}
}
if ($value == 'private') {
- $align = "center";
+ $css = "center";
if ($valuetoshow) {
$valuetoshow = yn($valuetoshow);
} else {
@@ -1179,18 +1183,18 @@ if ($num) {
}
}
if ($value == 'position') {
- $align = "center";
+ $css = "center";
}
- if ($value == 'joinfiles') {
- $align = "center";
+ if (in_array($value, array('joinfiles', 'defaultfortype'))) {
+ $css = "center";
if ($valuetoshow) {
$valuetoshow = yn(1);
} else {
$valuetoshow = '';
}
}
- if ($align) {
- $class .= ' '.$align;
+ if ($css) {
+ $class .= ' '.$css;
}
// Show value for field
@@ -1288,6 +1292,7 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
$formadmin = new FormAdmin($db);
foreach ($fieldlist as $field => $value) {
+ //print $value;
if ($value == 'module') {
print ' ';
} elseif ($value == 'fk_user') {
@@ -1343,11 +1348,11 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
}
print '';
} elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
- continue;
+ //print ' ';
} elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
- continue;
+ print ' ';
} elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
- continue;
+ //print ' ';
} else {
$size = ''; $class = ''; $classtd = '';
if ($value == 'code') {
@@ -1357,19 +1362,19 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
$class = 'maxwidth200';
}
if ($value == 'private') {
- $class = 'maxwidth50'; $classtd = 'center';
+ $class = 'maxwidth50';
+ $classtd = 'center';
}
if ($value == 'position') {
- $class = 'maxwidth50 center'; $classtd = 'center';
- }
- if ($value == 'libelle') {
- $class = 'quatrevingtpercent';
+ $class = 'maxwidth50 center';
+ $classtd = 'center';
}
if ($value == 'topic') {
$class = 'quatrevingtpercent';
}
- if ($value == 'sortorder' || $value == 'sens' || $value == 'category_type') {
- $size = 'size="2" ';
+ if ($value == 'defaultfortype') {
+ $class = 'width25 center';
+ $classtd = 'center';
}
print '';
@@ -1377,10 +1382,10 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
if (empty($user->admin)) {
print $form->selectyesno($value, '1', 1);
} else {
- print $form->selectyesno($value, (isset($obj->{$value}) ? $obj->{$value}:''), 1);
+ print $form->selectyesno($value, (isset($obj->$value) ? $obj->$value : ''), 1);
}
} else {
- print ' ';
+ print ' ';
}
print ' ';
}
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index a493b104036..36fd9425943 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -2381,3 +2381,5 @@ MAIN_IMAP_USE_PHPIMAP=Use the PHP-IMAP library for IMAP instead of native PHP IM
MAIN_CHECKBOX_LEFT_COLUMN=Show the column for field and line selection on the left (on the right by default)
NotAvailableByDefaultEnabledOnModuleActivation=Not created by default. Created on module activation only.
CSSPage=CSS Style
+Defaultfortype=Default
+DefaultForTypeDesc=Template used by default when creating a new email for the template type
\ No newline at end of file