content_only = true; } public function checkAccess() { return strcmp(Tools::getValue('token', ''), $this->module->secure_key) === 0; } public function displayAjaxAddReview() { $idHotel = Tools::getValue('id_hotel'); $idOrder = Tools::getValue('id_order'); $ratingOverall = Tools::getValue('rating_overall'); $ratingCategories = Tools::getValue('rating_categories'); $subject = Tools::getValue('subject'); $description = Tools::getValue('description'); $maxImages = (int) Configuration::get('QHR_MAX_IMAGES_PER_REVIEW'); $approvalEnabled = (int) Configuration::get('QHR_ADMIN_APPROVAL_ENABLED'); $status = false; $errors = array('by_key' => array(), 'general' => array()); $objModule = new QloHotelReview(); $objHotel = new HotelBranchInformation($idHotel); $objOrder = new Order($idOrder); // Validations if (!Validate::isLoadedObject($objHotel)) { $errors['general'][] = $objModule->l('Invalid hotel ID.', 'default'); } if (!Validate::isLoadedObject($objOrder)) { $errors['general'][] = $objModule->l('Invalid order ID.', 'default'); } $submittedSecureKey = Tools::getValue('order_secure_key', ''); if (!Validate::isLoadedObject($objOrder) || !$submittedSecureKey || $submittedSecureKey !== $objOrder->secure_key ) { $errors['general'][] = $objModule->l('You are not authorized to submit a review.', 'default'); $this->ajaxDie(json_encode(array('status' => false, 'errors' => $errors))); } if (!$subject) { $errors['by_key']['subject'] = $objModule->l('This field can not be empty.', 'default'); } elseif(!Validate::isGenericName($subject)) { $errors['by_key']['subject'] = $objModule->l('This field is invalid.', 'default'); } elseif(Tools::strlen($subject) > 255) { $errors['by_key']['subject'] = $objModule->l('This field is too long.', 'default'); } if(!Validate::isMessage($description)) { $errors['by_key']['description'] = $objModule->l('Review description is invalid.', 'default'); } elseif(Tools::strlen($description) > 65535) { $errors['by_key']['description'] = $objModule->l('This field is too long.', 'default'); } if (is_array($_FILES) && array_key_exists('images', $_FILES)) { if (count($_FILES['images']['name']) > $maxImages) { $errors['general'][] = sprintf( $objModule->l('Please upload a maximum of %d images.', 'default'), $maxImages ); } } if (is_array($_FILES) && array_key_exists('images', $_FILES) ) { $allowedExtensions = array('jpg', 'png', 'jpeg',); foreach ($_FILES['images']['name'] as $key => $imageName) { $extension = Tools::strtolower(pathinfo($imageName, PATHINFO_EXTENSION)); if (!in_array($extension, $allowedExtensions)) { $errors['general'][] = $objModule->l('Only images with the following extensions are allowed: jpg, jpeg, png','default'); } } } if (!count($errors['by_key']) && !count($errors['general'])) { $customerReview = QhrHotelReview::getByCustomer( $objOrder->id_customer, $idHotel, $idOrder ); if (!$customerReview) { $objHotelReview = new QhrHotelReview(); $objHotelReview->id_hotel = (int) $idHotel; $objHotelReview->id_order = (int) $idOrder; $objHotelReview->description = strip_tags($description); $objHotelReview->subject = $subject; $objHotelReview->rating = $ratingOverall; $objHotelReview->status_abusive = QhrHotelReview::QHR_STATUS_ABUSIVE_NOT_ABUSIVE; $objHotelReview->status = $approvalEnabled ? QhrHotelReview::QHR_STATUS_PENDING : QhrHotelReview::QHR_STATUS_APPROVED; if ($objHotelReview->save()) { $objHotelReview->addCategoryRatings($ratingCategories); if ($maxImages) { $objHotelReview->saveReviewImages(); } $status = true; } } else { $status = false; $errors['general'][] = $objModule->l('Something went wrong.', 'default'); } } else { $status = false; } if (is_array($errors['general']) && count($errors['general'])) { $html = '