dolibarr 25.0.0-alpha
agenda_reminder.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
39require_once DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php';
40
41if (!$user->admin) {
43}
44
45// Load translation files required by the page
46$langs->loadLangs(array("admin", "other", "agenda"));
47
48$action = GETPOST('action', 'aZ09');
49$value = GETPOST('value', 'alpha');
50$label = GETPOST('label', 'alpha');
51$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
52
53$param = GETPOST('param', 'alpha');
54$cancel = GETPOST('cancel', 'alpha');
55$scandir = GETPOST('scandir', 'alpha');
56$type = 'action';
57
58$form = new Form($db);
59
60/*
61 * Actions
62 */
63
64include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
65
66$reg = array();
67if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
68 $code = $reg[1];
69 $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
70 if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
71 header("Location: ".$_SERVER["PHP_SELF"]);
72 exit;
73 } else {
74 dol_print_error($db);
75 }
76}
77
78if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
79 $code = $reg[1];
80 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
81 header("Location: ".$_SERVER["PHP_SELF"]);
82 exit;
83 } else {
84 dol_print_error($db);
85 }
86}
87if ($action == 'set') {
88 dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity);
89 dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', GETPOST('AGENDA_DEFAULT_FILTER_TYPE'), 'chaine', 0, '', $conf->entity);
90 dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
91 dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
92 dolibarr_set_const($db, 'AGENDA_DEFAULT_REMINDER_OFFSET', GETPOSTINT('AGENDA_DEFAULT_REMINDER_OFFSET'), 'chaine', 0, '', $conf->entity);
93 dolibarr_set_const($db, 'AGENDA_DEFAULT_REMINDER_OFFSET_UNIT', GETPOST('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT_type_duration'), 'chaine', 0, '', $conf->entity);
94 dolibarr_set_const($db, 'AGENDA_DEFAULT_REMINDER_EMAIL_MODEL', GETPOSTINT('AGENDA_DEFAULT_REMINDER_EMAIL_MODELmodel_mail'), 'chaine', 0, '', $conf->entity);
95 dolibarr_set_const($db, 'AGENDA_DEFAULT_REMINDER_EVENT_TYPES', json_encode(GETPOST('AGENDA_DEFAULT_REMINDER_EVENT_TYPES')), 'chaine', 0, '', $conf->entity);
96} elseif ($action == 'specimen') { // For orders
97 $modele = GETPOST('module', 'alpha');
98
99 $commande = new CommandeFournisseur($db);
100 $commande->initAsSpecimen();
101 $specimenthirdparty = new Societe($db);
102 $specimenthirdparty->initAsSpecimen();
103 $commande->thirdparty = $specimenthirdparty;
104
105 // Search template files
106 $file = '';
107 $classname = '';
108 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
109 foreach ($dirmodels as $reldir) {
110 $file = dol_buildpath($reldir."core/modules/action/doc/pdf_".$modele.".modules.php", 0);
111 if (file_exists($file)) {
112 $classname = "pdf_".$modele;
113 break;
114 }
115 }
116
117 if ($classname !== '') {
118 require_once $file;
119
120 $module = new $classname($db, $commande);
121 '@phan-var-force pdf_standard_actions $module';
124 if ($module->write_file($commande, $langs) > 0) {
125 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
126 exit;
127 } else {
128 setEventMessages($module->error, $module->errors, 'errors');
129 dol_syslog($module->error, LOG_ERR);
130 }
131 } else {
132 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
133 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
134 }
135} elseif ($action == 'setmodel') {
136 // Activate a model
137 //print "sssd".$value;
138 $ret = addDocumentModel($value, $type, $label, $scandir);
139} elseif ($action == 'del') {
140 $ret = delDocumentModel($value, $type);
141 if ($ret > 0) {
142 if (getDolGlobalString('ACTION_EVENT_ADDON_PDF') == "$value") {
143 dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF', $conf->entity);
144 }
145 }
146} elseif ($action == 'setdoc') {
147 // Set default model
148 if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
149 // The constant that has been read in front of the new set
150 // is therefore passed through a variable to have a coherent display
151 $conf->global->ACTION_EVENT_ADDON_PDF = $value;
152 }
153
154 // On active le modele
155 $ret = delDocumentModel($value, $type);
156 if ($ret > 0) {
157 $ret = addDocumentModel($value, $type, $label, $scandir);
158 }
159}
160
161
167$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
168llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-agenda_reminder');
169
170$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>';
171
172print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
173
174
175$head = agenda_prepare_head();
176
177print dol_get_fiche_head($head, 'reminders', $langs->trans("Agenda"), -1, 'action');
178
179print "<br>\n";
180
181print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda" spellcheck="false">';
182print '<input type="hidden" name="token" value="'.newToken().'">';
183print '<input type="hidden" name="action" value="set">';
184
185print '<table class="noborder allwidth">'."\n";
186print '<tr class="liste_titre">'."\n";
187print '<td>'.$langs->trans("Parameters").'</td>'."\n";
188print '<td class="center">&nbsp;</td>'."\n";
189print '<td class="right"></td>'."\n";
190print '</tr>'."\n";
191
192// AGENDA REMINDER BROWSER
193print '<tr class="oddeven">'."\n";
194print '<td>';
195print $form->textwithpicto($langs->trans('AGENDA_REMINDER_BROWSER'), $langs->trans('AGENDA_REMINDER_BROWSERHelp').'<br>'.$langs->trans('AGENDA_REMINDER_Remind')).'<br>';
196print '</td>'."\n";
197print '<td class="center">&nbsp;</td>'."\n";
198print '<td class="right nowraponall">'."\n";
199
200if (!getDolGlobalString('AGENDA_REMINDER_BROWSER')) {
201 print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
202} else {
203 print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
204}
205print '</td></tr>'."\n";
206
207
208$job = new Cronjob($db);
209$job->fetch(0, 'ActionComm', 'sendEmailsReminder');
210
211// AGENDA REMINDER EMAIL
212print '<tr class="oddeven">'."\n";
213print '<td>';
214print $form->textwithpicto($langs->trans('AGENDA_REMINDER_EMAIL', $langs->transnoentities("Module2300Name")), $langs->trans('AGENDA_REMINDER_Help', 'E-mail').'<br>'.$langs->trans('AGENDA_REMINDER_Remind'));
215if (isModEnabled('cron')) {
216 if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
217 if ($job->id > 0) {
218 if ($job->status == $job::STATUS_ENABLED) {
219 print '<br><span class="opacitymedium">'.$langs->trans("AGENDA_REMINDER_EMAIL_NOTE", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
220 }
221 }
222 }
223}
224print '</td>'."\n";
225print '<td class="center">&nbsp;</td>'."\n";
226print '<td class="right nowraponall">'."\n";
227if (!isModEnabled('cron')) {
228 print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
229} else {
230 if (!getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
231 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
232 } else {
233 // Get the max frequency of reminder
234 if ($job->id > 0) {
235 if ($job->status != $job::STATUS_ENABLED) {
236 $langs->load("cron");
237 print '<span class="opacitymedium warning">'.$langs->trans("JobXMustBeEnabled", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
238 } else {
239 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
240 }
241 } else {
242 $langs->load("cron");
243 print '<span class="opacitymedium warning">'.$langs->trans("JobNotFound", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
244 }
245 }
246}
247print '</td></tr>'."\n";
248
249// AGENDA REMINDER SMS
250print '<tr class="oddeven">'."\n";
251print '<td>';
252print $form->textwithpicto($langs->trans('AGENDA_REMINDER_SMS'), $langs->trans('AGENDA_REMINDER_Help', 'SMS').'<br>'.$langs->trans('AGENDA_REMINDER_Remind'));
253if (isModEnabled('cron')) {
254 if (getDolGlobalString('AGENDA_REMINDER_SMS')) {
255 if ($job->id > 0) {
256 if ($job->status == $job::STATUS_ENABLED) {
257 print '<br><span class="opacitymedium">'.$langs->trans("AGENDA_REMINDER_EMAIL_NOTE", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
258 }
259 }
260 }
261}
262print '</td>'."\n";
263print '<td class="center">&nbsp;</td>'."\n";
264print '<td class="right nowraponall">'."\n";
265if (!isModEnabled('cron')) {
266 print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
267} else {
268 if (!getDolGlobalString('AGENDA_REMINDER_SMS')) {
269 print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_SMS&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
270 } else {
271 print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_SMS&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
272 }
273}
274print '</td></tr>'."\n";
275
276
277// AGENDA DEFAULT REMINDER EVENT TYPE
278if (getDolGlobalString('AGENDA_REMINDER_BROWSER') || getDolGlobalString('AGENDA_REMINDER_EMAIL') || getDolGlobalString('AGENDA_REMINDER_SMS')) {
279 print '<tr class="oddeven">'."\n";
280 print '<td>';
281 print $langs->trans('AGENDA_DEFAULT_REMINDER_EVENT_TYPES', $langs->transnoentities("Module2300Name"));
282 print '<br><span class="opacitymedium">'.$langs->trans("AGENDA_DEFAULT_REMINDER_EVENT_TYPES_NOTE", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
283 print '</td>'."\n";
284 print '<td class="center">&nbsp;</td>'."\n";
285 print '<td class="right nowraponall">'."\n";
286 if (!isModEnabled('cron')) {
287 print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
288 } else {
289 if (GETPOSTISSET('AGENDA_DEFAULT_REMINDER_EVENT_TYPES')) {
290 $selected = GETPOST('AGENDA_DEFAULT_REMINDER_EVENT_TYPES');
291 } else {
292 $selected = json_decode(getDolGlobalString('AGENDA_DEFAULT_REMINDER_EVENT_TYPES', ''));
293 }
294 // Assuming $selected is correct type: @phan-suppress-next-line PhanTypeMismatchArgumentNullable
295 print $formactions->select_type_actions($selected, "AGENDA_DEFAULT_REMINDER_EVENT_TYPES", "systemauto", 0, -1, 1, 1);
296 }
297 print '</td></tr>'."\n";
298}
299
300// AGENDA DEFAULT REMINDER OFFSET
301if (getDolGlobalString('AGENDA_REMINDER_BROWSER') || getDolGlobalString('AGENDA_REMINDER_EMAIL') || getDolGlobalString('AGENDA_REMINDER_SMS')) {
302 print '<tr class="oddeven">'."\n";
303 print '<td>';
304 print $langs->trans('AGENDA_DEFAULT_REMINDER_OFFSET', $langs->transnoentities("Module2300Name"));
305 print '</td>'."\n";
306 print '<td class="center">&nbsp;</td>'."\n";
307 print '<td class="right nowraponall minwidth75imp">'."\n";
308 if (!isModEnabled('cron')) {
309 print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
310 } else {
311 print '<input class="width50" type="number" name="AGENDA_DEFAULT_REMINDER_OFFSET" value="'.(GETPOSTISSET('AGENDA_DEFAULT_REMINDER_OFFSET') ? GETPOSTINT('AGENDA_DEFAULT_REMINDER_OFFSET') : getDolGlobalInt('AGENDA_DEFAULT_REMINDER_OFFSET', 30)).'"> ';
312 $selected = (GETPOSTISSET('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT_type_duration') ? GETPOST('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT_type_duration') : getDolGlobalString('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT', 'i'));
313 print $form->selectTypeDuration('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT_', $selected, array('y', 'm', 's'), 'width150 maxwidth150');
314 }
315 print '</td></tr>'."\n";
316}
317
318// AGENDA DEFAULT EMAIL MODEL
319if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
320 print '<tr class="oddeven">'."\n";
321 print '<td>';
322 print $langs->trans('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL', $langs->transnoentities("Module2300Name"));
323 print '</td>'."\n";
324 print '<td class="center">&nbsp;</td>'."\n";
325 print '<td class="right nowraponall">'."\n";
326 if (!isModEnabled('cron')) {
327 print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
328 } else {
329 $selected = (GETPOSTISSET('AGENDA_DEFAULT_REMINDER_EMAIL_MODELmodel_mail') ? GETPOST('AGENDA_DEFAULT_REMINDER_EMAIL_MODELmodel_mail') : getDolGlobalInt('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL', 0));
330 print $form->selectModelMail('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL', 'actioncomm_send', 1, 1, $selected, 'minwidth150 width300 flat onrightofpage');
331 }
332 print '</td></tr>'."\n";
333}
334
335print '</table>';
336
337print dol_get_fiche_end();
338
339print '<div class="center">';
340print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
341print '</div>';
342
343print '</form>';
344
345print "<br>";
346
347// End of page
348llxFooter();
349$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
agenda_prepare_head()
Prepare array with list of tabs.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage predefined suppliers products.
Cron Job class.
Class to manage building of HTML components.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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_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.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.