2001-12-28 01:59:30 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-08-09 16:30:59 +02:00
|
|
|
* eGroupWare - Preferences *
|
|
|
|
* http://www.egroupware.org *
|
2001-12-28 01:59:30 +01:00
|
|
|
* -------------------------------------------- *
|
|
|
|
* 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. *
|
|
|
|
\**************************************************************************/
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2001-12-28 01:59:30 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
class uiaclprefs
|
|
|
|
{
|
|
|
|
var $acl;
|
|
|
|
var $template;
|
|
|
|
|
|
|
|
var $public_functions = array('index' => True);
|
|
|
|
|
|
|
|
function uiaclprefs()
|
|
|
|
{
|
2005-10-14 16:31:35 +02:00
|
|
|
$GLOBALS['egw']->nextmatchs =& CreateObject('phpgwapi.nextmatchs');
|
2005-07-09 21:07:16 +02:00
|
|
|
|
|
|
|
if (!is_object($GLOBALS['egw']->html))
|
2004-08-28 15:41:23 +02:00
|
|
|
{
|
2005-10-14 16:31:35 +02:00
|
|
|
$GLOBALS['egw']->html =& CreateObject('phpgwapi.html');
|
2004-08-28 15:41:23 +02:00
|
|
|
}
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function index()
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$acl_app = get_var('acl_app',array('POST','GET'));
|
2004-08-31 11:33:08 +02:00
|
|
|
$start = get_var('start',array('POST','GET'),0);
|
2003-08-28 16:31:11 +02:00
|
|
|
$query = get_var('query',array('POST','GET'));
|
2005-07-09 21:07:16 +02:00
|
|
|
$owner = get_var('owner',array('POST','GET'),$GLOBALS['egw_info']['user']['account_id']);
|
2001-12-28 01:59:30 +01:00
|
|
|
|
2004-08-28 15:41:23 +02:00
|
|
|
if (!$acl_app)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$acl_app = 'preferences';
|
2002-06-18 03:13:43 +02:00
|
|
|
$acl_app_not_passed = True;
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
2003-04-20 22:47:50 +02:00
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->translation->add_app($acl_app);
|
2003-04-20 22:47:50 +02:00
|
|
|
}
|
2005-11-08 12:40:35 +01:00
|
|
|
// make acl called via sidebox menu of an app, to behave like a part of that app
|
|
|
|
$referer = $_POST['referer'];
|
|
|
|
if (!$referer)
|
|
|
|
{
|
|
|
|
list(,$referer) = explode($GLOBALS['egw_info']['server']['webserver_url'],$_SERVER['HTTP_REFERER']);
|
|
|
|
if (!$referer) $referer = '/preferences/index.php';
|
|
|
|
}
|
|
|
|
//echo '<p align="right">'."referer='$referer'</p>\n";
|
2001-12-28 01:59:30 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['currentapp'] = $acl_app;
|
2001-12-28 01:59:30 +01:00
|
|
|
|
|
|
|
if ($acl_app_not_passed)
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
if(is_object($GLOBALS['egw']->log))
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->log->message(array(
|
2001-12-28 01:59:30 +01:00
|
|
|
'text' => 'F-BadmenuactionVariable, failed to pass acl_app.',
|
|
|
|
'line' => __LINE__,
|
|
|
|
'file' => __FILE__
|
|
|
|
));
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw']->log->commit();
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
if (($GLOBALS['egw_info']['server']['deny_user_grants_access'] || $owner != $GLOBALS['egw_info']['user']['account_id'])
|
|
|
|
&& !isset($GLOBALS['egw_info']['user']['apps']['admin']) || $acl_app_not_passed)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2005-10-14 16:31:35 +02:00
|
|
|
$GLOBALS['egw']->common->egw_header();
|
2004-08-31 11:33:08 +02:00
|
|
|
echo parse_navbar();
|
2001-12-28 01:59:30 +01:00
|
|
|
echo '<center><b>' . lang('Access not permitted') . '</b></center>';
|
2005-10-14 16:31:35 +02:00
|
|
|
$GLOBALS['egw']->common->egw_footer();
|
2004-08-31 11:33:08 +02:00
|
|
|
return;
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
|
|
|
|
2005-11-08 12:40:35 +01:00
|
|
|
$owner_name = $GLOBALS['egw']->common->grab_owner_name($owner);
|
|
|
|
if($no_privat_grants = $GLOBALS['egw']->accounts->get_type($owner) != 'g')
|
2004-08-28 15:41:23 +02:00
|
|
|
{
|
2005-11-08 12:40:35 +01:00
|
|
|
// admin setting acl-rights is handled as with group-rights => no private grants !!
|
2005-07-09 21:07:16 +02:00
|
|
|
$no_privat_grants = $owner != $GLOBALS['egw_info']['user']['account_id'];
|
2004-08-28 15:41:23 +02:00
|
|
|
}
|
2005-10-14 16:31:35 +02:00
|
|
|
$this->acl =& CreateObject('phpgwapi.acl',(int)$owner);
|
2001-12-28 01:59:30 +01:00
|
|
|
$this->acl->read_repository();
|
|
|
|
|
2005-11-08 12:40:35 +01:00
|
|
|
if ($_POST['save'] || $_POST['apply'])
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$processed = $_POST['processed'];
|
2001-12-28 01:59:30 +01:00
|
|
|
$to_remove = unserialize(urldecode($processed));
|
2004-08-31 11:33:08 +02:00
|
|
|
foreach($to_remove as $uid)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
//echo "deleting acl-records for $uid=".$GLOBALS['egw']->accounts->id2name($uid)." and $acl_app<br>\n";
|
2004-08-31 11:33:08 +02:00
|
|
|
$this->acl->delete($acl_app,$uid);
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Group records */
|
2004-08-28 15:41:23 +02:00
|
|
|
$totalacl = array();
|
2005-07-09 21:07:16 +02:00
|
|
|
$group_variable = $_POST['g_'.$GLOBALS['egw_info']['flags']['currentapp']];
|
2001-12-28 01:59:30 +01:00
|
|
|
|
2004-08-28 15:41:23 +02:00
|
|
|
if (is_array($group_variable))
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2004-08-28 15:41:23 +02:00
|
|
|
foreach($group_variable as $rowinfo => $perm)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2004-08-28 15:41:23 +02:00
|
|
|
list($group_id,$rights) = explode('_',$rowinfo);
|
|
|
|
$totalacl[$group_id] += $rights;
|
|
|
|
}
|
|
|
|
foreach($totalacl as $group_id => $rights)
|
|
|
|
{
|
|
|
|
if($no_privat_grants)
|
|
|
|
{
|
|
|
|
/* Don't allow group-grants or admin to grant private */
|
2005-07-09 21:07:16 +02:00
|
|
|
$rights &= ~EGW_ACL_PRIVATE;
|
2004-08-28 15:41:23 +02:00
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
//echo "adding acl-rights $rights for $group_id=".$GLOBALS['egw']->accounts->id2name($group_id)." and $acl_app<br>\n";
|
|
|
|
$this->acl->add($GLOBALS['egw_info']['flags']['currentapp'],$group_id,$rights);
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* User records */
|
2004-08-28 15:41:23 +02:00
|
|
|
$totalacl = array();
|
2005-07-09 21:07:16 +02:00
|
|
|
$user_variable = $_POST['u_'.$GLOBALS['egw_info']['flags']['currentapp']];
|
2001-12-28 01:59:30 +01:00
|
|
|
|
2004-08-28 15:41:23 +02:00
|
|
|
if (is_array($user_variable))
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2004-08-28 15:41:23 +02:00
|
|
|
foreach($user_variable as $rowinfo => $perm)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2004-08-31 11:33:08 +02:00
|
|
|
list($user_id,$rights) = explode('_',$rowinfo);
|
2004-08-28 15:41:23 +02:00
|
|
|
$totalacl[$user_id] += $rights;
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
2004-08-28 15:41:23 +02:00
|
|
|
foreach($totalacl as $user_id => $rights)
|
|
|
|
{
|
|
|
|
if($no_privat_grants)
|
|
|
|
{
|
|
|
|
/* Don't allow group-grants or admin to grant private */
|
2005-07-09 21:07:16 +02:00
|
|
|
$rights &= ~ EGW_ACL_PRIVATE;
|
2004-08-28 15:41:23 +02:00
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
//echo "adding acl-rights $rights for $user_id=".$GLOBALS['egw']->accounts->id2name($user_id)." and $acl_app<br>\n";
|
|
|
|
$this->acl->add($GLOBALS['egw_info']['flags']['currentapp'],$user_id,$rights);
|
2004-08-28 15:41:23 +02:00
|
|
|
}
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
2004-08-31 11:33:08 +02:00
|
|
|
$this->acl->save_repository();
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
2005-11-08 12:40:35 +01:00
|
|
|
if ($_POST['save'] || $_POST['cancel'])
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->redirect_link($referer);
|
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('%1 - Preferences',$GLOBALS['egw_info']['apps'][$acl_app]['title']).' - '.lang('acl').': '.$owner_name;
|
2005-10-14 16:31:35 +02:00
|
|
|
$GLOBALS['egw']->common->egw_header();
|
2003-08-28 16:31:11 +02:00
|
|
|
echo parse_navbar();
|
2001-12-28 01:59:30 +01:00
|
|
|
|
2005-10-14 16:31:35 +02:00
|
|
|
$this->template =& CreateObject('phpgwapi.Template',$GLOBALS['egw']->common->get_tpl_dir($acl_app));
|
2001-12-28 01:59:30 +01:00
|
|
|
$templates = Array (
|
2005-11-08 12:40:35 +01:00
|
|
|
'preferences' => '../../../preferences/templates/default/acl.tpl',
|
2001-12-28 01:59:30 +01:00
|
|
|
'row_colspan' => 'preference_colspan.tpl',
|
|
|
|
'acl_row' => 'preference_acl_row.tpl'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->template->set_file($templates);
|
|
|
|
|
|
|
|
if ($submit)
|
|
|
|
{
|
|
|
|
$this->template->set_var('errors',lang('ACL grants have been updated'));
|
|
|
|
}
|
|
|
|
|
2004-08-28 15:41:23 +02:00
|
|
|
$common_hidden_vars = array(
|
|
|
|
'start' => $start,
|
|
|
|
'query' => $query,
|
|
|
|
'owner' => $owner,
|
|
|
|
'acl_app' => $acl_app,
|
2005-11-08 12:40:35 +01:00
|
|
|
'referer' => $referer,
|
2004-08-28 15:41:23 +02:00
|
|
|
);
|
2001-12-28 01:59:30 +01:00
|
|
|
$var = Array(
|
|
|
|
'errors' => '',
|
2003-04-20 22:47:50 +02:00
|
|
|
'title' => '<br>',
|
2005-07-09 21:07:16 +02:00
|
|
|
'action_url' => $GLOBALS['egw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app=' . $acl_app),
|
|
|
|
'bg_color' => $GLOBALS['egw_info']['theme']['th_bg'],
|
2005-11-08 12:40:35 +01:00
|
|
|
'lang_save' => lang('Save'),
|
|
|
|
'lang_apply' => lang('Apply'),
|
|
|
|
'lang_cancel' => lang('Cancel'),
|
2005-07-09 21:07:16 +02:00
|
|
|
'common_hidden_vars_form' => $GLOBALS['egw']->html->input_hidden($common_hidden_vars)
|
2001-12-28 01:59:30 +01:00
|
|
|
);
|
|
|
|
$this->template->set_var($var);
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
$vars = $this->template->get_undefined('row_colspan');
|
2004-08-28 15:41:23 +02:00
|
|
|
foreach($vars as $var)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2003-12-20 19:54:18 +01:00
|
|
|
if(strstr($var,'lang_'))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2003-12-20 19:54:18 +01:00
|
|
|
$value = str_replace('lang_','',$var);
|
|
|
|
$value = str_replace('_',' ',$value);
|
2001-12-28 01:59:30 +01:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->template->set_var($var,lang($value));
|
|
|
|
}
|
|
|
|
}
|
2001-12-28 01:59:30 +01:00
|
|
|
|
2005-07-09 21:07:16 +02:00
|
|
|
$accounts = $GLOBALS['egw']->accounts->search(array(
|
2004-08-28 15:41:23 +02:00
|
|
|
'type' => 'both',
|
|
|
|
'start' => $start,
|
|
|
|
'query' => $query,
|
|
|
|
'order' => 'account_type,account_lid',
|
|
|
|
'sort' => 'ASC',
|
|
|
|
));
|
2005-07-09 21:07:16 +02:00
|
|
|
$totalentries = $GLOBALS['egw']->accounts->total;
|
|
|
|
|
2005-11-08 12:40:35 +01:00
|
|
|
$memberships = (array) $GLOBALS['egw']->accounts->membership($owner);
|
2004-08-31 11:33:08 +02:00
|
|
|
|
2004-08-28 15:41:23 +02:00
|
|
|
$header_type = '';
|
|
|
|
$processed = Array();
|
|
|
|
foreach($accounts as $uid => $data)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2004-09-02 18:00:49 +02:00
|
|
|
if ($data['account_type'] == 'u' && $uid == $owner)
|
|
|
|
continue; /* no need to grant to self if user */
|
2001-12-28 01:59:30 +01:00
|
|
|
|
2004-08-28 15:41:23 +02:00
|
|
|
if ($data['account_type'] != $header_type)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2004-08-28 15:41:23 +02:00
|
|
|
$this->template->set_var('string',$data['account_type'] == 'g' ? lang('Groups') : lang('Users'));
|
|
|
|
$this->template->parse('row','row_colspan',True);
|
|
|
|
$header_type = $data['account_type'];
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
$tr_class = $GLOBALS['egw']->nextmatchs->alternate_row_color($tr_color,true);
|
2001-12-28 01:59:30 +01:00
|
|
|
|
2004-08-28 15:41:23 +02:00
|
|
|
if ($data['account_type'] == 'g')
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2005-05-21 20:25:08 +02:00
|
|
|
$this->display_row($tr_class,'g_',$data['account_id'],$data['account_lid'],$no_privat_grants,$memberships);
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
2004-08-28 15:41:23 +02:00
|
|
|
else
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$this->display_row($tr_class,'u_',$data['account_id'],$GLOBALS['egw']->common->display_fullname($data['account_lid'],$data['account_firstname'],$data['account_lastname']),$no_privat_grants,$memberships);
|
2004-08-28 15:41:23 +02:00
|
|
|
}
|
|
|
|
$processed[] = $uid;
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
|
|
|
|
2004-08-28 15:41:23 +02:00
|
|
|
$extra_parms = array(
|
|
|
|
'menuaction' => 'preferences.uiaclprefs.index',
|
|
|
|
'acl_app' => $acl_app,
|
|
|
|
'owner' => $owner,
|
2005-11-08 12:40:35 +01:00
|
|
|
'referer' => $referer,
|
2004-08-28 15:41:23 +02:00
|
|
|
);
|
2001-12-28 01:59:30 +01:00
|
|
|
|
|
|
|
$var = Array(
|
2005-07-09 21:07:16 +02:00
|
|
|
'nml' => $GLOBALS['egw']->nextmatchs->left('/index.php',$start,$totalentries,$extra_parms),
|
|
|
|
'nmr' => $GLOBALS['egw']->nextmatchs->right('/index.php',$start,$totalentries,$extra_parms),
|
|
|
|
'search_value' => isset($query) && $query ? $GLOBALS['egw']->html->htmlspecialchars($query) : '',
|
2001-12-28 01:59:30 +01:00
|
|
|
'search' => lang('search'),
|
|
|
|
'processed' => urlencode(serialize($processed))
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->template->set_var($var);
|
|
|
|
|
|
|
|
$this->template->pfp('out','preferences');
|
|
|
|
}
|
|
|
|
|
2004-08-28 15:41:23 +02:00
|
|
|
function check_acl($label,$id,$acl,$rights,$right,$disabled=False)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$this->template->set_var($acl,$label.$GLOBALS['egw_info']['flags']['currentapp'].'['.$id.'_'.$right.']');
|
2004-08-28 15:41:23 +02:00
|
|
|
$rights_set = ($rights & $right) ? ' checked="1"' : '';
|
|
|
|
if ($disabled)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
|
|
|
// This is so you can't select it in the GUI
|
2004-08-28 15:41:23 +02:00
|
|
|
$rights_set .= ' disabled="1"';
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
|
|
|
$this->template->set_var($acl.'_selected',$rights_set);
|
|
|
|
}
|
|
|
|
|
2005-05-21 20:25:08 +02:00
|
|
|
function display_row($tr_class,$label,$id,$name,$no_privat_grants,$memberships)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2005-05-21 20:25:08 +02:00
|
|
|
$this->template->set_var('row_class',$tr_class);
|
2005-07-09 21:07:16 +02:00
|
|
|
$this->template->set_var('row_color',$GLOBALS['egw_info']['theme'][$tr_class]);
|
2001-12-28 01:59:30 +01:00
|
|
|
$this->template->set_var('user',$name);
|
2005-07-09 21:07:16 +02:00
|
|
|
$rights = $this->acl->get_rights($id,$GLOBALS['egw_info']['flags']['currentapp']);
|
|
|
|
$is_group = $GLOBALS['egw']->accounts->get_type($id) == 'g';
|
2004-08-31 11:33:08 +02:00
|
|
|
|
|
|
|
foreach(array(
|
2005-07-09 21:07:16 +02:00
|
|
|
EGW_ACL_READ => 'read',
|
|
|
|
EGW_ACL_ADD => 'add',
|
|
|
|
EGW_ACL_EDIT => 'edit',
|
|
|
|
EGW_ACL_DELETE => 'delete',
|
|
|
|
EGW_ACL_PRIVATE => 'private',
|
|
|
|
EGW_ACL_CUSTOM_1 => 'custom_1',
|
|
|
|
EGW_ACL_CUSTOM_2 => 'custom_2',
|
|
|
|
EGW_ACL_CUSTOM_3 => 'custom_3',
|
2004-08-31 11:33:08 +02:00
|
|
|
) as $right => $name)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2004-08-31 11:33:08 +02:00
|
|
|
$is_group_set = False;
|
|
|
|
if ($is_group)
|
2001-12-28 01:59:30 +01:00
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
$grantors = $this->acl->get_ids_for_location($id,$right,$GLOBALS['egw_info']['flags']['currentapp']);
|
2004-08-31 11:33:08 +02:00
|
|
|
if (is_array($grantors))
|
2004-08-28 15:41:23 +02:00
|
|
|
{
|
2004-08-31 11:33:08 +02:00
|
|
|
foreach($grantors as $grantor)
|
|
|
|
{
|
2005-07-09 21:07:16 +02:00
|
|
|
//echo $GLOBALS['egw']->accounts->id2name($id)."=$id: $name-grant from ".$GLOBALS['egw']->accounts->id2name($grantor)."=$grantor<br>\n";
|
2004-08-31 11:33:08 +02:00
|
|
|
// check if the grant comes from a group, the owner is a member off, in that case he is NOT allowed to remove it
|
|
|
|
if(in_array($grantor,$memberships))
|
|
|
|
{
|
|
|
|
//echo "==> member of ==> set by group<br>";
|
|
|
|
$is_group_set = True;
|
|
|
|
}
|
|
|
|
}
|
2004-08-28 15:41:23 +02:00
|
|
|
}
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
2005-07-09 21:07:16 +02:00
|
|
|
$this->check_acl($label,$id,$name,$rights,$right,$is_group_set || $no_privat_grants && $right == EGW_ACL_PRIVATE);
|
2001-12-28 01:59:30 +01:00
|
|
|
}
|
|
|
|
$this->template->parse('row','acl_row',True);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|