downloads leads with comments
This commit is contained in:
@@ -444,6 +444,33 @@ echo'<div class="flex flex-row justify-between">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
$leadsWithComments = []; // Initialize an array to hold leads with comments
|
||||
|
||||
foreach ($leads as $singleLead) {
|
||||
try {
|
||||
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$stmt = $conn->prepare("SELECT * FROM comments WHERE leadid = :leadid ORDER BY created_at DESC");
|
||||
$stmt->bindParam(':leadid', $singleLead['id']);
|
||||
$stmt->execute();
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$comments = [];
|
||||
foreach ($rows as $row) {
|
||||
$comments[] = $row['comments'];
|
||||
}
|
||||
$singleLead['comments'] = $comments;
|
||||
|
||||
$leadsWithComments[] = $singleLead;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
|
||||
}
|
||||
}
|
||||
|
||||
// Now $leadsWithComments contains all leads with their respective comments
|
||||
|
||||
?>
|
||||
<script>
|
||||
// Function to fetch countries and populate the country dropdown
|
||||
function fetchCountries() {
|
||||
@@ -464,17 +491,17 @@ echo'<div class="flex flex-row justify-between">
|
||||
function fetchStates() {
|
||||
const selectedCountry = document.getElementById('country').value;
|
||||
fetch(`https://api.siliconpin.com/v3/list/country/state/?country=${selectedCountry}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
const stateDropdown = document.getElementById('state');
|
||||
stateDropdown.innerHTML = '<option value="">Select State</option>';
|
||||
data.forEach(state => {
|
||||
const option = document.createElement('option');
|
||||
option.value = state.iso2;
|
||||
option.text = state.name;
|
||||
stateDropdown.appendChild(option);
|
||||
});
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
const stateDropdown = document.getElementById('state');
|
||||
stateDropdown.innerHTML = '<option value="">Select State</option>';
|
||||
data.forEach(state => {
|
||||
const option = document.createElement('option');
|
||||
option.value = state.iso2;
|
||||
option.text = state.name;
|
||||
stateDropdown.appendChild(option);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Function to fetch cities based on selected country and state and populate the city dropdown
|
||||
@@ -528,7 +555,7 @@ echo'<div class="flex flex-row justify-between">
|
||||
}
|
||||
}
|
||||
}
|
||||
const data = <?php echo json_encode($leads); ?>;
|
||||
const data = <?php echo json_encode($leadsWithComments); ?>;
|
||||
const filename = `leads_data.csv`;
|
||||
|
||||
function downloadCSV(data, filename) {
|
||||
|
||||
Reference in New Issue
Block a user