Project

General

Profile

1 1358 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6 1707 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1358 Luisehahne
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11 1373 Luisehahne
 * @requirements    PHP 5.2.2 and higher
12 1358 Luisehahne
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16
 */
17 1402 Luisehahne
// 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 1664 darkviper
/*-- 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 1681 darkviper
	$mLang = ModLanguage::getInstance();
82
	$mLang->setLanguage(dirname(__FILE__).'/languages/', LANGUAGE, DEFAULT_LANGUAGE);
83 1664 darkviper
	$sDisabled = ' disabled="disabled"';
84
	$sSelected  = ' selected="selected"';
85
	$sChecked   = ' checked="checked"';
86
87 1358 Luisehahne
// Get page id
88 1664 darkviper
	$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 1358 Luisehahne
	}
108 1664 darkviper
	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 1358 Luisehahne
// Get display name of person who last modified the page
116 1664 darkviper
	$user=$admin->get_user_details($aCurrentPage['modified_by']);
117 1358 Luisehahne
// Convert the unix ts for modified_when to human a readable form
118 1664 darkviper
	if($aCurrentPage['modified_when'] != 0) {
119
		$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $aCurrentPage['modified_when']+TIMEZONE);
120 1707 Luisehahne
	} else {
121 1664 darkviper
		$modified_ts = 'Unknown';
122
	}
123 1358 Luisehahne
// Setup template object, parse vars to it, then parse it
124 1529 Luisehahne
// Create new template object
125 1707 Luisehahne
	$oTpl = new Template(dirname($admin->correct_theme_source('pages_settings.htt')),'keep' );
126 1664 darkviper
	$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 1707 Luisehahne
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 1664 darkviper
/*-- 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 1681 darkviper
	$bIsMenuLink = (intval($database->get_one($sql)) != 0);
164 1707 Luisehahne
//	$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 1681 darkviper
	}else {
175 1707 Luisehahne
//		$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 1664 darkviper
	}
182 1358 Luisehahne
183 1681 darkviper
/*-- 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 1707 Luisehahne
//	$oTpl->set_var('ICON_DIR', WB_REL.$sIconDir);
191
	$sHelp = replaceVars($mLang->HELP_PAGE_IMAGE_DIR, array('icon_dir'=>WB_REL.$sIconDir ) );
192
193
	$oTpl->set_var('p_page_icon_dir',  p($sHelp,$mLang->TEXT_PAGE_ICON_DIR));
194
	$oTpl->set_var('p_menu_icon0_dir', p($sHelp,$mLang->TEXT_MENU_ICON_0_DIR));
195
	$oTpl->set_var('p_menu_icon1_dir', p($sHelp,$mLang->TEXT_MENU_ICON_1_DIR));
196
	$oTpl->set_var('p_menu_page_code', p($mLang->HELP_PAGE_CODE,$mLang->TEXT_PAGE_CODE));
197
198 1681 darkviper
	if(is_readable(WB_PATH.$sIconDir)) {
199
		$oIterator = new DirectoryIterator(WB_PATH.$sIconDir);
200
		foreach ($oIterator as $fileinfo) {
201
			if(preg_match('/'.$sAllowedImageTypes.'$/i', $fileinfo->getFilename())) {
202 1685 darkviper
				$sItem = str_replace(str_replace('\\', '/', WB_PATH), '',
203
						             str_replace('\\', '/', $fileinfo->getPathname()));
204 1681 darkviper
//				$sItem = WB_REL.$sItem;
205
				$aPageIcons[] = array('VALUE'=>$sItem, 'NAME'=>$fileinfo->getFilename());
206
			}
207
		}
208
	}
209
/*-- show page-icon select box ---------------------------------------------------------*/
210
	$oTpl->set_block('main_block', 'page_icon_list_block', 'page_icon_list');
