<?

/*
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 permissions page
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_usersandpermissions.gif" width="19" height="20"> '.$MsgText[0][55];
	$BrowserTitle = $MsgText[0][55];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[0][55];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[4] == 'y') {
		
			$query = "select count(RecordNumber) as RecordsCount from `".$Settings['DBPrefix']."core-Users` where Level<='".$UserLevel."' and Username!='".$CookieUsername."'";
			$result = mysql_query($query) or die (mysql_error());
			$row = mysql_fetch_array($result);
				
			$RecordsCount = $row['RecordsCount'];
				
			$PagesCount = ceil($RecordsCount/intval($Settings['UsersPerPage']));
			
			$PageNumber = intval($Arguments3);
			
			if ($PageNumber > 0) {	
				if ($PageNumber > $PagesCount) {
					$PageNumber = $PagesCount;
				}
			}
			else {
				$PageNumber = 1;
			}
		
			$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)) {
				$LevelsDropdown .= '<option value="'.$row['Level'].'"> '.$row['Description'].' ('.$row['Level'].')</option>';
				$LevelDescriptions[$row['Level']] = $row['Description'];
			}
			
			$query = "select * from `".$Settings['DBPrefix']."core-Users` where Level<='".$UserLevel."' and Username!='".$CookieUsername."' order by Level desc, Username asc limit ".(($PageNumber-1)*intval($Settings['UsersPerPage'])).",".intval($Settings['UsersPerPage']);
   			$result = mysql_query($query) or die (mysql_error());
			while ($row = mysql_fetch_array($result)) {
				$UserCounter++;
				
				if ($row['DisplayName'] != '') { $row['DisplayName'] = ' (' . $row['DisplayName'] . ')'; }
				
				$PrintRows .= '<tr><td><font face="'.$FontFace.'" size="'.$FontSize.'">'.$row['Username'].$row['DisplayName'].'</td><td><input type="hidden" name="Username'.$UserCounter.'" value="'.$row['Username'].'"><input type="hidden" name="PreviousLevel'.$UserCounter.'" value="'.$row['Level'].'"><select name="NewLevel'.$UserCounter.'"><option value="'.$row['Level'].'" selected> '.$LevelDescriptions[$row['Level']].' ('.$row['Level'].')</option><option value="'.$row['Level'].'">----------</option>'.$LevelsDropdown.'</select></td></tr>';
			}
			if ($PrintRows == '') {
				$PrintRows = '<tr><td colspan="2"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$MsgText[0][341].'</td></tr>';
			}
			else {
				$PrintRows .= '<input type="hidden" name="RowsCount" value="'.$UserCounter.'">';
			}
			
			if ($PagesCount > 1 && $PageNumber > 1) {
				$PreviousPageLink = '<a href="'.$MainURL.'/admin/permissions/'.($PageNumber-1).'.html"><b>&lt; '.$MsgText[0][558].'</b></a>';
			}
			if ($PagesCount > 1 && $PageNumber < $PagesCount) {
				$NextPageLink = '<a href="'.$MainURL.'/admin/permissions/'.($PageNumber+1).'.html"><b>'.$MsgText[0][557].' &gt;</b></a>';
			}
			if ($PagesCount > 1) {
				$PLHeader = '<div align="center"><b>'.$MsgText[0][559].'</b></div>';
				$PageLinks = '<br><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="50%"><font face="'.$FontFace.'" size="'.($FontSize-1).'">'.$PreviousPageLink.'</font></td><td width="50%" align="right"><font face="'.$FontFace.'" size="'.($FontSize-1).'">'.$NextPageLink.'</font></td></tr></table><br>';
			}
	
			$PageContents = $MsgText[0][342].'<br><br><br><b>'.$MsgText[0][343].': '.$UserLevel.' - '.$LevelDescriptions[$UserLevel].'</b><br><form action="'.$BaseURL.'/'.$Settings['ScriptName'].'/admin/permissions-save" method="post"><input type="hidden" name="PageNumber" value="'.$PageNumber.'">'.$PLHeader.$PageLinks.'<div align="center"><table width="80%" border="0" cellpadding="3" cellspacing="0"><tr><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[0][99].'</b></td><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[0][344].'</b></td></tr>'.$PrintRows.'</table><br><br><input type="submit" value="'.$MsgText[0][123].'"></div>'.$PageLinks.'</form>';

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

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
