Browse code

Created repository.

DoubleBastionAdmin authored on 29/11/2024 03:10:08
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,106 @@
1
+<?php
2
+
3
+/**
4
+ * @copyright 2024 Double Bastion LLC <www.doublebastion.com>
5
+ *
6
+ * @author Double Bastion LLC
7
+ *
8
+ * @license GNU AGPL version 3 or any later version
9
+ *
10
+ * This program is free software; you can redistribute it and/or
11
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
12
+ * License as published by the Free Software Foundation; either
13
+ * version 3 of the License, or any later version.
14
+ *
15
+ * This program is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
19
+ *
20
+ * You should have received a copy of the GNU Affero General Public
21
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
+ *
23
+ */
24
+
25
+session_start();
26
+
27
+define('ACCESSCONST', TRUE);
28
+
29
+if (($_SESSION['loggedtorspanel'] == true) && ($_SESSION['userrole'] == 'superadmin')) {
30
+
31
+   require('db-connect.php');
32
+
33
+   // Insert new button data into the database
34
+   if (isset($_POST['userrole']) && isset($_POST['username']) && isset($_POST['nameonbutton']) && isset($_POST['buttonurl'])) {
35
+
36
+      $ordno = $_POST['ordno'];
37
+      $dbid = $_POST['dbid'];
38
+      $userrole = $_POST['userrole'];
39
+      $username = $_POST['username'];
40
+      $nameonbutton = $_POST['nameonbutton'];
41
+      $buttonurl = $_POST['buttonurl'];
42
+      $imgname = $_POST['imgname'];
43
+
44
+      if (($userrole != '') && ($username != '') && ($nameonbutton != '') && ($buttonurl != '')) {
45
+
46
+         if ($dbid == '') {
47
+
48
+             try {
49
+                 $query1 = $mysqli->prepare("INSERT INTO buttons (orderno, userrole, username, nameonbutton, buttonurl, imgname) VALUES (?, ?, ?, ?, ?, ?)");
50
+                 $query1->bind_param("isssss", $ordno, $userrole, $username, $nameonbutton, $buttonurl, $imgname);
51
+                 $query1->execute();
52
+                 $query1->close();
53
+
54
+                 $messageonsave = "The button has been added successfully !";
55
+
56
+             } catch(mysqli_sql_exception $e) {
57
+
58
+                 $messageonsave = "An error occurred when adding the button. Please check your input data !!!";
59
+               }
60
+
61
+
62
+         } else {
63
+
64
+             try {
65
+                if ($imgname != '') {
66
+                    $query2 = $mysqli->prepare("UPDATE buttons SET orderno=?, nameonbutton=?, buttonurl=?, imgname=? WHERE id=?");
67
+                    $query2->bind_param("isssi", $ordno, $nameonbutton, $buttonurl, $imgname, $dbid);
68
+                    $query2->execute();
69
+                    $query2->close();
70
+
71
+                } else {
72
+                    $query3 = $mysqli->prepare("UPDATE buttons SET orderno=?, nameonbutton=?, buttonurl=? WHERE id=?");
73
+                    $query3->bind_param("issi", $ordno, $nameonbutton, $buttonurl, $dbid);
74
+                    $query3->execute();
75
+                    $query3->close();
76
+                  }
77
+
78
+                 $messageonsave = "The button has been updated successfully !";
79
+
80
+             } catch(mysqli_sql_exception $e) {
81
+
82
+                 $messageonsave = "An error occurred when updating button data. Please check your input data !";
83
+               }
84
+
85
+           }
86
+
87
+      } else { $messageonsave = "Error. Please check your input data !"; }
88
+   }
89
+
90
+   $result = array(
91
+        'messageonsave' => $messageonsave
92
+   );
93
+
94
+   echo json_encode($result);
95
+
96
+
97
+} elseif (empty($_SESSION['loggedtorspanel'])) {
98
+
99
+      header("Location: panel-login.php");
100
+
101
+} elseif (($_SESSION['loggedtorspanel'] == true) && ($_SESSION['userrole'] != 'superadmin'))  {
102
+
103
+      header("Location: index.php");
104
+}
105
+
106
+?>