Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker 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: settings.php 1731 2012-08-31 09:46:20Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings.php $
14
 * @lastmodified    $Date: 2012-08-31 11:46:20 +0200 (Fri, 31 Aug 2012) $
15
 *
16
 */
17
// Create new admin object
18
require('../../config.php');
19
require_once(WB_PATH.'/framework/class.admin.php');
20
$admin = new admin('Pages', 'pages_settings');
21

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

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

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

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

    
144
	if( $admin->get_permission('pages_modify') )
145
	{
146
		$oTpl->set_var(array(
147
				'MODIFY_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/modify.php?page_id='.$aCurrentPage['page_id'].'">',
148
				'MODIFY_LINK_AFTER' => '</a>',
149
				'DISPLAY_MANAGE_MODIFY' => 'link',
150
				));
151
	} else {
152
		$oTpl->set_var(array(
153
				'MODIFY_LINK_BEFORE' => '<span class="bold grey">',
154
				'MODIFY_LINK_AFTER' => '</span>',
155
				'DISPLAY_MANAGE_MODIFY' => 'link',
156
				));
157
	}
158

    
159

    
160
/*-- workout if we should show the "manage sections" link ------------------------------*/
161
	$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'sections` '
162
	     . 'WHERE `page_id`='.$page_id.' AND `module`=\'menu_link\'';
163
	$bIsMenuLink = (intval($database->get_one($sql)) != 0);
164
//	$oTpl->set_block('main_block', 'show_manage_sections_block', 'show_manage_sections');
165
//	if(!$bIsMenuLink && (MANAGE_SECTIONS == true) && $admin->get_permission('pages_add') )
166
	if((MANAGE_SECTIONS == true) && $admin->get_permission('pages_add') )
167
	{
168
//		$oTpl->parse('show_manage_sections', 'show_manage_sections_block', true);
169
		$oTpl->set_var(array(
170
				'SECTIONS_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/sections.php?page_id='.$aCurrentPage['page_id'].'">',
171
				'SECTIONS_LINK_AFTER' => '</a>',
172
				'DISPLAY_MANAGE_SECTIONS' => 'link',
173
				));
174
	}else {
175
//		$oTpl->set_block('show_manage_sections', '');
176
		$oTpl->set_var(array(
177
				'SECTIONS_LINK_BEFORE' => '<span class="bold grey">',
178
				'SECTIONS_LINK_AFTER' => '</span>',
179
				'DISPLAY_MANAGE_SECTIONS' => 'link',
180
				));
181
	}
182

    
183
/*-- collect page-icons for select boxes -----------------------------------------------*/
184
    $sAllowedImageTypes = '\.jpg|\.jpeg|\.png|\.gif';
185
	$aPageIcons = array();
186
	$aIcon = array();
187
	$sTemplate = ($aCurrentPage['template'] == '' ? DEFAULT_TEMPLATE : $aCurrentPage['template']);
188
	$sIconDir = str_replace('\\', '/', ((defined('PAGE_ICON_DIR') && PAGE_ICON_DIR != '') ? PAGE_ICON_DIR : MEDIA_DIRECTORY));
189
	$sIconDir = str_replace('/*', '/'.$sTemplate, $sIconDir);
190
	$bIconDirHide = (defined('PAGE_EXTENDED') && PAGE_EXTENDED == 'true') ? '' : 'hide';
191
//	$oTpl->set_var('ICON_DIR', WB_REL.$sIconDir);
192
	$sHelp = replaceVars($mLang->HELP_PAGE_IMAGE_DIR, array('icon_dir'=>WB_REL.$sIconDir ) );
193

    
194
	$oTpl->set_var('PAGE_EXTENDED_HIDE',  $bIconDirHide);
195
	$oTpl->set_var('p_page_icon_dir',  p($sHelp,$mLang->TEXT_PAGE_ICON_DIR));
196
	$oTpl->set_var('p_menu_icon0_dir', p($sHelp,$mLang->TEXT_MENU_ICON_0_DIR));
