Esempio n. 1
0
 public function addAction()
 {
     $err = null;
     $arrData = null;
     $params = null;
     $this->view->arrCate = My_Model_Category::getAll();
     if ($this->_request->isPost()) {
         $params = array_merge(array("title" => null, "category" => null, "image" => null, "status" => null, "favorite" => null, "recent" => null), My_Util::santinize($this->_request->getParams()));
         if (!$params["title"]) {
             $err[] = "Title is empty";
         }
         if (!$err) {
             if ($_FILES["file"]) {
                 $arrImage = $this->_imageupload($_FILES["file"], UPLOAD_QUOTE_IMAGE_PATH, UPLOAD_QUOTE_IMAGE_URL);
             }
             if (!$arrImage["status"]) {
                 $err[] = $arrImage["error"];
             }
         }
         if (!$err) {
             $arrX = array("title" => $params["title"], "category" => implode(",", $params["category"]), "image" => isset($arrImage["data"]["link"]) ? $arrImage["data"]["link"] : null, "status" => $params["status"], "favorite" => (int) $params["favorite"], "recent" => (int) $params["recent"]);
             $result = My_Model_Quotes::insert($arrX);
             if ($result) {
                 $this->alert("Insert successfully.", BASE_URL . "/quote/main");
             } else {
                 $this->alert("Errors.", BASE_URL . "/quote/main/add");
             }
         }
     }
     $this->view->err = $err;
     $this->arrData = $params;
     $this->render("form");
 }