agenda_extsites.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 (empty($conf->global->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; $errorsaved = 0;
  92. // Save agendas
  93. while ($i <= $MAXAGENDA) {
  94. $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha'));
  95. $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha'));
  96. $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha'));
  97. $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha'));
  98. if ($color == '-1') {
  99. $color = '';
  100. }
  101. $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha'));
  102. if (!empty($src) && !dol_is_url($src)) {
  103. setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
  104. $error++;
  105. $errorsaved++;
  106. break;
  107. }
  108. //print '-name='.$name.'-color='.$color;
  109. $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
  110. if (!($res > 0)) {
  111. $error++;
  112. }
  113. $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
  114. if (!($res > 0)) {
  115. $error++;
  116. }
  117. $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
  118. if (!($res > 0)) {
  119. $error++;
  120. }
  121. $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
  122. if (!($res > 0)) {
  123. $error++;
  124. }
  125. $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
  126. if (!($res > 0)) {
  127. $error++;
  128. }
  129. $i++;
  130. }
  131. // Save nb of agenda
  132. if (!$error) {
  133. $res = dolibarr_set_const($db, 'AGENDA_EXT_NB', trim(GETPOST('AGENDA_EXT_NB', 'int')), 'chaine', 0, '', $conf->entity);
  134. if (!($res > 0)) {
  135. $error++;
  136. }
  137. if (empty($conf->global->AGENDA_EXT_NB)) {
  138. $conf->global->AGENDA_EXT_NB = 5;
  139. }
  140. $MAXAGENDA = empty($conf->global->AGENDA_EXT_NB) ? 5 : $conf->global->AGENDA_EXT_NB;
  141. }
  142. if (!$error) {
  143. $db->commit();
  144. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  145. } else {
  146. $db->rollback();
  147. if (empty($errorsaved)) {
  148. setEventMessages($langs->trans("Error"), null, 'errors');
  149. }
  150. }
  151. }
  152. /*
  153. * View
  154. */
  155. $form = new Form($db);
  156. $formadmin = new FormAdmin($db);
  157. $formother = new FormOther($db);
  158. $arrayofjs = array();
  159. $arrayofcss = array();
  160. $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
  161. llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss);
  162. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  163. print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
  164. print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  165. print '<input type="hidden" name="token" value="'.newToken().'">';
  166. print '<input type="hidden" name="action" value="save">';
  167. $head = agenda_prepare_head();
  168. print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
  169. print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
  170. print "<br>\n";
  171. $selectedvalue = getDolGlobalInt('AGENDA_DISABLE_EXT');
  172. if ($selectedvalue==1) $selectedvalue=0; else $selectedvalue=1;
  173. print "<table class=\"noborder\" width=\"100%\">";
  174. print "<tr class=\"liste_titre\">";
  175. print '<td>'.$langs->trans("Parameter")."</td>";
  176. print '<td class="center">'.$langs->trans("Value")."</td>";
  177. print "</tr>";
  178. // Show external agenda
  179. print '<tr class="oddeven">';
  180. print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
  181. print '<td class="center">';
  182. if ($conf->use_javascript_ajax) {
  183. print ajax_constantonoff('AGENDA_DISABLE_EXT', array('enabled'=>array(0=>'.hideifnotset')), null, 1);
  184. } else {
  185. if (empty($conf->global->AGENDA_DISABLE_EXT)) {
  186. print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  187. } else {
  188. print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  189. }
  190. }
  191. print "</td>";
  192. print "</tr>";
  193. // Nb of agenda
  194. print '<tr class="oddeven">';
  195. print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
  196. print '<td class="center">';
  197. print '<input class="flat hideifnotset" type="text" size="2" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="'.$conf->global->AGENDA_EXT_NB.'">';
  198. print "</td>";
  199. print "</tr>";
  200. print "</table>";
  201. print "<br>";
  202. print "<table class=\"noborder\" width=\"100%\">";
  203. print "<tr class=\"liste_titre\">";
  204. print "<td>".$langs->trans("Parameter")."</td>";
  205. print "<td>".$langs->trans("Name")."</td>";
  206. print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
  207. print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
  208. print '<td class="right">'.$langs->trans("Color").'</td>';
  209. print '<td class="right">'.$langs->trans("ActiveByDefault").'</td>';
  210. print "</tr>";
  211. $i = 1;
  212. while ($i <= $MAXAGENDA) {
  213. $key = $i;
  214. $name = 'AGENDA_EXT_NAME' . $key;
  215. $src = 'AGENDA_EXT_SRC' . $key;
  216. $offsettz = 'AGENDA_EXT_OFFSETTZ' . $key;
  217. $color = 'AGENDA_EXT_COLOR' . $key;
  218. $enabled = 'AGENDA_EXT_ENABLED' . $key;
  219. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key;
  220. print '<tr class="oddeven">';
  221. // Nb
  222. print '<td width="180" class="nowrap">' . $langs->trans("AgendaExtNb", $key) . "</td>";
  223. // Name
  224. 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>';
  225. // URL
  226. 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>';
  227. // Offset TZ
  228. 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>';
  229. // Color (Possible colors are limited by Google)
  230. print '<td class="nowrap right">';
  231. //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
  232. print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, 'extsitesconfig', 1, '', 'hideifnotset');
  233. print '</td>';
  234. // Calendar active by default
  235. print '<td class="nowrap right">';
  236. if (!empty($conf->use_javascript_ajax)) {
  237. print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key);
  238. } else {
  239. if (getDolGlobalString($default)) {
  240. print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
  241. } else {
  242. print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
  243. }
  244. }
  245. print '</td>';
  246. print "</tr>";
  247. $i++;
  248. }
  249. print '</table>';
  250. print dol_get_fiche_end();
  251. print '<div class="center">';
  252. print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
  253. print '</div>';
  254. print "</form>\n";
  255. // End of page
  256. llxFooter();
  257. $db->close();