<?php 
$con=mysqli_connect("localhost:3306","racin_Saikat","Samanta@2022","racin_cws") or die (mysql_error());

 $u_id=$_SESSION['user_id'];
$class=$_REQUEST["class"];

?>
<script>
function do_edit(i)
	{
		window.open("edithostel_details.php?id=" + i ,"_self");
	} 
function do_search(i)
	{
		//alert("dfkf");
		document.form1.h_page.value=i;
		document.form1.h_action.value="search";
		document.form1.submit();
	}
function do_delete(which_id)
	{
		//alert(which_id);
		var cnf=confirm("Are you sure?\n\nPress OK to proceed with delete.");
		if(cnf)
		{
			
			window.location.href="manage_complain.php?id="+ which_id + "&action=delete";
		}
    }	
</script>
<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">   
    <title>SCHOOL MANAGEMENT SYSTEM</title>
    <link rel="shortcut icon" href="../assets/dist/img/ico/favicon.png" type="image/x-icon">
   <link href="../assets/plugins/jquery-ui-1.12.1/jquery-ui.min.css" rel="stylesheet" type="text/css"/>
   <link href="../assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
   <link href="../assets/plugins/lobipanel/lobipanel.min.css" rel="stylesheet" type="text/css"/>
   <link href="../assets/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
   <link href="../assets/themify-icons/themify-icons.css" rel="stylesheet" type="text/css"/>
<link href="../assets/plugins/toastr/toastr.css" rel="stylesheet" type="text/css"/>
<link href="../assets/plugins/emojionearea/emojionearea.min.css" rel="stylesheet" type="text/css"/>
<link href="../assets/plugins/monthly/monthly.css" rel="stylesheet" type="text/css"/>
<link href="../assets/dist/css/stylehealth.min.css" rel="stylesheet" type="text/css"/>
<link href='../assets/dist/css/bootstrap-datepicker.min.css' rel='stylesheet' type='text/css'>


  
<link href='https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css' rel='stylesheet' type='text/css'>
<link href='https://cdn.datatables.net/buttons/1.5.6/css/buttons.dataTables.min.css' rel='stylesheet' type='text/css'>


    
</head>
<body class="hold-transition sidebar-mini">
    <!-- Site wrapper -->
    <div class="wrapper">
         <?php  include("../include/header.php"); ?>
        <!-- =============================================== -->
        <!-- Left side column. contains the sidebar -->
        <?php   
		 include("../include/left_menu_index.php");
		
		?>        <!-- =============================================== -->
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <div class="header-icon">
                   <i class="fas fa-rupee-sign"></i>
                </div>
                <div class="header-title">
                    <h1> Add Marks</h1><br>
                    
                    <ol class="breadcrumb hidden-xs">
                        <li><a href="../dashboard.php"><i class="pe-7s-home"></i> Home</a></li>
                    </ol>
					 <?php  // include("include/module_head.php"); ?>
                </div>
            </section>
            <!-- Main content -->
            <section class="content">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="panel panel-bd ">
                            <div class="panel-heading">
                                <div class="btn-group"> 
                                <h3>Add Marks for Class <?php echo $_REQUEST["class"]; ?>
                                    </h3>  
                                </div>        
                            </div>
                            <div class="panel-body">
                               
                           <hr>
                                <form method="post" enctype="multipart/form-data">
   <div align="left" style="background-color:#CCFFFF"> 
   <img 
    <br>&nbsp;&nbsp;<label>Select CSV File:
    &nbsp;&nbsp;<input type="file" name="file" /></label>
    <br /><br>
    &nbsp;&nbsp;<input type="submit" name="submit" value="Import" class="btn btn-info" />
    <br><br>
   </div>
  </form>

<hr>
 <div class="table-responsive">

   
    </div><?php


 if($_REQUEST["done"]=="yes") {
   // echo $class;
    mysqli_query($con,"update marks_ set `flag`='1' , `status`='active' where `class`='".$class."' and `flag`='0'");
    ?><h3>Total <?php echo $_REQUEST["i"]; ?> Row Submitted Successfully.</h3></div><?php 
} else { ?><br>
<a href="addmark.php?done=yes&i=<?php echo $i-1; ?>&class=<?php echo $_REQUEST['class']; ?>"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTfz3upZJUzgki4bn27faJf6gPIIo7Yo5HxZg&usqp=CAU" width="40"></a>&nbsp;&nbsp;&nbsp;
<a href="Accept"><img src="https://cdn-icons-png.flaticon.com/512/3298/3298599.png" width="45"></a>

<?php
}
$i=0;



