HEX
Server: LiteSpeed
System:
User: ()
PHP: 7.4.33
Disabled: sendmail,mail,exec,shell_exec,dl,system,passthru,pclose,proc_open,proc_nice,proc_terminate,proc_get_status,proc_close,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,escapeshellcmd,escapeshellarg shell-exec,fpassthru,crack_check,crack_closedict,crack_getlastmessage,crack_opendict,psockopen,php_uname,symlink,ini_restore,posix_getpwuid,posix_getegid,posix_getcwd,posix_geteuid,posix_getgroups,posix_uname,posix_setuid,eval,show_source,passthru,popen,allow_url_fopen,get_current_user,getmyuid,getmygid,entre2v2,index_changer_wp,index_changer_joomla,exec_mode_1,exec_mode_2,exec_mode_3,wsoFooter,wsoEx,wsoViewSize,wsoPerms,wsoPermsColor,ukuran,tulis,ambil,tukar,entre2v2,rapih,magicboom,goaction,scookie,showstat,index_changer
Upload Files
File: /home/muratemr/theotto.tr/admin/orders_archive.php
<?php
declare(strict_types=1);
$page_title  = 'Arşivlenen Siparişler';
$active_menu = 'daily_orders';

require_once __DIR__ . '/../includes/db.php';
require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/../includes/csrf.php';
require_once __DIR__ . '/../includes/functions.php';
require_permission('daily_orders');

// Toplu veya tekil silme
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!hash_equals(csrf_token(), $_POST['csrf_token'] ?? '')) {
        $err = 'Güvenlik hatası.';
    } elseif (isset($_POST['delete_ids'])) {
        $ids = array_filter(array_map('intval', explode(',', $_POST['delete_ids'])));
        if ($ids) {
            $ph = implode(',', array_fill(0, count($ids), '?'));
            // Sadece arşivlenenler silinebilir
            $items = db_rows("SELECT id FROM daily_orders WHERE id IN ($ph) AND is_archived=1", $ids);
            foreach ($items as $o) {
                db_run("DELETE FROM daily_order_items WHERE order_id=?", [$o['id']]);
                db_run("DELETE FROM daily_order_edit_logs WHERE order_id=?", [$o['id']]);
            }
            if ($items) {
                $item_ids = array_column($items, 'id');
                $ph2 = implode(',', array_fill(0, count($item_ids), '?'));
                db_run("DELETE FROM daily_orders WHERE id IN ($ph2)", $item_ids);
            }
            $msg = count($items) . ' sipariş silindi.';
        }
    }
}

// Filtreler
$filter_supplier = get_int('supplier_id');
$page     = max(1, get_int('page', 1));
$per_page = 30;

// is_archived kolonu var mı?
$has_archive_col = (bool)db_value(
    "SELECT COUNT(*) FROM information_schema.COLUMNS
      WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='daily_orders' AND COLUMN_NAME='is_archived'"
);

if (!$has_archive_col) {
    // Migration çalıştırılmamış
    $orders = [];
    $total  = 0;
    $pg     = paginate(0, 1, 30);
    $suppliers = [];
    require_once __DIR__ . '/../includes/admin_layout.php';
    echo '<div class="alert alert-warning m-3"><i class="bi bi-exclamation-triangle me-2"></i>';
    echo 'Arşiv özelliği için önce <code>migration_orders_archive.sql</code> dosyasını çalıştırın.</div>';
    require_once __DIR__ . '/../includes/admin_layout_end.php';
    exit;
}

$where  = ['do.is_archived = 1'];
$params = [];

if ($filter_supplier) {
    $where[]  = 'do.supplier_id = ?';
    $params[] = $filter_supplier;
}

$where_str = implode(' AND ', $where);

$total = (int)db_value("SELECT COUNT(*) FROM daily_orders do WHERE $where_str", $params);
$pg    = paginate($total, $page, $per_page);

