<?php

include '../layout/header.php';
$category = $_POST['category'];

 ?>
 <!-- Page Title
 ============================================= -->
 <section id="page-title" class="page-title-parallax page-title-dark" style="background-image: url('../images/inner-headers/about-header.jpg'); padding: 70px 0;" data-stellar-background-ratio="0.3">

   <div class="container clearfix">
     <h1>Results</h1>
     <span>All India Institute Of Medical Sciences, Raipur</span>
     <ol class="breadcrumb">
       <li><a href="#">Home</a></li>
       <li><a href="#">Vacancies</a></li>
       <li class="active">Results</li>
     </ol>
   </div>

 </section><!-- #page-title end -->

 <!-- Content
 ============================================= -->
 <section id="content">
  <section id="content">
  <div class="container">
     <div class="row">

                   
                 <form method="post">

                   
            <h2 style="margin-left:10px;margin-top:0px; margin-bottom: 0px;">Filter</h2>
                    <div class="col-lg-4 form-group">
             <select name="category" class="form-control">
                <option value="">Select Category</option>
               <?php
                    $loksabha_result =mysqli_query($con,"SELECT * from  vacancies_cat order by cat desc");


                            while($row = mysqli_fetch_assoc($loksabha_result))
                             {

                             echo $did = $row["cid"];
                             $cat = $row["cat"];
                             

                               ?>
                                  <option value="<?php echo $cat ?>" <?php if($cat == $category) echo "selected" ?>
                                    >
                                   <?php echo $cat; ?> / (<?php echo $cat; ?>)

                                  </option>
                               <?php
                                   }
                                ?>
                        </select>
                    </div>
  

                     <div class="col-lg-4 form-group">
                    <button type="submit" name="submit" class="btn btn-success">Search </button>

                    </div>
               
                </form>
                 </div>
                </div>
   <div class="content-wrap" style="padding-top: 0px;">
        <div class="container clearfix">
            <div class="table-responsive">
						  <table class="table table-bordered table-striped nobottommargin">
							<thead>
							  <tr>
								<th>S No</th>
								<th>Title</th>
                <th>Categories</th>
								<th>Publishing Date</th>
                <th>Download</th>
                <th>Corrigendum</th>
							  </tr>
							</thead>
							<tbody>
                          <?php 
                           $num_rec_per_page=20;
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $num_rec_per_page;
$showMax = 4;
                                $table="result";
                                
                                   $aid=0;
                  /*  $stmt = $con->prepare("SELECT * FROM $table where did = ? ORDER BY id DESC LIMIT $start_from, $num_rec_per_page");
                                $stmt->bind_param('i', $aid);
                                $stmt->execute();
                                $result1 = $stmt->get_result();
*/
                                  if(isset($_POST['submit'])){
                                   $stmt = mysqli_query($con,"SELECT * FROM $table where did = $aid and vac_cat like '$category%'");

                                   $count = mysqli_num_rows($stmt);
                                 }else{
                                   $stmt = mysqli_query($con,"SELECT * FROM $table where did = $aid ORDER BY date DESC LIMIT $start_from, $num_rec_per_page");
                                 }
                                $s=($page-1)*20+1;
                                  while($view =mysqli_fetch_assoc($stmt))

                                {
                                    $s=$a++;
                                    $id= $view['id'];
                                    $title=$view['title'];
                                    $htitle=$view['htitle'];
                                    $pdate=$view['pdate'];
                                    $did=$view['did'];
                                    $document=$view['file'];
									$link=$view['link'];
                                    $traget='../upload/result/'.$document;
                                    $document1=$view['cfile'];
                                    $traget1='../upload/result/'.$document1;
                                    $cdate=$view['cdate'];
                                    $cat = $view['vac_cat'];
                                    $exportcat = explode('/',$cat);
                                    
                                ?>							  <tr>
								              <td><?php echo $a ?></td>
								              <td><?php echo $title ?></td>
                              <td><?php echo $exportcat[0]; ?></td>

								              <td>



                                <?php

                                if(date("d-m-Y",strtotime($pdate)) == "01-01-1970"){
                                  echo "";
                                }else{
                                  echo date("d-m-Y",strtotime($pdate));
                                }
                                ?></td>
                                    
                               <td>
								   <?php 
								   if(!empty($link)){
								   ?>
								   <a href="<?=$link?>" target="_blank" class="button button-rounded button-red"><i class="icon-download2"></i>Link</a>
								   <?php } ?>
								   <a href="<?php echo $traget?>" target="_blank" class="button button-rounded button-aqua"><i class="icon-download2"></i>Download</a></td>
                                 <td><?php if($traget1!=""){?> <?php
                                    $splittedstring=explode(";",$document1);
foreach ($splittedstring as $key =>$value) {

echo " <a href=../upload/result/".$value." target='_blank'>".$value."<br></a>";
} ?><?php } ?></td>
                            <?php if($traget1=="")
                            {?>
                            <td></td>
                            <?php } ?></td>
							  </tr>
                           <?php } ?>
            				</tbody>
						  </table>

<?php

              if(!isset($_POST['submit'])){
                ?>
   <ul class="pagination nobottommargin">
                <?php 
$sql = "SELECT * FROM $table"; 
$rs_result = mysqli_query($con,$sql); //run the query
$total_records = mysqli_num_rows($rs_result);  //count number of records
$total_pages = ceil($total_records / $num_rec_per_page); 
if ($total_pages <= $showMax)
{
$endPage = $total_pages;
}
else{
        if ($page > $total_pages - 4)
                {
                    $endPage = $total_pages;
                }
                else{
                    $endPage = $start_from + $showMax - 1;
                }
  }
echo "<li><a href='vacancies-result.php?page=1' class='pagination'>".'First'."</a></li> "; // Goto 1st page 
if($page!=1){
    $prev_page=$page-1;
echo "<li><a href='vacancies-result.php?page=".$prev_page."' class='pagination'>".'Prev'."</a></li> "; // Goto Prev page  
}

for ($i=$page; $i<=$endPage; $i++) { 
            echo "<li><a href='vacancies-result.php?page=".$i."' class='pagination'>".$i."</a></li> "; 
}; 

if($page!=$total_pages){
$nxt_page=$page+1;
echo "<li><a href='vacancies-result.php?page=".$nxt_page."' class='pagination'>".'Next'."</a></li> "; 
}

echo "<li><a href='vacancies-result.php?page=$total_pages' class='pagination'>".'Last'."</a></li> "; // Goto last page

            ?>
          </ul>
        <?php } ?>
						</div>
				</div>
   </div>
</section>

 <?php
 include '../layout/footer.php';
  ?>
