<?php

require_once "lib/config.php";
require_once "lib/user.php";
require_once "lib/FacebookDriver.php";
$fb_driver = new FacebookDriver();
$APP_PROFILE = array();
$user = new User();
if (isset($_POST['action']) && $_POST['action'] == "register") {
    // Define Validator Object
    $validator = new validator();
    // Define Parameters
    $name = $_POST['name'];
    $age = $_POST['age'];
    $sex = $validator->sexvalid($_POST['sex']);
    $phone = $validator->phonevalid($_POST['phone']);
    $email = $validator->emailvalid($_POST['email'], "Invalid Email");
    $state = $_POST['state'];
    $team = trim($_POST['team']);
    $socid = $_POST['socid'];
    $params = array('socid' => $socid, 'name' => $name, 'age' => $age, 'sex' => $sex, 'email' => $email, 'phone' => $phone, 'state' => $state, 'team' => $team);
    // Create User Object and Register User
    $resp = $user->register($params);
    if (strstr($resp, "OK")) {
        $_SESSION['userid'] = $_POST['socid'];
        $_SESSION['teamid'] = $user->userprofile($_POST['socid']);
        header("Location: profile.php");
    }
} else {
    if ($fb_driver->in_session()) {
        // Get User