Пример #1
0
 /**
  * 添加酒店
  */
 public function ActionAddHotel()
 {
     $hotel_obj = new Hotel();
     // 获取获取所有大洲数据
     $continent = Continent::model()->findAll();
     // 判断是执行添加 还是跳转至添加页
     if (Yii::app()->request->isPostRequest) {
         // 获取提交的表单数据
         $hotel_obj->attributes = Yii::app()->request->getParam('Hotel');
         $hotel_obj->HotelIntroduction = $_POST['Hotel']['HotelIntroduction'];
         $hotel_obj->DecorationTime = $_POST['Hotel']['DecorationTime'];
         // 执行添加操作
         if ($hotel_obj->save()) {
             Yii::app()->user->setFlash('message', '添加成功');
             // 如保存基本信息后添加图片则跳转至添加图片页
             empty($_POST['add_pic']) ? $this->redirect(array('Hotel/HotelList')) : $this->redirect(array('Hotel/AddHotelPic', 'hotel_id' => $hotel_obj->attributes['Id']));
         } else {
             Yii::app()->user->setFlash('message', '添加失败');
             $this->render('add_hotel', array('hotel_obj' => $hotel_obj, 'continent' => $continent));
         }
     } else {
         // 跳转至添加酒店页
         $this->render('add_hotel', array('hotel_obj' => $hotel_obj, 'continent' => $continent));
     }
 }
Пример #2
0
 public function actionCreateHotel()
 {
     $hotel_name = isset($_POST['name']) ? $_POST['name'] : '';
     $address = isset($_POST['address']) ? $_POST['address'] : '';
     $city = isset($_POST['city']) ? $_POST['city'] : '';
     $longitude = isset($_POST['longitude']) ? $_POST['longitude'] : '';
     $latitude = isset($_POST['latitude']) ? $_POST['latitude'] : '';
     $hotel = new Hotel();
     $hotel->name = $hotel_name;
     $hotel->address = $address;
     $hotel->city = $city;
     $hotel->longitude = $longitude;
     $hotel->latitude = $latitude;
     $Criteria = new CDbCriteria();
     $Criteria->condition = "name ='" . $hotel_name . "'";
     $hotelModel = Hotel::model()->find($Criteria);
     $result = array();
     if ($hotelModel == NULL) {
         $hotel->save();
         $result['response'] = true;
         $result['message'] = "Successfull";
     } else {
         //echo '{"message":"Invalid Username/Password"}';
         $result['response'] = true;
         $result['message'] = "Failure";
     }
     header('Content-type: application/json');
     echo CJSON::encode($result);
     foreach (Yii::app()->log->routes as $route) {
         if ($route instanceof CWebLogRoute) {
             $route->enabled = false;
             // disable any weblogroutes
         }
     }
 }
Пример #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = ['name' => 'required|unique:hotel', 'address' => 'required', 'location' => 'required'];
     $messages = [];
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return Redirect::back()->withInput()->withErrors($validator->errors());
     }
     $hotel = new Hotel(Input::all());
     $hotel->save();
     Session::flash('success', 'Successfully created hotel!');
     return Redirect::back();
 }
Пример #4
0
 public function save($id = null)
 {
     if ($_POST) {
         $data = new Hotel($id);
         if ($id == '') {
             $_POST['created_by'] = $this->user->id;
         } else {
             $_POST['updated_by'] = $this->user->id;
         }
         $data->from_array($_POST);
         $data->save();
         $action = @$_POST['id'] > 0 ? 'UPDATE' : 'CREATE';
         save_logs($this->menu_id, $action, @$data->id, $action . ' ' . $data->hotel_name . ' Hotel ');
     }
     redirect("admin/settings/hotels");
 }
