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