agenda_reminder.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 = ''; $classname = ''; $filefound = 0;
  75. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  76. foreach ($dirmodels as $reldir) {
  77. $file = dol_buildpath($reldir."core/modules/action/doc/pdf_".$modele.".modules.php", 0);
  78. if (file_exists($file)) {
  79. $filefound = 1;
  80. $classname = "pdf_".$modele;
  81. break;
  82. }
  83. }
  84. if ($filefound) {
  85. require_once $file;
  86. $module = new $classname($db, $commande);
  87. if ($module->write_file($commande, $langs) > 0) {
  88. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
  89. return;
  90. } else {
  91. setEventMessages($module->error, $module->errors, 'errors');
  92. dol_syslog($module->error, LOG_ERR);
  93. }
  94. } else {
  95. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  96. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  97. }
  98. } elseif ($action == 'setmodel') {
  99. // Activate a model
  100. //print "sssd".$value;
  101. $ret = addDocumentModel($value, $type, $label, $scandir);
  102. } elseif ($action == 'del') {
  103. $ret = delDocumentModel($value, $type);
  104. if ($ret > 0) {
  105. if ($conf->global->ACTION_EVENT_ADDON_PDF == "$value") {
  106. dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF', $conf->entity);
  107. }
  108. }
  109. } elseif ($action == 'setdoc') {
  110. // Set default model
  111. if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  112. // The constant that has been read in front of the new set
  113. // is therefore passed through a variable to have a coherent display
  114. $conf->global->ACTION_EVENT_ADDON_PDF = $value;
  115. }
  116. // On active le modele
  117. $ret = delDocumentModel($value, $type);
  118. if ($ret > 0) {
  119. $ret = addDocumentModel($value, $type, $label, $scandir);
  120. }
  121. }
  122. /**
  123. * View
  124. */
  125. $formactions = new FormActions($db);
  126. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  127. llxHeader();
  128. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  129. print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
  130. $head = agenda_prepare_head();
  131. print dol_get_fiche_head($head, 'reminders', $langs->trans("Agenda"), -1, 'action');
  132. print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda">';
  133. print '<input type="hidden" name="token" value="'.newToken().'">';
  134. print '<input type="hidden" name="action" value="set">';
  135. print '<table class="noborder allwidth">'."\n";
  136. print '<tr class="liste_titre">'."\n";
  137. print '<td>'.$langs->trans("Parameters").'</td>'."\n";
  138. print '<td class="center">&nbsp;</td>'."\n";
  139. print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
  140. print '</tr>'."\n";
  141. // AGENDA REMINDER BROWSER
  142. print '<tr class="oddeven">'."\n";
  143. print '<td>'.$langs->trans('AGENDA_REMINDER_BROWSER').'</td>'."\n";
  144. print '<td class="center">&nbsp;</td>'."\n";
  145. print '<td class="right nowraponall">'."\n";
  146. if (empty($conf->global->AGENDA_REMINDER_BROWSER)) {
  147. if (!isHTTPS()) {
  148. $langs->load("errors");
  149. print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' ';
  150. }
  151. print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
  152. print '</td></tr>'."\n";
  153. } else {
  154. if (!isHTTPS()) {
  155. $langs->load("errors");
  156. print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' ';
  157. }
  158. print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_BROWSER&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
  159. print '</td></tr>'."\n";
  160. print '<tr class="oddeven">'."\n";
  161. print '<td>'.$langs->trans('AGENDA_REMINDER_BROWSER_SOUND').'</td>'."\n";
  162. print '<td class="center">&nbsp;</td>'."\n";
  163. print '<td class="right">'."\n";
  164. if (empty($conf->global->AGENDA_REMINDER_BROWSER_SOUND)) {
  165. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_BROWSER_SOUND&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
  166. } else {
  167. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_BROWSER_SOUND&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
  168. }
  169. print '</td></tr>'."\n";
  170. }
  171. $job = new Cronjob($db);
  172. $job->fetch(0, 'ActionComm', 'sendEmailsReminder');
  173. // AGENDA REMINDER EMAIL
  174. print '<tr class="oddeven">'."\n";
  175. print '<td>'.$langs->trans('AGENDA_REMINDER_EMAIL', $langs->transnoentities("Module2300Name"));
  176. if (isModEnabled('cron')) {
  177. if (!empty($conf->global->AGENDA_REMINDER_EMAIL)) {
  178. if ($job->id > 0) {
  179. if ($job->status == $job::STATUS_ENABLED) {
  180. print '<br><span class="opacitymedium">'.$langs->trans("AGENDA_REMINDER_EMAIL_NOTE", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
  181. }
  182. }
  183. }
  184. }
  185. print '</td>'."\n";
  186. print '<td class="center">&nbsp;</td>'."\n";
  187. print '<td class="right nowraponall">'."\n";
  188. if (!isModEnabled('cron')) {
  189. print '<span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).'</span>';
  190. } else {
  191. if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
  192. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
  193. } else {
  194. // Get the max frequency of reminder
  195. if ($job->id > 0) {
  196. if ($job->status != $job::STATUS_ENABLED) {
  197. $langs->load("cron");
  198. print '<span class="opacitymedium warning">'.$langs->trans("JobXMustBeEnabled", $langs->transnoentitiesnoconv("sendEmailsReminder")).'</span>';
  199. } else {
  200. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_REMINDER_EMAIL&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
  201. }
  202. }
  203. }
  204. }
  205. print '</td></tr>'."\n";
  206. print '</table>';
  207. print dol_get_fiche_end();
  208. //print '<div class="center"><input class="button button-save" type="submit" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></div>';
  209. print '</form>';
  210. print "<br>";
  211. // End of page
  212. llxFooter();
  213. $db->close();