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