예제 #1
0
 /**
  * Add the page title and toolbar.
  *
  * @since	1.6
  */
 protected function addToolbar()
 {
     JRequest::setVar('hidemainmenu', true);
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $isNew = $this->item->id == 0;
     $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $userId);
     $canDo = RentalHelper::getActions($this->state->get('filter.category_id'));
     JToolBarHelper::title($isNew ? JText::_('COM_RENTAL_MANAGER_APARTMENT_NEW') : JText::_('COM_RENTAL_MANAGER_APARTMENT_EDIT'), '#xs#.png');
     // If not checked out, can save the item.
     if (!$checkedOut && ($canDo->get('core.edit') || count($user->getAuthorisedCategories('com_rental', 'core.create')) > 0)) {
         JToolBarHelper::apply('apartment.apply');
         JToolBarHelper::save('apartment.save');
         if ($canDo->get('core.create')) {
             JToolBarHelper::save2new('apartment.save2new');
         }
     }
     // If an existing item, can save to a copy.
     if (!$isNew && $canDo->get('core.create')) {
         JToolBarHelper::save2copy('apartment.save2copy');
     }
     if (empty($this->item->id)) {
         JToolBarHelper::cancel('apartment.cancel');
     } else {
         JToolBarHelper::cancel('apartment.cancel', 'JTOOLBAR_CLOSE');
     }
 }
예제 #2
0
 /**
  * Add the page title and toolbar.
  *
  * @since	1.6
  */
 protected function addToolbar()
 {
     $canDo = RentalHelper::getActions($this->state->get('filter.category_id'));
     $user = JFactory::getUser();
     JToolBarHelper::title(JText::_('COM_RENTAL_MANAGER_LOCATIONS'), 'location.png');
     if ($canDo->get('core.create') || count($user->getAuthorisedCategories('com_rental', 'core.create')) > 0) {
         JToolBarHelper::addNew('location.add');
     }
     if ($canDo->get('core.edit') || $canDo->get('core.edit.own')) {
         JToolBarHelper::editList('location.edit');
     }
     if ($canDo->get('core.edit.state')) {
         JToolBarHelper::divider();
         JToolBarHelper::publish('locations.publish', 'JTOOLBAR_PUBLISH', true);
         JToolBarHelper::unpublish('locations.unpublish', 'JTOOLBAR_UNPUBLISH', true);
         JToolBarHelper::divider();
         JToolBarHelper::archiveList('locations.archive');
         JToolBarHelper::checkin('locations.checkin');
     }
     if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete')) {
         JToolBarHelper::deleteList('', 'locations.delete', 'JTOOLBAR_EMPTY_TRASH');
     } else {
         if ($canDo->get('core.edit.state')) {
             JToolBarHelper::trash('locations.trash');
         }
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_rental');
     }
 }
예제 #3
0
 /**
  * Method to display a view.
  *
  * @param	boolean			If true, the view output will be cached
  * @param	array			An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  *
  * @return	JController		This object to support chaining.
  * @since	1.5
  */
 public function display($cachable = false, $urlparams = false)
 {
     require_once JPATH_COMPONENT . '/helpers/rental.php';
     // Load the submenu.
     RentalHelper::addSubmenu(JRequest::getCmd('view', 'apartments'));
     parent::display();
     return $this;
 }
