-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
FIX adding tms and datec to email templates #36189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eldy
merged 14 commits into
Dolibarr:develop
from
JonBendtsen:adding_tms_datec_to_email_templates
Nov 11, 2025
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d25d55a
NEW: adding tms and datec to email templates
725a6b3
Escaping a timestamp string I just generated myself
cbbc1a4
switching single and double quotes in escape line for tms and datec t…
9481fbf
Add an id to the table
5bd5c0e
showing better names than tms and datec
19644bc
Changing code to label to fix #29116
52b1215
using hregis advice to use idate not escape the string with date
d5db220
requested changes
cc0fdcc
forgot to add my name to editors
14e8ddd
had to make class changes for API to work
f578a74
setting datec back to int|string
cc46b22
removing unused code lines and using idate in the api file
e9b1e25
no tms in create or update, but select. No datec in update
7b8b648
expanding hurl tests to prevent post with id or tms, put with id or d…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| * Copyright (C) 2018-2024 Frédéric France <[email protected]> | ||
| * Copyright (C) 2024-2025 MDW <[email protected]> | ||
| * Copyright (C) 2025 Vincent Maury <[email protected]> | ||
| * Copyright (C) 2025 Jon Bendtsen <[email protected]> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
|
|
@@ -120,22 +121,25 @@ | |
| $tabname[25] = MAIN_DB_PREFIX."c_email_templates"; | ||
|
|
||
| // Nom des champs en resultat de select pour affichage du dictionnaire | ||
| // Names of fields in select results for dictionary display (AI translated) | ||
| $tabfield = array(); | ||
| $tabfield[25] = "label,lang,type_template,fk_user,private,position,module,topic,joinfiles,defaultfortype,content"; | ||
| if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) { | ||
| $tabfield[25] .= ',content_lines'; | ||
| } | ||
|
|
||
| // Nom des champs d'edition pour modification d'un enregistrement | ||
| // Names of edit fields for modifying a record (AI translated) | ||
| $tabfieldvalue = array(); | ||
| $tabfieldvalue[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content"; | ||
| if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) { | ||
| $tabfieldvalue[25] .= ',content_lines'; | ||
| } | ||
|
|
||
| // Nom des champs dans la table pour insertion d'un enregistrement | ||
| // Field names in the table for inserting a record (AI translated) | ||
| $tabfieldinsert = array(); | ||
| $tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content"; | ||
| $tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content,tms,datec"; | ||
| if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) { | ||
| $tabfieldinsert[25] .= ',content_lines'; | ||
| } | ||
|
|
@@ -338,14 +342,14 @@ | |
| if ((GETPOST('actionadd', 'alpha') && $permissiontoadd) || (GETPOST('actionmodify', 'alpha') && $permissiontoedit)) { | ||
| $listfield = explode(',', str_replace(' ', '', $tabfield[25])); | ||
| $listfieldinsert = explode(',', $tabfieldinsert[25]); | ||
| $listfieldmodify = explode(',', $tabfieldinsert[25]); | ||
| $listfieldmodify = explode(',', $tabfieldvalue[25]); | ||
| $listfieldvalue = explode(',', $tabfieldvalue[25]); | ||
|
|
||
| // Check that all fields are filled | ||
| $ok = 1; | ||
| foreach ($listfield as $f => $value) { | ||
| // Not mandatory fields | ||
| if (in_array($value, ['joinfiles', 'defaultfortype', 'content', 'content_lines', 'module'])) { | ||
| if (in_array($value, ['joinfiles', 'defaultfortype', 'content', 'content_lines', 'module', 'tms', 'datec'])) { | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -399,6 +403,7 @@ | |
|
|
||
| // List of values | ||
| $i = 0; | ||
| $now = dol_now(); | ||
| foreach ($listfieldinsert as $f => $value) { | ||
| $keycode = isset($listfieldvalue[$i]) ? $listfieldvalue[$i] : ""; | ||
| if ($value == 'lang') { | ||
|
|
@@ -429,7 +434,11 @@ | |
| if ($i) { | ||
| $sql .= ", "; | ||
| } | ||
| if (GETPOST($keycode) == '' && $keycode != 'langcode') { | ||
| if ($keycode == 'datec') { | ||
| $sql .= "'".$db->idate($now)."'"; | ||
| } elseif ($keycode == 'tms') { | ||
| $sql .= "'".$db->idate($now)."'"; | ||
| } elseif (GETPOST($keycode) == '' && $keycode != 'langcode') { | ||
| $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 | ||
|
|
@@ -485,6 +494,7 @@ | |
| $sql = "UPDATE ".$tabname[25]." SET "; | ||
| // Modify value of fields | ||
| $i = 0; | ||
| $now = dol_now(); | ||
| foreach ($listfieldmodify as $field) { | ||
| if ($field == 'entity') { | ||
| // entity not present on listfieldmodify array | ||
|
|
@@ -631,7 +641,7 @@ | |
| $morejs = array(); | ||
| $morecss = array(); | ||
|
|
||
| $sql = "SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, email_from,joinfiles, defaultfortype, content_lines, content, enabled, active"; | ||
| $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"; | ||
| $sql .= " FROM ".MAIN_DB_PREFIX."c_email_templates"; | ||
| $sql .= " WHERE entity IN (".getEntity('email_template').")"; | ||
| if (!$user->admin) { | ||
|
|
@@ -757,14 +767,15 @@ | |
| $obj->content = GETPOST('content', 'restricthtml'); | ||
|
|
||
| // Form to add a new line | ||
| print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'; | ||
| print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" id="create_c_email_template">'; | ||
| print '<input type="hidden" name="token" value="'.newToken().'">'; | ||
| print '<input type="hidden" name="action" value="add">'; | ||
| print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">'; | ||
| print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; | ||
| print '<input type="hidden" name="datec" value="'.$db->idate($now).'">'; | ||
|
|
||
| print '<div class="div-table-responsive-no-min">'; | ||
| print '<table class="noborder centpercent">'; | ||
| print '<table class="noborder centpercent" id="table_create_c_email_template">'; | ||
|
|
||
| // Line to enter new values (title) | ||
| print '<tr class="liste_titre">'; | ||
|
|
@@ -793,7 +804,7 @@ | |
| $valuetoshow = $langs->trans("Code"); | ||
| } | ||
| if ($fieldlist[$field] == 'label') { | ||
| $valuetoshow = $langs->trans("Code"); | ||
| $valuetoshow = $langs->trans("Label"); | ||
| } | ||
| if ($fieldlist[$field] == 'type_template') { | ||
| $valuetoshow = $langs->trans("TypeOfTemplate"); | ||
|
|
@@ -844,7 +855,6 @@ | |
| $error = $hookmanager->error; | ||
| $errors = $hookmanager->errors; | ||
|
|
||
|
|
||
| // Line to enter new values (input fields) | ||
| print '<tr class="oddeven">'; | ||
|
|
||
|
|
@@ -932,12 +942,12 @@ | |
|
|
||
| $num = $db->num_rows($resql); | ||
|
|
||
| print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'; | ||
| print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" id="list_of_c_email_templates">'; | ||
| print '<input type="hidden" name="token" value="'.newToken().'">'; | ||
| print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">'; | ||
|
|
||
| print '<div class="div-table-responsive-no-min">'; | ||
| print '<table class="noborder centpercent">'; | ||
| print '<table class="noborder centpercent" id="table_list_of_c_email_templates">'; | ||
|
|
||
| $i = 0; | ||
|
|
||
|
|
@@ -981,7 +991,7 @@ | |
|
|
||
|
|
||
| // Title line with search boxes | ||
| print '<tr class="liste_titre">'; | ||
| print '<tr class="liste_titre" id="Title line with search boxes">'; | ||
| // Action column | ||
| if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { | ||
| print '<td class="liste_titre center" width="64">'; | ||
|
|
@@ -1018,6 +1028,9 @@ | |
| }*/ | ||
| // Status | ||
| print '<td></td>'; | ||
| // 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 | ||
| print '<td></td>'; // tms / Modif. date | ||
| print '<td></td>'; // datec / Date creation | ||
| // Action column | ||
| if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { | ||
| print '<td class="liste_titre center" width="64">'; | ||
|
|
@@ -1028,11 +1041,12 @@ | |
| print '</tr>'; | ||
|
|
||
| // Title of lines | ||
| print '<tr class="liste_titre">'; | ||
| print '<tr class="liste_titre" id="Title of lines">'; | ||
| // Action column | ||
| if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { | ||
| print getTitleFieldOfList(''); | ||
| } | ||
| array_push($fieldlist, "tms", "datec"); | ||
| foreach ($fieldlist as $field => $value) { | ||
| $showfield = 1; // By default | ||
| $css = "left"; | ||
|
|
@@ -1061,7 +1075,7 @@ | |
| $valuetoshow = $langs->trans("Type"); | ||
| } | ||
| if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') { | ||
| $valuetoshow = $langs->trans("Code"); | ||
| $valuetoshow = $langs->trans("Label"); | ||
| } | ||
| if ($fieldlist[$field] == 'type_template') { | ||
| $css = 'center'; | ||
|
|
@@ -1073,6 +1087,12 @@ | |
| if ($fieldlist[$field] == 'position') { | ||
| $css = 'center'; | ||
| } | ||
| if ($fieldlist[$field] == 'tms') { | ||
| $valuetoshow = 'Modif. date'; | ||
| } | ||
| if ($fieldlist[$field] == 'datec') { | ||
| $valuetoshow = 'Date creation'; | ||
| } | ||
|
|
||
| if ($fieldlist[$field] == 'joinfiles') { | ||
| $valuetoshow = $langs->trans("FilesAttachedToEmail"); | ||
|
|
@@ -1123,7 +1143,14 @@ | |
| print '<tr class="nohover oddeven" id="rowid-'.$obj->rowid.'">'; | ||
|
|
||
| $tmpaction = 'edit'; | ||
| $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]); | ||
| if ($action == 'edit') { | ||
| // do not show tms and datec | ||
| $fieldlist = explode(',', $tabfield[25]); | ||
| $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]); | ||
| } else { | ||
| array_push($fieldlist, "tms", "datec"); | ||
| $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]); | ||
| } | ||
| $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks | ||
| $error = $hookmanager->error; | ||
| $errors = $hookmanager->errors; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hregis you probably mean this line nr 439 - 441
This is during
in line 396, meaning this is during INSERT, and the configuration of the tms field is

So it only uses CURRENT_TIMESTAMP() during update, not during INSERT. So if I remove the tms line, then it does not get a value in tms, and I'd argue that creation of an object is a modification of the current state.