52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
require_once '../includes/header.php';
|
|
require_once '../db/config.php';
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<h2>Broadcast Message</h2>
|
|
<p>Send a message to all clients.</p>
|
|
<hr>
|
|
|
|
<form id="broadcast-form">
|
|
<div class="mb-3">
|
|
<label for="broadcast-message" class="form-label">Message</label>
|
|
<textarea class="form-control" id="broadcast-message" name="message" rows="5" required></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-danger">Send Broadcast</button>
|
|
</form>
|
|
</div>
|
|
|
|
<?php require_once '../includes/footer.php'; ?>
|
|
|
|
<script>
|
|
document.getElementById('broadcast-form').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
if (!confirm('Are you sure you want to send this message to all clients?')) {
|
|
return;
|
|
}
|
|
|
|
const form = e.target;
|
|
const formData = new FormData(form);
|
|
|
|
fetch('../api/broadcast_sms.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('Broadcast sent successfully!');
|
|
form.reset();
|
|
} else {
|
|
alert('Error: ' + data.error);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('An unexpected error occurred.');
|
|
});
|
|
});
|
|
</script>
|