/application/modules/user/controllers/ReserveController.php
PHP | 325 lines | 247 code | 46 blank | 32 comment | 51 complexity | d4c780665b5826d990bc65fc4abc75a2 MD5 | raw file
- <?php
- require_once 'Reward/Mvc/BaseUserController.php' ;
- require_once 'Reward/Util.php' ;
- require_once 'security/AES.class.php' ;
- require_once 'Reward/UserCommon.php';
- class ReserveController extends BaseUserController{
- public function init(){
- parent::init();
- $this->_helper->layout()->setLayout('layoutfooter');
- $bootstrap = $this->getInvokeArg('bootstrap');
- $this->config = $bootstrap->getOptions();
- }
-
- public function indexAction(){
- $tblHotel = new User_Model_Hotel();
- $tblRoom = new User_Model_Room();
-
- /*
- $hotelID = $this->getSessionUser();
- if(!isset($hotelID) || $hotelID <= 0 || isset($_POST['linkAdmin'])){
- $admin = $this->getSessionAdmin();
- if(!isset($admin) || $admin <= 0 || !isset($_POST['linkAdmin']) || !isset($_POST['hotelID']))
- $this->_redirect('/'.$_SESSION['lang']."/user/login/index");
- $hotelID = $_POST['hotelID'];
- $this->view->assign('typeUser','Admin');
- $this->view->assign('urlUser',$_POST['linkAdmin']);
- }else{
- $this->view->assign('typeUser','Client');
- $this->view->assign('urlUser','/'.$_SESSION['lang'].'/user/client/index');
- }
- */
- $hotelID = $this->getSessionUser();
- //$this->view->assign('HotelID',$hotelID);
-
- //********************* nam code *******************
-
- $admin = $this->getSessionAdmin();
- if(isset($hotelID )){
- $hotelID = $this->getSessionUser();
- }
- else if(isset($admin) && isset($_GET['HotelID']) ){
- $hotelID = $_GET['HotelID'];
- $this->view->assign('typeUser','Admin');
- $this->view->assign('urlUser',$_POST['linkAdmin']);
- $flag = 1;
- $this->view->assign('flag',$flag);
-
- }
- //****************************************************
- if(!isset($hotelID) || $hotelID <= 0 || isset($_POST['linkAdmin'])){
- $admin = $this->getSessionAdmin();
-
- if(!isset($admin) || $admin <= 0 || !isset($_POST['linkAdmin']) || !isset($_POST['hotelID']))
- $this->_redirect('/'.$_SESSION['lang']."/user/login/index");
- $hotelID = $_POST['hotelID'];
- $this->view->assign('typeUser','Admin');
- $this->view->assign('urlUser','/'.$_SESSION['lang'].'/admin/login/index');
- }else{
- $this->view->assign('typeUser','Client');
- $this->view->assign('urlUser','/'.$_SESSION['lang'].'/user/viewbooking/index');
- }
- //**************** phan language ******************
- $translate = Util::language();
-
-
- $this->view->assign('BackToPage', $translate->_('BackToPage'));
- $this->view->assign('NewHotelName', $translate->_('NewHotelName'));
- $this->view->assign('NewDescription', $translate->_('NewDescription'));
- $this->view->assign('NewRating', $translate->_('NewRating'));
- $this->view->assign('UploadandRemove', $translate->_('UploadandRemove'));
- $this->view->assign('HotelFeature', $translate->_('HotelFeature'));
- $this->view->assign('AdditionalFeatures', $translate->_('AdditionalFeatures'));
- $this->view->assign('CheckInTime', $translate->_('CheckInTime'));
- $this->view->assign('CheckOutTime', $translate->_('CheckOutTime'));
- $this->view->assign('ClickThumbnail', $translate->_('ClickThumbnail'));
- $this->view->assign('Days', $translate->_('Days'));
- $this->view->assign('HowToGetThere', $translate->_('HowToGetThere'));
- $this->view->assign('Parking', $translate->_('Parking'));
- $this->view->assign('Thingstodo', $translate->_('Thingstodo'));
- $this->view->assign('CheckinInstruction', $translate->_('CheckinInstruction'));
- $this->view->assign('BussinessFacility', $translate->_('BussinessFacility'));
- $this->view->assign('EditSubroomName', $translate->_('EditSubroomName'));
- $this->view->assign('TypicalPrice', $translate->_('TypicalPrice'));
- $this->view->assign('MinNightStay', $translate->_('MinNightStay'));
- $this->view->assign('RoomChange', $translate->_('RoomChange'));
- $this->view->assign('RoomType', $translate->_('RoomType'));
-
- $this->view->assign('RoomFeatures', $translate->_('RoomFeatures'));
- $this->view->assign('BedConfiguration', $translate->_('BedConfiguration'));
- $this->view->assign('RoomCondition', $translate->_('RoomCondition'));
- $this->view->assign('CancellationPolicy', $translate->_('CancellationPolicy'));
- $this->view->assign('Or', $translate->_('Or'));
- $this->view->assign('TypicalPrice', $translate->_('TypicalPrice'));
-
- $this->view->assign('MinStay', $translate->_('MinStay'));
- $this->view->assign('FullRate', $translate->_('FullRate'));
- $this->view->assign('StarRating', $translate->_('StarRating'));
- $this->view->assign('Confirm', $translate->_('Confirm'));
-
- $this->view->assign('Single', $translate->_('Single'));
- $this->view->assign('Double', $translate->_('Double'));
- $this->view->assign('BunkBed', $translate->_('BunkBed'));
- $this->view->assign('QueenBed', $translate->_('QueenBed'));
- $this->view->assign('KingBed', $translate->_('KingBed'));
- $this->view->assign('TwinBed', $translate->_('TwinBed'));
-
- // * phan footer * //
- $this->view->assign('HotelPartners', $translate->_('HotelPartners'));
- $this->view->assign('ContactUs', $translate->_('ContactUs'));
- $this->view->assign('AboutUs', $translate->_('AboutUs'));
- $this->view->assign('TermAndCondition', $translate->_('TermAndCondition'));
- $this->view->assign('Privacy', $translate->_('Privacy'));
- $this->view->assign('Security', $translate->_('Security'));
- $this->view->assign('Feedback', $translate->_('Feedback'));
- $this->view->assign('Help', $translate->_('Help'));
- //*************************************************
- $hotelInfor = $tblHotel->getHotelByID($hotelID);
- $this->view->assign('hotelID',$hotelID);
- if(count($hotelInfor) > 0){
-
- if(isset($_GET['date']) && $_GET['date'] > 0){
- $temp = $_GET['date'];
- }else{
- $temp = time();
- }
- $datenow = mktime(0,0,0,date('m',time()),date('d',time()),date('y',time()));
- if($datenow >= $temp)
- $dateToGet = $datenow;
- else
- $dateToGet = mktime(0,0,0,date('m',$temp),date('d',$temp),date('y',$temp));
-
- if(isset($hotelInfor['PropertyName'])){
- $hotelInfor['PropertyName'] = stripslashes($hotelInfor['PropertyName']);
- }
-
- if(isset($hotelInfor['PropertyDescription'])){
- $hotelInfor['PropertyDescription'] = stripslashes($hotelInfor['PropertyDescription_lang']);
- }
-
- $roomInfor = $tblRoom->getAllRoom($hotelID,$dateToGet);
- $hotelFeat = $tblHotel->getHotelFeature($hotelID);
- if(count($roomInfor) > 0){
- $roomType = array();
- $tblCurrency = new User_Model_Currency();
- $currency = $tblCurrency->getHotelCurrency($hotelID);
-
- foreach ($roomInfor as $infor){
- $all_bed = $tblRoom->getAllBed($infor['RoomID']);
- $roomType[] = array(
- 'RoomID' => $infor['RoomID'],
- 'Name' => stripslashes($infor['RoomName']),
- 'Decription' => stripslashes($infor['Decription_lang']),
- 'Condition' => stripslashes($infor['RoomCondition_lang']),
- 'Image' => $infor['RoomImage'],
- 'NumberofRooms' => $infor['NumberofRooms'],
- 'FullRate' => $currency['CurrencyText'].''.$infor['FullRatePrice'],
- 'MinStay' => $infor['MinStay'],
- 'RoomFeatures' => $tblRoom->getRoomFeature($infor['RoomID']),
- 'PriceList' => $this->getListPriceOfRoom($infor['RoomID'],$infor['NumberofRooms'],$dateToGet,14,$infor['TypicalPrice']),
- 'DateList' => $this->getListDate($dateToGet,14),
- 'BedType' => $all_bed
- );
- }
-
-
- $this->view->assign('listRoom', $roomType);
- }
- $n_date = $dateToGet + (7*24*60*60);
- $p_temp = mktime(0,0,0,date('m',time()),date('d',time()),date('y',time())) + (24*60*60)*7;
- if($dateToGet >= $p_temp){
- $p_date = $dateToGet - (7*24*60*60);
- }else{
- $p_date = $dateToGet;
- }
- $next = '/'.$_SESSION['lang']."/user/reserve/index?HotelID=".$hotelID."&date=".$n_date;
- $previous = '/'.$_SESSION['lang']."/user/reserve/index?HotelID=".$hotelID."&date=".$p_date;
-
- $listImage = $tblHotel->getImageOfHotel($hotelID);
-
- $tblFeature = new User_Model_Feature();
- $listRoomFeature = $tblFeature->getRows(1);
- $listHotelFeature = $tblFeature->getRows(0);
- $listImage = $tblHotel->getImageOfHotel($hotelID);
- $this->view->assign('listRoomFeature',$listRoomFeature);
- $this->view->assign('listHotelFeature',$listHotelFeature);
- if(count($listHotelFeature) > 0 ){
- $temp = ceil(count($listHotelFeature) / 3);
- $this->view->assign('totalHotelFeature',$temp);
- }
- $t_Hfea =array();
- if(isset($sdata['HotelFeature'])){
- foreach ($sdata['HotelFeature'] as $fea) {
- $t_Hfea[] = array('FeatureID' => $fea);
- }
- }else{
- $t_Hfea = $tblHotel->getHotelFeature($hotelID);
- }
- $this->view->assign('hotelFeature',$t_Hfea);
-
- $this->view->assign('HotelFeatures' ,$hotelFeat);
- $this->view->assign('listImage',$listImage);
- $this->view->assign('next',$next);
- $this->view->assign('previous',$previous);
- $this->view->assign('listDate', $this->getListDate($dateToGet,14));
- $this->view->assign('hotelInfor', $hotelInfor);
-
- }else{
- //$this->_redirect("/");
- }
- }
-
- public function successAction(){
- $hotelID = $this->getSessionUser();
- if(!isset($hotelID) || $hotelID <= 0 || isset($_POST['linkAdmin'])){
- $admin = $this->getSessionAdmin();
-
- if(!isset($admin) || $admin <= 0 || !isset($_POST['linkAdmin']) || !isset($_POST['hotelID']))
- $this->_redirect('/'.$_SESSION['lang']."/user/login/index");
- $hotelID = $_POST['hotelID'];
-
- $this->view->assign('typeUser','Admin');
- $this->view->assign('urlUser',$_POST['linkAdmin']);
- }else{
- $this->view->assign('typeUser','Client');
- $this->view->assign('urlUser','/'.$_SESSION['lang'].'/user/client/index');
- }
-
- if(!isset($_POST['r_id']) || !isset($_POST['d_s']) || !isset($_POST['d_e']) || !isset($_POST['n_r']))
- $this->_redirect("/".$_SESSION['lang'].'/user/');
-
- $id = $_POST['r_id'];
- $start = $_POST['d_s'];
- $end = $_POST['d_e'];
- $numb = $_POST['n_r'];
-
- $check_success = 1;
- $tblRoom = new User_Model_Room();
- for($i = $start ; $i <= $end ; $i = $i + 60*60*24){
- $room = $tblRoom->getRoomStock($id,$i);
- $stock = $room['StockRoom'] - $numb;
- if ($stock < 0){
- $check_success = 0;
- break;
- }
- $sold = $room['SoldRoom'] + $numb;
- $result = $tblRoom->updateStockRoom($id,$i,$stock,$sold);
- if($result == -1){
- $check_success = 0;
- }
- }
- $this->view->assign('result',$check_success);
- $this->_helper->layout()->setLayout('layoutsuccess');
- $this->view->assign('hotelID',$hotelID);
- }
-
- /**
- * Funtion to get list of room price by date
- * @param : $RoomID,$NumberOfRoom,$startDate,$toDate
- */
- Function getListPriceOfRoom($RoomID,$NumberOfRoom,$startDate,$toDate,$roomRate){
- $tblRoom = new User_Model_Room();
-
- $roomInfor = $tblRoom->getInforByDate($RoomID,$startDate);
-
- $list = array();
- for($i = 0; $i < $toDate ; $i++){
- $temp = $startDate + (24*60*60)*$i;
- $check = false;
- $idx = 0;
-
- for($j =0;$j<count($roomInfor);$j++){
- if($roomInfor[$j]['StayDate'] == $temp){
- $check = true;
- $idx = $j;
- break;
- }
- }
- if($check == true && $roomInfor[$idx]['Active'] == 1){
- if($roomInfor[$idx]['StockRoom'] == 0 && $roomInfor[$idx]['SoldRoom'] >= $NumberOfRoom){
- $list[$i] = array('price' => 'SOLD','stock' => '0');
- }else{
- if($roomInfor[$idx]['Price'] != NULL && $roomInfor[$idx]['Price'] > 0){
- $list[$i] = array('price' => $roomInfor[$idx]['Price'],'stock' => $roomInfor[$idx]['StockRoom']);
- }else{
- $list[$i] = array('price' => $roomRate,'stock' => $roomInfor[$idx]['StockRoom'] );
- }
- }
- }else{
- $list[$i] = array('price' => '0','stock' => '0');
- }
- }
- return $list;
- }
-
- /**
- *
- * Function to get list of Date
- * @param $startDate ,$toDate
- */
- function getListDate($startDate,$toDate){
- $list = array();
- for($i = 0 ; $i < $toDate ;$i++){
- $temp = $startDate + (24*60*60)*$i;
- $list[$i] = array(
- 'date' => date('D',$temp)." <br />".date('d M',$temp),
- 'time' => mktime(0,0,0,date('m',$temp),date('d',$temp),date('y',$temp))
- );
- }
-
- return $list;
- }
- }