if(isset($_POST["submit"]))
{
 if($_FILES['file']['name'])
 {
  $filename = explode(".", $_FILES['file']['name']);
  if($filename[1] == 'csv')
  {
   $handle = fopen($_FILES['file']['tmp_name'], "r");
   while($data = fgetcsv($handle))
   {
	   if($i=="0") { } else {
   
   echo $bpn = mysqli_real_escape_string($con, $data[0]);
    $name = mysqli_real_escape_string($con, $data[1]);
    $address = mysqli_real_escape_string($con, $data[2]); 
    $date = mysqli_real_escape_string($con, $data[3]);
    $holding = mysqli_real_escape_string($con, $data[4]);
    $ward=mysqli_real_escape_string($con, $data[5]);
    $spn = mysqli_real_escape_string($con, $data[6]);
    $app_date = mysqli_real_escape_string($con, $data[7]);
$lbs = mysqli_real_escape_string($con, $data[8]);
      
    mysqli_query($con,"insert into building (`building_plan_no`,`name`,`address`,`submit_date`,`holding_no`,`plan_no`,`approved_date`,`ward`,`lbs`) values 
    ('".$bpn."','".$name."','".$address."','".$date."','".$holding."','".$spn."','".$app_date."','".$ward."','".$lbs."')"); 
   
		//	   mysqli_query($con, $query);

  
  
  
              
	   }
	   $i++;
   }
   fclose($handle);
   ?><script> 
   window.location.href="?class=<?php echo $class; ?>&action=done&i=<?php echo $i; ?>";
   </script><?php 
  }
 }
}

?>


			 
<p>&nbsp;</p>
								</div>
                            </div>
                        </div>
                    </div>
                
             <!-- /.content -->
        </div> <!-- /.content-wrapper -->
         <?php   
		 include("../include/footer.php");
		
		?>


    </div> 
    <!-- Start Core Plugins
        =====================================================================-->
        <!-- jQuery -->
        <script src="../assets/plugins/jQuery/jquery-1.12.4.min.js" type="text/javascript"></script>
        <!-- jquery-ui --> 
        <script src="../assets/plugins/jquery-ui-1.12.1/jquery-ui.min.js" type="text/javascript"></script>
        <!-- Bootstrap -->
        <script src="../assets/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
        <!-- lobipanel -->
        <script src="../assets/plugins/lobipanel/lobipanel.min.js" type="text/javascript"></script>
        <!-- Pace js -->
        <script src="../assets/plugins/pace/pace.min.js" type="text/javascript"></script>
        <!-- SlimScroll -->
        <script src="../assets/plugins/slimScroll/jquery.slimscroll.min.js" type="text/javascript"></script>
        <!-- FastClick -->
        <script src="../assets/plugins/fastclick/fastclick.min.js" type="text/javascript"></script>
        <!-- Hadmin frame -->
        <script src="../assets/dist/js/custom1.js" type="text/javascript"></script>
        <!-- End Core Plugins
        =====================================================================-->
        <!-- Start Page Lavel Plugins
        =====================================================================-->
        <!-- Toastr js -->
        <script src="../assets/plugins/toastr/toastr.min.js" type="text/javascript"></script>
        <!-- Sparkline js -->
        <script src="../assets/plugins/sparkline/sparkline.min.js" type="text/javascript"></script>
        <!-- Data maps js -->
        <script src="../assets/plugins/datamaps/d3.min.js" type="text/javascript"></script>
        <script src="../assets/plugins/datamaps/topojson.min.js" type="text/javascript"></script>
        <script src="../assets/plugins/datamaps/datamaps.all.min.js" type="text/javascript"></script>
        <!-- Counter js -->
        <script src="../assets/plugins/counterup/waypoints.js" type="text/javascript"></script>
        <script src="../assets/plugins/counterup/jquery.counterup.min.js" type="text/javascript"></script>
        <!-- ChartJs JavaScript -->
        <script src="../assets/plugins/chartJs/Chart.min.js" type="text/javascript"></script>
        <script src="../assets/plugins/emojionearea/emojionearea.min.js" type="text/javascript"></script>
        <!-- Monthly js -->
        <script src="../assets/plugins/monthly/monthly.js" type="text/javascript"></script>
        <!-- Data maps -->
        <script src="../assets/plugins/datamaps/d3.min.js" type="text/javascript"></script>
        <script src="../assets/plugins/datamaps/topojson.min.js" type="text/javascript"></script>
        <script src="../assets/plugins/datamaps/datamaps.all.min.js" type="text/javascript"></script>
      
        <!-- End Page Lavel Plugins
        =====================================================================-->
        <!-- Start Theme label Script
        =====================================================================-->
        <!-- Dashboard js -->
        <script src="../assets/dist/js/custom.js" type="text/javascript"></script>



<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.flash.min.js" type="text/javascript"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js" type="text/javascript"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js" type="text/javascript"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.html5.min.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.print.min.js" type="text/javascript"></script>

        <script >
        $(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    } );
} );
</script>
</body>
</html>