agenda_extsites.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* Copyright (C) 2008-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/user/agenda_extsites.php
  20. * \ingroup agenda
  21. * \brief Page to setup external calendars for agenda module
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  32. // Load translation files required by page
  33. $langs->loadLangs(array('agenda', 'admin', 'other'));
  34. $def = array();
  35. $actiontest=GETPOST('test','alpha');
  36. $actionsave=GETPOST('save','alpha');
  37. $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'useragenda'; // To manage different context of search
  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. // Security check
  43. $id = GETPOST('id','int');
  44. $object = new User($db);
  45. $object->fetch($id, '', '', 1);
  46. $object->getrights();
  47. // Security check
  48. $socid=0;
  49. if ($user->societe_id > 0) $socid = $user->societe_id;
  50. $feature2 = (($socid && $user->rights->user->self->creer)?'':'user');
  51. if ($user->id == $id) // A user can always read its own card
  52. {
  53. $feature2='';
  54. }
  55. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  56. // If user is not user that read and no permission to read other users, we stop
  57. if (($object->id != $user->id) && (! $user->rights->user->user->lire))
  58. accessforbidden();
  59. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  60. $hookmanager->initHooks(array('usercard','useragenda','globalcard'));
  61. /*
  62. * Actions
  63. */
  64. $parameters=array('id'=>$socid);
  65. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  66. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  67. if (empty($reshook)) {
  68. if ($actionsave) {
  69. $db->begin();
  70. $errorsaved = 0;
  71. $error = 0;
  72. $tabparam = array();
  73. // Save agendas
  74. $i = 1;
  75. while ($i <= $MAXAGENDA) {
  76. $name = trim(GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$i, 'alpha'));
  77. $src = trim(GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$i, 'alpha'));
  78. $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i, 'alpha'));
  79. $color = trim(GETPOST('AGENDA_EXT_COLOR_'.$id.'_'.$i, 'alpha'));
  80. if ($color == '-1') {
  81. $color = '';
  82. }
  83. $enabled = trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i, 'alpha'));
  84. if (!empty($src) && !dol_is_url($src)) {
  85. setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
  86. $error ++;
  87. $errorsaved ++;
  88. break;
  89. }
  90. $tabparam['AGENDA_EXT_NAME_'.$id.'_'.$i]=$name;
  91. $tabparam['AGENDA_EXT_SRC_'.$id.'_'.$i]=$src;
  92. $tabparam['AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i]=$offsettz;
  93. $tabparam['AGENDA_EXT_COLOR_'.$id.'_'.$i]=$color;
  94. $tabparam['AGENDA_EXT_ENABLED_'.$id.'_'.$i]=$enabled;
  95. $i++;
  96. }
  97. if (!$error) {
  98. $result = dol_set_user_param($db, $conf, $object, $tabparam);
  99. if (!$result > 0) {
  100. $error ++;
  101. }
  102. }
  103. if (!$error) {
  104. $db->commit();
  105. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  106. } else {
  107. $db->rollback();
  108. if (empty($errorsaved)) {
  109. setEventMessages($langs->trans("Error"), null, 'errors');
  110. }
  111. }
  112. }
  113. }
  114. /*
  115. * View
  116. */
  117. $form=new Form($db);
  118. $formadmin=new FormAdmin($db);
  119. $formother=new FormOther($db);
  120. $arrayofjs=array();
  121. $arrayofcss=array();
  122. llxHeader('',$langs->trans("UserSetup"),'','',0,0,$arrayofjs,$arrayofcss);
  123. print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  124. print '<input type="hidden" name="id" value="'.$id.'">';
  125. $head=user_prepare_head($object);
  126. dol_fiche_head($head, 'extsites', $langs->trans("User"), -1, 'user');
  127. $linkback = '';
  128. if ($user->rights->user->user->lire || $user->admin) {
  129. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  130. }
  131. dol_banner_tab($object,'id',$linkback,$user->rights->user->user->lire || $user->admin);
  132. print '<div class="underbanner clearboth"></div>';
  133. print '<br>';
  134. print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
  135. print "<br>\n";
  136. $selectedvalue=$conf->global->AGENDA_DISABLE_EXT;
  137. if ($selectedvalue==1) $selectedvalue=0; else $selectedvalue=1;
  138. print '<div class="div-table-responsive">';
  139. print "<table class=\"noborder\" width=\"100%\">";
  140. print "<tr class=\"liste_titre\">";
  141. print "<td>".$langs->trans("Parameter")."</td>";
  142. print "<td>".$langs->trans("Name")."</td>";
  143. print "<td>".$langs->trans("ExtSiteUrlAgenda").'<div class="hideonsmartphone">'." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</div></td>';
  144. print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
  145. print '<td align="right">'.$langs->trans("Color").'</td>';
  146. print "</tr>";
  147. $i=1;
  148. while ($i <= $MAXAGENDA)
  149. {
  150. $key=$i;
  151. $name='AGENDA_EXT_NAME_'.$id.'_'.$key;
  152. $src='AGENDA_EXT_SRC_'.$id.'_'.$key;
  153. $offsettz='AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key;
  154. $color='AGENDA_EXT_COLOR_'.$id.'_'.$key;
  155. print '<tr class="oddeven">';
  156. // Nb
  157. print '<td class="maxwidth50onsmartphone">'.$langs->trans("AgendaExtNb",$key)."</td>";
  158. // Name
  159. print '<td class="maxwidth50onsmartphone"><input type="text" class="flat hideifnotset minwidth100" name="AGENDA_EXT_NAME_'.$id.'_'.$key.'" value="'. (GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key)?GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key):$object->conf->$name) . '"></td>';
  160. // URL
  161. print '<td class="maxwidth50onsmartphone"><input type="url" class="flat hideifnotset" name="AGENDA_EXT_SRC_'.$id.'_'.$key.'" value="'. (GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key)?GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key):$object->conf->$src) . '"></td>';
  162. // Offset TZ
  163. print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key.'" value="'. (GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key)?GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key):$object->conf->$offsettz) . '" size="1"></td>';
  164. // Color (Possible colors are limited by Google)
  165. print '<td class="nowrap" align="right">';
  166. //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
  167. print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key)?GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key):$object->conf->$color), "AGENDA_EXT_COLOR_".$id.'_'.$key, 'extsitesconfig', 1, '', 'hideifnotset');
  168. print '</td>';
  169. print "</tr>";
  170. $i++;
  171. }
  172. print '</table>';
  173. print '</div>';
  174. print '<div class="center">';
  175. print "<input type=\"submit\" id=\"save\" name=\"save\" class=\"button hideifnotset\" value=\"".$langs->trans("Save")."\">";
  176. print "</div>";
  177. dol_fiche_end();
  178. print "</form>\n";
  179. // End of page
  180. llxFooter();
  181. $db->close();