dolibarr 25.0.0-alpha
member_emails.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2012 J. Fernando Lagrange <fernando@demo-tic.org>
10 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
11 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
12 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
35// Load Dolibarr environment
36require '../../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
46
47// Load translation files required by the page
48$langs->loadLangs(array("admin", "members"));
49
50if (!$user->admin) {
52}
53
54
55$oldtypetonewone = array('texte' => 'text', 'chaine' => 'string'); // old type to new ones
56
57$action = GETPOST('action', 'aZ09');
58
59$error = 0;
60
61$helptext = '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
62$helptext .= '__DOL_MAIN_URL_ROOT__, __ID__, __FIRSTNAME__, __LASTNAME__, __FULLNAME__, __LOGIN__, __PASSWORD__, ';
63$helptext .= '__COMPANY__, __ADDRESS__, __ZIP__, __TOWN__, __COUNTRY__, __EMAIL__, __BIRTH__, __PHOTO__, __TYPE__, ';
64//$helptext.='__YEAR__, __MONTH__, __DAY__'; // Not supported
65
66// Editing global variables not related to a specific theme
67$constantes = array(
68 'MEMBER_REMINDER_EMAIL' => array('type' => 'yesno', 'label' => $langs->trans('MEMBER_REMINDER_EMAIL', $langs->transnoentities("Module2300Name")), 'help' => $langs->trans('MEMBER_REMINDER_EMAILHelp', $langs->transnoentities("Module2300Name"))),
69 'ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION' => array('type' => 'emailtemplate:member', 'label' => ''),
70 'ADHERENT_EMAIL_TEMPLATE_AUTOREGISTER' => array('type' => 'emailtemplate:member', 'label' => ''),
71 'ADHERENT_EMAIL_TEMPLATE_MEMBER_VALIDATION' => array('type' => 'emailtemplate:member', 'label' => ''),
72 'ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION' => array('type' => 'emailtemplate:member', 'label' => ''),
73 'ADHERENT_EMAIL_TEMPLATE_CANCELATION' => array('type' => 'emailtemplate:member', 'label' => ''),
74 'ADHERENT_EMAIL_TEMPLATE_EXCLUSION' => array('type' => 'emailtemplate:member', 'label' => ''),
75 'ADHERENT_MAIL_FROM' => array('type' => 'string', 'label' => ''),
76 'ADHERENT_CC_MAIL_FROM' => array('type' => 'string', 'label' => ''),
77 'ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT' => array('type' => 'string', 'label' => ''),
78 'ADHERENT_AUTOREGISTER_NOTIF_MAIL' => array('type' => 'html', 'tooltip' => $helptext, 'label' => '')
79);
80
81
82/*
83 * Actions
84 */
85
86//
87if ($action == 'updateall') {
88 $db->begin();
89
90 $res = 0;
91 foreach ($constantes as $constname => $value) {
92 $constvalue = (GETPOSTISSET('constvalue_'.$constname) ? GETPOST('constvalue_'.$constname, 'alphanohtml') : GETPOST('constvalue'));
93 $consttype = (GETPOSTISSET('consttype_'.$constname) ? GETPOST('consttype_'.$constname, 'alphanohtml') : GETPOST('consttype'));
94 $constnote = (GETPOSTISSET('constnote_'.$constname) ? GETPOST('constnote_'.$constname, 'restricthtml') : GETPOST('constnote'));
95
96 $typetouse = empty($oldtypetonewone[$consttype]) ? $consttype : $oldtypetonewone[$consttype];
97 $constvalue = preg_replace('/:member$/', '', $constvalue);
98
99 $res = dolibarr_set_const($db, $constname, $constvalue, $consttype, 0, $constnote, $conf->entity);
100 if ($res <= 0) {
101 $error++;
102 $action = 'list';
103 }
104 }
105
106 if ($error > 0) {
107 setEventMessages('ErrorFailedToSaveDate', null, 'errors');
108 $db->rollback();
109 } else {
110 setEventMessages('RecordModifiedSuccessfully', null, 'mesgs');
111 $db->commit();
112 }
113}
114
115// Action to update or add a constant
116if ($action == 'update' || $action == 'add') {
117 $constlineid = GETPOSTINT('rowid');
118 $constname = GETPOST('constname', 'alpha');
119
120 $constvalue = (GETPOSTISSET('constvalue_'.$constname) ? GETPOST('constvalue_'.$constname, 'alphanohtml') : GETPOST('constvalue'));
121 $consttype = (GETPOSTISSET('consttype_'.$constname) ? GETPOST('consttype_'.$constname, 'alphanohtml') : GETPOST('consttype'));
122 $constnote = (GETPOSTISSET('constnote_'.$constname) ? GETPOST('constnote_'.$constname, 'restricthtml') : GETPOST('constnote'));
123
124 $typetouse = empty($oldtypetonewone[$consttype]) ? $consttype : $oldtypetonewone[$consttype];
125 $constvalue = preg_replace('/:member$/', '', $constvalue);
126
127 $res = dolibarr_set_const($db, $constname, $constvalue, $typetouse, 0, $constnote, $conf->entity);
128
129 if (!($res > 0)) {
130 $error++;
131 }
132
133 if (!$error) {
134 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
135 } else {
136 setEventMessages($langs->trans("Error"), null, 'errors');
137 }
138}
139
140
141/*
142 * View
143 */
144
145$form = new Form($db);
146
147$title = $langs->trans("MembersSetup");
148$help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
149
150llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-admin_emails');
151
152$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
153
154print load_fiche_titre($langs->trans("MembersSetup"), $linkback, 'title_setup');
155
156
158
159print dol_get_fiche_head($head, 'emails', $langs->trans("Members"), -1, 'user');
160
161// Use global form
162print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
163print '<input type="hidden" name="token" value="'.newToken().'">';
164print '<input type="hidden" name="action" value="updateall">';
165
166print '<br>';
167
168// TODO Try to use the formsetup class.
169
170$tableau = $constantes;
171
172print '<div class="div-table-responsive-no-min">';
173print '<table class="noborder centpercent">';
174print '<tr class="liste_titre">';
175print '<td class="">'.$langs->trans("Parameter").'</td>';
176print '<td>';
177print '</td>';
178print "</tr>\n";
179
180foreach ($tableau as $key => $const) { // Loop on each param
181 $label = '';
182 $type = $const['type'];
183 $label = $const['label'];
184 $help = empty($const['help']) ? '' : $const['help'];
185 $const = $key;
186
187 $sql = "SELECT rowid, ".$db->decrypt('name')." as name, ".$db->decrypt('value')." as value, type, note";
188 $sql .= " FROM ".MAIN_DB_PREFIX."const";
189 $sql .= " WHERE ".$db->decrypt('name')." = '".$db->escape($const)."'";
190 $sql .= " AND entity IN (0, ".((int) $conf->entity).")";
191 $sql .= " ORDER BY name ASC, entity DESC";
192 $resql = $db->query($sql);
193
194 dol_syslog("List params", LOG_DEBUG);
195
196 if ($resql) {
197 $obj = $db->fetch_object($resql); // Take first result of select
198
199 if (empty($obj)) { // If not yet into table
200 $obj = (object) array('rowid' => '', 'name' => $const, 'value' => '', 'type' => $type, 'note' => '');
201 }
202 if ($const == 'ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION' && !getDolGlobalString('MEMBER_REMINDER_EMAIL')) {
203 continue;
204 }
205
206 print '<tr class="oddeven">';
207
208 // Show label of parameter
209 print '<td>';
210 print '<input type="hidden" name="rowid[]" value="'.$obj->rowid.'">';
211 print '<input type="hidden" name="constname[]" value="'.$const.'">';
212 print '<input type="hidden" name="constnote_'.$obj->name.'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
213 print '<input type="hidden" name="consttype_'.$obj->name.'" value="'.($obj->type ? $obj->type : 'string').'">';
214
215 $picto = '';
216 $tmparray = explode(':', $obj->type);
217 if (!empty($tmparray[1])) {
218 $picto = preg_replace('/_send$/', '', $tmparray[1]);
219 }
220 if ($picto) {
221 print img_picto('', $picto, 'class="pictofixedwidth"');
222 }
223
224 if (!empty($tableau[$key]['tooltip'])) {
225 print $form->textwithpicto($label ? $label : $langs->trans('Desc'.$const), $tableau[$key]['tooltip'] . $help);
226 } else {
227 print '<span class="valignmiddle">';
228 print($label ? $label : $langs->trans('Desc'.$const));
229 print '</span>';
230 if ($help) {
231 print $form->textwithpicto('', $help);
232 }
233 }
234
235 if (in_array($const, ['ADHERENT_MAIL_FROM', 'ADHERENT_CC_MAIL_FROM'])) {
236 print ' '.img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
237 }
238
239 print "</td>\n";
240
241 // Value
242 print '<td>';
243 print '<input type="hidden" name="consttype_'.$const.'" value="'.($obj->type ? $obj->type : 'string').'">';
244 print '<input type="hidden" name="constnote_'.$const.'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
245 if ($obj->type == 'textarea') {
246 print '<textarea class="flat" name="constvalue_'.$const.'" cols="50" rows="5" wrap="soft">'."\n";
247 print $obj->value;
248 print "</textarea>\n";
249 } elseif ($obj->type == 'html') {
250 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
251 $doleditor = new DolEditor('constvalue_'.$const, $obj->value, '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
252 $doleditor->Create();
253 } elseif ($obj->type == 'yesno') {
254 print $form->selectyesno('constvalue_'.$const, $obj->value, 1, false, 0, 1);
255 } elseif (preg_match('/emailtemplate/', $obj->type)) {
256 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
257 $formmail = new FormMail($db);
258
259 $tmp = explode(':', $obj->type);
260
261 $formmail->fetchAllEMailTemplate($tmp[1], $user, null, -1); // We set lang=null to get in priority record with no lang
262 $arrayofmessagename = array();
263 if (is_array($formmail->lines_model)) {
264 foreach ($formmail->lines_model as $modelmail) {
265 //var_dump($modelmail);
266 $moreonlabel = '';
267 if (!empty($arrayofmessagename[$modelmail->label])) {
268 $moreonlabel = ' <span class="opacitymedium">('.$langs->trans("SeveralLangugeVariatFound").')</span>';
269 }
270 // The 'label' is the key that is unique if we exclude the language
271 $arrayofmessagename[$modelmail->label.':'.$tmp[1]] = $langs->trans(preg_replace('/\‍(|\‍)/', '', $modelmail->label)).$moreonlabel;
272 }
273 }
274 //var_dump($arraydefaultmessage);
275 //var_dump($arrayofmessagename);
276 print $form->selectarray('constvalue_'.$const, $arrayofmessagename, $obj->value.':'.$tmp[1], 'None', 0, 0, '', 0, 0, 0, '', '', 1);
277
278 print '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/mails_templates.php', ['action' => 'create', 'type_template' => $tmp[1], 'backtopage' => dolBuildUrl($_SERVER["PHP_SELF"])]).'">'.img_picto('', 'add').'</a>';
279 } elseif (preg_match('/MAIL_FROM$/i', $const)) {
280 print img_picto('', 'email', 'class="pictofixedwidth"').'<input type="text" class="flat minwidth300" name="constvalue_'.$const.'" value="'.dol_escape_htmltag($obj->value).'">';
281 } else { // type = 'string' or 'chaine'
282 print '<input type="text" class="flat minwidth300" name="constvalue_'.$const .'" value="'.dol_escape_htmltag($obj->value).'">';
283 }
284 print '</td>';
285
286 print "</tr>\n";
287 }
288}
289print '</table>';
290print '</div>';
291
292
293print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>';
294print '</form>';
295
296print dol_get_fiche_end();
297
298// End of page
299llxFooter();
300$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
member_admin_prepare_head()
Return array head with list of tabs to view object information.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.