<?php
/*
  CREATIVE COMMONS - Attribution-No Derivative Works 3.0 Germany:
    - You may not alter, transform, or build upon this work.
    - Dieses Werk darf nicht bearbeitet oder in anderer Weise verändert werden.
*/
  session_name('GigKalender');
  session_start();

  include("includes/error_reporting.php");
  header("content-type: text/html; charset=utf-8");
  include("gigkalender.ini.php");
  include("functions/standard.php");

  // Variablen definieren
    foreach ($_REQUEST as $key => $value)
    {
      if (get_magic_quotes_gpc() AND !is_array($value)) $$key = stripslashes($value);
      else $$key = $value;
    }
    foreach ($_POST as $key => $value)
    {
      if (get_magic_quotes_gpc() AND !is_array($value)) $$key = stripslashes($value);
      else $$key = $value;
    }

  // getUID
    $userid=false;
    if (isset($_POST['username']) AND $_POST['username']!="" AND isset($_POST['userpass']) AND $_POST['userpass']!="")
      $userid=getUID($_POST['username'], $_POST['userpass']);
  // Login
    if (isset($_POST['login']))
      if ($userid) login($userid);
    else
      logoutInactiveUser();

  include('includes/backend_language_selector.php');

  // Fehlermeldung ausgeben
    $Message = '';
    if (isset($_POST['login']))
      if (!$userid) $Message = '<div class="ERROR">'.$L_071.'</div>';

  // Logout
    if (isset($_POST['logout']))
    {
      logout();
      $Message = '<div class="ERROR">'.$L_004.'</div>';
    }

  $timer = startTime();

  if (isset($_REQUEST['submenu'])) { $Submenu = $_REQUEST['submenu']; }
    else { $Submenu = "calendar"; }

  if (isset($_REQUEST['page'])) { $page = $_REQUEST['page']; }
  else
  {
    switch ( $Submenu )
    {
      case "calendar":
        if ( isset($_SESSION['MenuReminderCalendar']) ) $page = $_SESSION['MenuReminderCalendar'];
          else $page = "backend_showAllGigs";
       break;
      case "website":
        if ( isset($_SESSION['MenuReminderWebsite']) ) $page = $_SESSION['MenuReminderWebsite'];
          else $page = "backend_showAllGuestbookEntries";
        break;
      case "filesharing":
        if ( isset($_SESSION['MenuReminderFilesharing']) ) $page = $_SESSION['MenuReminderFilesharing'];
          else $page = "downloadMidiFiles";
        break;
      case "user":
        if ( isset($_SESSION['MenuReminderUser']) ) $page = $_SESSION['MenuReminderUser'];
          else $page = "editCurrentUser";
        break;
      case "mail":
        if ( isset($_SESSION['MenuReminderEmail']) ) $page = $_SESSION['MenuReminderEmail'];
          else $page = "mail";
        break;
      case "admin":
        if ( isset($_SESSION['MenuReminderAdmin']) ) $page = $_SESSION['MenuReminderAdmin'];
          else $page = "setup_general";
        break;
      case "help":
        if ( isset($_SESSION['MenuReminderHelp']) ) $page = $_SESSION['MenuReminderHelp'];
          else $page = "forum";
        break;
    }
  }
  include ('includes/header.php');
  // JavaScript einbinden
  include ('includes/javascript-switch.php');
  // Updating MySQL Datebase if update file is present
    if (is_file("update.sql.php")) include("update.sql.php");
?>
    </head>
  <body>
    <div id="Box">
      <div class="Head">
        <div class="Title"><img src="images/gigkalender-logo.png" alt="GigKalender-Logo" /></div>
        <div class="Login">
          <?php echo $Message; include("includes/login.php"); ?></div>
      </div>
      <div id="Box_Navigation">
        <?php
          
          if (loggedIn())
  	      {
            include("includes/mainmenue.php");
            if ($Submenu!="") { include "submenus/".$Submenu.".php"; }
          }
        ?>
      </div>
      <div class="BoxPage <?php echo $page; ?>">
        <?php
          if ($page=="menu" OR $page=="pages" OR $page=="media") $Submenu="cms";
          elseif ($page=="backend_showAllGuestbookEntries") $Submenu="guestbook";
          elseif ($page=="backend_delGuestbookEntries") $Submenu="guestbook";
          elseif ($page=="backend_showAllNews") $Submenu="news";
          elseif ($page=="backend_showAllAlbums") $Submenu="gallery";
          if (loggedIn())
  	      {
            if ($page!="") { include($Submenu.'/'.$page.'.php'); }
          }
        ?>
      </div>
      <div id="Box_Footer">
        <?php include("includes/footer.php"); ?>
      </div>
    </div>
  </body>
</html>