<?php
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 . 'manager.logic.php');
if (!isset($_SESSION['account'])) {
    $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'];
    }
   // header( 'Location: ' .   'index.php' ) ;
}


//require_once("models/header.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>New Customer Appointments</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="jqui.10.3/development-bundle/themes/ui-lightness/jquery.ui.all.css">
<link rel="stylesheet" type="text/css" href="jqui.10.3/css/ui-lightness/jquery-ui-1.10.3.custom.min.css">
<style type="text/css">
    #header {
        width: 100%;
        float: left;
    }
    #main {
        clear: both;
        width: 100%;
        float: left;
    }
    #logout {
        width: 200px;
        float: right;
    }
</style>
<!-- account: <?php echo $account; ?> location: <?php echo $location; ?>  -->

<script type="text/javascript" src="jqui.10.3/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="jqui.10.3/development-bundle/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="jqui.10.3/development-bundle/ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="jqui.10.3/development-bundle/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="jqui.10.3/development-bundle/ui/jquery.ui.mouse.js"></script>
<script type="text/javascript" src="jqui.10.3/development-bundle/ui/jquery.ui.slider.js"></script>
<script type="text/javascript" src="jqui.10.3/development-bundle/ui/jquery.ui.tabs.js"></script>
<script type="text/javascript" src="jqui.10.3/js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="validation/dist/jquery.validate.min.js"></script>
<script type="text/javascript" src="validation/dist/additional-methods.min.js"></script>

    <?php
    if (isset($_SESSION['location'])) {
    ?>
<script type="text/javascript">
$(document).ready( function(){
  $(function() {
    $( "#tabs" ).tabs();
  });
  $("#editemail").validate({
  rules: {
    customer_phone: {
      required: true,
      phoneUS: true
    }
}
  });
/* set form action */
$("#setAppt").click( function(){
   $(".formAction").val('setAppointment');
});
$("#deleteAppts").click (function(){
   $(".formAction").val('deleteAppts');
});

$(function(){
  $("#apptDate").datepicker();
  $('#apptTime').timepicker({
  	hourMin: <?php echo $hourMin; ?>,
  	hourMax: <?php echo $hourMax; ?>,
  	timeFormat: "hh:mmtt",
  	ampm: true,
  	stepMinute: <?php echo $appt_increments; ?>});
});
});
</script>
<?php   } ?>
</head>
<body>
<!--<p><a href="manager.php">Reset All</a></p>-->
<div id="header">
    <div id="locationform">
        <form method="get">
            <select name="location" id="location">
                <?php echo getLocations($_SESSION['account'], $location, $optionEl); ?>
            </select>
            <input type="hidden" name="formAction" value="chooseLocation" />
            <input type="submit" name="submitLocation" id="submitLocation" value="Set Location" />
        </form>
    </div>
    <div id="logout"><a href="manager.php?formAction=logout">log out</a></div>
</div>
<?php
if (isset($_SESSION['location'])) {
?>
<div id="main">
    <div id="tabs">
        <ul>
            <li><a href="#newcustform">New Customer</a></li>
            <li><a href="#allrecords">View All Records</a></li>
        </ul>
        <div id="newcustform">
            <?php include_once('emailform.inc'); ?>
        </div>
        <div id="allrecords">
            <?php include_once('recordsform.inc'); ?>
        </div>

    </div>
</div>
<?php
}
//var_dump($_SESSION);
?>
</body>
</html>