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 1760 Luisehahne
23 1664 darkviper
/*-- Parent page list ------------------------------------------------------------------*/
24
	function parent_list($parent)
25
	{
26
		global $admin, $database, $oTpl, $aCurrentPage, $field_set;
27
		$sDisabled = ' disabled="disabled"';
28 1780 Luisehahne
		$sSelected = ' selected="selected"';
29 1664 darkviper
30 1760 Luisehahne
		$sql = 'SELECT `page_id`, `level`, `link`, `parent`, `menu_title`, `page_title`, '
31 1664 darkviper
		     .        '`language`, `admin_groups`, `admin_users`, `visibility`, '
32
		     .        '`viewing_groups`, `viewing_users` '
33
		     . 'FROM `'.TABLE_PREFIX.'pages` '
34
			 . 'WHERE `parent`='.$parent.' '
35
			 . 'ORDER BY `position` ASC';
36
		$get_pages = $database->query($sql);
37
38
		while($page = $get_pages->fetchRow(MYSQL_ASSOC))
39
		{
40
			if(!$admin->page_is_visible($page)) { continue; }
41
			// if parent = 0 set flag_icon
42
			$oTpl->set_var('FLAG_ROOT_ICON',' none ');
43
			if( $page['parent'] == 0  && $field_set) {
44
				$oTpl->set_var('FLAG_ROOT_ICON','url('.THEME_URL.'/images/flags/'.strtolower($page['language']).'.png)');
45
			}
46
			// If the current page cannot be parent, then its children neither
47
			$list_next_level = true;
48
			// Stop users from adding pages with a level of more than the set page level limit
49
			if($page['level']+1 < PAGE_LEVEL_LIMIT)
50
			{
51
			// Get user permisions
52
				$can_modify = ($admin->ami_group_member($page['admin_groups']) ||
53
				               $admin->is_group_match($admin->get_user_id(), $page['admin_users']));
54
				// Title -'s prefix
55
				$title_prefix = '';
56
				for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - - &nbsp;'; }
57
				$oTpl->set_var(array(
58
							'ID' => $page['page_id'],
59
							'TITLE' => ($title_prefix.$page['menu_title']),
60
							'MENU-TITLE' => ($title_prefix.$page['menu_title']),
61
							'PAGE-TITLE' => ($title_prefix.$page['page_title']),
62
							'FLAG_ICON' => ' none ',
63
							));
64
				if($aCurrentPage['parent'] == $page['page_id']) {
65
					$oTpl->set_var('SELECTED', $sSelected);
66
				} elseif($aCurrentPage['page_id'] == $page['page_id']) {
67
					$oTpl->set_var('SELECTED', $sDisabled.' class="disabled"');
68
					$list_next_level=false;
69
				} elseif($can_modify != true) {
70
					$oTpl->set_var('SELECTED', $sDisabled.' class="disabled"');
71
				} else {
72
					$oTpl->set_var('SELECTED', '');
73
				}
74
				$oTpl->parse('parent_page_list', 'parent_page_list_block', true);
75
			}
76
			if ($list_next_level) {
77
			  parent_list($page['page_id']);
78
			}
79
		}
80
	} // end of function parent_list
81
/* -------------------------------------------------------------------------------------*/
82 1681 darkviper
	$mLang = ModLanguage::getInstance();
83
	$mLang->setLanguage(dirname(__FILE__).'/languages/', LANGUAGE, DEFAULT_LANGUAGE);
84 1664 darkviper
	$sDisabled = ' disabled="disabled"';
85 1780 Luisehahne
	$sSelected = ' selected="selected"';
86
	$sChecked  = ' checked="checked"';
87 1664 darkviper
88 1358 Luisehahne
// Get page id
89 1664 darkviper
	$page_id = $_GET['page_id'] ? intval($_GET['page_id']) : 0;
90
	if(!$page_id) {
91
		header("Location: index.php");
92
		exit(0);
93
	}
94
/*-- get all details of current page ---------------------------------------------------*/
95
	$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
96
	if( ($oPages = $database->query($sql)) ) {
97
		$aCurrentPage = $oPages->fetchRow(MYSQL_ASSOC);
98 1760 Luisehahne
		// Work-out if we should set seo_title
99
        $aCurrentPage['seo_title'] = basename($aCurrentPage['link']);
100 1664 darkviper
		// Work-out if we should check for existing page_code
101
		$field_set = isset($aCurrentPage['page_code']);
102
		if( !$admin->ami_group_member($aCurrentPage['admin_groups']) &&
103
			!$admin->is_group_match($admin->get_user_id(), $aCurrentPage['admin_users']) )
104
		{
105
			$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
106
		}
107
	}else {
108
		$admin->print_header();
109
		$admin->print_error($database->get_error());
110 1358 Luisehahne
	}
