agenda_extsites.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 <http://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. $langs->load("agenda");
  34. $langs->load("admin");
  35. $langs->load("other");
  36. $def = array();
  37. $actiontest=GETPOST('test','alpha');
  38. $actionsave=GETPOST('save','alpha');
  39. if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB=5;
  40. $MAXAGENDA=$conf->global->AGENDA_EXT_NB;
  41. // List of aviable colors
  42. $colorlist=array('BECEDD','DDBECE','BFDDBE','F598B4','F68654','CBF654','A4A4A5');
  43. /*
  44. * Actions
  45. */
  46. if ($actionsave)
  47. {
  48. $db->begin();
  49. $disableext=GETPOST('AGENDA_DISABLE_EXT','alpha');
  50. $res=dolibarr_set_const($db,'AGENDA_DISABLE_EXT',$disableext,'chaine',0,'',$conf->entity);
  51. $i=1; $errorsaved=0;
  52. $error=0;
  53. // Save agendas
  54. while ($i <= $MAXAGENDA)
  55. {
  56. $name=trim(GETPOST('AGENDA_EXT_NAME'.$i,'alpha'));
  57. $src=trim(GETPOST('AGENDA_EXT_SRC'.$i,'alpha'));
  58. $offsettz=trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i,'alpha'));
  59. $color=trim(GETPOST('AGENDA_EXT_COLOR'.$i,'alpha'));
  60. if ($color=='-1') $color='';
  61. $enabled=trim(GETPOST('AGENDA_EXT_ENABLED'.$i,'alpha'));
  62. if (! empty($src) && ! dol_is_url($src))
  63. {
  64. setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
  65. $error++;
  66. $errorsaved++;
  67. break;
  68. }
  69. //print '-name='.$name.'-color='.$color;
  70. $res=dolibarr_set_const($db,'AGENDA_EXT_NAME'.$i,$name,'chaine',0,'',$conf->entity);
  71. if (! $res > 0) $error++;
  72. $res=dolibarr_set_const($db,'AGENDA_EXT_SRC'.$i,$src,'chaine',0,'',$conf->entity);
  73. if (! $res > 0) $error++;
  74. $res=dolibarr_set_const($db,'AGENDA_EXT_OFFSETTZ'.$i,$offsettz,'chaine',0,'',$conf->entity);
  75. if (! $res > 0) $error++;
  76. $res=dolibarr_set_const($db,'AGENDA_EXT_COLOR'.$i,$color,'chaine',0,'',$conf->entity);
  77. if (! $res > 0) $error++;
  78. $res=dolibarr_set_const($db,'AGENDA_EXT_ENABLED'.$i,$enabled,'chaine',0,'',$conf->entity);
  79. if (! $res > 0) $error++;
  80. $i++;
  81. }
  82. // Save nb of agenda
  83. if (! $error)
  84. {
  85. $res=dolibarr_set_const($db,'AGENDA_EXT_NB',trim(GETPOST('AGENDA_EXT_NB','int')),'chaine',0,'',$conf->entity);
  86. if (! $res > 0) $error++;
  87. if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB=5;
  88. $MAXAGENDA=empty($conf->global->AGENDA_EXT_NB)?5:$conf->global->AGENDA_EXT_NB;
  89. }
  90. if (! $error)
  91. {
  92. $db->commit();
  93. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  94. }
  95. else
  96. {
  97. $db->rollback();
  98. if (empty($errorsaved)) setEventMessages($langs->trans("Error"), null, 'errors');
  99. }
  100. }
  101. /*
  102. * View
  103. */
  104. $form=new Form($db);
  105. $formadmin=new FormAdmin($db);
  106. $formother=new FormOther($db);
  107. $arrayofjs=array();
  108. $arrayofcss=array();
  109. $wikihelp='EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
  110. llxHeader('',$langs->trans("AgendaSetup"),$wikihelp,'',0,0,$arrayofjs,$arrayofcss);
  111. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  112. print load_fiche_titre($langs->trans("AgendaSetup"),$linkback,'title_setup');
  113. print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  114. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  115. print '<input type="hidden" name="action" value="save">';
  116. $head=agenda_prepare_head();
  117. dol_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
  118. print $langs->trans("AgendaExtSitesDesc")."<br>\n";
  119. print "<br>\n";
  120. $selectedvalue=$conf->global->AGENDA_DISABLE_EXT;
  121. if ($selectedvalue==1) $selectedvalue=0; else $selectedvalue=1;
  122. $var=true;
  123. print "<table class=\"noborder\" width=\"100%\">";
  124. print "<tr class=\"liste_titre\">";
  125. print '<td>'.$langs->trans("Parameter")."</td>";
  126. print '<td align="center">'.$langs->trans("Value")."</td>";
  127. print "</tr>";
  128. // Show external agenda
  129. print '<tr class="oddeven">';
  130. print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
  131. print '<td align="center">';
  132. if ($conf->use_javascript_ajax)
  133. {
  134. print ajax_constantonoff('AGENDA_DISABLE_EXT',array('enabled'=>array(0=>'.hideifnotset')),null,1);
  135. }
  136. else
  137. {
  138. if (empty($conf->global->AGENDA_DISABLE_EXT))
  139. {
  140. print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  141. }
  142. else
  143. {
  144. print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  145. }
  146. }
  147. print "</td>";
  148. print "</tr>";
  149. // Nb of agenda
  150. print '<tr class="oddeven">';
  151. print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
  152. print '<td align="center">';
  153. print '<input class="flat hideifnotset" type="text" size="2" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="'.$conf->global->AGENDA_EXT_NB.'">';
  154. print "</td>";
  155. print "</tr>";
  156. print "</table>";
  157. print "<br>";
  158. print "<table class=\"noborder\" width=\"100%\">";
  159. print "<tr class=\"liste_titre\">";
  160. print "<td>".$langs->trans("Parameter")."</td>";
  161. print "<td>".$langs->trans("Name")."</td>";
  162. print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
  163. print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
  164. print '<td align="right">'.$langs->trans("Color").'</td>';
  165. print "</tr>";
  166. $i=1;
  167. $var=true;
  168. while ($i <= $MAXAGENDA)
  169. {
  170. $key=$i;
  171. $name='AGENDA_EXT_NAME'.$key;
  172. $src='AGENDA_EXT_SRC'.$key;
  173. $offsettz='AGENDA_EXT_OFFSETTZ'.$key;
  174. $color='AGENDA_EXT_COLOR'.$key;
  175. $enabled='AGENDA_EXT_ENABLED'.$key;
  176. print '<tr class="oddeven">';
  177. // Nb
  178. print '<td width="180" class="nowrap">'.$langs->trans("AgendaExtNb",$key)."</td>";
  179. // Name
  180. 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>';
  181. // URL
  182. 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>';
  183. // Offset TZ
  184. 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>';
  185. // Color (Possible colors are limited by Google)
  186. print '<td class="nowrap" align="right">';
  187. //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
  188. print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR".$key)?GETPOST("AGENDA_EXT_COLOR".$key):$conf->global->$color), "AGENDA_EXT_COLOR".$key, 'extsitesconfig', 1, '', 'hideifnotset');
  189. print '</td>';
  190. print "</tr>";
  191. $i++;
  192. }
  193. print '</table>';
  194. dol_fiche_end();
  195. print '<div class="center">';
  196. print '<input type="submit" id="save" name="save" class="button hideifnotset" value="'.$langs->trans("Save").'">';
  197. print '</div>';
  198. print "</form>\n";
  199. llxFooter();
  200. $db->close();