Location: PHPKode > projects > SiteX > admin/links.php
<?PHP
ob_start();
session_start();
include("../includes/globals.php.inc");
include("../includes/functions.php");
include("../lang/English.php");
if(strtolower($sxSetup['Language']) != 'english') include("../lang/".$sxSetup['Language'].".php");
include("../themes/$THEME_FOLDER/config.php.inc");
if((!userEditor())AND(!userAdmin()))  loginError($sxLang['LoginRequired']);
if((userEditor())AND(!$sxSetup['EditorRightsLinksEdit']))  loginError($sxLang['LoginRequired']);

if($deleteCat)
{
	$query = "SELECT * FROM $DB_Links_Groups WHERE id='$deleteCat'";
	$result = mysql_query($query, $Link) or queryError("25", mysql_error());
	$ROW = mysql_fetch_object($result);
	$thisPos = $ROW->position;
	
	$query = "SELECT * FROM $DB_Links_Groups WHERE position>'$thisPos'";
	$result = mysql_query($query, $Link) or queryError("26", mysql_error());
	while($ROW = mysql_fetch_object($result))
	{
		if($ROW->position > 1)
			$new_position = $ROW->position-1;
		else
			$new_position = $ROW->position;
		$query2 = "UPDATE $DB_Links_Groups SET position='$new_position' WHERE id='$ROW->id'";
		$result2 = mysql_query($query2, $Link) or queryError("22", mysql_error());
	}
	
	$query = "DELETE FROM $DB_Links_Groups WHERE id='$deleteCat'";
	$result = mysql_query($query, $Link) or queryError("22", mysql_error());
	
	$query = "SELECT * FROM $DB_Links WHERE groupid='$deleteCat'";
	$result = mysql_query($query, $Link) or queryError("3456", mysql_error());
	while($ROW = mysql_fetch_object($result))
	{
		$query2 = "DELETE FROM $DB_Links WHERE id='$ROW->id'";
		$result2 = mysql_query($query2, $Link) or queryError("709", mysql_error());
	}
	$message = $sxLang['MessageLinkCategoryDeleted'];
}
if($deleteLink)
{
	$query = "DELETE FROM $DB_Links WHERE id='$deleteLink'";
	$result = mysql_query($query, $Link) or queryError("702", mysql_error());
	$message = $sxLang['MessageLinkDeleted'];
}
if($Submit_x)
{
	$query = "UPDATE $DB_Links_Groups SET name='$name' WHERE id='$catid'";
	$result = mysql_query($query, $Link) or queryError("22", mysql_error());
	$message = $sxLang['MessageLinkCategoryUpdated'];
}
if($sxNewCategoryName)
{
	$query = "SELECT * FROM $DB_Links_Groups ORDER BY position DESC LIMIT 0,1";
	$result = mysql_query($query, $Link) or queryError("22", mysql_error());
	$ROW = mysql_fetch_object($result);
	
	$position = $ROW->position + 1;
	
	$query = "INSERT INTO $DB_Links_Groups (name, position) VALUES ('".$sxNewCategoryName."', '$position')";
	$result = mysql_query($query, $Link) or queryError("22", mysql_error());
	$message = $sxLang['MessageLinkCategoryAdded'];
}
if($upid)
{
	$query = "SELECT * FROM $DB_Links_Groups WHERE id='$upid'";
	$result = mysql_query($query, $Link) or queryError("22", mysql_error());
	$ROW = mysql_fetch_object($result);
	
	$position1 = $ROW->position;
	$position2 = $position1 - 1;
	
	$query = "SELECT * FROM $DB_Links_Groups WHERE position='$position2'";
	$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	
	if(mysql_num_rows($result))
	{
		$ROW = mysql_fetch_object($result);
	
		$changeID = $ROW->id;
		
		$query = "UPDATE $DB_Links_Groups SET position='$position2' WHERE id='$upid'";
		$result = mysql_query($query, $Link) or queryError("22", mysql_error());
		
		$query = "UPDATE $DB_Links_Groups SET position='$position1' WHERE id='$changeID'";
		$result = mysql_query($query, $Link) or queryError("22", mysql_error());
	}
}
if($downid)
{
	$query = "SELECT * FROM $DB_Links_Groups WHERE id='$downid'";
	$result = mysql_query($query, $Link) or queryError("22", mysql_error());
	$ROW = mysql_fetch_object($result);
	
	$position1 = $ROW->position;
	$position2 = $position1 + 1;
	
	$query = "SELECT * FROM $DB_Links_Groups WHERE position='$position2'";
	$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	
	if(mysql_num_rows($result))
	{
		$ROW = mysql_fetch_object($result);
		$changeID = $ROW->id;
		
		$query = "UPDATE $DB_Links_Groups SET position='$position2' WHERE id='$downid'";
		$result = mysql_query($query, $Link) or queryError("22", mysql_error());
		
		$query = "UPDATE $DB_Links_Groups SET position='$position1' WHERE id='$changeID'";
		$result = mysql_query($query, $Link) or queryError("22", mysql_error());
	}
}

