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 1825 2012-11-20 17:46:08Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings.php $
14
 * @lastmodified    $Date: 2012-11-20 18:46:08 +0100 (Tue, 20 Nov 2012) $
15
 *
16
 */
17
// Create new admin object
18
if(!defined('WB_URL'))
19
{
20
    $config_file = realpath('../../config.php');
21
    if(file_exists($config_file) && !defined('WB_URL'))
22
    {
23
    	require($config_file);
24
    }
25
}
26

    
27
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
28

    
29
$admin = new admin('Pages', 'pages_settings');
30
/*-- Parent page list ------------------------------------------------------------------*/
31
	function parent_list($parent)
32
	{
33
		global $admin, $database, $oTpl, $aCurrentPage, $field_set;
34
		$sDisabled = ' disabled="disabled"';
35
		$sSelected = ' selected="selected"';
36

    
37
		$sql = 'SELECT `page_id`, `level`, `link`, `parent`, `menu_title`, `page_title`, '
38
		     .        '`language`, `admin_groups`, `admin_users`, `visibility`, '
39
		     .        '`viewing_groups`, `viewing_users` '
40
		     . 'FROM `'.TABLE_PREFIX.'pages` '
41
			 . 'WHERE `parent`='.$parent.' '
42
			 . 'ORDER BY `position` ASC';
43
		$get_pages = $database->query($sql);
44

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

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

    
143
	$sShowIconDirText = ($page_extend=='1') ? $TEXT['HIDE_ADVANCED'] : $TEXT['SHOW_ADVANCED'];
144

    
145
	$oTpl->set_var(array(
146
			'PAGE_ID'              => $aCurrentPage['page_id'],
147
			'PAGE_IDKEY'           => $admin->getIDKEY($aCurrentPage['page_id']),
148
			'PAGE_TITLE'           => ($aCurrentPage['page_title']),
149
			'PAGE_LINK'            => ($aCurrentPage['link']),
150
			'MENU_TITLE'           => ($aCurrentPage['menu_title']),
151
			'SEO_TITLE'            => ($aCurrentPage['seo_title']=='') ? $aCurrentPage['menu_title'] : $aCurrentPage['seo_title'],
152
			'DESCRIPTION'          => ($aCurrentPage['description']),
153
			'KEYWORDS'             => ($aCurrentPage['keywords']),
154
			'MODIFIED_BY'          => $user['display_name'],
155
			'MODIFIED_BY_USERNAME' => $user['username'],
156
			'MODIFIED_WHEN'        => $modified_ts,
157
			'TEXT_SAVE_BACK'       => $TEXT['SAVE'].' &amp; '.$TEXT['BACK'],
158
			'TEXT_EXTENDED'        => $sShowIconDirText,
159
			'ADMIN_URL'            => ADMIN_URL,
160
			'WB_URL'               => WB_URL,
161
			'THEME_URL'            => THEME_URL
162
			));
163

    
164
	if( $admin->get_permission('pages_modify') )
165
	{
166
		$oTpl->set_var(array(
167
				'MODIFY_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/modify.php?page_id='.$aCurrentPage['page_id'].'">',
168
				'MODIFY_LINK_AFTER' => '</a>',
169
				'DISPLAY_MANAGE_MODIFY' => 'link',
170
				));
171
	} else {
172
		$oTpl->set_var(array(
173
				'MODIFY_LINK_BEFORE' => '<span class="bold grey">',
174
				'MODIFY_LINK_AFTER' => '</span>',
175
				'DISPLAY_MANAGE_MODIFY' => 'link',
176
				));
177
	}
178

    
179

    
180
/*-- workout if we should show the "manage sections" link ------------------------------*/
181
	$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'sections` '
182
	     . 'WHERE `page_id`='.$page_id.' AND `module`=\'menu_link\'';
183
	$bIsMenuLink = (intval($database->get_one($sql)) != 0);
184
//	$oTpl->set_block('main_block', 'show_manage_sections_block', 'show_manage_sections');
185
//	if(!$bIsMenuLink && (MANAGE_SECTIONS == true) && $admin->get_permission('pages_add') )
186
	if((MANAGE_SECTIONS == true) && $admin->get_permission('pages_add') )
187
	{
188
//		$oTpl->parse('show_manage_sections', 'show_manage_sections_block', true);
189
		$oTpl->set_var(array(
190
				'SECTIONS_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/sections.php?page_id='.$aCurrentPage['page_id'].'">',
191
				'SECTIONS_LINK_AFTER' => '</a>',
192
				'DISPLAY_MANAGE_SECTIONS' => 'link',
193
				));
194
	} else {
195
//		$oTpl->set_block('show_manage_sections', '');
196
		$oTpl->set_var(array(
197
				'SECTIONS_LINK_BEFORE' => '<span class="bold grey">',
198
				'SECTIONS_LINK_AFTER' => '</span>',
199
				'DISPLAY_MANAGE_SECTIONS' => 'link',
200
				));
201
	}
202

    
203
/*-- collect page-icons for select boxes -----------------------------------------------*/
204
    $sAllowedImageTypes = '\.jpg|\.jpeg|\.png|\.gif';
205
	$aPageIcons = array();
206
	$aIcon = array();
207
	$sTemplate = ($aCurrentPage['template'] == '' ? DEFAULT_TEMPLATE : $aCurrentPage['template']);
208
	$sIconDir = str_replace('\\', '/', ((defined('PAGE_ICON_DIR') && PAGE_ICON_DIR != '') ? PAGE_ICON_DIR : MEDIA_DIRECTORY));
209
	$sIconDir = str_replace('/*', '/'.$sTemplate, $sIconDir);
210
	$bIconDirHide = ($page_extend=='1') ? '' : 'hide';
211
//	$oTpl->set_var('ICON_DIR', WB_REL.$sIconDir);
212
	$sHelp = replaceVars($mLang->HELP_PAGE_IMAGE_DIR, array('icon_dir'=>WB_REL.$sIconDir ) );
213

    
214
	$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` '
215
	     . 'WHERE `page_id`='.$page_id.' ';
216
	$sAccesFile = (($database->get_one($sql)));
217
	$sFilename = replaceVars($mLang->HELP_SEO_TITLE, array('filename'=>PAGES_DIRECTORY.$sAccesFile.PAGE_EXTENSION ) );
218

    
219
	$oTpl->set_var('PAGE_EXTENDED_HIDE',  $bIconDirHide);
220
	$oTpl->set_var('p_page_icon_dir',  p($sHelp,$mLang->TEXT_PAGE_ICON_DIR));
221
	$oTpl->set_var('p_menu_icon0_dir', p($sHelp,$mLang->TEXT_MENU_ICON_0_DIR));
222
	$oTpl->set_var('p_menu_icon1_dir', p($sHelp,$mLang->TEXT_MENU_ICON_1_DIR));
223
	$oTpl->set_var('p_menu_page_code', p($mLang->HELP_PAGE_CODE,$mLang->TEXT_PAGE_CODE));
224
	$oTpl->set_var('p_menu_filename',  p($sFilename,$mLang->TEXT_SEO_TITLE));
225

    
226
	if(is_readable(WB_PATH.$sIconDir)) {
227
		$oIterator = new DirectoryIterator(WB_PATH.$sIconDir);
228
		foreach ($oIterator as $fileinfo) {
229
			if(preg_match('/'.$sAllowedImageTypes.'$/i', $fileinfo->getFilename())) {
230
				$sItem = str_replace(str_replace('\\', '/', WB_PATH), '',
231
						             str_replace('\\', '/', $fileinfo->getPathname()));
232
//				$sItem = WB_REL.$sItem;
233
				$aPageIcons[] = array('VALUE'=>$sItem, 'NAME'=>$fileinfo->getFilename());
234
			}
235
		}
236
	}
237
/*-- show page-icon select box ---------------------------------------------------------*/
238
	$oTpl->set_block('main_block', 'page_icon_list_block', 'page_icon_list');
239
	if(sizeof($aPageIcons)>0){
240
		foreach($aPageIcons as $value) {
241
			$aIcon = $value;
242
			$aIcon['SELECTED'] = ($aCurrentPage['page_icon'] == $aIcon['VALUE'] ? $sSelected : '');
243
			$oTpl->set_var($aIcon);
244
			$oTpl->parse('page_icon_list', 'page_icon_list_block', true);
245
		}
246
	} else {
247
	$oTpl->parse('page_icon_list', '');
248
	}
249
/*-- show menu-icon-0 select box -------------------------------------------------------*/
250
	$oTpl->set_block('main_block', 'menu_icon0_list_block', 'menu_icon0_list');
251
	if(sizeof($aPageIcons)>0){
252
		foreach($aPageIcons as $value) {
253
			$aIcon = $value;
254
			$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_0'] == $aIcon['VALUE'] ? $sSelected : '');
255
			$oTpl->set_var($aIcon);
256
			$oTpl->parse('menu_icon0_list', 'menu_icon0_list_block', true);
257
		}
258
	} else {
259
	$oTpl->parse('menu_icon0_list', '');
260
	}
261
/*-- show menu-icon-1 select box -------------------------------------------------------*/
262
	$oTpl->set_block('main_block', 'menu_icon1_list_block', 'menu_icon1_list');
263
	if(sizeof($aPageIcons)>0){
264
		foreach($aPageIcons as $value) {
265
			$aIcon = $value;
266
			$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_1'] == $aIcon['VALUE'] ? $sSelected : '');
267
			$oTpl->set_var($aIcon);
268
			$oTpl->parse('menu_icon1_list', 'menu_icon1_list_block', true);
269
		}
270
	} else {
271
	$oTpl->parse('menu_icon1_list', '');
272
	}
273
/*-- show visibility select box --------------------------------------------------------*/
274
	$aVisibility = array();
275
	$aVisibility['PUBLIC_SELECTED']     = ($aCurrentPage['visibility'] == 'public' ? $sSelected : '');
276
	$aVisibility['PRIVATE_SELECTED']    = ($aCurrentPage['visibility'] == 'private' ? $sSelected : '');
277
	$aVisibility['REGISTERED_SELECTED'] = ($aCurrentPage['visibility'] == 'registered' ? $sSelected : '');
278
	$aVisibility['HIDDEN_SELECTED']     = ($aCurrentPage['visibility'] == 'hidden' ? $sSelected : '');
279
	$aVisibility['NO_VIS_SELECTED']     = ($aCurrentPage['visibility'] == 'none' ? $sSelected : '');
280
	$oTpl->set_var($aVisibility);
281

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

    
313
/*-- viewer group list block -----------------------------------------------------------*/
314
	$aViewingGroups = explode(',', '1,'.$aCurrentPage['viewing_groups']);
315
	$sViewingGroups = implode(',', array_unique($aViewingGroups));
316
	$oTpl->set_block('main_block', 'viewer_group_list_block', 'viewer_group_list');
317
	$sql = 'SELECT `group_id` `ID`, `name` `NAME` '
318
		 . 'FROM `'.TABLE_PREFIX.'groups` '
319
	     . 'ORDER BY (`ID` NOT IN('.$sViewingGroups.')), `NAME`';
320
	if(($oGroups = $database->query($sql))) {
321
		while($aGroup = $oGroups->fetchRow(MYSQL_ASSOC)) {
322
			if($aGroup['ID'] == 1) {
323
			// never uncheck admin group
324
				$aGroup['CHECKED'] = $sChecked;
325
				$aGroup['DISABLED'] = $sDisabled;
326
			}else {
327
			// check already selected groups
328
				$bChecked = $admin->is_group_match($aGroup['ID'], $aCurrentPage['viewing_groups']);
329
			// disable selected groups where current user is not member of
330
				$bDisabled = !$admin->ami_group_member('1');
331
				$aGroup['CHECKED']  = $bChecked ? $sChecked : '';
332
				$aGroup['DISABLED'] = ($bChecked && $bDisabled) ? $sDisabled : '';
333
			}
334
			$oTpl->set_var($aGroup);
335
			$oTpl->parse('viewer_group_list', 'viewer_group_list_block', true);
336
		}
337
	}
338

    
339
/*-- admin user list block -------------------------------------------------------------*/
340
// admin_group_show_list_block
341
	$oTpl->set_block('main_block', 'admin_group_show_list_block', 'admin_group_show_list');
342

    
343
	$aAdminUsers = ($aCurrentPage['admin_users'] == ''
344
	                ? array()
345
	                : explode(',', $aCurrentPage['admin_users']));
346
	$aAdminUsers = explode(',', $aCurrentPage['admin_users']);
347
	$oTpl->set_block('admin_group_show_list_block', 'admin_user_list_block', 'admin_user_list');
348
	$sAllowedAdminUsers = trim(implode(',',$aAdminUsers));
349
	$sAllowedAdminUsers = $sAllowedAdminUsers ? $sAllowedAdminUsers : '-1';
350
	$sql = 'SELECT `user_id`, `display_name`,`username` '
351
		 . 'FROM `'.TABLE_PREFIX.'users` '
352
	     . 'WHERE `active`=1 '
353
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedAdminUsers.')), `display_name`';
354
	if( ($oUsers = $database->query($sql)) ) {
355
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
356
			if($aUser['user_id'] == 1) { continue; }
357
			$oTpl->set_var(array(
358
				'ID'        => $aUser['user_id'],
359
				'NAME'      => $aUser['display_name'].' ('.$aUser['username'].')',
360
			    'SELECTED'  => (in_array($aUser['user_id'], $aAdminUsers) ? $sSelected : ''),
361
			));
362
			$oTpl->parse('admin_user_list', 'admin_user_list_block', true);
363
		}
364
	}
365
	if($admin->ami_group_member('1')) {
366
		$oTpl->parse('admin_group_show_list', 'admin_group_show_list_block', true);
367

    
368
	} else {
369
		$oTpl->parse('admin_group_show_list', '', true);
370
	}
371

    
372
/*-- viewer users list block -----------------------------------------------------------*/
373
	$aViewingUsers = ($aCurrentPage['viewing_users'] == ''
374
	                  ? array()
375
	                  : explode(',', $aCurrentPage['viewing_users']));
376
	$aViewingUsers = explode(',', $aCurrentPage['viewing_users']);
377
	$oTpl->set_block('main_block', 'viewer_user_list_block', 'viewer_user_list');
378
	$sAllowedViewingUsers = trim(implode(',',$aViewingUsers));
379
	$sAllowedViewingUsers = $sAllowedViewingUsers ? $sAllowedViewingUsers : '-1';
380
	$sql = 'SELECT `user_id`, `display_name`,`username` '
381
		 . 'FROM `'.TABLE_PREFIX.'users` '
382
	     . 'WHERE `active`=1 '
383
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedViewingUsers.')), `display_name`';
384
	if( ($oUsers = $database->query($sql)) ) {
385
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
386
			if($aUser['user_id'] == 1) { continue; }
387
			$oTpl->set_var(array(
388
				'ID'        => $aUser['user_id'],
389
				'NAME'      => $aUser['display_name'].' ('.$aUser['username'].')',
390
			    'SELECTED'  => (in_array($aUser['user_id'], $aViewingUsers) ? $sSelected : ''),
391
			));
392
			$oTpl->parse('viewer_user_list', 'viewer_user_list_block', true);
393
		}
394
	}
395

    
396
/*-- size user lists -------------------------------------------------------------------*/
397
	$aSkaleSizeOfList = array(0 => 5, 12 => 10, 25 => 20, 50 => 30, 75 => 40, 100 => 50);
398
	$iListSize = 6;
399
	if($oUsers) {
400
		$iNumberOfUsers = $oUsers->numRows();
401
		foreach($aSkaleSizeOfList as $key => $val){
402
			if($iNumberOfUsers > $key) {
403
				$iListSize = $val;
404
			}else { break; }
405
		}
406
	}
407
	$oTpl->set_var('USER_LIST_SIZE', $iListSize);
408

    
409
/*-- show private viewers block --------------------------------------------------------*/
410
	if($aCurrentPage['visibility'] == 'private' OR $aCurrentPage['visibility'] == 'registered')
411
	{
412
		$oTpl->set_var('DISPLAY_VIEWERS', '');
413
	} else {
414
		$oTpl->set_var('DISPLAY_VIEWERS', 'display:none;');
415
	}
416
/*-- start multilanguage page_code 20090904 --------------------------------------------*/
417
// Work-out if page languages feature is enabled
418
	$oTpl->set_block('main_block', 'show_page_code_block',  'show_page_code');
419
	if( (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) &&
420
		 isset($aCurrentPage['page_code']) &&
421
		 file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php') )
422
	{
423
		// workout field is set but module missing
424
		$oTpl->set_var('TEXT_PAGE_CODE',
425
						   '<a href="'.WB_URL.'/modules/mod_multilingual/update_keys.php?page_id='.$page_id.'">'.$mLang->TEXT_PAGE_CODE.'</a>'
426
		);
427
	/*-- begin recursive function page_code list ---------------------------------------*/
428
		function page_code_list($parent)
429
		{
430
			global $admin, $database, $oTpl, $aCurrentPage, $pageCode;
431
			$default_language = DEFAULT_LANGUAGE;
432

    
433
			$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` '
434
				 . 'WHERE `parent`='.$parent.' AND `language`=\''.$default_language.'\' '
435
				 . 'ORDER BY `position` ASC';
436
			$get_pages = $database->query($sql);
437

    
438
			while($page = $get_pages->fetchRow(MYSQL_ASSOC))
439
			{
440
				if(($admin->page_is_visible($page)==false) && ($page['visibility'] <> 'none') ) { continue; }
441

    
442
				$oTpl->set_var('FLAG_CODE_ICON',' none ');
443
				if( $page['parent'] == 0 )
444
				{
445
					$oTpl->set_var('FLAG_CODE_ICON','url('.THEME_URL.'/images/flags/'.strtolower($page['language']).'.png)');
446
				}
447

    
448
				// If the current page cannot be parent, then its children neither
449
				$list_next_level = true;
450
				// Stop users from adding pages with a level of more than the set page level limit
451
				if($page['level']+1 < PAGE_LEVEL_LIMIT)
452
				{
453
					$can_modify = ($admin->ami_group_member($page['admin_groups']) ||
454
								   $admin->is_group_match($admin->get_user_id(), $page['admin_users']));
455
					$title_prefix = '';
456
					for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - - &nbsp;'; }
457
					// $space = str_repeat('&nbsp;', 3);  $space.'&lt;'..'&gt;'
458
					$oTpl->set_var(array(
459
											'VALUE' => intval($page['page_code']),
460
											'PAGE_VALUE' => $title_prefix.$page['menu_title'],
461
											'PAGE_CODE' => $title_prefix.$page['page_id']
462
											)
463
									);
464
					if($aCurrentPage['page_code'] == $page['page_code'])
465
					{
466
						$oTpl->set_var('SELECTED', ' selected="selected"');
467
					} elseif($aCurrentPage['page_code'] == $page['page_code'])
468
					{
469
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
470
						$list_next_level=false;
471
					} elseif($can_modify != true)
472
					{
473
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
474
					} else {
475
						$oTpl->set_var('SELECTED', '');
476
					}
477
					$oTpl->parse('page_code_list', 'page_code_list_block', true);
478
				}
479
				if ($list_next_level)
480
					page_code_list($page['page_id']);
481
			}
482
		}
483
	/*-- end recursive function page_code list -----------------------------------------*/
484
		// Insert code_page values from page to modify
485
		$oTpl->set_block('show_page_code_block', 'page_code_list_block', 'page_code_list');
486
		if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
487
			$selected = ($aCurrentPage['parent'] == 0 ? $sSelected : '');
488
			$oTpl->set_var(array(
489
					'VALUE' => 0,
490
					'PAGE_CODE' => $mLang->TEXT_NONE,
491
					'PAGE_VALUE' => '',
492
					'SELECTED' => $selected
493
				)
494
			);
495
			$oTpl->parse('page_code_list', 'page_code_list_block', true);
496
		}
497
		// get pagecode form this page_id
498
		page_code_list(0);
499
		$oTpl->parse('show_page_code', 'show_page_code_block', true);
500
	}else {
501
		$oTpl->set_block('show_page_code', '');
502
	}
503
/*-- end multilanguage page_code 20090904 ----------------------------------------------*/
504

    
505
/*-- show list of parent pages ---------------------------------------------------------*/
506
	$oTpl->set_block('main_block', 'parent_page_list_block', 'parent_page_list');
507
	if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
508
		$oTpl->set_var(array(
509
					'ID' => '0',
510
					'TITLE' => $mLang->TEXT_NONE,
511
					'SELECTED' => ($aCurrentPage['parent'] == 0 ? $sSelected : ''),
512
					) );
