forked from mangoO-Microfinance/mangoO-Microfinance
/
admin_user.php
142 lines (129 loc) · 4.11 KB
/
admin_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
141
142
<!DOCTYPE HTML>
<?PHP
include 'functions.php';
check_logon();
check_admin();
connect();
//NEW USER Button
if(isset($_POST["newuser"])){
//Sanitize user input
include 'salt.php';
$user_name = sanitize($_POST['user_name']);
$user_pw = sha1($salt1.(sanitize($_POST['user_pw'])).$salt2);
$user_pw_conf = sha1($salt1.(sanitize($_POST['user_pw_conf'])).$salt2);
$ugroup = sanitize($_POST['ugroup']);
$timestamp = time();
//Check if Username already exists
$sql_check = "SELECT user_id FROM user WHERE user_name = '$user_name'";
$query_check = mysql_query($sql_check);
if($ausgabe = mysql_fetch_array($query_check)){
echo '<script>alert(\'Username already exists. Please choose a different Username.\')</script>';
}
//Insert new user into USER
else {
$sql_insert = "INSERT INTO user (user_name, user_pw, ugroup_id, user_created) VALUES ('$user_name', '$user_pw', '$ugroup', '$timestamp')";
$query_insert = mysql_query($sql_insert);
echo '<script>alert(\'User '.$user_name.' created successfully.\')</script>';
}
}
?>
<html>
<?PHP htmlHead('Settings | Users', 0) ?>
<script>
function validate(form){
fail = validateUser(form.user_name.value)
fail += validatePw(form.user_pw.value, form.user_pw_conf.value)
if (fail == "") return true
else { alert(fail); return false }
}
</script>
<script src="functions_validate.js"></script>
</head>
<body>
<!-- MENU HEADER & TABS -->
<?PHP
include 'menu_header.php';
menu_Tabs(6);
?>
<!-- MENU MAIN -->
<div id="menu_main">
<a href="admin_genset.php">General Settings</a>
<a href="admin_fees.php">Fees</a>
<a href="admin_user.php" id="item_selected">Users</a>
<a href="admin_ugroup.php">Usergroups</a>
<a href="admin_logrec.php">Log Records</a>
</div>
<!-- LEFT SIDE: Create New User Form -->
<div class="content_left">
<p class="heading_narrow">Create New User</p>
<form action="admin_user.php" method="post" onSubmit="return validate(this)">
<table id="tb_fields">
<tr>
<td class="center"><input type="text" name="user_name" placeholder="Username"/></td>
</tr>
<tr>
<td class="center"><input type="password" name="user_pw" placeholder="Password" /></td>
</tr>
<tr>
<td class="center"><input type="password" name="user_pw_conf" placeholder="Repeat Password" /></td>
</tr>
<tr>
<td class="center">
<select name="ugroup" size="1">
<?PHP
$sql_ugroup = "SELECT ugroup_name, ugroup_id FROM ugroup";
$query_ugroup = mysql_query($sql_ugroup);
check_sql($query_ugroup);
while ($row_ugroup = mysql_fetch_assoc($query_ugroup)){
echo '<option value="'.$row_ugroup['ugroup_id'].'">'.$row_ugroup['ugroup_name'].'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td class="center">
<input type="submit" name="newuser" value="Create New User" />
</td>
</tr>
</table>
</form>
</div>
<!-- RIGHT SIDE: List of Users -->
<div class="content_right">
<form action="admin_ugroup.php" method="post">
<table id="tb_table">
<colgroup>
<col width="35%">
<col width="35%">
<col width="20%">
<col width="10%">
</colgroup>
<tr>
<th class="title" colspan="4">Existing Users</th>
</tr>
<tr>
<th>User Name</th>
<th>User Group</th>
<th>Changed</th>
<th>Edit</th>
</tr>
<?PHP
$sql_user = "SELECT * FROM user, ugroup WHERE ugroup.ugroup_id = user.ugroup_id ORDER BY user_name";
$query_user = mysql_query($sql_user);
check_sql ($query_user);
$color=0;
while ($row_user = mysql_fetch_assoc($query_user)){
tr_colored($color); //Alternating row colors
echo '<td>'.$row_user['user_name'].'</td>';
echo '<td>'.$row_user['ugroup_name'].'</td>';
echo '<td>'.date('d.m.Y',$row_user['user_created']).'</td>';
echo '<td><a href="admin_user_edit.php?id='.$row_user['user_id'].'"><img src="ico/edit.png"></td>';
echo '</tr>';
}
?>
</table>
</form>
</div>
</body>
</html>