211 1707 Luisehahne
	if(sizeof($aPageIcons)>0){
212
		foreach($aPageIcons as $value) {
213
			$aIcon = $value;
214
			$aIcon['SELECTED'] = ($aCurrentPage['page_icon'] == $aIcon['VALUE'] ? $sSelected : '');
215
			$oTpl->set_var($aIcon);
216
			$oTpl->parse('page_icon_list', 'page_icon_list_block', true);
217
		}
218
	} else {
219
	$oTpl->parse('page_icon_list', '');
220 1681 darkviper
	}
221
/*-- show menu-icon-0 select box -------------------------------------------------------*/
222
	$oTpl->set_block('main_block', 'menu_icon0_list_block', 'menu_icon0_list');
223 1707 Luisehahne
	if(sizeof($aPageIcons)>0){
224
		foreach($aPageIcons as $value) {
225
			$aIcon = $value;
226
			$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_0'] == $aIcon['VALUE'] ? $sSelected : '');
227
			$oTpl->set_var($aIcon);
228
			$oTpl->parse('menu_icon0_list', 'menu_icon0_list_block', true);
229
		}
230
	} else {
231
	$oTpl->parse('menu_icon0_list', '');
232 1681 darkviper
	}
233
/*-- show menu-icon-1 select box -------------------------------------------------------*/
234
	$oTpl->set_block('main_block', 'menu_icon1_list_block', 'menu_icon1_list');
235 1707 Luisehahne
	if(sizeof($aPageIcons)>0){
236
		foreach($aPageIcons as $value) {
237
			$aIcon = $value;
238
			$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_1'] == $aIcon['VALUE'] ? $sSelected : '');
239
			$oTpl->set_var($aIcon);
240
			$oTpl->parse('menu_icon1_list', 'menu_icon1_list_block', true);
241
		}
242
	} else {
243
	$oTpl->parse('menu_icon1_list', '');
244 1681 darkviper
	}
245 1664 darkviper
/*-- show visibility select box --------------------------------------------------------*/
246
	$aVisibility = array();
247
	$aVisibility['PUBLIC_SELECTED']     = ($aCurrentPage['visibility'] == 'public' ? $sSelected : '');
248
	$aVisibility['PRIVATE_SELECTED']    = ($aCurrentPage['visibility'] == 'private' ? $sSelected : '');
249
	$aVisibility['REGISTERED_SELECTED'] = ($aCurrentPage['visibility'] == 'registered' ? $sSelected : '');
250
	$aVisibility['HIDDEN_SELECTED']     = ($aCurrentPage['visibility'] == 'hidden' ? $sSelected : '');
251
	$aVisibility['NO_VIS_SELECTED']     = ($aCurrentPage['visibility'] == 'none' ? $sSelected : '');
252
	$oTpl->set_var($aVisibility);
253 1358 Luisehahne
254 1664 darkviper
/*-- admin group list block ------------------------------------------------------------*/
255
	$aAdminGroups = explode(',', '1,'.$aCurrentPage['admin_groups']);
256
	$sAdminGroups = implode(',', array_unique($aAdminGroups));
257
	$sql = 'SELECT `group_id` `ID`, `name` `NAME`, `system_permissions` `permissions` '
258
	     . 'FROM `'.TABLE_PREFIX.'groups` '
259
	     . 'ORDER BY (`ID` NOT IN('.$sAdminGroups.')), `NAME`';
260
	if( ($oGroups = $database->query($sql)))
261
	{
262
		$oTpl->set_block('main_block', 'admin_group_list_block', 'admin_group_list');
263
		while( $aGroup = $oGroups->fetchRow(MYSQL_ASSOC))
264
		{
265
			if($aGroup['ID'] == 1) {
266
			// never uncheck admin group
267
				$aGroup['CHECKED'] = $sChecked;
268
				$aGroup['DISABLED'] = $sDisabled;
269
			}else {
270
			// skip groups without system_permissions
271
				if(!$admin->is_group_match('pages_modify', $aGroup['permissions'])) { continue; }
272
			// check already selected groups
273
				$bChecked = $admin->is_group_match($aGroup['ID'], $aCurrentPage['admin_groups']);
274
			// disable selected groups where current user is not member of
275
				$bDisabled = !$admin->ami_group_member($aGroup['ID']);
276
				$aGroup['CHECKED']  = $bChecked ? $sChecked : '';
277
				$aGroup['DISABLED'] = ($bChecked && $bDisabled) ? $sDisabled : '';
278
			}
279
			unset($aGroup['permissions']);
280
			$oTpl->set_var($aGroup);
281
			$oTpl->parse('admin_group_list', 'admin_group_list_block', true);
282 1358 Luisehahne
		}
283 1664 darkviper
	}
