adding choice in amount

This commit is contained in:
Flatlogic Bot 2026-02-15 05:26:55 +00:00
parent 2ce4fbf197
commit c700c01af3
4 changed files with 225 additions and 67 deletions

View File

@ -0,0 +1,31 @@
<?php
require_once 'auth.php';
require_once '../db/config.php';
require_once '../mail/WablasService.php';
require_login();
if (!is_super_admin()) {
header('HTTP/1.1 403 Forbidden');
echo json_encode(['success' => false, 'error' => 'Permission denied.']);
exit;
}
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('HTTP/1.1 405 Method Not Allowed');
echo json_encode(['success' => false, 'error' => 'Method Not Allowed']);
exit;
}
$recipient = $_POST['recipient'] ?? '';
$message = $_POST['message'] ?? 'This is a test message from ' . get_org_name();
if (empty($recipient)) {
echo json_encode(['success' => false, 'error' => 'Recipient phone number is required.']);
exit;
}
$result = WablasService::sendMessage($recipient, $message);
echo json_encode($result);

View File

@ -183,8 +183,11 @@ $is_rtl = (get_current_lang() === 'ar');
<!-- Wablas Settings -->
<div class="card">
<div class="card-header bg-white py-3">
<div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0"><i class="bi bi-whatsapp <?= $is_rtl ? 'ms-2' : 'me-2' ?>"></i> <?= __('Wablas WhatsApp Gateway') ?></h5>
<button type="button" class="btn btn-outline-secondary btn-test" id="btn-test-whatsapp">
<i class="bi bi-send <?= $is_rtl ? 'ms-1' : 'me-1' ?>"></i> <?= __('Test WhatsApp') ?>
</button>
</div>
<div class="card-body">
<div class="mb-3">
@ -208,86 +211,174 @@ $is_rtl = (get_current_lang() === 'ar');
<button type="submit" class="btn btn-primary px-5"><?= __('Save Settings') ?></button>
</div>
</form>
</div>
<!-- Test Email Modal -->
<div class="modal fade" id="testEmailModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?= __('Test SMTP Connection') ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p class="text-muted small"><?= __('Please save your settings before testing if you have made any changes.') ?></p>
<div class="mb-3">
<label class="form-label"><?= __('Recipient Email') ?></label>
<input type="email" id="test_recipient" class="form-control" placeholder="your-email@example.com">
<!-- Test Email Modal -->
<div class="modal fade" id="testEmailModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?= __('Test SMTP Connection') ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p class="text-muted small"><?= __('Please save your settings before testing if you have made any changes.') ?></p>
<div class="mb-3">
<label class="form-label"><?= __('Recipient Email') ?></label>
<input type="email" id="test_recipient_email" class="form-control" placeholder="your-email@example.com">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?= __('Cancel') ?></button>
<button type="button" class="btn btn-primary" id="btn-send-test-email"><?= __('Send Test Email') ?></button>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?= __('Cancel') ?></button>
<button type="button" class="btn btn-primary" id="btn-send-test"><?= __('Send Test Email') ?></button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const testEmailModal = new bootstrap.Modal(document.getElementById('testEmailModal'));
const btnTestSmtp = document.getElementById('btn-test-smtp');
const btnSendTest = document.getElementById('btn-send-test');
const recipientInput = document.getElementById('test_recipient');
const alertContainer = document.getElementById('test-alert-container');
<!-- Test WhatsApp Modal -->
<div class="modal fade" id="testWhatsAppModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?= __('Test WhatsApp Connection') ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p class="text-muted small"><?= __('Please save your settings before testing if you have made any changes.') ?></p>
<div class="mb-3">
<label class="form-label"><?= __('Recipient Phone Number') ?></label>
<input type="tel" id="test_recipient_phone" class="form-control" placeholder="e.g. 96812345678">
</div>
<div class="mb-3">
<label class="form-label"><?= __('Message') ?></label>
<textarea id="test_whatsapp_message" class="form-control" rows="3">This is a test message from <?= htmlspecialchars(get_org_name()) ?></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?= __('Cancel') ?></button>
<button type="button" class="btn btn-primary" id="btn-send-test-whatsapp"><?= __('Send Test Message') ?></button>
</div>
</div>
</div>
</div>
btnTestSmtp.addEventListener('click', function() {
testEmailModal.show();
});
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const alertContainer = document.getElementById('test-alert-container');
btnSendTest.addEventListener('click', function() {
const recipient = recipientInput.value.trim();
if (!recipient) {
alert('<?= __('Please enter a recipient email.') ?>');
return;
// Email Test
const testEmailModal = new bootstrap.Modal(document.getElementById('testEmailModal'));
const btnTestSmtp = document.getElementById('btn-test-smtp');
const btnSendTestEmail = document.getElementById('btn-send-test-email');
const emailRecipientInput = document.getElementById('test_recipient_email');
if (btnTestSmtp) {
btnTestSmtp.addEventListener('click', () => testEmailModal.show());
}
btnSendTest.disabled = true;
btnSendTest.innerHTML = '<span class="spinner-border spinner-border-sm <?= $is_rtl ? 'ms-1' : 'me-1' ?>"></span> <?= __('Sending...') ?>';
if (btnSendTestEmail) {
btnSendTestEmail.addEventListener('click', function() {
const recipient = emailRecipientInput.value.trim();
if (!recipient) {
alert('<?= __('Please enter a recipient email.') ?>');
return;
}
const formData = new FormData();
formData.append('recipient', recipient);
btnSendTestEmail.disabled = true;
btnSendTestEmail.innerHTML = '<span class="spinner-border spinner-border-sm <?= $is_rtl ? 'ms-1' : 'me-1' ?>"></span> <?= __('Sending...') ?>';
fetch('ajax_test_email.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
btnSendTest.disabled = false;
btnSendTest.innerHTML = '<?= __('Send Test Email') ?>';
testEmailModal.hide();
const formData = new FormData();
formData.append('recipient', recipient);
const alertType = data.success ? 'success' : 'danger';
const alertMsg = data.success ? '<?= __('Test email sent successfully! Please check your inbox.') ?>' : '<?= __('Failed to send test email:') ?> ' + (data.error || '<?= __('Unknown error') ?>');
fetch('ajax_test_email.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
showAlert(data.success, data.success ? '<?= __('Test email sent successfully! Please check your inbox.') ?>' : '<?= __('Failed to send test email:') ?> ' + (data.error || '<?= __('Unknown error') ?>'));
})
.catch(error => {
showAlert(false, '<?= __('An error occurred while sending the test email.') ?>');
console.error('Error:', error);
})
.finally(() => {
btnSendTestEmail.disabled = false;
btnSendTestEmail.innerHTML = '<?= __('Send Test Email') ?>';
testEmailModal.hide();
});
});
}
// WhatsApp Test
const testWhatsAppModal = new bootstrap.Modal(document.getElementById('testWhatsAppModal'));
const btnTestWhatsApp = document.getElementById('btn-test-whatsapp');
const btnSendTestWhatsApp = document.getElementById('btn-send-test-whatsapp');
const phoneRecipientInput = document.getElementById('test_recipient_phone');
const whatsappMessageInput = document.getElementById('test_whatsapp_message');
if (btnTestWhatsApp) {
btnTestWhatsApp.addEventListener('click', () => testWhatsAppModal.show());
}
if (btnSendTestWhatsApp) {
btnSendTestWhatsApp.addEventListener('click', function() {
const recipient = phoneRecipientInput.value.trim();
const message = whatsappMessageInput.value.trim();
if (!recipient) {
alert('<?= __('Please enter a recipient phone number.') ?>');
return;
}
if (!message) {
alert('<?= __('Please enter a message.') ?>');
return;
}
btnSendTestWhatsApp.disabled = true;
btnSendTestWhatsApp.innerHTML = '<span class="spinner-border spinner-border-sm <?= $is_rtl ? 'ms-1' : 'me-1' ?>"></span> <?= __('Sending...') ?>';
const formData = new FormData();
formData.append('recipient', recipient);
formData.append('message', message);
fetch('ajax_test_whatsapp.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
let errorMsg = data.error || '<?= __('Unknown error') ?>';
if (typeof errorMsg === 'object') {
errorMsg = JSON.stringify(errorMsg);
}
showAlert(data.success, data.success ? '<?= __('Test message sent successfully!') ?>' : '<?= __('Failed to send test message:') ?> ' + errorMsg);
})
.catch(error => {
showAlert(false, '<?= __('An error occurred while sending the test message.') ?>');
console.error('Error:', error);
})
.finally(() => {
btnSendTestWhatsApp.disabled = false;
btnSendTestWhatsApp.innerHTML = '<?= __('Send Test Message') ?>';
testWhatsAppModal.hide();
});
});
}
function showAlert(isSuccess, message) {
const alertType = isSuccess ? 'success' : 'danger';
const alertHtml = `
<div class="alert alert-${alertType} alert-dismissible fade show">
${alertMsg}
${message}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
`;
alertContainer.innerHTML = alertHtml;
})
.catch(error => {
btnSendTest.disabled = false;
btnSendTest.innerHTML = '<?= __('Send Test Email') ?>';
console.error('Error:', error);
alert('<?= __('An error occurred while sending the test email.') ?>');
});
}
});
});
</script>
</script>
</div>
</body>
</html>
</html>

