<?php

if (isset($_POST['action'])) {
    if ($_POST['action'] == "add") {
        if (isset($_POST['name'], $_POST['category'], $_POST['short_descr'], $_POST['image'], $_POST['description'], $_POST['price'], $_POST['stock'])) {
            $id_category = intval($_POST['category']);
            $itemManager = new ItemManager($database);
            $subcategoryManager = new SubcategoryManager($database);
            $subcategory = $subcategoryManager->findById($id_category);
            $photo_itemManager = new Photo_itemManager($database);
            try {
                $item = $itemManager->create($subcategory, $_POST['name'], $_POST['description'], $_POST['short_descr'], $_POST['price'], $_POST['stock']);
            } catch (Exception $e) {
                $_SESSION['errors'] = $e->getMessage();
            }
            if (!isset($_SESSION['errors']) || $_SESSION['errors'] == "") {
                try {
                    $photo = $photo_itemManager->add($item, $currentUser, $_POST['image']);
                } catch (Exception $e) {
                    $itemManager->delete($item);
                    $_SESSION['errors'] = $e->getMessage();
                }
                if (!isset($_SESSION['errors']) || $_SESSION['errors'] == "") {
                    $_SESSION['success'] = "Produit a bien  été :)";
                    header('Location: ?page=item&id=' . $item->getId());
                    exit;
                }
            }
        }
    }
}
Esempio n. 2
0
/**
 * Client
 */
function testCopy(ItemManager $manager, $item_code)
{
    /**
     * 商品のインスタンスを2つ作成
     */
    $item1 = $manager->create($item_code);
    $item2 = $manager->create($item_code);
    /**
     * 1つだけコメントを削除
     */
    $item2->getDetail()->comment = 'コメントを書き換えました';
    /**
     * 商品情報を表示
     * 深いコピーをした場合、$item2への変更は$item1に影響しない
     */
    echo '■オリジナル';
    $item1->dumpData();
    echo '■コピー';
    $item2->dumpData();
    echo '<hr>';
}
Esempio n. 3
0
<?php

if (isset($_SESSION['id']) && $currentUser->getStatus() > 0) {
    // Categories admin page
    if ($_GET['page'] == 'dashboard_items') {
        // Create new category
        if (isset($_POST['new_name'], $_POST['new_category'], $_POST['new_price'], $_POST['new_stock'], $_POST['new_image'], $_POST['new_description'])) {
            $itemManager = new ItemManager($db);
            $categoryManager = new CategoryManager($db);
            try {
                $category = $categoryManager->readById($_POST['new_category']);
                $item = $itemManager->create($category, $_POST['new_name'], $_POST['new_price'], $_POST['new_stock'], $_POST['new_image'], $_POST['new_description']);
            } catch (Exception $e) {
                $errors[] = $e->getMessage();
            }
            if (count($errors) == 0) {
                header('Location: ?page=dashboard_items');
                exit;
            }
        }
    }
}