downloads leads with comments
This commit is contained in:
@@ -444,6 +444,33 @@ echo'<div class="flex flex-row justify-between">
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</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>
|
<script>
|
||||||
// Function to fetch countries and populate the country dropdown
|
// Function to fetch countries and populate the country dropdown
|
||||||
function fetchCountries() {
|
function fetchCountries() {
|
||||||
@@ -464,17 +491,17 @@ echo'<div class="flex flex-row justify-between">
|
|||||||
function fetchStates() {
|
function fetchStates() {
|
||||||
const selectedCountry = document.getElementById('country').value;
|
const selectedCountry = document.getElementById('country').value;
|
||||||
fetch(`https://api.siliconpin.com/v3/list/country/state/?country=${selectedCountry}`)
|
fetch(`https://api.siliconpin.com/v3/list/country/state/?country=${selectedCountry}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const stateDropdown = document.getElementById('state');
|
const stateDropdown = document.getElementById('state');
|
||||||
stateDropdown.innerHTML = '<option value="">Select State</option>';
|
stateDropdown.innerHTML = '<option value="">Select State</option>';
|
||||||
data.forEach(state => {
|
data.forEach(state => {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = state.iso2;
|
option.value = state.iso2;
|
||||||
option.text = state.name;
|
option.text = state.name;
|
||||||
stateDropdown.appendChild(option);
|
stateDropdown.appendChild(option);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to fetch cities based on selected country and state and populate the city dropdown
|
// 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`;
|
const filename = `leads_data.csv`;
|
||||||
|
|
||||||
function downloadCSV(data, filename) {
|
function downloadCSV(data, filename) {
|
||||||
|
|||||||
Reference in New Issue
Block a user