<?php
session_start();
unset($_SESSION['token_acesso']);
$token = base64_encode(openssl_random_pseudo_bytes(32));
$_SESSION['token_acesso'] = $token;
?>
<?php
require("includes/functions.php");
//require_once('includes/recaptchalib.php');
//require("includes/configcheck.php");
require("config.php");
require("includes/debug.php");
require("includes/settings.php");

//checkdbver();

$cleanlogin = "0";
$conn = @mysql_connect($dbhost, $dbuser, $dbpass) or sqlerror();
//var_dump($conn);
mysql_select_db($dbname, $conn);
//var_dump(mysql_error());
//exit();
$sql = mysql_query("SELECT * FROM cmum_settings WHERE id='1'");
$line = mysql_fetch_array($sql);
//exit(var_dump($sql));
$cleanlogin = $line["cleanlogin"];
mysql_close($conn);

if ($cleanlogin == "1") {
    $pagetitle = "&nbsp;";
    $headertitle = "";
    $versionfooter = "";
    $favicon = "";
} else {
    $pagetitle = $longtitle;
    //$headertitle = $longtitle;
    $headertitle = 'PAINEL CSPControl';
    $versionfooter = $version;
    $favicon = "favicon.ico";
}
$pagetitle = $longtitle;
//$headertitle = $longtitle;
$headertitle = 'PAINEL CSPwebADM';
$versionfooter = $version;
$favicon = "favicon.ico";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
            <title><?php print($pagetitle); ?></title>
            <link rel="shortcut icon" href="<?php print($favicon); ?>"/> 
            <link rel="apple-touch-icon" href="favicon.png"/>
            <!--<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0-wip/css/bootstrap.min.css"/>-->
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                <link href="css/main.css" rel="stylesheet" type="text/css"/>
                <style>
                    table{
                        font-size: 8pt;
                    }
                </style>
                </head>
                <body onLoad="focus();
                        dologin.loginuser.focus()">
                    <div style="position: absolute; width: 500px; height: 400px; margin-left: -250px; left: 50%; top:50%; margin-top: -200px">
                        <table width="400px" border="0" cellspacing="0" cellpadding="0" align="center">
                            <tr>
                                <td height="36">&nbsp;</td>
                            </tr>
                            <!--<tr>
                                <td height="24" style="text-align: center"><h1><a href="index.php"><?php print($headertitle); ?></a></h1></td>
                            </tr>-->
                            <?php
                            if (isset($_GET["logout"]) and $_GET["logout"] == "true") {
                                print("<tr>");
                                //print("<td height=\"30\" bgcolor=\"#FFFFE0\" style=\"border-left: 1px solid #E6DB55; border-right: 1px solid #E6DB55; border-bottom: 1px solid #E6DB55; border-top: 1px solid #E6DB55; padding-left: 10px;\" valign=\"middle\">");
                                print("<td height='30' valign='middle'><div class='alert alert-warning'>");
                                print("logoff efetuado com sucesso.");
                                print("</div></td>");
                                print("</tr>");
                                // print("<tr><td>&nbsp;</td></tr>");
                            }
                            if (isset($_GET["error"]) and $_GET["error"] == "1") {
                                print("<tr>");
                                //print("<td height=\"30\" bgcolor=\"#FFEBE8\" style=\"border-left: 1px solid #CC0000; border-right: 1px solid #CC0000; border-bottom: 1px solid #CC0000; border-top: 1px solid #CC0000; padding-left: 10px;\" valign=\"middle\">");
                                print("<td height='30' valign='middle'><div class='alert alert-danger'>");
                                print("Login e Senha Incorretos");
                                print("</div></td>");
                                print("</tr>");
                                //print("<tr><td>&nbsp;</td></tr>");
                            }
                            if (isset($_GET["error"]) and $_GET["error"] == "2") {
                                print("<tr>");
                                print("<td height='30' valign='middle'><div class='alert alert-danger'>");
                                print("Login e Senha Obrigatórios");
                                print("</div></td>");
                                print("</tr>");
                                //print("<tr><td>&nbsp;</td></tr>");
                            }
                            if (isset($_GET["error"]) and $_GET["error"] == "3") {
                                print("<tr>");
                                print("<td height='30' valign='middle'><div class='alert alert-danger'>");
                                print("Acesso negado, entre em contato com seu revendedor.");
                                print("</div></td>");
                                print("</tr>");
                                // print("<tr><td>&nbsp;</td></tr>");
                            }
                            if (isset($_GET["error"]) and $_GET["error"] == "4") {
                                print("<tr>");
                                print("<td height='30' valign='middle'><div class='alert alert-danger'>");
                                print("Seu painel está vencido, entre em contato com seu revendedor.");
                                print("</div></td>");
                                print("</tr>");
                                //print("<tr><td>&nbsp;</td></tr>");
                            }
                            if (isset($_GET["error"]) and $_GET["error"] == "5") {
                                print("<tr>");
                                print("<td height='30' valign='middle'><div class='alert alert-danger'>");
                                print("Sessão Expirada.");
                                print("</div></td>");
                                print("</tr>");
                                // print("<tr><td>&nbsp;</td></tr>");
                            }
                            if (isset($_GET["error"]) and $_GET["error"] == "6") {
                                print("<tr>");
                                print("<td height='30' valign='middle'><div class='alert alert-danger'>");
                                print("Login e senha obrigatórios");
                                print("</div></td>");
                                print("</tr>");
                                //print("<tr><td>&nbsp;</td></tr>");
                            }
                            if (isset($_GET["error"]) and $_GET["error"] == "7") {
                                print("<tr>");
                                print("<td height='30' valign='middle'><div class='alert alert-danger'>");
                                print("Não existem dados cadastrados no sistema");
                                print("</div></td>");
                                print("</tr>");
                                //print("<tr><td>&nbsp;</td></tr>");
                            }
                            if (isset($_GET["error"]) and $_GET["error"] == "8") {
                                print("<tr>");
                                print("<td height='30' valign='middle'><div class='alert alert-danger'>");
                                print("Seu login foi desativado, entre em contato com seu revendedor.");
                                print("</div></td>");
                                print("</tr>");
                                //print("<tr><td>&nbsp;</td></tr>");
                            }
                            ?>
                            <tr>
                                <td height="162" bgcolor="" style="border: solid 0px" valign="top">                                        
                                    <center>    
                                        <br/>
                                        <fieldset style="">
                                            <legend style="text-align: left">ACESSO EXCLUSIVO</legend>
                                            <form name="dologin" action="login.php" method="post" style="border: solid 0px red;">
                                                <ul style="list-style: none; margin: 0px; padding: 0px">
                                                    <li style="text-align: left"><font color="#000000">&nbsp;</font></li>
                                                    <li style="border: solid 0px green;text-align: left"><!--<img src="images/login.png" style="width: 15px;"/>-->
                                                        <div class="input-group">                                                                
                                                            <div class="input-group-addon"><span class="glyphicon glyphicon-user"></span></div>
                                                            <input type="text" style="width: 100%;height: 30px" name="loginuser" size="25" placeholder="USER..." class="form-control"/></li>
                                                    </div>
                                                    <li style="text-align: left"><font color="#000000">&nbsp;</font></li>
                                                    <li style="border: solid 0px green;text-align: left">
                                                        <div class="input-group">                                                                
                                                            <div class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></div>
                                                            <input type="password" style="width: 100%; height: 30px" name="loginpass" size="25" placeholder="PASSWORD..." class="form-control"/>
                                                        </div>
                                                    </li>
                                                    <li style="text-align: right"><a href="index.php">AREA REVENDA</a></li>
                                                    <!--<li style="text-align: left; border: solid 0px; padding-top: 2px; padding-bottom: 2px; "><label style="font-size: 8pt;">Validando o Acesso:</label></li>
                                                    <li><?php
                                                        require_once('includes/recaptchalib.php');
                                                        $publickey = "6LfZO-ISAAAAAI5MO6IJMtjVnfy42188CnwhVepI"; // you got this from the signup page
                                                        echo recaptcha_get_html($publickey);
                                                        ?></li>-->
                                                    <!--<li style="text-align: right"><a href="">Acessar painel do cliente</a></li>-->
                                                    <!--<li>&nbsp;</li>-->
                                                    <li><input type="hidden" value="<?php echo $token; ?>" name="token_sessao"/></li>
                                                    <li style="text-align: left">
                                                        <button value="Logar como cliente" name="logar" class="btn btn-primary">ENTRAR</button>
                                                    </li>
                                                    <!--<input type="submit" value="Logar como cliente" name="logar" id="logar" style="height: 40px" class="btn btn-info"/>-->
                                                </ul>
                                            </form>
                                        </fieldset>
                                        <!--<p style="font-size: 8pt">                                                  
                                            <?php print($shorttitle); ?><br/>
                                        </p>-->
                                    </center>

                                </td>
                            </tr>

                        </table>
                    </div>
                </body>

