Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         preferences
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: index.php 1872 2013-02-25 11:48:24Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/preferences/index.php $
14
 * @lastmodified    $Date: 2013-02-25 12:48:24 +0100 (Mon, 25 Feb 2013) $
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
	global $HEADING, $TEXT;
26
	include_once(WB_PATH.'/framework/functions-utf8.php');
27
	// Setup template object, parse vars to it, then parse it
28
	// Setup template object, parse vars to it, then parse it
29
	// Create new template object
30
	$template = new Template(dirname($admin->correct_theme_source('preferences.htt')));
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
	        $langIcons = (empty($rec_lang['directory'])) ? 'none' : strtolower($rec_lang['directory']);
55
			$template->set_var('CODE',        $rec_lang['directory']);
56
			$template->set_var('NAME',        $rec_lang['name']);
57
			$template->set_var('FLAG',        THEME_URL.'/images/flags/'.$langIcons);
58
			$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
	$user_time = true;
75
	include_once( ADMIN_PATH.'/interface/date_formats.php' );
76
	$template->set_block('main_block', 'date_format_list_block', 'date_format_list');
77

    
78
	foreach( $DATE_FORMATS AS $format => $title )
79
	{
80
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
81
		$template->set_var( 'VALUE', ($format != 'system_default' ? $format : 'system_default') );
82
		$template->set_var( 'NAME',  $title );
83
		if( ($admin->get_session('DATE_FORMAT') == $format && !isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) ||
84
			('system_default' == $format && isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) )
85
		{
86
			$template->set_var('SELECTED', ' selected="selected"');
87
		}else {
88
			$template->set_var('SELECTED', '');
89
		}
90
		$template->parse('date_format_list', 'date_format_list_block', true);
91
	}
92
// Insert time format list
93
	$user_time = true;
94
	include_once( ADMIN_PATH.'/interface/time_formats.php' );
95
	$template->set_block('main_block', 'time_format_list_block', 'time_format_list');
96
	foreach( $TIME_FORMATS AS $format => $title )
97
	{
98
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
99
		$template->set_var('VALUE', $format != 'system_default' ? $format : 'system_default' );
100
		$template->set_var('NAME',  $title);
101
		if( ($admin->get_session('TIME_FORMAT') == $format && !isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) ||
102
		    ('system_default' == $format && isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) )
103
		{
104
			$template->set_var('SELECTED', ' selected="selected"');
105
		} else {
106
			$template->set_var('SELECTED', '');
107
		}
108
		$template->parse('time_format_list', 'time_format_list_block', true);
109
	}
110

    
111
// assign systemvars to template
112
	$template->set_var(array( 'ADMIN_URL'  => ADMIN_URL,
113
	                          'WB_URL'     => WB_URL,
114
                              'THEME_URL'  => THEME_URL,
115
		                      'ACTION_URL' => ADMIN_URL.'/preferences/save.php'
116
                            )
117
                      );
118
	$template->set_var('FTAN', $admin->getFTAN());
119
	$template->set_var('FORM_NAME', 'preferences_save');
120
// assign language vars
121
	$template->set_var(array( 'HEADING_MY_SETTINGS'      => $HEADING['MY_SETTINGS'],
122
                              'HEADING_MY_EMAIL'         => $HEADING['MY_EMAIL'],
123
                              'HEADING_MY_PASSWORD'      => $HEADING['MY_PASSWORD'],
124
                              'TEXT_SAVE'                => $TEXT['SAVE'],
125
                              'TEXT_RESET'               => $TEXT['RESET'],
126
                              'TEXT_DISPLAY_NAME'        => $TEXT['DISPLAY_NAME'],
127
                              'TEXT_USERNAME'            => $TEXT['USERNAME'],
128
                              'TEXT_EMAIL'               => $TEXT['EMAIL'],
129
                              'TEXT_LANGUAGE'            => $TEXT['LANGUAGE'],
130
                              'TEXT_TIMEZONE'            => $TEXT['TIMEZONE'],
131
                              'TEXT_DATE_FORMAT'         => $TEXT['DATE_FORMAT'],
132
                              'TEXT_TIME_FORMAT'         => $TEXT['TIME_FORMAT'],
133
                              'TEXT_CURRENT_PASSWORD'    => $TEXT['CURRENT_PASSWORD'],
134
                              'TEXT_NEW_PASSWORD'        => $TEXT['NEW_PASSWORD'],
135
                              'TEXT_RETYPE_NEW_PASSWORD' => $TEXT['RETYPE_NEW_PASSWORD'],
136
							  'TEXT_NEW_PASSWORD'        => $TEXT['NEW_PASSWORD'],
137
                              'TEXT_RETYPE_NEW_PASSWORD' => $TEXT['RETYPE_NEW_PASSWORD'],
138
							  'TEXT_NEED_CURRENT_PASSWORD' => $TEXT['NEED_CURRENT_PASSWORD'],
139
	                          'EMPTY_STRING'             => ''
140
                            )
141
                      );
142
// Parse template for preferences form
143
	$template->parse('main', 'main_block', false);
144
	$output = $template->finish($template->parse('output', 'page'));
145
	return $output;
146
}
147
// test if valid $admin-object already exists (bit complicated about PHP4 Compatibility)
148
if( !(isset($admin) && is_object($admin) && (get_class($admin) == 'admin')) )
149
{
150
    require( '../../config.php' );
151
	require_once( WB_PATH.'/framework/class.admin.php' );
152
	$admin = new admin('Preferences');
153
}
154
echo build_page($admin, $database);
155
$admin->print_footer();
156

    
157
?>
(1-1/2)