View File

@ -1,4 +1,4 @@
<?php
'''<?php
require_once 'db/config.php';
// Language configuration
@ -200,6 +200,13 @@ require_once 'includes/header.php';
<input type="hidden" name="case_id" id="modalCaseId">
<div class="mb-3">
<label class="form-label small fw-bold text-muted"><?= $t['modal_amount'] ?></label>
<div class="d-flex justify-content-between mb-2">
<button type="button" class="btn btn-outline-primary btn-sm flex-grow-1 mx-1" onclick="setAmount(1)">1</button>
<button type="button" class="btn btn-outline-primary btn-sm flex-grow-1 mx-1" onclick="setAmount(5)">5</button>
<button type="button" class="btn btn-outline-primary btn-sm flex-grow-1 mx-1" onclick="setAmount(20)">20</button>
<button type="button" class="btn btn-outline-primary btn-sm flex-grow-1 mx-1" onclick="setAmount(50)">50</button>
<button type="button" class="btn btn-outline-secondary btn-sm flex-grow-1 mx-1" onclick="setAmount('more')">More</button>
</div>
<div class="input-group">
<span class="input-group-text bg-white border-end-0">OMR</span>
<input type="number" name="amount" class="form-control border-start-0 ps-0" step="1" min="1" placeholder="10" required>
@ -277,6 +284,17 @@ require_once 'includes/header.php';
recipientPhone.removeAttribute('required');
}
}
function setAmount(amount) {
const amountInput = donateModal.querySelector('input[name="amount"]');
if (amount === 'more') {
amountInput.value = '';
amountInput.focus();
} else {
amountInput.value = amount;
}
}
</script>
</body>
</html>
</html>
'''

