/**
  * IS: -
  * FS: Mengirimkan ke viewer: form, gkey
  * Desc: Mengatur aksi yang dilakukan untuk halaman create
  */
 public function createAction()
 {
     //Creating instances: form, table
     $form = new Admin_Form_PoiForm();
     $form->draft->setLabel('Simpan Sebagai Draft');
     if ($this->_userInfo->canApprove) {
         $form->submit->setLabel('Terbitkan');
     } else {
         $form->submit->setLabel('Simpan Untuk Pratinjau');
     }
     $table_destination = new Model_DbTable_Destination();
     $table_destination_description = new Model_DbTable_DestinationDescription();
     $table_categorytopoi = new Model_DbTable_CategoryToPoi();
     $table_areatopoi = new Model_DbTable_AreaToPoi();
     $table_relatedpoi = new Model_DbTable_RelatedPoi();
     $table_related_article_poi = new Model_DbTable_RelatedArticlePoi();
     $this->table_cultureVideo = new Model_DbTable_CultureVideo();
     //
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $status = Model_DbTable_Destination::DRAFT;
             if (isset($_POST['Submit'])) {
                 if ($this->_userInfo->canApprove) {
                     $status = Model_DbTable_Destination::PUBLISH;
                 } else {
                     $status = Model_DbTable_Destination::PENDING;
                 }
             } else {
                 $status = Model_DbTable_Destination::DRAFT;
             }
             $featured = 0;
             if ($this->getRequest()->getPost('Featured')) {
                 $featured = $this->getRequest()->getPost('Featured');
             }
             $culture = array('pointX' => (double) $_POST['pointx'], 'pointY' => (double) $_POST['pointy'], 'main_category' => $_POST['MainCategory'], 'status' => $status, 'featured' => $featured);
             if ($form->header_image->isUploaded()) {
                 $file = pathinfo($form->header_image->getFileName());
                 $form->header_image->addFilter('Rename', UPLOAD_FOLDER . 'culture/' . $file['filename'] . '_' . time() . '.' . $file['extension']);
                 if ($form->header_image->receive()) {
                     $culture['image'] = $form->header_image->getValue();
                 }
             }
             $culture_id = $table_destination->insertPoi($culture);
             if (!empty($culture_id)) {
                 $culture_description = array('language_id' => 1, 'poi_id' => $culture_id, 'name' => $_POST['Name'], 'description' => $_POST['Description'], 'created_by' => $this->_userInfo->id, 'created_at' => date('Y-m-d H:i:s'));
                 $culture_description_id = $table_destination_description->insertPoiDescription($culture_description);
                 $category_count = $this->_getParam('MaxCategory');
                 $category_stack = array();
                 for ($i = 0; $i <= $category_count; $i++) {
                     if (!empty($_POST['catValue' . $i])) {
                         array_push($category_stack, $_POST['catValue' . $i]);
                     }
                 }
                 /* inserting data for categorytopoi table */
                 foreach ($category_stack as $cat_id) {
                     $category_poi = array('category_id' => $cat_id, 'poi_id' => $culture_id);
                     $table_categorytopoi->insertCategoryToPoi($category_poi);
                 }
                 /* Preparing area data for table insert
                  * Get area count and data */
                 $area_count = $this->_getParam('MaxArea');
                 $area_stack = array();
                 for ($i = 0; $i <= $area_count; $i++) {
                     if (!empty($_POST['areaValue' . $i])) {
                         array_push($area_stack, $_POST['areaValue' . $i]);
                     }
                 }
                 /* inserting to areatopoi table */
                 foreach ($area_stack as $area_id) {
                     $area_poi = array('area_id' => $area_id, 'poi_id' => $culture_id);
                     $table_areatopoi->insertAreaToPoi($area_poi);
                 }
                 $relCtr = $_POST['relPoi_counter'];
                 for ($i = 0; $i <= $relCtr; $i++) {
                     if (!empty($_POST['relpoi' . $i])) {
                         $data = array('poi_id' => $culture_id, 'related_poi' => $_POST['relpoi' . $i]);
                         $table_relatedpoi->insertRelatedPoi($data);
                     }
                 }
                 //          $counter berisi jumlah related article (link)
                 $counter = $_POST['counterRelated'];
                 for ($i = 1; $i <= $counter; $i++) {
                     if (!empty($_POST['label' . $i]) and !empty($_POST['link' . $i])) {
                         $data = array('poi_id' => $culture_id, 'label' => $_POST['label' . $i], 'link' => $_POST['link' . $i], 'language_id' => 1);
                         $table_related_article_poi->insertRelated($data);
                     }
                 }
                 $this->handleInsertVideoLink($culture_id);
                 $upload_dir = UPLOAD_FOLDER . 'documents/';
                 $upload_image_dir = UPLOAD_FOLDER . 'culture/';
                 $upload = new Zend_File_Transfer_Adapter_Http();
                 $table_galery = new Model_DbTable_Image();
                 $table_file = new Model_DbTable_FileAttachments();
                 $files = $upload->getFileInfo();
                 $i = 0;
                 $j = 0;
                 foreach ($files as $file => $info) {
                     $info['destination'] = $upload_image_dir;
                     if (strstr($file, 'files')) {
                         $file = array('poi_id' => $culture_id, 'title' => $_POST['titles'][$i], 'name' => $info['name'], 'size' => $info['size']);
                         $table_file->insert($file);
                         $upload->setDestination($upload_dir);
                         $i++;
                     } else {
                         if (strstr($file, 'images')) {
                             $image = array('poi_id' => $culture_id, 'source' => $info['name'], 'name' => $_POST['imageTitles'][$j]);
                             $table_galery->insert($image);
                             $upload->setDestination($upload_image_dir);
                             $j++;
                         }
                     }
                     $upload->receive($info['name']);
                 }
                 $this->loggingaction('Culture', 'Create', $culture_id, 1);
                 $this->_flash->addMessage('Item kebudayaan berhasil ditambahkan.');
             } else {
                 $this->_flash->addMessage('Item kebudayaan gagal ditambahkan.');
             }
             $this->_redirect($this->view->rootUrl('/admin/culture/'));
         }
     }
     $this->view->form = $form;
 }
 /**
  * IS: -
  * FS: Mengirimkan ke viewer: form, gkey
  * Desc: Mengatur aksi yang dilakukan untuk halaman create
  */
 public function createAction()
 {
     //Creating instances: form, table
     $language_id = 2;
     $form = new Admin_Form_PoiFormIndo();
     $table_destination = new Model_DbTable_Destination();
     $table_destination_description = new Model_DbTable_DestinationDescription();
     $table_categorytopoi = new Model_DbTable_CategoryToPoi();
     $table_areatopoi = new Model_DbTable_AreaToPoi();
     $table_relatedpoi = new Model_DbTable_RelatedPoi();
     $table_related_article_poi = new Model_DbTable_RelatedArticlePoi();
     //if this is a post request
     if ($this->getRequest()->isPost()) {
         //if the post is valid
         if ($form->isValid($_POST)) {
             //check if it is a special destination or not
             if ($_POST['SpecialDestination'] == 1) {
                 //if it was a special destination but no image uploaded
                 if ($_POST['HeaderImage'] == '') {
                     $this->_flash->addMessage('3\\Warning: Data is saved without image! You should upload an image for a featured destination.');
                 } else {
                     $header_image = preg_replace("/'/", "&#39;", $_POST['HeaderImage']);
                 }
             } else {
                 $header_image = null;
             }
             $PoiName = preg_replace("/'/", "&#39;", $_POST['PoiName']);
             $PoiAddress = preg_replace("/'/", "&#39;", $_POST['PoiAddress']);
             $PoiPhone = preg_replace("/'/", "&#39;", $_POST['PoiPhone']);
             $PoiWebsite = preg_replace("/'/", "&#39;", $_POST['PoiWebsite']);
             /*preparing data for Poi table*/
             $data = array('pointX' => $_POST['pointx'], 'pointY' => $_POST['pointy'], 'address' => $PoiAddress, 'phone' => $PoiPhone, 'website' => $PoiWebsite, 'main_category' => $_POST['MainCategory'], 'popular' => $_POST['PopularSelect'], 'status' => $_POST['SaveStatus'], 'special' => $_POST['SpecialDestination'], 'header_image' => ' ');
             /*inserting data to Poi table and get the last inserted poi id*/
             $Poi_id = $table_destination->insertPoi($data);
             /*preparing data for poi description table*/
             if (!empty($Poi_id)) {
                 //preparing for description
                 $PoiTagLine = preg_replace("/'/", "&#39;", $_POST['PoiTagline']);
                 $PoiInformation = preg_replace("/'/", "&#39;", $_POST['PoiInformation']);
                 $PoiHowToGetThere = preg_replace("/'/", "&#39;", $_POST['PoiHowToGetThere']);
                 $PoiHowToGetAround = preg_replace("/'/", "&#39;", $_POST['PoiHowToGetAround']);
                 $PoiWhatToDo = preg_replace("/'/", "&#39;", $_POST['PoiWhatToDo']);
                 $PoiWhereToEat = preg_replace("/'/", "&#39;", $_POST['PoiWhereToEat']);
                 $PoiWhereToStay = preg_replace("/'/", "&#39;", $_POST['PoiWhereToStay']);
                 $PoiWhatToBuy = preg_replace("/'/", "&#39;", $_POST['PoiWhatToBuy']);
                 $PoiTips = preg_replace("/'/", "&#39;", $_POST['PoiTips']);
                 $desc = array('poi_id' => $Poi_id, 'name' => $PoiName, 'language_id' => 2, 'tagline' => $PoiTagLine, 'description' => $PoiInformation, 'howToGetThere' => $PoiHowToGetThere, 'howToGetAround' => $PoiHowToGetAround, 'whatToDo' => $PoiWhatToDo, 'whereToEat' => $PoiWhereToEat, 'whereToStay' => $PoiWhereToStay, 'whatToBuy' => $PoiWhatToBuy, 'tips' => $PoiTips, 'header_image' => $header_image);
                 //insert to the database
                 $Poi_descid = $table_destination_description->insertPoiDescription($desc);
                 /*preparing data for categorytopoi table
                  *Get category count and data*/
                 $category_count = $this->_getParam('MaxCategory');
                 $category_stack = array();
                 for ($i = 0; $i <= $category_count; $i++) {
                     if (!empty($_POST['catValue' . $i])) {
                         array_push($category_stack, $_POST['catValue' . $i]);
                     }
                 }
                 /*inserting data for categorytopoi table*/
                 foreach ($category_stack as $cat_id) {
                     $category_poi = array('category_id' => $cat_id, 'poi_id' => $Poi_id);
                     $table_categorytopoi->insertCategoryToPoi($category_poi, 2);
                 }
                 /*Preparing area data for table insert
                  *Get area count and data*/
                 $area_count = $this->_getParam('MaxArea');
                 $area_stack = array();
                 for ($i = 0; $i <= $area_count; $i++) {
                     if (!empty($_POST['areaValue' . $i])) {
                         array_push($area_stack, $_POST['areaValue' . $i]);
                     }
                 }
                 /*inserting to areatopoi table*/
                 foreach ($area_stack as $area_id) {
                     $area_poi = array('area_id' => $area_id, 'poi_id' => $Poi_id);
                     $table_areatopoi->insertAreaToPoi($area_poi);
                 }
                 /*processing related poi data*/
                 $relCtr = $_POST['relPoi_counter'];
                 for ($i = 0; $i <= $relCtr; $i++) {
                     if (!empty($_POST['relpoi' . $i])) {
                         $data = array('poi_id' => $Poi_id, 'related_poi' => $_POST['relpoi' . $i]);
                         $table_relatedpoi->insertRelatedPoi($data);
                     }
                 }
                 /* inserting to related_article_poi */
                 //counter related article poi
                 $counter = $_POST['counterRelated'];
                 for ($i = 1; $i <= $counter; $i++) {
                     if (!empty($_POST['label' . $i]) and !empty($_POST['link' . $i])) {
                         $data = array('poi_id' => $Poi_id, 'label' => $_POST['label' . $i], 'link' => $_POST['link' . $i], 'language_id' => 2);
                         //insert into table
                         $table_related_article_poi->insertRelated($data);
                     }
                 }
                 /*send a success message via flashmessenger*/
                 $this->loggingaction('destination', 'create', $Poi_id, $language_id);
                 $this->_flash->addMessage('1\\Destination Insert Success!');
             } else {
                 /*send a failed message via flashmessenger*/
                 $this->_flash->addMessage('2\\Destination Insert Failed!');
             }
             /*redirect to the destination list page*/
             $this->_redirect($this->view->rootUrl('/admin/destinationindo/'));
         }
     }
     /*send form to the view*/
     $this->view->form = $form;
 }