usergroups.lib.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. {
  31. global $langs, $conf, $user;
  32. $langs->load("users");
  33. $canreadperms=true;
  34. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
  35. {
  36. $canreadperms=($user->admin || ($user->id != $object->id && $user->rights->user->user_advance->readperms) || ($user->id == $object->id && $user->rights->user->self_advance->readperms));
  37. }
  38. $h = 0;
  39. $head = array();
  40. $head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$object->id;
  41. $head[$h][1] = $langs->trans("UserCard");
  42. $head[$h][2] = 'user';
  43. $h++;
  44. if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE))
  45. {
  46. $langs->load("ldap");
  47. $head[$h][0] = DOL_URL_ROOT.'/user/ldap.php?id='.$object->id;
  48. $head[$h][1] = $langs->trans("LDAPCard");
  49. $head[$h][2] = 'ldap';
  50. $h++;
  51. }
  52. if ($canreadperms)
  53. {
  54. $head[$h][0] = DOL_URL_ROOT.'/user/perms.php?id='.$object->id;
  55. $head[$h][1] = $langs->trans("UserRights");
  56. $head[$h][2] = 'rights';
  57. $h++;
  58. }
  59. $head[$h][0] = DOL_URL_ROOT.'/user/param_ihm.php?id='.$object->id;
  60. $head[$h][1] = $langs->trans("UserGUISetup");
  61. $head[$h][2] = 'guisetup';
  62. $h++;
  63. if (! empty($conf->clicktodial->enabled))
  64. {
  65. $head[$h][0] = DOL_URL_ROOT.'/user/clicktodial.php?id='.$object->id;
  66. $head[$h][1] = $langs->trans("ClickToDial");
  67. $head[$h][2] = 'clicktodial';
  68. $h++;
  69. }
  70. // Show more tabs from modules
  71. // Entries must be declared in modules descriptor with line
  72. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  73. // $this->tabs = array('entity:-tabname); to remove a tab
  74. complete_head_from_modules($conf,$langs,$object,$head,$h,'user');
  75. //Info on users is visible only by internal user
  76. if (empty($user->societe_id))
  77. {
  78. $head[$h][0] = DOL_URL_ROOT.'/user/note.php?id='.$object->id;
  79. $head[$h][1] = $langs->trans("Note");
  80. $head[$h][2] = 'note';
  81. $h++;
  82. $head[$h][0] = DOL_URL_ROOT.'/user/info.php?id='.$object->id;
  83. $head[$h][1] = $langs->trans("Info");
  84. $head[$h][2] = 'info';
  85. $h++;
  86. }
  87. complete_head_from_modules($conf,$langs,$object,$head,$h,'user','remove');
  88. return $head;
  89. }
  90. function group_prepare_head($object)
  91. {
  92. global $langs, $conf, $user;
  93. $canreadperms=true;
  94. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
  95. {
  96. $canreadperms=($user->admin || $user->rights->user->group_advance->readperms);
  97. }
  98. $h = 0;
  99. $head = array();
  100. $head[$h][0] = DOL_URL_ROOT.'/user/group/fiche.php?id='.$object->id;
  101. $head[$h][1] = $langs->trans("GroupCard");
  102. $head[$h][2] = 'group';
  103. $h++;
  104. if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE))
  105. {
  106. $langs->load("ldap");
  107. $head[$h][0] = DOL_URL_ROOT.'/user/group/ldap.php?id='.$object->id;
  108. $head[$h][1] = $langs->trans("LDAPCard");
  109. $head[$h][2] = 'ldap';
  110. $h++;
  111. }
  112. if ($canreadperms)
  113. {
  114. $head[$h][0] = DOL_URL_ROOT.'/user/group/perms.php?id='.$object->id;
  115. $head[$h][1] = $langs->trans("GroupRights");
  116. $head[$h][2] = 'rights';
  117. $h++;
  118. }
  119. // Show more tabs from modules
  120. // Entries must be declared in modules descriptor with line
  121. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  122. // $this->tabs = array('entity:-tabname); to remove a tab
  123. complete_head_from_modules($conf,$langs,$object,$head,$h,'group');
  124. complete_head_from_modules($conf,$langs,$object,$head,$h,'group','remove');
  125. return $head;
  126. }
  127. /**
  128. * Prepare array with list of tabs
  129. *
  130. * @return array Array of tabs to shoc
  131. */
  132. function user_admin_prepare_head()
  133. {
  134. global $langs, $conf, $user;
  135. $langs->load("users");
  136. $h=0;
  137. $head[$h][0] = DOL_URL_ROOT.'/admin/user.php';
  138. $head[$h][1] = $langs->trans("Parameters");
  139. $head[$h][2] = 'card';
  140. $h++;
  141. $head[$h][0] = DOL_URL_ROOT.'/user/admin/user_extrafields.php';
  142. $head[$h][1] = $langs->trans("ExtraFields");
  143. $head[$h][2] = 'attributes';
  144. $h++;
  145. // Show more tabs from modules
  146. // Entries must be declared in modules descriptor with line
  147. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  148. // $this->tabs = array('entity:-tabname); to remove a tab
  149. complete_head_from_modules($conf,$langs,null,$head,$h,'useradmin');
  150. complete_head_from_modules($conf,$langs,null,$head,$h,'useradmin','remove');
  151. return $head;
  152. }
  153. /**
  154. * Prepare array with list of tabs
  155. *
  156. * @param Object $object Object related to tabs
  157. * @param array $aEntities Entities array
  158. * @return array Array of tabs
  159. */
  160. function entity_prepare_head($object, $aEntities)
  161. {
  162. global $mc;
  163. $head = array();
  164. foreach($aEntities as $entity)
  165. {
  166. $mc->getInfo($entity);
  167. $head[$entity][0] = $_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;entity='.$entity;
  168. $head[$entity][1] = $mc->label;
  169. $head[$entity][2] = $entity;
  170. }
  171. return $head;
  172. }
  173. /**
  174. * Show list of themes. Show all thumbs of themes
  175. *
  176. * @param User $fuser User concerned or '' for global theme
  177. * @param int $edit 1 to add edit form
  178. * @param boolean $foruserprofile Show for user profile view
  179. * @return void
  180. */
  181. function show_theme($fuser,$edit=0,$foruserprofile=false)
  182. {
  183. global $conf,$langs,$bc;
  184. //$dirthemes=array(empty($conf->global->MAIN_FORCETHEMEDIR)?'/theme':$conf->global->MAIN_FORCETHEMEDIR.'/theme');
  185. $dirthemes=array('/theme');
  186. if (! empty($conf->modules_parts['theme'])) // Using this feature slow down application
  187. {
  188. foreach($conf->modules_parts['theme'] as $reldir)
  189. {
  190. $dirthemes=array_merge($dirthemes,(array) ($reldir.'theme'));
  191. }
  192. }
  193. $dirthemes=array_unique($dirthemes);
  194. // Now dir_themes=array('/themes') or dir_themes=array('/theme','/mymodule/theme')
  195. $selected_theme='';
  196. if (empty($foruserprofile)) $selected_theme=$conf->global->MAIN_THEME;
  197. else $selected_theme=empty($fuser->conf->MAIN_THEME)?'':$fuser->conf->MAIN_THEME;
  198. $colspan=2;
  199. if ($foruserprofile) $colspan=4;
  200. $thumbsbyrow=6;
  201. print '<table class="noborder" width="100%">';
  202. $var=false;
  203. // Title
  204. if ($foruserprofile)
  205. {
  206. print '<tr class="liste_titre"><th width="25%">'.$langs->trans("Parameter").'</th><th width="25%">'.$langs->trans("DefaultValue").'</th>';
  207. print '<th colspan="2">&nbsp;</th>';
  208. print '</tr>';
  209. print '<tr '.$bc[$var].'>';
  210. print '<td>'.$langs->trans("DefaultSkin").'</td>';
  211. print '<td>'.$conf->global->MAIN_THEME.'</td>';
  212. print '<td align="left" class="nowrap" width="20%"><input '.$bc[$var].' name="check_MAIN_THEME"'.($edit?'':' disabled').' type="checkbox" '.($selected_theme?" checked":"").'> '.$langs->trans("UsePersonalValue").'</td>';
  213. print '<td>&nbsp;</td>';
  214. print '</tr>';
  215. }
  216. else
  217. {
  218. print '<tr class="liste_titre"><th width="35%">'.$langs->trans("DefaultSkin").'</th>';
  219. print '<th align="right">';
  220. $url='http://www.dolistore.com/lang-en/4-skins';
  221. if (preg_match('/fr/i',$langs->defaultlang)) $url='http://www.dolistore.com/lang-fr/4-themes';
  222. //if (preg_match('/es/i',$langs->defaultlang)) $url='http://www.dolistore.com/lang-es/4-themes';
  223. print '<a href="'.$url.'" target="_blank">';
  224. print $langs->trans('DownloadMoreSkins');
  225. print '</a>';
  226. print '</th></tr>';
  227. print '<tr '.$bc[$var].'>';
  228. print '<td>'.$langs->trans("ThemeDir").'</td>';
  229. print '<td>';
  230. foreach($dirthemes as $dirtheme)
  231. {
  232. echo '"'.$dirtheme.'" ';
  233. }
  234. print '</td>';
  235. print '</tr>';
  236. }
  237. $var=!$var;
  238. print '<tr '.$bc[$var].'><td colspan="'.$colspan.'">';
  239. print '<table class="nobordernopadding" width="100%"><tr><td><div align="center">';
  240. $i=0;
  241. foreach($dirthemes as $dir)
  242. {
  243. //print $dirroot.$dir;exit;
  244. $dirtheme=dol_buildpath($dir,0); // This include loop on $conf->file->dol_document_root
  245. $urltheme=dol_buildpath($dir,1);
  246. if (is_dir($dirtheme))
  247. {
  248. $handle=opendir($dirtheme);
  249. if (is_resource($handle))
  250. {
  251. while (($subdir = readdir($handle))!==false)
  252. {
  253. if (is_dir($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.'
  254. && substr($subdir, 0, 3) <> 'CVS' && ! preg_match('/common|phones/i',$subdir))
  255. {
  256. // Disable not stable themes
  257. //if ($conf->global->MAIN_FEATURES_LEVEL < 1 && preg_match('/bureau2crea/i',$subdir)) continue;
  258. print '<div class="inline-block" style="margin-top: 10px; margin-bottom: 10px; margin-right: 20px; margin-left: 20px;">';
  259. $file=$dirtheme."/".$subdir."/thumb.png";
  260. $url=$urltheme."/".$subdir."/thumb.png";
  261. if (! file_exists($file)) $url=$urltheme."/common/nophoto.jpg";
  262. 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").'">';
  263. if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive");
  264. else $title=$langs->trans("ShowPreview");
  265. print '<img src="'.$url.'" border="0" width="80" height="60" alt="'.$title.'" title="'.$title.'" style="margin-bottom: 5px;">';
  266. print '</a><br>';
  267. if ($subdir == $selected_theme)
  268. {
  269. print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" checked name="main_theme" value="'.$subdir.'"> <b>'.$subdir.'</b>';
  270. }
  271. else
  272. {
  273. print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" name="main_theme" value="'.$subdir.'"> '.$subdir;
  274. }
  275. print '</div>';
  276. $i++;
  277. }
  278. }
  279. }
  280. }
  281. }
  282. print '</div></td></tr></table>';
  283. print '</td></tr>';
  284. print '</table>';
  285. }
  286. ?>