-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathsuperadmin.php
42 lines (32 loc) · 1.21 KB
/
superadmin.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
<?php
session_start();
if(!isset($_SESSION['hng-admin'])){
header("location:login.php");
exit();
}
require 'classControllers/init.php';
$admin = new AdminClass();
$my_role = $_SESSION['hng-admin']['role'];
if($my_role != 1){
//not a super admin
$_SESSION['err_msg'] = "<div class='alert alert-warning'>This task is only available for a super admin!</div>";
header("location:test_home.php");
exit();
}
$firstname = $database->escape_string($_POST['fname']);
$lastname = $database->escape_string($_POST['name']);
$email = $database->escape_string($_POST['email']);
$password = $database->escape_string($_POST['password']);
$enc_password = sha1($password);
$role = $database->escape_string($_POST['role']);
if($admin->adminExist($email) == 1){
$_SESSION['err_msg'] = "<div class='alert alert-warning'>Admin already exists!</div>";
}else{
if($admin->createAdmin("$email","$firstname","$lastname","$email","$role","$enc_password")){
$_SESSION['err_msg'] = "<div class='alert alert-success'>Admin added successfully!</div>";
}else{
$_SESSION['err_msg'] = "<div class='alert alert-info'>Unable to add new admin</div>";
}
}
header("location:add_admin.php");
exit();