Project

General

Profile

1 1435 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         preferences
6
 * @author          Independend-Software-Team
7
 * @author          WebsiteBaker Project
8
 * @copyright       2004-2009, Ryan Djurovich
9
 * @copyright       2009-2011, Website Baker Org. e.V.
10
 * @link			http://www.websitebaker2.org/
11
 * @license         http://www.gnu.org/licenses/gpl.html
12
 * @platform        WebsiteBaker 2.8.x
13
 * @requirements    PHP 5.2.2 and higher
14
 * @version         $Id$
15
 * @filesource		$HeadURL$
16
 * @lastmodified    $Date$
17
 *
18
 */
19
20
// prevent this file from being accessed directly
21
//if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
22
//Workaround if this is first page (WBAdmin in use)
23
24
// put all inside a function to prevent global vars
25
function build_page( &$admin, &$database )
26
{
27
	global $HEADING, $TEXT;
28
	include_once(WB_PATH.'/framework/functions-utf8.php');
29
// Create new template object, assign template file, start main-block
30
	$template = new Template( THEME_PATH.'/templates' );
31
	$template->set_file( 'page', 'preferences.htt' );
32
	$template->set_block( 'page', 'main_block', 'main' );
33
// read user-info from table users and assign it to template
34
	$sql  = 'SELECT `display_name`, `username`, `email` FROM `'.TABLE_PREFIX.'users` ';
35
	$sql .= 'WHERE `user_id` = '.(int)$admin->get_user_id();
36
	if( $res_user = $database->query($sql) )
37
	{
38
		if( $rec_user = $res_user->fetchRow() )
39
		{
40
			$template->set_var('DISPLAY_NAME', $rec_user['display_name']);
41
			$template->set_var('USERNAME',     $rec_user['username']);
42
			$template->set_var('EMAIL',        $rec_user['email']);
43
			$template->set_var('ADMIN_URL',    ADMIN_URL);
44
		}
45
	}
46
// read available languages from table addons and assign it to the template
47
	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
48
	$sql .= 'WHERE `type` = \'language\' ORDER BY `directory`';
49
	if( $res_lang = $database->query($sql) )
50
	{
51
		$template->set_block('main_block', 'language_list_block', 'language_list');
52
		while( $rec_lang = $res_lang->fetchRow() )
53
		{
54 1457 Luisehahne
	        $langIcons = (empty($rec_lang['directory'])) ? 'none' : strtolower($rec_lang['directory']);
55 1435 Luisehahne
			$template->set_var('CODE',        $rec_lang['directory']);
56
			$template->set_var('NAME',        $rec_lang['name']);
57 1457 Luisehahne
			$template->set_var('FLAG',        THEME_URL.'/images/flags/'.$langIcons);
58 1435 Luisehahne
			$template->set_var('SELECTED',    (LANGUAGE == $rec_lang['directory'] ? ' selected="selected"' : '') );
59
			$template->parse('language_list', 'language_list_block', true);
60
		}
61
	}
62
// Insert default timezone values
63
	$user_time = true;
64
	include_once( ADMIN_PATH.'/interface/timezones.php' );
65
	$template->set_block('main_block', 'timezone_list_block', 'timezone_list');
66
	foreach( $TIMEZONES AS $hour_offset => $title )
67
	{
68
		$template->set_var('VALUE',    $hour_offset);
69
		$template->set_var('NAME',     $title);
70
		$template->set_var('SELECTED', ($admin->get_timezone() == ($hour_offset * 3600) ? ' selected="selected"' : '') );
71
		$template->parse('timezone_list', 'timezone_list_block', true);
72
	}
73
// Insert date format list
74
	include_once( ADMIN_PATH.'/interface/date_formats.php' );
75
	$template->set_block('main_block', 'date_format_list_block', 'date_format_list');
76
	foreach( $DATE_FORMATS AS $format => $title )
77
	{
78
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
79
		$template->set_var( 'VALUE', ($format != 'system_default' ? $format : 'system_default') );
80
		$template->set_var( 'NAME',  $title );
81
		if( (DATE_FORMAT == $format && !isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) ||
82
			('system_default' == $format && isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) )
83
		{
84
			$template->set_var('SELECTED', ' selected="selected"');
85
		}else {
86
			$template->set_var('SELECTED', '');
87
		}
88
		$template->parse('date_format_list', 'date_format_list_block', true);
89
	}
90
// Insert time format list
91
	include_once( ADMIN_PATH.'/interface/time_formats.php' );
92
	$template->set_block('main_block', 'time_format_list_block', 'time_format_list');
93
	foreach( $TIME_FORMATS AS $format => $title )
94
	{
95
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
96
		$template->set_var('VALUE', $format != 'system_default' ? $format : 'system_default' );
97
		$template->set_var('NAME',  $title);
98
		if( (TIME_FORMAT == $format && !isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) ||
99
		    ('system_default' == $format && isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) )
100
		{
101
			$template->set_var('SELECTED', ' selected="selected"');
102
		} else {
103
			$template->set_var('SELECTED', '');
104
		}
105
		$template->parse('time_format_list', 'time_format_list_block', true);
106
	}
107
108
// assign systemvars to template
109
	$template->set_var(array( 'ADMIN_URL'  => ADMIN_URL,
110
	                          'WB_URL'     => WB_URL,
111
                              'THEME_URL'  => THEME_URL,
112
		                      'ACTION_URL' => ADMIN_URL.'/preferences/save.php'
113
                            )
114
                      );
115
	$template->set_var('FTAN', $admin->getFTAN());
116
	$template->set_var('FORM_NAME', 'preferences_save');
117
// assign language vars
118
	$template->set_var(array( 'HEADING_MY_SETTINGS'      => $HEADING['MY_SETTINGS'],
119
                              'HEADING_MY_EMAIL'         => $HEADING['MY_EMAIL'],
120
                              'HEADING_MY_PASSWORD'      => $HEADING['MY_PASSWORD'],
121
                              'TEXT_SAVE'                => $TEXT['SAVE'],
122
                              'TEXT_RESET'               => $TEXT['RESET'],
123
                              'TEXT_DISPLAY_NAME'        => $TEXT['DISPLAY_NAME'],
124
                              'TEXT_USERNAME'            => $TEXT['USERNAME'],
125
                              'TEXT_EMAIL'               => $TEXT['EMAIL'],
126
                              'TEXT_LANGUAGE'            => $TEXT['LANGUAGE'],
127
                              'TEXT_TIMEZONE'            => $TEXT['TIMEZONE'],
128
                              'TEXT_DATE_FORMAT'         => $TEXT['DATE_FORMAT'],
129
                              'TEXT_TIME_FORMAT'         => $TEXT['TIME_FORMAT'],
130
                              'TEXT_CURRENT_PASSWORD'    => $TEXT['CURRENT_PASSWORD'],
131
                              'TEXT_NEW_PASSWORD'        => $TEXT['NEW_PASSWORD'],
132
                              'TEXT_RETYPE_NEW_PASSWORD' => $TEXT['RETYPE_NEW_PASSWORD'],
133
							  'TEXT_NEW_PASSWORD'        => $TEXT['NEW_PASSWORD'],
134
                              'TEXT_RETYPE_NEW_PASSWORD' => $TEXT['RETYPE_NEW_PASSWORD'],
135
							  'TEXT_NEED_CURRENT_PASSWORD' => $TEXT['NEED_CURRENT_PASSWORD'],
136
	                          'EMPTY_STRING'             => ''
137
                            )
138
                      );
139
// Parse template for preferences form
140
	$template->parse('main', 'main_block', false);
141
	$output = $template->finish($template->parse('output', 'page'));
142
	return $output;
143
}
144
// test if valid $admin-object already exists (bit complicated about PHP4 Compatibility)
145
if( !(isset($admin) && is_object($admin) && (get_class($admin) == 'admin')) )
146
{
147
    require( '../../config.php' );
148
	require_once( WB_PATH.'/framework/class.admin.php' );
149
	$admin = new admin('Preferences');
150
}
151
echo build_page($admin, $database);
152
$admin->print_footer();
153
154 1313 Luisehahne
?>