39496-vm/admin_integrations.php
2026-04-06 05:37:02 +00:00

257 lines
15 KiB
PHP

<?php
// admin_integrations.php
if (!isset($pdo)) {
$pdo = db();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if ($_POST['action'] === 'save_wablas') {
$domain = $_POST['wablas_domain'] ?? '';
$token = $_POST['wablas_token'] ?? '';
$security_key = $_POST['wablas_security_key'] ?? '';
$stmt = $pdo->prepare("UPDATE platform_profile SET wablas_domain = :domain, wablas_token = :token, wablas_security_key = :security_key WHERE id = 1");
$stmt->execute([
'domain' => $domain,
'token' => $token,
'security_key' => $security_key
]);
header('Location: ' . app_url('admin.php', ['page' => 'integrations', 'tab' => 'wablas', 'saved' => 1]));
exit;
}
if ($_POST['action'] === 'save_thawani') {
$secret = $_POST['thawani_secret_key'] ?? '';
$publishable = $_POST['thawani_publishable_key'] ?? '';
$mode = $_POST['thawani_mode'] ?? 'test';
$stmt = $pdo->prepare("UPDATE platform_profile SET thawani_secret_key = :secret, thawani_publishable_key = :publishable, thawani_mode = :mode WHERE id = 1");
$stmt->execute([
'secret' => $secret,
'publishable' => $publishable,
'mode' => $mode
]);
header('Location: ' . app_url('admin.php', ['page' => 'integrations', 'tab' => 'thawani', 'saved' => 1]));
exit;
}
if ($_POST['action'] === 'save_smtp') {
$smtp_host = $_POST['smtp_host'] ?? '';
$smtp_port = $_POST['smtp_port'] ?? '';
$smtp_secure = $_POST['smtp_secure'] ?? '';
$smtp_user = $_POST['smtp_user'] ?? '';
$smtp_pass = $_POST['smtp_pass'] ?? '';
$smtp_from_email = $_POST['smtp_from_email'] ?? '';
$smtp_from_name = $_POST['smtp_from_name'] ?? '';
$stmt = $pdo->prepare("UPDATE platform_profile SET
smtp_host = :smtp_host,
smtp_port = :smtp_port,
smtp_secure = :smtp_secure,
smtp_user = :smtp_user,
smtp_pass = :smtp_pass,
smtp_from_email = :smtp_from_email,
smtp_from_name = :smtp_from_name
WHERE id = 1");
$stmt->execute([
'smtp_host' => $smtp_host,
'smtp_port' => $smtp_port,
'smtp_secure' => $smtp_secure,
'smtp_user' => $smtp_user,
'smtp_pass' => $smtp_pass,
'smtp_from_email' => $smtp_from_email,
'smtp_from_name' => $smtp_from_name
]);
header('Location: ' . app_url('admin.php', ['page' => 'integrations', 'tab' => 'smtp', 'saved' => 1]));
exit;
}
}
$stmt = $pdo->query("SELECT * FROM platform_profile WHERE id = 1");
$prof = $stmt->fetch(PDO::FETCH_ASSOC) ?: [];
$thawani_mode = $prof['thawani_mode'] ?? 'test';
$smtp_secure = $prof['smtp_secure'] ?? 'tls';
$active_tab = $_GET['tab'] ?? 'wablas';
?>
<div class="section-header mb-4">
<div>
<span class="eyebrow"><?= h(t('Settings', 'الإعدادات')) ?></span>
<h1 class="section-title mb-2"><?= h(t('All Integrations', 'كل التكاملات')) ?></h1>
<p class="text-secondary mb-0"><?= h(t('Manage your gateway and email configurations here.', 'قم بإدارة إعدادات البوابات والبريد الإلكتروني هنا.')) ?></p>
</div>
</div>
<?php if (!empty($_GET['saved'])): ?>
<div class="alert alert-success"><?= h(t('Settings updated successfully.', 'تم تحديث الإعدادات بنجاح.')) ?></div>
<?php endif; ?>
<div class="panel-card p-0 mb-4">
<div class="card-header bg-white border-bottom pt-3 pb-0 px-4">
<ul class="nav nav-tabs border-bottom-0" id="integrationsTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link <?= $active_tab === 'wablas' ? 'active text-primary fw-bold' : 'text-secondary' ?>" id="wablas-tab" data-bs-toggle="tab" data-bs-target="#wablas-pane" type="button" role="tab" style="<?= $active_tab === 'wablas' ? 'border-bottom: 2px solid var(--accent); color: var(--accent) !important;' : '' ?>">
<?= h(t('Wablas', 'Wablas')) ?>
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link <?= $active_tab === 'thawani' ? 'active text-primary fw-bold' : 'text-secondary' ?>" id="thawani-tab" data-bs-toggle="tab" data-bs-target="#thawani-pane" type="button" role="tab" style="<?= $active_tab === 'thawani' ? 'border-bottom: 2px solid var(--accent); color: var(--accent) !important;' : '' ?>">
<?= h(t('Thawani', 'Thawani')) ?>
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link <?= $active_tab === 'smtp' ? 'active text-primary fw-bold' : 'text-secondary' ?>" id="smtp-tab" data-bs-toggle="tab" data-bs-target="#smtp-pane" type="button" role="tab" style="<?= $active_tab === 'smtp' ? 'border-bottom: 2px solid var(--accent); color: var(--accent) !important;' : '' ?>">
<?= h(t('SMTP Mail', 'بريد SMTP')) ?>
</button>
</li>
</ul>
</div>
<div class="card-body p-4">
<div class="tab-content" id="integrationsTabsContent">
<!-- WABLAS TAB -->
<div class="tab-pane fade <?= $active_tab === 'wablas' ? 'show active' : '' ?>" id="wablas-pane" role="tabpanel">
<form method="post">
<input type="hidden" name="action" value="save_wablas">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label fw-medium"><?= h(t('Wablas Domain / URL', 'نطاق Wablas / الرابط')) ?></label>
<input type="text" name="wablas_domain" class="form-control" value="<?= h($prof['wablas_domain'] ?? '') ?>" placeholder="e.g. https://solo.wablas.com">
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-medium"><?= h(t('API Token', 'رمز API')) ?></label>
<input type="password" name="wablas_token" class="form-control" value="<?= h($prof['wablas_token'] ?? '') ?>" placeholder="Your Wablas API token">
</div>
<div class="col-md-12 mb-4">
<label class="form-label fw-medium"><?= h(t('Security Key', 'مفتاح الأمان')) ?></label>
<input type="password" name="wablas_security_key" class="form-control" value="<?= h($prof['wablas_security_key'] ?? '') ?>" placeholder="Your Wablas Security Key">
</div>
</div>
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-primary px-4" style="background-color: var(--accent); border-color: var(--accent);">
<?= h(t('Save Wablas Settings', 'حفظ إعدادات Wablas')) ?>
</button>
</div>
</form>
</div>
<!-- THAWANI TAB -->
<div class="tab-pane fade <?= $active_tab === 'thawani' ? 'show active' : '' ?>" id="thawani-pane" role="tabpanel">
<form method="post">
<input type="hidden" name="action" value="save_thawani">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label fw-medium"><?= h(t('Secret Key', 'المفتاح السري')) ?></label>
<input type="password" name="thawani_secret_key" class="form-control" value="<?= h($prof['thawani_secret_key'] ?? '') ?>" placeholder="sk_...">
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-medium"><?= h(t('Publishable Key', 'المفتاح القابل للنشر')) ?></label>
<input type="text" name="thawani_publishable_key" class="form-control" value="<?= h($prof['thawani_publishable_key'] ?? '') ?>" placeholder="pk_...">
</div>
<div class="col-md-12 mb-4">
<label class="form-label fw-medium"><?= h(t('Mode', 'الوضع')) ?></label>
<select name="thawani_mode" class="form-select">
<option value="test" <?= $thawani_mode === 'test' ? 'selected' : '' ?>><?= h(t('Test Mode', 'وضع الاختبار')) ?></option>
<option value="live" <?= $thawani_mode === 'live' ? 'selected' : '' ?>><?= h(t('Live Mode', 'الوضع الحي')) ?></option>
</select>
</div>
</div>
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-primary px-4" style="background-color: var(--accent); border-color: var(--accent);">
<?= h(t('Save Thawani Settings', 'حفظ إعدادات Thawani')) ?>
</button>
</div>
</form>
</div>
<!-- SMTP TAB -->
<div class="tab-pane fade <?= $active_tab === 'smtp' ? 'show active' : '' ?>" id="smtp-pane" role="tabpanel">
<form method="post">
<input type="hidden" name="action" value="save_smtp">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label fw-medium"><?= h(t('SMTP Host', 'خادم SMTP')) ?></label>
<input type="text" name="smtp_host" class="form-control" value="<?= h($prof['smtp_host'] ?? '') ?>" placeholder="e.g. smtp.example.com">
</div>
<div class="col-md-3 mb-3">
<label class="form-label fw-medium"><?= h(t('SMTP Port', 'منفذ SMTP')) ?></label>
<input type="text" name="smtp_port" class="form-control" value="<?= h($prof['smtp_port'] ?? '587') ?>" placeholder="587">
</div>
<div class="col-md-3 mb-3">
<label class="form-label fw-medium"><?= h(t('Encryption', 'التشفير')) ?></label>
<select name="smtp_secure" class="form-select">
<option value="tls" <?= $smtp_secure === 'tls' ? 'selected' : '' ?>>TLS</option>
<option value="ssl" <?= $smtp_secure === 'ssl' ? 'selected' : '' ?>>SSL</option>
<option value="" <?= $smtp_secure === '' ? 'selected' : '' ?>><?= h(t('None', 'لا يوجد')) ?></option>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-medium"><?= h(t('SMTP Username', 'اسم المستخدم (SMTP)')) ?></label>
<input type="text" name="smtp_user" class="form-control" value="<?= h($prof['smtp_user'] ?? '') ?>" placeholder="user@example.com">
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-medium"><?= h(t('SMTP Password', 'كلمة المرور (SMTP)')) ?></label>
<input type="password" name="smtp_pass" class="form-control" value="<?= h($prof['smtp_pass'] ?? '') ?>" placeholder="••••••••">
</div>
<div class="col-md-6 mb-4">
<label class="form-label fw-medium"><?= h(t('From Email', 'البريد الإلكتروني للمرسل')) ?></label>
<input type="email" name="smtp_from_email" class="form-control" value="<?= h($prof['smtp_from_email'] ?? '') ?>" placeholder="noreply@example.com">
</div>
<div class="col-md-6 mb-4">
<label class="form-label fw-medium"><?= h(t('From Name', 'اسم المرسل')) ?></label>
<input type="text" name="smtp_from_name" class="form-control" value="<?= h($prof['smtp_from_name'] ?? '') ?>" placeholder="My Platform">
</div>
</div>
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-primary px-4" style="background-color: var(--accent); border-color: var(--accent);">
<?= h(t('Save SMTP Settings', 'حفظ إعدادات SMTP')) ?>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
// Simple script to update URL when tabs are clicked so refresh keeps the same tab active
document.addEventListener('DOMContentLoaded', function () {
const tabs = document.querySelectorAll('button[data-bs-toggle="tab"]');
tabs.forEach(tab => {
tab.addEventListener('shown.bs.tab', function (event) {
const targetId = event.target.id;
let tabName = 'wablas';
if (targetId === 'thawani-tab') tabName = 'thawani';
if (targetId === 'smtp-tab') tabName = 'smtp';
// Update URL parameter without reloading
const url = new URL(window.location);
url.searchParams.set('tab', tabName);
// Remove 'saved' parameter to clear alert on tab switch
url.searchParams.delete('saved');
window.history.replaceState({}, '', url);
// Update styling logic manually to match inline active styles
tabs.forEach(t => {
t.style.borderBottom = '';
t.style.setProperty('color', 'var(--bs-secondary)', 'important');
t.classList.remove('text-primary', 'fw-bold');
t.classList.add('text-secondary');
});
event.target.style.borderBottom = '2px solid var(--accent)';
event.target.style.setProperty('color', 'var(--accent)', 'important');
event.target.classList.remove('text-secondary');
event.target.classList.add('text-primary', 'fw-bold');
});
});
});
</script>