Пример #1
0
 public function __construct($id = false)
 {
     parent::__construct();
     $this->name = "form_brand";
     $this->enctype = "multipart/form-data";
     $this->action = URL::current();
     if (!$id) {
         $this->text("title", "Название:", FormProcessor::getSessionData("title"));
         $this->file("img", "Картинка:");
         $this->textarea("meta_desc", "Описание:", FormProcessor::getSessionData("meta_desc"));
         $this->textarea("meta_key", "Ключевые слова:", FormProcessor::getSessionData("meta_key"));
         $this->text("alias", "ЧПУ ссылка", FormProcessor::getSessionData("alias"));
         $this->submit("insert_brand", "Сохранить");
     } else {
         $this->hidden("id", $id);
         $obj = new BrandDB();
         $obj->load($id);
         $this->text("title", "Название:", $obj->title);
         $this->file("img", "Картинка:");
         $this->textarea("meta_desc", "Описание:", $obj->meta_desc);
         $this->textarea("meta_key", "Ключевые слова:", $obj->meta_key);
         $link = URL::get("brand", "", array("id" => $id), true, "", false);
         $alias = SefDB::getAliasOnLink($link);
         $this->text("alias", "ЧПУ ссылка", $alias);
         $this->submit("update_brand", "Сохранить");
     }
 }
Пример #2
0
 public function actionBrand()
 {
     $obj = new BrandDB();
     if (!$obj->load($this->request->id)) {
         $this->notFound();
     }
     $this->title = $obj->title;
     $this->meta_desc = $obj->meta_desc;
     $this->meta_key = $obj->meta_key;
     $head = $this->getHead(array("/css/main.css"));
     $head->js = array("/js/main.js");
     $content = new Brandproduct();
     $hornav = $this->getHornav();
     $hornav->addData($obj->title);
     $content->hornav = $hornav;
     $content->title = $obj->title;
     $count = ProductDB::getCountProductOnBrand($this->request->id);
     $offset = $this->getOffset(Config::COUNT_PRODUCTS_ON_PAGE);
     $url = URL::get("brand", "", array("id" => $this->request->id));
     $products = ProductDB::getProductOnBrand($this->request->id, Config::COUNT_PRODUCTS_ON_PAGE, $offset);
     $pagination = $this->getPagination($count, Config::COUNT_PRODUCTS_ON_PAGE, $url);
     $content->products = $products;
     $content->pagination = $pagination;
     $this->render($head, $content);
 }
Пример #3
0
 public function actionDelete()
 {
     if (!self::isAuthAdmin()) {
         return null;
     }
     switch ($this->request->view) {
         case "brand":
             try {
                 $obj_db = new BrandDB();
                 $obj_db->load($this->request->id);
                 $tmp = $obj_db->img;
                 $link = URL::get($this->request->view, "", array("id" => $this->request->id), true, "", false);
                 $sef_db = new SefDB();
                 $sef_db->loadOnLink($link);
                 if ($tmp) {
                     File::delete(Config::DIR_IMG_BRAND . $tmp);
                 }
                 if ($obj_db->delete() && $sef_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "product":
             try {
                 $obj_db = new ProductDB();
                 $obj_db->load($this->request->id);
                 $tmp = $obj_db->img;
                 $link = URL::get($this->request->view, "", array("id" => $this->request->id), true, "", false);
                 $sef_db = new SefDB();
                 $sef_db->loadOnLink($link);
                 if ($tmp) {
                     File::delete(Config::DIR_IMG_PRODUCT . $tmp);
                 }
                 if ($obj_db->delete() && $sef_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "category":
             try {
                 $obj_db = new CategoryDB();
                 $obj_db->load($this->request->id);
                 $link = URL::get($this->request->view, "", array("id" => $this->request->id), true, "", false);
                 $sef_db = new SefDB();
                 $sef_db->loadOnLink($link);
                 if ($obj_db->delete() && $sef_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "section":
             try {
                 $obj_db = new SectionDB();
                 $obj_db->load($this->request->id);
                 $link = URL::get($this->request->view, "", array("id" => $this->request->id), true, "", false);
                 $sef_db = new SefDB();
                 $sef_db->loadOnLink($link);
                 if ($obj_db->delete() && $sef_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "slider":
             try {
                 $obj_db = new SliderDB();
                 $obj_db->load($this->request->id);
                 if ($obj_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "dop_foto":
             try {
                 $obj_db = new ImgDB();
                 $obj_db->load($this->request->id);
                 File::delete($obj_db->url);
                 if ($obj_db->delete()) {
                     $this->fp->setSessionMessage("product", "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::referer());
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
     }
 }