Delete comment
This commit is contained in:
@@ -1,13 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
// admin_panel.php - ПОЛНОСТЬЮ ИСПРАВЛЕННАЯ ВЕРСИЯ
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
// Включаем отладку ошибок
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
|
|
||||||
// Проверка прав администратора
|
|
||||||
if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
||||||
echo "<script>alert('Требуется авторизация администратора'); window.location.href = 'login.php';</script>";
|
echo "<script>alert('Требуется авторизация администратора'); window.location.href = 'login.php';</script>";
|
||||||
exit();
|
exit();
|
||||||
@@ -15,12 +13,10 @@ if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
|||||||
|
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
// Обработка действий
|
|
||||||
$action = $_GET['action'] ?? 'dashboard';
|
$action = $_GET['action'] ?? 'dashboard';
|
||||||
$message = $_GET['message'] ?? '';
|
$message = $_GET['message'] ?? '';
|
||||||
$error = $_GET['error'] ?? '';
|
$error = $_GET['error'] ?? '';
|
||||||
|
|
||||||
// Обработка POST запросов - ДОБАВЛЕНО ПРОСТОЕ И РАБОТАЮЩЕЕ!
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$post_action = $_POST['action'] ?? '';
|
$post_action = $_POST['action'] ?? '';
|
||||||
|
|
||||||
@@ -50,7 +46,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ИСПРАВЬТЕ БЛОК edit_category или добавьте его если его нет:
|
|
||||||
if ($post_action === 'edit_category' && isset($_POST['category_id'])) {
|
if ($post_action === 'edit_category' && isset($_POST['category_id'])) {
|
||||||
$category_id = (int)$_POST['category_id'];
|
$category_id = (int)$_POST['category_id'];
|
||||||
$name = trim($_POST['name'] ?? '');
|
$name = trim($_POST['name'] ?? '');
|
||||||
@@ -99,15 +94,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$material = trim($_POST['material'] ?? '');
|
$material = trim($_POST['material'] ?? '');
|
||||||
$card_size = trim($_POST['card_size'] ?? 'small');
|
$card_size = trim($_POST['card_size'] ?? 'small');
|
||||||
|
|
||||||
|
|
||||||
// ВАЖНО: Проверяем category_id
|
|
||||||
if ($category_id <= 0) {
|
if ($category_id <= 0) {
|
||||||
$_SESSION['error'] = 'Выберите корректную категорию';
|
$_SESSION['error'] = 'Выберите корректную категорию';
|
||||||
header('Location: admin_panel.php?action=add_product');
|
header('Location: admin_panel.php?action=add_product');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем существование категории
|
|
||||||
$check_category = $db->prepare("SELECT COUNT(*) FROM categories WHERE category_id = ?");
|
$check_category = $db->prepare("SELECT COUNT(*) FROM categories WHERE category_id = ?");
|
||||||
$check_category->execute([$category_id]);
|
$check_category->execute([$category_id]);
|
||||||
if ($check_category->fetchColumn() == 0) {
|
if ($check_category->fetchColumn() == 0) {
|
||||||
@@ -119,7 +111,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
if (empty($name)) throw new Exception('Название товара обязательно');
|
if (empty($name)) throw new Exception('Название товара обязательно');
|
||||||
if ($price <= 0) throw new Exception('Цена должна быть больше 0');
|
if ($price <= 0) throw new Exception('Цена должна быть больше 0');
|
||||||
|
|
||||||
// Генерируем SKU если пустой
|
|
||||||
if (empty($sku)) {
|
if (empty($sku)) {
|
||||||
$sku = 'PROD-' . strtoupper(substr(preg_replace('/[^a-z0-9]/i', '', $name), 0, 6)) . '-' . rand(100, 999);
|
$sku = 'PROD-' . strtoupper(substr(preg_replace('/[^a-z0-9]/i', '', $name), 0, 6)) . '-' . rand(100, 999);
|
||||||
}
|
}
|
||||||
@@ -145,11 +136,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ИСПРАВЛЕННЫЙ КОД для edit_product в admin_panel.php:
|
|
||||||
if ($post_action === 'edit_product' && isset($_POST['product_id'])) {
|
if ($post_action === 'edit_product' && isset($_POST['product_id'])) {
|
||||||
$product_id = (int)$_POST['product_id'];
|
$product_id = (int)$_POST['product_id'];
|
||||||
$name = trim($_POST['name'] ?? '');
|
$name = trim($_POST['name'] ?? '');
|
||||||
$category_id = (int)($_POST['category_id'] ?? 1); // ПО УМОЛЧАНИЮ 1, чтобы избежать 0
|
$category_id = (int)($_POST['category_id'] ?? 1);
|
||||||
$description = trim($_POST['description'] ?? '');
|
$description = trim($_POST['description'] ?? '');
|
||||||
$price = (float)($_POST['price'] ?? 0);
|
$price = (float)($_POST['price'] ?? 0);
|
||||||
$old_price = !empty($_POST['old_price']) ? (float)$_POST['old_price'] : NULL;
|
$old_price = !empty($_POST['old_price']) ? (float)$_POST['old_price'] : NULL;
|
||||||
@@ -159,9 +149,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$color = trim($_POST['color'] ?? '');
|
$color = trim($_POST['color'] ?? '');
|
||||||
$material = trim($_POST['material'] ?? '');
|
$material = trim($_POST['material'] ?? '');
|
||||||
|
|
||||||
// ВАЖНО: Проверяем category_id
|
|
||||||
if ($category_id <= 0) {
|
if ($category_id <= 0) {
|
||||||
// Если category_id = 0, устанавливаем первую доступную категорию
|
|
||||||
$firstCat = $db->query("SELECT category_id FROM categories LIMIT 1")->fetchColumn();
|
$firstCat = $db->query("SELECT category_id FROM categories LIMIT 1")->fetchColumn();
|
||||||
$category_id = $firstCat ?: 1;
|
$category_id = $firstCat ?: 1;
|
||||||
}
|
}
|
||||||
@@ -194,32 +183,30 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
if ($post_action === 'delete_category' && isset($_POST['category_id'])) {
|
if ($post_action === 'delete_category' && isset($_POST['category_id'])) {
|
||||||
$categoryId = intval($_POST['category_id']);
|
$categoryId = intval($_POST['category_id']);
|
||||||
|
|
||||||
// 1. Проверяем, есть ли товары в этой категории
|
|
||||||
$checkProducts = $db->prepare("SELECT COUNT(*) FROM products WHERE category_id = ?");
|
$checkProducts = $db->prepare("SELECT COUNT(*) FROM products WHERE category_id = ?");
|
||||||
$checkProducts->execute([$categoryId]);
|
$checkProducts->execute([$categoryId]);
|
||||||
$productCount = $checkProducts->fetchColumn();
|
$productCount = $checkProducts->fetchColumn();
|
||||||
|
|
||||||
// 2. Проверяем, есть ли дочерние категории
|
|
||||||
$checkChildren = $db->prepare("SELECT COUNT(*) FROM categories WHERE parent_id = ?");
|
$checkChildren = $db->prepare("SELECT COUNT(*) FROM categories WHERE parent_id = ?");
|
||||||
$checkChildren->execute([$categoryId]);
|
$checkChildren->execute([$categoryId]);
|
||||||
$childCount = $checkChildren->fetchColumn();
|
$childCount = $checkChildren->fetchColumn();
|
||||||
|
|
||||||
if ($productCount > 0) {
|
if ($productCount > 0) {
|
||||||
// Если есть товары, делаем категорию неактивной вместо удаления
|
|
||||||
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
|
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
|
||||||
$stmt->execute([$categoryId]);
|
$stmt->execute([$categoryId]);
|
||||||
|
|
||||||
header('Location: admin_panel.php?action=categories&message=Категория+скрыта+(содержит+товары)');
|
header('Location: admin_panel.php?action=categories&message=Категория+скрыта+(содержит+товары)');
|
||||||
exit();
|
exit();
|
||||||
} elseif ($childCount > 0) {
|
} elseif ($childCount > 0) {
|
||||||
// Если есть дочерние категории, делаем неактивной
|
|
||||||
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
|
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
|
||||||
$stmt->execute([$categoryId]);
|
$stmt->execute([$categoryId]);
|
||||||
|
|
||||||
header('Location: admin_panel.php?action=categories&message=Категория+скрыта+(имеет+дочерние+категории)');
|
header('Location: admin_panel.php?action=categories&message=Категория+скрыта+(имеет+дочерние+категории)');
|
||||||
exit();
|
exit();
|
||||||
} else {
|
} else {
|
||||||
// Если нет товаров и дочерних категорий, удаляем
|
|
||||||
$stmt = $db->prepare("DELETE FROM categories WHERE category_id = ?");
|
$stmt = $db->prepare("DELETE FROM categories WHERE category_id = ?");
|
||||||
$stmt->execute([$categoryId]);
|
$stmt->execute([$categoryId]);
|
||||||
|
|
||||||
@@ -236,10 +223,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Получение данных для отображения
|
|
||||||
try {
|
try {
|
||||||
// Статистика
|
|
||||||
$stats = [
|
$stats = [
|
||||||
'total_products' => $db->query("SELECT COUNT(*) FROM products")->fetchColumn(),
|
'total_products' => $db->query("SELECT COUNT(*) FROM products")->fetchColumn(),
|
||||||
'active_products' => $db->query("SELECT COUNT(*) FROM products WHERE is_available = TRUE")->fetchColumn(),
|
'active_products' => $db->query("SELECT COUNT(*) FROM products WHERE is_available = TRUE")->fetchColumn(),
|
||||||
@@ -248,10 +233,8 @@ try {
|
|||||||
'revenue' => $db->query("SELECT COALESCE(SUM(final_amount), 0) FROM orders WHERE status = 'completed'")->fetchColumn()
|
'revenue' => $db->query("SELECT COALESCE(SUM(final_amount), 0) FROM orders WHERE status = 'completed'")->fetchColumn()
|
||||||
];
|
];
|
||||||
|
|
||||||
// Получаем все категории
|
|
||||||
$allCategories = $db->query("SELECT * FROM categories WHERE is_active = TRUE ORDER BY name")->fetchAll();
|
$allCategories = $db->query("SELECT * FROM categories WHERE is_active = TRUE ORDER BY name")->fetchAll();
|
||||||
|
|
||||||
// Получаем родительские категории
|
|
||||||
$parentCategories = $db->query("SELECT * FROM categories WHERE parent_id IS NULL AND is_active = TRUE ORDER BY name")->fetchAll();
|
$parentCategories = $db->query("SELECT * FROM categories WHERE parent_id IS NULL AND is_active = TRUE ORDER BY name")->fetchAll();
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
@@ -387,7 +370,7 @@ try {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ($action == 'dashboard'): ?>
|
<?php if ($action == 'dashboard'): ?>
|
||||||
<!-- Дашборд -->
|
|
||||||
<h2>Статистика</h2>
|
<h2>Статистика</h2>
|
||||||
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 20px 0;">
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 20px 0;">
|
||||||
<div style="background: white; padding: 20px; border-radius: 5px; text-align: center;">
|
<div style="background: white; padding: 20px; border-radius: 5px; text-align: center;">
|
||||||
@@ -418,7 +401,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php elseif ($action == 'products'): ?>
|
<?php elseif ($action == 'products'): ?>
|
||||||
<!-- Товары -->
|
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
||||||
<h2>Управление товарами</h2>
|
<h2>Управление товарами</h2>
|
||||||
<div>
|
<div>
|
||||||
@@ -492,7 +475,7 @@ try {
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php elseif ($action == 'categories'): ?>
|
<?php elseif ($action == 'categories'): ?>
|
||||||
<!-- Категории -->
|
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
||||||
<h2>Управление категориями</h2>
|
<h2>Управление категориями</h2>
|
||||||
<a href="?action=add_category" class="btn btn-success">
|
<a href="?action=add_category" class="btn btn-success">
|
||||||
@@ -520,12 +503,11 @@ try {
|
|||||||
<td><?= htmlspecialchars($category['parent_name'] ?? '—') ?></td>
|
<td><?= htmlspecialchars($category['parent_name'] ?? '—') ?></td>
|
||||||
<td><?= $category['product_count'] ?></td>
|
<td><?= $category['product_count'] ?></td>
|
||||||
<td class="action-buttons">
|
<td class="action-buttons">
|
||||||
<!-- Кнопка редактирования -->
|
|
||||||
<a href="?action=edit_category&id=<?= $category['category_id'] ?>" class="btn btn-warning btn-sm">
|
<a href="?action=edit_category&id=<?= $category['category_id'] ?>" class="btn btn-warning btn-sm">
|
||||||
<i class="fas fa-edit"></i> Редактировать
|
<i class="fas fa-edit"></i> Редактировать
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<!-- Кнопка удаления с AJAX -->
|
|
||||||
<button type="button" class="btn btn-danger btn-sm delete-category-btn"
|
<button type="button" class="btn btn-danger btn-sm delete-category-btn"
|
||||||
data-id="<?= $category['category_id'] ?>"
|
data-id="<?= $category['category_id'] ?>"
|
||||||
<?= $category['product_count'] > 0 ? 'disabled' : '' ?>>
|
<?= $category['product_count'] > 0 ? 'disabled' : '' ?>>
|
||||||
@@ -538,7 +520,7 @@ try {
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php elseif (in_array($action, ['add_category', 'edit_category'])): ?>
|
<?php elseif (in_array($action, ['add_category', 'edit_category'])): ?>
|
||||||
<!-- Форма добавления/редактирования категории -->
|
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<h2><?= $action == 'add_category' ? 'Добавление категории' : 'Редактирование категории' ?></h2>
|
<h2><?= $action == 'add_category' ? 'Добавление категории' : 'Редактирование категории' ?></h2>
|
||||||
|
|
||||||
@@ -597,7 +579,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php elseif ($action == 'orders'): ?>
|
<?php elseif ($action == 'orders'): ?>
|
||||||
<!-- Заказы -->
|
|
||||||
<h2>Заказы</h2>
|
<h2>Заказы</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -629,7 +611,7 @@ try {
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php elseif ($action == 'users'): ?>
|
<?php elseif ($action == 'users'): ?>
|
||||||
<!-- Пользователи -->
|
|
||||||
<h2>Пользователи</h2>
|
<h2>Пользователи</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -663,7 +645,7 @@ try {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
// Удаление категории через AJAX
|
|
||||||
$('.delete-category-btn').click(function() {
|
$('.delete-category-btn').click(function() {
|
||||||
const categoryId = $(this).data('id');
|
const categoryId = $(this).data('id');
|
||||||
const btn = $(this);
|
const btn = $(this);
|
||||||
@@ -686,7 +668,6 @@ $('.delete-category-btn').click(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка формы категории
|
|
||||||
$('#categoryForm').submit(function(e) {
|
$('#categoryForm').submit(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Проверяем наличие товара на складе
|
|
||||||
$checkStock = $db->prepare("
|
$checkStock = $db->prepare("
|
||||||
SELECT stock_quantity, name, price
|
SELECT stock_quantity, name, price
|
||||||
FROM products
|
FROM products
|
||||||
@@ -39,7 +39,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, есть ли товар уже в корзине пользователя
|
|
||||||
$checkCart = $db->prepare("
|
$checkCart = $db->prepare("
|
||||||
SELECT cart_id, quantity
|
SELECT cart_id, quantity
|
||||||
FROM cart
|
FROM cart
|
||||||
@@ -49,10 +48,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
$cartItem = $checkCart->fetch();
|
$cartItem = $checkCart->fetch();
|
||||||
|
|
||||||
if ($cartItem) {
|
if ($cartItem) {
|
||||||
// Обновляем количество
|
|
||||||
$newQuantity = $cartItem['quantity'] + $quantity;
|
$newQuantity = $cartItem['quantity'] + $quantity;
|
||||||
|
|
||||||
// Проверяем общее количество
|
|
||||||
if ($newQuantity > $product['stock_quantity']) {
|
if ($newQuantity > $product['stock_quantity']) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Превышено доступное количество']);
|
echo json_encode(['success' => false, 'message' => 'Превышено доступное количество']);
|
||||||
exit();
|
exit();
|
||||||
@@ -65,7 +63,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
");
|
");
|
||||||
$updateStmt->execute([$newQuantity, $cartItem['cart_id']]);
|
$updateStmt->execute([$newQuantity, $cartItem['cart_id']]);
|
||||||
} else {
|
} else {
|
||||||
// Добавляем новый товар
|
|
||||||
$insertStmt = $db->prepare("
|
$insertStmt = $db->prepare("
|
||||||
INSERT INTO cart (user_id, product_id, quantity)
|
INSERT INTO cart (user_id, product_id, quantity)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
@@ -73,7 +71,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
$insertStmt->execute([$user_id, $product_id, $quantity]);
|
$insertStmt->execute([$user_id, $product_id, $quantity]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обновляем сессию
|
|
||||||
if (!isset($_SESSION['cart'])) {
|
if (!isset($_SESSION['cart'])) {
|
||||||
$_SESSION['cart'] = [];
|
$_SESSION['cart'] = [];
|
||||||
}
|
}
|
||||||
@@ -89,7 +86,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получаем общее количество товаров в корзине
|
|
||||||
$cartCountStmt = $db->prepare("
|
$cartCountStmt = $db->prepare("
|
||||||
SELECT SUM(quantity) as total
|
SELECT SUM(quantity) as total
|
||||||
FROM cart
|
FROM cart
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// login_handler.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Проверяем пользователя в базе данных
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
SELECT user_id, email, password_hash, full_name, phone, city, is_admin, is_active
|
SELECT user_id, email, password_hash, full_name, phone, city, is_admin, is_active
|
||||||
FROM users
|
FROM users
|
||||||
@@ -34,13 +34,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем пароль
|
|
||||||
if (!password_verify($password, $user['password_hash'])) {
|
if (!password_verify($password, $user['password_hash'])) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Неверный пароль']);
|
echo json_encode(['success' => false, 'message' => 'Неверный пароль']);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сохраняем в сессию
|
|
||||||
$_SESSION['user_id'] = $user['user_id'];
|
$_SESSION['user_id'] = $user['user_id'];
|
||||||
$_SESSION['user_email'] = $user['email'];
|
$_SESSION['user_email'] = $user['email'];
|
||||||
$_SESSION['full_name'] = $user['full_name'];
|
$_SESSION['full_name'] = $user['full_name'];
|
||||||
@@ -50,7 +48,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$_SESSION['isAdmin'] = (bool)$user['is_admin'];
|
$_SESSION['isAdmin'] = (bool)$user['is_admin'];
|
||||||
$_SESSION['login_time'] = time();
|
$_SESSION['login_time'] = time();
|
||||||
|
|
||||||
// Обновляем время последнего входа
|
|
||||||
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
||||||
$updateStmt->execute([$user['user_id']]);
|
$updateStmt->execute([$user['user_id']]);
|
||||||
|
|
||||||
|
|||||||
15
api/cart.php
15
api/cart.php
@@ -1,14 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* API для работы с корзиной
|
|
||||||
* Эндпоинты: add, update, remove, get, count
|
|
||||||
*/
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
// Проверка авторизации
|
|
||||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Требуется авторизация']);
|
echo json_encode(['success' => false, 'message' => 'Требуется авторизация']);
|
||||||
exit();
|
exit();
|
||||||
@@ -30,7 +26,6 @@ try {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем существование товара
|
|
||||||
$checkProduct = $db->prepare("SELECT product_id, stock_quantity FROM products WHERE product_id = ? AND is_available = TRUE");
|
$checkProduct = $db->prepare("SELECT product_id, stock_quantity FROM products WHERE product_id = ? AND is_available = TRUE");
|
||||||
$checkProduct->execute([$productId]);
|
$checkProduct->execute([$productId]);
|
||||||
$product = $checkProduct->fetch();
|
$product = $checkProduct->fetch();
|
||||||
@@ -40,18 +35,17 @@ try {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, есть ли товар уже в корзине
|
|
||||||
$checkCart = $db->prepare("SELECT cart_id, quantity FROM cart WHERE user_id = ? AND product_id = ?");
|
$checkCart = $db->prepare("SELECT cart_id, quantity FROM cart WHERE user_id = ? AND product_id = ?");
|
||||||
$checkCart->execute([$userId, $productId]);
|
$checkCart->execute([$userId, $productId]);
|
||||||
$cartItem = $checkCart->fetch();
|
$cartItem = $checkCart->fetch();
|
||||||
|
|
||||||
if ($cartItem) {
|
if ($cartItem) {
|
||||||
// Обновляем количество
|
|
||||||
$newQuantity = $cartItem['quantity'] + $quantity;
|
$newQuantity = $cartItem['quantity'] + $quantity;
|
||||||
$stmt = $db->prepare("UPDATE cart SET quantity = ?, updated_at = CURRENT_TIMESTAMP WHERE cart_id = ?");
|
$stmt = $db->prepare("UPDATE cart SET quantity = ?, updated_at = CURRENT_TIMESTAMP WHERE cart_id = ?");
|
||||||
$stmt->execute([$newQuantity, $cartItem['cart_id']]);
|
$stmt->execute([$newQuantity, $cartItem['cart_id']]);
|
||||||
} else {
|
} else {
|
||||||
// Добавляем новый товар
|
|
||||||
$stmt = $db->prepare("INSERT INTO cart (user_id, product_id, quantity) VALUES (?, ?, ?)");
|
$stmt = $db->prepare("INSERT INTO cart (user_id, product_id, quantity) VALUES (?, ?, ?)");
|
||||||
$stmt->execute([$userId, $productId, $quantity]);
|
$stmt->execute([$userId, $productId, $quantity]);
|
||||||
}
|
}
|
||||||
@@ -64,7 +58,7 @@ try {
|
|||||||
$quantity = (int)($_POST['quantity'] ?? 1);
|
$quantity = (int)($_POST['quantity'] ?? 1);
|
||||||
|
|
||||||
if ($quantity <= 0) {
|
if ($quantity <= 0) {
|
||||||
// Удаляем товар если количество 0
|
|
||||||
$stmt = $db->prepare("DELETE FROM cart WHERE user_id = ? AND product_id = ?");
|
$stmt = $db->prepare("DELETE FROM cart WHERE user_id = ? AND product_id = ?");
|
||||||
$stmt->execute([$userId, $productId]);
|
$stmt->execute([$userId, $productId]);
|
||||||
} else {
|
} else {
|
||||||
@@ -131,4 +125,3 @@ try {
|
|||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Ошибка базы данных: ' . $e->getMessage()]);
|
echo json_encode(['success' => false, 'message' => 'Ошибка базы данных: ' . $e->getMessage()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// get_cart.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ if ($user_id == 0) {
|
|||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Получаем корзину из БД
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
c.cart_id,
|
c.cart_id,
|
||||||
@@ -36,7 +36,6 @@ try {
|
|||||||
$stmt->execute([$user_id]);
|
$stmt->execute([$user_id]);
|
||||||
$cart_items = $stmt->fetchAll();
|
$cart_items = $stmt->fetchAll();
|
||||||
|
|
||||||
// Обновляем сессию
|
|
||||||
$_SESSION['cart'] = [];
|
$_SESSION['cart'] = [];
|
||||||
foreach ($cart_items as $item) {
|
foreach ($cart_items as $item) {
|
||||||
$_SESSION['cart'][$item['product_id']] = [
|
$_SESSION['cart'][$item['product_id']] = [
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// get_cart_count.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
// Проверяем авторизацию администратора
|
|
||||||
if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Доступ запрещен']);
|
echo json_encode(['success' => false, 'message' => 'Доступ запрещен']);
|
||||||
exit();
|
exit();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// process_order.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
@@ -21,7 +21,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
try {
|
try {
|
||||||
$db->beginTransaction();
|
$db->beginTransaction();
|
||||||
|
|
||||||
// Получаем данные из формы
|
|
||||||
$customer_name = $_POST['full_name'] ?? '';
|
$customer_name = $_POST['full_name'] ?? '';
|
||||||
$customer_email = $_POST['email'] ?? '';
|
$customer_email = $_POST['email'] ?? '';
|
||||||
$customer_phone = $_POST['phone'] ?? '';
|
$customer_phone = $_POST['phone'] ?? '';
|
||||||
@@ -33,10 +32,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$discount_amount = floatval($_POST['discount'] ?? 0);
|
$discount_amount = floatval($_POST['discount'] ?? 0);
|
||||||
$delivery_cost = floatval($_POST['delivery_price'] ?? 2000);
|
$delivery_cost = floatval($_POST['delivery_price'] ?? 2000);
|
||||||
|
|
||||||
// Генерируем номер заказа
|
|
||||||
$order_number = 'ORD-' . date('Ymd-His') . '-' . rand(1000, 9999);
|
$order_number = 'ORD-' . date('Ymd-His') . '-' . rand(1000, 9999);
|
||||||
|
|
||||||
// Получаем корзину пользователя
|
|
||||||
$cartStmt = $db->prepare("
|
$cartStmt = $db->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
c.product_id,
|
c.product_id,
|
||||||
@@ -55,7 +52,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
throw new Exception('Корзина пуста');
|
throw new Exception('Корзина пуста');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Рассчитываем итоги
|
|
||||||
$total_amount = 0;
|
$total_amount = 0;
|
||||||
foreach ($cart_items as $item) {
|
foreach ($cart_items as $item) {
|
||||||
$total_amount += $item['price'] * $item['quantity'];
|
$total_amount += $item['price'] * $item['quantity'];
|
||||||
@@ -63,7 +59,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
$final_amount = $total_amount - $discount_amount + $delivery_cost;
|
$final_amount = $total_amount - $discount_amount + $delivery_cost;
|
||||||
|
|
||||||
// Создаем заказ
|
|
||||||
$orderStmt = $db->prepare("
|
$orderStmt = $db->prepare("
|
||||||
INSERT INTO orders (
|
INSERT INTO orders (
|
||||||
user_id, order_number, total_amount, discount_amount,
|
user_id, order_number, total_amount, discount_amount,
|
||||||
@@ -83,9 +78,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
$order_id = $orderStmt->fetchColumn();
|
$order_id = $orderStmt->fetchColumn();
|
||||||
|
|
||||||
// Добавляем товары в заказ и обновляем остатки
|
|
||||||
foreach ($cart_items as $item) {
|
foreach ($cart_items as $item) {
|
||||||
// Добавляем в order_items
|
|
||||||
$itemStmt = $db->prepare("
|
$itemStmt = $db->prepare("
|
||||||
INSERT INTO order_items (
|
INSERT INTO order_items (
|
||||||
order_id, product_id, product_name,
|
order_id, product_id, product_name,
|
||||||
@@ -99,7 +93,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$item['quantity'], $item['price'], $item_total
|
$item['quantity'], $item['price'], $item_total
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Обновляем остатки на складе
|
|
||||||
$updateStmt = $db->prepare("
|
$updateStmt = $db->prepare("
|
||||||
UPDATE products
|
UPDATE products
|
||||||
SET stock_quantity = stock_quantity - ?,
|
SET stock_quantity = stock_quantity - ?,
|
||||||
@@ -109,16 +102,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$updateStmt->execute([$item['quantity'], $item['product_id']]);
|
$updateStmt->execute([$item['quantity'], $item['product_id']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Очищаем корзину
|
|
||||||
$clearCartStmt = $db->prepare("DELETE FROM cart WHERE user_id = ?");
|
$clearCartStmt = $db->prepare("DELETE FROM cart WHERE user_id = ?");
|
||||||
$clearCartStmt->execute([$user_id]);
|
$clearCartStmt->execute([$user_id]);
|
||||||
|
|
||||||
// Очищаем сессию
|
|
||||||
unset($_SESSION['cart']);
|
unset($_SESSION['cart']);
|
||||||
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
|
|
||||||
// Перенаправляем на страницу успеха
|
|
||||||
header('Location: order_success.php?id=' . $order_id);
|
header('Location: order_success.php?id=' . $order_id);
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
// register_handler.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
// Получаем данные из формы
|
|
||||||
$full_name = trim($_POST['fio'] ?? '');
|
$full_name = trim($_POST['fio'] ?? '');
|
||||||
$city = trim($_POST['city'] ?? '');
|
$city = trim($_POST['city'] ?? '');
|
||||||
$email = trim($_POST['email'] ?? '');
|
$email = trim($_POST['email'] ?? '');
|
||||||
@@ -14,7 +13,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$password = $_POST['password'] ?? '';
|
$password = $_POST['password'] ?? '';
|
||||||
$confirm_password = $_POST['confirm-password'] ?? '';
|
$confirm_password = $_POST['confirm-password'] ?? '';
|
||||||
|
|
||||||
// Валидация данных
|
|
||||||
if (empty($full_name) || strlen($full_name) < 3) {
|
if (empty($full_name) || strlen($full_name) < 3) {
|
||||||
$errors[] = 'ФИО должно содержать минимум 3 символа';
|
$errors[] = 'ФИО должно содержать минимум 3 символа';
|
||||||
}
|
}
|
||||||
@@ -39,12 +37,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$errors[] = 'Пароли не совпадают';
|
$errors[] = 'Пароли не совпадают';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка согласия с условиями
|
|
||||||
if (!isset($_POST['privacy']) || $_POST['privacy'] !== 'on') {
|
if (!isset($_POST['privacy']) || $_POST['privacy'] !== 'on') {
|
||||||
$errors[] = 'Необходимо согласие с условиями обработки персональных данных';
|
$errors[] = 'Необходимо согласие с условиями обработки персональных данных';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Если есть ошибки, возвращаем на форму
|
|
||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
$_SESSION['registration_errors'] = $errors;
|
$_SESSION['registration_errors'] = $errors;
|
||||||
$_SESSION['old_data'] = [
|
$_SESSION['old_data'] = [
|
||||||
@@ -57,11 +53,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Подключаемся к базе данных
|
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Проверяем, существует ли пользователь с таким email
|
|
||||||
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
||||||
$checkStmt->execute([$email]);
|
$checkStmt->execute([$email]);
|
||||||
|
|
||||||
@@ -77,57 +72,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Хэшируем пароль
|
|
||||||
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
// Определяем, является ли пользователь администратором
|
|
||||||
$is_admin = false;
|
$is_admin = false;
|
||||||
$admin_emails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
$admin_emails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
||||||
if (in_array(strtolower($email), $admin_emails)) {
|
if (in_array(strtolower($email), $admin_emails)) {
|
||||||
$is_admin = true;
|
$is_admin = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// РАЗНЫЕ ВАРИАНТЫ ДЛЯ ТЕСТИРОВАНИЯ - РАСКОММЕНТИРУЙТЕ НУЖНЫЙ
|
|
||||||
|
|
||||||
// Вариант 1: С явным преобразованием boolean (самый надежный)
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
INSERT INTO users (email, password_hash, full_name, phone, city, is_admin)
|
INSERT INTO users (email, password_hash, full_name, phone, city, is_admin)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
RETURNING user_id
|
RETURNING user_id
|
||||||
");
|
");
|
||||||
|
|
||||||
// Преобразуем boolean в integer для PostgreSQL
|
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
$email,
|
$email,
|
||||||
$password_hash,
|
$password_hash,
|
||||||
$full_name,
|
$full_name,
|
||||||
$phone,
|
$phone,
|
||||||
$city,
|
$city,
|
||||||
$is_admin ? 1 : 0 // Преобразуем в integer (1 или 0)
|
$is_admin ? 1 : 0
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Вариант 2: С использованием CAST в SQL (альтернатива)
|
|
||||||
/*
|
|
||||||
$stmt = $db->prepare("
|
|
||||||
INSERT INTO users (email, password_hash, full_name, phone, city, is_admin)
|
|
||||||
VALUES (?, ?, ?, ?, ?, CAST(? AS boolean))
|
|
||||||
RETURNING user_id
|
|
||||||
");
|
|
||||||
|
|
||||||
$stmt->execute([
|
|
||||||
$email,
|
|
||||||
$password_hash,
|
|
||||||
$full_name,
|
|
||||||
$phone,
|
|
||||||
$city,
|
|
||||||
$is_admin ? 'true' : 'false' // Строковые значения true/false
|
|
||||||
]);
|
|
||||||
*/
|
|
||||||
|
|
||||||
$user_id = $stmt->fetchColumn();
|
$user_id = $stmt->fetchColumn();
|
||||||
|
|
||||||
if ($user_id) {
|
if ($user_id) {
|
||||||
// Автоматически авторизуем пользователя
|
|
||||||
$_SESSION['user_id'] = $user_id;
|
$_SESSION['user_id'] = $user_id;
|
||||||
$_SESSION['user_email'] = $email;
|
$_SESSION['user_email'] = $email;
|
||||||
$_SESSION['full_name'] = $full_name;
|
$_SESSION['full_name'] = $full_name;
|
||||||
@@ -137,11 +108,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$_SESSION['isAdmin'] = $is_admin;
|
$_SESSION['isAdmin'] = $is_admin;
|
||||||
$_SESSION['login_time'] = time();
|
$_SESSION['login_time'] = time();
|
||||||
|
|
||||||
// Обновляем время последнего входа
|
|
||||||
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
||||||
$updateStmt->execute([$user_id]);
|
$updateStmt->execute([$user_id]);
|
||||||
|
|
||||||
// Перенаправляем на главную или каталог
|
|
||||||
$_SESSION['registration_success'] = 'Регистрация прошла успешно! ' .
|
$_SESSION['registration_success'] = 'Регистрация прошла успешно! ' .
|
||||||
($is_admin ? 'Вы зарегистрированы как администратор.' : 'Добро пожаловать в AETERNA!');
|
($is_admin ? 'Вы зарегистрированы как администратор.' : 'Добро пожаловать в AETERNA!');
|
||||||
|
|
||||||
@@ -152,7 +121,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
// Логируем полную ошибку для отладки
|
|
||||||
error_log("Registration DB Error: " . $e->getMessage());
|
error_log("Registration DB Error: " . $e->getMessage());
|
||||||
error_log("SQL State: " . $e->getCode());
|
error_log("SQL State: " . $e->getCode());
|
||||||
error_log("Email: " . $email);
|
error_log("Email: " . $email);
|
||||||
@@ -175,7 +144,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Если запрос не POST, перенаправляем на форму регистрации
|
|
||||||
header('Location: register.php');
|
header('Location: register.php');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для сообщений внизу страницы */
|
|
||||||
.page-messages {
|
.page-messages {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// script.js
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Инициализация корзины
|
|
||||||
let cart = {
|
let cart = {
|
||||||
items: [
|
items: [
|
||||||
{ id: 1, name: 'Кресло OPPORTUNITY', price: 16999, quantity: 1 },
|
{ id: 1, name: 'Кресло OPPORTUNITY', price: 16999, quantity: 1 },
|
||||||
@@ -12,12 +11,10 @@ $(document).ready(function() {
|
|||||||
discount: 0
|
discount: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
// Функция обновления общей суммы
|
|
||||||
function updateTotal() {
|
function updateTotal() {
|
||||||
let productsTotal = 0;
|
let productsTotal = 0;
|
||||||
let totalCount = 0;
|
let totalCount = 0;
|
||||||
|
|
||||||
// Пересчитываем товары
|
|
||||||
$('.products__item').each(function() {
|
$('.products__item').each(function() {
|
||||||
const $item = $(this);
|
const $item = $(this);
|
||||||
const price = parseInt($item.data('price'));
|
const price = parseInt($item.data('price'));
|
||||||
@@ -27,50 +24,39 @@ $(document).ready(function() {
|
|||||||
totalCount += quantity;
|
totalCount += quantity;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обновляем отображение
|
|
||||||
$('.products-total').text(productsTotal + ' ₽');
|
$('.products-total').text(productsTotal + ' ₽');
|
||||||
$('.summary-count').text(totalCount);
|
$('.summary-count').text(totalCount);
|
||||||
$('.total-count').text(totalCount + ' шт.');
|
$('.total-count').text(totalCount + ' шт.');
|
||||||
$('.cart-count').text(totalCount);
|
$('.cart-count').text(totalCount);
|
||||||
|
|
||||||
// Обновляем итоговую сумму
|
|
||||||
const finalTotal = productsTotal + cart.delivery - cart.discount;
|
const finalTotal = productsTotal + cart.delivery - cart.discount;
|
||||||
$('.final-total').text(finalTotal + ' ₽');
|
$('.final-total').text(finalTotal + ' ₽');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция валидации email
|
|
||||||
function validateEmail(email) {
|
function validateEmail(email) {
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
return emailRegex.test(email);
|
return emailRegex.test(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция валидации имени (ФИО)
|
|
||||||
function validateFullName(name) {
|
function validateFullName(name) {
|
||||||
// Проверяем, что имя содержит только буквы, пробелы, дефисы и апострофы
|
|
||||||
const nameRegex = /^[a-zA-Zа-яА-ЯёЁ\s\-']+$/;
|
const nameRegex = /^[a-zA-Zа-яА-ЯёЁ\s\-']+$/;
|
||||||
|
|
||||||
// Проверяем, что имя состоит минимум из 2 слов
|
|
||||||
const words = name.trim().split(/\s+/);
|
const words = name.trim().split(/\s+/);
|
||||||
|
|
||||||
return nameRegex.test(name) && words.length >= 2;
|
return nameRegex.test(name) && words.length >= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция валидации телефона
|
|
||||||
function validatePhone(phone) {
|
function validatePhone(phone) {
|
||||||
// Российский формат телефона: +7XXXXXXXXXX
|
|
||||||
const phoneRegex = /^\+7\d{10}$/;
|
const phoneRegex = /^\+7\d{10}$/;
|
||||||
return phoneRegex.test(phone);
|
return phoneRegex.test(phone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция отображения сообщения
|
|
||||||
function showMessage(messageId, duration = 5000) {
|
function showMessage(messageId, duration = 5000) {
|
||||||
// Скрываем все сообщения
|
|
||||||
$('.message').hide();
|
$('.message').hide();
|
||||||
|
|
||||||
// Показываем нужное сообщение
|
|
||||||
$(messageId).fadeIn(300);
|
$(messageId).fadeIn(300);
|
||||||
|
|
||||||
// Автоматически скрываем через указанное время
|
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$(messageId).fadeOut(300);
|
$(messageId).fadeOut(300);
|
||||||
@@ -78,7 +64,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция показа ошибки приватности
|
|
||||||
function showPrivacyError(show) {
|
function showPrivacyError(show) {
|
||||||
if (show) {
|
if (show) {
|
||||||
$('#privacy-error').show();
|
$('#privacy-error').show();
|
||||||
@@ -87,9 +72,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция отображения ошибки конкретного поля
|
|
||||||
function showFieldError(fieldId, message) {
|
function showFieldError(fieldId, message) {
|
||||||
// Убираем старые ошибки
|
|
||||||
$(fieldId).removeClass('error-input');
|
$(fieldId).removeClass('error-input');
|
||||||
$(fieldId + '-error').remove();
|
$(fieldId + '-error').remove();
|
||||||
|
|
||||||
@@ -99,7 +82,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация поля при потере фокуса с указанием конкретной ошибки
|
|
||||||
$('#fullname').on('blur', function() {
|
$('#fullname').on('blur', function() {
|
||||||
const value = $(this).val().trim();
|
const value = $(this).val().trim();
|
||||||
if (value) {
|
if (value) {
|
||||||
@@ -139,7 +121,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Валидация обязательных полей
|
|
||||||
$('#region').on('blur', function() {
|
$('#region').on('blur', function() {
|
||||||
const value = $(this).val().trim();
|
const value = $(this).val().trim();
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@@ -158,13 +139,11 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Очистка ошибки при начале ввода
|
|
||||||
$('.form__input').on('input', function() {
|
$('.form__input').on('input', function() {
|
||||||
const fieldId = '#' + $(this).attr('id');
|
const fieldId = '#' + $(this).attr('id');
|
||||||
showFieldError(fieldId, '');
|
showFieldError(fieldId, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик увеличения количества
|
|
||||||
$('.products__qty-btn.plus').click(function() {
|
$('.products__qty-btn.plus').click(function() {
|
||||||
const $qtyValue = $(this).siblings('.products__qty-value');
|
const $qtyValue = $(this).siblings('.products__qty-value');
|
||||||
let quantity = parseInt($qtyValue.text());
|
let quantity = parseInt($qtyValue.text());
|
||||||
@@ -172,7 +151,6 @@ $(document).ready(function() {
|
|||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик уменьшения количества
|
|
||||||
$('.products__qty-btn.minus').click(function() {
|
$('.products__qty-btn.minus').click(function() {
|
||||||
const $qtyValue = $(this).siblings('.products__qty-value');
|
const $qtyValue = $(this).siblings('.products__qty-value');
|
||||||
let quantity = parseInt($qtyValue.text());
|
let quantity = parseInt($qtyValue.text());
|
||||||
@@ -182,21 +160,18 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик удаления товара
|
|
||||||
$('.remove-from-cart').click(function() {
|
$('.remove-from-cart').click(function() {
|
||||||
const $productItem = $(this).closest('.products__item');
|
const $productItem = $(this).closest('.products__item');
|
||||||
$productItem.fadeOut(300, function() {
|
$productItem.fadeOut(300, function() {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
updateTotal();
|
updateTotal();
|
||||||
|
|
||||||
// Показываем сообщение, если корзина пуста
|
|
||||||
if ($('.products__item').length === 0) {
|
if ($('.products__item').length === 0) {
|
||||||
$('.products__list').html('<div class="empty-cart">Корзина пуста</div>');
|
$('.products__list').html('<div class="empty-cart">Корзина пуста</div>');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик применения промокода
|
|
||||||
$('.promo__btn').click(function() {
|
$('.promo__btn').click(function() {
|
||||||
const promoCode = $('.promo__input').val().toUpperCase();
|
const promoCode = $('.promo__input').val().toUpperCase();
|
||||||
|
|
||||||
@@ -218,7 +193,6 @@ $(document).ready(function() {
|
|||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик выбора доставки
|
|
||||||
$('input[name="delivery"]').change(function() {
|
$('input[name="delivery"]').change(function() {
|
||||||
if ($(this).val() === 'pickup') {
|
if ($(this).val() === 'pickup') {
|
||||||
cart.delivery = 0;
|
cart.delivery = 0;
|
||||||
@@ -230,16 +204,13 @@ $(document).ready(function() {
|
|||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Функция проверки всех полей формы
|
|
||||||
function validateForm() {
|
function validateForm() {
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
let errorMessages = [];
|
let errorMessages = [];
|
||||||
|
|
||||||
// Очищаем все старые ошибки
|
|
||||||
$('.field-error').remove();
|
$('.field-error').remove();
|
||||||
$('.form__input').removeClass('error-input');
|
$('.form__input').removeClass('error-input');
|
||||||
|
|
||||||
// Проверка обязательных полей
|
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
{
|
{
|
||||||
id: '#fullname',
|
id: '#fullname',
|
||||||
@@ -278,7 +249,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// Проверяем каждое поле
|
|
||||||
requiredFields.forEach(field => {
|
requiredFields.forEach(field => {
|
||||||
if (field.required && (!field.value || !field.validator(field.value))) {
|
if (field.required && (!field.value || !field.validator(field.value))) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -287,7 +257,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Проверка согласия на обработку данных
|
|
||||||
if (!$('#privacy-checkbox').is(':checked')) {
|
if (!$('#privacy-checkbox').is(':checked')) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
showPrivacyError(true);
|
showPrivacyError(true);
|
||||||
@@ -296,12 +265,10 @@ $(document).ready(function() {
|
|||||||
showPrivacyError(false);
|
showPrivacyError(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показываем общее сообщение, если есть ошибки
|
|
||||||
if (!isValid && errorMessages.length > 0) {
|
if (!isValid && errorMessages.length > 0) {
|
||||||
showMessage('#form-error', 5000);
|
showMessage('#form-error', 5000);
|
||||||
$('#form-error').text('Исправьте следующие ошибки: ' + errorMessages.join('; ')).removeClass('success').addClass('error');
|
$('#form-error').text('Исправьте следующие ошибки: ' + errorMessages.join('; ')).removeClass('success').addClass('error');
|
||||||
|
|
||||||
// Прокручиваем к первой ошибке
|
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $('.error-input').first().offset().top - 100
|
scrollTop: $('.error-input').first().offset().top - 100
|
||||||
}, 500);
|
}, 500);
|
||||||
@@ -310,26 +277,20 @@ $(document).ready(function() {
|
|||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обработчик оформления заказа
|
|
||||||
$('#submit-order').click(function() {
|
$('#submit-order').click(function() {
|
||||||
// Проверка валидации всех полей
|
|
||||||
if (!validateForm()) {
|
if (!validateForm()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Симуляция отправки заказа
|
|
||||||
$(this).prop('disabled', true).text('ОБРАБОТКА...');
|
$(this).prop('disabled', true).text('ОБРАБОТКА...');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
showMessage('#order-success', 5000);
|
showMessage('#order-success', 5000);
|
||||||
$(this).prop('disabled', false).text('ОФОРМИТЬ ЗАКАЗ');
|
$(this).prop('disabled', false).text('ОФОРМИТЬ ЗАКАЗ');
|
||||||
|
|
||||||
// Здесь можно добавить редирект на страницу благодарности
|
|
||||||
// window.location.href = 'спасибо.html';
|
|
||||||
}, 2000);
|
}, 2000);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Маска для телефона
|
|
||||||
$('#phone').on('input', function() {
|
$('#phone').on('input', function() {
|
||||||
let phone = $(this).val().replace(/\D/g, '');
|
let phone = $(this).val().replace(/\D/g, '');
|
||||||
if (phone.length > 0) {
|
if (phone.length > 0) {
|
||||||
@@ -341,6 +302,5 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Инициализация при загрузке
|
|
||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Функции для отображения сообщений
|
|
||||||
function showMessage(type, text) {
|
function showMessage(type, text) {
|
||||||
const messageId = type + 'Message';
|
const messageId = type + 'Message';
|
||||||
const $message = $('#' + messageId);
|
const $message = $('#' + messageId);
|
||||||
@@ -9,30 +9,25 @@ $(document).ready(function() {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка, является ли email администратора
|
|
||||||
function isAdminEmail(email) {
|
function isAdminEmail(email) {
|
||||||
const adminEmails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
const adminEmails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
||||||
return adminEmails.includes(email.toLowerCase());
|
return adminEmails.includes(email.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация ФИО (без цифр)
|
|
||||||
function validateFIO(fio) {
|
function validateFIO(fio) {
|
||||||
const words = fio.trim().split(/\s+/);
|
const words = fio.trim().split(/\s+/);
|
||||||
// Проверяем, что минимум 2 слова и нет цифр
|
|
||||||
const hasNoDigits = !/\d/.test(fio);
|
const hasNoDigits = !/\d/.test(fio);
|
||||||
return words.length >= 2 && words.every(word => word.length >= 2) && hasNoDigits;
|
return words.length >= 2 && words.every(word => word.length >= 2) && hasNoDigits;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация города
|
|
||||||
function validateCity(city) {
|
function validateCity(city) {
|
||||||
return city.trim().length >= 2 && /^[а-яА-ЯёЁ\s-]+$/.test(city);
|
return city.trim().length >= 2 && /^[а-яА-ЯёЁ\s-]+$/.test(city);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация email
|
|
||||||
function validateEmail(email) {
|
function validateEmail(email) {
|
||||||
const localPart = email.split('@')[0];
|
const localPart = email.split('@')[0];
|
||||||
|
|
||||||
// Проверка на кириллические символы перед @
|
|
||||||
if (/[а-яА-ЯёЁ]/.test(localPart)) {
|
if (/[а-яА-ЯёЁ]/.test(localPart)) {
|
||||||
showError('email', 'В тексте перед знаком "@" не должно быть кириллических символов');
|
showError('email', 'В тексте перед знаком "@" не должно быть кириллических символов');
|
||||||
return false;
|
return false;
|
||||||
@@ -48,18 +43,15 @@ $(document).ready(function() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация телефона
|
|
||||||
function validatePhone(phone) {
|
function validatePhone(phone) {
|
||||||
const phoneRegex = /^(\+7|8)[\s-]?\(?\d{3}\)?[\s-]?\d{3}[\s-]?\d{2}[\s-]?\d{2}$/;
|
const phoneRegex = /^(\+7|8)[\s-]?\(?\d{3}\)?[\s-]?\d{3}[\s-]?\d{2}[\s-]?\d{2}$/;
|
||||||
return phoneRegex.test(phone.replace(/\s/g, ''));
|
return phoneRegex.test(phone.replace(/\s/g, ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация пароля
|
|
||||||
function validatePassword(password) {
|
function validatePassword(password) {
|
||||||
return password.length >= 6;
|
return password.length >= 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показать/скрыть ошибку
|
|
||||||
function showError(fieldId, message) {
|
function showError(fieldId, message) {
|
||||||
$('#' + fieldId).addClass('error');
|
$('#' + fieldId).addClass('error');
|
||||||
$('#' + fieldId + '-error').text(message).show();
|
$('#' + fieldId + '-error').text(message).show();
|
||||||
@@ -70,11 +62,9 @@ $(document).ready(function() {
|
|||||||
$('#' + fieldId + '-error').hide();
|
$('#' + fieldId + '-error').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация формы
|
|
||||||
function validateForm() {
|
function validateForm() {
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
|
|
||||||
// Валидация ФИО
|
|
||||||
const fio = $('#fio').val();
|
const fio = $('#fio').val();
|
||||||
if (!validateFIO(fio)) {
|
if (!validateFIO(fio)) {
|
||||||
if (/\d/.test(fio)) {
|
if (/\d/.test(fio)) {
|
||||||
@@ -87,7 +77,6 @@ $(document).ready(function() {
|
|||||||
hideError('fio');
|
hideError('fio');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация города
|
|
||||||
const city = $('#city').val();
|
const city = $('#city').val();
|
||||||
if (!validateCity(city)) {
|
if (!validateCity(city)) {
|
||||||
showError('city', 'Укажите корректное название города (только русские буквы)');
|
showError('city', 'Укажите корректное название города (только русские буквы)');
|
||||||
@@ -96,7 +85,6 @@ $(document).ready(function() {
|
|||||||
hideError('city');
|
hideError('city');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация email
|
|
||||||
const email = $('#email').val();
|
const email = $('#email').val();
|
||||||
if (!validateEmail(email)) {
|
if (!validateEmail(email)) {
|
||||||
showError('email', 'Введите корректный email адрес');
|
showError('email', 'Введите корректный email адрес');
|
||||||
@@ -105,7 +93,6 @@ $(document).ready(function() {
|
|||||||
hideError('email');
|
hideError('email');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация телефона
|
|
||||||
const phone = $('#phone').val();
|
const phone = $('#phone').val();
|
||||||
if (!validatePhone(phone)) {
|
if (!validatePhone(phone)) {
|
||||||
showError('phone', 'Введите номер в формате: +7(912)999-12-23');
|
showError('phone', 'Введите номер в формате: +7(912)999-12-23');
|
||||||
@@ -114,7 +101,6 @@ $(document).ready(function() {
|
|||||||
hideError('phone');
|
hideError('phone');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация пароля
|
|
||||||
const password = $('#password').val();
|
const password = $('#password').val();
|
||||||
if (!validatePassword(password)) {
|
if (!validatePassword(password)) {
|
||||||
showError('password', 'Пароль должен содержать минимум 6 символов');
|
showError('password', 'Пароль должен содержать минимум 6 символов');
|
||||||
@@ -123,7 +109,6 @@ $(document).ready(function() {
|
|||||||
hideError('password');
|
hideError('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка совпадения паролей
|
|
||||||
const confirmPassword = $('#confirm-password').val();
|
const confirmPassword = $('#confirm-password').val();
|
||||||
if (password !== confirmPassword) {
|
if (password !== confirmPassword) {
|
||||||
showError('confirm-password', 'Пароли не совпадают');
|
showError('confirm-password', 'Пароли не совпадают');
|
||||||
@@ -132,7 +117,6 @@ $(document).ready(function() {
|
|||||||
hideError('confirm-password');
|
hideError('confirm-password');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка согласия с условиями
|
|
||||||
if (!$('#privacy').is(':checked')) {
|
if (!$('#privacy').is(':checked')) {
|
||||||
$('#privacy-error').show();
|
$('#privacy-error').show();
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -143,7 +127,6 @@ $(document).ready(function() {
|
|||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Реальная валидация при вводе
|
|
||||||
$('input').on('blur', function() {
|
$('input').on('blur', function() {
|
||||||
const fieldId = $(this).attr('id');
|
const fieldId = $(this).attr('id');
|
||||||
const value = $(this).val();
|
const value = $(this).val();
|
||||||
@@ -199,7 +182,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка отправки формы
|
|
||||||
$('#registrationForm').on('submit', function(e) {
|
$('#registrationForm').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@@ -207,7 +189,6 @@ $(document).ready(function() {
|
|||||||
const email = $('#email').val();
|
const email = $('#email').val();
|
||||||
const isAdmin = isAdminEmail(email);
|
const isAdmin = isAdminEmail(email);
|
||||||
|
|
||||||
// Сохраняем данные пользователя в localStorage
|
|
||||||
const userData = {
|
const userData = {
|
||||||
email: email,
|
email: email,
|
||||||
fio: $('#fio').val(),
|
fio: $('#fio').val(),
|
||||||
@@ -220,12 +201,11 @@ $(document).ready(function() {
|
|||||||
localStorage.setItem('isLoggedIn', 'true');
|
localStorage.setItem('isLoggedIn', 'true');
|
||||||
localStorage.setItem('isAdmin', isAdmin.toString());
|
localStorage.setItem('isAdmin', isAdmin.toString());
|
||||||
|
|
||||||
// Эмуляция успешной регистрации
|
|
||||||
showMessage('success', 'Регистрация прошла успешно! ' +
|
showMessage('success', 'Регистрация прошла успешно! ' +
|
||||||
(isAdmin ? 'Вы зарегистрированы как администратор.' : 'Добро пожаловать в AETERNA!'));
|
(isAdmin ? 'Вы зарегистрированы как администратор.' : 'Добро пожаловать в AETERNA!'));
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// Перенаправление на главную страницу
|
|
||||||
window.location.href = 'cite_mebel.php';
|
window.location.href = 'cite_mebel.php';
|
||||||
}, 2000);
|
}, 2000);
|
||||||
} else {
|
} else {
|
||||||
@@ -233,7 +213,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Плавная прокрутка к якорям
|
|
||||||
$('a[href^="#"]').on('click', function(event) {
|
$('a[href^="#"]').on('click', function(event) {
|
||||||
var target = $(this.getAttribute('href'));
|
var target = $(this.getAttribute('href'));
|
||||||
if (target.length) {
|
if (target.length) {
|
||||||
@@ -244,7 +223,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Переключение между регистрацией и входом
|
|
||||||
$('.login-btn').on('click', function() {
|
$('.login-btn').on('click', function() {
|
||||||
showMessage('warning', 'Переход к форме входа...');
|
showMessage('warning', 'Переход к форме входа...');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -252,13 +230,11 @@ $(document).ready(function() {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка ссылки "Сменить пароль"
|
|
||||||
$('.password-link').on('click', function(e) {
|
$('.password-link').on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
showMessage('warning', 'Функция смены пароля будет доступна после регистрации');
|
showMessage('warning', 'Функция смены пароля будет доступна после регистрации');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Маска для телефона
|
|
||||||
$('#phone').on('input', function() {
|
$('#phone').on('input', function() {
|
||||||
let value = $(this).val().replace(/\D/g, '');
|
let value = $(this).val().replace(/\D/g, '');
|
||||||
if (value.startsWith('7') || value.startsWith('8')) {
|
if (value.startsWith('7') || value.startsWith('8')) {
|
||||||
@@ -274,18 +250,16 @@ $(document).ready(function() {
|
|||||||
$(this).val(value);
|
$(this).val(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Запрет ввода цифр в поле ФИО
|
|
||||||
$('#fio').on('input', function() {
|
$('#fio').on('input', function() {
|
||||||
let value = $(this).val();
|
let value = $(this).val();
|
||||||
// Удаляем цифры из значения
|
|
||||||
value = value.replace(/\d/g, '');
|
value = value.replace(/\d/g, '');
|
||||||
$(this).val(value);
|
$(this).val(value);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Для входа (файл вход.html)
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Проверяем, если пользователь уже вошел
|
|
||||||
if (localStorage.getItem('isLoggedIn') === 'true') {
|
if (localStorage.getItem('isLoggedIn') === 'true') {
|
||||||
const userData = JSON.parse(localStorage.getItem('userData') || '{}');
|
const userData = JSON.parse(localStorage.getItem('userData') || '{}');
|
||||||
if (userData.email) {
|
if (userData.email) {
|
||||||
@@ -293,9 +267,8 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция проверки пароля администратора
|
|
||||||
function checkAdminPassword(email, password) {
|
function checkAdminPassword(email, password) {
|
||||||
// Административные аккаунты
|
|
||||||
const adminAccounts = {
|
const adminAccounts = {
|
||||||
'admin@aeterna.ru': 'admin123',
|
'admin@aeterna.ru': 'admin123',
|
||||||
'administrator@aeterna.ru': 'admin123',
|
'administrator@aeterna.ru': 'admin123',
|
||||||
@@ -305,7 +278,6 @@ $(document).ready(function() {
|
|||||||
return adminAccounts[email.toLowerCase()] === password;
|
return adminAccounts[email.toLowerCase()] === password;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация формы входа
|
|
||||||
$('#loginForm').on('submit', function(e) {
|
$('#loginForm').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@@ -313,7 +285,6 @@ $(document).ready(function() {
|
|||||||
const email = $('#login-email').val();
|
const email = $('#login-email').val();
|
||||||
const password = $('#login-password').val();
|
const password = $('#login-password').val();
|
||||||
|
|
||||||
// Валидация email
|
|
||||||
if (!isValidEmail(email)) {
|
if (!isValidEmail(email)) {
|
||||||
$('#email-error').show();
|
$('#email-error').show();
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -321,7 +292,6 @@ $(document).ready(function() {
|
|||||||
$('#email-error').hide();
|
$('#email-error').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация пароля
|
|
||||||
if (password.length < 6) {
|
if (password.length < 6) {
|
||||||
$('#password-error').show();
|
$('#password-error').show();
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -330,17 +300,15 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
// Здесь обычно отправка данных на сервер
|
|
||||||
showMessage('success', 'Вы успешно вошли в систему!');
|
showMessage('success', 'Вы успешно вошли в систему!');
|
||||||
|
|
||||||
// Перенаправление на главную страницу через 1.5 секунды
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
window.location.href = 'cite_mebel.php';
|
window.location.href = 'cite_mebel.php';
|
||||||
}, 1500);
|
}, 1500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Функция показа сообщений
|
|
||||||
function showMessage(type, text) {
|
function showMessage(type, text) {
|
||||||
const messageId = type + 'Message';
|
const messageId = type + 'Message';
|
||||||
const $message = $('#' + messageId);
|
const $message = $('#' + messageId);
|
||||||
@@ -352,12 +320,10 @@ $(document).ready(function() {
|
|||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Скрываем сообщения об ошибках при фокусе на полях
|
|
||||||
$('input').on('focus', function() {
|
$('input').on('focus', function() {
|
||||||
$(this).next('.error-message').hide();
|
$(this).next('.error-message').hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка чекбокса "Запомнить меня"
|
|
||||||
$('#remember').on('change', function() {
|
$('#remember').on('change', function() {
|
||||||
if ($(this).is(':checked')) {
|
if ($(this).is(':checked')) {
|
||||||
const email = $('#login-email').val();
|
const email = $('#login-email').val();
|
||||||
@@ -369,14 +335,12 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Автозаполнение email, если пользователь выбрал "Запомнить меня"
|
|
||||||
const rememberedEmail = localStorage.getItem('rememberedEmail');
|
const rememberedEmail = localStorage.getItem('rememberedEmail');
|
||||||
if (rememberedEmail) {
|
if (rememberedEmail) {
|
||||||
$('#login-email').val(rememberedEmail);
|
$('#login-email').val(rememberedEmail);
|
||||||
$('#remember').prop('checked', true);
|
$('#remember').prop('checked', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обработка ссылки "Забыли пароль?"
|
|
||||||
$('.forgot-password').on('click', function(e) {
|
$('.forgot-password').on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
showMessage('info', 'Для восстановления пароля обратитесь к администратору');
|
showMessage('info', 'Для восстановления пароля обратитесь к администратору');
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для сообщений внизу страницы */
|
|
||||||
.page-messages {
|
.page-messages {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
@@ -60,7 +59,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Дополнительные стили для формы регистрации */
|
|
||||||
.input-group {
|
.input-group {
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
@@ -89,13 +87,11 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Исправление отступов для страницы регистрации */
|
|
||||||
.profile-page-main {
|
.profile-page-main {
|
||||||
padding: 40px 0;
|
padding: 40px 0;
|
||||||
min-height: calc(100vh - 200px);
|
min-height: calc(100vh - 200px);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Убедимся, что контейнер не перекрывает шапку и футер */
|
|
||||||
.profile-container {
|
.profile-container {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -108,7 +104,6 @@
|
|||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для страницы входа */
|
|
||||||
.form-options {
|
.form-options {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|||||||
@@ -83,4 +83,3 @@
|
|||||||
border-color: @color-primary;
|
border-color: @color-primary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
// check_auth.js
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Проверка авторизации при загрузке страницы
|
|
||||||
checkAuthStatus();
|
checkAuthStatus();
|
||||||
|
|
||||||
// Обработка формы входа
|
|
||||||
$('#loginForm').on('submit', function(e) {
|
$('#loginForm').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@@ -22,14 +21,13 @@ $(document).ready(function() {
|
|||||||
try {
|
try {
|
||||||
const result = JSON.parse(response);
|
const result = JSON.parse(response);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// Сохраняем в localStorage если выбрано "Запомнить меня"
|
|
||||||
if (remember) {
|
if (remember) {
|
||||||
localStorage.setItem('rememberedEmail', email);
|
localStorage.setItem('rememberedEmail', email);
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem('rememberedEmail');
|
localStorage.removeItem('rememberedEmail');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Перенаправляем
|
|
||||||
window.location.href = result.redirect || 'catalog.php';
|
window.location.href = result.redirect || 'catalog.php';
|
||||||
} else {
|
} else {
|
||||||
showMessage('error', result.message || 'Ошибка авторизации');
|
showMessage('error', result.message || 'Ошибка авторизации');
|
||||||
@@ -44,7 +42,6 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Проверка статуса авторизации
|
|
||||||
function checkAuthStatus() {
|
function checkAuthStatus() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'check_auth_status.php',
|
url: 'check_auth_status.php',
|
||||||
@@ -62,9 +59,8 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обновление профиля пользователя
|
|
||||||
function updateUserProfile(user) {
|
function updateUserProfile(user) {
|
||||||
// Обновляем шапку, если есть элементы для профиля
|
|
||||||
if ($('#userEmail').length) {
|
if ($('#userEmail').length) {
|
||||||
$('#userEmail').text(user.email);
|
$('#userEmail').text(user.email);
|
||||||
}
|
}
|
||||||
@@ -73,7 +69,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показать сообщение
|
|
||||||
function showMessage(type, text) {
|
function showMessage(type, text) {
|
||||||
const $message = $('#' + type + 'Message');
|
const $message = $('#' + type + 'Message');
|
||||||
if ($message.length) {
|
if ($message.length) {
|
||||||
@@ -84,7 +79,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка авторизации для ссылок
|
|
||||||
function checkAuth(redirectUrl) {
|
function checkAuth(redirectUrl) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'check_auth_status.php',
|
url: 'check_auth_status.php',
|
||||||
@@ -95,7 +89,7 @@ $(document).ready(function() {
|
|||||||
if (result.loggedIn) {
|
if (result.loggedIn) {
|
||||||
window.location.href = redirectUrl;
|
window.location.href = redirectUrl;
|
||||||
} else {
|
} else {
|
||||||
// Показываем модальное окно или перенаправляем на вход
|
|
||||||
showLoginModal(redirectUrl);
|
showLoginModal(redirectUrl);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@@ -106,9 +100,8 @@ $(document).ready(function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показать модальное окно входа
|
|
||||||
function showLoginModal(redirectUrl) {
|
function showLoginModal(redirectUrl) {
|
||||||
// Можно реализовать модальное окно или перенаправить на страницу входа
|
|
||||||
window.location.href = 'вход.php?redirect=' + encodeURIComponent(redirectUrl);
|
window.location.href = 'вход.php?redirect=' + encodeURIComponent(redirectUrl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// config/database.php
|
|
||||||
class Database {
|
class Database {
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Функции авторизации для AETERNA
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
/**
|
|
||||||
* Авторизация пользователя
|
|
||||||
*/
|
|
||||||
function loginUser(string $email, string $password): array {
|
function loginUser(string $email, string $password): array {
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
@@ -31,7 +25,6 @@ function loginUser(string $email, string $password): array {
|
|||||||
return ['success' => false, 'message' => 'Неверный пароль'];
|
return ['success' => false, 'message' => 'Неверный пароль'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сохраняем в сессию
|
|
||||||
$_SESSION['user_id'] = $user['user_id'];
|
$_SESSION['user_id'] = $user['user_id'];
|
||||||
$_SESSION['user_email'] = $user['email'];
|
$_SESSION['user_email'] = $user['email'];
|
||||||
$_SESSION['full_name'] = $user['full_name'];
|
$_SESSION['full_name'] = $user['full_name'];
|
||||||
@@ -41,7 +34,6 @@ function loginUser(string $email, string $password): array {
|
|||||||
$_SESSION['isAdmin'] = (bool)$user['is_admin'];
|
$_SESSION['isAdmin'] = (bool)$user['is_admin'];
|
||||||
$_SESSION['login_time'] = time();
|
$_SESSION['login_time'] = time();
|
||||||
|
|
||||||
// Обновляем время последнего входа
|
|
||||||
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
||||||
$updateStmt->execute([$user['user_id']]);
|
$updateStmt->execute([$user['user_id']]);
|
||||||
|
|
||||||
@@ -52,9 +44,6 @@ function loginUser(string $email, string $password): array {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Регистрация нового пользователя
|
|
||||||
*/
|
|
||||||
function registerUser(array $data): array {
|
function registerUser(array $data): array {
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
@@ -64,7 +53,6 @@ function registerUser(array $data): array {
|
|||||||
$phone = trim($data['phone'] ?? '');
|
$phone = trim($data['phone'] ?? '');
|
||||||
$city = trim($data['city'] ?? '');
|
$city = trim($data['city'] ?? '');
|
||||||
|
|
||||||
// Валидация
|
|
||||||
if (empty($email) || empty($password) || empty($fullName)) {
|
if (empty($email) || empty($password) || empty($fullName)) {
|
||||||
return ['success' => false, 'message' => 'Заполните все обязательные поля'];
|
return ['success' => false, 'message' => 'Заполните все обязательные поля'];
|
||||||
}
|
}
|
||||||
@@ -78,7 +66,7 @@ function registerUser(array $data): array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Проверяем существование пользователя
|
|
||||||
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
||||||
$checkStmt->execute([$email]);
|
$checkStmt->execute([$email]);
|
||||||
|
|
||||||
@@ -86,7 +74,6 @@ function registerUser(array $data): array {
|
|||||||
return ['success' => false, 'message' => 'Пользователь с таким email уже существует'];
|
return ['success' => false, 'message' => 'Пользователь с таким email уже существует'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаем пользователя
|
|
||||||
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
|
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
@@ -97,7 +84,6 @@ function registerUser(array $data): array {
|
|||||||
$stmt->execute([$email, $passwordHash, $fullName, $phone, $city]);
|
$stmt->execute([$email, $passwordHash, $fullName, $phone, $city]);
|
||||||
$userId = $stmt->fetchColumn();
|
$userId = $stmt->fetchColumn();
|
||||||
|
|
||||||
// Автоматически авторизуем
|
|
||||||
$_SESSION['user_id'] = $userId;
|
$_SESSION['user_id'] = $userId;
|
||||||
$_SESSION['user_email'] = $email;
|
$_SESSION['user_email'] = $email;
|
||||||
$_SESSION['full_name'] = $fullName;
|
$_SESSION['full_name'] = $fullName;
|
||||||
@@ -114,9 +100,6 @@ function registerUser(array $data): array {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Выход пользователя
|
|
||||||
*/
|
|
||||||
function logoutUser(): void {
|
function logoutUser(): void {
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
|
|
||||||
@@ -131,9 +114,6 @@ function logoutUser(): void {
|
|||||||
session_destroy();
|
session_destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Проверка является ли пользователь администратором
|
|
||||||
*/
|
|
||||||
function checkAdminAccess(): bool {
|
function checkAdminAccess(): bool {
|
||||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||||
return false;
|
return false;
|
||||||
@@ -145,4 +125,3 @@ function checkAdminAccess(): bool {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,4 +47,3 @@
|
|||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Общие функции для AETERNA
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Проверка авторизации пользователя
|
|
||||||
*/
|
|
||||||
function isLoggedIn(): bool {
|
function isLoggedIn(): bool {
|
||||||
return isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
return isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Проверка прав администратора
|
|
||||||
*/
|
|
||||||
function isAdmin(): bool {
|
function isAdmin(): bool {
|
||||||
return isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
return isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Требовать авторизацию - редирект на login если не авторизован
|
|
||||||
*/
|
|
||||||
function requireAuth(string $redirectUrl = 'login.php'): void {
|
function requireAuth(string $redirectUrl = 'login.php'): void {
|
||||||
if (!isLoggedIn()) {
|
if (!isLoggedIn()) {
|
||||||
header('Location: ' . $redirectUrl . '?error=auth_required&redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
header('Location: ' . $redirectUrl . '?error=auth_required&redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
||||||
@@ -27,9 +15,6 @@ function requireAuth(string $redirectUrl = 'login.php'): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Требовать права администратора
|
|
||||||
*/
|
|
||||||
function requireAdmin(string $redirectUrl = 'login.php'): void {
|
function requireAdmin(string $redirectUrl = 'login.php'): void {
|
||||||
if (!isAdmin()) {
|
if (!isAdmin()) {
|
||||||
header('Location: ' . $redirectUrl . '?error=admin_required');
|
header('Location: ' . $redirectUrl . '?error=admin_required');
|
||||||
@@ -37,9 +22,6 @@ function requireAdmin(string $redirectUrl = 'login.php'): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Получить текущего пользователя
|
|
||||||
*/
|
|
||||||
function getCurrentUser(): ?array {
|
function getCurrentUser(): ?array {
|
||||||
if (!isLoggedIn()) {
|
if (!isLoggedIn()) {
|
||||||
return null;
|
return null;
|
||||||
@@ -53,38 +35,23 @@ function getCurrentUser(): ?array {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Форматирование цены
|
|
||||||
*/
|
|
||||||
function formatPrice(float $price): string {
|
function formatPrice(float $price): string {
|
||||||
return number_format($price, 0, '', ' ') . ' ₽';
|
return number_format($price, 0, '', ' ') . ' ₽';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Безопасный вывод HTML
|
|
||||||
*/
|
|
||||||
function e(string $str): string {
|
function e(string $str): string {
|
||||||
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
|
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Генерация номера заказа
|
|
||||||
*/
|
|
||||||
function generateOrderNumber(): string {
|
function generateOrderNumber(): string {
|
||||||
return 'AET-' . date('Ymd') . '-' . strtoupper(substr(uniqid(), -6));
|
return 'AET-' . date('Ymd') . '-' . strtoupper(substr(uniqid(), -6));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Генерация SKU для товара
|
|
||||||
*/
|
|
||||||
function generateSKU(string $productName): string {
|
function generateSKU(string $productName): string {
|
||||||
$prefix = strtoupper(substr(preg_replace('/[^a-zA-Z0-9]/', '', transliterate($productName)), 0, 6));
|
$prefix = strtoupper(substr(preg_replace('/[^a-zA-Z0-9]/', '', transliterate($productName)), 0, 6));
|
||||||
return $prefix . '-' . rand(100, 999);
|
return $prefix . '-' . rand(100, 999);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Транслитерация кириллицы в латиницу
|
|
||||||
*/
|
|
||||||
function transliterate(string $str): string {
|
function transliterate(string $str): string {
|
||||||
$converter = [
|
$converter = [
|
||||||
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
|
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
|
||||||
@@ -105,9 +72,6 @@ function transliterate(string $str): string {
|
|||||||
return strtr($str, $converter);
|
return strtr($str, $converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Создание slug из строки
|
|
||||||
*/
|
|
||||||
function createSlug(string $str): string {
|
function createSlug(string $str): string {
|
||||||
$slug = transliterate($str);
|
$slug = transliterate($str);
|
||||||
$slug = strtolower($slug);
|
$slug = strtolower($slug);
|
||||||
@@ -116,9 +80,6 @@ function createSlug(string $str): string {
|
|||||||
return $slug;
|
return $slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Показать flash-сообщение
|
|
||||||
*/
|
|
||||||
function setFlashMessage(string $type, string $message): void {
|
function setFlashMessage(string $type, string $message): void {
|
||||||
$_SESSION['flash_message'] = [
|
$_SESSION['flash_message'] = [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
@@ -126,9 +87,6 @@ function setFlashMessage(string $type, string $message): void {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Получить и удалить flash-сообщение
|
|
||||||
*/
|
|
||||||
function getFlashMessage(): ?array {
|
function getFlashMessage(): ?array {
|
||||||
if (isset($_SESSION['flash_message'])) {
|
if (isset($_SESSION['flash_message'])) {
|
||||||
$message = $_SESSION['flash_message'];
|
$message = $_SESSION['flash_message'];
|
||||||
@@ -137,4 +95,3 @@ function getFlashMessage(): ?array {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Единый header для всех страниц AETERNA
|
|
||||||
* Подключение: require_once 'includes/header.php';
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Запускаем сессию если еще не запущена
|
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Определяем текущую страницу
|
|
||||||
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
|
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
|
||||||
|
|
||||||
// Проверяем авторизацию
|
|
||||||
$isLoggedIn = isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
$isLoggedIn = isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
||||||
$isAdmin = isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
$isAdmin = isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
||||||
$userEmail = $_SESSION['user_email'] ?? '';
|
$userEmail = $_SESSION['user_email'] ?? '';
|
||||||
@@ -29,7 +22,7 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
|||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||||
<style>
|
<style>
|
||||||
/* Стили для профиля пользователя */
|
|
||||||
.user-profile-dropdown { position: relative; display: inline-block; }
|
.user-profile-dropdown { position: relative; display: inline-block; }
|
||||||
.user-profile-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 12px; border-radius: 4px; transition: all 0.3s ease; }
|
.user-profile-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 12px; border-radius: 4px; transition: all 0.3s ease; }
|
||||||
.user-profile-toggle:hover { background-color: rgba(0, 0, 0, 0.05); }
|
.user-profile-toggle:hover { background-color: rgba(0, 0, 0, 0.05); }
|
||||||
@@ -86,13 +79,12 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
|||||||
|
|
||||||
<div class="header__icons--top">
|
<div class="header__icons--top">
|
||||||
<?php if ($isLoggedIn): ?>
|
<?php if ($isLoggedIn): ?>
|
||||||
<!-- Иконка корзины -->
|
|
||||||
<a href="checkout.php" class="icon cart-icon">
|
<a href="checkout.php" class="icon cart-icon">
|
||||||
<i class="fas fa-shopping-cart"></i>
|
<i class="fas fa-shopping-cart"></i>
|
||||||
<span class="cart-count" id="cartCount">0</span>
|
<span class="cart-count" id="cartCount">0</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<!-- Блок профиля -->
|
|
||||||
<div class="user-profile-dropdown">
|
<div class="user-profile-dropdown">
|
||||||
<div class="user-profile-toggle" id="profileToggle">
|
<div class="user-profile-toggle" id="profileToggle">
|
||||||
<div class="user-avatar"><?= !empty($userEmail) ? strtoupper(substr($userEmail, 0, 1)) : 'U' ?></div>
|
<div class="user-avatar"><?= !empty($userEmail) ? strtoupper(substr($userEmail, 0, 1)) : 'U' ?></div>
|
||||||
@@ -149,7 +141,7 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Профиль пользователя - открытие/закрытие
|
|
||||||
$('#profileToggle').click(function(e) {
|
$('#profileToggle').click(function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
$('#profileMenu').toggle();
|
$('#profileMenu').toggle();
|
||||||
@@ -161,7 +153,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обновление счетчика корзины
|
|
||||||
<?php if ($isLoggedIn): ?>
|
<?php if ($isLoggedIn): ?>
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'api/cart.php?action=count',
|
url: 'api/cart.php?action=count',
|
||||||
@@ -178,4 +169,3 @@ $(document).ready(function() {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Быстрый скрипт для назначения прав администратора пользователю admin@mail.ru
|
|
||||||
* Запуск: php migrations/grant_admin.php
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
@@ -16,7 +12,6 @@ try {
|
|||||||
|
|
||||||
$email = 'admin@mail.ru';
|
$email = 'admin@mail.ru';
|
||||||
|
|
||||||
// Проверяем, существует ли пользователь
|
|
||||||
$checkStmt = $db->prepare("SELECT user_id, email, full_name, is_admin, is_active FROM users WHERE email = ?");
|
$checkStmt = $db->prepare("SELECT user_id, email, full_name, is_admin, is_active FROM users WHERE email = ?");
|
||||||
$checkStmt->execute([$email]);
|
$checkStmt->execute([$email]);
|
||||||
$user = $checkStmt->fetch(PDO::FETCH_ASSOC);
|
$user = $checkStmt->fetch(PDO::FETCH_ASSOC);
|
||||||
@@ -31,7 +26,7 @@ try {
|
|||||||
if ($user['is_admin']) {
|
if ($user['is_admin']) {
|
||||||
echo "[INFO] Пользователь уже имеет права администратора\n";
|
echo "[INFO] Пользователь уже имеет права администратора\n";
|
||||||
} else {
|
} else {
|
||||||
// Обновляем права
|
|
||||||
$updateStmt = $db->prepare("
|
$updateStmt = $db->prepare("
|
||||||
UPDATE users
|
UPDATE users
|
||||||
SET is_admin = TRUE,
|
SET is_admin = TRUE,
|
||||||
@@ -47,8 +42,6 @@ try {
|
|||||||
echo "[WARN] Пользователь с email $email не найден\n";
|
echo "[WARN] Пользователь с email $email не найден\n";
|
||||||
echo "[INFO] Создаю нового пользователя с правами администратора...\n";
|
echo "[INFO] Создаю нового пользователя с правами администратора...\n";
|
||||||
|
|
||||||
// Создаем пользователя с правами админа
|
|
||||||
// Пароль по умолчанию: admin123
|
|
||||||
$password_hash = password_hash('admin123', PASSWORD_DEFAULT);
|
$password_hash = password_hash('admin123', PASSWORD_DEFAULT);
|
||||||
|
|
||||||
$insertStmt = $db->prepare("
|
$insertStmt = $db->prepare("
|
||||||
@@ -73,7 +66,6 @@ try {
|
|||||||
echo "[WARN] Рекомендуется сменить пароль после первого входа!\n";
|
echo "[WARN] Рекомендуется сменить пароль после первого входа!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем результат
|
|
||||||
$verifyStmt = $db->prepare("SELECT user_id, email, full_name, is_admin, is_active FROM users WHERE email = ?");
|
$verifyStmt = $db->prepare("SELECT user_id, email, full_name, is_admin, is_active FROM users WHERE email = ?");
|
||||||
$verifyStmt->execute([$email]);
|
$verifyStmt->execute([$email]);
|
||||||
$finalUser = $verifyStmt->fetch(PDO::FETCH_ASSOC);
|
$finalUser = $verifyStmt->fetch(PDO::FETCH_ASSOC);
|
||||||
@@ -91,4 +83,3 @@ try {
|
|||||||
echo "[ERROR] Ошибка: " . $e->getMessage() . "\n";
|
echo "[ERROR] Ошибка: " . $e->getMessage() . "\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Простой раннер миграций для PostgreSQL
|
|
||||||
* Запуск: php migrations/migrate.php
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Подключаем конфиг базы данных
|
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
echo "===========================================\n";
|
echo "===========================================\n";
|
||||||
@@ -15,7 +10,6 @@ try {
|
|||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
echo "[OK] Подключение к базе данных успешно\n\n";
|
echo "[OK] Подключение к базе данных успешно\n\n";
|
||||||
|
|
||||||
// 1. Создаем таблицу для отслеживания миграций
|
|
||||||
$db->exec("
|
$db->exec("
|
||||||
CREATE TABLE IF NOT EXISTS migrations (
|
CREATE TABLE IF NOT EXISTS migrations (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
@@ -25,12 +19,10 @@ try {
|
|||||||
");
|
");
|
||||||
echo "[OK] Таблица migrations готова\n";
|
echo "[OK] Таблица migrations готова\n";
|
||||||
|
|
||||||
// 2. Получаем список уже примененных миграций
|
|
||||||
$stmt = $db->query("SELECT filename FROM migrations ORDER BY filename");
|
$stmt = $db->query("SELECT filename FROM migrations ORDER BY filename");
|
||||||
$applied = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
$applied = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
echo "[INFO] Уже применено миграций: " . count($applied) . "\n\n";
|
echo "[INFO] Уже применено миграций: " . count($applied) . "\n\n";
|
||||||
|
|
||||||
// 3. Сканируем папку на SQL-файлы
|
|
||||||
$migrationFiles = glob(__DIR__ . '/*.sql');
|
$migrationFiles = glob(__DIR__ . '/*.sql');
|
||||||
sort($migrationFiles);
|
sort($migrationFiles);
|
||||||
|
|
||||||
@@ -39,18 +31,15 @@ try {
|
|||||||
foreach ($migrationFiles as $file) {
|
foreach ($migrationFiles as $file) {
|
||||||
$filename = basename($file);
|
$filename = basename($file);
|
||||||
|
|
||||||
// Пропускаем seed_data.sql - он запускается отдельно
|
|
||||||
if ($filename === 'seed_data.sql') {
|
if ($filename === 'seed_data.sql') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, была ли миграция уже применена
|
|
||||||
if (in_array($filename, $applied)) {
|
if (in_array($filename, $applied)) {
|
||||||
echo "[SKIP] $filename (уже применена)\n";
|
echo "[SKIP] $filename (уже применена)\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Применяем миграцию
|
|
||||||
echo "[RUN] Применяю $filename... ";
|
echo "[RUN] Применяю $filename... ";
|
||||||
|
|
||||||
$sql = file_get_contents($file);
|
$sql = file_get_contents($file);
|
||||||
@@ -58,7 +47,6 @@ try {
|
|||||||
try {
|
try {
|
||||||
$db->exec($sql);
|
$db->exec($sql);
|
||||||
|
|
||||||
// Записываем в таблицу миграций
|
|
||||||
$stmt = $db->prepare("INSERT INTO migrations (filename) VALUES (?)");
|
$stmt = $db->prepare("INSERT INTO migrations (filename) VALUES (?)");
|
||||||
$stmt->execute([$filename]);
|
$stmt->execute([$filename]);
|
||||||
|
|
||||||
@@ -80,7 +68,6 @@ try {
|
|||||||
echo "[INFO] Все миграции уже применены\n";
|
echo "[INFO] Все миграции уже применены\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Спрашиваем про seed_data
|
|
||||||
$seedFile = __DIR__ . '/seed_data.sql';
|
$seedFile = __DIR__ . '/seed_data.sql';
|
||||||
if (file_exists($seedFile)) {
|
if (file_exists($seedFile)) {
|
||||||
echo "\n[?] Хотите загрузить начальные данные (seed_data.sql)?\n";
|
echo "\n[?] Хотите загрузить начальные данные (seed_data.sql)?\n";
|
||||||
@@ -106,4 +93,3 @@ try {
|
|||||||
echo "[ERROR] Ошибка подключения к БД: " . $e->getMessage() . "\n";
|
echo "[ERROR] Ошибка подключения к БД: " . $e->getMessage() . "\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
// index.php - ПОЛНОСТЬЮ ИСПРАВЛЕННАЯ ВЕРСИЯ
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
// Включаем отладку ошибок
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
|
|
||||||
// Проверка прав администратора
|
|
||||||
if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
||||||
echo "<script>alert('Требуется авторизация администратора'); window.location.href = '../login.php';</script>";
|
echo "<script>alert('Требуется авторизация администратора'); window.location.href = '../login.php';</script>";
|
||||||
exit();
|
exit();
|
||||||
@@ -15,12 +13,10 @@ if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
|||||||
|
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
// Обработка действий
|
|
||||||
$action = $_GET['action'] ?? 'dashboard';
|
$action = $_GET['action'] ?? 'dashboard';
|
||||||
$message = $_GET['message'] ?? '';
|
$message = $_GET['message'] ?? '';
|
||||||
$error = $_GET['error'] ?? '';
|
$error = $_GET['error'] ?? '';
|
||||||
|
|
||||||
// Обработка POST запросов - ДОБАВЛЕНО ПРОСТОЕ И РАБОТАЮЩЕЕ!
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$post_action = $_POST['action'] ?? '';
|
$post_action = $_POST['action'] ?? '';
|
||||||
|
|
||||||
@@ -50,7 +46,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ИСПРАВЬТЕ БЛОК edit_category или добавьте его если его нет:
|
|
||||||
if ($post_action === 'edit_category' && isset($_POST['category_id'])) {
|
if ($post_action === 'edit_category' && isset($_POST['category_id'])) {
|
||||||
$category_id = (int)$_POST['category_id'];
|
$category_id = (int)$_POST['category_id'];
|
||||||
$name = trim($_POST['name'] ?? '');
|
$name = trim($_POST['name'] ?? '');
|
||||||
@@ -99,15 +94,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$material = trim($_POST['material'] ?? '');
|
$material = trim($_POST['material'] ?? '');
|
||||||
$card_size = trim($_POST['card_size'] ?? 'small');
|
$card_size = trim($_POST['card_size'] ?? 'small');
|
||||||
|
|
||||||
|
|
||||||
// ВАЖНО: Проверяем category_id
|
|
||||||
if ($category_id <= 0) {
|
if ($category_id <= 0) {
|
||||||
$_SESSION['error'] = 'Выберите корректную категорию';
|
$_SESSION['error'] = 'Выберите корректную категорию';
|
||||||
header('Location: index.php?action=add_product');
|
header('Location: index.php?action=add_product');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем существование категории
|
|
||||||
$check_category = $db->prepare("SELECT COUNT(*) FROM categories WHERE category_id = ?");
|
$check_category = $db->prepare("SELECT COUNT(*) FROM categories WHERE category_id = ?");
|
||||||
$check_category->execute([$category_id]);
|
$check_category->execute([$category_id]);
|
||||||
if ($check_category->fetchColumn() == 0) {
|
if ($check_category->fetchColumn() == 0) {
|
||||||
@@ -119,7 +111,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
if (empty($name)) throw new Exception('Название товара обязательно');
|
if (empty($name)) throw new Exception('Название товара обязательно');
|
||||||
if ($price <= 0) throw new Exception('Цена должна быть больше 0');
|
if ($price <= 0) throw new Exception('Цена должна быть больше 0');
|
||||||
|
|
||||||
// Генерируем SKU если пустой
|
|
||||||
if (empty($sku)) {
|
if (empty($sku)) {
|
||||||
$sku = 'PROD-' . strtoupper(substr(preg_replace('/[^a-z0-9]/i', '', $name), 0, 6)) . '-' . rand(100, 999);
|
$sku = 'PROD-' . strtoupper(substr(preg_replace('/[^a-z0-9]/i', '', $name), 0, 6)) . '-' . rand(100, 999);
|
||||||
}
|
}
|
||||||
@@ -145,11 +136,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ИСПРАВЛЕННЫЙ КОД для edit_product в index.php:
|
|
||||||
if ($post_action === 'edit_product' && isset($_POST['product_id'])) {
|
if ($post_action === 'edit_product' && isset($_POST['product_id'])) {
|
||||||
$product_id = (int)$_POST['product_id'];
|
$product_id = (int)$_POST['product_id'];
|
||||||
$name = trim($_POST['name'] ?? '');
|
$name = trim($_POST['name'] ?? '');
|
||||||
$category_id = (int)($_POST['category_id'] ?? 1); // ПО УМОЛЧАНИЮ 1, чтобы избежать 0
|
$category_id = (int)($_POST['category_id'] ?? 1);
|
||||||
$description = trim($_POST['description'] ?? '');
|
$description = trim($_POST['description'] ?? '');
|
||||||
$price = (float)($_POST['price'] ?? 0);
|
$price = (float)($_POST['price'] ?? 0);
|
||||||
$old_price = !empty($_POST['old_price']) ? (float)$_POST['old_price'] : NULL;
|
$old_price = !empty($_POST['old_price']) ? (float)$_POST['old_price'] : NULL;
|
||||||
@@ -159,9 +149,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$color = trim($_POST['color'] ?? '');
|
$color = trim($_POST['color'] ?? '');
|
||||||
$material = trim($_POST['material'] ?? '');
|
$material = trim($_POST['material'] ?? '');
|
||||||
|
|
||||||
// ВАЖНО: Проверяем category_id
|
|
||||||
if ($category_id <= 0) {
|
if ($category_id <= 0) {
|
||||||
// Если category_id = 0, устанавливаем первую доступную категорию
|
|
||||||
$firstCat = $db->query("SELECT category_id FROM categories LIMIT 1")->fetchColumn();
|
$firstCat = $db->query("SELECT category_id FROM categories LIMIT 1")->fetchColumn();
|
||||||
$category_id = $firstCat ?: 1;
|
$category_id = $firstCat ?: 1;
|
||||||
}
|
}
|
||||||
@@ -194,32 +183,30 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
if ($post_action === 'delete_category' && isset($_POST['category_id'])) {
|
if ($post_action === 'delete_category' && isset($_POST['category_id'])) {
|
||||||
$categoryId = intval($_POST['category_id']);
|
$categoryId = intval($_POST['category_id']);
|
||||||
|
|
||||||
// 1. Проверяем, есть ли товары в этой категории
|
|
||||||
$checkProducts = $db->prepare("SELECT COUNT(*) FROM products WHERE category_id = ?");
|
$checkProducts = $db->prepare("SELECT COUNT(*) FROM products WHERE category_id = ?");
|
||||||
$checkProducts->execute([$categoryId]);
|
$checkProducts->execute([$categoryId]);
|
||||||
$productCount = $checkProducts->fetchColumn();
|
$productCount = $checkProducts->fetchColumn();
|
||||||
|
|
||||||
// 2. Проверяем, есть ли дочерние категории
|
|
||||||
$checkChildren = $db->prepare("SELECT COUNT(*) FROM categories WHERE parent_id = ?");
|
$checkChildren = $db->prepare("SELECT COUNT(*) FROM categories WHERE parent_id = ?");
|
||||||
$checkChildren->execute([$categoryId]);
|
$checkChildren->execute([$categoryId]);
|
||||||
$childCount = $checkChildren->fetchColumn();
|
$childCount = $checkChildren->fetchColumn();
|
||||||
|
|
||||||
if ($productCount > 0) {
|
if ($productCount > 0) {
|
||||||
// Если есть товары, делаем категорию неактивной вместо удаления
|
|
||||||
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
|
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
|
||||||
$stmt->execute([$categoryId]);
|
$stmt->execute([$categoryId]);
|
||||||
|
|
||||||
header('Location: index.php?action=categories&message=Категория+скрыта+(содержит+товары)');
|
header('Location: index.php?action=categories&message=Категория+скрыта+(содержит+товары)');
|
||||||
exit();
|
exit();
|
||||||
} elseif ($childCount > 0) {
|
} elseif ($childCount > 0) {
|
||||||
// Если есть дочерние категории, делаем неактивной
|
|
||||||
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
|
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
|
||||||
$stmt->execute([$categoryId]);
|
$stmt->execute([$categoryId]);
|
||||||
|
|
||||||
header('Location: index.php?action=categories&message=Категория+скрыта+(имеет+дочерние+категории)');
|
header('Location: index.php?action=categories&message=Категория+скрыта+(имеет+дочерние+категории)');
|
||||||
exit();
|
exit();
|
||||||
} else {
|
} else {
|
||||||
// Если нет товаров и дочерних категорий, удаляем
|
|
||||||
$stmt = $db->prepare("DELETE FROM categories WHERE category_id = ?");
|
$stmt = $db->prepare("DELETE FROM categories WHERE category_id = ?");
|
||||||
$stmt->execute([$categoryId]);
|
$stmt->execute([$categoryId]);
|
||||||
|
|
||||||
@@ -236,10 +223,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Получение данных для отображения
|
|
||||||
try {
|
try {
|
||||||
// Статистика
|
|
||||||
$stats = [
|
$stats = [
|
||||||
'total_products' => $db->query("SELECT COUNT(*) FROM products")->fetchColumn(),
|
'total_products' => $db->query("SELECT COUNT(*) FROM products")->fetchColumn(),
|
||||||
'active_products' => $db->query("SELECT COUNT(*) FROM products WHERE is_available = TRUE")->fetchColumn(),
|
'active_products' => $db->query("SELECT COUNT(*) FROM products WHERE is_available = TRUE")->fetchColumn(),
|
||||||
@@ -248,10 +233,8 @@ try {
|
|||||||
'revenue' => $db->query("SELECT COALESCE(SUM(final_amount), 0) FROM orders WHERE status = 'completed'")->fetchColumn()
|
'revenue' => $db->query("SELECT COALESCE(SUM(final_amount), 0) FROM orders WHERE status = 'completed'")->fetchColumn()
|
||||||
];
|
];
|
||||||
|
|
||||||
// Получаем все категории
|
|
||||||
$allCategories = $db->query("SELECT * FROM categories WHERE is_active = TRUE ORDER BY name")->fetchAll();
|
$allCategories = $db->query("SELECT * FROM categories WHERE is_active = TRUE ORDER BY name")->fetchAll();
|
||||||
|
|
||||||
// Получаем родительские категории
|
|
||||||
$parentCategories = $db->query("SELECT * FROM categories WHERE parent_id IS NULL AND is_active = TRUE ORDER BY name")->fetchAll();
|
$parentCategories = $db->query("SELECT * FROM categories WHERE parent_id IS NULL AND is_active = TRUE ORDER BY name")->fetchAll();
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
@@ -387,7 +370,7 @@ try {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ($action == 'dashboard'): ?>
|
<?php if ($action == 'dashboard'): ?>
|
||||||
<!-- Дашборд -->
|
|
||||||
<h2>Статистика</h2>
|
<h2>Статистика</h2>
|
||||||
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 20px 0;">
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 20px 0;">
|
||||||
<div style="background: white; padding: 20px; border-radius: 5px; text-align: center;">
|
<div style="background: white; padding: 20px; border-radius: 5px; text-align: center;">
|
||||||
@@ -418,7 +401,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php elseif ($action == 'products'): ?>
|
<?php elseif ($action == 'products'): ?>
|
||||||
<!-- Товары -->
|
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
||||||
<h2>Управление товарами</h2>
|
<h2>Управление товарами</h2>
|
||||||
<div>
|
<div>
|
||||||
@@ -492,7 +475,7 @@ try {
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php elseif ($action == 'categories'): ?>
|
<?php elseif ($action == 'categories'): ?>
|
||||||
<!-- Категории -->
|
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
||||||
<h2>Управление категориями</h2>
|
<h2>Управление категориями</h2>
|
||||||
<a href="?action=add_category" class="btn btn-success">
|
<a href="?action=add_category" class="btn btn-success">
|
||||||
@@ -520,12 +503,11 @@ try {
|
|||||||
<td><?= htmlspecialchars($category['parent_name'] ?? '—') ?></td>
|
<td><?= htmlspecialchars($category['parent_name'] ?? '—') ?></td>
|
||||||
<td><?= $category['product_count'] ?></td>
|
<td><?= $category['product_count'] ?></td>
|
||||||
<td class="action-buttons">
|
<td class="action-buttons">
|
||||||
<!-- Кнопка редактирования -->
|
|
||||||
<a href="?action=edit_category&id=<?= $category['category_id'] ?>" class="btn btn-warning btn-sm">
|
<a href="?action=edit_category&id=<?= $category['category_id'] ?>" class="btn btn-warning btn-sm">
|
||||||
<i class="fas fa-edit"></i> Редактировать
|
<i class="fas fa-edit"></i> Редактировать
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<!-- Кнопка удаления с AJAX -->
|
|
||||||
<button type="button" class="btn btn-danger btn-sm delete-category-btn"
|
<button type="button" class="btn btn-danger btn-sm delete-category-btn"
|
||||||
data-id="<?= $category['category_id'] ?>"
|
data-id="<?= $category['category_id'] ?>"
|
||||||
<?= $category['product_count'] > 0 ? 'disabled' : '' ?>>
|
<?= $category['product_count'] > 0 ? 'disabled' : '' ?>>
|
||||||
@@ -538,7 +520,7 @@ try {
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php elseif (in_array($action, ['add_product', 'edit_product'])): ?>
|
<?php elseif (in_array($action, ['add_product', 'edit_product'])): ?>
|
||||||
<!-- Форма добавления/редактирования товара -->
|
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<h2><?= $action == 'add_product' ? 'Добавление товара' : 'Редактирование товара' ?></h2>
|
<h2><?= $action == 'add_product' ? 'Добавление товара' : 'Редактирование товара' ?></h2>
|
||||||
|
|
||||||
@@ -644,7 +626,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php elseif (in_array($action, ['add_category', 'edit_category'])): ?>
|
<?php elseif (in_array($action, ['add_category', 'edit_category'])): ?>
|
||||||
<!-- Форма добавления/редактирования категории -->
|
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<h2><?= $action == 'add_category' ? 'Добавление категории' : 'Редактирование категории' ?></h2>
|
<h2><?= $action == 'add_category' ? 'Добавление категории' : 'Редактирование категории' ?></h2>
|
||||||
|
|
||||||
@@ -703,7 +685,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php elseif ($action == 'orders'): ?>
|
<?php elseif ($action == 'orders'): ?>
|
||||||
<!-- Заказы -->
|
|
||||||
<h2>Заказы</h2>
|
<h2>Заказы</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -735,7 +717,7 @@ try {
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php elseif ($action == 'users'): ?>
|
<?php elseif ($action == 'users'): ?>
|
||||||
<!-- Пользователи -->
|
|
||||||
<h2>Пользователи</h2>
|
<h2>Пользователи</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -769,7 +751,7 @@ try {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
// Удаление категории через AJAX
|
|
||||||
$('.delete-category-btn').click(function() {
|
$('.delete-category-btn').click(function() {
|
||||||
const categoryId = $(this).data('id');
|
const categoryId = $(this).data('id');
|
||||||
const btn = $(this);
|
const btn = $(this);
|
||||||
@@ -792,7 +774,6 @@ $('.delete-category-btn').click(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка формы категории
|
|
||||||
$('#categoryForm').submit(function(e) {
|
$('#categoryForm').submit(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Проверяем наличие товара на складе
|
|
||||||
$checkStock = $db->prepare("
|
$checkStock = $db->prepare("
|
||||||
SELECT stock_quantity, name, price
|
SELECT stock_quantity, name, price
|
||||||
FROM products
|
FROM products
|
||||||
@@ -39,7 +39,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, есть ли товар уже в корзине пользователя
|
|
||||||
$checkCart = $db->prepare("
|
$checkCart = $db->prepare("
|
||||||
SELECT cart_id, quantity
|
SELECT cart_id, quantity
|
||||||
FROM cart
|
FROM cart
|
||||||
@@ -49,10 +48,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
$cartItem = $checkCart->fetch();
|
$cartItem = $checkCart->fetch();
|
||||||
|
|
||||||
if ($cartItem) {
|
if ($cartItem) {
|
||||||
// Обновляем количество
|
|
||||||
$newQuantity = $cartItem['quantity'] + $quantity;
|
$newQuantity = $cartItem['quantity'] + $quantity;
|
||||||
|
|
||||||
// Проверяем общее количество
|
|
||||||
if ($newQuantity > $product['stock_quantity']) {
|
if ($newQuantity > $product['stock_quantity']) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Превышено доступное количество']);
|
echo json_encode(['success' => false, 'message' => 'Превышено доступное количество']);
|
||||||
exit();
|
exit();
|
||||||
@@ -65,7 +63,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
");
|
");
|
||||||
$updateStmt->execute([$newQuantity, $cartItem['cart_id']]);
|
$updateStmt->execute([$newQuantity, $cartItem['cart_id']]);
|
||||||
} else {
|
} else {
|
||||||
// Добавляем новый товар
|
|
||||||
$insertStmt = $db->prepare("
|
$insertStmt = $db->prepare("
|
||||||
INSERT INTO cart (user_id, product_id, quantity)
|
INSERT INTO cart (user_id, product_id, quantity)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
@@ -73,7 +71,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
$insertStmt->execute([$user_id, $product_id, $quantity]);
|
$insertStmt->execute([$user_id, $product_id, $quantity]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обновляем сессию
|
|
||||||
if (!isset($_SESSION['cart'])) {
|
if (!isset($_SESSION['cart'])) {
|
||||||
$_SESSION['cart'] = [];
|
$_SESSION['cart'] = [];
|
||||||
}
|
}
|
||||||
@@ -89,7 +86,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получаем общее количество товаров в корзине
|
|
||||||
$cartCountStmt = $db->prepare("
|
$cartCountStmt = $db->prepare("
|
||||||
SELECT SUM(quantity) as total
|
SELECT SUM(quantity) as total
|
||||||
FROM cart
|
FROM cart
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// login_handler.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Проверяем пользователя в базе данных
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
SELECT user_id, email, password_hash, full_name, phone, city, is_admin, is_active
|
SELECT user_id, email, password_hash, full_name, phone, city, is_admin, is_active
|
||||||
FROM users
|
FROM users
|
||||||
@@ -34,7 +34,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем пароль
|
|
||||||
if (empty($user['password_hash'])) {
|
if (empty($user['password_hash'])) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Ошибка: пароль не найден в базе данных']);
|
echo json_encode(['success' => false, 'message' => 'Ошибка: пароль не найден в базе данных']);
|
||||||
exit();
|
exit();
|
||||||
@@ -45,7 +44,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сохраняем в сессию
|
|
||||||
$_SESSION['user_id'] = $user['user_id'];
|
$_SESSION['user_id'] = $user['user_id'];
|
||||||
$_SESSION['user_email'] = $user['email'];
|
$_SESSION['user_email'] = $user['email'];
|
||||||
$_SESSION['full_name'] = $user['full_name'];
|
$_SESSION['full_name'] = $user['full_name'];
|
||||||
@@ -55,7 +53,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$_SESSION['isAdmin'] = (bool)$user['is_admin'];
|
$_SESSION['isAdmin'] = (bool)$user['is_admin'];
|
||||||
$_SESSION['login_time'] = time();
|
$_SESSION['login_time'] = time();
|
||||||
|
|
||||||
// Обновляем время последнего входа
|
|
||||||
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
||||||
$updateStmt->execute([$user['user_id']]);
|
$updateStmt->execute([$user['user_id']]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* API для работы с корзиной
|
|
||||||
* Эндпоинты: add, update, remove, get, count
|
|
||||||
*/
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
// Проверка авторизации
|
|
||||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Требуется авторизация']);
|
echo json_encode(['success' => false, 'message' => 'Требуется авторизация']);
|
||||||
exit();
|
exit();
|
||||||
@@ -30,7 +26,6 @@ try {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем существование товара
|
|
||||||
$checkProduct = $db->prepare("SELECT product_id, stock_quantity FROM products WHERE product_id = ? AND is_available = TRUE");
|
$checkProduct = $db->prepare("SELECT product_id, stock_quantity FROM products WHERE product_id = ? AND is_available = TRUE");
|
||||||
$checkProduct->execute([$productId]);
|
$checkProduct->execute([$productId]);
|
||||||
$product = $checkProduct->fetch();
|
$product = $checkProduct->fetch();
|
||||||
@@ -40,18 +35,17 @@ try {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, есть ли товар уже в корзине
|
|
||||||
$checkCart = $db->prepare("SELECT cart_id, quantity FROM cart WHERE user_id = ? AND product_id = ?");
|
$checkCart = $db->prepare("SELECT cart_id, quantity FROM cart WHERE user_id = ? AND product_id = ?");
|
||||||
$checkCart->execute([$userId, $productId]);
|
$checkCart->execute([$userId, $productId]);
|
||||||
$cartItem = $checkCart->fetch();
|
$cartItem = $checkCart->fetch();
|
||||||
|
|
||||||
if ($cartItem) {
|
if ($cartItem) {
|
||||||
// Обновляем количество
|
|
||||||
$newQuantity = $cartItem['quantity'] + $quantity;
|
$newQuantity = $cartItem['quantity'] + $quantity;
|
||||||
$stmt = $db->prepare("UPDATE cart SET quantity = ?, updated_at = CURRENT_TIMESTAMP WHERE cart_id = ?");
|
$stmt = $db->prepare("UPDATE cart SET quantity = ?, updated_at = CURRENT_TIMESTAMP WHERE cart_id = ?");
|
||||||
$stmt->execute([$newQuantity, $cartItem['cart_id']]);
|
$stmt->execute([$newQuantity, $cartItem['cart_id']]);
|
||||||
} else {
|
} else {
|
||||||
// Добавляем новый товар
|
|
||||||
$stmt = $db->prepare("INSERT INTO cart (user_id, product_id, quantity) VALUES (?, ?, ?)");
|
$stmt = $db->prepare("INSERT INTO cart (user_id, product_id, quantity) VALUES (?, ?, ?)");
|
||||||
$stmt->execute([$userId, $productId, $quantity]);
|
$stmt->execute([$userId, $productId, $quantity]);
|
||||||
}
|
}
|
||||||
@@ -64,7 +58,7 @@ try {
|
|||||||
$quantity = (int)($_POST['quantity'] ?? 1);
|
$quantity = (int)($_POST['quantity'] ?? 1);
|
||||||
|
|
||||||
if ($quantity <= 0) {
|
if ($quantity <= 0) {
|
||||||
// Удаляем товар если количество 0
|
|
||||||
$stmt = $db->prepare("DELETE FROM cart WHERE user_id = ? AND product_id = ?");
|
$stmt = $db->prepare("DELETE FROM cart WHERE user_id = ? AND product_id = ?");
|
||||||
$stmt->execute([$userId, $productId]);
|
$stmt->execute([$userId, $productId]);
|
||||||
} else {
|
} else {
|
||||||
@@ -131,4 +125,3 @@ try {
|
|||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Ошибка базы данных: ' . $e->getMessage()]);
|
echo json_encode(['success' => false, 'message' => 'Ошибка базы данных: ' . $e->getMessage()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// get_cart.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ if ($user_id == 0) {
|
|||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Получаем корзину из БД
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
c.cart_id,
|
c.cart_id,
|
||||||
@@ -36,7 +36,6 @@ try {
|
|||||||
$stmt->execute([$user_id]);
|
$stmt->execute([$user_id]);
|
||||||
$cart_items = $stmt->fetchAll();
|
$cart_items = $stmt->fetchAll();
|
||||||
|
|
||||||
// Обновляем сессию
|
|
||||||
$_SESSION['cart'] = [];
|
$_SESSION['cart'] = [];
|
||||||
foreach ($cart_items as $item) {
|
foreach ($cart_items as $item) {
|
||||||
$_SESSION['cart'][$item['product_id']] = [
|
$_SESSION['cart'][$item['product_id']] = [
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// get_cart_count.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
// Проверяем авторизацию администратора
|
|
||||||
if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Доступ запрещен']);
|
echo json_encode(['success' => false, 'message' => 'Доступ запрещен']);
|
||||||
exit();
|
exit();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// process_order.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
@@ -21,7 +21,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
try {
|
try {
|
||||||
$db->beginTransaction();
|
$db->beginTransaction();
|
||||||
|
|
||||||
// Получаем данные из формы
|
|
||||||
$customer_name = $_POST['full_name'] ?? '';
|
$customer_name = $_POST['full_name'] ?? '';
|
||||||
$customer_email = $_POST['email'] ?? '';
|
$customer_email = $_POST['email'] ?? '';
|
||||||
$customer_phone = $_POST['phone'] ?? '';
|
$customer_phone = $_POST['phone'] ?? '';
|
||||||
@@ -33,10 +32,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$discount_amount = floatval($_POST['discount'] ?? 0);
|
$discount_amount = floatval($_POST['discount'] ?? 0);
|
||||||
$delivery_cost = floatval($_POST['delivery_price'] ?? 2000);
|
$delivery_cost = floatval($_POST['delivery_price'] ?? 2000);
|
||||||
|
|
||||||
// Генерируем номер заказа
|
|
||||||
$order_number = 'ORD-' . date('Ymd-His') . '-' . rand(1000, 9999);
|
$order_number = 'ORD-' . date('Ymd-His') . '-' . rand(1000, 9999);
|
||||||
|
|
||||||
// Получаем корзину пользователя
|
|
||||||
$cartStmt = $db->prepare("
|
$cartStmt = $db->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
c.product_id,
|
c.product_id,
|
||||||
@@ -55,7 +52,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
throw new Exception('Корзина пуста');
|
throw new Exception('Корзина пуста');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Рассчитываем итоги
|
|
||||||
$total_amount = 0;
|
$total_amount = 0;
|
||||||
foreach ($cart_items as $item) {
|
foreach ($cart_items as $item) {
|
||||||
$total_amount += $item['price'] * $item['quantity'];
|
$total_amount += $item['price'] * $item['quantity'];
|
||||||
@@ -63,7 +59,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
$final_amount = $total_amount - $discount_amount + $delivery_cost;
|
$final_amount = $total_amount - $discount_amount + $delivery_cost;
|
||||||
|
|
||||||
// Создаем заказ
|
|
||||||
$orderStmt = $db->prepare("
|
$orderStmt = $db->prepare("
|
||||||
INSERT INTO orders (
|
INSERT INTO orders (
|
||||||
user_id, order_number, total_amount, discount_amount,
|
user_id, order_number, total_amount, discount_amount,
|
||||||
@@ -83,9 +78,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
$order_id = $orderStmt->fetchColumn();
|
$order_id = $orderStmt->fetchColumn();
|
||||||
|
|
||||||
// Добавляем товары в заказ и обновляем остатки
|
|
||||||
foreach ($cart_items as $item) {
|
foreach ($cart_items as $item) {
|
||||||
// Добавляем в order_items
|
|
||||||
$itemStmt = $db->prepare("
|
$itemStmt = $db->prepare("
|
||||||
INSERT INTO order_items (
|
INSERT INTO order_items (
|
||||||
order_id, product_id, product_name,
|
order_id, product_id, product_name,
|
||||||
@@ -99,7 +93,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$item['quantity'], $item['price'], $item_total
|
$item['quantity'], $item['price'], $item_total
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Обновляем остатки на складе
|
|
||||||
$updateStmt = $db->prepare("
|
$updateStmt = $db->prepare("
|
||||||
UPDATE products
|
UPDATE products
|
||||||
SET stock_quantity = stock_quantity - ?,
|
SET stock_quantity = stock_quantity - ?,
|
||||||
@@ -109,16 +102,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$updateStmt->execute([$item['quantity'], $item['product_id']]);
|
$updateStmt->execute([$item['quantity'], $item['product_id']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Очищаем корзину
|
|
||||||
$clearCartStmt = $db->prepare("DELETE FROM cart WHERE user_id = ?");
|
$clearCartStmt = $db->prepare("DELETE FROM cart WHERE user_id = ?");
|
||||||
$clearCartStmt->execute([$user_id]);
|
$clearCartStmt->execute([$user_id]);
|
||||||
|
|
||||||
// Очищаем сессию
|
|
||||||
unset($_SESSION['cart']);
|
unset($_SESSION['cart']);
|
||||||
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
|
|
||||||
// Перенаправляем на страницу успеха
|
|
||||||
header('Location: order_success.php?id=' . $order_id);
|
header('Location: order_success.php?id=' . $order_id);
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
// register_handler.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
// Получаем данные из формы
|
|
||||||
$full_name = trim($_POST['fio'] ?? '');
|
$full_name = trim($_POST['fio'] ?? '');
|
||||||
$city = trim($_POST['city'] ?? '');
|
$city = trim($_POST['city'] ?? '');
|
||||||
$email = trim($_POST['email'] ?? '');
|
$email = trim($_POST['email'] ?? '');
|
||||||
@@ -14,7 +13,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$password = $_POST['password'] ?? '';
|
$password = $_POST['password'] ?? '';
|
||||||
$confirm_password = $_POST['confirm-password'] ?? '';
|
$confirm_password = $_POST['confirm-password'] ?? '';
|
||||||
|
|
||||||
// Валидация данных
|
|
||||||
if (empty($full_name) || strlen($full_name) < 3) {
|
if (empty($full_name) || strlen($full_name) < 3) {
|
||||||
$errors[] = 'ФИО должно содержать минимум 3 символа';
|
$errors[] = 'ФИО должно содержать минимум 3 символа';
|
||||||
}
|
}
|
||||||
@@ -39,12 +37,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$errors[] = 'Пароли не совпадают';
|
$errors[] = 'Пароли не совпадают';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка согласия с условиями
|
|
||||||
if (!isset($_POST['privacy']) || $_POST['privacy'] !== 'on') {
|
if (!isset($_POST['privacy']) || $_POST['privacy'] !== 'on') {
|
||||||
$errors[] = 'Необходимо согласие с условиями обработки персональных данных';
|
$errors[] = 'Необходимо согласие с условиями обработки персональных данных';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Если есть ошибки, возвращаем на форму
|
|
||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
$_SESSION['registration_errors'] = $errors;
|
$_SESSION['registration_errors'] = $errors;
|
||||||
$_SESSION['old_data'] = [
|
$_SESSION['old_data'] = [
|
||||||
@@ -57,11 +53,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Подключаемся к базе данных
|
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Проверяем, существует ли пользователь с таким email
|
|
||||||
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
||||||
$checkStmt->execute([$email]);
|
$checkStmt->execute([$email]);
|
||||||
|
|
||||||
@@ -77,17 +72,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Хэшируем пароль
|
|
||||||
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
// Определяем, является ли пользователь администратором
|
|
||||||
$is_admin = false;
|
$is_admin = false;
|
||||||
$admin_emails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
$admin_emails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
||||||
if (in_array(strtolower($email), $admin_emails)) {
|
if (in_array(strtolower($email), $admin_emails)) {
|
||||||
$is_admin = true;
|
$is_admin = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Используем CAST для правильной передачи boolean в PostgreSQL
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
INSERT INTO users (email, password_hash, full_name, phone, city, is_admin, is_active)
|
INSERT INTO users (email, password_hash, full_name, phone, city, is_admin, is_active)
|
||||||
VALUES (?, ?, ?, ?, ?, CAST(? AS boolean), TRUE)
|
VALUES (?, ?, ?, ?, ?, CAST(? AS boolean), TRUE)
|
||||||
@@ -100,7 +92,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$full_name,
|
$full_name,
|
||||||
$phone,
|
$phone,
|
||||||
$city,
|
$city,
|
||||||
$is_admin ? 'true' : 'false' // Строковые значения true/false для CAST
|
$is_admin ? 'true' : 'false'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user_id = $stmt->fetchColumn();
|
$user_id = $stmt->fetchColumn();
|
||||||
@@ -109,7 +101,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
throw new Exception('Ошибка при создании пользователя: user_id не получен');
|
throw new Exception('Ошибка при создании пользователя: user_id не получен');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, что пользователь действительно создался
|
|
||||||
$verifyStmt = $db->prepare("SELECT user_id, email, password_hash FROM users WHERE user_id = ?");
|
$verifyStmt = $db->prepare("SELECT user_id, email, password_hash FROM users WHERE user_id = ?");
|
||||||
$verifyStmt->execute([$user_id]);
|
$verifyStmt->execute([$user_id]);
|
||||||
$verifyUser = $verifyStmt->fetch(PDO::FETCH_ASSOC);
|
$verifyUser = $verifyStmt->fetch(PDO::FETCH_ASSOC);
|
||||||
@@ -118,12 +109,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
throw new Exception('Ошибка: пользователь не найден после создания');
|
throw new Exception('Ошибка: пользователь не найден после создания');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, что пароль сохранился правильно
|
|
||||||
if (empty($verifyUser['password_hash'])) {
|
if (empty($verifyUser['password_hash'])) {
|
||||||
throw new Exception('Ошибка: пароль не сохранен');
|
throw new Exception('Ошибка: пароль не сохранен');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Автоматически авторизуем пользователя
|
|
||||||
$_SESSION['user_id'] = $user_id;
|
$_SESSION['user_id'] = $user_id;
|
||||||
$_SESSION['user_email'] = $email;
|
$_SESSION['user_email'] = $email;
|
||||||
$_SESSION['full_name'] = $full_name;
|
$_SESSION['full_name'] = $full_name;
|
||||||
@@ -133,11 +122,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$_SESSION['isAdmin'] = (bool)$is_admin;
|
$_SESSION['isAdmin'] = (bool)$is_admin;
|
||||||
$_SESSION['login_time'] = time();
|
$_SESSION['login_time'] = time();
|
||||||
|
|
||||||
// Обновляем время последнего входа
|
|
||||||
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
||||||
$updateStmt->execute([$user_id]);
|
$updateStmt->execute([$user_id]);
|
||||||
|
|
||||||
// Перенаправляем на главную или каталог
|
|
||||||
$_SESSION['registration_success'] = 'Регистрация прошла успешно! ' .
|
$_SESSION['registration_success'] = 'Регистрация прошла успешно! ' .
|
||||||
($is_admin ? 'Вы зарегистрированы как администратор.' : 'Добро пожаловать в AETERNA!');
|
($is_admin ? 'Вы зарегистрированы как администратор.' : 'Добро пожаловать в AETERNA!');
|
||||||
|
|
||||||
@@ -145,7 +132,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
exit();
|
exit();
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
// Логируем полную ошибку для отладки
|
|
||||||
error_log("Registration DB Error: " . $e->getMessage());
|
error_log("Registration DB Error: " . $e->getMessage());
|
||||||
error_log("SQL State: " . $e->getCode());
|
error_log("SQL State: " . $e->getCode());
|
||||||
error_log("Email: " . $email);
|
error_log("Email: " . $email);
|
||||||
@@ -168,7 +155,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Если запрос не POST, перенаправляем на форму регистрации
|
|
||||||
header('Location: register.php');
|
header('Location: register.php');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для сообщений внизу страницы */
|
|
||||||
.page-messages {
|
.page-messages {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// script.js
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Инициализация корзины
|
|
||||||
let cart = {
|
let cart = {
|
||||||
items: [
|
items: [
|
||||||
{ id: 1, name: 'Кресло OPPORTUNITY', price: 16999, quantity: 1 },
|
{ id: 1, name: 'Кресло OPPORTUNITY', price: 16999, quantity: 1 },
|
||||||
@@ -12,12 +11,10 @@ $(document).ready(function() {
|
|||||||
discount: 0
|
discount: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
// Функция обновления общей суммы
|
|
||||||
function updateTotal() {
|
function updateTotal() {
|
||||||
let productsTotal = 0;
|
let productsTotal = 0;
|
||||||
let totalCount = 0;
|
let totalCount = 0;
|
||||||
|
|
||||||
// Пересчитываем товары
|
|
||||||
$('.products__item').each(function() {
|
$('.products__item').each(function() {
|
||||||
const $item = $(this);
|
const $item = $(this);
|
||||||
const price = parseInt($item.data('price'));
|
const price = parseInt($item.data('price'));
|
||||||
@@ -27,50 +24,39 @@ $(document).ready(function() {
|
|||||||
totalCount += quantity;
|
totalCount += quantity;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обновляем отображение
|
|
||||||
$('.products-total').text(productsTotal + ' ₽');
|
$('.products-total').text(productsTotal + ' ₽');
|
||||||
$('.summary-count').text(totalCount);
|
$('.summary-count').text(totalCount);
|
||||||
$('.total-count').text(totalCount + ' шт.');
|
$('.total-count').text(totalCount + ' шт.');
|
||||||
$('.cart-count').text(totalCount);
|
$('.cart-count').text(totalCount);
|
||||||
|
|
||||||
// Обновляем итоговую сумму
|
|
||||||
const finalTotal = productsTotal + cart.delivery - cart.discount;
|
const finalTotal = productsTotal + cart.delivery - cart.discount;
|
||||||
$('.final-total').text(finalTotal + ' ₽');
|
$('.final-total').text(finalTotal + ' ₽');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция валидации email
|
|
||||||
function validateEmail(email) {
|
function validateEmail(email) {
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
return emailRegex.test(email);
|
return emailRegex.test(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция валидации имени (ФИО)
|
|
||||||
function validateFullName(name) {
|
function validateFullName(name) {
|
||||||
// Проверяем, что имя содержит только буквы, пробелы, дефисы и апострофы
|
|
||||||
const nameRegex = /^[a-zA-Zа-яА-ЯёЁ\s\-']+$/;
|
const nameRegex = /^[a-zA-Zа-яА-ЯёЁ\s\-']+$/;
|
||||||
|
|
||||||
// Проверяем, что имя состоит минимум из 2 слов
|
|
||||||
const words = name.trim().split(/\s+/);
|
const words = name.trim().split(/\s+/);
|
||||||
|
|
||||||
return nameRegex.test(name) && words.length >= 2;
|
return nameRegex.test(name) && words.length >= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция валидации телефона
|
|
||||||
function validatePhone(phone) {
|
function validatePhone(phone) {
|
||||||
// Российский формат телефона: +7XXXXXXXXXX
|
|
||||||
const phoneRegex = /^\+7\d{10}$/;
|
const phoneRegex = /^\+7\d{10}$/;
|
||||||
return phoneRegex.test(phone);
|
return phoneRegex.test(phone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция отображения сообщения
|
|
||||||
function showMessage(messageId, duration = 5000) {
|
function showMessage(messageId, duration = 5000) {
|
||||||
// Скрываем все сообщения
|
|
||||||
$('.message').hide();
|
$('.message').hide();
|
||||||
|
|
||||||
// Показываем нужное сообщение
|
|
||||||
$(messageId).fadeIn(300);
|
$(messageId).fadeIn(300);
|
||||||
|
|
||||||
// Автоматически скрываем через указанное время
|
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$(messageId).fadeOut(300);
|
$(messageId).fadeOut(300);
|
||||||
@@ -78,7 +64,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция показа ошибки приватности
|
|
||||||
function showPrivacyError(show) {
|
function showPrivacyError(show) {
|
||||||
if (show) {
|
if (show) {
|
||||||
$('#privacy-error').show();
|
$('#privacy-error').show();
|
||||||
@@ -87,9 +72,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция отображения ошибки конкретного поля
|
|
||||||
function showFieldError(fieldId, message) {
|
function showFieldError(fieldId, message) {
|
||||||
// Убираем старые ошибки
|
|
||||||
$(fieldId).removeClass('error-input');
|
$(fieldId).removeClass('error-input');
|
||||||
$(fieldId + '-error').remove();
|
$(fieldId + '-error').remove();
|
||||||
|
|
||||||
@@ -99,7 +82,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация поля при потере фокуса с указанием конкретной ошибки
|
|
||||||
$('#fullname').on('blur', function() {
|
$('#fullname').on('blur', function() {
|
||||||
const value = $(this).val().trim();
|
const value = $(this).val().trim();
|
||||||
if (value) {
|
if (value) {
|
||||||
@@ -139,7 +121,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Валидация обязательных полей
|
|
||||||
$('#region').on('blur', function() {
|
$('#region').on('blur', function() {
|
||||||
const value = $(this).val().trim();
|
const value = $(this).val().trim();
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@@ -158,13 +139,11 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Очистка ошибки при начале ввода
|
|
||||||
$('.form__input').on('input', function() {
|
$('.form__input').on('input', function() {
|
||||||
const fieldId = '#' + $(this).attr('id');
|
const fieldId = '#' + $(this).attr('id');
|
||||||
showFieldError(fieldId, '');
|
showFieldError(fieldId, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик увеличения количества
|
|
||||||
$('.products__qty-btn.plus').click(function() {
|
$('.products__qty-btn.plus').click(function() {
|
||||||
const $qtyValue = $(this).siblings('.products__qty-value');
|
const $qtyValue = $(this).siblings('.products__qty-value');
|
||||||
let quantity = parseInt($qtyValue.text());
|
let quantity = parseInt($qtyValue.text());
|
||||||
@@ -172,7 +151,6 @@ $(document).ready(function() {
|
|||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик уменьшения количества
|
|
||||||
$('.products__qty-btn.minus').click(function() {
|
$('.products__qty-btn.minus').click(function() {
|
||||||
const $qtyValue = $(this).siblings('.products__qty-value');
|
const $qtyValue = $(this).siblings('.products__qty-value');
|
||||||
let quantity = parseInt($qtyValue.text());
|
let quantity = parseInt($qtyValue.text());
|
||||||
@@ -182,21 +160,18 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик удаления товара
|
|
||||||
$('.remove-from-cart').click(function() {
|
$('.remove-from-cart').click(function() {
|
||||||
const $productItem = $(this).closest('.products__item');
|
const $productItem = $(this).closest('.products__item');
|
||||||
$productItem.fadeOut(300, function() {
|
$productItem.fadeOut(300, function() {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
updateTotal();
|
updateTotal();
|
||||||
|
|
||||||
// Показываем сообщение, если корзина пуста
|
|
||||||
if ($('.products__item').length === 0) {
|
if ($('.products__item').length === 0) {
|
||||||
$('.products__list').html('<div class="empty-cart">Корзина пуста</div>');
|
$('.products__list').html('<div class="empty-cart">Корзина пуста</div>');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик применения промокода
|
|
||||||
$('.promo__btn').click(function() {
|
$('.promo__btn').click(function() {
|
||||||
const promoCode = $('.promo__input').val().toUpperCase();
|
const promoCode = $('.promo__input').val().toUpperCase();
|
||||||
|
|
||||||
@@ -218,7 +193,6 @@ $(document).ready(function() {
|
|||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработчик выбора доставки
|
|
||||||
$('input[name="delivery"]').change(function() {
|
$('input[name="delivery"]').change(function() {
|
||||||
if ($(this).val() === 'pickup') {
|
if ($(this).val() === 'pickup') {
|
||||||
cart.delivery = 0;
|
cart.delivery = 0;
|
||||||
@@ -230,16 +204,13 @@ $(document).ready(function() {
|
|||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Функция проверки всех полей формы
|
|
||||||
function validateForm() {
|
function validateForm() {
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
let errorMessages = [];
|
let errorMessages = [];
|
||||||
|
|
||||||
// Очищаем все старые ошибки
|
|
||||||
$('.field-error').remove();
|
$('.field-error').remove();
|
||||||
$('.form__input').removeClass('error-input');
|
$('.form__input').removeClass('error-input');
|
||||||
|
|
||||||
// Проверка обязательных полей
|
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
{
|
{
|
||||||
id: '#fullname',
|
id: '#fullname',
|
||||||
@@ -278,7 +249,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// Проверяем каждое поле
|
|
||||||
requiredFields.forEach(field => {
|
requiredFields.forEach(field => {
|
||||||
if (field.required && (!field.value || !field.validator(field.value))) {
|
if (field.required && (!field.value || !field.validator(field.value))) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -287,7 +257,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Проверка согласия на обработку данных
|
|
||||||
if (!$('#privacy-checkbox').is(':checked')) {
|
if (!$('#privacy-checkbox').is(':checked')) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
showPrivacyError(true);
|
showPrivacyError(true);
|
||||||
@@ -296,12 +265,10 @@ $(document).ready(function() {
|
|||||||
showPrivacyError(false);
|
showPrivacyError(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показываем общее сообщение, если есть ошибки
|
|
||||||
if (!isValid && errorMessages.length > 0) {
|
if (!isValid && errorMessages.length > 0) {
|
||||||
showMessage('#form-error', 5000);
|
showMessage('#form-error', 5000);
|
||||||
$('#form-error').text('Исправьте следующие ошибки: ' + errorMessages.join('; ')).removeClass('success').addClass('error');
|
$('#form-error').text('Исправьте следующие ошибки: ' + errorMessages.join('; ')).removeClass('success').addClass('error');
|
||||||
|
|
||||||
// Прокручиваем к первой ошибке
|
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $('.error-input').first().offset().top - 100
|
scrollTop: $('.error-input').first().offset().top - 100
|
||||||
}, 500);
|
}, 500);
|
||||||
@@ -310,26 +277,20 @@ $(document).ready(function() {
|
|||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обработчик оформления заказа
|
|
||||||
$('#submit-order').click(function() {
|
$('#submit-order').click(function() {
|
||||||
// Проверка валидации всех полей
|
|
||||||
if (!validateForm()) {
|
if (!validateForm()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Симуляция отправки заказа
|
|
||||||
$(this).prop('disabled', true).text('ОБРАБОТКА...');
|
$(this).prop('disabled', true).text('ОБРАБОТКА...');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
showMessage('#order-success', 5000);
|
showMessage('#order-success', 5000);
|
||||||
$(this).prop('disabled', false).text('ОФОРМИТЬ ЗАКАЗ');
|
$(this).prop('disabled', false).text('ОФОРМИТЬ ЗАКАЗ');
|
||||||
|
|
||||||
// Здесь можно добавить редирект на страницу благодарности
|
|
||||||
// window.location.href = 'спасибо.html';
|
|
||||||
}, 2000);
|
}, 2000);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Маска для телефона
|
|
||||||
$('#phone').on('input', function() {
|
$('#phone').on('input', function() {
|
||||||
let phone = $(this).val().replace(/\D/g, '');
|
let phone = $(this).val().replace(/\D/g, '');
|
||||||
if (phone.length > 0) {
|
if (phone.length > 0) {
|
||||||
@@ -341,6 +302,5 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Инициализация при загрузке
|
|
||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Функции для отображения сообщений
|
|
||||||
function showMessage(type, text) {
|
function showMessage(type, text) {
|
||||||
const messageId = type + 'Message';
|
const messageId = type + 'Message';
|
||||||
const $message = $('#' + messageId);
|
const $message = $('#' + messageId);
|
||||||
@@ -9,30 +9,25 @@ $(document).ready(function() {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка, является ли email администратора
|
|
||||||
function isAdminEmail(email) {
|
function isAdminEmail(email) {
|
||||||
const adminEmails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
const adminEmails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
||||||
return adminEmails.includes(email.toLowerCase());
|
return adminEmails.includes(email.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация ФИО (без цифр)
|
|
||||||
function validateFIO(fio) {
|
function validateFIO(fio) {
|
||||||
const words = fio.trim().split(/\s+/);
|
const words = fio.trim().split(/\s+/);
|
||||||
// Проверяем, что минимум 2 слова и нет цифр
|
|
||||||
const hasNoDigits = !/\d/.test(fio);
|
const hasNoDigits = !/\d/.test(fio);
|
||||||
return words.length >= 2 && words.every(word => word.length >= 2) && hasNoDigits;
|
return words.length >= 2 && words.every(word => word.length >= 2) && hasNoDigits;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация города
|
|
||||||
function validateCity(city) {
|
function validateCity(city) {
|
||||||
return city.trim().length >= 2 && /^[а-яА-ЯёЁ\s-]+$/.test(city);
|
return city.trim().length >= 2 && /^[а-яА-ЯёЁ\s-]+$/.test(city);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация email
|
|
||||||
function validateEmail(email) {
|
function validateEmail(email) {
|
||||||
const localPart = email.split('@')[0];
|
const localPart = email.split('@')[0];
|
||||||
|
|
||||||
// Проверка на кириллические символы перед @
|
|
||||||
if (/[а-яА-ЯёЁ]/.test(localPart)) {
|
if (/[а-яА-ЯёЁ]/.test(localPart)) {
|
||||||
showError('email', 'В тексте перед знаком "@" не должно быть кириллических символов');
|
showError('email', 'В тексте перед знаком "@" не должно быть кириллических символов');
|
||||||
return false;
|
return false;
|
||||||
@@ -48,18 +43,15 @@ $(document).ready(function() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация телефона
|
|
||||||
function validatePhone(phone) {
|
function validatePhone(phone) {
|
||||||
const phoneRegex = /^(\+7|8)[\s-]?\(?\d{3}\)?[\s-]?\d{3}[\s-]?\d{2}[\s-]?\d{2}$/;
|
const phoneRegex = /^(\+7|8)[\s-]?\(?\d{3}\)?[\s-]?\d{3}[\s-]?\d{2}[\s-]?\d{2}$/;
|
||||||
return phoneRegex.test(phone.replace(/\s/g, ''));
|
return phoneRegex.test(phone.replace(/\s/g, ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация пароля
|
|
||||||
function validatePassword(password) {
|
function validatePassword(password) {
|
||||||
return password.length >= 6;
|
return password.length >= 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показать/скрыть ошибку
|
|
||||||
function showError(fieldId, message) {
|
function showError(fieldId, message) {
|
||||||
$('#' + fieldId).addClass('error');
|
$('#' + fieldId).addClass('error');
|
||||||
$('#' + fieldId + '-error').text(message).show();
|
$('#' + fieldId + '-error').text(message).show();
|
||||||
@@ -70,11 +62,9 @@ $(document).ready(function() {
|
|||||||
$('#' + fieldId + '-error').hide();
|
$('#' + fieldId + '-error').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация формы
|
|
||||||
function validateForm() {
|
function validateForm() {
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
|
|
||||||
// Валидация ФИО
|
|
||||||
const fio = $('#fio').val();
|
const fio = $('#fio').val();
|
||||||
if (!validateFIO(fio)) {
|
if (!validateFIO(fio)) {
|
||||||
if (/\d/.test(fio)) {
|
if (/\d/.test(fio)) {
|
||||||
@@ -87,7 +77,6 @@ $(document).ready(function() {
|
|||||||
hideError('fio');
|
hideError('fio');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация города
|
|
||||||
const city = $('#city').val();
|
const city = $('#city').val();
|
||||||
if (!validateCity(city)) {
|
if (!validateCity(city)) {
|
||||||
showError('city', 'Укажите корректное название города (только русские буквы)');
|
showError('city', 'Укажите корректное название города (только русские буквы)');
|
||||||
@@ -96,7 +85,6 @@ $(document).ready(function() {
|
|||||||
hideError('city');
|
hideError('city');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация email
|
|
||||||
const email = $('#email').val();
|
const email = $('#email').val();
|
||||||
if (!validateEmail(email)) {
|
if (!validateEmail(email)) {
|
||||||
showError('email', 'Введите корректный email адрес');
|
showError('email', 'Введите корректный email адрес');
|
||||||
@@ -105,7 +93,6 @@ $(document).ready(function() {
|
|||||||
hideError('email');
|
hideError('email');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация телефона
|
|
||||||
const phone = $('#phone').val();
|
const phone = $('#phone').val();
|
||||||
if (!validatePhone(phone)) {
|
if (!validatePhone(phone)) {
|
||||||
showError('phone', 'Введите номер в формате: +7(912)999-12-23');
|
showError('phone', 'Введите номер в формате: +7(912)999-12-23');
|
||||||
@@ -114,7 +101,6 @@ $(document).ready(function() {
|
|||||||
hideError('phone');
|
hideError('phone');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация пароля
|
|
||||||
const password = $('#password').val();
|
const password = $('#password').val();
|
||||||
if (!validatePassword(password)) {
|
if (!validatePassword(password)) {
|
||||||
showError('password', 'Пароль должен содержать минимум 6 символов');
|
showError('password', 'Пароль должен содержать минимум 6 символов');
|
||||||
@@ -123,7 +109,6 @@ $(document).ready(function() {
|
|||||||
hideError('password');
|
hideError('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка совпадения паролей
|
|
||||||
const confirmPassword = $('#confirm-password').val();
|
const confirmPassword = $('#confirm-password').val();
|
||||||
if (password !== confirmPassword) {
|
if (password !== confirmPassword) {
|
||||||
showError('confirm-password', 'Пароли не совпадают');
|
showError('confirm-password', 'Пароли не совпадают');
|
||||||
@@ -132,7 +117,6 @@ $(document).ready(function() {
|
|||||||
hideError('confirm-password');
|
hideError('confirm-password');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка согласия с условиями
|
|
||||||
if (!$('#privacy').is(':checked')) {
|
if (!$('#privacy').is(':checked')) {
|
||||||
$('#privacy-error').show();
|
$('#privacy-error').show();
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -143,7 +127,6 @@ $(document).ready(function() {
|
|||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Реальная валидация при вводе
|
|
||||||
$('input').on('blur', function() {
|
$('input').on('blur', function() {
|
||||||
const fieldId = $(this).attr('id');
|
const fieldId = $(this).attr('id');
|
||||||
const value = $(this).val();
|
const value = $(this).val();
|
||||||
@@ -199,7 +182,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка отправки формы
|
|
||||||
$('#registrationForm').on('submit', function(e) {
|
$('#registrationForm').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@@ -207,7 +189,6 @@ $(document).ready(function() {
|
|||||||
const email = $('#email').val();
|
const email = $('#email').val();
|
||||||
const isAdmin = isAdminEmail(email);
|
const isAdmin = isAdminEmail(email);
|
||||||
|
|
||||||
// Сохраняем данные пользователя в localStorage
|
|
||||||
const userData = {
|
const userData = {
|
||||||
email: email,
|
email: email,
|
||||||
fio: $('#fio').val(),
|
fio: $('#fio').val(),
|
||||||
@@ -220,12 +201,11 @@ $(document).ready(function() {
|
|||||||
localStorage.setItem('isLoggedIn', 'true');
|
localStorage.setItem('isLoggedIn', 'true');
|
||||||
localStorage.setItem('isAdmin', isAdmin.toString());
|
localStorage.setItem('isAdmin', isAdmin.toString());
|
||||||
|
|
||||||
// Эмуляция успешной регистрации
|
|
||||||
showMessage('success', 'Регистрация прошла успешно! ' +
|
showMessage('success', 'Регистрация прошла успешно! ' +
|
||||||
(isAdmin ? 'Вы зарегистрированы как администратор.' : 'Добро пожаловать в AETERNA!'));
|
(isAdmin ? 'Вы зарегистрированы как администратор.' : 'Добро пожаловать в AETERNA!'));
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// Перенаправление на главную страницу
|
|
||||||
window.location.href = 'cite_mebel.php';
|
window.location.href = 'cite_mebel.php';
|
||||||
}, 2000);
|
}, 2000);
|
||||||
} else {
|
} else {
|
||||||
@@ -233,7 +213,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Плавная прокрутка к якорям
|
|
||||||
$('a[href^="#"]').on('click', function(event) {
|
$('a[href^="#"]').on('click', function(event) {
|
||||||
var target = $(this.getAttribute('href'));
|
var target = $(this.getAttribute('href'));
|
||||||
if (target.length) {
|
if (target.length) {
|
||||||
@@ -244,7 +223,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Переключение между регистрацией и входом
|
|
||||||
$('.login-btn').on('click', function() {
|
$('.login-btn').on('click', function() {
|
||||||
showMessage('warning', 'Переход к форме входа...');
|
showMessage('warning', 'Переход к форме входа...');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -252,13 +230,11 @@ $(document).ready(function() {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка ссылки "Сменить пароль"
|
|
||||||
$('.password-link').on('click', function(e) {
|
$('.password-link').on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
showMessage('warning', 'Функция смены пароля будет доступна после регистрации');
|
showMessage('warning', 'Функция смены пароля будет доступна после регистрации');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Маска для телефона
|
|
||||||
$('#phone').on('input', function() {
|
$('#phone').on('input', function() {
|
||||||
let value = $(this).val().replace(/\D/g, '');
|
let value = $(this).val().replace(/\D/g, '');
|
||||||
if (value.startsWith('7') || value.startsWith('8')) {
|
if (value.startsWith('7') || value.startsWith('8')) {
|
||||||
@@ -274,18 +250,16 @@ $(document).ready(function() {
|
|||||||
$(this).val(value);
|
$(this).val(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Запрет ввода цифр в поле ФИО
|
|
||||||
$('#fio').on('input', function() {
|
$('#fio').on('input', function() {
|
||||||
let value = $(this).val();
|
let value = $(this).val();
|
||||||
// Удаляем цифры из значения
|
|
||||||
value = value.replace(/\d/g, '');
|
value = value.replace(/\d/g, '');
|
||||||
$(this).val(value);
|
$(this).val(value);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Для входа (файл вход.html)
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Проверяем, если пользователь уже вошел
|
|
||||||
if (localStorage.getItem('isLoggedIn') === 'true') {
|
if (localStorage.getItem('isLoggedIn') === 'true') {
|
||||||
const userData = JSON.parse(localStorage.getItem('userData') || '{}');
|
const userData = JSON.parse(localStorage.getItem('userData') || '{}');
|
||||||
if (userData.email) {
|
if (userData.email) {
|
||||||
@@ -293,9 +267,8 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Функция проверки пароля администратора
|
|
||||||
function checkAdminPassword(email, password) {
|
function checkAdminPassword(email, password) {
|
||||||
// Административные аккаунты
|
|
||||||
const adminAccounts = {
|
const adminAccounts = {
|
||||||
'admin@aeterna.ru': 'admin123',
|
'admin@aeterna.ru': 'admin123',
|
||||||
'administrator@aeterna.ru': 'admin123',
|
'administrator@aeterna.ru': 'admin123',
|
||||||
@@ -305,7 +278,6 @@ $(document).ready(function() {
|
|||||||
return adminAccounts[email.toLowerCase()] === password;
|
return adminAccounts[email.toLowerCase()] === password;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация формы входа
|
|
||||||
$('#loginForm').on('submit', function(e) {
|
$('#loginForm').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@@ -313,7 +285,6 @@ $(document).ready(function() {
|
|||||||
const email = $('#login-email').val();
|
const email = $('#login-email').val();
|
||||||
const password = $('#login-password').val();
|
const password = $('#login-password').val();
|
||||||
|
|
||||||
// Валидация email
|
|
||||||
if (!isValidEmail(email)) {
|
if (!isValidEmail(email)) {
|
||||||
$('#email-error').show();
|
$('#email-error').show();
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -321,7 +292,6 @@ $(document).ready(function() {
|
|||||||
$('#email-error').hide();
|
$('#email-error').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация пароля
|
|
||||||
if (password.length < 6) {
|
if (password.length < 6) {
|
||||||
$('#password-error').show();
|
$('#password-error').show();
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -330,17 +300,15 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
// Здесь обычно отправка данных на сервер
|
|
||||||
showMessage('success', 'Вы успешно вошли в систему!');
|
showMessage('success', 'Вы успешно вошли в систему!');
|
||||||
|
|
||||||
// Перенаправление на главную страницу через 1.5 секунды
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
window.location.href = 'cite_mebel.php';
|
window.location.href = 'cite_mebel.php';
|
||||||
}, 1500);
|
}, 1500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Функция показа сообщений
|
|
||||||
function showMessage(type, text) {
|
function showMessage(type, text) {
|
||||||
const messageId = type + 'Message';
|
const messageId = type + 'Message';
|
||||||
const $message = $('#' + messageId);
|
const $message = $('#' + messageId);
|
||||||
@@ -352,12 +320,10 @@ $(document).ready(function() {
|
|||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Скрываем сообщения об ошибках при фокусе на полях
|
|
||||||
$('input').on('focus', function() {
|
$('input').on('focus', function() {
|
||||||
$(this).next('.error-message').hide();
|
$(this).next('.error-message').hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка чекбокса "Запомнить меня"
|
|
||||||
$('#remember').on('change', function() {
|
$('#remember').on('change', function() {
|
||||||
if ($(this).is(':checked')) {
|
if ($(this).is(':checked')) {
|
||||||
const email = $('#login-email').val();
|
const email = $('#login-email').val();
|
||||||
@@ -369,14 +335,12 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Автозаполнение email, если пользователь выбрал "Запомнить меня"
|
|
||||||
const rememberedEmail = localStorage.getItem('rememberedEmail');
|
const rememberedEmail = localStorage.getItem('rememberedEmail');
|
||||||
if (rememberedEmail) {
|
if (rememberedEmail) {
|
||||||
$('#login-email').val(rememberedEmail);
|
$('#login-email').val(rememberedEmail);
|
||||||
$('#remember').prop('checked', true);
|
$('#remember').prop('checked', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обработка ссылки "Забыли пароль?"
|
|
||||||
$('.forgot-password').on('click', function(e) {
|
$('.forgot-password').on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
showMessage('info', 'Для восстановления пароля обратитесь к администратору');
|
showMessage('info', 'Для восстановления пароля обратитесь к администратору');
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для сообщений внизу страницы */
|
|
||||||
.page-messages {
|
.page-messages {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
@@ -60,7 +59,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Дополнительные стили для формы регистрации */
|
|
||||||
.input-group {
|
.input-group {
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
@@ -89,13 +87,11 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Исправление отступов для страницы регистрации */
|
|
||||||
.profile-page-main {
|
.profile-page-main {
|
||||||
padding: 40px 0;
|
padding: 40px 0;
|
||||||
min-height: calc(100vh - 200px);
|
min-height: calc(100vh - 200px);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Убедимся, что контейнер не перекрывает шапку и футер */
|
|
||||||
.profile-container {
|
.profile-container {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -108,7 +104,6 @@
|
|||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для страницы входа */
|
|
||||||
.form-options {
|
.form-options {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|||||||
@@ -83,4 +83,3 @@
|
|||||||
border-color: @color-primary;
|
border-color: @color-primary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
// СТРОГАЯ ПРОВЕРКА - НЕ ПУСКАЕМ БЕЗ АВТОРИЗАЦИИ
|
|
||||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||||
header('Location: login.php?error=auth_required&redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
header('Location: login.php?error=auth_required&redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
||||||
exit();
|
exit();
|
||||||
@@ -10,7 +9,6 @@ if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
|||||||
|
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
// Получаем параметры фильтрации
|
|
||||||
$category_id = $_GET['category'] ?? 0;
|
$category_id = $_GET['category'] ?? 0;
|
||||||
$search = $_GET['search'] ?? '';
|
$search = $_GET['search'] ?? '';
|
||||||
$min_price = $_GET['min_price'] ?? 0;
|
$min_price = $_GET['min_price'] ?? 0;
|
||||||
@@ -19,12 +17,11 @@ $colors = isset($_GET['colors']) ? (array)$_GET['colors'] : [];
|
|||||||
$materials = isset($_GET['materials']) ? (array)$_GET['materials'] : [];
|
$materials = isset($_GET['materials']) ? (array)$_GET['materials'] : [];
|
||||||
$show_all = isset($_GET['show_all']) && $_GET['show_all'] == '1';
|
$show_all = isset($_GET['show_all']) && $_GET['show_all'] == '1';
|
||||||
|
|
||||||
// Проверяем уведомления
|
|
||||||
$success_message = $_GET['success'] ?? '';
|
$success_message = $_GET['success'] ?? '';
|
||||||
$error_message = $_GET['error'] ?? '';
|
$error_message = $_GET['error'] ?? '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Получаем информацию о пользователе
|
|
||||||
$user_id = $_SESSION['user_id'] ?? 0;
|
$user_id = $_SESSION['user_id'] ?? 0;
|
||||||
$userStmt = $db->prepare("SELECT * FROM users WHERE user_id = ?");
|
$userStmt = $db->prepare("SELECT * FROM users WHERE user_id = ?");
|
||||||
$userStmt->execute([$user_id]);
|
$userStmt->execute([$user_id]);
|
||||||
@@ -35,7 +32,6 @@ try {
|
|||||||
$fullName = $_SESSION['full_name'] ?? $userEmail;
|
$fullName = $_SESSION['full_name'] ?? $userEmail;
|
||||||
$loginTime = $_SESSION['login_time'] ?? time();
|
$loginTime = $_SESSION['login_time'] ?? time();
|
||||||
|
|
||||||
// Получаем категории (ИСПРАВЛЕНО: убрано дублирование fetchAll)
|
|
||||||
try {
|
try {
|
||||||
$categoriesStmt = $db->prepare("
|
$categoriesStmt = $db->prepare("
|
||||||
SELECT * FROM categories
|
SELECT * FROM categories
|
||||||
@@ -49,7 +45,6 @@ try {
|
|||||||
error_log("Ошибка получения категорий: " . $e->getMessage());
|
error_log("Ошибка получения категорий: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получаем подкатегории для текущей категории (если выбрана)
|
|
||||||
$subcategories = [];
|
$subcategories = [];
|
||||||
if ($category_id > 0) {
|
if ($category_id > 0) {
|
||||||
$subStmt = $db->prepare("
|
$subStmt = $db->prepare("
|
||||||
@@ -61,7 +56,6 @@ try {
|
|||||||
$subcategories = $subStmt->fetchAll();
|
$subcategories = $subStmt->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем наличие столбцов color и material в таблице products
|
|
||||||
$checkColumns = $db->query("
|
$checkColumns = $db->query("
|
||||||
SELECT column_name
|
SELECT column_name
|
||||||
FROM information_schema.columns
|
FROM information_schema.columns
|
||||||
@@ -73,7 +67,6 @@ try {
|
|||||||
$hasColorColumn = in_array('color', $existingColumns);
|
$hasColorColumn = in_array('color', $existingColumns);
|
||||||
$hasMaterialColumn = in_array('material', $existingColumns);
|
$hasMaterialColumn = in_array('material', $existingColumns);
|
||||||
|
|
||||||
// Получаем доступные цвета из базы данных (если столбец существует)
|
|
||||||
$availableColors = [];
|
$availableColors = [];
|
||||||
if ($hasColorColumn) {
|
if ($hasColorColumn) {
|
||||||
$colorsStmt = $db->query("
|
$colorsStmt = $db->query("
|
||||||
@@ -84,7 +77,6 @@ try {
|
|||||||
$availableColors = $colorsStmt->fetchAll(PDO::FETCH_COLUMN);
|
$availableColors = $colorsStmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получаем доступные материалы из базы данных (если столбец существует)
|
|
||||||
$availableMaterials = [];
|
$availableMaterials = [];
|
||||||
if ($hasMaterialColumn) {
|
if ($hasMaterialColumn) {
|
||||||
$materialsStmt = $db->query("
|
$materialsStmt = $db->query("
|
||||||
@@ -95,7 +87,6 @@ try {
|
|||||||
$availableMaterials = $materialsStmt->fetchAll(PDO::FETCH_COLUMN);
|
$availableMaterials = $materialsStmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получаем товары из базы данных с фильтрами
|
|
||||||
$sql = "SELECT p.*, c.name as category_name
|
$sql = "SELECT p.*, c.name as category_name
|
||||||
FROM products p
|
FROM products p
|
||||||
LEFT JOIN categories c ON p.category_id = c.category_id
|
LEFT JOIN categories c ON p.category_id = c.category_id
|
||||||
@@ -103,65 +94,57 @@ try {
|
|||||||
|
|
||||||
$params = [];
|
$params = [];
|
||||||
|
|
||||||
// Фильтрация по доступности
|
|
||||||
if (!$show_all && !$isAdmin) {
|
if (!$show_all && !$isAdmin) {
|
||||||
$sql .= " AND p.is_available = TRUE";
|
$sql .= " AND p.is_available = TRUE";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Фильтрация по категории
|
|
||||||
if ($category_id > 0) {
|
if ($category_id > 0) {
|
||||||
$sql .= " AND p.category_id = ?";
|
$sql .= " AND p.category_id = ?";
|
||||||
$params[] = $category_id;
|
$params[] = $category_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Фильтрация по цене
|
|
||||||
if ($min_price > 0 || $max_price < 1000000) {
|
if ($min_price > 0 || $max_price < 1000000) {
|
||||||
$sql .= " AND p.price BETWEEN ? AND ?";
|
$sql .= " AND p.price BETWEEN ? AND ?";
|
||||||
$params[] = $min_price;
|
$params[] = $min_price;
|
||||||
$params[] = $max_price;
|
$params[] = $max_price;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Фильтрация по цвету
|
|
||||||
if ($hasColorColumn && !empty($colors)) {
|
if ($hasColorColumn && !empty($colors)) {
|
||||||
$placeholders = implode(',', array_fill(0, count($colors), '?'));
|
$placeholders = implode(',', array_fill(0, count($colors), '?'));
|
||||||
$sql .= " AND p.color IN ($placeholders)";
|
$sql .= " AND p.color IN ($placeholders)";
|
||||||
$params = array_merge($params, $colors);
|
$params = array_merge($params, $colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Фильтрация по материалу
|
|
||||||
if ($hasMaterialColumn && !empty($materials)) {
|
if ($hasMaterialColumn && !empty($materials)) {
|
||||||
$placeholders = implode(',', array_fill(0, count($materials), '?'));
|
$placeholders = implode(',', array_fill(0, count($materials), '?'));
|
||||||
$sql .= " AND p.material IN ($placeholders)";
|
$sql .= " AND p.material IN ($placeholders)";
|
||||||
$params = array_merge($params, $materials);
|
$params = array_merge($params, $materials);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Поиск
|
|
||||||
if (!empty($search)) {
|
if (!empty($search)) {
|
||||||
$sql .= " AND (p.name LIKE ? OR p.description LIKE ?)";
|
$sql .= " AND (p.name LIKE ? OR p.description LIKE ?)";
|
||||||
$params[] = "%$search%";
|
$params[] = "%$search%";
|
||||||
$params[] = "%$search%";
|
$params[] = "%$search%";
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= " ORDER BY p.product_id ASC LIMIT 50"; // Увеличил лимит до 50
|
$sql .= " ORDER BY p.product_id ASC LIMIT 50";
|
||||||
|
|
||||||
$stmt = $db->prepare($sql);
|
$stmt = $db->prepare($sql);
|
||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
$filteredProducts = $stmt->fetchAll();
|
$filteredProducts = $stmt->fetchAll();
|
||||||
|
|
||||||
// Оригинальные размеры для первых 9 товаров (ID 1-9)
|
|
||||||
$originalSizes = [
|
$originalSizes = [
|
||||||
1 => 'small', // Светильник MINNIGHT
|
1 => 'small',
|
||||||
2 => 'large', // Диван MODERN (Кровать MODER)
|
2 => 'large',
|
||||||
3 => 'tall align-right', // Торшер MARCIA
|
3 => 'tall align-right',
|
||||||
4 => 'wide', // Светильник POLET
|
4 => 'wide',
|
||||||
5 => 'small1', // Стол NORD
|
5 => 'small1',
|
||||||
6 => 'wide2', // Диван ROYALTY
|
6 => 'wide2',
|
||||||
7 => 'wide3', // Кресло MINIMAL
|
7 => 'wide3',
|
||||||
8 => 'wide2_1', // Стол LONKI
|
8 => 'wide2_1',
|
||||||
9 => 'full-width' // Диван HEMMINS
|
9 => 'full-width'
|
||||||
];
|
];
|
||||||
|
|
||||||
// Классы для изображений
|
|
||||||
$imgClasses = ['small1', 'wide2', 'wide3', 'wide2_1'];
|
$imgClasses = ['small1', 'wide2', 'wide3', 'wide2_1'];
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
@@ -179,7 +162,7 @@ try {
|
|||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||||
<style>
|
<style>
|
||||||
/* В стилях для catalog.php добавьте: */
|
|
||||||
.catalog-dropdown__menu {
|
.catalog-dropdown__menu {
|
||||||
max-height: 400px;
|
max-height: 400px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
@@ -212,7 +195,6 @@ try {
|
|||||||
color: #453227;
|
color: #453227;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* СТИЛИ ТОЧНО КАК В HTML МАКЕТЕ */
|
|
||||||
.user-profile-dropdown {
|
.user-profile-dropdown {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@@ -412,7 +394,6 @@ try {
|
|||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для названий товаров внизу слева - ПОЛНОСТЬЮ ПРОЗРАЧНЫЕ */
|
|
||||||
.product-name-overlay {
|
.product-name-overlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 15px;
|
left: 15px;
|
||||||
@@ -448,7 +429,6 @@ try {
|
|||||||
text-align: left !important;
|
text-align: left !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Специальный стиль для стола Lonki - текст справа */
|
|
||||||
.product-name-overlay.lonki-right {
|
.product-name-overlay.lonki-right {
|
||||||
left: auto !important;
|
left: auto !important;
|
||||||
right: 15px !important;
|
right: 15px !important;
|
||||||
@@ -456,13 +436,11 @@ try {
|
|||||||
text-align: right !important;
|
text-align: right !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Для Lonki цена тоже справа */
|
|
||||||
.product-name-overlay.lonki-right .name,
|
.product-name-overlay.lonki-right .name,
|
||||||
.product-name-overlay.lonki-right .price {
|
.product-name-overlay.lonki-right .price {
|
||||||
text-align: right !important;
|
text-align: right !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Специальный стиль для дивана HEMMINS - текст слева сверху */
|
|
||||||
.product-name-overlay.compact-top-left {
|
.product-name-overlay.compact-top-left {
|
||||||
left: 15px !important;
|
left: 15px !important;
|
||||||
top: 15px !important;
|
top: 15px !important;
|
||||||
@@ -470,13 +448,11 @@ try {
|
|||||||
text-align: left !important;
|
text-align: left !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Для дивана HEMMINS цена тоже сверху */
|
|
||||||
.product-name-overlay.compact-top-left .name,
|
.product-name-overlay.compact-top-left .name,
|
||||||
.product-name-overlay.compact-top-left .price {
|
.product-name-overlay.compact-top-left .price {
|
||||||
text-align: left !important;
|
text-align: left !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для иконки корзины */
|
|
||||||
.product-wishlist-icon {
|
.product-wishlist-icon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 15px;
|
bottom: 15px;
|
||||||
@@ -518,12 +494,10 @@ try {
|
|||||||
transition: transform 0.3s ease;
|
transition: transform 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Убираем старый overlay внизу */
|
|
||||||
.product-info-overlay {
|
.product-info-overlay {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стиль для акционных товаров */
|
|
||||||
.product-card .product-discount {
|
.product-card .product-discount {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 15px;
|
top: 15px;
|
||||||
@@ -537,7 +511,6 @@ try {
|
|||||||
z-index: 3;
|
z-index: 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стиль для недоступных товаров */
|
|
||||||
.product-card.unavailable {
|
.product-card.unavailable {
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
filter: grayscale(0.7);
|
filter: grayscale(0.7);
|
||||||
@@ -598,7 +571,6 @@ try {
|
|||||||
border-left: 4px solid #617365;
|
border-left: 4px solid #617365;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Адаптивность для мобильных */
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.product-name-overlay {
|
.product-name-overlay {
|
||||||
left: 10px;
|
left: 10px;
|
||||||
@@ -705,7 +677,6 @@ try {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для уведомлений */
|
|
||||||
.notification {
|
.notification {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
@@ -733,7 +704,6 @@ try {
|
|||||||
background: #17a2b8;
|
background: #17a2b8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для админ-панели */
|
|
||||||
.admin-catalog-btn {
|
.admin-catalog-btn {
|
||||||
background: #453227;
|
background: #453227;
|
||||||
color: white;
|
color: white;
|
||||||
@@ -895,7 +865,7 @@ try {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ($isAdmin): ?>
|
<?php if ($isAdmin): ?>
|
||||||
<!-- В файле catalog.php найдите эти строки: -->
|
|
||||||
<div class="admin-panel">
|
<div class="admin-panel">
|
||||||
<h3 style="margin-bottom: 15px; color: #453227;">
|
<h3 style="margin-bottom: 15px; color: #453227;">
|
||||||
<i class="fas fa-user-shield"></i> Панель управления каталогом
|
<i class="fas fa-user-shield"></i> Панель управления каталогом
|
||||||
@@ -904,14 +874,14 @@ try {
|
|||||||
</span>
|
</span>
|
||||||
</h3>
|
</h3>
|
||||||
<div>
|
<div>
|
||||||
<!-- КНОПКА КАТАЛОГ ДОБАВЛЕНА -->
|
|
||||||
<a href="admin/index.php?action=catalog" class="admin-btn">
|
<a href="admin/index.php?action=catalog" class="admin-btn">
|
||||||
<i class="fas fa-boxes"></i> Управление каталогом
|
<i class="fas fa-boxes"></i> Управление каталогом
|
||||||
</a>
|
</a>
|
||||||
<a href="admin/index.php?action=add_product" class="admin-btn">
|
<a href="admin/index.php?action=add_product" class="admin-btn">
|
||||||
<i class="fas fa-plus"></i> Добавить товар
|
<i class="fas fa-plus"></i> Добавить товар
|
||||||
</a>
|
</a>
|
||||||
<!-- КНОПКА УПРАВЛЕНИЯ КАТЕГОРИЯМИ - ПЕРЕХОД В ОТДЕЛЬНЫЙ РАЗДЕЛ -->
|
|
||||||
<a href="admin/index.php?action=categories" class="admin-btn">
|
<a href="admin/index.php?action=categories" class="admin-btn">
|
||||||
<i class="fas fa-tags"></i> Управление категориями
|
<i class="fas fa-tags"></i> Управление категориями
|
||||||
</a>
|
</a>
|
||||||
@@ -1089,10 +1059,9 @@ try {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- В catalog.php, в секции вывода товаров: -->
|
|
||||||
<div class="products-container">
|
<div class="products-container">
|
||||||
<?php
|
<?php
|
||||||
// Оригинальные 9 товаров с их размерами
|
|
||||||
$originalProducts = [
|
$originalProducts = [
|
||||||
1 => ['name' => 'Светильник MINNIGHT', 'price' => 7999, 'image' => 'img2/1_2.png', 'size' => 'small'],
|
1 => ['name' => 'Светильник MINNIGHT', 'price' => 7999, 'image' => 'img2/1_2.png', 'size' => 'small'],
|
||||||
2 => ['name' => 'Кровать MODER', 'price' => 45999, 'image' => 'img2/3_3.png', 'size' => 'large'],
|
2 => ['name' => 'Кровать MODER', 'price' => 45999, 'image' => 'img2/3_3.png', 'size' => 'large'],
|
||||||
@@ -1105,7 +1074,6 @@ try {
|
|||||||
9 => ['name' => 'Диван HEMMINS', 'price' => 89999, 'image' => 'img2/9_9.png', 'size' => 'full-width']
|
9 => ['name' => 'Диван HEMMINS', 'price' => 89999, 'image' => 'img2/9_9.png', 'size' => 'full-width']
|
||||||
];
|
];
|
||||||
|
|
||||||
// Если в базе данных товаров нет, показываем оригинальные
|
|
||||||
if (empty($filteredProducts)) {
|
if (empty($filteredProducts)) {
|
||||||
foreach ($originalProducts as $id => $product): ?>
|
foreach ($originalProducts as $id => $product): ?>
|
||||||
<div class="product-card <?= $product['size'] ?>"
|
<div class="product-card <?= $product['size'] ?>"
|
||||||
@@ -1130,14 +1098,14 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
<?php endforeach;
|
<?php endforeach;
|
||||||
} else {
|
} else {
|
||||||
// Вывод товаров из базы данных
|
|
||||||
foreach ($filteredProducts as $product):
|
foreach ($filteredProducts as $product):
|
||||||
// Определяем размер по ID
|
|
||||||
$productId = $product['product_id'];
|
$productId = $product['product_id'];
|
||||||
if ($productId <= 9 && isset($originalProducts[$productId])) {
|
if ($productId <= 9 && isset($originalProducts[$productId])) {
|
||||||
$sizeClass = $originalProducts[$productId]['size'];
|
$sizeClass = $originalProducts[$productId]['size'];
|
||||||
} else {
|
} else {
|
||||||
$sizeClass = 'small'; // Все новые товары - размер small
|
$sizeClass = 'small';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<div class="product-card <?= $sizeClass ?>"
|
<div class="product-card <?= $sizeClass ?>"
|
||||||
@@ -1218,13 +1186,12 @@ try {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Слайдер цены
|
|
||||||
$('#priceSlider').on('input', function() {
|
$('#priceSlider').on('input', function() {
|
||||||
const value = $(this).val();
|
const value = $(this).val();
|
||||||
$('#priceDisplay').text('До ' + new Intl.NumberFormat('ru-RU').format(value) + ' ₽');
|
$('#priceDisplay').text('До ' + new Intl.NumberFormat('ru-RU').format(value) + ' ₽');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Профиль пользователя
|
|
||||||
$('#profileToggle').click(function(e) {
|
$('#profileToggle').click(function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
$('#profileMenu').toggle();
|
$('#profileMenu').toggle();
|
||||||
@@ -1236,10 +1203,8 @@ try {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обновление счетчика корзины
|
|
||||||
updateCartCount();
|
updateCartCount();
|
||||||
|
|
||||||
// Добавление в корзину
|
|
||||||
$('.add-to-cart-btn').click(function(e) {
|
$('.add-to-cart-btn').click(function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const productId = $(this).data('product-id');
|
const productId = $(this).data('product-id');
|
||||||
@@ -1254,8 +1219,6 @@ try {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Клик по карточке товара
|
|
||||||
// В catalog.php, в разделе JavaScript:
|
|
||||||
$('.product-card').click(function(e) {
|
$('.product-card').click(function(e) {
|
||||||
if (!$(e.target).closest('.add-to-cart-btn').length &&
|
if (!$(e.target).closest('.add-to-cart-btn').length &&
|
||||||
!$(e.target).closest('.product-wishlist-icon').length) {
|
!$(e.target).closest('.product-wishlist-icon').length) {
|
||||||
@@ -1263,7 +1226,7 @@ try {
|
|||||||
const isAvailable = $(this).data('available');
|
const isAvailable = $(this).data('available');
|
||||||
|
|
||||||
if (isAvailable) {
|
if (isAvailable) {
|
||||||
// Для дивана MODERN (ID 2) ведем на отдельную страницу
|
|
||||||
if (productId == 2) {
|
if (productId == 2) {
|
||||||
window.location.href = 'product_modern.php';
|
window.location.href = 'product_modern.php';
|
||||||
} else {
|
} else {
|
||||||
@@ -1272,7 +1235,7 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Показываем уведомления, если они есть
|
|
||||||
<?php if ($success_message): ?>
|
<?php if ($success_message): ?>
|
||||||
showNotification('<?= $messages[$success_message] ?? "Операция выполнена успешно!" ?>', 'success');
|
showNotification('<?= $messages[$success_message] ?? "Операция выполнена успешно!" ?>', 'success');
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
// check_auth.js
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Проверка авторизации при загрузке страницы
|
|
||||||
checkAuthStatus();
|
checkAuthStatus();
|
||||||
|
|
||||||
// Обработка формы входа
|
|
||||||
$('#loginForm').on('submit', function(e) {
|
$('#loginForm').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@@ -22,14 +21,13 @@ $(document).ready(function() {
|
|||||||
try {
|
try {
|
||||||
const result = JSON.parse(response);
|
const result = JSON.parse(response);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// Сохраняем в localStorage если выбрано "Запомнить меня"
|
|
||||||
if (remember) {
|
if (remember) {
|
||||||
localStorage.setItem('rememberedEmail', email);
|
localStorage.setItem('rememberedEmail', email);
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem('rememberedEmail');
|
localStorage.removeItem('rememberedEmail');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Перенаправляем
|
|
||||||
window.location.href = result.redirect || 'catalog.php';
|
window.location.href = result.redirect || 'catalog.php';
|
||||||
} else {
|
} else {
|
||||||
showMessage('error', result.message || 'Ошибка авторизации');
|
showMessage('error', result.message || 'Ошибка авторизации');
|
||||||
@@ -44,7 +42,6 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Проверка статуса авторизации
|
|
||||||
function checkAuthStatus() {
|
function checkAuthStatus() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'check_auth_status.php',
|
url: 'check_auth_status.php',
|
||||||
@@ -62,9 +59,8 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обновление профиля пользователя
|
|
||||||
function updateUserProfile(user) {
|
function updateUserProfile(user) {
|
||||||
// Обновляем шапку, если есть элементы для профиля
|
|
||||||
if ($('#userEmail').length) {
|
if ($('#userEmail').length) {
|
||||||
$('#userEmail').text(user.email);
|
$('#userEmail').text(user.email);
|
||||||
}
|
}
|
||||||
@@ -73,7 +69,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показать сообщение
|
|
||||||
function showMessage(type, text) {
|
function showMessage(type, text) {
|
||||||
const $message = $('#' + type + 'Message');
|
const $message = $('#' + type + 'Message');
|
||||||
if ($message.length) {
|
if ($message.length) {
|
||||||
@@ -84,7 +79,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка авторизации для ссылок
|
|
||||||
function checkAuth(redirectUrl) {
|
function checkAuth(redirectUrl) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'check_auth_status.php',
|
url: 'check_auth_status.php',
|
||||||
@@ -95,7 +89,7 @@ $(document).ready(function() {
|
|||||||
if (result.loggedIn) {
|
if (result.loggedIn) {
|
||||||
window.location.href = redirectUrl;
|
window.location.href = redirectUrl;
|
||||||
} else {
|
} else {
|
||||||
// Показываем модальное окно или перенаправляем на вход
|
|
||||||
showLoginModal(redirectUrl);
|
showLoginModal(redirectUrl);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@@ -106,9 +100,8 @@ $(document).ready(function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показать модальное окно входа
|
|
||||||
function showLoginModal(redirectUrl) {
|
function showLoginModal(redirectUrl) {
|
||||||
// Можно реализовать модальное окно или перенаправить на страницу входа
|
|
||||||
window.location.href = 'вход.php?redirect=' + encodeURIComponent(redirectUrl);
|
window.location.href = 'вход.php?redirect=' + encodeURIComponent(redirectUrl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
// checkout.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
// Проверка авторизации
|
|
||||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||||
header('Location: login.php?error=auth_required');
|
header('Location: login.php?error=auth_required');
|
||||||
exit();
|
exit();
|
||||||
@@ -12,7 +11,6 @@ if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
|||||||
$user_id = $_SESSION['user_id'] ?? 0;
|
$user_id = $_SESSION['user_id'] ?? 0;
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
// Получаем корзину пользователя
|
|
||||||
$cart_items = [];
|
$cart_items = [];
|
||||||
$total_amount = 0;
|
$total_amount = 0;
|
||||||
$total_quantity = 0;
|
$total_quantity = 0;
|
||||||
@@ -35,7 +33,6 @@ try {
|
|||||||
$stmt->execute([$user_id]);
|
$stmt->execute([$user_id]);
|
||||||
$cart_items = $stmt->fetchAll();
|
$cart_items = $stmt->fetchAll();
|
||||||
|
|
||||||
// Рассчитываем общую сумму
|
|
||||||
foreach ($cart_items as $item) {
|
foreach ($cart_items as $item) {
|
||||||
$total_amount += $item['price'] * $item['quantity'];
|
$total_amount += $item['price'] * $item['quantity'];
|
||||||
$total_quantity += $item['quantity'];
|
$total_quantity += $item['quantity'];
|
||||||
@@ -272,11 +269,11 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// Если файла footer.php нет, используем встроенный футер
|
|
||||||
if (file_exists('footer.php')) {
|
if (file_exists('footer.php')) {
|
||||||
include 'footer.php';
|
include 'footer.php';
|
||||||
} else {
|
} else {
|
||||||
// Встроенный футер
|
|
||||||
?>
|
?>
|
||||||
<footer class="footer" id="footer">
|
<footer class="footer" id="footer">
|
||||||
<div class="container footer__content">
|
<div class="container footer__content">
|
||||||
@@ -327,7 +324,7 @@ if (file_exists('footer.php')) {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Обновление количества товаров
|
|
||||||
$('.products__qty-btn').on('click', function(e) {
|
$('.products__qty-btn').on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -343,10 +340,9 @@ $(document).ready(function() {
|
|||||||
} else if (quantity > 1) {
|
} else if (quantity > 1) {
|
||||||
quantity--;
|
quantity--;
|
||||||
} else {
|
} else {
|
||||||
return; // Не уменьшаем ниже 1
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Временно обновляем UI
|
|
||||||
$qtyValue.text(quantity);
|
$qtyValue.text(quantity);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -362,21 +358,20 @@ $(document).ready(function() {
|
|||||||
if (result.success) {
|
if (result.success) {
|
||||||
updateTotals();
|
updateTotals();
|
||||||
} else {
|
} else {
|
||||||
// Откатываем изменения при ошибке
|
|
||||||
$qtyValue.text(isPlus ? quantity - 1 : quantity + 1);
|
$qtyValue.text(isPlus ? quantity - 1 : quantity + 1);
|
||||||
alert('Ошибка: ' + result.message);
|
alert('Ошибка: ' + result.message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
console.error('AJAX ошибка:', status, error);
|
console.error('AJAX ошибка:', status, error);
|
||||||
// Откатываем изменения
|
|
||||||
$qtyValue.text(isPlus ? quantity - 1 : quantity + 1);
|
$qtyValue.text(isPlus ? quantity - 1 : quantity + 1);
|
||||||
alert('Ошибка сервера');
|
alert('Ошибка сервера');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Удаление товара
|
|
||||||
$('.remove-from-cart').on('click', function(e) {
|
$('.remove-from-cart').on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const productId = $(this).data('id');
|
const productId = $(this).data('id');
|
||||||
@@ -400,7 +395,6 @@ $(document).ready(function() {
|
|||||||
$(this).remove();
|
$(this).remove();
|
||||||
updateTotals();
|
updateTotals();
|
||||||
|
|
||||||
// Если корзина пуста, показываем сообщение
|
|
||||||
if ($('#cartItems .products__item').length === 0) {
|
if ($('#cartItems .products__item').length === 0) {
|
||||||
$('#cartItems').html('<div class="empty-cart"><i class="fas fa-shopping-cart" style="font-size: 48px; color: #ccc; margin-bottom: 20px;"></i><p>Ваша корзина пуста</p></div>');
|
$('#cartItems').html('<div class="empty-cart"><i class="fas fa-shopping-cart" style="font-size: 48px; color: #ccc; margin-bottom: 20px;"></i><p>Ваша корзина пуста</p></div>');
|
||||||
$('.order').hide();
|
$('.order').hide();
|
||||||
@@ -417,7 +411,6 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обновление итогов
|
|
||||||
function updateTotals() {
|
function updateTotals() {
|
||||||
let productsTotal = 0;
|
let productsTotal = 0;
|
||||||
let totalCount = 0;
|
let totalCount = 0;
|
||||||
@@ -439,7 +432,6 @@ $(document).ready(function() {
|
|||||||
$('.final-total').text(finalTotal.toLocaleString('ru-RU') + ' ₽');
|
$('.final-total').text(finalTotal.toLocaleString('ru-RU') + ' ₽');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Применение промокода
|
|
||||||
$('#applyPromo').click(function() {
|
$('#applyPromo').click(function() {
|
||||||
const promoCode = $('#promo_code').val().toUpperCase();
|
const promoCode = $('#promo_code').val().toUpperCase();
|
||||||
|
|
||||||
@@ -461,7 +453,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка формы заказа
|
|
||||||
$('#orderForm').submit(function(e) {
|
$('#orderForm').submit(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
// check_auth.js
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Проверка авторизации при загрузке страницы
|
|
||||||
checkAuthStatus();
|
checkAuthStatus();
|
||||||
|
|
||||||
// Обработка формы входа
|
|
||||||
$('#loginForm').on('submit', function(e) {
|
$('#loginForm').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@@ -22,14 +21,13 @@ $(document).ready(function() {
|
|||||||
try {
|
try {
|
||||||
const result = JSON.parse(response);
|
const result = JSON.parse(response);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// Сохраняем в localStorage если выбрано "Запомнить меня"
|
|
||||||
if (remember) {
|
if (remember) {
|
||||||
localStorage.setItem('rememberedEmail', email);
|
localStorage.setItem('rememberedEmail', email);
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem('rememberedEmail');
|
localStorage.removeItem('rememberedEmail');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Перенаправляем
|
|
||||||
window.location.href = result.redirect || 'catalog.php';
|
window.location.href = result.redirect || 'catalog.php';
|
||||||
} else {
|
} else {
|
||||||
showMessage('error', result.message || 'Ошибка авторизации');
|
showMessage('error', result.message || 'Ошибка авторизации');
|
||||||
@@ -44,7 +42,6 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Проверка статуса авторизации
|
|
||||||
function checkAuthStatus() {
|
function checkAuthStatus() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'check_auth_status.php',
|
url: 'check_auth_status.php',
|
||||||
@@ -62,9 +59,8 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обновление профиля пользователя
|
|
||||||
function updateUserProfile(user) {
|
function updateUserProfile(user) {
|
||||||
// Обновляем шапку, если есть элементы для профиля
|
|
||||||
if ($('#userEmail').length) {
|
if ($('#userEmail').length) {
|
||||||
$('#userEmail').text(user.email);
|
$('#userEmail').text(user.email);
|
||||||
}
|
}
|
||||||
@@ -73,7 +69,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показать сообщение
|
|
||||||
function showMessage(type, text) {
|
function showMessage(type, text) {
|
||||||
const $message = $('#' + type + 'Message');
|
const $message = $('#' + type + 'Message');
|
||||||
if ($message.length) {
|
if ($message.length) {
|
||||||
@@ -84,7 +79,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка авторизации для ссылок
|
|
||||||
function checkAuth(redirectUrl) {
|
function checkAuth(redirectUrl) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'check_auth_status.php',
|
url: 'check_auth_status.php',
|
||||||
@@ -95,7 +89,7 @@ $(document).ready(function() {
|
|||||||
if (result.loggedIn) {
|
if (result.loggedIn) {
|
||||||
window.location.href = redirectUrl;
|
window.location.href = redirectUrl;
|
||||||
} else {
|
} else {
|
||||||
// Показываем модальное окно или перенаправляем на вход
|
|
||||||
showLoginModal(redirectUrl);
|
showLoginModal(redirectUrl);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@@ -106,9 +100,8 @@ $(document).ready(function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показать модальное окно входа
|
|
||||||
function showLoginModal(redirectUrl) {
|
function showLoginModal(redirectUrl) {
|
||||||
// Можно реализовать модальное окно или перенаправить на страницу входа
|
|
||||||
window.location.href = 'вход.php?redirect=' + encodeURIComponent(redirectUrl);
|
window.location.href = 'вход.php?redirect=' + encodeURIComponent(redirectUrl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// config/database.php
|
|
||||||
class Database {
|
class Database {
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// В начале файла
|
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -12,7 +12,7 @@ require_once __DIR__ . '/../config/database.php';
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||||
<script src="check_auth.js"></script>
|
<script src="check_auth.js"></script>
|
||||||
<style>
|
<style>
|
||||||
/* Стили для блокировки доступа */
|
|
||||||
.link-disabled {
|
.link-disabled {
|
||||||
cursor: not-allowed !important;
|
cursor: not-allowed !important;
|
||||||
opacity: 0.7 !important;
|
opacity: 0.7 !important;
|
||||||
|
|||||||
@@ -47,4 +47,3 @@
|
|||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Единый header для страниц AETERNA (версия для public/)
|
|
||||||
* Подключение: include 'header_common.php';
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Запускаем сессию если еще не запущена
|
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Определяем текущую страницу
|
|
||||||
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
|
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
|
||||||
|
|
||||||
// Проверяем авторизацию
|
|
||||||
$isLoggedIn = isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
$isLoggedIn = isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
||||||
$isAdmin = isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
$isAdmin = isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
||||||
$userEmail = $_SESSION['user_email'] ?? '';
|
$userEmail = $_SESSION['user_email'] ?? '';
|
||||||
@@ -49,13 +42,12 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
|||||||
|
|
||||||
<div class="header__icons--top">
|
<div class="header__icons--top">
|
||||||
<?php if ($isLoggedIn): ?>
|
<?php if ($isLoggedIn): ?>
|
||||||
<!-- Иконка корзины -->
|
|
||||||
<a href="checkout.php" class="icon cart-icon">
|
<a href="checkout.php" class="icon cart-icon">
|
||||||
<i class="fas fa-shopping-cart"></i>
|
<i class="fas fa-shopping-cart"></i>
|
||||||
<span class="cart-count" id="cartCount">0</span>
|
<span class="cart-count" id="cartCount">0</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<!-- Блок профиля -->
|
|
||||||
<div class="user-profile-dropdown">
|
<div class="user-profile-dropdown">
|
||||||
<div class="user-profile-toggle" id="profileToggle">
|
<div class="user-profile-toggle" id="profileToggle">
|
||||||
<div class="user-avatar"><?= !empty($userEmail) ? strtoupper(substr($userEmail, 0, 1)) : 'U' ?></div>
|
<div class="user-avatar"><?= !empty($userEmail) ? strtoupper(substr($userEmail, 0, 1)) : 'U' ?></div>
|
||||||
@@ -111,7 +103,7 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Стили для профиля пользователя */
|
|
||||||
.user-profile-dropdown { position: relative; display: inline-block; }
|
.user-profile-dropdown { position: relative; display: inline-block; }
|
||||||
.user-profile-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 12px; border-radius: 4px; transition: all 0.3s ease; }
|
.user-profile-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 12px; border-radius: 4px; transition: all 0.3s ease; }
|
||||||
.user-profile-toggle:hover { background-color: rgba(0, 0, 0, 0.05); }
|
.user-profile-toggle:hover { background-color: rgba(0, 0, 0, 0.05); }
|
||||||
@@ -137,7 +129,7 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Профиль пользователя - открытие/закрытие
|
|
||||||
$('#profileToggle').click(function(e) {
|
$('#profileToggle').click(function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
$('#profileMenu').toggle();
|
$('#profileMenu').toggle();
|
||||||
@@ -149,7 +141,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обновление счетчика корзины
|
|
||||||
<?php if ($isLoggedIn): ?>
|
<?php if ($isLoggedIn): ?>
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'api/cart.php?action=count',
|
url: 'api/cart.php?action=count',
|
||||||
@@ -166,4 +157,3 @@ $(document).ready(function() {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для сообщений внизу страницы */
|
|
||||||
.page-messages {
|
.page-messages {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для сообщений внизу страницы */
|
|
||||||
.page-messages {
|
.page-messages {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Функции авторизации для AETERNA
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
/**
|
|
||||||
* Авторизация пользователя
|
|
||||||
*/
|
|
||||||
function loginUser(string $email, string $password): array {
|
function loginUser(string $email, string $password): array {
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
@@ -31,7 +25,6 @@ function loginUser(string $email, string $password): array {
|
|||||||
return ['success' => false, 'message' => 'Неверный пароль'];
|
return ['success' => false, 'message' => 'Неверный пароль'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сохраняем в сессию
|
|
||||||
$_SESSION['user_id'] = $user['user_id'];
|
$_SESSION['user_id'] = $user['user_id'];
|
||||||
$_SESSION['user_email'] = $user['email'];
|
$_SESSION['user_email'] = $user['email'];
|
||||||
$_SESSION['full_name'] = $user['full_name'];
|
$_SESSION['full_name'] = $user['full_name'];
|
||||||
@@ -41,7 +34,6 @@ function loginUser(string $email, string $password): array {
|
|||||||
$_SESSION['isAdmin'] = (bool)$user['is_admin'];
|
$_SESSION['isAdmin'] = (bool)$user['is_admin'];
|
||||||
$_SESSION['login_time'] = time();
|
$_SESSION['login_time'] = time();
|
||||||
|
|
||||||
// Обновляем время последнего входа
|
|
||||||
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
||||||
$updateStmt->execute([$user['user_id']]);
|
$updateStmt->execute([$user['user_id']]);
|
||||||
|
|
||||||
@@ -52,9 +44,6 @@ function loginUser(string $email, string $password): array {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Регистрация нового пользователя
|
|
||||||
*/
|
|
||||||
function registerUser(array $data): array {
|
function registerUser(array $data): array {
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
@@ -64,7 +53,6 @@ function registerUser(array $data): array {
|
|||||||
$phone = trim($data['phone'] ?? '');
|
$phone = trim($data['phone'] ?? '');
|
||||||
$city = trim($data['city'] ?? '');
|
$city = trim($data['city'] ?? '');
|
||||||
|
|
||||||
// Валидация
|
|
||||||
if (empty($email) || empty($password) || empty($fullName)) {
|
if (empty($email) || empty($password) || empty($fullName)) {
|
||||||
return ['success' => false, 'message' => 'Заполните все обязательные поля'];
|
return ['success' => false, 'message' => 'Заполните все обязательные поля'];
|
||||||
}
|
}
|
||||||
@@ -78,7 +66,7 @@ function registerUser(array $data): array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Проверяем существование пользователя
|
|
||||||
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
||||||
$checkStmt->execute([$email]);
|
$checkStmt->execute([$email]);
|
||||||
|
|
||||||
@@ -86,7 +74,6 @@ function registerUser(array $data): array {
|
|||||||
return ['success' => false, 'message' => 'Пользователь с таким email уже существует'];
|
return ['success' => false, 'message' => 'Пользователь с таким email уже существует'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаем пользователя
|
|
||||||
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
|
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
@@ -97,7 +84,6 @@ function registerUser(array $data): array {
|
|||||||
$stmt->execute([$email, $passwordHash, $fullName, $phone, $city]);
|
$stmt->execute([$email, $passwordHash, $fullName, $phone, $city]);
|
||||||
$userId = $stmt->fetchColumn();
|
$userId = $stmt->fetchColumn();
|
||||||
|
|
||||||
// Автоматически авторизуем
|
|
||||||
$_SESSION['user_id'] = $userId;
|
$_SESSION['user_id'] = $userId;
|
||||||
$_SESSION['user_email'] = $email;
|
$_SESSION['user_email'] = $email;
|
||||||
$_SESSION['full_name'] = $fullName;
|
$_SESSION['full_name'] = $fullName;
|
||||||
@@ -114,9 +100,6 @@ function registerUser(array $data): array {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Выход пользователя
|
|
||||||
*/
|
|
||||||
function logoutUser(): void {
|
function logoutUser(): void {
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
|
|
||||||
@@ -131,9 +114,6 @@ function logoutUser(): void {
|
|||||||
session_destroy();
|
session_destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Проверка является ли пользователь администратором
|
|
||||||
*/
|
|
||||||
function checkAdminAccess(): bool {
|
function checkAdminAccess(): bool {
|
||||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||||
return false;
|
return false;
|
||||||
@@ -145,4 +125,3 @@ function checkAdminAccess(): bool {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,4 +47,3 @@
|
|||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Общие функции для AETERNA
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Проверка авторизации пользователя
|
|
||||||
*/
|
|
||||||
function isLoggedIn(): bool {
|
function isLoggedIn(): bool {
|
||||||
return isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
return isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Проверка прав администратора
|
|
||||||
*/
|
|
||||||
function isAdmin(): bool {
|
function isAdmin(): bool {
|
||||||
return isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
return isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Требовать авторизацию - редирект на login если не авторизован
|
|
||||||
*/
|
|
||||||
function requireAuth(string $redirectUrl = 'login.php'): void {
|
function requireAuth(string $redirectUrl = 'login.php'): void {
|
||||||
if (!isLoggedIn()) {
|
if (!isLoggedIn()) {
|
||||||
header('Location: ' . $redirectUrl . '?error=auth_required&redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
header('Location: ' . $redirectUrl . '?error=auth_required&redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
||||||
@@ -27,9 +15,6 @@ function requireAuth(string $redirectUrl = 'login.php'): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Требовать права администратора
|
|
||||||
*/
|
|
||||||
function requireAdmin(string $redirectUrl = 'login.php'): void {
|
function requireAdmin(string $redirectUrl = 'login.php'): void {
|
||||||
if (!isAdmin()) {
|
if (!isAdmin()) {
|
||||||
header('Location: ' . $redirectUrl . '?error=admin_required');
|
header('Location: ' . $redirectUrl . '?error=admin_required');
|
||||||
@@ -37,9 +22,6 @@ function requireAdmin(string $redirectUrl = 'login.php'): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Получить текущего пользователя
|
|
||||||
*/
|
|
||||||
function getCurrentUser(): ?array {
|
function getCurrentUser(): ?array {
|
||||||
if (!isLoggedIn()) {
|
if (!isLoggedIn()) {
|
||||||
return null;
|
return null;
|
||||||
@@ -53,38 +35,23 @@ function getCurrentUser(): ?array {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Форматирование цены
|
|
||||||
*/
|
|
||||||
function formatPrice(float $price): string {
|
function formatPrice(float $price): string {
|
||||||
return number_format($price, 0, '', ' ') . ' ₽';
|
return number_format($price, 0, '', ' ') . ' ₽';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Безопасный вывод HTML
|
|
||||||
*/
|
|
||||||
function e(string $str): string {
|
function e(string $str): string {
|
||||||
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
|
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Генерация номера заказа
|
|
||||||
*/
|
|
||||||
function generateOrderNumber(): string {
|
function generateOrderNumber(): string {
|
||||||
return 'AET-' . date('Ymd') . '-' . strtoupper(substr(uniqid(), -6));
|
return 'AET-' . date('Ymd') . '-' . strtoupper(substr(uniqid(), -6));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Генерация SKU для товара
|
|
||||||
*/
|
|
||||||
function generateSKU(string $productName): string {
|
function generateSKU(string $productName): string {
|
||||||
$prefix = strtoupper(substr(preg_replace('/[^a-zA-Z0-9]/', '', transliterate($productName)), 0, 6));
|
$prefix = strtoupper(substr(preg_replace('/[^a-zA-Z0-9]/', '', transliterate($productName)), 0, 6));
|
||||||
return $prefix . '-' . rand(100, 999);
|
return $prefix . '-' . rand(100, 999);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Транслитерация кириллицы в латиницу
|
|
||||||
*/
|
|
||||||
function transliterate(string $str): string {
|
function transliterate(string $str): string {
|
||||||
$converter = [
|
$converter = [
|
||||||
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
|
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
|
||||||
@@ -105,9 +72,6 @@ function transliterate(string $str): string {
|
|||||||
return strtr($str, $converter);
|
return strtr($str, $converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Создание slug из строки
|
|
||||||
*/
|
|
||||||
function createSlug(string $str): string {
|
function createSlug(string $str): string {
|
||||||
$slug = transliterate($str);
|
$slug = transliterate($str);
|
||||||
$slug = strtolower($slug);
|
$slug = strtolower($slug);
|
||||||
@@ -116,9 +80,6 @@ function createSlug(string $str): string {
|
|||||||
return $slug;
|
return $slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Показать flash-сообщение
|
|
||||||
*/
|
|
||||||
function setFlashMessage(string $type, string $message): void {
|
function setFlashMessage(string $type, string $message): void {
|
||||||
$_SESSION['flash_message'] = [
|
$_SESSION['flash_message'] = [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
@@ -126,9 +87,6 @@ function setFlashMessage(string $type, string $message): void {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Получить и удалить flash-сообщение
|
|
||||||
*/
|
|
||||||
function getFlashMessage(): ?array {
|
function getFlashMessage(): ?array {
|
||||||
if (isset($_SESSION['flash_message'])) {
|
if (isset($_SESSION['flash_message'])) {
|
||||||
$message = $_SESSION['flash_message'];
|
$message = $_SESSION['flash_message'];
|
||||||
@@ -137,4 +95,3 @@ function getFlashMessage(): ?array {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Единый header для всех страниц AETERNA
|
|
||||||
* Подключение: require_once 'includes/header.php';
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Запускаем сессию если еще не запущена
|
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Определяем текущую страницу
|
|
||||||
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
|
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
|
||||||
|
|
||||||
// Проверяем авторизацию
|
|
||||||
$isLoggedIn = isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
$isLoggedIn = isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
||||||
$isAdmin = isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
$isAdmin = isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
||||||
$userEmail = $_SESSION['user_email'] ?? '';
|
$userEmail = $_SESSION['user_email'] ?? '';
|
||||||
@@ -29,7 +22,7 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
|||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||||
<style>
|
<style>
|
||||||
/* Стили для профиля пользователя */
|
|
||||||
.user-profile-dropdown { position: relative; display: inline-block; }
|
.user-profile-dropdown { position: relative; display: inline-block; }
|
||||||
.user-profile-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 12px; border-radius: 4px; transition: all 0.3s ease; }
|
.user-profile-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 12px; border-radius: 4px; transition: all 0.3s ease; }
|
||||||
.user-profile-toggle:hover { background-color: rgba(0, 0, 0, 0.05); }
|
.user-profile-toggle:hover { background-color: rgba(0, 0, 0, 0.05); }
|
||||||
@@ -88,13 +81,12 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
|||||||
|
|
||||||
<div class="header__icons--top">
|
<div class="header__icons--top">
|
||||||
<?php if ($isLoggedIn): ?>
|
<?php if ($isLoggedIn): ?>
|
||||||
<!-- Иконка корзины -->
|
|
||||||
<a href="checkout.php" class="icon cart-icon">
|
<a href="checkout.php" class="icon cart-icon">
|
||||||
<i class="fas fa-shopping-cart"></i>
|
<i class="fas fa-shopping-cart"></i>
|
||||||
<span class="cart-count" id="cartCount">0</span>
|
<span class="cart-count" id="cartCount">0</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<!-- Блок профиля -->
|
|
||||||
<div class="user-profile-dropdown">
|
<div class="user-profile-dropdown">
|
||||||
<div class="user-profile-toggle" id="profileToggle">
|
<div class="user-profile-toggle" id="profileToggle">
|
||||||
<div class="user-avatar"><?= !empty($userEmail) ? strtoupper(substr($userEmail, 0, 1)) : 'U' ?></div>
|
<div class="user-avatar"><?= !empty($userEmail) ? strtoupper(substr($userEmail, 0, 1)) : 'U' ?></div>
|
||||||
@@ -151,7 +143,7 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Профиль пользователя - открытие/закрытие
|
|
||||||
$('#profileToggle').click(function(e) {
|
$('#profileToggle').click(function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
$('#profileMenu').toggle();
|
$('#profileMenu').toggle();
|
||||||
@@ -163,7 +155,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обновление счетчика корзины
|
|
||||||
<?php if ($isLoggedIn): ?>
|
<?php if ($isLoggedIn): ?>
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'api/cart.php?action=count',
|
url: 'api/cart.php?action=count',
|
||||||
@@ -180,4 +171,3 @@ $(document).ready(function() {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
// Упрощенная проверка для каталога
|
|
||||||
if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
||||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||||
// Перенаправляем на вход
|
|
||||||
header('Location: login.php?redirect=' . urlencode('catalog.php'));
|
header('Location: login.php?redirect=' . urlencode('catalog.php'));
|
||||||
exit();
|
exit();
|
||||||
} else {
|
} else {
|
||||||
// Если авторизован - пускаем в каталог
|
|
||||||
header('Location: catalog.php');
|
header('Location: catalog.php');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
@@ -25,7 +24,6 @@ if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
/* Стили для профиля пользователя */
|
|
||||||
.user-profile-dropdown {
|
.user-profile-dropdown {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@@ -223,7 +221,6 @@ if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стиль для заблокированных ссылок */
|
|
||||||
.link-disabled {
|
.link-disabled {
|
||||||
cursor: not-allowed !important;
|
cursor: not-allowed !important;
|
||||||
opacity: 0.6 !important;
|
opacity: 0.6 !important;
|
||||||
@@ -245,7 +242,6 @@ if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
|||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Кнопка каталога с замком */
|
|
||||||
.catalog-locked {
|
.catalog-locked {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
@@ -285,17 +281,14 @@ if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Вставьте этот код в секцию header__icons--top вместо текущего -->
|
|
||||||
<!-- Вставьте этот код в секцию header__icons--top вместо текущего -->
|
|
||||||
<div class="header__icons--top">
|
<div class="header__icons--top">
|
||||||
<?php if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true): ?>
|
<?php if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true): ?>
|
||||||
<!-- Иконка корзины -->
|
|
||||||
<a href="checkout.php" class="icon cart-icon">
|
<a href="checkout.php" class="icon cart-icon">
|
||||||
<i class="fas fa-shopping-cart"></i>
|
<i class="fas fa-shopping-cart"></i>
|
||||||
<span class="cart-count">0</span>
|
<span class="cart-count">0</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<!-- Блок профиля с выпадающим меню -->
|
|
||||||
<div class="user-profile-dropdown">
|
<div class="user-profile-dropdown">
|
||||||
<div class="user-profile-toggle">
|
<div class="user-profile-toggle">
|
||||||
<div class="user-avatar">
|
<div class="user-avatar">
|
||||||
@@ -359,7 +352,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<!-- Если не авторизован -->
|
|
||||||
<a href="/login.php" class="icon">
|
<a href="/login.php" class="icon">
|
||||||
<i class="far fa-user"></i>
|
<i class="far fa-user"></i>
|
||||||
</a>
|
</a>
|
||||||
@@ -609,7 +602,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
|||||||
<p>© 2025 AETERNA. Все права защищены.</p>
|
<p>© 2025 AETERNA. Все права защищены.</p>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<!-- Статус пользователя (будет показан после авторизации) -->
|
|
||||||
<div class="user-status-overlay" id="userStatus" style="display: none; position: fixed; top: 20px; right: 20px; z-index: 1000; background: white; padding: 10px 15px; border-radius: 5px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
|
<div class="user-status-overlay" id="userStatus" style="display: none; position: fixed; top: 20px; right: 20px; z-index: 1000; background: white; padding: 10px 15px; border-radius: 5px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
|
||||||
<div style="display: flex; align-items: center; gap: 10px;">
|
<div style="display: flex; align-items: center; gap: 10px;">
|
||||||
<i class="fas fa-user" id="statusIcon"></i>
|
<i class="fas fa-user" id="statusIcon"></i>
|
||||||
@@ -623,7 +616,6 @@ if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Модальное окно для быстрого входа -->
|
|
||||||
<div class="quick-login-modal" id="quickLoginModal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 2000; align-items: center; justify-content: center;">
|
<div class="quick-login-modal" id="quickLoginModal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 2000; align-items: center; justify-content: center;">
|
||||||
<div style="background: white; padding: 30px; border-radius: 10px; width: 90%; max-width: 400px; text-align: center;">
|
<div style="background: white; padding: 30px; border-radius: 10px; width: 90%; max-width: 400px; text-align: center;">
|
||||||
<h3 style="margin-bottom: 20px; color: #453227;">
|
<h3 style="margin-bottom: 20px; color: #453227;">
|
||||||
@@ -652,16 +644,15 @@ if (isset($_GET['action']) && $_GET['action'] == 'go_to_catalog') {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Проверка авторизации
|
|
||||||
function checkAuth(redirectUrl) {
|
function checkAuth(redirectUrl) {
|
||||||
// Просто перенаправляем на страницу с action
|
|
||||||
window.location.href = 'cite_mebel.php?action=go_to_catalog';
|
window.location.href = 'cite_mebel.php?action=go_to_catalog';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем статус при загрузке
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Синхронизируем PHP сессию с localStorage
|
|
||||||
<?php if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true): ?>
|
<?php if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true): ?>
|
||||||
if (localStorage.getItem('isLoggedIn') !== 'true') {
|
if (localStorage.getItem('isLoggedIn') !== 'true') {
|
||||||
localStorage.setItem('isLoggedIn', 'true');
|
localStorage.setItem('isLoggedIn', 'true');
|
||||||
@@ -670,11 +661,10 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
// Блокируем все ссылки на каталог если не авторизован
|
|
||||||
const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
|
const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
|
||||||
|
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
// Находим ВСЕ ссылки на каталог
|
|
||||||
$('a[href*="catalog"]').each(function() {
|
$('a[href*="catalog"]').each(function() {
|
||||||
const originalHref = $(this).attr('href');
|
const originalHref = $(this).attr('href');
|
||||||
if (originalHref && originalHref.includes('catalog')) {
|
if (originalHref && originalHref.includes('catalog')) {
|
||||||
@@ -687,12 +677,10 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Блокируем поиск
|
|
||||||
$('#searchInput').prop('disabled', true).attr('placeholder', 'Войдите для поиска');
|
$('#searchInput').prop('disabled', true).attr('placeholder', 'Войдите для поиска');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Быстрый вход для тестирования (можно удалить в продакшене)
|
|
||||||
function quickLogin(role) {
|
function quickLogin(role) {
|
||||||
let email, password;
|
let email, password;
|
||||||
|
|
||||||
@@ -715,7 +703,7 @@ function quickLogin(role) {
|
|||||||
try {
|
try {
|
||||||
const result = JSON.parse(response);
|
const result = JSON.parse(response);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// Сохраняем в localStorage
|
|
||||||
localStorage.setItem('isLoggedIn', 'true');
|
localStorage.setItem('isLoggedIn', 'true');
|
||||||
localStorage.setItem('user_email', email);
|
localStorage.setItem('user_email', email);
|
||||||
localStorage.setItem('isAdmin', (role === 'admin').toString());
|
localStorage.setItem('isAdmin', (role === 'admin').toString());
|
||||||
@@ -733,36 +721,32 @@ function quickLogin(role) {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Открытие/закрытие меню профиля
|
|
||||||
$('.user-profile-toggle').click(function(e) {
|
$('.user-profile-toggle').click(function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
$('.user-profile-menu').toggle();
|
$('.user-profile-menu').toggle();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Закрытие меню при клике вне его
|
|
||||||
$(document).click(function() {
|
$(document).click(function() {
|
||||||
$('.user-profile-menu').hide();
|
$('.user-profile-menu').hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обработка выхода
|
|
||||||
$('.logout-link').click(function(e) {
|
$('.logout-link').click(function(e) {
|
||||||
if (!confirm('Вы действительно хотите выйти?')) {
|
if (!confirm('Вы действительно хотите выйти?')) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Обновляем время входа при загрузке страницы
|
|
||||||
updateLoginTime();
|
updateLoginTime();
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateLoginTime() {
|
function updateLoginTime() {
|
||||||
// Можно добавить AJAX запрос для обновления времени последнего входа
|
|
||||||
// или использовать время из сессии
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<?php if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true): ?>
|
<?php if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true): ?>
|
||||||
<!-- Кнопки быстрого тестирования (только для неавторизованных) -->
|
|
||||||
<div style="position: fixed; bottom: 20px; right: 20px; z-index: 1000; background: white; padding: 10px; border-radius: 5px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
|
<div style="position: fixed; bottom: 20px; right: 20px; z-index: 1000; background: white; padding: 10px; border-radius: 5px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
|
||||||
<h4 style="margin: 0 0 10px 0; font-size: 14px; color: #453227;">Быстрый вход:</h4>
|
<h4 style="margin: 0 0 10px 0; font-size: 14px; color: #453227;">Быстрый вход:</h4>
|
||||||
<button onclick="window.location.href='login.php'" style="background: #453227; color: white; border: none; padding: 8px 15px; border-radius: 4px; cursor: pointer; margin: 5px; width: 100%;">
|
<button onclick="window.location.href='login.php'" style="background: #453227; color: white; border: none; padding: 8px 15px; border-radius: 4px; cursor: pointer; margin: 5px; width: 100%;">
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ session_start();
|
|||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||||
<style>
|
<style>
|
||||||
/* Добавляем стили для статуса пользователя */
|
|
||||||
.user-status {
|
.user-status {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
@@ -48,7 +48,7 @@ session_start();
|
|||||||
</style>
|
</style>
|
||||||
<script src="check_auth.js"></script>
|
<script src="check_auth.js"></script>
|
||||||
<style>
|
<style>
|
||||||
/* Стили для блокировки доступа */
|
|
||||||
.link-disabled {
|
.link-disabled {
|
||||||
cursor: not-allowed !important;
|
cursor: not-allowed !important;
|
||||||
opacity: 0.7 !important;
|
opacity: 0.7 !important;
|
||||||
@@ -69,7 +69,7 @@ session_start();
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- Статус пользователя -->
|
|
||||||
<div class="user-status" id="userStatus" style="display: none;">
|
<div class="user-status" id="userStatus" style="display: none;">
|
||||||
<i class="fas fa-user status-icon" id="statusIcon"></i>
|
<i class="fas fa-user status-icon" id="statusIcon"></i>
|
||||||
<div>
|
<div>
|
||||||
@@ -189,7 +189,6 @@ session_start();
|
|||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<!-- Блок для системных сообщений -->
|
|
||||||
<div class="page-messages">
|
<div class="page-messages">
|
||||||
<div class="message error" id="errorMessage"></div>
|
<div class="message error" id="errorMessage"></div>
|
||||||
<div class="message success" id="successMessage"></div>
|
<div class="message success" id="successMessage"></div>
|
||||||
@@ -246,29 +245,25 @@ session_start();
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Проверяем редирект после входа
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const redirectUrl = urlParams.get('redirect');
|
const redirectUrl = urlParams.get('redirect');
|
||||||
|
|
||||||
// Если есть редирект - сохраняем его
|
|
||||||
if (redirectUrl) {
|
if (redirectUrl) {
|
||||||
sessionStorage.setItem('redirectAfterLogin', redirectUrl);
|
sessionStorage.setItem('redirectAfterLogin', redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обработка формы входа
|
|
||||||
$('#loginForm').on('submit', function(e) {
|
$('#loginForm').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const email = $('#login-email').val();
|
const email = $('#login-email').val();
|
||||||
const password = $('#login-password').val();
|
const password = $('#login-password').val();
|
||||||
|
|
||||||
// Валидация на клиенте
|
|
||||||
if (!email || !password) {
|
if (!email || !password) {
|
||||||
alert('Заполните все поля');
|
alert('Заполните все поля');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Отправляем данные на сервер для PHP сессии
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'api/auth.php',
|
url: 'api/auth.php',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -279,7 +274,7 @@ session_start();
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// Редирект на сохраненный URL или каталог
|
|
||||||
const savedRedirect = sessionStorage.getItem('redirectAfterLogin') || 'catalog.php';
|
const savedRedirect = sessionStorage.getItem('redirectAfterLogin') || 'catalog.php';
|
||||||
sessionStorage.removeItem('redirectAfterLogin');
|
sessionStorage.removeItem('redirectAfterLogin');
|
||||||
window.location.href = savedRedirect;
|
window.location.href = savedRedirect;
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
// Очищаем все данные сессии
|
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
|
|
||||||
// Удаляем cookie сессии
|
|
||||||
if (ini_get("session.use_cookies")) {
|
if (ini_get("session.use_cookies")) {
|
||||||
$params = session_get_cookie_params();
|
$params = session_get_cookie_params();
|
||||||
setcookie(session_name(), '', time() - 42000,
|
setcookie(session_name(), '', time() - 42000,
|
||||||
@@ -13,10 +11,7 @@ if (ini_get("session.use_cookies")) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Уничтожаем сессию
|
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
|
||||||
// Очищаем localStorage через JS
|
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
// product_page.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
// Проверка авторизации
|
|
||||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||||
header('Location: login.php?error=auth_required&redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
header('Location: login.php?error=auth_required&redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
||||||
exit();
|
exit();
|
||||||
@@ -19,7 +18,7 @@ $product_id = intval($_GET['id']);
|
|||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Получаем информацию о товаре
|
|
||||||
$productStmt = $db->prepare("
|
$productStmt = $db->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
p.*,
|
p.*,
|
||||||
@@ -37,7 +36,6 @@ try {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получаем похожие товары
|
|
||||||
$similarStmt = $db->prepare("
|
$similarStmt = $db->prepare("
|
||||||
SELECT * FROM products
|
SELECT * FROM products
|
||||||
WHERE category_id = ?
|
WHERE category_id = ?
|
||||||
@@ -49,7 +47,6 @@ try {
|
|||||||
$similarStmt->execute([$product['category_id'], $product_id]);
|
$similarStmt->execute([$product['category_id'], $product_id]);
|
||||||
$similarProducts = $similarStmt->fetchAll();
|
$similarProducts = $similarStmt->fetchAll();
|
||||||
|
|
||||||
// Получаем отзывы (если есть отдельная таблица reviews)
|
|
||||||
$reviewsStmt = $db->prepare("
|
$reviewsStmt = $db->prepare("
|
||||||
SELECT rating, comment, created_at
|
SELECT rating, comment, created_at
|
||||||
FROM reviews
|
FROM reviews
|
||||||
@@ -64,7 +61,6 @@ try {
|
|||||||
die("Ошибка базы данных: " . $e->getMessage());
|
die("Ошибка базы данных: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTML код страницы товара
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="ru">
|
<html lang="ru">
|
||||||
@@ -389,7 +385,7 @@ try {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Управление количеством
|
|
||||||
$('.product__qty-btn.plus').click(function() {
|
$('.product__qty-btn.plus').click(function() {
|
||||||
const $input = $('.product__qty-value');
|
const $input = $('.product__qty-value');
|
||||||
let value = parseInt($input.val());
|
let value = parseInt($input.val());
|
||||||
@@ -407,7 +403,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Добавление в корзину
|
|
||||||
window.addToCart = function(productId) {
|
window.addToCart = function(productId) {
|
||||||
const quantity = $('.product__qty-value').val();
|
const quantity = $('.product__qty-value').val();
|
||||||
|
|
||||||
@@ -423,7 +418,7 @@ $(document).ready(function() {
|
|||||||
const result = JSON.parse(response);
|
const result = JSON.parse(response);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
alert('Товар добавлен в корзину!');
|
alert('Товар добавлен в корзину!');
|
||||||
// Обновляем счетчик в шапке
|
|
||||||
$('.cart-count').text(result.cart_count);
|
$('.cart-count').text(result.cart_count);
|
||||||
} else {
|
} else {
|
||||||
alert('Ошибка: ' + result.message);
|
alert('Ошибка: ' + result.message);
|
||||||
@@ -435,7 +430,6 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Покупка сейчас
|
|
||||||
window.buyNow = function(productId) {
|
window.buyNow = function(productId) {
|
||||||
const quantity = $('.product__qty-value').val();
|
const quantity = $('.product__qty-value').val();
|
||||||
|
|
||||||
@@ -452,7 +446,6 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Уведомление о поступлении
|
|
||||||
window.notifyWhenAvailable = function(productId) {
|
window.notifyWhenAvailable = function(productId) {
|
||||||
const email = prompt('Введите ваш email для уведомления:');
|
const email = prompt('Введите ваш email для уведомления:');
|
||||||
if (email) {
|
if (email) {
|
||||||
@@ -470,7 +463,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Удаление товара (админ)
|
|
||||||
window.deleteProduct = function(productId) {
|
window.deleteProduct = function(productId) {
|
||||||
if (confirm('Вы уверены, что хотите удалить этот товар?')) {
|
if (confirm('Вы уверены, что хотите удалить этот товар?')) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|||||||
@@ -31,23 +31,19 @@ if (isset($_GET['quick_login'])) {
|
|||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
|
|
||||||
// Проверяем, если пользователь уже авторизован - перенаправляем
|
|
||||||
if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true) {
|
if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true) {
|
||||||
header('Location: catalog.php');
|
header('Location: catalog.php');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получаем сообщения из сессии
|
|
||||||
$registration_errors = $_SESSION['registration_errors'] ?? [];
|
$registration_errors = $_SESSION['registration_errors'] ?? [];
|
||||||
$old_data = $_SESSION['old_data'] ?? [];
|
$old_data = $_SESSION['old_data'] ?? [];
|
||||||
$registration_success = $_SESSION['registration_success'] ?? '';
|
$registration_success = $_SESSION['registration_success'] ?? '';
|
||||||
|
|
||||||
// Очищаем сессию от сообщений
|
|
||||||
unset($_SESSION['registration_errors']);
|
unset($_SESSION['registration_errors']);
|
||||||
unset($_SESSION['old_data']);
|
unset($_SESSION['old_data']);
|
||||||
unset($_SESSION['registration_success']);
|
unset($_SESSION['registration_success']);
|
||||||
|
|
||||||
// Обработка быстрой регистрации (для тестирования)
|
|
||||||
if (isset($_GET['quick_register'])) {
|
if (isset($_GET['quick_register'])) {
|
||||||
$email = $_GET['quick_register'] == 'admin' ? 'admin@aeterna.ru' : 'test@user.com';
|
$email = $_GET['quick_register'] == 'admin' ? 'admin@aeterna.ru' : 'test@user.com';
|
||||||
$password = $_GET['quick_register'] == 'admin' ? 'admin123' : 'user123';
|
$password = $_GET['quick_register'] == 'admin' ? 'admin123' : 'user123';
|
||||||
@@ -58,12 +54,12 @@ if (isset($_GET['quick_register'])) {
|
|||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getInstance()->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Проверяем, существует ли пользователь
|
|
||||||
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
||||||
$checkStmt->execute([$email]);
|
$checkStmt->execute([$email]);
|
||||||
|
|
||||||
if (!$checkStmt->fetch()) {
|
if (!$checkStmt->fetch()) {
|
||||||
// Создаем пользователя
|
|
||||||
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||||||
$is_admin = ($_GET['quick_register'] == 'admin');
|
$is_admin = ($_GET['quick_register'] == 'admin');
|
||||||
|
|
||||||
@@ -76,7 +72,7 @@ if (isset($_GET['quick_register'])) {
|
|||||||
$stmt->execute([$email, $password_hash, $full_name, $phone, $city, $is_admin]);
|
$stmt->execute([$email, $password_hash, $full_name, $phone, $city, $is_admin]);
|
||||||
$user_id = $stmt->fetchColumn();
|
$user_id = $stmt->fetchColumn();
|
||||||
} else {
|
} else {
|
||||||
// Получаем существующего пользователя
|
|
||||||
$stmt = $db->prepare("SELECT user_id, is_admin FROM users WHERE email = ?");
|
$stmt = $db->prepare("SELECT user_id, is_admin FROM users WHERE email = ?");
|
||||||
$stmt->execute([$email]);
|
$stmt->execute([$email]);
|
||||||
$user = $stmt->fetch();
|
$user = $stmt->fetch();
|
||||||
@@ -84,7 +80,6 @@ if (isset($_GET['quick_register'])) {
|
|||||||
$is_admin = $user['is_admin'];
|
$is_admin = $user['is_admin'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Авторизуем
|
|
||||||
$_SESSION['user_id'] = $user_id;
|
$_SESSION['user_id'] = $user_id;
|
||||||
$_SESSION['user_email'] = $email;
|
$_SESSION['user_email'] = $email;
|
||||||
$_SESSION['full_name'] = $full_name;
|
$_SESSION['full_name'] = $full_name;
|
||||||
@@ -370,7 +365,6 @@ if (isset($_GET['quick_register'])) {
|
|||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<!-- Блок для системных сообщений -->
|
|
||||||
<div class="page-messages">
|
<div class="page-messages">
|
||||||
<div class="message error" id="errorMessage" style="display: none;"></div>
|
<div class="message error" id="errorMessage" style="display: none;"></div>
|
||||||
<div class="message success" id="successMessage" style="display: none;"></div>
|
<div class="message success" id="successMessage" style="display: none;"></div>
|
||||||
@@ -425,7 +419,6 @@ if (isset($_GET['quick_register'])) {
|
|||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<!-- Кнопки для быстрой регистрации (тестирование) -->
|
|
||||||
<div class="quick-register-buttons">
|
<div class="quick-register-buttons">
|
||||||
<button class="quick-btn admin" onclick="window.location.href='?quick_register=admin'">
|
<button class="quick-btn admin" onclick="window.location.href='?quick_register=admin'">
|
||||||
<i class="fas fa-user-shield"></i> Quick Admin
|
<i class="fas fa-user-shield"></i> Quick Admin
|
||||||
@@ -437,7 +430,7 @@ if (isset($_GET['quick_register'])) {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Функции для отображения сообщений
|
|
||||||
function showMessage(type, text) {
|
function showMessage(type, text) {
|
||||||
const messageId = type + 'Message';
|
const messageId = type + 'Message';
|
||||||
const $message = $('#' + messageId);
|
const $message = $('#' + messageId);
|
||||||
@@ -447,29 +440,24 @@ $(document).ready(function() {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка, является ли email администратора
|
|
||||||
function isAdminEmail(email) {
|
function isAdminEmail(email) {
|
||||||
const adminEmails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
const adminEmails = ['admin@aeterna.ru', 'administrator@aeterna.ru', 'aeterna@mail.ru'];
|
||||||
return adminEmails.includes(email.toLowerCase());
|
return adminEmails.includes(email.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация ФИО (без цифр, минимум 2 слова)
|
|
||||||
function validateFIO(fio) {
|
function validateFIO(fio) {
|
||||||
const words = fio.trim().split(/\s+/);
|
const words = fio.trim().split(/\s+/);
|
||||||
const hasNoDigits = !/\d/.test(fio);
|
const hasNoDigits = !/\d/.test(fio);
|
||||||
return words.length >= 2 && words.every(word => word.length >= 2) && hasNoDigits;
|
return words.length >= 2 && words.every(word => word.length >= 2) && hasNoDigits;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация города
|
|
||||||
function validateCity(city) {
|
function validateCity(city) {
|
||||||
return city.trim().length >= 2 && /^[а-яА-ЯёЁ\s-]+$/.test(city);
|
return city.trim().length >= 2 && /^[а-яА-ЯёЁ\s-]+$/.test(city);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация email
|
|
||||||
function validateEmail(email) {
|
function validateEmail(email) {
|
||||||
const localPart = email.split('@')[0];
|
const localPart = email.split('@')[0];
|
||||||
|
|
||||||
// Проверка на кириллические символы перед @
|
|
||||||
if (/[а-яА-ЯёЁ]/.test(localPart)) {
|
if (/[а-яА-ЯёЁ]/.test(localPart)) {
|
||||||
showError('email', 'В тексте перед знаком "@" не должно быть кириллических символов');
|
showError('email', 'В тексте перед знаком "@" не должно быть кириллических символов');
|
||||||
return false;
|
return false;
|
||||||
@@ -485,17 +473,14 @@ $(document).ready(function() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация телефона
|
|
||||||
function validatePhone(phone) {
|
function validatePhone(phone) {
|
||||||
// Очищаем от всех символов кроме цифр
|
|
||||||
const cleanPhone = phone.replace(/\D/g, '');
|
const cleanPhone = phone.replace(/\D/g, '');
|
||||||
|
|
||||||
// Проверяем российский формат
|
|
||||||
if (cleanPhone.length === 11 && (cleanPhone.startsWith('7') || cleanPhone.startsWith('8'))) {
|
if (cleanPhone.length === 11 && (cleanPhone.startsWith('7') || cleanPhone.startsWith('8'))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем международный формат
|
|
||||||
if (cleanPhone.length === 12 && cleanPhone.startsWith('7')) {
|
if (cleanPhone.length === 12 && cleanPhone.startsWith('7')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -503,12 +488,10 @@ $(document).ready(function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация пароля
|
|
||||||
function validatePassword(password) {
|
function validatePassword(password) {
|
||||||
return password.length >= 6;
|
return password.length >= 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Показать/скрыть ошибку
|
|
||||||
function showError(fieldId, message) {
|
function showError(fieldId, message) {
|
||||||
$('#' + fieldId).addClass('error');
|
$('#' + fieldId).addClass('error');
|
||||||
$('#' + fieldId + '-error').text(message).show();
|
$('#' + fieldId + '-error').text(message).show();
|
||||||
@@ -519,7 +502,6 @@ $(document).ready(function() {
|
|||||||
$('#' + fieldId + '-error').hide();
|
$('#' + fieldId + '-error').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Реальная валидация при вводе
|
|
||||||
$('input').on('blur', function() {
|
$('input').on('blur', function() {
|
||||||
const fieldId = $(this).attr('id');
|
const fieldId = $(this).attr('id');
|
||||||
const value = $(this).val();
|
const value = $(this).val();
|
||||||
@@ -575,17 +557,14 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Очистка ошибки при фокусе
|
|
||||||
$('input').on('focus', function() {
|
$('input').on('focus', function() {
|
||||||
const fieldId = $(this).attr('id');
|
const fieldId = $(this).attr('id');
|
||||||
hideError(fieldId);
|
hideError(fieldId);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Валидация всей формы
|
|
||||||
function validateForm() {
|
function validateForm() {
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
|
|
||||||
// Валидация ФИО
|
|
||||||
const fio = $('#fio').val();
|
const fio = $('#fio').val();
|
||||||
if (!validateFIO(fio)) {
|
if (!validateFIO(fio)) {
|
||||||
if (/\d/.test(fio)) {
|
if (/\d/.test(fio)) {
|
||||||
@@ -598,7 +577,6 @@ $(document).ready(function() {
|
|||||||
hideError('fio');
|
hideError('fio');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация города
|
|
||||||
const city = $('#city').val();
|
const city = $('#city').val();
|
||||||
if (!validateCity(city)) {
|
if (!validateCity(city)) {
|
||||||
showError('city', 'Укажите корректное название города (только русские буквы)');
|
showError('city', 'Укажите корректное название города (только русские буквы)');
|
||||||
@@ -607,7 +585,6 @@ $(document).ready(function() {
|
|||||||
hideError('city');
|
hideError('city');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация email
|
|
||||||
const email = $('#email').val();
|
const email = $('#email').val();
|
||||||
if (!validateEmail(email)) {
|
if (!validateEmail(email)) {
|
||||||
showError('email', 'Введите корректный email адрес');
|
showError('email', 'Введите корректный email адрес');
|
||||||
@@ -616,7 +593,6 @@ $(document).ready(function() {
|
|||||||
hideError('email');
|
hideError('email');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация телефона
|
|
||||||
const phone = $('#phone').val();
|
const phone = $('#phone').val();
|
||||||
if (!validatePhone(phone)) {
|
if (!validatePhone(phone)) {
|
||||||
showError('phone', 'Введите номер в формате: +7(912)999-12-23');
|
showError('phone', 'Введите номер в формате: +7(912)999-12-23');
|
||||||
@@ -625,7 +601,6 @@ $(document).ready(function() {
|
|||||||
hideError('phone');
|
hideError('phone');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Валидация пароля
|
|
||||||
const password = $('#password').val();
|
const password = $('#password').val();
|
||||||
if (!validatePassword(password)) {
|
if (!validatePassword(password)) {
|
||||||
showError('password', 'Пароль должен содержать минимум 6 символов');
|
showError('password', 'Пароль должен содержать минимум 6 символов');
|
||||||
@@ -634,7 +609,6 @@ $(document).ready(function() {
|
|||||||
hideError('password');
|
hideError('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка совпадения паролей
|
|
||||||
const confirmPassword = $('#confirm-password').val();
|
const confirmPassword = $('#confirm-password').val();
|
||||||
if (password !== confirmPassword) {
|
if (password !== confirmPassword) {
|
||||||
showError('confirm-password', 'Пароли не совпадают');
|
showError('confirm-password', 'Пароли не совпадают');
|
||||||
@@ -643,7 +617,6 @@ $(document).ready(function() {
|
|||||||
hideError('confirm-password');
|
hideError('confirm-password');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка согласия с условиями
|
|
||||||
if (!$('#privacy').is(':checked')) {
|
if (!$('#privacy').is(':checked')) {
|
||||||
$('#privacy-error').show();
|
$('#privacy-error').show();
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -654,26 +627,23 @@ $(document).ready(function() {
|
|||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обработка отправки формы
|
|
||||||
$('#registrationForm').on('submit', function(e) {
|
$('#registrationForm').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (validateForm()) {
|
if (validateForm()) {
|
||||||
// Показываем загрузку
|
|
||||||
$('#submitBtn').prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> Регистрация...');
|
$('#submitBtn').prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> Регистрация...');
|
||||||
|
|
||||||
// Отправляем форму
|
|
||||||
this.submit();
|
this.submit();
|
||||||
} else {
|
} else {
|
||||||
showMessage('error', 'Пожалуйста, исправьте ошибки в форме');
|
showMessage('error', 'Пожалуйста, исправьте ошибки в форме');
|
||||||
// Прокручиваем к первой ошибке
|
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $('.error').first().offset().top - 100
|
scrollTop: $('.error').first().offset().top - 100
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Маска для телефона
|
|
||||||
$('#phone').on('input', function() {
|
$('#phone').on('input', function() {
|
||||||
let value = $(this).val().replace(/\D/g, '');
|
let value = $(this).val().replace(/\D/g, '');
|
||||||
|
|
||||||
@@ -686,7 +656,6 @@ $(document).ready(function() {
|
|||||||
value = '7' + value.substring(1);
|
value = '7' + value.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Форматируем номер
|
|
||||||
let formatted = '+7';
|
let formatted = '+7';
|
||||||
if (value.length > 1) formatted += ' (' + value.substring(1, 4);
|
if (value.length > 1) formatted += ' (' + value.substring(1, 4);
|
||||||
if (value.length > 4) formatted += ') ' + value.substring(4, 7);
|
if (value.length > 4) formatted += ') ' + value.substring(4, 7);
|
||||||
@@ -697,21 +666,19 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Запрет ввода цифр в поле ФИО
|
|
||||||
$('#fio').on('input', function() {
|
$('#fio').on('input', function() {
|
||||||
let value = $(this).val();
|
let value = $(this).val();
|
||||||
// Удаляем цифры из значения
|
|
||||||
value = value.replace(/\d/g, '');
|
value = value.replace(/\d/g, '');
|
||||||
$(this).val(value);
|
$(this).val(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Проверка авторизации для ссылок
|
|
||||||
function checkAuth(redirectUrl) {
|
function checkAuth(redirectUrl) {
|
||||||
<?php if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true): ?>
|
<?php if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true): ?>
|
||||||
window.location.href = redirectUrl;
|
window.location.href = redirectUrl;
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
showMessage('warning', 'Требуется авторизация. Зарегистрируйтесь или войдите в систему.');
|
showMessage('warning', 'Требуется авторизация. Зарегистрируйтесь или войдите в систему.');
|
||||||
// Перенаправляем на страницу входа
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = 'login.php?redirect=' + encodeURIComponent(redirectUrl);
|
window.location.href = 'login.php?redirect=' + encodeURIComponent(redirectUrl);
|
||||||
}, 1500);
|
}, 1500);
|
||||||
@@ -719,10 +686,9 @@ $(document).ready(function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Удаление кириллических символов из email
|
|
||||||
$('#email').on('input', function() {
|
$('#email').on('input', function() {
|
||||||
let value = $(this).val();
|
let value = $(this).val();
|
||||||
// Если есть кириллические символы до @, заменяем их
|
|
||||||
const atIndex = value.indexOf('@');
|
const atIndex = value.indexOf('@');
|
||||||
if (atIndex > -1) {
|
if (atIndex > -1) {
|
||||||
const localPart = value.substring(0, atIndex);
|
const localPart = value.substring(0, atIndex);
|
||||||
@@ -732,7 +698,6 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Показываем тестовые данные для демонстрации
|
|
||||||
function fillTestData(isAdmin = false) {
|
function fillTestData(isAdmin = false) {
|
||||||
if (isAdmin) {
|
if (isAdmin) {
|
||||||
$('#fio').val('Администратор Системы');
|
$('#fio').val('Администратор Системы');
|
||||||
@@ -753,21 +718,19 @@ $(document).ready(function() {
|
|||||||
showMessage('success', 'Тестовые данные заполнены. Теперь можно нажать "Зарегистрироваться"');
|
showMessage('success', 'Тестовые данные заполнены. Теперь можно нажать "Зарегистрироваться"');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Добавляем кнопки для заполнения тестовых данных
|
|
||||||
$(document).on('keydown', function(e) {
|
$(document).on('keydown', function(e) {
|
||||||
// Alt+A - заполнить данные администратора
|
|
||||||
if (e.altKey && e.key === 'a') {
|
if (e.altKey && e.key === 'a') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
fillTestData(true);
|
fillTestData(true);
|
||||||
}
|
}
|
||||||
// Alt+U - заполнить данные пользователя
|
|
||||||
if (e.altKey && e.key === 'u') {
|
if (e.altKey && e.key === 'u') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
fillTestData(false);
|
fillTestData(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Информация о горячих клавишах
|
|
||||||
console.log('Горячие клавиши для тестирования:');
|
console.log('Горячие клавиши для тестирования:');
|
||||||
console.log('Alt+A - заполнить данные администратора');
|
console.log('Alt+A - заполнить данные администратора');
|
||||||
console.log('Alt+U - заполнить данные пользователя');
|
console.log('Alt+U - заполнить данные пользователя');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// В начале файла
|
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -13,7 +13,7 @@ require_once __DIR__ . '/../config/database.php';
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||||
<script src="check_auth.js"></script>
|
<script src="check_auth.js"></script>
|
||||||
<style>
|
<style>
|
||||||
/* Стили для блокировки доступа */
|
|
||||||
.link-disabled {
|
.link-disabled {
|
||||||
cursor: not-allowed !important;
|
cursor: not-allowed !important;
|
||||||
opacity: 0.7 !important;
|
opacity: 0.7 !important;
|
||||||
@@ -37,7 +37,6 @@ require_once __DIR__ . '/../config/database.php';
|
|||||||
<body>
|
<body>
|
||||||
<?php include 'header_common.php'; ?>
|
<?php include 'header_common.php'; ?>
|
||||||
|
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<section class="services-section">
|
<section class="services-section">
|
||||||
<div class="container services__wrapper">
|
<div class="container services__wrapper">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// В начале файла
|
|
||||||
require_once __DIR__ . '/../config/database.php';
|
require_once __DIR__ . '/../config/database.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -12,7 +12,7 @@ require_once __DIR__ . '/../config/database.php';
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||||
<script src="check_auth.js"></script>
|
<script src="check_auth.js"></script>
|
||||||
<style>
|
<style>
|
||||||
/* Стили для блокировки доступа */
|
|
||||||
.link-disabled {
|
.link-disabled {
|
||||||
cursor: not-allowed !important;
|
cursor: not-allowed !important;
|
||||||
opacity: 0.7 !important;
|
opacity: 0.7 !important;
|
||||||
@@ -37,7 +37,6 @@ require_once __DIR__ . '/../config/database.php';
|
|||||||
<body>
|
<body>
|
||||||
<?php include 'header_common.php'; ?>
|
<?php include 'header_common.php'; ?>
|
||||||
|
|
||||||
|
|
||||||
<main class="catalog-main">
|
<main class="catalog-main">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="breadcrumbs">
|
<div class="breadcrumbs">
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для сообщений внизу страницы */
|
|
||||||
.page-messages {
|
.page-messages {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
@@ -60,7 +59,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Дополнительные стили для формы регистрации */
|
|
||||||
.input-group {
|
.input-group {
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
@@ -89,13 +87,11 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Исправление отступов для страницы регистрации */
|
|
||||||
.profile-page-main {
|
.profile-page-main {
|
||||||
padding: 40px 0;
|
padding: 40px 0;
|
||||||
min-height: calc(100vh - 200px);
|
min-height: calc(100vh - 200px);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Убедимся, что контейнер не перекрывает шапку и футер */
|
|
||||||
.profile-container {
|
.profile-container {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -108,7 +104,6 @@
|
|||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для страницы входа */
|
|
||||||
.form-options {
|
.form-options {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для сообщений внизу страницы */
|
|
||||||
.page-messages {
|
.page-messages {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
@@ -60,7 +59,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Дополнительные стили для формы регистрации */
|
|
||||||
.input-group {
|
.input-group {
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
@@ -89,13 +87,11 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Исправление отступов для страницы регистрации */
|
|
||||||
.profile-page-main {
|
.profile-page-main {
|
||||||
padding: 40px 0;
|
padding: 40px 0;
|
||||||
min-height: calc(100vh - 200px);
|
min-height: calc(100vh - 200px);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Убедимся, что контейнер не перекрывает шапку и футер */
|
|
||||||
.profile-container {
|
.profile-container {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -108,7 +104,6 @@
|
|||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Стили для страницы входа */
|
|
||||||
.form-options {
|
.form-options {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|||||||
Reference in New Issue
Block a user