function store($post) { //dump($post); $this->tip_oper = JRequest::getInt('tip_oper'); $this->key_control_reservation = isset($_SESSION['key_control_reservation']) ? $_SESSION['key_control_reservation'] : ''; // dbg($_SESSION); if (count($post) > 0) { if (isset($post['reserve_room_id'])) { $this->reserve_room_id = $post['reserve_room_id']; } if (isset($post['reserve_offer_id'])) { $this->reserve_offer_id = $post['reserve_offer_id']; } if (isset($post['reserve_current'])) { $this->reserve_current = $post['reserve_current']; } if (!isset($post['items_reserved'])) { $post['items_reserved'] = array(); } if (isset($post['items_reserved'])) { $this->items_reserved = $post['items_reserved']; } if (isset($this->items_reserved)) { $sorted_items = array(); foreach ($this->items_reserved as $itemReserved) { $values = explode("|", $itemReserved); $sorted_items[$values[2] - 1] = $itemReserved; } ksort($sorted_items); $this->items_reserved = $sorted_items; //dump($this->items_reserved); } $session = JFactory::getSession(); $userData = $_SESSION['userData']; /* if( isset($userData) ) { $post["year_start"] = $userData->year_start; $post["month_start"] = $userData->month_start; $post["day_start"] = $userData->day_start; $post["year_end"] = $userData->year_end; $post["month_end"] = $userData->month_end; $post["day_end"] = $userData->day_end; $post["guest_adult"] = $userData->adults; $post["guest_child"] = $userData->childrens; } else { $post["year_start"] = ''; $post["month_start"] = ''; $post["day_start"] = ''; $post["year_end"] = ''; $post["month_end"] = ''; $post["day_end"] = ''; $post["guest_adult"] = ''; $post["guest_child"] = ''; } */ if (isset($post['reservation_status'])) { $this->reservation_status = $post['reservation_status']; } if (isset($post['year_start'])) { $this->year_start = $post['year_start']; } else { if (isset($post['jhotelreservation_datas'])) { $this->year_start = date('Y', strtotime($post['jhotelreservation_datas'])); } } if (isset($post['month_start'])) { $this->month_start = $post['month_start']; } else { if (isset($post['jhotelreservation_datas'])) { $this->month_start = date('m', strtotime($post['jhotelreservation_datas'])); } } if (isset($post['day_start'])) { $this->day_start = $post['day_start']; } else { if (isset($post['jhotelreservation_datas'])) { $this->day_start = date('d', strtotime($post['jhotelreservation_datas'])); } } if (isset($post['year_end'])) { $this->year_end = $post['year_end']; } else { if (isset($post['jhotelreservation_datae'])) { $this->year_end = date('Y', strtotime($post['jhotelreservation_datae'])); } } if (isset($post['month_end'])) { $this->month_end = $post['month_end']; } else { if (isset($post['jhotelreservation_datae'])) { $this->month_end = date('m', strtotime($post['jhotelreservation_datae'])); } } if (isset($post['day_end'])) { $this->day_end = $post['day_end']; } else { if (isset($post['jhotelreservation_datae'])) { $this->day_start = date('d', strtotime($post['jhotelreservation_datae'])); } } if (isset($post['datas']) && strlen($post['datas']) == 10) { $post['datas'] = convertToMysqlFormat($post['datas']); $d = explode("-", $post['datas']); $this->day_start = $d[2]; $this->month_start = $d[1]; $this->year_start = $d[0]; } if (isset($post['datae']) && strlen($post['datae']) == 10) { $post['datae'] = convertToMysqlFormat($post['datae']); $d = explode("-", $post['datae']); $this->day_end = $d[2]; $this->month_end = $d[1]; $this->year_end = $d[0]; } if (isset($post['rooms'])) { $this->rooms = $post['rooms']; } if (isset($post['confirmation_id'])) { $this->confirmation_id = $post['confirmation_id']; } //dump($post['guest_adult']); if (isset($post['room_guests'])) { $this->room_guests = explode(",", $post['room_guests']); } else { if (isset($userData->roomGuests)) { $this->room_guests = $userData->roomGuests; } else { if ($this->rooms > 1) { $this->room_guests = array(); for ($i = 0; $i < $this->rooms; $i++) { $this->room_guests[] = isset($post['guest_adult']) ? $post['guest_adult'] : 2; } } else { $this->room_guests = isset($post['guest_adult']) ? $post['guest_adult'] : 2; } } } //dump($post['room_guests']); //dump($this->room_guests); if (isset($post['hotel_id'])) { $this->hotel_id = $post['hotel_id']; } if (isset($post['voucher'])) { $this->voucher = $post['voucher']; } if (isset($post['mediaReferer'])) { $this->mediaReferer = $post['mediaReferer']; } if (isset($post['voucher'])) { $this->voucher = $post['voucher']; } if (isset($post['discount_code'])) { $this->discount_code = $post['discount_code']; } $this->tabId = JRequest::getVar("tabId"); if (!isset($this->tabId) || $this->tabId == 0) { $this->tabId = 1; } if (isset($post['guest_adult'])) { $this->guest_adult = $post['guest_adult']; } if (isset($post['guest_child'])) { $this->guest_child = $post['guest_child']; } if (isset($post['coupon_code'])) { $this->coupon_code = $post['coupon_code']; } //if( isset($post['option_ids']) ) if (!isset($post['option_ids'])) { $post['option_ids'] = ''; } if (isset($post['option_ids'])) { $this->option_ids = is_array($post['option_ids']) ? $post['option_ids'] : explode(',', $post['option_ids']); } if (!isset($post['room_ids'])) { $post['room_ids'] = ''; } if (isset($post['room_ids'])) { $this->room_ids = is_array($post['room_ids']) ? $post['room_ids'] : explode(',', $post['room_ids']); } $this->prepareArray(5, $post['package_ids'], $this->package_ids); //dbg($this->package_ids); $this->prepareArray(0, $post['package_day'], $this->package_day); //if($this->confirmation_id == 0) $this->prepareArray(2, $post['itemPackageNumbers'], $this->itemPackageNumbers); //else // $this->itemPackageNumbers = $this->getPackageNumbers( $this->confirmation_id ); $this->prepareArray(1, $post['arrival_option_ids'], $this->arrival_option_ids); $this->prepareArray(1, $post['extraOptionIds'], $this->extraOptionIds); $this->prepareArray(4, $post['airport_airline_ids'], $this->airport_airline_ids); $this->prepareArray(4, $post['airport_transfer_type_ids'], $this->airport_transfer_type_ids); $this->prepareArray(4, $post['airport_transfer_dates'], $this->airport_transfer_dates); $this->prepareArray(4, $post['airport_transfer_time_hours'], $this->airport_transfer_time_hours); $this->prepareArray(4, $post['airport_transfer_time_mins'], $this->airport_transfer_time_mins); $this->prepareArray(4, $post['airport_transfer_flight_nrs'], $this->airport_transfer_flight_nrs); $this->prepareArray(4, $post['airport_transfer_guests'], $this->airport_transfer_guests); //dump($this->extraOptionIds); //settings persons and days for extra foreach ($this->extraOptionIds as &$extraOption) { if ($extraOption[5] > 0 || $extraOption[6] > 0) { continue; } if (isset($post["extra-option-days-" . $extraOption[3]])) { $extraOption[6] = $post["extra-option-days-" . $extraOption[3]]; } if (isset($post["extra-option-persons-" . $extraOption[3]])) { $extraOption[5] = $post["extra-option-persons-" . $extraOption[3]]; } } //dump($this->extraOptionIds); //saving guest informations if (isset($post['payment_name'])) { $this->payment_name = $post['payment_name']; } if (isset($post['payment_tel'])) { $this->payment_tel = $post['payment_tel']; } if (isset($post['payment_code'])) { $this->payment_code = $post['payment_code']; } if (isset($post['guest_first_name'])) { $this->guest_first_name = $post['guest_first_name']; } if (isset($post['guest_last_name'])) { $this->guest_last_name = $post['guest_last_name']; } if (isset($post['guest_identification_number'])) { $this->guest_identification_number = $post['guest_identification_number']; } if (isset($post['company_name'])) { $this->company_name = $post['company_name']; } if (isset($post['guest_type'])) { $this->guest_type = $post['guest_type']; } if (isset($post['first_name'])) { $this->first_name = $post['first_name']; } if (isset($post['last_name'])) { $this->last_name = $post['last_name']; } if (isset($post['details'])) { $this->details = $post['details']; } if (isset($post['address'])) { $this->address = $post['address']; } if (isset($post['city'])) { $this->city = $post['city']; } if (isset($post['state_name'])) { $this->state_name = $post['state_name']; } if (isset($post['country'])) { $this->country = $post['country']; } if (isset($post['postal_code'])) { $this->postal_code = $post['postal_code']; } if (isset($post['tel'])) { $this->tel = $post['tel']; } if (isset($post['email'])) { $this->email = $post['email']; } if (isset($post['conf_email'])) { $this->conf_email = $post['conf_email']; } if (isset($post['card_type_id'])) { $this->card_type_id = $post['card_type_id']; } if (isset($post['card_name'])) { $this->card_name = $post['card_name']; } if (isset($post['card_number'])) { $this->card_number = $post['card_number']; } if (isset($post['card_expiration_month'])) { $this->card_expiration_month = $post['card_expiration_month']; } if (isset($post['card_expiration_year'])) { $this->card_expiration_year = $post['card_expiration_year']; } if (isset($post['card_security_code'])) { $this->card_security_code = $post['card_security_code']; } if (isset($post['card_type'])) { $this->card_type = $this->getCardTypeById($this->card_type_id); } if (isset($post['confirmation_payment_status'])) { $this->confirmation_payment_status = $post['confirmation_payment_status']; } if (isset($post['email_confirmation'])) { $this->email_confirmation = $post['email_confirmation']; } if (isset($post['room_available_ids'])) { $this->room_available_ids = is_array($post['room_available_ids']) ? $post['room_available_ids'] : explode(',', $post['room_available_ids']); } if (isset($post['room_feature_available_ids'])) { $this->room_feature_available_ids = is_array($post['room_feature_available_ids']) ? $post['room_feature_available_ids'] : explode(',', $post['room_feature_available_ids']); } $this->itemCurrency = $this->getCurrency(); if (isset($post['currency_selector'])) { $this->currency_selector = $post['currency_selector']; } else { if ((!isset($post['currency_selector']) || $post['currency_selector'] == '') && $this->itemCurrency) { $this->currency_selector = $this->itemCurrency->description; } } if (isset($post['itemRoomsCapacity'])) { if (is_array($post['itemRoomsCapacity'])) { $ex = array(); foreach ($post['itemRoomsCapacity'] as $v) { $ex1 = explode('|', $v); if (count($ex1) == 3) { $ex[$ex1[0]] = array($ex1[1], $ex1[2]); } } $this->itemRoomsCapacity = $ex; } else { $ex = explode(',', $post['itemRoomsCapacity']); foreach ($ex as $value) { $ex1 = explode('|', $value); if (count($ex1) == 3) { $this->itemRoomsCapacity[$ex1[0]] = array($ex1[1], $ex1[2]); } } } } else { if ($this->confirmation_id > 0) { $this->itemRoomsCapacity = $this->getRoomsCapacity($this->confirmation_id); } } if (isset($post['itemArrivalOptions'])) { if (is_array($post['itemArrivalOptions'])) { $this->itemArrivalOptions = $post['itemArrivalOptions']; } else { $ex = explode(',', $post['itemArrivalOptions']); $this->itemArrivalOptions = $ex; } } // dbg($post); if (isset($post['itemRoomsNumbers'])) { if (is_array($post['itemRoomsNumbers'])) { $ex = array(); foreach ($post['itemRoomsNumbers'] as $v) { $ex1 = explode('|', $v); if (count($ex1) == 4) { $ex[$ex1[0] . '|' . $ex1[1] . '|' . $ex1[2]] = $ex1[3]; } } $this->itemRoomsNumbers = $ex; } else { $ex = explode(',', $post['itemRoomsNumbers']); foreach ($ex as $value) { $ex1 = explode('|', $value); if (count($ex1) == 4) { $this->itemRoomsNumbers[$ex1[0] . '|' . $ex1[1] . '|' . $ex1[2]] = $ex1[1]; } } } } // dbg($this->key_control_reservation); // dbg($_SESSION); if (isset($post['payment_processor_sel_id'])) { $this->payment_processor_sel_id = $post['payment_processor_sel_id']; } if (isset($post['payment_processor_sel_type'])) { $this->payment_processor_sel_type = $post['payment_processor_sel_type']; } if (isset($post['subscribeToNewsletter'])) { $this->subscribeToNewsletter = $post['subscribeToNewsletter']; } $this->itemHotelSelected = $this->getHotelByID($this->hotel_id); $this->guest_types[] = JHTML::_('select.option', 1, JText::_('LNG_GUEST_TYPE_1', true)); $this->guest_types[] = JHTML::_('select.option', 2, JText::_('LNG_GUEST_TYPE_2', true)); $this->guest_types[] = JHTML::_('select.option', 3, JText::_('LNG_GUEST_TYPE_3', true)); $datas = date("Y-m-d", mktime(0, 0, 0, $this->month_start, $this->day_start, $this->year_start)); $datae = date("Y-m-d", mktime(0, 0, 0, $this->month_end, $this->day_end, $this->year_end)); switch ($this->tip_oper) { case -1: $this->key_control_reservation = $this->getUniqueCode(); $_SESSION['key_control_reservation'] = $this->key_control_reservation; $adults = $this->room_guests; if (is_array($this->room_guests)) { $adults = $this->room_guests[$this->getReservedItems()]; } $this->roomsAvailable = $this->getHotelRooms($this->hotel_id, $datas, $datae, array(), $adults, $adults); $this->offersAvailable = $this->getHotelOffers($this->hotel_id, $datas, $datae, array(), $adults, $adults); $this->checkRoomAvailability($this->roomsAvailable, $this->items_reserved, $this->hotel_id, $datas, $datae); $this->checkRoomAvailability($this->offersAvailable, $this->items_reserved, $this->hotel_id, $datas, $datae); $this->setRoomDisplayPrice($this->roomsAvailable); $this->setOfferDisplayPrice($this->offersAvailable); $this->cleanAllUnwantedReservations(); break; case 2: $this->key_control_reservation = $this->getUniqueCode(); $_SESSION['key_control_reservation'] = $this->key_control_reservation; $adults = $this->room_guests; if (is_array($this->room_guests)) { $adults = $this->room_guests[$this->getReservedItems()]; } $this->roomsAvailable = $this->getHotelRooms($this->hotel_id, $datas, $datae, array(), $adults, $adults); $this->offersAvailable = $this->getHotelOffers($this->hotel_id, $datas, $datae, array(), $adults, $adults); $this->setRoomDisplayPrice($this->roomsAvailable); $this->setOfferDisplayPrice($this->offersAvailable); $this->itemPackages = $this->getPackages($this->package_ids); $this->itemArrivalOptions = $this->getArrivalOptions($this->arrival_option_ids); $this->itemAirportTransferTypes = $this->getAirportTransferTypes($this->airport_transfer_type_ids); $this->itemArrivalAirlines = $this->getArrivalAirlines($this->airport_airline_ids); break; case 3: $this->key_control_reservation = $this->getUniqueCode(); $_SESSION['key_control_reservation'] = $this->key_control_reservation; $roomReserved = $this->items_reserved[$this->getReservedItems() - 1]; $roomReservedInfo = explode("|", $roomReserved); $this->extraOptions = $this->getHotelExtraOptions($this->hotel_id, $datas, $datae, array(), $roomReservedInfo[1], $roomReservedInfo[0]); $this->itemPackages = $this->getPackages($this->package_ids); $this->itemArrivalOptions = $this->getArrivalOptions($this->arrival_option_ids); $this->itemAirportTransferTypes = $this->getAirportTransferTypes($this->airport_transfer_type_ids); $this->itemArrivalAirlines = $this->getArrivalAirlines($this->airport_airline_ids); //$this->itemPaymentProcessors = $this->getPaymentProcessors(); break; case 4: //dump($this->items_reserved); $this->itemTypeCards = $this->getTypeCards(); $this->roomsAvailable = array(); //$this->getRoomsAvailable();//$this->room_available_ids); $this->itemRoomsSelected = array(); $sorted_items = array(); foreach ($this->items_reserved as $room_reserved) { //dump($room_reserved); $values = explode("|", $room_reserved); $nr_guests = 0; //dump($values); //dump($this->room_guests ); if (isset($this->room_guests)) { $nr_guests = $this->room_guests[$values[2] - 1]; } //dump($values); $itemSelected = null; if ($values[0] == 0) { $itemSelected = $this->getHotelRooms($this->hotel_id, $datas, $datae, array($values[1]), $nr_guests, 0); } else { $itemSelected = $this->getHotelOffers($this->hotel_id, $datas, $datae, array($room_reserved), $nr_guests, 0); } $this->itemRoomsSelected[$values[2] - 1] = $itemSelected[0]; $sorted_items[$values[2] - 1] = $room_reserved; } ksort($this->itemRoomsSelected); ksort($sorted_items); foreach ($this->itemRoomsSelected as $index => $item) { $item->current = $index + 1; } $this->items_reserved = $sorted_items; $this->itemPackages = $this->getPackages($this->package_ids); $this->itemArrivalOptions = $this->getArrivalOptions($this->arrival_option_ids); if (isset($this->extraOptionIds) && count($this->extraOptionIds) > 0) { $this->extraOptions = $this->getHotelExtraOptions($this->hotel_id, $datas, $datae, $this->extraOptionIds, $this->reserve_room_id, $this->reserve_offer_id); } $this->itemAirportTransferTypes = $this->getAirportTransferTypes($this->airport_transfer_type_ids); $this->itemArrivalAirlines = $this->getArrivalAirlines($this->airport_airline_ids); $this->itemFeatureOptions = $this->getFeatureOptions($this->option_ids); $this->itemTaxes = $this->getTaxes(); $this->itemPayments = $this->getConfirmationPayments(); $this->itemPaymentProcessors = $this->getPaymentProcessors(); $this->Guest_Details = $this->getGuestDetails(); $this->countries = $this->getCountries(); //dump($this->itemRoomsSelected); foreach ($this->itemRoomsSelected as $room) { if ($room->hasDiscounts) { $this->showDiscounts = true; } if (!isset($this->itemRoomsCapacity[$room->room_id]) || $this->itemRoomsCapacity[$room->room_id][1] == 0) { continue; } //$this->rooms += $this->itemRoomsCapacity[ $room->room_id ][1]; //$this->guest_adult += $this->itemRoomsCapacity[ $room->room_id ][1];// * $room->room_capacity; } if ($this->itemAppSettings->is_enable_payment) { $this->Payment_Information = $this->getPaymentInformation(); } else { $this->Payment_Information = ''; } $this->Reservation_Details = $this->getReservationDetails($this, true); $this->Reservation_Details_EMail = $this->getReservationDetails($this, false); //$this->itemPaymentProcessors = $this->getPaymentProcessors(); break; case 5: $this->itemTypeCards = $this->getTypeCards(); $this->card_type_name = $this->getCardTypeById($this->card_type_id); $this->roomsAvailable = array(); //$this->getRoomsAvailable();//$this->room_available_ids); $this->itemRoomsSelected = array(); $sorted_items = array(); foreach ($this->items_reserved as $room_reserved) { //dump($room_reserved); $values = explode("|", $room_reserved); $nr_guests = 0; //dump($values); //dump($this->room_guests ); if (isset($this->room_guests)) { $nr_guests = $this->room_guests[$values[2] - 1]; } $itemSelected = null; if ($values[0] == 0) { $itemSelected = $this->getHotelRooms($this->hotel_id, $datas, $datae, array($values[1]), $nr_guests, 0); } else { $itemSelected = $this->getHotelOffers($this->hotel_id, $datas, $datae, array($room_reserved), $nr_guests, 0); } $this->itemRoomsSelected[$values[2] - 1] = $itemSelected[0]; $sorted_items[$values[2] - 1] = $room_reserved; } ksort($this->itemRoomsSelected); ksort($sorted_items); foreach ($this->itemRoomsSelected as $index => $item) { $item->current = $index + 1; } //dump($this->itemRoomsSelected); $this->items_reserved = $sorted_items; $this->itemPackages = $this->getPackages($this->package_ids); $this->itemArrivalOptions = $this->getArrivalOptions($this->arrival_option_ids); $this->extraOptions = $this->getHotelExtraOptions($this->hotel_id, $datas, $datae, $this->extraOptionIds, $this->reserve_room_id, $this->reserve_offer_id); $this->itemAirportTransferTypes = $this->getAirportTransferTypes($this->airport_transfer_type_ids); $this->itemArrivalAirlines = $this->getArrivalAirlines($this->airport_airline_ids); $this->itemFeatureOptions = $this->getFeatureOptions($this->option_ids); $this->itemTaxes = $this->getTaxes(); $this->itemPayments = $this->getConfirmationPayments(); $this->itemPaymentProcessors = $this->getPaymentProcessors(); $this->countries = $this->getCountries(); // $this->itemRoomsDiscounts = $this->getRoomsDiscounts(); // $this->rooms = 0; //$this->guest_adult = 0; foreach ($this->itemRoomsSelected as $key_room => $room) { if (!isset($this->itemRoomsCapacity[$room->room_id]) || count($this->itemRoomsCapacity[$room->room_id]) == 0 || $this->itemRoomsCapacity[$room->room_id][1] == 0) { continue; } //$this->rooms += $this->itemRoomsCapacity[ $room->room_id ][1]; //$this->guest_adult += $this->itemRoomsCapacity[ $room->room_id ][1] ;//* $room->room_capacity; } $this->Reservation_Details = $this->getReservationDetails($this, true); $this->Reservation_Details_EMail = $this->getReservationDetails($this, false); $this->Guest_Details = $this->getGuestDetails(); if ($this->itemAppSettings->save_all_guests_data) { $this->GuestsDetails = $this->prepareGuestDetails(); } else { $this->GuestsDetails = ''; } if ($this->itemAppSettings->is_enable_payment) { $this->Payment_Information = $this->getPaymentInformation(); } else { $this->Payment_Information = ''; } $this->Confirmation = $this->getConfirmation(); $this->itemPaymentProcessors = $this->getPaymentProcessors(); break; } } }
function store($data) { // dbg($data); // exit; $data['offer_datas'] = convertToMysqlFormat($data['offer_datas']); $data['offer_datae'] = convertToMysqlFormat($data['offer_datae']); $data['offer_datasf'] = convertToMysqlFormat($data['offer_datasf']); $data['offer_dataef'] = convertToMysqlFormat($data['offer_dataef']); try { //$this->_db->BeginTrans(); $query = "START TRANSACTION;"; $this->_db->setQuery($query); $this->_db->queryBatch(); $row =& $this->getTable(); //dump($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->_offer_id = $data['offer_id']; //update vouchers if ($data["processVouchers"] == 1) { $this->_db->setQuery(" DELETE FROM #__hotelreservation_offers_vouchers\r\n\t\t\t\t\t\t\t\t\t\tWHERE offerId = {$this->_offer_id}"); if (!$this->_db->query()) { // dbg($db); $ret = false; $e = 'INSERT / UPDATE sql STATEMENT error !'; } //dbg($data['vouchers']); if (isset($data['vouchers']) && count($data['vouchers']) > 0) { foreach ($data['vouchers'] as $key => $value) { $recordName = trim($data['vouchers'][$key]); $this->_db->setQuery("\r\n\t\t\t\t\t\t\t\t\t\tINSERT INTO #__hotelreservation_offers_vouchers\r\n\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\tofferId,\r\n\t\t\t\t\t\t\t\t\t\t\tvoucher\r\n\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\t'{$this->_offer_id}',\r\n\t\t\t\t\t\t\t\t\t\t\t'{$recordName}'\r\n\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t"); dbg($recordName); if (!$this->_db->query()) { // dbg($db); $ret = false; $e = 'INSERT / UPDATE sql STATEMENT error !'; } } } } //end update vouchers //exit; //prepare photos $path_old = makePathFile(JPATH_ROOT . DS . PATH_PICTURES . PATH_OFFER_PICTURES . ($data['offer_id'] + 0) . "/"); $files = glob($path_old . "*.*"); $path_new = makePathFile(JPATH_ROOT . DS . PATH_PICTURES . PATH_OFFER_PICTURES . ($data['offer_id'] + 0) . "/"); $picture_ids = array(); foreach ($data['pictures'] as $value) { $row =& $this->getTable('ManageOfferPictures'); // dbg($key); $pic = new stdClass(); $pic->offer_picture_id = 0; $pic->offer_id = $data['offer_id']; $pic->offer_picture_info = $value['offer_picture_info']; $pic->offer_picture_path = $value['offer_picture_path']; $pic->offer_picture_enable = $value['offer_picture_enable']; //dbg($pic); $file_tmp = makePathFile($path_old . basename($pic->offer_picture_path)); if (!is_file($file_tmp)) { continue; } if (!is_dir($path_new)) { if (!@mkdir($path_new)) { throw new Exception($this->_db->getErrorMsg()); } } if ($path_old . basename($pic->offer_picture_path) != $path_new . basename($pic->offer_picture_path)) { if (@rename($path_old . basename($pic->offer_picture_path), $path_new . basename($pic->offer_picture_path))) { $pic->offer_picture_path = PATH_OFFER_PICTURES . ($data['room_id'] + 0) . '/' . basename($pic->offer_picture_path); //@unlink($path_old.basename($pic->offer_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 == makePathFile(JPATH_ROOT . $value['offer_picture_path'])) { $is_find = true; break; } } //if( $is_find == false ) // @unlink( makePathFile(JPATH_COMPONENT.$value['offer_picture_path']) ); } $query = " DELETE FROM #__hotelreservation_offers_pictures \r\n\t\t\t\t\t\tWHERE offer_id = '" . $data['offer_id'] . "'\r\n\t\t\t\t\t\t" . (count($picture_ids) > 0 ? " AND offer_picture_id NOT IN (" . implode(',', $picture_ids) . ")" : ""); // dbg($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } //~prepare photos //room $offer_room_ids = array(); foreach ($data['rooms'] as $value) { $row =& $this->getTable('ManageOfferRooms'); // dbg($key); $offer_room = new stdClass(); $offer_room->offer_id = $data['offer_id']; $offer_room->room_id = $value['room_id']; if (!$row->bind($offer_room)) { 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()); } $offer_room_ids[] = $this->_db->insertid(); } $query = " DELETE FROM #__hotelreservation_offers_rooms \r\n\t\t\t\t\t\tWHERE offer_id = '" . $data['offer_id'] . "'\r\n\t\t\t\t\t\t" . (count($offer_room_ids) > 0 ? " AND offer_room_id NOT IN (" . implode(',', $offer_room_ids) . ")" : ""); // dbg($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } //~room packages dbg($data['rooms']); //exit; //room discounts $room_discount_ids = array(); foreach ($data['rooms'] as $valueRoom) { //dbg( $valueRoom); if (count($valueRoom['offer_price']) > 0) { $offer_price = $valueRoom['offer_price']; $offer_price['offer_id'] = $data['offer_id']; $offer_price['room_id'] = $valueRoom['room_id']; $offer_price['id'] = $offer_price['offer_room_rate_id']; dump($offer_price); //exit; $row =& $this->getTable('OfferRate'); //dump($offer_price); //exit; if (!$row->bind($offer_price)) { dump($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { dump($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store()) { dump($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); $this->setError($this->_db->getErrorMsg()); } $room_discount_ids[] = $this->_db->insertid(); } } //prepare themes //dbg($data['themes']); $query = " DELETE FROM #__hotelreservation_offers_themes_relation\r\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE offerId = " . $data['offer_id']; // dbg($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } foreach ($data['themes'] as $theme) { $row =& $this->getTable('ManageOffersThemesRelation'); $themeRelation->offerId = $data['offer_id']; $themeRelation->themeId = $theme; //dbg($facilityRelation); if (!$row->bind($themeRelation)) { 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()); } } //store extra options $this->storeExtraOptions($this->_offer_id, $data["extra_options_ids"]); $query = "COMMIT"; $this->_db->setQuery($query); $this->_db->queryBatch(); } catch (Exception $ex) { dbg($ex); // exit; //$this->_db->RollbackTrans(); $query = "ROLLBACK"; $this->_db->setQuery($query); $this->_db->queryBatch(); return false; } return true; }
function store($data) { try { $query = "START TRANSACTION;"; $this->_db->setQuery($query); $this->_db->queryBatch(); $row =& $this->getTable(); $data["package_datas"] = convertToMysqlFormat($data["package_datas"]); $data["package_datae"] = convertToMysqlFormat($data["package_datae"]); // Bind the form fields to the table if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); } // Make sure the record is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); } // Store the web link table to the database if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); throw new Exception($this->_db->getErrorMsg()); } if ($data['package_id'] == '' || $data['package_id'] == 0 || $data['package_id'] == null) { $data['package_id'] = $this->_db->insertid(); } if ($data['package_datai'] == null || $data['package_datai'] == 'NaN-NaN-NaN') { $data['package_datai'] = '0000-00-00'; } $di = explode(',', $data['package_datai']); $arr_di = array(); // dbg($di); // exit; foreach ($di as $di_v) { if ($di_v == '0000-00-00' || $di_v == 'NaN-NaN-NaN') { continue; } $row =& $this->getTable('ManagePackagesDatesIgnored'); $d = new stdClass(); $d->package_date_ignored_id = 0; $d->package_id = $data['package_id']; $d->package_date_data = $di_v; 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()); } $arr_di[] = $this->_db->insertid(); } $query = " DELETE FROM #__hotelreservation_packages_date_ignored\r\n\t\t\t\t\t\tWHERE package_id = '" . $data['package_id'] . "'\r\n\t\t\t\t\t\t" . (count($arr_di) > 0 ? " AND package_date_ignored_id NOT IN (" . implode(',', $arr_di) . ")" : ""); // dbg($query); // exit; $this->_db->setQuery($query); if (!$this->_db->query()) { throw new Exception($this->_db->getErrorMsg()); } // dbg($d); //$this->_db->CommitTrans(); $query = "COMMIT"; $this->_db->setQuery($query); $this->_db->queryBatch(); } catch (Exception $ex) { //$this->_db->RollbackTrans(); $query = "ROLLBACK"; $this->_db->setQuery($query); $this->_db->queryBatch(); return false; } return true; }