PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/lib/usergroups.lib.php

https://bitbucket.org/speedealing/speedealing
PHP | 283 lines | 181 code | 48 blank | 54 comment | 42 complexity | c61a159951ad18935708d3a1c0bc8fc6 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
  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. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/lib/usergroups.lib.php
  21. * \brief Ensemble de fonctions de base pour la gestion des utilisaterus et groupes
  22. */
  23. /**
  24. * Prepare array with list of tabs
  25. *
  26. * @param Object $object Object related to tabs
  27. * @return array Array of tabs to shoc
  28. */
  29. function user_prepare_head($object) {
  30. global $langs, $conf, $user;
  31. $langs->load("users");
  32. $canreadperms = ($user->admin || ($user->id != $object->id && $user->rights->user->user_advance->readperms) || ($user->id == $object->id && $user->rights->user->self_advance->readperms));
  33. $h = 0;
  34. $head = array();
  35. $head[$h][0] = DOL_URL_ROOT . '/user/fiche.php?id=' . $object->id;
  36. $head[$h][1] = $langs->trans("UserCard");
  37. $head[$h][2] = 'user';
  38. $h++;
  39. if (!empty($conf->ldap->enabled) && !empty($conf->global->LDAP_SYNCHRO_ACTIVE)) {
  40. $langs->load("ldap");
  41. $head[$h][0] = DOL_URL_ROOT . '/user/ldap.php?id=' . $object->id;
  42. $head[$h][1] = $langs->trans("LDAPCard");
  43. $head[$h][2] = 'ldap';
  44. $h++;
  45. }
  46. $head[$h][0] = DOL_URL_ROOT . '/user/param_ihm.php?id=' . $object->id;
  47. $head[$h][1] = $langs->trans("UserGUISetup");
  48. $head[$h][2] = 'guisetup';
  49. $h++;
  50. if (!empty($conf->clicktodial->enabled)) {
  51. $head[$h][0] = DOL_URL_ROOT . '/user/clicktodial.php?id=' . $object->id;
  52. $head[$h][1] = $langs->trans("ClickToDial");
  53. $head[$h][2] = 'clicktodial';
  54. $h++;
  55. }
  56. // Show more tabs from modules
  57. // Entries must be declared in modules descriptor with line
  58. // $this->tabs = array('entity:+tabname:Title:@mymodule:conditiontoshow:/mymodule/mypage.php?id=__ID__'); to add new tab
  59. // $this->tabs = array('entity:-tabname:Title:@mymodule:conditiontoshow:/mymodule/mypage.php?id=__ID__'); to remove a tab
  60. complete_head_from_modules($conf, $langs, $object, $head, $h, 'user');
  61. if (!empty($user->societe_id)) {
  62. $head[$h][0] = DOL_URL_ROOT . '/user/note.php?id=' . $object->id;
  63. $head[$h][1] = $langs->trans("Note");
  64. $head[$h][2] = 'note';
  65. $h++;
  66. $head[$h][0] = DOL_URL_ROOT . '/user/info.php?id=' . $object->id;
  67. $head[$h][1] = $langs->trans("Info");
  68. $head[$h][2] = 'info';
  69. $h++;
  70. }
  71. return $head;
  72. }
  73. function group_prepare_head($object) {
  74. global $langs, $conf, $user;
  75. $canreadperms = true;
  76. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  77. $canreadperms = ($user->admin || $user->rights->user->group_advance->readperms);
  78. }
  79. $h = 0;
  80. $head = array();
  81. $head[$h][0] = DOL_URL_ROOT . '/user/group/fiche.php?id=' . $object->id;
  82. $head[$h][1] = $langs->trans("GroupCard");
  83. $head[$h][2] = 'group';
  84. $h++;
  85. if (!empty($conf->ldap->enabled) && !empty($conf->global->LDAP_SYNCHRO_ACTIVE)) {
  86. $langs->load("ldap");
  87. $head[$h][0] = DOL_URL_ROOT . '/user/group/ldap.php?id=' . $object->id;
  88. $head[$h][1] = $langs->trans("LDAPCard");
  89. $head[$h][2] = 'ldap';
  90. $h++;
  91. }
  92. if ($canreadperms) {
  93. $head[$h][0] = DOL_URL_ROOT . '/user/group/perms.php?id=' . $object->id;
  94. $head[$h][1] = $langs->trans("GroupRights");
  95. $head[$h][2] = 'rights';
  96. $h++;
  97. }
  98. // Show more tabs from modules
  99. // Entries must be declared in modules descriptor with line
  100. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  101. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  102. complete_head_from_modules($conf, $langs, $object, $head, $h, 'group');
  103. return $head;
  104. }
  105. /**
  106. * Prepare array with list of tabs
  107. *
  108. * @param Object $object Object related to tabs
  109. * @param array $aEntities Entities array
  110. * @return array Array of tabs
  111. */
  112. function entity_prepare_head($object, $aEntities) {
  113. global $mc;
  114. $head = array();
  115. foreach ($aEntities as $entity) {
  116. $mc->getInfo($entity);
  117. $head[$entity][0] = $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&amp;entity=' . $entity;
  118. $head[$entity][1] = $mc->label;
  119. $head[$entity][2] = $entity;
  120. }
  121. return $head;
  122. }
  123. /**
  124. * Show list of themes. Show all thumbs of themes
  125. *
  126. * @param User $fuser User concerned or '' for global theme
  127. * @param int $edit 1 to add edit form
  128. * @param boolean $foruserprofile Show for user profile view
  129. * @return void
  130. */
  131. function show_theme($fuser, $edit = 0, $foruserprofile = false) {
  132. global $conf, $langs, $bc;
  133. $forcethemedir = (!empty($conf->global->MAIN_FORCETHEMEDIR) ? $conf->global->MAIN_FORCETHEMEDIR : '');
  134. $dirthemes = array($forcethemedir . '/theme');
  135. if (!empty($conf->modules_parts['themes'])) {
  136. $dirthemes = array_merge(array($forcethemedir . '/theme'), (array) $conf->modules_parts['themes']);
  137. }
  138. $selected_theme = $conf->global->MAIN_THEME;
  139. if (!empty($fuser->conf->MAIN_THEME))
  140. $selected_theme = $fuser->conf->MAIN_THEME;
  141. $colspan = 2;
  142. if ($foruserprofile)
  143. $colspan = 4;
  144. $thumbsbyrow = 6;
  145. print '<table class="noborder" width="100%">';
  146. $var = false;
  147. // Title
  148. if ($foruserprofile) {
  149. print '<tr class="liste_titre"><th width="25%">' . $langs->trans("Parameter") . '</th><th width="25%">' . $langs->trans("DefaultValue") . '</th>';
  150. print '<th colspan="2">&nbsp;</th>';
  151. print '</tr>';
  152. print '<tr ' . $bc[$var] . '>';
  153. print '<td>' . $langs->trans("DefaultSkin") . '</td>';
  154. print '<td>' . $conf->global->MAIN_THEME . '</td>';
  155. print '<td align="left" nowrap="nowrap" width="20%"><input ' . $bc[$var] . ' name="check_MAIN_THEME"' . ($edit ? '' : ' disabled') . ' type="checkbox" ' . ($selected_theme ? " checked" : "") . '> ' . $langs->trans("UsePersonalValue") . '</td>';
  156. print '<td>&nbsp;</td>';
  157. print '</tr>';
  158. } else {
  159. print '<tr class="liste_titre"><th width="35%">' . $langs->trans("DefaultSkin") . '</th>';
  160. print '<th align="right">';
  161. $url = 'http://www.dolistore.com/lang-en/4-skins';
  162. if (preg_match('/fr/i', $langs->defaultlang))
  163. $url = 'http://www.dolistore.com/lang-fr/4-themes';
  164. //if (preg_match('/es/i',$langs->defaultlang)) $url='http://www.dolistore.com/lang-es/4-themes';
  165. print '<a href="' . $url . '" target="_blank">';
  166. print $langs->trans('DownloadMoreSkins');
  167. print '</a>';
  168. print '</th></tr>';
  169. print '<tr ' . $bc[$var] . '>';
  170. print '<td>' . $langs->trans("ThemeDir") . '</td>';
  171. print '<td>';
  172. foreach ($dirthemes as $dirtheme) {
  173. echo '"' . $dirtheme . '" ';
  174. }
  175. print '</td>';
  176. print '</tr>';
  177. }
  178. $var = !$var;
  179. print '<tr ' . $bc[$var] . '><td colspan="' . $colspan . '">';
  180. print '<table class="nobordernopadding" width="100%">';
  181. $i = 0;
  182. foreach ($dirthemes as $dir) {
  183. $dirtheme = dol_buildpath($dir, 0);
  184. $urltheme = dol_buildpath($dir, 1);
  185. if (is_dir($dirtheme)) {
  186. $handle = opendir($dirtheme);
  187. if (is_resource($handle)) {
  188. while (($subdir = readdir($handle)) !== false) {
  189. if (is_dir($dirtheme . "/" . $subdir) && substr($subdir, 0, 1) <> '.'
  190. && substr($subdir, 0, 3) <> 'CVS' && !preg_match('/common|phones/i', $subdir)) {
  191. // Disable not stable themes
  192. //if ($conf->global->MAIN_FEATURES_LEVEL < 1 && preg_match('/bureau2crea/i',$subdir)) continue;
  193. if ($i % $thumbsbyrow == 0) {
  194. print '<tr ' . $bc[$var] . '>';
  195. }
  196. print '<td align="center">';
  197. $file = $dirtheme . "/" . $subdir . "/thumb.png";
  198. $url = $urltheme . "/" . $subdir . "/thumb.png";
  199. if (!file_exists($file))
  200. $url = $urltheme . "/common/nophoto.jpg";
  201. print '<table><tr><td>';
  202. print '<a href="' . $_SERVER["PHP_SELF"] . ($edit ? '?action=edit&theme=' : '?theme=') . $subdir . (GETPOST("optioncss") ? '&optioncss=' . GETPOST("optioncss", 'alpha', 1) : '') . ($fuser ? '&id=' . $fuser->id : '') . '" style="font-weight: normal;" alt="' . $langs->trans("Preview") . '">';
  203. if ($subdir == $conf->global->MAIN_THEME)
  204. $title = $langs->trans("ThemeCurrentlyActive");
  205. else
  206. $title = $langs->trans("ShowPreview");
  207. print '<img src="' . $url . '" border="0" width="80" height="60" alt="' . $title . '" title="' . $title . '">';
  208. print '</a>';
  209. print '</td></tr><tr><td align="center">';
  210. if ($subdir == $selected_theme) {
  211. print '<input ' . ($edit ? '' : 'disabled') . ' type="radio" ' . $bc[$var] . ' style="border: 0px;" checked name="main_theme" value="' . $subdir . '"> <b>' . $subdir . '</b>';
  212. } else {
  213. print '<input ' . ($edit ? '' : 'disabled') . ' type="radio" ' . $bc[$var] . ' style="border: 0px;" name="main_theme" value="' . $subdir . '"> ' . $subdir;
  214. }
  215. print '</td></tr></table></td>';
  216. $i++;
  217. if ($i % $thumbsbyrow == 0)
  218. print '</tr>';
  219. }
  220. }
  221. }
  222. }
  223. }
  224. if ($i % $thumbsbyrow != 0) {
  225. while ($i % $thumbsbyrow != 0) {
  226. print '<td>&nbsp;</td>';
  227. $i++;
  228. }
  229. print '</tr>';
  230. }
  231. print '</table>';
  232. print '</td></tr>';
  233. print '</table>';
  234. }
  235. ?>