<?php
require("config.php");
require("includes/functions.php");
require("includes/logincheck.php");
require("includes/admincheck.php");
require("includes/settings.php");

$admId = $_SESSION["adminid"];
$level = $_SESSION["adminlevel"];

$loguntil = 10;
$nologs = "None";
$failedloginlog = "10 Latest Failed Login Attempts";

if (isset($_POST["sublogshowall"]) and $_POST["sublogshowall"] == "Show all") {
    $loguntil = 0;
    $failedloginlog = "All Failed Login Attempts";
}

if (isset($_POST["sublogclear"]) and $_POST["sublogclear"] == "Clear logs") {
    $conn = @mysql_connect($dbhost, $dbuser, $dbpass) or sqlerror();
    mysql_select_db($dbname, $conn);
    $sql = mysql_query("TRUNCATE TABLE cmum_failedlogins");
    mysql_close($conn);
    $nologs = "Logs cleard!";
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=<?php print($charset); ?>" />
        <title>:: <?php print($longtitle); ?></title>
        <link rel="shortcut icon" href="favicon.ico">
            <link rel="apple-touch-icon" href="favicon.png">
                <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">
                        </head>

                        <body>
                        <!--<table width="980" border="0" align="center" valign="top" cellpadding="0" cellspacing="0" style="border-left: 1px solid #DDDDDD; border-right: 1px solid #DDDDDD; text-align: left;">
                          <tr bgcolor="#808080">
                            <td height="22" colspan="6">&nbsp;</td>
                          </tr>
                          <tr bgcolor="#808080">
                            <td width="15" bgcolor="#808080">&nbsp;</td>
                            <td width="751" height="120" bgcolor="#808080"><?php //require("includes/header.php");  ?></td>
                            <td width="15" bgcolor="#808080">&nbsp;</td>
                          </tr>
                          <tr bgcolor="#808080">
                            <td height="18">&nbsp;</td>
                            <td height="18"><center><?php //require("includes/menu.php");  ?></center></td>
                            <td height="18">&nbsp;</td>
                          </tr>
                            <tr bgcolor="#808080">
                            <td height="18">&nbsp;</td>
                            <td height="18">&nbsp;</td>
                            <td height="18">&nbsp;</td>
                          </tr>
                        </table>-->
                            <?php require_once 'topo.php'; ?>
                            <table width="980" height="20" border="0" align="center" valign="top" cellpadding="0" cellspacing="0" style="border-left: 0px solid #DDDDDD; border-right: 0px solid #DDDDDD; text-align: left;">
                                <tr >
                                    <td width="15" height="20">&nbsp;</td>
                                    <td height="20" colspan="4">
                                        <form name="Estatistica de Usuarios">
                                            <fieldset>
                                                <legend><font color="#000000">Estatisticas de Usuarios Cadastrados</font></legend>
                                                <?php
                                                $agora = date('Y-m-d H:i:s');
                                                $conn = @mysql_connect($dbhost, $dbuser, $dbpass) or sqlerror();
                                                mysql_select_db($dbname, $conn);
                                                $sql = mysql_query("SELECT * FROM cmum_udb");
                                                $rowcheckA = mysql_num_rows($sql);
                                                $sql = mysql_query("SELECT * FROM cmum_udb WHERE enabled='true' AND expiredate > '{$agora}'");
                                                $rowcheckE = mysql_num_rows($sql);
                                                $sql = mysql_query("SELECT * FROM cmum_udb WHERE enabled='false'");
                                                $rowcheckD = mysql_num_rows($sql);
                                                $sql = mysql_query("SELECT * FROM cmum_udb WHERE enabled='true' AND expiredate < '{$agora}'");
                                                $rowcheckV = mysql_num_rows($sql);
                                                $sql = mysql_query("SELECT * FROM cmum_admins WHERE level='0'");
                                                $rowcheckAdm = mysql_num_rows($sql);
                                                $sql = mysql_query("SELECT * FROM cmum_admins WHERE level='1'");
                                                $rowcheckRev = mysql_num_rows($sql);
                                                mysql_close($conn);
                                                echo "<div class='alert alert-success'>Logins cadastrados: (" . $rowcheckA . ") Logins ativos: (" . $rowcheckE . ") Logins desativados: (" . $rowcheckD . ") Logins vencidos: ({$rowcheckV}) Admins: (" . $rowcheckAdm . ") Revendas: (" . $rowcheckRev.")</div>";
                                                ?>
                                            </fieldset>
                                        </form>
                                        <?php
                                        $conn = @mysql_connect($dbhost, $dbuser, $dbpass) or sqlerror();
                                        mysql_select_db($dbname, $conn);
                                        $sqlset = mysql_query("SELECT * FROM cmum_settings WHERE id='1'");
                                        $sql2 = mysql_query("SELECT * FROM cmum_failedlogins");
                                        $flrowcheck = mysql_num_rows($sql2);
                                        $lineset = mysql_fetch_array($sqlset);
                                        require("includes/cspsrvinfo.php");
                                        /* if ($_SESSION["fetchfromcsp"] == "1" and checkcspconn() == "1") {

                                          } */
                                        if ($lineset["logfailedlogins"] == "1" and $flrowcheck <> "0") {
                                            require("includes/failedloginlog.php");
                                        }
                                        mysql_close($conn);
                                        ?>
                                    </td>
                                    <td width="15" height="20">&nbsp;</td>
                                </tr>
                            </table>
                            <table width="980" height="20" border="0" align="center" valign="top" cellpadding="0" cellspacing="0" style="border-left: 0px solid #DDDDDD; border-right: 0px solid #DDDDDD; border-bottom: 0px solid #DDDDDD; text-align: left;">
                                <tr>
                                    <td height="25" width="780">&nbsp;</td>
                                </tr>
                            </table>
                            <?php
                            require("includes/footer.php");
                            ?>
                        </body>
                        </html>
