Location: PHPKode > projects > PapyrusBB > PapyrusBB-0.6/include/admin/adminPermissions.php
<?php
defined('WikyBlog') or die("Not an entry point...");

if( $_SESSION['userlevel'] !== 5){
	global $page;
	$page->contentA['Admin Only'] = 'You must be an administrator to access this page.';
	return;
}


global $bb_permissions;
$bb_permissions = array(	'view_forum'=>-1, //unrestricted
							'view_topics'=>-1,
							'new_topics'=>1, //logged in
							'new_posts'=>1,
							'mod_sticky'=>3, //owner
							'mod_edit_own'=>1,
							'mod_edit_topics'=>3,
							'mod_delete_own'=>1,
							'mod_delete_topics'=>3,
							'mod_options'=>3,
							);
							
if( function_exists('imagecreate') ){
	$bb_permissions['use_captcha'] = -1;
}

pluginIncludeFile('include/admin/adminForums.php',false);

class adminPermissions extends forumAdmin{
	

	var $forum_id;
	var $permissionsRow;
	function adminPermissions(){
		global $page,$langA,$dbObject,$rootDir,$pageOwner,$wbPluginSpace;
		
		
		pluginIncludeFile('include/allForumScripts.php');
		wbLang::pluginFile('admin.php');
		
		
		$dbObject->links[$langA['forum_admin']] = '/Admin/'.$pageOwner['username'].'/'.$wbPluginSpace.'/Admin';
		$dbObject->links[$langA['categories']] = '/Admin/'.$pageOwner['username'].'/'.$wbPluginSpace.'/Categories';
		$dbObject->links[$langA['permissions']] = '/Admin/'.$pageOwner['username'].'/'.$wbPluginSpace.'/Permissions';
		$dbObject->links['forums'] = '/'.$wbPluginSpace;
		
		$this->title = $langA['permissions'];
		$page->formAction =& $dbObject->links[$this->title];
		
		$getList = false;
		if( isset($_POST['id']) ){
			$this->forum_id = $_POST['id'];
		}elseif(isset($_GET['id'])){
			$this->forum_id = $_GET['id'];
		}else{
			$getList = true;
		}
		
		
		
		if( !is_numeric($this->forum_id) ){
			$getList = true;
		}
		if( !$this->getPermissions() ){
			$getList = true;
		}
		
		
		ob_start();
		
		if( $getList || empty($page->userCmd) ){
			$this->getList(); //from adminForums.php
			$page->contentA[$langA['forum_admin']] = wb::get_clean();
			return;
			
		}else{
		
			
			switch($page->userCmd){
				
				case 'savepermissions':
					$this->savePermissions();
				case 'edit':
					$this->showPermissions();
				break;
				
				default:
					$this->getList(); //from adminForums.php
					//$this->showForums();
				break;
			}
		}
		
		
		$page->contentA[$this->title] = wb::get_clean();
	}

	
	function getPermissions(){
		global $wbTables;
		
		$query = 'SELECT * FROM '.$wbTables['bb_forums_access'];
		$query .= ' WHERE `forum_id` = "'.wbDB::escape($this->forum_id).'" ';
		$result = wbDB::runQuery($query);
		if( !$result ){
			return false;
		}
		$num = mysql_num_rows($result);
		if( $num == 0 ){
			return true;
		}
		$this->permissionsRow = mysql_fetch_assoc($result);
		return true;
	}
	
	
	////////////////////////////////////////////////////////////////////////////////////
	//
	//		Permissions Changing
	//
	function showPermissions(){
		global $langA,$bb_permissions;
		
		echo '<input type="hidden" name="id" value="'.$this->forum_id.'" />';
		
		echo '<table class="tableRows">';
		echo '<tr>';
		echo '<th>';
		echo $langA['permission'];
		echo '</th>';
		echo '<th>';
		echo $langA['level'];
		echo '</th>';
		echo '</tr>';
		foreach($bb_permissions as $permission => $default){
			echo '<tr>';
			echo '<td><b>';
			echo $langA[$permission];
			echo '</b>';
			echo '</td>';
			echo '<td>';
			$this->showLevel($permission,$default);
			echo '</td>';
			echo '</tr>';
		}
		echo '<tr>';
		echo '<td>';
		echo '</td>';
		echo '<td>';
		echo '<input type="submit" name="cmd" value="'.$langA['submit'].'" />';
		echo ' &nbsp; ';
		echo '<input type="submit" name="" value="'.$langA['cancel'].'" onclick="wbCA.close();return false;" />';
		echo '</td>';
		echo '</tr>';
		
		echo '</table>';
		
	}
	function showLevel($name,$default){
		global $langA;
		
		if( isset($this->permissionsRow[$name]) ){
			$level = $this->permissionsRow[$name];
		}else{
			$level = $default;
		}
		
		$levels[5] = 'administrator';
		$levels[4] = 'owner_strict';
		$levels[3] = 'owner';
		$levels[2] = 'workgroup';
		$levels[1] = 'registered';
		$levels[0] = 'anonymous';
		$levels[-1] = 'unrestricted';
		
		echo '<select name="'.$name.'" >';
		$i = 0;
		foreach($levels as $raw => $user){
			if( isset($langA[$user]) ){
				$label = $langA[$user];
			}else{
				$label = $user;
			}
			$label = str_pad('',$i,'&nbsp;').' '.$label;
			
			if( (int)$raw === (int)$level ){
				echo '<option value="'.$raw.'" selected="selected" >'.$label.'</option>';
			}else{
				echo '<option value="'.$raw.'" >'.$label.'</option>';
			}
			$i+=12;
		}
		echo '</select>';
	}
	
	function savePermissions(){
		global $wbTables,$bb_permissions;
		
		$query = 'REPLACE INTO '.$wbTables['bb_forums_access'];
		$query .= ' SET ';
		
		$insertA = array();
		$insertA[] = ' `forum_id` = "'.wbDB::escape($this->forum_id).'" ';
		foreach($bb_permissions as $permission => $default){
			$insertA[] = ' `'.$permission.'` = "'.wbDB::escape($_POST[$permission]).'" ';
		}
		$query .= implode(', ',$insertA);
		if( !wbDB::runQuery($query) ){
			message('REQUEST_FAILED');
		}else{
			$this->getPermissions();
			message('saved');
		}
		
	}
}
new adminPermissions();
Return current item: PapyrusBB