Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.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 1923 2013-06-08 09:58:47Z darkviper $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings.php $
14
 * @lastmodified    $Date: 2013-06-08 11:58:47 +0200 (Sat, 08 Jun 2013) $
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
	$mLang = Translate::getinstance();
92
	$mLang->enableAddon('admin\pages');
93
	$sDisabled = ' disabled="disabled"';
94
	$sSelected = ' selected="selected"';
95
	$sChecked  = ' checked="checked"';
96

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

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

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

    
182

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

    
206
/*-- collect page-icons for select boxes -----------------------------------------------*/
207
  $sAllowedImageTypes = '\.jpg|\.jpeg|\.png|\.gif';
208
	$aPageIcons = array();
209
	$aIcon = array();
210
	$sTemplate = ($aCurrentPage['template'] == '' ? DEFAULT_TEMPLATE : $aCurrentPage['template']);
211
	$sIconDir = str_replace('\\', '/', ((defined('PAGE_ICON_DIR') && PAGE_ICON_DIR != '') ? PAGE_ICON_DIR : MEDIA_DIRECTORY));
212
	$sIconDir = str_replace('/*', '/'.$sTemplate, $sIconDir);
213
	$bIconDirHide = ($page_extend==true) ? 'display:block;' : 'display:none;';
214

    
215
//	$oTpl->set_var('ICON_DIR', WB_REL.$sIconDir);
216
	$sHelp = replaceVars($mLang->HELP_PAGE_IMAGE_DIR, array('icon_dir'=>WB_REL.$sIconDir ) );
217

    
218
	$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` '
219
	     . 'WHERE `page_id`='.$page_id.' ';
220
	$sAccesFile = (($database->get_one($sql)));
221
	$sFilename = replaceVars($mLang->HELP_SEO_TITLE, array('filename'=>PAGES_DIRECTORY.$sAccesFile.PAGE_EXTENSION ) );
222

    
223
	$oTpl->set_var('PAGE_EXTENDET_HIDE',  $bIconDirHide);
224
	$oTpl->set_var('p_page_icon_dir',  p($sHelp,$mLang->TEXT_PAGE_ICON_DIR));
225
	$oTpl->set_var('p_menu_icon0_dir', p($sHelp,$mLang->TEXT_MENU_ICON_0_DIR));
226
	$oTpl->set_var('p_menu_icon1_dir', p($sHelp,$mLang->TEXT_MENU_ICON_1_DIR));
227
	$oTpl->set_var('p_menu_page_code', p($mLang->HELP_PAGE_CODE,$mLang->TEXT_PAGE_CODE));
228
	$oTpl->set_var('p_menu_filename',  p($sFilename,$mLang->TEXT_SEO_TITLE));
229

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

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

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

    
343
/*-- admin user list block -------------------------------------------------------------*/
344
// admin_group_show_list_block
345
	$oTpl->set_block('main_block', 'admin_group_show_list_block', 'admin_group_show_list');
346

    
347
	$aAdminUsers = ($aCurrentPage['admin_users'] == ''
348
	                ? array()
349
	                : explode(',', $aCurrentPage['admin_users']));
350
	$aAdminUsers = explode(',', $aCurrentPage['admin_users']);
351
	$oTpl->set_block('admin_group_show_list_block', 'admin_user_list_block', 'admin_user_list');
352
	$sAllowedAdminUsers = trim(implode(',',$aAdminUsers));
353
	$sAllowedAdminUsers = $sAllowedAdminUsers ? $sAllowedAdminUsers : '-1';
354
	$sql = 'SELECT `user_id`, `display_name`,`username` '
355
		 . 'FROM `'.TABLE_PREFIX.'users` '
356
	     . 'WHERE `active`=1 '
357
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedAdminUsers.')), `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'].' ('.$aUser['username'].')',
364
			    'SELECTED'  => (in_array($aUser['user_id'], $aAdminUsers) ? $sSelected : ''),
365
			));
366
			$oTpl->parse('admin_user_list', 'admin_user_list_block', true);
367
		}
368
	}
369
	if($admin->ami_group_member('1')) {
370
		$oTpl->parse('admin_group_show_list', 'admin_group_show_list_block', true);
371

    
372
	} else {
373
		$oTpl->parse('admin_group_show_list', '', true);
374
	}
375

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
646
	return $retVal;
647
}
648

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