dolibarr/htdocs/lib/usergroups.lib.php

273 lines
8.8 KiB
PHP
Raw Normal View History

<?php
2010-09-17 07:18:01 +02:00
/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2011-08-01 01:24:38 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
2008-11-26 20:37:25 +01:00
/**
* \file htdocs/lib/usergroups.lib.php
* \brief Ensemble de fonctions de base pour la gestion des utilisaterus et groupes
*/
2010-09-17 07:18:01 +02:00
function user_prepare_head($object)
{
2010-10-29 07:38:33 +02:00
global $langs, $conf, $user;
2010-11-07 18:45:51 +01:00
2006-11-28 23:18:48 +01:00
$langs->load("users");
2010-11-07 18:45:51 +01:00
2010-11-08 12:40:52 +01:00
$canreadperms=true;
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
{
$canreadperms=($user->admin || ($user->id != $object->id && $user->rights->user->user_advance->readperms) || ($user->id == $object->id && $user->rights->user->self_advance->readperms));
}
2009-08-05 19:19:55 +02:00
$h = 0;
$head = array();
2009-08-05 19:19:55 +02:00
2010-09-17 07:18:01 +02:00
$head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$object->id;
$head[$h][1] = $langs->trans("UserCard");
$head[$h][2] = 'user';
$h++;
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE)
{
$langs->load("ldap");
2010-09-17 07:18:01 +02:00
$head[$h][0] = DOL_URL_ROOT.'/user/ldap.php?id='.$object->id;
$head[$h][1] = $langs->trans("LDAPCard");
$head[$h][2] = 'ldap';
$h++;
}
2010-11-07 18:45:51 +01:00
2010-10-29 07:38:33 +02:00
if ($canreadperms)
{
$head[$h][0] = DOL_URL_ROOT.'/user/perms.php?id='.$object->id;
$head[$h][1] = $langs->trans("UserRights");
$head[$h][2] = 'rights';
$h++;
}
2010-09-17 07:18:01 +02:00
$head[$h][0] = DOL_URL_ROOT.'/user/param_ihm.php?id='.$object->id;
$head[$h][1] = $langs->trans("UserGUISetup");
$head[$h][2] = 'guisetup';
$h++;
if ($conf->clicktodial->enabled)
{
2010-09-17 07:18:01 +02:00
$head[$h][0] = DOL_URL_ROOT.'/user/clicktodial.php?id='.$object->id;
$head[$h][1] = $langs->trans("ClickToDial");
$head[$h][2] = 'clicktodial';
$h++;
}
2011-01-25 00:35:21 +01:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'user');
if (! $user->societe_id)
{
$head[$h][0] = DOL_URL_ROOT.'/user/note.php?id='.$object->id;
$head[$h][1] = $langs->trans("Note");
$head[$h][2] = 'note';
$h++;
2010-11-07 18:45:51 +01:00
$head[$h][0] = DOL_URL_ROOT.'/user/info.php?id='.$object->id;
$head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info';
$h++;
}
2010-11-07 18:45:51 +01:00
return $head;
}
2010-09-17 07:18:01 +02:00
function group_prepare_head($object)
{
2010-10-29 07:38:33 +02:00
global $langs, $conf, $user;
2010-11-07 18:45:51 +01:00
2010-11-08 12:40:52 +01:00
$canreadperms=true;
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
{
$canreadperms=($user->admin || $user->rights->user->group_advance->readperms);
}
2009-08-05 19:19:55 +02:00
$h = 0;
$head = array();
2009-08-05 19:19:55 +02:00
2010-09-17 07:18:01 +02:00
$head[$h][0] = DOL_URL_ROOT.'/user/group/fiche.php?id='.$object->id;
$head[$h][1] = $langs->trans("GroupCard");
$head[$h][2] = 'group';
$h++;
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE)
{
$langs->load("ldap");
2010-09-17 07:18:01 +02:00
$head[$h][0] = DOL_URL_ROOT.'/user/group/ldap.php?id='.$object->id;
$head[$h][1] = $langs->trans("LDAPCard");
$head[$h][2] = 'ldap';
$h++;
}
2010-11-07 18:45:51 +01:00
2010-10-29 07:38:33 +02:00
if ($canreadperms)
{
$head[$h][0] = DOL_URL_ROOT.'/user/group/perms.php?id='.$object->id;
$head[$h][1] = $langs->trans("GroupRights");
$head[$h][2] = 'rights';
$h++;
}
2010-11-07 18:45:51 +01:00
2011-01-25 00:35:21 +01:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'group');
2011-01-25 00:35:21 +01:00
return $head;
}
2008-11-26 20:37:25 +01:00
/**
2010-11-20 01:27:59 +01:00
* Show list of themes. Show all thumbs of themes
2011-07-04 11:01:37 +02:00
* @param fuser User concerned or '' for global theme
* @param edit 1 to add edit form
* @param foruserprofile Show for user profile view
2008-11-26 20:37:25 +01:00
*/
2009-08-05 19:19:55 +02:00
function show_theme($fuser,$edit=0,$foruserprofile=false)
2008-11-26 20:37:25 +01:00
{
global $conf,$langs,$bc;
2009-08-05 19:19:55 +02:00
2011-07-19 01:35:06 +02:00
$dirtheme=dol_buildpath($conf->global->MAIN_FORCETHEMEDIR.'/theme',0);
$urltheme=dol_buildpath($conf->global->MAIN_FORCETHEMEDIR.'/theme',1);
2011-07-19 01:35:06 +02:00
2008-11-26 20:37:25 +01:00
$selected_theme=$conf->global->MAIN_THEME;
if (! empty($fuser)) $selected_theme=$fuser->conf->MAIN_THEME;
2009-08-05 19:19:55 +02:00
2008-11-26 20:37:25 +01:00
$colspan=2;
if ($foruserprofile) $colspan=4;
2009-08-05 19:19:55 +02:00
2008-11-26 20:37:25 +01:00
$thumbsbyrow=6;
print '<table class="noborder" width="100%">';
// Title
2008-11-26 20:37:25 +01:00
if ($foruserprofile)
{
print '<tr class="liste_titre"><td width="25%">'.$langs->trans("Parameter").'</td><td width="25%">'.$langs->trans("DefaultValue").'</td>';
print '<td colspan="2">&nbsp;</td>';
print '</tr>';
2008-11-26 20:37:25 +01:00
}
else
{
print '<tr class="liste_titre"><td width="35%">'.$langs->trans("DefaultSkin").'</td>';
print '<td align="right">';
2010-06-28 21:01:47 +02:00
$url='http://www.dolistore.com/lang-en/4-skins';
if (preg_match('/fr/i',$langs->defaultlang)) $url='http://www.dolistore.com/lang-fr/4-themes';
2011-07-19 01:35:06 +02:00
//if (preg_match('/es/i',$langs->defaultlang)) $url='http://www.dolistore.com/lang-es/4-themes';
2010-06-28 21:01:47 +02:00
print '<a href="'.$url.'" target="_blank">';
print $langs->trans('DownloadMoreSkins');
print '</a>';
print '</td></tr>';
2008-11-26 20:37:25 +01:00
}
$var=false;
if ($foruserprofile)
{
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("DefaultSkin").'</td>';
2008-11-26 20:37:25 +01:00
print '<td>'.$conf->global->MAIN_THEME.'</td>';
print '<td '.$bc[$var].' align="left" nowrap="nowrap" width="20%"><input '.$bc[$var].' name="check_MAIN_THEME"'.($edit?'':' disabled').' type="checkbox" '.($selected_theme?" checked":"").'> '.$langs->trans("UsePersonalValue").'</td>';
print '<td '.$bc[$var].'>&nbsp;</td>';
print '</tr>';
2008-11-26 20:37:25 +01:00
}
2009-08-05 19:19:55 +02:00
if (! $foruserprofile)
{
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("ThemeDir").'</td>';
print '<td'.($foruserprofile?' colspan="3"':'').'>'.$dirtheme.'</td>';
print '</tr>';
}
2011-07-19 01:35:06 +02:00
2009-08-05 19:19:55 +02:00
if ($edit)
2008-11-26 20:37:25 +01:00
{
if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive");
else $title=$langs->trans("ShowPreview");
}
2009-08-05 19:19:55 +02:00
2008-11-26 20:37:25 +01:00
$var=!$var;
print '<tr '.$bc[$var].'><td colspan="'.$colspan.'">';
print '<table class="nobordernopadding" width="100%">';
2008-11-26 20:37:25 +01:00
$handle=opendir($dirtheme);
$i=0;
while (($subdir = readdir($handle))!==false)
{
if (is_dir($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.'
2010-04-12 21:11:14 +02:00
&& substr($subdir, 0, 3) <> 'CVS' && ! preg_match('/common|phones/i',$subdir))
2008-11-26 20:37:25 +01:00
{
2011-01-04 01:23:23 +01:00
// Disable not stable themes
2011-08-18 10:25:09 +02:00
//if ($conf->global->MAIN_FEATURES_LEVEL < 1 && preg_match('/bureau2crea/i',$subdir)) continue;
2011-01-25 00:35:21 +01:00
2008-11-26 20:37:25 +01:00
if ($i % $thumbsbyrow == 0)
{
print '<tr '.$bc[$var].'>';
}
2009-08-05 19:19:55 +02:00
2008-11-26 20:37:25 +01:00
print '<td align="center">';
$file=$dirtheme."/".$subdir."/thumb.png";
$url=$urltheme."/".$subdir."/thumb.png";
if (! file_exists($file)) $url=$urltheme."/common/nophoto.jpg";
2008-11-26 20:37:25 +01:00
print '<table><tr><td>';
print '<a href="'.$_SERVER["PHP_SELF"].($edit?'?action=edit&theme=':'?theme=').$subdir.(! empty($_GET["optioncss"])?'&optioncss='.$_GET["optioncss"]:'').($fuser?'&id='.$fuser->id:'').'" style="font-weight: normal;" alt="'.$langs->trans("Preview").'">';
2008-11-26 20:37:25 +01:00
if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive");
else $title=$langs->trans("ShowPreview");
print '<img src="'.$url.'" border="0" width="80" height="60" alt="'.$title.'" title="'.$title.'">';
2008-11-26 20:37:25 +01:00
print '</a>';
print '</td></tr><tr><td align="center">';
if ($subdir == $selected_theme)
{
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" checked name="main_theme" value="'.$subdir.'"> <b>'.$subdir.'</b>';
}
else
{
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" name="main_theme" value="'.$subdir.'"> '.$subdir;
}
print '</td></tr></table></td>';
$i++;
if ($i % $thumbsbyrow == 0) print '</tr>';
}
}
if ($i % $thumbsbyrow != 0)
{
while ($i % $thumbsbyrow != 0)
{
print '<td>&nbsp;</td>';
$i++;
}
print '</tr>';
2009-08-05 19:19:55 +02:00
}
2008-11-26 20:37:25 +01:00
print '</table>';
print '</td></tr>';
print '</table>';
}
?>