<?

/*
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 existing category
	// ========================================================================================
	
	
	$query = "select * from `".$Settings['DBPrefix']."lm-Settings`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		$lmSettings[$row['Name']] = $row['Value'];
	}
	
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_links.gif" width="20" height="21"> '.$MsgText[8][20];
	$BrowserTitle = $MsgText[8][20];
	$LocationBar = '<a href="'.$IndexURL.'">Home</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL.'/admin/links.html">'.$MsgText[8][2].'</a> > '.$MsgText[8][20];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[801] == 'y') {
		
			$Arguments3 = intval($Arguments3);
		
			if ($Arguments3 > 0) {
								
				$query = "select * from `".$Settings['DBPrefix']."lm-Categories` where RecordNumber='".$Arguments3."' limit 1";
				$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				
				$CurrentCategoryID = $row['Parent'];
				
				$ThisCategoryID = $row['RecordNumber'];
				
				
				$query2 = "select * from `".$Settings['DBPrefix']."lm-Categories` ORDER BY Title ASC";
				$result2 = mysql_query($query2) or die (mysql_error());
			
				while ($row2 = mysql_fetch_array($result2)) { 
	    	        
					$CategoryIDsArray[$row2['Parent']][] = $row2['RecordNumber'];
					$CategoryNamesArray[$row2['Parent']][] = $row2['Title'];
				
				}
				
				
				
				$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><b>'.$MsgText[8][20].':</b><br><br><form action="'.$MainURL.'/admin/links-catedit-save" method="post">
				<input type="hidden" name="CatIDToEdit" value="'.$Arguments3.'">
			
				<b>'.$MsgText[8][13].':</b><br>
				<input type="text" name="Title" size="50" value="'.str_replace('"','&#34;',$row['Title']).'" style="'.$FormStyle.'">
				<br><br>
				<b>'.$MsgText[8][15].'</b><br>
				<input type="text" name="Description" size="50" value="'.str_replace('"','&#34;',$row['Description']).'" style="'.$FormStyle.'">
				<br><br>
				<b>'.$MsgText[8][17].':</b><br>
				<select name="Parent" style="'.$FormStyle.'">'.$CategoryDropdown.'</select>
				<br><br>
				<br><b>'.$MsgText[8][22].':</b> <input type="checkbox" name="DeleteCat" value="y"> '.$MsgText[0][118].'<br>			
				<br><br><br>
				<input type="submit" value="'.$MsgText[0][123].'" style="'.$FormStyle.'">
				
				</form>';
			
			}
			else {
			
				$PageContents = $MsgText[8][23];
			
			}
			
		
		} // end if permissions are sufficient
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}
				
	
	// ========================================================================================




?>
