/** * 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; }
/** * 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, language_id, parent_id, parent_data * Desc: Mengatur aksi yang dilakukan untuk halaman edit */ public function editAction() { //variable and class initiation $area_id = $this->_getParam('id'); $language_id = $this->_getParam('lang'); $form = new Admin_Form_AreaForm(); $table_area = new Model_DbTable_Area(); $table_regionalinfo = new Model_DbTable_Regional(); $parent_data = $table_area->getAllParentArea(array('area_id')); $area_data = null; //if this is a post request if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { if ($language_id != 1) { $indo = $table_regionalinfo->checkForIndo($area_id); if ($indo) { $data = array('area_id' => $area_id, 'language_id' => $language_id, 'area_name' => $_POST['areaNameLan'], 'regional_description' => $_POST['areaDescription'], 'history' => $_POST['areaHistory'], 'people_and_customs' => $_POST['areaPeople'], 'entry' => $_POST['areaEntry'], 'cuisine' => $_POST['areaCuisine'], 'tourism_office' => $_POST['areaTourismOffice']); $table_regionalinfo->updateArea($area_id, $data, $language_id); } else { $data = array('area_id' => $area_id, 'language_id' => $language_id, 'area_name' => $_POST['areaNameLan'], 'regional_description' => $_POST['areaDescription'], 'history' => $_POST['areaHistory'], 'people_and_customs' => $_POST['areaPeople'], 'entry' => $_POST['areaEntry'], 'cuisine' => $_POST['areaCuisine'], 'tourism_office' => $_POST['areaTourismOffice']); $table_regionalinfo->insertArea($data); } } else { //get the parent area for determine area type $area_type = $table_area->getAreaTypeById($_POST['parentArea']) + 1; //preparing data for insert process $data = array('pointX' => $_POST['pointx'], 'pointY' => $_POST['pointy'], 'parent_id' => $_POST['parentArea'], 'area_type' => $area_type); $table_area->updateArea($area_id, $data); $data = array('area_id' => $area_id, 'language_id' => $language_id, 'area_name' => $_POST['areaNameLan'], 'regional_description' => $_POST['areaDescription'], 'history' => $_POST['areaHistory'], 'people_and_customs' => $_POST['areaPeople'], 'entry' => $_POST['areaEntry'], 'cuisine' => $_POST['areaCuisine'], 'tourism_office' => $_POST['areaTourismOffice']); $table_regionalinfo->updateArea($area_id, $data, 1); } $this->loggingaction('region', 'edit', $area_id, $language_id); $this->_flash->addMessage('1\\Region Update Success!'); $this->_redirect($this->view->rootUrl('/admin/region/')); } } if ($language_id != 1) { $indo = $table_regionalinfo->checkForIndo($area_id); if ($indo) { $area_data = $table_area->getAllById($area_id, $language_id); } } else { $area_data = $table_area->getAllById($area_id, $language_id); } //get data from the database and load it to the view // if($area_data !=null) // { $this->view->parent_id = $area_data['parent_id']; //set element value $form->areaDescription->setvalue($area_data['regional_description']); $form->areaEntry->setvalue($area_data['entry']); $form->areaHistory->setvalue($area_data['history']); $form->areaPeople->setvalue($area_data['people_and_customs']); $form->areaCuisine->setvalue($area_data['cuisine']); $form->areaTourismOffice->setvalue($area_data['tourism_office']); $form->areaNameLang->setvalue($area_data['area_name']); $form->Poi_x->setvalue($area_data['pointX']); $form->Poi_y->setvalue($area_data['pointY']); //send data to the view $this->view->language_id = $language_id; $this->view->parent_data = $parent_data; $this->view->form = $form; $this->view->gkey = Zend_Registry::get('gmap_key'); // } }