513
		$oTpl->parse('parent_page_list', 'parent_page_list_block', true);
514
	}
515
	parent_list(0);
516
	$oTpl->set_var('DISPLAY_MODIFIED', ($modified_ts == 'Unknown' ? 'hide' : ''));
517

    
518
/*-- show list of templates ------------------------------------------------------------*/
519
	$oTpl->set_block('main_block', 'template_list_block', 'template_list');
520
	$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
521
	     . 'WHERE `type`=\'template\' AND `function`=\'template\' '
522
	     . 'ORDER BY `name`';
523
	if(($res_templates = $database->query($sql))) {
524
		while($rec_template = $res_templates->fetchRow(MYSQL_ASSOC)) {
525
			// Check if the user has perms to use this template
526
			if($rec_template['directory'] == $aCurrentPage['template'] OR
527
			   $admin->get_permission($rec_template['directory'], 'template'))
528
			{
529
				$oTpl->set_var('VALUE', $rec_template['directory']);
530
				$oTpl->set_var('NAME', $rec_template['name']);
531
				if($rec_template['directory'] == $aCurrentPage['template']) {
532
					$oTpl->set_var('SELECTED', $sSelected);
533
				} else {
534
					$oTpl->set_var('SELECTED', '');
535
				}
536
				$oTpl->parse('template_list', 'template_list_block', true);
537
			}
538
		}
539
	}
540

    
541
/*-- show menu select box --------------------------------------------------------------*/
542
	$oTpl->set_block('main_block', 'show_menu_list_block', 'show_menu_list');
543
	if(MULTIPLE_MENUS)
544
	{
545
	/*-- get menusettings from template info file --------------------------------------*/
546
		function getTemplateInfo($sTpl = '') {
547
			if(!$sTpl) { $sTpl = DEFAULT_TEMPLATE; }
548
			$sTplFile = WB_PATH.'/templates/'.$sTpl.'/info.php';
549
			if(is_readable($sTplFile)) { require_once($sTplFile); }
550
			$menu = isset($menu) ? $menu : array();
551
			return $menu;
552
		}
553
		$aMenu = getTemplateInfo($aCurrentPage['template']);
554
		// set menu[1] as default if there's no entry in info.php
555
		$aMenu[1] = (!isset($aMenu[1]) OR ($aMenu[1] == '')) ? $TEXT['MAIN'] : $aMenu[1];
556
		$oTpl->set_block('show_menu_list_block', 'menu_list_block', 'menu_list');
557
		foreach($aMenu as $iIndex => $sMenuName) {
558
			$aVars = array();
559
			$aVars['NAME']  = $sMenuName;
560
			$aVars['VALUE'] = $iIndex;
561
			$aVars['SELECTED'] = ($aCurrentPage['menu'] == $iIndex) ? $sSelected : '';
562
			$oTpl->set_var($aVars);
563
			$oTpl->parse('menu_list', 'menu_list_block', true);
564
		}
565
		$oTpl->parse('show_menu_list', 'show_menu_list_block', true);
566
	}else {
567
		$oTpl->set_block('show_menu_list', '');
568
	}
569

    
570
/*-- show language select box ----------------------------------------------------------*/
571
	$sql = 'SELECT `directory`, `name` FROM `'.TABLE_PREFIX.'addons` '
572
		 . 'WHERE `type`=\'language\' ';
573
	if( !defined('PAGE_LANGUAGES') || !PAGE_LANGUAGES) {
574
	// display only default and current language if site is single language only
575
		$sql .= 'AND `directory`=\''.DEFAULT_LANGUAGE.'\' ';
576
		if($aCurrentPage['language'] != DEFAULT_LANGUAGE) {
577
			$sql .= 'AND `directory`=\''.$aCurrentPage['language'].'\' ';
578
		}
579
	}
580
	$sql .= 'ORDER BY `name`';
581
	if( ($oLanguages = $database->query($sql)) )
582
	{
583
		$aAvailLanguages = array();
584
		while($aLanguage = $oLanguages->fetchRow(MYSQL_ASSOC)) {
585
			$aAvailLanguages[$aLanguage['directory']] = $aLanguage['name'];
586
		}
587
		natsort($aAvailLanguages);
588
		$oTpl->set_block('main_block', 'language_list_block', 'language_list');
589
		foreach($aAvailLanguages as $key => $val) {
590
			$oTpl->set_var(array(
591
				'VALUE' => $key,
592
				'NAME'  => $val,
593
				'FLAG_LANG_ICONS' => 'url('.THEME_URL.'/images/flags/'.strtolower($key).'.png)',
594
				'SELECTED' => ($aCurrentPage['language'] == $key ? $sSelected : ''),
595
			));
596
			$oTpl->parse('language_list', 'language_list_block', true);
597
		}
598
	}
