Project

General

Profile

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