284 1358 Luisehahne
285 1664 darkviper
/*-- viewer group list block -----------------------------------------------------------*/
286
	$aViewingGroups = explode(',', '1,'.$aCurrentPage['viewing_groups']);
287
	$sViewingGroups = implode(',', array_unique($aViewingGroups));
288
	$oTpl->set_block('main_block', 'viewer_group_list_block', 'viewer_group_list');
289
	$sql = 'SELECT `group_id` `ID`, `name` `NAME` '
290
		 . 'FROM `'.TABLE_PREFIX.'groups` '
291
	     . 'ORDER BY (`ID` NOT IN('.$sViewingGroups.')), `NAME`';
292
	if(($oGroups = $database->query($sql))) {
293
		while($aGroup = $oGroups->fetchRow(MYSQL_ASSOC)) {
294
			if($aGroup['ID'] == 1) {
295
			// never uncheck admin group
296
				$aGroup['CHECKED'] = $sChecked;
297
				$aGroup['DISABLED'] = $sDisabled;
298
			}else {
299
			// check already selected groups
300
				$bChecked = $admin->is_group_match($aGroup['ID'], $aCurrentPage['viewing_groups']);
301
			// disable selected groups where current user is not member of
302
				$bDisabled = !$admin->ami_group_member($aGroup['ID']);
303
				$aGroup['CHECKED']  = $bChecked ? $sChecked : '';
304
				$aGroup['DISABLED'] = ($bChecked && $bDisabled) ? $sDisabled : '';
305 1358 Luisehahne
			}
306 1664 darkviper
			$oTpl->set_var($aGroup);
307
			$oTpl->parse('viewer_group_list', 'viewer_group_list_block', true);
308 1358 Luisehahne
		}
309
	}
310 1415 DarkViper
311 1664 darkviper
/*-- admin user list block -------------------------------------------------------------*/
312 1707 Luisehahne
// admin_group_show_list_block
313
	$oTpl->set_block('main_block', 'admin_group_show_list_block', 'admin_group_show_list');
314
315 1664 darkviper
	$aAdminUsers = ($aCurrentPage['admin_users'] == ''
316
	                ? array()
317
	                : explode(',', $aCurrentPage['admin_users']));
318
	$aAdminUsers = explode(',', $aCurrentPage['admin_users']);
319 1707 Luisehahne
	$oTpl->set_block('admin_group_show_list_block', 'admin_user_list_block', 'admin_user_list');
320 1664 darkviper
	$sAllowedAdminUsers = trim(implode(',',$aAdminUsers));
321
	$sAllowedAdminUsers = $sAllowedAdminUsers ? $sAllowedAdminUsers : '-1';
322
	$sql = 'SELECT `user_id`, `display_name` '
323
		 . 'FROM `'.TABLE_PREFIX.'users` '
324
	     . 'WHERE `active`=1 '
325
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedAdminUsers.')), `display_name`';
326
	if( ($oUsers = $database->query($sql)) ) {
327
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
328
			if($aUser['user_id'] == 1) { continue; }
329
			$oTpl->set_var(array(
330
				'ID'        => $aUser['user_id'],
331
				'NAME'      => $aUser['display_name'],
332
			    'SELECTED'  => (in_array($aUser['user_id'], $aAdminUsers) ? $sSelected : ''),
333
			));
334
			$oTpl->parse('admin_user_list', 'admin_user_list_block', true);
335
		}
336
	}
337 1707 Luisehahne
	if($admin->ami_group_member('1')) {
338
		$oTpl->parse('admin_group_show_list', 'admin_group_show_list_block', true);
339 1358 Luisehahne
340 1707 Luisehahne
	} else {
341
		$oTpl->parse('admin_group_show_list', '', true);
342
	}
