AnonSec Shell
Server IP : 54.36.91.62  /  Your IP : 216.73.217.94
Web Server : Apache
System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User : coopiak ( 151928)
PHP Version : 8.3.23
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/coopiak/amisdesseniors-fr/voscatalogues/plugins/djcatalog2delivery/inpost/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/voscatalogues/plugins/djcatalog2delivery/inpost/inpost.php
<?php
/**
 * @package DJ-Catalog2
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 */

// no direct access
defined('_JEXEC') or die('Restricted access');


class plgDjcatalog2deliveryInpost extends JPlugin
{
	public function __construct(&$subject, $config = array())
	{
		parent::__construct($subject, $config);
		$this->loadLanguage();
	}
	
	protected function isAllowed($plgInfo, $type = 'djcatalog2delivery')
	{
		if (empty($plgInfo)) return false;
		return (bool)($plgInfo->plugin == $this->_name && $this->_type == $type);
	}
	
	public function onContentPrepareForm($form, $data)
	{
		if ($form->getName() != 'com_djcatalog2.delivery') {
			return;
		}
		
		$plugin = '';
		
		if (!empty($data) && !empty($data->plugin)) {
			$plugin = $data->plugin;
		} else {
			$jform = JFactory::getApplication()->input->get('jform', array(), 'array');
			if (!empty($jform) && isset($jform['plugin'])) {
				$plugin = $jform['plugin'];
			}
		}
		
		if ($plugin != $this->_name) {
			return true;
		}
		
		return $form->loadFile(dirname(__FILE__) . '/config/configuration.xml', false);
	}
	
	public function onDJC2DisplayBackendShipment($context, $table, $plgInfo)
	{
		if ($context != 'com_djcatalog2.order.delivery' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		
		$app = JFactory::getApplication();
		$shipmentId = isset($table->delivery_params['shipmentId']) ? $table->delivery_params['shipmentId'] : 0;
		
		
		// Create shippment form
		if (!$shipmentId) {
			$formId = 'inpost-' . $plgInfo->id;
			
			$modal_params = array();
			$modal_params['css'] = "inpostModal";
			$modal_params['height'] = "1100px;";
			$modal_params['url'] = JRoute::_('index.php?option=com_djcatalog2&task=order.displayDeliveryForm&id=' . $table->id . '&delivery_method_id=' . (int)$plgInfo->id . '&tmpl=component');
			
			
			$modalForm = JHTML::_('bootstrap.renderModal', $formId, $modal_params);
			
			$shippmentForm = array(
				'modal' => $modalForm,
				'button' => $this->getShippmentFormBtn($formId)
			);
			
		} else { // Get labels
			$shippmentForm = array(
				'button' => '<a href="' . JRoute::_('index.php?option=com_djcatalog2&task=order.downloadDeliveryLabel&oid=' . (int)$table->id) . '" class="btn" >' . JText::_('PLG_DJCATALOG2DELIVERY_INPOST_DOWNLOAD_LABEL') . '</a>'
			);
			
		}
		return $shippmentForm;
	}
	
	public function onDJC2DownloadDeliveryLabel($context, $table, $plgInfo)
	{
		
		if ($context != 'com_djcatalog2.order.delivery' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		$shipmentId = isset($table->delivery_params['shipmentId']) ? $table->delivery_params['shipmentId'] : 0;
		
		if ($shipmentId) {
			$app = JFactory::getApplication();
			$user = JFactory::getUser();
			if (!$user->authorise('core.manage', 'com_djcatalog2') && !$user->authorise('core.admin', 'com_djcatalog2')) {
				return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
			}
			$path = $this->getLabelPdf($shipmentId);
			
			if (empty($path) || strpos($path, 'media') === false || strpos($path, 'djcatalog2') === false) {
				$app->redirect('index.php?option=com_djcatalog2', JText::sprintf('COM_DJCATALOG2_ERROR_FILE_MISSING', $path), 'error');
				return false;
			}
			
			if (!DJCatalog2FileHelper::getFileByPath($path, null, 'text/csv')) {
				//JError::raiseError(404);
				throw new Exception('', 404);
				return false;
			}
			$app->close();
			return true;
		}
		
	}
	
	public function onDJC2ProcessCreateShipments($context, $table, $data, $plgInfo)
	{
		if ($context != 'com_djcatalog2.order.delivery' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		$app = JFactory::getApplication();
		
		$app->redirect('index.php?option=com_djcatalog2&task=order.displayDeliveryForm&id=' . $table->id . '&delivery_method_id=' . (int)$plgInfo->id . '&tmpl=component');
	}
	
	public function onDJC2BeforeSaveOrder($context, $table, $isNew, $plgInfo)
	{
		if ($context != 'com_djcatalog2.checkout.delivery' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		
		$app = JFactory::getApplication();
		$jinput = $app->input;
		
		$inpostPoint = $jinput->get('inpostPoint');
		
		if(!$inpostPoint || !strlen($inpostPoint)) {
			$app->enqueueMessage(JText::_('PLG_DJCATALOG2DELIVERY_INPOST_POINT_REQUIRED'), 'error');
			return false;
		}
		
		$delivery_params = array(
			'inpostPoint' => $inpostPoint
		);
		
		$table->delivery_params = json_encode($delivery_params);
		
		return true;
	}
	
	public function onDJC2AfterSaveOrder($context, $table, $isNew, $plgInfo)
	{
		if ($context != 'com_djcatalog2.checkout.delivery' || !$this->isAllowed($plgInfo)) {
			return;
		}
	}
	
	public function onDJC2CheckoutDetailsDisplay($context, $plgInfo)
	{
		if ($context != 'com_djcatalog2.checkout.delivery' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		$document = JFactory::getDocument();
		//$document->addScript('https://sandbox-geowidget.easypack24.net/js/sdk-for-javascript.js');
		$document->addScript('https://geowidget.easypack24.net/js/sdk-for-javascript.js');
		$document->addScript(JUri::base(true) . '/plugins/djcatalog2delivery/inpost/assets/js/djc2inpost.js');
		//$document->addStyleSheet('https://sandbox-geowidget.easypack24.net/css/easypack.css');
		$document->addStyleSheet('https://geowidget.easypack24.net/css/easypack.css');
		
		
		$html = '';
		if (trim(strip_tags($plgInfo->description)) != '') {
			$html = '<h4>' . $plgInfo->name . '</h4>';
			$html .= $plgInfo->description;
		}
		
		
		JText::script('PLG_DJCATALOG2DELIVERY_INPOST_SELECT_POINT');
		JText::script('PLG_DJCATALOG2DELIVERY_INPOST_SELECTED_POINT');
		JText::script('PLG_DJCATALOG2DELIVERY_INPOST_CHANGE_POINT');
		
		// Init js function
		$document->addScriptDeclaration('jQuery(document).ready(function() {DJC2Inpost(' . $plgInfo->id . ');});');
		
		
		return $html;
	}
	
	public function onDJC2OrderDetailsDisplay($context, $order, $plgInfo)
	{
		if ($context != 'com_djcatalog2.order.delivery' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		$html = '';
		if (trim(strip_tags($plgInfo->description)) != '') {
			$html = '<h4>' . $plgInfo->name . '</h4>';
			$html .= $plgInfo->description;
		}
		
		return $html;
	}
	
	public function onEmailAfterDeliveryDisplay($context, $data, $plgInfo) {
		if ($context != 'com_djcatalog2.cart.confirm' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		if (empty($data['id'])) {
			return;
		}
		
		$table = JTable::getInstance('Orders', 'Djcatalog2Table');
		if (!$table->load($data['id'])) {
			return;
		}
		
		$params = (!empty($table->delivery_params)) ? $table->delivery_params : false;
		if (empty($params)) {
			return;
		}
			
		$params = (is_array($params)) ? $params : json_decode($params, true);
		if (empty($params['inpostPoint'])) {
			return;
		}
		
		$html = $params['inpostPoint'];
		
		return $html;
	}
	
	private function setShipmentId($shipmentId, $orderId)
	{
		$order = new stdClass();
		$order->id = $orderId;
		$order->delivery_params = json_encode(array('shipmentId' => $shipmentId));
		
		$result = JFactory::getDbo()->updateObject('#__djc2_orders', $order, 'id');
	}
	
	public function renderShippmentForm($context, $table, $plgInfo)
	{
		if ($context != 'com_djcatalog2.order.delivery' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		$form = $this->getForm($context, $this->getConfigDir() . '/shippment.xml', $table, $plgInfo);
		$order = $table;
		
		ob_start();
		include($this->getConfigDir() . '/form.php');
		$html = ob_get_contents();
		ob_end_clean();
		return $html;
	}
	
	private function getForm($context, $path, $table, $plgInfo)
	{
		$app = JFactory::getApplication();
		$filledData = array('createShipments' => $app->getUserState($context));
		
		
		$shippmentForm = JForm::getInstance($context, $path, $filledData);
		
		if(isset($table->delivery_params['inpostPoint']) && $table->delivery_params['inpostPoint']) {
			$shippmentForm->setValue('point', 'createShipments.parcels', $table->delivery_params['inpostPoint']);
		}
		
		
		
		return $shippmentForm;
	}
	
	private function getShippmentFormBtn($formId)
	{
		return '<a href="#' . $formId . '" class="btn" data-toggle="modal">' . JText::_('PLG_DJCATALOG2DELIVERY_INPOST_CREATE_SHIPMENT') . '</a>';
	}
	
	private function getConfigDir()
	{
		return dirname(__FILE__) . '/config';
	}
	
	private function getBackendMedia()
	{
		return JPATH_ROOT . '/administrator/media/djcatalog2/delivery/inpost';
	}
	
	private function getLabelPdf($shipmentId)
	{
		$file = $this->getBackendMedia() . '/' . $shipmentId . '.pdf';
		
		if (JFile::exists($file)) return $file;
	}
	
	private function getEndpoint($endvironamnet)
	{
		return $endvironamnet ? 'https://api-shipx-pl.easypack24.net/' : 'https://sandbox-api-shipx-pl.easypack24.net/';
	}
	
	
	private function isCurlEnabled()
	{
		if (in_array('curl', get_loaded_extensions())) return true;
		
		return false;
	}
}

Anon7 - 2022
AnonSec Team