<?

/*
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 article
	// ========================================================================================
	
	$query = "select * from `".$Settings['DBPrefix']."na-Settings`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		$naSettings[$row['Name']] = $row['Value'];
	}

	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_articles.gif" width="22" height="21"> '.$MsgText[7][31];
	$BrowserTitle = $MsgText[7][31];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL.'/admin/articles.html">'.$naSettings['Title'].'</a> > '.$MsgText[7][31];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[703] == 'y') {
			
			$Arguments3 = intval($Arguments3);
			
			if ($Arguments3 > 0) {
			
				$query = "select * from `".$Settings['DBPrefix']."na-Categories` where RecordNumber='".$Arguments3."' limit 1";
				$result = mysql_query($query) or die (mysql_error());
				if (mysql_num_rows($result) > 0) {
					$row = mysql_fetch_array($result);
					
					
					
						$CurrentCategoryID = $row['Parent'];
				
				$ThisCategoryID = $row['RecordNumber'];
				
				
				$query2 = "select * from `".$Settings['DBPrefix']."na-Categories` ORDER BY CategoryName ASC";
				$result2 = mysql_query($query2) or die (mysql_error());
			
				while ($row2 = mysql_fetch_array($result2)) { 
	    	        
					$CategoryIDsArray[$row2['Parent']][] = $row2['RecordNumber'];
					$CategoryNamesArray[$row2['Parent']][] = $row2['CategoryName'];
				
				}
				
				
				
				$CategoryDropdown = '<option value="0"> '.$MsgText[0][248].'</option>';
			
			$CatParent5 = 0;
			$LastParentAbove5 = '0';
			$CatLevel5['0'] = 0;
						
			function SpiderCategories5($CatParent5) {
				
				Global $ThisCategoryID, $CurrentCategoryID, $CategoryIDsArray, $CategoryNamesArray, $CategoryDropdown, $LastParent5, $LastParentAbove5, $CatSpacersArray5, $CatLevel5, $CatsCount5;
				
				for ($i = 0; $i < count($CategoryIDsArray[$CatParent5]); $i++) {
				
					if ($CategoryIDsArray[$CatParent5][$i] != $ThisCategoryID) {
					
					$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;\'------';
							$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;|------';
								$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
								$ResetAfter5 = 'y2';
							}
							else {
								//$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
								$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;';
							$CatSpacersArray5[$CatLevel5[$CatParent5]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
							$ResetAfter5 = 'n';
						}
										
					}
					
					
					if ($CurrentCategoryID == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';
					
										
					if (count($CategoryIDsArray[$CatParent5][$i]) > 0) {
						SpiderCategories5($CategoryIDsArray[$CatParent5][$i]);
					}
				
				} // end if
				} // end loop
				
				
			}
			
			SpiderCategories5('0');
						
					
								
						$PageContents .= '<br><form name="PostForm" action="'.$MainURL.'/admin/articles-cat-edit-save" method="post"><input type="hidden" name="CategoryIDToEdit" value="'.$Arguments3.'">
		
<b>'.$MsgText[7][29].':</b><br><input type="text" name="CategoryName" size="50" value="'.str_replace('"','&#34;',$row['CategoryName']).'" style="'.$FormStyle.'">
<br><br>

<b>'.$MsgText[7][95].':</b><br><input type="text" name="CategoryDescription" size="50" value="'.str_replace('"','&#34;',$row['CategoryDescription']).'" style="'.$FormStyle.'">
<br><br>
			
				<b>'.$MsgText[8][17].':</b><br>
				<select name="Parent" style="'.$FormStyle.'">'.$CategoryDropdown.'</select>
				
				<br>

				
				<br><br><b>'.$MsgText[7][32].':</b> <input type="checkbox" name="DeleteCategory" value="y"><br>
						
						
						<br><br><input type="submit" value="'.$MsgText[0][123].'" style="'.$FormStyle.'"></form>';
				
				}
				else {
					$PageContents = $MsgText[7][33];
				}
			
			}
			else {
				$PageContents = $MsgText[7][33];
			}
			
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}
		


?>
