gitea init
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// controllers/create.php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/productmodels.php';
|
||||
require_once __DIR__ . '/../../../../vendor/autoload.php';
|
||||
// ბაზის კავშირის გადაცემა მოდელს
|
||||
ProductModel::setDb($pdo);
|
||||
|
||||
// (დროებით არ გვჭირდება dropdown-ებისთვის ცალკე მონაცემები, მაგრამ თუ დაგჭირდება შემიძლია დავამატო)
|
||||
|
||||
// გადადი ფორმის ვიუ გვერდზე
|
||||
require_once __DIR__ . '/../views/create.php';
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/productmodels.php';
|
||||
|
||||
ProductModel::setDb($pdo);
|
||||
|
||||
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
|
||||
$id = (int) $_GET['id'];
|
||||
ProductModel::deleteProductById($id);
|
||||
}
|
||||
|
||||
header("Location: dashboard.php?module=product&action=list&deleted=1");
|
||||
exit;
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/productmodels.php';
|
||||
require_once __DIR__ . '/../../../../vendor/autoload.php';
|
||||
|
||||
ProductModel::setDb($pdo);
|
||||
|
||||
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||
echo "<div class='container-xl mt-4'><div class='alert alert-danger'>ID არ არის სწორი.</div></div>";
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = (int) $_GET['id'];
|
||||
$product = ProductModel::getProductById($id);
|
||||
|
||||
if (!$product) {
|
||||
echo "<div class='container-xl mt-4'><div class='alert alert-danger'>პროდუქტი ვერ მოიძებნა.</div></div>";
|
||||
exit;
|
||||
}
|
||||
|
||||
$tab = $_GET['tab'] ?? 'details';
|
||||
|
||||
require_once __DIR__ . '/../views/edit.php';
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
// Product index controller - redirects to list
|
||||
header("Location: dashboard.php?module=product&action=list");
|
||||
exit;
|
||||
?>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// controllers/list.php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/productmodels.php';
|
||||
require_once __DIR__ . '/../../../../vendor/autoload.php';
|
||||
|
||||
ProductModel::setDb($pdo);
|
||||
$products = ProductModel::getAllProducts();
|
||||
|
||||
require_once __DIR__ . '/../views/list.php';
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/producttypesmodel.php';
|
||||
|
||||
ProductTypesModel::setDb($pdo);
|
||||
|
||||
$message = '';
|
||||
$messageType = '';
|
||||
$action = $_GET['subaction'] ?? 'list';
|
||||
|
||||
// POST მოთხოვნების მართვა
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$postAction = $_POST['action'] ?? '';
|
||||
|
||||
switch ($postAction) {
|
||||
case 'add':
|
||||
$data = [
|
||||
'name' => trim($_POST['name'] ?? ''),
|
||||
'description' => trim($_POST['description'] ?? ''),
|
||||
'icon' => $_POST['icon'] ?? 'box',
|
||||
'sort_order' => (int)($_POST['sort_order'] ?? 0),
|
||||
'is_active' => isset($_POST['is_active']) ? 1 : 0
|
||||
];
|
||||
|
||||
if (empty($data['name'])) {
|
||||
$message = 'პროდუქტის ტიპის სახელი სავალდებულოა';
|
||||
$messageType = 'danger';
|
||||
} else {
|
||||
try {
|
||||
ProductTypesModel::addType($data);
|
||||
$message = 'პროდუქტის ტიპი წარმატებით დაემატა';
|
||||
$messageType = 'success';
|
||||
$action = 'list';
|
||||
} catch (Exception $e) {
|
||||
$message = 'შეცდომა: ' . $e->getMessage();
|
||||
$messageType = 'danger';
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$data = [
|
||||
'name' => trim($_POST['name'] ?? ''),
|
||||
'description' => trim($_POST['description'] ?? ''),
|
||||
'icon' => $_POST['icon'] ?? 'box',
|
||||
'sort_order' => (int)($_POST['sort_order'] ?? 0),
|
||||
'is_active' => isset($_POST['is_active']) ? 1 : 0
|
||||
];
|
||||
|
||||
if (empty($data['name']) || $id <= 0) {
|
||||
$message = 'არასწორი მონაცემები';
|
||||
$messageType = 'danger';
|
||||
} else {
|
||||
try {
|
||||
ProductTypesModel::updateType($id, $data);
|
||||
$message = 'პროდუქტის ტიპი წარმატებით განახლდა';
|
||||
$messageType = 'success';
|
||||
$action = 'list';
|
||||
} catch (Exception $e) {
|
||||
$message = 'შეცდომა: ' . $e->getMessage();
|
||||
$messageType = 'danger';
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
if ($id > 0) {
|
||||
try {
|
||||
ProductTypesModel::deleteType($id);
|
||||
$message = 'პროდუქტის ტიპი წარმატებით წაიშალა';
|
||||
$messageType = 'success';
|
||||
} catch (Exception $e) {
|
||||
$message = 'შეცდომა: ' . $e->getMessage();
|
||||
$messageType = 'danger';
|
||||
}
|
||||
}
|
||||
$action = 'list';
|
||||
break;
|
||||
|
||||
case 'update_order':
|
||||
$orders = $_POST['orders'] ?? [];
|
||||
try {
|
||||
ProductTypesModel::updateSortOrder($orders);
|
||||
$message = 'რიგითობა წარმატებით განახლდა';
|
||||
$messageType = 'success';
|
||||
} catch (Exception $e) {
|
||||
$message = 'შეცდომა: ' . $e->getMessage();
|
||||
$messageType = 'danger';
|
||||
}
|
||||
$action = 'list';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// მონაცემების მომზადება view-სთვის
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
case 'edit':
|
||||
$availableIcons = ProductTypesModel::getAvailableIcons();
|
||||
if ($action === 'edit') {
|
||||
$editId = (int)($_GET['id'] ?? 0);
|
||||
$editType = ProductTypesModel::getTypeById($editId);
|
||||
if (!$editType) {
|
||||
$message = 'პროდუქტის ტიპი ვერ მოიძებნა';
|
||||
$messageType = 'danger';
|
||||
$action = 'list';
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'list':
|
||||
default:
|
||||
$productTypes = ProductTypesModel::getAllTypes();
|
||||
break;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../views/product_types.php';
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// controllers/save.php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/productmodels.php';
|
||||
|
||||
ProductModel::setDb($pdo);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$product = [
|
||||
'name' => trim($_POST['name']),
|
||||
'group' => trim($_POST['group']),
|
||||
'type' => trim($_POST['type']),
|
||||
'url' => trim($_POST['url']),
|
||||
'module' => trim($_POST['module']),
|
||||
'hidden' => isset($_POST['hidden']) ? 1 : 0
|
||||
];
|
||||
|
||||
$success = ProductModel::createProduct($product);
|
||||
|
||||
if ($success) {
|
||||
header("Location: dashboard.php?module=product&action=list&added=1");
|
||||
} else {
|
||||
header("Location: dashboard.php?module=product&action=create&error=1");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
header("Location: dashboard.php?module=product&action=create");
|
||||
exit;
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
// modules/product/controllers/update.php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/productmodels.php';
|
||||
|
||||
ProductModel::setDb($pdo);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['id'])) {
|
||||
$id = (int) $_POST['id'];
|
||||
$data = [
|
||||
'name' => trim($_POST['name']),
|
||||
'group' => trim($_POST['group']),
|
||||
'type' => trim($_POST['type']),
|
||||
'url' => trim($_POST['url']),
|
||||
'module' => trim($_POST['module']),
|
||||
'hidden' => isset($_POST['hidden']) ? 1 : 0,
|
||||
];
|
||||
|
||||
$success = ProductModel::updateProduct($id, $data);
|
||||
|
||||
if ($success) {
|
||||
header("Location: dashboard.php?module=product&action=edit&id=$id&updated=1");
|
||||
} else {
|
||||
header("Location: dashboard.php?module=product&action=edit&id=$id&updated=0");
|
||||
}
|
||||
exit;
|
||||
} else {
|
||||
header("Location: dashboard.php?module=product&action=list");
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user