File "admin-flyers-products-edit.inc.php"

Full Path: /srv/www/www.cadoro.it/src/controllers/admin-flyers-products-edit.inc.php
File size: 1.88 KB
MIME-type: text/x-php
Charset: utf-8

<?php
  $flyer = models\Flyer::get_by_id($flyer_id);
  if (!$flyer) {
    not_found();
  }

  $product = $flyer->get_product_by_id($product_id);
  if (!$product) {
    not_found();
  }

  $errors = array();

  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $params = array(
      'category' => _post('category'),
      'subcategory' => _post('subcategory'),
      'code' => _post('code'),
      'title' => _post('title'),
      'description' => _post('description'),
      'brand' => _post('brand'),
      'offer_multi' => _post('offer_multi'),
      'offer_discount' => _post('offer_discount'),
      'offer_price' => _post('offer_price'),
      'offer_price_old' => _post('offer_price_old'),
      'offer_type' => _post('offer_type'),
      'notes' => _post('notes'),
      'ean' => _post('ean'),
      'stores' => _post('stores'),
      'stores_card' => _post('stores_card'),
      'label' => _post('label'),
      'label2' => _post('label2'),
      'date_begin' => _post_date('date_begin'),
      'date_end' => _post_date('date_end'),
      'below_cost' => _post('below_cost'),
      'homepage' => _post('homepage'),
      'image_thumb' => null,
      'image_full' => null,
    );
    if (!$params['category']) {
      $errors['category'] = 1;
    }
    if (!$params['title']) {
      $errors['title'] = 1;
    }
    if (!$errors) {
      $image = _image('image', 'flyers');
      if ($image) {
        $params['image_full'] = $image['asset'];
        $params['image_thumb'] = _resize_c($image['path'], 220, 128, 'flyers');
      }
      $product->update($params);
      header("Location: " . BASE_URL . "/admin/flyers/" . $flyer_id . "/products");
      exit;
    }
  }

  $smarty->assign("errors", $errors);
  $smarty->assign("flyer", $flyer);
  $smarty->assign("product", $product);

  $smarty->assign("menu", "content");
  $smarty->assign("submenu", "flyers");

  $smarty->display("admin-flyers-products-edit.tmpl");
?>