public function edittranslationAction()
 {
     $id = $this->_getParam('id');
     $this->_form->name->setRequired(false)->setAttrib('disabled', true);
     $this->_form->image->setRequired(false)->setAttrib('disabled', true);
     $this->_form->draft->setLabel('Save as draft')->setAttrib('disabled', true);
     $this->_form->submit->setLabel('Save');
     if (null != $id) {
         $article = $this->_article->fetchWithDescription($id, self::LANGUAGE_EN);
         if (null != $article) {
             $this->_form->populate($article->toArray());
         } else {
             $this->_helper->redirector('index');
         }
     } else {
         $this->_helper->redirector('index');
     }
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost();
         $description = $post['article']['description'];
         if ($this->_form->description->isValid($description)) {
             $data = array('description' => $description);
             $this->_description->update($data, array('article_id = ?' => $id, 'language_id = ?' => self::LANGUAGE_EN));
             $this->_flashMessenger->addMessage('Article translation saved successfully.');
             $this->_helper->redirector('index');
         }
     }
     if (null != $article->image) {
         if (file_exists(UPLOAD_FOLDER . 'article/' . $article->image)) {
             $this->view->image = 'upload/article/' . $article->image;
         }
     }
     $this->view->form = $this->_form;
 }
 /**
  * IS: Parameter id terdeklarasi
  * FS: Mengirimkan ke viewer: form, rel_poi, poi_id
  * Desc: Mengatur aksi yang dilakukan untuk halaman edit
  */
 public function editAction()
 {
     $langId = $this->_getParam('lang');
     //print_r($langId);
     $form = new Admin_Form_ArticleForm(array('languageId' => 1));
     $form->draft->setLabel('Draft');
     if ($this->_userInfo->canApprove) {
         $form->submit->setLabel('Update');
     } else {
         $form->submit->setLabel('Update for review');
     }
     $table_article = new Model_DbTable_Article();
     $table_article_description = new Model_DbTable_ArticleDescription();
     $article_id = $this->_getParam('id');
     $table_related_article_attraction = new Model_DbTable_RelatedArticleAttraction();
     /* set form element value */
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $title = preg_replace("/'/", "'", $_POST['ArticleTitle']);
             $content = preg_replace("/'/", "'", $_POST['ArticleContent']);
             if ($langId != 1) {
                 $indo = $table_article_description->checkForIndo($article_id);
                 if ($indo == null) {
                     $data = array('article_id' => $article_id, 'language_id' => $langId, 'title' => $title, 'content' => $content);
                     $table_article_description->insertArticleDescription($data);
                 } else {
                     $data = array('article_id' => $article_id, 'language_id' => 2, 'title' => $title, 'content' => $content);
                     $table_article_description->updateArticleDescription($data, $article_id, $langId);
                 }
             } else {
                 if ($_POST['ArticleMainImage'] == '') {
                     $this->_flash->addMessage('3\\Warning: Data is saved without image!');
                 } else {
                     $main_image = preg_replace("/'/", "'", $_POST['ArticleMainImage']);
                 }
                 $status = Model_DbTable_Article::DRAFT;
                 if ($this->getRequest()->getPost('action') == 'Update' || $this->getRequest()->getPost('action') == 'Update for review') {
                     if ($this->_userInfo->canApprove) {
                         $status = Model_DbTable_Article::PUBLISH;
                     } else {
                         $status = Model_DbTable_Article::PENDING;
                     }
                 }
                 $data = array('status' => $status, 'main_image' => $main_image, 'sort_order' => $_POST['articleSortOrder'], 'category' => $_POST['category'], 'updated_by' => $this->_userInfo->id, 'updated_at' => date('Y-m-d H:i:s'));
                 $table_article->updateArticle($data, $article_id);
                 $data = array('article_id' => $article_id, 'language_id' => 1, 'title' => $title, 'content' => $content);
                 $table_article_description->updateArticleDescription($data, $article_id, $langId);
             }
             //$this->_helper->layout()->disableLayout();
             //$this->_helper->viewRenderer->setNoRender(true);
             /* update related article */
             //param
             // this part add related
             if ($_POST['counterRelated'] > 0) {
                 $counter = $_POST['counterRelated'];
                 for ($i = 1; $i <= $counter; $i++) {
                     //echo $_POST['link'.$i];
                     //cek existing label and link in database
                     // if $cek having value = false, then data will be saved
                     if (isset($_POST['label' . $i])) {
                         $cek = $table_related_article_attraction->cek_existing($_POST['label' . $i], $_POST['link' . $i]);
                         if (!$cek or $cek == false) {
                             $data = array('article_id' => $article_id, 'label' => $_POST['label' . $i], 'link' => $_POST['link' . $i], 'language_id' => $language_id);
                             $table_related_article_attraction->insertRelated($data);
                         }
                     }
                 }
             }
             //here part delete related, (if there are request)
             if ($_POST['counterDel'] > 0) {
                 $counterDel = $_POST['counterDel'];
                 for ($i = 1; $i <= $counterDel; $i++) {
                     //cek existing label and link in database
                     // if found, data will be removed
                     if (isset($_POST['labeldel' . $i])) {
                         $cek = $table_related_article_attraction->cek_existing_forDel($_POST['labeldel' . $i], $_POST['linkdel' . $i]);
                     }
                 }
             }
             $this->loggingaction('attraction', 'edit', $article_id);
             $this->_flash->addMessage('1\\Article Update Success!');
             $this->_redirect($this->view->rootUrl('/admin/article/'));
         }
     }
     $new_translate = false;
     if ($langId != 1) {
         $indo = $table_article_description->checkForIndo($article_id);
         if ($indo) {
             $data = $table_article->getAllWithDescByLanguageId($article_id, $langId);
             $form->article_poi_id->setValue($data['poi_id']);
             $form->article_status->setValue($data['status']);
             $form->articleSortOrder->setValue($data['sort_order']);
             $form->article_main_image->setValue($data['main_image']);
             $form->article_title->setValue(html_entity_decode($data['title']));
             $form->article_content->setValue(html_entity_decode($data['content']));
             $form->category_select->setValue($data['category']);
             $this->view->rel_poi = $data['poi_id'];
             $this->view->poi_id = $data['poi_id'];
         }
     } else {
         $data = $table_article->getAllWithDescByLanguageId($article_id, $langId);
         $form->article_poi_id->setValue($data['poi_id']);
         $form->article_status->setValue($data['status']);
         $form->articleSortOrder->setValue($data['sort_order']);
         $form->article_main_image->setValue($data['main_image']);
         $form->article_title->setValue(html_entity_decode($data['title']));
         $form->article_content->setValue($data['content']);
         $form->category_select->setValue($data['category']);
         $this->view->rel_poi = $data['poi_id'];
         $this->view->poi_id = $data['poi_id'];
     }
     //get realated article data
     // @param =  article_id
     $ralated_article = $table_related_article_attraction->getByArticleId($article_id, $langId);
     $this->view->edit = 1;
     $this->view->ralated_article = $ralated_article;
     $this->view->article_id = $article_id;
     $this->view->languageID = 2;
     $this->view->form = $form;
     $this->view->langid_id = $langId;
 }
 public function init()
 {
     $this->setLanguageId(1);
     parent::init();
 }
 public function init()
 {
     parent::setLanguageId(2);
     parent::init();
 }
 public function editArticleAction()
 {
     $articleID = $this->_getParam('articleID', 0);
     $this->view->articleID = $articleID;
     $form = new Admin_Form_ArticleForm();
     $article = $this->_articles->getArticleByID($articleID);
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             // copy file
             if ($form->Image->isUploaded()) {
                 $form->Image->receive();
                 $fileName = $form->Image->getFileName();
                 $path = "img/articles/" . $articleID . ".jpg";
                 Admin_View_Helper_ImageControls::resizeImage($fileName, $path, 300, 200);
                 unlink($form->Image->getFileName());
                 $formData['ImageUpdateTime'] = Site_View_Helper_Date::formatDate();
                 $article->ImageUpdateTime = Site_View_Helper_Date::formatDate();
             }
             // update
             $this->_articles->updateArticle($formData, $articleID);
             $this->_redirect('/enlighten/panel/articles');
         } else {
             $form->populate($formData);
         }
     } else {
         $data = $article->toArray();
         $form->populate($data);
     }
     $this->view->article = $article;
     $this->view->form = $form;
 }