Location: PHPKode > projects > ArticleSetup > ArticleSetup-v1-1/upload/rightsidebar.php
<?php 

// Create the right sidebar template
	$rightsidebar = new Template("templates/".$template."/rightsidebar.tpl");


// Print out the 250 x 300 code
	$query = "select * from adboxes where id=1;"; 
	$result = mysql_query($query,$connection) or die(mysql_error());
	$info = mysql_fetch_assoc($result);

	$rightsidebar->set("250adcode", stripslashes($info['adcode']));
	
// determine if this is category.php, article.php, or other
	$currentfile = $_SERVER["SCRIPT_NAME"];
    $parts = Explode('/', $currentfile);
    $currentfile = $parts[count($parts) - 1];
    
    if ($currentfile == "category.php") {
    
		$rightsidebar->set("righttitle", "Most Viewed - ".$cattitle."");
		$catquery = "select * from categories where id =".$_GET['id'];
		$query = "select title, views, id from articles, articleviews 
		where articleviews.articleid = articles.id and status=0 
		and (categoryid = ".$_GET['id']." OR parentid = ".$_GET['id'].") 
		order by articleviews.views desc LIMIT 0, 12;";

// Otherwise, display articles from all categories						
	} else {
		$rightsidebar->set("righttitle", "Most Viewed - All Categories");
		$catquery = "select * from categories";
		$query = "select title, views, id from articles, articleviews 
		where articleviews.articleid = articles.id and status=0 
		order by articleviews.views desc LIMIT 0, 12;";
	}


	$catresult = mysql_query($catquery,$connection) or die(mysql_error());
	$catinfo = mysql_fetch_array($catresult);
	$cattitle = $catinfo['name'];
			
	$articleresults = mysql_query($query,$connection) or die(mysql_error());
	$num_results = mysql_num_rows($articleresults);
	
	
//	If this category is empty...
	if ($num_results == 0) {
		$rightsidebar->set("rightarticles", "No Articles Found!");
	} else {

		for ($i=0; $i <$num_results; $i++) { 
			$row = mysql_fetch_assoc($articleresults); 
	
			//Get article info	
			$id = $row['id'];
			$title = $row['title'];
			if ($seourls == 1) {  $scrubtitle = generate_seo_link($title); }

			// Display the article list
			if ($seourls == 1) { // With SEO URLS 
				$rightlist = "<li><a href=\"".$siteurl."/".$id."/".$scrubtitle."/\">".$title."</a></li>";
				$rightoutput .= $rightlist; 
			} else {
				$rightlist = "<li><a href=\"".$siteurl."/article.php?id=".$id."\">".$title."</a></li>";
				$rightoutput .= $rightlist; 
			}
			$rightsidebar->set("rightarticles", $rightoutput);
		}
	}


/* OPTIONAL SIDBAR FEATURES FOR TEMPLATES TAHT ONLY USE A RIGHT SIDEBAR */

// Check if  user is logged in. If so, display custom menu
	session_start();
	if (isset($_SESSION['valid_user'])) { 
		$username = $_SESSION['valid_user'];
		$rightsidebar->set("authormenu", '
		<h3>Welcome, '.$username.':</h3>
		<div class="author-list">
		<ul>
			<li><a href="'.$siteurl.'/author/index.php">Dashboard Home</a></li>
			<li><a href="'.$siteurl.'/author/submit.php">Submit an Article</a></li>
			<li><a href="'.$siteurl.'/author/articles.php">View & Edit Articles</a></li>
			<li><a href="'.$siteurl.'/author/profile.php">Update Your Profile</a></li>
			<li><a href="'.$siteurl.'/author/settings.php">Account Settings</a></li>
			<li><a href="'.$siteurl.'/author/logout.php">Logout</a></li>
		</ul>
		<br style="clear:left"/>
		</div>
		<br/>');
	} else {
		$rightsidebar->set("authormenu", '<h2>Already a Member?</h3>
			<form method="post" action="'.$siteurl.'/login.php">
	<table>
	<tr><td style="width:100px;">Username:</td>
	<td><input type="text" name="userid" style="width:90px;"></td></tr>
	<tr><td>Password:</td>
	<td><input type="password" name="password" style="width:90px;"></td></tr>
	<tr><td>Remember Me:</td>
	<td><input type="checkbox" name="remember"></td></tr>
	<tr><td colspan="2" align="center">
	<input type="submit" id="submitstyle" value="Log in"></td></tr>
	</table></form>
		<br/> 
		<center><a href="'.$siteurl.'/login.php">Signup to submit articles &raquo;</a></center>');

	}


// Print the 120 x XXX sidebar code
	$query = "select * from adboxes where id=3;"; 
	$result = mysql_query($query,$connection) or die(mysql_error());
	$info = mysql_fetch_assoc($result);

	$rightsidebar->set("120adcode", stripslashes($info['adcode'])); 



// Populates the sidebar with all categories 
	$rightlistquery = "select * from categories where parentid is null order by name;"; 
	$rightlistresult = mysql_query($rightlistquery,$connection) or die(mysql_error());
	$right_num_results = mysql_num_rows($rightlistresult);
		
	for ($i=0; $i <$right_num_results; $i++) { 
		$row = mysql_fetch_assoc($rightlistresult);
		if ($seourls == 1) { $scrubcatname = generate_seo_link($row['name']); }
		
		if ($seourls == 1) { // With SEO URLS 
			$rightcatlist = "<li><a href=\"".$siteurl."/category/".$row['id']."/".$scrubcatname."/\">
			".$row['name']."</a></li>"; 
			$rightcatoutput .= $rightcatlist;
		} else {
			$rightcatlist = "<li><a href=\"".$siteurl."/category.php?id=".$row['id']."\">".$row['name']."</a></li>";
			$rightcatoutput .= $rightcatlist;
		}
		$rightsidebar->set("sidecats", $rightcatoutput); 
	}

	
// Populates the sidebar with all pages
	$query = "select * from pages;"; 
	$result = mysql_query($query,$connection) or die(mysql_error());
	$num_results = mysql_num_rows($result);
	
	if (!$num_results) {
		$rightsidebar->set("sidepages", "");
	} else {

		for ($i=0; $i <$num_results; $i++) { 
			$row = mysql_fetch_assoc($result); 
		
			if ($seourls == 1) { $scrubtitle = generate_seo_link($row['title']); }
		
			if ($seourls == 1) { // With SEO URLS 
				$rightpagelist = "<li><a href=\"".$siteurl."/page/".$row['id']."/".$scrubtitle."/\">
				".$row['title']."</a></li>";
				$rightpageoutput .= $rightpagelist; 
			} else {
				$rightpagelist = "<li><a href=\"".$siteurl."/page.php?p=".$row['id']."\">".$row['title']."</a></li>";
				$rightpageoutput .= $rightpagelist; 
			}
			$rightsidebar->set("sidepages", $rightpageoutput); 
		}
	}

	$rightsidebar->set("siteurl", $siteurl); 
	
	
// Outputs the right sidebar template!
	 
	echo $rightsidebar->output();

?>
Return current item: ArticleSetup