Ejemplo n.º 1
0
 public function editAction()
 {
     $id = $this->_request->getParam('page_id');
     $form = new Application_Form_NewPageForm();
     $results = $this->url->getUrls();
     $this->view->page_url = $results->page_url;
     $this->view->page_id = $id;
     if (isset($id)) {
         $this->user_session->page_id = $id;
     }
     if (isset($id) || isset($this->user_session->page_id)) {
         $result = $this->page->getPageByID($this->user_session->page_id);
         //var_dump($result);
         //return;
         $this->view->page_id = $result->page_id;
         $form->title->setValue($result->title);
         $form->url_slug->setValue($result->url_slug);
         $form->image->setValue($result->image);
         $form->description->setValue($result->description);
         $this->view->save_description = $result->draft_content;
         $form->submit->setLabel("Update");
         $this->view->url_slug = $result->url_slug;
         $this->user_session->image = $result->image;
         $this->view->image = $result->image;
         $this->view->form = $form;
     }
     if (!$this->_request->isPost()) {
         $this->view->form = $form;
         return;
     }
     $formData = $this->_request->getPost();
     if (!$form->isValid($formData)) {
         $this->view->form = $form;
         return;
     }
     //For Image upload
     $file_name = NULL;
     $image_name = $_FILES["image"]["name"];
     if (isset($image_name) && strlen($image_name) > 0) {
         try {
             if (isset($this->user_session->image)) {
                 unlink(SYSTEM_PATH . "/images/user/pages/" . $result->image);
                 unlink(SYSTEM_PATH . "/images/user/pages/500X500/" . $result->image);
                 unlink(SYSTEM_PATH . '/images/user/pages/200X200/' . $result->image);
             }
             $image = $_FILES['image']['name'];
             $random = rand(10, 10000);
             $time = time() + 7 * 24 * 60 * 60;
             $file_name = $time . $random . $image;
             $formData["image"] = $file_name;
             move_uploaded_file($_FILES["image"]['tmp_name'], SYSTEM_PATH . "/images/user/pages/" . $file_name);
             $thumb = new Application_Model_Thumbnail(SYSTEM_PATH . "/images/user/pages/" . $file_name);
             $thumb->resize(500, 500);
             $thumb->save(SYSTEM_PATH . '/images/user/pages/500X500/' . $file_name);
             $thumb->resize(200, 200);
             $thumb->save(SYSTEM_PATH . '/images/user/pages/200X200/' . $file_name);
         } catch (Zend_File_Transfer_Exception $e) {
             throw new Exception('Bad data: ' . $e->getMessage());
         }
     } else {
         $formData['image'] = $this->user_session->image;
     }
     $formData['page_id'] = $this->user_session->page_id;
     //$slug= $formData['url_slug'];
     //$formData['url_slug']= str_replace("-","", $slug);
     $formData['date_published'] = date("Y-m-d H:i:s");
     if ($formData['submit'] == "0") {
         $formData['is_in_draft'] = 0;
         $formData['draft_content'] = $formData['description'];
     } else {
         $formData['is_in_draft'] = 1;
         $formData['draft_content'] = $formData['description'];
     }
     $result = $this->page->updatePage($formData);
     $this->view->msg = $result;
 }
Ejemplo n.º 2
0
 public function editAction()
 {
     $id = $this->_request->getParam('page_id');
     $form = new Application_Form_NewPageForm();
     $results = $this->url->getUrls();
     $this->view->page_url = $results->page_url;
     $this->view->page_id = $id;
     if (isset($id)) {
         $this->user_session->page_id = $id;
     }
     if (isset($id) || isset($this->user_session->page_id)) {
         $result = $this->page->getPageByID($this->user_session->page_id);
         //var_dump($result);
         //return;
         $this->view->page_id = $result->page_id;
         $form->title->setValue($result->title);
         $form->url_slug->setValue($result->url_slug);
         $form->image->setValue($result->image);
         $form->description->setValue($result->description);
         $form->submit->setLabel("Update");
         $this->view->url_slug = $result->url_slug;
         $this->user_session->image = $result->image;
         $this->view->image = $result->image;
         $this->view->form = $form;
     }
     if (!$this->_request->isPost()) {
         $this->view->form = $form;
         return;
     }
     $formData = $this->_request->getPost();
     if (!$form->isValid($formData)) {
         $this->view->form = $form;
         return;
     }
     //For Image upload
     $file_name = NULL;
     $image_name = $_FILES["image"]["name"];
     if (isset($image_name) && strlen($image_name) > 0) {
         try {
             if (isset($this->user_session->image)) {
                 unlink(SYSTEM_PATH . "/images/pages/original/" . $result->image);
                 unlink(SYSTEM_PATH . "/images/pages/500X500/" . $result->image);
                 unlink(SYSTEM_PATH . '/images/pages/800/' . $result->image);
             }
             $image = $_FILES['image']['name'];
             $random = rand(10, 10000);
             $time = time() + 7 * 24 * 60 * 60;
             $file_name = $time . $random . $image;
             $formData["image"] = $file_name;
             move_uploaded_file($_FILES["image"]['tmp_name'], SYSTEM_PATH . "/images/pages/original/" . $file_name);
             $thumb = new Application_Model_Thumbnail(SYSTEM_PATH . "/images/pages/original/" . $file_name);
             $thumb->resize(500, 500);
             $thumb->save(SYSTEM_PATH . '/images/pages/500X500/' . $file_name);
             $thumb->resize(800, 800);
             $thumb->save(SYSTEM_PATH . '/images/posts/800/' . $file_name);
         } catch (Zend_File_Transfer_Exception $e) {
             throw new Exception('Bad data: ' . $e->getMessage());
         }
     } else {
         $formData['image'] = $this->user_session->image;
     }
     $formData['page_id'] = $this->user_session->page_id;
     $formData['is_in_draft'] = $formData['submit'];
     $slug = $formData['url_slug'];
     $formData['url_slug'] = str_replace("-", "", $slug);
     /*check from database if the slug is already in db  
     	$data = array ("url"=>$formData["url_slug"]);
     	$data["url"]=$formData["url_slug"];
     			
     	 if($this->page->checkPageSlug($data)){
     	 $this->view->msg =  "<div class='alert alert-danger'>Url Slug Is Already Exist. Please change to another.</div>";
     		 return;
     		} */
     if ($formData['submit'] == "0") {
         $formData['is_in_draft'] = 0;
         $result = $this->page->updatePage($formData);
         $this->view->msg = $result;
         //$this->_redirect("/admin/page/lists");
     } else {
         if ($formData['submit'] == "1") {
             $formData['is_in_draft'] = 1;
             $result = $this->page->updateDraftPage($formData);
             $this->view->msg = $result;
             //$this->_redirect("/admin/page/lists");
         }
     }
 }