<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// Manage Permission Levels
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_usersandpermissions.gif" width="19" height="20"> '.$MsgText[0][56];
	$BrowserTitle = $MsgText[0][56];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[0][56];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[6] == 'y') {
		
			$query = "select * from `".$Settings['DBPrefix']."core-Permissions` where Level<'".$UserLevel."' order by Level desc";
   			$result = mysql_query($query) or die (mysql_error());
			while ($row = mysql_fetch_array($result)) {
				$Levels[] = $row['Level'];
				$PermissionsBlock[] = $row['Permissions'];
				$LevelDescriptions[$row['Level']] = $row['Description'];
				
				$AllPermissions .= $row['Permissions'];
			}
			
			if ($UserLevel == 100) {
				for ($i = 1; $i <= 1000; $i++) {
					$Permissions[$i] = 'y';
				}
			}
			else {
				$PA = split('-',$AllPermissions);
		
				for ($i = 0; $i < count($PA); $i++) {
					if ($PA[$i] > 0) {
						$Permissions[$PA[$i]] = 'y';
					}
				}
			}
			
			
			$PH[1] = $MsgText[0][569]; 	// 1-99 = FlexCMS core
			$PH[2] = $MsgText[1][1]; 	// 100-199 = Calendar module
			$PH[3] = $MsgText[2][1];	// 200-299 = Message Board module
			$PH[4] = $MsgText[3][1]; 	// 300-399 = Photo Gallery module
			$PH[5] = $MsgText[4][1]; 	// 400-499 = Counter and Stats module
			$PH[6] = $MsgText[5][1]; 	// 500-599 = Newsletter module
			$PH[7] = $MsgText[6][1]; 	// 600-699 = Guestbook module
			$PH[8] = $MsgText[7][1]; 	// 700-799 = News/Articles module
			$PH[9] = $MsgText[8][1]; 	// 800-899 = Links module
			$PH[10] = $MsgText[9][1]; 		// 900-999 = eCommerce module
			
			
			
			
			$PD[1] = $MsgText[0][57]; 		// View Server and Version Information
			$PD[2] = $MsgText[0][50]; 		// Menu Blocks
			//$PD[3] = $MsgText[0][51];		// Pages (no longer used as of 1.3.1 6oct2005 -- now split into edit and create, 18 & 19)
			$PD[4] = $MsgText[0][55]; 		// Manage Users' Permissions
			$PD[5] = $MsgText[0][54]; 		// Edit Another User's Account
			$PD[6] = $MsgText[0][56]; 		// Manage Permission Levels
			$PD[7] = $MsgText[0][62]; 		// Modify Site Preferences
			$PD[8] = $MsgText[0][64]; 		// Modify Site Settings
			$PD[9] = $MsgText[0][345]; 		// Edit/Create PHP Enabled Content
			$PD[10] = $MsgText[0][53]; 		// Create a New User Account
			$PD[11] = $MsgText[0][58]; 		// View 'Where Are They Now'
			$PD[12] = $MsgText[0][59]; 		// View Members List
			$PD[13] = $MsgText[0][61]; 		// Modify Registration Form Fields
			$PD[14] = $MsgText[0][49]; 		// Manage Modules
			$PD[15] = $MsgText[0][60]; 		// Manage Smilies
			$PD[16] = $MsgText[0][63]; 		// Switch Templates
			//$PD[17] = $MsgText[0][52]; 		// Manage/Upload Images
			$PD[18] = $MsgText[0][573];		// Edit Existing Pages
			$PD[19] = $MsgText[0][574];		// Create New Pages
			$PD[20] = $MsgText[0][575];		// Edit Page Categories
			$PD[21] = $MsgText[0][581];		// Manage Countries and Regions
			$PD[22] = $MsgText[0][583];		// Create Site Backup
			$PD[23] = $MsgText[0][584];		// Restore Site From Backup
			$PD[24] = $MsgText[0][680];		// Bypass Maintenance Mode
			$PD[25] = $MsgText[0][681];		// Enable/Disable Maintenance Mode
			$PD[26] = $MsgText[0][697];		// File Manager
			
			$PD[80] = $MsgText[0][698];		// Upload GIF/JPG/PNG Images
			$PD[81] = $MsgText[0][699];		// Upload Plain Text Files
			$PD[82] = $MsgText[0][700];		// Upload Archive Files
			$PD[83] = $MsgText[0][701];		// Upload Office/Document Files
			$PD[84] = $MsgText[0][702];		// Upload Audio/Video Files
			$PD[85] = $MsgText[0][703];		// Upload Other Image Files
			$PD[86] = $MsgText[0][704];		// Upload Non-Server Script Files
			$PD[87] = $MsgText[0][705];		// Upload Restricted Files
			
			
			
			$PD[100] = $MsgText[1][2];		// Manage Calendar Events
			$PD[101] = $MsgText[1][3];		// Modify Calendar Preferences
			
			
			$PD[201] = $MsgText[0][346];	// Post Messages and Create Topics
			$PD[202] = $MsgText[0][347];	// Moderate (Edit/Delete/Move) Topics
			$PD[203] = $MsgText[0][348];	// View Posters' IP Addresses
			$PD[204] = $MsgText[0][349];	// Manage Boards/Categories, and Settings
			
			
			$PD[301] = $MsgText[0][350];	// Manage Photos & Galleries
			$PD[302] = $MsgText[3][4];		// Modify Photo & Gallery Preferences
			
			
			$PD[401] = $MsgText[0][351];	// View Counter and Statistics Reports
			$PD[402] = $MsgText[0][352];	// Modify Counter Preferences
			
			
			$PD[501] = $MsgText[0][353];	// Send Newsletter Messages
			$PD[502] = $MsgText[0][354];	// Manage Subscribers, Settings, and Archives
			$PD[503] = $MsgText[5][5];		// Modify Settings & Preferences
			
			
			$PD[601] = $MsgText[6][2];		// Manage Guestbook Entries
			$PD[602] = $MsgText[6][19];		// Modify Guestbook Preferences
			
			
			$PD[701] = $MsgText[7][81];		// Create Articles
			$PD[702] = $MsgText[7][82];		// Approve & Moderate Articles
			$PD[703] = $MsgText[7][83];		// Manage Categories
			$PD[704] = $MsgText[7][84];		// Modify Preferences & Settings
			
				
			$PD[801] = $MsgText[8][36];		// Manage Links and Preferences
			
			
			$PD[901] = $MsgText[9][360];	// Manage Products and Categories
			$PD[902] = $MsgText[9][129];		// Modify Settings and Preferences
			$PD[903] = $MsgText[9][72];		// Manage Shipping Options
			$PD[904] = $MsgText[9][116];	// Manage Taxes
			$PD[905] = $MsgText[9][15];		// View and Process Orders
			$PD[906] = $MsgText[9][175];	// View Reports and Statistics
			
			
			
			
			
			for ($i = 1; $i <= 1000; $i++) {
				if ($Permissions[$i] == 'y' && $PD[$i] != '') {
					$PNum[] = $i;
					$PDesc[] = $PD[$i];
					
					if ($NewHeadingPrinted[floor($i/100)+1] != 'y') {
						$NewHeadingPrinted[floor($i/100)+1] = 'y';
						$NewCheckboxes .= '<br><b>'.$PH[floor($i/100)+1].':</b><br>';
					}
					
					$NewCheckboxes .= '<input type="checkbox" name="NewPermissions-'.$i.'" value="y"> '.$PD[$i].'<br>';
				}
			}
			
			
			
			for ($i = 0; $i < count($Levels); $i++) {
			
				if ($LevelsString == '') {
					$LevelsString = $Levels[$i];
				}
				else {
					$LevelsString .= '-'.$Levels[$i];
				}
				
				$FormContents .= '<br><br><input type="text" name="Name'.$Levels[$i].'" size="40" value="'.$LevelDescriptions[$Levels[$i]].'"> <input type="text" name="Level'.$Levels[$i].'" size="3" value="'.$Levels[$i].'"><br><input type="checkbox" name="Delete'.$Levels[$i].'" value="delete"> '.$MsgText[0][355].'<br>';
				
				$PA = split('-',$PermissionsBlock[$i]);
		
				$TempPermissions = '';
				
				
				// if permission 3 is still in use, convert it to 18, 19, and 20
				for ($j = 0; $j < count($PA); $j++) {
					if ($PA[$j] > 0) {
						if ($PA[$j] == 3) {
							$PA[$j] = 18;
							$PA[count($PA)] = 19;
							$PA[count($PA)] = 20;
						}
					}
				}
				// --
				
				
				for ($j = 0; $j < count($PA); $j++) {
					if ($PA[$j] > 0) {
						$TempPermissions[$PA[$j]] = ' checked';
					}
				}
				
				for ($k = 0; $k < count($PNum); $k++) {
					if ($HeadingPrinted[floor($PNum[$k]/100)+1][$i] != 'y') {
						$HeadingPrinted[floor($PNum[$k]/100)+1][$i] = 'y';
						$FormContents .= '<br><b>'.$PH[floor($PNum[$k]/100)+1].':</b><br>';
					}
					$FormContents .= '<input type="checkbox" name="Permissions'.$Levels[$i].'-'.$PNum[$k].'" value="y"'.$TempPermissions[$PNum[$k]].'> '.$PDesc[$k].'<br>';
				}
				
				$FormContents .= '<br><br>';
			
			}
			
			
			$PageContents = $MsgText[0][356].'<br><br><br><a href="#new"><b>'.$MsgText[0][357].'</b></a><br><form action="'.$MainURL.'/admin/levels-save" method="post"><input type="hidden" name="Levels" value="'.$LevelsString.'">'.$FormContents.'<br><br><input type="submit" value="'.$MsgText[0][123].'"></form><br><br><br><a name="new"></a><b>'.$MsgText[0][357].':</b><br><form action="'.$MainURL.'/admin/levels-new-save" method="post">'.$MsgText[0][358].':<br><input type="text" name="NewName" size="40"><br><br>'.$MsgText[0][359].':<font size="1"> ('.$MsgText[0][360].')</font><br><input type="text" name="NewLevel" size="3"><br><br>'.$MsgText[0][361].':<br>'.$NewCheckboxes.'<br><br><input type="submit" value="'.$MsgText[0][362].'"></form>';
			

		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

	// ========================================================================================




?>
