<?php

  define( 'INC_FILE', 'index.inc.php' );
  define( 'CONTENT_FILE', 'content.inc.php' );

  {
    require 'common/private/start.inc.php';

    $user = array();
    {
      // set some defaults
      $user['name'] = 'First Last';
      $user['mug'] = 'common/public/mug.default.png';
      $user['email'] = 'user@domain.com';
      $user['contact'] = 'City, State';
      $user['linkedin_url'] = NULL;
      $user['flickr_url'] = NULL;
      $user['scholar_id'] = NULL;
      $user['g_analytics'] = NULL;
      $user['tabs'] = array( 'cv'=>'CV', 'links'=>'Links' );
      $user['handler'] = '_pages';
      $user['timezone'] = 'America/Detroit';
      $user['favico'] = NULL;
      $user['css_base_all'] = true;
      $user['css_base_print'] = true;
      $user['css_custom_all'] = NULL;
      $user['css_custom_print'] = NULL;
      $user['rss_tab'] = NULL;
      $user['footer'] = NULL;

      // override if available
      @include( INC_FILE );
    }

    $page_info['title'] = $user['name'];

    date_default_timezone_set( $user['timezone'] );

    // favico
    if ( !is_null( $user['favico'] ) && is_readable( $user['favico'] ) )
    {
      $page_info['favico'] = $user['favico'];
    }

    // css
    foreach ( array( 'all', 'print' ) as $css )
    {
      if ( !$user[ 'css_base_' . $css ] )
      {
        $page_info[ 'css-' . $css ] = '';
      }

      if ( !is_null( $user[ 'css_custom_' . $css ] ) &&
            is_readable( $user[ 'css_custom_' . $css ] ) )
      {
        $page_info['head'][] = ( '<link href="' . htmlentities( $user[ 'css_custom_' . $css ] ) . '?' . http_build_query( array( 'type'=>$page_info['type'] ) ) . '" rel="stylesheet" type="text/css" media="' . htmlentities( $css ) . '" />' );
      }
    }

    // rss
    if ( !is_null( $user['rss_tab'] ) )
    {
      $page_info['head'][] = ( '<link rel="alternate" type="application/rss+xml" title="' . htmlentities( $user['name'] ) . '" href="?' . http_build_query( array( 'blank'=>'Y', 'tab'=>$user['rss_tab'] ) ) . '">' );
    }
  }

  // move the content function to component files in the private folder
  function _pages( $id, $prefix )
  {

  	$content = array();
  	@include( CONTENT_FILE );

    if ( $id == 'home' )
    {

      echo misc_section('',
      	$content['headline']);

    	echo misc_section('',
    		 $content['introduction']);

      echo misc_section('Important Dates',
       $content['important_dates']);

      echo misc_section('Perspectives of Interest',
       $content['perspectives_of_interest']);

      echo misc_section('',
        $content['perspectives_extra']);

      echo misc_section('Submission Topics',
       $content['topics']);
    }
    else if ( $id == 'submissions' )
    {
     echo misc_section('Submission Format',
       $content['submission_instructions']);

     echo misc_section('Important Dates',
      $content['important_dates']);

     echo misc_section('Perspectives of Interest',
       $content['perspectives_of_interest']);

     echo misc_section('Submission Topics',
       $content['topics']);
    }
    else if ( $id == 'committee' )
    {
      echo misc_section('Organizing Committee',
        $content['organizing_committee']);

      echo misc_section('Contact Us',
        $content['contact_us']);
    }
    else if ( $id == 'speakers' )
    {
      echo misc_section('Invited Speakers',
        $content['speaker_list']);
    }
    else if ( $id == 'dates' )
    {
      echo misc_section('Important Dates',
        $content['important_dates']);
    }
    else if ( $id == 'program' )
    {

      echo misc_section('',
        $content['prog_headline']);

      echo misc_section('Thursday, Nov 9',
        $content['day_1']);

      echo misc_section('Friday, Nov 10',
        $content['day_2']);

      echo misc_section('Saturday, Nov 11',
        $content['day_3']);
    }
  }

?>

<?php
  if ( $page_info['type'] != 'blank' )
  {
?>

    <!-- Filling page container -->
    <div id="container">

      <!-- Filling top of the page -->
      <div id="top">

        <!-- Insert details regarding the workshop -->
        <div id="contact">
          <div class="header">
            <a href="https://www.aaai.org/Symposia/Fall/fss17symposia.php#fs04"><?php echo htmlentities( $user['name'] ) . ":"; ?></a>
          </div>
          <div class="subheader">
            <a href="https://www.aaai.org/Symposia/Fall/fss17symposia.php#fs04">Studies, Algorithms and Challenges</a>
          </div>
          <div class="venue">
            AAAI 2017 Fall Symposium Series <br />
            November 9-11, 2017,
            Arlington, Virginia <br />

            <span style="font-style: italic">email</span>:
            <a href="mailto:<?php echo htmlentities( $user['email'] ); ?>">
              <?php echo htmlentities( $user['email'] ); ?>
            </a>
          </div>
          <br />
          <?php echo htmlentities( $user['contact'] ); ?>
          <br />
          <br />
        </div>

        <!-- Insert image/thumbnail -->
        <div id="mug">
          <img src="<?php echo htmlentities( $user['mug'] ); ?>" alt="<?php echo htmlentities( $user['name'] ); ?>" /> <br />
        </div>
      </div>

      <!-- Filling page content / tabs -->
      <div id="content">
        <?php
          if ( count( $user['tabs'] ) > 1 )
          {
            jquery_create_tabs( 'tabs', $user['tabs'], $user['handler'], "\t\t" );
          }
          else if ( count( $user['tabs'] ) == 1 )
          {
            $keys = array_keys( $user['tabs'] );
            call_user_func_array( $user['handler'], array( $keys[0], "\t\t" ) );
          }
        ?>
      </div>
    </div>

    <!-- Filling footer -->
    <div id="footer">
      <?php
          $footer = array();
          if ( !is_null( $user['footer'] ) )
          {
            $temp = explode( "\n", $user['footer'] );
            foreach ( $temp as $t )
            {
              $footer[] = $t;
            }
          }
          $footer[] = ( 'last updated on ' . htmlentities( date( 'j F Y', filemtime( ( is_readable( INC_FILE ) )?( INC_FILE ):( $_SERVER['SCRIPT_FILENAME'] ) ) ) ) . ' | powered by <a href="https://github.com/natederbinsky/vitagen" target="_blank">vitagen</a>' );

        foreach ( $footer as $f )
        {
          echo ( "\t" . $f . '<br />' . "\n" );
        }
      ?>
    </div>

<?php
  }
  else
  {
    $tab = misc_param( 'tab' );
    if ( empty( $tab ) )
    {
      $keys = array_keys( $user['tabs'] );
      $tab = $keys[0];
    }

    call_user_func_array( $user['handler'], array( $tab, "" ) );
  }
?>


<?php
  {
    require 'common/private/end.inc.php';
  }
?>