<?

/*
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
*/



	// ========================================================================================
	// admin permission levels page
	// ========================================================================================
	
	$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') {
		
			ReadFormArguments();
			Global $FormArguments;
			
			if (count($FormArguments) > 0) {
			
			
			$LevelsArray = split('-',$FormArguments['Levels']);
			
			for ($i = 0; $i < count($LevelsArray); $i++) {
			
				if ($FormArguments['Delete'.$LevelsArray[$i]] == 'delete') {
				
					// delete the level
					//print 'Delete '.$LevelsArray[$i].'<br><br>';
					$query = "delete from `".$Settings['DBPrefix']."core-Permissions` where Level=".$LevelsArray[$i]." LIMIT 1";
					$result = mysql_query($query) or die (mysql_error());
				
				
				}
				else {
					if ($FormArguments['Level'.$LevelsArray[$i]] == $LevelsArray[$i]) {
						// level number hasn't changed
						
						$NewPermissions = '';
						for ($x = 1; $x <= 1000; $x++) {
							if ($FormArguments['Permissions'.$FormArguments['Level'.$LevelsArray[$i]].'-'.$x] == 'y') {
								$NewPermissions .= $x.'-';
							}
						}
						
						$query = "update `".$Settings['DBPrefix']."core-Permissions` set Description='".$FormArguments['Name'.$LevelsArray[$i]]."', Permissions='".$NewPermissions."' where Level=".$LevelsArray[$i]." LIMIT 1";
						$result = mysql_query($query) or die (mysql_error());
						
											
					}
					else {										
					
						$query = "select Permissions from `".$Settings['DBPrefix']."core-Permissions` where Level=".$FormArguments['Level'.$LevelsArray[$i]]." LIMIT 1";
			  			$result = mysql_query($query) or die (mysql_error());				
						if (mysql_num_rows($result) == 0 && $FormArguments['Level'.$LevelsArray[$i]] > 0) {
				
							$NewPermissions = '';
							for ($x = 1; $x <= 1000; $x++) {
								if ($FormArguments['Permissions'.$LevelsArray[$i].'-'.$x] == 'y') {
									$NewPermissions .= $x.'-';
								}
							}
						
							$query = "update `".$Settings['DBPrefix']."core-Permissions` set Description='".$FormArguments['Name'.$LevelsArray[$i]]."', Level='".$FormArguments['Level'.$LevelsArray[$i]]."', Permissions='".$NewPermissions."' where Level=".$LevelsArray[$i]." LIMIT 1";
							$result = mysql_query($query) or die (mysql_error());
																
						}
						else {
						
							$PageContents .= '<br><br>'.$FormArguments['Name'.$LevelsArray[$i]].' '.$MsgText[0][365].' ('.$FormArguments['Level'.$LevelsArray[$i]].') '.$MsgText[0][366].' <a href="'.$MainURL.'/admin/levels.html">'.$MsgText[0][367].'</a> '.$MsgText[0][368];
					
						}
					
					} // end if number has changed
					
				} // end if not deleting
						
			} // end loop
			
			
			if ($PageContents == '') {
			
				header('Location: ' . $MainURL.'/options.html');
			
			}
			
			
			}
			else {
				$PageContents = $MsgText[0][98];
			}
						

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

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
