<?

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



	// ========================================================================================
	
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_ecom.gif" width="20" height="21" align="middle"> '.$MsgText[9][13];
	$BrowserTitle = $MsgText[9][13];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL.'/admin/store-categories.html">'.$MsgText[9][2].'</a> > '.$MsgText[9][13];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[901] == 'y') {
		
			
			$query = "select * from `".$Settings['DBPrefix']."ec-Categories` 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']."ec-Categories` where RecordNumber='".intval($Arguments3)."' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			$row = mysql_fetch_array($result);

			$CurrentCategory = $row['Parent'];

			$ThisCategoryID = $row['RecordNumber'];

			
			

			$CatParent5 = 0;
			$LastParentAbove5 = '0';
			$CatLevel5['0'] = 0;
									
			function SpiderCategories5($CatParent5) {
							
				Global $CategoryIDsArray, $CategoryNamesArray, $CategoryDropdown, $LastParent5, $LastParentAbove5, $CatSpacersArray5, $CatLevel5, $CatsCount5, $CurrentCategory, $MainURL, $CategoriesPrint, $ThisCategoryID;
							
				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;&nbsp;&nbsp;&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;&nbsp;&nbsp;&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;';
							}
						}
						
							
						$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;&nbsp;';
							$ResetAfter5 = 'n';
						}
													
					}
					
					
					
					$CategoryID = $CategoryIDsArray[$CatParent5][$i];
				
					if ($CategoryID != $ThisCategoryID) {					
						if ($CategoryIDsArray[$CatParent5][$i] == $CurrentCategory) {
							$CategoryDropdown .= '<option value="'.$CategoryID.'"'.$ElementStyle.' selected> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].$AsteriskAdded.'</option>';
						}
						else {
							$CategoryDropdown .= '<option value="'.$CategoryID.'"'.$ElementStyle.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].$AsteriskAdded.'</option>';
						}
					}
								
												
					
					if (count($CategoryIDsArray[$CategoryIDsArray[$CatParent5][$i]]) > 0) {
						SpiderCategories5($CategoryIDsArray[$CatParent5][$i]);
					}
							
				}
							
							
			}
			
			SpiderCategories5('0');


			$PageContents .= '<br><b>'.$MsgText[9][13].':</b><br><br><form action="'.$MainURL.'/admin/store-categories_edit_save" method="post"><input type="hidden" name="CategoryIDToEdit" value="'.$Arguments3.'"><b>'.$MsgText[9][7].':</b> ('.$MsgText[0][418].')<br><input type="text" name="CategoryID" size="25" style="'.$FormStyle.'" value="'.$row['CategoryID'].'"><br><font size="1">('.$MsgText[9][8].')</font><br><br><b>'.$MsgText[9][9].':</b><br><input type="text" name="CategoryName" size="40" style="'.$FormStyle.'" value="'.str_replace('"','&#34;',$row['Name']).'"><br><br><b>'.$MsgText[9][10].':</b> ('.$MsgText[0][418].')<br><input type="text" name="CategoryDescription" size="60" style="'.$FormStyle.'" value="'.str_replace('"','&#34;',$row['Description']).'"><br><br><b>'.$MsgText[9][11].':</b><br><select name="CategoryParent" style="'.$FormStyle.'"><option value="0">'.$MsgText[0][248].'</option>'.$CategoryDropdown.'</select><br><br><br><input type="checkbox" name="DeleteCategory" value="yes"> '.$MsgText[9][14].'<br><br><br><input type="submit" value="'.$MsgText[0][123].'" style="'.$FormStyle.'"></form>';
		
		
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