343
344 1664 darkviper
/*-- viewer users list block -----------------------------------------------------------*/
345
	$aViewingUsers = ($aCurrentPage['viewing_users'] == ''
346
	                  ? array()
347
	                  : explode(',', $aCurrentPage['viewing_users']));
348
	$aViewingUsers = explode(',', $aCurrentPage['viewing_users']);
349
	$oTpl->set_block('main_block', 'viewer_user_list_block', 'viewer_user_list');
350
	$sAllowedViewingUsers = trim(implode(',',$aViewingUsers));
351
	$sAllowedViewingUsers = $sAllowedViewingUsers ? $sAllowedViewingUsers : '-1';
352
	$sql = 'SELECT `user_id`, `display_name` '
353
		 . 'FROM `'.TABLE_PREFIX.'users` '
354
	     . 'WHERE `active`=1 '
355
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedViewingUsers.')), `display_name`';
356
	if( ($oUsers = $database->query($sql)) ) {
357
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
358
			if($aUser['user_id'] == 1) { continue; }
359
			$oTpl->set_var(array(
360
				'ID'        => $aUser['user_id'],
361
				'NAME'      => $aUser['display_name'],
362
			    'SELECTED'  => (in_array($aUser['user_id'], $aViewingUsers) ? $sSelected : ''),
363
			));
364
			$oTpl->parse('viewer_user_list', 'viewer_user_list_block', true);
365 1358 Luisehahne
		}
366 1664 darkviper
	}
367 1358 Luisehahne
368 1664 darkviper
/*-- size user lists -------------------------------------------------------------------*/
369
	$aSkaleSizeOfList = array(0 => 5, 12 => 10, 25 => 20, 50 => 30, 75 => 40, 100 => 50);
370
	$iListSize = 6;
371
	if($oUsers) {
372
		$iNumberOfUsers = $oUsers->numRows();
373
		foreach($aSkaleSizeOfList as $key => $val){
374
			if($iNumberOfUsers > $key) {
375
				$iListSize = $val;
376
			}else { break; }
377 1358 Luisehahne
		}
378 1664 darkviper
	}
379
	$oTpl->set_var('USER_LIST_SIZE', $iListSize);
380 1358 Luisehahne
381 1664 darkviper
/*-- show private viewers block --------------------------------------------------------*/
382
	if($aCurrentPage['visibility'] == 'private' OR $aCurrentPage['visibility'] == 'registered')
383
	{
384
		$oTpl->set_var('DISPLAY_VIEWERS', '');
385
	} else {
386
		$oTpl->set_var('DISPLAY_VIEWERS', 'display:none;');
387 1358 Luisehahne
	}
388 1664 darkviper
/*-- start multilanguage page_code 20090904 --------------------------------------------*/
389 1358 Luisehahne
// Work-out if page languages feature is enabled
390 1664 darkviper
	$oTpl->set_block('main_block', 'show_page_code_block',  'show_page_code');