111 1664 darkviper
	if(!isset($aCurrentPage['page_code'])) {
112
		$database->field_add(TABLE_PREFIX.'pages', 'page_code', 'INT NOT NULL DEFAULT \'0\'');
113
	}
114
	if($oPages->numRows() == 0) {
115
		$admin->print_header();
116
		$admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
117
	}
118 1358 Luisehahne
// Get display name of person who last modified the page
119 1664 darkviper
	$user=$admin->get_user_details($aCurrentPage['modified_by']);
120 1358 Luisehahne
// Convert the unix ts for modified_when to human a readable form
121 1664 darkviper
	if($aCurrentPage['modified_when'] != 0) {
122
		$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $aCurrentPage['modified_when']+TIMEZONE);
123 1707 Luisehahne
	} else {
124 1664 darkviper
		$modified_ts = 'Unknown';
125
	}
126 1358 Luisehahne
// Setup template object, parse vars to it, then parse it
127 1529 Luisehahne
// Create new template object
128 1707 Luisehahne
	$oTpl = new Template(dirname($admin->correct_theme_source('pages_settings.htt')),'keep' );
129 1664 darkviper
	$oTpl->set_file('page', 'pages_settings.htt');
130
	$oTpl->set_block('page', 'main_block', 'main');
131
	$oTpl->set_var('FTAN', $admin->getFTAN());
132
	$oTpl->set_var(array(
133
			'PAGE_ID'              => $aCurrentPage['page_id'],
134
			'PAGE_IDKEY'           => $admin->getIDKEY($aCurrentPage['page_id']),
135
			'PAGE_TITLE'           => ($aCurrentPage['page_title']),
136 1760 Luisehahne
			'PAGE_LINK'            => ($aCurrentPage['link']),
137 1664 darkviper
			'MENU_TITLE'           => ($aCurrentPage['menu_title']),
138 1760 Luisehahne
			'SEO_TITLE'            => ($aCurrentPage['seo_title']=='') ? $aCurrentPage['menu_title'] : $aCurrentPage['seo_title'],
139 1664 darkviper
			'DESCRIPTION'          => ($aCurrentPage['description']),
140
			'KEYWORDS'             => ($aCurrentPage['keywords']),
141
			'MODIFIED_BY'          => $user['display_name'],
142
			'MODIFIED_BY_USERNAME' => $user['username'],
143
			'MODIFIED_WHEN'        => $modified_ts,
144
			'ADMIN_URL'            => ADMIN_URL,
145
			'WB_URL'               => WB_URL,
146
			'THEME_URL'            => THEME_URL
147
			));
148 1707 Luisehahne
149
	if( $admin->get_permission('pages_modify') )
150
	{
151
		$oTpl->set_var(array(
152
				'MODIFY_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/modify.php?page_id='.$aCurrentPage['page_id'].'">',
153
				'MODIFY_LINK_AFTER' => '</a>',
154
				'DISPLAY_MANAGE_MODIFY' => 'link',
155
				));
156
	} else {
157
		$oTpl->set_var(array(
158
				'MODIFY_LINK_BEFORE' => '<span class="bold grey">',
159
				'MODIFY_LINK_AFTER' => '</span>',
160
				'DISPLAY_MANAGE_MODIFY' => 'link',
161
				));
162
	}
163
164
165 1664 darkviper
/*-- workout if we should show the "manage sections" link ------------------------------*/
166
	$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'sections` '
167
	     . 'WHERE `page_id`='.$page_id.' AND `module`=\'menu_link\'';
168 1681 darkviper
	$bIsMenuLink = (intval($database->get_one($sql)) != 0);
169 1707 Luisehahne
//	$oTpl->set_block('main_block', 'show_manage_sections_block', 'show_manage_sections');
170
//	if(!$bIsMenuLink && (MANAGE_SECTIONS == true) && $admin->get_permission('pages_add') )
171
	if((MANAGE_SECTIONS == true) && $admin->get_permission('pages_add') )
172
	{
173
//		$oTpl->parse('show_manage_sections', 'show_manage_sections_block', true);
174
		$oTpl->set_var(array(
175
				'SECTIONS_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/sections.php?page_id='.$aCurrentPage['page_id'].'">',
176
				'SECTIONS_LINK_AFTER' => '</a>',
177
				'DISPLAY_MANAGE_SECTIONS' => 'link',
178
				));
179 1681 darkviper
	}else {
180 1707 Luisehahne
//		$oTpl->set_block('show_manage_sections', '');
181
		$oTpl->set_var(array(
182
				'SECTIONS_LINK_BEFORE' => '<span class="bold grey">',
183
				'SECTIONS_LINK_AFTER' => '</span>',
184
				'DISPLAY_MANAGE_SECTIONS' => 'link',
185
				));
186 1664 darkviper
	}
