dolibarr 21.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 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
31require_once DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php';
32
33if (!$user->admin) {
35}
36
37// Load translation files required by the page
38$langs->loadLangs(array("admin", "other", "agenda"));
39
40$action = GETPOST('action', 'aZ09');
41$value = GETPOST('value', 'alpha');
42$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
43
44$param = GETPOST('param', 'alpha');
45$cancel = GETPOST('cancel', 'alpha');
46$scandir = GETPOST('scandir', 'alpha');
47$type = 'action';
48
49$form = new Form($db);
50
51/*
52 * Actions
53 */
54
55include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
56
57if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
58 $code = $reg[1];
59 $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
60 if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
61 header("Location: ".$_SERVER["PHP_SELF"]);
62 exit;
63 } else {
64 dol_print_error($db);
65 }
66}
67
68if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
69 $code = $reg[1];
70 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
71 header("Location: ".$_SERVER["PHP_SELF"]);
72 exit;
73 } else {
74 dol_print_error($db);
75 }
76}
77if ($action == 'set') {
78 dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity);
79 dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', GETPOST('AGENDA_DEFAULT_FILTER_TYPE'), 'chaine', 0, '', $conf->entity);
80 dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
81 dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
82 dolibarr_set_const($db, 'AGENDA_DEFAULT_REMINDER_OFFSET', GETPOSTINT('AGENDA_DEFAULT_REMINDER_OFFSET'), 'chaine', 0, '', $conf->entity);
83 dolibarr_set_const($db, 'AGENDA_DEFAULT_REMINDER_OFFSET_UNIT', GETPOST('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT_type_duration'), 'chaine', 0, '', $conf->entity);
84 dolibarr_set_const($db, 'AGENDA_DEFAULT_REMINDER_EMAIL_MODEL', GETPOSTINT('AGENDA_DEFAULT_REMINDER_EMAIL_MODELmodel_mail'), 'chaine', 0, '', $conf->entity);
85 dolibarr_set_const($db, 'AGENDA_DEFAULT_REMINDER_EVENT_TYPES', json_encode(GETPOST('AGENDA_DEFAULT_REMINDER_EVENT_TYPES')), 'chaine', 0, '', $conf->entity);
86} elseif ($action == 'specimen') { // For orders
87 $modele = GETPOST('module', 'alpha');
88
89 $commande = new CommandeFournisseur($db);
90 $commande->initAsSpecimen();
91 $specimenthirdparty = new Societe($db);
92 $specimenthirdparty->initAsSpecimen();
93 $commande->thirdparty = $specimenthirdparty;
94
95 // Search template files
96 $file = '';
97 $classname = '';
98 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
99 foreach ($dirmodels as $reldir) {
100 $file = dol_buildpath($reldir."core/modules/action/doc/pdf_".$modele.".modules.php", 0);
101 if (file_exists($file)) {
102 $classname = "pdf_".$modele;
103 break;
104 }
105 }
106
107 if ($classname !== '') {
108 require_once $file;
109
110 $module = new $classname($db, $commande);
111 '@phan-var-force pdf_standard_actions $module';
112
113 if ($module->write_file($commande, $langs) > 0) {
114 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
115 return;
116 } else {
117 setEventMessages($module->error, $module->errors, 'errors');
118 dol_syslog($module->error, LOG_ERR);
119 }
120 } else {
121 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
122 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
123 }
124} elseif ($action == 'setmodel') {
125 // Activate a model
126 //print "sssd".$value;
127 $ret = addDocumentModel($value, $type, $label, $scandir);
128} elseif ($action == 'del') {
129 $ret = delDocumentModel($value, $type);
130 if ($ret > 0) {
131 if ($conf->global->ACTION_EVENT_ADDON_PDF == "$value") {
132 dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF', $conf->entity);
133 }
134 }
135} elseif ($action == 'setdoc') {
136 // Set default model
137 if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
138 // The constant that has been read in front of the new set
139 // is therefore passed through a variable to have a coherent display
140 $conf->global->ACTION_EVENT_ADDON_PDF = $value;
141 }
142
143 // On active le modele
144 $ret = delDocumentModel($value, $type);
145 if ($ret > 0) {
146 $ret = addDocumentModel($value, $type, $label, $scandir);
147 }
148}
149
150
156$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
157llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-agenda_reminder');
158
159$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
160print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
161
162
163$head = agenda_prepare_head();
164
165print dol_get_fiche_head($head, 'reminders', $langs->trans("Agenda"), -1, 'action');
166
167print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda">';
168print '<input type="hidden" name="token" value="'.newToken().'">';
169print '<input type="hidden" name="action" value="set">';
170
171print '<table class="noborder allwidth">'."\n";
172print '<tr class="liste_titre">'."\n";
173print '<td>'.$langs->trans("Parameters").'</td>'."\n";
174print '<td class="center">&nbsp;</td>'."\n";
175print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
176print '</tr>'."\n";
177
178// AGENDA REMINDER BROWSER
179print '<tr class="oddeven">'."\n";
180print '<td>';
181print $langs->trans('AGENDA_REMINDER_BROWSER').'<br>';
182print '<span class="opacitymedium">'.$langs->trans('AGENDA_REMINDER_BROWSERHelp').'</span>';
183print '</td>'."\n";
184print '<td class="center">&nbsp;</td>'."\n";
185print '<td class="right nowraponall">'."\n";
186
187if (!getDolGlobalString('AGENDA_REMINDER_BROWSER')) {
188 /*if (!isHTTPS()) {
189 $langs->load("errors");
190 print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' ';
191 }*/
192 print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
193 print '</td></tr>'."\n";
194} else {
195 /*if (!isHTTPS()) {
196 $langs->load("errors");
197 print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' ';
198 }*/
199 print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
200 print '</td></tr>'."\n";
201
202 /* This feature need to use the old method AGENDA_NOTIFICATION_METHOD = 'jsnotification' that is broken on a lot of browser setup
203 print '<tr class="oddeven">'."\n";
204 print '<td>'.$langs->trans('AGENDA_REMINDER_BROWSER_SOUND').'</td>'."\n";
205 print '<td class="center">&nbsp;</td>'."\n";
206 print '<td class="right">'."\n";
207
208 if (!getDolGlobalString('AGENDA_REMINDER_BROWSER_SOUND')) {
209 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_BROWSER_SOUND&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
210 } else {
211 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_BROWSER_SOUND&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
212 }
213
214 print '</td></tr>'."\n";
215 */
216}
217
218$job = new Cronjob($db);
219$job->fetch(0, 'ActionComm', 'sendEmailsReminder');
220
221// AGENDA REMINDER EMAIL
222print '<tr class="oddeven">'."\n";
223print '<td>';
224print $langs->trans('AGENDA_REMINDER_EMAIL', $langs->transnoentities("Module2300Name"));
225if (isModEnabled('cron')) {
226 if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
227 if ($job->id > 0) {
228 if ($job->status == $job::STATUS_ENABLED) {
229 print '<br><span class="opacitymedium">'.$langs->trans("AGENDA_REMINDER_EMAIL_NOTE", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
230 }
231 }
232 }
233}
234print '</td>'."\n";
235print '<td class="center">&nbsp;</td>'."\n";
236print '<td class="right nowraponall">'."\n";
237
238if (!isModEnabled('cron')) {
239 print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
240} else {
241 if (!getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
242 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
243 } else {
244 // Get the max frequency of reminder
245 if ($job->id > 0) {
246 if ($job->status != $job::STATUS_ENABLED) {
247 $langs->load("cron");
248 print '<span class="opacitymedium warning">'.$langs->trans("JobXMustBeEnabled", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
249 } else {
250 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
251 }
252 } else {
253 $langs->load("cron");
254 print '<span class="opacitymedium warning">'.$langs->trans("JobNotFound", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
255 }
256 }
257}
258
259// AGENDA DEFAULT REMINDER EVENT TYPE
260if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
261 print '<tr class="oddeven">'."\n";
262 print '<td>';
263 print $langs->trans('AGENDA_DEFAULT_REMINDER_EVENT_TYPES', $langs->transnoentities("Module2300Name"));
264 print '<br><span class="opacitymedium">'.$langs->trans("AGENDA_DEFAULT_REMINDER_EVENT_TYPES_NOTE", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
265 print '</td>'."\n";
266 print '<td class="center">&nbsp;</td>'."\n";
267 print '<td class="right nowraponall">'."\n";
268 if (!isModEnabled('cron')) {
269 print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
270 } else {
271 if (GETPOSTISSET('AGENDA_DEFAULT_REMINDER_EVENT_TYPES')) {
272 $selected = GETPOST('AGENDA_DEFAULT_REMINDER_EVENT_TYPES');
273 } else {
274 $selected = json_decode(getDolGlobalString('AGENDA_DEFAULT_REMINDER_EVENT_TYPES', ''));
275 }
276 print $formactions->select_type_actions($selected, "AGENDA_DEFAULT_REMINDER_EVENT_TYPES", "systemauto", 0, -1, 1, 1);
277 print '</td></tr>';
278 }
279}
280
281// AGENDA DEFAULT REMINDER OFFSET
282if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
283 print '<tr class="oddeven">'."\n";
284 print '<td>';
285 print $langs->trans('AGENDA_DEFAULT_REMINDER_OFFSET', $langs->transnoentities("Module2300Name"));
286 print '</td>'."\n";
287 print '<td class="center">&nbsp;</td>'."\n";
288 print '<td class="right nowraponall">'."\n";
289 if (!isModEnabled('cron')) {
290 print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
291 } else {
292 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)).'"> ';
293 $selected = (GETPOSTISSET('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT_type_duration') ? GETPOST('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT_type_duration') : getDolGlobalString('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT', 'i'));
294 print $form->selectTypeDuration('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT_', $selected, array('y', 'm'));
295 }
296}
297
298// AGENDA DEFAULT EMAIL MODEL
299if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
300 print '<tr class="oddeven">'."\n";
301 print '<td>';
302 print $langs->trans('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL', $langs->transnoentities("Module2300Name"));
303 print '</td>'."\n";
304 print '<td class="center">&nbsp;</td>'."\n";
305 print '<td class="right nowraponall">'."\n";
306 if (!isModEnabled('cron')) {
307 print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
308 } else {
309 $selected = (GETPOSTISSET('AGENDA_DEFAULT_REMINDER_EMAIL_MODELmodel_mail') ? GETPOST('AGENDA_DEFAULT_REMINDER_EMAIL_MODELmodel_mail') : getDolGlobalInt('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL', 0));
310 print $form->selectModelMail('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL', 'actioncomm_send', 1, 1, $selected);
311 }
312}
313print '</td></tr>'."\n";
314
315print '</table>';
316
317print dol_get_fiche_end();
318
319print '<div class="center">';
320print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
321print '</div>';
322
323print '</form>';
324
325print "<br>";
326
327// End of page
328llxFooter();
329$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.
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:70
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...)
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.