$sxTitleAddendum = $sxLang['AdminHeading'];
include("../themes/$THEME_FOLDER/header.php");
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function confirmDeleteCat(theID,theName){
	if(confirm("<?PHP echo $sxLang['GeneralJSDeleteEntry3']; ?> '"+theName+"' <?PHP echo $sxLang['GeneralJSDeleteEntry2']; ?>")){
		window.location='<?PHP print $PHP_SELF."?sxViewCat=$sxViewCat&deleteCat="; ?>'+theID;
	}
}
function confirmDeleteLink(theID,theName){
	if(confirm("<?PHP echo $sxLang['GeneralJSDeleteEntry3']; ?> '"+theName+"' <?PHP echo $sxLang['GeneralJSDeleteEntry2']; ?>")){
		window.location='<?PHP print $PHP_SELF."?sxViewCat=$sxViewCat&deleteLink="; ?>'+theID;
	}
}
//-->
</script>     
<div class="bodyWrapper">
   <h1 class="sxAdminHeading"><?PHP echo getComponentName("5").' '.$sxLang['GeneralHeadingManager']; ?></h1>
   <div class="sxAdminBreadcrumbs"><?PHP if(userAdmin()) { ?><a href="index.php"><?PHP echo $sxLang['AdminBreadcrumb']; ?><?PHP }?><?PHP if(userEditor()) { ?><a href="editor_index.php"><?PHP echo $sxLang['EditorBreadcrumb']; ?><?PHP }?></a> > <?PHP echo getComponentName("5").' '.$sxLang['GeneralHeadingManager']; ?></div>   
   <?PHP echoMessage($message); ?>
	<table border="0" cellspacing="2" cellpadding="5">
	<?PHP if((userAdmin())OR($sxSetup['EditorRightsLinksAdd'])) { ?>
	  <tr>
	    <td colspan="3" align="right">   	
		<input name="AddLink" type="button" value="<?PHP echo $sxLang['AdminLinkLinkAdd']; ?>" onclick="window.location='links_add.php'" />
	    </td>
	  </tr>
	 <?PHP } ?>
	  <tr>
		<td class="tableColumn">&nbsp;</td>
		<td class="tableColumn"><?PHP echo $sxLang['GeneralItemCategory']; ?></td>
		<td class="tableColumn"><?PHP echo $sxLang['GeneralItemOptions']; ?></td>
	  </tr><form name="sxFormLinksCategoryManage" method="post" action="<?PHP echo $PHP_SELF; ?>">
		<?PHP	
		$query = "SELECT * FROM $DB_Links_Groups ORDER BY position ASC";
		$result = mysql_query($query, $Link) or queryError("21", mysql_error());
		while($ROW = mysql_fetch_object($result))
		{
			$query2 = "SELECT * FROM $DB_Links WHERE groupid='$ROW->id'";
			$result2 = mysql_query($query2, $Link) or queryError("21", mysql_error());
			$sxNumLinks = mysql_num_rows($result2);
				
			if(intval($sxViewCat) == $ROW->id)
			{
				$sxFolderImage = "folder_open.gif";
				$sxFolderLinkVar = "sxCloseCat";
				$sxFolderOpened = true;
			}
			else
			{
				$sxFolderImage = "folder_closed.gif";
				$sxFolderLinkVar = "sxViewCat";
				$sxFolderOpened = false;
			}
			
			echo '  <tr bgcolor="' . $sxTheme['ColorTableRow'] . '">'."\n";
			echo '     <td><a href="' . $_SERVER['PHP_SELF'] . '?' . $sxFolderLinkVar . '=' . $ROW->id . '"><img src="../images/' . $sxFolderImage . '" style="border: 0;" /></a>';
			echo '</td>'."\n";
			
			if($editid == $ROW->id)
			{
				echo '<td colspan="2">'."\n";
				echo '<input style="width:200px;" type="text" name="name" value="' .  htmlspecialchars($ROW->name) . '" />'."\n";
				echo '<input type="hidden" name="catid" value="' . $ROW->id . '" />'."\n";
				echo '<input type="image" name="Submit" src="../images/admin_edit.gif" value="' . $sxLang['ButtonEdit'] . '" alt="' . $sxLang['ButtonEdit'] . '" /></td>'."\n";
			}
			else
			{
				echo '     <td>' . $ROW->name . ' (' . $sxNumLinks . ')</td>';
				echo '     <td>';
				echo '     <a href="' . $_SERVER['PHP_SELF'] . '?editid=' . $ROW->id . '" title="' . $sxLang['ButtonEdit'] . '"><img alt="' . $sxLang['ButtonEdit'] . '" src="../images/admin_edit.gif" style="border: 0;" /></a>';
				echo '     <a href="#" onclick="confirmDeleteCat(' . $ROW->id . ',\'' .  htmlspecialchars(addslashes($ROW->name)) . '\')" title="' . $sxLang['ButtonDelete'] . '"><img alt="' . $sxLang['ButtonDelete'] . '" src="../images/admin_delete.gif" style="border: 0;" /></a>';
				echo '     <a href="' . $_SERVER['PHP_SELF'] . '?upid=' . $ROW->id . '" title="' . $sxLang['ButtonUp'] . '"><img alt="' . $sxLang['ButtonUp'] . '" src="../images/admin_up.gif" style="border: 0;" /></a>';
				echo '     <a href="' . $_SERVER['PHP_SELF'] . '?downid=' . $ROW->id . '" title="' . $sxLang['ButtonDown'] . '"><img alt="' . $sxLang['ButtonDown'] . '" src="../images/admin_down.gif" style="border: 0;" /></a>';
			}
			echo '  </tr>';
			
			// Print out folder contents (links in that category)
			if($sxFolderOpened == true)
			{
				$query2 = "SELECT * FROM $DB_Links WHERE groupid='$ROW->id' ORDER BY name ASC";
				$result2 = mysql_query($query2, $Link) or queryError("21", mysql_error());
				while($ROW2 = mysql_fetch_object($result2))
				{
					echo '  <tr bgcolor="' . incrementHexNumber($sxTheme['ColorTableRow']) . '">'."\n";
					echo '     <td>&nbsp;</td>'."\n";
					echo '     <td><a href="links_edit.php?linkid=' . $ROW2->id . '">' . $ROW2->name . '</a></td>';
					echo '     <td>';
					echo '     <a href="links_edit.php?linkid=' . $ROW2->id . '" title="' . $sxLang['ButtonEdit'] . '"><img alt="' . $sxLang['ButtonEdit'] . '" src="../images/admin_edit.gif" style="border: 0;" /></a>';
					echo '     <a href="#" onclick="confirmDeleteLink(' . $ROW2->id . ',\'' .  htmlspecialchars(addslashes($ROW2->name)) . '\')" title="' . $sxLang['ButtonDelete'] . '"><img alt="' . $sxLang['ButtonDelete'] . '" src="../images/admin_delete.gif" style="border: 0;" /></a>';
					echo '  </tr>';				
				}
				if(mysql_num_rows($result2) == 0)
				{
					echo '  <tr bgcolor="' . incrementHexNumber($sxTheme['ColorTableRow']) . '">'."\n";
					echo '     <td>&nbsp;</td>'."\n";
					echo '     <td colspan="2">' . $sxLang['NoLinks'] . ' <a href="links_add.php?sxCat=' . $ROW->id . '">' . $sxLang['AdminLinkLinkAdd'] . '</a></td>';
					echo '  </tr>';				
				}				
			}
		}
		if(mysql_num_rows($result) == 0)
			echo '<tr bgcolor="' . $sxTheme['ColorTableRow'] . '"><td colspan="3"><em>' . $sxLang['NoCategories'] . '</em></td></tr>';
	
		?></form></table>
		<?PHP if((userAdmin())OR($sxSetup['EditorRightsLinksAdd'])) { ?>
	<form name="sxFormLinksCategoryAdd" method="post" action="<?PHP echo $PHP_SELF; ?>">
	  <input name="sxNewCategoryName" type="text" size="35" maxlength="255" />
	  <input name="Add" type="submit" value="<?PHP echo $sxLang['LinksButtonAddCategory']; ?>" class="sxButton" />
	</form>
	<?PHP } ?>
  </div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX