<?

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



	// ========================================================================================
	// edit page category
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_content.gif" width="23" height="20"> '.$MsgText[0][296];
	$BrowserTitle = $MsgText[0][296];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL.'/admin/pages.html">'.$MsgText[0][244].'</a> > '.$MsgText[0][296];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[20] == 'y') {
	
						
			if ($Arguments3 != '') {
			
			$Arguments3 = intval($Arguments3);
			
			
			
			$query = "select * from `".$Settings['DBPrefix']."core-PageCategories` where RecordNumber!=".$Arguments3." ORDER BY Name ASC";
			$result = mysql_query($query) or die (mysql_error());
		
			while ($row = mysql_fetch_array($result)) { 
         	   
				$CategoryIDsArray[$row['Parent']][] = $row['RecordNumber'];
				$CategoryNamesArray[$row['Parent']][] = $row['Name'];
		
			}	
			
			
			
			$query = "select * from `".$Settings['DBPrefix']."core-PageCategories` where RecordNumber=".$Arguments3." limit 1";
			$result = mysql_query($query) or die (mysql_error());
			$row = mysql_fetch_array($result);
			
			
			
			$CurrentPageCategory = $row['Parent'];
			
			
			$PageCategoryDropdown = '<option value="0"> '.$MsgText[0][248].'</option>';
			
			$CatParent5 = 0;
			$LastParentAbove5 = '0';
			$CatLevel5['0'] = 0;
						
			function SpiderCategories5($CatParent5) {
				
				Global $CategoryIDsArray, $CategoryNamesArray, $PageCategoryDropdown, $LastParent5, $LastParentAbove5, $CatSpacersArray5, $CatLevel5, $CatsCount5, $CurrentPageCategory;
				
				for ($i = 0; $i < count($CategoryIDsArray[$CatParent5]); $i++) {
					
					$LastParentAboveB5 = $LastParentAbove5;
					$LastParentB5 = $LastParent5;
					
					$CatLevel5[$CategoryIDsArray[$CatParent5][$i]] = $CatLevel5[$CatParent5];
					if ($CatParent5 != $LastParent5 && $CatParent5 == $LastParentAbove5) {
				
						$CatLevel5[$CategoryIDsArray[$CatParent5][$i]] = $CatLevel5[$CatParent5] + 1;
						$CatLevel5[$CatParent5]++;
												
						$CatsCount5[$CatLevel5[$CatParent5]] = 0;
				
					}
					
					$LastParent5 = $CatParent5;
					$LastParentAbove5 = $CategoryIDsArray[$CatParent5][$i];
					
					$CatsCount5[$CatLevel5[$CatParent5]]++;
					
										
					$CatSpacer5 = '';
					for ($x = 0; $x < $CatLevel5[$CatParent5]; $x++) {
						
						if ($CatsCount5[$CatLevel5[$CatParent5]] == count($CategoryIDsArray[$CatParent5]) && $x == $CatLevel5[$CatParent5]-1) {
							$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;\'------';
							$ResetAfter5 = 'y';
						}
						else if ($CatsCount5[$CatLevel5[$CatParent5]] == count($CategoryIDsArray[$CatParent5])) {
							$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
						}
						else {
							if ($x < $CatLevel5[$CatParent5]) {
								$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;|------';
								$ResetAfter5 = 'y2';
							}
							else {
								$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
							}
						}
						
							
						$CatSpacer5 .= $CatSpacersArray5[$x+1];
						
						if ($ResetAfter5 == 'y') {
							$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
							$ResetAfter5 = 'n';
						}
						else if ($ResetAfter5 == 'y2') {
							$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
							$ResetAfter5 = 'n';
						}
										
					}
					
					
					if ($CategoryIDsArray[$CatParent5][$i] == $CurrentPageCategory) {
						$PageCategoryDropdown .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'" selected> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';
					}
					else {
						$PageCategoryDropdown .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';
					}
					
										
					if (count($CategoryIDsArray[$CatParent5][$i]) > 0) {
						SpiderCategories5($CategoryIDsArray[$CatParent5][$i]);
					}
				
				}
				
				
			}
			
			SpiderCategories5('0');
			
			
			
			if ($row['HideCategory'] == 'y') { $HideCategoryChecked = ' checked'; }
			
	
			$row['Name'] = str_replace('"', '&#34;', $row['Name']);
			
			$row['Description'] = str_replace('"', '&#34;', $row['Description']);
			
			
			$PageContents = '<br><b>'.$MsgText[0][296].':</b><form action="'.$MainURL . '/admin/pages-catedit-save" method="post"><input type="hidden" name="CatIDToEdit" value="'.$Arguments3.'">

<b>'.$MsgText[0][252].':</b><br><select name="CatParent">'.$PageCategoryDropdown.'</select>

<br><br>

<b>'.$MsgText[0][279].':</b><br><input type="text" name="CatName" size="30" value="'.$row['Name'].'">

<br><br>

<b>'.$MsgText[0][280].':</b><br><input type="text" name="CatDescription" size="50" value="'.$row['Description'].'">


<br><br>
<b>'.$MsgText[0][281].':</b>&nbsp;&nbsp;<input type="checkbox" name="HideCategory" value="y"'.$HideCategoryChecked.'> '.$MsgText[0][118].'<br><font size="1">'.$MsgText[0][282].'<br></font>


<br>
<br><br><b>'.$MsgText[0][297].':</b><br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="DeleteCategory" value="delete"> '.$MsgText[0][118].'<br>
<br><br>
<br>
<input type="submit" value="'.$MsgText[0][123].'">


</form><br><br><br><br>';
		
		}
			

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

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
