307 lines
20 KiB
PHP
307 lines
20 KiB
PHP
<?php
|
|
$title = 'company_profile';
|
|
require_once __DIR__ . '/includes/header.php';
|
|
if ($current_role === 'limited_viewer') { header('Location: admin.php'); exit; }
|
|
|
|
if ($current_role !== 'super_admin') {
|
|
echo '<div class="alert alert-danger">' . __('Access Denied') . '</div>';
|
|
require_once __DIR__ . '/includes/footer.php';
|
|
exit;
|
|
}
|
|
|
|
$success = '';
|
|
$error = '';
|
|
$is_super = ($current_role === 'super_admin');
|
|
|
|
$stmt = db()->query("SELECT * FROM companies LIMIT 1");
|
|
$company = $stmt->fetch();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
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_no = $_POST['vat_no'] ?? '';
|
|
$ctr_no = $_POST['ctr_no'] ?? '';
|
|
|
|
$logo = $company['logo'];
|
|
if (isset($_FILES['logo']) && !empty($_FILES['logo']['name'])) {
|
|
if ($_FILES['logo']['error'] === UPLOAD_ERR_OK) {
|
|
$ext = pathinfo($_FILES['logo']['name'], PATHINFO_EXTENSION);
|
|
$filename = 'logo_' . time() . '.' . $ext;
|
|
$rel_path = 'assets/images/company/' . $filename;
|
|
$abs_path = __DIR__ . '/' . $rel_path;
|
|
if (!is_dir(dirname($abs_path))) mkdir(dirname($abs_path), 0775, true);
|
|
if (move_uploaded_file($_FILES['logo']['tmp_name'], $abs_path)) {
|
|
$logo = $rel_path;
|
|
} else {
|
|
$error .= "Failed to move uploaded logo. ";
|
|
}
|
|
} else {
|
|
$error .= "Error uploading logo (Code: " . $_FILES['logo']['error'] . "). ";
|
|
}
|
|
}
|
|
|
|
$favicon = $company['favicon'];
|
|
if (isset($_FILES['favicon']) && !empty($_FILES['favicon']['name'])) {
|
|
if ($_FILES['favicon']['error'] === UPLOAD_ERR_OK) {
|
|
$ext = pathinfo($_FILES['favicon']['name'], PATHINFO_EXTENSION);
|
|
$filename = 'favicon_' . time() . '.' . $ext;
|
|
$rel_path = 'assets/images/company/' . $filename;
|
|
$abs_path = __DIR__ . '/' . $rel_path;
|
|
if (!is_dir(dirname($abs_path))) mkdir(dirname($abs_path), 0775, true);
|
|
if (move_uploaded_file($_FILES['favicon']['tmp_name'], $abs_path)) {
|
|
$favicon = $rel_path;
|
|
} else {
|
|
$error .= "Failed to move uploaded favicon. ";
|
|
}
|
|
} else {
|
|
$error .= "Error uploading favicon (Code: " . $_FILES['favicon']['error'] . "). ";
|
|
}
|
|
}
|
|
|
|
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_no, $ctr_no, $vat_no, $company['id']]);
|
|
$success = __('success_update');
|
|
$stmt = db()->query("SELECT * FROM companies LIMIT 1");
|
|
$company = $stmt->fetch();
|
|
} catch (Exception $e) { $error = __('error_update') . ' ' . $e->getMessage(); }
|
|
}
|
|
|
|
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 = __('success_update');
|
|
}
|
|
|
|
if ($is_super && isset($_POST['save_loyalty_settings'])) {
|
|
set_setting('loyalty_enabled', $_POST['loyalty_enabled'] ?? '0');
|
|
set_setting('loyalty_points_per_currency', $_POST['loyalty_points_per_currency'] ?? '1');
|
|
set_setting('loyalty_currency_per_point', $_POST['loyalty_currency_per_point'] ?? '0.05');
|
|
$success = __('success_update');
|
|
}
|
|
|
|
if ($is_super && isset($_POST['save_smtp_settings'])) {
|
|
set_setting('smtp_host', $_POST['smtp_host'] ?? '');
|
|
set_setting('smtp_port', $_POST['smtp_port'] ?? '587');
|
|
set_setting('smtp_user', $_POST['smtp_user'] ?? '');
|
|
set_setting('smtp_pass', $_POST['smtp_pass'] ?? '');
|
|
set_setting('smtp_secure', $_POST['smtp_secure'] ?? 'tls');
|
|
$success = __('success_update');
|
|
}
|
|
}
|
|
|
|
// Ensure SMTP settings exist for display fallback
|
|
if ($is_super) {
|
|
if (get_setting('smtp_host') === null) {
|
|
$env_host = getenv('SMTP_HOST');
|
|
set_setting('smtp_host', $env_host !== false ? $env_host : '');
|
|
$env_port = getenv('SMTP_PORT');
|
|
set_setting('smtp_port', $env_port !== false ? $env_port : '587');
|
|
$env_user = getenv('SMTP_USER');
|
|
set_setting('smtp_user', $env_user !== false ? $env_user : '');
|
|
$env_pass = getenv('SMTP_PASS');
|
|
set_setting('smtp_pass', $env_pass !== false ? $env_pass : '');
|
|
$env_secure = getenv('SMTP_SECURE');
|
|
set_setting('smtp_secure', $env_secure !== false ? $env_secure : 'tls');
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="h3 mb-0"><?= __('company_profile') ?></h2>
|
|
</div>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success alert-dismissible fade show rounded-4 border-0 shadow-sm" role="alert">
|
|
<i class="bi bi-check-circle-fill me-2"></i> <?= $success ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger alert-dismissible fade show rounded-4 border-0 shadow-sm" role="alert">
|
|
<i class="bi bi-exclamation-triangle-fill me-2"></i> <?= $error ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<ul class="nav nav-pills mb-4" id="settingsTabs" role="tablist">
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link active px-4 rounded-pill me-2 fw-semibold" id="main-tab" data-bs-toggle="pill" data-bs-target="#main-settings" type="button" role="tab"><i class="bi bi-building me-2"></i> <?= is_arabic() ? 'الإعدادات العامة' : 'Main Settings' ?></button>
|
|
</li>
|
|
<?php if ($is_super): ?>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link px-4 rounded-pill me-2 fw-semibold" id="whatsapp-tab" data-bs-toggle="pill" data-bs-target="#whatsapp-settings" type="button" role="tab"><i class="bi bi-whatsapp me-2"></i> <?= __('whatsapp_settings') ?></button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link px-4 rounded-pill me-2 fw-semibold" id="loyalty-tab" data-bs-toggle="pill" data-bs-target="#loyalty-settings" type="button" role="tab"><i class="bi bi-star-fill me-2"></i> <?= __('loyalty_settings') ?></button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link px-4 rounded-pill fw-semibold" id="smtp-tab" data-bs-toggle="pill" data-bs-target="#smtp-settings" type="button" role="tab"><i class="bi bi-envelope me-2"></i> <?= __('smtp_settings') ?></button>
|
|
</li>
|
|
<?php endif; ?>
|
|
</ul>
|
|
|
|
<div class="tab-content" id="settingsTabsContent">
|
|
<!-- MAIN SETTINGS -->
|
|
<div class="tab-pane fade show active" id="main-settings" role="tabpanel">
|
|
<div class="card p-4 shadow-sm border-0" 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-4 mb-3"><label class="form-label small fw-bold"><?= __('name_en') ?></label><input type="text" name="name_en" class="form-control form-control-sm rounded-3" value="<?= htmlspecialchars($company['name_en'] ?? '') ?>" required></div>
|
|
<div class="col-md-4 mb-3"><label class="form-label small fw-bold"><?= __('name_ar') ?></label><input type="text" name="name_ar" class="form-control form-control-sm rounded-3" value="<?= htmlspecialchars($company['name_ar'] ?? '') ?>" required></div>
|
|
<div class="col-md-4 mb-3"><label class="form-label small fw-bold"><?= __('email') ?></label><input type="email" name="email" class="form-control form-control-sm rounded-3" value="<?= htmlspecialchars($company['email'] ?? '') ?>"></div>
|
|
<div class="col-md-4 mb-3"><label class="form-label small fw-bold"><?= __('phone') ?></label><input type="text" name="phone" class="form-control form-control-sm rounded-3" value="<?= htmlspecialchars($company['phone'] ?? '') ?>"></div>
|
|
<div class="col-md-4 mb-3"><label class="form-label small fw-bold"><?= __('ctr_no') ?></label><input type="text" name="ctr_no" class="form-control form-control-sm rounded-3" value="<?= htmlspecialchars($company['ctr_no'] ?? '') ?>"></div>
|
|
<div class="col-md-4 mb-3"><label class="form-label small fw-bold"><?= __('vat_no') ?></label><input type="text" name="vat_no" class="form-control form-control-sm rounded-3" value="<?= htmlspecialchars($company['vat_no'] ?? '') ?>"></div>
|
|
|
|
<div class="col-md-8 mb-3">
|
|
<div class="row">
|
|
<div class="col-md-6"><label class="form-label small fw-bold"><?= __('logo') ?></label><input type="file" name="logo" class="form-control form-control-sm rounded-3" accept="image/*"><?php if ($company['logo']): ?><img src="<?= $company['logo'] ?>" alt="Logo" class="mt-2 rounded border" style="max-height: 50px;"><?php endif; ?></div>
|
|
<div class="col-md-6"><label class="form-label small fw-bold"><?= __('favicon') ?></label><input type="file" name="favicon" class="form-control form-control-sm rounded-3" accept="image/*"><?php if ($company['favicon']): ?><img src="<?= $company['favicon'] ?>" alt="Favicon" class="mt-2 rounded border" style="max-height: 32px;"><?php endif; ?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3"><label class="form-label small fw-bold"><?= __('address_en') ?></label><textarea name="address_en" class="form-control form-control-sm rounded-3" rows="3"><?= htmlspecialchars($company['address_en'] ?? '') ?></textarea></div>
|
|
<div class="col-md-6 mb-3"><label class="form-label small fw-bold"><?= __('address_ar') ?></label><textarea name="address_ar" class="form-control form-control-sm rounded-3" rows="3"><?= htmlspecialchars($company['address_ar'] ?? '') ?></textarea></div>
|
|
</div>
|
|
<div class="text-end mt-2"><button type="submit" name="save_company_profile" class="btn btn-primary px-5 rounded-4 shadow-sm"><i class="bi bi-save me-2"></i> <?= __('save_changes') ?></button></div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($is_super): ?>
|
|
<!-- WHATSAPP SETTINGS -->
|
|
<div class="tab-pane fade" id="whatsapp-settings" role="tabpanel">
|
|
<div class="card p-4 shadow-sm border-0 mb-4" 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="form-check form-switch mb-4">
|
|
<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 fw-semibold" for="whatsapp_enabled"><?= __('whatsapp_enabled') ?></label>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-4 mb-3"><label class="form-label small fw-bold"><?= __('wablas_token') ?></label><input type="text" class="form-control form-control-sm rounded-3" name="wablas_token" value="<?= htmlspecialchars(get_setting('wablas_token', '')) ?>"></div>
|
|
<div class="col-md-4 mb-3"><label class="form-label small fw-bold"><?= __('wablas_server') ?></label><input type="text" class="form-control form-control-sm rounded-3" name="wablas_server" value="<?= htmlspecialchars(get_setting('wablas_server', 'https://console.wablas.com')) ?>"></div>
|
|
<div class="col-md-4 mb-4"><label class="form-label small fw-bold"><?= __('wablas_security_key') ?></label><input type="text" class="form-control form-control-sm rounded-3" name="wablas_security_key" value="<?= htmlspecialchars(get_setting('wablas_security_key', '')) ?>"></div>
|
|
</div>
|
|
|
|
<hr class="text-muted opacity-25 my-4">
|
|
|
|
<h5 class="fw-bold mb-3 mt-3"><i class="bi bi-chat-dots me-2"></i> <?= is_arabic() ? 'قوالب الرسائل' : 'Message Templates' ?></h5>
|
|
<div class="row">
|
|
<div class="col-md-4 mb-3">
|
|
<label class="form-label small fw-bold"><?= __('msg_order_created_ar') ?></label>
|
|
<textarea class="form-control form-control-sm rounded-3 mb-1" name="msg_order_created_ar" rows="4"><?= htmlspecialchars(get_setting('msg_order_created_ar', '')) ?></textarea>
|
|
<small class="text-muted" style="font-size: 0.75rem;">Tags: {customer_name}, {order_number}, {order_details}, {total_price}</small>
|
|
</div>
|
|
<div class="col-md-4 mb-3">
|
|
<label class="form-label small fw-bold"><?= __('msg_order_ready_ar') ?></label>
|
|
<textarea class="form-control form-control-sm rounded-3 mb-1" name="msg_order_ready_ar" rows="4"><?= htmlspecialchars(get_setting('msg_order_ready_ar', '')) ?></textarea>
|
|
<small class="text-muted" style="font-size: 0.75rem;">Tags: {customer_name}, {order_number}</small>
|
|
</div>
|
|
<div class="col-md-4 mb-4">
|
|
<label class="form-label small fw-bold"><?= __('msg_payment_ar') ?></label>
|
|
<textarea class="form-control form-control-sm rounded-3 mb-1" name="msg_payment_ar" rows="4"><?= htmlspecialchars(get_setting('msg_payment_ar', '')) ?></textarea>
|
|
<small class="text-muted" style="font-size: 0.75rem;">Tags: {customer_name}, {order_number}, {amount}, {remaining_balance}</small>
|
|
</div>
|
|
</div>
|
|
<div class="text-end"><button type="submit" name="save_whatsapp_settings" class="btn btn-primary px-4 rounded-3 shadow-sm"><?= __('save') ?></button></div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- LOYALTY SETTINGS -->
|
|
<div class="tab-pane fade" id="loyalty-settings" role="tabpanel">
|
|
<div class="card p-4 shadow-sm border-0 mb-4" style="border-radius: 20px;">
|
|
<h5 class="fw-bold mb-4"><i class="bi bi-star-fill text-warning me-2"></i> <?= __('loyalty_settings') ?></h5>
|
|
<form method="POST">
|
|
<div class="form-check form-switch mb-4">
|
|
<input class="form-check-input" type="checkbox" id="loyalty_enabled" name="loyalty_enabled" value="1" <?= get_setting('loyalty_enabled') == '1' ? 'checked' : '' ?>>
|
|
<label class="form-check-label fw-semibold" for="loyalty_enabled"><?= __('loyalty_enabled') ?></label>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-4 mb-3">
|
|
<label class="form-label small fw-bold"><?= __('loyalty_points_per_currency') ?></label>
|
|
<input type="number" step="0.01" class="form-control form-control-sm rounded-3" name="loyalty_points_per_currency" value="<?= htmlspecialchars(get_setting('loyalty_points_per_currency', '1')) ?>">
|
|
</div>
|
|
<div class="col-md-4 mb-4">
|
|
<label class="form-label small fw-bold"><?= __('loyalty_currency_per_point') ?></label>
|
|
<input type="number" step="0.001" class="form-control form-control-sm rounded-3" name="loyalty_currency_per_point" value="<?= htmlspecialchars(get_setting('loyalty_currency_per_point', '0.05')) ?>">
|
|
</div>
|
|
</div>
|
|
<div class="text-end"><button type="submit" name="save_loyalty_settings" class="btn btn-primary px-4 rounded-3 shadow-sm"><?= __('save') ?></button></div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- SMTP SETTINGS -->
|
|
<div class="tab-pane fade" id="smtp-settings" role="tabpanel">
|
|
<div class="card p-4 shadow-sm border-0 mb-4" style="border-radius: 20px;">
|
|
<h5 class="fw-bold mb-4"><i class="bi bi-envelope text-primary me-2"></i> <?= __('smtp_settings') ?></h5>
|
|
<form method="POST">
|
|
<div class="row">
|
|
<div class="col-md-4 mb-3">
|
|
<label class="form-label small fw-bold"><?= __('smtp_host') ?></label>
|
|
<input type="text" class="form-control form-control-sm rounded-3" name="smtp_host" value="<?= htmlspecialchars(get_setting('smtp_host', '')) ?>">
|
|
</div>
|
|
<div class="col-md-4 mb-3">
|
|
<label class="form-label small fw-bold"><?= __('smtp_port') ?></label>
|
|
<input type="number" class="form-control form-control-sm rounded-3" name="smtp_port" value="<?= htmlspecialchars(get_setting('smtp_port', '587')) ?>">
|
|
</div>
|
|
<div class="col-md-4 mb-3">
|
|
<label class="form-label small fw-bold"><?= __('smtp_secure') ?></label>
|
|
<select class="form-select form-select-sm rounded-3" name="smtp_secure">
|
|
<option value="tls" <?= get_setting('smtp_secure', 'tls') == 'tls' ? 'selected' : '' ?>>TLS</option>
|
|
<option value="ssl" <?= get_setting('smtp_secure') == 'ssl' ? 'selected' : '' ?>>SSL</option>
|
|
<option value="" <?= get_setting('smtp_secure') == '' ? 'selected' : '' ?>>None</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4 mb-4">
|
|
<label class="form-label small fw-bold"><?= __('smtp_user') ?></label>
|
|
<input type="text" class="form-control form-control-sm rounded-3" name="smtp_user" value="<?= htmlspecialchars(get_setting('smtp_user', '')) ?>">
|
|
</div>
|
|
<div class="col-md-4 mb-4">
|
|
<label class="form-label small fw-bold"><?= __('smtp_pass') ?></label>
|
|
<input type="password" class="form-control form-control-sm rounded-3" name="smtp_pass" value="<?= htmlspecialchars(get_setting('smtp_pass', '')) ?>">
|
|
</div>
|
|
</div>
|
|
<div class="text-end"><button type="submit" name="save_smtp_settings" class="btn btn-primary px-4 rounded-3 shadow-sm"><?= __('save') ?></button></div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<script>
|
|
// Save active tab in localStorage
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
let activeTab = localStorage.getItem('activeSettingsTab');
|
|
if (activeTab) {
|
|
let tabEl = document.querySelector('button[data-bs-target="' + activeTab + '"]');
|
|
if (tabEl) {
|
|
let tab = new bootstrap.Tab(tabEl);
|
|
tab.show();
|
|
}
|
|
}
|
|
document.querySelectorAll('button[data-bs-toggle="pill"]').forEach(function(el) {
|
|
el.addEventListener('shown.bs.tab', function(e) {
|
|
localStorage.setItem('activeSettingsTab', e.target.getAttribute('data-bs-target'));
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|