187 1358 Luisehahne
188 1681 darkviper
/*-- collect page-icons for select boxes -----------------------------------------------*/
189
    $sAllowedImageTypes = '\.jpg|\.jpeg|\.png|\.gif';
190
	$aPageIcons = array();
191
	$aIcon = array();
192
	$sTemplate = ($aCurrentPage['template'] == '' ? DEFAULT_TEMPLATE : $aCurrentPage['template']);
193
	$sIconDir = str_replace('\\', '/', ((defined('PAGE_ICON_DIR') && PAGE_ICON_DIR != '') ? PAGE_ICON_DIR : MEDIA_DIRECTORY));
194
	$sIconDir = str_replace('/*', '/'.$sTemplate, $sIconDir);
195 1736 Luisehahne
	$bIconDirHide = (defined('PAGE_EXTENDED') && PAGE_EXTENDED) ? '' : 'hide';
196 1707 Luisehahne
//	$oTpl->set_var('ICON_DIR', WB_REL.$sIconDir);
197
	$sHelp = replaceVars($mLang->HELP_PAGE_IMAGE_DIR, array('icon_dir'=>WB_REL.$sIconDir ) );
198
199 1780 Luisehahne
	$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` '
200
	     . 'WHERE `page_id`='.$page_id.' ';
201
	$sAccesFile = (($database->get_one($sql)));
202
	$sFilename = replaceVars($mLang->HELP_SEO_TITLE, array('filename'=>PAGES_DIRECTORY.$sAccesFile.PAGE_EXTENSION ) );
203
204 1731 Luisehahne
	$oTpl->set_var('PAGE_EXTENDED_HIDE',  $bIconDirHide);
205 1707 Luisehahne
	$oTpl->set_var('p_page_icon_dir',  p($sHelp,$mLang->TEXT_PAGE_ICON_DIR));
206
	$oTpl->set_var('p_menu_icon0_dir', p($sHelp,$mLang->TEXT_MENU_ICON_0_DIR));
207
	$oTpl->set_var('p_menu_icon1_dir', p($sHelp,$mLang->TEXT_MENU_ICON_1_DIR));
208
	$oTpl->set_var('p_menu_page_code', p($mLang->HELP_PAGE_CODE,$mLang->TEXT_PAGE_CODE));
209 1780 Luisehahne
	$oTpl->set_var('p_menu_filename', p($sFilename,$mLang->TEXT_SEO_TITLE));
210 1707 Luisehahne
211 1681 darkviper
	if(is_readable(WB_PATH.$sIconDir)) {
212
		$oIterator = new DirectoryIterator(WB_PATH.$sIconDir);
213
		foreach ($oIterator as $fileinfo) {
214
			if(preg_match('/'.$sAllowedImageTypes.'$/i', $fileinfo->getFilename())) {
215 1685 darkviper
				$sItem = str_replace(str_replace('\\', '/', WB_PATH), '',
216
						             str_replace('\\', '/', $fileinfo->getPathname()));
217 1681 darkviper
//				$sItem = WB_REL.$sItem;
218
				$aPageIcons[] = array('VALUE'=>$sItem, 'NAME'=>$fileinfo->getFilename());
219
			}
220
		}
221
	}
222
/*-- show page-icon select box ---------------------------------------------------------*/
223
	$oTpl->set_block('main_block', 'page_icon_list_block', 'page_icon_list');
224 1707 Luisehahne
	if(sizeof($aPageIcons)>0){
225
		foreach($aPageIcons as $value) {
226
			$aIcon = $value;
227
			$aIcon['SELECTED'] = ($aCurrentPage['page_icon'] == $aIcon['VALUE'] ? $sSelected : '');
228
			$oTpl->set_var($aIcon);
229
			$oTpl->parse('page_icon_list', 'page_icon_list_block', true);
230
		}
231
	} else {
232
	$oTpl->parse('page_icon_list', '');
233 1681 darkviper
	}
234
/*-- show menu-icon-0 select box -------------------------------------------------------*/
235
	$oTpl->set_block('main_block', 'menu_icon0_list_block', 'menu_icon0_list');
236 1707 Luisehahne
	if(sizeof($aPageIcons)>0){
237
		foreach($aPageIcons as $value) {
238
			$aIcon = $value;
239
			$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_0'] == $aIcon['VALUE'] ? $sSelected : '');
240
			$oTpl->set_var($aIcon);
241
			$oTpl->parse('menu_icon0_list', 'menu_icon0_list_block', true);
242
		}
243
	} else {
244
	$oTpl->parse('menu_icon0_list', '');
245 1681 darkviper
	}
246
/*-- show menu-icon-1 select box -------------------------------------------------------*/
247
	$oTpl->set_block('main_block', 'menu_icon1_list_block', 'menu_icon1_list');
248 1707 Luisehahne
	if(sizeof($aPageIcons)>0){
249
		foreach($aPageIcons as $value) {
250
			$aIcon = $value;
251
			$aIcon['SELECTED'] = ($aCurrentPage['menu_icon_1'] == $aIcon['VALUE'] ? $sSelected : '');
252
			$oTpl->set_var($aIcon);
253
			$oTpl->parse('menu_icon1_list', 'menu_icon1_list_block', true);
254
		}
255
	} else {
256
	$oTpl->parse('menu_icon1_list', '');
257 1681 darkviper
	}
258 1664 darkviper
/*-- show visibility select box --------------------------------------------------------*/
259
	$aVisibility = array();
260
	$aVisibility['PUBLIC_SELECTED']     = ($aCurrentPage['visibility'] == 'public' ? $sSelected : '');
261
	$aVisibility['PRIVATE_SELECTED']    = ($aCurrentPage['visibility'] == 'private' ? $sSelected : '');
262
	$aVisibility['REGISTERED_SELECTED'] = ($aCurrentPage['visibility'] == 'registered' ? $sSelected : '');
263
	$aVisibility['HIDDEN_SELECTED']     = ($aCurrentPage['visibility'] == 'hidden' ? $sSelected : '');
264
	$aVisibility['NO_VIS_SELECTED']     = ($aCurrentPage['visibility'] == 'none' ? $sSelected : '');
265
	$oTpl->set_var($aVisibility);
266 1358 Luisehahne
267 1664 darkviper
/*-- admin group list block ------------------------------------------------------------*/
268
	$aAdminGroups = explode(',', '1,'.$aCurrentPage['admin_groups']);
269
	$sAdminGroups = implode(',', array_unique($aAdminGroups));
270
	$sql = 'SELECT `group_id` `ID`, `name` `NAME`, `system_permissions` `permissions` '
271
	     . 'FROM `'.TABLE_PREFIX.'groups` '
272
	     . 'ORDER BY (`ID` NOT IN('.$sAdminGroups.')), `NAME`';
273
	if( ($oGroups = $database->query($sql)))
274
	{
275
		$oTpl->set_block('main_block', 'admin_group_list_block', 'admin_group_list');
276
		while( $aGroup = $oGroups->fetchRow(MYSQL_ASSOC))
277
		{
278
			if($aGroup['ID'] == 1) {
279
			// never uncheck admin group
280
				$aGroup['CHECKED'] = $sChecked;
281
				$aGroup['DISABLED'] = $sDisabled;
282
			}else {
283
			// skip groups without system_permissions
284
				if(!$admin->is_group_match('pages_modify', $aGroup['permissions'])) { continue; }
285
			// check already selected groups
286
				$bChecked = $admin->is_group_match($aGroup['ID'], $aCurrentPage['admin_groups']);
287
			// disable selected groups where current user is not member of
288 1766 Luisehahne
				$bDisabled = !$admin->ami_group_member('1');
289 1664 darkviper
				$aGroup['CHECKED']  = $bChecked ? $sChecked : '';
290
				$aGroup['DISABLED'] = ($bChecked && $bDisabled) ? $sDisabled : '';
291
			}
292
			unset($aGroup['permissions']);
293
			$oTpl->set_var($aGroup);
294
			$oTpl->parse('admin_group_list', 'admin_group_list_block', true);
295 1358 Luisehahne
		}
296 1664 darkviper
	}
297 1358 Luisehahne
298 1664 darkviper
/*-- viewer group list block -----------------------------------------------------------*/
299
	$aViewingGroups = explode(',', '1,'.$aCurrentPage['viewing_groups']);
300
	$sViewingGroups = implode(',', array_unique($aViewingGroups));
301
	$oTpl->set_block('main_block', 'viewer_group_list_block', 'viewer_group_list');
302
	$sql = 'SELECT `group_id` `ID`, `name` `NAME` '
303
		 . 'FROM `'.TABLE_PREFIX.'groups` '
304
	     . 'ORDER BY (`ID` NOT IN('.$sViewingGroups.')), `NAME`';
305
	if(($oGroups = $database->query($sql))) {
306
		while($aGroup = $oGroups->fetchRow(MYSQL_ASSOC)) {
307
			if($aGroup['ID'] == 1) {
308
			// never uncheck admin group
309
				$aGroup['CHECKED'] = $sChecked;
310
				$aGroup['DISABLED'] = $sDisabled;
311
			}else {
312
			// check already selected groups
313
				$bChecked = $admin->is_group_match($aGroup['ID'], $aCurrentPage['viewing_groups']);
314
			// disable selected groups where current user is not member of
315 1766 Luisehahne
				$bDisabled = !$admin->ami_group_member('1');
316 1664 darkviper
				$aGroup['CHECKED']  = $bChecked ? $sChecked : '';
317
				$aGroup['DISABLED'] = ($bChecked && $bDisabled) ? $sDisabled : '';
318 1358 Luisehahne
			}
319 1664 darkviper
			$oTpl->set_var($aGroup);
320
			$oTpl->parse('viewer_group_list', 'viewer_group_list_block', true);
321 1358 Luisehahne
		}
322
	}
323 1415 DarkViper
324 1664 darkviper
/*-- admin user list block -------------------------------------------------------------*/
325 1707 Luisehahne
// admin_group_show_list_block
326
	$oTpl->set_block('main_block', 'admin_group_show_list_block', 'admin_group_show_list');
327
328 1664 darkviper
	$aAdminUsers = ($aCurrentPage['admin_users'] == ''
329
	                ? array()
330
	                : explode(',', $aCurrentPage['admin_users']));
331
	$aAdminUsers = explode(',', $aCurrentPage['admin_users']);
332 1707 Luisehahne
	$oTpl->set_block('admin_group_show_list_block', 'admin_user_list_block', 'admin_user_list');
333 1664 darkviper
	$sAllowedAdminUsers = trim(implode(',',$aAdminUsers));
334
	$sAllowedAdminUsers = $sAllowedAdminUsers ? $sAllowedAdminUsers : '-1';
335
	$sql = 'SELECT `user_id`, `display_name` '
336
		 . 'FROM `'.TABLE_PREFIX.'users` '
337
	     . 'WHERE `active`=1 '
338
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedAdminUsers.')), `display_name`';
339
	if( ($oUsers = $database->query($sql)) ) {
340
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
341
			if($aUser['user_id'] == 1) { continue; }
342
			$oTpl->set_var(array(
343
				'ID'        => $aUser['user_id'],
344
				'NAME'      => $aUser['display_name'],
345
			    'SELECTED'  => (in_array($aUser['user_id'], $aAdminUsers) ? $sSelected : ''),
346
			));
347
			$oTpl->parse('admin_user_list', 'admin_user_list_block', true);
348
		}
349
	}
350 1707 Luisehahne
	if($admin->ami_group_member('1')) {
351
		$oTpl->parse('admin_group_show_list', 'admin_group_show_list_block', true);
352 1358 Luisehahne
353 1707 Luisehahne
	} else {
354
		$oTpl->parse('admin_group_show_list', '', true);
355
	}
356
357 1664 darkviper
/*-- viewer users list block -----------------------------------------------------------*/
358
	$aViewingUsers = ($aCurrentPage['viewing_users'] == ''
359
	                  ? array()
360
	                  : explode(',', $aCurrentPage['viewing_users']));
361
	$aViewingUsers = explode(',', $aCurrentPage['viewing_users']);
362
	$oTpl->set_block('main_block', 'viewer_user_list_block', 'viewer_user_list');
363
	$sAllowedViewingUsers = trim(implode(',',$aViewingUsers));
364
	$sAllowedViewingUsers = $sAllowedViewingUsers ? $sAllowedViewingUsers : '-1';
365
	$sql = 'SELECT `user_id`, `display_name` '
366
		 . 'FROM `'.TABLE_PREFIX.'users` '
367
	     . 'WHERE `active`=1 '
368
	     . 'ORDER BY (`user_id` NOT IN('.$sAllowedViewingUsers.')), `display_name`';
369
	if( ($oUsers = $database->query($sql)) ) {
370
		while($aUser = $oUsers->fetchRow(MYSQL_ASSOC)) {
371
			if($aUser['user_id'] == 1) { continue; }
372
			$oTpl->set_var(array(
373
				'ID'        => $aUser['user_id'],
374
				'NAME'      => $aUser['display_name'],
375
			    'SELECTED'  => (in_array($aUser['user_id'], $aViewingUsers) ? $sSelected : ''),
376
			));
377
			$oTpl->parse('viewer_user_list', 'viewer_user_list_block', true);
378 1358 Luisehahne
		}
379 1664 darkviper
	}
380 1358 Luisehahne
381 1664 darkviper
/*-- size user lists -------------------------------------------------------------------*/
382
	$aSkaleSizeOfList = array(0 => 5, 12 => 10, 25 => 20, 50 => 30, 75 => 40, 100 => 50);
383
	$iListSize = 6;
384
	if($oUsers) {
385
		$iNumberOfUsers = $oUsers->numRows();
386
		foreach($aSkaleSizeOfList as $key => $val){
387
			if($iNumberOfUsers > $key) {
388
				$iListSize = $val;
389
			}else { break; }
390 1358 Luisehahne
		}
391 1664 darkviper
	}
392
	$oTpl->set_var('USER_LIST_SIZE', $iListSize);
393 1358 Luisehahne
394 1664 darkviper
/*-- show private viewers block --------------------------------------------------------*/
395
	if($aCurrentPage['visibility'] == 'private' OR $aCurrentPage['visibility'] == 'registered')
396
	{
397
		$oTpl->set_var('DISPLAY_VIEWERS', '');
398
	} else {
399
		$oTpl->set_var('DISPLAY_VIEWERS', 'display:none;');
400 1358 Luisehahne
	}
401 1664 darkviper
/*-- start multilanguage page_code 20090904 --------------------------------------------*/
402 1358 Luisehahne
// Work-out if page languages feature is enabled
403 1664 darkviper
	$oTpl->set_block('main_block', 'show_page_code_block',  'show_page_code');
404
	if( (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) &&
405
		 isset($aCurrentPage['page_code']) &&
406
		 file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php') )
407
	{
408
		// workout field is set but module missing
409
		$oTpl->set_var('TEXT_PAGE_CODE',
410 1707 Luisehahne
						   '<a href="'.WB_URL.'/modules/mod_multilingual/update_keys.php?page_id='.$page_id.'">'.$mLang->TEXT_PAGE_CODE.'</a>'
411 1664 darkviper
		);
412
	/*-- begin recursive function page_code list ---------------------------------------*/
413
		function page_code_list($parent)
414
		{
415
			global $admin, $database, $oTpl, $aCurrentPage, $pageCode;
416
			$default_language = DEFAULT_LANGUAGE;
417 1358 Luisehahne
418 1664 darkviper
			$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` '
