Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: settings.php 1685 2012-05-06 14:29:47Z darkviper $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings.php $
15
 * @lastmodified    $Date: 2012-05-06 16:29:47 +0200 (Sun, 06 May 2012) $
16
 *
17
 */
18
// Create new admin object
19
require('../../config.php');
20
require_once(WB_PATH.'/framework/class.admin.php');
21
$admin = new admin('Pages', 'pages_settings');
22

    
23
/*-- Parent page list ------------------------------------------------------------------*/
24
	function parent_list($parent)
25
	{
26
		global $admin, $database, $oTpl, $aCurrentPage, $field_set;
27
		$sDisabled = ' disabled="disabled"';
28
		$sSelected  = ' selected="selected"';
29

    
30
		$sql = 'SELECT `page_id`, `level`, `parent`, `menu_title`, `page_title`, '
31
		     .        '`language`, `admin_groups`, `admin_users`, `visibility`, '
32
		     .        '`viewing_groups`, `viewing_users` '
33
		     . 'FROM `'.TABLE_PREFIX.'pages` '
34
			 . 'WHERE `parent`='.$parent.' '
35
			 . 'ORDER BY `position` ASC';
36
		$get_pages = $database->query($sql);
37

    
38
		while($page = $get_pages->fetchRow(MYSQL_ASSOC))
39
		{
40
			if(!$admin->page_is_visible($page)) { continue; }
41
			// if parent = 0 set flag_icon
42
			$oTpl->set_var('FLAG_ROOT_ICON',' none ');
43
			if( $page['parent'] == 0  && $field_set) {
44
				$oTpl->set_var('FLAG_ROOT_ICON','url('.THEME_URL.'/images/flags/'.strtolower($page['language']).'.png)');
45
			}
46
			// If the current page cannot be parent, then its children neither
47
			$list_next_level = true;
48
			// Stop users from adding pages with a level of more than the set page level limit
49
			if($page['level']+1 < PAGE_LEVEL_LIMIT)
50
			{
51
			// Get user permisions
52
				$can_modify = ($admin->ami_group_member($page['admin_groups']) ||
53
				               $admin->is_group_match($admin->get_user_id(), $page['admin_users']));
54
				// Title -'s prefix
55
				$title_prefix = '';
56
				for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - - &nbsp;'; }
57
				$oTpl->set_var(array(
58
							'ID' => $page['page_id'],
59
							'TITLE' => ($title_prefix.$page['menu_title']),
60
							'MENU-TITLE' => ($title_prefix.$page['menu_title']),
61
							'PAGE-TITLE' => ($title_prefix.$page['page_title']),
62
							'FLAG_ICON' => ' none ',
63
							));
64
				if($aCurrentPage['parent'] == $page['page_id']) {
65
					$oTpl->set_var('SELECTED', $sSelected);
66
				} elseif($aCurrentPage['page_id'] == $page['page_id']) {
67
					$oTpl->set_var('SELECTED', $sDisabled.' class="disabled"');
68
					$list_next_level=false;
69
				} elseif($can_modify != true) {
70
					$oTpl->set_var('SELECTED', $sDisabled.' class="disabled"');
71
				} else {
72
					$oTpl->set_var('SELECTED', '');
73
				}
74
				$oTpl->parse('parent_page_list', 'parent_page_list_block', true);
75
			}
76
			if ($list_next_level) {
77
			  parent_list($page['page_id']);
78
			}
79
		}
80
	} // end of function parent_list
81
/* -------------------------------------------------------------------------------------*/
82
	$mLang = ModLanguage::getInstance();
83
	$mLang->setLanguage(dirname(__FILE__).'/languages/', LANGUAGE, DEFAULT_LANGUAGE);
84
	$sDisabled = ' disabled="disabled"';
85
	$sSelected  = ' selected="selected"';
86
	$sChecked   = ' checked="checked"';
87

    
88
// Get page id
89
	$page_id = $_GET['page_id'] ? intval($_GET['page_id']) : 0;
90
	if(!$page_id) {
91
		header("Location: index.php");
92
		exit(0);
93
	}
94
/*-- get all details of current page ---------------------------------------------------*/
95
	$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
