236 lines
12 KiB
PHP
236 lines
12 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/includes/layout.php';
|
|
|
|
ensure_schema();
|
|
|
|
$errors = [];
|
|
$success = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$companyName = trim($_POST['company_name'] ?? '');
|
|
$companyEmail = trim($_POST['company_email'] ?? '');
|
|
$companyPhone = trim($_POST['company_phone'] ?? '');
|
|
$companyAddress = trim($_POST['company_address'] ?? '');
|
|
$platformCharge = trim($_POST['platform_charge_percentage'] ?? '0');
|
|
|
|
$updates = [
|
|
'company_name' => $companyName,
|
|
'company_email' => $companyEmail,
|
|
'company_phone' => $companyPhone,
|
|
'company_address' => $companyAddress,
|
|
'platform_charge_percentage' => $platformCharge,
|
|
'terms_en' => trim($_POST['terms_en'] ?? ''),
|
|
'terms_ar' => trim($_POST['terms_ar'] ?? ''),
|
|
'privacy_en' => trim($_POST['privacy_en'] ?? ''),
|
|
'privacy_ar' => trim($_POST['privacy_ar'] ?? ''),
|
|
];
|
|
|
|
// Handle file uploads
|
|
$uploadDir = __DIR__ . '/uploads/logos/';
|
|
if (!is_dir($uploadDir)) {
|
|
mkdir($uploadDir, 0775, true);
|
|
}
|
|
|
|
if (isset($_FILES['logo_file']) && $_FILES['logo_file']['error'] === UPLOAD_ERR_OK) {
|
|
$tmpName = $_FILES['logo_file']['tmp_name'];
|
|
$ext = strtolower(pathinfo($_FILES['logo_file']['name'], PATHINFO_EXTENSION));
|
|
$allowedExt = ['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp'];
|
|
if (in_array($ext, $allowedExt, true)) {
|
|
$logoName = 'logo_' . time() . '.' . $ext;
|
|
$dest = $uploadDir . $logoName;
|
|
if (move_uploaded_file($tmpName, $dest)) {
|
|
$updates['logo_path'] = '/uploads/logos/' . $logoName;
|
|
}
|
|
} else {
|
|
$errors[] = "Invalid logo format.";
|
|
}
|
|
}
|
|
|
|
if (isset($_FILES['favicon_file']) && $_FILES['favicon_file']['error'] === UPLOAD_ERR_OK) {
|
|
$tmpName = $_FILES['favicon_file']['tmp_name'];
|
|
$ext = strtolower(pathinfo($_FILES['favicon_file']['name'], PATHINFO_EXTENSION));
|
|
$allowedExt = ['ico', 'png', 'svg', 'gif'];
|
|
if (in_array($ext, $allowedExt, true)) {
|
|
$faviconName = 'favicon_' . time() . '.' . $ext;
|
|
$dest = $uploadDir . $faviconName;
|
|
if (move_uploaded_file($tmpName, $dest)) {
|
|
$updates['favicon_path'] = '/uploads/logos/' . $faviconName;
|
|
}
|
|
} else {
|
|
$errors[] = "Invalid favicon format.";
|
|
}
|
|
}
|
|
|
|
if (empty($errors)) {
|
|
$pdo = db();
|
|
foreach ($updates as $key => $val) {
|
|
$stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (:k, :v) ON DUPLICATE KEY UPDATE setting_value = :v2");
|
|
$stmt->execute([':k' => $key, ':v' => $val, ':v2' => $val]);
|
|
}
|
|
$success = "Company profile updated successfully.";
|
|
}
|
|
}
|
|
|
|
// Fetch current settings
|
|
$settings = get_settings();
|
|
$currentName = $settings['company_name'] ?? t('app_name');
|
|
$currentEmail = $settings['company_email'] ?? '';
|
|
$currentPhone = $settings['company_phone'] ?? '';
|
|
$currentAddress = $settings['company_address'] ?? '';
|
|
$currentPlatformCharge = $settings['platform_charge_percentage'] ?? '0';
|
|
$currentLogo = $settings['logo_path'] ?? '';
|
|
$currentFavicon = $settings['favicon_path'] ?? '';
|
|
$currentTermsEn = $settings['terms_en'] ?? '';
|
|
$currentTermsAr = $settings['terms_ar'] ?? '';
|
|
$currentPrivacyEn = $settings['privacy_en'] ?? '';
|
|
$currentPrivacyAr = $settings['privacy_ar'] ?? '';
|
|
|
|
render_header('Company Profile', 'admin', true);
|
|
?>
|
|
|
|
<div class="row g-0">
|
|
<div class="col-md-2 bg-white border-end min-vh-100">
|
|
<?php render_admin_sidebar('company_profile'); ?>
|
|
</div>
|
|
<div class="col-md-10 p-4">
|
|
<div class="page-intro mb-4">
|
|
<h1 class="section-title mb-1">Company Profile</h1>
|
|
<p class="muted mb-0">Update your app name, logo, favicon, contact details, platform charge, and legal policies.</p>
|
|
</div>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success"><?= e($success) ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($errors): ?>
|
|
<div class="alert alert-danger"><?= e(implode('<br>', $errors)) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="panel p-4">
|
|
<form method="post" enctype="multipart/form-data">
|
|
<ul class="nav nav-tabs mb-4" id="companySettingsTab" role="tablist">
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link active" id="company-tab" data-bs-toggle="tab" data-bs-target="#company" type="button" role="tab" aria-controls="company" aria-selected="true">
|
|
<i class="bi bi-building me-2"></i>Company Setting
|
|
</button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link" id="legal-tab" data-bs-toggle="tab" data-bs-target="#legal" type="button" role="tab" aria-controls="legal" aria-selected="false">
|
|
<i class="bi bi-file-earmark-text me-2"></i>Legal & Policies
|
|
</button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link" id="privacy-tab" data-bs-toggle="tab" data-bs-target="#privacy" type="button" role="tab" aria-controls="privacy" aria-selected="false">
|
|
<i class="bi bi-shield-lock me-2"></i>Privacy Policy
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="tab-content" id="companySettingsTabContent">
|
|
<!-- Tab 1: Company Setting -->
|
|
<div class="tab-pane fade show active" id="company" role="tabpanel" aria-labelledby="company-tab">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Company / App Name</label>
|
|
<input type="text" name="company_name" class="form-control" value="<?= e($currentName) ?>" required>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Contact Email</label>
|
|
<input type="email" name="company_email" class="form-control" value="<?= e($currentEmail) ?>">
|
|
<div class="form-text">Displayed in the footer.</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Contact Phone</label>
|
|
<input type="text" name="company_phone" class="form-control" value="<?= e($currentPhone) ?>">
|
|
<div class="form-text">Displayed in the footer.</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Address</label>
|
|
<input type="text" name="company_address" class="form-control" value="<?= e($currentAddress) ?>">
|
|
<div class="form-text">Displayed in the footer.</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Platform Charge (%)</label>
|
|
<div class="input-group">
|
|
<input type="number" step="0.01" min="0" max="100" name="platform_charge_percentage" class="form-control" value="<?= e($currentPlatformCharge) ?>">
|
|
<span class="input-group-text">%</span>
|
|
</div>
|
|
<div class="form-text">Percentage applied as a platform fee.</div>
|
|
</div>
|
|
|
|
<div class="col-md-12">
|
|
<hr class="my-2">
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Company Logo</label>
|
|
<?php if ($currentLogo): ?>
|
|
<div class="mb-2">
|
|
<img src="<?= e($currentLogo) ?>" alt="Logo" height="40" class="border rounded p-1">
|
|
</div>
|
|
<?php endif; ?>
|
|
<input type="file" name="logo_file" class="form-control" accept="image/*">
|
|
<div class="form-text">Recommended size: 150x40px (PNG, JPG, SVG). Leave empty to keep current.</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Favicon</label>
|
|
<?php if ($currentFavicon): ?>
|
|
<div class="mb-2">
|
|
<img src="<?= e($currentFavicon) ?>" alt="Favicon" height="32" class="border rounded p-1">
|
|
</div>
|
|
<?php endif; ?>
|
|
<input type="file" name="favicon_file" class="form-control" accept="image/png, image/x-icon, image/svg+xml">
|
|
<div class="form-text">Recommended size: 32x32px (ICO, PNG, SVG). Leave empty to keep current.</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab 2: Legal & Policies -->
|
|
<div class="tab-pane fade" id="legal" role="tabpanel" aria-labelledby="legal-tab">
|
|
<div class="row g-3">
|
|
<div class="col-12">
|
|
<h5 class="fw-bold mb-3">Terms of Service</h5>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">English</label>
|
|
<textarea name="terms_en" class="form-control" rows="10" placeholder="Enter Terms of Service in English..."><?= e($currentTermsEn) ?></textarea>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Arabic</label>
|
|
<textarea name="terms_ar" class="form-control" rows="10" dir="rtl" placeholder="أدخل شروط الخدمة باللغة العربية..."><?= e($currentTermsAr) ?></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab 3: Privacy Policy -->
|
|
<div class="tab-pane fade" id="privacy" role="tabpanel" aria-labelledby="privacy-tab">
|
|
<div class="row g-3">
|
|
<div class="col-12">
|
|
<h5 class="fw-bold mb-3">Privacy Policy</h5>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">English</label>
|
|
<textarea name="privacy_en" class="form-control" rows="10" placeholder="Enter Privacy Policy in English..."><?= e($currentPrivacyEn) ?></textarea>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Arabic</label>
|
|
<textarea name="privacy_ar" class="form-control" rows="10" dir="rtl" placeholder="أدخل سياسة الخصوصية باللغة العربية..."><?= e($currentPrivacyAr) ?></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<hr class="my-4">
|
|
<button type="submit" class="btn btn-primary px-4">Save Changes</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php render_footer(); ?>
|