<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

include_once 'calendar_functions.php';

/******************************************************************
// load viewer library
*******************************************************************/
$libraryPath = 'cmsb/lib/viewer_functions.php';
$dirsToCheck = ['','../','../../','../../../','../../../../']; // add if needed: '/home/customer/www/rodneys46.sg-host.com/public_html/'
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

include_once("all-CMS.php");

// Retrieve and validate GET parameters for the view and navigation
$params = getCalendarParams();
$view  = $params['view'];
$year  = $params['year'];
$month = $params['month'];
$week  = $params['week'];
$day   = $params['day'];


// Determine if we're in example mode or production mode (can be based on a constant or environment variable)
$mode = 'production'; // or 'example'


// Check the execution mode
if ($mode === 'production') {

	$FORMAT_START = 'Y-m-d 00:00:00';  // Format for the start of a period (midnight)
	$FORMAT_END   = 'Y-m-d 23:59:59';  // Format for the end of a period (11:59 PM)

	switch ($view) {
		case 'month':
			// Create a date for the first day of the month
			$date = sprintf("%04d-%02d-01", $year, $month);
			
			// For the month, take the previous and next month
			$debut = date($FORMAT_START, strtotime("$date -1 month"));               // Previous month
			$fin   = date($FORMAT_END, strtotime("$date +1 month +1 month -1 day")); // End of the next month
			
			// Look for events that overlap with this period
			$query = "start_date <= '$fin' AND end_date >= '$debut'";
			break;

		case 'week':
			// Create a date for the first day of the week
			$debut_semaine = date($FORMAT_START, strtotime("{$year}-W{$week}"));
			
			// Take the previous and next week
			$debut = date($FORMAT_START, strtotime("$debut_semaine -1 week"));      // Previous week
			$fin   = date($FORMAT_END, strtotime("$debut_semaine +2 week -1 day")); // End of the next week
			
			// Look for events that overlap with this period
			$query = "start_date <= '$fin' AND end_date >= '$debut'";
			break;

		case 'day':
			// Create the start and end dates for the specified day
			$debut = sprintf("%04d-%02d-%02d 00:00:00", $year, $month, $day);
			$fin   = sprintf("%04d-%02d-%02d 23:59:59", $year, $month, $day);
			
			// Look for events happening on that day
			$query = "(start_date BETWEEN '$debut' AND '$fin') 
					  OR (end_date BETWEEN '$debut' AND '$fin')
					  OR (start_date <= '$debut' AND end_date >= '$fin')";
			break;
			
		case 'year':
			// Create the start and end dates for the year
			$debut = sprintf("%04d-01-01 00:00:00", $year);
			$fin   = sprintf("%04d-12-31 23:59:59", $year);
			
			// Look for events happening this year
			$query = "(start_date BETWEEN '$debut' AND '$fin') 
					  OR (end_date BETWEEN '$debut' AND '$fin')
					  OR (start_date <= '$debut' AND end_date >= '$fin')";
			break;
			
		default:
			// If the view is not valid, return an empty string
			$query = "";
			break;
	}

    // Load records from the 'events' table
    list($events) = getRecords(array(
        'tableName'   => 'events',
        'where'       => $query,
        'loadUploads' => true,
        'allowSearch' => false,
        'debugSql'    => false,
    ));

} else {

	// Example mode: use a static array with mock events
	$events = [
		[
			'title' => 'Annual Conference',
			'start_date' => '2024-10-21 09:00:00',
			'end_date' => '2024-10-21 17:00:00',
			'permalink' => 'annual-conference',
			'description' => 'Annual conference on technological innovations.',
			'location' => 'Main Auditorium',
			'category' => 'conference'
		],
		[
			'title' => 'Digital Marketing Seminar',
			'start_date' => '2024-10-22 10:00:00',
			'end_date' => '2024-10-22 15:00:00',
			'permalink' => 'digital-marketing-seminar',
			'description' => 'Seminar on the latest trends in digital marketing.',
			'location' => 'Meeting Room B',
			'category' => 'conference'
		],
		[
			'title' => 'Team Meeting',
			'start_date' => '2024-10-25 14:00:00',
			'end_date' => '2024-10-26 12:00:00',
			'permalink' => 'team-meeting',
			'description' => 'Weekly team meeting to discuss progress.',
			'location' => 'Conference Room C',
			'category' => 'conference'
		],
		[
			'title' => 'PHP Workshop...',
			'start_date' => '2024-11-02 07:30:00',
			'end_date' => '2024-11-02 17:00:00',
			'permalink' => 'php-workshop',
			'description' => 'A hands-on workshop on PHP development.',
			'location' => 'Training Room D',
			'category' => 'workshop'
		],
		[
			'title' => 'Product Launch',
			'start_date' => '2024-11-30 10:00:00',
			'end_date' => '2024-11-30 16:00:00',
			'permalink' => 'product-launch',
			'description' => 'Launch event for our new product.',
			'location' => 'Main Hall',
			'category' => 'workshop'
		],
		[
			'title' => 'Holiday Party W49',
			'start_date' => '2024-12-01 18:00:00',
			'end_date' => '2024-12-01 23:00:00',
			'permalink' => 'holiday-party',
			'description' => 'Annual holiday party for all employees.',
			'location' => 'Rooftop Lounge',
			'holiday' => 'holiday'
		],
		[
			'title' => 'Year-End Review W49',
			'start_date' => '2024-12-02 14:00:00',
			'end_date' => '2024-12-02 17:00:00',
			'permalink' => 'year-end-review',
			'description' => 'Review of the year\'s achievements and goals.',
			'location' => 'Conference Room A',
			'category' => 'conference'
		]
	];
}