96
	if( ($oPages = $database->query($sql)) ) {
97
		$aCurrentPage = $oPages->fetchRow(MYSQL_ASSOC);
98
		// Work-out if we should check for existing page_code
99
		$field_set = isset($aCurrentPage['page_code']);
100
		if( !$admin->ami_group_member($aCurrentPage['admin_groups']) &&
101
			!$admin->is_group_match($admin->get_user_id(), $aCurrentPage['admin_users']) )
102
		{
103
			$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
104
		}
105
	}else {
106
		$admin->print_header();
107
		$admin->print_error($database->get_error());
108
	}
109
	if(!isset($aCurrentPage['page_code'])) {
110
		$database->field_add(TABLE_PREFIX.'pages', 'page_code', 'INT NOT NULL DEFAULT \'0\'');
111
	}
112
	if($oPages->numRows() == 0) {
113
		$admin->print_header();
114
		$admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
115
	}
116
// Get display name of person who last modified the page
117
	$user=$admin->get_user_details($aCurrentPage['modified_by']);
118
// Convert the unix ts for modified_when to human a readable form
119
	if($aCurrentPage['modified_when'] != 0) {
120
		$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $aCurrentPage['modified_when']+TIMEZONE);
121
	}else {
122
		$modified_ts = 'Unknown';
123
	}
124
// Setup template object, parse vars to it, then parse it
125
// Create new template object
126
	$oTpl = new Template(dirname($admin->correct_theme_source('pages_settings.htt')), 'keep');
127
	$oTpl->set_file('page', 'pages_settings.htt');
128
	$oTpl->set_block('page', 'main_block', 'main');
129
	$oTpl->set_var('FTAN', $admin->getFTAN());
130
	$oTpl->set_var(array(
131
			'PAGE_ID'              => $aCurrentPage['page_id'],
132
			'PAGE_IDKEY'           => $admin->getIDKEY($aCurrentPage['page_id']),
133
			'PAGE_TITLE'           => ($aCurrentPage['page_title']),
134
			'MENU_TITLE'           => ($aCurrentPage['menu_title']),
135
			'DESCRIPTION'          => ($aCurrentPage['description']),
136
			'KEYWORDS'             => ($aCurrentPage['keywords']),
137
			'MODIFIED_BY'          => $user['display_name'],
138
			'MODIFIED_BY_USERNAME' => $user['username'],
139
			'MODIFIED_WHEN'        => $modified_ts,
140
			'ADMIN_URL'            => ADMIN_URL,
141
			'WB_URL'               => WB_URL,
142
			'THEME_URL'            => THEME_URL
143
			));
144
/*-- workout if we should show the "manage sections" link ------------------------------*/
145
	$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'sections` '
146
	     . 'WHERE `page_id`='.$page_id.' AND `module`=\'menu_link\'';
147
	$bIsMenuLink = (intval($database->get_one($sql)) != 0);
148
	$oTpl->set_block('main_block', 'show_manage_sections_block', 'show_manage_sections');
149
	if(!$bIsMenuLink && (MANAGE_SECTIONS == true)) {
150
		$oTpl->parse('show_manage_sections', 'show_manage_sections_block', true);
151
	}else {
152
		$oTpl->set_block('show_manage_sections', '');
153
	}
154

    
155
/*-- collect page-icons for select boxes -----------------------------------------------*/
156
    $sAllowedImageTypes = '\.jpg|\.jpeg|\.png|\.gif';
157
	$aPageIcons = array();
158
	$aIcon = array();
159
	$sTemplate = ($aCurrentPage['template'] == '' ? DEFAULT_TEMPLATE : $aCurrentPage['template']);
160
	$sIconDir = str_replace('\\', '/', ((defined('PAGE_ICON_DIR') && PAGE_ICON_DIR != '') ? PAGE_ICON_DIR : MEDIA_DIRECTORY));
161
	$sIconDir = str_replace('/*', '/'.$sTemplate, $sIconDir);
162
	$oTpl->set_var('ICON_DIR', WB_REL.$sIconDir);
