<?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['file']['name'];

$ext = pathinfo($filename, PATHINFO_EXTENSION);



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

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

    header('location: prospect_management_bulk_import.php');

    return;

} else {

    date_default_timezone_set("Asia/Kolkata");

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

    $path = "./temp/";

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



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



    foreach ($reader as $key => $col) {



        if ($key > 0) {

            if (isset($col[0])) {

                $name = $col['0'] ?? "";

                $mobile = $col['1'] ?? "";

                $email = $col['2'] ?? "";

                $source = $col['3'] ?? "";

                $city = $col['4'] ?? "";

                $country = $col['5'] ?? "";

                $status = $col['6'] ?? "new";



                $eve1 = "INSERT INTO res_prospect_management (name,mobile,email,source,city,country,status) VALUES('$name','$mobile','$email','$source','$city','$country','$status')";

                $re1 = mysqli_query($conn, $eve1);

            }

        }

    }

}

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

header('Location: prospect_management.php');

?>