Cleaned up the preferences section, its now split into seperate sections (using tabs) for admins. User, default and forced

This commit is contained in:
jengo 2001-09-03 23:01:42 +00:00
parent 4234adb5df
commit 3c633fcbc1
4 changed files with 207 additions and 114 deletions

View File

@ -28,11 +28,59 @@
$pref_tpl->set_block('pref','link_row'); $pref_tpl->set_block('pref','link_row');
$pref_tpl->set_block('pref','spacer_row'); $pref_tpl->set_block('pref','spacer_row');
if ($phpgw->acl->check('run',1,'admin'))
{
// This is where we will keep track of our postion.
// Developers won't have to pass around a variable then
$session_data = $phpgw->session->appsession('session_data','preferences');
if (! is_array($session_data))
{
$session_data = array(
'type' => 'user'
);
$phpgw->session->appsession('session_data','preferences',$session_data);
}
if (! $GLOBALS['type'])
{
$type = $session_data['type'];
}
else
{
$session_data = array(
'type' => $GLOBALS['type']
);
$phpgw->session->appsession('session_data','preferences',$session_data);
}
$tabs[] = array(
'label' => 'Your preferences',
'link' => $phpgw->link('/preferences/index.php','type=user')
);
$tabs[] = array(
'label' => 'Default preferences',
'link' => $phpgw->link('/preferences/index.php','type=default')
);
$tabs[] = array(
'label' => 'Forced preferences',
'link' => $phpgw->link('/preferences/index.php','type=forced')
);
switch($type)
{
case 'user': $selected = 0; break;
case 'default': $selected = 1; break;
case 'forced': $selected = 2; break;
}
$pref_tpl->set_var('tabs',$phpgw->common->create_tabs($tabs,$selected));
}
// This func called by the includes to dump a row header // This func called by the includes to dump a row header
function section_start($name='',$icon='',$appname='') function section_start($name='',$icon='',$appname='')
{ {
global $phpgw_info, $pref_tpl; global $phpgw_info, $pref_tpl;
$pref_tpl->set_var('icon_backcolor',$phpgw_info['theme']['row_off']); $pref_tpl->set_var('icon_backcolor',$phpgw_info['theme']['row_off']);
// $pref_tpl->set_var('link_backcolor',$phpgw_info['theme']['row_off']); // $pref_tpl->set_var('link_backcolor',$phpgw_info['theme']['row_off']);
$pref_tpl->set_var('a_name',$appname); $pref_tpl->set_var('a_name',$appname);
@ -60,7 +108,7 @@
function section_end() function section_end()
{ {
global $pref_tpl; global $pref_tpl;
$pref_tpl->parse('rows','spacer_row',True); $pref_tpl->parse('rows','spacer_row',True);
} }
@ -76,7 +124,7 @@
section_end(); section_end();
} }
$phpgw->common->hook('preferences'); $phpgw->common->hook('preferences',array('preferences'));
$pref_tpl->pparse('out','list'); $pref_tpl->pfp('out','list');
$phpgw->common->phpgw_footer(); $phpgw->common->phpgw_footer();
?> ?>

View File