163
	if(is_readable(WB_PATH.$sIconDir)) {
164
		$oIterator = new DirectoryIterator(WB_PATH.$sIconDir);
165
		foreach ($oIterator as $fileinfo) {
166
			if(preg_match('/'.$sAllowedImageTypes.'$/i', $fileinfo->getFilename())) {
167
				$sItem = str_replace(str_replace('\\', '/', WB_PATH), '',
168
						             str_replace('\\', '/', $fileinfo->getPathname()));
169
//				$sItem = WB_REL.$sItem;
170
				$aPageIcons[] = array('VALUE'=>$sItem, 'NAME'=>$fileinfo->getFilename());
171
			}
172
		}
173
	}
174
/*-- show page-icon select box ---------------------------------------------------------*/
175
	$oTpl->set_block('main_block', 'page_icon_list_block', 'page_icon_list');
176
	foreach($aPageIcons as $value) {
177
		$aIcon = $value;
178
		$aIcon['SELECTED'] = ($aCurrentPage['page_icon'] == $aIcon['VALUE'] ? $sSelected : '');
179
		$oTpl->set_var($aIcon);
180
		$oTpl->parse('page_icon_list', 'page_icon_list_block', true);
181
	}
182
/*-- show menu-icon-0 select box -------------------------------------------------------*/
183
	$oTpl->set_block('main_block', 'menu_icon0_list_block', 'menu_icon0_list');
184
	foreach($aPageIcons as $value) {
185
		$aIcon = $value;
186
		$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_0'] == $aIcon['VALUE'] ? $sSelected : '');
187
		$oTpl->set_var($aIcon);
188
		$oTpl->parse('menu_icon0_list', 'menu_icon0_list_block', true);
189
	}
190
/*-- show menu-icon-1 select box -------------------------------------------------------*/
191
	$oTpl->set_block('main_block', 'menu_icon1_list_block', 'menu_icon1_list');
192
	foreach($aPageIcons as $value) {
193
		$aIcon = $value;
194
		$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_1'] == $aIcon['VALUE'] ? $sSelected : '');
195
		$oTpl->set_var($aIcon);
196
		$oTpl->parse('menu_icon1_list', 'menu_icon1_list_block', true);
197
	}
198

    
199
/*-- show visibility select box --------------------------------------------------------*/
200
	$aVisibility = array();
201
	$aVisibility['PUBLIC_SELECTED']     = ($aCurrentPage['visibility'] == 'public' ? $sSelected : '');
202
	$aVisibility['PRIVATE_SELECTED']    = ($aCurrentPage['visibility'] == 'private' ? $sSelected : '');
203
	$aVisibility['REGISTERED_SELECTED'] = ($aCurrentPage['visibility'] == 'registered' ? $sSelected : '');
204
	$aVisibility['HIDDEN_SELECTED']     = ($aCurrentPage['visibility'] == 'hidden' ? $sSelected : '');
205
	$aVisibility['NO_VIS_SELECTED']     = ($aCurrentPage['visibility'] == 'none' ? $sSelected : '');
206
	$oTpl->set_var($aVisibility);
207

    
208
/*-- admin group list block ------------------------------------------------------------*/
209
	$aAdminGroups = explode(',', '1,'.$aCurrentPage['admin_groups']);
210
	$sAdminGroups = implode(',', array_unique($aAdminGroups));
211
	$sql = 'SELECT `group_id` `ID`, `name` `NAME`, `system_permissions` `permissions` '
212
	     . 'FROM `'.TABLE_PREFIX.'groups` '
213
	     . 'ORDER BY (`ID` NOT IN('.$sAdminGroups.')), `NAME`';
214
	if( ($oGroups = $database->query($sql)))
215
	{
216
		$oTpl->set_block('main_block', 'admin_group_list_block', 'admin_group_list');
217
		while( $aGroup = $oGroups->fetchRow(MYSQL_ASSOC))
218
		{
219
			if($aGroup['ID'] == 1) {
220
			// never uncheck admin group
221
				$aGroup['CHECKED'] = $sChecked;
222
				$aGroup['DISABLED'] = $sDisabled;
223
			}else {
224
			// skip groups without system_permissions
225
				if(!$admin->is_group_match('pages_modify', $aGroup['permissions'])) { continue; }
226
			// check already selected groups
227
				$bChecked = $admin->is_group_match($aGroup['ID'], $aCurrentPage['admin_groups']);
228
			// disable selected groups where current user is not member of
229
				$bDisabled = !$admin->ami_group_member($aGroup['ID']);
230
				$aGroup['CHECKED']  = $bChecked ? $sChecked : '';
231
				$aGroup['DISABLED'] = ($bChecked && $bDisabled) ? $sDisabled : '';
232
			}
233
			unset($aGroup['permissions']);
234
			$oTpl->set_var($aGroup);
235
			$oTpl->parse('admin_group_list', 'admin_group_list_block', true);
236
		}
237
	}
