<?php 
/**
 * Template Name: The One Page
 *
 * @author Designova (designova.net)
 * @theme next
 */
get_header();
global $smof_data;
$next_count = 0; 
//$next_countPages = wp_count_posts('page')->publish;
$next_pages = get_pages( 'sort_order=asc&sort_column=menu_order&depth=1');
$next_totalOnepages = 0;
//count one pages only
foreach($next_pages as $next_pag):
  $next_include_onepage = get_post_meta($next_pag->ID,'next_include_onepage',true );
  $next_templ_name      = get_post_meta( $next_pag->ID, '_wp_page_template', true );
  $next_filename        = preg_replace('"\.php$"', '', $next_templ_name); 
  if($next_include_onepage == 1 &&  $next_filename !='the-onepage') { $next_totalOnepages++; }
endforeach;

//Pages to sections published pages
foreach($next_pages as $next_pag):

setup_postdata($next_pag);
//Anchor point and title
$next_newanchorpoint   = strtolower(preg_replace('/[^a-zA-Z0-9]/s', '', $next_pag->post_name)); 

$next_new_title      = $next_newanchorpoint;
$next_templ_name     = get_post_meta( $next_pag->ID, '_wp_page_template', true );
$next_filename       = preg_replace('"\.php$"', '', $next_templ_name); 

//Check wether to include in one page
$next_include_onepage =  get_post_meta($next_pag->ID,'next_include_onepage',true );
//Get Other Meta Items
$next_bg_color        =  get_post_meta($next_pag->ID,'next_pagebg_color',true );
$next_heading_color   =  get_post_meta($next_pag->ID,'next_pagehead_color',true );





//Failsafe BG color
if($next_bg_color !='')
{
  $next_bg_color= $next_bg_color;
}else 
{ 
  $next_bg_color ="#FFF"; 
}


//Menu Trigger waypoint
if($next_include_onepage == 1) { $next_count++; }
//if($next_totalOnepages == $next_count) { $last_section = "last-section"; }else {$last_section = "";}
if($next_include_onepage == 1 AND $next_count == '2') 
{ 
  //Menu appearance trigger
   $next_sidenav_arr = array('pageid'=>$next_new_title,'ahswitch' => $smof_data['menu_hidden']);
   wp_localize_script('sidenav_hide', 'pagehandle', $next_sidenav_arr);
}


//Background
$next_page_heading      =  $next_pag->post_title;

?>

<?php
/*-------------------------------------
 Splash Page
--------------------------------------*/
if($next_filename == 'home-splash' && $next_include_onepage == '1')
   {
      if(isset($smof_data['splash_bg_mode']) AND $smof_data['splash_bg_mode'] == '1'):
         $bgm = '  style="background: url('.$smof_data['bg_splash'].') center top repeat;" ';
      else:
         $bgm = '';
      endif;

?>
<section id="<?php echo $next_new_title;?>" class="splash-home" <?php echo $bgm; ?> data-stellar-background-ratio="1.7">
         <?php the_content();?>  
</section>
    <!--Wrap-->

<?php 
} 

/*-------------------------------------
Default One-Page Section
--------------------------------------*/
elseif($next_include_onepage == 1 && $next_filename != 'the-onepage')
{

?>

<section id="<?php echo $next_new_title;?>" class="page-section navigation-fadeIn"  data-stellar-background-ratio="2" style="background:<?php echo $next_bg_color;?>">
      <section class="container">
        <div class="row">
          <article class="col-md-12 text-left">
            <h2 class="page-heading" style="color:<?php echo $next_heading_color; ?> "><?php echo $next_page_heading; ?></h2>
            <div class="liner"><span></span></div>
          </article>
        </div>
            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>></div>
            <?php the_content();?>
    </section>         
</section>
<?php 
/*New Sub-Section Code*/
$group_data = get_post_meta($next_pag->ID, 'gp',false );

$next_content_count  =   count($group_data);
$next_arraypo        =   $next_content_count-1;
 for($i=0;$i<=$next_arraypo;$i++)
  {
      if(isset($group_data[$i]['next_pagesubsection_title'])):
        $next_panel_point   = strtolower(preg_replace('/[^a-zA-Z]/s', '', $group_data[$i]['next_pagesubsection_title'])); 
      else:
        $next_panel_point   = ""; 
      endif;
    //Default fall back
     if(!isset($group_data[$i]['next_pagesubsection_bgcolor']) OR $group_data[$i]['next_pagesubsection_bgcolor'] =='')
     { $secbg_color="#202937"; }else{ $secbg_color = $group_data[$i]['next_pagesubsection_bgcolor']; }
  //Ensure its a subsection
if(isset($group_data[$i]['next_pagesubsection_content']) AND ($group_data[$i]['next_pagesubsection_content']!='')): 
 ?>
<section id="ne-<?php echo $next_panel_point;?>-panel" class="page-section-sub"   style="background:<?php echo $secbg_color;?>">
  <section class="container">

    <?php if(isset($group_data[$i]['next_pagesubsection_title']) AND ($group_data[$i]['next_pagesubsection_title'] !='')): ?>  
      <div class="row">
          <article class="text-left">
            <h2 class="page-heading page-heading-alt" style="color:<?php echo $group_data[$i]['next_pagesubsection_headcolor'];?> !important; "><?php echo $group_data[$i]['next_pagesubsection_title'];?> </h2>
            <div class="liner"><span></span></div>
          </article>
        </div>
      <div class="row add-top">
    <?php else: ?>
    <div class="row">
    <?php endif; ?>  




  <?php echo do_shortcode($group_data[$i]['next_pagesubsection_content']); ?>
  </section>
</section>
<?php
 endif;
 }
?>
<?php 
}
endforeach;
get_footer(); 
?>