dolibarr  16.0.5
agenda_reminder.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 require '../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php';
29 
30 if (!$user->admin) {
32 }
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("admin", "other", "agenda"));
36 
37 $action = GETPOST('action', 'aZ09');
38 $value = GETPOST('value', 'alpha');
39 $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
40 
41 $param = GETPOST('param', 'alpha');
42 $cancel = GETPOST('cancel', 'alpha');
43 $scandir = GETPOST('scandir', 'alpha');
44 $type = 'action';
45 
46 
47 /*
48  * Actions
49  */
50 
51 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
52 
53 if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
54  $code = $reg[1];
55  $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
56  if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
57  Header("Location: ".$_SERVER["PHP_SELF"]);
58  exit;
59  } else {
60  dol_print_error($db);
61  }
62 }
63 
64 if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
65  $code = $reg[1];
66  if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
67  Header("Location: ".$_SERVER["PHP_SELF"]);
68  exit;
69  } else {
70  dol_print_error($db);
71  }
72 }
73 if ($action == 'set') {
74  dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity);
75  dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', GETPOST('AGENDA_DEFAULT_FILTER_TYPE'), 'chaine', 0, '', $conf->entity);
76  dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
77  dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
78 } elseif ($action == 'specimen') { // For orders
79  $modele = GETPOST('module', 'alpha');
80 
81  $commande = new CommandeFournisseur($db);
82  $commande->initAsSpecimen();
83  $commande->thirdparty = $specimenthirdparty;
84 
85  // Search template files
86  $file = ''; $classname = ''; $filefound = 0;
87  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
88  foreach ($dirmodels as $reldir) {
89  $file = dol_buildpath($reldir."core/modules/action/doc/pdf_".$modele.".modules.php", 0);
90  if (file_exists($file)) {
91  $filefound = 1;
92  $classname = "pdf_".$modele;
93  break;
94  }
95  }
96 
97  if ($filefound) {
98  require_once $file;
99 
100  $module = new $classname($db, $commande);
101 
102  if ($module->write_file($commande, $langs) > 0) {
103  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
104  return;
105  } else {
106  setEventMessages($module->error, $module->errors, 'errors');
107  dol_syslog($module->error, LOG_ERR);
108  }
109  } else {
110  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
111  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
112  }
113 } elseif ($action == 'setmodel') {
114  // Activate a model
115  //print "sssd".$value;
116  $ret = addDocumentModel($value, $type, $label, $scandir);
117 } elseif ($action == 'del') {
118  $ret = delDocumentModel($value, $type);
119  if ($ret > 0) {
120  if ($conf->global->ACTION_EVENT_ADDON_PDF == "$value") {
121  dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF', $conf->entity);
122  }
123  }
124 } elseif ($action == 'setdoc') {
125  // Set default model
126  if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
127  // The constant that has been read in front of the new set
128  // is therefore passed through a variable to have a coherent display
129  $conf->global->ACTION_EVENT_ADDON_PDF = $value;
130  }
131 
132  // On active le modele
133  $ret = delDocumentModel($value, $type);
134  if ($ret > 0) {
135  $ret = addDocumentModel($value, $type, $label, $scandir);
136  }
137 }
138 
139 
145 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
146 llxHeader();
147 
148 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
149 print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
150 
151 
152 
153 $head = agenda_prepare_head();
154 
155 print dol_get_fiche_head($head, 'reminders', $langs->trans("Agenda"), -1, 'action');
156 
157 print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda">';
158 print '<input type="hidden" name="token" value="'.newToken().'">';
159 print '<input type="hidden" name="action" value="set">';
160 
161 print '<table class="noborder allwidth">'."\n";
162 print '<tr class="liste_titre">'."\n";
163 print '<td>'.$langs->trans("Parameters").'</td>'."\n";
164 print '<td class="center">&nbsp;</td>'."\n";
165 print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
166 print '</tr>'."\n";
167 
168 // AGENDA REMINDER BROWSER
169 print '<tr class="oddeven">'."\n";
170 print '<td>'.$langs->trans('AGENDA_REMINDER_BROWSER').'</td>'."\n";
171 print '<td class="center">&nbsp;</td>'."\n";
172 print '<td class="right nowraponall">'."\n";
173 
174 if (empty($conf->global->AGENDA_REMINDER_BROWSER)) {
175  if (!isHTTPS()) {
176  $langs->load("errors");
177  print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' ';
178  }
179  print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
180  print '</td></tr>'."\n";
181 } else {
182  if (!isHTTPS()) {
183  $langs->load("errors");
184  print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' ';
185  }
186  print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
187  print '</td></tr>'."\n";
188 
189  print '<tr class="oddeven">'."\n";
190  print '<td>'.$langs->trans('AGENDA_REMINDER_BROWSER_SOUND').'</td>'."\n";
191  print '<td class="center">&nbsp;</td>'."\n";
192  print '<td class="right">'."\n";
193 
194  if (empty($conf->global->AGENDA_REMINDER_BROWSER_SOUND)) {
195  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_BROWSER_SOUND&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
196  } else {
197  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_BROWSER_SOUND&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
198  }
199 
200  print '</td></tr>'."\n";
201 }
202 
203 $job = new Cronjob($db);
204 $job->fetch(0, 'ActionComm', 'sendEmailsReminder');
205 
206 // AGENDA REMINDER EMAIL
207 print '<tr class="oddeven">'."\n";
208 print '<td>'.$langs->trans('AGENDA_REMINDER_EMAIL', $langs->transnoentities("Module2300Name"));
209 if (!empty($conf->cron->enabled)) {
210  if (!empty($conf->global->AGENDA_REMINDER_EMAIL)) {
211  if ($job->id > 0) {
212  if ($job->status == $job::STATUS_ENABLED) {
213  print '<br><span class="opacitymedium">'.$langs->trans("AGENDA_REMINDER_EMAIL_NOTE", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
214  }
215  }
216  }
217 }
218 print '</td>'."\n";
219 print '<td class="center">&nbsp;</td>'."\n";
220 print '<td class="right nowraponall">'."\n";
221 
222 if (empty($conf->cron->enabled)) {
223  print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
224 } else {
225  if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
226  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
227  } else {
228  // Get the max frequency of reminder
229  if ($job->id > 0) {
230  if ($job->status != $job::STATUS_ENABLED) {
231  $langs->load("cron");
232  print '<span class="opacitymedium warning">'.$langs->trans("JobXMustBeEnabled", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
233  } else {
234  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
235  }
236  }
237  }
238 }
239 print '</td></tr>'."\n";
240 
241 print '</table>';
242 
243 print dol_get_fiche_end();
244 
245 //print '<div class="center"><input class="button button-save" type="submit" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></div>';
246 
247 print '</form>';
248 
249 print "<br>";
250 
251 // End of page
252 llxFooter();
253 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Cronjob
Cron Job class.
Definition: cronjob.class.php:31
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
agenda_prepare_head
agenda_prepare_head()
Prepare array with list of tabs.
Definition: agenda.lib.php:363
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
delDocumentModel
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1894
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
$formactions
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.
Definition: agenda_reminder.php:144
CommandeFournisseur
Class to manage predefined suppliers products.
Definition: fournisseur.commande.class.php:47
dolibarr_set_const
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).
Definition: admin.lib.php:627
addDocumentModel
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1863
isHTTPS
isHTTPS()
Return if we are using a HTTPS connexion Check HTTPS (no way to be modified by user but may be empty ...
Definition: functions.lib.php:3541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59