function OrderTable($ordersProducts, $connection)
{
    foreach ($ordersProducts as $arrayNumber => $orders_data) {
        echo "<tr class='product'>";
        foreach ($orders_data as $data_key => $data_value) {
            //echo "data-key: ".$data_key." data-value: ".$data_value."<br>";
            switch ($data_key) {
                case "product_id":
                    $product = \App\DB\Products::get($data_value, $connection);
                    $flag = v::arr()->notEmpty()->validate($product);
                    if ($flag) {
                        printProduct($product);
                    } else {
                        echo "<td class='deleted-product' colspan='2'>Товар удален из базы данных</td>";
                    }
                    break;
                case "amount":
                    echo "<td data-amount='{$data_value}'>" . $data_value . "</td></tr>";
                    break;
                default:
                    break;
            }
        }
    }
}
function orderCost($connection)
{
    $orderCost = 0;
    $productsInCart = $_COOKIE['products'];
    foreach ($productsInCart as $id => $value) {
        $product = \App\DB\Products::get($id, $connection);
        $totalPrice = $product['price'] * $value;
        $orderCost += $totalPrice;
    }
    return $orderCost;
}
 public function __construct(Connection $connection, $name, $address, $email, $addition)
 {
     parent::__construct($connection, $name, $address, $email, $addition);
     $productsInCart = $_COOKIE['products'];
     $cost = 0;
     $this->order_id = parent::getCurrentId($connection);
     foreach ($productsInCart as $id => $value) {
         $product = Products::get($id, $connection);
         $cost += $product['price'] * $value;
         $insProd = $connection->prepare('INSERT INTO `ordersproducts`
             (`order_id`, `product_id`, `amount`)
             VALUES (:order_id, :product_id, :amount)');
         $insProd->execute([":order_id" => $this->order_id, ":product_id" => $id, ":amount" => $value]);
     }
     parent::setPrice($connection, $cost, $this->order_id);
 }
示例#4
0
function showTableOrders($connection)
{
    echo "Заказы в таблице Orders<br/>";
    $statement = $connection->prepare("SELECT * FROM `orders`");
    $statement->execute();
    $statement->setFetchMode(PDO::FETCH_ASSOC);
    echo "<table class='prod_tab'>\n\t\t<thead><td>Id</td><td>Номер заказа</td><td>ФИО</td><td>Адрес</td><td>E-mail</td></thead>\n\t\t<tbody>";
    while ($row = $statement->fetch()) {
        echo "<tr><td>" . $row['id'] . "</td><td>" . $row['num_order'] . "</td><td>" . $row['fio'] . "</td><td>" . $row['address'] . "</td><td>" . $row['email'] . "</td></tr>\n\t\t\t<tr><td><table>";
        $itogo = 0;
        $stmt = $connection->prepare("SELECT * FROM `order_product` WHERE `num_order` = :num_ord");
        $stmt->execute(['num_ord' => $row['num_order']]);
        $productsInCart = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        foreach ($productsInCart as $id => $prd) {
            $product = \App\DB\Products::get($prd['id_prod'], $connection);
            echo "<tr><td>" . $product['name'] . "</td><td>" . $prd['amount_prod'] . "</td><td>" . $product['price'] . "</td></tr>";
            $itogo += $prd['amount_prod'] * $product['price'];
        }
        echo "<tr><td colspan='2'>Итого</td><td>" . $itogo . "</td></tr>";
        echo "</table></td></tr>";
    }
    echo "</tbody></table>";
}
<?php

if (isset($_GET['item_id'])) {
    $id = $_GET['item_id'];
    $pro_info = \App\DB\Products::get($id, $connection);
}
if (isset($_GET['item_id'])) {
    ?>
<h2>Редактирование товара</h2>
<form class="edit-elem-form" name="edit-form" method="post" action="/admin/?to_do=edit_item_tb&item_id=<?php 
    echo $id;
    ?>
&item_act=edit">
	<input name="tek_id" type="hidden" value="<?php 
    echo $pro_info['id'];
    ?>
"/>
	<label>
		<p>Title</p>
		<input name="t_title" type="text" value="<?php 
    echo $pro_info['name'];
    ?>
" />
	</label>
	<label>
		<p>Description</p>
		<input name="t_descr" type="text" value="<?php 
    echo $pro_info['description'];
    ?>
" />
	</label>
示例#6
0
            <div class="row clearfix">
<?php 
use Respect\Validation\Validator as v;
include_once $src_path . 'autoload.php';
$connection = new \App\DB\Connection('root', '');
if (isset($_GET['id'])) {
    $id = $_GET['id'];
} else {
    $id = 'error';
}
$product = \App\DB\Products::get($id, $connection);
$flag = v::arr()->notEmpty()->validate($product);
if (!$flag) {
    echo "Такого товара не существует";
} else {
    $deleteProduct = \App\DB\Products::deleteProduct($id, $connection);
    // Back to previous page
    if (isset($_SERVER['HTTP_REFERER'])) {
        header('Location: ' . $_SERVER['HTTP_REFERER']);
    } else {
        header('Location: / ');
    }
}
?>
            </div>
        </div>
    </div>
    </div>
    </div>
</section>
<?php 
示例#7
0
<?php

if (isset($_GET['item']) && is_numeric($_GET['item'])) {
    $item = $_GET['item'];
    $product = \App\DB\Products::get($item, $connection);
    if ($product) {
        if (isset($_COOKIE['products'][$product['id']])) {
            $value = $_COOKIE['products'][$product['id']] + 1;
        } else {
            $value = 1;
        }
        setcookie("products[{$product['id']}]", $value, time() + 3 * 24 * 60 * 60, "/");
    }
    //получаем общее кол-во товаров в корзине для вывода в верхнем меню (+1, т.к. setcookie срабатывает только при перезагрузке страницы)
    $amount = \App\Utilities\Cookie::getBascketAmount() + 1;
    echo $amount;
}
示例#8
0
} else {
    include_once "/product_data-validate.php";
    // Data Validation
    $errors = [];
    $title = titleValidate($errors, $_POST['title']);
    $description = descriptionValidate($errors, $_POST['description']);
    $price = priceValidate($errors, $_POST['price']);
    if ($_FILES['userfile']['error'] != 4) {
        $userfile = fileValidate($errors, $_FILES['userfile']['name']);
    } else {
        $userfile = false;
    }
    if (!v::arr()->notEmpty()->validate($errors)) {
        $category_id = $_POST['category'];
        $createProduct = new \App\DB\Products($connection, $title, $description, $price, $category_id);
        $id = \App\DB\Products::getCurrentId($connection);
        if ($userfile) {
            // Set new photo
            include_once "add-image.php";
        }
        if ($createProduct) {
            header("Refresh: 0; url=/edit/?id=" . $id);
        } else {
            echo "Ошибка. Товар не создан";
        }
    } else {
        include_once "templates/_add-shop-item-form.php";
        include_once "templates/_form-errors.php";
    }
}
?>
示例#9
0
    $title = titleValidate($errors, $_POST['title']);
    $description = descriptionValidate($errors, $_POST['description']);
    $price = priceValidate($errors, $_POST['price']);
    if ($_FILES['userfile']['error'] != 4) {
        $userfile = fileValidate($errors, $_FILES['userfile']['name']);
    } else {
        $userfile = false;
    }
    if (!v::arr()->notEmpty()->validate($errors)) {
        $id = $_GET['id'];
        $category_id = $_POST['category'];
        if ($userfile) {
            // Set new photo
            include_once "add-image.php";
        }
        $updateProduct = \App\DB\Products::updateProduct($connection, $id, $title, $description, $price, $category_id);
        if ($updateProduct) {
            header("Refresh:0");
        } else {
            echo "Ошибка. Товар не изменен";
        }
    } else {
        include_once "templates/_edit-form.php";
        include_once "templates/_form-errors.php";
    }
}
?>
            </div>
        </div>
    </div>
    </div>
