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

if (isset($_GET["p"]) and $_GET["p"] <> "") {
    //exit("IF 1");
	//$adminid = $_GET["id"];
    $params = json_decode(base64_decode($_GET["p"]),true);
    $id = $params["id"];
    if($_SESSION["adminlevel"] == 1){
        //exit("IF 2 - {$_SESSION["adminlevel"]}");
        if($params["aid"] != $_SESSION["adminid"]){
            //exit("IF 3 {$params["aid"]} - {$_SESSION["adminid"]}");
            //exit(var_dump($params));
            //exit(var_dump($_SESSION["adminid"]));
            header("Location: manusers.php");
        }        
    }
} else {
    exit("ELSE 2");
	header("Location: manusers.php");
}
?>
<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=<?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="//netdna.bootstrapcdn.com/bootstrap/3.0.0-wip/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="#FFFFFF">
    <td height="22" colspan="6">&nbsp;</td>
  </tr>
  <tr bgcolor="#0066FF">
    <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="#FFFFFF">
    <td height="18">&nbsp;</td>
    <td height="18"><center><?php //require("includes/menu.php"); ?></center></td>
    <td height="18">&nbsp;</td>
  </tr>
    <tr bgcolor="#FFFFFF">
    <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="14" height="20">&nbsp;</td>
    <td height="20">
    <?php
	$conn = @mysql_connect($dbhost,$dbuser,$dbpass) or sqlerror();
	mysql_select_db($dbname, $conn);
	$sql = mysql_query("SELECT * FROM cmum_udb WHERE id='".$id."'");
	$info=mysql_fetch_array($sql);
	
	$profiles = "";
	$dbprof = unserialize($info["profiles"]);
	if ($dbprof <> "") {
		foreach($dbprof as $printprof) {
			$sql2 = mysql_query("SELECT * FROM cmum_profiles WHERE id='".$printprof."'");
			$profname=mysql_fetch_array($sql2);
				$profiles = $profiles.$profname["name"]." - ";
		}
		$profiles = substr($profiles,0,-3);
	}
	
	/*if ($_SESSION["fetchfromcsp"] == "1" and checkcspconn() == "1") {
		$xml = simplexml_load_file($_SESSION["cspsrv_protocol"]."://".$_SESSION["cspsrv_user"].":".$_SESSION["cspsrv_pass"]."@".$_SESSION["cspsrv_ip"].":".$_SESSION["cspsrv_port"]."/xmlHandler?command=proxy-users&name=".$info["name"]);
		$proxyusers = "proxy-users";
		$i = 0;
		$userstate = "Offline";
		if ((string)$xml->$proxyusers->attributes()->count <> "0") {
			foreach($xml->$proxyusers->user->session as $sessions) {
				if ((string)$xml->$proxyusers->user->session[$i]->attributes()->active == "true") {
					$userstate = "Online";
				}
				$i++;
			}
		}
		if ((string)$xml->$proxyusers->attributes()->count <> "0" and $userstate == "Offline") {
			$userstate = "Online (idle)";
		}
	}*/
	mysql_close($conn);
	?>
    <form name="back" action="manusers.php">
    <fieldset>
    <legend>Informações do Usuario</legend>
    <table valign="top">
		<tr><td width="120" valign="top">loguin:</td><td width="530" valign="top"><?php print($info["name"]); ?></td></tr>
		<tr><td width="120" valign="top">senha:</td><td width="530" valign="top"><?php print($info["password"]); ?></td></tr>
		<tr><td width="120" valign="top">nome de usuario:</td><td width="530" valign="top"><?php print($info["displayname"]); ?></td></tr>
        <tr><td width="120" valign="top">Grupo:</td><td width="530" valign="top"><?php print($info["usrgroup"]); ?></td></tr>
        <tr><td width="120" valign="top">E-mail:</td><td width="530" valign="top"><?php print($info["email"]); ?></td></tr>
        <?php
		/*if ($_SESSION["fetchfromcsp"] == "1" and checkcspconn() == "1") {
			print("<tr><td width=\"100\">State:</td><td width=\"550\">".$userstate."</td></tr>");
		}*/
		?>
		<tr><td width="120" valign="top">IP mask:</td><td width="530" valign="top"><?php print($info["ipmask"]); ?></td></tr>
		<tr><td width="120" valign="top">Profile(s):</td><td width="530" valign="top"><?php print($profiles); ?></td></tr>
        <tr><td width="120" valign="top">Max connections:</td><td width="530" valign="top"><?php print($info["maxconnections"]); ?></td></tr>
        <tr><td width="120" valign="top">Admin:</td><td width="530" valign="top"><?php print(ucfirst($info["admin"])); ?></td></tr>
        <tr><td width="120" valign="top">Enabled:</td><td width="530" valign="top"><?php print(ucfirst($info["enabled"])); ?></td></tr>
        <tr><td width="120" valign="top">Map exclude:</td><td width="530" valign="top"><?php print(ucfirst($info["mapexclude"])); ?></td></tr>
        <tr><td width="120" valign="top">Debug:</td><td width="530" valign="top"><?php print(ucfirst($info["debug"])); ?></td></tr>
        <tr><td width="120" valign="top">Custom CSP values:</td><td width="530" valign="top"><?php print($info["customvalues"]); ?></td></tr>
        <tr><td width="120" valign="top">Ecm rate:</td><td width="530" valign="top"><?php print($info["ecmrate"]); ?></td></tr>
        <tr><td width="120" valign="top">Start date:</td><td width="530" valign="top"><?php print($info["startdate"]); ?></td></tr>
        <tr><td width="120" valign="top">Expire date:</td><td width="530" valign="top"><?php print($info["expiredate"]); ?></td></tr>
        <tr><td width="120" valign="top">&nbsp;</td><td width="530" valign="top">&nbsp;</td></tr>
        <tr><td width="120" valign="top">Comment:</td><td width="530" valign="top"><?php print(nl2br($info["comment"])); ?></td></tr>
        <?php
		if ($info["added"] <> "" or $info["changed"] <> "") {
			print("<tr><td width=\"120\">&nbsp;</td><td width=\"530\">&nbsp;</td></tr>");
		}
		if ($info["added"] <> "") {
			print("<tr><td width=\"120\">Added:</td><td width=\"530\">".$info["added"]." by ".getadminname($info["addedby"],1)."</td></tr>");
		}
		if ($info["changed"] <> "") {
			print("<tr><td width=\"120\">Last changed:</td><td width=\"530\">".$info["changed"]." by ".getadminname($info["changedby"],1)."</td></tr>");
		}
		?>
	</table>
    <br>
    <!-- <input type="submit" id="submit" value="Back">-->
        <button id="" type="submit" value="Back" alt="Voltar" title="Voltar" style="" height="32px">
            <img src="images/back.png"  width="32px"  height="32px" alt="Voltar" title="Voltar"/>
            </button>
    </fieldset>
    </form>
    </td>
    <td width="17" 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="20" width="780">&nbsp;</td>
  </tr>
</table>
<?php
require("includes/footer.php");
?>
</body>
</html>