Пример #5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Hotel();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Hotel'])) {
         $model->attributes = $_POST['Hotel'];
         if ($model->validate()) {
             $model->fecha_creacion = date('Y-m-d H:i:s');
             $model->fecha_modificacion = date('Y-m-d H:i:s');
             $model->usuario_id = Yii::app()->user->id;
             if ($model->save()) {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #6
0
 /**
  * Store a newly created hotel in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Hotel::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $hotel = new Hotel();
     $hotel->nome_br = $data['nome_br'];
     $hotel->nome_en = $data['nome_en'];
     $hotel->descricao_br = $data['descricao_br'];
     $hotel->descricao_en = $data['descricao_en'];
     $hotel->estrelas = $data['estrelas'];
     $hotel->pais_id = $data['pais_id'];
     $hotel->valor = $data['valor'];
     $hotel->cidade = $data['cidade'];
     //$hotel->estado = $data['estado'];
     $hotel->publicado = $data['publicado'];
     if (Input::hasFile('imagem')) {
         $up_success = $this->uploadImage(Input::file('imagem'), 'hoteis');
         if ($up_success) {
             $hotel->imagem = $up_success['filename'];
         }
     }
     $hotel->save();
     if (Input::has('caracteristicas')) {
         $hotel->caracteristicas()->sync(Input::get('caracteristicas'));
     }
     if (Input::hasFile('imagens')) {
         $imagens = Input::file('imagens');
         foreach ($imagens as $img) {
             $imginfo = $this->uploadImage($img, 'hoteis');
             if ($imginfo) {
                 $imagem = new Imagem();
                 $imagem->nome = $imginfo['filename'];
                 $imagem->caminho = $imginfo['destinationPath'];
                 $hotel->imagens()->save($imagem);
             }
         }
     }
     return Redirect::to('admin/hotel/')->with('success', array('Registro salvo.'));
 }
 public function add_data_csv()
 {
     if (!$this->securitypolicy->validateAccessRight(1, 'add')) {
         $this->load->view('access_denied');
     }
     $this->load->library('form_validation');
     $this->load->helper('form');
     $lineno = array();
     $hotelIds = array();
     $hotelNames = array();
     $hotelAmounts = array();
     $hotelDates = array();
     if (array_key_exists('revenue-csv', $_FILES)) {
         $this->form_validation->set_rules('category', 'Category', 'required');
         if ($this->form_validation->run() == false || $_FILES['revenue-csv']['error'] === 4) {
             $this->_setViewDataErrCsv();
             $this->_getLatestActivity();
             $this->load->view('add_financial_info_csverr', $this->_viewdata);
         } else {
             $this->load->library('Csvimport');
             $config['upload_path'] = './uploads/csv';
             $config['allowed_types'] = 'csv';
             $config['overwrite'] = true;
             $this->load->library('upload', $config);
             if ($this->upload->do_upload('revenue-csv')) {
                 $filedata = $this->upload->data();
                 $path = $config['upload_path'] . '/' . $filedata['file_name'];
                 $this->csvimport->column_headers(array('hotel id', 'hotel name', 'amount', 'date'));
                 if ($this->csvimport->get_array($path)) {
                     $csv_array = $this->csvimport->get_array($path);
                     foreach ($csv_array as $line => $row) {
                         $lineno[] = $line + 2;
                         $hotelIds[] = $row['hotel id'];
                         $hotelNames[] = $row['hotel name'];
                         $hotelAmounts[] = $row['amount'];
                         $hotelDates[] = $row['date'];
                     }
                 }
             } else {
                 $this->_setViewDataErrCsv();
                 $this->_getLatestActivity();
                 $this->load->view('add_financial_info_csverr', $this->_viewdata);
             }
         }
     } else {
         $lineno = $this->input->post('lineno[]');
         $hotelIds = $this->input->post('hotel-id[]');
         $hotelNames = $this->input->post('hotel-name[]');
         $hotelAmounts = $this->input->post('amount[]');
         $hotelDates = $this->input->post('date[]');
     }
     # revenue data collection
     $revenues = new RevenueColl();
     //valid revenue data
     $revenuesErrIdNameEmpty = new RevenueColl();
     //id and name empty
     $revenuesErrIdMatch = new RevenueColl();
     //id not match name
     $revenuesErrNameMatch = new RevenueColl();
     //name not match id
     $revenuesErrIdNotFound = new RevenueColl();
     //id not found
     $revenuesErrAmount = new RevenueColl();
     //amount error
     $revenuesErrDate = new RevenueColl();
     //date error
     $revenuesErrMulti = new RevenueColl();
     //more than input error
     # hotel name collection
     $hotelNamesErrIdMatch = array();
     // hotel names for id not match
     $hotelNamesErrMatch = array();
     // hotel names
     # line number collections
     $linenoErrIdNameEmpty = array();
     $linenoErrIdMatch = array();
     $linenoErrNameMatch = array();
     $linenoErrDate = array();
     $linenoErrAmount = array();
     $linenoErrMulti = array();
     $linenoErrIdNotFound = array();
     $hotels = new HotelColl();
     $hotels->setAll();
     foreach ($hotelIds as $index => $hotelId) {
         $errors = array();
         $isIdMatch = false;
         $isNameMatch = false;
         $revenue = new RevenueData();
         $revenue->setAmount(str_replace(',', '', $hotelAmounts[$index]));
         $revenue->setAcctId($this->input->post('category'));
         $revenue->setDateEffect($hotelDates[$index]);
         foreach ($hotels as $hotel) {
             if ($hotel->getId() == $hotelId) {
                 $isIdMatch = true;
             }
             if ($hotel->getName() == $hotelNames[$index]) {
                 $isNameMatch = true;
             }
             if ($isIdMatch || $isNameMatch) {
                 break;
             }
         }
         if (!$isIdMatch && !$isNameMatch) {
             $hotel = new Hotel();
             # saving new hotel
             if (!empty($hotelNames[$index]) && !empty($hotelId)) {
                 if (!empty($hotelId)) {
                     $hotel->setId($hotelId);
                 }
                 $hotel->setName($hotelNames[$index]);
                 $hotel->save();
             } else {
                 if (empty($hotelId) && empty($hotelNames[$index])) {
                     $errors[] = 1;
                 } else {
                     if (empty($hotelNames[$index]) && !empty($hotelId)) {
                         $errors[] = 6;
                         $revenue->setHotelId($hotelId);
                     } else {
                         $errors[] = 2;
                     }
                 }
             }
         } elseif ($isIdMatch || $isNameMatch) {
             $hotel = new Hotel();
             # id - name match validation
             if (!$isIdMatch) {
                 $errors[] = 2;
                 $hotelNamesErrIdMatch[] = $hotelNames[$index];
                 # id not match
                 if (!empty($hotelId)) {
                     $hotel->setId($hotelId);
                 } else {
                     $nameFilter = new HtlNameFiltr();
                     $nameFilter->setFilter($hotelNames[$index]);
                     $hotel->addFilter($nameFilter);
                     $hotel->set();
                     $hotel->setId($hotelId);
                 }
             } elseif (!$isNameMatch) {
                 # name not match
                 $hotel->setById($hotelId);
                 if (!empty($hotelNames[$index])) {
                     $errors[] = 3;
                     $hotelNamesErrMatch[] = $hotelNames[$index];
                 }
             } else {
                 $hotel->setById($hotelId);
             }
             $revenue->setHotelId($hotel->getId());
         }
         # validate amount
         if (empty($hotelAmounts[$index]) || !is_numeric($hotelAmounts[$index])) {
             $errors[] = 4;
         }
         # validate dates
         if (empty($hotelDates[$index]) || !validateDate($hotelDates[$index])) {
             $errors[] = 5;
         }
         if (count($errors) == 1) {
             if (in_array(1, $errors)) {
                 $revenuesErrIdNameEmpty->addRevenue($revenue);
                 $linenoErrIdNameEmpty[] = $lineno[$index];
             } elseif (in_array(2, $errors)) {
                 $revenuesErrIdMatch->addRevenue($revenue);
                 $linenoErrIdMatch[] = $lineno[$index];
             } elseif (in_array(3, $errors)) {
                 $revenuesErrNameMatch->addRevenue($revenue);
                 $linenoErrNameMatch[] = $lineno[$index];
             } elseif (in_array(4, $errors)) {
                 $revenuesErrAmount->addRevenue($revenue);
                 $linenoErrAmount[] = $lineno[$index];
             } elseif (in_array(5, $errors)) {
                 $revenuesErrDate->addRevenue($revenue);
                 $linenoErrDate[] = $lineno[$index];
             } elseif (in_array(6, $errors)) {
                 $revenuesErrIdNotFound->addRevenue($revenue);
                 $linenoErrIdNotFound[] = $lineno[$index];
             }
         } elseif (count($errors) > 1) {
             $revenuesErrMulti->addRevenue($revenue);
             $linenoErrMulti[] = $lineno[$index];
         } elseif (empty($errors)) {
             # add to valid revenue data
             $revenues->addRevenue($revenue);
         }
     }
     # End foreach hotelI$revenuesErrDate->count > 0
     if ($revenues->count() > 0) {
         $revenues->save();
     }
     if ($revenuesErrIdNameEmpty->count() > 0 || $revenuesErrIdMatch->count() > 0 || $revenuesErrNameMatch->count() > 0 || $revenuesErrAmount->count() > 0 || $revenuesErrDate->count() > 0 || $revenuesErrMulti->count() > 0 || $revenuesErrIdNotFound->count() > 0) {
         $this->_viewdata['revenuesErrIdNameEmpty'] = $revenuesErrIdNameEmpty;
         $this->_viewdata['revenuesErrIdMatch'] = $revenuesErrIdMatch;
         $this->_viewdata['revenuesErrNameMatch'] = $revenuesErrNameMatch;
         $this->_viewdata['revenuesErrAmount'] = $revenuesErrAmount;
         $this->_viewdata['revenuesErrDate'] = $revenuesErrDate;
         $this->_viewdata['revenuesErrMulti'] = $revenuesErrMulti;
         $this->_viewdata['revenuesErrIdNotFound'] = $revenuesErrIdNotFound;
         $this->_viewdata['hotelNamesErrMatch'] = $hotelNamesErrMatch;
         $this->_viewdata['hotelNamesErrIdMatch'] = $hotelNamesErrIdMatch;
         $this->_viewdata['linenoErrIdNameEmpty'] = $linenoErrIdNameEmpty;
         $this->_viewdata['linenoErrIdMatch'] = $linenoErrIdMatch;
         $this->_viewdata['linenoErrNameMatch'] = $linenoErrNameMatch;
         $this->_viewdata['linenoErrAmount'] = $linenoErrAmount;
         $this->_viewdata['linenoErrDate'] = $linenoErrDate;
         $this->_viewdata['linenoErrMulti'] = $linenoErrMulti;
         $this->_viewdata['linenoErrIdNotFound'] = $linenoErrIdNotFound;
         $this->_viewdata['category'] = $this->input->post('category');
         $this->_viewdata['hotels'] = $hotels;
         $this->_viewdata['showmsg'] = true;
         $this->_viewdata['status'] = 'error';
         $this->_viewdata['msg'] = 'Some records you tried to import had wrong or missing values. Please correct these below and try again.';
         $this->load->view('add_financial_info_csverr', $this->_viewdata);
     } else {
         $this->session->set_userdata(array('status' => 'success'));
         redirect(site_url('Admin/add_revenue_data_csv'));
     }
 }
Пример #8
0
<?php

require_once "../../includes/initialize.php";
if ($session->is_logged_in()) {
    redirect_to("page.php?id={$session->user_id}");
}
if (isset($_POST['submit'])) {
    $hotel = new Hotel();
    $hotel->hotel_name = trim($_POST['hotel_name']);
    $hotel->password = trim($_POST['password']);
    $hotel->confirm_password = trim($_POST['confirm_password']);
    $hotel->city_id = trim($_POST['city_id']);
    if ($hotel->save()) {
        $session->login($hotel);
        redirect_to("info.php?id={$hotel->id}");
        /*redirect_to("more_info.php?id={$hotel->id}");*/
    } else {
        $session->message(join("<br>", $hotel->errors));
        redirect_to("login.php");
    }
}
if (isset($_POST['submit1'])) {
    $hotel_name = trim($_POST['hotel_name']);
    $password = trim($_POST['password']);
    $found_hotel = Hotel::authenticate($hotel_name, $password);
    if ($found_hotel) {
        $session->login($found_hotel);
        redirect_to("page.php?id={$found_hotel->id}");
    } else {
        $message = "hotel name/password incorect";
    }