From a4b81a5393a49906041d1577f39b0f4c263ed408 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 21 Feb 2026 10:33:17 +0000 Subject: [PATCH] updaing import items --- index.php | 81 ++++++++++++++++++++++---------------- lib/LicenseService.php | 16 +++++++- license_manager/manage.php | 13 ++++++ 3 files changed, 74 insertions(+), 36 deletions(-) diff --git a/index.php b/index.php index 6433c24..44c0365 100644 --- a/index.php +++ b/index.php @@ -94,34 +94,15 @@ if ($page === 'activate') { } } - if (isset($_POST['update_license'])) { - $id = (int)$_POST['id']; - $status = $_POST['status'] ?? null; - $owner = $_POST['owner'] ?? null; - $address = $_POST['address'] ?? null; - - $updateData = []; - if ($status !== null) $updateData['status'] = $status; - if ($owner !== null) $updateData['owner'] = $owner; - if ($address !== null) $updateData['address'] = $address; - - $res = LicenseService::updateLicense($id, $updateData); + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['start_trial'])) { + // We need a way to call startTrial() which is private in LicenseService + // I'll make it public or use a public wrapper + $res = LicenseService::initTrial(); if ($res['success']) { - $message = "License updated successfully!"; + $success = "Trial period started! Redirecting..."; + header("refresh:2;url=index.php"); } else { - $message = "Error: " . ($res['error'] ?? 'Unknown error'); - } - } - - if (isset($_POST['issue_license'])) { - $max = (int)($_POST['max_activations'] ?? 1); - $owner = $_POST['owner'] ?? null; - $address = $_POST['address'] ?? null; - $res = LicenseService::issueLicense($max, 'FLAT', $owner, $address); - if ($res['success']) { - $message = "New License Issued: " . $res['license_key']; - } else { - $message = "Error: " . ($res['error'] ?? 'Unknown error'); + $error = $res['error']; } } ?> @@ -171,8 +152,18 @@ if ($page === 'activate') {
- + + + +
+
+

+
+ +
+
+ @@ -1188,15 +1179,37 @@ function getPromotionalPrice($item) { if (isset($_POST['import_items'])) { if (isset($_FILES['excel_file']) && $_FILES['excel_file']['error'] === 0) { - $handle = fopen($_FILES['excel_file']['tmp_name'], "r"); - fgetcsv($handle); $count = 0; - while (($data = fgetcsv($handle)) !== FALSE) { - if ($data[1] || $data[2]) { - db()->prepare("INSERT INTO stock_items (sku, name_en, name_ar, sale_price, purchase_price) VALUES (?, ?, ?, ?, ?)")->execute([$data[0] ?? '', $data[1] ?? '', $data[2] ?? '', (float)($data[3] ?? 0), (float)($data[4] ?? 0)]); - $count++; + $tmpPath = $_FILES['excel_file']['tmp_name']; + $firstBytes = file_get_contents($tmpPath, false, null, 0, 4); + if ($firstBytes === "PK\x03\x04") { + $message = "Error: It looks like you uploaded an Excel (.xlsx) file. Please save it as CSV (UTF-8) and try again."; + } else { + $handle = fopen($tmpPath, "r"); + fgetcsv($handle); // Skip header + $count = 0; $errors = 0; + while (($data = fgetcsv($handle)) !== FALSE) { + if (empty($data[1]) && empty($data[2])) continue; + try { + foreach ($data as &$val) { + if ($val === null) continue; + if (!mb_check_encoding($val, 'UTF-8')) { + $val = mb_convert_encoding($val, 'UTF-8', 'Windows-1252'); + } + $val = mb_convert_encoding($val, 'UTF-8', 'UTF-8'); + } + db()->prepare("INSERT INTO stock_items (sku, name_en, name_ar, sale_price, purchase_price) + VALUES (?, ?, ?, ?, ?) + ON DUPLICATE KEY UPDATE name_en=VALUES(name_en), name_ar=VALUES(name_ar), + sale_price=VALUES(sale_price), purchase_price=VALUES(purchase_price)") + ->execute([$data[0] ?? '', $data[1] ?? '', $data[2] ?? '', (float)($data[3] ?? 0), (float)($data[4] ?? 0)]); + $count++; + } catch (Exception $e) { + $errors++; + } } + fclose($handle); + $message = "Import completed! $count items processed." . ($errors > 0 ? " ($errors rows skipped due to data errors.)" : ""); } - fclose($handle); $message = "Imported $count items!"; } } diff --git a/lib/LicenseService.php b/lib/LicenseService.php index 849495c..00ccf36 100644 --- a/lib/LicenseService.php +++ b/lib/LicenseService.php @@ -21,8 +21,8 @@ class LicenseService { $res = $stmt->fetch(); if (!$res || !$res['trial_started_at']) { - self::startTrial(); - return 15; + // self::startTrial(); // Disabled automatic trial start as per user request to keep things manual + return 0; // Return 0 if trial not started } $started = strtotime($res['trial_started_at']); @@ -79,6 +79,18 @@ class LicenseService { } } + /** + * Public wrapper to initialize the trial period. + */ + public static function initTrial() { + try { + self::startTrial(); + return ['success' => true]; + } catch (Exception $e) { + return ['success' => false, 'error' => $e->getMessage()]; + } + } + /** * Initializes the trial period. */ diff --git a/license_manager/manage.php b/license_manager/manage.php index 9a43860..e4a1917 100644 --- a/license_manager/manage.php +++ b/license_manager/manage.php @@ -127,12 +127,25 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $message = "License limits updated successfully."; break; } + + // Redirect to prevent re-submission on refresh + if ($message) { + $_SESSION['flash_message'] = $message; + header("Location: manage.php"); + exit; + } } } catch (Exception $e) { $error = "Operation failed: " . $e->getMessage(); } } +// Get flash message from session +if (isset($_SESSION['flash_message'])) { + $message = $_SESSION['flash_message']; + unset($_SESSION['flash_message']); +} + // Fetch Licenses try { $licenses = $pdo->query("SELECT * FROM licenses ORDER BY created_at DESC")->fetchAll();