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 1435 Luisehahne
	include_once(WB_PATH.'/framework/functions-utf8.php');
27 1529 Luisehahne
	// Setup template object, parse vars to it, then parse it
28 1625 Luisehahne
	// Setup template object, parse vars to it, then parse it
29 1529 Luisehahne
	// Create new template object
30 1625 Luisehahne
	$template = new Template(dirname($admin->correct_theme_source('preferences.htt')));
31 1435 Luisehahne
	$template->set_file( 'page', 'preferences.htt' );
32
	$template->set_block( 'page', 'main_block', 'main' );
33 1912 Luisehahne
	$mLang = Translate::getinstance();
34
	$mLang->enableAddon('admin\preferences');
35
	$template->set_var($mLang->getLangArray());
36
37 1435 Luisehahne
// read user-info from table users and assign it to template
38
	$sql  = 'SELECT `display_name`, `username`, `email` FROM `'.TABLE_PREFIX.'users` ';
39
	$sql .= 'WHERE `user_id` = '.(int)$admin->get_user_id();
40
	if( $res_user = $database->query($sql) )
41
	{
42
		if( $rec_user = $res_user->fetchRow() )
43
		{
44
			$template->set_var('DISPLAY_NAME', $rec_user['display_name']);
45
			$template->set_var('USERNAME',     $rec_user['username']);
46
			$template->set_var('EMAIL',        $rec_user['email']);
47
			$template->set_var('ADMIN_URL',    ADMIN_URL);
48
		}
49
	}
50
// read available languages from table addons and assign it to the template
51 1912 Luisehahne
//	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
52
//	$sql .= 'WHERE `type` = \'language\' ORDER BY `directory`';
53
//	if( $res_lang = $database->query($sql) )
54
//	{
55
//		$template->set_block('main_block', 'language_list_block', 'language_list');
56
//		while( $rec_lang = $res_lang->fetchRow(MYSQL_ASSOC) )
57
//		{
58
//	        $langIcons = (empty($rec_lang['directory'])) ? 'none' : strtolower($rec_lang['directory']);
59
//			$template->set_var('CODE',        $rec_lang['directory']);
60
//			$template->set_var('NAME',        $rec_lang['name']);
61
//			$template->set_var('FLAG',        THEME_URL.'/images/flags/'.$langIcons);
62
//			$template->set_var('SELECTED',    (LANGUAGE == $rec_lang['directory'] ? ' selected="selected"' : '') );
63
//			$template->parse('language_list', 'language_list_block', true);
64
//		}
65
//	}
66
67
$aLangAddons = array();
68
$aLangBrowser = array();
69
70
// read available languages from table addons
71
$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
72
$sql .= 'WHERE `type` = \'language\' ORDER BY `directory`';
73
if( $oLang = $database->query($sql) )
74
{
75
    while( $aLang = $oLang->fetchRow(MYSQL_ASSOC) )
76
    {
77
        $aLangAddons[$aLang['directory']] = $aLang['name'];
78
    }
79
}
80
81
// default, if no information from client available
82
$sAutoLanguage = DEFAULT_LANGUAGE;
83
84
$aLangUsed = array_flip(explode(',',$admin->GetLanguagesInUsed()));
85
$aLangUsed = array_intersect_key($aLangAddons, $aLangUsed);
86
$template->set_block('main_block', 'language_list_block', 'language_list');
87
foreach( $aLangUsed as $sDirectory => $sName  )
88
{
89
	$langIcons = ( empty($sDirectory) ? 'none' : strtolower($sDirectory));
90
91
	$template->set_var('CODE',        $sDirectory);
92
	$template->set_var('NAME',        $sName);
93
	$template->set_var('FLAG',        THEME_URL.'/images/flags/'.$langIcons);
94
	$template->set_var('SELECTED',    ( $_SESSION['LANGUAGE'] == $sDirectory ? ' selected="selected"' : '') );
95
96
	$template->parse('language_list', 'language_list_block', true);
97
}
98
99 1435 Luisehahne
// Insert default timezone values
100 1872 Luisehahne
	$user_time = true;
