<?php
/**
 * Created by JetBrains PhpStorm.
 * User: jrotering
 * Date: 7/26/13
 * Time: 6:43 AM
 * To change this template use File | Settings | File Templates.
 */
/* THIS PAGE IS WHERE THE USER GETS ROUTED TO AFTER THE USERCAKE LOGIN. IT TIES THAT LOGIN TO AN ACCOUNT
   IN THE CONFIRMATIONS ACCOUNT TABLE, THEN FORWARDS THE USER TO THE MANAGER PAGE.
*/
require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
define('MAIN_DIR', dirname(__FILE__) . '/');
define('SCRIPT_DIR', MAIN_DIR . 'scripts/' );
require_once(SCRIPT_DIR . 'db_calls.php');

if (isset($loggedInUser)) {
    $acctArray = fetchUserDetails(NULL, NULL, $loggedInUser->user_id);
    $acct_name = $acctArray['user_name'];

    if ($acct_name == 'imaginal') {
        header("Location: confirmations-admin.php"); die();
    }
    else {
        $account = null;
        $QUERY = getAccountByName($acct_name); // check for valid account value
        if (isset($QUERY['results'])) {
            $ACCOUNT = $QUERY['results'];
            $_SESSION['account'] = $ACCOUNT['id'];
            $account = $_SESSION['account'];
            header("Location: manager.php");
        }
        else {
            echo $QUERY['error'];
        }
    }
}
else {
    header("Location: account.php");
}