���� JFIF �� � ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /proc/self/root/var/www/html/tien-dien/code/admin/product/ |
<?php global $DB, $print; // Check if tables already exist $check_product = $DB->query("SHOW TABLES LIKE 'tb_product'"); $product_exists = $DB->get_num_rows() > 0; $check_categories = $DB->query("SHOW TABLES LIKE 'tb_product_categories'"); $categories_exists = $DB->get_num_rows() > 0; $check_category = $DB->query("SHOW TABLES LIKE 'tb_product_category'"); $category_exists = $DB->get_num_rows() > 0; $messages = []; // Create product table if it doesn't exist if (!$product_exists) { $sql_product = "CREATE TABLE `tb_product` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `ftitle` varchar(255) NOT NULL, `etitle` varchar(255) DEFAULT NULL, `intro` text DEFAULT NULL, `eintro` text DEFAULT NULL, `body` text DEFAULT NULL, `ebody` text DEFAULT NULL, `specification` text DEFAULT NULL, `especification` text DEFAULT NULL, `price` float NOT NULL DEFAULT 0, `old_price` float DEFAULT 0, `quantity` int(11) NOT NULL DEFAULT 0, `path_img` varchar(255) DEFAULT NULL, `img` varchar(255) DEFAULT NULL, `tags` varchar(255) DEFAULT NULL, `time` int(11) NOT NULL, `pos` int(11) NOT NULL DEFAULT 0, `status` tinyint(1) NOT NULL DEFAULT 0, `noibat` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;"; $result = $DB->query($sql_product); if ($result) { $messages[] = "Đã tạo bảng tb_product thành công."; } else { $messages[] = "Lỗi khi tạo bảng tb_product: " . $DB->error(); } } // Create product categories table if it doesn't exist if (!$categories_exists) { $sql_categories = "CREATE TABLE `tb_product_categories` ( `category_id` int(11) NOT NULL AUTO_INCREMENT, `category_name` varchar(255) NOT NULL, `category_ename` varchar(255) DEFAULT NULL, `category_parentid` int(11) NOT NULL DEFAULT 0, `category_pos` int(11) NOT NULL DEFAULT 0, `category_status` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`category_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;"; $result = $DB->query($sql_categories); if ($result) { $messages[] = "Đã tạo bảng tb_product_categories thành công."; // Add default category $DB->query("INSERT INTO `tb_product_categories` (`category_name`, `category_ename`, `category_parentid`, `category_pos`, `category_status`) VALUES ('Sản phẩm mặc định', 'Default Products', 0, 0, 0);"); } else { $messages[] = "Lỗi khi tạo bảng tb_product_categories: " . $DB->error(); } } // Create product-category relationship table if it doesn't exist if (!$category_exists) { $sql_category = "CREATE TABLE `tb_product_category` ( `id` int(11) NOT NULL AUTO_INCREMENT, `product_id` int(11) NOT NULL, `category_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `product_id` (`product_id`), KEY `category_id` (`category_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;"; $result = $DB->query($sql_category); if ($result) { $messages[] = "Đã tạo bảng tb_product_category thành công."; } else { $messages[] = "Lỗi khi tạo bảng tb_product_category: " . $DB->error(); } } // Check if product attributes tables exist $check_attributes = $DB->query("SHOW TABLES LIKE 'tb_product_attributes'"); $attributes_exists = $DB->get_num_rows() > 0; $check_attribute_values = $DB->query("SHOW TABLES LIKE 'tb_product_attribute_values'"); $attribute_values_exists = $DB->get_num_rows() > 0; $check_product_attributes = $DB->query("SHOW TABLES LIKE 'tb_product_attribute_mapping'"); $product_attributes_exists = $DB->get_num_rows() > 0; // Create product attributes table if it doesn't exist if (!$attributes_exists) { $sql_attributes = "CREATE TABLE `tb_product_attributes` ( `attribute_id` int(11) NOT NULL AUTO_INCREMENT, `attribute_name` varchar(255) NOT NULL, `attribute_ename` varchar(255) DEFAULT NULL, PRIMARY KEY (`attribute_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;"; $result = $DB->query($sql_attributes); if ($result) { $messages[] = "Đã tạo bảng tb_product_attributes thành công."; } else { $messages[] = "Lỗi khi tạo bảng tb_product_attributes: " . $DB->error(); } } // Create product attribute values table if it doesn't exist if (!$attribute_values_exists) { $sql_attribute_values = "CREATE TABLE `tb_product_attribute_values` ( `value_id` int(11) NOT NULL AUTO_INCREMENT, `attribute_id` int(11) NOT NULL, `value_name` varchar(255) NOT NULL, `value_ename` varchar(255) DEFAULT NULL, `additional_price` float NOT NULL DEFAULT 0, `quantity` int(11) NOT NULL DEFAULT 0, `path_img` varchar(255) DEFAULT NULL, `img` varchar(255) DEFAULT NULL, `is_video` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`value_id`), KEY `attribute_id` (`attribute_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;"; $result = $DB->query($sql_attribute_values); if ($result) { $messages[] = "Đã tạo bảng tb_product_attribute_values thành công."; } else { $messages[] = "Lỗi khi tạo bảng tb_product_attribute_values: " . $DB->error(); } } // Create product-attribute mapping table if it doesn't exist if (!$product_attributes_exists) { $sql_product_attributes = "CREATE TABLE `tb_product_attribute_mapping` ( `id` int(11) NOT NULL AUTO_INCREMENT, `product_id` int(11) NOT NULL, `value_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `product_id` (`product_id`), KEY `value_id` (`value_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;"; $result = $DB->query($sql_product_attributes); if ($result) { $messages[] = "Đã tạo bảng tb_product_attribute_mapping thành công."; } else { $messages[] = "Lỗi khi tạo bảng tb_product_attribute_mapping: " . $DB->error(); } } // Check if module exists in tb_module $check_module = $DB->query("SELECT * FROM tb_module WHERE module_url='act=admin&code=product'"); $module_exists = $DB->get_num_rows() > 0; if (!$module_exists) { // Find the content category ID (usually 1 for Content Management) $query_category = $DB->query("SELECT module_category_id FROM tb_module_category WHERE module_category_name='Quản lý nội dung' OR module_category_name='Content Management'"); $category_id = 1; // Default to 1 if not found if ($row_category = $DB->fetch_row($query_category)) { $category_id = $row_category['module_category_id']; } // Get the highest position $query_pos = $DB->query("SELECT MAX(module_pos) as max_pos FROM tb_module WHERE module_cat='$category_id'"); $row_pos = $DB->fetch_row($query_pos); $pos = isset($row_pos['max_pos']) ? $row_pos['max_pos'] + 1 : 1; // Add module to tb_module $sql_module = "INSERT INTO tb_module (module_name, module_ename, module_url, module_cat, module_pos, module_status) VALUES ('Sản phẩm', 'Products', 'act=admin&code=product', '$category_id', '$pos', 'active')"; $result = $DB->query($sql_module); if ($result) { $messages[] = "Đã thêm module sản phẩm vào menu quản trị."; } else { $messages[] = "Lỗi khi thêm module sản phẩm vào menu: " . $DB->error(); } } // Check if there are already products in the database $check_products_exist = $DB->query("SELECT COUNT(*) as count FROM tb_product"); $row = $DB->fetch_row($check_products_exist); $products_count = $row['count']; // Insert 100 demo products if no products exist if ($products_count == 0 && $product_exists) { $messages[] = "Bắt đầu thêm 100 sản phẩm demo..."; // Get default category ID $default_category_id = 1; $query_category = $DB->query("SELECT category_id FROM tb_product_categories WHERE category_name='Sản phẩm mặc định' OR category_ename='Default Products' LIMIT 1"); if ($row_category = $DB->fetch_row($query_category)) { $default_category_id = $row_category['category_id']; } // Insert 100 demo products $success_count = 0; for ($i = 1; $i <= 100; $i++) { $title = "Sản phẩm demo " . $i; $ftitle = "san-pham-demo-" . $i; $etitle = "Demo Product " . $i; $intro = "Giới thiệu ngắn về sản phẩm demo " . $i; $eintro = "Short introduction for demo product " . $i; $body = "Mô tả chi tiết về sản phẩm demo " . $i . ". Đây là sản phẩm mẫu được tạo tự động."; $ebody = "Detailed description for demo product " . $i . ". This is an automatically generated sample product."; $specification = "Thông số kỹ thuật của sản phẩm demo " . $i; $especification = "Technical specifications for demo product " . $i; $price = rand(100000, 10000000); // Random price between 100,000 and 10,000,000 $old_price = $price + rand(100000, 1000000); // Old price higher than current price $quantity = rand(10, 100); // Random quantity between 10 and 100 // Use placeholder image with random dimensions $width = rand(300, 800); $height = rand(300, 800); $img = "https://placehold.co/{$width}x{$height}"; $time = time(); $pos = $i; $status = 1; // Active $noibat = rand(0, 1); // Random featured status // Insert product $sql_insert = "INSERT INTO tb_product (title, ftitle, etitle, intro, eintro, body, ebody, specification, especification, price, old_price, quantity, img, time, pos, status, noibat) VALUES ('$title', '$ftitle', '$etitle', '$intro', '$eintro', '$body', '$ebody', '$specification', '$especification', $price, $old_price, $quantity, '$img', $time, $pos, $status, $noibat)"; $result = $DB->query($sql_insert); if ($result) { $product_id = $DB->insert_id(); // Associate product with default category $DB->query("INSERT INTO tb_product_category (product_id, category_id) VALUES ($product_id, $default_category_id)"); $success_count++; } } $messages[] = "Đã thêm thành công $success_count sản phẩm demo."; } // Display results echo '<div class="alert alert-info">'; if (empty($messages)) { echo 'Tất cả các bảng đã tồn tại và module đã được cài đặt.'; } else { echo implode('<br>', $messages); } echo '</div>'; // Redirect back to product admin page after 3 seconds echo '<script>setTimeout(function(){ window.location.href = "?act=admin&code=product"; }, 3000);</script>'; exit(); ?>