197
	$oTpl->set_var('p_menu_icon1_dir', p($sHelp,$mLang->TEXT_MENU_ICON_1_DIR));
198
	$oTpl->set_var('p_menu_page_code', p($mLang->HELP_PAGE_CODE,$mLang->TEXT_PAGE_CODE));
199

    
200
	if(is_readable(WB_PATH.$sIconDir)) {
201
		$oIterator = new DirectoryIterator(WB_PATH.$sIconDir);
202
		foreach ($oIterator as $fileinfo) {
203
			if(preg_match('/'.$sAllowedImageTypes.'$/i', $fileinfo->getFilename())) {
204
				$sItem = str_replace(str_replace('\\', '/', WB_PATH), '',
205
						             str_replace('\\', '/', $fileinfo->getPathname()));
206
//				$sItem = WB_REL.$sItem;
207
				$aPageIcons[] = array('VALUE'=>$sItem, 'NAME'=>$fileinfo->getFilename());
208
			}
209
		}
210
	}
211
/*-- show page-icon select box ---------------------------------------------------------*/
212
	$oTpl->set_block('main_block', 'page_icon_list_block', 'page_icon_list');
213
	if(sizeof($aPageIcons)>0){
214
		foreach($aPageIcons as $value) {
215
			$aIcon = $value;
216
			$aIcon['SELECTED'] = ($aCurrentPage['page_icon'] == $aIcon['VALUE'] ? $sSelected : '');
217
			$oTpl->set_var($aIcon);
218
			$oTpl->parse('page_icon_list', 'page_icon_list_block', true);
219
		}
220
	} else {
221
	$oTpl->parse('page_icon_list', '');
222
	}
223
/*-- show menu-icon-0 select box -------------------------------------------------------*/
224
	$oTpl->set_block('main_block', 'menu_icon0_list_block', 'menu_icon0_list');
225
	if(sizeof($aPageIcons)>0){
226
		foreach($aPageIcons as $value) {
227
			$aIcon = $value;
228
			$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_0'] == $aIcon['VALUE'] ? $sSelected : '');
229
			$oTpl->set_var($aIcon);
230
			$oTpl->parse('menu_icon0_list', 'menu_icon0_list_block', true);
231
		}
232
	} else {
233
	$oTpl->parse('menu_icon0_list', '');
234
	}
235
/*-- show menu-icon-1 select box -------------------------------------------------------*/
236
	$oTpl->set_block('main_block', 'menu_icon1_list_block', 'menu_icon1_list');
237
	if(sizeof($aPageIcons)>0){
238
		foreach($aPageIcons as $value) {
239
			$aIcon = $value;
240
			$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_1'] == $aIcon['VALUE'] ? $sSelected : '');
241
			$oTpl->set_var($aIcon);
242
			$oTpl->parse('menu_icon1_list', 'menu_icon1_list_block', true);
243
		}
244
	} else {
245
	$oTpl->parse('menu_icon1_list', '');
246
	}
247
/*-- show visibility select box --------------------------------------------------------*/
248
	$aVisibility = array();
249
	$aVisibility['PUBLIC_SELECTED']     = ($aCurrentPage['visibility'] == 'public' ? $sSelected : '');
250
	$aVisibility['PRIVATE_SELECTED']    = ($aCurrentPage['visibility'] == 'private' ? $sSelected : '');
251
	$aVisibility['REGISTERED_SELECTED'] = ($aCurrentPage['visibility'] == 'registered' ? $sSelected : '');
252
	$aVisibility['HIDDEN_SELECTED']     = ($aCurrentPage['visibility'] == 'hidden' ? $sSelected : '');
253
	$aVisibility['NO_VIS_SELECTED']     = ($aCurrentPage['visibility'] == 'none' ? $sSelected : '');
254
	$oTpl->set_var($aVisibility);
255

    
256
/*-- admin group list block ------------------------------------------------------------*/
257
	$aAdminGroups = explode(',', '1,'.$aCurrentPage['admin_groups']);
