1
+ <?php
2
+ if (!isset ($ _SESSION )) session_start ();
3
+
4
+ if (($ _SESSION ['userlevel ' ] === NULL ) OR ($ _SESSION ['userlevel ' ] == 0 )) {
5
+ die ("<h3 style='text-align: center; color: coral; margin-bottom: 10px'><span style='color: red'>Haha</span>! C'mon you can do better!</h3><form style='text-align: center' action= \"logout.php \" method= \"post \"><button style='font-size: larger' class= \"form1 btn btn-info btn-block \">Back</button><br/><br/></form> " );
6
+ }
7
+ ?>
8
+
9
+ <!DOCTYPE html>
10
+ <html lang="en">
11
+ <head>
12
+ <title>Save New Account (Admin) : CCNB</title>
13
+ <meta charset="utf-8">
14
+ <meta name="viewport" content="width=device-width, initial-scale=1">
15
+ <link rel="stylesheet" href="css/style.css">
16
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
17
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
18
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
19
+ <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
20
+ <link rel="shortcut icon" href="img/logo.png" type="image/x-icon">
21
+ <link rel="icon" href="img/logo.png" type="image/x-icon">
22
+ </head>
23
+ <body>
24
+
25
+ <?php
26
+
27
+ require 'connect.php ' ;
28
+
29
+ if (isset ($ _SESSION ['password ' ])) {
30
+ $ pass = $ _SESSION ['password ' ];
31
+
32
+ if (isset ($ _POST ['username ' ]) AND isset ($ _POST ['password ' ]) AND isset ($ _POST ['department ' ]) AND isset ($ _POST ['description ' ]) AND isset ($ _POST ['link ' ]) AND isset ($ _POST ['name ' ]) AND isset ($ _POST ['userlevel ' ]) AND isset ($ _POST ['designation ' ]) AND isset ($ _POST ['website ' ]) AND isset ($ _POST ['phone ' ]) AND isset ($ _POST ['email ' ]) AND isset ($ _POST ['password1 ' ])) {
33
+ $ password1 = md5 ($ _POST ['password1 ' ]);
34
+
35
+ if ($ pass === $ password1 ) {
36
+ $ username = addslashes ($ _POST ['username ' ]);
37
+ $ password = md5 ($ _POST ['password ' ]);
38
+ $ department = addslashes ($ _POST ['department ' ]);
39
+ $ description = addslashes ($ _POST ['description ' ]);
40
+ $ link = $ _POST ['link ' ];
41
+ $ name = addslashes ($ _POST ['name ' ]);
42
+ $ userlevel = $ _POST ['userlevel ' ];
43
+ $ designation = addslashes ($ _POST ['designation ' ]);
44
+ $ website = $ _POST ['website ' ];
45
+ $ phone = $ _POST ['phone ' ];
46
+ $ email = $ _POST ['email ' ];
47
+
48
+ $ insert = "INSERT INTO departments (department, dep_description, linked) VALUES (' $ department', ' $ description', ' $ link') " ;
49
+ $ res = mysqli_query ($ mysql , $ insert ) or die ("<h5 style= \"margin-bottom: 100px; text-align: center; color: coral \">Something went <span style= \"color: red \">wrong</span>! (<span style= \"color: red \">Database or Server issue</span>)</h5><form action= \"add.php \" method= \"post \"><button class= \"form1 btn btn-success btn-block \">Back</button></form> " );
50
+ if ($ res === TRUE ) {
51
+
52
+ $ query = "SELECT * FROM departments WHERE department=' $ department' " ;
53
+ $ result = mysqli_query ($ mysql , $ query ) or die ("<h5 style= \"margin-bottom: 100px; text-align: center; color: coral \">Something went <span style= \"color: red \">wrong</span>! (<span style= \"color: red \">Database or Server issue</span>)</h5><form action= \"add.php \" method= \"post \"><button class= \"form1 btn btn-success btn-block \">Back</button></form> " );
54
+ while ($ row = mysqli_fetch_assoc ($ result )) {
55
+ $ departmentID = $ row ['departmentId ' ];
56
+
57
+ $ insert1 = "INSERT INTO login_details (departmentId, username, password, name, userlevel) VALUES (' $ departmentID', ' $ username', ' $ password', ' $ name', ' $ userlevel') " ;
58
+ $ result1 = mysqli_query ($ mysql , $ insert1 ) or die ("<h5 style= \"margin-bottom: 100px; text-align: center; color: coral \">Something went <span style= \"color: red \">wrong</span>! (<span style= \"color: red \">Database or Server issue</span>)</h5><form action= \"add.php \" method= \"post \"><button class= \"form1 btn btn-success btn-block \">Back</button></form> " );
59
+ if ($ result1 === TRUE ) {
60
+
61
+ $ insert2 = "INSERT INTO contact_info (departmentId, designation, website, phone, email) VALUES (' $ departmentID',' $ designation', ' $ website', ' $ phone', ' $ email') " ;
62
+ $ result2 = mysqli_query ($ mysql , $ insert2 ) or die ("<h5 style= \"margin-bottom: 100px; text-align: center; color: coral \">Something went <span style= \"color: red \">wrong</span>! (<span style= \"color: red \">Database or Server issue</span>)</h5><form action= \"add.php \" method= \"post \"><button class= \"form1 btn btn-success btn-block \">Back</button></form> " );
63
+ if ($ result2 === TRUE ) {
64
+
65
+ if ($ userlevel == 1 ) {
66
+
67
+ echo "<h3 style='text-align: center; color: #2daae4; margin-bottom: 10px'>Congratulations! New <span style='color: dodgerblue'>ADMIN</span> has been added successfully.</h3> " ;
68
+ include 'add.php ' ;
69
+ } else {
70
+ echo "<h3 style='text-align: center; color: #2daae4; margin-bottom: 10px'>Congratulations! New <span style='color: dodgerblue'>USER</span> has been added successfully.</h3> " ;
71
+ include 'add.php ' ;
72
+ }
73
+ } else {
74
+ echo "<h3 style='text-align: center; color: coral; margin-bottom: 10px'>Sorry! Couldn't enter <span style='color: red'>details</span>!.3</h3> " ;
75
+ include 'add.php ' ;
76
+ }
77
+ } else {
78
+ echo "<h3 style='text-align: center; color: coral; margin-bottom: 10px'>Sorry! Couldn't enter <span style='color: red'>details</span>!.2</h3> " ;
79
+ include 'add.php ' ;
80
+ }
81
+ }
82
+ } else {
83
+ echo "<h3 style='text-align: center; color: coral; margin-bottom: 10px'>Sorry! Couldn't enter <span style='color: red'>details</span>!.1</h3> " ;
84
+ include 'add.php ' ;
85
+ }
86
+ } else {
87
+ echo "<h3 style='text-align: center; color: coral; margin-bottom: 10px'>Make sure your <span style='color: red'>password</span> is correct!</h3> " ;
88
+ include 'add.php ' ;
89
+ }
90
+ } else {
91
+ echo "<h3 style='text-align: center; color: coral; margin-bottom: 10px'>Make sure all <span style='color: red'>entries</span> are filled with constraints!</h3> " ;
92
+ include 'add.php ' ;
93
+ }
94
+ } else {
95
+ echo "<h3 style='text-align: center; color: coral; margin-bottom: 10px'>Make sure you're <span style='color: red'>logged in</span>!</h3> " ;
96
+ include 'add.php ' ;
97
+ }
98
+ ?>
99
+
100
+ </body>
101
+ </html>
0 commit comments