$orders = db_rows("
    SELECT do.id, do.order_date, do.general_note, do.archived_reason, do.created_at, do.updated_at,
           s.company_name AS supplier_name,
           u.full_name AS creator_name,
           COUNT(doi.id) AS item_count,
           COALESCE(SUM(doi.quantity * COALESCE(doi.approx_price,0)),0) AS total_price
    FROM daily_orders do
    LEFT JOIN suppliers s ON s.id = do.supplier_id
    LEFT JOIN users u ON u.id = do.created_by
    LEFT JOIN daily_order_items doi ON doi.order_id = do.id
    WHERE $where_str
    GROUP BY do.id
    ORDER BY do.updated_at DESC
    LIMIT {$pg['limit']} OFFSET {$pg['offset']}
", $params);

$suppliers = db_rows("SELECT DISTINCT s.id, s.company_name FROM daily_orders do
    JOIN suppliers s ON s.id = do.supplier_id WHERE do.is_archived=1 ORDER BY s.company_name");

require_once __DIR__ . '/../includes/admin_layout.php';
?>

<div class="d-flex align-items-center gap-2 mb-4">
    <a href="daily_orders.php" class="btn btn-outline-secondary btn-sm">
        <i class="bi bi-arrow-left me-1"></i>Günlük Siparişler
    </a>
    <h5 class="mb-0 ms-2">
        <i class="bi bi-archive text-warning me-2"></i>Arşivlenen Siparişler
    </h5>
</div>

<?php if (!empty($msg)): ?>
<div class="alert alert-success alert-dismissible fade show">
    <i class="bi bi-check-circle me-2"></i><?= e($msg) ?>
    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>

<!-- Filtre -->
<div class="card mb-3">
    <div class="card-body py-2">
        <form method="GET" class="row g-2 align-items-end">
            <div class="col-md-4">
                <label class="form-label small">Tedarikçi</label>
                <select name="supplier_id" class="form-select form-select-sm">
                    <option value="">Tümü</option>
                    <?php foreach ($suppliers as $s): ?>
                    <option value="<?= $s['id'] ?>" <?= $filter_supplier == $s['id'] ? 'selected' : '' ?>>
                        <?= e($s['company_name']) ?>
                    </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="col-md-auto d-flex gap-2">
                <button type="submit" class="btn btn-sm btn-gold">
                    <i class="bi bi-search me-1"></i>Filtrele
                </button>
                <a href="orders_archive.php" class="btn btn-sm btn-outline-secondary">
                    <i class="bi bi-x-lg"></i>
                </a>
            </div>
        </form>
    </div>
</div>

<!-- Tablo -->
<div class="card">
    <div class="card-header d-flex align-items-center justify-content-between">
        <span><i class="bi bi-archive me-2"></i>Arşiv (<?= $total ?> sipariş)</span>
        <?php if (is_admin() && !empty($orders)): ?>
        <div class="d-flex gap-2">
            <button class="btn btn-sm btn-outline-secondary" onclick="selectAll()">Tümünü Seç</button>
            <button class="btn btn-sm btn-outline-danger" id="bulkDeleteBtn" onclick="bulkDelete()" disabled>
                <i class="bi bi-trash me-1"></i>Seçilenleri Sil
            </button>
        </div>
        <?php endif; ?>
    </div>
    <div class="card-body p-0">
        <?php if (empty($orders)): ?>
        <div class="text-center py-5" style="color:rgba(255,255,255,0.4)">
            <i class="bi bi-archive d-block mb-2" style="font-size:36px"></i>
            Arşivde sipariş bulunmuyor.
        </div>
        <?php else: ?>
        <form id="archiveForm" method="POST" action="orders_archive.php">
            <input type="hidden" name="csrf_token" value="<?= htmlspecialchars(csrf_token()) ?>">
            <input type="hidden" name="delete_ids" id="deleteIdsInput" value="">
            <div class="table-responsive">
                <table class="table table-dark table-hover mb-0">
                    <thead>
                        <tr>
                            <?php if (is_admin()): ?>
                            <th style="width:40px">
                                <input type="checkbox" class="form-check-input" id="selectAllCb"
                                    onchange="toggleAll(this.checked)">
                            </th>
                            <?php endif; ?>
                            <th>Tarih</th>
                            <th>Tedarikçi</th>
                            <th>Ürünler</th>
                            <th>Tutar</th>
                            <th>Oluşturan</th>
                            <th>Arşiv Nedeni</th>
                            <?php if (is_admin()): ?><th>İşlem</th><?php endif; ?>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($orders as $o): ?>
                        <tr>
                            <?php if (is_admin()): ?>
                            <td>
                                <input type="checkbox" class="form-check-input order-cb"
                                    value="<?= $o['id'] ?>" onchange="updateBulkBtn()">
                            </td>
                            <?php endif; ?>
                            <td><?= format_date($o['order_date']) ?></td>
                            <td><?= e($o['supplier_name'] ?? '—') ?></td>
                            <td>
                                <span class="badge bg-secondary"><?= $o['item_count'] ?> ürün</span>
                            </td>
                            <td class="text-warning">
                                <?= number_format((float)$o['total_price'], 2, ',', '.') ?> ₺
                            </td>
                            <td class="fs-12 text-muted"><?= e($o['creator_name'] ?? '—') ?></td>
                            <td class="fs-12 text-muted" style="max-width:200px">
                                <?= e($o['archived_reason'] ?? '—') ?>
                            </td>
                            <?php if (is_admin()): ?>
                            <td>
                                <button class="btn btn-sm btn-outline-danger btn-action"
                                    onclick="deleteSingle(<?= $o['id'] ?>)" title="Sil">
                                    <i class="bi bi-trash"></i>
                                </button>
                            </td>
                            <?php endif; ?>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </form>

        <!-- Pagination -->
        <?php if ($pg['total_pages'] > 1): ?>
        <div class="card-body border-top py-2">
            <nav><ul class="pagination pagination-sm mb-0 justify-content-center">
                <?php for ($i = 1; $i <= $pg['total_pages']; $i++): ?>
                <li class="page-item <?= $i === $pg['current_page'] ? 'active' : '' ?>">
                    <a class="page-link" href="?page=<?= $i ?>&supplier_id=<?= $filter_supplier ?>">
                        <?= $i ?>
                    </a>
                </li>
                <?php endfor; ?>
            </ul></nav>
        </div>
        <?php endif; ?>
        <?php endif; ?>
    </div>
</div>

<?php require_once __DIR__ . '/../includes/admin_layout_end.php'; ?>
<script>
function toggleAll(checked) {
    document.querySelectorAll('.order-cb').forEach(function(cb) { cb.checked = checked; });
    updateBulkBtn();
}

function selectAll() {
    document.querySelectorAll('.order-cb').forEach(function(cb) { cb.checked = true; });
    document.getElementById('selectAllCb').checked = true;
    updateBulkBtn();
}

function updateBulkBtn() {
    var checked = document.querySelectorAll('.order-cb:checked').length;
    var btn = document.getElementById('bulkDeleteBtn');
    if (btn) {
        btn.disabled = checked === 0;
        btn.textContent = checked > 0 ? checked + ' Siparişi Sil' : 'Seçilenleri Sil';
    }
}

function bulkDelete() {
    var ids = Array.from(document.querySelectorAll('.order-cb:checked')).map(function(cb) { return cb.value; });
    if (ids.length === 0) return;
    confirmAction(ids.length + ' sipariş kalıcı olarak silinsin mi? Bu işlem geri alınamaz.', function() {
        document.getElementById('deleteIdsInput').value = ids.join(',');
        document.getElementById('archiveForm').submit();
    });
}

function deleteSingle(id) {
    confirmAction('Bu sipariş kalıcı olarak silinsin mi?', function() {
        document.getElementById('deleteIdsInput').value = id;
        document.getElementById('archiveForm').submit();
    });
}
</script>