<?php session_start();

		ini_set( 'display_errors', 1 );
error_reporting(E_ERROR);
	
include("dbcon.php");
include('securityfun.php');

/*Insert code*/
if(isset($_POST['add']))
{
	
	    $startDate = $_POST['startDate'];
	    $closeDate = $_POST['closeDate'];
	$liger = "insert into rajdhaninightpanel(startDate,closeDate)VALUES('$startDate','$closeDate')";
	//echo $liger;
	
	if(mysql_query($liger))
	{
		echo "<script type='text/javascript'>alert('Data Inserted Successfully');</script>";
               //header("location:manageCategory.php");
                 echo '<script type="text/javascript">window.location = "Rajdhaninightpanel.php"</script>';
	}
	}

/*Insert code*/
/* code for pagination */
	$tbl_name="panel";   //=CHANGES=
 	
	// 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";
    $total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = $total_pages[num];
      
    /* Setup vars for query. */
    $targetpage = "Rajdhaninightpanel.php"; 	//your file name  (the name of this file) //=CHANGES=
    $limit = 20; 								//how many items to show per page
    $page = $_GET['page'];
    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 order by rajdhaninightId desc LIMIT $start, $limit";
	$result = mysql_query($sql);
    $rowCount=mysql_num_rows($result);   
      
    /* Setup page vars for display. */
    if ($page == 0) $page = 1;					//if no page var is given, default to 1.
     $prev = $page - 1;							//previous page is page - 1
    $next = $page + 1;							//next 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\">";
          //previous button
          if ($page > 1) 
		   $pagination.= "<a href=\"$targetpage?page=$prev\">Previous</a>";
          else
              $pagination.= "<span class=\"disabled\">previous</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?page=$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?page=$counter\">$counter</a>";					
                  }
                  $pagination.= "...";
                  $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                  $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
              }
              //in middle; hide some front and some back
              elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
              {
                  $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
                  $pagination.= "<a href=\"$targetpage?page=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?page=$counter\">$counter</a>";					
                  }
                  $pagination.= "...";
                  $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                  $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
              }
              //close to end; only hide early pages
              else
              {
                  $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
                  $pagination.= "<a href=\"$targetpage?page=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?page=$counter\">$counter</a>";					
                  }
              }
          }
         
          //next button
          if ($page < $counter - 1) 
              $pagination.= "<a href=\"$targetpage?page=$next\">next </a>";
          else
              $pagination.= "<span class=\"disabled\">next </span>";
          $pagination.= "</div>\n";		
    }

/*end code for pagination*/
?>
  <!-- Include Header file -->
         <?php include('header.php');?>
      <!-- Header file --> 
             <div class="wrapper row-offcanvas row-offcanvas-left">
            <?php include('sidebar.php');?>
            <!-- Right side column. Contains the navbar and content of the page -->
            <aside class="right-side">                
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                       Rajdhani Night Panel Chart
                       <!-- <small>Control panel</small>-->
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="home.php"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active"> Rajdhani Night Panel Chart</li>
                        
                    </ol>
                </section>
                
                <section class="content">
                <div class="box-body">
                   <form method="post" enctype="multipart/form-data">
                   
                       <div class="form-group">
                          <label>Start Date<span style="color:#F00">*</span> </label>
                          <input required  name="startDate" type="text" id="datepicker1" class="form-control" value="" autocomplete="off" placeholder="Please Start Select Date"/>
                     <span id="catNameerror" style="color:#F00">
                     </div>
                     
                     <div class="form-group">
                          <label>Close date<span style="color:#F00">*</span> </label>
                          <input required  name="closeDate" type="text" id="datepicker2" class="form-control" value="" autocomplete="off" placeholder="Please Close Select Date"/>
                     <span id="catNameerror" style="color:#F00">
                     </div>
                                            
                 <div class="form-group">
                       <input type="submit" class="form-group" name="add" >
                       <input type="reset" class="form-group" name="reset" onClick="window.location='Rajdhaninightpanel.php'">
                      </div>   

         </form>
                             
</div>

                </section>

                <!-- Main content -->
                <section class="content">
                   <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title"> Rajdhani Night Panel Chart</h3>                                   <!-- /.box-header -->
                                <div class="box-body table-responsive">
                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                 <th>Sr.No</th>
                                                 <th>Start Date</th>
                                                  <th>Close Date</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
									<?php 
                                       if($rowCount>=1)
                                      { 
                                       $empCount	=	($limit * ($page-1)) + 1;	
                                      while($content = mysql_fetch_array($result,MYSQL_ASSOC))
                                      {?>
                                            <tr>
                                               <td><?php echo $empCount++; ?></td>
                                                <td><?php echo $content['startDate'];?></td>
                                                <td><?php echo $content['closeDate'];?></td>
                                                <td><a href="editRajdhaninight.php?rajdhaninightId=<?php echo $content['rajdhaninightId']; ?>"><img src="icons/brick_edit.png" title="Edit" width="16" height="16" />
                                </a><a href="deleteRajdhaninight.php?rajdhaninightId=<?php echo $content['rajdhaninightId']; ?>" onclick="return confirm('Do You Want To Delete This Entry?')"><img src="icons/user_delete.png" title="Delete" width="16" height="16" /></a></td>
                                            </tr>
                                           <?php }}?>
                                        </tbody>
                                        <tfoot>
                                        
                                        </tfoot>
                                        
                                    </table>
                                     <div><?=$pagination?></div>
                                </div><!-- /.box-body -->
                            </div>

                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->

<?php include('footer.php');?><!--Add footer-->
<link rel="stylesheet" href="datepicker/jquery-ui.css">
  <script src="datepicker/jquery-1.12.4.js"></script>
  <script src="datepicker/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#datepicker1" ).datepicker({
      changeMonth: true,
      changeYear: true
    });
	 $( "#datepicker2" ).datepicker({
      changeMonth: true,
      changeYear: true
    });
  } );
  </script>