Exemple #1
0
<?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';