419
				 . 'WHERE `parent`='.$parent.' AND `language`=\''.$default_language.'\' '
420
				 . 'ORDER BY `position` ASC';
421
			$get_pages = $database->query($sql);
422 1358 Luisehahne
423 1664 darkviper
			while($page = $get_pages->fetchRow(MYSQL_ASSOC))
424
			{
425
				if(($admin->page_is_visible($page)==false) && ($page['visibility'] <> 'none') ) { continue; }
426 1358 Luisehahne
427 1664 darkviper
				$oTpl->set_var('FLAG_CODE_ICON',' none ');
428
				if( $page['parent'] == 0 )
429
				{
430
					$oTpl->set_var('FLAG_CODE_ICON','url('.THEME_URL.'/images/flags/'.strtolower($page['language']).'.png)');
431
				}
432 1358 Luisehahne
433 1664 darkviper
				// If the current page cannot be parent, then its children neither
434
				$list_next_level = true;
435
				// Stop users from adding pages with a level of more than the set page level limit
436
				if($page['level']+1 < PAGE_LEVEL_LIMIT)
437
				{
438
					$can_modify = ($admin->ami_group_member($page['admin_groups']) ||
439
								   $admin->is_group_match($admin->get_user_id(), $page['admin_users']));
440
					$title_prefix = '';
441
					for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - - &nbsp;'; }
442
					// $space = str_repeat('&nbsp;', 3);  $space.'&lt;'..'&gt;'
443
					$oTpl->set_var(array(
444
											'VALUE' => intval($page['page_code']),
445
											'PAGE_VALUE' => $title_prefix.$page['menu_title'],
446
											'PAGE_CODE' => $title_prefix.$page['page_id']
447
											)
448
									);
449
					if($aCurrentPage['page_code'] == $page['page_code'])
450 1358 Luisehahne
					{
451 1664 darkviper
						$oTpl->set_var('SELECTED', ' selected="selected"');
452
					} elseif($aCurrentPage['page_code'] == $page['page_code'])
453
					{
454
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
455
						$list_next_level=false;
456
					} elseif($can_modify != true)
457
					{
458
						$oTpl->set_var('SELECTED', ' disabled="disabled" class="disabled"');
459
					} else {
460
						$oTpl->set_var('SELECTED', '');
461 1358 Luisehahne
					}
462 1664 darkviper
					$oTpl->parse('page_code_list', 'page_code_list_block', true);
463 1358 Luisehahne
				}
464 1664 darkviper
				if ($list_next_level)
465
					page_code_list($page['page_id']);
466 1358 Luisehahne
			}