@ -29,6 +29,17 @@
Header('Location: ' . $GLOBALS['phpgw']->link('/preferences/index.php')); Header('Location: ' . $GLOBALS['phpgw']->link('/preferences/index.php'));
} }
$t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('preferences'));
$t->set_file(array(
'_preferences' => 'preferences.tpl'
));
$t->set_block('_preferences','list');
$t->set_block('_preferences','row');
$t->set_block('_preferences','header');
$t->set_block('_preferences','footer');
$t->set_block('_preferences','row_error');
// Make things a little easier to follow // Make things a little easier to follow
// Some places we will need to change this if there in common // Some places we will need to change this if there in common
function check_app($appname) function check_app($appname)
@ -43,23 +54,9 @@
} }
} }
function parse_row(&$tpl)
{
if (is_admin())
{
$tpl->fp('rows','row_a',True);
}
else
{
$tpl->fp('rows','row_u',True);
}
}
function is_forced_value($appname,$preference_name) function is_forced_value($appname,$preference_name)
{ {
global $gp; if ($GLOBALS['gp']->data[$appname][$preference_name] && $GLOBALS['type'] != 'forced')
if ($gp->data[$appname][$preference_name])
{ {
return True; return True;
} }
@ -72,25 +69,28 @@
function create_input_box($label_name,$preference_name,$size = '',$max_size = '') function create_input_box($label_name,$preference_name,$size = '',$max_size = '')
{ {
global $appname, $t, $dp, $gp; global $appname, $t, $dp, $gp;
$_appname = check_app($appname); $_appname = check_app($appname);
$GLOBALS['phpgw']->nextmatchs->template_alternate_row_color(&$t); $GLOBALS['phpgw']->nextmatchs->template_alternate_row_color(&$t);
$t->set_var('row_name',lang($label_name)); $t->set_var('row_name',lang($label_name));
if (! is_forced_value($_appname,$preference_name))
if (is_forced_value($_appname,$preference_name))
{ {
$t->set_var('row_user','<input name="user[' . $preference_name . ']" value="' . $GLOBALS['phpgw_info']['user']['preferences'][$_appname][$preference_name] . '">'); return True;
} }
else
switch ($GLOBALS['type'])
{ {
$t->set_var('row_user','&nbsp;'); case 'user': $s = '<input name="user[' . $preference_name . ']" value="' . $GLOBALS['phpgw_info']['user']['preferences'][$_appname][$preference_name] . '">';
break;
case 'default': $s = '<input name="default[' . $preference_name . ']" value="' . $dp->data[$_appname][$preference_name] . '">';
break;
case 'forced': $s = '<input name="forced[' . $preference_name . ']" value="' . $gp->data[$_appname][$preference_name] . '">';
break;
} }
if (is_admin()) $t->set_var('row_value',$s);
{
$t->set_var('row_global','<input name="global[' . $preference_name . ']" value="' . $gp->data[$_appname][$preference_name] . '">'); $t->fp('rows','row',True);
$t->set_var('row_default','<input name="default[' . $preference_name . ']" value="' . $dp->data[$_appname][$preference_name] . '">');
}
parse_row(&$t);
} }
function create_option_string($selected,$values) function create_option_string($selected,$values)
@ -113,31 +113,35 @@
$_appname = check_app($appname); $_appname = check_app($appname);
if (is_forced_value($_appname,$preference_name))
{
return True;
}
$GLOBALS['phpgw']->nextmatchs->template_alternate_row_color(&$t); $GLOBALS['phpgw']->nextmatchs->template_alternate_row_color(&$t);
$t->set_var('row_name',lang($label_name)); $t->set_var('row_name',lang($label_name));
if (! is_forced_value($_appname,$preference_name))
switch ($GLOBALS['type'])
{ {
$s = '<option value="">' . lang('Select one') . '</option>' case 'user':
. create_option_string($GLOBALS['phpgw_info']['user']['preferences'][$_appname][$preference_name],$values); $s = '<option value="">' . lang('Select one') . '</option>'
$t->set_var('row_user','<select name="user[' . $preference_name . ']">' . $s . '</select>'); . create_option_string($GLOBALS['phpgw_info']['user']['preferences'][$_appname][$preference_name],$values);
} $t->set_var('row_value','<select name="user[' . $preference_name . ']">' . $s . '</select>');
else break;
{ case 'default':
$t->set_var('row_user','&nbsp;'); $s = '<option value="">' . lang('Select one') . '</option>'
. create_option_string($dp->data[$_appname][$preference_name],$values);
$t->set_var('row_value','<select name="default[' . $preference_name . ']">' . $s . '</select>');
break;
case 'forced':
$s = '<option value="**NULL**">' . lang('Users choice') . '</option>'
. create_option_string($gp->data[$_appname][$preference_name],$values);
$t->set_var('row_value','<select name="forced[' . $preference_name . ']">' . $s . '</select>');
break;
} }
if (is_admin()) $t->fp('rows','row',True);
{
$s = '<option value="**NULL**">' . lang('Users choice') . '</option>'
. create_option_string($gp->data[$_appname][$preference_name],$values);
$t->set_var('row_global','<select name="global[' . $preference_name . ']">' . $s . '</select>');
$s = '<option value="">' . lang('Select one') . '</option>'
. create_option_string($dp->data[$_appname][$preference_name],$values);
$t->set_var('row_default','<select name="default[' . $preference_name . ']">' . $s . '</select>');
}
parse_row(&$t);
} }
function process_array(&$_p, $array) function process_array(&$_p, $array)
@ -173,11 +177,69 @@
{ {
// Don't use a global variable for this ... // Don't use a global variable for this ...
define('HAS_ADMIN_RIGHTS',1); define('HAS_ADMIN_RIGHTS',1);
}
if (is_admin())
{
// This is where we will keep track of our postion.
// Developers won't have to pass around a variable then
$session_data = $phpgw->session->appsession('session_data','preferences');
if (! is_array($session_data))
{
$session_data = array(
'type' => 'user'
);
$phpgw->session->appsession('session_data','preferences',$session_data);
}
if (! $GLOBALS['type'])
{
$type = $session_data['type'];
}
else
{
$session_data = array(
'type' => $GLOBALS['type']
);
$phpgw->session->appsession('session_data','preferences',$session_data);
}
$tabs[] = array(
'label' => 'Your preferences',
'link' => $phpgw->link('/preferences/preferences.php','appname=' . $appname . '&type=user')
);
$tabs[] = array(
'label' => 'Default preferences',
'link' => $phpgw->link('/preferences/preferences.php','appname=' . $appname . '&type=default')
);
$tabs[] = array(
'label' => 'Forced preferences',
'link' => $phpgw->link('/preferences/preferences.php','appname=' . $appname . '&type=forced')
);
switch($type)
{
case 'user': $selected = 0; break;
case 'default': $selected = 1; break;
case 'forced': $selected = 2; break;
}
$t->set_var('tabs',$phpgw->common->create_tabs($tabs,$selected));
}
else
{
$GLOBALS['type'] = 'user';
}
// Only load if there working on the default preferences
if ($type == 'default')
{
$dp = createobject('phpgwapi.preferences',-2); $dp = createobject('phpgwapi.preferences',-2);
$dp->read_repository(); $dp->read_repository();
} }
// Makes the ifs a little nicer, plus ... this will change once the ACL manager is in place
// and is able to create less powerfull admins. This will handle the ACL checks for that (jengo)
function is_admin() function is_admin()
{ {
if (HAS_ADMIN_RIGHTS == 1) if (HAS_ADMIN_RIGHTS == 1)
@ -190,31 +252,25 @@
} }
} }
$t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('preferences'));
$t->set_file(array(
'_preferences' => 'preferences.tpl'
));
$t->set_block('_preferences','list_a');
$t->set_block('_preferences','row_a');
$t->set_block('_preferences','list_u');
$t->set_block('_preferences','row_u');
$t->set_block('_preferences','header');
$t->set_block('_preferences','footer');
$t->set_block('_preferences','row_error');
if ($GLOBALS['HTTP_POST_VARS']['submit']) if ($GLOBALS['HTTP_POST_VARS']['submit'])
{ {
process_array(&$p, $user); // Don't use a switch here, we need to check some permissions durring the ifs
if ($type == 'user')
if (is_admin())
{ {
process_array(&$gp, $global); process_array(&$p, $user);
process_array(&$dp, $default);
} }
Header('Location: ' . $GLOBALS['phpgw']->link('/preferences/index.php#' . $appname)); if ($type == 'default' && is_admin())
{
process_array(&$dp, $default);
}
if ($type == 'forced' && is_admin())
{
process_array(&$gp, $forced);
}
Header('Location: ' . $GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $appname));
$GLOBALS['phpgw']->common->phpgw_exit(); $GLOBALS['phpgw']->common->phpgw_exit();
} }
@ -229,29 +285,33 @@
{ {
$t->set_var('lang_title',lang('%1 - Preferences',$GLOBALS['phpgw_info']['navbar'][$appname]['title'])); $t->set_var('lang_title',lang('%1 - Preferences',$GLOBALS['phpgw_info']['navbar'][$appname]['title']));
} }
$t->set_var('action_url',$GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $appname)); $t->set_var('action_url',$GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $appname));
$t->set_var('th_bg', $GLOBALS['phpgw_info']['theme']['th_bg']); $t->set_var('th_bg', $GLOBALS['phpgw_info']['theme']['th_bg']);
$t->set_var('th_text',$GLOBALS['phpgw_info']['theme']['th_text']); $t->set_var('th_text',$GLOBALS['phpgw_info']['theme']['th_text']);
$t->set_var('row_on', $GLOBALS['phpgw_info']['theme']['row_on']); $t->set_var('row_on', $GLOBALS['phpgw_info']['theme']['row_on']);
$t->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']); $t->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);
if (is_admin()) if ($appname == 'preferences')
{ {
$t->set_var('lang_user',lang('Yours')); if (! $GLOBALS['phpgw']->common->hook_single('settings','preferences',True))
$t->set_var('lang_global',lang('Forced')); {
$t->set_var('lang_default',lang('Default')); $error = True;
}
} }
else else
{ {
$t->set_var('lang_user','&nbsp;'); if (! $GLOBALS['phpgw']->common->hook_single('settings',$appname))
{
$error = True;
}
} }
if (! $GLOBALS['phpgw']->common->hook_single('settings',$appname,True)) if ($error)
{ {
$t->set_var('messages',lang('Error: There was a problem finding the preference file for %1 in %2', $t->set_var('messages',lang('Error: There was a problem finding the preference file for %1 in %2',
$GLOBALS['phpgw_info']['navbar'][$appname]['title'],PHPGW_SERVER_ROOT . SEP $GLOBALS['phpgw_info']['navbar'][$appname]['title'],PHPGW_SERVER_ROOT . SEP
. $appname . SEP . 'inc' . SEP . 'hook_settings.inc.php')); . $appname . SEP . 'inc' . SEP . 'hook_settings.inc.php'));
$error = True;
} }
$t->pfp('out','header'); $t->pfp('out','header');
@ -260,20 +320,10 @@
if (! $error) if (! $error)
{ {
if (is_admin()) $t->pfp('out','list');
{
$t->pfp('out','list_a');
}
else
{
$t->pfp('out','list_u');
}
}
if (! $error)
{
$t->pfp('out','footer'); $t->pfp('out','footer');
} }
$GLOBALS['phpgw']->common->phpgw_footer(); $GLOBALS['phpgw']->common->phpgw_footer();
?>
?>

