Código PHP:
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "0";
$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 = "noacceso.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($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO usuario (cedula, nombre, password, Nivel) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['TxtCedNew'], "text"),
GetSQLValueString($_POST['TxtNameNew'], "text"),
GetSQLValueString($_POST['TxtPassNew'], "text"),
GetSQLValueString($_POST['CmbNivelNew'], "int"));
mysql_select_db($database_comisaria, $comisaria);
$Result1 = mysql_query($insertSQL, $comisaria) or die(mysql_error());
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE usuario SET nombre=%s, password=%s, Nivel=%s WHERE cedula=%s",
GetSQLValueString($_POST['TxtNameUsrEdit'], "text"),
GetSQLValueString($_POST['TxtPassUsrEdit'], "text"),
GetSQLValueString($_POST['CmbNivelusrEdit'], "int"),
GetSQLValueString($_POST['TxtCedUsrEdit'], "text"));
mysql_select_db($database_comisaria, $comisaria);
$Result1 = mysql_query($updateSQL, $comisaria) or die(mysql_error());
}
mysql_select_db($database_comisaria, $comisaria);
$query_UsuarioSQL = "SELECT cedula FROM usuario ORDER BY cedula ASC";
$UsuarioSQL = mysql_query($query_UsuarioSQL, $comisaria) or die(mysql_error());
$row_UsuarioSQL = mysql_fetch_assoc($UsuarioSQL);
$totalRows_UsuarioSQL = mysql_num_rows($UsuarioSQL);
$colname_UsuarioEditSQL = "-1";
if (isset($_POST['CmbSQLCedula'])) {
$colname_UsuarioEditSQL = (get_magic_quotes_gpc()) ? $_POST['CmbSQLCedula'] : addslashes($_POST['CmbSQLCedula']);
}
mysql_select_db($database_comisaria, $comisaria);
$query_UsuarioEditSQL = sprintf("SELECT * FROM usuario WHERE cedula = '%s'", $colname_UsuarioEditSQL);
$UsuarioEditSQL = mysql_query($query_UsuarioEditSQL, $comisaria) or die(mysql_error());
$row_UsuarioEditSQL = mysql_fetch_assoc($UsuarioEditSQL);
$totalRows_UsuarioEditSQL = mysql_num_rows($UsuarioEditSQL);
mysql_select_db($database_comisaria, $comisaria);
$query_NivelSQL = "SELECT * FROM nivelesacceso ORDER BY idnivel ASC";
$NivelSQL = mysql_query($query_NivelSQL, $comisaria) or die(mysql_error());
$row_NivelSQL = mysql_fetch_assoc($NivelSQL);
$totalRows_NivelSQL = mysql_num_rows($NivelSQL);
?>