467
		}
468 1664 darkviper
	/*-- end recursive function page_code list -----------------------------------------*/
469
		// Insert code_page values from page to modify
470
		$oTpl->set_block('show_page_code_block', 'page_code_list_block', 'page_code_list');
471
		if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
472
			$selected = ($aCurrentPage['parent'] == 0 ? $sSelected : '');
473
			$oTpl->set_var(array(
474
					'VALUE' => 0,
475 1681 darkviper
					'PAGE_CODE' => $mLang->TEXT_NONE,
476 1664 darkviper
					'PAGE_VALUE' => '',
477
					'SELECTED' => $selected
478
				)
479
			);
480
			$oTpl->parse('page_code_list', 'page_code_list_block', true);
481
		}
482
		// get pagecode form this page_id
483
		page_code_list(0);
484
		$oTpl->parse('show_page_code', 'show_page_code_block', true);
485
	}else {
486
		$oTpl->set_block('show_page_code', '');
487 1358 Luisehahne
	}
488 1664 darkviper
/*-- end multilanguage page_code 20090904 ----------------------------------------------*/
489 1358 Luisehahne
490 1664 darkviper
/*-- show list of parent pages ---------------------------------------------------------*/
491
	$oTpl->set_block('main_block', 'parent_page_list_block', 'parent_page_list');
