agenda_extsites.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?php
  2. /* Copyright (C) 2008-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011-2015 Juanjo Menent <jmenent@2byte.es>
  4. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  5. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  6. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/admin/agenda_extsites.php
  23. * \ingroup agenda
  24. * \brief Page to setup external calendars for agenda module
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  34. if (!$user->admin) {
  35. accessforbidden();
  36. }
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('agenda', 'admin', 'other'));
  39. $def = array();
  40. $action = GETPOST('action', 'alpha');
  41. if (!getDolGlobalString('AGENDA_EXT_NB')) {
  42. $conf->global->AGENDA_EXT_NB = 5;
  43. }
  44. $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
  45. // List of available colors
  46. $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
  47. /*
  48. * Actions
  49. */
  50. $error = 0;
  51. $errors = array();
  52. if (preg_match('/set_(.*)/', $action, $reg)) {
  53. $db->begin();
  54. $code = $reg[1];
  55. $value = (GETPOST($code) ? GETPOST($code) : 1);
  56. $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
  57. if (!($res > 0)) {
  58. $error++;
  59. $errors[] = $db->lasterror();
  60. }
  61. if ($error) {
  62. $db->rollback();
  63. setEventMessages('', $errors, 'errors');
  64. } else {
  65. $db->commit();
  66. setEventMessage($langs->trans('SetupSaved'));
  67. header('Location: ' . $_SERVER["PHP_SELF"]);
  68. exit();
  69. }
  70. } elseif (preg_match('/del_(.*)/', $action, $reg)) {
  71. $db->begin();
  72. $code = $reg[1];
  73. $res = dolibarr_del_const($db, $code, $conf->entity);
  74. if (!($res > 0)) {
  75. $error++;
  76. $errors[] = $db->lasterror();
  77. }
  78. if ($error) {
  79. $db->rollback();
  80. setEventMessages('', $errors, 'errors');
  81. } else {
  82. $db->commit();
  83. setEventMessage($langs->trans('SetupSaved'));
  84. header('Location: ' . $_SERVER["PHP_SELF"]);
  85. exit();
  86. }
  87. } elseif ($action == 'save') {
  88. $db->begin();
  89. $disableext = GETPOST('AGENDA_DISABLE_EXT', 'alpha');
  90. $res = dolibarr_set_const($db, 'AGENDA_DISABLE_EXT', $disableext, 'chaine', 0, '', $conf->entity);
  91. $i = 1;
  92. $errorsaved = 0;
  93. // Save agendas
  94. while ($i <= $MAXAGENDA) {
  95. $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha'));
  96. $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha'));
  97. $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha'));
  98. $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha'));
  99. if ($color == '-1') {
  100. $color = '';
  101. }
  102. $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha'));
  103. if (!empty($src) && !dol_is_url($src)) {
  104. setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
  105. $error++;
  106. $errorsaved++;
  107. break;
  108. }
  109. //print '-name='.$name.'-color='.$color;
  110. $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
  111. if (!($res > 0)) {
  112. $error++;
  113. }
  114. $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
  115. if (!($res > 0)) {
  116. $error++;
  117. }
  118. $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
  119. if (!($res > 0)) {
  120. $error++;
  121. }
  122. $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
  123. if (!($res > 0)) {
  124. $error++;
  125. }
  126. $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
  127. if (!($res > 0)) {
  128. $error++;
  129. }
  130. $i++;
  131. }
  132. // Save nb of agenda
  133. if (!$error) {
  134. $res = dolibarr_set_const($db, 'AGENDA_EXT_NB', trim(GETPOST('AGENDA_EXT_NB', 'int')), 'chaine', 0, '', $conf->entity);
  135. if (!($res > 0)) {
  136. $error++;
  137. }
  138. if (!getDolGlobalString('AGENDA_EXT_NB')) {
  139. $conf->global->AGENDA_EXT_NB = 5;
  140. }
  141. $MAXAGENDA = !getDolGlobalString('AGENDA_EXT_NB') ? 5 : $conf->global->AGENDA_EXT_NB;
  142. }
  143. if (!$error) {
  144. $db->commit();
  145. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  146. } else {
  147. $db->rollback();
  148. if (empty($errorsaved)) {
  149. setEventMessages($langs->trans("Error"), null, 'errors');
  150. }
  151. }
  152. }
  153. /*
  154. * View
  155. */
  156. $form = new Form($db);
  157. $formadmin = new FormAdmin($db);
  158. $formother = new FormOther($db);
  159. $arrayofjs = array();
  160. $arrayofcss = array();
  161. $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
  162. llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss);
  163. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  164. print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
  165. print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  166. print '<input type="hidden" name="token" value="'.newToken().'">';
  167. print '<input type="hidden" name="action" value="save">';
  168. $head = agenda_prepare_head();
  169. print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
  170. print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
  171. print "<br>\n";
  172. $selectedvalue = getDolGlobalInt('AGENDA_DISABLE_EXT');
  173. if ($selectedvalue==1) {
  174. $selectedvalue=0;
  175. } else {
  176. $selectedvalue=1;
  177. }
  178. print "<table class=\"noborder\" width=\"100%\">";
  179. print "<tr class=\"liste_titre\">";
  180. print '<td>'.$langs->trans("Parameter")."</td>";
  181. print '<td class="center">'.$langs->trans("Value")."</td>";
  182. print "</tr>";
  183. // Show external agenda
  184. print '<tr class="oddeven">';
  185. print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
  186. print '<td class="center">';
  187. if ($conf->use_javascript_ajax) {
  188. print ajax_constantonoff('AGENDA_DISABLE_EXT', array('enabled'=>array(0=>'.hideifnotset')), null, 1);
  189. } else {
  190. if (!getDolGlobalString('AGENDA_DISABLE_EXT')) {
  191. print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  192. } else {
  193. print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  194. }
  195. }
  196. print "</td>";
  197. print "</tr>";
  198. // Nb of agenda
  199. print '<tr class="oddeven">';
  200. print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
  201. print '<td class="center">';
  202. print '<input class="flat hideifnotset" type="text" size="2" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="' . getDolGlobalString('AGENDA_EXT_NB').'">';
  203. print "</td>";
  204. print "</tr>";
  205. print "</table>";
  206. print "<br>";
  207. print "<table class=\"noborder\" width=\"100%\">";
  208. print "<tr class=\"liste_titre\">";
  209. print "<td>".$langs->trans("Parameter")."</td>";
  210. print "<td>".$langs->trans("Name")."</td>";
  211. print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
  212. print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
  213. print '<td class="right">'.$langs->trans("Color").'</td>';
  214. print '<td class="right">'.$langs->trans("ActiveByDefault").'</td>';
  215. print "</tr>";
  216. $i = 1;
  217. while ($i <= $MAXAGENDA) {
  218. $key = $i;
  219. $name = 'AGENDA_EXT_NAME' . $key;
  220. $src = 'AGENDA_EXT_SRC' . $key;
  221. $offsettz = 'AGENDA_EXT_OFFSETTZ' . $key;
  222. $color = 'AGENDA_EXT_COLOR' . $key;
  223. $enabled = 'AGENDA_EXT_ENABLED' . $key;
  224. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key;
  225. print '<tr class="oddeven">';
  226. // Nb
  227. print '<td width="180" class="nowrap">' . $langs->trans("AgendaExtNb", $key) . "</td>";
  228. // Name
  229. print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_NAME' . $key . '" value="' . (GETPOST('AGENDA_EXT_NAME' . $key) ? GETPOST('AGENDA_EXT_NAME' . $key, 'alpha') : getDolGlobalString($name)) . '" size="28"></td>';
  230. // URL
  231. print '<td><input type="url" class="flat hideifnotset" name="AGENDA_EXT_SRC' . $key . '" value="' . (GETPOST('AGENDA_EXT_SRC' . $key) ? GETPOST('AGENDA_EXT_SRC' . $key, 'alpha') : getDolGlobalString($src)) . '" size="60"></td>';
  232. // Offset TZ
  233. print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ' . $key . '" value="' . (GETPOST('AGENDA_EXT_OFFSETTZ' . $key) ? GETPOST('AGENDA_EXT_OFFSETTZ' . $key) : getDolGlobalString($offsettz)) . '" size="2"></td>';
  234. // Color (Possible colors are limited by Google)
  235. print '<td class="nowrap right">';
  236. print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, 'extsitesconfig', 1, '', 'hideifnotset');
  237. print '</td>';
  238. // Calendar active by default
  239. print '<td class="nowrap right">';
  240. if (!empty($conf->use_javascript_ajax)) {
  241. print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key);
  242. } else {
  243. if (getDolGlobalString($default)) {
  244. print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
  245. } else {
  246. print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
  247. }
  248. }
  249. print '</td>';
  250. print "</tr>";
  251. $i++;
  252. }
  253. print '</table>';
  254. print dol_get_fiche_end();
  255. print '<div class="center">';
  256. print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
  257. print '</div>';
  258. print "</form>\n";
  259. // End of page
  260. llxFooter();
  261. $db->close();