258
	$sAdminGroups = implode(',', array_unique($aAdminGroups));
259
	$sql = 'SELECT `group_id` `ID`, `name` `NAME`, `system_permissions` `permissions` '
260
	     . 'FROM `'.TABLE_PREFIX.'groups` '
261
	     . 'ORDER BY (`ID` NOT IN('.$sAdminGroups.')), `NAME`';
262
	if( ($oGroups = $database->query($sql)))
263
	{
264
		$oTpl->set_block('main_block', 'admin_group_list_block', 'admin_group_list');
265
		while( $aGroup = $oGroups->fetchRow(MYSQL_ASSOC))
266
		{
267
			if($aGroup['ID'] == 1) {
268
			// never uncheck admin group
269
				$aGroup['CHECKED'] = $sChecked;
270
				$aGroup['DISABLED'] = $sDisabled;
271
			}else {
272
			// skip groups without system_permissions
273
				if(!$admin->is_group_match('pages_modify', $aGroup['permissions'])) { continue; }
274
			// check already selected groups
275
				$bChecked = $admin->is_group_match($aGroup['ID'], $aCurrentPage['admin_groups']);
276
			// disable selected groups where current user is not member of
277
				$bDisabled = !$admin->ami_group_member($aGroup['ID']);
278
				$aGroup['CHECKED']  = $bChecked ? $sChecked : '';
279
				$aGroup['DISABLED'] = ($bChecked && $bDisabled) ? $sDisabled : '';
280
			}
281
			unset($aGroup['permissions']);
282
			$oTpl->set_var($aGroup);
283
			$oTpl->parse('admin_group_list', 'admin_group_list_block', true);
284
		}
285
	}
286

    
287
/*-- viewer group list block -----------------------------------------------------------*/
288
	$aViewingGroups = explode(',', '1,'.$aCurrentPage['viewing_groups']);
289
	$sViewingGroups = implode(',', array_unique($aViewingGroups));
290
	$oTpl->set_block('main_block', 'viewer_group_list_block', 'viewer_group_list');
291
	$sql = 'SELECT `group_id` `ID`, `name` `NAME` '
292
		 . 'FROM `'.TABLE_PREFIX.'groups` '
293
	     . 'ORDER BY (`ID` NOT IN('.$sViewingGroups.')), `NAME`';
294
	if(($oGroups = $database->query($sql))) {
295
		while($aGroup = $oGroups->fetchRow(MYSQL_ASSOC)) {
296
			if($aGroup['ID'] == 1) {
297
			// never uncheck admin group
298
				$aGroup['CHECKED'] = $sChecked;
299
				$aGroup['DISABLED'] = $sDisabled;
300
			}else {
301
			// check already selected groups
302
				$bChecked = $admin->is_group_match($aGroup['ID'], $aCurrentPage['viewing_groups']);
303
			// disable selected groups where current user is not member of
304
				$bDisabled = !$admin->ami_group_member($aGroup['ID']);
305
				$aGroup['CHECKED']  = $bChecked ? $sChecked : '';
306
				$aGroup['DISABLED'] = ($bChecked && $bDisabled) ? $sDisabled : '';
307
			}
308
			$oTpl->set_var($aGroup);
309
			$oTpl->parse('viewer_group_list', 'viewer_group_list_block', true);
310
		}
311
	}
312

    
313
/*-- admin user list block -------------------------------------------------------------*/
314
// admin_group_show_list_block
315
	$oTpl->set_block('main_block', 'admin_group_show_list_block', 'admin_group_show_list');
316

    
317
	$aAdminUsers = ($aCurrentPage['admin_users'] == ''
318
	                ? array()
319
	                : explode(',', $aCurrentPage['admin_users']));
320
	$aAdminUsers = explode(',', $aCurrentPage['admin_users']);
321
	$oTpl->set_block('admin_group_show_list_block', 'admin_user_list_block', 'admin_user_list');
322
	$sAllowedAdminUsers = trim(implode(',',$aAdminUsers));
