<?php

//////////////// script of show all blog////////////
function ShowAllBlogs()
{
	
	?>
<script>
function valdiation()
{
   if(document.frm.keyword.value=="")
	{	
	alert("Please Enter Blog Title for Search");
	document.frm.keyword.focus();
	return false;
	}

}
</script>

	<form name="frm" action="searchblog.php" method="post" onsubmit="return valdiation();">
	<table width="100%" cellpadding="2" cellspacing="2" border="0" align="center">	
	<tr>
     <td align="right">
     <input type="text" name="keyword" value="">&nbsp;&nbsp;&nbsp;<input type="submit" name="search1" value="Search" >
     </td></tr>	
     </table>
     </form>
     <table width="100%"  cellpadding="2" cellspacing="2" border="0" align="center">
		<tr>
			<td  align = "center">
			<?
			if($_GET['page']!="")
				 $page=$_GET['page'];
 			else
				 $page=1;
			
				$showdata1=mysql_query("select a.id,first_name,blogtitle,blogcat,blogcontent,blogdate,blogimage,blogid,blogviews from user a, 
				tbl_newblogs b where a.id=b.usrid order by blogid desc");
				
				$numrows=mysql_num_rows($showdata1);
			
			?>
			
		</td>
		</tr>

		<tr>
			<td  colspan="2" valign="top">
				
				<?php
				if($_SESSION['uid']!="")
	{?>
			<a href= "bloghome.php?mode=addnewblog" class="txt_red">[Upload Blog]</a>&nbsp;&nbsp;&nbsp;<?php
			
	}?>
			<a href= "bloghome.php?mode=mostview" class="txt_red">[Most Viewed]</a>
			<a href= "bloghome.php?mode=mostrecent" class="txt_red">[Most Recent]</a>
			<?php
				if($_SESSION['uid']!="")
	          {?>
			<a href= "bloghome.php?mode=myblog" class="txt_red">[My Upload Blog]</a>
			<? }?>
            <a href= "bloghome.php?mode=myfavorite" class="txt_red">[My favorite]</a>
            <a href= "bloghome.php?mode=featured" class="txt_red">[Featured]</a>
			</td>
		</tr>
		<?
			if($numrows>0)
			{
				while($showdatarow = @mysql_fetch_array($showdata1))
				{
					?>
					<tr>
						<td class="header text"  colspan="2">Category:							  
					      <a href="bloghome.php?mode=showcategorywise&catid=<? echo $showdatarow['blogcat'];?>" >
						  <?=get_fieldval(cid,cname,t123go_category,$showdatarow['blogcat'])?></a></td>
					</tr>
					<tr>
					<td valign="top" align = "left" width="35%">							
							<a href = "bloghome.php?mode=showdetailblog&blogid=<?=$showdatarow[blogid]?>" >
                                   <?=get_blog_image($showdatarow['blogimage'],100,100);?></a><br>
					  <strong>From:</strong>&nbsp;<?=get_profile_name($showdatarow[0]);?>&nbsp;&nbsp;
                          	  </td>
						
					 <td class="text6" valign="top" width="65%">
							<?

						 $data = substr(strip_tags($showdatarow['blogtitle']), 0, 25);
						 echo "<a href='bloghome.php?mode=showdetailblog&blogid=".$showdatarow['blogid']."' class='txt_blue'>".$data."</a> <br/>";
								if(strlen($showdatarow['blogcontent'])>100)
								{
									echo $data = substr(strip_tags($showdatarow['blogcontent']), 0, 100);
							
								}
								else
								{
									echo strip_tags($showdatarow['blogcontent']);
								}
							?>
						</td>
					</tr>
					
					<tr>
						<td colspan="2">
						<? if($showdatarow[0] == $_SESSION['uid'])
								{	
							?>
							[ <a href="bloghome.php?mode=deleteblog&blogid=<? echo $showdatarow['blogid'];?>" >DELETE</a> ]
							<?
								}	
							?>	
						</td>
					</tr>
					<tr>
						<td style="background:#ffffff; border:none; border-top:1px; border-top-color:#00adef;" colspan="2">
						</td>
					</tr>
					<?
				}
			}
			else
			{
				echo "<tr><td align='center'>";
				echo "There is no blog present in the database. Click <a href='bloghome.php?mode=addnewblog'  class='mnutxt'>here</a> to add your own blog";
				echo "</td></tr>";
			}
			?>
</table><br />
	<?
}

function ShowOneBlog()
{
	
	$blogid = $_GET['blogid'];
	$getblogviews = mysql_query("select * from tbl_newblogs where blogid='".$blogid."'");
	$getblogviewsrow =mysql_fetch_row($getblogviews);
	$addview = $getblogviewsrow[0] + 1;
	$updateviews =mysql_query("update tbl_newblogs set blogviews='$addview' where blogid='$blogid'");
	if($_GET['page']!="")
 		$page=$_GET['page'];
 	else
 		$page=1;
		$showdata1=mysql_query("select a.id,first_name,blogtitle,blogcat,blogcontent,blogdate,blogimage,blogid,blogviews from user a, 
				tbl_newblogs b where a.id=b.usrid and blogid = '$blogid' order by blogid desc");
		$showdatarow = @mysql_fetch_array($showdata1); //Fetch the data from database
	?>
		<table  style="width:100%" cellpadding = "8" cellspacing = "2" border = "0" align = "center" >		
			<tr class="header">
				<td colspan = "2"><a href = "bloghome.php" class = "mnutxt">Blog</a> <strong>>></strong> <? echo $showdatarow['blogtitle'];?></td>
		  </tr>
			<tr>
				<td width="50%" valign="top" align="center"><?=get_blog_image($showdatarow[blogimage],300,300)?><br>
					</strong>
				</td>
				<td width="50%" valign="top">
					<table width="100%" cellpadding="8" cellspacing="2" align="center" border="0">
						
                              <tr>
							<td align="right"><strong>By</strong></td>
							<td align="center" width="2%"><strong>:</strong></td>
							<td>
								<?=get_profile_name($showdatarow[0]);?>
							</td>
						</tr>
						<tr>
							<td align="right">
						
								<strong>Category</strong>
							</td>
							<td align="center" width="2%"><strong>:</strong></td>
							<td>
								<?=get_fieldval(cid,cname,t123go_category,$showdatarow['blogcat'])?>
							</td>
						</tr>
						<tr>
							<td align="right"><strong>Date</strong>	</td>
							<td align="center" width="2%"><strong>:</strong></td>
							<td>
								<? echo $showdatarow['blogdate'];?>
							</td>
						</tr>
						<tr>
							<td align="right"><strong>Rating</strong></td>
							<td align="center" width="2%"><strong>:</strong></td>
							<td>&nbsp;
								
							</td>
						</tr>
						<tr>
							<td align="right"><strong>Views</strong></td>
							<td align="center" width="2%"><strong>:</strong></td>
							<td>
								<?
									/*if($showdatarow['blogviews']=='')
									{
										echo "0";
									}
									else
									{
										echo $showdatarow['blogviews'];
									}*/
								?>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan = "2" class="text_blue">
					<? echo $showdatarow['blogcontent']; ?>
					
				</td>
			</tr><br>
			<tr>
				<td colspan="2">
					<?
						if($showdatarow[0]  == $_SESSION['uid'])
						{
							?>
							<a href="bloghome.php?mode=addnewblog" class="mnutxt">[WRITE NEW BLOG]</a>
							<a href="bloghome.php?mode=ediblog&blogid=<? echo $showdatarow['blogid']?>" class="mnutxt">[EDIT BLOG]</a>
							<?
						}
					?>
				</td>
			</tr>
			<tr>
				<td colspan = "2">&nbsp;</td>
			</tr>
			 
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2">
					<? viewcomment($blogid); ?>
				</td>
			</tr>
			</tr>
</table>
	<?
}
	
function addnewblog()
{
	
	?>
	<form name = "addnewblog" action = "bloghome.php?mode=addblogdata"  method = "post" enctype="multipart/form-data">

		<table border="0" cellpadding = "2" cellspacing = "1" width ="50%" align = "center" class = "borBlue">
			<tr>
				<td class = "mnutxt"colspan="2">
					<h4 class="toph1">Add Your Blog</h4>
				</td>			
			</tr>
			<tr>
				<td width="95%"><strong>Blog Title </strong></td>
			</tr>
			<tr>
				<td><input name="title" type="text" size="80"></td>
			</tr>
		
			<tr>
				<td width="95%"><strong>Upload Image </strong></td>
			</tr>
			<tr>
				<td><input type="file" name="userfile" size="40"></td>

			</tr>

			<tr>
				<td><strong>Blog Category</strong></td>
			</tr>
			<tr>
				<td >
				
				<select name="category">
				
				 <option value="0">--Select MainCategory--</option>
                                <? $select=mysql_query("select * from t123go_category ");
					while($mymaincat=mysql_fetch_array($select))
					{					
						echo '<option value="'.$mymaincat['cid'].'">'.$mymaincat['cname'].'</option>';
				                      	}
				                 ?>
                                </select>
				
				
				
				
				</td>
			</tr>
			<tr>
				<td ><strong>Content</strong></td>
			</tr>
			<tr>
				<td ><textarea name="comment" cols="70" rows="15"></textarea></td>
			</tr>
			<tr>
				<td ><input type="submit" name="Submit" value="Add Blog" class="button"></td>
			</tr>
		</table>
	</form>
	<!-- SCRIPT OF ADD BLOG AND UPLOAD IMAGE-->
	<?
}

function addblogdata()
{
		
	
	$userid = $_SESSION['uid'];
	$title = $_POST['title'];
	$category = $_POST['category'];
	$content = $_POST['comment'];
	$date = date("Y-m-d");
	$userfile=$_FILES['userfile']['name'];
	
	if($title=='')
	{
		echo "<table border='0' width='80%' cellspacing='1' cellpadding='3'><tr><td align='center'>";
		echo "Title field is blank click <a href='bloghome.php?mode=addnewblog' class='mnutxt'>here</a> to continue<br><br><br>";
		echo "</td></tr></table>";
	}
	else
	{
		if($category=='') 
		{
			echo "<table border='0' width='80%' cellspacing='1' cellpadding='3'><tr><td align='center'>";
			echo "You haven't chosen category field. click <a href='bloghome.php?mode=addnewblog' class='mnutxt'>here</a> to continue<br><br><br>";
			echo "</td></tr></table>";
		}
		else
		{
			if($content=='') 
			{
				echo "<table border='0' width='80%' cellspacing='1' cellpadding='3'><tr><td align='center'>";
				echo "Content field don't have any data yet!. click <a href='bloghome.php?mode=addnewblog' class='mnutxt'>here</a> to continue<br><br><br>";
				echo "</td></tr></table>";
			}
			else
			{  
				if($userfile=='') 
			{
				echo "<table border='0' width='100%' cellspacing='1' cellpadding='3'><tr><td align='center'>";
				echo "File not uploaded yet!. click <a href='bloghome.php?mode=addnewblog' class='mnutxt'>here</a> to continue<br><br><br>";
				echo "</td></tr></table>";
			}
			else 
				$uploaddir = 'images/blog_images/';
				
				copy($_FILES['userfile']['tmp_name'], $uploaddir .$_FILES['userfile']['name']);

              $blog_add="insert into tbl_newblogs(usrid,blogtitle,blogcat,blogcontent,blogimage,blogdate)values
			  ('".$userid."', '".$title."', '".$category."', '".$content."','".$userfile."', '".$date."')";
				$insertcomment=mysql_query($blog_add);
				if($insertcomment)
				{
					echo "<table border='0' width='100%' cellspacing='1' cellpadding='3'><tr><td align='center'>";
					echo "<script language='javascript'>alert(\"Your blog has added sucessfully!!\");
					document.location='bloghome.php'</script>;
					";
					echo "</td></tr></table>";
				}
				else
				{
					echo "<table border='0' width='100%' cellspacing='1' cellpadding='3'><tr><td align='center'>";
					echo "Your blog has not added";
					echo "</td></tr></table>";
				}
			}
		}
	}
}
/// End of  add blog script///


function deleteblog()
{
	
	$blogid = $_GET['blogid'];
	$deletecomment = mysql_query("delete from tbl_newblogs where blogid='$blogid'");
	if($deletecomment)
	{
		echo "<table width='100%' border='0' cellspacing='1' cellpadding='3'><tr><td align='center'>";
		echo "Your comment has been deleted sucessfully. click <a href='bloghome.php' class='mnutxt'>here</a> to continue";
		echo "</td></tr></table>";
	}
	else
	{
		echo "<table width='100%' border='0' cellspacing='1' cellpadding='3'><tr><td align='center'>";
		echo "Your comment has not been deleted";
		echo "</td></tr></table>";
	}
}


			// script of edit blog//
function ediblog()
{
	
	$blogid = $_GET['blogid'];
	$getdata = mysql_query("select * from tbl_newblogs where blogid='$blogid'");
	$getdatarow  = mysql_fetch_array($getdata); //Fetch the data from database
	?>
	<form name = "editblog" action = "bloghome.php?mode=editblogdata&blogid=<? echo $blogid; ?>" method = "post">
		<table border="0" cellpadding = "2" cellspacing = "1" width ="100%" align = "center" class = "borBlue">
			<tr>
				<td  class="mnutxt">
					<h4 class="toph1">Edit :<? echo $getdatarow['blogtitle'];?></h4>
				</td>			
			</tr>
			<tr>
				<td width="95%"><strong>Blog Title </strong></td>
			</tr>
			<tr>
				<td><input name="title" type="text" size="80" value = "<? echo $getdatarow['blogtitle']?>"></td>
			</tr>
			<tr>
				<td><strong>Blog Category</strong></td>
			</tr>
			<tr>
				<td ><select name="category">
				  <option value=""></option>
                           <? $sel_cat="select * from t123go_category ";
							$cat_query=mysql_query($sel_cat);							
							while($mymaincat=mysql_fetch_array($cat_query)){					
								if($getdatarow['blogcat']==$mymaincat['cid']){					
									echo '<option value="cid'.$mymaincat['cid'].'" selected>'.$mymaincat['cname'].'</option>';
								}else{
									echo '<option value="cid'.$mymaincat['cid'].'">'.$mymaincat['cname'].'</option>';
								}
							}
							?>
								 
							
                                </select>
				
				
				
				
				
					
						
				</td>
			</tr>
			<tr>
				<td ><strong>Content</strong></td>
			</tr>
			<tr>
				<td ><textarea name="comment" cols="70" rows="15"><? echo $getdatarow['blogcontent']?></textarea></td>
			</tr>
			<tr>
				<td><input type="submit" name="Submit" value="Edit Blog" class="button"></td>
			</tr>
		</table>
	</form>
	<?
}

function editblogdata()
{
	
	$blogid = $_GET['blogid'];
	$title = $_POST['title'];
	$category = $_POST['category'];
	$comment = $_POST['comment'];
	$updateblogdata = mysql_query("update tbl_newblogs set blogtitle='".$title."', blogcat='".$category."', blogcontent='".$comment."' where blogid='".$blogid."'");
	if($updateblogdata)
	{
		echo "<table border='0' width='100%' cellspacing='1' cellpadding='3'><tr><td align='center'><br><br><br>";
		echo "<strong>Your blog has updated sucessfully!!</strong><br><br>Click <a href='bloghome.php' class='mnutxt'>Here</a> to continue!!<br>";
		echo "</td></tr><tr><td></td></tr></table>";
	}
	else
	{
		echo "<table border='0' width='100%'><tr><td align='center'><br><br><br>";
		echo "<strong>Your blog has not updated!!</strong><br><br><br>";
		echo "</td></tr><tr><td></td></tr></table>";
	}
}


function myblog()

{
	
?>
	
	<table  width="100%"  cellpadding="2" cellspacing="8" border="0" align="center">
		<tr>
			<td colspan = "2" align = "center">
			<?
			if($_GET['page']!="")
				 $page=$_GET['page'];
 			else
				 $page=1;
				$profileperpage = 5;
				$StartRow = $profileperpage * ($page-1);
				$showdata1=mysql_query("select a.id,first_name,blogtitle,blogcat,blogcontent,blogdate,blogimage,blogid,blogviews from user a, 
				tbl_newblogs b where a.id=b.usrid and a.id='".$_SESSION['uid']."' ");
			   $numrows=mysql_num_rows($showdata1);
				//header("location:bloghome.php");
				
	?>
			</td>
		</tr>
		<tr>
			<td align="left" class="txt_red" colspan="2">
		
			</td>
			
			
		</tr>
		<?
			if($numrows>0)
			{
				while($showdatarow =mysql_fetch_array($showdata1))
				{
					?>
					<tr>
						<td colspan="2" class="normaltext"> Category:					  
					      <a href="#?catid=<? echo $showdatarow['blogcat'];?>" ><?=get_fieldval(cid,cname,t123go_category,$showdatarow['blogcat'])?></a></td>
					</tr>
					<tr>
					<td valign="top" align = "left" width="35%">
								
							<a href = "bloghome.php?mode=showdetailblog&blogid=<? echo $showdatarow[blogid];?>" >
								<?=get_blog_image($showdatarow[blogimage],100,100)?></a><br>
					 From:	<?=get_profile_name($showdatarow[0]);?>				  </td>
                        
					 <td  class="text6" valign="top" width="65%">
							<?

						 $data = substr(strip_tags($showdatarow['blogtitle']), 0, 25);
						 echo "<a href='bloghome.php?mode=showdetailblog&blogid=".$showdatarow['blogid']."' class='txt_blue'>".$data."</a> <br/>";
								if(strlen($showdatarow['blogcontent'])>100)
								{
									echo $data = substr(strip_tags($showdatarow['blogcontent']), 0, 100);
								
								}
								else
								{
									echo strip_tags($showdatarow['blogcontent']);
								}
							?>
					  </td>
					</tr>
					
					<tr>
						<td colspan="2">
							<?				
								
								if($showdatarow[0] == $_SESSION['uid'])
								{	
							?>
							[ <a href="bloghome.php?mode=deleteblog&blogid=<? echo $showdatarow['blogid'];?>" class="mnutxt">DELETE</a> ]
							<?
								}	
							?>
										</td>
	  </tr>
					<tr>
						<td style="background:#ffffff; border:none; border-top:1px; border-top-color:#00adef;" colspan="2">
						</td>
					</tr>
					<?
				}
			}
			else

			{
				echo "<tr><td align='center'>";
				echo "There is no blog present in the database. Click <a href='bloghome.php?mode=addnewblog'  class='mnutxt'>here</a> to add your own blog";
				echo "</td></tr>";
			}
			?>
</table><br />
	<?
}



//////////////////////////////script of most view blog//////////////
function mostview()
{
		
	?>


	<table  width="100%"  cellpadding="2" cellspacing="8" border="0" align="center">
		<tr>
			<td colspan = "2" align = "center">
			<?
			if($_GET['page']!="")
				 $page=$_GET['page'];
 			else
				 $page=1;
				$profileperpage = 4;
				$StartRow = $profileperpage * ($page-1);
				$showdata1=mysql_query("select a.id,first_name,blogtitle,blogcat,blogcontent,blogdate,blogimage,blogid,blogviews from user a, 
				tbl_newblogs b where a.id=b.usrid order by blogid desc");
				$numrows = @mysql_num_rows($showdata1); //Count the total row of database
				?>
			</td>
		</tr>
		<tr>
			<td align="left" class="txt_red" colspan="2">
			<?
			?>
				<!--<a href= "bloghome.php?mode= " >[Featured]</a>-->&nbsp;&nbsp;&nbsp;
				<a href= "bloghome.php?mode=addnewblog" >[ADD BLOG]</a>&nbsp;&nbsp;&nbsp;
			</td>
			
			
		</tr>
		<?
			if($numrows>0)
			{
				while($showdatarow =mysql_fetch_array($showdata1))
				{
					?>
					<tr>
						<td  colspan="2"  class="text6">Category:							  
					      <a href="blogcategories.php?catid=<? echo $showdatarow['blogcat'];?>" >
						  <?=get_fieldval(cid,cname,t123go_category,$showdatarow['blogcat'])?></a></td>
					</tr>
					<tr>

					<td valign="top" align = "left" width="35%">
							
							<a href = "bloghome.php?mode=showdetailblog&blogid=<? echo $showdatarow[blogid];?>" >
								<?=get_blog_image($showdatarow[blogimage],100,100)?></a><br>
					 From:	<?=get_profile_name($showdatarow[0]);?>		  </td>

						
					 <td class="text6" valign="top" width="65%">
							<?

						 $data = substr(strip_tags($showdatarow['blogtitle']), 0, 25);
						 echo "<a href='bloghome.php?mode=showdetailblog&blogid=".$showdatarow['blogid']."' class='txt_blue'>".$data."</a> <br/>";
								if(strlen($showdatarow['blogcontent'])>100)
								{
									echo $data = substr(strip_tags($showdatarow['blogcontent']), 0, 100);
									
								}
								else
								{
									echo strip_tags($showdatarow['blogcontent']);
								}
							?>
						</td>
					</tr>
					
					<tr>
						<td colspan="2">
							<?				
								
								if($showdatarow[0] == $_SESSION['uid'])
								{	
							?>
							[ <a href="bloghome.php?mode=deleteblog&blogid=<? echo $showdatarow['blogid'];?>" class="mnutxt" onclick="return confirm('are sure delete this blog')">DELETE</a> ]
							<?
								}	
							?>
						
							</td>
					</tr>
					<tr>
						<td style="background:#ffffff; border:none; border-top:1px; border-top-color:#00adef;" colspan="2">
						</td>
					</tr>
					<?
				}
			}
			else
			{
				echo "<tr><td align='center'>";
				echo "There is no blog present in the database. Click <a href='bloghome.php?mode=addnewblog'  class='mnutxt'>here</a> to add your own blog";
				echo "</td></tr>";
			}
			?>
</table><br />
	<?
						
}

/////////////Script of  Most recent //////////////////////////
function mostrecent()
{
?>

	<table  width="100%"  cellpadding="2" cellspacing="8" border="0" align="center">
		<tr>
			<td colspan = "2" align = "center">
			<?
			$showdata1=mysql_query("select a.id,first_name,blogtitle,blogcat,blogcontent,blogdate,blogimage,blogid,blogviews from user a, 
				tbl_newblogs b where a.id=b.usrid order by blogid desc limit 2");
				
				$numrows = @mysql_num_rows($showdata1); //Count the total row of database
				
				?>
			</td>
		</tr>
		<tr>
			<td align="left" class="txt_red" colspan="2">
			<?
			?>
				<!--<a href= "bloghome.php?mode= " >[Featured]</a>-->&nbsp;&nbsp;&nbsp;
				<a href= "bloghome.php?mode=addnewblog" >[ADD BLOG]</a>&nbsp;&nbsp;&nbsp;
			</td>
		
		</tr>
		<?
			if($numrows>0)
			{
				while($showdatarow = @mysql_fetch_array($showdata1))
				{
					?>
					<tr>
						<td class="header text6" colspan="2" >Category:							  
					      <a href="#.php?catid=<? echo $showdatarow['blogcat'];?>" ><?=get_fieldval(cid,cname,t123go_category,$showdatarow['blogcat'])?></a></td>
					</tr>
					<tr>

					<td valign="top" align = "left" width="35%">
							<a href = "bloghome.php?mode=showdetailblog&blogid=<? echo $showdatarow[blogid];?>" >
								<?=get_blog_image($showdatarow[blogimage],100,100)?></a><br>
					 From:	<?=get_profile_name($showdatarow[0]);?>	
                          
                           </td>
						
					 <td class="text6" valign="top" width="65%">
							<?

						 $data = substr(strip_tags($showdatarow['blogtitle']), 0, 25);
						 echo "<a href='bloghome.php?mode=showdetailblog&blogid=".$showdatarow['blogid']."' class='txt_blue'>".$data."</a> <br/>";
								if(strlen($showdatarow['blogcontent'])>100)
								{
									echo $data = substr(strip_tags($showdatarow['blogcontent']), 0, 100);
									//echo "...[ <a href='bloghome.php?mode=showdetailblog&blogid=".$showdatarow['blogid']."' class='mnutxt'>READ MORE</a> ]";
								}
								else
								{
									echo strip_tags($showdatarow['blogcontent']);
								}
							?>
						</td>
					</tr>
					
					<tr>
						<td colspan="2">
							<?				
								
								if($showdatarow[0] == $_SESSION['uid'])
								{	
							?>
							[ <a href="bloghome.php?mode=deleteblog&blogid=<? echo $showdatarow['blogid'];?>" class="mnutxt">DELETE</a> ]
							<?
								}	
							?>
						
						</td>
					</tr>
					<tr>
						<td style="background:#ffffff; border:none; border-top:1px; border-top-color:#00adef;" colspan="2">
						</td>
					</tr>
					<?
				}
			}
			else
			{
				echo "<tr><td align='center'>";
				echo "There is no blog present in the database. Click <a href='bloghome.php?mode=addnewblog'  class='mnutxt'>here</a> to add your own blog";
				echo "</td></tr>";
			}
			?>
</table><br />
	<?
}

function ShowCategoryWise()
{
	$catid=$_REQUEST['catid'];
	?>
	<table  width="100%"  cellpadding="2" cellspacing="8" border="0" align="center">
		<tr>
			<td colspan = "2" align = "center">
			<?			
			if($_GET['page']!="")
				 $page=$_GET['page'];
 			else
				$page=1;
				$profileperpage = 5;
				$StartRow = $profileperpage * ($page-1);
				
				$showdata1=mysql_query("select a.id,first_name,blogtitle,blogcat,blogcontent,blogdate,blogimage,blogid,blogviews from user a, 
				tbl_newblogs b where a.id=b.usrid and blogcat='".$_REQUEST['catid']."' order by blogid desc");
				$numrows=mysql_num_rows($showdata1);
				
				
				
				?>
			</td>
		</tr>
		<tr>
			<td  class="txt_red" colspan="2">
				<!--<a href= "bloghome.php?mode= " >[Featured]</a>-->&nbsp;&nbsp;&nbsp;
				<a href= "bloghome.php?mode=addnewblog" >[ADD BLOG]</a>&nbsp;&nbsp;&nbsp;
			<a href= "bloghome.php?mode=mostview">[Most Viewed]</a>
			</td>
		</tr>
		<?
			if($numrows>0)
			{
				while($showdatarow = mysql_fetch_array($showdata1))
				{
					?>
					<tr>
						<td class="header" colspan="2">Category:							  
					      <a href="bloghome.php?mode=showcategorywise&catid=<? echo $showdatarow['blogcat'];?>" >
						  <?=get_fieldval(cid,cname,t123go_category,$showdatarow['blogcat'])?></a>
                               </td>
					</tr>
					<tr>

					<td valign="top" align = "left">
							
							<a href = "bloghome.php?mode=showdetailblog&blogid=<? echo $showdatarow[blogid];?>" >
								<?=get_blog_image($showdatarow[blogimage],100,100)?></a><br>
					 From:	<?=get_profile_name($showdatarow[0]);?>	
                          					  </td>

						
					 <td colspan="2" class="text" valign="top">
							<?

						 $data = substr(strip_tags($showdatarow['title']), 0, 25);
						 echo "<a href='bloghome.php?mode=showdetailblog&blogid=".$showdatarow['blogid']."' class='txt_blue'>".$data."</a> <br/>";
								if(strlen($showdatarow['blogcontent'])>100)
								{
									echo $data = substr(strip_tags($showdatarow['blogcontent']), 0, 100);
									
								}
								else
								{
									echo strip_tags($showdatarow['blogcontent']);
								}
							?>
						</td>
					</tr>
					
					<tr>
						<td colspan="2">
							<?
								if($showdatarow[0] == $_SESSION['uid'])
								{	
							?>
							[ <a href="bloghome.php?mode=deleteblog&blogid=<? echo $showdatarow['blogid'];?>" class="mnutxt">DELETE</a> ]
							<?
								}	
							?>
						</td>
					</tr>
					<tr>
						<td style="background:#ffffff; border:none; border-top:1px; border-top-color:#00adef;" colspan="2">
						</td>
					</tr>
					<?
				}
			}
			else
			{
				echo "<tr><td align='center'>";
				echo "There is no blog present with your selection. Click <a href='bloghome.php?mode=addnewblog'  class='mnutxt'>here</a> to add your own blog";
				echo "</td></tr>";
			}
			?>
</table><br />
	<?
} 



function CommentBlog()
{
	
	$blogid = $_GET['blogid'];
	?>
		<form action = "bloghome.php?mode=addcomment&blogid=<? echo $blogid; ?>" method = "post">
			<table width = "100%" cellpadding = "2" cellspacing = "8" border = "0" align = "center" class="borBlue">
				<tr class = "td">
					<td class = "mnutxt">
						<h4 class="toph1">Post comment</h4>
					</td>
			</tr>
				<tr>
					<td>
						<strong>Your Comment</strong>
					</td>
				</tr>
				<tr>
					<td>
						<textarea name = "comment" cols = "60" rows = "10"></textarea>
					</td>
				</tr>
				<tr>
					<td>
						<input type = "submit" value = "Add Comment" name = "submit" class="button">
					</td>
				</tr>
			</table>
		</form>
	<?
}

function addcomment()
{
	
	$blogid = $_GET['blogid'];
	$comment = $_POST['comment'];
	$today = date("Y-m-d");
	$userid = $_SESSION['uid'];
	if($comment=='')
	{
		echo "<table border='0' width='100%' cellspacing='1' cellpadding='3'><tr><td align='center'>";
		echo "Comment field is empty. click <a href='bloghome.php?mode=CommentBlog&blogid=".$blogid."' class='mnutxt'>here</a> to continue.<br><br><br>";
		echo "</td></tr></table>";
	}
	else
	{
		
		$insertcomment = mysql_query("insert into tbl_blogcomments(blogid,fileid,commentedby,commentsposted,commenteddate)values
		('$blogid','$blogid','$userid','$comment','$today')");
		if($insertcomment)
		{
			echo "<table border='0' width='100%' cellspacing='1' cellpadding='3'><tr><td align='center'><br><br>";
			echo "<strong>Your comment has added sucessfully!!</strong> <br>Click <a href='bloghome.php?mode=showdetailblog&blogid=".$blogid."' class='mnutxt'>here</a> to continue!!<br><br><br>";
			echo "</td></tr></table>";
		}
		else
		{
			echo "<table border='0' width='100%' cellspacing='1' cellpadding='3'><tr><td align='center'>";
			echo "Your comment is not added<br><br><br>";
			echo "</td></tr></table>";
		}
	}
}



function viewcomment($blogid)
{  
	$getdata=mysql_query("select * from tbl_newblogs where blogid='$blogid'");
	$getdatarow =mysql_fetch_array($getdata); //Fetch the data from database
	?>
		<table cellpadding = "2" cellspacing = "8" width = "100%" border = "0" align="center">
			<tr>
				<td colspan="2" align="center">
					<?
						/* Here Starts paging code */
						$page = $_GET['page'];
						if(!$page)
							$page = 1;
						else
							$page = $page;
						$profileperpage = 2;
						$StartRow = $profileperpage * ($page-1);
						$comment1=mysql_query("select a.id,c.commentedby,c.commentsposted,c.commenteddate,c.commentid from user a, tbl_blogcomments c 
						where a.id=c.commentedby and c.fileid='$blogid' order by c.commentid desc");
						$numrows = @mysql_num_rows($comment1);
					?>
				</td>
			</tr>
			<tr class = "td">
				<td class = "mnutxt" colspan="2">
					<h4 class = "toph1">Comments  </h4>
				</td>
			</tr>
			<?
			if($getdatarow['usrid'] != $_SESSION['uid'])
					{
					?>
					<tr>
						<td align = "right" colspan="2">
							<a href = "bloghome.php?mode=CommentBlog&blogid=<? echo $blogid; ?>" class = "mnutxt">Post Comment</a>					
						</td>
					</tr>
					<?
					}
			if($numrows>0)
			{ 
				while($commentrow = mysql_fetch_array($comment1))
				{
					?>
					<tr>
						<td width = "19%" align = "center" valign="top">
							
							<?=get_user_image($commentrow['commentedby'],100,100);?><br>
							<?=get_profile_name($commentrow['commentedby']);?>
						</td>
						<td width="81%" valign="top">
							<strong>Posted Date : </strong><? echo $commentrow['commenteddate']; ?><br><br>
							<? echo $commentrow['commentsposted'];?>
						</td>
					</tr>
					<tr>
						<td align="center">
							<?  
								if($commentrow['commentedby'] == $_SESSION['uid'])
								{?>
									<a href = "bloghome.php?mode=deletecomment&commentid=<? echo $commentrow['commentid'];?>&blogid=<? echo $blogid?>" class = "mnutxt">Delete Comment</a>
								<?
								}
							?>
						</td>
					</tr>
					<?
				}
			}
			else
			{
				if($getdatarow['usrid'] == $_SESSION['uid'])
				{
					echo "<tr><td>";
					echo "There is no comment posted in the database.<br><br><br>";
					echo "</td></tr>";
				}
				else
				{
					echo "<tr><td>";
					echo "There is no comment posted in the database. To add a comment click <a href = 'bloghome.php?mode=CommentBlog&blogid=".$blogid."' class='mnutxt' >here</a><br><br><br>";
					
					echo "</td></tr>";
				}
			}
			?>
		</table>
	<?
}

function deletecomment()
{
	
	$blogid = $_GET['blogid'];
	$commentid = $_GET['commentid'];
	$deletecomment = mysql_query("delete from tbl_blogcomments where commentid='$commentid'");
	if($deletecomment)
	{
		echo "<table width='100%' border='0' cellspacing='1' cellpadding='3'><tr><td align='center'><br>";
		echo "Your comment has been deleted sucessfully. click <a href='bloghome.php?mode=showdetailblog&blogid=".$blogid."' class='mnutxt'>here</a> to continue";
		echo "</td></tr></table>";
	}
	else
	{
		echo "<table width='100%' border='0' cellspacing='1' cellpadding='3'><tr><td align='center'>";
		echo "Your comment has not been deleted";
		echo "</td></tr></table>";
	}
}


?>


