İçeriğe geç
Tüm kodlar

ER3NSHOP

Kurulum sihirbazlı online mağaza sistemi

132 satır · 3,9 KBHamİndir
<?php

// Bakım modu: yönetici dışındaki ziyaretçiler bakım sayfasını görür.
function maintenance_guard()
{
    // Ödeme dönüşleri bakımda da çalışmalı, yoksa ödenmiş siparişler kaybolur.
    $open = ['/kurulum.php', '/odeme-bildirim.php', '/odeme-sonuc.php'];
    if (setting('maintenance') !== '1' || in_admin() || is_admin() || in_array(current_script(), $open, true)) {
        return;
    }
    http_response_code(503);
    header('Retry-After: 3600');
    include PARTS . '/maintenance.php';
    exit;
}

function popup_settings()
{
    return [
        'enabled' => setting('popup_enabled') === '1',
        'title'   => setting('popup_title', ''),
        'text'    => setting('popup_text', ''),
        'image'   => setting('popup_image', ''),
        'button'  => setting('popup_button', ''),
        'link'    => setting('popup_link', ''),
        'delay'   => max(0, (int) setting('popup_delay', 5)),
        'pages'   => setting('popup_pages', 'home'),
        'repeat'  => setting('popup_repeat', 'session'),
        'version' => setting('popup_version', '1'),
    ];
}

function popup_visible()
{
    $popup = popup_settings();
    if (!$popup['enabled'] || !$popup['title']) {
        return false;
    }
    return $popup['pages'] === 'all' || current_file() === 'index';
}

function cookie_bar_visible()
{
    return setting('cookie_enabled', '1') === '1';
}

// Kargo ücreti: şehre özel kural varsa o, yoksa genel ayar.
function shipping_rule($city)
{
    $city = trim((string) $city);
    if ($city === '') {
        return null;
    }
    static $rules = null;
    $rules ??= db_all('SELECT * FROM shipping_rules');
    foreach ($rules as $rule) {
        if (mb_strtolower($rule['city'], 'UTF-8') === mb_strtolower($city, 'UTF-8')) {
            return $rule;
        }
    }
    return null;
}

function tax_rate()
{
    return max(0, (float) setting('tax_rate', 20));
}

function tax_included($total)
{
    $rate = tax_rate();
    return $rate > 0 ? round($total - $total / (1 + $rate / 100), 2) : 0;
}

// Yönetici işlem günlüğü.
function log_action($action, $subject = '')
{
    $admin = current_admin();
    try {
        db_insert('activity_log', [
            'admin_id'   => $admin['id'] ?? null,
            'admin_name' => $admin['name'] ?? null,
            'action'     => $action,
            'subject'    => mb_substr((string) $subject, 0, 255),
            'ip'         => client_ip(),
        ]);
    } catch (Throwable $e) {
    }
}

// CSV dosyası olarak indirir (Excel uyumlu, ; ayraçlı, UTF-8 BOM).
function csv_download($filename, $header, $rows)
{
    header('Content-Type: text/csv; charset=utf-8');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    $out = fopen('php://output', 'w');
    fwrite($out, "\xEF\xBB\xBF");
    fputcsv($out, $header, ';', '"', '\\');
    foreach ($rows as $row) {
        fputcsv($out, array_values($row), ';', '"', '\\');
    }
    fclose($out);
    exit;
}

function csv_read($path)
{
    $handle = fopen($path, 'r');
    $first = fgets($handle);
    $delimiter = substr_count($first, ';') >= substr_count($first, ',') ? ';' : ',';
    rewind($handle);
    $header = array_map(fn($cell) => mb_strtolower(trim(str_replace("\xEF\xBB\xBF", '', $cell))), fgetcsv($handle, 0, $delimiter, '"', '\\') ?: []);
    $rows = [];
    while (($row = fgetcsv($handle, 0, $delimiter, '"', '\\')) !== false) {
        if (count(array_filter($row, 'strlen'))) {
            $rows[] = array_combine($header, array_pad(array_slice($row, 0, count($header)), count($header), ''));
        }
    }
    fclose($handle);
    return $rows;
}

// Toplu fiyat güncellemede yuvarlama: tam sayı, ,90 ya da ,99 ile bitirme.
function price_round($price, $mode)
{
    return match ($mode) {
        '90'    => max(0, floor($price) + 0.90),
        '99'    => max(0, floor($price) + 0.99),
        'int'   => round($price),
        default => round($price, 2),
    };
}

Lisans bilgisi projenin LICENSE dosyasında.