コード例 #1
0
ファイル: edit.php プロジェクト: sydorenkovd/e-com.loc
<?php

$id = Url::getParam('id');
if (!empty($id)) {
    $objCatalogue = new Catalogue();
    $product = $objCatalogue->getProduct($id);
    if (!empty($product)) {
        $objForm = new Form();
        $objValid = new Validation($objForm);
        $categories = $objCatalogue->getCategories();
        if ($objForm->isPost('name')) {
            $objValid->_expected = array('category', 'name', 'description', 'price');
            $objValid->_required = array('category', 'name', 'description', 'price');
            if ($objValid->isValid()) {
                if ($objCatalogue->updateProduct($objValid->_post, $id)) {
                    $objUpload = new Upload();
                    if ($objUpload->upload(CATALOGUE_PATH)) {
                        if (is_file(CATALOGUE_PATH . DS . $product['image'])) {
                            unlink(CATALOGUE_PATH . DS . $product['image']);
                        }
                        $objCatalogue->updateProduct(array('image' => $objUpload->_names[0]), $id);
                        Helper::redirect('/admin' . Url::getCurrentUrl(array('action', 'id')) . '&action=edited');
                    } else {
                        Helper::redirect('/admin' . Url::getCurrentUrl(array('action', 'id')) . '&action=edited-no-upload');
                    }
                } else {
                    Helper::redirect('/admin' . Url::getCurrentUrl(array('action', 'id')) . '&action=edited-failed');
                }
            }
        }
        require_once 'template/_header.php';
コード例 #2
0
ファイル: add.php プロジェクト: sydorenkovd/e-com.loc
<?php

$objForm = new Form();
$objValid = new Validation($objForm);
$objCatalogue = new Catalogue();
$categories = $objCatalogue->getCategories();
if ($objForm->isPost('name')) {
    $objValid->_expected = array('category', 'name', 'description', 'price');
    $objValid->_required = array('category', 'name', 'description', 'price');
    if ($objValid->isValid()) {
        if ($objCatalogue->addProduct($objValid->_post)) {
            $objUpload = new Upload();
            if ($objUpload->upload(CATALOGUE_PATH)) {
                $objCatalogue->updateProduct(array('image' => $objUpload->_names[0]), $objCatalogue->_id);
                Helper::redirect('/admin' . Url::getCurrentUrl(array('action', 'id')) . '&action=added');
            } else {
                Helper::redirect('/admin' . Url::getCurrentUrl(array('action', 'id')) . '&action=added-no-upload');
            }
        } else {
            Helper::redirect('/admin' . Url::getCurrentUrl(array('action', 'id')) . '&action=added-failed');
        }
    }
}
require_once 'template/_header.php';
?>

<h1>Products :: Add</h1>

<form action="" method="post" enctype="multipart/form-data">
	
	<table cellpadding="0" cellspacing="0" border="0" class="tbl_insert">