238

    
239
/*-- viewer group list block -----------------------------------------------------------*/
240
	$aViewingGroups = explode(',', '1,'.$aCurrentPage['viewing_groups']);
241
	$sViewingGroups = implode(',', array_unique($aViewingGroups));
242
	$oTpl->set_block('main_block', 'viewer_group_list_block', 'viewer_group_list');
243
	$sql = 'SELECT `group_id` `ID`, `name` `NAME` '
244
		 . 'FROM `'.TABLE_PREFIX.'groups` '
245
	     . 'ORDER BY (`ID` NOT IN('.$sViewingGroups.')), `NAME`';
246
	if(($oGroups = $database->query($sql))) {
247
		while($aGroup = $oGroups->fetchRow(MYSQL_ASSOC)) {
248
			if($aGroup['ID'] == 1) {
249
			// never uncheck admin group
250
				$aGroup['CHECKED'] = $sChecked;
251
				$aGroup['DISABLED'] = $sDisabled;
252
			}else {
253
			// check already selected groups
254
				$bChecked = $admin->is_group_match($aGroup['ID'], $aCurrentPage['viewing_groups']);
255
			// disable selected groups where current user is not member of
256
				$bDisabled = !$admin->ami_group_member($aGroup['ID']);
257
				$aGroup['CHECKED']  = $bChecked ? $sChecked : '';
258
				$aGroup['DISABLED'] = ($bChecked && $bDisabled) ? $sDisabled : '';
259
			}
260
			$oTpl->set_var($aGroup);
261
			$oTpl->parse('viewer_group_list', 'viewer_group_list_block', true);
262
		}
263
	}
264

    
265
/*-- admin user list block -------------------------------------------------------------*/
266
	$aAdminUsers = ($aCurrentPage['admin_users'] == ''
267
	                ? array()
268
	                : explode(',', $aCurrentPage['admin_users']));
269
	$aAdminUsers = explode(',', $aCurrentPage['admin_users']);
270
	$oTpl->set_block('main_block', 'admin_user_list_block', 'admin_user_list');
271
	$sAllowedAdminUsers = trim(implode(',',$aAdminUsers));
272
	$sAllowedAdminUsers = $sAllowedAdminUsers ? $sAllowedAdminUsers : '-1';
273
	$sql = 'SELECT `user_id`, `display_name` '
274
		 . 'FROM `'.TABLE_PREFIX.'users` '
275
	     . 'WHERE `active`=1 '
276
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedAdminUsers.')), `display_name`';
277
	if( ($oUsers = $database->query($sql)) ) {
278
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
279
			if($aUser['user_id'] == 1) { continue; }
280
			$oTpl->set_var(array(
281
				'ID'        => $aUser['user_id'],
282
				'NAME'      => $aUser['display_name'],
283
			    'SELECTED'  => (in_array($aUser['user_id'], $aAdminUsers) ? $sSelected : ''),
284
			));
285
			$oTpl->parse('admin_user_list', 'admin_user_list_block', true);
286
		}
287
	}
288

    
289
/*-- viewer users list block -----------------------------------------------------------*/
290
	$aViewingUsers = ($aCurrentPage['viewing_users'] == ''
291
	                  ? array()
292
	                  : explode(',', $aCurrentPage['viewing_users']));
293
	$aViewingUsers = explode(',', $aCurrentPage['viewing_users']);
294
	$oTpl->set_block('main_block', 'viewer_user_list_block', 'viewer_user_list');
295
	$sAllowedViewingUsers = trim(implode(',',$aViewingUsers));
