/**
  * IS: -
  * FS: Mengirimkan ke viewer: tourism, customName
  * Desc: Fungsi untuk menampilkan daftar overseas representatives
  */
 public function indexAction()
 {
     // Model
     $tourismOperDb = new Model_DbTable_TourismOperator();
     // Data
     // Tipe 6 = vito / overseas representatives
     $tourismOperQuery = $tourismOperDb->getAllWithDescById('6', $this->_languageId);
     // View
     $this->view->tourism = parent::setPaginator($tourismOperQuery);
     // id_page_overseas = 'representative(s)'
     $this->view->customName = $this->view->translate('id_page_overseas');
 }
 /**
  * IS: Parameter sortby, sortorder, searchname terdeklarasi
  * FS: Mengirimkan ke viewer: pageTitle, sectionTitle, sectionContent, 
  *     searchName 
  * Desc: Fungsi untuk menampilkan list souvenir di destinasi
  */
 public function findsouvenirAction()
 {
     $this->_helper->layout->setLayout('one-column');
     // Param
     $sortBy = $this->_getParam('sortby');
     $sortOrder = $this->_getParam('sortorder', 'asc');
     $searchName = $this->_getParam('searchname', '');
     // Model
     $tourismOperatorDb = new Model_DbTable_TourismOperator();
     // untuk mengenerate koordinate google map
     $destinationDb = new Model_DbTable_Destination();
     $destination = $destinationDb->getAllByIdLang($this->_destId, $this->_languageId);
     $this->view->pointX = $destination['pointX'];
     $this->view->pointY = $destination['pointY'];
     // Data
     $souvenir = $tourismOperatorDb->getTourismoperatorById($this->_destId, 4, $this->_languageId, array('sort_by' => $sortBy, 'sort_order' => $sortOrder, 'search_name' => $searchName));
     $this->_generateSorter($sortBy, $sortOrder);
     if ($this->_languageId != 2) {
         $textfind = 'Find Souvenir';
     } else {
         $textfind = 'Cari Suvenir';
     }
     // Breadcrumb
     $this->_generateFindBreadcrumb($textfind);
     if ($this->_languageId != 2) {
         $textsectitle = 'SOUVENIR';
     } else {
         $textsectitle = 'SUVENIR';
     }
     // Passing ke view
     $this->view->pageTitle = $this->_destTitle . ' - Souvenir';
     $this->view->sectionTitle = $textsectitle;
     $this->view->sectionContent = parent::setPaginator($souvenir);
     $this->view->searchName = $searchName;
     // Render
     $this->render('index');
 }
 /**
  * IS: Parameter id terdeklarasi
  * FS: Mengirimkan ke viewer: form, gkey, area, data, tourismid
  * Desc: Mengatur aksi yang dilakukan untuk halaman edit
  */
 public function editAction()
 {
     /*Creating table instances*/
     $table_classification = new Model_DbTable_Classification();
     $table_area = new Model_DbTable_Area();
     $table_tourism = new Model_DbTable_TourismOperator();
     $table_tourismdescription = new Model_DbTable_TourismOperatorDescription();
     $table_classtotourism = new Model_DbTable_ClassificationToTourismOperator();
     $table_coveragearea = new Model_DbTable_CoverageArea();
     $form = new Admin_Form_TourismOperatorForm();
     $island_list = $table_area->getAllParentArea();
     $tourism_id = $this->_getParam('id');
     $language_id = $this->_getParam('lang');
     $this->view->state_edit = TRUE;
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             /*preparing data for tourismoperator table*/
             if ($language_id != 1) {
                 $indo = $table_tourismdescription->checkForIndo($tourism_id);
                 if ($indo) {
                     $data = array('tourismoperator_id' => $tourism_id, 'language_id' => 2, 'name' => $_POST['TourismOperatorLangName'], 'description' => $_POST['TourismOperatorDescription']);
                     $table_tourismdescription->updateTourismOperatorDescription($data, $tourism_id);
                 } else {
                     $data = array('tourismoperator_id' => $tourism_id, 'language_id' => 2, 'name' => $_POST['TourismOperatorLangName'], 'description' => $_POST['TourismOperatorDescription']);
                     $table_tourismdescription->insertTourismOperatorDescription($data);
                 }
             } else {
                 $data = array('area_id' => $_POST['TourismArea'], 'phone' => $_POST['TourismOperatorPhone'], 'website' => $_POST['TourismOperatorWebsite'], 'address' => $_POST['TourismOperatorAddress'], 'pointX' => $_POST['Pointx'], 'pointY' => $_POST['Pointy'], 'star' => $_POST['TourismOperatorStar'], 'fax' => $_POST['TourismOperatorFax'], 'email' => $_POST['TourismOperatorEmail']);
                 /*updating data to the tourismoperator table*/
                 $table_tourism->updateTourismOperator($data, $tourism_id);
                 /*preparing data for tourismoperatordescription table*/
                 $data = array('tourismoperator_id' => $tourism_id, 'language_id' => 1, 'name' => $_POST['TourismOperatorLangName'], 'description' => $_POST['TourismOperatorDescription']);
                 /*updating data to the tourismoperator description table*/
                 $table_tourismdescription->updateTourismOperatorDescription($data, $tourism_id);
                 /*get all saved classification*/
                 $temp_class = $table_classtotourism->getAllClassByTourismId($tourism_id);
                 $saved_class = array();
                 foreach ($temp_class as $class_id) {
                     array_push($saved_class, $class_id['class']);
                 }
                 /*get all added classification*/
                 $class_count = $_POST['MaxClass'];
                 $class_stack = array();
                 for ($i = 0; $i < $class_count; $i++) {
                     if (!empty($_POST['classValue' . $i])) {
                         array_push($class_stack, $_POST['classValue' . $i]);
                     }
                 }
                 /*if not exist insert classification to the database*/
                 foreach ($class_stack as $class_id) {
                     if (!in_array($class_id, $saved_class)) {
                         $class_tourism = array('classification_id' => $class_id, 'tourismoperator_id' => $tourism_id);
                         $table_classtotourism->insertClassificationTourism($class_tourism);
                     }
                 }
                 /*complementary check*/
                 foreach ($saved_class as $class_id) {
                     if (!in_array($class_id, $class_stack)) {
                         $table_classtotourism->deleteClassificationTourism($class_id, $tourism_id);
                     }
                 }
                 if (in_array(3, $class_stack)) {
                     /*get coverage area list from the database*/
                     $table_coveragearea = new Model_DbTable_CoverageArea();
                     $area_list = $table_coveragearea->getAllAreaByTourismId($tourism_id);
                     $old_area = array();
                     foreach ($area_list as $value) {
                         array_push($old_area, $value['area_id']);
                     }
                     $area_count = $this->_getParam('MaxArea');
                     $area_stack = array();
                     for ($i = 0; $i <= $area_count; $i++) {
                         if (!empty($_POST['areaCoverValue' . $i])) {
                             array_push($area_stack, $_POST['areaCoverValue' . $i]);
                         }
                     }
                     foreach ($area_stack as $new_area) {
                         if (!in_array($new_area, $old_area)) {
                             $data = array('area_id' => $new_area, 'tourismoperator_id' => $tourism_id);
                             $table_coveragearea->insertCoverageArea($data);
                         }
                     }
                     foreach ($old_area as $saved_area) {
                         if (!in_array($saved_area, $area_stack)) {
                             $table_coveragearea->deleteSpecificCoverage($tourism_id, $saved_area);
                         }
                     }
                 }
             }
             $this->loggingaction('tourismoperator', 'edit', $tourism_id);
             $this->_flash->addMessage('1\\Tourism Operator Update Success!');
             $this->_redirect($this->view->rootUrl('/admin/tourismoperator/'));
         }
     }
     $data_amount = $table_classtotourism->countClassByTourismId($tourism_id);
     if ($language_id != 1) {
         $indo = $table_tourismdescription->checkForIndo($tourism_id);
         if ($indo) {
             $data = $table_tourism->getAllTourismDataByIdLang($tourism_id, $language_id);
         }
     } else {
         $data = $table_tourism->getAllTourismDataByIdLang($tourism_id, $language_id);
     }
     /**
      *Set every element Value
      *Below are standard element value set that doesnt require any further database select operation
      */
     $form->TourismOperatorEmail->setValue($data['email']);
     $form->TourismOperatorPhone->setValue($data['phone']);
     $form->TourismOperatorArea->setValue($data['area_id']);
     $form->TourismOperatorWebsite->setValue($data['website']);
     $form->Pointx->setValue($data['pointX']);
     $form->Pointy->setValue($data['pointY']);
     $form->TourismOperatorAddress->setValue($this->view->HtmlDecode($data['address']));
     $form->TourismOperatorStar->setValue($data['star']);
     $form->TourismOperatorFax->setValue($data['fax']);
     $form->TourismOperatorLangName->setValue($data['langname']);
     $form->TourismOperatorDescription->setValue($this->view->HtmlDecode($data['description']));
     /*Count tourismoperator classification*/
     $form->Count_class->setValue($data_amount);
     $form->Class_counter->setValue($data_amount);
     /*Send variable to the view*/
     $this->view->form = $form;
     $this->view->language_id = $language_id;
     $this->view->gkey = Zend_Registry::get('gmap_key');
     $this->view->area = $data['area_id'];
     $this->view->data = $data;
     $this->view->tourismid = $tourism_id;
 }
 /**
  * IS: Parameter id terdeklarasi
  * FS: Mengirimkan ke viewer: form, gkey, area, data, tourismid
  * Desc: Mengatur aksi yang dilakukan untuk halaman edit
  */
 public function editAction()
 {
     /*Creating table instances*/
     $table_classification = new Model_DbTable_Classification();
     $table_area = new Model_DbTable_Area();
     $table_tourism = new Model_DbTable_TourismOperator();
     $table_tourismdescription = new Model_DbTable_TourismOperatorDescription();
     $table_classtotourism = new Model_DbTable_ClassificationToTourismOperator();
     $table_coveragearea = new Model_DbTable_CoverageArea();
     $form = new Admin_Form_VitoForm();
     $island_list = $table_area->getAllParentArea();
     $tourism_id = $this->_getParam('id');
     $this->view->state_edit = TRUE;
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             /*preparing data for tourismoperator table*/
             $data = array('area_id' => $_POST['TourismArea'], 'phone' => $_POST['TourismOperatorPhone'], 'website' => $_POST['TourismOperatorWebsite'], 'address' => $_POST['TourismOperatorAddress'], 'pointX' => 0, 'pointY' => 0, 'star' => 0, 'fax' => $_POST['TourismOperatorFax'], 'email' => $_POST['TourismOperatorEmail']);
             /*updating data to the tourismoperator table*/
             $table_tourism->updateTourismOperator($data, $tourism_id);
             /*preparing data for tourismoperatordescription table*/
             $data = array('tourismoperator_id' => $tourism_id, 'language_id' => 1, 'name' => $_POST['TourismOperatorRegion'], 'description' => $_POST['TourismOperatorLangName']);
             /*updating data to the tourismoperator description table*/
             $table_tourismdescription->updateTourismOperatorDescription($data, $tourism_id);
             $this->loggingaction('vito', 'edit', $tourism_id);
             $this->_flash->addMessage('1\\Vito Update Success!');
             $this->_redirect($this->view->rootUrl('/admin/vito/'));
         }
     }
     $data_amount = $table_classtotourism->countClassByTourismId($tourism_id);
     $data = $table_tourism->getAllTourismDataByIdLang($tourism_id, 1);
     /**
      *Set every element Value
      *Below are standard element value set that doesnt require any further database select operation
      */
     $form->TourismOperatorEmail->setValue($data['email']);
     $form->TourismOperatorPhone->setValue($data['phone']);
     $form->TourismOperatorArea->setValue($data['area_id']);
     $form->TourismOperatorWebsite->setValue($data['website']);
     $form->TourismOperatorAddress->setValue($this->view->HtmlDecode($data['address']));
     $form->TourismOperatorFax->setValue($data['fax']);
     $form->TourismOperatorRegion->setValue($data['langname']);
     $form->TourismOperatorLangName->setValue($this->view->HtmlDecode($data['description']));
     /*Count tourismoperator classification*/
     /*Send variable to the view*/
     $this->view->form = $form;
     $this->view->gkey = Zend_Registry::get('gmap_key');
     $this->view->tourismid = $tourism_id;
 }