101 1435 Luisehahne
	include_once( ADMIN_PATH.'/interface/timezones.php' );
102
	$template->set_block('main_block', 'timezone_list_block', 'timezone_list');
103
	foreach( $TIMEZONES AS $hour_offset => $title )
104
	{
105
		$template->set_var('VALUE',    $hour_offset);
106
		$template->set_var('NAME',     $title);
107
		$template->set_var('SELECTED', ($admin->get_timezone() == ($hour_offset * 3600) ? ' selected="selected"' : '') );
108
		$template->parse('timezone_list', 'timezone_list_block', true);
109
	}
110
// Insert date format list
111 1849 Luisehahne
	$user_time = true;
112 1435 Luisehahne
	include_once( ADMIN_PATH.'/interface/date_formats.php' );
113
	$template->set_block('main_block', 'date_format_list_block', 'date_format_list');
114 1872 Luisehahne
115 1435 Luisehahne
	foreach( $DATE_FORMATS AS $format => $title )
116
	{
117
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
118
		$template->set_var( 'VALUE', ($format != 'system_default' ? $format : 'system_default') );
119
		$template->set_var( 'NAME',  $title );
120 1872 Luisehahne
		if( ($admin->get_session('DATE_FORMAT') == $format && !isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) ||
121 1435 Luisehahne
			('system_default' == $format && isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) )
122
		{
123
			$template->set_var('SELECTED', ' selected="selected"');
124
		}else {
125
			$template->set_var('SELECTED', '');
126
		}
127
		$template->parse('date_format_list', 'date_format_list_block', true);
128
	}
129
// Insert time format list
130 1872 Luisehahne
	$user_time = true;
131 1435 Luisehahne
	include_once( ADMIN_PATH.'/interface/time_formats.php' );
132
	$template->set_block('main_block', 'time_format_list_block', 'time_format_list');
133
	foreach( $TIME_FORMATS AS $format => $title )
134
	{
135
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
136
		$template->set_var('VALUE', $format != 'system_default' ? $format : 'system_default' );
137
		$template->set_var('NAME',  $title);
138 1872 Luisehahne
		if( ($admin->get_session('TIME_FORMAT') == $format && !isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) ||
139 1435 Luisehahne
		    ('system_default' == $format && isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) )
140
		{
141
			$template->set_var('SELECTED', ' selected="selected"');
142
		} else {
143
			$template->set_var('SELECTED', '');
144
		}
145
		$template->parse('time_format_list', 'time_format_list_block', true);
146
	}
147
148
// assign systemvars to template
149
	$template->set_var(array( 'ADMIN_URL'  => ADMIN_URL,
150
	                          'WB_URL'     => WB_URL,
151
                              'THEME_URL'  => THEME_URL,
152
		                      'ACTION_URL' => ADMIN_URL.'/preferences/save.php'
153
                            )
154
                      );
155
	$template->set_var('FTAN', $admin->getFTAN());
156
	$template->set_var('FORM_NAME', 'preferences_save');
157
// assign language vars
158 1912 Luisehahne
	$template->set_var(array(
159
                              'EMPTY_STRING'             => ''
160 1435 Luisehahne
                            )
161
                      );
162
// Parse template for preferences form
163
	$template->parse('main', 'main_block', false);
164
	$output = $template->finish($template->parse('output', 'page'));
165 1912 Luisehahne
	$mLang->disableAddon();
166
167 1435 Luisehahne
	return $output;
168
}
169
// test if valid $admin-object already exists (bit complicated about PHP4 Compatibility)
170
if( !(isset($admin) && is_object($admin) && (get_class($admin) == 'admin')) )
171
{
172
    require( '../../config.php' );
173
	require_once( WB_PATH.'/framework/class.admin.php' );
174
	$admin = new admin('Preferences');
175
}
176
echo build_page($admin, $database);
177
$admin->print_footer();