PageRenderTime 120ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

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