Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions htdocs/admin/mails_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -429,7 +434,11 @@
if ($i) {
$sql .= ", ";
}
if (GETPOST($keycode) == '' && $keycode != 'langcode') {
if ($keycode == 'datec') {
$sql .= "'".$db->idate($now)."'";
} elseif ($keycode == 'tms') {
Copy link
Contributor Author

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

		if ($ok && GETPOST('actionadd')) {

in line 396, meaning this is during INSERT, and the configuration of the tms field is
image

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.

$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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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">';
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -844,7 +855,6 @@
$error = $hookmanager->error;
$errors = $hookmanager->errors;


// Line to enter new values (input fields)
print '<tr class="oddeven">';

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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">';
Expand Down Expand Up @@ -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">';
Expand All @@ -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";
Expand Down Expand Up @@ -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';
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions htdocs/core/class/cemailtemplate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ public function create($user, $notrigger = 0)
$sql .= " '".((int) $this->fk_user)."',";
}
if (is_null($this->datec)) {
$sql .= " NULL,";
$sql .= " '".$this->db->idate($now)."',";
} else {
$sql .= " ".((int) $this->datec).",";
$sql .= " ".((string) $this->datec).",";
}
$sql .= " '".$this->db->escape($this->label)."',";
$sql .= " ".((int) $this->position).", ".((int) $this->defaultfortype).",";
Expand Down Expand Up @@ -372,7 +372,7 @@ public function update(User $user, $notrigger = 0)
$sql .= " lang=".($this->lang ? "'".$this->db->escape($this->lang)."', " : 'NULL, ');
$sql .= " private=".((int) $this->private).",";
$sql .= " fk_user=".((int) $this->fk_user).",";
$sql .= " datec=".((int) $this->datec).",";
$sql .= " datec='".$this->db->idate($this->datec)."',";
$sql .= " label=".($this->label ? "'".$this->db->escape($this->label)."', " : 'NULL, ');
$sql .= " position=".((int) $this->position).",";
$sql .= " defaultfortype=".((int) $this->defaultfortype).",";
Expand Down Expand Up @@ -528,7 +528,7 @@ public function apifetch($id, $label = '')
$this->active = (int) $obj->active;
$this->content = (string) $obj->content;
$this->content_lines = (string) $obj->content_lines;
$this->datec = (int) $obj->datec;
$this->datec = $this->db->jdate($obj->datec);
$this->defaultfortype = (int) $obj->defaultfortype;
$this->email_from = (string) $obj->email_from;
$this->email_to = (string) $obj->email_to;
Expand All @@ -542,7 +542,7 @@ public function apifetch($id, $label = '')
$this->module = (string) $obj->module;
$this->position = (int) $obj->position;
$this->private = (int) $obj->private;
$this->tms = $obj->tms;
$this->tms = $this->db->jdate($obj->tms);
$this->topic = (string) $obj->topic;
$this->type_template = (string) $obj->type_template;

Expand Down
Loading