-
Notifications
You must be signed in to change notification settings - Fork 234
/
add_user.php
84 lines (79 loc) · 2.95 KB
/
add_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
<?php
$page_title = 'Add User';
require_once('includes/load.php');
// Checkin What level user has permission to view this page
page_require_level(1);
$groups = find_all('user_groups');
?>
<?php
if(isset($_POST['add_user'])){
$req_fields = array('full-name','username','password','level' );
validate_fields($req_fields);
if(empty($errors)){
$name = remove_junk($db->escape($_POST['full-name']));
$username = remove_junk($db->escape($_POST['username']));
$password = remove_junk($db->escape($_POST['password']));
$user_level = (int)$db->escape($_POST['level']);
$password = sha1($password);
$query = "INSERT INTO users (";
$query .="name,username,password,user_level,status";
$query .=") VALUES (";
$query .=" '{$name}', '{$username}', '{$password}', '{$user_level}','1'";
$query .=")";
if($db->query($query)){
//sucess
$session->msg('s',"User account has been creted! ");
redirect('add_user.php', false);
} else {
//failed
$session->msg('d',' Sorry failed to create account!');
redirect('add_user.php', false);
}
} else {
$session->msg("d", $errors);
redirect('add_user.php',false);
}
}
?>
<?php include_once('layouts/header.php'); ?>
<?php echo display_msg($msg); ?>
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<strong>
<span class="glyphicon glyphicon-th"></span>
<span>Add New User</span>
</strong>
</div>
<div class="panel-body">
<div class="col-md-6">
<form method="post" action="add_user.php">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="full-name" placeholder="Full Name">
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" name="username" placeholder="Username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name ="password" placeholder="Password">
</div>
<div class="form-group">
<label for="level">User Role</label>
<select class="form-control" name="level">
<?php foreach ($groups as $group ):?>
<option value="<?php echo $group['group_level'];?>"><?php echo ucwords($group['group_name']);?></option>
<?php endforeach;?>
</select>
</div>
<div class="form-group clearfix">
<button type="submit" name="add_user" class="btn btn-primary">Add User</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include_once('layouts/footer.php'); ?>