<?php debug_backtrace() || die ("Direct access not permitted"); ?>
<?php
if (!function_exists('pms_format_gmt_date')) {
function pms_format_gmt_date($format, $timestamp = null) # BINARIQUE EDITED
{
    if ($timestamp === null) {
        $timestamp = time();
    }

    // For PHP 8.1+ where strftime is deprecated
    if (function_exists('datefmt_format_object')) {
        $map = [
            '%a' => 'EEE',    // Abbreviated weekday name
            '%A' => 'EEEE',   // Full weekday name
            '%b' => 'MMM',    // Abbreviated month name
            '%B' => 'MMMM',   // Full month name
            '%c' => 'yyyy-MM-dd HH:mm:ss', // Preferred date and time representation
            '%C' => 'yy',     // Century number (year/100)
            '%d' => 'dd',     // Day of the month (01-31)
            '%D' => 'MM/dd/yy', // Short MM/DD/YY date
            '%e' => 'd',      // Day of the month (1-31) with single digits preceded by space
            '%F' => 'yyyy-MM-dd', // ISO 8601 date
            '%g' => 'yy',     // Two-digit year (ISO 8601)
            '%G' => 'yyyy',   // Four-digit year (ISO 8601)
            '%h' => 'MMM',   // Abbreviated month name (same as %b)
            '%H' => 'HH',     // Hour in 24h format (00-23)
            '%I' => 'hh',     // Hour in 12h format (01-12)
            '%j' => 'D',      // Day of the year (001-366)
            '%k' => 'H',      // Hour in 24h format (0-23) with single digits preceded by space
            '%l' => 'h',      // Hour in 12h format (1-12) with single digits preceded by space
            '%m' => 'MM',     // Month as decimal number (01-12)
            '%M' => 'mm',     // Minute (00-59)
            '%n' => "\n",     // Newline character
            '%p' => 'a',      // AM or PM
            '%P' => 'a',      // am or pm (lowercase)
            '%r' => 'hh:mm:ss a', // 12-hour time with AM/PM
            '%R' => 'HH:mm',  // 24-hour time without seconds
            '%S' => 'ss',     // Second (00-61)
            '%t' => "\t",     // Tab character
            '%T' => 'HH:mm:ss', // 24-hour time with seconds
            '%u' => 'e',      // ISO 8601 weekday as number (1-7, Monday is 1)
            '%U' => 'w',      // Week number with Sunday as first day (00-53)
            '%V' => 'ww',     // ISO 8601 week number (01-53)
            '%w' => 'e',     // Weekday as decimal (0-6, Sunday is 0)
            '%W' => 'w',      // Week number with Monday as first day (00-53)
            '%x' => 'yyyy-MM-dd', // Preferred date representation
            '%X' => 'HH:mm:ss', // Preferred time representation
            '%y' => 'yy',     // Two-digit year (00-99)
            '%Y' => 'yyyy',   // Four-digit year
            '%z' => 'xx',    // Timezone offset
            '%Z' => 'zzz',    // Timezone name or abbreviation
            '%%' => '%'       // Literal % character
        ];

        $intlFormat = strtr($format, $map);

        try {
            $date = new DateTime('@' . $timestamp);
            $date->setTimezone(new DateTimeZone('UTC'));

            $formatter = new IntlDateFormatter(
                'en_US',
                IntlDateFormatter::FULL,
                IntlDateFormatter::FULL,
                'UTC',
                IntlDateFormatter::GREGORIAN,
                $intlFormat
            );

            // Handle special cases that IntlDateFormatter doesn't support directly
            $result = $formatter->format($date);

            // Post-processing for formats that don't map perfectly
            if (strpos($format, '%P') !== false) {
                $result = strtolower($result);
            }
            if (strpos($format, '%e') !== false) {
                $result = str_replace(' 1', ' 1', $result); // Space-padded day
            }

            return $result;
        } catch (Exception $e) {
            return false;
        }
    }

    // For older PHP versions where strftime is available
    if (function_exists('gmstrftime')) {
        error_reporting(0);
        return gmstrftime($format, $timestamp);
    }

    // Fallback for very old PHP versions (shouldn't be needed in practice)
    return date($format, $timestamp);
}
///////////
}
/////////////////////////////////