492
	if($admin->get_permission('pages_add_l0') == true OR $aCurrentPage['level'] == 0) {
493
		$oTpl->set_var(array(
494
					'ID' => '0',
495 1681 darkviper
					'TITLE' => $mLang->TEXT_NONE,
496 1664 darkviper
					'SELECTED' => ($aCurrentPage['parent'] == 0 ? $sSelected : ''),
497
					) );
498
		$oTpl->parse('parent_page_list', 'parent_page_list_block', true);
499 1358 Luisehahne
	}
500 1664 darkviper
	parent_list(0);
501
	$oTpl->set_var('DISPLAY_MODIFIED', ($modified_ts == 'Unknown' ? 'hide' : ''));
502 1358 Luisehahne
503 1664 darkviper
/*-- show list of templates ------------------------------------------------------------*/
504
	$oTpl->set_block('main_block', 'template_list_block', 'template_list');
505
	$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
506
	     . 'WHERE `type`=\'template\' AND `function`=\'template\' '
507
	     . 'ORDER BY `name`';
508
	if(($res_templates = $database->query($sql))) {
509
		while($rec_template = $res_templates->fetchRow(MYSQL_ASSOC)) {
510
			// Check if the user has perms to use this template
511
			if($rec_template['directory'] == $aCurrentPage['template'] OR
512
			   $admin->get_permission($rec_template['directory'], 'template'))
513
			{
514
				$oTpl->set_var('VALUE', $rec_template['directory']);
515
				$oTpl->set_var('NAME', $rec_template['name']);
516
				if($rec_template['directory'] == $aCurrentPage['template']) {
517
					$oTpl->set_var('SELECTED', $sSelected);
518
				} else {
519
					$oTpl->set_var('SELECTED', '');
520 1358 Luisehahne
				}
521 1664 darkviper
				$oTpl->parse('template_list', 'template_list_block', true);
522 1358 Luisehahne
			}
523
		}
524
	}