599

    
600
/*-- show search activated box ---------------------------------------------------------*/
601
	$oTpl->set_var('SEARCHING_SELECTED_ON',  ($aCurrentPage['searching'] == 0) ? '' : $sSelected);
602
	$oTpl->set_var('SEARCHING_SELECTED_OFF', ($aCurrentPage['searching'] == 0) ? $sSelected : '');
603

    
604
/*-- show target select box ------------------------------------------------------------*/
605
	$oTpl->set_var('TOP_SELECTED',   ($aCurrentPage['target'] == '_top'   ? $sSelected : ''));
606
	$oTpl->set_var('SELF_SELECTED',  ($aCurrentPage['target'] == '_self'  ? $sSelected : ''));
607
	$oTpl->set_var('BLANK_SELECTED', ($aCurrentPage['target'] == '_blank' ? $sSelected : ''));
608

    
609
/*-- insert all needed vars from language files ----------------------------------------*/
610
	$oTpl->set_var($mLang->getLangArray());
611
/*-- finalize the page -----------------------------------------------------------------*/
612
	$oTpl->parse('main', 'main_block', false);
613
	$oTpl->pparse('output', 'page');
614
// Print admin footer
615
	$admin->print_footer();
616

    
617
function p($text,$lang)
618
{
619
	global $admin;
620
	$retVal  = 'onclick="return overlib(';
621
	$retVal .= '\''.$text.'\',';
622
	$retVal .= 'CAPTION,\''.$lang.'\',';
623
	$retVal .= 'FGCOLOR,\'#ffffff\',';
624
	$retVal .= 'BGCOLOR,\'#557c9e\',';
625
	$retVal .= 'BORDER,1,';
626
	$retVal .= 'WIDTH,';
627
	$retVal .= 'HEIGHT,';
628
	$retVal .= 'STICKY,';
629
	$retVal .= 'CAPTIONSIZE,\'13px\',';
630
	$retVal .= 'CLOSETEXT,\'X\',';
631
	$retVal .= 'CLOSESIZE,\'14px\',';
632
	$retVal .= 'CLOSECOLOR,\'#ffffff\',';
633
	$retVal .= 'TEXTSIZE,\'12px\',';
634
	$retVal .= 'VAUTO,';
635
	$retVal .= 'HAUTO,';
636
	$retVal .= 'MOUSEOFF,';
637
	$retVal .= 'WRAP,';
638
	$retVal .= 'CELLPAD,5';
639
	$retVal .= ')" onmouseout="return nd()"';
640
//	$retVal .= '';
641

    
642
	return $retVal;
643
}
644

    
645
/**
646
* replace varnames with values in a string
647
*
648
* @param string $subject: stringvariable with vars placeholder
649
* @param array $replace: values to replace vars placeholder
650
* @return string
651
*/
652
function replaceVars($subject = '', $replace = null )
653
{
654
	if(is_array($replace)==true)
655
	{
656
		foreach ($replace  as $key => $value) {
657
			$subject = str_replace("{{".$key."}}", $value, $subject);
658
		}
659
	}
660
	return $subject;
661
}
(21-21/23)