?>
<footer>
    <section id="mainFooter">
        <div class="container" id="footer">
            <div class="row">
                <div class="col-md-4">
                    <?php pms_displayWidgets("footer_col_1", $pms_page_id); ?>
                </div>
                <div class="col-md-4">
                    <?php pms_displayWidgets("footer_col_2", $pms_page_id); ?>
                </div>
                <div class="col-md-4">
                    <?php pms_displayWidgets("footer_col_3", $pms_page_id); ?>
                </div>
            </div>
        </div>
    </section>
    <div id="footerRights">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <p>
                        &copy; <?php echo date("Y"); ?>
                        <?php echo PMS_OWNER." ".$pms_texts['ALL_RIGHTS_RESERVED']; ?>
                    </p>
                </div>
                <div class="col-md-6">
                    <p class="text-right">
                        <a href="<?php echo DOCBASE; ?>feed/" target="_blank" title="<?php echo $pms_texts['RSS_FEED']; ?>"><i class="fas fa-fw fa-rss"></i></a>
                        <?php
                        foreach($pms_menus['footer'] as $nav_id => $nav){ ?>
                            <a href="<?php echo $nav['href']; ?>" title="<?php echo $nav['title']; ?>"><?php echo $nav['name']; ?></a>
                            &nbsp;&nbsp;
                            <?php
                        } ?>
                    </p>
                </div>
            </div>
        </div>
    </div>
</footer>

