root / addUserRecord.php

1
<?php
2
3
/*
4
5
  Copyright (C) 2010, All Rights Reserved.
6
7
  This file is part of RPInventory.
8
9
  RPInventory is free software: you can redistribute it and/or modify
10
  it under the terms of the GNU General Public License as published by
11
  the Free Software Foundation, either version 3 of the License, or
12
  (at your option) any later version.
13
14
  RPInventory is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
  GNU General Public License for more details.
18
19
  You should have received a copy of the GNU General Public License
20
  along with RPInventory.  If not, see <http://www.gnu.org/licenses/>.
21
22
 */
23
24
require_once('lib/auth.lib.php');  //Session
25
require_once('lib/users.lib.php'); // User library
26
require_once('class/database.class.php');
27
28
// Connect
29
$db = new database();
30
31
//Authenticate
32
$auth = GetAuthority();
33
if ($auth < 2)
34
{
35
    die("You dont have permission to access this page");
36
}
37
38
//Username
39
$username = $_POST["username"];
40
if(strlen($username) == 0)
41
    die("Must have a username");
42
if(!preg_match('/^[a-z\d_]{4,20}$/i', $username))
43
    die("Invalid username $username");
44
45
//Password
46
$password = $_POST["password"];
47
if(strlen($password) == 0)
48
    die("Must have a password");
49
50
//Access level        
51
$access = (int)$_POST["access_level"];
52
if($access > 3 || $access < 1)
53
    die("Invalid access level");                
54
55
//email
56
$email = $_POST["email"];
57
if(strlen($email) == 0)
58
    die("Must have a email");
59
60
// Check club id in session
61
if (!isset($_SESSION['club']))
62
{
63
    die('Must have a club ID');
64
}
65
66
// Ensure you have permission to make an admin account
67
if ($access > 2)
68
{
69
    if ($auth < 3)
70
    {
71
        die('Insufficient permission');
72
    }
73
}
74
75
addUser($username, md5($password), $access, $email, $_SESSION['club'], $db);
76
77
$db->close();
78
79
header('Location: manageUsers.php');
80
81
?>
82