porting admin to xslt

This commit is contained in:
ceb 2003-04-23 21:52:22 +00:00
parent fb2360c3d5
commit bf3affb467
5 changed files with 382 additions and 145 deletions

View File

@ -78,6 +78,24 @@
}
}
function check_rights($action, $access = 'group_access')
{
switch($action)
{
case 'view': $right = '8'; break;
case 'add': $right = '4'; break;
case 'edit': $right = '16'; break;
case 'delete': $right = '32'; break;
case 'search': $right = '2'; break;
}
if (!$GLOBALS['phpgw']->acl->check($access,$right,'admin'))
{
return True;
}
return False;
}
function delete_group($account_id)
{
if ($GLOBALS['phpgw']->acl->check('group_access',32,'admin'))

View File

@ -65,6 +65,8 @@
$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'search_field',
$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'nextmatchs'));
/* what should this be for??? this is the same call for both cases! can this be removed? [ceb] */
if ($GLOBALS['phpgw']->acl->check('group_access',2,'admin'))
{
$account_info = $GLOBALS['phpgw']->accounts->get_list('groups',$start,$sort, $order, $query, $total);
@ -91,40 +93,20 @@
'lang_sort_statustext' => lang('sort the entries')
);
if (! $GLOBALS['phpgw']->acl->check('group_access',8,'admin'))
{
$can_view = True;
}
if (! $GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
{
$can_edit = True;
}
if (! $GLOBALS['phpgw']->acl->check('group_access',32,'admin'))
{
$can_delete = True;
}
while (list($null,$account) = each($account_info))
{
$group_data[] = Array
(
'edit_url' => ($can_edit?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.edit_group&account_id=' . $account['account_id']):''),
'lang_edit' => ($can_edit?lang('edit'):''),
'lang_edit_statustext' => ($can_edit?lang('edit this group'):''),
'edit_url' => ($this->bo->check_rights('edit')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.edit_group&account_id=' . $account['account_id']):''),
'lang_edit' => ($this->bo->check_rights('edit')?lang('edit'):''),
'lang_edit_statustext' => ($this->bo->check_rights('edit')?lang('edit this group'):''),
'group_name' => (!$account['account_lid']?'':$account['account_lid']),
'delete_url' => ($can_delete?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.delete_group&account_id=' . $account['account_id']):''),
'lang_delete_statustext' => ($can_delete?lang('delete this group'):''),
'lang_delete' => ($can_delete?lang('delete'):'')
'delete_url' => ($this->bo->check_rights('delete')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.delete_group&account_id=' . $account['account_id']):''),
'lang_delete_statustext' => ($this->bo->check_rights('delete')?lang('delete this group'):''),
'lang_delete' => ($this->bo->check_rights('delete')?lang('delete'):'')
);
}
if (! $GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
{
$add_access = 'yes';
}
$group_add = array
(
'lang_add' => lang('add'),
@ -133,14 +115,9 @@
'lang_done' => lang('done'),
'lang_done_statustext' => lang('return to admin mainscreen'),
'done_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uimainscreen.mainscreen'),
'add_access' => $add_access,
'add_access' => ($this->bo->check_rights('add')?'yes':''),
);
if (! $GLOBALS['phpgw']->acl->check('group_access',2,'admin'))
{
$search_access = 'yes';
}
$data = array
(
'start_record' => $start,
@ -154,11 +131,10 @@
'lang_searchbutton_statustext' => lang('Submit the search string'),
'query' => $query,
'lang_search' => lang('search'),
'lang_groups' => lang('user groups'),
'group_header' => $group_header,
'group_data' => $group_data,
'group_add' => $group_add,
'search_access' => $search_access
'search_access' => ($this->bo->check_rights('search')?'yes':'')
);
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('group_list' => $data));
}
@ -196,20 +172,13 @@
$sort = 'ASC';
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
$GLOBALS['phpgw']->common->phpgw_header();
$GLOBALS['phpgw_info']['flags']['app_header'] = lang('administration') . ': ' . lang('list users');
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$GLOBALS['phpgw']->xslttpl->add_file(array('app_data','users',
$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'search_field',
$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'nextmatchs'));
$p->set_file(
Array(
'accounts' => 'accounts.tpl'
)
);
$p->set_block('accounts','list','list');
$p->set_block('accounts','row','row');
$p->set_block('accounts','row_empty','row_empty');
/* the same like in groups... we really should remove this... :) [ceb] */
if ($GLOBALS['phpgw']->acl->check('account_access',2,'admin'))
{
@ -222,101 +191,87 @@
$total = $GLOBALS['phpgw']->accounts->total;
}
$url = $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users');
$var = Array(
'bg_color' => $GLOBALS['phpgw_info']['theme']['bg_color'],
'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
'left_next_matchs' => $this->nextmatchs->left($url,$start,$total,'menuaction=admin.uiaccounts.list_users'),
'lang_user_accounts' => lang('user accounts'),
'right_next_matchs' => $this->nextmatchs->right($url,$start,$total,'menuaction=admin.uiaccounts.list_users'),
'lang_loginid' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,$url,lang('LoginID')),
'lang_lastname' => $this->nextmatchs->show_sort_order($sort,'account_lastname',$order,$url,lang('last name')),
'lang_firstname' => $this->nextmatchs->show_sort_order($sort,'account_firstname',$order,$url,lang('first name')),
$user_header = array
(
'sort_lid' => $this->nextmatchs->show_sort_order(array
(
'sort' => $sort,
'var' => 'account_lid',
'order' => $order,
'extra' => 'menuaction=admin.uiaccounts.list_users'
)),
'lang_lid' => lang('loginid'),
'sort_lastname' => $this->nextmatchs->show_sort_order(array
(
'sort' => $sort,
'var' => 'account_lastname',
'order' => $order,
'extra' => 'menuaction=admin.uiaccounts.list_users'
)),
'lang_lastname' => lang('Lastname'),
'sort_firstname' => $this->nextmatchs->show_sort_order(array
(
'sort' => $sort,
'var' => 'account_firstname',
'order' => $order,
'extra' => 'menuaction=admin.uiaccounts.list_users'
)),
'lang_firstname' => lang('firstname'),
'lang_view' => lang('view'),
'lang_edit' => lang('edit'),
'lang_delete' => lang('delete'),
'lang_view' => lang('view'),
'actionurl' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.add_user'),
'accounts_url' => $url,
'lang_search' => lang('search'),
'lang_done' => lang('Done'),
'doneurl' => $GLOBALS['phpgw']->link('/admin/index.php')
'lang_sort_statustext' => lang('sort the entries')
);
$p->set_var($var);
if (! $GLOBALS['phpgw']->acl->check('account_access',4,'admin'))
{
$p->set_var('input_add','<input type="submit" value="' . lang('Add') . '">');
}
if (! $GLOBALS['phpgw']->acl->check('account_access',2,'admin'))
{
$p->set_var('input_search',lang('Search') . '&nbsp;<input type="text" name="query">');
}
if (!count($account_info) || !$total)
{
$p->set_var('message',lang('No matches found'));
$p->parse('rows','row_empty',True);
}
else
{
if (! $GLOBALS['phpgw']->acl->check('account_access',8,'admin'))
{
$can_view = True;
}
if (! $GLOBALS['phpgw']->acl->check('account_access',16,'admin'))
{
$can_edit = True;
}
if (! $GLOBALS['phpgw']->acl->check('account_access',32,'admin'))
{
$can_delete = True;
}
while (list($null,$account) = each($account_info))
{
$this->nextmatchs->template_alternate_row_color($p);
$var = array(
'row_loginid' => $account['account_lid'],
'row_firstname' => (!$account['account_firstname']?'&nbsp':$account['account_firstname']),
'row_lastname' => (!$account['account_lastname']?'&nbsp':$account['account_lastname'])
$user_data[] = Array
(
'view_url' => ($this->bo->check_rights('view','account_access')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.view_user&account_id=' . $account['account_id']):''),
'lang_view' => ($this->bo->check_rights('view','account_access')?lang('view'):''),
'lang_view_statustext' => ($this->bo->check_rights('view','account_access')?lang('view this user'):''),
'edit_url' => ($this->bo->check_rights('edit','account_access')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.edit_user&account_id=' . $account['account_id']):''),
'lang_edit' => ($this->bo->check_rights('edit','account_access')?lang('edit'):''),
'lang_edit_statustext' => ($this->bo->check_rights('edit','account_access')?lang('edit this user'):''),
'lid' => (!$account['account_lid']?'':$account['account_lid']),
'firstname' => (!$account['account_firstname']?'':$account['account_firstname']),
'lastname' => (!$account['account_lastname']?'':$account['account_lastname']),
'delete_url' => ($this->bo->check_rights('delete','account_access')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.delete_user&account_id=' . $account['account_id']):''),
'lang_delete_statustext' => ($this->bo->check_rights('delete','account_access')?lang('delete this user'):''),
'lang_delete' => ($this->bo->check_rights('delete','account_access')?lang('delete'):'')
);
$p->set_var($var);
if ($can_edit)
{
$p->set_var('row_edit',$this->row_action('edit','user',$account['account_id']));
}
else
{
$p->set_var('row_edit','&nbsp;');
}
if ($can_delete)
{
$p->set_var('row_delete',($GLOBALS['phpgw_info']['user']['userid'] != $account['account_lid']?$this->row_action('delete','user',$account['account_id']):'&nbsp'));
}
else
{
$p->set_var('row_delete','&nbsp;');
}
$user_add = array
(
'lang_add' => lang('add'),
'lang_add_statustext' => lang('add a user'),
'add_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.edit_user'),
'lang_done' => lang('done'),
'lang_done_statustext' => lang('return to admin mainscreen'),
'done_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uimainscreen.mainscreen'),
'add_access' => ($this->bo->check_rights('add','account_access')?'yes':''),
);
if ($can_view)
{
$p->set_var('row_view',$this->row_action('view','user',$account['account_id']));
}
else
{
$p->set_var('row_view','&nbsp;');
}
$p->parse('rows','row',True);
}
} // End else
$p->pfp('out','list');
$data = array
(
'start_record' => $start,
'record_limit' => $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'],
'num_records' => count($account_info),
'all_records' => $total,
'nextmatchs_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users'),
'nextmatchs_img_path' => $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
'select_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users'),
'lang_searchfield_statustext' => lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'),
'lang_searchbutton_statustext' => lang('Submit the search string'),
'query' => $query,
'lang_search' => lang('search'),
'user_header' => $user_header,
'user_data' => $user_data,
'user_add' => $user_add,
'search_access' => ($this->bo->check_rights('search','account_access')?'yes':'')
);
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('account_list' => $data));
}
function add_user()

View File

@ -8,7 +8,6 @@
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
if (! $GLOBALS['phpgw']->acl->check('site_config_access',1,'admin'))

View File

@ -17,6 +17,9 @@
<xsl:when test="group_edit">
<xsl:call-template name="groups"/>
</xsl:when>
<xsl:when test="account_list">
<xsl:call-template name="users"/>
</xsl:when>
<xsl:when test="delete">
<xsl:call-template name="app_delete"/>
</xsl:when>

View File

@ -0,0 +1,262 @@
<!-- $Id$ -->
<xsl:template name="users">
<xsl:choose>
<xsl:when test="account_list">
<xsl:apply-templates select="account_list"/>
</xsl:when>
<xsl:when test="group_edit">
<xsl:apply-templates select="user_edit"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- BEGIN user_list -->
<xsl:template match="account_list">
<center>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td colspan="6" width="100%">
<xsl:call-template name="nextmatchs"/>
</td>
</tr>
<tr>
<td colspan="6" width="100%" align="right">
<xsl:choose>
<xsl:when test="search_access = 'yes'">
<xsl:call-template name="search_field"/>
</xsl:when>
</xsl:choose>
</td>
</tr>
<xsl:apply-templates select="user_header"/>
<xsl:apply-templates select="user_data"/>
<xsl:apply-templates select="user_add"/>
</table>
</center>
</xsl:template>
<!-- BEGIN user_header -->
<xsl:template match="user_header">
<xsl:variable name="sort_lid" select="sort_lid"/>
<xsl:variable name="sort_firstname" select="sort_firstname"/>
<xsl:variable name="sort_lastname" select="sort_lastname"/>
<xsl:variable name="lang_sort_statustext" select="lang_sort_statustext"/>
<tr class="th">
<td width="20%"><a href="{$sort_lid}" onMouseover="window.status='{$lang_sort_statustext}';return true;" onMouseout="window.status='';return true;" class="th_text"><xsl:value-of select="lang_lid"/></a></td>
<td width="20%"><a href="{$sort_firstname}" onMouseover="window.status='{$lang_sort_statustext}';return true;" onMouseout="window.status='';return true;" class="th_text"><xsl:value-of select="lang_firstname"/></a></td>
<td width="20%"><a href="{$sort_lastname}" onMouseover="window.status='{$lang_sort_statustext}';return true;" onMouseout="window.status='';return true;" class="th_text"><xsl:value-of select="lang_lastname"/></a></td>
<td width="8%" align="center"><xsl:value-of select="lang_view"/></td>
<td width="8%" align="center"><xsl:value-of select="lang_edit"/></td>
<td width="8%" align="center"><xsl:value-of select="lang_delete"/></td>
</tr>
</xsl:template>
<!-- BEGIN user_data -->
<xsl:template match="user_data">
<xsl:variable name="lang_view_statustext"><xsl:value-of select="lang_view_statustext"/></xsl:variable>
<xsl:variable name="lang_edit_statustext"><xsl:value-of select="lang_edit_statustext"/></xsl:variable>
<xsl:variable name="lang_delete_statustext"><xsl:value-of select="lang_delete_statustext"/></xsl:variable>
<tr>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="@class">
<xsl:value-of select="@class"/>
</xsl:when>
<xsl:when test="position() mod 2 = 0">
<xsl:text>row_off</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>row_on</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<td><xsl:value-of select="lid"/></td>
<td><xsl:value-of select="firstname"/></td>
<td><xsl:value-of select="lastname"/></td>
<td align="center">
<xsl:variable name="view_url" select="view_url"/>
<a href="{$view_url}" onMouseover="window.status='{$lang_view_statustext}';return true;" onMouseout="window.status='';return true;" class="th_text"><xsl:value-of select="lang_view"/></a>
</td>
<td align="center">
<xsl:variable name="edit_url" select="edit_url"/>
<a href="{$edit_url}" onMouseover="window.status='{$lang_edit_statustext}';return true;" onMouseout="window.status='';return true;" class="th_text"><xsl:value-of select="lang_edit"/></a>
</td>
<td align="center">
<xsl:variable name="delete_url" select="delete_url"/>
<a href="{$delete_url}" onMouseover="window.status='{$lang_delete_statustext}';return true;" onMouseout="window.status='';return true;" class="th_text"><xsl:value-of select="lang_delete"/></a>
</td>
</tr>
</xsl:template>
<!-- BEGIN user_add -->
<xsl:template match="user_add">
<tr>
<td height="50" valign="bottom">
<xsl:choose>
<xsl:when test="add_access = 'yes'">
<xsl:variable name="add_url"><xsl:value-of select="add_url"/></xsl:variable>
<xsl:variable name="lang_add"><xsl:value-of select="lang_add"/></xsl:variable>
<form method="post" action="{$add_url}">
<input type="submit" name="add" value="{$lang_add}" onMouseout="window.status='';return true;">
<xsl:attribute name="onMouseover">
<xsl:text>window.status='</xsl:text>
<xsl:value-of select="lang_add_statustext"/>
<xsl:text>'; return true;</xsl:text>
</xsl:attribute>
</input>
</form>
</xsl:when>
</xsl:choose>
</td>
</tr>
<tr>
<td height="50" valign="bottom">
<xsl:variable name="done_url"><xsl:value-of select="done_url"/></xsl:variable>
<xsl:variable name="lang_done"><xsl:value-of select="lang_done"/></xsl:variable>
<form method="post" action="{$done_url}">
<input type="submit" name="done" value="{$lang_done}" onMouseout="window.status='';return true;">
<xsl:attribute name="onMouseover">
<xsl:text>window.status='</xsl:text>
<xsl:value-of select="lang_done_statustext"/>
<xsl:text>'; return true;</xsl:text>
</xsl:attribute>
</input>
</form>
</td>
</tr>
</xsl:template>
<!-- END user_list -->
<!-- BEGIN group_edit -->
<xsl:template match="group_edit">
<table border="0" cellpadding="2" cellspacing="2" align="center" width="79%">
<tr>
<td><xsl:value-of select="error"/></td>
</tr>
<tr>
<td valign="top">
<!-- {rows} -->
</td>
<td valign="top">
<table border="0" width="100%">
<xsl:variable name="edit_url"><xsl:value-of select="edit_url"/></xsl:variable>
<xsl:variable name="account_id" select="account_id"/>
<xsl:variable name="select_size" select="select_size"/>
<form action="{$edit_url}" method="POST">
<input type="hidden" name="values[account_id]" value="{$account_id}"/>
<tr>
<td><xsl:value-of select="lang_account_name"/></td>
<td><input name="values[account_name]">
<xsl:attribute name="value">
<xsl:value-of select="value_account_name"/>
</xsl:attribute>
</input>
</td>
</tr>
<tr>
<td><xsl:value-of select="lang_include_user"/></td>
<td>
<select name="account_user[]" multiple="multiple" size="{$select_size}">
<xsl:apply-templates select="user_list"/>
</select>
</td>
</tr>
<tr>
<td><xsl:value-of select="lang_file_space"/></td>
<td>
<!-- {account_file_space}{account_file_space_select} -->
</td>
</tr>
<tr>
<td valign="top"><xsl:value-of select="lang_permissions"/></td>
<td>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr class="th">
<td><xsl:value-of select="lang_application"/></td>
<td>&nbsp;</td>
<td><xsl:value-of select="lang_acl"/></td>
</tr>
<xsl:apply-templates select="app_list"/>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="left">
<xsl:variable name="lang_save"><xsl:value-of select="lang_save"/></xsl:variable>
<input type="submit" name="values[save]" value="{$lang_save}"/>
</td>
</tr>
</form>
<tr>
<xsl:variable name="done_url"><xsl:value-of select="done_url"/></xsl:variable>
<xsl:variable name="lang_done"><xsl:value-of select="lang_done"/></xsl:variable>
<form method="POST" action="{$done_url}">
<td align="left">
<input type="submit" name="done" value="{$lang_done}"/>
</td>
</form>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="user_list">
<xsl:variable name="account_id" select="account_id"/>
<xsl:choose>
<xsl:when test="selected != ''">
<option value="{$account_id}" selected="selected"><xsl:value-of select="account_name"/></option>
</xsl:when>
<xsl:otherwise>
<option value="{$account_id}"><xsl:value-of select="account_name"/></option>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="app_list">
<xsl:variable name="checkbox_name" select="checkbox_name"/>
<tr>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="@class">
<xsl:value-of select="@class"/>
</xsl:when>
<xsl:when test="position() mod 2 = 0">
<xsl:text>row_off</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>row_on</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<td width="40%"><xsl:value-of select="app_name"/></td>
<td width="5%" align="center">
<xsl:choose>
<xsl:when test="checked != ''">
<input type="checkbox" name="{$checkbox_name}" value="True" checked="checked"/>
</xsl:when>
<xsl:otherwise>
<input type="checkbox" name="{$checkbox_name}" value="True"/>
</xsl:otherwise>
</xsl:choose>
</td>
<td width="5%" align="center">
<xsl:choose>
<xsl:when test="acl_url != ''">
<xsl:variable name="acl_url" select="acl_url"/>
<xsl:variable name="acl_img" select="acl_img"/>
<xsl:variable name="img_name" select="img_name"/>
<a href="{$acl_url}"><img src="{$acl_img}" border="0" hspace="3" align="absmiddle" alt="{$img_name}" name="{$img_name}"/></a>
</xsl:when>
</xsl:choose>
</td>
</tr>
</xsl:template>