323
	$sAllowedAdminUsers = $sAllowedAdminUsers ? $sAllowedAdminUsers : '-1';
324
	$sql = 'SELECT `user_id`, `display_name` '
325
		 . 'FROM `'.TABLE_PREFIX.'users` '
326
	     . 'WHERE `active`=1 '
327
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedAdminUsers.')), `display_name`';
328
	if( ($oUsers = $database->query($sql)) ) {
329
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
330
			if($aUser['user_id'] == 1) { continue; }
331
			$oTpl->set_var(array(
332
				'ID'        => $aUser['user_id'],
333
				'NAME'      => $aUser['display_name'],
334
			    'SELECTED'  => (in_array($aUser['user_id'], $aAdminUsers) ? $sSelected : ''),
335
			));
336
			$oTpl->parse('admin_user_list', 'admin_user_list_block', true);
337
		}
338
	}
339
	if($admin->ami_group_member('1')) {
340
		$oTpl->parse('admin_group_show_list', 'admin_group_show_list_block', true);
341

    
342
	} else {
343
		$oTpl->parse('admin_group_show_list', '', true);
344
	}
345

    
346
/*-- viewer users list block -----------------------------------------------------------*/
347
	$aViewingUsers = ($aCurrentPage['viewing_users'] == ''
348
	                  ? array()
349
	                  : explode(',', $aCurrentPage['viewing_users']));
350
	$aViewingUsers = explode(',', $aCurrentPage['viewing_users']);
351
	$oTpl->set_block('main_block', 'viewer_user_list_block', 'viewer_user_list');
352
	$sAllowedViewingUsers = trim(implode(',',$aViewingUsers));
353
	$sAllowedViewingUsers = $sAllowedViewingUsers ? $sAllowedViewingUsers : '-1';
354
	$sql = 'SELECT `user_id`, `display_name` '
355
		 . 'FROM `'.TABLE_PREFIX.'users` '
356
	     . 'WHERE `active`=1 '
357
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedViewingUsers.')), `display_name`';
358
	if( ($oUsers = $database->query($sql)) ) {
359
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
360
			if($aUser['user_id'] == 1) { continue; }
361
			$oTpl->set_var(array(
362
				'ID'        => $aUser['user_id'],
363
				'NAME'      => $aUser['display_name'],
364
			    'SELECTED'  => (in_array($aUser['user_id'], $aViewingUsers) ? $sSelected : ''),
365
			));
366
			$oTpl->parse('viewer_user_list', 'viewer_user_list_block', true);
367
		}
368
	}
369

    
370
/*-- size user lists -------------------------------------------------------------------*/
371
	$aSkaleSizeOfList = array(0 => 5, 12 => 10, 25 => 20, 50 => 30, 75 => 40, 100 => 50);
372
	$iListSize = 6;
373
	if($oUsers) {
374
		$iNumberOfUsers = $oUsers->numRows();
375
		foreach($aSkaleSizeOfList as $key => $val){
376
			if($iNumberOfUsers > $key) {
377
				$iListSize = $val;
378
			}else { break; }
379
		}
380
	}
381
	$oTpl->set_var('USER_LIST_SIZE', $iListSize);
382

    
383
/*-- show private viewers block --------------------------------------------------------*/
384
	if($aCurrentPage['visibility'] == 'private' OR $aCurrentPage['visibility'] == 'registered')
385
	{
386
		$oTpl->set_var('DISPLAY_VIEWERS', '');
387
	} else {
388
		$oTpl->set_var('DISPLAY_VIEWERS', 'display:none;');
389
	}
390
/*-- start multilanguage page_code 20090904 --------------------------------------------*/
391
// Work-out if page languages feature is enabled
392
	$oTpl->set_block('main_block', 'show_page_code_block',  'show_page_code');
