File: /home/temp/yarusvl.ru/adminx/core/StoreAdmin.php
<?php
require_once('api/Mgc.php');
class StoreAdmin extends Mgc {
public function fetch() {
$store = new stdClass;
/*Принимаем инофмрацию о бренде*/
if($this->request->method('post')) {
$store->id = $this->request->post('id', 'integer');
$store->name = $this->request->post('name');
$store->annotation = $this->request->post('annotation');
$store->description = $this->request->post('description');
$store->visible = $this->request->post('visible', 'boolean');
$store->code = $this->request->post('code', 'string');
$store->external_id = $this->request->post('external_id', 'string');
$store->url = trim($this->request->post('url', 'string'));
$store->meta_title = $this->request->post('meta_title');
$store->meta_keywords = $this->request->post('meta_keywords');
$store->meta_description = $this->request->post('meta_description');
$store->url = preg_replace("/[\s]+/ui", '', $store->url);
$store->url = strtolower(preg_replace("/[^0-9a-z]+/ui", '', $store->url));
if (empty($store->url)) {
$store->url = $this->translit_alpha($store->name);
}
// Не допустить одинаковые URL разделов.
if(($c = $this->stores->get_store($store->url)) && $c->id!=$store->id) {
$this->design->assign('message_error', 'url_exists');
} elseif(empty($store->name)) {
$this->design->assign('message_error', 'empty_name');
} elseif(empty($store->url)) {
$this->design->assign('message_error', 'empty_url');
} else {
/*Добавляем/обновляем бренд*/
if(empty($store->id)) {
$store->id = $this->stores->add_store($store);
$this->design->assign('message_success', 'added');
} else {
$this->stores->update_store($store->id, $store);
$this->design->assign('message_success', 'updated');
}
// Удаление изображения
if ($this->request->post('delete_image')) {
$this->image->delete_image($store->id, 'image', 'stores', $this->config->original_stores_dir, $this->config->resized_stores_dir);
}
// Загрузка изображения
$image = $this->request->files('image');
if (!empty($image['name']) && ($filename = $this->image->upload_image($image['tmp_name'], $image['name'], $this->config->original_stores_dir))) {
$this->image->delete_image($store->id, 'image', 'stores', $this->config->original_stores_dir, $this->config->resized_stores_dir);
$this->stores->update_store($store->id, array('image'=>$filename));
}
$store = $this->stores->get_store($store->id);
}
} else {
$store->id = $this->request->get('id', 'integer');
$store = $this->stores->get_store($store->id);
}
//var_dump($store);
$this->design->assign('store', $store);
return $this->design->fetch('store.tpl');
}
}