<?php
$sql_portal=$db->query("select * from chitaportal where portalID=1");
$res_portal=$db->fetchNextArray($sql_portal);
?><!DOCTYPE html>
<html>
	<head>
		<title><?php if($_SESSION['language']=="pr"){echo $res_portal['title'];}else{echo $res_portal['titleen'];}?> | <?php echo $tag['name']; ?>   <?php if($array[2]=='page'){ echo '| صفحه'.$array[3];}?></title>
		
		<!-- metas -->
		<meta charset="utf-8">
		<meta name="keywords" content="">
        <meta content="<?php echo $tag['name']; ?>" name="description"/>
		<meta name="description" content="">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
		<!--/ metas -->
		
		<!-- styles -->
		<?php 
if(isset($_SESSION['language'])){
	$temp=$_SESSION['language'];
	if($temp=="en"){
		include("include/spkm/headeren.php");
		 }elseif($temp=="pr"){
			 include("include/spkm/headerfa.php");
			  } } ?>
		
		<!--/ styles -->
		
		<!--[if lt IE 9]><script src="js/html5.js"></script><![endif]-->
	</head>
	
	<body>
		<div class="page">

			<!-- page header -->
			<?php	include("include/spkm/menu.php");?>
			<!--/ page header -->
			
			<!-- quick search -->
			<?php	include("include/spkm/search.php");?>
			<!--/ quick search -->

			<!-- page title -->
			<section class="page-title">
				<div class="grid-row clearfix">
					<h1><?php if($_SESSION['language']=="pr"){echo 'جستار مرتبط';}else{echo 'Related Search';}?></h1>
					
					<nav class="bread-crumbs">
						<a href="index.php"><?php if($_SESSION['language']=="pr"){echo 'صفحه اصلی';}else{echo 'Home';}?></a>&nbsp;&nbsp;<i class="fa fa-angle-left"></i>&nbsp;
						<a><?php if($_SESSION['language']=="pr"){echo $tag['name'];}else{echo $tag['name'];}?></a>&nbsp;&nbsp;<i class="fa fa-angle-left"></i>&nbsp;
					</nav>
				</div>
			</section>
			<!--/ page title -->
			
			<!-- page content -->
			<main class="page-content">
				<div class="grid-row">
					<!-- photo tour -->
					<section id="photo-tour" class="widget photo-tour photo-tour-4">
						<div class="widget-title"><?php if($_SESSION['language']=="pr"){echo 'جستار مرتبط';}else{echo 'Related Search';}?></div>
						
						
						
						<div class="grid">
                        <?php 	/*
	/*
		Place code to connect to your DB here.
	*/
	// include your code to connect to DB.

	$tbl_name="tags_relations";		//your table name
	// How many adjacent pages should be shown on each side?
	$adjacents = 3;
	
	/* 
	   First get total number of rows in data table. 
	   If you have a WHERE clause in your query, make sure you mirror it here.
	*/

	$query = "SELECT COUNT(*) as num FROM $tbl_name where tag_id='".$tag['id']."'";
	$total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = $total_pages[num];
	
	/* Setup vars for query. */
	$targetpage = "tag/".$tag['slug']."/page"; 	//your file name  (the name of this file)
	$limit =21; 								//how many items to show per page
	$page = $array[4];
	if($page) 
		$start = ($page - 1) * $limit; 			//first item to display on this page
	else
		$start = 0;								//if no page var is given, set start to 0
	
	/* Get data. */
	
	$sql = "SELECT * FROM $tbl_name where tag_id='".$tag['id']."' ORDER BY id DESC LIMIT $start, $limit";	
	$result = mysql_query($sql);
	
	/* Setup page vars for display. */
	if ($page == 0) $page = 1;					//if no page var is given, default to 1.
	$prev = $page - 1;							//قبلی page is page - 1
	$next = $page + 1;							//بعدی page is page + 1
	$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
	$lpm1 = $lastpage - 1;						//last page minus 1
	
	/* 
		Now we apply our rules and draw the pagination object. 
		We're actually saving the code to a variable in case we want to draw it more than once.
	*/
	$pagination = "";
	if($lastpage > 1)
	{	
		$pagination .= "<div class=\"pagination\">";
		//قبلی button
		if ($page > 1) 
			$pagination.= "<a href=\"$targetpage/$prev\">« قبلی</a>";
		else
			$pagination.= "<span class=\"disabled\">« قبلی</span>";	
		
		//pages	
		if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage/$counter\">$counter</a>";					
			}
		}
		elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
		{
			//close to beginning; only hide later pages
			if($page < 1 + ($adjacents * 2))		
			{
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"current\">$counter</span>";
					else
						$pagination.= "<a href=\"$targetpage/$counter\">$counter</a>";					
				}
				$pagination.= "...";
				$pagination.= "<a href=\"$targetpage/$lpm1\">$lpm1</a>";
				$pagination.= "<a href=\"$targetpage/$lastpage\">$lastpage</a>";		
			}
			//in middle; hide some front and some back
			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
			{
				$pagination.= "<a href=\"$targetpage/1\">1</a>";
				$pagination.= "<a href=\"$targetpage/2\">2</a>";
				$pagination.= "...";
				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"current\">$counter</span>";
					else
						$pagination.= "<a href=\"$targetpage/$counter\">$counter</a>";					
				}
				$pagination.= "...";
				$pagination.= "<a href=\"$targetpage/$lpm1\">$lpm1</a>";
				$pagination.= "<a href=\"$targetpage/$lastpage\">$lastpage</a>";		
			}
			//close to end; only hide early pages
			else
			{
				$pagination.= "<a href=\"$targetpage/1\">1</a>";
				$pagination.= "<a href=\"$targetpage/2\">2</a>";
				$pagination.= "...";
				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"current\">$counter</span>";
					else
						$pagination.= "<a href=\"$targetpage/$counter\">$counter</a>";					
				}
			}
		}
		
		//بعدی button
		if ($page < $counter - 1) 
			$pagination.= "<a href=\"$targetpage/$next\">بعدی »</a>";
		else
			$pagination.= "<span class=\"disabled\">بعدی »</span>";
		$pagination.= "</div>\n";		
	}

	while($post3 = mysql_fetch_array($result))
		{
			
           ?>

							<div class="item item2">
								<div class="pic">
                                <?  $eimage=$db->query("SELECT * FROM picturespart where adid='".$post3['id']."' and profile=1");
			 $image=$db->fetchNextArray($eimage); ?>
									<img src="<?php echo $image['file'];?>" width="270" height="142" alt="Nullam euismod commodo">
									<div class="links">
										<ul>
											<li><a href="<?php echo seourl('post',$post3['post_id']);?>" class="fa fa-link"></a></li>										
										</ul>
									</div>
								</div>
								<h3><?php 
if(isset($_SESSION['language'])){
	$temp=$_SESSION['language'];
	if($temp=="en"){?><?php posttitleen($post3['post_id']);?> <? }elseif($temp=="pr"){?>
			 <?php posttitle($post3['post_id']);?>
			 <? } } ?></h3>
								<p></p>
							</div>	
                             <?php } ?>	
                             <div class="col-md-12" style="margin-bottom:40px !important;">
      <!-- content parent -->
      <div class="blog-sim-main">
        <div class="row">
          <div class="col-md-12 col-sm-12">
            <article class="blog-text-main">
              <?=$pagination?>
            </article>
         
            
          </div>
        </div> 
      </div>
    </div>																																																																																																																																																								
						</div>
						
						
					</section>
					<!--/ photo tour -->
				</div>
			</main>
			<!--/ page content -->

			<!-- copyrights -->
			<?php	include("include/spkm/footer.php");?>
			<!--/ copyrights -->

		</div>
		
		<!-- scripts -->
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/jquery-ui.min.js"></script>
		<script type="text/javascript" src="js/jquery.migrate.min.js"></script>
		<script type="text/javascript" src="js/owl.carousel.min.js"></script>
		<script type="text/javascript" src="js/jquery.isotope.min.js"></script>
		<script type="text/javascript" src="js/jquery.fancybox.pack.js"></script>
		<script type="text/javascript" src="js/jquery.fancybox-media.js"></script>
		<script type="text/javascript" src="js/jquery.flot.js"></script>
		<script type="text/javascript" src="js/jquery.flot.pie.js"></script>
		<script type="text/javascript" src="js/jquery.flot.categories.js"></script>
		<script type="text/javascript" src="js/greensock.js"></script>
		<script type="text/javascript" src="js/layerslider.transitions.js"></script>
		<script type="text/javascript" src="js/layerslider.kreaturamedia.jquery.js"></script>

	<!-- Superscrollorama -->		
		<script type="text/javascript" src="js/jquery.superscrollorama.js"></script>
		<script type="text/javascript" src="js/TweenMax.min.js"></script>
		<script type="text/javascript" src="js/TimelineMax.min.js"></script>
	<!--/ Superscrollorama -->
	
		<script type="text/javascript" src="js/jquery.ui.core.min.js"></script>
		<script type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
		<script type="text/javascript" src="js/jquery.ui.tabs.min.js"></script>
		<script type="text/javascript" src="js/jquery-ui-tabs-rotate.js"></script>
		<script type="text/javascript" src="js/jquery.ui.accordion.min.js"></script>
		<script type="text/javascript" src="js/jquery.tweet.js"></script>
	<!-- EASYPIECHART -->
		<script type="text/javascript" src="js/jquery.easypiechart.js"></script>
	<!--/ EASYPIECHART -->
		<script type="text/javascript" src="js/jquery.autocomplete.min.js"></script>
		<script type="text/javascript" src="js/scripts.js"></script>
		<!--/ scripts -->
		
	</body>
</html>