View File

@ -1,4 +1,4 @@
<?php
'''<?php
require_once 'db/config.php';
// Language configuration
@ -523,6 +523,13 @@ require_once 'includes/header.php';
<input type="hidden" name="case_id" id="modalCaseId">
<div class="mb-3">
<label class="form-label small fw-bold text-muted"><?= $t['modal_amount'] ?></label>
<div class="d-flex justify-content-between mb-2">
<button type="button" class="btn btn-outline-primary btn-sm flex-grow-1 mx-1" onclick="setAmount(1)">1</button>
<button type="button" class="btn btn-outline-primary btn-sm flex-grow-1 mx-1" onclick="setAmount(5)">5</button>
<button type="button" class="btn btn-outline-primary btn-sm flex-grow-1 mx-1" onclick="setAmount(20)">20</button>
<button type="button" class="btn btn-outline-primary btn-sm flex-grow-1 mx-1" onclick="setAmount(50)">50</button>
<button type="button" class="btn btn-outline-secondary btn-sm flex-grow-1 mx-1" onclick="setAmount('more')">More</button>
</div>
<div class="input-group">
<span class="input-group-text bg-white border-end-0">OMR</span>
<input type="number" name="amount" class="form-control border-start-0 ps-0" step="1" min="1" placeholder="10" required>
@ -603,6 +610,16 @@ require_once 'includes/header.php';
recipientPhone.removeAttribute('required');
}
}
function setAmount(amount) {
const amountInput = donateModal.querySelector('input[name="amount"]');
if (amount === 'more') {
amountInput.value = '';
amountInput.focus();
} else {
amountInput.value = amount;
}
}
function highlightCase(id) {
const el = document.getElementById('case-' + id);
@ -621,4 +638,5 @@ require_once 'includes/header.php';
}
</script>
</body>
</html>
</html>
''