function store($data) { // dmp($data); // exit; if (!isset($data["has_breakfast"])) { $data["has_breakfast"] = 0; } if (isset($data['start_date'])) { $data['start_date'] = JHotelUtil::convertToMysqlFormat($data['start_date']); } if (isset($data['end_date'])) { $data['end_date'] = JHotelUtil::convertToMysqlFormat($data['end_date']); } try { //$this->_db->BeginTrans(); $query = "START TRANSACTION;"; $this->_db->setQuery($query); $this->_db->queryBatch(); $row = $this->getTable(); if (count($data['option_ids']) > 0) { $data['option_ids'] = implode(',', $data['option_ids']); } else { $data['option_ids'] = ''; } // Bind the form fields to the table if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); return false; } // Make sure the record is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); return false; } // Store the web link table to the database if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); return false; } //prepare photos $path_old = JHotelUtil::makePathFile(JPATH_COMPONENT . PATH_ROOM_PICTURES . ($data['room_id'] + 0) . "/"); $files = glob($path_old . "*.*"); if ($data['room_id'] == '' || $data['room_id'] == 0 || $data['room_id'] == null) { $data['room_id'] = $this->_db->insertid(); //update all temporary seasons $query = " UPDATE #__hotelreservation_rooms_seasons SET room_id = " . $data['room_id'] . " WHERE room_id =0 "; $this->_db->setQuery($query); $this->_db->query(); //~update all temporary seasons } $this->_room_id = $data['room_id']; $path_new = JHotelUtil::makePathFile(JPATH_COMPONENT . PATH_ROOM_PICTURES . ($data['room_id'] + 0) . "/"); $picture_ids = array(); foreach ($data['pictures'] as $value) { $row = $this->getTable('ManageRoomPictures'); // dmp($key); $pic = new stdClass(); $pic->room_picture_id = 0; $pic->room_id = $data['room_id']; $pic->room_picture_info = $value['room_picture_info']; $pic->room_picture_path = $value['room_picture_path']; $pic->room_picture_enable = $value['room_picture_enable']; //dmp($pic); $file_tmp = JHotelUtil::makePathFile($path_old . basename($pic->room_picture_path)); if (!is_file($file_tmp)) { continue; } if (!is_dir($path_new)) { if (!@mkdir($path_new)) { throw new Exception($this->_db->getErrorMsg()); } } // dmp(($path_old.basename($pic->room_picture_path).",".$path_new.basename($pic->room_picture_path))); // exit; if ($path_old . basename($pic->room_picture_path) != $path_new . basename($pic->room_picture_path)) { if (@rename($path_old . basename($pic->room_picture_path), $path_new . basename($pic->room_picture_path))) { $pic->room_picture_path = PATH_ROOM_PICTURES . ($data['room_id'] + 0) . '/' . basename($pic->room_picture_path); //@unlink($path_old.basename($pic->room_picture_path)); } else { throw new Exception($this->_db->getErrorMsg()); } } if (!$row->bind($pic)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } $picture_ids[] = $this->_db->insertid(); } $files = glob($path_new . "*.*"); foreach ($files as $pic) { $is_find = false; foreach ($data['pictures'] as $value) { if ($pic == JHotelUtil::makePathFile(JPATH_COMPONENT . $value['room_picture_path'])) { $is_find = true; break; } } if ($is_find == false) { @unlink(JHotelUtil::makePathFile(JPATH_COMPONENT . $value['room_picture_path'])); } } $query = " DELETE FROM #__hotelreservation_rooms_pictures \r\n\t\t\t\t\t\tWHERE room_id = '" . $data['room_id'] . "'\r\n\t\t\t\t\t\t" . (count($picture_ids) > 0 ? " AND room_picture_id NOT IN (" . implode(',', $picture_ids) . ")" : ""); // dmp($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } //~prepare photos //prepare intervals numbers $room_interval_number_ids = array(); $room_number_ids = array(); $room_number_date_ignored_ids = array(); $c = count($data['room_intervals_numbers']['nrs']); for ($i = 0; $i < $c; $i++) { $row = $this->getTable('ManageRoomIntervalsNumbers'); $d = new stdClass(); $d->room_date_id = 0; $d->room_id = $data['room_id']; $d->nrs = $data['room_intervals_numbers']['nrs'][$i]; $d->nre = $data['room_intervals_numbers']['nre'][$i]; $d->is_ignore_duplicate = $data['room_intervals_numbers']['is_ignore_duplicate'][$i]; $d->datas = JHotelUtil::convertToMysqlFormat($data['room_intervals_numbers']['datas'][$i]); $d->datae = JHotelUtil::convertToMysqlFormat($data['room_intervals_numbers']['datae'][$i]); $d->datai = $data['room_intervals_numbers']['datai'][$i]; if ($d->datai == null || $d->datai == 'NaN-NaN-NaN') { $d->datai = '0000-00-00'; } if (!$row->bind($d)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } if (!$row->store()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } $d->room_interval_number_id = $this->_db->insertid(); $room_interval_number_ids[] = $d->room_interval_number_id; //prepare intervals numbers explicit for ($k = $d->nrs; $k <= $d->nre; $k++) { $row = $this->getTable('ManageRoomNumbers'); $d_ex = new stdClass(); $d_ex->room_id = $d->room_id; $d_ex->room_number_number = $k; $d_ex->type_price = $data['type_price']; $d_ex->room_number_price_1 = $data['room_price_1']; $d_ex->room_number_price_2 = $data['room_price_2']; $d_ex->room_number_price_3 = $data['room_price_3']; $d_ex->room_number_price_4 = $data['room_price_4']; $d_ex->room_number_price_5 = $data['room_price_5']; $d_ex->room_number_price_6 = $data['room_price_6']; $d_ex->room_number_price_7 = $data['room_price_7']; $d_ex->room_number_price = $data['room_price']; $d_ex->room_number_midweek = $data['room_price_midweek']; $d_ex->room_price_weekend = $data['room_price_weekend']; $d_ex->room_number_datas = JHotelUtil::convertToMysqlFormat($d->datas); $d_ex->room_number_datae = JHotelUtil::convertToMysqlFormat($d->datae); $d_ex->room_number_datai = $d->datai; if (!$row->bind($d_ex)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } if (!$row->store()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } $d->room_number_id = $this->_db->insertid(); $room_number_ids[] = $d->room_number_id; $di = explode(',', $d->datai); $arr_di = array(); foreach ($di as $di_v) { if ($di_v == 'NaN-NaN-NaN' || $di_v == '' || $di_v == '0000-00-00') { continue; } $row = $this->getTable('ManageRoomNumbersDatesIgnored'); $d_ex = new stdClass(); $d_ex->room_id = $d->room_id; $d_ex->room_interval_number_id = $d->room_interval_number_id; $d_ex->room_number_id = $d->room_number_id; $d_ex->room_number_date_number = $k; $d_ex->room_number_date_data = $di_v; if (!$row->bind($d_ex)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } if (!$row->store()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } $room_number_date_ignored_ids[] = $this->_db->insertid(); $arr_di[] = $di_v; } } //~prepare intervals numbers explicit } $query = " DELETE FROM #__hotelreservation_rooms_intervals_numbers\r\n\t\t\t\t\t\tWHERE room_id = '" . $data['room_id'] . "'\r\n\t\t\t\t\t\t" . (count($room_interval_number_ids) > 0 ? " AND room_interval_number_id NOT IN (" . implode(',', $room_interval_number_ids) . ")" : ""); // dmp($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } $query = " DELETE FROM #__hotelreservation_rooms_numbers\r\n\t\t\t\t\t\tWHERE room_id = '" . $data['room_id'] . "'\r\n\t\t\t\t\t\t" . (count($room_number_ids) > 0 ? " AND room_number_id NOT IN (" . implode(',', $room_number_ids) . ")" : ""); // dmp($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } $query = " DELETE FROM #__hotelreservation_rooms_numbers_date_ignored\r\n\t\t\t\t\t\tWHERE room_id = '" . $data['room_id'] . "'\r\n\t\t\t\t\t\t" . (count($room_number_date_ignored_ids) > 0 ? " AND room_number_date_ignored_id NOT IN (" . implode(',', $room_number_date_ignored_ids) . ")" : ""); // dmp($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } //~prepare intervals numbers //$this->_db->CommitTrans(); $query = "COMMIT"; $this->_db->setQuery($query); $this->_db->queryBatch(); } catch (Exception $ex) { // dmp($ex); // exit; //$this->_db->RollbackTrans(); $query = "ROLLBACK"; $this->_db->setQuery($query); $this->_db->queryBatch(); return false; } return true; }
public function populateReservationDetails($data) { $userData = new stdClass(); $userData->confirmation_id = $data["reservationId"]; //dmp($data["roomdetails"]); $guestInfo = $this->getNumberOfGuests($data["roomdetails"]); $userData->roomGuests = $guestInfo->adults; //dmp($userData->roomGuests); $userData->total_adults = 0; if (isset($userData->roomGuests) && count($userData->roomGuests) >= 1) { foreach ($userData->roomGuests as $guestPerRoom) { $userData->total_adults += $guestPerRoom; } } $userData->adults = $userData->total_adults; $userData->children = 0; $userData->first_name = $data["first_name"]; $userData->last_name = $data["last_name"]; $userData->address = $data["address"]; $userData->city = $data["city"]; $userData->state_name = $data["state_name"]; $userData->country = $data["country"]; $userData->postal_code = $data["postal_code"]; $userData->phone = $data["phone"]; $userData->email = $data["email"]; $userData->company_name = $data["company_name"]; $userData->guest_type = isset($data["guest_type"]) ? $data["guest_type"] : 0; $userData->discount_code = $data["discount_code"]; $userData->reservedItems = $data["reservedItem"]; $userData->hotelId = $data["hotelId"]; $userData->totalPaid = $data["totalPaid"]; /*--------------------------------------------------------------*/ //MICOD //Aquí anexamos el nuevo campo de edades a la variable $userSata $edades = array($data["edad-1"], $data["edad-2"], $data["edad-3"], $data["edad-4"], $data["edad-5"], $data["edad-6"]); //Concatenar todo en un nuevo Array $string_edades = implode("|", $edades); //Pegar todo en un nuevo string $userData->child_age = $string_edades; //Pasar la variable al userData $_SESSION["child_age"] = $userData->child_age; //Pasar la variable a una sesión para cargarlo en el archivo ReservationService.php /*dmp($_SESSION["child_age"]); die;*/ /*--------------------------------------------------------------*/ $userData->voucher = $data["voucher"]; $userData->remarks = $data["remarks"]; $userData->remarks_admin = $data["remarks_admin"]; $userData->start_date = JHotelUtil::convertToMysqlFormat($data["start_date"]); $userData->end_date = JHotelUtil::convertToMysqlFormat($data["end_date"]); $hotel = HotelService::getHotel($userData->hotelId); $userData->currency = HotelService::getHotelCurrency($hotel); $userData->arrival_time = $data["arrival_time"]; $userData->rooms = count($data["roomdetails"]); if ($data["update_price_type"] == 2 || empty($data["update_price_type"])) { $userData->roomCustomPrices = $this->prepareCustomPrices($userData->reservedItems, $data["roomdetails"], $userData->start_date); } if (!empty($data["extraOptionIds"])) { $extraOptions = array(); if (isset($data["extraOptionIds"])) { foreach ($data["extraOptionIds"] as $key => $value) { $extraOption = explode("|", $value); if ($extraOption[5] > 0 || $extraOption[6] > 0) { continue; } if (isset($data["extra-option-days-" . $extraOption[3]])) { $extraOption[6] = $data["extra-option-days-" . $extraOption[3]]; } if (isset($data["extra-option-persons-" . $extraOption[3]])) { $extraOption[5] = $data["extra-option-persons-" . $extraOption[3]]; } $extraOptions[$key] = implode("|", $extraOption); } } $userData->extraOptionIds = $extraOptions; } $guestDetails = array(); if (isset($data["guest_first_name"])) { for ($i = 0; $i < count($data["guest_first_name"]); $i++) { $guestDetail = new stdClass(); $guestDetail->first_name = $data["guest_first_name"][$i]; $guestDetail->last_name = $data["guest_last_name"][$i]; $guestDetail->identification_number = $data["guest_identification_number"][$i]; $guestDetails[] = $guestDetail; } } $userData->guestDetails = $guestDetails; return $userData; }
/** * save a record (and redirect to main page) * @return void */ function save() { $bRet = 0; $post = JRequest::get('post'); $model = $this->getModel('managereservations'); $tsk = 'edit'; if (isset($post['is_assign_number_rooms']) && $post['is_assign_number_rooms'] == 1) { $tsk = 'assign_number_rooms'; } if (isset($post['is_status']) && $post['is_status'] == 1) { $ret = $this->changeStatus(); return $ret; } else { if (isset($post['change_confirmation_payment_status']) && $post['change_confirmation_payment_status'] > 0) { $ret = $this->changeConfirmationPaymentStatus($post['change_confirmation_payment_status']); return $ret; } else { if ($tsk == 'edit') { // if( strtotime($post['datas']) < strtotime( date('Y-m-d') ) ) // $bRet = -1; // if( strtotime($post['datae']) < strtotime($post['datas'] ) ) // $bRet = -2; // if( count($post['room_ids']) == 0) // $bRet = -3; } if ($bRet == 0) { $modelVariables = $this->getModel('Variables'); $modelConfirmations = $this->getModel('Confirmations'); //$modelConfirmations = $this->getModel('Confirmations'); if (isset($post['is_assign_number_rooms']) && $post['is_assign_number_rooms'] == 1) { JRequest::setVar('tip_oper', 5); $modelVariables->load($post['confirmation_id'], $post['email'], $modelVariables->itemCurrency, array('itemRoomsNumbers' => $post['itemRoomsNumbers'])); $tsk = 'assign_number_rooms'; // dmp($modelVariables->itemRoomsNumbers); // exit; foreach ($modelVariables->itemRoomsNumbers as $key => $valueNumber) { if ($valueNumber == 0) { JError::raiseWarning(500, JText::_('LNG_PLEASE_SELECT_ROOM_NUMBER', true)); $this->setRedirect('index.php?option=' . getBookingExtName() . '&controller=managereservations&view=managereservations&confirmation_id[]=' . $post['confirmation_id'] . '&task=' . $tsk); return false; } } //$post['itemRoomsNumbers'] = $str; } else { if ($tsk == 'edit') { $start_date = JHotelUtil::convertToMysqlFormat($post["datas"]); $end_date = JHotelUtil::convertToMysqlFormat($post["datae"]); //dmp($start_date); //dmp($end_date); //dmp($post); JRequest::setVar('tip_oper', 5); $modelVariables = new JHotelReservationModelVariables($post['hotel_id']); $modelVariables->load($post['confirmation_id'], $post['email'], $modelVariables->itemCurrency, $post); $modelVariables->store($post); //dmp($modelVariables); } } //dmp($modelVariables); //exit; if ($modelVariables->checkAvalability(true)) { // $str = $modelVariables->getStringRoomsCapacity( $modelVariables->itemRoomsCapacity ); // $post['itemRoomsCapacity'] = $str; // $modelVariables->store($post); $check_totals = true; if (isset($post['is_assign_number_rooms']) && $post['is_assign_number_rooms'] == 1) { $check_totals = false; } else { $modelVariables->status_reservation_id = RESERVED_ID; } //$modelVariables->itemRoomsDiscounts = $modelVariables->getRoomsDiscounts(); /* //numbers if( isset( $post['is_assign_number_rooms']) && $post['is_assign_number_rooms'] == 1 ) { $modelVariables->getRoomsAvailable($modelVariables->room_ids, true ); foreach($modelVariables->itemRoomsNumbers as $key=> $nr ) { foreach( $modelVariables->itemRoomsAvailable as $k => $v ) { if($v->room_id == $key ) { foreach( $modelVariables->itemRoomsAvailable[$k]->daily as $d => $vd ) { // dmp($modelVariables->itemRoomsNumbers); $modelVariables->itemRoomsAvailable[$k]->daily['numbers'][] = array( 'data' => $vd['numbers'], 'id' => -1, 'nr' => $nr, 'price' => $vd['price_final'], 'discounts' => $vd[ 'discounts' ] ); } } } } echo 3; } dmp($modelVariables->itemRoomsAvailable); exit;*/ if ($modelVariables->total > $modelVariables->total_payed) { $modelVariables->confirmation_payment_status = PAYMENT_STATUS_NOTPAYED; } //check is allready payed on website /*if( !$modelVariables->comparePayedValues() && $check_totals == true ){ $bRet = -5; }*/ if ($modelConfirmations->store($modelVariables, true, false)) { $bRet = 1; } //exit; } else { $bRet = -4; } } //exit; switch ($bRet) { case 1: $msg = JText::_('LNG_RESERVATION_SAVED', true); $this->setRedirect('index.php?option=' . getBookingExtName() . '&controller=managereservations&view=managereservations', $msg); break; case 0: JError::raiseWarning(500, JText::_('LNG_ERROR_SAVING_RESERVATION', true)); $this->setRedirect('index.php?option=' . getBookingExtName() . '&controller=managereservations&view=managereservations&confirmation_id[]=' . $post['confirmation_id']); break; case -1: JError::raiseWarning(500, JText::_('LNG_DATA_START_DATA_CURRENT', true)); //$this->setRedirect( 'index.php?option='.getBookingExtName().'&controller=managereservations&view=managereservations', $msg ); $this->setRedirect('index.php?option=' . getBookingExtName() . '&controller=managereservations&view=managereservations&task=' . $tsk . '&confirmation_id[]=' . $post['confirmation_id']); break; case -2: JError::raiseWarning(500, JText::_('LNG_DATA_STOP_LOWER_DATA_START', true)); $this->setRedirect('index.php?option=' . getBookingExtName() . '&controller=managereservations&view=managereservations&task=' . $tsk . '&confirmation_id[]=' . $post['confirmation_id']); //$this->setRedirect( 'index.php?option='.getBookingExtName().'&controller=managereservations&view=managereservations', $msg ); break; case -3: JError::raiseWarning(500, JText::_('LNG_PLEASE_SELECT_AT_LEAST_ONE_ROOM', true)); $this->setRedirect('index.php?option=' . getBookingExtName() . '&controller=managereservations&view=managereservations&task=' . $tsk . '&confirmation_id[]=' . $post['confirmation_id']); //$this->setRedirect( 'index.php?option='.getBookingExtName().'&controller=managereservations&view=managereservations', $msg ); break; case -4: JError::raiseWarning(500, JText::_('LNG_CURRENTLY_THERE_ARE_NO_ENOUGH_ROOMS_AVAILABLE', true)); $this->setRedirect('index.php?option=' . getBookingExtName() . '&controller=managereservations&view=managereservations&task=' . $tsk . '&confirmation_id[]=' . $post['confirmation_id']); //$this->setRedirect( 'index.php?option='.getBookingExtName().'&controller=managereservations&view=managereservations', $msg ); break; case -5: JError::raiseWarning(500, JText::_('LNG_WEBSITE_PAYED_FINAL_LOWER_PRICE', true)); $this->setRedirect('index.php?option=' . getBookingExtName() . '&controller=managereservations&view=managereservations&task=' . $tsk . '&confirmation_id[]=' . $post['confirmation_id']); //$this->setRedirect( 'index.php?option='.getBookingExtName().'&controller=managereservations&view=managereservations', $msg ); break; } } } }
public static function createUserData($data) { $log = Logger::getInstance(JPATH_COMPONENT . "/logs/site-log-" . date("d-m-Y") . '.log', 1); $log->LogDebug("Archivo \\components\\com_jhotelreservation\\classes\\services\\UserDataService.php"); $log->LogDebug("createUserData"); //MICOD for ($i = 0; $i < 5; $i++) { $_SESSION["string_edades_habit_" . $i] = NULL; } $_SESSION["array_edades_habit"] = NULL; $userData = new stdClass(); //var_dump("create user data"); if (isset($data) && count($data) > 0 && isset($data["jhotelreservation_datas"])) { if (isset($data["keyword"])) { $userData->keyword = $data["keyword"]; } else { $userData->keyword = ""; } $userData->start_date = JHotelUtil::convertToMysqlFormat($data["jhotelreservation_datas"]); $userData->end_date = JHotelUtil::convertToMysqlFormat($data["jhotelreservation_datae"]); $userData->rooms = $data["rooms"]; $userData->adults = $data["guest_adult"]; $userData->total_adults = $userData->adults; $userData->children = $data["guest_child"]; $userData->total_children = $userData->children; $userData->year_start = $data["year_start"]; $userData->month_start = $data["month_start"]; $userData->day_start = $data["day_start"]; $userData->year_end = $data["year_end"]; $userData->month_end = $data["month_end"]; $userData->day_end = $data["day_end"]; /*--------------------------------------------------------------*/ //MICOD /*En éste espacio capturo los datos de las edades por habitación y los cargo en una sesión PHP de tipo arreglo. De aquí saltamos a la línea 419 de éste archivo*/ $rooms = $data["rooms"]; $rooms = $rooms + 1; if ($data["rooms"] > 1) { for ($i = 0; $i < $rooms; $i++) { $edades_habit = array($data["edad-" . $i . "-1"], $data["edad-" . $i . "-2"], $data["edad-" . $i . "-3"], $data["edad-" . $i . "-4"], $data["edad-" . $i . "-5"], $data["edad-" . $i . "-6"]); $string_edades_habit = implode("|", $edades_habit); $_SESSION["string_edades_habit_" . $i] = $string_edades_habit; } $_SESSION["array_edades_habit"] = array($_SESSION["string_edades_habit_1"], $_SESSION["string_edades_habit_2"], $_SESSION["string_edades_habit_3"], $_SESSION["string_edades_habit_4"]); } else { //dmp($_SESSION["string_edades_habit_4"]); /*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/ //MICOD //Aquí anexamos el nuevo campo de edades a la variable $userSata $edades = array($data["edad-1"], $data["edad-2"], $data["edad-3"], $data["edad-4"], $data["edad-5"], $data["edad-6"]); //Concatenar todo en un nuevo Array $string_edades = implode("|", $edades); //Pegar todo en un nuevo string $userData->child_age = $string_edades; //Pasar la variable al userData $_SESSION["child_age"] = $userData->child_age; //Pasar la variable a una sesión para cargarlo en el archivo ReservationService.php /*dmp($_SESSION["child_age"]); die;*/ /*--------------------------------------------------------------*/ } if (isset($data["user_currency"])) { $userData->user_currency = $data["user_currency"]; } else { $userData->user_currency = ""; } if (isset($data["excursions"])) { $userData->excursions = $data["excursions"]; } else { $userData->excursions = array(); } $userData->voucher = isset($data["voucher"]) ? $data["voucher"] : ""; $log->LogDebug("voucher: " . $userData->voucher); $userData->filterParams = ''; $userData->searchFilter = array("filterCategories" => array()); if (isset($data["room-guests"]) && count($data["room-guests"]) > 1) { $userData->roomGuests = $data["room-guests"]; $userData->rooms = count($userData->roomGuests); $userData->total_adults = 0; foreach ($userData->roomGuests as $guestPerRoom) { $userData->total_adults += $guestPerRoom; } JRequest::setVar('jhotelreservation_rooms', $userData->rooms); JRequest::setVar('jhotelreservation_guest_adult', $userData->total_adults); } else { $userData->roomGuests = array($data["guest_adult"]); } if (isset($data["room-guests-children"]) && count($data["room-guests-children"]) > 1) { $userData->roomGuestsChildren = $data["room-guests-children"]; $userData->total_children = 0; foreach ($userData->roomGuestsChildren as $guestPerRoom) { $userData->total_children += $guestPerRoom; } JRequest::setVar('jhotelreservation_guest_child', $userData->total_children); } else { $userData->roomGuestsChildren = array($data["guest_child"]); } /*--------------------------------------------------------------*/ //MICOD /*Aqui estoy cargando las edades por habitación en el arreglo*/ if (isset($_SESSION["array_edades_habit"]) && count($_SESSION["array_edades_habit"]) > 1) { $userData->child_ages = $_SESSION["array_edades_habit"]; JRequest::setVar('jhotelreservation_child_ages', $userData->child_ages); } else { $userData->child_ages = array($_SESSION["array_edades_habit"]); } /*--------------------------------------------------------------*/ $userData->noDates = JRequest::getVar('no-dates', null); } else { $userData->searchType = ''; $userData->keyword = ''; $userData->start_date = date('Y-m-d'); $userData->end_date = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); $userData->rooms = '1'; $userData->roomGuests = array(2); $userData->roomGuestsChildren = array(0); $userData->adults = isset($data["guest_adult"]) ? $data["guest_adult"] : '2'; $userData->children = isset($data["guest_children"]) ? $data["guest_children"] : '0'; $userData->total_adults = $userData->adults; $userData->total_children = $userData->children; $userData->nights = '1'; $userData->year_start = date('Y'); $userData->month_start = date('m'); $userData->day_start = date('d'); $userData->year_end = date("Y", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); $userData->month_end = date("m", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); $userData->day_end = date("d", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); $userData->voucher = isset($data["voucher"]) ? $data["voucher"] : ""; $userData->filterParams = ''; $userData->searchFilter = array("filterCategories" => array()); $userData->excursions = array(); if (isset($data["keyword"])) { $userData->keyword = $data["keyword"]; } else { $userData->keyword = ""; } $userData->user_currency = ""; } $userData->reservedItems = array(); $userData->confirmation_id = 0; $userData->first_name = ''; $userData->last_name = ''; $userData->address = ''; $userData->city = ''; $userData->state_name = ''; $userData->country = ''; $userData->postal_code = ''; $userData->phone = ''; $userData->email = ''; $userData->conf_email = ''; $userData->company_name = ''; $userData->coupon_code = ''; //$userData->voucher=''; $userData->guest_type = 0; $userData->discount_code = ''; $userData->remarks = ''; $userData->remarks_admin = ''; $userData->media_referer = ''; $userData->arrival_time = ''; $userData->totalPaid = 0; $userData->extraOptionIds = array(); return $userData; }
function addHotelRoom() { $roomId = JRequest::getInt("roomId"); $current = JRequest::getInt("current"); $hotelId = JRequest::getInt("hotelId"); $discountCode = JRequest::getVar("discountCode"); $startDate = JHotelUtil::convertToMysqlFormat(JRequest::getVar("startDate")); $endDate = JHotelUtil::convertToMysqlFormat(JRequest::getVar("endDate")); $adults = JRequest::getInt("adults"); $children = JRequest::getInt("children"); $room = HotelService::getHotelRooms($hotelId, $startDate, $endDate, array($roomId), $adults, $children, $discountCode); $room = $room[0]; //echo($room); $room->current = $current; $model = $this->getModel('reservation'); $buff = $model->getRoomHtmlContent($room, $startDate, $endDate); //header("Content-type:text/xml"); echo '<?xml version="1.0" encoding="utf-8" ?>'; echo '<room_statement>'; echo '<answer error="0" content_records="' . $buff . '" />'; echo '</room_statement>'; echo '</xml>'; JFactory::getApplication()->close(); }
public static function createUserData($data) { //$log = Logger::getInstance(JPATH_COMPONENT."/logs/site-log-".date("d-m-Y").'.log',1); //$log->LogDebug("createUserData"); $userData = new stdClass(); //var_dump("create user data"); if (isset($data) && count($data) > 0 && isset($data["jhotelreservation_datas"])) { if (isset($data["keyword"])) { $userData->keyword = $data["keyword"]; } else { $userData->keyword = ""; } $userData->start_date = JHotelUtil::convertToMysqlFormat($data["jhotelreservation_datas"]); $userData->end_date = JHotelUtil::convertToMysqlFormat($data["jhotelreservation_datae"]); $userData->rooms = $data["rooms"]; $userData->adults = $data["guest_adult"]; $userData->total_adults = $userData->adults; $userData->children = $data["guest_child"]; $userData->total_children = $userData->children; $userData->year_start = $data["year_start"]; $userData->month_start = $data["month_start"]; $userData->day_start = $data["day_start"]; $userData->year_end = $data["year_end"]; $userData->month_end = $data["month_end"]; $userData->day_end = $data["day_end"]; if (isset($data["user_currency"])) { $userData->user_currency = $data["user_currency"]; } else { $userData->user_currency = ""; } if (isset($data["excursions"])) { $userData->excursions = $data["excursions"]; } else { $userData->excursions = array(); } $userData->voucher = isset($data["voucher"]) ? $data["voucher"] : ""; //$log->LogDebug("voucher: ".$userData->voucher); $userData->filterParams = ''; $userData->searchFilter = array("filterCategories" => array()); if (isset($data["room-guests"]) && count($data["room-guests"]) > 1) { $userData->roomGuests = $data["room-guests"]; $userData->rooms = count($userData->roomGuests); $userData->total_adults = 0; foreach ($userData->roomGuests as $guestPerRoom) { $userData->total_adults += $guestPerRoom; } JRequest::setVar('jhotelreservation_rooms', $userData->rooms); JRequest::setVar('jhotelreservation_guest_adult', $userData->total_adults); } else { $userData->roomGuests = array($data["guest_adult"]); } if (isset($data["room-guests-children"]) && count($data["room-guests-children"]) > 1) { $userData->roomGuestsChildren = $data["room-guests-children"]; $userData->total_children = 0; foreach ($userData->roomGuestsChildren as $guestPerRoom) { $userData->total_children += $guestPerRoom; } JRequest::setVar('jhotelreservation_guest_child', $userData->total_children); } else { $userData->roomGuestsChildren = array($data["guest_child"]); } $userData->noDates = JRequest::getVar('no-dates', null); } else { $userData->searchType = ''; $userData->keyword = ''; $userData->start_date = date('Y-m-d'); $userData->end_date = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); $userData->rooms = '1'; $userData->roomGuests = array(2); $userData->roomGuestsChildren = array(0); $userData->adults = isset($data["guest_adult"]) ? $data["guest_adult"] : '2'; $userData->children = isset($data["guest_children"]) ? $data["guest_children"] : '0'; $userData->total_adults = $userData->adults; $userData->total_children = $userData->children; $userData->nights = '1'; $userData->year_start = date('Y'); $userData->month_start = date('m'); $userData->day_start = date('d'); $userData->year_end = date("Y", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); $userData->month_end = date("m", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); $userData->day_end = date("d", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); $userData->voucher = isset($data["voucher"]) ? $data["voucher"] : ""; $userData->filterParams = ''; $userData->searchFilter = array("filterCategories" => array()); $userData->excursions = array(); if (isset($data["keyword"])) { $userData->keyword = $data["keyword"]; } else { $userData->keyword = ""; } $userData->user_currency = ""; } $userData->reservedItems = array(); $userData->confirmation_id = 0; $userData->first_name = ''; $userData->last_name = ''; $userData->address = ''; $userData->city = ''; $userData->state_name = ''; $userData->country = ''; $userData->postal_code = ''; $userData->phone = ''; $userData->email = ''; $userData->conf_email = ''; $userData->company_name = ''; $userData->coupon_code = ''; //$userData->voucher=''; $userData->guest_type = 0; $userData->discount_code = ''; $userData->remarks = ''; $userData->remarks_admin = ''; $userData->media_referer = ''; $userData->arrival_time = ''; $userData->totalPaid = 0; $userData->extraOptionIds = array(); return $userData; }
public function populateReservationDetails($data) { $userData = new stdClass(); $userData->confirmation_id = $data["reservationId"]; //dmp($data["roomdetails"]); $guestInfo = $this->getNumberOfGuests($data["roomdetails"]); $userData->roomGuests = $guestInfo->adults; //dmp($userData->roomGuests); $userData->total_adults = 0; if (isset($userData->roomGuests) && count($userData->roomGuests) >= 1) { foreach ($userData->roomGuests as $guestPerRoom) { $userData->total_adults += $guestPerRoom; } } $userData->adults = $userData->total_adults; $userData->children = 0; $userData->first_name = $data["first_name"]; $userData->last_name = $data["last_name"]; $userData->address = $data["address"]; $userData->city = $data["city"]; $userData->state_name = $data["state_name"]; $userData->country = $data["country"]; $userData->postal_code = $data["postal_code"]; $userData->phone = $data["phone"]; $userData->email = $data["email"]; $userData->company_name = $data["company_name"]; $userData->guest_type = isset($data["guest_type"]) ? $data["guest_type"] : 0; $userData->discount_code = $data["discount_code"]; $userData->reservedItems = $data["reservedItem"]; $userData->hotelId = $data["hotelId"]; $userData->totalPaid = $data["totalPaid"]; $userData->voucher = $data["voucher"]; $userData->remarks = $data["remarks"]; $userData->remarks_admin = $data["remarks_admin"]; $userData->start_date = JHotelUtil::convertToMysqlFormat($data["start_date"]); $userData->end_date = JHotelUtil::convertToMysqlFormat($data["end_date"]); $hotel = HotelService::getHotel($userData->hotelId); $userData->currency = HotelService::getHotelCurrency($hotel); $userData->arrival_time = $data["arrival_time"]; $userData->rooms = count($data["roomdetails"]); if ($data["update_price_type"] == 2 || empty($data["update_price_type"])) { $userData->roomCustomPrices = $this->prepareCustomPrices($userData->reservedItems, $data["roomdetails"], $userData->start_date); } if (!empty($data["extraOptionIds"])) { $extraOptions = array(); if (isset($data["extraOptionIds"])) { foreach ($data["extraOptionIds"] as $key => $value) { $extraOption = explode("|", $value); if ($extraOption[5] > 0 || $extraOption[6] > 0) { continue; } if (isset($data["extra-option-days-" . $extraOption[3]])) { $extraOption[6] = $data["extra-option-days-" . $extraOption[3]]; } if (isset($data["extra-option-persons-" . $extraOption[3]])) { $extraOption[5] = $data["extra-option-persons-" . $extraOption[3]]; } $extraOptions[$key] = implode("|", $extraOption); } } $userData->extraOptionIds = $extraOptions; } $guestDetails = array(); if (isset($data["guest_first_name"])) { for ($i = 0; $i < count($data["guest_first_name"]); $i++) { $guestDetail = new stdClass(); $guestDetail->first_name = $data["guest_first_name"][$i]; $guestDetail->last_name = $data["guest_last_name"][$i]; $guestDetail->identification_number = $data["guest_identification_number"][$i]; $guestDetails[] = $guestDetail; } } $userData->guestDetails = $guestDetails; return $userData; }
function initFilterParams() { $post = JRequest::get('post'); if (isset($post['filter_datas'])) { $post['filter_datas'] = JHotelUtil::convertToMysqlFormat($post['filter_datas']); } if (isset($post['filter_datae'])) { $post['filter_datae'] = JHotelUtil::convertToMysqlFormat($post['filter_datae']); } if (isset($post['hotel_id'])) { $this->hotel_id = $post['hotel_id']; } else { $this->hotel_id = $post['hotel_id'] = 0; } if (isset($post['filter_room_types'])) { $this->filter_room_types = $post['filter_room_types']; } else { $this->filter_room_types = $post['filter_room_types'] = 0; } if (isset($post['filter_datas'])) { $this->filter_datas = $post['filter_datas']; } else { $this->filter_datas = $post['filter_datas'] = date('Y-m-01'); } if (isset($post['filter_datae'])) { $this->filter_datae = $post['filter_datae']; } else { $this->filter_datae = $post['filter_datae'] = date('Y-m-t'); } if (isset($post['filter_report_type'])) { $this->filter_report_type = $post['filter_report_type']; } else { $this->filter_report_type = "MONTH"; } $this->filter_datas = JHotelUtil::convertToFormat($this->filter_datas); $this->filter_datae = JHotelUtil::convertToFormat($this->filter_datae); $hotels = $this->get('Hotels'); $hotels = checkHotels(JFactory::getUser()->id, $hotels); $this->hotels = $hotels; return $post; }
/** * Method to build an SQL query to load the list data. * * @return string An SQL query * * @since 1.6 */ protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select all fields from the table. $query->select($this->getState('list.select', 'c.confirmation_id,c.hotel_id, c.start_date, c.end_date, c.first_name,c.cancellation_notes , c.last_name, c.reservation_status, c.voucher, c.created, c.adults, c.children,c.rooms, c.total')); $query->from($db->quoteName('#__hotelreservation_confirmations') . ' AS c'); $query->select('h.hotel_name'); $query->join('LEFT', '#__hotelreservation_hotels AS h ON c.hotel_id=h.hotel_id'); $query->select(' sum(cr.adults) as total_adults,sum(cr.adults) as total_children'); $query->join('LEFT', '#__hotelreservation_confirmations_rooms AS cr ON c.confirmation_id=cr.confirmation_id'); $query->select('s.status_reservation_name, s.bkcolor, s.color, s.is_modif'); $query->join('LEFT', '#__hotelreservation_status_reservation AS s ON c.reservation_status=s.status_reservation_id'); $query->select('min(cp.payment_status) as payment_status, (cp.amount) as amount_paid'); $query->join('LEFT', '#__hotelreservation_confirmations_payments as cp on c.confirmation_id= cp.confirmation_id'); //if other than super user restrict hotels $userId = JFactory::getUser()->id; if (!(isSuperUser($userId) || isManager($userId))) { $query->join('INNER', $db->quoteName('#__hotelreservation_user_hotel_mapping') . ' AS hum ON h.hotel_id=hum.hotel_id'); $query->where("hum.user_id = " . $userId); } // Filter by search in title. $search = $this->getState('filter.search'); if (!empty($search)) { if (is_numeric($search)) { $query->where("c.confirmation_id={$search}"); } else { $query->where("(c.first_name LIKE '%{$search}%' or c.last_name LIKE '%{$search}%' or h.hotel_name LIKE '%{$search}%')"); } } // Filter by search in title. $searchVoucher = $this->getState('filter.voucher'); if (!empty($searchVoucher)) { //dmp($searchVoucher); $query->where("c.voucher LIKE '%" . $searchVoucher . "%'"); } $searchStartDate = $this->getState('filter.start_date'); $searchEndDate = $this->getState('filter.end_date'); if (!empty($searchEndDate) && !empty($searchStartDate)) { $query->where("c.start_date between '" . JHotelUtil::convertToMysqlFormat($searchStartDate) . "' and '" . JHotelUtil::convertToMysqlFormat($searchEndDate) . "'"); } else { if (!empty($searchStartDate)) { $query->where("c.start_date >= " . JHotelUtil::convertToMysqlFormat($searchStartDate)); } } // Filter the items over the menu id if set. $hotelId = $this->getState('filter.hotel_id'); if (!empty($hotelId)) { $query->where('h.hotel_id = ' . $hotelId); } // Filter the items over the menu id if set. $roomId = $this->getState('filter.room_type'); if (!empty($roomId)) { $query->where('cr.room_id = ' . $roomId); } // Filter the items over the menu id if set. $status = $this->getState('filter.status'); if (!empty($status)) { $query->where('s.status_reservation_id = ' . $status); } // Filter the items over the menu id if set. $payment_status = $this->getState('filter.payment_status'); if ($payment_status != -1 && $payment_status != "") { $query->where('cp.payment_status = ' . $db->quote($payment_status)); } $query->group('c.confirmation_id'); // Add the list ordering clause. $query->order($db->escape($this->getState('list.ordering', 'c.confirmation_id')) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))); return $query; }
/** * Method to save the form data. * * @param array The form data. * @return boolean True on success. */ public function save($data) { $id = !empty($data['id']) ? $data['id'] : (int) $this->getState('excursion.id'); $isNew = true; for ($day = 1; $day <= 7; $day++) { if (!isset($data["excursion_day_{$day}"])) { $data["excursion_day_{$day}"] = 0; } } // Get a row instance. $table = $this->getTable(); $data['excursion_order'] = $table->getExcursionOrder(); // Load the row if saving an existing item. if ($id > 0) { $table->load($id); $isNew = false; } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } $table->name = $data["excursion_name"]; $table->data_start = JHotelUtil::convertToMysqlFormat($data["data_start"]); $table->data_end = JHotelUtil::convertToMysqlFormat($data["data_end"]); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } $this->setState('excursion.id', $table->id); // Clean the cache $this->cleanCache(); return true; }
/** * Method to save the form data. * * @param array The form data. * @return boolean True on success. */ function store($data) { // dmp($data); // exit; $data['offer_datas'] = JHotelUtil::convertToMysqlFormat($data['offer_datas']); $data['offer_datae'] = JHotelUtil::convertToMysqlFormat($data['offer_datae']); $data['offer_datasf'] = JHotelUtil::convertToMysqlFormat($data['offer_datasf']); $data['offer_dataef'] = JHotelUtil::convertToMysqlFormat($data['offer_dataef']); try { //$this->_db->BeginTrans(); $query = "START TRANSACTION;"; $this->_db->setQuery($query); $this->_db->queryBatch(); $row = $this->getTable('ManageOffers', 'Table'); $data['offer_order'] = $row->getOfferOrder(); //dmp($data); //exit; // Bind the form fields to the table if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); return false; } // Make sure the record is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); return false; } // Store the web link table to the database if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); return false; } if ($data['offer_id'] == '' || $data['offer_id'] == 0 || $data['offer_id'] == null) { $data['offer_id'] = $this->_db->insertid(); } $this->setState('offer.offer_id', $data['offer_id']); $this->_offer_id = $data['offer_id']; $this->storeVouchers($data); $this->storePictures($data); $this->storeRooms($data); $this->storeRate($data); $this->storeThemes($data); //store extra options $this->storeExtraOptions($this->_offer_id, $data["extra_options_ids"]); $this->storeOfferExcursions($this->getState('offer.offer_id'), $data["excursion_ids"]); $query = "COMMIT"; $this->_db->setQuery($query); $this->_db->queryBatch(); } catch (Exception $ex) { dmp($ex); // exit; //$this->_db->RollbackTrans(); $query = "ROLLBACK"; $this->_db->setQuery($query); $this->_db->queryBatch(); return false; } return true; }
/** * Method to save the form data. * * @param array The form data. * @return boolean True on success. */ public function save($data) { $id = !empty($data['id']) ? $data['id'] : (int) $this->getState('extraoption.id'); $isNew = true; $data["start_date"] = JHotelUtil::convertToMysqlFormat($data["start_date"]); $data["end_date"] = JHotelUtil::convertToMysqlFormat($data["end_date"]); // Get a row instance. $table = $this->getTable(); // Load the row if saving an existing item. if ($id > 0) { $table->load($id); $isNew = false; } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } $this->setState('extraoption.id', $table->id); // Clean the cache $this->cleanCache(); if ($id == 0) { $this->storePicture($data["image_path"], $table->id, $id); } return true; }
function getDetailedAvailabilityReport() { $report = array(); $startDate = JHotelUtil::convertToMysqlFormat($this->getState('filter.start_date')); $endDate = JHotelUtil::convertToMysqlFormat($this->getState('filter.end_date')); $hotelId = $this->getState('filter.hotel_id'); $query = "select *\r\n\t\t\t\t from #__hotelreservation_confirmations hc\r\n\t\t\t\t inner join #__hotelreservation_confirmations_rooms hcr on hcr.confirmation_id \t\t= hc.confirmation_id\r\n\t\t\t\t inner join #__hotelreservation_status_reservation hsr on hsr.status_reservation_id\t= hc.reservation_status\r\n\t\t\t\t where ((hc.start_date >='{$startDate}' and hc.end_date <='{$endDate}') or ('{$startDate}' between hc.start_date and hc.end_date) or ('{$endDate}' between hc.start_date and hc.end_date)) and hc.hotel_id = {$hotelId}\r\n\t\t\t\t order by hc.start_date, hc.end_date\r\n\t\t\t\t\t"; $bookings = $this->_getList($query); // dmp($query); // dmp($bookings); //dmp(count($bookings)); if (count($bookings)) { foreach ($bookings as $booking) { if (!isset($report[$booking->room_id])) { $report[$booking->room_id][] = array($booking); //dmp("add first id:".$booking->confirmation_id); } else { $levels =& $report[$booking->room_id]; $index = 0; $added = false; foreach ($levels as $i => &$level) { $lastBooking = end($level); if (strtotime($lastBooking->end_date) <= strtotime($booking->start_date)) { $level[] = $booking; $added = true; //dmp($level); //dmp("Add B". $booking->confirmation_id." L:".$i." C: ".count($level)); break; } } if (!$added) { //debug_zval_dump($booking); //dmp("create new level add: ".$booking->confirmation_id); $report[$booking->room_id][] = array($booking); } } } } return $report; }
function store($data) { try { $this->_db->BeginTrans(); $row = $this->getTable('hotels'); //$data["hotel_description"]= strip_tags($data["hotel_description"]); $this->checkHotelRestrictions($data['hotel_id']); $data['start_date'] = JHotelUtil::convertToMysqlFormat($data['start_date']); $data['end_date'] = JHotelUtil::convertToMysqlFormat($data['end_date']); //dmp($data); //exit; // Bind the form fields to the table if (!$row->bind($data)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); // return false; } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); // return false; } // Store the web link table to the database if (!$row->store()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); // return false; } if ($data['hotel_id'] == '' || $data['hotel_id'] == 0 || $data['hotel_id'] == null) { $data['hotel_id'] = $this->_db->insertid(); $this->_hotel_id = $data['hotel_id']; self::copyEmailContent($this->_hotel_id); } //prepare photos $managePictures = JRequest::getVar("manage_pictures", null); if (!empty($managePictures)) { $path_old = JHotelUtil::makePathFile(JPATH_ROOT . DS . PATH_HOTEL_PICTURES . ($data['hotel_id'] + 0) . "/"); $files = glob($path_old . "*.*"); $path_new = JHotelUtil::makePathFile(JPATH_ROOT . DS . PATH_HOTEL_PICTURES . ($data['hotel_id'] + 0) . "/"); //dmp($data); //dmp($data['pictures']); //exit; $picture_ids = array(); foreach ($data['pictures'] as $value) { $row = $this->getTable('ManageHotelPictures'); //dmp($key); $pic = new stdClass(); $pic->hotel_picture_id = 0; $pic->hotel_id = $data['hotel_id']; $pic->hotel_picture_info = $value['hotel_picture_info']; $pic->hotel_picture_path = $value['hotel_picture_path']; $pic->hotel_picture_enable = $value['hotel_picture_enable']; $file_tmp = JHotelUtil::makePathFile($path_old . basename($pic->hotel_picture_path)); if (!is_file($file_tmp)) { continue; } if (!is_dir($path_new)) { if (!@mkdir($path_new)) { throw new Exception($this->_db->getErrorMsg()); } } //dmp(($path_old.basename($pic->hotel_picture_path).",".$path_new.basename($pic->hotel_picture_path))); //exit; if ($path_old . basename($pic->hotel_picture_path) != $path_new . basename($pic->hotel_picture_path)) { if (@rename($path_old . basename($pic->hotel_picture_path), $path_new . basename($pic->hotel_picture_path))) { $pic->hotel_picture_path = PATH_HOTEL_PICTURES . ($data['hotel_id'] + 0) . '/' . basename($pic->hotel_picture_path); //@unlink($path_old.basename($pic->room_picture_path)); } else { throw new Exception($this->_db->getErrorMsg()); } } if (!$row->bind($pic)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } $picture_ids[] = $this->_db->insertid(); } //dmp($picture_ids); $files = glob($path_new . "*.*"); foreach ($files as $pic) { $is_find = false; foreach ($data['pictures'] as $value) { $path = JHotelUtil::makePathFile(JPATH_ROOT . DS . $value['hotel_picture_path']); if ($pic == JHotelUtil::makePathFile(JPATH_ROOT . DS . $value['hotel_picture_path'])) { $is_find = true; break; } } //if( $is_find == false ) //@unlink( $pic ); } $query = " DELETE FROM #__hotelreservation_hotel_pictures\n\t\t\t\t\t\t\tWHERE hotel_id = '" . $data['hotel_id'] . "'\n\t\t\t\t\t\t\t" . (count($picture_ids) > 0 ? " AND hotel_picture_id NOT IN (" . implode(',', $picture_ids) . ")" : ""); //dmp($query); //exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } } //~prepare photos //prepare payments default /* $query = " INSERT INTO #__hotelreservation_paymentsettings ( hotel_id, payment_type_id, payment_name, payment_percent, payment_value, payment_days, payment_order, payment_status, is_check_days, is_available ) SELECT ".$data['hotel_id'].", h1.payment_type_id , h1.payment_name, h1.payment_percent, h1.payment_value, h1.payment_days, h1.payment_order, h1.payment_status, h1.is_check_days, h1.is_available FROM #__hotelreservation_paymentsettings h1 WHERE h1.payment_type_id NOT IN ( SELECT h2.payment_type_id FROM #__hotelreservation_paymentsettings h2 WHERE h2.hotel_id = ".$data['hotel_id']." ) AND h1.hotel_id = 0 "; */ //dmp($query); //exit; /* $this->_db->setQuery( $query ); if (!$this->_db->query()) { throw( new Exception($this->_db->getErrorMsg()) ); } */ //~prepare payments default $query = " DELETE FROM #__hotelreservation_hotel_facility_relation WHERE hotelId = " . $data['hotel_id']; //dmp($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } if (isset($data['facilities'])) { //prepare facilities //dmp($data['facilities']); foreach ($data['facilities'] as $facility) { $row = $this->getTable('ManageHotelFacilityRelation'); $facilityRelation->hotelId = $data['hotel_id']; $facilityRelation->facilityId = $facility; //dmp($facilityRelation); if (!$row->bind($facilityRelation)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store(true)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } } } $query = " DELETE FROM #__hotelreservation_hotel_type_relation\r\n\t\t\tWHERE hotelId = " . $data['hotel_id']; // dmp($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } if (isset($data['types'])) { //prepare types //dmp($data['types']); foreach ($data['types'] as $type) { //dmp("step"); $row = $this->getTable('ManageHotelTypeRelation'); $typeRelation->hotelId = $data['hotel_id']; $typeRelation->typeId = $type; //dmp($typeRelation); if (!$row->bind($typeRelation)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store(true)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } } } $query = " DELETE FROM #__hotelreservation_hotel_accommodation_type_relation\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE hotelId = " . $data['hotel_id']; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } if (isset($data['accommodationtypes'])) { //prepare accommodationTypes //dmp($data['accommodationtypes']); foreach ($data['accommodationtypes'] as $type) { $row = $this->getTable('ManageHotelAccommodationTypeRelation'); $accommodationTypeRelation->hotelId = $data['hotel_id']; $accommodationTypeRelation->accommodationtypeId = $type; //dmp($accommodationTypeRelation); if (!$row->bind($accommodationTypeRelation)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store(true)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } } } //prepare environments //dmp($data['environments']); $query = " DELETE FROM #__hotelreservation_hotel_environment_relation\r\n\t\t\t\t\t\tWHERE hotelId = " . $data['hotel_id']; // dmp($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } if (isset($data['environments'])) { foreach ($data['environments'] as $environment) { $row = $this->getTable('ManageHotelEnvironmentRelation'); $environmentRelation->hotelId = $data['hotel_id']; $environmentRelation->environmentId = $environment; //dmp($environmentRelation); if (!$row->bind($environmentRelation)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store(true)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } } } //prepare regions // dmp($data['regions']); $query = " DELETE FROM #__hotelreservation_hotel_region_relation\r\n\t\t\t\t\t\tWHERE hotelId = " . $data['hotel_id']; // dmp($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } if (isset($data['regions'])) { foreach ($data['regions'] as $region) { $row = $this->getTable('ManageHotelRegionRelation'); $regionRelation->hotelId = $data['hotel_id']; $regionRelation->regionId = $region; // dmp($regionRelation); if (!$row->bind($regionRelation)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store(true)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } } } $data["id"] = $data["informationId"]; //dmp($data); //exit; $row = $this->getTable('managehotelinformations'); if (!$row->bind($data)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store(true)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } $data["id"] = $data["contactId"]; $row = $this->getTable('hotelcontact'); if (!$row->bind($data)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store(true)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } //prepare payment options //dmp($data['regions']); if (isset($data['paymentOptions'])) { $query = " DELETE FROM #__hotelreservation_hotel_payment_option_relation\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE hotelId = " . $data['hotel_id']; //dmp($query); $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } foreach ($data['paymentOptions'] as $paymentOption) { $row = $this->getTable('managehotelpaymentoptionrelation'); $paymentRelation->hotelId = $data['hotel_id']; $paymentRelation->paymentOptionId = $paymentOption; if (!$row->bind($paymentRelation)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store(true)) { throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } } } //save channel manager data $user = $data["cubilis_user"]; $password = $data["cubilis_password"]; if (isset($user) && isset($password)) { $channel = CHANNEL_MANAGER_CUBILIS; $hotel_id = $data['hotel_id']; $query = "INSERT INTO #__hotelreservation_hotel_channel_manager (hotel_id, service, user, password) VALUES ({$hotel_id}, '{$channel}', '{$user}','{$password}')\t\n\t\t\t\t\t\t ON DUPLICATE KEY UPDATE user = '******', password = '******' "; $this->_db->setQuery($query); if (!$this->_db->query()) { $ret = false; $e = 'INSERT / UPDATE sql STATEMENT error !'; } } $this->_db->CommitTrans(); } catch (Exception $ex) { dmp($ex); exit; $this->_db->RollbackTrans(); return false; } return true; }
function store($data) { $row = $this->getTable(); $data['discount_datas'] = JHotelUtil::convertToMysqlFormat($data['discount_datas']); $data['discount_datae'] = JHotelUtil::convertToMysqlFormat($data['discount_datae']); // Bind the form fields to the table if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } // Make sure the record is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } // Store the web link table to the database if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; }