111 lines
5.9 KiB
PHP
111 lines
5.9 KiB
PHP
<?php
|
|
require_once('.hta_config/crm_config.php');
|
|
require_once('.htac_header.php');
|
|
require_once('.htac_nav.php');
|
|
|
|
try {
|
|
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
// Check if file is uploaded
|
|
if(isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
|
|
$file_tmp = $_FILES['file']['tmp_name'];
|
|
// Read CSV file
|
|
$csvData = file_get_contents($file_tmp);
|
|
$rows = explode("\n", $csvData);
|
|
// Remove header row
|
|
array_shift($rows);
|
|
// Parse CSV data and insert into database
|
|
foreach ($rows as $row) {
|
|
$data = str_getcsv($row);
|
|
// Prepare SQL statement
|
|
$stmt = $conn->prepare("INSERT INTO cleads (name, email, phone, formname, note, details, origin, verticals, business_type, status) VALUES (:name, :email, :phone, 'crm-portal', :note, :details, :origin, '5', :business_type, 'New')");
|
|
$stmt->bindParam(':name', $data[0]);
|
|
$stmt->bindParam(':email', $data[1]);
|
|
$stmt->bindParam(':phone', $data[2]);
|
|
$stmt->bindParam(':note', $data[9]);
|
|
$stmt->bindParam(':details', $data[5]);
|
|
$stmt->bindParam(':origin', $data[6]);
|
|
$stmt->bindParam(':business_type', $data[8]);
|
|
|
|
// Execute the SQL statement
|
|
$stmt->execute();
|
|
}
|
|
|
|
echo "Records added successfully";
|
|
} else {
|
|
// echo "No file uploaded or an error occurred while uploading the file.";
|
|
}
|
|
} catch(PDOException $e) {
|
|
echo "Error: " . $e->getMessage();
|
|
}
|
|
|
|
// Close the database connection
|
|
$conn = null;
|
|
?>
|
|
<div class="container mx-auto p-4">
|
|
<p>TH(the first row) will not be added (Ignored), in every uploads the first row have to be there, as provided in the sample csv </p>
|
|
<p><span style="font-weight: bold;">Origin:</span> Facebook-Ads, Google-Ads, Linkedin-Ads, Instagram, Messenger, Whatsapp, GMB, Linkedin, Inbound-Call, Outbound-Call, Others</p>
|
|
<p><span style="font-weight: bold;">Verticals:</span> beanstalk, inhouse, teenybeans, iimtt, buzzapp, atheneum, teenybeans_curriculum</p>
|
|
</div>
|
|
<div class="flex flex-col place-items-center mt-10 mb-[20%]">
|
|
<div class="flex flex-col justify-center bg-[#F6F6F6] p-6 rounded-xl" style="min-width: 600px;">
|
|
<div class="flex flex-row place-content-between pb-8" style="border-bottom: 1px solid #DADADA;">
|
|
<p style="font-size: 25px; font-weight: bold;">Upload CSV</p>
|
|
<a href="/assets/Sample_CSV.csv" download="Sample_CSV.csv" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%); color: #fff; padding: 10px 20px 10px 20px; border-radius: 10px;">Download CSV File</a>
|
|
</div>
|
|
<form method="post" enctype="multipart/form-data" class="flex flex-col pt-6" >
|
|
<div id="fileInfo" class="mt-4 flex flex-col justify-center place-items-center p-[30px]" style="display: none; border: 2px solid #6F6BFF; border-style: dashed; border-radius: 10px; background-color: #fff; cursor: pointer;">
|
|
<p id="fileName"></p>
|
|
<p id="uploadStatus"></p>
|
|
<div id="spinner" class="spinner" style="display: none;"></div>
|
|
</div>
|
|
<label for="file" id="lebel-id" class="flex flex-col justify-center place-items-center p-[30px]" style="border: 2px solid #6F6BFF; border-style: dashed; border-radius: 10px; background-color: #fff; cursor: pointer;">
|
|
<input class="hidden" type="file" name="file" id="file" onchange="handleFileUpload(this.files)" accept=".csv" />
|
|
<img src="/assets/csv_icon.svg" alt="" />
|
|
<p style="font-size: 20px; font-weight: bold; color: #363650;">Select a CSV file to upload</p>
|
|
<p style="font-size: 16px; font-weight: bold; color: #5F5F5F;">or drag and drop it here</p>
|
|
</label>
|
|
<div class="flex flex-row place-content-between mt-4">
|
|
<p onclick="removeFile()" style="border: 3px solid #6F6BFF; padding: 10px 20px 10px 20px; border-radius: 6px; font-weight: bold; background: linear-gradient(90deg, #7B77FD 0%, #55498E 100%); -webkit-background-clip: text; background-clip: text; color: transparent; text-decoration: none; cursor: pointer;" >Cancel</p>
|
|
<input type="submit" value="Upload Files" name="submit" id="submit" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%); color: #fff; padding: 10px 20px 10px 20px; border-radius: 10px; cursor: pointer;"/>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
function handleFileUpload(files) {
|
|
const file = files[0];
|
|
const fileName = file.name;
|
|
document.getElementById('lebel-id').style.display = 'none';
|
|
document.getElementById("fileInfo").style.display = "block";
|
|
document.getElementById("fileName").textContent = "File Name: " + fileName;
|
|
|
|
document.getElementById("spinner").style.display = "block";
|
|
|
|
setTimeout(() => {
|
|
document.getElementById("uploadStatus").textContent = "Upload Complete";
|
|
// Hide spinner after upload completion
|
|
document.getElementById("spinner").style.display = "none";
|
|
}, 2000); // Simulated upload time 2 seconds
|
|
}
|
|
function removeFile() {
|
|
document.getElementById('lebel-id').style.display = 'flex';
|
|
document.getElementById('file').value = '';
|
|
document.getElementById("fileInfo").style.display = "none";
|
|
}
|
|
</script>
|
|
<style>
|
|
.spinner {
|
|
border: 4px solid rgba(0, 0, 0, 0.1);
|
|
border-left-color: #6F6BFF;
|
|
border-radius: 50%;
|
|
width: 30px;
|
|
height: 30px;
|
|
animation: spin 1s linear infinite;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
</style>
|