393
	if( (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) &&
394
		 isset($aCurrentPage['page_code']) &&
395
		 file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php') )
396
	{
397
		// workout field is set but module missing
398
		$oTpl->set_var('TEXT_PAGE_CODE',
399
						   '<a href="'.WB_URL.'/modules/mod_multilingual/update_keys.php?page_id='.$page_id.'">'.$mLang->TEXT_PAGE_CODE.'</a>'
400
		);
401
	/*-- begin recursive function page_code list ---------------------------------------*/
402
		function page_code_list($parent)
403
		{
404
			global $admin, $database, $oTpl, $aCurrentPage, $pageCode;
405
			$default_language = DEFAULT_LANGUAGE;
406

    
407
			$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` '
408
				 . 'WHERE `parent`='.$parent.' AND `language`=\''.$default_language.'\' '
409
				 . 'ORDER BY `position` ASC';
410
			$get_pages = $database->query($sql);
411

    
412
			while($page = $get_pages->fetchRow(MYSQL_ASSOC))
413
			{
414
				if(($admin->page_is_visible($page)==false) && ($page['visibility'] <> 'none') ) { continue; }
415

    
416
				$oTpl->set_var('FLAG_CODE_ICON',' none ');
417
				if( $page['parent'] == 0 )
418
				{
419
					$oTpl->set_var('FLAG_CODE_ICON','url('.THEME_URL.'/images/flags/'.strtolower($page['language']).'.png)');
420
				}
421

    
422
				// If the current page cannot be parent, then its children neither
423
				$list_next_level = true;
424
				// Stop users from adding pages with a level of more than the set page level limit
425
				if($page['level']+1 < PAGE_LEVEL_LIMIT)
426
				{
427
					$can_modify = ($admin->ami_group_member($page['admin_groups']) ||
428
								   $admin->is_group_match($admin->get_user_id(), $page['admin_users']));
429
					$title_prefix = '';
430
					for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - - &nbsp;'; }
431
					// $space = str_repeat('&nbsp;', 3);  $space.'&lt;'..'&gt;'
432
					$oTpl->set_var(array(
433
											'VALUE' => intval($page['page_code']),
434
											'PAGE_VALUE' => $title_prefix.$page['menu_title'],
435
											'PAGE_CODE' => $title_prefix.$page['page_id']
436
											)
437
									);
438
					if($aCurrentPage['page_code'] == $page['page_code'])
439
					{
440
						$oTpl->set_var('SELECTED', ' selected="selected"');
441
					} elseif($aCurrentPage['page_code'] == $page['page_code'])
442
					{
443
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
444
						$list_next_level=false;
445
					} elseif($can_modify != true)
446
					{
447
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
448
					} else {
449
						$oTpl->set_var('SELECTED', '');
450
					}
451
					$oTpl->parse('page_code_list', 'page_code_list_block', true);
452
				}
453
				if ($list_next_level)
454
					page_code_list($page['page_id']);
455
			}
456
		}
457
	/*-- end recursive function page_code list -----------------------------------------*/
458
		// Insert code_page values from page to modify
459
		$oTpl->set_block('show_page_code_block', 'page_code_list_block', 'page_code_list');
460
		if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
461
			$selected = ($aCurrentPage['parent'] == 0 ? $sSelected : '');
462
			$oTpl->set_var(array(
463
					'VALUE' => 0,
464
					'PAGE_CODE' => $mLang->TEXT_NONE,
465
					'PAGE_VALUE' => '',
466
					'SELECTED' => $selected
467
				)
468
			);
469
			$oTpl->parse('page_code_list', 'page_code_list_block', true);
470
		}
471
		// get pagecode form this page_id
472
		page_code_list(0);
473
		$oTpl->parse('show_page_code', 'show_page_code_block', true);
474
	}else {
475
		$oTpl->set_block('show_page_code', '');
476
	}
477
/*-- end multilanguage page_code 20090904 ----------------------------------------------*/
478

    
479
/*-- show list of parent pages ---------------------------------------------------------*/
480
	$oTpl->set_block('main_block', 'parent_page_list_block', 'parent_page_list');
481
	if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
482
		$oTpl->set_var(array(
483
					'ID' => '0',
484
					'TITLE' => $mLang->TEXT_NONE,
485
					'SELECTED' => ($aCurrentPage['parent'] == 0 ? $sSelected : ''),
486
					) );
487
		$oTpl->parse('parent_page_list', 'parent_page_list_block', true);
488
	}
489
	parent_list(0);
490
	$oTpl->set_var('DISPLAY_MODIFIED', ($modified_ts == 'Unknown' ? 'hide' : ''));
491

    
492
/*-- show list of templates ------------------------------------------------------------*/
493
	$oTpl->set_block('main_block', 'template_list_block', 'template_list');
494
	$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
495
	     . 'WHERE `type`=\'template\' AND `function`=\'template\' '
496
	     . 'ORDER BY `name`';
497
	if(($res_templates = $database->query($sql))) {
498
		while($rec_template = $res_templates->fetchRow(MYSQL_ASSOC)) {
499
			// Check if the user has perms to use this template
500
			if($rec_template['directory'] == $aCurrentPage['template'] OR
501
			   $admin->get_permission($rec_template['directory'], 'template'))
502
			{
503
				$oTpl->set_var('VALUE', $rec_template['directory']);
504
				$oTpl->set_var('NAME', $rec_template['name']);
505
				if($rec_template['directory'] == $aCurrentPage['template']) {
506
					$oTpl->set_var('SELECTED', $sSelected);
507
				} else {
508
					$oTpl->set_var('SELECTED', '');
509
				}
510
				$oTpl->parse('template_list', 'template_list_block', true);
511
			}
512
		}
513
	}
514

    
515
/*-- show menu select box --------------------------------------------------------------*/
516
	$oTpl->set_block('main_block', 'show_menu_list_block', 'show_menu_list');
517
	if(MULTIPLE_MENUS)
518
	{
519
	/*-- get menusettings from template info file --------------------------------------*/
520
		function getTemplateInfo($sTpl = '') {
521
			if(!$sTpl) { $sTpl = DEFAULT_TEMPLATE; }
522
			$sTplFile = WB_PATH.'/templates/'.$sTpl.'/info.php';
523
			if(is_readable($sTplFile)) { require_once($sTplFile); }
524
			$menu = isset($menu) ? $menu : array();
525
			return $menu;
526
		}
527
		$aMenu = getTemplateInfo($aCurrentPage['template']);
528
		// set menu[1] as default if there's no entry in info.php
529
		$aMenu[1] = (!isset($aMenu[1]) OR ($aMenu[1] == '')) ? $TEXT['MAIN'] : $aMenu[1];
530
		$oTpl->set_block('show_menu_list_block', 'menu_list_block', 'menu_list');
531
		foreach($aMenu as $iIndex => $sMenuName) {
532
			$aVars = array();
533
			$aVars['NAME']  = $sMenuName;
534
			$aVars['VALUE'] = $iIndex;
535
			$aVars['SELECTED'] = ($aCurrentPage['menu'] == $iIndex) ? $sSelected : '';
536
			$oTpl->set_var($aVars);
537
			$oTpl->parse('menu_list', 'menu_list_block', true);
538
		}
539
		$oTpl->parse('show_menu_list', 'show_menu_list_block', true);
540
	}else {
541
		$oTpl->set_block('show_menu_list', '');
542
	}
543

    
544
/*-- show language select box ----------------------------------------------------------*/
545
	$sql = 'SELECT `directory`, `name` FROM `'.TABLE_PREFIX.'addons` '
546
		 . 'WHERE `type`=\'language\' ';
547
	if( !defined('PAGE_LANGUAGES') || !PAGE_LANGUAGES) {
548
	// display only default and current language if site is single language only
549
		$sql .= 'AND `directory`=\''.DEFAULT_LANGUAGE.'\' ';
550
		if($aCurrentPage['language'] != DEFAULT_LANGUAGE) {
551
			$sql .= 'AND `directory`=\''.$aCurrentPage['language'].'\' ';
552
		}
553
	}
554
	$sql .= 'ORDER BY `name`';
555
	if( ($oLanguages = $database->query($sql)) )
556
	{
557
		$aAvailLanguages = array();
558
		while($aLanguage = $oLanguages->fetchRow(MYSQL_ASSOC)) {
559
			$aAvailLanguages[$aLanguage['directory']] = $aLanguage['name'];
560
		}
561
		natsort($aAvailLanguages);
562
		$oTpl->set_block('main_block', 'language_list_block', 'language_list');
563
		foreach($aAvailLanguages as $key => $val) {
564
			$oTpl->set_var(array(
565
				'VALUE' => $key,
566
				'NAME'  => $val,
567
				'FLAG_LANG_ICONS' => 'url('.THEME_URL.'/images/flags/'.strtolower($key).'.png)',
568
				'SELECTED' => ($aCurrentPage['language'] == $key ? $sSelected : ''),
569
			));
570
			$oTpl->parse('language_list', 'language_list_block', true);
571
		}
572
	}
573

    
574
/*-- show search activated box ---------------------------------------------------------*/
575
	$oTpl->set_var('SEARCHING_SELECTED_ON',  ($aCurrentPage['searching'] == 0) ? '' : $sSelected);
576
	$oTpl->set_var('SEARCHING_SELECTED_OFF', ($aCurrentPage['searching'] == 0) ? $sSelected : '');
577

    
578
/*-- show target select box ------------------------------------------------------------*/
579
	$oTpl->set_var('TOP_SELECTED',   ($aCurrentPage['target'] == '_top'   ? $sSelected : ''));
580
	$oTpl->set_var('SELF_SELECTED',  ($aCurrentPage['target'] == '_self'  ? $sSelected : ''));
581
	$oTpl->set_var('BLANK_SELECTED', ($aCurrentPage['target'] == '_blank' ? $sSelected : ''));
582

    
583
/*-- insert all needed vars from language files ----------------------------------------*/
584
	$oTpl->set_var($mLang->getLangArray());
585
/*-- finalize the page -----------------------------------------------------------------*/
586
	$oTpl->parse('main', 'main_block', false);
587
	$oTpl->pparse('output', 'page');
588
// Print admin footer
589
	$admin->print_footer();
590

    
591
function p($text,$lang)
592
{
593
	global $admin;
594
	$retVal  = 'onmouseover="return overlib(';
595
	$retVal .= '\''.$text.'\',';
596
	$retVal .= 'CAPTION,\''.$lang.'\',';
597
	$retVal .= 'FGCOLOR,\'#ffffff\',';
598
	$retVal .= 'BGCOLOR,\'#557c9e\',';
599
	$retVal .= 'BORDER,1,';
600
	$retVal .= 'WIDTH,';
601
	$retVal .= 'HEIGHT,';
602
	$retVal .= 'STICKY,';
603
	$retVal .= 'CAPTIONSIZE,\'13px\',';
604
	$retVal .= 'CLOSETEXT,\'X\',';
605
	$retVal .= 'CLOSESIZE,\'14px\',';
606
	$retVal .= 'CLOSECOLOR,\'#ffffff\',';
607
	$retVal .= 'TEXTSIZE,\'12px\',';
608
	$retVal .= 'VAUTO,';
609
	$retVal .= 'HAUTO,';
610
	$retVal .= 'MOUSEOFF,';
611
	$retVal .= 'WRAP,';
612
	$retVal .= 'CELLPAD,5';
613
	$retVal .= ')" onmouseout="return nd()"';
614
//	$retVal .= '';
615

    
616
	return $retVal;
617
}
618

    
619
/**
620
* replace varnames with values in a string
621
*
622
* @param string $subject: stringvariable with vars placeholder
623
* @param array $replace: values to replace vars placeholder
624
* @return string
625
*/
626
function replaceVars($subject = '', $replace = null )
627
{
628
	if(is_array($replace)==true)
629
	{
630
		foreach ($replace  as $key => $value) {
631
			$subject = str_replace("{{".$key."}}", $value, $subject);
632
		}
633
	}
634
	return $subject;
635
}
(20-20/22)