<?php
	session_start();
	if (isset($_SESSION['acesso_admin'])){
		$acesso_idusuario=$_SESSION['acesso_idusuario'];
		$acesso_idempresa=$_SESSION['acesso_idempresa'];
		$acesso_admin=$_SESSION['acesso_admin'];
		$acesso_revenda=$_SESSION['acesso_revenda'];
		require_once ('../Amfphp/Services/conexao.php');
		$con=new conexao();
		include('funcoes.php');
		$diaatual=date('d/m/Y');
		$horaatual=date('h:i');	
		$sql="select csp_user.*, provedor.nome, provedor.email, profile.descricao as profile  from csp_user, provedor, profile where csp_user.id = provedor.idprovedor and csp_user.name = '$csp_login'  and csp_user.idempresa='$acesso_idempresa' and csp_user.idprofile = profile.idprofile";
		$resultado = $con->banco->Execute($sql);
		$registro = $resultado->FetchNextObject();
		$val_cliente=$registro->NOME;
		$val_email=$registro->EMAIL;
		$val_login=$registro->NAME;
		$val_senha=$registro->PASSWORD;
		$val_profile=$registro->PROFILE;
		$val_expire=dmy($registro->EXPIREDATE);
		$val_enabled=$registro->ENABLED;	
	} else {
		echo "<script>window.location='index.php';</script>";
	}
	
?>

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Oque deseja fazer com este login?</title>
<link href="cspadm.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form id="form1" name="form1" method="post" action="?oqfazer=executar">
  <table width="410" border="1">
    <tr class="txtAlertaBOX">
      <td colspan="2" bgcolor="#FFFFCC"><a href="renovar_mobile.php">(&lt;-- Voltar)<br />
        CSPADM Mobile - Oque deseja Fazer?</a></td>
    </tr>
    <tr class="txtBOX">
      <td width="162">Cliente:</td>
      <td width="232"><em><?php echo $val_cliente;?></em></td>
    </tr>
    <tr class="txtBOX">
      <td>Login:</td>
      <td><label for="edt_login"></label>
      <input name="edt_login" type="text" id="edt_login" size="15" readonly="readonly" value = "<?php echo $val_login;?>" /></td>
    </tr>
    <tr bgcolor="#FFCCFF" class="txtBOX">
      <td>Senha</td>
      <td><label for="edt_senha"></label>
      <input name="edt_senha" type="text" id="edt_senha" size="15" value="<?php echo $val_senha;?>"  /></td>
    </tr>
    <tr class="txtBOX">
      <td>Profile</td>
      <td><?php echo $val_profile;?></td>
    </tr>
    <tr bgcolor="#FFCCFF" class="txtBOX">
      <td>Valido ATE:</td>
      <td><strong>
        <input name="edt_renovar" type="text" id="edt_renovar" size="15" maxlength="10" value="<?php echo $val_expire;?>" />
      </strong></td>
    </tr>
    <tr class="txtBOX">
      <td>E-mail:</td>
      <td><?php echo $val_email;?></td>
    </tr>
    <tr class="txtBOX">
      <td bgcolor="#FFCCFF"><strong>Bloqueado:</strong></td>
      <td bgcolor="#FFCCFF"><strong>
        <input name="chk_enabled" type="checkbox" id="chk_enabled" value="Inativo" 
        <?php if ($val_enabled == "Inativo"){ echo "checked='checked'"; } ?> />
      </strong></td>
    </tr>
    <tr class="txtBOX">
      <td colspan="2" align="center"><input type="submit" name="button" id="button" value="Executar ACAO" /></td>
    </tr>
  </table>
</form>
<?php if ($oqfazer=="executar"){
	if ($edt_senha == "" || $edt_renovar == ""){
		echo "<script>window.alert('ERRO. Dados Obrigatorios nao preenchidos');</script>";
		echo "<script>window.location='renovar_mobile.php';</script>";
	} else {
		$valido=ymd($edt_renovar);
		if ($chk_enabled == "Inativo"){
			$situacao = "Inativo";
		} else {
			$situacao = "Ativo";
		}
		$sql = "update csp_user set password='$edt_senha', expiredate='$valido', enabled='$situacao' where csp_user.idempresa='$acesso_idempresa'  and csp_user.name='$edt_login'";	
		$con->banco->Execute($sql);
		echo "<script>window.alert('Cliente $edt_login alterado com sucesso. Valido ate $edt_renovar e sua situacao atual e $situacao');</script>" ;
		echo "<script>window.location='renovar_mobile.php';</script>";
	}
}
?>
</body>
</html>