Location: PHPKode > projects > eBlog > sections.php
<?php

/**************************************************************************
 *                                                                        *
 *                                                                        *
 *         Solution: eBlog                                                *
 *          Release: 1.7                                                  *
 *             File: sections.php                                         *
 *               By: Emuci inc.                                           *
 *          Website: http://www.emuci.com                                 *
 *        Copyright: (C) 2010 Emcui inc.                                  *
 *                                                                        *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *                                                                        *
 *   This script is NOT freeware and is subjected to Emuci terms of use   *
 *   located in the docs folder.                                          *
 *                                                                        *
 *                                                                        *
 *************************************************************************/



include_once 'includes/global.php';



	$action = $_GET['action'];
	$id = $_GET['id'];
	$spoint = $_GET['spoint'];	

	
	if(($action == "show")&&(!empty($id))){
	
		$conn = mysql_connect($dbhost, $dbuser, $dbpass);
		mysql_select_db($dbname);
			
			
		$defaultTemplate = $template;
		$copyrights = "&copy; " . date("Y") . " " . $lang_admin_globalRights1;
	
		if(empty($spoint))
		{
			$spoint = 0;
		}
		
		
		if($sort_by == 1)
		$sortBy = "title";
		if($sort_by == 2)
		$sortBy = "id";
		if($sort_by == 3)
		$sortBy = "allviewers";
		
		if($sort_order == 1)
		$sortOrder = "DESC";
		if($sort_order == 2)
		$sortOrder = "ASC";	
		
		$result = mysql_query("SELECT * FROM eblog_sections WHERE id = '$id'");	
		$row = mysql_fetch_row($result);
		$rowID = $row[0];
		if(empty($rowID))
		{
			echo "<meta http-equiv=\"refresh\" content=\"0;url=message.php?action=message&code=404\">";
		}		
		$rowTitle = $row[1];
		$rowDisc = $row[2];
		$rowParent = $row[4];
		
		$tempParent = $rowParent;		
		while(!empty($tempParent))
		{
			$result = mysql_query("SELECT title FROM eblog_sections WHERE id = '$tempParent'");	
			$row = mysql_fetch_row($result);
			$parentName = $row[0];
			$parentLink =  "&nbsp;<img src=\"images/prev_$blog_dir.gif\">&nbsp;<a href=\"sections.php?action=show&id=$tempParent\">$parentName</a>" . $parentLink;	
			$result = mysql_query("SELECT parent FROM eblog_sections WHERE id = '$tempParent'");	
			$row = mysql_fetch_row($result);
			$tempParent = $row[0];				
		}


		
		
		$tree_map = "<a href=\"index.php\">$lang_online_index</a>$parentLink&nbsp;<img src=\"images/prev_$blog_dir.gif\">&nbsp;<font class=\"normalfont\">$rowTitle</font>";	
		
		$EqualCellWidth = 100/$cellPR;
		$numberOfChildren = 0;
		$cellCounter = 0;
		$fulltable = "<table width=\"100%\" border=\"0\"><tr>";
		$query  = "SELECT * FROM eblog_sections WHERE parent = $id";
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$numberOfChildren++;
			$rowID = $row['id'];
			$rowTitle = $row['title'];
			$rowDisc = $row['disc'];
			
			$static_value = array ($rowID, $rowTitle, $rowDisc);
			$static_name = array ("{rowID}","{rowTitle}", "{rowDisc}");
			$file = $new_template->load_template ("templates/$defaultTemplate/subcategory.html");
			$output = $new_template->replace_static($static_name, $static_value, $file);
	
			
			$newRow = "";
			if($cellCounter >= $cellPR-1){
			$newRow  = "</tr><tr>";
			$cellCounter = 0;
			}
			else
			{
			$cellCounter++;
			}
			
			$fulltable  = $fulltable . "<td width=\"$EqualCellWidth%\">" . $output . "</td>$newRow";
	
		}
		$fulltable = $fulltable . "</tr></table>";	
		
		if($numberOfChildren>0)	
		{
			$subcatsList = $subcatsList . $fulltable;
			$header_title = $lang_blog_ListOfSubcategories;
			
			$static_value = array ($header_title);
			$static_name = array ("{header_title}");
			$file = $new_template->load_template ("templates/$defaultTemplate/subheader.html");
			$output = $new_template->replace_static($static_name, $static_value, $file);
					
			$fulltable = $output . $fulltable . "<br><br>";
		}			
		
		
		$topicsList = "";
		$cellCounter = 1;
		$EqualCellWidth = 100/$topicPR;
		$query  = "SELECT * FROM eblog_topics WHERE sec = $id ORDER BY $sortBy $sortOrder";
		$result = mysql_query($query);
		$counter = 0;
		$totalNumberOfTopics = 0;
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{	
		$totalNumberOfTopics++;
		
		if(($counter < $topicsPP)&&($totalNumberOfTopics > $spoint)){
		$counter++;
		$cellCounter++;	
		$rowID = $row['id'];
		$rowSec = $row['sec'];
		$rowTitle = $row['title'];
		$rowDate = $row['date'];
		$chunks = explode("-",$rowDate);$toGet = $chunks[1];
		$rowDate = $chunks[0] . " " . $MonthsArray[$toGet] . " " . $chunks[2];			
		$rowContent = $row['contents'];
		$rowThumb = $row['thumb'];
		$rowAllViewers = $row['allviewers'];
		
		if(strlen($rowContent) > $wrap)
		$rowContent = substr($rowContent, 0, $wrap-3).'...';
		
		$lengthX = strlen($rowThumb);
		$rowThumb = substr($rowThumb, 3, $lengthX);	
		if(empty($rowThumb))
		$rowThumb = "images/noThumb.jpg";
		
		$result3 = mysql_query("SELECT title FROM eblog_sections WHERE id = '$rowSec'");	
		$row3 = mysql_fetch_row($result3);
		$rowSecName = $row3[0];
	
		
		$readLink = "<a href=\"topics.php?action=show&id=$rowID\" $popupDefine>$lang_blog_readMore</a>";
		
		$imageLink = "href=\"topics.php?action=show&id=$rowID\" title=\"$rowTitle\" $popupDefine";	
		
		
	
			if($enablethumb == 1)
			{
				$static_value = array ($readLink, $imageLink, $rowTitle, $thumb_width, $thumb_height, $bw, $rowThumb);
				$static_name = array ("{readLink}","{imageLink}", "{rowTitle}", "{thumb_width}", "{thumb_height}", "{bw}", "{rowThumb}");
				$file = $new_template->load_template ("templates/$defaultTemplate/thumb.html");
				$output = $new_template->replace_static($static_name, $static_value, $file);	
				if($cellCounter > $topicPR)
				{
					$end = "</td></tr><tr>";
					$cellCounter = 1;
				}
				else
				{
					$end = "</td>";
				}
				$start = "<td align=\"center\" width=\"$EqualCellWidth%\" valign=\"top\">";
								
			}
			else
			{
				$static_value = array ($readLink, $imageLink, $rowTitle, $thumb_width, $thumb_height, $bw, $rowThumb,
									   $lang_blog_topicViewers, $rowAllViewers, $lang_blog_date, $rowDate, $lang_blog_inSec,
									   $rowSecName
									  );
				$static_name = array ("{readLink}","{imageLink}", "{rowTitle}", "{thumb_width}", "{thumb_height}", "{bw}", "{rowThumb}",
									  "{lang_blog_topicViewers}", "{rowAllViewers}", "{lang_blog_date}", "{rowDate}", "{lang_blog_inSec}",
									   "{rowSecName}"
									 );
				$file = $new_template->load_template ("templates/$defaultTemplate/block.html");
				$output = $new_template->replace_static($static_name, $static_value, $file);		
			}	
			

			$topicsList = $topicsList . $start . $output . $end;
					
			}
			
		}		
		
		$temp = $topicPR + 1;
		if(($cellCounter > 1)&&($enablethumb == 1))
		{
			$innerCounter = $temp - $cellCounter;
			while ($innerCounter > 0)
			{
				$topicsList = $topicsList . "<td  width=\"$EqualCellWidth%\">&nbsp;</td>";
				$innerCounter = $innerCounter - 1;
			}
			$topicsList = $topicsList . "</tr>";
		}
				
						
		if($enablethumb == 0)
		$topicsList = "<td>" . $topicsList . "</td>";
		
		$extraTable = "";
		if($counter < $totalNumberOfTopics)
		{
			$prevPoint = $spoint-$topicsPP;
			$nextPoint = $spoint+$topicsPP;
			$nextToShow = $nextPoint;
			if($prevPoint < 1){
			$prevPoint = 0;
			}
			if($nextPoint > $totalNumberOfTopics)
			{
				$nextPoint = $spoint;
				$nextToShow = $totalNumberOfTopics;	
			}
			
			$prevToShow  = $spoint+1;
			$showingInfo = "$lang_blog_showing " . $prevToShow . " $lang_blog_to " . $nextToShow . " $lang_blog_outOf " . $totalNumberOfTopics;
			
			$output = "";
			$prevLink = "sections.php?action=show&id=$id&spoint=$prevPoint";
			$nextLink = "sections.php?action=show&id=$id&spoint=$nextPoint";

			$static_value = array ($prevLink, $nextLink, $blog_dir, $lang_blog_prev, $lang_blog_next, $showingInfo);
			$static_name = array ("{prevLink}","{nextLink}", "{blog_dir}", "{lang_blog_prev}", "{lang_blog_next}", "{showingInfo}");
			$file = $new_template->load_template ("templates/$defaultTemplate/navigation.html");
			$output = $new_template->replace_static($static_name, $static_value, $file);				
			
			$extraTable = $output;
		}		
			
		$topicsList = "<table width=\"100%\" border=\"0\" cellspacing=\"5\"><tr>" . $topicsList . "</tr></table>";
		
		if($counter < 1)
		{
			$topicsList = $lang_blog_noTopics;
		}	

							
		
		$page_content = $fulltable . $topicsList . $extraTable;

		$static_value = array ($lang_blog_secionsList, $sections_list);
		$static_name = array ("{lang_blog_secionsList}","{sections_list}");
		$file = $new_template->load_template ("templates/$defaultTemplate/sideMenu.html");
		$side_menu = $new_template->replace_static($static_name, $static_value, $file);		
		
		$static_value = array (
								$blog_windows_encoding,$blog_slogan, $lang_blog_search, $lang_blog_recentTopics,
							    $tree_map, $css, $side_menu,$page_content, $blog_dir, $blog_name,
							    $meta, $social_networks, $copyrights, $lang_blog_emailMe, $lang_blog_joinMyMainingList,
							    $lang_blog_MyFriends, $lang_blog_visitors, $visitors,$popupDefine
							  );
							  
							  
		$static_name  = array (
							   "{blog_windows_encoding}", "{blog_slogan}","{lang_blog_search}", "{lang_blog_recentTopics}",
							   "{tree_map}", "{css}", "{side_menu}", "{page_content}", "{blog_dir}", "{blog_name}",
							   "{meta}", "{social_networks}", "{copyrights}", "{lang_blog_emailMe}", "{lang_blog_joinMyMainingList}",
							   "{lang_blog_MyFriends}", "{lang_blog_visitors}", "{visitors}", "{popupDefine}"
							  );
							  
		$header = $new_template->load_template ("templates/$defaultTemplate/header.html");
		$body = $new_template->load_template ("templates/$defaultTemplate/sections.html");
		$footer = $new_template->load_template ("templates/$defaultTemplate/footer.html");
		$template = $new_template->replace_static($static_name, $static_value, $header . $body	. $footer);
		echo $template;
		
		mysql_close($conn);
		
	}
	else
	{
		echo "<meta http-equiv=\"refresh\" content=\"0;url=message.php?action=message&code=404\">";
	}


?>
Return current item: eBlog