296
	$sAllowedViewingUsers = $sAllowedViewingUsers ? $sAllowedViewingUsers : '-1';
297
	$sql = 'SELECT `user_id`, `display_name` '
298
		 . 'FROM `'.TABLE_PREFIX.'users` '
299
	     . 'WHERE `active`=1 '
300
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedViewingUsers.')), `display_name`';
301
	if( ($oUsers = $database->query($sql)) ) {
302
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
303
			if($aUser['user_id'] == 1) { continue; }
304
			$oTpl->set_var(array(
305
				'ID'        => $aUser['user_id'],
306
				'NAME'      => $aUser['display_name'],
307
			    'SELECTED'  => (in_array($aUser['user_id'], $aViewingUsers) ? $sSelected : ''),
308
			));
309
			$oTpl->parse('viewer_user_list', 'viewer_user_list_block', true);
310
		}
311
	}
312

    
313
/*-- size user lists -------------------------------------------------------------------*/
314
	$aSkaleSizeOfList = array(0 => 5, 12 => 10, 25 => 20, 50 => 30, 75 => 40, 100 => 50);
315
	$iListSize = 6;
316
	if($oUsers) {
317
		$iNumberOfUsers = $oUsers->numRows();
318
		foreach($aSkaleSizeOfList as $key => $val){
319
			if($iNumberOfUsers > $key) {
320
				$iListSize = $val;
321
			}else { break; }
322
		}
323
	}
324
	$oTpl->set_var('USER_LIST_SIZE', $iListSize);
325

    
326
/*-- show private viewers block --------------------------------------------------------*/
327
	if($aCurrentPage['visibility'] == 'private' OR $aCurrentPage['visibility'] == 'registered')
328
	{
329
		$oTpl->set_var('DISPLAY_VIEWERS', '');
330
	} else {
331
		$oTpl->set_var('DISPLAY_VIEWERS', 'display:none;');
332
	}
333
/*-- start multilanguage page_code 20090904 --------------------------------------------*/
334
// Work-out if page languages feature is enabled
335
	$oTpl->set_block('main_block', 'show_page_code_block',  'show_page_code');
