agenda_reminder.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. /**
  18. * \file htdocs/admin/agenda_reminder.php
  19. * \ingroup agenda
  20. * \brief Page to setup agenda reminder options
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php';
  28. if (!$user->admin) {
  29. accessforbidden();
  30. }
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("admin", "other", "agenda"));
  33. $action = GETPOST('action', 'aZ09');
  34. $value = GETPOST('value', 'alpha');
  35. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  36. $param = GETPOST('param', 'alpha');
  37. $cancel = GETPOST('cancel', 'alpha');
  38. $scandir = GETPOST('scandir', 'alpha');
  39. $type = 'action';
  40. /*
  41. * Actions
  42. */
  43. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  44. if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
  45. $code = $reg[1];
  46. $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
  47. if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
  48. Header("Location: ".$_SERVER["PHP_SELF"]);
  49. exit;
  50. } else {
  51. dol_print_error($db);
  52. }
  53. }
  54. if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
  55. $code = $reg[1];
  56. if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
  57. Header("Location: ".$_SERVER["PHP_SELF"]);
  58. exit;
  59. } else {
  60. dol_print_error($db);
  61. }
  62. }
  63. if ($action == 'set') {
  64. dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity);
  65. dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', GETPOST('AGENDA_DEFAULT_FILTER_TYPE'), 'chaine', 0, '', $conf->entity);
  66. dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
  67. dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
  68. } elseif ($action == 'specimen') { // For orders
  69. $modele = GETPOST('module', 'alpha');
  70. $commande = new CommandeFournisseur($db);
  71. $commande->initAsSpecimen();
  72. $commande->thirdparty = $specimenthirdparty;
  73. // Search template files
  74. $file = '';
  75. $classname = '';
  76. $filefound = 0;
  77. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  78. foreach ($dirmodels as $reldir) {
  79. $file = dol_buildpath($reldir."core/modules/action/doc/pdf_".$modele.".modules.php", 0);
  80. if (file_exists($file)) {
  81. $filefound = 1;
  82. $classname = "pdf_".$modele;
  83. break;
  84. }
  85. }
  86. if ($filefound) {
  87. require_once $file;
  88. $module = new $classname($db, $commande);
  89. if ($module->write_file($commande, $langs) > 0) {
  90. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
  91. return;
  92. } else {
  93. setEventMessages($module->error, $module->errors, 'errors');
  94. dol_syslog($module->error, LOG_ERR);
  95. }
  96. } else {
  97. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  98. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  99. }
  100. } elseif ($action == 'setmodel') {
  101. // Activate a model
  102. //print "sssd".$value;
  103. $ret = addDocumentModel($value, $type, $label, $scandir);
  104. } elseif ($action == 'del') {
  105. $ret = delDocumentModel($value, $type);
  106. if ($ret > 0) {
  107. if ($conf->global->ACTION_EVENT_ADDON_PDF == "$value") {
  108. dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF', $conf->entity);
  109. }
  110. }
  111. } elseif ($action == 'setdoc') {
  112. // Set default model
  113. if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  114. // The constant that has been read in front of the new set
  115. // is therefore passed through a variable to have a coherent display
  116. $conf->global->ACTION_EVENT_ADDON_PDF = $value;
  117. }
  118. // On active le modele
  119. $ret = delDocumentModel($value, $type);
  120. if ($ret > 0) {
  121. $ret = addDocumentModel($value, $type, $label, $scandir);
  122. }
  123. }
  124. /**
  125. * View
  126. */
  127. $formactions = new FormActions($db);
  128. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  129. llxHeader();
  130. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  131. print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
  132. $head = agenda_prepare_head();
  133. print dol_get_fiche_head($head, 'reminders', $langs->trans("Agenda"), -1, 'action');
  134. print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda">';
  135. print '<input type="hidden" name="token" value="'.newToken().'">';
  136. print '<input type="hidden" name="action" value="set">';
  137. print '<table class="noborder allwidth">'."\n";
  138. print '<tr class="liste_titre">'."\n";
  139. print '<td>'.$langs->trans("Parameters").'</td>'."\n";
  140. print '<td class="center">&nbsp;</td>'."\n";
  141. print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
  142. print '</tr>'."\n";
  143. // AGENDA REMINDER BROWSER
  144. print '<tr class="oddeven">'."\n";
  145. print '<td>'.$langs->trans('AGENDA_REMINDER_BROWSER').'</td>'."\n";
  146. print '<td class="center">&nbsp;</td>'."\n";
  147. print '<td class="right nowraponall">'."\n";
  148. if (!getDolGlobalString('AGENDA_REMINDER_BROWSER')) {
  149. if (!isHTTPS()) {
  150. $langs->load("errors");
  151. print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' ';
  152. }
  153. print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
  154. print '</td></tr>'."\n";
  155. } else {
  156. if (!isHTTPS()) {
  157. $langs->load("errors");
  158. print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' ';
  159. }
  160. print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
  161. print '</td></tr>'."\n";
  162. print '<tr class="oddeven">'."\n";
  163. print '<td>'.$langs->trans('AGENDA_REMINDER_BROWSER_SOUND').'</td>'."\n";
  164. print '<td class="center">&nbsp;</td>'."\n";
  165. print '<td class="right">'."\n";
  166. if (!getDolGlobalString('AGENDA_REMINDER_BROWSER_SOUND')) {
  167. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_BROWSER_SOUND&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
  168. } else {
  169. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_BROWSER_SOUND&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
  170. }
  171. print '</td></tr>'."\n";
  172. }
  173. $job = new Cronjob($db);
  174. $job->fetch(0, 'ActionComm', 'sendEmailsReminder');
  175. // AGENDA REMINDER EMAIL
  176. print '<tr class="oddeven">'."\n";
  177. print '<td>'.$langs->trans('AGENDA_REMINDER_EMAIL', $langs->transnoentities("Module2300Name"));
  178. if (isModEnabled('cron')) {
  179. if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
  180. if ($job->id > 0) {
  181. if ($job->status == $job::STATUS_ENABLED) {
  182. print '<br><span class="opacitymedium">'.$langs->trans("AGENDA_REMINDER_EMAIL_NOTE", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
  183. }
  184. }
  185. }
  186. }
  187. print '</td>'."\n";
  188. print '<td class="center">&nbsp;</td>'."\n";
  189. print '<td class="right nowraponall">'."\n";
  190. if (!isModEnabled('cron')) {
  191. print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
  192. } else {
  193. if (!getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
  194. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
  195. } else {
  196. // Get the max frequency of reminder
  197. if ($job->id > 0) {
  198. if ($job->status != $job::STATUS_ENABLED) {
  199. $langs->load("cron");
  200. print '<span class="opacitymedium warning">'.$langs->trans("JobXMustBeEnabled", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
  201. } else {
  202. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
  203. }
  204. } else {
  205. $langs->load("cron");
  206. print '<span class="opacitymedium warning">'.$langs->trans("JobNotFound", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
  207. }
  208. }
  209. }
  210. print '</td></tr>'."\n";
  211. print '</table>';
  212. print dol_get_fiche_end();
  213. //print '<div class="center"><input class="button button-save" type="submit" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></div>';
  214. print '</form>';
  215. print "<br>";
  216. // End of page
  217. llxFooter();
  218. $db->close();