525
526 1664 darkviper
/*-- show menu select box --------------------------------------------------------------*/
527
	$oTpl->set_block('main_block', 'show_menu_list_block', 'show_menu_list');
528
	if(MULTIPLE_MENUS)
529
	{
530
	/*-- get menusettings from template info file --------------------------------------*/
531
		function getTemplateInfo($sTpl = '') {
532
			if(!$sTpl) { $sTpl = DEFAULT_TEMPLATE; }
533
			$sTplFile = WB_PATH.'/templates/'.$sTpl.'/info.php';
534
			if(is_readable($sTplFile)) { require_once($sTplFile); }
535
			$menu = isset($menu) ? $menu : array();
536
			return $menu;
537
		}
538
		$aMenu = getTemplateInfo($aCurrentPage['template']);
539
		// set menu[1] as default if there's no entry in info.php
540
		$aMenu[1] = (!isset($aMenu[1]) OR ($aMenu[1] == '')) ? $TEXT['MAIN'] : $aMenu[1];
541
		$oTpl->set_block('show_menu_list_block', 'menu_list_block', 'menu_list');
542
		foreach($aMenu as $iIndex => $sMenuName) {
543
			$aVars = array();
544
			$aVars['NAME']  = $sMenuName;
545
			$aVars['VALUE'] = $iIndex;
546
			$aVars['SELECTED'] = ($aCurrentPage['menu'] == $iIndex) ? $sSelected : '';
547
			$oTpl->set_var($aVars);
548
			$oTpl->parse('menu_list', 'menu_list_block', true);
549
		}
550
		$oTpl->parse('show_menu_list', 'show_menu_list_block', true);
551
	}else {
552
		$oTpl->set_block('show_menu_list', '');
553 1358 Luisehahne
	}
554
555 1664 darkviper
/*-- show language select box ----------------------------------------------------------*/
556
	$sql = 'SELECT `directory`, `name` FROM `'.TABLE_PREFIX.'addons` '
557
		 . 'WHERE `type`=\'language\' ';
