2001-08-27 05:17:14 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - Preferences *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* 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. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2001-09-18 05:47:31 +02:00
|
|
|
$user = (@isset($GLOBALS['HTTP_POST_VARS']['user'])?$GLOBALS['HTTP_POST_VARS']['user']:'');
|
|
|
|
$global = (@isset($GLOBALS['HTTP_POST_VARS']['global'])?$GLOBALS['HTTP_POST_VARS']['global']:'');
|
|
|
|
$default = (@isset($GLOBALS['HTTP_POST_VARS']['default'])?$GLOBALS['HTTP_POST_VARS']['default']:'');
|
2001-08-31 18:23:31 +02:00
|
|
|
|
|
|
|
$GLOBALS['phpgw_info']['flags'] = array(
|
2001-08-27 05:17:14 +02:00
|
|
|
'noheader' => True,
|
2001-09-05 05:49:40 +02:00
|
|
|
'noappheader' => True,
|
2001-08-27 05:17:14 +02:00
|
|
|
'nonavbar' => True,
|
2001-09-18 05:47:31 +02:00
|
|
|
'currentapp' => $GLOBALS['HTTP_GET_VARS']['appname'],
|
2001-08-27 05:17:14 +02:00
|
|
|
'enable_nextmatchs_class' => True
|
|
|
|
);
|
|
|
|
include('../header.inc.php');
|
|
|
|
|
2001-08-31 18:35:43 +02:00
|
|
|
if ($GLOBALS['HTTP_POST_VARS']['cancel'])
|
|
|
|
{
|
|
|
|
Header('Location: ' . $GLOBALS['phpgw']->link('/preferences/index.php'));
|
|
|
|
}
|
|
|
|
|
2001-09-04 01:01:42 +02:00
|
|
|
$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');
|
|
|
|
|
2001-09-05 05:49:40 +02:00
|
|
|
/* Make things a little easier to follow */
|
|
|
|
/* Some places we will need to change this if there in common */
|
2001-09-18 05:47:31 +02:00
|
|
|
function check_app()
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
if ($GLOBALS['HTTP_GET_VARS']['appname'] == 'preferences')
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
|
|
|
return 'common';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
return $GLOBALS['HTTP_GET_VARS']['appname'];
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-18 05:47:31 +02:00
|
|
|
function is_forced_value($_appname,$preference_name)
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
if ($GLOBALS['gp']->data[$_appname][$preference_name] && $GLOBALS['type'] != 'forced')
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_input_box($label_name,$preference_name,$size = '',$max_size = '')
|
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
global $t;
|
2001-08-27 05:17:14 +02:00
|
|
|
|
2001-09-18 05:47:31 +02:00
|
|
|
$_appname = check_app();
|
2001-08-31 18:23:31 +02:00
|
|
|
$GLOBALS['phpgw']->nextmatchs->template_alternate_row_color(&$t);
|
2001-08-27 05:17:14 +02:00
|
|
|
$t->set_var('row_name',lang($label_name));
|
2001-09-04 01:01:42 +02:00
|
|
|
|
|
|
|
if (is_forced_value($_appname,$preference_name))
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
2001-09-04 01:01:42 +02:00
|
|
|
return True;
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
2001-09-04 01:01:42 +02:00
|
|
|
|
|
|
|
switch ($GLOBALS['type'])
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
2001-09-04 01:01:42 +02:00
|
|
|
case 'user': $s = '<input name="user[' . $preference_name . ']" value="' . $GLOBALS['phpgw_info']['user']['preferences'][$_appname][$preference_name] . '">';
|
|
|
|
break;
|
2001-09-18 05:47:31 +02:00
|
|
|
case 'default': $s = '<input name="default[' . $preference_name . ']" value="' . $GLOBALS['dp']->data[$_appname][$preference_name] . '">';
|
2001-09-04 01:01:42 +02:00
|
|
|
break;
|
2001-09-18 05:47:31 +02:00
|
|
|
case 'forced': $s = '<input name="forced[' . $preference_name . ']" value="' . $GLOBALS['gp']->data[$_appname][$preference_name] . '">';
|
2001-09-04 01:01:42 +02:00
|
|
|
break;
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
2001-09-04 01:01:42 +02:00
|
|
|
$t->set_var('row_value',$s);
|
|
|
|
|
|
|
|
$t->fp('rows','row',True);
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function create_option_string($selected,$values)
|
|
|
|
{
|
|
|
|
while (is_array($values) && list($var,$value) = each($values))
|
|
|
|
{
|
|
|
|
$s .= '<option value="' . $var . '"';
|
|
|
|
if ($var == $selected)
|
|
|
|
{
|
|
|
|
$s .= ' selected';
|
|
|
|
}
|
|
|
|
$s .= '>' . $value . '</option>';
|
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_select_box($label_name,$preference_name,$values)
|
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
global $t;
|
2001-08-27 05:17:14 +02:00
|
|
|
|
2001-09-18 05:47:31 +02:00
|
|
|
$_appname = check_app();
|
2001-09-04 01:01:42 +02:00
|
|
|
if (is_forced_value($_appname,$preference_name))
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2001-08-31 18:23:31 +02:00
|
|
|
$GLOBALS['phpgw']->nextmatchs->template_alternate_row_color(&$t);
|
2001-08-27 05:17:14 +02:00
|
|
|
|
|
|
|
$t->set_var('row_name',lang($label_name));
|
|
|
|
|
2001-09-04 01:01:42 +02:00
|
|
|
switch ($GLOBALS['type'])
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
2001-09-04 01:01:42 +02:00
|
|
|
case 'user':
|
|
|
|
$s = '<option value="">' . lang('Select one') . '</option>'
|
|
|
|
. create_option_string($GLOBALS['phpgw_info']['user']['preferences'][$_appname][$preference_name],$values);
|
|
|
|
$t->set_var('row_value','<select name="user[' . $preference_name . ']">' . $s . '</select>');
|
|
|
|
break;
|
|
|
|
case 'default':
|
|
|
|
$s = '<option value="">' . lang('Select one') . '</option>'
|
2001-09-18 05:47:31 +02:00
|
|
|
. create_option_string($GLOBALS['dp']->data[$_appname][$preference_name],$values);
|
2001-09-04 01:01:42 +02:00
|
|
|
$t->set_var('row_value','<select name="default[' . $preference_name . ']">' . $s . '</select>');
|
|
|
|
break;
|
|
|
|
case 'forced':
|
|
|
|
$s = '<option value="**NULL**">' . lang('Users choice') . '</option>'
|
2001-09-18 05:47:31 +02:00
|
|
|
. create_option_string($GLOBALS['gp']->data[$_appname][$preference_name],$values);
|
2001-09-04 01:01:42 +02:00
|
|
|
$t->set_var('row_value','<select name="forced[' . $preference_name . ']">' . $s . '</select>');
|
|
|
|
break;
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
2001-09-04 01:01:42 +02:00
|
|
|
|
|
|
|
$t->fp('rows','row',True);
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function process_array(&$_p, $array)
|
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
$_appname = check_app();
|
2001-08-27 05:17:14 +02:00
|
|
|
|
|
|
|
while (is_array($array) && list($var,$value) = each($array))
|
|
|
|
{
|
|
|
|
if ($value && $value != '**NULL**')
|
|
|
|
{
|
|
|
|
$_p->add($_appname,$var,$value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unset($_p->data[$_appname][$var]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$_p->save_repository(True);
|
|
|
|
}
|
|
|
|
|
|
|
|
$p = createobject('phpgwapi.preferences');
|
|
|
|
$p->read_repository();
|
|
|
|
|
2001-09-05 05:49:40 +02:00
|
|
|
/* So we can check if the admin is allowing users to make there own choices */
|
|
|
|
/* in life. */
|
2001-09-18 05:47:31 +02:00
|
|
|
$GLOBALS['gp'] = createobject('phpgwapi.preferences',-1);
|
|
|
|
$GLOBALS['gp']->read_repository();
|
2001-08-27 05:17:14 +02:00
|
|
|
|
2001-09-05 05:49:40 +02:00
|
|
|
/* Only check this once */
|
2001-08-31 18:23:31 +02:00
|
|
|
if ($GLOBALS['phpgw']->acl->check('run',1,'admin'))
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
2001-09-05 05:49:40 +02:00
|
|
|
/* Don't use a global variable for this ... */
|
2001-08-27 05:17:14 +02:00
|
|
|
define('HAS_ADMIN_RIGHTS',1);
|
2001-09-04 01:01:42 +02:00
|
|
|
}
|
2001-08-27 05:17:14 +02:00
|
|
|
|
2001-09-05 05:49:40 +02:00
|
|
|
/* 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) */
|
2001-09-05 04:57:30 +02:00
|
|
|
function is_admin()
|
|
|
|
{
|
|
|
|
if (HAS_ADMIN_RIGHTS == 1)
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-04 01:01:42 +02:00
|
|
|
if (is_admin())
|
|
|
|
{
|
2001-09-05 05:49:40 +02:00
|
|
|
/* This is where we will keep track of our postion. */
|
|
|
|
/* Developers won't have to pass around a variable then */
|
2001-09-18 05:47:31 +02:00
|
|
|
$session_data = $GLOBALS['phpgw']->session->appsession('session_data','preferences');
|
2001-09-04 01:01:42 +02:00
|
|
|
|
|
|
|
if (! is_array($session_data))
|
|
|
|
{
|
|
|
|
$session_data = array(
|
|
|
|
'type' => 'user'
|
|
|
|
);
|
2001-09-18 05:47:31 +02:00
|
|
|
$GLOBALS['phpgw']->session->appsession('session_data','preferences',$session_data);
|
2001-09-04 01:01:42 +02:00
|
|
|
}
|
|
|
|
|
2001-09-18 03:26:21 +02:00
|
|
|
if (!isset($GLOBALS['HTTP_GET_VARS']['type']))
|
2001-09-04 01:01:42 +02:00
|
|
|
{
|
2001-09-18 04:21:31 +02:00
|
|
|
$GLOBALS['type'] = $session_data['type'];
|
2001-09-04 01:01:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-18 04:21:31 +02:00
|
|
|
$GLOBALS['type'] = $GLOBALS['HTTP_GET_VARS']['type'];
|
2001-09-04 01:01:42 +02:00
|
|
|
$session_data = array(
|
2001-09-18 04:21:31 +02:00
|
|
|
'type' => $GLOBALS['type']
|
2001-09-04 01:01:42 +02:00
|
|
|
);
|
2001-09-18 05:47:31 +02:00
|
|
|
$GLOBALS['phpgw']->session->appsession('session_data','preferences',$session_data);
|
2001-09-04 01:01:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$tabs[] = array(
|
|
|
|
'label' => 'Your preferences',
|
2001-09-18 05:47:31 +02:00
|
|
|
'link' => $GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $GLOBALS['HTTP_GET_VARS']['appname'] . '&type=user')
|
2001-09-04 01:01:42 +02:00
|
|
|
);
|
|
|
|
$tabs[] = array(
|
|
|
|
'label' => 'Default preferences',
|
2001-09-18 05:47:31 +02:00
|
|
|
'link' => $GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $GLOBALS['HTTP_GET_VARS']['appname'] . '&type=default')
|
2001-09-04 01:01:42 +02:00
|
|
|
);
|
|
|
|
$tabs[] = array(
|
|
|
|
'label' => 'Forced preferences',
|
2001-09-18 05:47:31 +02:00
|
|
|
'link' => $GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $GLOBALS['HTTP_GET_VARS']['appname'] . '&type=forced')
|
2001-09-04 01:01:42 +02:00
|
|
|
);
|
|
|
|
|
2001-09-18 04:21:31 +02:00
|
|
|
switch($GLOBALS['type'])
|
2001-09-04 01:01:42 +02:00
|
|
|
{
|
|
|
|
case 'user': $selected = 0; break;
|
|
|
|
case 'default': $selected = 1; break;
|
|
|
|
case 'forced': $selected = 2; break;
|
|
|
|
}
|
2001-09-18 03:26:21 +02:00
|
|
|
$t->set_var('tabs',$GLOBALS['phpgw']->common->create_tabs($tabs,$selected));
|
2001-09-04 01:01:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-18 04:21:31 +02:00
|
|
|
$GLOBALS['type'] = 'user';
|
2001-09-04 01:01:42 +02:00
|
|
|
}
|
|
|
|
|
2001-09-05 05:49:40 +02:00
|
|
|
/* Only load if there working on the default preferences */
|
2001-09-18 04:21:31 +02:00
|
|
|
if ($GLOBALS['type'] == 'default')
|
2001-09-04 01:01:42 +02:00
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
$GLOBALS['dp'] = createobject('phpgwapi.preferences',-2);
|
|
|
|
$GLOBALS['dp']->read_repository();
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
|
|
|
|
2001-08-31 18:23:31 +02:00
|
|
|
if ($GLOBALS['HTTP_POST_VARS']['submit'])
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
2001-09-05 05:49:40 +02:00
|
|
|
/* Don't use a switch here, we need to check some permissions durring the ifs */
|
2001-09-18 04:21:31 +02:00
|
|
|
if ($GLOBALS['type'] == 'user')
|
2001-09-04 01:01:42 +02:00
|
|
|
{
|
2001-09-18 03:26:21 +02:00
|
|
|
process_array($p, $user);
|
2001-09-04 01:01:42 +02:00
|
|
|
}
|
|
|
|
|
2001-09-18 04:21:31 +02:00
|
|
|
if ($GLOBALS['type'] == 'default' && is_admin())
|
2001-09-04 01:01:42 +02:00
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
process_array($GLOBALS['dp'], $default);
|
2001-09-04 01:01:42 +02:00
|
|
|
}
|
2001-08-27 05:17:14 +02:00
|
|
|
|
2001-09-18 04:21:31 +02:00
|
|
|
if ($GLOBALS['type'] == 'forced' && is_admin())
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
process_array($GLOBALS['gp'], $forced);
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
|
|
|
|
2001-09-05 05:49:40 +02:00
|
|
|
Header('Location: ' . $GLOBALS['phpgw']->link('/preferences/index.php'));
|
2001-08-31 18:23:31 +02:00
|
|
|
$GLOBALS['phpgw']->common->phpgw_exit();
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
|
|
|
|
2001-08-31 18:23:31 +02:00
|
|
|
$GLOBALS['phpgw']->common->phpgw_header();
|
2001-08-27 05:17:14 +02:00
|
|
|
echo parse_navbar();
|
|
|
|
|
2001-09-18 05:47:31 +02:00
|
|
|
if ($GLOBALS['HTTP_GET_VARS']['appname'] == 'preferences')
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
|
|
|
$t->set_var('lang_title',lang('Preferences'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
$t->set_var('lang_title',lang('%1 - Preferences',$GLOBALS['phpgw_info']['navbar'][$GLOBALS['HTTP_GET_VARS']['appname']]['title']));
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
2001-09-04 01:01:42 +02:00
|
|
|
|
2001-09-18 05:47:31 +02:00
|
|
|
$t->set_var('action_url',$GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $GLOBALS['HTTP_GET_VARS']['appname']));
|
2001-08-31 18:23:31 +02:00
|
|
|
$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('row_on', $GLOBALS['phpgw_info']['theme']['row_on']);
|
|
|
|
$t->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);
|
2001-08-27 05:17:14 +02:00
|
|
|
|
2001-09-18 05:47:31 +02:00
|
|
|
if ($GLOBALS['HTTP_GET_VARS']['appname'] == 'preferences')
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
2001-09-04 01:01:42 +02:00
|
|
|
if (! $GLOBALS['phpgw']->common->hook_single('settings','preferences',True))
|
|
|
|
{
|
|
|
|
$error = True;
|
|
|
|
}
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-18 05:47:31 +02:00
|
|
|
if (! $GLOBALS['phpgw']->common->hook_single('settings',$GLOBALS['HTTP_GET_VARS']['appname']))
|
2001-09-04 01:01:42 +02:00
|
|
|
{
|
|
|
|
$error = True;
|
|
|
|
}
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
|
|
|
|
2001-09-04 01:01:42 +02:00
|
|
|
if ($error)
|
2001-08-27 05:17:14 +02:00
|
|
|
{
|
|
|
|
$t->set_var('messages',lang('Error: There was a problem finding the preference file for %1 in %2',
|
2001-09-18 05:47:31 +02:00
|
|
|
$GLOBALS['phpgw_info']['navbar'][$GLOBALS['HTTP_GET_VARS']['appname']]['title'],PHPGW_SERVER_ROOT . SEP
|
|
|
|
. $GLOBALS['HTTP_GET_VARS']['appname'] . SEP . 'inc' . SEP . 'hook_settings.inc.php'));
|
2001-08-27 05:17:14 +02:00
|
|
|
}
|
|
|
|
$t->pfp('out','header');
|
|
|
|
|
|
|
|
$t->set_var('lang_submit', lang('submit'));
|
|
|
|
$t->set_var('lang_cancel', lang('cancel'));
|
|
|
|
|
|
|
|
if (! $error)
|
|
|
|
{
|
2001-09-04 01:01:42 +02:00
|
|
|
$t->pfp('out','list');
|
2001-08-27 05:17:14 +02:00
|
|
|
$t->pfp('out','footer');
|
|
|
|
}
|
|
|
|
|
2001-08-31 18:23:31 +02:00
|
|
|
$GLOBALS['phpgw']->common->phpgw_footer();
|
2001-09-05 04:57:30 +02:00
|
|
|
?>
|