Project

General

Profile

« Previous | Next » 

Revision 1839

Added by darkviper over 11 years ago

The second runtime optimization of PageTree by recoding /admin/pages/index.php
Added new class a_pages_PageTree() for use with /admin/pages/index.php

View differences:

index.php
1 1
<?php
2
/**
2

  
3
/** 
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 5
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher and higher
12
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
15 10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 18
 */
19
/**
20
 * calling file to create ACP-Pagetree
21
 *
22
 * @category     WbACP
23
 * @package      WbACP_Pages
24
 * @author       Werner v.d. Decken <wkl@isteam.de>
25
 * @copyright    Werner v.d. Decken <wkl@isteam.de>
26
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
27
 * @version      1.0.0
28
 * @revision     $Revision$
29
 * @link         $HeadURL$
30
 * @lastmodified $Date$
31
 * @since        file added on 2012-12-21
32
 * @todo         rebuild this file to go into coding standards (sideeffects!!!)
33
 */
17 34

  
18
require('../../config.php');
19
require_once(WB_PATH.'/framework/class.admin.php');
20
$admin = new admin('Pages', 'pages');
21
$admin->clearIDKEY();
22
// Include the WB functions file
23
require_once(WB_PATH.'/framework/functions.php');
24
// eggsurplus: add child pages for a specific page
25
/**/
26

  
27
echo '<script type="text/javascript" src="'.ADMIN_URL.'/pages/eggsurplus.js"></script>'.PHP_EOL;
28
// fixes A URI contains impermissible characters or quotes around the URI are not closed.
29
$MESSAGE['PAGES_DELETE_CONFIRM'] = url_encode(  $MESSAGE['PAGES_DELETE_CONFIRM'] );
30

  
31
function set_node ($parent,& $par)
32
{
33
    $retval = '';
34
	if ($par['num_subs']) {
35
		$retval .= "\n".'<ul id="p'.$parent.'"';
36
		if ($parent != 0) {
37
			$retval .= ' class="page_list"';
38
			if (isset ($_COOKIE['p'.$parent]) && $_COOKIE['p'.$parent] == '1') {
39
				 $retval .= ' style="display:block"';
35
// --- start helper functions ------------------------------------------------------------
36
/**
37
 * create a list of groups
38
 * @param type $sPermission which permission the groups should have
39
 * @return array 
40
 */
41
	function admin_pages_makeGroupList($sPermission)
42
	{
43
		$aNewGroups = array();
44
		$sql = 'SELECT `group_id` ID, `name` NAME, \'\' CHECKED, \'\' DISABLED '
45
			 . 'FROM `'.TABLE_PREFIX.'groups` '
46
			 . 'WHERE FIND_IN_SET(\'pages_'.$sPermission.'\', `system_permissions`) '
47
			 . 'ORDER BY `NAME` ASC'
48
		;
49
		if(($oGroups = WbDatabase::getInstance()->query($sql))) {
50
			while($aGroup = $oGroups->fetchRow(MYSQL_ASSOC)) {
51
				if($aGroup['ID'] == 1) {
52
					$aGroup['CHECKED'] = ' checked="checked"';
53
					$aGroup['DISABLED'] = ' disabled="disabled"';
54
					// move it to topmost position of list
55
					array_unshift($aNewGroups, $aGroup);
56
				}else {
57
					if(in_array($aGroup['ID'], $GLOBALS['admin']->get_groups_id())) {
58
						$aGroup['CHECKED'] = ' checked="checked"';
59
					}
60
					// move it at the end of list
61
					$aNewGroups[] = $aGroup;
62
				}
40 63
			}
41 64
		}
42
		$retval .= ">\n";
43
 	}
44
	return $retval;
45
}
65
		return $aNewGroups;
66
	} // end of admin_pages_makeGroupList()
67
// --- end helper functions --------------------------------------------------------------
68
// #######################################################################################
69
// --- start script ----------------------------------------------------------------------
46 70

  
47
function make_list($parent = 0, $editable_pages = 0) {
48
	// Get objects and vars from outside this function
49
	global $admin, $template, $TEXT, $MESSAGE, $HEADING, $par;
71
// read configuration and initialize the system
72
	if(!defined('WB_URL')) {
73
		$sCfgFile = realpath(dirname(__FILE__).'/../../config.php');
74
		if(is_readable($sCfgFile)) {
75
			include($sCfgFile);
76
		}else {
77
			throw new RuntimeException('unable to read configuration file!!!');
78
		}
79
	}
80
// import languange translations
81
 	global $TEXT, $MESSAGE, $HEADING;
82
// define additional constants
83
	if(!defined('ADMIN_REL')) { define('ADMIN_REL', WB_REL.'/'.ADMIN_DIRECTORY); }
84
	if(!defined('THEME_REL')) {
85
		$sTmp = preg_replace('/^'.preg_quote(WB_URL, '/').'/siU', '', THEME_URL);
86
		define('THEME_REL', WB_REL.$sTmp);
87
	}
88
// create the needed admin object
50 89
	$database = WbDatabase::getInstance();
51
	static $row = 0;
52
//	static $iLevel = 0;
53
//	static $iOldLevel = 0;
54
//	static $aRowLevel = array();
90
	if(!class_exists('admin', false)) { include(WB_PATH.'/framework/class.admin.php'); }
91
	$admin = new admin('Pages', 'pages');
92
	$admin->clearIDKEY();
93
// include the WB functions file
94
	if(!function_exists('get_page_title')) { include(WB_PATH.'/framework/functions.php'); }
95
// add module depending Javascript (eggsurplus: add child pages for a specific page)
96
	$sOutput = '<script type="text/javascript" src="'.ADMIN_REL.'/pages/eggsurplus.js" '
97
	         . 'charset="utf-8"></script>'.PHP_EOL
98
	         . '<script type="text/javascript" charset="utf-8">'.PHP_EOL
99
	         . "\t".'var pages_delete_confirm =\''.$MESSAGE['PAGES_DELETE_CONFIRM'].'\';'.PHP_EOL
100
	         . "\t".'var THEME_URL = \''.THEME_REL.'\';'.PHP_EOL
101
	         . "\t".'var WB_URL = \''.WB_REL.'\';'.PHP_EOL
102
	         . '</script>'.PHP_EOL;
103
	echo $sOutput;
104
// create page tree and display it -------------------------------------------------------
105
	$oPageTree = new a_pages_PageTree();
106
	$oPageTree->displayTree();
55 107
	
56
    print set_node ($parent, $par);
57
	// Get page list from database
58
 $sql = 'SELECT `module`, MAX(s.`publ_start` + s.`publ_end`) published, p.* '
59
      . 'FROM `'.TABLE_PREFIX.'pages` p '
60
      .     'INNER JOIN `'.TABLE_PREFIX.'sections` s ON p.`page_id` = s.`page_id` '
61
      . 'WHERE `parent`='.$parent.((PAGE_TRASH != 'inline') ?  ' AND `visibility`!=\'deleted\' ' : ' ')
62
      . 'GROUP BY p.`page_id` '
63
      . 'ORDER BY p.`position` ASC';
64

  
65
    if($get_pages = $database->query($sql)) {
66
    	// Work out how many pages there are for this parent
67
    	$num_pages = $get_pages->numRows();
68
    	// Insert values into main page list
69
    	if($num_pages > 0)
70
    	{
71
    		while($page = $get_pages->fetchRow(MYSQL_ASSOC))
72
    		{
73
//echo implode('-',$page);
74
    			$sLineOut = '';
75
    			$row = $row++ % 2; // toggle row colors between 0<->1
76
    			// Get user permissions
77
    			$can_modify = false;
78
    			if( $admin->ami_group_member($page['admin_users']) ||
79
    			    $admin->is_group_match($admin->get_groups_id(), $page['admin_groups']))
80
    			{
81
    				if(($page['visibility'] == 'deleted' && PAGE_TRASH == 'inline') ||
82
    				   ($page['visibility'] != 'deleted'))
83
    				{
84
    					$can_modify = true;
85
    					$editable_pages++;
86
    				}
87
    			} else {
88
    				if($page['visibility'] == 'private') { continue; }
89
    			}
90
    			// check if the page has children
91
//                $sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'pages` ';
92
//    			$sql .= 'WHERE `parent`='.$page['page_id'];
93
//                $sql .= (PAGE_TRASH != 'inline') ? ' AND `visibility`!=\'deleted\'' : '';
94
                $sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'pages` '
95
    			     . 'WHERE `parent`='.$page['page_id'].((PAGE_TRASH != 'inline') ? ' AND `visibility`!=\'deleted\'' : '');
96
    			$par['num_subs'] = intval($database->get_one($sql));
97
    			$display_plus = (bool)$par['num_subs'];
98
    			$sLineOut .= '<li class="p'.$page['parent'].'">';
99
    // ---------------------------------------------------------------------------------------
100
    			$sLineOut .= '<table class="pages_view">';
101
    			$sLineOut .= "\t".'<tbody>';
102
    			$sLineOut .= "\t\t".'<tr class="row_'.$row.'">';
103
    // --- Tab 1 ---
104
    			$sLineOut .= "\t\t\t".'<td valign="middle" width="20" style="padding-left: '.
105
    				 (($page['level'] == 0) ? 0 : ($page['level']*25)-pow($page['level'],2)).'px;">';
106
    			if($display_plus == true) {
107
    				$sLineOut .= '<a href="javascript:toggle_visibility(\'p'.$page['page_id'].'\');" '.
108
    					 'title="'.$TEXT['EXPAND'].'/'.$TEXT['COLLAPSE'].'">';
109
    				$sLineOut .= '<span>';
110
    				$sLineOut .= '<img src="'.THEME_URL.'/images/'.
111
    					 ( ((isset($_COOKIE['p'.$page['page_id']]) && $_COOKIE['p'.$page['page_id']] == '1') ? 'minus' : 'plus').
112
    					 '_16.png" onclick="toggle_plus_minus(\''.$page['page_id'].'\');" '.
113
    					 'name="plus_minus_'.$page['page_id'] ).'" alt="+" />';
114
    				$sLineOut .= '</span>';
115
    				$sLineOut .= '</a>';
116
    			}
117
    			$sLineOut .= '</td>'.PHP_EOL;
118
    // --- Tab 2 ---
119
    			$sLineOut .= "\t\t\t".'<td class="list_menu_title">';
120
                $sClassMenutitle = '';
121
    			if($admin->get_permission('pages_modify') && $can_modify) {
122
    				$sLineOut .= '<a href="'.ADMIN_URL.'/pages/modify.php?page_id='.$page['page_id'].'" title="'.$TEXT['MODIFY'].'">';
123
                    $sClassMenutitle = 'bold grey';
124
    			}
125
    			$sLineOut .= '<span>';
126
    			switch($page['visibility']):
127
    				case 'private':
128
    					$sIcon = 'private_16.png';
129
    					$sText = $TEXT['PRIVATE'];
130
    					break;
131
    				case 'registered':
132
    					$sIcon = 'keys_16.png';
133
    					$sText = $TEXT['REGISTERED'];
134
    					break;
135
    				case 'hidden':
136
    					$sIcon = 'hidden_16.png';
137
    					$sText = $TEXT['HIDDEN'];
138
    					break;
139
    				case 'none':
140
    					$sIcon = 'none_16.png';
141
    					$sText = $TEXT['NONE'];
142
    					break;
143
    				case 'deleted':
144
    					$sIcon = 'deleted_16.png';
145
    					$sText = $TEXT['DELETED'];
146
    					break;
147
    				default: // public
148
    					$sIcon = 'visible_16.png';
149
    					$sText = $TEXT['PUBLIC'];
150
    					break;
151
                     endswitch;
152
                     $sLineOut .= '<img src="'.THEME_URL.'/images/'.$sIcon.'" ';
153
                     $sLineOut .= 'alt="'.$TEXT['VISIBILITY'].': '.$sText.'" class="page_list_rights" />';
154
                     if($admin->get_permission('pages_modify') && $can_modify) {
155
                      $sLineOut .= '<span class="modify_link">'.$page['menu_title'].'</span></a>';
156
                     }else {
157
                      $sLineOut .=  '<span class="bold grey">'.$page['menu_title'].'</span>';
158
                     }
159
                     $sLineOut .= '</td>'.PHP_EOL;
160
    // --- Tab 3 ---
161
    			$sLineOut .= "\t\t\t".'<td class="list_page_title">'.$page['page_title'].'</td>'.PHP_EOL;
162
    // --- Tab 4 ---
163
    			$sLineOut .= "\t\t\t".'<td class="list_page_id right">'.$page['page_id'].'</td>'.PHP_EOL;
164
    // --- Tab 5 ---
165
    			$sLineOut .= "\t\t\t".'<td class="list_actions">';
166
    			if($page['visibility'] != 'deleted' && $page['visibility'] != 'none') {
167
    				$sLineOut .= '<a href="'.$admin->page_link($page['link']).'" target="_blank" '.
168
    					 'title="'.$TEXT['VIEW'].'">';
169
    				$sLineOut .= '<img src="'.THEME_URL.'/images/view_16.png" alt="'.$TEXT['VIEW'].'" />';
170
    				$sLineOut .= '</a>';
171
    			}
172
    			$sLineOut .= '</td>'.PHP_EOL;
173
    // --- Tab 6 ---		
174
    			$sLineOut .= "\t\t\t".'<td class="list_actions">';
175
    			if($page['visibility'] != 'deleted') { 
176
    				if($admin->get_permission('pages_settings') && $can_modify) {
177
    					$sLineOut .= '<a href="'.ADMIN_URL.'/pages/settings.php?page_id='.$page['page_id'].'" '.
178
    						 'title="'.$TEXT['SETTINGS'].'">';
179
    					$sLineOut .= '<img src="'.THEME_URL.'/images/modify_16.png" alt="'.$TEXT['SETTINGS'].'" />';
180
    					$sLineOut .= '</a>';
181
    				}
182
    			}else {
183
    				$sLineOut .= '<a href="'.ADMIN_URL.'/pages/restore.php?page_id='.$page['page_id'].'" '.
184
    					 'title="'.$TEXT['RESTORE'].'">';
185
    				$sLineOut .= '<img src="'.THEME_URL.'/images/restore_16.png" alt="'.$TEXT['RESTORE'].'" />';
186
    				$sLineOut .= '</a>';
187
    			}
188
    			$sLineOut .= '</td>'.PHP_EOL;
189
    // --- Tab 7 --- MANAGE SECTIONS AND DATES BUTTONS ---
190
    			$sLineOut .= "\t\t\t".'<td class="list_actions">';
191
    			// Work-out if we should show the "manage dates" link
192
    			if( MANAGE_SECTIONS && $admin->get_permission('pages_add') && $can_modify ) {
193
    				$sLineOut .= '<a href="'.ADMIN_URL.'/pages/sections.php?page_id='.$page['page_id'].'"'.
194
    					 ' title="'.$HEADING['MANAGE_SECTIONS'].'">';
195
                     $file = $admin->page_is_active($page) ? "clock_16.png" : "clock_red_16.png";
196
                     $file = ($page['published'] && $page['module'] != 'menu_link') ? $file : 'noclock_16.png';
197
     				$sLineOut .= '<img src="'.THEME_URL.'/images/'.$file.'" alt="'.$HEADING['MANAGE_SECTIONS'].'" />';
198
    				$sLineOut .= '</a>';
199
    			}
200
    			$sLineOut .= '</td>'.PHP_EOL;
201
    // --- Tab 8 ---
202
    			$sLineOut .= "\t\t\t".'<td class="list_actions">';
203
    			if($page['position'] != 1) {
204
    				if($page['visibility'] != 'deleted') {
205
    					if($admin->get_permission('pages_settings') && $can_modify) {
206
    						$sLineOut .= '<a href="'.ADMIN_URL.'/pages/move_up.php?page_id='.$page['page_id'].'" '.
207
    							 'title="'.$TEXT['MOVE_UP'].'"><img src="'.THEME_URL.
208
    							 '/images/up_16.png" alt="'.$TEXT['MOVE_UP'].'" /></a>';
209
    					}
210
    				}
211
    			}
212
    			$sLineOut .= '</td>'.PHP_EOL;
213
    // --- Tab 9 ---
214
    			$sLineOut .= "\t\t\t".'<td class="list_actions">';
215
    			if($page['position'] != $num_pages) {
216
    				if($page['visibility'] != 'deleted') {
217
    					if($admin->get_permission('pages_settings') && $can_modify) {
218
    						$sLineOut .= '<a href="'.ADMIN_URL.'/pages/move_down.php?page_id='.$page['page_id'].'" '.
219
    							 'title="'.$TEXT['MOVE_DOWN'].'"><img src="'.THEME_URL.
220
    							 '/images/down_16.png" alt="'.$TEXT['MOVE_DOWN'].'" /></a>';
221
    					}
222
    				}
223
    			}else { $sLineOut .= '&nbsp;'; }
224
    			$sLineOut .= '</td>'.PHP_EOL;
225
    // --- Tab 10 ---
226
    			$sLineOut .= "\t\t\t".'<td class="list_actions">';
227
    			if($admin->get_permission('pages_delete') && $can_modify) {
228
    				$sLineOut .= '<a href="javascript:confirm_link(\''.$MESSAGE['PAGES_DELETE_CONFIRM'].
229
    					 '?,'.ADMIN_URL.'/pages/delete.php?page_id='.$admin->getIDKEY($page['page_id']).'\');" '.
230
    					 'title="'.$TEXT['DELETE'].'">';
231
    				$sLineOut .= '<img src="'.THEME_URL.'/images/delete_16.png" alt="'.$TEXT['DELETE'].'" />';
232
    				$sLineOut .= '</a>';
233
    			}else { $sLineOut .= '&nbsp;'; }
234
    			$sLineOut .= '</td>'.PHP_EOL;
235
    // --- Tab 11 --- Add action to add a page as a child ---
236
    			$sLineOut .= "\t\t\t".'<td class="list_actions">';
237
    			if($admin->get_permission('pages_add') && $can_modify && ($page['visibility'] != 'deleted')) {
238
    				$sLineOut .= '<a href="javascript:add_child_page(\''.$page['page_id'].'\');" '
239
    					.'title="'.$HEADING['ADD_CHILD_PAGE'].'">';
240
    				$sLineOut .= '<img src="'.THEME_URL.'/images/siteadd.png" name="addpage_'.$page['page_id'].'" '
241
    					.'alt="Add Child Page" />';
242
    				$sLineOut .= '</a>';
243
    			}else { $sLineOut .= '&nbsp;'; }
244
    			$sLineOut .= '</td>'.PHP_EOL;
245
    // --- Tab 12 ---
246
    			$sLineOut .= "\t\t\t".'<td class="list_page_id center">'.$page['language'].'</td>'.PHP_EOL;
247
    // --- End TR / TBODY / TABLE		
248
    			$sLineOut .= "\t\t".'</tr>'.PHP_EOL;
249
    			$sLineOut .= "\t".'</tbody>'.PHP_EOL;
250
    			$sLineOut .= '</table>'.PHP_EOL;
251
    // ---------------------------------------------------------------------------------------
252
           echo $sLineOut;
253
           if ( $page['parent'] == 0) {
254
            $page_tmp_id = $page['page_id'];
255
           }
256
           // Get subs
257
           $editable_pages = make_list($page['page_id'], $editable_pages);
258
                    echo '</li>'.PHP_EOL;
259
          } // end of WHILE
260
    	} // end of $num_pages > 0
261
    }  // end of $get_pages = $database->query($sql)
262

  
263
	$output = ($par['num_subs'] )? '</ul>'.PHP_EOL : '';
264
    $par['num_subs'] = (empty($output) ) ?  1 : $par['num_subs'];
265
    echo $output;
266
	return $editable_pages;
267
}
268
// Generate pages list
269
if($admin->get_permission('pages_view') == true) 
270
{
271
	$sListHeader = <<<LHEAD
272
	<div class="jsadmin hide"></div>
273
		<table>
274
			<tbody>
275
				<tr>
276
					<td><h2 class="left">{$HEADING['MODIFY_DELETE_PAGE']}</h2></td>
277
					<td align="right"></td>
278
				</tr>
279
			</tbody>
280
		</table>
281
		<div class="pages_list">
282
			<table>
283
				<tbody>
284
					<tr class="pages_list_header">
285
						<td class="header_list_menu_title">{$TEXT['VISIBILITY']} / {$TEXT['MENU_TITLE']}:</td>
286
						<td class="header_list_page_title">{$TEXT['PAGE_TITLE']}:</td>
287
						<td class="header_list_page_id">PID</td>
288
						<td class="header_list_actions">{$TEXT['ACTIONS']}:</td>
289
						<td class="list_page_id">&nbsp;</td>
290
					</tr>
291
				</tbody>
292
			</table>
293
LHEAD;
294
	echo $sListHeader;
295
	// Work-out if we should check for existing page_code
296
	$field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
297
    $par = array();
298
	$par['num_subs'] = 1;
299
	$editable_pages = make_list(0, 0);
300
}else {
301
	$editable_pages = 0;
302
}
303
echo "\t\t".'</div>'.PHP_EOL;
304
if(!intval($editable_pages)) {
305
	echo "\t\t".'<div class="empty_list">'.$TEXT['NONE_FOUND'].'</div>'.PHP_EOL;
306
}
307
// Setup template object, parse vars to it, then parse it
308
// Create new template object
309
$template = new Template(dirname($admin->correct_theme_source('pages.htt')),'keep');
310
// $template->debug = true;
311
$template->set_file('page', 'pages.htt');
312
$template->set_block('page', 'main_block', 'main');
313
// Insert values into the add page form
314
$template->set_var('FTAN', $admin->getFTAN());
315
// Group list 1
316
$query = "SELECT * FROM ".TABLE_PREFIX."groups";
317
$get_groups = $database->query($query);
318

  
319
$template->set_block('main_block', 'group_list_block', 'group_list');
320
// Insert admin group and current group first
321
$admin_group_name = $get_groups->fetchRow(MYSQL_ASSOC);
322
$template->set_var(array(
323
						'ID' => 1,
324
						'TOGGLE' => '1',
325
						'DISABLED' => ' disabled="disabled"',
326
						'LINK_COLOR' => '000000',
327
						'CURSOR' => 'default',
328
						'NAME' => $admin_group_name['name'],
329
						'CHECKED' => ' checked="checked"'
330
						)
331
					);
332
$template->parse('group_list', 'group_list_block', true);
333
while($group = $get_groups->fetchRow(MYSQL_ASSOC)) {
334
	// check if the user is a member of this group
335
	$flag_disabled = '';
336
	$flag_checked =  '';
337
	$flag_cursor =   'pointer';
338
	$flag_color =    '';
339
	if (in_array($group["group_id"], $admin->get_groups_id())) {
340
		$flag_disabled = ''; //' disabled';
341
		$flag_checked =  ' checked="checked"';
342
		$flag_cursor =   'default';
343
		$flag_color =    '000000';
108
// Setup template object, parse vars to it, then parse it --------------------------------
109
	$oTpl = new Template(dirname($admin->correct_theme_source('pages.htt')),'keep');
110
	// $oTpl->debug = true;
111
	$oTpl->set_file('page', 'pages.htt');
112
	$oTpl->set_block('page', 'main_block', 'main');
113
	// Insert values into the add page form
114
	$oTpl->set_var('FTAN', $admin->getFTAN());
115
	
116
// --- admin groups list -----------------------------------------------------------------
117
	$aAdminGroups = admin_pages_makeGroupList('modify');
118
	// write block into template
119
	$oTpl->set_block('main_block', 'admingroups_list_block', 'admingroups_list');
120
	foreach($aAdminGroups as $aValue) {
121
		$oTpl->set_var($aValue);
122
		$oTpl->parse('admingroups_list', 'admingroups_list_block', true);
344 123
	}
345
	// Check if the group is allowed to edit pages
346
	$system_permissions = explode(',', $group['system_permissions']);
347
	if(is_numeric(array_search('pages_modify', $system_permissions))) {
348
		$template->set_var(array(
349
								'ID' => $group['group_id'],
350
								'TOGGLE' => $group['group_id'],
351
								'CHECKED' => $flag_checked,
352
								'DISABLED' => $flag_disabled,
353
								'LINK_COLOR' => $flag_color,
354
								'CURSOR' => $flag_checked,
355
								'NAME' => $group['name'],
356
								)
357
							);
358
		$template->parse('group_list', 'group_list_block', true);
124
	unset($aAdminGroups);
125
	
126
// --- viewer groups list ----------------------------------------------------------------
127
	$aViewerGroups = admin_pages_makeGroupList('view');
128
	// write block into template
129
	$oTpl->set_block('main_block', 'viewergroups_list_block', 'viewergroups_list');
130
	foreach($aViewerGroups as $aValue) {
131
		$oTpl->set_var($aValue);
132
		$oTpl->parse('viewergroups_list', 'viewergroups_list_block', true);
359 133
	}
360
}
361
// Group list 2
362
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'groups`';
363
$get_groups = $database->query($sql);
364
$template->set_block('main_block', 'group_list_block2', 'group_list2');
365
// Insert admin group and current group first
366
$admin_group_name = $get_groups->fetchRow(MYSQL_ASSOC);
367
$template->set_var(array(
368
						'ID' => 1,
369
						'TOGGLE' => '1',
370
						'DISABLED' => ' disabled="disabled"',
371
						'LINK_COLOR' => '000000',
372
						'CURSOR' => 'default',
373
						'NAME' => $admin_group_name['name'],
374
						'CHECKED' => ' checked="checked"'
375
						)
376
					);
377
$template->parse('group_list2', 'group_list_block2', true);
378
while($group = $get_groups->fetchRow(MYSQL_ASSOC)) {
379
	// check if the user is a member of this group
380
	$flag_disabled = '';
381
	$flag_checked =  '';
382
	$flag_cursor =   'pointer';
383
	$flag_color =    '';
384
	if (in_array($group["group_id"], $admin->get_groups_id())) {
385
		$flag_disabled = ''; //' disabled';
386
		$flag_checked =  ' checked="checked"';
387
		$flag_cursor =   'default';
388
		$flag_color =    '000000';
389
	}
390
	$template->set_var(array(
391
							'ID' => $group['group_id'],
392
							'TOGGLE' => $group['group_id'],
393
							'CHECKED' => $flag_checked,
394
							'DISABLED' => $flag_disabled,
395
							'LINK_COLOR' => $flag_color,
396
							'CURSOR' => $flag_cursor,
397
							'NAME' => $group['name'],
398
							)
399
						);
400
	$template->parse('group_list2', 'group_list_block2', true);
401
}
402
// Parent page list
403
// $database = new database();
404
function parent_list($parent)
405
{
406
	global $admin, $template, $field_set;
407
	$database = WbDatabase::getInstance();
408
	$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` '.
409
	       'WHERE `parent`='.$parent.' AND `visibility`!=\'deleted\' '.
410
	       'ORDER BY `position` ASC';
411
	$get_pages = $database->query($sql);
412

  
413
	while($page = $get_pages->fetchRow(MYSQL_ASSOC)) {
414
		if(!$admin->page_is_visible($page)) { continue; }
415
		// if parent = 0 set flag_icon
416
		$template->set_var('FLAG_ROOT_ICON', ' none ');
417
		if( $page['parent'] == 0 && $field_set) {
418
			$template->set_var('FLAG_ROOT_ICON','url('.THEME_URL.'/images/flags/'.strtolower($page['language']).'.png)');
134
	unset($aViewerGroups);
135
	
136
// --- build parent pages list -----------------------------------------------------------
137
	$aParents = $oPageTree->getParentList();
138
	$aFirstEntry = array();
139
	$aFirstEntry['ID']             = 0;
140
	$aFirstEntry['TITLE']          = $TEXT['NONE'];
141
	$aFirstEntry['DISABLED']       = 0;
142
	$aFirstEntry['PARENT']         = 99;
143
	$aFirstEntry['FLAG_ROOT_ICON'] = '';
144
	$aFirstEntry['LEVEL']          = 0;
145
	$aFirstEntry['LANGUAGE']       = '';
146
	array_unshift($aParents, $aFirstEntry);
147
	reset($aParents);
148
	$oTpl->set_block('main_block', 'parents_list_block', 'parents_list');
149
	// walk through all items
150
	while (list(, $aItem) = each($aParents)) {
151
		if($admin->get_permission('pages_add')) {
152
			// modify item
153
			$aItem['DISABLED'] = ($aItem['DISABLED'] ? ' disabled="disabled" class="disabled"' : '');
154
			if(!$aItem['PARENT']) {
155
				$aItem['FLAG_ROOT_ICON'] = ' style="background-image: url('.THEME_REL.'/images/flags/'
156
										 . strtolower($aItem['LANGUAGE']).'.png);"';
157
			}
158
			$aItem['TITLE'] = str_repeat('- ', $aItem['LEVEL']).$aItem['TITLE'];
159
			// write block into template
160
			$oTpl->set_var($aItem);
161
			$oTpl->parse('parents_list', 'parents_list_block', true);
419 162
		}
420
		// Stop users from adding pages with a level of more than the set page level limit
421
		if($page['level']+1 < PAGE_LEVEL_LIMIT) {
422
			// Get user permissions
423
			$can_modify = ($admin->ami_group_member($page['admin_groups']) ||
424
					       $admin->is_group_match($admin->get_groups_id(), $page['admin_users']));
425
			// Title -'s prefix
426
			$title_prefix = '';
427
			for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - - &nbsp;'; }
428
				$template->set_var(array(
429
										'ID' => $page['page_id'],
430
										'TITLE' => ($title_prefix.$page['menu_title']),
431
										'MENU-TITLE' => ($title_prefix.$page['menu_title']),
432
										'PAGE-TITLE' => ($title_prefix.$page['page_title'])
433
										));
434
				if($can_modify == true) {
435
					$template->set_var('DISABLED', '');
436
				} else {
437
					$template->set_var('DISABLED', ' disabled="disabled" class="disabled"');
438
				}
439
				$template->parse('page_list2', 'page_list_block2', true);
440
		}
441
		parent_list($page['page_id']);
442 163
	}
443
}
444
$template->set_block('main_block', 'page_list_block2', 'page_list2');
445
if($admin->get_permission('pages_add_l0') == true) {
446
	$template->set_var(array(
447
						'ID' => '0',
448
						'TITLE' => $TEXT['NONE'],
449
						'SELECTED' => ' selected="selected"',
450
						'DISABLED' => ''
451
					)
452
				);
453
	$template->parse('page_list2', 'page_list_block2', true);
454
}
455
parent_list(0);
456
// Explode module permissions
457
$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
458
// Modules list
459
$template->set_block('main_block', 'module_list_block', 'module_list');
460
$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'page' order by name");
461
if($result->numRows() > 0) {
462
	while ($module = $result->fetchRow(MYSQL_ASSOC)) {
463
		// Check if user is allowed to use this module
464
		if(!is_numeric(array_search($module['directory'], $module_permissions))) {
465
			$template->set_var('VALUE', $module['directory']);
466
			$template->set_var('NAME', $module['name']);
467
			if($module['directory'] == 'wysiwyg') {
468
				$template->set_var('SELECTED', ' selected="selected"');
469
			} else {
470
				$template->set_var('SELECTED', '');
471
			}
472
			$template->parse('module_list', 'module_list_block', true);
164
	unset($aParents);
165
	
166
// --- build modules list ----------------------------------------------------------------
167
	$bMatch = false;
168
	$aModulePermissions = '\''.implode(',', $_SESSION['MODULE_PERMISSIONS']).'\'';
169
	$sql = 'SELECT `directory` DIRECTORY, `name` NAME, \'\' SELECTED FROM `'.TABLE_PREFIX.'addons` '
170
	     . 'WHERE `type`=\'module\' AND `function`=\'page\' ';
171
	if($admin->get_user_id() != 1) {
172
		$sql .= 'AND NOT FIND_IN_SET(`DIRECTORY`, '.$aModulePermissions.') ';
173
	}
174
	$sql .= 'ORDER BY `name` ASC';
175
	if(($oModules = $database->query($sql))) {
176
		$oTpl->set_block('main_block', 'module_list_block', 'module_list');
177
		while ($aModule = $oModules->fetchRow(MYSQL_ASSOC)) {
178
			$bMatch = true;
179
			// Check if user is allowed to use this module
180
			$aModule['SELECTED'] = ($aModule['DIRECTORY'] == 'wysiwyg' ? ' selected="selected"' : '');
181
			$oTpl->set_var($aModule);
182
			$oTpl->parse('module_list', 'module_list_block', true);
473 183
		}
474 184
	}
475
}
185
	if(!$bMatch) {
186
		$aModule = array('DIRECTORY' => '',
187
		                 'NAME'      => $TEXT['NONE'],
188
		                 'SELECTED'  => ''
189
		                );
190
		$oTpl->set_var($aModule);
191
		$oTpl->parse('module_list', 'module_list_block', true);
192
	}
193

  
194
// --- Insert global replacements --------------------------------------------------------	
476 195
// Insert urls
477
$template->set_var(array(
478
								'THEME_URL' => THEME_URL,
479
								'WB_URL' => WB_URL,
480
								'ADMIN_URL' => ADMIN_URL,
481
								)
482
						);
483
// Insert language headings
484
$template->set_var(array(
485
								'HEADING_ADD_PAGE' => $HEADING['ADD_PAGE'],
486
								'HEADING_MODIFY_INTRO_PAGE' => $HEADING['MODIFY_INTRO_PAGE']
487
								)
488
						);
196
	$oTpl->set_var(array(
197
		'WB_URL'    => WB_REL,
198
		'ADMIN_URL' => ADMIN_REL,
199
		'THEME_URL' => THEME_REL,
200
		'WB_REL'    => WB_REL,
201
		'ADMIN_REL' => ADMIN_REL,
202
		'THEME_REL' => THEME_REL
203
		)
204
	);
489 205
// Insert language text and messages
490
$template->set_var(array(
491
								'TEXT_TITLE' => $TEXT['TITLE'],
492
								'TEXT_TYPE' => $TEXT['TYPE'],
493
								'TEXT_PARENT' => $TEXT['PARENT'],
494
								'TEXT_VISIBILITY' => $TEXT['VISIBILITY'],
495
								'TEXT_PUBLIC' => $TEXT['PUBLIC'],
496
								'TEXT_PRIVATE' => $TEXT['PRIVATE'],
497
								'TEXT_REGISTERED' => $TEXT['REGISTERED'],
498
								'TEXT_HIDDEN' => $TEXT['HIDDEN'],
499
								'TEXT_NONE' => $TEXT['NONE'],
500
								'TEXT_NONE_FOUND' => $TEXT['NONE_FOUND'],
501
								'TEXT_ADD' => $TEXT['ADD'],
502
								'TEXT_RESET' => $TEXT['RESET'],
503
								'TEXT_ADMINISTRATORS' => $TEXT['ADMINISTRATORS'],
504
								'TEXT_PRIVATE_VIEWERS' => $TEXT['PRIVATE_VIEWERS'],
505
								'TEXT_REGISTERED_VIEWERS' => $TEXT['REGISTERED_VIEWERS'],
506
								'INTRO_LINK' => $MESSAGE['PAGES_INTRO_LINK'],
507
								)
508
						);
206
	$oTpl->set_var(array(
207
		'HEADING_ADD_PAGE'          => $HEADING['ADD_PAGE'],
208
		'HEADING_MODIFY_INTRO_PAGE' => $HEADING['MODIFY_INTRO_PAGE'],
209
		'TEXT_TITLE'                => $TEXT['TITLE'],
210
		'TEXT_TYPE'                 => $TEXT['TYPE'],
211
		'TEXT_PARENT'               => $TEXT['PARENT'],
212
		'TEXT_VISIBILITY'           => $TEXT['VISIBILITY'],
213
		'TEXT_PUBLIC'               => $TEXT['PUBLIC'],
214
		'TEXT_PRIVATE'              => $TEXT['PRIVATE'],
215
		'TEXT_REGISTERED'           => $TEXT['REGISTERED'],
216
		'TEXT_HIDDEN'               => $TEXT['HIDDEN'],
217
		'TEXT_NONE'                 => $TEXT['NONE'],
218
		'TEXT_NONE_FOUND'           => $TEXT['NONE_FOUND'],
219
		'TEXT_ADD'                  => $TEXT['ADD'],
220
		'TEXT_RESET'                => $TEXT['RESET'],
221
		'TEXT_ADMINISTRATORS'       => $TEXT['ADMINISTRATORS'],
222
		'TEXT_PRIVATE_VIEWERS'      => $TEXT['PRIVATE_VIEWERS'],
223
		'TEXT_REGISTERED_VIEWERS'   => $TEXT['REGISTERED_VIEWERS'],
224
		'INTRO_LINK'                => $MESSAGE['PAGES_INTRO_LINK'],
225
		)
226
	);
509 227
// Insert permissions values
510
if($admin->get_permission('pages_add') != true) {
511
	$template->set_var('DISPLAY_ADD', 'hide');
512
} elseif($admin->get_permission('pages_add_l0') != true && $editable_pages == 0) {
513
	$template->set_var('DISPLAY_ADD', 'hide');
514
}
515
if($admin->get_permission('pages_intro') != true || INTRO_PAGE != 'enabled') {
516
	$template->set_var('DISPLAY_INTRO', 'hide');
517
}
228
	if($admin->get_permission('pages_add') != true) {
229
		$oTpl->set_var('DISPLAY_ADD', 'hide');
230
	} elseif($admin->get_permission('pages_add_l0') != true && !$oPageTree->getWriteablePages()) {
231
		$oTpl->set_var('DISPLAY_ADD', 'hide');
232
	}
233
	if($admin->get_permission('pages_intro') != true || INTRO_PAGE != 'enabled') {
234
		$oTpl->set_var('DISPLAY_INTRO', 'hide');
235
	}
518 236
// Parse template object
519
$template->parse('main', 'main_block', false);
520
$template->pparse('output', 'page');
521
// include the required file for Javascript admin
522
if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')) {
523
	include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
524
}
525
// Print admin
526
$admin->print_footer();
237
	$oTpl->parse('main', 'main_block', false);
238
	$oTpl->pparse('output', 'page');
239
	// include the required file for Javascript admin
240
	if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')) {
241
		include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
242
	}
243
	// Print admin
244
	$admin->print_footer();
245
	

Also available in: Unified diff