Location: PHPKode > projects > SiteX > admin/forums_manager.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((!userForumManager())AND(!userAdmin())AND(!userEditor()))  loginError($sxLang['LoginRequired']);
if((userEditor())AND(!$sxSetup['EditorRightsForumsManage']))  loginError($sxLang['LoginRequired']);

if($delete)
{
	$query = "SELECT * FROM $DB_Forums_Groups WHERE id='$delete'";
	$result = mysql_query($query, $Link) or queryError("25", mysql_error());
	$ROW = mysql_fetch_object($result);
	$thisPos = $ROW->position;
	
	$query = "SELECT * FROM $DB_Forums_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_Forums_Groups SET position='$new_position' WHERE id='$ROW->id'";
		$result2 = mysql_query($query2, $Link) or queryError("23", mysql_error());
	}
	$query = "DELETE FROM $DB_Forums_Groups WHERE id='$delete'";
	$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	$message = $sxLang['MessageForumGroupDeleted'];
}

if($deleteForum)
{
	$queryA = "SELECT * FROM $DB_Forums WHERE id='$deleteForum'";
	$resultA = mysql_query($queryA, $Link) or queryError("2080", mysql_error());
	$ROWA = mysql_fetch_object($resultA);
	$sxOldPosition = $ROWA->position;
	$sxOldGroup = $ROWA->groupid;
		
	// Update remaining forum positions
	$queryB = "SELECT * FROM $DB_Forums WHERE groupid='$sxOldGroup' AND position>'$sxOldPosition'";
	$resultB = mysql_query($queryB, $Link) or queryError("2087", mysql_error());
	if(mysql_num_rows($resultB))
	{
		while($ROWB = mysql_fetch_object($resultB))
		{
			$query = "UPDATE $DB_Forums SET position='".($ROWB->position - 1)."' WHERE id='$ROWB->id'";
			$result = mysql_query($query, $Link) or queryError("2088", mysql_error());
		}
	}
	$query = "SELECT * FROM $DB_Forums_Posts WHERE forumid='$deleteForum'";
	$result = mysql_query($query, $Link) or queryError("25", mysql_error());
	while($ROW = mysql_fetch_object($result))
	{
		$query2 = "DELETE FROM $DB_Forums_Unread WHERE postid='$ROW->id'";
		$result2 = mysql_query($query2, $Link) or queryError("23", mysql_error());
		$query2 = "DELETE FROM $DB_Forums_Posts WHERE id='$ROW->id'";
		$result2 = mysql_query($query2, $Link) or queryError("23", mysql_error());
	}
	$query = "DELETE FROM $DB_Forums_Private WHERE forumid='$deleteForum'";
	$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	
	$query = "DELETE FROM $DB_Forums WHERE id='$deleteForum'";
	$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	
	$message = $sxLang['MessageForumDeleted'];
}
if($Submit)
{
	$query = "UPDATE $DB_Forums_Groups SET name='$name' WHERE id='$groupid'";
	$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	$message = $sxLang['MessageForumGroupNameUpdated'];
}
if(($Add)AND(strlen($name2) > 0))
{
	$query = "SELECT * FROM $DB_Forums_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_Forums_Groups (name, position) VALUES ('$name2', '$position')";
	$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	$message = $sxLang['MessageForumGroupAdded'];
}
if($group_upid)
{
	$query = "SELECT * FROM $DB_Forums_Groups WHERE id='$group_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_Forums_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_Forums_Groups SET position='$position2' WHERE id='$group_upid'";
		$result = mysql_query($query, $Link) or queryError("23", mysql_error());
		
		$query = "UPDATE $DB_Forums_Groups SET position='$position1' WHERE id='$changeID'";
		$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	}
}
if($group_downid)
{
	$query = "SELECT * FROM $DB_Forums_Groups WHERE id='$group_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_Forums_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_Forums_Groups SET position='$position2' WHERE id='$group_downid'";
		$result = mysql_query($query, $Link) or queryError("23", mysql_error());
		
		$query = "UPDATE $DB_Forums_Groups SET position='$position1' WHERE id='$changeID'";
		$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	}
}

