| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      
 
     | 
  
  
    | 
      3
     | 
    
      // $Id: class.admin.php 127 2005-09-18 23:14:39Z ryan $
 
     | 
  
  
    | 
      4
     | 
    
      
 
     | 
  
  
    | 
      5
     | 
    
      /*
 
     | 
  
  
    | 
      6
     | 
    
      
 
     | 
  
  
    | 
      7
     | 
    
       Website Baker Project <http://www.websitebaker.org/>
 
     | 
  
  
    | 
      8
     | 
    
       Copyright (C) 2004-2005, Ryan Djurovich
 
     | 
  
  
    | 
      9
     | 
    
      
 
     | 
  
  
    | 
      10
     | 
    
       Website Baker is free software; you can redistribute it and/or modify
 
     | 
  
  
    | 
      11
     | 
    
       it under the terms of the GNU General Public License as published by
 
     | 
  
  
    | 
      12
     | 
    
       the Free Software Foundation; either version 2 of the License, or
 
     | 
  
  
    | 
      13
     | 
    
       (at your option) any later version.
 
     | 
  
  
    | 
      14
     | 
    
      
 
     | 
  
  
    | 
      15
     | 
    
       Website Baker is distributed in the hope that it will be useful,
 
     | 
  
  
    | 
      16
     | 
    
       but WITHOUT ANY WARRANTY; without even the implied warranty of
 
     | 
  
  
    | 
      17
     | 
    
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
     | 
  
  
    | 
      18
     | 
    
       GNU General Public License for more details.
 
     | 
  
  
    | 
      19
     | 
    
      
 
     | 
  
  
    | 
      20
     | 
    
       You should have received a copy of the GNU General Public License
 
     | 
  
  
    | 
      21
     | 
    
       along with Website Baker; if not, write to the Free Software
 
     | 
  
  
    | 
      22
     | 
    
       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
     | 
  
  
    | 
      23
     | 
    
      
 
     | 
  
  
    | 
      24
     | 
    
      */
 
     | 
  
  
    | 
      25
     | 
    
      
 
     | 
  
  
    | 
      26
     | 
    
      /*
 
     | 
  
  
    | 
      27
     | 
    
      
 
     | 
  
  
    | 
      28
     | 
    
      Admin class
 
     | 
  
  
    | 
      29
     | 
    
      
 
     | 
  
  
    | 
      30
     | 
    
      This class will be used for every program that will be included
 
     | 
  
  
    | 
      31
     | 
    
      in the administration section of Website Baker.
 
     | 
  
  
    | 
      32
     | 
    
      
 
     | 
  
  
    | 
      33
     | 
    
      */
 
     | 
  
  
    | 
      34
     | 
    
      
 
     | 
  
  
    | 
      35
     | 
    
      if(!defined('WB_URL')) {
     | 
  
  
    | 
      36
     | 
    
      	header('Location: ../index.php');
     | 
  
  
    | 
      37
     | 
    
      }
 
     | 
  
  
    | 
      38
     | 
    
      
 
     | 
  
  
    | 
      39
     | 
    
      require_once(WB_PATH.'/framework/class.wb.php');
 
     | 
  
  
    | 
      40
     | 
    
      
 
     | 
  
  
    | 
      41
     | 
    
      // Include PHPLIB template class
 
     | 
  
  
    | 
      42
     | 
    
      require_once(WB_PATH."/include/phplib/template.inc");
 
     | 
  
  
    | 
      43
     | 
    
      
 
     | 
  
  
    | 
      44
     | 
    
      
 
     | 
  
  
    | 
      45
     | 
    
      // Get WB version
 
     | 
  
  
    | 
      46
     | 
    
      require_once(ADMIN_PATH.'/interface/version.php');
 
     | 
  
  
    | 
      47
     | 
    
      
 
     | 
  
  
    | 
      48
     | 
    
      /*
 
     | 
  
  
    | 
      49
     | 
    
      Begin user changeable settings
 
     | 
  
  
    | 
      50
     | 
    
      */
 
     | 
  
  
    | 
      51
     | 
    
      
 
     | 
  
  
    | 
      52
     | 
    
      
 
     | 
  
  
    | 
      53
     | 
    
      class admin extends wb {
     | 
  
  
    | 
      54
     | 
    
      	// Authenticate user then auto print the header
 
     | 
  
  
    | 
      55
     | 
    
      	function admin($section_name, $section_permission = 'start', $auto_header = true, $auto_auth = true) {
     | 
  
  
    | 
      56
     | 
    
      		$this->wb();
 
     | 
  
  
    | 
      57
     | 
    
      		global $MESSAGE;
 
     | 
  
  
    | 
      58
     | 
    
      		// Specify the current applications name
 
     | 
  
  
    | 
      59
     | 
    
      		$this->section_name = $section_name;
 
     | 
  
  
    | 
      60
     | 
    
      		$this->section_permission = $section_permission;
 
     | 
  
  
    | 
      61
     | 
    
      		// Authenticate the user for this application
 
     | 
  
  
    | 
      62
     | 
    
      		if($auto_auth == true) {
     | 
  
  
    | 
      63
     | 
    
      			// First check if the user is logged-in
 
     | 
  
  
    | 
      64
     | 
    
      			if($this->is_authenticated() == false) {
     | 
  
  
    | 
      65
     | 
    
      				header('Location: '.ADMIN_URL.'/login/index.php');
     | 
  
  
    | 
      66
     | 
    
      			}
 
     | 
  
  
    | 
      67
     | 
    
      			// Now check if they are allowed in this section
 
     | 
  
  
    | 
      68
     | 
    
      			if($this->get_permission($section_permission) == false) {
     | 
  
  
    | 
      69
     | 
    
      				die($MESSAGE['ADMIN']['INSUFFICIENT_PRIVELLIGES']);
 
     | 
  
  
    | 
      70
     | 
    
      			}
 
     | 
  
  
    | 
      71
     | 
    
      		}
 
     | 
  
  
    | 
      72
     | 
    
      		// Auto header code
 
     | 
  
  
    | 
      73
     | 
    
      		if($auto_header == true) {
     | 
  
  
    | 
      74
     | 
    
      			$this->print_header();
 
     | 
  
  
    | 
      75
     | 
    
      		}
 
     | 
  
  
    | 
      76
     | 
    
      	}
 
     | 
  
  
    | 
      77
     | 
    
      	
 
     | 
  
  
    | 
      78
     | 
    
      	// Print the admin header
 
     | 
  
  
    | 
      79
     | 
    
      	function print_header($body_tags = '') {
     | 
  
  
    | 
      80
     | 
    
      		// Get vars from the language file
 
     | 
  
  
    | 
      81
     | 
    
      		global $MENU;
 
     | 
  
  
    | 
      82
     | 
    
      		global $MESSAGE;
 
     | 
  
  
    | 
      83
     | 
    
      		global $TEXT;
 
     | 
  
  
    | 
      84
     | 
    
      		// Connect to database and get website title
 
     | 
  
  
    | 
      85
     | 
    
      		global $database;
 
     | 
  
  
    | 
      86
     | 
    
      		$get_title = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'title'");
     | 
  
  
    | 
      87
     | 
    
      		$title = $get_title->fetchRow();
 
     | 
  
  
    | 
      88
     | 
    
      		$header_template = new Template(ADMIN_PATH."/interface");
 
     | 
  
  
    | 
      89
     | 
    
      		$header_template->set_file('page', 'header.html');
     | 
  
  
    | 
      90
     | 
    
      		$header_template->set_block('page', 'header_block', 'header');
     | 
  
  
    | 
      91
     | 
    
      		$header_template->set_var(	array(
 
     | 
  
  
    | 
      92
     | 
    
      													'SECTION_NAME' => $MENU[strtoupper($this->section_name)],
 
     | 
  
  
    | 
      93
     | 
    
      													'INTERFACE_DIR' => ADMIN_URL.'/interface',
 
     | 
  
  
    | 
      94
     | 
    
      													'BODY_TAGS' => $body_tags,
 
     | 
  
  
    | 
      95
     | 
    
      													'WEBSITE_TITLE' => ($title['value']),
 
     | 
  
  
    | 
      96
     | 
    
      													'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'],
 
     | 
  
  
    | 
      97
     | 
    
      													'VERSION' => VERSION
 
     | 
  
  
    | 
      98
     | 
    
      													)
 
     | 
  
  
    | 
      99
     | 
    
      											);
 
     | 
  
  
    | 
      100
     | 
    
      		// Create the menu
 
     | 
  
  
    | 
      101
     | 
    
      		$menu = array(
 
     | 
  
  
    | 
      102
     | 
    
      					array(ADMIN_URL.'/start/index.php', '', $MENU['START'], 'start', 0),
 
     | 
  
  
    | 
      103
     | 
    
      					array(ADMIN_URL.'/pages/index.php', '', $MENU['PAGES'], 'pages', 1),
 
     | 
  
  
    | 
      104
     | 
    
      					array(ADMIN_URL.'/media/index.php', '', $MENU['MEDIA'], 'media', 1),
 
     | 
  
  
    | 
      105
     | 
    
      					array(ADMIN_URL.'/addons/index.php', '', $MENU['ADDONS'], 'addons', 1),
 
     | 
  
  
    | 
      106
     | 
    
      					array(ADMIN_URL.'/preferences/index.php', '', $MENU['PREFERENCES'], 'preferences', 0),
 
     | 
  
  
    | 
      107
     | 
    
      					array(ADMIN_URL.'/settings/index.php', '', $MENU['SETTINGS'], 'settings', 1),
 
     | 
  
  
    | 
      108
     | 
    
      					array(ADMIN_URL.'/access/index.php', '', $MENU['ACCESS'], 'access', 1),
 
     | 
  
  
    | 
      109
     | 
    
      					array('http://www.websitebaker.org/2/help/', '_blank', $MENU['HELP'], 'help', 0),
     | 
  
  
    | 
      110
     | 
    
      					array(WB_URL.'/', '_blank', $MENU['VIEW'], 'view', 0),
 
     | 
  
  
    | 
      111
     | 
    
      					array(ADMIN_URL.'/logout/index.php', '', $MENU['LOGOUT'], 'logout', 0)
 
     | 
  
  
    | 
      112
     | 
    
      					);
 
     | 
  
  
    | 
      113
     | 
    
      		$header_template->set_block('header_block', 'linkBlock', 'link');
     | 
  
  
    | 
      114
     | 
    
      		foreach($menu AS $menu_item) {
     | 
  
  
    | 
      115
     | 
    
      			$link = $menu_item[0];
 
     | 
  
  
    | 
      116
     | 
    
      			$target = $menu_item[1];
 
     | 
  
  
    | 
      117
     | 
    
      			$title = $menu_item[2];
 
     | 
  
  
    | 
      118
     | 
    
      			$permission_title = $menu_item[3];
 
     | 
  
  
    | 
      119
     | 
    
      			$required = $menu_item[4];
 
     | 
  
  
    | 
      120
     | 
    
      			$replace_old = array(ADMIN_URL, WB_URL, '/', 'index.php');
 
     | 
  
  
    | 
      121
     | 
    
      			if($required == false OR $this->get_link_permission($permission_title)) {
     | 
  
  
    | 
      122
     | 
    
      				$header_template->set_var('LINK', $link);
     | 
  
  
    | 
      123
     | 
    
      				$header_template->set_var('TARGET', $target);
     | 
  
  
    | 
      124
     | 
    
      				// If link is the current section apply a class name
 
     | 
  
  
    | 
      125
     | 
    
      				if($permission_title == strtolower($this->section_name)) {
     | 
  
  
    | 
      126
     | 
    
      					$header_template->set_var('CLASS', 'current');
     | 
  
  
    | 
      127
     | 
    
      				} else {
     | 
  
  
    | 
      128
     | 
    
      					$header_template->set_var('CLASS', '');
     | 
  
  
    | 
      129
     | 
    
      				}
 
     | 
  
  
    | 
      130
     | 
    
      				$header_template->set_var('TITLE', $title);
     | 
  
  
    | 
      131
     | 
    
      				// Print link
 
     | 
  
  
    | 
      132
     | 
    
      				$header_template->parse('link', 'linkBlock', true);
     | 
  
  
    | 
      133
     | 
    
      			}
 
     | 
  
  
    | 
      134
     | 
    
      		}
 
     | 
  
  
    | 
      135
     | 
    
      		$header_template->parse('header', 'header_block', false);
     | 
  
  
    | 
      136
     | 
    
      		$header_template->pparse('output', 'page');
     | 
  
  
    | 
      137
     | 
    
      	}
 
     | 
  
  
    | 
      138
     | 
    
      	
 
     | 
  
  
    | 
      139
     | 
    
      	// Print the admin footer
 
     | 
  
  
    | 
      140
     | 
    
      	function print_footer() {
     | 
  
  
    | 
      141
     | 
    
      		$footer_template = new Template(ADMIN_PATH."/interface");
 
     | 
  
  
    | 
      142
     | 
    
      		$footer_template->set_file('page', 'footer.html');
     | 
  
  
    | 
      143
     | 
    
      		$footer_template->set_block('page', 'footer_block', 'header');
     | 
  
  
    | 
      144
     | 
    
      		$footer_template->parse('header', 'footer_block', false);
     | 
  
  
    | 
      145
     | 
    
      		$footer_template->pparse('output', 'page');
     | 
  
  
    | 
      146
     | 
    
      	}
 
     | 
  
  
    | 
      147
     | 
    
      	
 
     | 
  
  
    | 
      148
     | 
    
      	// Print a success message which then automatically redirects the user to another page
 
     | 
  
  
    | 
      149
     | 
    
      	function print_success($message, $redirect = 'index.php') {
     | 
  
  
    | 
      150
     | 
    
      		global $TEXT;
 
     | 
  
  
    | 
      151
     | 
    
      		$success_template = new Template(ADMIN_PATH.'/interface');
 
     | 
  
  
    | 
      152
     | 
    
      		$success_template->set_file('page', 'success.html');
     | 
  
  
    | 
      153
     | 
    
      		$success_template->set_block('page', 'main_block', 'main');
     | 
  
  
    | 
      154
     | 
    
      		$success_template->set_var('MESSAGE', $message);
     | 
  
  
    | 
      155
     | 
    
      		$success_template->set_var('REDIRECT', $redirect);
     | 
  
  
    | 
      156
     | 
    
      		$success_template->set_var('NEXT', $TEXT['NEXT']);
     | 
  
  
    | 
      157
     | 
    
      		$success_template->parse('main', 'main_block', false);
     | 
  
  
    | 
      158
     | 
    
      		$success_template->pparse('output', 'page');
     | 
  
  
    | 
      159
     | 
    
      	}
 
     | 
  
  
    | 
      160
     | 
    
      	
 
     | 
  
  
    | 
      161
     | 
    
      	// Print a error message
 
     | 
  
  
    | 
      162
     | 
    
      	function print_error($message, $link = 'index.php', $auto_footer = true) {
     | 
  
  
    | 
      163
     | 
    
      		global $TEXT;
 
     | 
  
  
    | 
      164
     | 
    
      		$success_template = new Template(ADMIN_PATH.'/interface');
 
     | 
  
  
    | 
      165
     | 
    
      		$success_template->set_file('page', 'error.html');
     | 
  
  
    | 
      166
     | 
    
      		$success_template->set_block('page', 'main_block', 'main');
     | 
  
  
    | 
      167
     | 
    
      		$success_template->set_var('MESSAGE', $message);
     | 
  
  
    | 
      168
     | 
    
      		$success_template->set_var('LINK', $link);
     | 
  
  
    | 
      169
     | 
    
      		$success_template->set_var('BACK', $TEXT['BACK']);
     | 
  
  
    | 
      170
     | 
    
      		$success_template->parse('main', 'main_block', false);
     | 
  
  
    | 
      171
     | 
    
      		$success_template->pparse('output', 'page');
     | 
  
  
    | 
      172
     | 
    
      		if($auto_footer == true) {
     | 
  
  
    | 
      173
     | 
    
      			$this->print_footer();
 
     | 
  
  
    | 
      174
     | 
    
      		}
 
     | 
  
  
    | 
      175
     | 
    
      		exit();
 
     | 
  
  
    | 
      176
     | 
    
      	}
 
     | 
  
  
    | 
      177
     | 
    
      
 
     | 
  
  
    | 
      178
     | 
    
      	// Return a system permission
 
     | 
  
  
    | 
      179
     | 
    
      	function get_permission($name, $type = 'system') {
     | 
  
  
    | 
      180
     | 
    
      		// Append to permission type
 
     | 
  
  
    | 
      181
     | 
    
      		$type .= '_permissions';
 
     | 
  
  
    | 
      182
     | 
    
      		// Check if we have a section to check for
 
     | 
  
  
    | 
      183
     | 
    
      		if($name == 'start') {
     | 
  
  
    | 
      184
     | 
    
      			return true;
 
     | 
  
  
    | 
      185
     | 
    
      		} else {
     | 
  
  
    | 
      186
     | 
    
      			// Set system permissions var
 
     | 
  
  
    | 
      187
     | 
    
      			$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
     | 
  
  
    | 
      188
     | 
    
      			// Set module permissions var
 
     | 
  
  
    | 
      189
     | 
    
      			$module_permissions = $this->get_session('MODULE_PERMISSIONS');
     | 
  
  
    | 
      190
     | 
    
      			// Set template permissions var
 
     | 
  
  
    | 
      191
     | 
    
      			$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS');
     | 
  
  
    | 
      192
     | 
    
      			// Return true if system perm = 1
 
     | 
  
  
    | 
      193
     | 
    
      			if(is_numeric(array_search($name, $$type))) {
     | 
  
  
    | 
      194
     | 
    
      				if($type == 'system_permissions') {
     | 
  
  
    | 
      195
     | 
    
      					return true;
 
     | 
  
  
    | 
      196
     | 
    
      				} else {
     | 
  
  
    | 
      197
     | 
    
      					return false;
 
     | 
  
  
    | 
      198
     | 
    
      				}
 
     | 
  
  
    | 
      199
     | 
    
      			} else {
     | 
  
  
    | 
      200
     | 
    
      				if($type == 'system_permissions') {
     | 
  
  
    | 
      201
     | 
    
      					return false;
 
     | 
  
  
    | 
      202
     | 
    
      				} else {
     | 
  
  
    | 
      203
     | 
    
      					return true;
 
     | 
  
  
    | 
      204
     | 
    
      				}
 
     | 
  
  
    | 
      205
     | 
    
      			}
 
     | 
  
  
    | 
      206
     | 
    
      		}
 
     | 
  
  
    | 
      207
     | 
    
      	}
 
     | 
  
  
    | 
      208
     | 
    
      
 
     | 
  
  
    | 
      209
     | 
    
      	// Returns a system permission for a menu link
 
     | 
  
  
    | 
      210
     | 
    
      	function get_link_permission($title) {
     | 
  
  
    | 
      211
     | 
    
      		$title = str_replace('_blank', '', $title);
     | 
  
  
    | 
      212
     | 
    
      		$title = strtolower($title);
 
     | 
  
  
    | 
      213
     | 
    
      		// Set system permissions var
 
     | 
  
  
    | 
      214
     | 
    
      		$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
     | 
  
  
    | 
      215
     | 
    
      		// Set module permissions var
 
     | 
  
  
    | 
      216
     | 
    
      		$module_permissions = $this->get_session('MODULE_PERMISSIONS');
     | 
  
  
    | 
      217
     | 
    
      		if($title == 'start') {
     | 
  
  
    | 
      218
     | 
    
      			return true;
 
     | 
  
  
    | 
      219
     | 
    
      		} else {
     | 
  
  
    | 
      220
     | 
    
      			// Return true if system perm = 1
 
     | 
  
  
    | 
      221
     | 
    
      			if(is_numeric(array_search($title, $system_permissions))) {
     | 
  
  
    | 
      222
     | 
    
      				return true;
 
     | 
  
  
    | 
      223
     | 
    
      			} else {
     | 
  
  
    | 
      224
     | 
    
      				return false;
 
     | 
  
  
    | 
      225
     | 
    
      			}
 
     | 
  
  
    | 
      226
     | 
    
      		}
 
     | 
  
  
    | 
      227
     | 
    
      	}
 
     | 
  
  
    | 
      228
     | 
    
      }
 
     | 
  
  
    | 
      229
     | 
    
      
 
     | 
  
  
    | 
      230
     | 
    
      ?>
 
     |