agenda_extsites.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/admin/agenda_extsites.php
  22. * \ingroup agenda
  23. * \brief Page to setup external calendars for agenda module
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  32. if (!$user->admin) accessforbidden();
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('agenda', 'admin', 'other'));
  35. $def = array();
  36. $actiontest = GETPOST('test', 'alpha');
  37. $actionsave = GETPOST('save', 'alpha');
  38. if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB = 5;
  39. $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
  40. // List of available colors
  41. $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
  42. /*
  43. * Actions
  44. */
  45. if ($actionsave)
  46. {
  47. $db->begin();
  48. $disableext = GETPOST('AGENDA_DISABLE_EXT', 'alpha');
  49. $res = dolibarr_set_const($db, 'AGENDA_DISABLE_EXT', $disableext, 'chaine', 0, '', $conf->entity);
  50. $i = 1; $errorsaved = 0;
  51. $error = 0;
  52. // Save agendas
  53. while ($i <= $MAXAGENDA)
  54. {
  55. $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha'));
  56. $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha'));
  57. $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha'));
  58. $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha'));
  59. if ($color == '-1') $color = '';
  60. $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha'));
  61. if (!empty($src) && !dol_is_url($src))
  62. {
  63. setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
  64. $error++;
  65. $errorsaved++;
  66. break;
  67. }
  68. //print '-name='.$name.'-color='.$color;
  69. $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
  70. if (!$res > 0) $error++;
  71. $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
  72. if (!$res > 0) $error++;
  73. $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
  74. if (!$res > 0) $error++;
  75. $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
  76. if (!$res > 0) $error++;
  77. $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
  78. if (!$res > 0) $error++;
  79. $i++;
  80. }
  81. // Save nb of agenda
  82. if (!$error)
  83. {
  84. $res = dolibarr_set_const($db, 'AGENDA_EXT_NB', trim(GETPOST('AGENDA_EXT_NB', 'int')), 'chaine', 0, '', $conf->entity);
  85. if (!$res > 0) $error++;
  86. if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB = 5;
  87. $MAXAGENDA = empty($conf->global->AGENDA_EXT_NB) ? 5 : $conf->global->AGENDA_EXT_NB;
  88. }
  89. if (!$error)
  90. {
  91. $db->commit();
  92. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  93. }
  94. else
  95. {
  96. $db->rollback();
  97. if (empty($errorsaved)) setEventMessages($langs->trans("Error"), null, 'errors');
  98. }
  99. }
  100. /*
  101. * View
  102. */
  103. $form = new Form($db);
  104. $formadmin = new FormAdmin($db);
  105. $formother = new FormOther($db);
  106. $arrayofjs = array();
  107. $arrayofcss = array();
  108. $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
  109. llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss);
  110. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  111. print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
  112. print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  113. print '<input type="hidden" name="token" value="'.newToken().'">';
  114. print '<input type="hidden" name="action" value="save">';
  115. $head = agenda_prepare_head();
  116. dol_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
  117. print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
  118. print "<br>\n";
  119. $selectedvalue = $conf->global->AGENDA_DISABLE_EXT;
  120. if ($selectedvalue == 1) $selectedvalue = 0; else $selectedvalue = 1;
  121. print "<table class=\"noborder\" width=\"100%\">";
  122. print "<tr class=\"liste_titre\">";
  123. print '<td>'.$langs->trans("Parameter")."</td>";
  124. print '<td class="center">'.$langs->trans("Value")."</td>";
  125. print "</tr>";
  126. // Show external agenda
  127. print '<tr class="oddeven">';
  128. print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
  129. print '<td class="center">';
  130. if ($conf->use_javascript_ajax)
  131. {
  132. print ajax_constantonoff('AGENDA_DISABLE_EXT', array('enabled'=>array(0=>'.hideifnotset')), null, 1);
  133. }
  134. else
  135. {
  136. if (empty($conf->global->AGENDA_DISABLE_EXT))
  137. {
  138. print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  139. }
  140. else
  141. {
  142. print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  143. }
  144. }
  145. print "</td>";
  146. print "</tr>";
  147. // Nb of agenda
  148. print '<tr class="oddeven">';
  149. print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
  150. print '<td class="center">';
  151. print '<input class="flat hideifnotset" type="text" size="2" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="'.$conf->global->AGENDA_EXT_NB.'">';
  152. print "</td>";
  153. print "</tr>";
  154. print "</table>";
  155. print "<br>";
  156. print "<table class=\"noborder\" width=\"100%\">";
  157. print "<tr class=\"liste_titre\">";
  158. print "<td>".$langs->trans("Parameter")."</td>";
  159. print "<td>".$langs->trans("Name")."</td>";
  160. print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
  161. print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
  162. print '<td class="right">'.$langs->trans("Color").'</td>';
  163. print "</tr>";
  164. $i = 1;
  165. while ($i <= $MAXAGENDA)
  166. {
  167. $key = $i;
  168. $name = 'AGENDA_EXT_NAME'.$key;
  169. $src = 'AGENDA_EXT_SRC'.$key;
  170. $offsettz = 'AGENDA_EXT_OFFSETTZ'.$key;
  171. $color = 'AGENDA_EXT_COLOR'.$key;
  172. $enabled = 'AGENDA_EXT_ENABLED'.$key;
  173. print '<tr class="oddeven">';
  174. // Nb
  175. print '<td width="180" class="nowrap">'.$langs->trans("AgendaExtNb", $key)."</td>";
  176. // Name
  177. 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') : $conf->global->$name).'" size="28"></td>';
  178. // URL
  179. 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') : $conf->global->$src).'" size="60"></td>';
  180. // Offset TZ
  181. print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ'.$key.'" value="'.(GETPOST('AGENDA_EXT_OFFSETTZ'.$key) ?GETPOST('AGENDA_EXT_OFFSETTZ'.$key) : $conf->global->$offsettz).'" size="2"></td>';
  182. // Color (Possible colors are limited by Google)
  183. print '<td class="nowrap right">';
  184. //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
  185. print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR".$key) ?GETPOST("AGENDA_EXT_COLOR".$key) : $conf->global->$color), "AGENDA_EXT_COLOR".$key, 'extsitesconfig', 1, '', 'hideifnotset');
  186. print '</td>';
  187. print "</tr>";
  188. $i++;
  189. }
  190. print '</table>';
  191. dol_fiche_end();
  192. print '<div class="center">';
  193. print '<input type="submit" id="save" name="save" class="button hideifnotset" value="'.$langs->trans("Save").'">';
  194. print '</div>';
  195. print "</form>\n";
  196. // End of page
  197. llxFooter();
  198. $db->close();