-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusuarios.php
166 lines (157 loc) · 5.91 KB
/
usuarios.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
* Gestión de administradores.
*/
require_once('home.php');
require_once('redirect.php');
$id = ! empty($_REQUEST['id']) ? (int)$_REQUEST['id'] : 0;
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
if ( validate_required(array(
'Nombres' => $_POST['nombres'],
'Usuario' => $_POST['usuario']))) {
$error = false;
if($_POST['password']!=$_POST['pwd2']) {
$error = true;
$msg = "Las contraseñas no coinciden.";
}else{
$pwd = trim($_POST['password']);
if(empty($pwd)&&(!$id)) {
$error = true;
$msg = "La contraseña es un campo requerido.";
}
}
if(!$error) :
$user_values = array(
'nombres' => $_POST['nombres'],
'usuario' => $_POST['usuario'],
);
if($id&&(!empty($_POST['password']))) {
$user_values['password'] = md5(trim($_POST['password']));
}
if($id===0) {
$user_values['password'] = md5(trim($_POST['password']));
}
$user_values = array_map('strip_tags', $user_values);
$id = save_user($id, $user_values);
if($id) $id = 0;
$msg = "Los datos se guardaron satisfactoriamente.";
endif;
} else
$msg = "Ya existe el usuario '$user_values[usuario]'.";
}
$users = get_items($bcdb->admin);
$user = array();
if($id) {
$user = get_item($id, $bcdb->admin);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/reset.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/text.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/960.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/layout.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/thickbox.css" />
<link href="/favicon.ico" type="image/ico" rel="shortcut icon" />
<script type="text/javascript" src="/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.validate.js"></script>
<script type="text/javascript" src="/scripts/jquery.collapsible.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#frmusers").validate();
/**
* Varios
*/
$('#nombres').focus();
});
</script>
<title>Usuarios | Alquiler de máquinas</title>
</head>
<body>
<div class="container_16">
<div id="header">
<h1 id="logo"> <a href="/"><span>Alquiler de máquinas</span></a> </h1>
<?php include "menutop.php"; ?>
<?php if(isset($_SESSION['loginuser'])) : ?>
<div id="logout">Sesión: <?php print $_SESSION['loginuser']['nombres']; ?> <a href="logout.php">Salir</a></div>
<?php endif; ?>
</div>
<div class="clear"></div>
<div id="icon" class="grid_3">
<p class="align-center"><img src="images/usuarios.png" alt="Usuarios" /></p>
</div>
<div id="content" class="grid_13">
<h1>Usuarios</h1>
<?php if (isset($msg)): ?>
<p class="<?php echo ($error) ? "error" : "msg" ?>"><?php print $msg; ?></p>
<?php endif; ?>
<form name="frmusers" id="frmusers" method="post" action="usuarios.php">
<fieldset class="collapsible">
<legend>Datos del usuario</legend>
<p>
<label for="nombres">Nombres:</label>
<input type="text" name="nombres" id="nombres" maxlength="255" size="60" value="<?php print ($user) ? $user['nombres'] : ""; ?>" />
</p>
<p>
<label for="usuario" title="Nombre de Usuario">Usuario:</label>
<input type="text" name="usuario" id="usuario" maxlength="100" size="40" value="<?php print ($user) ? $user['usuario'] : ""; ?>" class="required" title="Ingresa el nombre de usuario" <?php print (isset($user['usuario'])) ? 'readonly="readonly"' : ""; ?> />
</p>
<p>
<label for="password">Contraseña:</label>
<input type="password" name="password" id="pwd" maxlength="100" title="Ingresa la contraseña" />
</p>
<p>
<label for="pwd2">Otra vez:</label>
<input type="password" name="pwd2" id="pwd2" maxlength="100" title="Ingresa la contraseña" />
<br />
<span class="nota">Si no va a cambiar la contraseña, deje los campos en blanco.</span> </p>
<p class="align-center">
<button type="submit" name="submit" id="submit">Guardar</button>
<input type="hidden" name="id" id="id" value="<?php print $id; ?>" />
</p>
</fieldset>
</form>
<fieldset class="collapsibleClosed">
<legend>Usuario existentes</legend>
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombres</th>
<th>Usuario</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
<?php if ($users): ?>
<?php $alt = "even"; ?>
<?php foreach($users as $k=> $usuario): ?>
<tr class="<?php print $alt ?>">
<th><?php print $usuario['id']; ?>
</td>
<th><?php print $usuario['nombres']; ?>
</td>
<td><?php print $usuario['usuario']; ?></td>
<td><a href="usuarios.php?id=<?php print $usuario['id']; ?>">Editar</a></td>
<?php $alt = ($alt == "even") ? "odd" : "even"; ?>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr class="<?php print $alt; ?>">
<td colspan="4">No existen datos
</th>
</tr>
<?php endif; ?>
</tbody>
</table>
<?php include "pager.php"; ?>
</fieldset>
</div>
<div class="clear"></div>
<?php include "footer.php"; ?>
</div>
</body>
</html>