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