<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php header("Cache-Control: no-cache"); ?>
<?php
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = ['','../','../../','../../../','../../../../'];
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  list($sec_introRecords, $sec_introMetaData) = getRecords(array(
    'tableName'   => 'sec_intro',
    'where'       => "`sn` = 'bl'",
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $sec_introRecord = @$sec_introRecords[0]; // get first record
  if (!$sec_introRecord) { dieWith404("Record not found!"); } // show error message if no record found

  // load records from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'loadUploads' => true,
    'allowSearch' => true,
    'orderBy' 	  => "date DESC",
    'where'       => "`dnd`= 0",
  ));
     if(!@$_REQUEST['createdDate_keyword']){
     $curYear = date("Y");
   }
   else{
     $curYear = date("Y",strtotime($_REQUEST['createdDate_keyword']));
   }
//grouping by month/date
  $dateOptions=array();
  $query = "SELECT createdDate FROM `cmsb_blog` WHERE NOW()>=createdDate order by createdDate DESC";
  $records=mysql_query_fetch_all_assoc($query);
  
  foreach($records as $record) {
    $date = date("Y-m",strtotime($record['createdDate']));
    $year = date("Y",strtotime($record['createdDate']));
    $dateOptions[$year][$date]=date("F",strtotime($record['createdDate']));
  }
  $keys = array_keys($dateOptions);
  $min = min($keys);
  $max = max($keys);
?><!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="author" content="Blue Circle Designs">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="keywords" content="<?php echo htmlencode($sec_introRecord['keywords']) ?>">
    <meta name="description" content="<?php echo htmlencode($sec_introRecord['page_description']) ?>">
    <!-- title  -->
    <title><?php echo htmlencode($sec_introRecord['title']) ?><?php include("core-title-end.php") ?> </title>
	<?php include("core-head.php") ?>
</head>

<body>

    <!-- PAGE LOADING
    ================================================== -->
    <div id="preloader"></div>
	<?php include("core-analytics.php") ?>

    <!-- MAIN WRAPPER
    ================================================== -->
    <div class="main-wrapper">

        <!-- HEADER
        ================================================== -->
        <header class="header-style1 menu_area-light">
			<?php include("core-header.php") ?>
        </header>

        <!-- PAGE TITLE
        ================================================== -->
        <section class="top-position1 pt-0">
            <div class="page-title-section bg-img cover-background theme-overlay-blue-dark" data-overlay-dark="55" data-background="img/bg/bg-svc.jpg">
                <div class="container">
                    <div class="row">
                        <div class="col-lg-12">
                            <h1><?php echo htmlencode($sec_introRecord['title']) ?></h1>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="breadcrumb">
                            <ul>
                                <li><a href="index.php">Home</a></li>
                                <li><a href="blog.php"><?php echo htmlencode($sec_introRecord['title']) ?></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- BLOG DETAIL
        ================================================== -->
        <section class="pt-0 blog-detail">
            <div class="container">
                 <div class="section-heading4">
                    <span>Blog</span>
                    <h2>News and Information from BPC</h2>
                </div>
                <div class="row mt-3">
                    <!-- blog left -->
                    <div class="col-lg-8 mt-n2-9 mb-2-9 mb-lg-0">
                        <?php foreach ($blogRecords as $record): ?>
                        <div class="row g-0 mt-2-9 wow fadeIn" data-wow-delay="200ms">
                        	<?php foreach ($record['list_photo'] as $index => $upload): ?>
                            <div class="col-md-5 bg-img cover-background theme-overlay-blue-dark min-height-300 blog-image" data-background="<?php echo htmlencode($upload['urlPath']) ?>">
                            <?php endforeach ?>
                            </div>
                            <div class="col-md-7">
                                <div class="card card-style7 h-100">
                                    <div class="card-body">
                                        <div class="p-2 bg-primary d-inline-block mb-3">
                                            <h6 class="text-white mb-0 display-31"><?php echo date("D, M jS, Y", strtotime($record['date'])) ?></h6>
                                        </div>
                                        <h5 class="mb-0"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a></h5>
                                        <!--<ul class="blog-meta-list">
                                           <li><span class="ti-user pe-2 text-primary align-middle"></span><?php echo htmlencode($record['author']) ?></li>
                                            <li><span class="ti-tag pe-2 text-primary align-middle"></span>Household</li>
                                        </ul>-->
                                        <p class="card-text"><?php echo htmlencode($record['blog_summary']) ?></p>
                                        <p><a href="<?php echo $record['_link'] ?>" class="read-more"><?php echo htmlencode($record['link_text']) ?></a></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php endforeach ?>

                    </div>
                    <!-- end blog left -->

                    <!-- blog right -->
                    <div class="col-lg-4">
                        <div class="blog-sidebar ps-lg-1-6 ps-xl-1-9">
                            <div class="widget search wow fadeIn" data-wow-delay="200ms">
                                <h6 class="widget-title">Search</h6>
                                <form method="POST" action="view-search-results.php" class="search-bar">
                                    <input type="search" name="title,author,blog_summary,content" placeholder="Type here ..." />
                                    <button name="submit" type="submit" class="btn btn-primary btn-sm" id="submit"> Search</button>
                                   <!-- <a href="#!" class="btn-newsletter"><i class="far fa-paper-plane"></i></a>-->
                                </form>
                            </div>
                            <!--<div class="widget wow fadeIn" data-wow-delay="600ms">
                                <h6 class="widget-title">Categories</h6>
                                <ul class="list-style9">
                                    <li><a href="#!">Catagory 1</a><span>10</span></li>
                                    <li><a href="#!">Catagory 2</a><span>15</span></li>
                                    <li><a href="#!">Catagory 3</a><span>04</span></li>
                                    <li><a href="#!">Catagory 4</a><span>06</span></li>
                                </ul>
                            </div>-->

                            <div class="widget wow fadeIn" data-wow-delay="1000ms">
                               <?php
							   if(!@$_REQUEST['createdDate_keyword']){
							     $curYear = date("Y");
							     $cDate = "home";							     
							   }
							   else{
							     $curYear = date("Y",strtotime($_REQUEST['createdDate_keyword']));
							     $cDate = "";
							     $cDate = $_REQUEST['createdDate_keyword'];
							   }
							 ?>

							<?php if($cDate != "blog"): ?>							 
							 <?php foreach($dateOptions as $year=>$months): ?>
							    <?php if($year==$curYear){$display="block;";}else{$display="none;";}?>
			
								<?php if($year==$curYear): ?>
								<h6 class="widget-title">Archives</h6>
									<nav id="subnav">
									<ul class="list-style9">
								        <?php foreach($months as $date => $name): ?>
										    <li><a href="blog.php?createdDate_keyword=<?php echo "$date";?>" ><?php echo $name;?> <?php echo $year;?><span><?php echo $blogMetaData['totalRecords']; ?></span><i class=" icon-right-open"></i></a></li>
									  	<?php endforeach ?>
								    </ul>
								    </nav>
								<?php endif ?>
							 <?php endforeach ?>
							<?php endif ?>
                            </div>
                        </div>
                    </div>
                    <!-- end blog right -->
                </div>
            </div>
        </section>

        <!-- Contact Us
        ================================================== -->
		<?php include("core-contact.php") ?>

        <!-- FOOTER
        ================================================== -->
		<?php include("core-footer.php") ?>
    </div>
		<?php include("core-bootstrap.php") ?>
</body>

</html>