-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit_user.php
140 lines (137 loc) · 5.57 KB
/
edit_user.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
<?php
$page_title = 'Editar Usuario';
require_once('include/load.php');
// Checkin What level user has permission to view this page
page_require_level(1);
?>
<?php
$e_user = find_by_id('users',(int)$_GET['id']);
$groups = find_all('user_groups');
if(!$e_user){
$session->msg("d","Missing user id.");
redirect(SITE_URL.'users.php');
}
?>
<?php
//Update User basic info
if (isset($_POST['update'])) {
$req_fields = array('name','username','level');
validate_fields($req_fields);
if (empty($errors)) {
$id = (int)$e_user['id'];
$name = remove_junk($db->escape($_POST['name']));
$username = remove_junk($db->escape($_POST['username']));
$level = (int)$db->escape($_POST['level']);
$status = remove_junk($db->escape($_POST['status']));
$sql = "UPDATE users SET name ='{$name}', username ='{$username}',user_level='{$level}',status='{$status}' WHERE id='{$db->escape($id)}'";
$result = $db->query($sql);
if ($result) {
if ($db->affected_rows() === 1) {
$session->msg('s',' Cuenta actualizada');
redirect(SITE_URL.'users.php', false);
} else {
$session->msg('w',' No se cambió la información');
redirect(SITE_URL.'edit_user.php?id='.(int)$e_user['id'], false);
}
} else {
$session->msg('d',' Error en la transacción con la Base de Datos');
redirect(SITE_URL.'edit_user.php?id='.(int)$e_user['id'], false);
}
} else {
$session->msg("d", $errors);
redirect(SITE_URL.'edit_user.php?id='.(int)$e_user['id'],false);
}
}
?>
<?php
// Update user password
if (isset($_POST['update-pass'])) {
$req_fields = array('password');
validate_fields($req_fields);
if (empty($errors)) {
$id = (int)$e_user['id'];
$password = remove_junk($db->escape($_POST['password']));
$h_pass = hash("sha512", $password);
$sql = "UPDATE users SET password='{$h_pass}' WHERE id='{$db->escape($id)}'";
$result = $db->query($sql);
if ($result) {
if ($db->affected_rows() === 1) {
$session->msg('s',"Se ha actualizado la contraseña del usuario. ");
redirect(SITE_URL.'edit_user.php?id='.(int)$e_user['id'], false);
} else {
$session->msg('w',' No se cambió la información');
redirect(SITE_URL.'edit_user.php?id='.(int)$e_user['id'], false);
}
} else {
$session->msg('d',' Error en la transacción con la Base de Datos');
redirect(SITE_URL.'edit_user.php?id='.(int)$e_user['id'], false);
}
} else {
$session->msg("d", $errors);
redirect(SITE_URL.'edit_user.php?id='.(int)$e_user['id'],false);
}
}
?>
<?php include_once('layouts/header.php'); ?>
<div class="row">
<div class="col-md-12"> <?php echo display_msg($msg); ?> </div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<i class="glyphicon glyphicon-pencil mx-1"></i>
Actualizar cuenta para: '<?php echo remove_junk(ucwords($e_user['name'])); ?>'
</div>
<div class="panel-body">
<form method="post" action="edit_user.php?id=<?php echo (int)$e_user['id'];?>" class="clearfix">
<div class="form-group">
<label for="name" class="control-label">Nombre Completo</label>
<input type="name" class="form-control" name="name" value="<?php echo remove_junk(ucwords($e_user['name'])); ?>">
</div>
<div class="form-group">
<label for="username" class="control-label">Username/Nick</label>
<input type="text" class="form-control" name="username" value="<?php echo remove_junk($e_user['username']); ?>">
</div>
<div class="form-group">
<label for="level">Rol de usuario</label>
<select class="form-control" name="level">
<?php foreach ($groups as $group ):?>
<option <?php if($group['group_level'] === $e_user['user_level']) echo 'selected="selected"';?> value="<?php echo $group['group_level'];?>"><?php echo $group['group_name'];?></option>
<?php endforeach;?>
</select>
</div>
<div class="form-group">
<label for="status">Estado</label>
<select class="form-control" name="status">
<option <?php if($e_user['status'] === '1') echo 'selected="selected"';?>value="1">Activo</option>
<option <?php if($e_user['status'] === '0') echo 'selected="selected"';?> value="0">Inactivo</option>
</select>
</div>
<div class="form-group clearfix">
<button type="submit" name="update" class="btn btn-info">Actualizar</button>
</div>
</form>
</div>
</div>
</div>
<!-- Change password form -->
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fas fw fa-key mx-1"></i>
Cambiar Password para: '<?php echo remove_junk(ucwords($e_user['name'])); ?>'
</div>
<div class="panel-body">
<form action="edit_user.php?id=<?php echo (int)$e_user['id'];?>" method="post" class="clearfix">
<div class="form-group">
<label for="password" class="control-label">Contraseña</label>
<input type="password" class="form-control" name="password" placeholder="Ingresa la nueva contraseña" required>
</div>
<div class="form-group clearfix">
<button type="submit" name="update-pass" class="btn btn-danger">Cambiar</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include_once('layouts/footer.php'); ?>