336
	if( (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) &&
337
		 isset($aCurrentPage['page_code']) &&
338
		 file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php') )
339
	{
340
		// workout field is set but module missing
341
		$oTpl->set_var('TEXT_PAGE_CODE',
342
						   '<a href="'.WB_URL.'/modules/mod_multilingual/update_keys.php?page_id='.
343
						   $page_id.'">'.$mLang->TEXT_PAGE_CODE.'</a>'
344
		);
345
	/*-- begin recursive function page_code list ---------------------------------------*/
346
		function page_code_list($parent)
347
		{
348
			global $admin, $database, $oTpl, $aCurrentPage, $pageCode;
349
			$default_language = DEFAULT_LANGUAGE;
350

    
351
			$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` '
352
				 . 'WHERE `parent`='.$parent.' AND `language`=\''.$default_language.'\' '
353
				 . 'ORDER BY `position` ASC';
354
			$get_pages = $database->query($sql);
355

    
356
			while($page = $get_pages->fetchRow(MYSQL_ASSOC))
357
			{
358
				if(($admin->page_is_visible($page)==false) && ($page['visibility'] <> 'none') ) { continue; }
359

    
360
				$oTpl->set_var('FLAG_CODE_ICON',' none ');
361
				if( $page['parent'] == 0 )
362
				{
363
					$oTpl->set_var('FLAG_CODE_ICON','url('.THEME_URL.'/images/flags/'.strtolower($page['language']).'.png)');
364
				}
365

    
366
				// If the current page cannot be parent, then its children neither
367
				$list_next_level = true;
368
				// Stop users from adding pages with a level of more than the set page level limit
369
				if($page['level']+1 < PAGE_LEVEL_LIMIT)
370
				{
371
					$can_modify = ($admin->ami_group_member($page['admin_groups']) ||
372
								   $admin->is_group_match($admin->get_user_id(), $page['admin_users']));
373
					$title_prefix = '';
374
					for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - - &nbsp;'; }
375
					// $space = str_repeat('&nbsp;', 3);  $space.'&lt;'..'&gt;'
376
					$oTpl->set_var(array(
377
											'VALUE' => intval($page['page_code']),
378
											'PAGE_VALUE' => $title_prefix.$page['menu_title'],
379
											'PAGE_CODE' => $title_prefix.$page['page_id']
380
											)
381
									);
382
					if($aCurrentPage['page_code'] == $page['page_code'])
383
					{
384
						$oTpl->set_var('SELECTED', ' selected="selected"');
385
					} elseif($aCurrentPage['page_code'] == $page['page_code'])
386
					{
387
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
388
						$list_next_level=false;
389
					} elseif($can_modify != true)
390
					{
391
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
392
					} else {
393
						$oTpl->set_var('SELECTED', '');
394
					}
395
					$oTpl->parse('page_code_list', 'page_code_list_block', true);
396
				}
397
				if ($list_next_level)
398
					page_code_list($page['page_id']);
399
			}
400
		}
401
	/*-- end recursive function page_code list -----------------------------------------*/
402
		// Insert code_page values from page to modify
403
		$oTpl->set_block('show_page_code_block', 'page_code_list_block', 'page_code_list');
404
		if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
405
			$selected = ($aCurrentPage['parent'] == 0 ? $sSelected : '');
406
			$oTpl->set_var(array(
407
					'VALUE' => 0,
408
					'PAGE_CODE' => $mLang->TEXT_NONE,
409
					'PAGE_VALUE' => '',
410
					'SELECTED' => $selected
411
				)
412
			);
413
			$oTpl->parse('page_code_list', 'page_code_list_block', true);
414
		}
415
		// get pagecode form this page_id
416
		page_code_list(0);
417
		$oTpl->parse('show_page_code', 'show_page_code_block', true);
418
	}else {
419
		$oTpl->set_block('show_page_code', '');
420
	}
421
/*-- end multilanguage page_code 20090904 ----------------------------------------------*/
422

    
423
/*-- show list of parent pages ---------------------------------------------------------*/
424
	$oTpl->set_block('main_block', 'parent_page_list_block', 'parent_page_list');
425
	if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
426
		$oTpl->set_var(array(
427
					'ID' => '0',
428
					'TITLE' => $mLang->TEXT_NONE,
429
					'SELECTED' => ($aCurrentPage['parent'] == 0 ? $sSelected : ''),
430
					) );
431
		$oTpl->parse('parent_page_list', 'parent_page_list_block', true);
432
	}
433
	parent_list(0);
434
	$oTpl->set_var('DISPLAY_MODIFIED', ($modified_ts == 'Unknown' ? 'hide' : ''));
435

    
436
/*-- show list of templates ------------------------------------------------------------*/
437
	$oTpl->set_block('main_block', 'template_list_block', 'template_list');
438
	$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
439
	     . 'WHERE `type`=\'template\' AND `function`=\'template\' '
440
	     . 'ORDER BY `name`';
441
	if(($res_templates = $database->query($sql))) {
442
		while($rec_template = $res_templates->fetchRow(MYSQL_ASSOC)) {
443
			// Check if the user has perms to use this template
444
			if($rec_template['directory'] == $aCurrentPage['template'] OR
445
			   $admin->get_permission($rec_template['directory'], 'template'))
446
			{
447
				$oTpl->set_var('VALUE', $rec_template['directory']);
448
				$oTpl->set_var('NAME', $rec_template['name']);
449
				if($rec_template['directory'] == $aCurrentPage['template']) {
450
					$oTpl->set_var('SELECTED', $sSelected);
451
				} else {
452
					$oTpl->set_var('SELECTED', '');
453
				}
454
				$oTpl->parse('template_list', 'template_list_block', true);
455
			}
456
		}
457
	}
458

    
459
/*-- show menu select box --------------------------------------------------------------*/
460
	$oTpl->set_block('main_block', 'show_menu_list_block', 'show_menu_list');
461
	if(MULTIPLE_MENUS)
462
	{
463
	/*-- get menusettings from template info file --------------------------------------*/
464
		function getTemplateInfo($sTpl = '') {
465
			if(!$sTpl) { $sTpl = DEFAULT_TEMPLATE; }
466
			$sTplFile = WB_PATH.'/templates/'.$sTpl.'/info.php';
467
			if(is_readable($sTplFile)) { require_once($sTplFile); }
468
			$menu = isset($menu) ? $menu : array();
469
			return $menu;
470
		}
471
		$aMenu = getTemplateInfo($aCurrentPage['template']);
472
		// set menu[1] as default if there's no entry in info.php
473
		$aMenu[1] = (!isset($aMenu[1]) OR ($aMenu[1] == '')) ? $TEXT['MAIN'] : $aMenu[1];
474
		$oTpl->set_block('show_menu_list_block', 'menu_list_block', 'menu_list');
475
		foreach($aMenu as $iIndex => $sMenuName) {
476
			$aVars = array();
477
			$aVars['NAME']  = $sMenuName;
478
			$aVars['VALUE'] = $iIndex;
479
			$aVars['SELECTED'] = ($aCurrentPage['menu'] == $iIndex) ? $sSelected : '';
480
			$oTpl->set_var($aVars);
481
			$oTpl->parse('menu_list', 'menu_list_block', true);
482
		}
483
		$oTpl->parse('show_menu_list', 'show_menu_list_block', true);
484
	}else {
485
		$oTpl->set_block('show_menu_list', '');
486
	}
487

    
488
/*-- show language select box ----------------------------------------------------------*/
489
	$sql = 'SELECT `directory`, `name` FROM `'.TABLE_PREFIX.'addons` '
490
		 . 'WHERE `type`=\'language\' ';
491
	if( !defined('PAGE_LANGUAGES') || !PAGE_LANGUAGES) {
492
	// display only default and current language if site is single language only
493
		$sql .= 'AND `directory`=\''.DEFAULT_LANGUAGE.'\' ';
494
		if($aCurrentPage['language'] != DEFAULT_LANGUAGE) {
495
			$sql .= 'AND `directory`=\''.$aCurrentPage['language'].'\' ';
496
		}
497
	}
498
	$sql .= 'ORDER BY `name`';
499
	if( ($oLanguages = $database->query($sql)) )
500
	{
501
		$aAvailLanguages = array();
502
		while($aLanguage = $oLanguages->fetchRow(MYSQL_ASSOC)) {
503
			$aAvailLanguages[$aLanguage['directory']] = $aLanguage['name'];
504
		}
505
		natsort($aAvailLanguages);
506
		$oTpl->set_block('main_block', 'language_list_block', 'language_list');
507
		foreach($aAvailLanguages as $key => $val) {
508
			$oTpl->set_var(array(
509
				'VALUE' => $key,
510
				'NAME'  => $val,
511
				'FLAG_LANG_ICONS' => 'url('.THEME_URL.'/images/flags/'.strtolower($key).'.png)',
512
				'SELECTED' => ($aCurrentPage['language'] == $key ? $sSelected : ''),
513
			));
514
			$oTpl->parse('language_list', 'language_list_block', true);
515
		}
516
	}
517

    
518
/*-- show search activated box ---------------------------------------------------------*/
519
	$oTpl->set_var('SEARCHING_SELECTED_ON',  ($aCurrentPage['searching'] == 0) ? '' : $sSelected);
520
	$oTpl->set_var('SEARCHING_SELECTED_OFF', ($aCurrentPage['searching'] == 0) ? $sSelected : '');
521

    
522
/*-- show target select box ------------------------------------------------------------*/
523
	$oTpl->set_var('TOP_SELECTED',   ($aCurrentPage['target'] == '_top'   ? $sSelected : ''));
524
	$oTpl->set_var('SELF_SELECTED',  ($aCurrentPage['target'] == '_self'  ? $sSelected : ''));
525
	$oTpl->set_var('BLANK_SELECTED', ($aCurrentPage['target'] == '_blank' ? $sSelected : ''));
526

    
527
/*-- insert all needed vars from language files ----------------------------------------*/
528
	$oTpl->set_var($mLang->getLangArray());
529
/*-- finalize the page -----------------------------------------------------------------*/
530
	$oTpl->parse('main', 'main_block', false);
531
	$oTpl->pparse('output', 'page');
532
// Print admin footer
533
	$admin->print_footer();
(20-20/22)