/******************************************************************
// Set HTTP headers for cache control
*******************************************************************/
header('Cache-Control: no-cache, no-store, must-revalidate'); // No caching allowed
header('Expires: 0'); // Set expiration to 0
header_remove('Pragma'); // Remove pragma header

?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Calendar <?php echo date('Y'); ?></title>    
        <meta charset="utf-8">
        <!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        
        <link rel=canonical href=#/ >
        
        <!-- Favicons -->
        <link rel="shortcut icon" href="../images/favicon.png">
    
         <!-- CSS -->
        <link rel="stylesheet" href="../css/bootstrap.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <link rel="stylesheet" href="../css/style-responsive.css">
        <link rel="stylesheet" href="../css/vertical-rhythm.min.css">
        <link rel="stylesheet" href="../css/magnific-popup.css">
        <link rel="stylesheet" href="../css/owl.carousel.css">
        <link rel="stylesheet" href="../css/animate.min.css">
        <link rel="stylesheet" href="../css/splitting.css">
        <link rel="stylesheet" href="../css/calendar.css">
        
        <!-- CSS Fonts -->
        <link rel="stylesheet" href="https://use.typekit.net/fca2gup.css">
        <script src="https://kit.fontawesome.com/840fe7a337.js" crossorigin="anonymous"></script>
        
        <style>
            #main {background-color: #00699d;}            
            .side-nav.dark .sidebar .nav-link { color: #000;}
            .main-nav-side.dark {border-top: 1px dotted rgba(184, 154, 116);}
            .main-nav.dark .inner-nav ul > li > a {color: #fff}
            .main-nav-side.dark li a{color: rgba(184, 154, 116);}
            table {margin-bottom:0px}
        </style>

</head>

 <body class="appear-animate">
    
<!-- Page Loader -->        
        <div class="page-loader">
            <div class="loader">Loading...</div>
        </div>
        <!-- End Page Loader -->
     
             <!-- Skip to Content -->
        <a href="#main" class="btn skip-to-content">Skip to Content</a>
        <!-- End Skip to Content -->

<!-- Page Wrap -->
        <div class="page" id="top">
            
           <!-- Navigation panel -->
            <nav class="main-nav dark light-after-scroll transparent stick-fixed wow-menubar">
                <div class="full-wrapper relative clearfix">
                    
                    <div class="container relative full-width">
                            <div class="row section-text">
                            
                                <div class="col-md-4 col-lg-4 offset-md-4 offset-sm-0">
                                    <div class="text-center mb-sm-50">
                        <div class="nav-logo-wrap local-scroll">
                        <a href="/" class="logo">
                            <img src="../images/Worth-Abbey-logo-reverse.svg" alt="Worth Abbey" width="188" height="37" class="logo-white" />
                            <img src="../images/Worth-Abbey-illustration-icon.svg" alt="Worth Abbey" width="188" height="37" class="logo-dark" />
                        </a>
                    </div>
                        </div> 
                                </div>
                                
                                <?php include_once("top-navigation.php"); ?>
                                
                            </div>
                        </div>
                    
                    
                    
                </div>
            </nav>
            <!-- End Navigation panel -->
            
            <div class="side-nav dark light-after-scroll stick-fixed">
                    
                    <!-- Main Menu -->
                   <nav class="navbar navbar-expand-xl navbar-light">
  <div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
      
      
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <nav class="sidebar">
            
           <?php include_once("top-navigation-mobile.php"); ?>

            
<ul class="nav flex-column" id="nav_accordion">
	<li class="nav-item">
		<a class="nav-link" data-bs-toggle="collapse" data-bs-target="#menu_item1" href="#">Visit Worth Abbey</a>
		<ul id="menu_item1" class="submenu collapse" data-bs-parent="#nav_accordion">
        <?php foreach ($visit_navigationRecords as $categoryRecord): ?>
          <?php echo $categoryRecord['_listItemStart'] ?>

          <?php if ($categoryRecord['_isSelected']): ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php else: ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php endif; ?>

          <?php echo $categoryRecord['_listItemEnd'] ?>
        <?php endforeach; ?>
      </ul>
	</li>
	
		<li class="nav-item">
		<a class="nav-link" data-bs-toggle="collapse" data-bs-target="#menu_item2" href="#">Our Life As Monks</a>
		<ul id="menu_item2" class="submenu collapse" data-bs-parent="#nav_accordion">
			<?php foreach ($life_navigationRecords as $categoryRecord): ?>
          <?php echo $categoryRecord['_listItemStart'] ?>

          <?php if ($categoryRecord['_isSelected']): ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php else: ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php endif; ?>

          <?php echo $categoryRecord['_listItemEnd'] ?>
        <?php endforeach; ?>
		</ul>
	</li>
	
	<li class="nav-item">
		<a class="nav-link" data-bs-toggle="collapse" data-bs-target="#menu_item3" href="#">Connect With Us</a>
		<ul id="menu_item3" class="submenu collapse" data-bs-parent="#nav_accordion">
            <?php foreach ($connect_navigationRecords as $categoryRecord): ?>
          <?php echo $categoryRecord['_listItemStart'] ?>

          <?php if ($categoryRecord['_isSelected']): ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php else: ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php endif; ?>

          <?php echo $categoryRecord['_listItemEnd'] ?>
        <?php endforeach; ?>
      </ul>
	</li>
	
	<li class="nav-item">
		<a class="nav-link" data-bs-toggle="collapse" data-bs-target="#menu_item4" href="#">About Us</a>
		<ul id="menu_item4" class="submenu collapse" data-bs-parent="#nav_accordion">
            <?php foreach ($about_navigationRecords as $categoryRecord): ?>
          <?php echo $categoryRecord['_listItemStart'] ?>

          <?php if ($categoryRecord['_isSelected']): ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php else: ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php endif; ?>

          <?php echo $categoryRecord['_listItemEnd'] ?>
        <?php endforeach; ?>
            <li><a class="nav-link" href="/contact-us/">Contact Us</a></li>
      </ul>
	</li>
	
	<li class="nav-item">
		<a class="nav-link" data-bs-toggle="collapse" data-bs-target="#menu_item5" href="#">News &amp; Events</a>
		<ul id="menu_item5" class="submenu collapse show" data-bs-parent="#nav_accordion">
            <?php foreach ($news_navigationRecords as $categoryRecord): ?>
          <?php echo $categoryRecord['_listItemStart'] ?>

          <?php if ($categoryRecord['_isSelected']): ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php else: ?>
            <a class="nav-link" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
          <?php endif; ?>

          <?php echo $categoryRecord['_listItemEnd'] ?>
        <?php endforeach; ?>
      </ul>
	</li>
</ul>
			
<ul class="main-nav-side dark light-after-scroll logo clearlist">
            <img src="../images/Worth-Crest-gold.svg" alt="Worth Abbey" width="188" height="37" class="logo-white" />
            <img src="../images/Worth-Crest-gold.svg" alt="Worth Abbey" width="188" height="37" class="logo-dark" />
            <li class="mt-10 ml-40"><a href="#"><i class="fa-brands fa-facebook-f"></i> Follow Us</a></li>
     </ul>
</nav>
    </div>
  </div>
</nav>
                <!-- End Main Menu -->
            </div>
            
            <main id="main">
				<!-- Home Section -->
                <?php foreach ($selectedNews_navigation['banner_image'] as $index => $upload): ?>
                <section class="page-section bg-scroll page-section-detail-abbey" data-background="<?php echo htmlencode($upload['urlPath']) ?>" id="home">
                    <?php endforeach ?>
					<div class="circle-container">
                    <div class="circle">
                        <div class="h1-container">
                            <h1 class="hs-line-11 serif"><?php echo htmlencode($selectedNews_navigation['name']) ?></h1></div>
                        </div>
                    </div>
                    
                       
                 </section>
                <!-- End Home Section -->
				
                
                <!-- About Section -->
                <section class="page-section section-padding content-section pt-sm-20 pt-100 pb-50" id="about">
                    <div class="full-wrapper relative content-text">
                    <?php 
	// Display the view switcher to toggle between 'month', 'week', and 'day' views
	renderViewSwitcher($month, $year, $week, $view, $lang, $translations);

	// Select and display the calendar view based on the user's choice (month, week, day, year)
	if ($view == 'month') {

		// Display navigation for the month (buttons to go to the previous or next month)
		renderMonthNavigation($month, $year, $lang, $translations);

		// Display the monthly view with the month's events
		renderMonthCalendar($month, $year, $events, $weekStart, $lang, $translations);

	} elseif ($view == 'week') {

		// Display navigation for the week (buttons to go to the previous or next week)
		renderWeekNavigation($year, $week, $lang, $translations);

		// Display the weekly view with the week's events
		renderWeekView($month, $year, $week, $events, $weekStart, $lang, $translations, $workingStartTime, $workingEndTime);

	} elseif ($view == 'day') {

		// Display navigation for the day (buttons to go to the previous or next day)
        renderDayNavigation($month, $year, $day, $lang, $translations);

		// Display the daily view with events, including the hours of the day
		renderDayViewWithHours($month, $year, $day, $events, $lang, $translations, $workingStartTime, $workingEndTime);
		
	} elseif ($view == 'year') {

		// Display navigation for the year
		renderYearNavigation($year, $lang, $translations);

		// Display the annual calendar
		renderYearCalendar($year, $events, $weekStart, $lang, $translations);
	}
?>
                    </div>
                </section>
                <!-- End About Section -->
                 
                
            </main>
            
           <!-- Footer -->
			<section class="page-section parallax-5">
                    <div class="container pt-100 pb-100 pt-md-20">
                        
                        <!-- Round Edge -->
                        <div class="edge-bottom-figure">                            
                            <svg class="svg-angle-green" viewBox="0 0 100 100" preserveAspectRatio="none">
        <polygon points="0,100 100,0 100,100" />
    </svg>
                        </div>
                        <!-- Env Round Edge -->
                        
                    </div>
                </section>
            
            <?php include_once("footer.php"); ?>
            <!-- End Footer -->
        
        </div>
        <!-- End Page Wrap -->


     
        <!-- JS -->
        <script src="../js/jquery-3.5.1.min.js"></script>
        <script src="../js/jquery.easing.1.3.js"></script>
        <script src="../js/bootstrap.bundle.min.js"></script>
        <script src="../js/SmoothScroll.js"></script>
        <script src="../js/jquery.scrollTo.min.js"></script>
        <script src="../js/jquery.localScroll.min.js"></script>
        <script src="../js/jquery.viewport.mini.js"></script>
        <script src="../js/jquery.countTo.js"></script>
        <script src="../js/jquery.appear.js"></script>
        <script src="../js/jquery.parallax-1.1.3.js"></script>
        <script src="../js/jquery.fitvids.js"></script>
        <script src="../js/owl.carousel.min.js"></script>
        <script src="../js/isotope.pkgd.min.js"></script>
        <script src="../js/imagesloaded.pkgd.min.js"></script>
        <script src="../js/jquery.magnific-popup.min.js"></script>
        <script src="../js/masonry.pkgd.min.js"></script>
        <script src="../js/jquery.lazyload.min.js"></script>
        <script src="../js/wow.min.js"></script>
        <script src="../js/morphext.js"></script>
        <script src="../js/typed.min.js"></script>
        <script src="../js/all.js"></script>
        <script src="../js/jquery.ajaxchimp.min.js"></script>
        <script src="../js/splitting.min.js"></script>
     
</body>

</html>