| 1 | <?php
 | 
  
    | 2 | 
 | 
  
    | 3 | /** 
 | 
  
    | 4 |  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 | 
  
    | 5 |  *
 | 
  
    | 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.
 | 
  
    | 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/>.
 | 
  
    | 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: 1839 $
 | 
  
    | 29 |  * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/index.php $
 | 
  
    | 30 |  * @lastmodified $Date: 2012-12-21 15:12:16 +0100 (Fri, 21 Dec 2012) $
 | 
  
    | 31 |  * @since        file added on 2012-12-21
 | 
  
    | 32 |  * @todo         rebuild this file to go into coding standards (sideeffects!!!)
 | 
  
    | 33 |  */
 | 
  
    | 34 | 
 | 
  
    | 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 | 				}
 | 
  
    | 63 | 			}
 | 
  
    | 64 | 		}
 | 
  
    | 65 | 		return $aNewGroups;
 | 
  
    | 66 | 	} // end of admin_pages_makeGroupList()
 | 
  
    | 67 | // --- end helper functions --------------------------------------------------------------
 | 
  
    | 68 | // #######################################################################################
 | 
  
    | 69 | // --- start script ----------------------------------------------------------------------
 | 
  
    | 70 | 
 | 
  
    | 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
 | 
  
    | 89 | 	$database = WbDatabase::getInstance();
 | 
  
    | 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();
 | 
  
    | 107 | 	
 | 
  
    | 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);
 | 
  
    | 123 | 	}
 | 
  
    | 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);
 | 
  
    | 133 | 	}
 | 
  
    | 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);
 | 
  
    | 162 | 		}
 | 
  
    | 163 | 	}
 | 
  
    | 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);
 | 
  
    | 183 | 		}
 | 
  
    | 184 | 	}
 | 
  
    | 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 --------------------------------------------------------	
 | 
  
    | 195 | // Insert urls
 | 
  
    | 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 | 	);
 | 
  
    | 205 | // Insert language text and messages
 | 
  
    | 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 | 	);
 | 
  
    | 227 | // Insert permissions values
 | 
  
    | 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 | 	}
 | 
  
    | 236 | // Parse template object
 | 
  
    | 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 | 	
 |