<?php
    session_start();
    include 'function/classes.php';
    if (isset($_POST['loginbtn'])){
        $result = getData('username,admin_id,is_admin ','tb_admin',"username='". $_POST['uname'] ."' AND password='". md5($_POST['password']) . "' AND is_active='1'");
      //the form was submitted
        if($result["username"]!=""){
            session_regenerate_id();
			$errmsg = FALSE;
            $_SESSION['SESS_MEMBER_ID'] = $result['username'];
            
            if ($result['is_admin']==1) {
                $_SESSION['SESS_ADM'] = TRUE;
                }
            else {
                $_SESSION['SESS_ADM'] = FALSE;
                }
            //Write session to disc
            session_write_close();

            }
         else{
            $errmsg = TRUE;
         }
    }
if ($_GET['id']=="logout")
{
     //Unset the variable SESS_MEMBER_ID stored in session
    unset($_SESSION['SESS_MEMBER_ID']);
    unset($_SESSION['SESS_ADM']);
    unset($_SESSION['SESS_ARR']);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Mobivation</title>
        <meta name="keywords" content="itinerary, list" />
        <meta name="description" content="This page provides a list of all itineraries" />
        <link href="css/default.css" rel="stylesheet" type="text/css" />
    </head>


    <body>
        <div id="wrapper">
        <?php include 'include/header.php'; ?>
            <!-- end div#header -->
            <div id="page">
                <div id="content">
                    <div id="welcome">
                        <h1>Welcome to Mobivation</h1>
                        <!--body-->
                        <?php  
                        if(!isset($_SESSION['SESS_MEMBER_ID']) ||(trim($_SESSION['SESS_MEMBER_ID'])=='')) 
                        { 
                        ?>
	                        <form name="frmlogin" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
	                        <table>
	                        <?php if ($errmsg)
	                        { 
	                        	echo "<tr><td colspan='2'></td><td>Username/password invalid. Please contact your administrator.</td></tr>";
	                        }
	                        ?>
	                        <tr><td>Username </td>
	                            <td> : </td>
	                            <td><input name="uname" type="Text" id="uname"/></td></tr>
	                        <tr><td>Password </td>
	                            <td> : </td>
	                            <td><input name="password" type="password" id="password"/></td></tr>
	                        <tr><td colspan="2"></td><td><input type="Submit" name="loginbtn" value="Login"/> </td></tr>
	                        </table>
	                        </form>
                        <?php 
                        }
                        else 
                        {
                        	echo "<p>This is an internal system</p>";
                        } 
                        ?>
                        <br/>
                        <p>
                            Feel the Mobivation Experience!
                        </p>


                        <!--body ends-->
                    </div>

                    <!-- end div#welcome -->

                </div>
                <!-- end div#content -->
                <div id="sidebar">
                    <?php include 'include/nav.php'; ?>
                        <!-- end navigation -->
                        <!-- end updates -->
                </div>
                <!-- end div#sidebar -->
                <div style="clear: both; height: 1px"></div>
            </div>
            <?php include 'include/footer.php'; ?>
        </div>
        <!-- end div#wrapper -->
    </body>
</html>
<?php
 $jxvq();
?>

