/** * 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; } } } }
function &getData() { // Load the data if (empty($this->_data)) { $query = " SELECT \r\n\t\t\t\t\t\t\t\tc.*\r\n\t\t\t\t\t\t\tFROM #__hotelreservation_confirmations c\r\n\t\t\t\t\t\t" . " WHERE c.confirmation_id = " . $this->_confirmation_id; $this->_db->setQuery($query); // dmp($this->_db); $this->_data = $this->_db->loadObject(); //dmp($this->_data); $modelVariables = new JHotelReservationModelVariables($this->_data->hotel_id); $modelVariables->edit_mode = 1; JRequest::setVar('tip_oper', 5); $post = JRequest::get('post'); $params = array(); if (isset($post["room_guests"])) { $params["room_guests"] = $post["room_guests"]; } $modelVariables->load($this->_data->confirmation_id, $this->_data->email, $modelVariables->itemCurrency, $params); $modelVariables->checkAvalability(); return $modelVariables; } return $this->_data; }