Location: PHPKode > projects > SiteX > admin/components.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(!userAdmin()) loginError($sxLang['LoginRequired']);

if($EditName_x)
{
	// Update navigation item if name is still the same as component name
	$sxQuery = "SELECT $DB_Components_Rename.new_name, $DB_Navigation.id
	              FROM $DB_Components_Rename, $DB_Navigation
				  WHERE $DB_Components_Rename.compid='$compid' AND
				        $DB_Navigation.name=$DB_Components_Rename.new_name";
	$sxResult = mysql_query($sxQuery, $Link) or queryError("6001", mysql_error());
	if(mysql_num_rows($sxResult) > 0)
	{
		$sxROW = mysql_fetch_object($sxResult);
		$sxQueryUpdate = "UPDATE $DB_Navigation SET name='$new_name' WHERE id='$sxROW->id'";
		$sxResultUpdate = mysql_query($sxQueryUpdate, $Link) or queryError("6003", mysql_error());
	}
	
	// Rename component
	$query2 = "UPDATE $DB_Components_Rename SET new_name='$new_name' WHERE compid='$compid'";
	$result2 = mysql_query($query2, $Link) or queryError("55", mysql_error());	
	
	$message = $sxLang['MessageComponentRenamed'];
}

if($activate)
{
	$query = "UPDATE $DB_Components SET  active='1' WHERE id='$activate'";
	$result = mysql_query($query, $Link) or queryError("55", mysql_error());
	
	$query = "SELECT * FROM $DB_Navigation 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 = "SELECT * FROM $DB_Components, $DB_Components_Rename
			          WHERE $DB_Components.id=$DB_Components_Rename.compid AND
					        $DB_Components.id='$activate'";
	$result = mysql_query($query, $Link) or queryError("22", mysql_error());
	$ROW = mysql_fetch_object($result);
	
	$query = "INSERT INTO $DB_Navigation (name, url, position) VALUES ('$ROW->new_name', '$ROW->page_url', '$position')";
	$result = mysql_query($query, $Link);
	
	$message = $sxLang['MessageComponentActivated'];
}

if($deactivate)
{
	$query = "UPDATE $DB_Components SET active='0' WHERE id='$deactivate'";
	$result = mysql_query($query, $Link) or queryError("55", mysql_error());
	
	$query = "SELECT * FROM $DB_Components WHERE id='$deactivate'";
	$result = mysql_query($query, $Link) or queryError("21", mysql_error());
	$ROW = mysql_fetch_object($result);
	
	$query2 = "SELECT * FROM $DB_Navigation WHERE url='$ROW->page_url'";
	$result2 = mysql_query($query2, $Link) or queryError("21", mysql_error());
	if(mysql_num_rows($result2))
	{
		while($ROW2 = mysql_fetch_object($result2))
		{
			$thisPos = $ROW2->position;
			
			$query4 = "SELECT * FROM $DB_Navigation WHERE position>'$thisPos'";
			$result4 = mysql_query($query4, $Link) or queryError("26", mysql_error());
			while($ROW4 = mysql_fetch_object($result4))
			{
				$new_position = $ROW4->position - 1;
				$query5 = "UPDATE $DB_Navigation SET position='$new_position' WHERE id='$ROW4->id'";
				$result5 = mysql_query($query5, $Link);
			}
			$query4 = "DELETE FROM $DB_Navigation WHERE id='$ROW2->id'";
			$result4 = mysql_query($query4, $Link);
		}
	}
	$message = $sxLang['MessageComponentDeactivated'];
}

$sxTitleAddendum = $sxLang['AdminHeading'];
include("../themes/$THEME_FOLDER/header.php");
?>   
<div class="bodyWrapper">
   <h1 class="sxAdminHeading"><?PHP echo $sxLang['ComponentsHeading']; ?></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 $sxLang['ComponentsHeading']; ?></div>   
	<?PHP echoMessage($message); ?>
	<table border="0" cellspacing="2" cellpadding="5">
	  <tr>
		<td class="tableColumn"><?PHP echo $sxLang['ComponentsTableActivated']; ?></td>
		<td class="tableColumn"><?PHP echo $sxLang['ComponentsTableComponent']; ?></td>
		<td class="tableColumn"><?PHP echo $sxLang['ComponentsTableRename']; ?></td>
	  </tr>
	<?PHP
	$query = "SELECT * FROM $DB_Components, $DB_Components_Rename WHERE $DB_Components.id=$DB_Components_Rename.compid ORDER BY $DB_Components.name ASC";
	$result = mysql_query($query, $Link) or queryError("21", mysql_error());
	while($ROW = mysql_fetch_object($result)){
		echo ' <form name="form1" method="post" action="' . $PHP_SELF . '"><tr>';
		if($ROW->active) echo '     <td bgcolor="' . $sxTheme['ColorTableRow'] . '"><a href="' . "$PHP_SELF?deactivate=$ROW->compid" . '"><img alt="' . $sxLang['ImgAltDeactivate'] . '" src="../images/check.gif" style="border: 0;" /></a></td>';
		else echo '     <td bgcolor="' . $sxTheme['ColorTableRow'] . '"><a href="' . "$PHP_SELF?activate=$ROW->compid" . '"><img alt="' . $sxLang['ImgAltActivate'] . '" src="../images/x.gif" style="border: 0;" /></a></td>';
		echo '     <td bgcolor="' . $sxTheme['ColorTableRow'] . '">' .  htmlspecialchars($ROW->name) . '</td>';
		echo '     <td bgcolor="' . $sxTheme['ColorTableRow'] . '">';
		echo '       <input name="new_name" type="text" maxlength="255" value="' . $ROW->new_name . '" />';
		echo '       <input name="compid" type="hidden" value="' . $ROW->compid . '" />';
		echo '       <input name="EditName" type="image" value="' . $sxLang['ComponentsButtonEdit'] . '" alt="' . $sxLang['ComponentsButtonEdit'] . '"  src="../images/admin_edit.gif" /> </td>';
		echo '  </tr></form>';
	}
	?></table>
</div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX