Your IP : 216.73.216.224


Current Path : /var/www/html/components/com_osmembership/view/fieldlayout/
Upload File :
Current File : /var/www/html/components/com_osmembership/view/fieldlayout/signature.php

<?php
/**
 * @package        Joomla
 * @subpackage     Membership Pro
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2012 - 2026 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;

/**
 * Layout variables
 *
 * @var OSMembershipHelperBootstrap|null $bootstrapHelper
 * @var string                           $name
 * @var string|null                      $value
 * @var stdClass                         $row
 */

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();

$wa->registerAndUseScript(
	'com_osmembership.signature_pad',
	'media/com_osmembership/assets/js/signature_pad/signature_pad.umd.min.js',
	[],
	['defer' => true]
);

$wa->registerAndUseScript(
	'com_osmembership.field_signature',
	'media/com_osmembership/js/field-signature.min.js',
	['version' => 'auto'],
	['defer' => true],
	['com_osmembership.signature_pad']
);

$wa->registerAndUseStyle(
	'com_osmembership.field_signature',
	'media/com_osmembership/assets/css/field-signature.min.css',
	['version' => 'auto']
);

$uniqueId     = 'osm_sig_' . $name;
$hasSignature = $value && preg_match('/^[a-f0-9]{32}\.png$/i', (string) $value);

// Determine button class based on the active CSS framework
if ($bootstrapHelper)
{
	$btnClass = $bootstrapHelper->getClassMapping('btn') . ' ' . $bootstrapHelper->getClassMapping('btn-small');
}
else
{
	$btnClass = 'btn btn-sm btn-secondary';
}
?>
<div class="osm-signature-wrapper">
	<canvas id="<?php echo $uniqueId; ?>_canvas"
	        class="osm-signature-canvas"
	        width="400" height="200"></canvas>
	<br>
	<button type="button"
	        id="<?php echo $uniqueId; ?>_clear"
	        class="osm-signature-clear <?php echo htmlspecialchars($btnClass, ENT_COMPAT, 'UTF-8'); ?>">
		<?php echo Text::_('OSM_SIGNATURE_CLEAR'); ?>
	</button>
	<!-- Hidden field that stores the base64 PNG data URI for submission -->
	<input type="hidden"
	       name="<?php echo htmlspecialchars($name, ENT_COMPAT, 'UTF-8'); ?>"
	       id="<?php echo $uniqueId; ?>_data"
	       class="osm-signature-data"
	       value="<?php echo $hasSignature ? htmlspecialchars($value, ENT_COMPAT, 'UTF-8') : ''; ?>" />
</div>
<?php
if ($hasSignature)
{
	$signatureUrl = Uri::root() . 'index.php?option=com_osmembership&task=render_signature&signature_file=' . rawurlencode($value);
	?>
	<div id="<?php echo $uniqueId; ?>_existing" class="osm-signature-existing">
		<div><?php echo Text::_('OSM_CURRENT_SIGNATURE'); ?></div>
		<img src="<?php echo htmlspecialchars($signatureUrl, ENT_COMPAT, 'UTF-8'); ?>"
		     alt="<?php echo Text::_('OSM_CURRENT_SIGNATURE'); ?>"
		     class="osm-signature-image" />
	</div>
	<?php
}