/**
  * 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;
 }