558
	if( !defined('PAGE_LANGUAGES') || !PAGE_LANGUAGES) {
559
	// display only default and current language if site is single language only
560
		$sql .= 'AND `directory`=\''.DEFAULT_LANGUAGE.'\' ';
561
		if($aCurrentPage['language'] != DEFAULT_LANGUAGE) {
562
			$sql .= 'AND `directory`=\''.$aCurrentPage['language'].'\' ';
563 1358 Luisehahne
		}
564
	}
565 1664 darkviper
	$sql .= 'ORDER BY `name`';
566
	if( ($oLanguages = $database->query($sql)) )
567
	{
568
		$aAvailLanguages = array();
569
		while($aLanguage = $oLanguages->fetchRow(MYSQL_ASSOC)) {
570
			$aAvailLanguages[$aLanguage['directory']] = $aLanguage['name'];
571
		}
572
		natsort($aAvailLanguages);
573
		$oTpl->set_block('main_block', 'language_list_block', 'language_list');
574
		foreach($aAvailLanguages as $key => $val) {
575
			$oTpl->set_var(array(
576
				'VALUE' => $key,
577
				'NAME'  => $val,
578
				'FLAG_LANG_ICONS' => 'url('.THEME_URL.'/images/flags/'.strtolower($key).'.png)',
579
				'SELECTED' => ($aCurrentPage['language'] == $key ? $sSelected : ''),
580
			));
581
			$oTpl->parse('language_list', 'language_list_block', true);
582
		}
583 1358 Luisehahne
	}
584
585 1664 darkviper
/*-- show search activated box ---------------------------------------------------------*/
586
	$oTpl->set_var('SEARCHING_SELECTED_ON',  ($aCurrentPage['searching'] == 0) ? '' : $sSelected);
587
	$oTpl->set_var('SEARCHING_SELECTED_OFF', ($aCurrentPage['searching'] == 0) ? $sSelected : '');
588 1358 Luisehahne
589 1664 darkviper
/*-- show target select box ------------------------------------------------------------*/
590
	$oTpl->set_var('TOP_SELECTED',   ($aCurrentPage['target'] == '_top'   ? $sSelected : ''));
591
	$oTpl->set_var('SELF_SELECTED',  ($aCurrentPage['target'] == '_self'  ? $sSelected : ''));
592
	$oTpl->set_var('BLANK_SELECTED', ($aCurrentPage['target'] == '_blank' ? $sSelected : ''));
593 1457 Luisehahne
594 1664 darkviper
/*-- insert all needed vars from language files ----------------------------------------*/
595 1681 darkviper
	$oTpl->set_var($mLang->getLangArray());
596
/*-- finalize the page -----------------------------------------------------------------*/
597 1664 darkviper
	$oTpl->parse('main', 'main_block', false);
598
	$oTpl->pparse('output', 'page');
599 1358 Luisehahne
// Print admin footer
600 1664 darkviper
	$admin->print_footer();
601 1707 Luisehahne
602
function p($text,$lang)
603
{
604
	global $admin;
605 1780 Luisehahne
	$retVal  = 'onclick="return overlib(';
606 1707 Luisehahne
	$retVal .= '\''.$text.'\',';
607
	$retVal .= 'CAPTION,\''.$lang.'\',';
608
	$retVal .= 'FGCOLOR,\'#ffffff\',';
609
	$retVal .= 'BGCOLOR,\'#557c9e\',';
610
	$retVal .= 'BORDER,1,';
611
	$retVal .= 'WIDTH,';
612
	$retVal .= 'HEIGHT,';
613
	$retVal .= 'STICKY,';
614
	$retVal .= 'CAPTIONSIZE,\'13px\',';
615
	$retVal .= 'CLOSETEXT,\'X\',';
616
	$retVal .= 'CLOSESIZE,\'14px\',';
617
	$retVal .= 'CLOSECOLOR,\'#ffffff\',';
618
	$retVal .= 'TEXTSIZE,\'12px\',';
619
	$retVal .= 'VAUTO,';
620
	$retVal .= 'HAUTO,';
621
	$retVal .= 'MOUSEOFF,';
622
	$retVal .= 'WRAP,';
623
	$retVal .= 'CELLPAD,5';
624
	$retVal .= ')" onmouseout="return nd()"';
625
//	$retVal .= '';
626
627
	return $retVal;
628
}
629
630
/**
631
* replace varnames with values in a string
632
*
633
* @param string $subject: stringvariable with vars placeholder
634
* @param array $replace: values to replace vars placeholder
635
* @return string
636
*/
637
function replaceVars($subject = '', $replace = null )
638
{
639
	if(is_array($replace)==true)
640
	{
641
		foreach ($replace  as $key => $value) {
642
			$subject = str_replace("{{".$key."}}", $value, $subject);
643
		}
644
	}
645
	return $subject;
646
}