Project

General

Profile

1 1435 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         preferences
6 1529 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7 1912 Luisehahne
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9 1435 Luisehahne
 * @license         http://www.gnu.org/licenses/gpl.html
10 1912 Luisehahne
 * @platform        WebsiteBaker 2.8.4
11 1435 Luisehahne
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id$
13 1912 Luisehahne
 * @filesource      $HeadURL$
14 1435 Luisehahne
 * @lastmodified    $Date$
15
 *
16
 */
17
18
// prevent this file from being accessed directly
19
//if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
20
//Workaround if this is first page (WBAdmin in use)
21
22
// put all inside a function to prevent global vars
23
function build_page( &$admin, &$database )
24
{
25 1912 Luisehahne
//	global $HEADING, $TEXT;
26 2091 darkviper
    $mLang = Translate::getInstance();
27 1986 Luisehahne
	$oReg  = WbAdaptor::getInstance();
28 1435 Luisehahne
	include_once(WB_PATH.'/framework/functions-utf8.php');
29 1529 Luisehahne
	// Setup template object, parse vars to it, then parse it
30 1625 Luisehahne
	// Setup template object, parse vars to it, then parse it
31 1529 Luisehahne
	// Create new template object
32 1625 Luisehahne
	$template = new Template(dirname($admin->correct_theme_source('preferences.htt')));
33 1435 Luisehahne
	$template->set_file( 'page', 'preferences.htt' );
34
	$template->set_block( 'page', 'main_block', 'main' );
35 2091 darkviper
	$mLang = Translate::getInstance();
36 1922 darkviper
//	$mLang->enableAddon('admin\preferences');
37 1912 Luisehahne
	$template->set_var($mLang->getLangArray());
38
39 1435 Luisehahne
// read user-info from table users and assign it to template
40
	$sql  = 'SELECT `display_name`, `username`, `email` FROM `'.TABLE_PREFIX.'users` ';
41
	$sql .= 'WHERE `user_id` = '.(int)$admin->get_user_id();
42
	if( $res_user = $database->query($sql) )
43
	{
44
		if( $rec_user = $res_user->fetchRow() )
45
		{
46
			$template->set_var('DISPLAY_NAME', $rec_user['display_name']);
47
			$template->set_var('USERNAME',     $rec_user['username']);
48
			$template->set_var('EMAIL',        $rec_user['email']);
49
			$template->set_var('ADMIN_URL',    ADMIN_URL);
50
		}
51
	}
52
// read available languages from table addons and assign it to the template
53 1912 Luisehahne
//	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
54
//	$sql .= 'WHERE `type` = \'language\' ORDER BY `directory`';
55
//	if( $res_lang = $database->query($sql) )
56
//	{
57
//		$template->set_block('main_block', 'language_list_block', 'language_list');
58
//		while( $rec_lang = $res_lang->fetchRow(MYSQL_ASSOC) )
59
//		{
60
//	        $langIcons = (empty($rec_lang['directory'])) ? 'none' : strtolower($rec_lang['directory']);
61
//			$template->set_var('CODE',        $rec_lang['directory']);
62
//			$template->set_var('NAME',        $rec_lang['name']);
63
//			$template->set_var('FLAG',        THEME_URL.'/images/flags/'.$langIcons);
64
//			$template->set_var('SELECTED',    (LANGUAGE == $rec_lang['directory'] ? ' selected="selected"' : '') );
65
//			$template->parse('language_list', 'language_list_block', true);
66
//		}
67
//	}
68
69
$aLangAddons = array();
70
$aLangBrowser = array();
71
72
73
// default, if no information from client available
74
$sAutoLanguage = DEFAULT_LANGUAGE;
75 1986 Luisehahne
// read available languages from table addons
76
$aLangAddons = $admin->getAvailableLanguages();
77 1912 Luisehahne
78 1986 Luisehahne
$aLangUsed = array_flip(explode(',',$admin->getLanguagesInUsed()));
79 1912 Luisehahne
$aLangUsed = array_intersect_key($aLangAddons, $aLangUsed);
80 1986 Luisehahne
if( (sizeof($aLangUsed)<2) || !($oReg->PageLanguages) ){
81
    $aLangUsed =  $aLangAddons;
82
}
83 1912 Luisehahne
$template->set_block('main_block', 'language_list_block', 'language_list');
84
foreach( $aLangUsed as $sDirectory => $sName  )
85
{
86
	$langIcons = ( empty($sDirectory) ? 'none' : strtolower($sDirectory));
87
88
	$template->set_var('CODE',        $sDirectory);
89
	$template->set_var('NAME',        $sName);
90
	$template->set_var('FLAG',        THEME_URL.'/images/flags/'.$langIcons);
91
	$template->set_var('SELECTED',    ( $_SESSION['LANGUAGE'] == $sDirectory ? ' selected="selected"' : '') );
92
93
	$template->parse('language_list', 'language_list_block', true);
94
}
95
96 1435 Luisehahne
// Insert default timezone values
97 1872 Luisehahne
	$user_time = true;
98 1435 Luisehahne
	include_once( ADMIN_PATH.'/interface/timezones.php' );
99
	$template->set_block('main_block', 'timezone_list_block', 'timezone_list');
100
	foreach( $TIMEZONES AS $hour_offset => $title )
101
	{
102
		$template->set_var('VALUE',    $hour_offset);
103
		$template->set_var('NAME',     $title);
104
		$template->set_var('SELECTED', ($admin->get_timezone() == ($hour_offset * 3600) ? ' selected="selected"' : '') );
105
		$template->parse('timezone_list', 'timezone_list_block', true);
106
	}
107
// Insert date format list
108 1849 Luisehahne
	$user_time = true;
109 1435 Luisehahne
	include_once( ADMIN_PATH.'/interface/date_formats.php' );
110
	$template->set_block('main_block', 'date_format_list_block', 'date_format_list');
111 1872 Luisehahne
112 1435 Luisehahne
	foreach( $DATE_FORMATS AS $format => $title )
113
	{
114
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
115
		$template->set_var( 'VALUE', ($format != 'system_default' ? $format : 'system_default') );
116
		$template->set_var( 'NAME',  $title );
117 1872 Luisehahne
		if( ($admin->get_session('DATE_FORMAT') == $format && !isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) ||
118 1435 Luisehahne
			('system_default' == $format && isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) )
119
		{
120
			$template->set_var('SELECTED', ' selected="selected"');
121
		}else {
122
			$template->set_var('SELECTED', '');
123
		}
124
		$template->parse('date_format_list', 'date_format_list_block', true);
125
	}
126
// Insert time format list
127 1872 Luisehahne
	$user_time = true;
128 1435 Luisehahne
	include_once( ADMIN_PATH.'/interface/time_formats.php' );
129
	$template->set_block('main_block', 'time_format_list_block', 'time_format_list');
130
	foreach( $TIME_FORMATS AS $format => $title )
131
	{
132
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
133
		$template->set_var('VALUE', $format != 'system_default' ? $format : 'system_default' );
134
		$template->set_var('NAME',  $title);
135 1872 Luisehahne
		if( ($admin->get_session('TIME_FORMAT') == $format && !isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) ||
136 1435 Luisehahne
		    ('system_default' == $format && isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) )
137
		{
138
			$template->set_var('SELECTED', ' selected="selected"');
139
		} else {
140
			$template->set_var('SELECTED', '');
141
		}
142
		$template->parse('time_format_list', 'time_format_list_block', true);
143
	}
144
145
// assign systemvars to template
146
	$template->set_var(array( 'ADMIN_URL'  => ADMIN_URL,
147
	                          'WB_URL'     => WB_URL,
148
                              'THEME_URL'  => THEME_URL,
149
		                      'ACTION_URL' => ADMIN_URL.'/preferences/save.php'
150
                            )
151
                      );
152
	$template->set_var('FTAN', $admin->getFTAN());
153
	$template->set_var('FORM_NAME', 'preferences_save');
154
// assign language vars
155 1912 Luisehahne
	$template->set_var(array(
156
                              'EMPTY_STRING'             => ''
157 1435 Luisehahne
                            )
158
                      );
159
// Parse template for preferences form
160
	$template->parse('main', 'main_block', false);
161
	$output = $template->finish($template->parse('output', 'page'));
162 1912 Luisehahne
	$mLang->disableAddon();
163
164 1435 Luisehahne
	return $output;
165
}
166
// test if valid $admin-object already exists (bit complicated about PHP4 Compatibility)
167
if( !(isset($admin) && is_object($admin) && (get_class($admin) == 'admin')) )
168
{
169
    require( '../../config.php' );
170
	require_once( WB_PATH.'/framework/class.admin.php' );
171
	$admin = new admin('Preferences');
172
}
173
echo build_page($admin, $database);
174
$admin->print_footer();