-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserAdd.php
More file actions
57 lines (51 loc) · 1.89 KB
/
Copy pathuserAdd.php
File metadata and controls
57 lines (51 loc) · 1.89 KB
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
<?php
/*******************************************************
* userAdd.php
* Called from userMaint.php
* Calls: returns to userMaint.php upon success or failure
*
* ** AJAX Version **
*
* Purpose: adds new user to database
* validates input and adds record
********************************************************/
session_start();
require_once('common.php');
/********** Check permissions for page access ***********/
$allowed = array("ADMIN");
if (false === array_search($userdata['authlevel'],$allowed)) {
$_SESSION['notify'] = array("type"=>"info", "message"=>"You do not have permission to access this information - Add User");
header("location:main.php");
exit;
}
/********************************************************/
$username=$fullname="";
if (isset($_POST['username'])) $username = clean_input($_POST['username']);
if (isset($_POST['fullname'])) $fullname = clean_input($_POST['fullname']);
$authlevel = $_POST['authlevel'];
$valid = array("ADMIN","STAFF","PATRON","PUBLIC");
//If the authlevel is invalid, set it to PATRON
if (! in_array($authlevel, $valid)) $authlevel = "PATRON";
if ($username == "") {
$_SESSION['notify'] = array("type"=>"error", "message"=>"Missing username.");
header("location:userMaint.php");
exit;
}
if ($fullname == "") {
$_SESSION['notify'] = array("type"=>"error", "message"=>"Missing fullname.");
header("location:userMaint.php");
exit;
}
$password = password_hash($defaultPWD, PASSWORD_DEFAULT);
$sql = "INSERT INTO users (username, fullname, authlevel, password) VALUES (?, ?, ?, ? )";
if ($stmt = $db->prepare($sql)) {
$stmt->bind_param("ssss", $username, $fullname, $authlevel, $password);
$stmt->execute();
$stmt->close();
} else {
die("Invalid query: " . mysqli_error($db) . "\n<br>SQL: $sql");
}
$_SESSION['notify'] = array("type"=>"success", "message"=>"User record has been added.");
header("location:userMaint.php");
exit;
?>