agenda_extsites.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 <https://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. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  33. // Load translation files required by page
  34. $langs->loadLangs(array('agenda', 'admin', 'other'));
  35. $def = array();
  36. $actiontest = GETPOST('test', 'alpha');
  37. $actionsave = GETPOST('save', 'alpha');
  38. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'useragenda'; // To manage different context of search
  39. if (empty($conf->global->AGENDA_EXT_NB)) {
  40. $conf->global->AGENDA_EXT_NB = 5;
  41. }
  42. $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
  43. // List of available colors
  44. $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
  45. // Security check
  46. $id = GETPOST('id', 'int');
  47. $object = new User($db);
  48. $object->fetch($id, '', '', 1);
  49. $object->getrights();
  50. // Security check
  51. $socid = 0;
  52. if ($user->socid > 0) {
  53. $socid = $user->socid;
  54. }
  55. $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
  56. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  57. // If user is not user that read and no permission to read other users, we stop
  58. if (($object->id != $user->id) && (!$user->rights->user->user->lire)) {
  59. accessforbidden();
  60. }
  61. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  62. $hookmanager->initHooks(array('usercard', 'useragenda', 'globalcard'));
  63. /*
  64. * Actions
  65. */
  66. $parameters = array('id'=>$socid);
  67. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  68. if ($reshook < 0) {
  69. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  70. }
  71. if (empty($reshook)) {
  72. if ($actionsave) {
  73. $db->begin();
  74. $errorsaved = 0;
  75. $error = 0;
  76. $tabparam = array();
  77. // Save agendas
  78. $i = 1;
  79. while ($i <= $MAXAGENDA) {
  80. $name = trim(GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$i, 'alpha'));
  81. $src = trim(GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$i, 'alpha'));
  82. $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i, 'alpha'));
  83. $color = trim(GETPOST('AGENDA_EXT_COLOR_'.$id.'_'.$i, 'alpha'));
  84. if ($color == '-1') {
  85. $color = '';
  86. }
  87. $enabled = trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i, 'alpha'));
  88. if (!empty($src) && !dol_is_url($src)) {
  89. setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
  90. $error++;
  91. $errorsaved++;
  92. break;
  93. }
  94. $tabparam['AGENDA_EXT_NAME_'.$id.'_'.$i] = $name;
  95. $tabparam['AGENDA_EXT_SRC_'.$id.'_'.$i] = $src;
  96. $tabparam['AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i] = $offsettz;
  97. $tabparam['AGENDA_EXT_COLOR_'.$id.'_'.$i] = $color;
  98. $tabparam['AGENDA_EXT_ENABLED_'.$id.'_'.$i] = $enabled;
  99. $i++;
  100. }
  101. if (!$error) {
  102. $result = dol_set_user_param($db, $conf, $object, $tabparam);
  103. if (!($result > 0)) {
  104. $error++;
  105. }
  106. }
  107. if (!$error) {
  108. $db->commit();
  109. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  110. } else {
  111. $db->rollback();
  112. if (empty($errorsaved)) {
  113. setEventMessages($langs->trans("Error"), null, 'errors');
  114. }
  115. }
  116. }
  117. }
  118. /*
  119. * View
  120. */
  121. $form = new Form($db);
  122. $formadmin = new FormAdmin($db);
  123. $formother = new FormOther($db);
  124. $arrayofjs = array();
  125. $arrayofcss = array();
  126. $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
  127. $title = $person_name." - ".$langs->trans('ExtSites');
  128. $help_url = '';
  129. llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss);
  130. print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  131. print '<input type="hidden" name="id" value="'.$id.'">';
  132. print '<input type="hidden" name="token" value="'.newToken().'">';
  133. $head = user_prepare_head($object);
  134. print dol_get_fiche_head($head, 'extsites', $langs->trans("User"), -1, 'user');
  135. $linkback = '';
  136. if ($user->rights->user->user->lire || $user->admin) {
  137. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  138. }
  139. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'" class="refid">';
  140. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  141. $morehtmlref .= '</a>';
  142. dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', $morehtmlref);
  143. print '<div class="fichecenter">';
  144. print '<div class="underbanner clearboth"></div>';
  145. print '<table class="border tableforfield centpercent">';
  146. // Login
  147. print '<tr><td id="anchorforperms" class="titlefield">'.$langs->trans("Login").'</td>';
  148. if (!empty($object->ldap_sid) && $object->statut == 0) {
  149. print '<td class="error">';
  150. print $langs->trans("LoginAccountDisableInDolibarr");
  151. print '</td>';
  152. } else {
  153. print '<td>';
  154. $addadmin = '';
  155. if (property_exists($object, 'admin')) {
  156. if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
  157. $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
  158. } elseif (!empty($object->admin)) {
  159. $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
  160. }
  161. }
  162. print showValueWithClipboardCPButton($object->login).$addadmin;
  163. print '</td>';
  164. }
  165. print '</tr>'."\n";
  166. print '</table>';
  167. print '</div>';
  168. print dol_get_fiche_end();
  169. print '<br>';
  170. print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
  171. print "<br>\n";
  172. $selectedvalue = empty($conf->global->AGENDA_DISABLE_EXT) ? 0 : $conf->global->AGENDA_DISABLE_EXT;
  173. if ($selectedvalue == 1) {
  174. $selectedvalue = 0;
  175. } else {
  176. $selectedvalue = 1;
  177. }
  178. print '<div class="div-table-responsive">';
  179. print '<table class="noborder centpercent">';
  180. print "<tr class=\"liste_titre\">";
  181. print "<td>".$langs->trans("Parameter")."</td>";
  182. print "<td>".$langs->trans("Name")."</td>";
  183. print "<td>".$langs->trans("ExtSiteUrlAgenda").'<div class="hideonsmartphone opacitymedium">'." (".$langs->trans("Example").': https://externalcalendar/agenda/agenda.ics)</div></td>';
  184. print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
  185. print '<td class="right">'.$langs->trans("Color").'</td>';
  186. print "</tr>";
  187. $i = 1;
  188. while ($i <= $MAXAGENDA) {
  189. $key = $i;
  190. $name = 'AGENDA_EXT_NAME_'.$id.'_'.$key;
  191. $src = 'AGENDA_EXT_SRC_'.$id.'_'.$key;
  192. $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key;
  193. $color = 'AGENDA_EXT_COLOR_'.$id.'_'.$key;
  194. print '<tr class="oddeven">';
  195. // Nb
  196. print '<td class="maxwidth50onsmartphone">'.$langs->trans("AgendaExtNb", $key)."</td>";
  197. // Name
  198. $name_value = (GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) ?GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) : (empty($object->conf->$name) ? '' : $object->conf->$name));
  199. print '<td><input type="text" class="flat hideifnotset minwidth100 maxwidth100onsmartphone" name="AGENDA_EXT_NAME_'.$id.'_'.$key.'" value="'.$name_value.'"></td>';
  200. // URL
  201. $src_value = (GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) ?GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) : (empty($object->conf->$src) ? '' : $object->conf->$src));
  202. print '<td><input type="url" class="flat hideifnotset width300" name="AGENDA_EXT_SRC_'.$id.'_'.$key.'" value="'.$src_value.'"></td>';
  203. // Offset TZ
  204. $offsettz_value = (GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) ? GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) : (empty($object->conf->$offsettz) ? '' : $object->conf->$offsettz));
  205. print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key.'" value="'.$offsettz_value.'" size="1"></td>';
  206. // Color (Possible colors are limited by Google)
  207. print '<td class="nowraponall right">';
  208. //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
  209. $color_value = (GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) ?GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) : (empty($object->conf->$color) ? 'ffffff' : $object->conf->$color));
  210. print $formother->selectColor($color_value, "AGENDA_EXT_COLOR_".$id.'_'.$key, 'extsitesconfig', 1, '', 'hideifnotset');
  211. print '</td>';
  212. print "</tr>";
  213. $i++;
  214. }
  215. print '</table>';
  216. print '</div>';
  217. $addition_button = array(
  218. 'name' => 'save',
  219. 'label_key' => 'Save',
  220. 'addclass' => 'hideifnotset',
  221. );
  222. print $form->buttonsSaveCancel("", "", $addition_button);
  223. print dol_get_fiche_end();
  224. print "</form>\n";
  225. // End of page
  226. llxFooter();
  227. $db->close();