示例#10
0
<?php

$products = \App\DB\Products::getAll($connection);
include_once __DIR__ . '/templates/_header.php';
include_once __DIR__ . '/templates/_top_menu.php';
?>
<section>
<div class="container">
	<div class="row clearfix">
	    <!-- боковое меню -->
        <?php 
include_once 'templates/_menu.php';
?>
		<div class="column column9">
			<div class="catalog">
				<!-- хлебные крошки -->
				<div class="breadcrumbs">
					<a href="<?php 
echo \App\Utilities\Options::URL;
?>
/">Магазин</a>
					<p>Мини-утки</p>
				</div>
				<div class="row clearfix">
					<!-- элементы каталога -->
				<?php 
if (!empty($products)) {
    include_once __DIR__ . '/templates/_pagination.php';
} else {
    echo "<h2>Список товаров пуст</h2>";
    if (!isset($_SESSION['user_id'])) {
示例#11
0
<?php

$flag = false;
$products = [];
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
    $id = $_GET['id'];
    $category = \App\DB\Categories::get($id, $connection);
    if (!$category) {
        $flag = true;
        $category['title'] = "Неизвестная категория";
    }
    if (!$flag) {
        $products = \App\DB\Products::getByCategory($category['id'], $connection);
    }
} else {
    $flag = true;
    $category['title'] = "Неизвестная категория";
}
include_once __DIR__ . '/templates/_header.php';
include_once __DIR__ . '/templates/_top_menu.php';
?>
    <section>
        <div class="container">
            <div class="row clearfix">
                <!-- боковое меню -->
                <?php 
include_once 'templates/_menu.php';
?>
                <div class="column column9">
                    <div class="catalog">
                        <!-- хлебные крошки -->
示例#12
0
<?php

$flag = false;
$images = \App\DB\Images::getAll($connection);
$uploadfile = '../data/uploads/' . basename($_FILES['userfile']['name']);
foreach ($images as $image) {
    if ($image['photo'] === $uploadfile) {
        // Если нашли в таблице изображений такой файл, обновляем таблицу с продуктами
        $flag = true;
        $uploadProducts = \App\DB\Products::setPhoto($connection, $image['id'], $id);
        break;
    }
}
if (!$flag) {
    // Если не нашли, обновляем две таблицы - заносим новый файл к изображениям и информацию об его ID в продукты
    $image = new \App\DB\Images($connection, $uploadfile);
    $image_id = \App\DB\Images::getCurrentId($connection);
    $uploadProducts = \App\DB\Products::setPhoto($connection, $image_id, $id);
}
示例#13
0
<?php

$products = \App\DB\Products::getToMainPage($connection);
include_once __DIR__ . '/templates/_header.php';
include_once __DIR__ . '/templates/_top_menu.php';
include_once __DIR__ . '/templates/_main.php';
include_once __DIR__ . '/templates/_footer.php';
示例#14
0
<?php

$products = \App\DB\Products::getLastCreated($connection);
include_once __DIR__ . '/templates/_header.php';
include_once __DIR__ . '/templates/_top_menu.php';
include_once __DIR__ . '/templates/_main.php';
include_once __DIR__ . '/templates/_footer.php';
示例#15
0
                        <div class="row clearfix">
                            <?php 
use Respect\Validation\Validator as v;
include_once $src_path . 'autoload.php';
$connection = new \App\DB\Connection('root', '');
if (isset($_GET['id'])) {
    $id = $_GET['id'];
} else {
    $id = 'error';
}
$category = \App\DB\Categories::get($id, $connection);
$flag = v::arr()->notEmpty()->validate($category);
if (!$flag) {
    echo "Такой категории не существует";
} else {
    $deleteCategory = \App\DB\Categories::deleteCategory($id, $connection);
    if ($deleteCategory) {
        $deleteCategoryId = \App\DB\Products::deleteCategoryId($id, $connection);
    }
    // Back to previous page
    header('Location: ' . \App\Utilities\Options::URL . '/edit-cat-all');
}
?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
<?php 
include_once __DIR__ . '/templates/_footer.php';