agenda_extsites.php 10 KB

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