public function processSave() { $hotel_id = Tools::getValue('hotel_id'); $hotel_name = Tools::getValue('hotel_name'); $phone = Tools::getValue('phone'); $email = Tools::getValue('email'); $check_in = Tools::getValue('check_in'); $check_out = Tools::getValue('check_out'); $short_description = Tools::getValue('short_description'); $description = Tools::getValue('description'); $rating = Tools::getValue('hotel_rating'); $city = Tools::getValue('hotel_city'); $state = Tools::getValue('hotel_state'); $country = Tools::getValue('hotel_country'); $policies = Tools::getValue('hotel_policies'); $zipcode = Tools::getValue('hotel_postal_code'); $address = Tools::getValue('address'); $active = Tools::getValue('ENABLE_HOTEL'); if ($hotel_name == '') { $this->errors[] = Tools::displayError('Hotel name is required field.'); } else { if (!Validate::isGenericName($hotel_name)) { $this->errors[] = Tools::displayError($this->l('Hotel name must not have Invalid characters <>;=#{}')); } } if (!$phone) { $this->errors[] = Tools::displayError('Phone number is required field.'); } else { if (!Validate::isPhoneNumber($phone)) { $this->errors[] = Tools::displayError('Please enter a valid phone number.'); } } if ($email == '') { $this->errors[] = Tools::displayError('Email is required field.'); } else { if (!Validate::isEmail($email)) { $this->errors[] = Tools::displayError('Please enter a valid email.'); } } if ($check_in == '') { $this->errors[] = Tools::displayError('Check In time is required field.'); } if ($check_out == '') { $this->errors[] = Tools::displayError('Check Out Time is required field.'); } if ($zipcode == '') { $this->errors[] = Tools::displayError('Postal Code is required field.'); } else { if (!Validate::isPostCode($zipcode)) { $this->errors[] = Tools::displayError('Enter a Valid Postal Code.'); } } if (!$rating) { $this->errors[] = Tools::displayError('Rating is required field.'); } if ($address == '') { $this->errors[] = Tools::displayError('Address is required field.'); } if (!$country) { $this->errors[] = Tools::displayError('Country is required field.'); } if (!$state) { $this->errors[] = Tools::displayError('State is required field.'); } if ($city == '') { $this->errors[] = Tools::displayError('City is required field.'); } else { if (!Validate::isCityName($city)) { $this->errors[] = Tools::displayError('Enter a Valid City Name.'); } } //validate hotel main image if (isset($_FILES['hotel_image']) && $_FILES['hotel_image']['name']) { $obj_htl_img = new HotelImage(); $error = $obj_htl_img->validAddHotelMainImage($_FILES['hotel_image']); if ($error) { $this->errors[] = Tools::displayError('<strong>' . $_FILES['hotel_image']['name'] . '</strong> : Image format not recognized, allowed formats are: .gif, .jpg, .png', false); } } //validate Hotel's other images if (isset($_FILES['images']) && $_FILES['images']) { $obj_htl_img = new HotelImage(); $error = $obj_htl_img->validAddHotelOtherImage($_FILES['images']); if ($error) { $this->errors[] = Tools::displayError('<strong>' . $_FILES['hotel_image']['name'] . '</strong> : Image format not recognized, allowed formats are: .gif, .jpg, .png', false); } } if (!count($this->errors)) { if ($hotel_id) { $obj_hotel_info = new HotelBranchInformation($hotel_id); } else { $obj_hotel_info = new HotelBranchInformation(); } if ($obj_hotel_info) { if (!$active) { $obj_htl_rm_info = new HotelRoomType(); $ids_product = $obj_htl_rm_info->getIdProductByHotelId($obj_hotel_info->id); if (isset($ids_product) && $ids_product) { foreach ($ids_product as $key_prod => $value_prod) { $obj_product = new Product($value_prod['id_product']); if ($obj_product->active) { $obj_product->toggleStatus(); } } } } } $obj_hotel_info->active = $active; $obj_hotel_info->hotel_name = $hotel_name; $obj_hotel_info->phone = $phone; $obj_hotel_info->email = $email; $obj_hotel_info->check_in = $check_in; $obj_hotel_info->check_out = $check_out; $obj_hotel_info->short_description = $short_description; $obj_hotel_info->description = $description; $obj_hotel_info->rating = $rating; $obj_hotel_info->city = $city; $obj_hotel_info->state_id = $state; $obj_hotel_info->country_id = $country; $obj_hotel_info->zipcode = $zipcode; $obj_hotel_info->policies = $policies; $obj_hotel_info->address = $address; $obj_hotel_info->save(); $new_hotel_id = $obj_hotel_info->id; $hotel_img_path = _PS_MODULE_DIR_ . 'hotelreservationsystem/views/img/hotel_img/'; //upload hotel's image if (isset($_FILES['hotel_image']) && $_FILES['hotel_image']) { $obj_htl_img = new HotelImage(); $obj_htl_img->uploadMainImage($_FILES['hotel_image'], $new_hotel_id, $hotel_img_path); } //upload hotel's other images if (isset($_FILES['images']) && $_FILES['images']) { $obj_htl_img = new HotelImage(); $obj_htl_img->uploadOtherImages($_FILES['images'], $new_hotel_id, $hotel_img_path); } if ($new_hotel_id) { $grp_ids = array(); $obj_grp = new Group(); $data_grp_ids = $obj_grp->getGroups(1, $id_shop = false); foreach ($data_grp_ids as $key => $value) { $grp_ids[] = $value['id_group']; } $country_name = (new Country())->getNameById(Configuration::get('PS_LANG_DEFAULT'), $country); $cat_country = $this->addCategory($country_name, false, $grp_ids); if ($cat_country) { $state_name = (new State())->getNameById($state); $cat_state = $this->addCategory($state_name, $cat_country, $grp_ids); } if ($cat_state) { $cat_city = $this->addCategory($city, $cat_state, $grp_ids); } if ($cat_city) { $cat_hotel = $this->addCategory($hotel_name, $cat_city, $grp_ids, 1, $new_hotel_id); } if ($cat_hotel) { $obj_hotel_info = new HotelBranchInformation($new_hotel_id); $obj_hotel_info->id_category = $cat_hotel; $obj_hotel_info->save(); } } if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) { if ($hotel_id) { Tools::redirectAdmin(self::$currentIndex . '&id=' . (int) $new_hotel_id . '&update' . $this->table . '&conf=4&token=' . $this->token); } else { Tools::redirectAdmin(self::$currentIndex . '&id=' . (int) $new_hotel_id . '&update' . $this->table . '&conf=3&token=' . $this->token); } } else { if ($hotel_id) { Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=3&token=' . $this->token); } } } else { if ($hotel_id) { $this->display = 'edit'; } else { $this->display = 'add'; } } }