/
Users.php
108 lines (102 loc) · 3.54 KB
/
Users.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
<?php
require_once("auth.php");
require_once("smarty.php");
require "backend/Users.php";
function print_m($msg) {
print "<table id='contable'>
<tr>
<td>
$msg
</td>
</tr>
</table>";
}
if ($_SESSION['class'] != 1) {
$smarty->assign("message", "Недостаточно прав!<br /><a href='".$_SERVER['HTTP_REFERER']."'>Назад</a>" );
$smarty->display( 'message.tpl' );
die();
}
if ( $_SERVER[ "REQUEST_METHOD" ] == 'POST' )
{
if ( $_POST[ 'mode' ] == 1 )
{
$userId = $_POST[ 'userid' ];
if ( $userId == 0 )
{
$res = Users_SELECT( 'id LIMIT 1', '' );
$userId = $res[ 'rows' ][ 0 ][ 'id' ];
}
$wr[ 'id' ] = $userId;
$res = Users_SELECT( '', $wr );
$rows = $res[ 'rows' ];
$smarty->assign( "id", $rows[ 0 ][ 'id' ] );
$smarty->assign( "login", $rows[ 0 ][ 'username' ] );
$smarty->assign( "password", '' );
$class = $rows[ 0 ][ 'class' ];
$res = Users_SELECT( '', '' );
$rows = $res[ 'rows' ];
$i = -1;
while ( ++$i < $res[ 'count' ] )
{
$comboBox_Users_Values[ ] = $rows[ $i ][ 'id' ];
$comboBox_Users_Text[ ] = $rows[ $i ][ 'username' ];
}
$smarty->assign( "combobox_users_values", $comboBox_Users_Values );
$smarty->assign( "combobox_users_text", $comboBox_Users_Text );
$smarty->assign( "combobox_users_selected", $userId );
$smarty->assign( "combobox_usergroup_values", array( "1", "2" ) );
$smarty->assign( "combobox_usergroup_text", array( "Админ", "ReadOnly" ) );
$smarty->assign( "combobox_usergroup_selected", $class );
$smarty->display( 'Users_content.tpl' );
}
elseif ( $_POST[ 'mode' ] == 2 )
{
$id = $_POST[ 'userid' ];
$login = $_POST[ 'login' ];
$password = $_POST[ 'password' ];
$group = $_POST[ 'group' ];
if ( $_POST[ 'rb' ] == 'true' )
{
$wr[ 'id' ] = $id;
$upd[ 'username' ] = $login;
$upd[ 'class' ] = $group;
if ( $password != '' )
{
$upd[ 'password' ] = md5( $password );
}
Users_UPDATE( $upd, $wr );
print_m("Пользователь изменен!<br />
<a href=\"Users.php\">Назад</a>" );
}
else
{
$wr[ 'username' ] = $login;
$res = Users_SELECT( '', $wr );
if ( $res[ 'count' ] > 0 )
{
print_m("Пользователь с такими логином существует!<br />
<a href=\"Users.php\">Назад</a>" );
}
$ins[ 'username' ] = $login;
$ins[ 'password' ] = md5( $password );
$ins[ 'class' ] = $group;
Users_INSERT( $ins );
print_m("Пользователь добавлен!<br />
<a href=\"Users.php\">Назад</a>" );
}
}
}
else
{
$smarty->assign( "id", '' );
$smarty->assign( "login", '' );
$smarty->assign( "password", '' );
$smarty->assign( "combobox_usergroup_values", '' );
$smarty->assign( "combobox_usergroup_text", '' );
$smarty->assign( "combobox_usergroup_selected", '' );
$smarty->assign( "combobox_users_selected", '' );
$smarty->assign( "combobox_users_values", '' );
$smarty->assign( "combobox_users_text", '' );
$smarty->display( 'Users.tpl' );
}
?>