first_php_project/admin/usuarios_altera.php

197 lines
7.5 KiB
PHP
Raw Permalink Normal View History

2021-11-19 22:12:23 -03:00
<?php require_once('../Connections/conn_sustentabilidade.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "sup";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "invasor_user.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form-usuarios-atualiza")) {
$updateSQL = sprintf("UPDATE tbusuarios SET login_usuario=%s, senha_usuario=%s, nivel_usuario=%s WHERE id_usuario=%s",
GetSQLValueString($_POST['login_usuario'], "text"),
GetSQLValueString($_POST['senha_usuario'], "text"),
GetSQLValueString($_POST['nivel_usuario'], "text"),
GetSQLValueString($_POST['id_usuario'], "int"));
mysql_select_db($database_conn_sustentabilidade, $conn_sustentabilidade);
$Result1 = mysql_query($updateSQL, $conn_sustentabilidade) or die(mysql_error());
$updateGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_usuarios_atualiza = "-1";
if (isset($_GET['id_usuario'])) {
$colname_usuarios_atualiza = $_GET['id_usuario'];
}
mysql_select_db($database_conn_sustentabilidade, $conn_sustentabilidade);
$query_usuarios_atualiza = sprintf("SELECT * FROM tbusuarios WHERE id_usuario = %s", GetSQLValueString($colname_usuarios_atualiza, "int"));
$usuarios_atualiza = mysql_query($query_usuarios_atualiza, $conn_sustentabilidade) or die(mysql_error());
$row_usuarios_atualiza = mysql_fetch_assoc($usuarios_atualiza);
$totalRows_usuarios_atualiza = mysql_num_rows($usuarios_atualiza);
?>
<!doctype html>
<html>
<!-- Alterações do código -->
<!-- 28/11/2018 -->
<!-- Willian, acertei o problema na hora de alterar, você deixou "atualiza_usuarios" e não "usuarios_atualiza" -->
<head>
<meta charset="utf-8">
<title>Usuarios Altera</title>
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<nav>
<?php include("menu_adm.php"); ?>
</nav>
<section class="container-fluid">
<section class="container">
<section class="col-xs-12 col-sm-offset col-sm-8 col-md-offset col-md-6 col-lg-offset-4 col-lg-4">
<h1>Usuários-Altera</h1>
<hr>
<form action="<?php echo $editFormAction; ?>" name="form-usuarios-atualiza" method="POST" id="form_usuarios_atualiza" enctype="multipart/form-data">
<input type="hidden" name="id_usuario" id="id_usuario" value="<?php echo $row_usuarios_atualiza['id_usuario']; ?>">
<label for="nome_usuario">Nome:</label>
<p class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input name="login_usuario" class="form-control input" type="text" id="login_usuario" value="<?php echo $row_usuarios_atualiza['login_usuario']; ?>" maxlength="30" required>
</p>
<label for="senha_usuario">Senha:</label>
<p class="input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-lock"></span></span>
<input name="senha_usuario" class="form-control input" type="password" id="senha_usuario" value="<?php echo $row_usuarios_atualiza['senha_usuario']; ?>" maxlength="16" required >
</p>
<br>
<h5>Nivel de Usúario:<h5>
<p class="hidden"><b>Nível de Permissão:</b><br>
<p>
<input name="nivel_usuario" type="radio" id="nivel_usuario" value="sup" title="<?php echo $row_usuarios_atualiza['nivel_usuario']; ?>" required>
<label for="nivel_usuario_sup">Super Usuário</label>
<br>
<input name="nivel_usuario" type="radio" id="nivel_usuario" value="com" required checked>
<label for="nivel_usuario_com"> <b>Usuário Comum</b></label>
</p>
<p><input class="btn btn-success " type="submit" value="Atualizar">
&nbsp;&nbsp;&nbsp;&nbsp;
<input class="btn btn-danger " type="submit" value="Limpar"></p>
<input type="hidden" name="MM_update" value="form-usuarios-atualiza">
</section>
</section>
</section>
</form>
<!-- Jquery (obrigatório para plugin JS do Bootstrap) -->
<script src="../bootstrap/jquery.min.js"></script>
<!-- Plugin JS-->
<script src="../bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
<?php
mysql_free_result($usuarios_atualiza);
?>