|
14 | 14 | * Copyright (C) 2018-2024 Frédéric France <[email protected]> |
15 | 15 | * Copyright (C) 2024-2025 MDW <[email protected]> |
16 | 16 | * Copyright (C) 2025 Vincent Maury <[email protected]> |
| 17 | + * Copyright (C) 2025 Jon Bendtsen <[email protected]> |
17 | 18 | * |
18 | 19 | * This program is free software; you can redistribute it and/or modify |
19 | 20 | * it under the terms of the GNU General Public License as published by |
|
120 | 121 | $tabname[25] = MAIN_DB_PREFIX."c_email_templates"; |
121 | 122 |
|
122 | 123 | // Nom des champs en resultat de select pour affichage du dictionnaire |
| 124 | +// Names of fields in select results for dictionary display (AI translated) |
123 | 125 | $tabfield = array(); |
124 | 126 | $tabfield[25] = "label,lang,type_template,fk_user,private,position,module,topic,joinfiles,defaultfortype,content"; |
125 | 127 | if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) { |
126 | 128 | $tabfield[25] .= ',content_lines'; |
127 | 129 | } |
128 | 130 |
|
129 | 131 | // Nom des champs d'edition pour modification d'un enregistrement |
| 132 | +// Names of edit fields for modifying a record (AI translated) |
130 | 133 | $tabfieldvalue = array(); |
131 | 134 | $tabfieldvalue[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content"; |
132 | 135 | if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) { |
133 | 136 | $tabfieldvalue[25] .= ',content_lines'; |
134 | 137 | } |
135 | 138 |
|
136 | 139 | // Nom des champs dans la table pour insertion d'un enregistrement |
| 140 | +// Field names in the table for inserting a record (AI translated) |
137 | 141 | $tabfieldinsert = array(); |
138 | | -$tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content"; |
| 142 | +$tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content,datec"; |
139 | 143 | if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) { |
140 | 144 | $tabfieldinsert[25] .= ',content_lines'; |
141 | 145 | } |
|
338 | 342 | if ((GETPOST('actionadd', 'alpha') && $permissiontoadd) || (GETPOST('actionmodify', 'alpha') && $permissiontoedit)) { |
339 | 343 | $listfield = explode(',', str_replace(' ', '', $tabfield[25])); |
340 | 344 | $listfieldinsert = explode(',', $tabfieldinsert[25]); |
341 | | - $listfieldmodify = explode(',', $tabfieldinsert[25]); |
| 345 | + $listfieldmodify = explode(',', $tabfieldvalue[25]); |
342 | 346 | $listfieldvalue = explode(',', $tabfieldvalue[25]); |
343 | 347 |
|
344 | 348 | // Check that all fields are filled |
345 | 349 | $ok = 1; |
346 | 350 | foreach ($listfield as $f => $value) { |
347 | 351 | // Not mandatory fields |
348 | | - if (in_array($value, ['joinfiles', 'defaultfortype', 'content', 'content_lines', 'module'])) { |
| 352 | + if (in_array($value, ['joinfiles', 'defaultfortype', 'content', 'content_lines', 'module', 'tms', 'datec'])) { |
349 | 353 | continue; |
350 | 354 | } |
351 | 355 |
|
|
399 | 403 |
|
400 | 404 | // List of values |
401 | 405 | $i = 0; |
| 406 | + $now = dol_now(); |
402 | 407 | foreach ($listfieldinsert as $f => $value) { |
403 | 408 | $keycode = isset($listfieldvalue[$i]) ? $listfieldvalue[$i] : ""; |
404 | 409 | if ($value == 'lang') { |
|
429 | 434 | if ($i) { |
430 | 435 | $sql .= ", "; |
431 | 436 | } |
432 | | - if (GETPOST($keycode) == '' && $keycode != 'langcode') { |
| 437 | + if ($keycode == 'datec') { |
| 438 | + $sql .= "'".$db->idate($now)."'"; |
| 439 | + } elseif (GETPOST($keycode) == '' && $keycode != 'langcode') { |
433 | 440 | $sql .= "null"; // langcode must be '' if not defined so the unique key that include lang will work |
434 | 441 | } elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') { |
435 | 442 | $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work |
|
631 | 638 | $morejs = array(); |
632 | 639 | $morecss = array(); |
633 | 640 |
|
634 | | -$sql = "SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, email_from,joinfiles, defaultfortype, content_lines, content, enabled, active"; |
| 641 | +$sql = "SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, email_from,joinfiles, defaultfortype, content_lines, content, enabled, active, tms, datec"; |
635 | 642 | $sql .= " FROM ".MAIN_DB_PREFIX."c_email_templates"; |
636 | 643 | $sql .= " WHERE entity IN (".getEntity('email_template').")"; |
637 | 644 | if (!$user->admin) { |
|
757 | 764 | $obj->content = GETPOST('content', 'restricthtml'); |
758 | 765 |
|
759 | 766 | // Form to add a new line |
760 | | - print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'; |
| 767 | + print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" id="create_c_email_template">'; |
761 | 768 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
762 | 769 | print '<input type="hidden" name="action" value="add">'; |
763 | 770 | print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">'; |
764 | 771 | print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; |
765 | 772 |
|
766 | 773 | print '<div class="div-table-responsive-no-min">'; |
767 | | - print '<table class="noborder centpercent">'; |
| 774 | + print '<table class="noborder centpercent" id="table_create_c_email_template">'; |
768 | 775 |
|
769 | 776 | // Line to enter new values (title) |
770 | 777 | print '<tr class="liste_titre">'; |
|
793 | 800 | $valuetoshow = $langs->trans("Code"); |
794 | 801 | } |
795 | 802 | if ($fieldlist[$field] == 'label') { |
796 | | - $valuetoshow = $langs->trans("Code"); |
| 803 | + $valuetoshow = $langs->trans("Label"); |
797 | 804 | } |
798 | 805 | if ($fieldlist[$field] == 'type_template') { |
799 | 806 | $valuetoshow = $langs->trans("TypeOfTemplate"); |
|
932 | 939 |
|
933 | 940 | $num = $db->num_rows($resql); |
934 | 941 |
|
935 | | -print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'; |
| 942 | +print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" id="list_of_c_email_templates">'; |
936 | 943 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
937 | 944 | print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">'; |
938 | 945 |
|
939 | 946 | print '<div class="div-table-responsive-no-min">'; |
940 | | -print '<table class="noborder centpercent">'; |
| 947 | +print '<table class="noborder centpercent" id="table_list_of_c_email_templates">'; |
941 | 948 |
|
942 | 949 | $i = 0; |
943 | 950 |
|
|
981 | 988 |
|
982 | 989 |
|
983 | 990 | // Title line with search boxes |
984 | | -print '<tr class="liste_titre">'; |
| 991 | +print '<tr class="liste_titre" id="Title line with search boxes">'; |
985 | 992 | // Action column |
986 | 993 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
987 | 994 | print '<td class="liste_titre center" width="64">'; |
|
1018 | 1025 | }*/ |
1019 | 1026 | // Status |
1020 | 1027 | print '<td></td>'; |
| 1028 | +// Have to expand the id="Title line with search boxes" with 2 extra fields because the line below id="Title of lines" are 2 fields longer |
| 1029 | +print '<td></td>'; // tms / Modif. date |
| 1030 | +print '<td></td>'; // datec / Date creation |
1021 | 1031 | // Action column |
1022 | 1032 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
1023 | 1033 | print '<td class="liste_titre center" width="64">'; |
|
1028 | 1038 | print '</tr>'; |
1029 | 1039 |
|
1030 | 1040 | // Title of lines |
1031 | | -print '<tr class="liste_titre">'; |
| 1041 | +print '<tr class="liste_titre" id="Title of lines">'; |
1032 | 1042 | // Action column |
1033 | 1043 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
1034 | 1044 | print getTitleFieldOfList(''); |
1035 | 1045 | } |
| 1046 | +array_push($fieldlist, "tms", "datec"); |
1036 | 1047 | foreach ($fieldlist as $field => $value) { |
1037 | 1048 | $showfield = 1; // By default |
1038 | 1049 | $css = "left"; |
|
1061 | 1072 | $valuetoshow = $langs->trans("Type"); |
1062 | 1073 | } |
1063 | 1074 | if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') { |
1064 | | - $valuetoshow = $langs->trans("Code"); |
| 1075 | + $valuetoshow = $langs->trans("Label"); |
1065 | 1076 | } |
1066 | 1077 | if ($fieldlist[$field] == 'type_template') { |
1067 | 1078 | $css = 'center'; |
|
1073 | 1084 | if ($fieldlist[$field] == 'position') { |
1074 | 1085 | $css = 'center'; |
1075 | 1086 | } |
| 1087 | + if ($fieldlist[$field] == 'tms') { |
| 1088 | + $valuetoshow = 'Modif. date'; |
| 1089 | + } |
| 1090 | + if ($fieldlist[$field] == 'datec') { |
| 1091 | + $valuetoshow = 'Date creation'; |
| 1092 | + } |
1076 | 1093 |
|
1077 | 1094 | if ($fieldlist[$field] == 'joinfiles') { |
1078 | 1095 | $valuetoshow = $langs->trans("FilesAttachedToEmail"); |
|
1123 | 1140 | print '<tr class="nohover oddeven" id="rowid-'.$obj->rowid.'">'; |
1124 | 1141 |
|
1125 | 1142 | $tmpaction = 'edit'; |
1126 | | - $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]); |
| 1143 | + if ($action == 'edit') { |
| 1144 | + // do not show tms and datec |
| 1145 | + $fieldlist = explode(',', $tabfield[25]); |
| 1146 | + $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]); |
| 1147 | + } else { |
| 1148 | + $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]); |
| 1149 | + } |
1127 | 1150 | $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks |
1128 | 1151 | $error = $hookmanager->error; |
1129 | 1152 | $errors = $hookmanager->errors; |
|
0 commit comments