<?php

error_reporting(E_ERROR | E_PARSE);

session_start(); 



if(!isset($_SESSION['tulsilogin']))

{

	header('Location: index.php');

	return;

}



	






$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));	

	

	include("connect.php");
include("mylibrary.php");


	require('importfromexcel/php-excel-reader/excel_reader2.php');



    require('importfromexcel/SpreadsheetReader.php');

	

	

	

	$allowed =  array('xlsx');

	$filename = $_FILES['header']['name'];

	 $ext = pathinfo($filename, PATHINFO_EXTENSION);

	if(!in_array($ext,$allowed) ) 

	{

		$_SESSION['msg']="Unsupport File.Select Excel File only";

		header('location: college.php');

		return;

	}

	else

	{

	

	

	

	date_default_timezone_set("Asia/Kolkata");

	$filenameheader = date("YmdHis").$_FILES['header']['name'];

	$path = "./temp/";

	move_uploaded_file( $_FILES['header']['tmp_name'], $path ."/". $filenameheader );

	



    $Reader = new SpreadsheetReader('temp/'.$filenameheader);

	

	$i=0;

    foreach ($Reader as $Col)

    {

       		

		$coursenamecode=str_replace ("'","\'",$Col[0]);

		$coursenamecode=str_replace ('"','\"',$coursenamecode);
		
		 

		$coursename=str_replace ("'","\'",$Col[1]);

		$coursename=str_replace ('"','\"',$coursename);
		
			

		if($i==0)

		{

			$i++;

			continue;

		}

		
		

		

		 $eve = "select coursenamecode from res_coursename_master where coursenamecode='$coursenamecode' ";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		continue;
	}
	else
	{	
	
		 $eve1 = "INSERT INTO res_coursename_master (coursenamecode,coursename) VALUES('$coursenamecode','$coursename')";
		
		if($conn->query($eve1) === TRUE)
	{
		 
			
		$_SESSION['msg'] = "Record Saved successfully";
	}

			

	$_SESSION['msg'] = "Program Data Imported";

	header('Location: coursename.php');

	}
	}
	}
	header('Location: coursename.php');

?>