391
	if( (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) &&
392
		 isset($aCurrentPage['page_code']) &&
393
		 file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php') )
394
	{
395
		// workout field is set but module missing
396
		$oTpl->set_var('TEXT_PAGE_CODE',
397 1707 Luisehahne
						   '<a href="'.WB_URL.'/modules/mod_multilingual/update_keys.php?page_id='.$page_id.'">'.$mLang->TEXT_PAGE_CODE.'</a>'
398 1664 darkviper
		);
399
	/*-- begin recursive function page_code list ---------------------------------------*/
400
		function page_code_list($parent)
401
		{
402
			global $admin, $database, $oTpl, $aCurrentPage, $pageCode;
403
			$default_language = DEFAULT_LANGUAGE;
404 1358 Luisehahne
405 1664 darkviper
			$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` '
406
				 . 'WHERE `parent`='.$parent.' AND `language`=\''.$default_language.'\' '
407
				 . 'ORDER BY `position` ASC';
408
			$get_pages = $database->query($sql);
409 1358 Luisehahne
410 1664 darkviper
			while($page = $get_pages->fetchRow(MYSQL_ASSOC))
411
			{
412
				if(($admin->page_is_visible($page)==false) && ($page['visibility'] <> 'none') ) { continue; }
413 1358 Luisehahne
414 1664 darkviper
				$oTpl->set_var('FLAG_CODE_ICON',' none ');
415
				if( $page['parent'] == 0 )
416
				{
417
					$oTpl->set_var('FLAG_CODE_ICON','url('.THEME_URL.'/images/flags/'.strtolower($page['language']).'.png)');
418
				}
419 1358 Luisehahne
420 1664 darkviper
				// If the current page cannot be parent, then its children neither
421
				$list_next_level = true;
422
				// Stop users from adding pages with a level of more than the set page level limit
423
				if($page['level']+1 < PAGE_LEVEL_LIMIT)
424
				{
425
					$can_modify = ($admin->ami_group_member($page['admin_groups']) ||
426
								   $admin->is_group_match($admin->get_user_id(), $page['admin_users']));
427
					$title_prefix = '';
428
					for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - - &nbsp;'; }
429
					// $space = str_repeat('&nbsp;', 3);  $space.'&lt;'..'&gt;'
430
					$oTpl->set_var(array(
431
											'VALUE' => intval($page['page_code']),
432
											'PAGE_VALUE' => $title_prefix.$page['menu_title'],
433
											'PAGE_CODE' => $title_prefix.$page['page_id']
434
											)
435
									);
436
					if($aCurrentPage['page_code'] == $page['page_code'])
437 1358 Luisehahne
					{
438 1664 darkviper
						$oTpl->set_var('SELECTED', ' selected="selected"');
439
					} elseif($aCurrentPage['page_code'] == $page['page_code'])
440
					{
441
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
442
						$list_next_level=false;
443
					} elseif($can_modify != true)
444
					{
445
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
446
					} else {
447
						$oTpl->set_var('SELECTED', '');
448 1358 Luisehahne
					}
449 1664 darkviper
					$oTpl->parse('page_code_list', 'page_code_list_block', true);
450 1358 Luisehahne
				}
451 1664 darkviper
				if ($list_next_level)
452
					page_code_list($page['page_id']);
453 1358 Luisehahne
			}
454
		}
455 1664 darkviper
	/*-- end recursive function page_code list -----------------------------------------*/
456
		// Insert code_page values from page to modify
457
		$oTpl->set_block('show_page_code_block', 'page_code_list_block', 'page_code_list');
458
		if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
459
			$selected = ($aCurrentPage['parent'] == 0 ? $sSelected : '');
460
			$oTpl->set_var(array(
461
					'VALUE' => 0,
462 1681 darkviper
					'PAGE_CODE' => $mLang->TEXT_NONE,
463 1664 darkviper
					'PAGE_VALUE' => '',
464
					'SELECTED' => $selected
465
				)
466
			);
467
			$oTpl->parse('page_code_list', 'page_code_list_block', true);
468
		}
469
		// get pagecode form this page_id
470
		page_code_list(0);
471
		$oTpl->parse('show_page_code', 'show_page_code_block', true);
472
	}else {
473
		$oTpl->set_block('show_page_code', '');
474 1358 Luisehahne
	}
475 1664 darkviper
/*-- end multilanguage page_code 20090904 ----------------------------------------------*/
476 1358 Luisehahne
477 1664 darkviper
/*-- show list of parent pages ---------------------------------------------------------*/
478
	$oTpl->set_block('main_block', 'parent_page_list_block', 'parent_page_list');
479
	if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
480
		$oTpl->set_var(array(
481
					'ID' => '0',
482 1681 darkviper
					'TITLE' => $mLang->TEXT_NONE,
483 1664 darkviper
					'SELECTED' => ($aCurrentPage['parent'] == 0 ? $sSelected : ''),
484
					) );
485
		$oTpl->parse('parent_page_list', 'parent_page_list_block', true);
486 1358 Luisehahne
	}
487 1664 darkviper
	parent_list(0);
488
	$oTpl->set_var('DISPLAY_MODIFIED', ($modified_ts == 'Unknown' ? 'hide' : ''));
489 1358 Luisehahne
490 1664 darkviper
/*-- show list of templates ------------------------------------------------------------*/
491
	$oTpl->set_block('main_block', 'template_list_block', 'template_list');
492
	$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
493
	     . 'WHERE `type`=\'template\' AND `function`=\'template\' '
494
	     . 'ORDER BY `name`';
495
	if(($res_templates = $database->query($sql))) {
496
		while($rec_template = $res_templates->fetchRow(MYSQL_ASSOC)) {
497
			// Check if the user has perms to use this template
498
			if($rec_template['directory'] == $aCurrentPage['template'] OR
499
			   $admin->get_permission($rec_template['directory'], 'template'))
500
			{
501
				$oTpl->set_var('VALUE', $rec_template['directory']);
502
				$oTpl->set_var('NAME', $rec_template['name']);
503
				if($rec_template['directory'] == $aCurrentPage['template']) {
504
					$oTpl->set_var('SELECTED', $sSelected);
505
				} else {
506
					$oTpl->set_var('SELECTED', '');
507 1358 Luisehahne
				}
508 1664 darkviper
				$oTpl->parse('template_list', 'template_list_block', true);
509 1358 Luisehahne
			}
510
		}
511
	}
512
513 1664 darkviper
/*-- show menu select box --------------------------------------------------------------*/
514
	$oTpl->set_block('main_block', 'show_menu_list_block', 'show_menu_list');
515
	if(MULTIPLE_MENUS)
516
	{
517
	/*-- get menusettings from template info file --------------------------------------*/
518
		function getTemplateInfo($sTpl = '') {
519
			if(!$sTpl) { $sTpl = DEFAULT_TEMPLATE; }
520
			$sTplFile = WB_PATH.'/templates/'.$sTpl.'/info.php';
521
			if(is_readable($sTplFile)) { require_once($sTplFile); }
522
			$menu = isset($menu) ? $menu : array();
523
			return $menu;
524
		}
525
		$aMenu = getTemplateInfo($aCurrentPage['template']);
526
		// set menu[1] as default if there's no entry in info.php
527
		$aMenu[1] = (!isset($aMenu[1]) OR ($aMenu[1] == '')) ? $TEXT['MAIN'] : $aMenu[1];
528
		$oTpl->set_block('show_menu_list_block', 'menu_list_block', 'menu_list');
529
		foreach($aMenu as $iIndex => $sMenuName) {
530
			$aVars = array();
531
			$aVars['NAME']  = $sMenuName;
532
			$aVars['VALUE'] = $iIndex;
533
			$aVars['SELECTED'] = ($aCurrentPage['menu'] == $iIndex) ? $sSelected : '';
534
			$oTpl->set_var($aVars);
535
			$oTpl->parse('menu_list', 'menu_list_block', true);
536
		}
537
		$oTpl->parse('show_menu_list', 'show_menu_list_block', true);
538
	}else {
539
		$oTpl->set_block('show_menu_list', '');
540 1358 Luisehahne
	}
541
542 1664 darkviper
/*-- show language select box ----------------------------------------------------------*/
543
	$sql = 'SELECT `directory`, `name` FROM `'.TABLE_PREFIX.'addons` '
544
		 . 'WHERE `type`=\'language\' ';
545
	if( !defined('PAGE_LANGUAGES') || !PAGE_LANGUAGES) {
546
	// display only default and current language if site is single language only
547
		$sql .= 'AND `directory`=\''.DEFAULT_LANGUAGE.'\' ';
548
		if($aCurrentPage['language'] != DEFAULT_LANGUAGE) {
549
			$sql .= 'AND `directory`=\''.$aCurrentPage['language'].'\' ';
550 1358 Luisehahne
		}
551
	}
552 1664 darkviper
	$sql .= 'ORDER BY `name`';
553
	if( ($oLanguages = $database->query($sql)) )
554
	{
555
		$aAvailLanguages = array();
556
		while($aLanguage = $oLanguages->fetchRow(MYSQL_ASSOC)) {
557
			$aAvailLanguages[$aLanguage['directory']] = $aLanguage['name'];
558
		}
559
		natsort($aAvailLanguages);
560
		$oTpl->set_block('main_block', 'language_list_block', 'language_list');
561
		foreach($aAvailLanguages as $key => $val) {
562
			$oTpl->set_var(array(
563
				'VALUE' => $key,
564
				'NAME'  => $val,
565
				'FLAG_LANG_ICONS' => 'url('.THEME_URL.'/images/flags/'.strtolower($key).'.png)',
566
				'SELECTED' => ($aCurrentPage['language'] == $key ? $sSelected : ''),
567
			));
568
			$oTpl->parse('language_list', 'language_list_block', true);
569
		}
570 1358 Luisehahne
	}
571
572 1664 darkviper
/*-- show search activated box ---------------------------------------------------------*/
573
	$oTpl->set_var('SEARCHING_SELECTED_ON',  ($aCurrentPage['searching'] == 0) ? '' : $sSelected);
574
	$oTpl->set_var('SEARCHING_SELECTED_OFF', ($aCurrentPage['searching'] == 0) ? $sSelected : '');
575 1358 Luisehahne
576 1664 darkviper
/*-- show target select box ------------------------------------------------------------*/
577
	$oTpl->set_var('TOP_SELECTED',   ($aCurrentPage['target'] == '_top'   ? $sSelected : ''));
578
	$oTpl->set_var('SELF_SELECTED',  ($aCurrentPage['target'] == '_self'  ? $sSelected : ''));
579
	$oTpl->set_var('BLANK_SELECTED', ($aCurrentPage['target'] == '_blank' ? $sSelected : ''));
580 1457 Luisehahne
581 1664 darkviper
/*-- insert all needed vars from language files ----------------------------------------*/
582 1681 darkviper
	$oTpl->set_var($mLang->getLangArray());
583
/*-- finalize the page -----------------------------------------------------------------*/
584 1664 darkviper
	$oTpl->parse('main', 'main_block', false);
585
	$oTpl->pparse('output', 'page');
586 1358 Luisehahne
// Print admin footer
587 1664 darkviper
	$admin->print_footer();
588 1707 Luisehahne
589
function p($text,$lang)
590
{
591
	global $admin;
592
	$retVal  = 'onmouseover="return overlib(';
593
	$retVal .= '\''.$text.'\',';
594
	$retVal .= 'CAPTION,\''.$lang.'\',';
595
	$retVal .= 'FGCOLOR,\'#ffffff\',';
596
	$retVal .= 'BGCOLOR,\'#557c9e\',';
597
	$retVal .= 'BORDER,1,';
598
	$retVal .= 'WIDTH,';
599
	$retVal .= 'HEIGHT,';
600
	$retVal .= 'STICKY,';
601
	$retVal .= 'CAPTIONSIZE,\'13px\',';
602
	$retVal .= 'CLOSETEXT,\'X\',';
603
	$retVal .= 'CLOSESIZE,\'14px\',';
604
	$retVal .= 'CLOSECOLOR,\'#ffffff\',';
605
	$retVal .= 'TEXTSIZE,\'12px\',';
606
	$retVal .= 'VAUTO,';
607
	$retVal .= 'HAUTO,';
608
	$retVal .= 'MOUSEOFF,';
609
	$retVal .= 'WRAP,';
610
	$retVal .= 'CELLPAD,5';
611
	$retVal .= ')" onmouseout="return nd()"';
612
//	$retVal .= '';
613
614
	return $retVal;
615
}
616
617
/**
618
* replace varnames with values in a string
619
*
620
* @param string $subject: stringvariable with vars placeholder
621
* @param array $replace: values to replace vars placeholder
622
* @return string
623
*/
624
function replaceVars($subject = '', $replace = null )
625
{
626
	if(is_array($replace)==true)
627
	{
628
		foreach ($replace  as $key => $value) {
629
			$subject = str_replace("{{".$key."}}", $value, $subject);
630
		}
631
	}
632
	return $subject;
633
}