View File

@ -1,4 +1,10 @@
<!-- BEGIN list --> <!-- BEGIN list -->
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td align="left">{tabs}</td>
</tr>
</table>
<table width="75%" border="0" cellspacing="0" cellpadding="0"> <table width="75%" border="0" cellspacing="0" cellpadding="0">
{rows} {rows}
</table> </table>

View File

@ -2,6 +2,14 @@
<b>{lang_title}</b> <b>{lang_title}</b>
<hr><p> <hr><p>
<center>{messages}</center>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td>{tabs}</td>
</tr>
</table>
<form method="POST" action="{action_url}"> <form method="POST" action="{action_url}">
<table border="0"> <table border="0">
@ -17,36 +25,17 @@
</table> </table>
<!-- END footer --> <!-- END footer -->
<!-- BEGIN list_a --> <!-- BEGIN list -->
<tr bgcolor="{th_bg}"> <tr bgcolor="{th_bg}">
<td>&nbsp;</td> <td>&nbsp;</td>
<td>{lang_user}</td> <td>{list_label}</td>
<td>{lang_global}</td>
<td>{lang_default}</td>
</tr> </tr>
{rows} {rows}
<!-- END list_a --> <!-- END list -->
<!-- BEGIN row_a --> <!-- BEGIN row -->
<tr bgcolor="{tr_color}"> <tr bgcolor="{tr_color}">
<td>{row_name}</td> <td>{row_name}</td>
<td>{row_user}</td> <td>{row_value}</td>
<td>{row_global}</td>
<td>{row_default}</td>
</tr> </tr>
<!-- END row_a --> <!-- END row -->
<!-- BEGIN list_u -->
<tr bgcolor="{th_bg}">
<td>&nbsp;</td>
<td>{lang_user}</td>
</tr>
{rows}
<!-- END list_u -->
<!-- BEGIN row_u -->
<tr bgcolor="{tr_color}">
<td>{row_name}</td>
<td>{row_user}</td>
</tr>
<!-- END row_u -->