403Webshell
Server IP : 46.105.57.169  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux webm002.cluster120.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User : verseaumee ( 152031)
PHP Version : 8.5.7
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/verseaumee/ptitsanes/plugins/solidres/experience/components/com_solidres/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/verseaumee/ptitsanes/plugins/solidres/experience/components/com_solidres/models/bookform.php
<?php
/**
------------------------------------------------------------------------
SOLIDRES - Accommodation booking extension for Joomla
------------------------------------------------------------------------
 * @author    Solidres Team <contact@solidres.com>
 * @website   https://www.solidres.com
 * @copyright Copyright (C) 2013 - 2020 Solidres. All Rights Reserved.
 * @license   GNU General Public License version 3, or later
------------------------------------------------------------------------
 */

defined('_JEXEC') or die;

use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Environment\Browser;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Table\Table;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\User\UserHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Utilities\IpHelper;
use Joomla\CMS\Factory as CMSFactory;

class SolidresModelBookForm extends SRModelAdmin
{
	public function getCustomFields()
	{
		static $fields = null;

		if (null === $fields)
		{
			$data       = $this->loadFormData();
			$categories = array();

			if (!empty($data['experience_id']))
			{
				$db    = CMSFactory::getDbo();
				$query = $db->getQuery(true)
					->select('a.category_id')
					->from($db->quoteName('#__sr_experience_category_xref', 'a'))
					->where($db->quoteName('a.experience_id') . ' = ' . (int) $data['experience_id']);
				$db->setQuery($query);

				if ($columns = $db->loadColumn())
				{
					$categories = $columns;
				}
			}

			$fields = SRCustomFieldHelper::findFields(array('context' => SRExperienceHelper::getCustomFieldContext()), $categories);
		}

		return $fields;
	}

	public function getForm($data = array(), $loadData = true)
	{
		Form::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_solidres/models/fields');
		/** @var $form JForm */
		$form = $this->loadForm('com_solidres.bookform', 'bookform', array('control' => 'jform', 'load_data' => $loadData));

		if (empty($form))
		{
			return false;
		}

		$data         = $this->loadFormData();
		$customFields = $this->getCustomFields();

		if ($customFields)
		{
			$fields     = array();
			$fieldNames = array();

			foreach ($customFields as $field)
			{
				$required     = (bool) $field->optional ? 'false' : 'true';
				$fields[]     = '<field type="hidden" name="' . $field->field_name . '" required="' . $required . '"/>';
				$fieldNames[] = $field->field_name;
			}

			if ($form->load('<form><fieldset name="guestform">' . join("\n", $fields) . '</fieldset></form>') && $loadData)
			{
				$user = CMSFactory::getUser();

				if (!$user->guest && SRPlugin::isEnabled('user'))
				{
					Table::addIncludePath(SRPlugin::getAdminPath('user') . '/tables');
					$customer = Table::getInstance('Customer', 'SolidresTable');

					if ($customer->load(array('user_id' => $user->id)))
					{
						$customFieldData = array('customer_email' => $user->email);

						foreach ($customer->getProperties() as $name => $value)
						{
							if (in_array('customer_' . $name, $fieldNames))
							{
								$customFieldData['customer_' . $name] = $value;
							}
						}

						$form->bind($customFieldData);
					}
				}

				if (!empty($data))
				{
					$customFieldData = array();

					foreach ($data as $name => $value)
					{
						if (strpos($name, 'customer_') === 0 && is_string($value) && !empty($value))
						{
							$customFieldData[$name] = $value;
						}
					}

					if (!empty($customFieldData))
					{
						$form->bind($customFieldData);
					}
				}
			}
		}

		return $form;
	}


	protected function loadFormData()
	{
		static $data = null;

		if (null === $data)
		{
			$app     = CMSFactory::getApplication();
			$context = base64_decode($app->input->getBase64('context', ''));
			$data    = $app->getUserState($context ?: 'com_solidres.bookform.data', []);
		}

		return $data;
	}

	public function validate($form, $data, $group = null)
	{
		$data          = parent::validate($form, $data, $group);
		$experience    = SRExperienceHelper::getItem($data['experience_id']);
		$participants  = (int) $data['participants'];
		$availableSize = SRExperienceHelper::getAvailableSize($experience);

		if ($availableSize < $participants)
		{
			$this->setError(Text::sprintf('SR_ERROR_PARTICIPANTS_HIGHER_AVAILABLE_SIZE_PLURAL', $participants, $availableSize));

			return false;
		}

		return $data;
	}

	public function save($data)
	{
		Table::addIncludePath(SRPlugin::getAdminPath('experience') . '/tables');
		Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_solidres/tables');
		$resTable   = Table::getInstance('ExpReservation', 'SolidresTable');
		$user       = CMSFactory::getUser();
		$userId     = (int) $user->get('id');
		$customerId = 0;

		if (!$userId
			&& !empty($data['register'])
			&& !empty($data['customer_username'])
			&& !empty($data['customer_password']))
		{
			if (PluginHelper::isEnabled('system', 'privacyconsent')
				&& empty($data['privacyConsent'])
			)
			{
				$this->setError(Text::_('SR_ERR_PRIVACY_CONSENT_MSG'));

				return false;
			}

			$userData              = array();
			$userData['name']      = join(' ', array($data['customer_firstname'], $data['customer_middlename'], $data['customer_lastname']));
			$userData['username']  = $data['customer_username'];
			$userData['password1'] = $data['customer_password'];
			$userData['email1']    = $data['customer_email'];

			CMSFactory::getLanguage()->load('com_users', JPATH_SITE);
			BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_users/models', 'UsersModel');
			Form::addFormPath(JPATH_SITE . '/components/com_users/models/forms');

			$userModel = BaseDatabaseModel::getInstance('Registration', 'UsersModel');
			$register  = $userModel->register($userData);

			if ($register !== false)
			{
				$userId = (int) UserHelper::getUserId($userData['username']);
			}
			else
			{
				$errors = $userModel->getErrors();

				foreach ($errors as $error)
				{
					$this->setError($error);
				}

				return false;
			}
		}

		if (SRPlugin::isEnabled('user'))
		{
			Table::addIncludePath(SRPlugin::getAdminPath('user') . ' /tables');
			$customerTable = Table::getInstance('Customer', 'SolidresTable');

			if ($userId && $customerTable)
			{
				$customerTable->load(array('user_id' => $userId));
				$customerTable->set('user_id', $userId);
				$excludeFields = array('customer_group_id', 'customer_code', 'id', 'user_id');

				foreach ($customerTable->getProperties() as $name => $value)
				{
					if (in_array($name, $excludeFields))
					{
						continue;
					}
					if (!empty($data['customer_' . $name]))
					{
						$customerTable->set($name, $data['customer_' . $name]);
					}
				}

				if ($customerTable->store())
				{
					$customerId = (int) $customerTable->get('id');

					if (!empty($data['privacyConsent']))
					{
						CMSFactory::getApplication()->triggerEvent('onActivateUserPrivacyConsent', [$customerId]);
					}
				}
			}
		}

		$bookDate         = $data['date'];
		$participants     = (int) $data['participants'];
		$experienceId     = (int) $data['experience_id'];
		$paymentId        = (int) $data['payment_method_id'];
		$totalPrice       = (float) $data['summary']['grandTotal'];
		$totalDiscount    = (float) $data['summary']['discounts'];
		$depositAmount    = (float) $data['summary']['depositAmount'];
		$surchargeAmount  = (float) $data['summary']['surchargeAmount'];
		$paymentDiscount  = (float) $data['summary']['paymentDiscount'];
		$supplementAmount = (float) $data['summary']['supplementAmount'];

		if ($experienceItem = SRExperienceHelper::getItem($experienceId))
		{
			$db             = $this->getDbo();
			$currency       = SRExperienceHelper::getCurrency();
			$experienceName = $experienceItem->name;
			$startTime      = $experienceItem->start_time;
			$paymentData    = isset($data['payment_data']) ? $data['payment_data'] : array();

			if (!is_string($paymentData))
			{
				$paymentData = json_encode($paymentData);
			}

			$customerName = array();

			if (isset($data['customer_firstname']))
			{
				$customerName[] = trim($data['customer_firstname']);
			}

			if (isset($data['customer_middlename']))
			{
				$customerName[] = trim($data['customer_middlename']);
			}

			if (isset($data['customer_lastname']))
			{
				$customerName[] = trim($data['customer_lastname']);
			}

			$browser  = Browser::getInstance();
			$params   = ComponentHelper::getParams('com_solidres');
			$bindData = [
				'state'                    => $params->get('default_exp_reservation_state', 3),
				'user_id'                  => $userId,
				'customer_id'              => $customerId,
				'book_date'                => $bookDate,
				'start_time'               => $startTime,
				'experience_id'            => $experienceId,
				'experience_name'          => $experienceName,
				'experience_history'       => serialize($experienceItem),
				'participants'             => $participants,
				'payment_method_id'        => $paymentId,
				'total_price'              => $totalPrice, // Price include tax amount + extra
				'total_discount'           => $totalDiscount,
				'total_paid'               => 0.00,
				'tax_amount'               => (float) $data['summary']['taxes'],
				'currency_id'              => $currency->getId(),
				'currency_code'            => $currency->getCode(),
				'summary'                  => json_encode($data['summary']),
				'payment_data'             => $paymentData,
				'deposit_amount'           => $depositAmount,
				'payment_method_surcharge' => $surchargeAmount,
				'payment_method_discount'  => $paymentDiscount,
				'supplement_amount'        => $supplementAmount,
				'time_slot_id'             => isset($data['time_slot_id']) ? $data['time_slot_id'] : 0,
				'guide_id'                 => isset($data['guide_id']) ? $data['guide_id'] : 0,
				'guide_name'               => isset($data['guide_name']) ? $data['guide_name'] : null,
				'time_slot_from'           => isset($data['time_slot_from']) ? $data['time_slot_from'] : null,
				'time_slot_to'             => isset($data['time_slot_to']) ? $data['time_slot_to'] : null,
				'time_slot_w_day'          => isset($data['time_slot_w_day']) ? $data['time_slot_w_day'] : 0,
				'coupon_id'                => isset($data['coupon_id']) ? $data['coupon_id'] : null,
				'coupon_code'              => isset($data['coupon_code']) ? $data['coupon_code'] : null,
				'coupon_amount'            => isset($data['coupon_amount']) ? $data['coupon_amount'] : null,
				'customer_name'            => trim(join(' ', $customerName)),
				'origin_id'                => 0,
				'customer_ua'              => $browser->getAgentString(),
				'customer_ismobile'        => $browser->isMobile() ? 1 : 0,
				'customer_ip'              => IpHelper::getIp(),
				'customer_coordinates'     => '',
				'customer_language'        => CMSFactory::getLanguage()->getTag(),
			];

			$countryId = isset($data['customer_country_id']) ? (int) $data['customer_country_id'] : 0;

			if ($countryId)
			{
				$query = $db->getQuery(true)
					->select('a.name')
					->from($db->quoteName('#__sr_countries', 'a'))
					->where('a.id = ' . $countryId);

				if ($countryName = $db->setQuery($query)->loadResult())
				{
					$location = trim($countryName);
					$mapAPI   = 'https://maps.googleapis.com/maps/api/geocode/json?key=' . $params->get('google_map_api_key', '') . '&address=';

					if (!empty($data['customer_city']))
					{
						$location = trim($data['customer_city']) . ',' . $location;
					}

					if ($json = file_get_contents($mapAPI . urlencode($location)))
					{
						$bindData['customer_coordinates'] = $json;
					}
				}
			}

			$query = $db->getQuery(true)
				->select('a.id')
				->from($db->quoteName('#__sr_origins', 'a'))
				->where('a.scope = 1 AND a.state = 1 AND a.is_default = 1');

			if ($originId = $db->setQuery($query)->loadResult())
			{
				$bindData['origin_id'] = (int) $originId;
			}

			$resTable->bind($bindData);
			$isNew = (int) $resTable->get('id') > 0;

			if (!empty($experienceItem->params['collect_guest_info']) && !empty($data['guests']))
			{
				$resId     = '{{reservation_id}}';
				$dbColumns = array(
					'reservation_id',
					'adult',
					'range_age',
				);
				$dbValues  = array();
				$columns   = array();

				foreach ($data['guests'] as $type => $fields)
				{
					$adult    = $type == 'adults' ? '1' : '0';
					$rangeAge = $adult ? '' : str_replace(array('children_', '_'), array('', '-'), $type);

					foreach ($fields as $field)
					{
						$dbValue = $db->quote($resId) . ',' . $db->quote($adult) . ',' . $db->quote($rangeAge);

						foreach ($field as $name => $value)
						{
							if (in_array($name, array('reservation_id', 'adult', 'range_age')))
							{
								continue;
							}

							foreach (array('first_name', 'middle_name', 'last_name', 'dob', 'gender', 'nationality', 'single_room') as $fieldName)
							{
								if (!empty($experienceItem->params['collect_guest_' . $fieldName]) && $name == $fieldName)
								{
									if (!in_array($fieldName, $dbColumns))
									{
										$dbColumns[] = $fieldName;
										$columns[]   = $fieldName;
									}

									$value = trim($value);

									if (!is_string($value) || $value === '')
									{
										$this->setError(Text::sprintf('SR_EXP_ERROR_GUEST_FIELD_CANNOT_EMPTY', Text::_('SR_GUEST_' . strtoupper($fieldName))));

										return false;
									}

									$dbValue .= ',' . $db->quote($value);
								}
							}
						}

						$dbValues[] = $dbValue . ',' . $db->quote(json_encode($columns));
					}
				}

				$dbColumns[] = 'columns';
			}

			if ($resTable->store())
			{
				if ($fields = SRCustomFieldHelper::findFields(array('context' => SRExperienceHelper::getCustomFieldContext())))
				{
					$customFieldData = [];
					$reservationId   = $resTable->get('id');
					$context         = SRExperienceHelper::getCustomFieldContext($reservationId);
					$uploadBasePath  = 'media/com_solidres/assets/files';

					foreach ($fields as $field)
					{
						$fieldName = $field->field_name;
						$value     = isset($data[$fieldName]) ? $data[$fieldName] : null;

						if ($field->type == 'file'
							&& is_array($value)
							&& isset($value['name'])
							&& isset($value['tmp_name'])
						)
						{
							$fileName = File::makeSafe($value['name']);

							if (!is_dir(JPATH_SITE . '/' . $uploadBasePath))
							{
								Folder::create(JPATH_SITE . '/' . $uploadBasePath, 0755);
							}

							$fileName = 'experience' . $reservationId . '-' . md5(json_encode($value)) . '_' . $fileName;

							if (File::upload($value['tmp_name'], JPATH_SITE . '/' . $uploadBasePath . '/' . $fileName))
							{
								$value = 'file://' . $uploadBasePath . '/' . $fileName;
							}
						}

						if (isset($value))
						{
							$customFieldData[] = [
								'id'      => 0,
								'context' => $context,
								'value'   => $value,
								'storage' => $field,
							];
						}
					}

					if ($customFieldData)
					{
						SRCustomFieldHelper::storeValues($customFieldData, true);
					}
				}

				if (isset($dbColumns) && isset($dbValues))
				{
					$query = $db->getQuery(true)
						->insert($db->quoteName('#__sr_experience_reservation_guests'))
						->columns($db->quoteName($dbColumns))
						->values(array_map(function ($dbValue) use ($resTable) {
							return str_replace('{{reservation_id}}', $resTable->id, $dbValue);
						}, $dbValues));
					$db->setQuery($query)->execute();
				}

				if (!empty($data['extrasCalculated']))
				{
					$query         = $db->getQuery(true)
						->insert($db->quoteName('#__sr_experience_reservation_extra_xref'))
						->columns(array('reservation_id', 'extra_id', 'extra_name', 'extra_quantity', 'extra_price', 'extra_taxes', 'extra_description'));
					$reservationId = (int) (int) $resTable->id;

					foreach ($data['extrasCalculated'] as $id => $extra)
					{
						$query->values(
							$db->quote($reservationId) . ','
							. $db->quote($id) . ','
							. $db->quote($extra['name']) . ','
							. $db->quote($extra['quantity']) . ','
							. $db->quote($extra['price']) . ','
							. $db->quote($extra['taxes']) . ','
							. $db->quote($extra['description'])
						);
					}

					$db->setQuery($query)
						->execute();
				}

				if (!empty($data['coupons']))
				{
					foreach ($data['coupons'] as $code => $coupon)
					{
						if ($coupon['applied'])
						{
							$query = $db->getQuery(true)
								->update($db->quoteName('#__sr_coupons'))
								->set($db->quoteName('quantity') . ' = ' . $db->quoteName('quantity') . ' - 1')
								->where($db->quoteName('scope') . ' = 1')
								->where($db->quoteName('quantity') . ' IS NOT NULL AND ' . $db->quoteName('quantity') . ' > 0')
								->where($db->quoteName('coupon_code') . ' = ' . $db->quote($code));
							$db->setQuery($query)
								->execute();
						}
					}
				}

				CMSFactory::getApplication()->triggerEvent('onExperienceReservationAfterSave', [$data, $resTable, $isNew, $this]);

				return $resTable;
			}
			else
			{
				foreach ($resTable->getErrors() as $error)
				{
					$this->setError($error);
				}
			}
		}
		else
		{
			$this->setError(Text::_('SR_ERROR_TOUR_NOT_FOUND'));
		}

		return false;

	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit