<?

/*
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 link
	// ========================================================================================
	
	
	$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][24];
	$BrowserTitle = $MsgText[8][24];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL.'/admin/links.html">'.$MsgText[8][2].'</a> > '.$MsgText[8][24];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[801] == 'y') {
		
			$Arguments3 = intval($Arguments3);
		
			if ($Arguments3 > 0) {
		
				$query = "select * from `".$Settings['DBPrefix']."lm-Links` where RecordNumber='".$Arguments3."' limit 1";
				$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				
				
				$CurrentCategoryID = $row['Category'];
				$CurrentCategoryID2 = $row['Category2'];
				$CurrentCategoryID3 = $row['Category3'];
				$CurrentCategoryID4 = $row['Category4'];
				$CurrentCategoryID5 = $row['Category5'];
				$CurrentCategoryID6 = $row['Category6'];
				$CurrentCategoryID7 = $row['Category7'];
				$CurrentCategoryID8 = $row['Category8'];
				$CurrentCategoryID9 = $row['Category9'];
				$CurrentCategoryID10 = $row['Category10'];
				
						
				$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>';
				$CategoryDropdown2 = '<option value="0"></option><option value="0"> '.$MsgText[0][248].'</option>';
				$CategoryDropdown3 = '<option value="0"></option><option value="0"> '.$MsgText[0][248].'</option>';
				$CategoryDropdown4 = '<option value="0"></option><option value="0"> '.$MsgText[0][248].'</option>';
				$CategoryDropdown5 = '<option value="0"></option><option value="0"> '.$MsgText[0][248].'</option>';
				$CategoryDropdown6 = '<option value="0"></option><option value="0"> '.$MsgText[0][248].'</option>';
				$CategoryDropdown7 = '<option value="0"></option><option value="0"> '.$MsgText[0][248].'</option>';
				$CategoryDropdown8 = '<option value="0"></option><option value="0"> '.$MsgText[0][248].'</option>';
				$CategoryDropdown9 = '<option value="0"></option><option value="0"> '.$MsgText[0][248].'</option>';
				$CategoryDropdown10 = '<option value="0"></option><option value="0"> '.$MsgText[0][248].'</option>';
				
				
			
			$CatParent5 = 0;
			$LastParentAbove5 = '0';
			$CatLevel5['0'] = 0;
						
			function SpiderCategories5($CatParent5) {
				
				Global $CurrentCategoryID, $CurrentCategoryID2, $CurrentCategoryID3, $CurrentCategoryID4, $CurrentCategoryID5, $CurrentCategoryID6, $CurrentCategoryID7, $CurrentCategoryID8, $CurrentCategoryID9, $CurrentCategoryID10, $CategoryIDsArray, $CategoryNamesArray, $CategoryDropdown, $CategoryDropdown2, $CategoryDropdown3, $CategoryDropdown4, $CategoryDropdown5, $CategoryDropdown6, $CategoryDropdown7, $CategoryDropdown8, $CategoryDropdown9, $CategoryDropdown10, $LastParent5, $LastParentAbove5, $CatSpacersArray5, $CatLevel5, $CatsCount5;
				
				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;\'------';
							$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 ($CurrentCategoryID2 == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown2 .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';




					if ($CurrentCategoryID3 == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown3 .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';




					if ($CurrentCategoryID4 == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown4 .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';




					if ($CurrentCategoryID5 == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown5 .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';




					if ($CurrentCategoryID6 == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown6 .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';




					if ($CurrentCategoryID7 == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown7 .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';




					if ($CurrentCategoryID8 == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown8 .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';




					if ($CurrentCategoryID9 == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown9 .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';




					if ($CurrentCategoryID10 == $CategoryIDsArray[$CatParent5][$i]) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$CategoryDropdown10 .= '<option value="'.$CategoryIDsArray[$CatParent5][$i].'"'.$Selected.'> '.$CatSpacer5.' '.$CategoryNamesArray[$CatParent5][$i].'</option>';

					
										
					if (count($CategoryIDsArray[$CatParent5][$i]) > 0) {
						SpiderCategories5($CategoryIDsArray[$CatParent5][$i]);
					}
				
				
				} // end loop
				
				
			}
			
			SpiderCategories5('0');
			
			
				$PageContents .= '<br><br><form action="'.$MainURL.'/admin/links-edit-save" method="post">
				<input type="hidden" name="LinkIDToEdit" 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][14].':</b><br>
				<input type="text" name="Link" size="50" value="'.str_replace('"','&#34;',$row['Link']).'" 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][10].':</b><br>
				<input type="text" name="StartingCount" size="10" value="'.$row['ClicksCount'].'" style="'.$FormStyle.'">
				<br><br>
				<b>'.$MsgText[8][17].':</b><br>
				<select name="Category" style="'.$FormStyle.'">'.$CategoryDropdown.'</select><br>
				<select name="Category2" style="'.$FormStyle.'">'.$CategoryDropdown2.'</select><br>
				<select name="Category3" style="'.$FormStyle.'">'.$CategoryDropdown3.'</select><br>
				<select name="Category4" style="'.$FormStyle.'">'.$CategoryDropdown4.'</select><br>
				<select name="Category5" style="'.$FormStyle.'">'.$CategoryDropdown5.'</select><br>
				<select name="Category6" style="'.$FormStyle.'">'.$CategoryDropdown6.'</select><br>
				<select name="Category7" style="'.$FormStyle.'">'.$CategoryDropdown7.'</select><br>
				<select name="Category8" style="'.$FormStyle.'">'.$CategoryDropdown8.'</select><br>
				<select name="Category9" style="'.$FormStyle.'">'.$CategoryDropdown9.'</select><br>
				<select name="Category10" style="'.$FormStyle.'">'.$CategoryDropdown10.'</select>
				<br><br>
				<br><b>'.$MsgText[8][26].':</b> <input type="checkbox" name="DeleteLink" value="y"> '.$MsgText[0][118].'<br>			
				<br><br><br>
				<input type="submit" value="'.$MsgText[0][123].'" style="'.$FormStyle.'">
				
				</form>';
			
			}
			else {
			
				$PageContents = $MsgText[8][25];
			
			}
			
		
		} // end if permissions are sufficient
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

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




?>