<?php
$result_popup = $pms_db->query('SELECT * FROM pm_popup
                            WHERE lang = '.PMS_LANG_ID.'
                                AND checked = 1 
                                AND (publish_date IS NULL || publish_date <= '.time().')
                                AND (unpublish_date IS NULL || unpublish_date > '.time().')
                                AND (allpages = 1 OR pages REGEXP \'(^|,)'.$pms_page_id.'(,|$)\')
                            LIMIT 1');
if($result_popup !== false && $pms_db->last_row_count() > 0){
    $row = $result_popup->fetch();
    
    $id_popup = $row['id'];
    
    if(!isset($_SESSION['popup_'.$id_popup])){
        $popup_content = $row['content'];
        $popup_bg = $row['background'];
        
        $_SESSION['popup_'.$id_popup] = 1; ?>
        
        <a class="popup-modal hide" href="#popup-<?php echo $id_popup; ?>"></a>
        
        <div id="popup-<?php echo $id_popup; ?>" class="white-popup-block mfp-hide"<?php if(!empty($popup_bg)) echo ' style="background-color:'.$popup_bg.';"'; ?>>
            <div class="fluid-container">
                <div class="row">
                    <div class="col-md-12">
                        <?php echo $popup_content; ?>
                    </div>
                </div>
            </div>
        </div>
        <?php
    }
} ?>

<?php
if(isset($_SESSION['book'])
 && $pms_page_id != $pms_sys_pages['booking-activities']['id']
 && $pms_page_id != $pms_sys_pages['details']['id']
 && $pms_page_id != $pms_sys_pages['summary']['id']
 && $pms_page_id != $pms_sys_pages['payment']['id']
 && isset($_SESSION['book']['rooms'])
 && count($_SESSION['book']['rooms']) > 0){ ?>
	<div id="booking-cart" class="alert alert-dismissible">
        <form method="post" class="ajax-form">
            <a href="#" class="close sendAjaxForm" data-action="<?php echo pms_getFromTemplate('common/cancel_booking.php'); ?>" data-dismiss="alert" aria-label="close">&times;</a>
            <?php
            if(isset($_SESSION['book']['rooms']) && count($_SESSION['book']['rooms']) > 0){
                $rooms = array_keys($_SESSION['book']['rooms']);
                $id_room = array_shift($rooms);
                $result_room_file = $pms_db->query('SELECT * FROM pm_room_file WHERE id_item = '.$id_room.' AND checked = 1 AND lang = '.PMS_LANG_ID.' AND type = \'image\' AND file != \'\' ORDER BY `rank`');
                if($result_room_file !== false && $pms_db->last_row_count() > 0){
                    $row = $result_room_file->fetch(PDO::FETCH_ASSOC);

                    $file_id = $row['id'];
                    $filename = $row['file'];
                    $label = $row['label'];

                    $realpath = SYSBASE.'medias/room/small/'.$file_id.'/'.$filename;
                    $thumbpath = DOCBASE.'medias/room/small/'.$file_id.'/'.$filename;
                    $zoompath = DOCBASE.'medias/room/big/'.$file_id.'/'.$filename;

                    if(is_file($realpath)){
                        $s = getimagesize($realpath); ?>
                        <div class="img-container sm pull-left">
                            <img alt="<?php echo $label; ?>" src="<?php echo $thumbpath; ?>">
                        </div>
                        <?php
                    }
                }
            }
            $step = (isset($_SESSION['book']['step'])) ? $_SESSION['book']['step'] : 'details'; ?>
            <a href="<?php echo DOCBASE.$pms_sys_pages[$step]['alias']; ?>" class="alert-link"><?php echo $pms_texts['COMPLETE_YOUR_BOOKING']; ?></a><br>
            <small><?php echo pms_format_gmt_date(PMS_DATE_FORMAT, $_SESSION['book']['from_date']); ?> <i class="fas fa-fw fa-arrow-right"></i> <?php echo pms_format_gmt_date(PMS_DATE_FORMAT, $_SESSION['book']['to_date']); ?></small><br>
			<?php if(isset($_SESSION['book']['num_rooms'])) echo $_SESSION['book']['num_rooms'].' '.pms_getAltText($pms_texts['ROOM'], $pms_texts['ROOMS'], $_SESSION['book']['num_rooms']); ?>
            <b><?php if($_SESSION['book']['total'] > 0) echo ' - '.pms_formatPrice($_SESSION['book']['total']); ?></b>
            <div class="clearfix"></div>
        </form>
	</div>
	<?php
} ?>

<a href="#" id="toTop"><i class="fas fa-fw fa-angle-up"></i></a>

<!--[if lt IE 9]>
    <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.18/js/bootstrap-select.min.js"></script>
<script src="//rawgit.com/tuupola/jquery_lazyload/2.x/lazyload.min.js"></script>
<script src="<?php echo DOCBASE; ?>common/js/modernizr-2.6.1.min.js"></script>

<script>
    Modernizr.load({
        load : [
            '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js',
            '//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js',
            '//code.jquery.com/ui/1.12.1/jquery-ui.js',
            <?php if(PMS_LANG_TAG != "en") : ?>'//rawgit.com/jquery/jquery-ui/master/ui/i18n/datepicker-<?php echo PMS_LANG_TAG; ?>.js',<?php endif; ?>
            '//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js',
            '//cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js',
            '//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js',
            
            //Javascripts required by the current model
            <?php if(isset($pms_javascripts)) foreach($pms_javascripts as $javascript) echo "'".$javascript."',\n"; ?>
            
            '//unpkg.com/imagesloaded@4/imagesloaded.pkgd.min.js',
            '<?php echo DOCBASE; ?>js/plugins/imagefill/js/jquery-imagefill.js',
            '<?php echo DOCBASE; ?>js/plugins/toucheeffect/toucheffects.js',
            '//use.fontawesome.com/releases/v5.15.3/js/all.js'
        ],
        complete : function(){
            Modernizr.load({
                load : [
                    '<?php echo DOCBASE; ?>common/js/custom.js',
                    '<?php echo DOCBASE; ?>js/custom.js'
                ]
            });
        }
    });
    
    $(function(){
		<?php
		if(PMS_ENABLE_ICAL && PMS_ENABLE_AUTO_ICAL_SYNC){ ?>
			$.ajax({
				url: '<?php echo DOCBASE; ?>includes/icalendar/ical_import.php',
				type: 'POST',
				data: 'ical_sync_mode=auto'
			});
			<?php
		}
        if(isset($msg_error) && $msg_error != ""){
            $str = mb_ereg_replace("(\r\n|\n|\r)","'+\n'",nl2br($msg_error));
            if(!empty($str)){ ?>
                $('.alert-danger').html('<?php echo $str; ?>').slideDown();
                <?php
            }
        }
        if(isset($msg_success) && $msg_success != ""){
            $str = mb_ereg_replace("(\r\n|\n|\r)","'+\n'",nl2br($msg_success));
            if(!empty($str)){ ?>
                $('.alert-success').html('<?php echo $str; ?>').slideDown();
                <?php
            }
        }
        if(isset($field_notice) && !empty($field_notice))
            foreach($field_notice as $field => $notice) echo "$('.field-notice[rel=\"".$field."\"]').html('".$notice."').fadeIn('slow').parent().addClass('alert alert-danger');\n"; ?>
    });
</script>
<script src='https://www.google.com/recaptcha/api.js?hl=<?php echo PMS_LANG_TAG; ?>'></script>
</body>
</html>
