diff --git a/preferences/preferences.php b/preferences/preferences.php new file mode 100755 index 0000000000..9dc16f4169 --- /dev/null +++ b/preferences/preferences.php @@ -0,0 +1,269 @@ + True, + 'nonavbar' => True, + 'currentapp' => $appname, + 'enable_nextmatchs_class' => True + ); + include('../header.inc.php'); + + // Make things a little easier to follow + function is_admin() + { + if (HAS_ADMIN_RIGHTS == 1) + { + return True; + } + else + { + return False; + } + } + + // Some places we will need to change this if there in common + function check_app($appname) + { + if ($appname == 'preferences') + { + return 'common'; + } + else + { + return $appname; + } + } + + 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) + { + global $gp; + + if ($gp->data[$appname][$preference_name]) + { + return True; + } + else + { + return False; + } + } + + function create_input_box($label_name,$preference_name,$size = '',$max_size = '') + { + global $phpgw, $phpgw_info, $appname, $t, $dp, $gp; + + $_appname = check_app($appname); + + $phpgw->nextmatchs->template_alternate_row_color(&$t); + $t->set_var('row_name',lang($label_name)); + if (! is_forced_value($_appname,$preference_name)) + { + $t->set_var('row_user',''); + } + else + { + $t->set_var('row_user',' '); + } + if (is_admin()) + { + $t->set_var('row_global',''); + $t->set_var('row_default',''); + } + parse_row(&$t); + } + + function create_option_string($selected,$values) + { + while (is_array($values) && list($var,$value) = each($values)) + { + $s .= ''; + } + return $s; + } + + function create_select_box($label_name,$preference_name,$values) + { + global $phpgw, $phpgw_info, $appname, $t, $dp, $gp; + + $_appname = check_app($appname); + + $phpgw->nextmatchs->template_alternate_row_color(&$t); + + $t->set_var('row_name',lang($label_name)); + if (! is_forced_value($_appname,$preference_name)) + { + $s = '' . lang('Select one') . '' + . create_option_string($phpgw_info['user']['preferences'][$_appname][$preference_name],$values); + $t->set_var('row_user','' . $s . ''); + } + else + { + $t->set_var('row_user',' '); + } + + if (is_admin()) + { + $s = '' . lang('Users choice') . '' + . create_option_string($gp->data[$_appname][$preference_name],$values); + $t->set_var('row_global','' . $s . ''); + + $s = '' . lang('Select one') . '' + . create_option_string($dp->data[$_appname][$preference_name],$values); + $t->set_var('row_default','' . $s . ''); + } + parse_row(&$t); + } + + function process_array(&$_p, $array) + { + global $appname; + + $_appname = check_app($appname); + + 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(); + + // So we can check if the admin is allowing users to make there own choices + // in life. + $gp = createobject('phpgwapi.preferences',-1); + $gp->read_repository(); + + // Only check this once + if ($phpgw->acl->check('run',1,'admin')) + { + // Don't use a global variable for this ... + define('HAS_ADMIN_RIGHTS',1); + + $dp = createobject('phpgwapi.preferences',-2); + $dp->read_repository(); + } + + $t = CreateObject('phpgwapi.Template',$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 ($submit) + { + process_array(&$p, $user); + + if (is_admin()) + { + process_array(&$gp, $global); + process_array(&$dp, $default); + } + + Header('Location: ' . $phpgw->link('/preferences/index.php#' . $appname)); + $phpgw->common->phpgw_exit(); + } + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + if ($appname == 'preferences') + { + $t->set_var('lang_title',lang('Preferences')); + } + else + { + $t->set_var('lang_title',lang('%1 - Preferences',$phpgw_info['navbar'][$appname]['title'])); + } + $t->set_var('action_url',$phpgw->link('/preferences/preferences.php','appname=' . $appname)); + $t->set_var('th_bg',$phpgw_info['theme']['th_bg']); + $t->set_var('th_text',$phpgw_info['theme']['th_text']); + $t->set_var('row_on',$phpgw_info['theme']['row_on']); + $t->set_var('row_off',$phpgw_info['theme']['row_off']); + + if (is_admin()) + { + $t->set_var('lang_user',lang('Yours')); + $t->set_var('lang_global',lang('Forced')); + $t->set_var('lang_default',lang('Default')); + } + else + { + $t->set_var('lang_user',' '); + } + + if (! $phpgw->common->hook_single('settings',$appname,True)) + { + $t->set_var('messages',lang('Error: There was a problem finding the preference file for %1 in %2', + $phpgw_info['navbar'][$appname]['title'],PHPGW_SERVER_ROOT . SEP + . $appname . SEP . 'inc' . SEP . 'hook_settings.inc.php')); + $error = True; + } + $t->pfp('out','header'); + + $t->set_var('lang_submit', lang('submit')); + $t->set_var('lang_cancel', lang('cancel')); + + if (! $error) + { + if (is_admin()) + { + $t->pfp('out','list_a'); + } + else + { + $t->pfp('out','list_u'); + } + } + + if (! $error) + { + $t->pfp('out','footer'); + } + + $phpgw->common->phpgw_footer(); +?> \ No newline at end of file diff --git a/preferences/settings.php b/preferences/settings.php deleted file mode 100755 index f3b6726364..0000000000 --- a/preferences/settings.php +++ /dev/null @@ -1,340 +0,0 @@ - * - * -------------------------------------------- * - * 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$ */ - - if ($submit) { - $phpgw_info["flags"] = array("nonavbar" => True, "noheader" => True); - } - $phpgw_info["flags"]["currentapp"] = "preferences"; - $phpgw_info["flags"]["enable_sbox_class"] = True; - - include("../header.inc.php"); - - function is_user_admin($owner) - { - global $phpgw; - - $acl = CreateObject('phpgwapi.acl',intval($owner)); - $acl_list = $acl->read_repository(); - - for ($k=0;$kmembership($owner); - unset($acct); - for ($k=0;$kget_app_list_for_id('run',1,$memberships[$k]['account_id']); - - if (is_array($apps_list)) - { - asort($apps_list); - - while($apps = each($apps_list)) - { - if($apps[1] == 'admin') - { - return True; - } - } - } - } - return False; - } - - if (! $submit) { - if ($phpgw_info["server"]["useframes"] != "never") { - $target = ' target="_top"'; - } - ?> - > - - - : - - " size="2"> - - - - - - - - - - common->list_templates(); - while (list ($key, $value) = each ($templates)){ - echo ''.$templates[$key]["title"].''; - } - ?> - - - - - - - - - - - - common->list_themes(); - while (list ($key, $value) = each ($themes)){ - echo ''.$value.''; - } - ?> - - - - - - - : - - - - " . lang("icons only"); ?> - " . lang("icons and text"); ?> - " . lang("text only"); ?> - - - - - - - : - - > - - - - - : - - - - " . lang("Top"); ?> - " . lang("bottom"); ?> - - - - - - - : - - $i\n"; - else - echo ">+$i\n"; - } - ?> - - - - - - : - - - - >m/d/y - >m-d-y - >m.d.y - - >y/d/m - >y-d-m - >y.d.m - - >y/m/d - >y-m-d - >y.m.d - - >d/m/y - >d-m-y - >d.m.y - - - - - : - " - . "12 Hour" - . "24 Hour" - . "\n"; - ?> - - - - - - - - sbox->form_select($phpgw_info['user']['preferences']['common']['country'],'settings[country]'); - ?> - - - - - - - - - - - lang('Use Selectbox'), 'use_text' => lang('Use Text Entry')); - while (list ($key, $value) = each ($country)){ - echo ''.$value.''; - } - ?> - - - - - - - - - - - db->query("select distinct lang from lang;"); - while ($phpgw->db->next_record()) { - $phpgw_info["installed_langs"][$phpgw->db->f("lang")] = $phpgw->db->f("lang"); - } - reset ($phpgw_info["installed_langs"]); - while (list ($key, $value) = each ($phpgw_info["installed_langs"])) { - $sql = "select lang_name from languages where lang_id = '".$value."';"; - $phpgw->db->query($sql); - $phpgw->db->next_record(); - echo ''.$phpgw->db->f("lang_name").''; - } - ?> - - - - ' . lang("show current users on navigation bar") . '' - . '"; - } - - if ($phpgw_info['server']['force_default_app'] == 'user_choice') - { - - ?> - - - - - - " . lang($phpgw_info["apps"][$permission[0]]["title"]).""; - } - } - ?> - - - - - - - - - "> - - - - - - "> - - - - - - common->phpgw_footer(); - } else { - - if(!$owner) { - $owner = $phpgw_info['user']['account_id']; - } - - $pref = CreateObject('phpgwapi.preferences',intval($owner)); - $pref->read_repository(); - $pref->delete('common'); - - while ($setting = each($settings)) { - $pref->add('common',$setting[0],$setting[1]); - } - - // This one is specialized, so we do it manually - if (is_user_admin($owner)) { - if ($show_currentusers) { - $pref->add('common','show_currentusers'); - } - } - - $pref->save_repository(); - - if ($phpgw_info['server']['useframes'] != 'never') { - Header('Location: ' . $phpgw->link('/preferences/index.php')); - $phpgw->common->phpgw_exit(); - } - - Header('Location: ' . $phpgw->link('/preferences/index.php')); - } -?>