예제 #4
0
 public function _check_validate()
 {
     $data = array();
     $order_item_id = STInput::request('order_item_id', '');
     $st_first_name = STInput::request('st_first_name', '');
     if (empty($st_first_name)) {
         STAdmin::set_message(__('The firstname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_last_name = STInput::request('st_last_name', '');
     if (empty($st_last_name)) {
         STAdmin::set_message(__('The lastname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_email = STInput::request('st_email', '');
     if (empty($st_email)) {
         STAdmin::set_message(__('The email field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_phone = STInput::request('st_phone', '');
     if (empty($st_phone)) {
         STAdmin::set_message(__('The phone field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     if (STInput::request('section', '') != 'edit_order_item') {
         $item_id = intval(STInput::request('item_id', ''));
         if ($item_id <= 0 || get_post_type($item_id) != 'st_rental') {
             STAdmin::set_message(__('The rental field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_in = STInput::request('check_in', '');
         if (empty($check_in)) {
             STAdmin::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_out = STInput::request('check_out', '');
         if (empty($check_out)) {
             STAdmin::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         if (STInput::request('adult_number', '') == "") {
             STAdmin::set_message(__('The No. adults field is not empty', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $adult_number = intval(STInput::request('adult_number', ''));
         if ($adult_number <= 0) {
             $adult_number = 1;
         }
         if (STInput::request('child_number', '') == "") {
             STAdmin::set_message(__('The No. children field is not empty', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $child_number = intval(STInput::request('child_number', ''));
         if ($child_number <= 0) {
             $child_number = 0;
         }
         if (strtotime($check_out) - strtotime($check_in) <= 0) {
             STAdmin::set_message(__('The check-out is later than the check-in.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $adult = intval(get_post_meta($item_id, 'rental_max_adult', true));
         $children = intval(get_post_meta($item_id, 'rental_max_children', true));
         if ($adult_number > $adult) {
             STAdmin::set_message(__('Number of adults in the room are incorrect.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         if ($child_number > $children) {
             STAdmin::set_message(__('Number of children in the room are incorrect.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $today = date('m/d/Y');
         $period = TravelHelper::dateDiff($today, $check_in);
         $compare = TravelHelper::dateCompare($today, $check_in);
         $booking_period = get_post_meta($item_id, 'rentals_booking_period', true);
         if (empty($booking_period) || $booking_period <= 0) {
             $booking_period = 0;
         }
         if ($compare < 0) {
             STAdmin::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         if ($period < $booking_period) {
             STAdmin::set_message(sprintf(__('This rental allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
             return false;
         }
         $checkin_ymd = date('Y-m-d', strtotime($check_in));
         $checkout_ymd = date('Y-m-d', strtotime($check_out));
         if (!RentalHelper::check_day_cant_order($item_id, $checkin_ymd, $checkout_ymd, 1)) {
             STAdmin::set_message(sprintf(__('This rental is not available from %s to %s.', ST_TEXTDOMAIN), $checkin_ymd, $checkout_ymd), 'danger');
             $pass_validate = FALSE;
             return false;
         }
         if (!RentalHelper::_check_room_available($item_id, $checkin_ymd, $checkout_ymd, 1)) {
             STAdmin::set_message(__('This rental is not available.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = FALSE;
             return false;
         }
         $data = array('order_item_id' => $order_item_id, 'item_id' => $item_id, 'type' => 'normal_booking', 'check_in' => $check_in, 'check_out' => $check_out, 'st_booking_post_type' => 'st_rental', 'st_booking_id' => $item_id, 'adult_number' => $adult_number, 'child_number' => $child_number, 'room_num_search' => 1, 'check_in_timestamp' => strtotime($check_in), 'check_out_timestamp' => strtotime($check_out), 'status' => $_POST['status']);
     }
     return $data;
 }
예제 #5
0
 function _get_where_query($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_rental')) {
         return $where;
     }
     global $wpdb;
     if ($location_id = STInput::get('location_id') and STInput::get('location_id') or get_post_type(get_the_ID()) == 'location') {
         if (!$location_id) {
             $location_id = get_the_ID();
         }
         $list = TravelHelper::getLocationByParent($location_id);
         if (is_array($list) && count($list)) {
             $where .= " AND (";
             $where_tmp = "";
             foreach ($list as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $list = implode(',', $list);
             $where_tmp .= " OR tb.location_id IN ({$list})";
             $where .= $where_tmp . ")";
         } else {
             $where .= " AND (tb.multi_location LIKE '%_{$location_id}_%' OR tb.location_id IN ('{$location_id}')) ";
         }
     } elseif ($location_name = STInput::request('location_name')) {
         $ids_location = TravelerObject::_get_location_by_name($location_name);
         if (is_array($ids_location) && count($ids_location)) {
             $ids_location_tmp = array();
             foreach ($ids_location as $item) {
                 $list = TravelHelper::getLocationByParent($item);
                 if (is_array($list) && count($list)) {
                     foreach ($list as $item) {
                         $ids_location_tmp[] = $item;
                     }
                 }
             }
             if (count($ids_location_tmp)) {
                 $ids_location = $ids_location_tmp;
             }
         }
         if (!empty($ids_location)) {
             $where .= " AND ((";
             $where_tmp = "";
             foreach ($ids_location as $id) {
                 if (empty($where_tmp)) {
                     $where_tmp .= " tb.multi_location LIKE '%_{$id}_%' ";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$id}_%' ";
                 }
             }
             $ids_location = implode(',', $ids_location);
             $where_tmp .= " OR (tb.location_id IN ({$ids_location})";
             $where .= $where_tmp . ")";
             $where .= " OR (tb.address LIKE '%{$location_name}%'";
             $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')))";
         } else {
             if (!empty($_REQUEST['search_all'])) {
                 $where .= " AND (tb.address LIKE '%{$location_name}%'";
                 $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')";
             }
         }
     } elseif ($address = STInput::request('address', '')) {
         $value = STInput::request('address');
         $value = explode(",", $value);
         if (!empty($value[0]) and !empty($value[2])) {
             $where .= " AND (tb.address LIKE '%{$value[0]}%' OR tb.address LIKE '%{$value[2]}%')";
         } else {
             $where .= " AND (tb.address LIKE '%{$address}%')";
         }
     }
     if (isset($_GET['start']) && isset($_GET['end']) and !empty($_GET['start']) and !empty($_GET['end'])) {
         $check_in = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['start'])));
         $check_out = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['end'])));
         $today = date('m/d/Y');
         $period = TravelHelper::dateDiff($today, $check_in);
         $adult_number = STInput::get('adult_number', 0);
         if (intval($adult_number) < 0) {
             $adult_number = 0;
         }
         $children_number = STInput::get('children_num', 0);
         if (intval($children_number) < 0) {
             $children_number = 0;
         }
         $list_rental = RentalHelper::_rentalValidate($check_in, $check_out, $adult_number, $children_number, 1);
         if (!is_array($list_rental) || count($list_rental) <= 0) {
             $list_rental = "''";
         } else {
             $list_rental = implode(',', $list_rental);
         }
         $where .= " AND {$wpdb->posts}.ID NOT IN ({$list_rental}) AND CAST(tb.rentals_booking_period AS UNSIGNED) <= {$period}";
     }
     if ($star = STInput::get('star_rate')) {
         $stars = STInput::get('star_rate', 1);
         $stars = explode(',', $stars);
         $all_star = array();
         if (!empty($stars) && is_array($stars)) {
             foreach ($stars as $val) {
                 for ($i = $val; $i < $val + 0.9; $i += 0.1) {
                     if ($i) {
                         $all_star[] = $i;
                     }
                 }
             }
         }
         $list_star = implode(',', $all_star);
         if ($list_star) {
             $where .= " AND (tb.rate_review IN ({$list_star}))";
         }
     }
     if ($price = STInput::get('price_range')) {
         $priceobj = explode(';', $price);
         $priceobj[0] = TravelHelper::convert_money_to_default($priceobj[0]);
         $where .= " AND (tb.sale_price >= {$priceobj[0]})";
         if (isset($priceobj[1])) {
             $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
             $where .= " AND (tb.sale_price <= {$priceobj[1]})";
         }
     }
     if (isset($_REQUEST['range']) and isset($_REQUEST['location_id'])) {
         $range = STInput::request('range', '5');
         $location_id = STInput::request('location_id');
         $post_type = get_query_var('post_type');
         $map_lat = (double) get_post_meta($location_id, 'map_lat', true);
         $map_lng = (double) get_post_meta($location_id, 'map_lng', true);
         global $wpdb;
         $where .= "\r\n                AND {$wpdb->posts}.ID IN (\r\n                        SELECT ID FROM (\r\n                            SELECT {$wpdb->posts}.*,( 6371 * acos( cos( radians({$map_lat}) ) * cos( radians( mt1.meta_value ) ) *\r\n                                            cos( radians( mt2.meta_value ) - radians({$map_lng}) ) + sin( radians({$map_lat}) ) *\r\n                                            sin( radians( mt1.meta_value ) ) ) ) AS distance\r\n                                                FROM {$wpdb->posts}, {$wpdb->postmeta} as mt1,{$wpdb->postmeta} as mt2\r\n                                                WHERE {$wpdb->posts}.ID = mt1.post_id\r\n                                                and {$wpdb->posts}.ID=mt2.post_id\r\n                                                AND mt1.meta_key = 'map_lat'\r\n                                                and mt2.meta_key = 'map_lng'\r\n                                                AND {$wpdb->posts}.post_status = 'publish'\r\n                                                AND {$wpdb->posts}.post_type = '{$post_type}'\r\n                                                AND {$wpdb->posts}.post_date < NOW()\r\n                                                GROUP BY {$wpdb->posts}.ID HAVING distance<{$range}\r\n                                                ORDER BY distance ASC\r\n                        ) as st_data\r\n\t            )";
     }
     if (isset($_REQUEST['item_id']) and !empty($_REQUEST['item_id'])) {
         $item_id = STInput::request('item_id', '');
         $where .= " AND ({$wpdb->prefix}posts.ID = '{$item_id}')";
     }
     if (!empty($_REQUEST['room_num_search'])) {
         $room_num_search = $_REQUEST['room_num_search'];
         $list_not_in = RentalHelper::get_list_not_in($room_num_search);
         $where .= " AND {$wpdb->prefix}posts.ID NOT IN ({$list_not_in})";
     }
     return $where;
 }
예제 #6
0
 static function _get_disable_date()
 {
     $list_date = array();
     if (!TravelHelper::checkTableDuplicate('st_rental')) {
         echo json_encode($list_date);
         die;
     }
     $rental_id = STInput::request('rental_id');
     $year = STInput::request('year');
     if (empty($year)) {
         $year = date('Y');
     }
     $month = STInput::request('month');
     if (empty($month)) {
         $month = date('m');
     }
     $result = RentalHelper::_get_full_ordered($rental_id, $month, $month, $year, $year);
     $number_rental = intval(get_post_meta($rental_id, 'rental_number', true));
     $min_max = RentalHelper::_get_min_max_date_ordered($rental_id, $year, $year);
     if (is_array($min_max) && count($min_max) && is_array($result) && count($result)) {
         $disable = array();
         for ($i = intval($min_max['min_date']); $i <= intval($min_max['max_date']); $i = strtotime('+1 day', $i)) {
             $num_rental = 0;
             foreach ($result as $key => $date) {
                 if ($i >= intval($date['check_in_timestamp']) && $i <= intval($date['check_out_timestamp'])) {
                     $num_rental += 1;
                 }
             }
             $disable[$i] = $num_rental;
         }
         if (count($disable)) {
             foreach ($disable as $key => $num_rental) {
                 if (intval($num_rental) >= $number_rental) {
                     $list_date[] = date(TravelHelper::getDateFormat(), $key);
                 }
             }
         }
     }
     $list_date_2 = AvailabilityHelper::_getDisableCustomDateRental($rental_id, $month, $month, $year, $year);
     if (is_array($list_date_2) && count($list_date_2)) {
         $list_date = array_merge($list_date, $list_date_2);
     }
     echo json_encode($list_date);
     die;
 }