update pos
This commit is contained in:
parent
2a16f1f83e
commit
ec6f16b511
64
admin.php
64
admin.php
@ -2,17 +2,6 @@
|
||||
$title = 'dashboard';
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
// Handle WhatsApp Settings Save
|
||||
if ($is_super && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_whatsapp_settings'])) {
|
||||
set_setting('whatsapp_enabled', $_POST['whatsapp_enabled'] ?? '0');
|
||||
set_setting('wablas_token', $_POST['wablas_token'] ?? '');
|
||||
set_setting('wablas_server', $_POST['wablas_server'] ?? '');
|
||||
set_setting('msg_order_created_ar', $_POST['msg_order_created_ar'] ?? '');
|
||||
set_setting('msg_order_ready_ar', $_POST['msg_order_ready_ar'] ?? '');
|
||||
set_setting('msg_payment_ar', $_POST['msg_payment_ar'] ?? '');
|
||||
$success_msg = is_arabic() ? 'تم حفظ الإعدادات بنجاح' : 'Settings saved successfully';
|
||||
}
|
||||
|
||||
// Helper functions for status colors
|
||||
if (!function_exists('getStatusColor')) {
|
||||
function getStatusColor($status) {
|
||||
@ -292,59 +281,8 @@ if (!$is_limited) {
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php if ($is_super): ?>
|
||||
<div class="mt-4">
|
||||
<div class="card p-4 shadow-sm" style="border-radius: 20px;">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h5 class="fw-bold mb-0"><i class="bi bi-whatsapp text-success me-2"></i> <?= __('whatsapp_settings') ?></h5>
|
||||
<?php if (isset($success_msg)): ?>
|
||||
<div class="alert alert-success py-2 px-3 mb-0" style="border-radius: 10px;"><?= $success_msg ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<form method="POST">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-12">
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input class="form-check-input" type="checkbox" id="whatsapp_enabled" name="whatsapp_enabled" value="1" <?= get_setting('whatsapp_enabled') == '1' ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="whatsapp_enabled"><?= __('whatsapp_enabled') ?></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold"><?= __('wablas_token') ?></label>
|
||||
<input type="text" class="form-control" name="wablas_token" value="<?= htmlspecialchars(get_setting('wablas_token', '')) ?>" placeholder="Wablas API Token">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold"><?= __('wablas_server') ?></label>
|
||||
<input type="text" class="form-control" name="wablas_server" value="<?= htmlspecialchars(get_setting('wablas_server', 'https://console.wablas.com')) ?>" placeholder="https://console.wablas.com">
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label class="form-label fw-semibold"><?= __('msg_order_created_ar') ?></label>
|
||||
<textarea class="form-control mb-2" name="msg_order_created_ar" rows="2"><?= htmlspecialchars(get_setting('msg_order_created_ar', '')) ?></textarea>
|
||||
<small class="text-muted">Tags: {customer_name}, {order_number}, {order_details}, {total_price}</small>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label class="form-label fw-semibold"><?= __('msg_order_ready_ar') ?></label>
|
||||
<textarea class="form-control mb-2" name="msg_order_ready_ar" rows="2"><?= htmlspecialchars(get_setting('msg_order_ready_ar', '')) ?></textarea>
|
||||
<small class="text-muted">Tags: {customer_name}, {order_number}</small>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label class="form-label fw-semibold"><?= __('msg_payment_ar') ?></label>
|
||||
<textarea class="form-control mb-2" name="msg_payment_ar" rows="2"><?= htmlspecialchars(get_setting('msg_payment_ar', '')) ?></textarea>
|
||||
<small class="text-muted">Tags: {customer_name}, {order_number}, {amount}, {remaining_balance}</small>
|
||||
</div>
|
||||
<div class="col-12 mt-4">
|
||||
<button type="submit" name="save_whatsapp_settings" class="btn btn-primary px-4 py-2" style="border-radius: 12px;">
|
||||
<i class="bi bi-save me-2"></i> <?= is_arabic() ? 'حفظ' : 'Save' ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/footer.php';
|
||||
?>
|
||||
?>
|
||||
@ -19,6 +19,35 @@ $payment_method = $input['payment_method'] ?? null;
|
||||
$branch_id = $_SESSION['branch_id'];
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
// Check if branch_id is 'all' (happens when super_admin views all branches)
|
||||
if ($branch_id === 'all') {
|
||||
// We need a specific branch_id to save an order.
|
||||
// If we're in "all" mode, we'll try to get the user's primary branch or just the first available branch.
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt_u = $pdo->prepare("SELECT branch_id FROM users WHERE id = ?");
|
||||
$stmt_u->execute([$user_id]);
|
||||
$u_branch = $stmt_u->fetchColumn();
|
||||
|
||||
if ($u_branch && $u_branch != 'all') {
|
||||
$branch_id = $u_branch;
|
||||
} else {
|
||||
// Fallback to first branch in user_branches
|
||||
$stmt_ub = $pdo->prepare("SELECT branch_id FROM user_branches WHERE user_id = ? LIMIT 1");
|
||||
$stmt_ub->execute([$user_id]);
|
||||
$ub_branch = $stmt_ub->fetchColumn();
|
||||
if ($ub_branch) {
|
||||
$branch_id = $ub_branch;
|
||||
} else {
|
||||
// Last resort: first branch in system
|
||||
$branch_id = $pdo->query("SELECT id FROM branches LIMIT 1")->fetchColumn();
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Silently continue, might fail at insert
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($items)) {
|
||||
echo json_encode(['success' => false, 'error' => 'Cart is empty']);
|
||||
exit;
|
||||
@ -157,4 +186,4 @@ try {
|
||||
} catch (Exception $e) {
|
||||
if (isset($pdo)) $pdo->rollBack();
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
39
api/update_setting.php
Normal file
39
api/update_setting.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'super_admin') {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'error' => 'Unauthorized']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['success' => false, 'error' => 'Method not allowed']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$key = $_POST['key'] ?? '';
|
||||
$value = $_POST['value'] ?? '';
|
||||
|
||||
if (empty($key)) {
|
||||
echo json_encode(['success' => false, 'error' => 'Missing key']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Basic security check to ensure we only update allowed settings
|
||||
$allowed_keys = ['whatsapp_enabled', 'wablas_token', 'wablas_server', 'wablas_security_key'];
|
||||
if (!in_array($key, $allowed_keys)) {
|
||||
echo json_encode(['success' => false, 'error' => 'Invalid key']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
set_setting($key, $value);
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
@ -12,53 +12,68 @@ if ($current_role !== 'super_admin') {
|
||||
|
||||
$success = '';
|
||||
$error = '';
|
||||
$is_super = ($current_role === 'super_admin');
|
||||
|
||||
// Get company data
|
||||
$stmt = db()->query("SELECT * FROM companies LIMIT 1");
|
||||
$company = $stmt->fetch();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$name_en = $_POST['name_en'] ?? '';
|
||||
$name_ar = $_POST['name_ar'] ?? '';
|
||||
$email = $_POST['email'] ?? '';
|
||||
$phone = $_POST['phone'] ?? '';
|
||||
$address_en = $_POST['address_en'] ?? '';
|
||||
$address_ar = $_POST['address_ar'] ?? '';
|
||||
$vat_number = $_POST['vat_no'] ?? ''; // Keep for compatibility
|
||||
$ctr_no = $_POST['ctr_no'] ?? '';
|
||||
$vat_no = $_POST['vat_no'] ?? '';
|
||||
if (isset($_POST['save_company_profile'])) {
|
||||
$name_en = $_POST['name_en'] ?? '';
|
||||
$name_ar = $_POST['name_ar'] ?? '';
|
||||
$email = $_POST['email'] ?? '';
|
||||
$phone = $_POST['phone'] ?? '';
|
||||
$address_en = $_POST['address_en'] ?? '';
|
||||
$address_ar = $_POST['address_ar'] ?? '';
|
||||
$vat_number = $_POST['vat_no'] ?? ''; // Keep for compatibility
|
||||
$ctr_no = $_POST['ctr_no'] ?? '';
|
||||
$vat_no = $_POST['vat_no'] ?? '';
|
||||
|
||||
// Handle Logo Upload
|
||||
$logo = $company['logo'];
|
||||
if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
|
||||
$ext = pathinfo($_FILES['logo']['name'], PATHINFO_EXTENSION);
|
||||
$filename = 'logo_' . time() . '.' . $ext;
|
||||
$target = 'assets/images/company/' . $filename;
|
||||
if (move_uploaded_file($_FILES['logo']['tmp_name'], $target)) {
|
||||
$logo = $target;
|
||||
// Handle Logo Upload
|
||||
$logo = $company['logo'];
|
||||
if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
|
||||
$ext = pathinfo($_FILES['logo']['name'], PATHINFO_EXTENSION);
|
||||
$filename = 'logo_' . time() . '.' . $ext;
|
||||
$target = 'assets/images/company/' . $filename;
|
||||
if (move_uploaded_file($_FILES['logo']['tmp_name'], $target)) {
|
||||
$logo = $target;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Favicon Upload
|
||||
$favicon = $company['favicon'];
|
||||
if (isset($_FILES['favicon']) && $_FILES['favicon']['error'] === UPLOAD_ERR_OK) {
|
||||
$ext = pathinfo($_FILES['favicon']['name'], PATHINFO_EXTENSION);
|
||||
$filename = 'favicon_' . time() . '.' . $ext;
|
||||
$target = 'assets/images/company/' . $filename;
|
||||
if (move_uploaded_file($_FILES['favicon']['tmp_name'], $target)) {
|
||||
$favicon = $target;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = db()->prepare("UPDATE companies SET name_en = ?, name_ar = ?, logo = ?, favicon = ?, email = ?, phone = ?, address_en = ?, address_ar = ?, vat_number = ?, ctr_no = ?, vat_no = ? WHERE id = ?");
|
||||
$stmt->execute([$name_en, $name_ar, $logo, $favicon, $email, $phone, $address_en, $address_ar, $vat_number, $ctr_no, $vat_no, $company['id']]);
|
||||
$success = __('success_update');
|
||||
// Refresh data
|
||||
$stmt = db()->query("SELECT * FROM companies LIMIT 1");
|
||||
$company = $stmt->fetch();
|
||||
} catch (Exception $e) {
|
||||
$error = __('error_update') . ' ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Favicon Upload
|
||||
$favicon = $company['favicon'];
|
||||
if (isset($_FILES['favicon']) && $_FILES['favicon']['error'] === UPLOAD_ERR_OK) {
|
||||
$ext = pathinfo($_FILES['favicon']['name'], PATHINFO_EXTENSION);
|
||||
$filename = 'favicon_' . time() . '.' . $ext;
|
||||
$target = 'assets/images/company/' . $filename;
|
||||
if (move_uploaded_file($_FILES['favicon']['tmp_name'], $target)) {
|
||||
$favicon = $target;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = db()->prepare("UPDATE companies SET name_en = ?, name_ar = ?, logo = ?, favicon = ?, email = ?, phone = ?, address_en = ?, address_ar = ?, vat_number = ?, ctr_no = ?, vat_no = ? WHERE id = ?");
|
||||
$stmt->execute([$name_en, $name_ar, $logo, $favicon, $email, $phone, $address_en, $address_ar, $vat_number, $ctr_no, $vat_no, $company['id']]);
|
||||
$success = __('success_update');
|
||||
// Refresh data
|
||||
$stmt = db()->query("SELECT * FROM companies LIMIT 1");
|
||||
$company = $stmt->fetch();
|
||||
} catch (Exception $e) {
|
||||
$error = __('error_update') . ' ' . $e->getMessage();
|
||||
// Handle WhatsApp Settings Save
|
||||
if ($is_super && isset($_POST['save_whatsapp_settings'])) {
|
||||
set_setting('whatsapp_enabled', $_POST['whatsapp_enabled'] ?? '0');
|
||||
set_setting('wablas_token', $_POST['wablas_token'] ?? '');
|
||||
set_setting('wablas_server', $_POST['wablas_server'] ?? '');
|
||||
set_setting('wablas_security_key', $_POST['wablas_security_key'] ?? '');
|
||||
set_setting('msg_order_created_ar', $_POST['msg_order_created_ar'] ?? '');
|
||||
set_setting('msg_order_ready_ar', $_POST['msg_order_ready_ar'] ?? '');
|
||||
set_setting('msg_payment_ar', $_POST['msg_payment_ar'] ?? '');
|
||||
$success = is_arabic() ? 'تم حفظ إعدادات الواتساب بنجاح' : 'WhatsApp settings saved successfully';
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,16 +91,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<div class="alert alert-danger"><?= $error ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card p-4">
|
||||
<div class="card p-4 mb-4 shadow-sm" style="border-radius: 20px;">
|
||||
<h5 class="fw-bold mb-4"><i class="bi bi-building me-2"></i> <?= is_arabic() ? 'معلومات الشركة' : 'Company Information' ?></h5>
|
||||
<form action="company_profile.php" method="POST" enctype="multipart/form-data">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label"><?= __('name_en') ?></label>
|
||||
<input type="text" name="name_en" class="form-control" value="<?= htmlspecialchars($company['name_en']) ?>" required>
|
||||
<input type="text" name="name_en" class="form-control" value="<?= htmlspecialchars($company['name_en'] ?? '') ?>" required>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label"><?= __('name_ar') ?></label>
|
||||
<input type="text" name="name_ar" class="form-control" value="<?= htmlspecialchars($company['name_ar']) ?>" required>
|
||||
<input type="text" name="name_ar" class="form-control" value="<?= htmlspecialchars($company['name_ar'] ?? '') ?>" required>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label"><?= __('email') ?></label>
|
||||
@ -131,9 +147,59 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-end">
|
||||
<button type="submit" class="btn btn-primary px-5"><?= __('save_changes') ?></button>
|
||||
<button type="submit" name="save_company_profile" class="btn btn-primary px-5" style="border-radius: 12px;">
|
||||
<i class="bi bi-save me-2"></i> <?= __('save_changes') ?>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php if ($is_super): ?>
|
||||
<div class="card p-4 shadow-sm" style="border-radius: 20px;">
|
||||
<h5 class="fw-bold mb-4"><i class="bi bi-whatsapp text-success me-2"></i> <?= __('whatsapp_settings') ?></h5>
|
||||
<form method="POST">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-12">
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input class="form-check-input" type="checkbox" id="whatsapp_enabled" name="whatsapp_enabled" value="1" <?= get_setting('whatsapp_enabled') == '1' ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="whatsapp_enabled"><?= __('whatsapp_enabled') ?></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold"><?= __('wablas_token') ?></label>
|
||||
<input type="text" class="form-control" name="wablas_token" value="<?= htmlspecialchars(get_setting('wablas_token', '')) ?>" placeholder="Wablas API Token">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold"><?= __('wablas_server') ?></label>
|
||||
<input type="text" class="form-control" name="wablas_server" value="<?= htmlspecialchars(get_setting('wablas_server', 'https://console.wablas.com')) ?>" placeholder="https://console.wablas.com">
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label class="form-label fw-semibold"><?= __('wablas_security_key') ?></label>
|
||||
<input type="text" class="form-control" name="wablas_security_key" value="<?= htmlspecialchars(get_setting('wablas_security_key', '')) ?>" placeholder="Wablas Security Key">
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label class="form-label fw-semibold"><?= __('msg_order_created_ar') ?></label>
|
||||
<textarea class="form-control mb-2" name="msg_order_created_ar" rows="2"><?= htmlspecialchars(get_setting('msg_order_created_ar', '')) ?></textarea>
|
||||
<small class="text-muted">Tags: {customer_name}, {order_number}, {order_details}, {total_price}</small>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label class="form-label fw-semibold"><?= __('msg_order_ready_ar') ?></label>
|
||||
<textarea class="form-control mb-2" name="msg_order_ready_ar" rows="2"><?= htmlspecialchars(get_setting('msg_order_ready_ar', '')) ?></textarea>
|
||||
<small class="text-muted">Tags: {customer_name}, {order_number}</small>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label class="form-label fw-semibold"><?= __('msg_payment_ar') ?></label>
|
||||
<textarea class="form-control mb-2" name="msg_payment_ar" rows="2"><?= htmlspecialchars(get_setting('msg_payment_ar', '')) ?></textarea>
|
||||
<small class="text-muted">Tags: {customer_name}, {order_number}, {amount}, {remaining_balance}</small>
|
||||
</div>
|
||||
<div class="col-12 mt-4">
|
||||
<button type="submit" name="save_whatsapp_settings" class="btn btn-primary px-4 py-2" style="border-radius: 12px;">
|
||||
<i class="bi bi-save me-2"></i> <?= is_arabic() ? 'حفظ' : 'Save' ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
@ -200,6 +200,20 @@ if ($current_user_id && $current_page !== 'login.php' && $current_page !== 'logo
|
||||
.dropdown-toggle {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.whatsapp-toggle-btn {
|
||||
transition: all 0.3s;
|
||||
border: 2px solid #e9ecef;
|
||||
background: #fff;
|
||||
}
|
||||
.whatsapp-toggle-btn.active {
|
||||
border-color: #25D366;
|
||||
color: #25D366;
|
||||
background: rgba(37, 211, 102, 0.1);
|
||||
}
|
||||
.whatsapp-toggle-btn:not(.active) {
|
||||
color: #6c757d;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -303,7 +317,7 @@ if ($current_user_id && $current_page !== 'login.php' && $current_page !== 'logo
|
||||
<?php if (has_permission('view', 'company_profile.php')): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'company_profile.php' ? 'active' : '' ?>" href="company_profile.php">
|
||||
<i class="bi bi-building"></i>
|
||||
<i class="bi bi-gear"></i>
|
||||
<?= __('company_profile') ?>
|
||||
</a>
|
||||
</li>
|
||||
@ -327,6 +341,57 @@ if ($current_user_id && $current_page !== 'login.php' && $current_page !== 'logo
|
||||
<h1 class="h2"><?= __($title ?? 'dashboard') ?></h1>
|
||||
<div class="mb-2 mb-md-0">
|
||||
<div class="d-flex align-items-center">
|
||||
<?php if ($current_role === 'super_admin'): ?>
|
||||
<?php $is_whatsapp_enabled = get_setting('whatsapp_enabled') == '1'; ?>
|
||||
<button id="global_whatsapp_toggle_btn" class="btn btn-sm rounded-pill px-3 me-3 whatsapp-toggle-btn <?= $is_whatsapp_enabled ? 'active' : '' ?>" style="height: 38px; display: flex; align-items: center; font-weight: 600;">
|
||||
<i class="bi <?= $is_whatsapp_enabled ? 'bi-whatsapp' : 'bi-chat-left-dots' ?> me-2"></i>
|
||||
<span><?= $is_whatsapp_enabled ? __('messages_enabled') : __('messages_disabled') ?></span>
|
||||
</button>
|
||||
|
||||
<script>
|
||||
document.getElementById('global_whatsapp_toggle_btn').addEventListener('click', function() {
|
||||
const btn = this;
|
||||
const isActive = btn.classList.contains('active');
|
||||
const newValue = isActive ? '0' : '1';
|
||||
const span = btn.querySelector('span');
|
||||
const icon = btn.querySelector('i');
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('key', 'whatsapp_enabled');
|
||||
formData.append('value', newValue);
|
||||
|
||||
fetch('api/update_setting.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
if (newValue === '1') {
|
||||
btn.classList.add('active');
|
||||
span.textContent = '<?= __('messages_enabled') ?>';
|
||||
icon.className = 'bi bi-whatsapp me-2';
|
||||
} else {
|
||||
btn.classList.remove('active');
|
||||
span.textContent = '<?= __('messages_disabled') ?>';
|
||||
icon.className = 'bi bi-chat-left-dots me-2';
|
||||
}
|
||||
|
||||
// Sync with settings page toggle if it exists
|
||||
const settingsToggle = document.getElementById('whatsapp_enabled');
|
||||
if (settingsToggle) settingsToggle.checked = (newValue === '1');
|
||||
} else {
|
||||
alert('Error: ' + data.error);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Network error updating setting');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (count($user_branches) > 1 || $current_role === 'super_admin'): ?>
|
||||
<div class="dropdown me-2">
|
||||
<button class="btn btn-sm btn-outline-primary dropdown-toggle rounded-pill px-3" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
@ -393,7 +458,7 @@ if ($current_user_id && $current_page !== 'login.php' && $current_page !== 'logo
|
||||
<?php if (has_permission('view', 'company_profile.php')): ?>
|
||||
<li>
|
||||
<a class="dropdown-item py-2" href="company_profile.php">
|
||||
<i class="bi bi-building"></i> <?= __('company_profile') ?>
|
||||
<i class="bi bi-gear"></i> <?= __('company_profile') ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
|
||||
@ -18,7 +18,9 @@ $translations = [
|
||||
'branches' => 'Branches',
|
||||
'users' => 'Users',
|
||||
'settings' => 'Settings',
|
||||
'whatsapp_settings' => 'WhatsApp Settings', 'whatsapp_enabled' => 'WhatsApp Enabled', 'wablas_token' => 'Wablas API Token', 'wablas_server' => 'Wablas Server URL', 'msg_order_created_ar' => 'Order Created Message (Arabic)', 'msg_order_ready_ar' => 'Order Ready Message (Arabic)', 'msg_payment_ar' => 'Payment Received Message (Arabic)',
|
||||
'whatsapp_settings' => 'WhatsApp Settings', 'whatsapp_enabled' => 'WhatsApp Enabled', 'wablas_token' => 'Wablas API Token', 'wablas_server' => 'Wablas Server URL', 'wablas_security_key' => 'Wablas Security Key', 'msg_order_created_ar' => 'Order Created Message (Arabic)', 'msg_order_ready_ar' => 'Order Ready Message (Arabic)', 'msg_payment_ar' => 'Payment Received Message (Arabic)',
|
||||
'messages_enabled' => 'Messages Enabled',
|
||||
'messages_disabled' => 'Messages Disabled',
|
||||
'logout' => 'Logout',
|
||||
'login' => 'Login',
|
||||
'username' => 'Username',
|
||||
@ -97,7 +99,7 @@ $translations = [
|
||||
'no_items_found' => 'No items found',
|
||||
'pricing_management' => 'Pricing Management',
|
||||
'are_you_sure' => 'Are you sure?',
|
||||
'company_profile' => 'Company Profile',
|
||||
'company_profile' => 'Settings',
|
||||
'user_profile' => 'User Profile',
|
||||
'logo' => 'Logo',
|
||||
'favicon' => 'Aيقونة الموقع',
|
||||
@ -207,7 +209,9 @@ $translations = [
|
||||
'branches' => 'الفروع',
|
||||
'users' => 'المستخدمين',
|
||||
'settings' => 'الإعدادات',
|
||||
'whatsapp_settings' => 'إعدادات الواتساب', 'whatsapp_enabled' => 'تفعيل الواتساب', 'wablas_token' => 'رمز API Wablas', 'wablas_server' => 'رابط خادم Wablas', 'msg_order_created_ar' => 'رسالة إنشاء الطلب (بالعربية)', 'msg_order_ready_ar' => 'رسالة الطلب جاهز (بالعربية)', 'msg_payment_ar' => 'رسالة استلام الدفعة (بالعربية)',
|
||||
'whatsapp_settings' => 'إعدادات الواتساب', 'whatsapp_enabled' => 'تفعيل الواتساب', 'wablas_token' => 'رمز API Wablas', 'wablas_server' => 'رابط خادم Wablas', 'wablas_security_key' => 'مفتاح الأمان Wablas', 'msg_order_created_ar' => 'رسالة إنشاء الطلب (بالعربية)', 'msg_order_ready_ar' => 'رسالة الطلب جاهز (بالعربية)', 'msg_payment_ar' => 'رسالة استلام الدفعة (بالعربية)',
|
||||
'messages_enabled' => 'الرسائل مفعلة',
|
||||
'messages_disabled' => 'الرسائل معطلة',
|
||||
'logout' => 'تسجيل الخروج',
|
||||
'login' => 'تسجيل الدخول',
|
||||
'username' => 'اسم المستخدم',
|
||||
@ -286,7 +290,7 @@ $translations = [
|
||||
'no_items_found' => 'لا يوجد أصناف',
|
||||
'pricing_management' => 'إدارة الأسعار',
|
||||
'are_you_sure' => 'هل أنت متأكد؟',
|
||||
'company_profile' => 'ملف الشركة',
|
||||
'company_profile' => 'الإعدادات',
|
||||
'user_profile' => 'ملف المستخدم',
|
||||
'logo' => 'الشعار',
|
||||
'favicon' => 'أيقونة الموقع',
|
||||
|
||||
@ -8,22 +8,25 @@ function send_whatsapp_message($phone, $message) {
|
||||
|
||||
$token = get_setting('wablas_token');
|
||||
$server = get_setting('wablas_server', 'https://console.wablas.com');
|
||||
$security_key = get_setting('wablas_security_key');
|
||||
|
||||
if (empty($token) || empty($server)) {
|
||||
return ['success' => false, 'error' => 'Wablas configuration is incomplete'];
|
||||
}
|
||||
|
||||
// Clean phone number (ensure it has country code, e.g., 966 for Saudi Arabia if not provided)
|
||||
// For now, assume user provides it or we just use it as is if it looks correct.
|
||||
// Clean phone number
|
||||
$phone = preg_replace('/[^0-9]/', '', $phone);
|
||||
|
||||
// Wablas API expects phone number.
|
||||
$curl = curl_init();
|
||||
$data = [
|
||||
'phone' => $phone,
|
||||
'message' => $message,
|
||||
];
|
||||
|
||||
if (!empty($security_key)) {
|
||||
$data['security_key'] = $security_key;
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: $token",
|
||||
]);
|
||||
@ -48,4 +51,4 @@ function send_whatsapp_message($phone, $message) {
|
||||
}
|
||||
|
||||
return ['success' => false, 'error' => $response['message'] ?? 'Unknown error from Wablas'];
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user