if($forum_upid)
{
	$query = "SELECT * FROM $DB_Forums WHERE id='$forum_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_Forums WHERE position='$position2' AND groupid='$ROW->groupid'";
	$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_Forums SET position='$position2' WHERE id='$forum_upid'";
		$result = mysql_query($query, $Link) or queryError("23", mysql_error());
		
		$query = "UPDATE $DB_Forums SET position='$position1' WHERE id='$changeID'";
		$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	}
}
if($forum_downid)
{
	$query = "SELECT * FROM $DB_Forums WHERE id='$forum_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_Forums WHERE position='$position2' AND groupid='$ROW->groupid'";
	$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_Forums SET position='$position2' WHERE id='$forum_downid'";
		$result = mysql_query($query, $Link) or queryError("23", mysql_error());
		
		$query = "UPDATE $DB_Forums SET position='$position1' WHERE id='$changeID'";
		$result = mysql_query($query, $Link) or queryError("23", mysql_error());
	}
}

$sxTitleAddendum = $sxLang['AdminHeading'];
include("../themes/$THEME_FOLDER/header.php");
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function confirmDelete(theID,theName){
	if(confirm("<?PHP echo $sxLang['GeneralJSDeleteEntry4']; ?> '"+theName+"' <?PHP echo $sxLang['GeneralJSDeleteEntry2']; ?>")){
		window.location='<?PHP print $PHP_SELF."?delete="; ?>'+theID;
	}
}
function confirmDeleteForum(theID,theName){
	if(confirm("<?PHP echo $sxLang['ForumJSConfirmDelete1']; ?> '"+theName+"' <?PHP echo $sxLang['ForumJSConfirmDelete2']; ?>")){
		window.location='<?PHP print $PHP_SELF."?deleteForum="; ?>'+theID;
	}
}
//-->
</script>     
  <div class="bodyWrapper">
   <h1 class="sxAdminHeading"><?PHP echo $sxLang['ForumHeadingManager']; ?></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['ForumHeadingManager']; ?></div>   
   <?PHP echoMessage($message); ?>
	<table border="0" cellspacing="2" cellpadding="3" width="<?PHP echo $sxThemeConfig['ContentWidth']-20; ?>">
	<form method="post" action="<?PHP echo $PHP_SELF; ?>" name="sxForumManager">
	<?PHP	
	$query = "SELECT * FROM $DB_Forums_Groups ORDER BY position ASC";
	$result = mysql_query($query, $Link) or queryError("21", mysql_error());
	while($ROW = mysql_fetch_object($result))
	{
		echo '  <tr>';
		
		if($group_editid == $ROW->id)
		{
			echo '<td class="tableColumn" colspan="2">'."\n";
			echo '<input style="width:400px;" type="text" name="name" value="' . $ROW->name . '" />'."\n";
			echo '<input type="hidden" name="groupid" value="' . $ROW->id . '" />'."\n";
			echo '<input type="submit" name="Submit" value="' . $sxLang['ButtonEditName'] . '" class="sxButton" /></td>'."\n";
		}
		else
		{
			echo '     <td class="tableColumn">&nbsp;&nbsp;' . $ROW->name . '</td>'."\n";
			echo '     <td class="tableColumn" style="text-align:right;">'."\n";
			echo '     <a href="' . $PHP_SELF . '?group_editid=' . $ROW->id . '" title="' . $sxLang['ButtonEdit'] . '"><img src="../images/admin_edit.gif" alt="' . $sxLang['ButtonEdit'] . '" style="border: 0;"/></a> ';
			
			$query2 = "SELECT * FROM $DB_Forums WHERE groupid='$ROW->id' ORDER BY position ASC";
			$result2 = mysql_query($query2, $Link) or queryError("71", mysql_error());
			
			if(mysql_num_rows($result2))
				echo '     <a href="#" onclick="javascript:alert(\'' . $sxLang['ForumJSCannotDeleteGroup'] . '\')" title="' . $sxLang['ButtonDelete'] . '"><img src="../images/admin_delete.gif" alt="' . $sxLang['ButtonDelete'] . '" style="border: 0;" /></a> ';
			else
				echo '     <a href="#" onclick="confirmDelete(' . $ROW->id . ',\'' . addslashes( htmlspecialchars($ROW->name)) . '\')" title="' . $sxLang['ButtonDelete'] . '"><img src="../images/admin_delete.gif" style="border: 0;" alt="' . $sxLang['ButtonDelete'] . '" /></a> ';
			
			echo '     <a href="' . $PHP_SELF . '?group_upid=' . $ROW->id . '" title="' . $sxLang['ButtonUp'] . '"><img src="../images/admin_up.gif" style="border: 0;" alt="' . $sxLang['ButtonUp'] . '" /></a> ';
			echo '     <a href="' . $PHP_SELF . '?group_downid=' . $ROW->id . '" title="' . $sxLang['ButtonDown'] . '"><img src="../images/admin_down.gif" style="border: 0;" alt="' . $sxLang['ButtonDown'] . '" /></a></td>';
		}
		
		echo '  </tr>';
		echo '<tr><td colspan="2"><table border="0" cellspacing="1" cellpadding="5" width="' .  ($sxThemeConfig['ContentWidth']-20) . '">';
		
		$query2 = "SELECT * FROM $DB_Forums WHERE groupid='$ROW->id' ORDER BY position ASC";
		$result2 = mysql_query($query2, $Link) or queryError("71", mysql_error());
		while($ROW2 = mysql_fetch_object($result2))
		{
			echo '<tr bgcolor="' . $sxTheme['ColorTableRow'] . '">';
			echo '<td nowrap="nowrap"><strong>&nbsp;&nbsp;&nbsp;' . $ROW2->name . '</strong></td>';
			echo '     <td align="right">';
			echo '     <a href="forums_edit.php?forumid=' . $ROW2->id . '" title="' . $sxLang['ButtonEdit'] . '"><img src="../images/admin_edit.gif" style="border: 0;" alt="' . $sxLang['ButtonEdit'] . '" /></a> ';
			echo '     <a href="#" onclick="confirmDeleteForum(' . $ROW2->id . ',\'' . addslashes( htmlspecialchars($ROW2->name)) . '\')" title="' . $sxLang['ButtonDelete'] . '"><img src="../images/admin_delete.gif" style="border: 0;" alt="' . $sxLang['ButtonDelete'] . '" /></a> ';
			echo '     <a href="' . $PHP_SELF . '?forum_upid=' . $ROW2->id . '" title="' . $sxLang['ButtonUp'] . '"><img src="../images/admin_up.gif" style="border: 0;" alt="' . $sxLang['ButtonUp'] . '" /></a> ';
			echo '     <a href="' . $PHP_SELF . '?forum_downid=' . $ROW2->id . '" title="' . $sxLang['ButtonDown'] . '"><img src="../images/admin_down.gif" style="border: 0;" alt="' . $sxLang['ButtonDown'] . '" /></a></td>';
			echo '</tr>';
		}
		echo '</table></td></tr>';
	}
	if(mysql_num_rows($result) == 0)
		echo '<tr bgcolor="' . $sxTheme['ColorTableRow'] . '"><td colspan="3"><em>' . $sxLang['NoGroups'] . '</em></td></tr>';

	?></form></table>
	<form name="sxFormAddGroup" method="post" action="<?PHP echo $PHP_SELF; ?>">
	  <input name="name2" type="text" id="name2" size="35" maxlength="255" />
	  <input name="Add" type="submit" id="Add" value="<?PHP echo $sxLang['ForumButtonAddGroup']; ?>" class="sxButton" />
	</form>
  </div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX