<?php
error_reporting(0);
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>Notification For Various Vacancies</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">Vacancies</li>
     </ol>
   </div>

 </section><!-- #page-title end -->

 <!-- 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>Start Date</th>
                               <th>Closing Date</th>
                                <th class="coldownload">Download</th>
                                <th>Amendment</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="career";
                                $aid=0;
								$currentdate=date('Y-m-d');
                                if(isset($_POST['submit'])){
                                   $stmt = mysqli_query($con,"SELECT * FROM $table where did = $aid and vac_cat like '$category%' and (cdate>='$currentdate' or cdate ='' or cdate is null)");

                                   $count = mysqli_num_rows($stmt);
                                 }else{
                                   $stmt = mysqli_query($con,"SELECT * FROM $table where did = $aid and (cdate>='$currentdate' or cdate ='' or cdate is null) ORDER BY submit_date DESC LIMIT $start_from, $num_rec_per_page");
                                 }
                   
                               /* $stmt->bind_param('i', $aid);
                                $stmt->execute();
                                $result1 = $stmt->get_result();*/
                                $s=($page-1)*20+1;
                                while($view =mysqli_fetch_assoc($stmt))
                                {                                   
					                         $a=$s++;
                                    $id=$view['id'];
                                    $title=$view['title'];
                                    $htitle=$view['htitle'];
                                    $pdate=$view['pdate'];
                                    $sdate=$view['sdate'];
                                    $cdate=$view['cdate'];
                                    $pdf=$view['download'];
                                    $link=$view['link'];
                                    $amendment=$view['amendment'];
                                    $marknew=$view['marknew'];

                                    $cat = $view['vac_cat'];
                                    $exportcat = explode('/',$cat);
                                   
                                     $document1=$view['cfile'];
                    $traget1='../upload/vacancies/'.$document1;
                                    $did=$view['did'];


                                    /*if($isset($_POST['submit'])){
                                      if($count != 0){}
                                    }*/
                                    
                                ?>
							  <tr>

								<td><?php echo $a ?></td>
								<td>
									<?php if($marknew==1){
										echo "<img src='../images/icons/new-icon-gif-3.jpg' width=40 />";
									}?>
									
								<?php echo $title ?></td>
                <td><?php echo $exportcat[0]; ?></td>
                <?php if($pdate!=""){?>
								<td><?php echo date("d-m-Y",strtotime($pdate)); ?></td>
                <?php } if($pdate==""){ ?>
                <td><?php echo $pdate?></td>
                <?php } ?>
                <?php if($sdate!=""){?>
                               <td style="width: 100px;"><?php echo date("d-m-Y",strtotime($sdate)); ?></td>
                               <?php } if($sdate==""){?>
                               <td><?php echo $sdate?></td>
                               <?php } ?>
                               <?php if($cdate!=""){?>
                               <td style="width: 100px;"><?php echo date("d-m-Y", strtotime($cdate));?></td>
                               <?php } if($cdate==""){?>
                               <td><?php echo $cdate;?></td>
                               <?php }?>
                               <?php if($link==""){
                                    ?>
                                <td><a href="../upload/vacancies/<?php echo $pdf?>" target="_blank" class="button button-rounded button-small button-aqua" style=""><i class="icon-download2"></i>Download</a></td> <?php } ?>
                                <?php if($link !="" && $pdf ==""){
                                    ?>
                                <td><a href="<?php echo $link?>" target="_blank" class="button button-rounded button-small button-red"><i class="icon-download2"></i>Link</a></td> <?php } ?>
                                 
                               <?php  if($link !="" && $pdf !=""){?>
                                <td>
                                        <a href="<?php echo $link?>" target="_blank" class="button button-rounded button-red"><i class="icon-download2"></i>Link</a>
                                        <a href="../upload/vacancies/<?php echo $pdf?>" target="_blank" class="button button-rounded button-aqua"><i class="icon-download2"></i>Download</a>
                                        </td> 
                                        <?php } ?>
                                <td><?php if($traget1!=""){?> <?php
                                    $splittedstring=explode(";",$document1);
foreach ($splittedstring as $key =>$value) {

echo " <a href=../upload/vacancies/".$value." target='_blank'>".$value."<br></a>";
} ?><?php } ?></td>
                            <?php if($traget1=="")
                            {?>
                            <td></td>
                            <?php } ?>


							  </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.php?page=1' class='pagination'>".'First'."</a></li> "; // Goto 1st page 
if($page!=1){
    $prev_page=$page-1;
echo "<li><a href='vacancies.php?page=".$prev_page."' class='pagination'>".'Prev'."</a></li> "; // Goto Prev page  
}

for ($i=$page; $i<=$endPage; $i++) { 
            echo "<li><a href='vacancies.php?page=".$i."' class='pagination'>".$i."</a></li> "; 
}; 

if($page!=$total_pages){
$nxt_page=$page+1;
echo "<li><a href='vacancies.php?page=".$nxt_page."' class='pagination'>".'Next'."</a></li> "; 
}

echo "<li><a href='vacancies.php?page=$total_pages' class='pagination'>".'Last'."</a></li> "; // Goto last page

            ?>
          </ul>
                  <?php } ?>

						</div>
				</div>
   </div>
</section>

 <?php
 include '../layout/footer.php';
  ?>
