| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,321 @@ |
| 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 |
+define('ACCESSCONST', TRUE);
|
|
| 26 |
+ |
|
| 27 |
+require('db-connect.php');
|
|
| 28 |
+ |
|
| 29 |
+session_start(); |
|
| 30 |
+ |
|
| 31 |
+if (($_SESSION['loggedtorspanel'] == true) && ($_SESSION['userrole'] == 'superadmin')) {
|
|
| 32 |
+ |
|
| 33 |
+?> |
|
| 34 |
+ |
|
| 35 |
+<!doctype html> |
|
| 36 |
+ |
|
| 37 |
+<head> |
|
| 38 |
+ <meta charset="utf-8"> |
|
| 39 |
+ <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|
| 40 |
+ <title>Add Buttons</title> |
|
| 41 |
+ <meta name="description" content="Add buttons to dashboard to launch applications with one click"> |
|
| 42 |
+ <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
| 43 |
+ |
|
| 44 |
+ <link rel="shortcut icon" type="image/png" href="images/favicon.png" /> |
|
| 45 |
+ <link rel="stylesheet" href="assets/css/normalize.min.css"> |
|
| 46 |
+ <link rel="stylesheet" href="assets/css/bootstrap.min.css"> |
|
| 47 |
+ <link rel="stylesheet" href="assets/css/font-awesome-4.7.0/css/font-awesome.min.css"> |
|
| 48 |
+ <link rel="stylesheet" href="assets/css/themify-icons/themify-icons.css"> |
|
| 49 |
+ <link rel="stylesheet" href="assets/css/cs-skin-elastic.css"> |
|
| 50 |
+ <link rel="stylesheet" href="assets/css/style.css"> |
|
| 51 |
+ |
|
| 52 |
+ <script type="text/javascript" src="assets/js/jquery-3.3.1.min.js"></script> |
|
| 53 |
+ <script type="text/javascript" src="assets/js/jquery.min.js"></script> |
|
| 54 |
+ <script type="text/javascript" src="assets/js/popper.min.js"></script> |
|
| 55 |
+ <script type="text/javascript" src="assets/js/bootstrap.min.js"></script> |
|
| 56 |
+ <script type="text/javascript" src="assets/js/jquery.matchHeight.min.js"></script> |
|
| 57 |
+ <script type="text/javascript" src="assets/js/main.js"></script> |
|
| 58 |
+ <script type="text/javascript" src="assets/js/moment.min.js"></script> |
|
| 59 |
+ |
|
| 60 |
+ <script type="text/javascript" src="assets/js/settingsmenu.js"></script> |
|
| 61 |
+ <script type="text/javascript" src="assets/js/arrow-up.js"></script> |
|
| 62 |
+ |
|
| 63 |
+</head> |
|
| 64 |
+ |
|
| 65 |
+<body> |
|
| 66 |
+ |
|
| 67 |
+<?php include 'panels.php'; ?> |
|
| 68 |
+ |
|
| 69 |
+ <!-- Content --> |
|
| 70 |
+ |
|
| 71 |
+ <div class="content"> |
|
| 72 |
+ |
|
| 73 |
+ <div class="pagetitle">Add Buttons to Dashboard</div> |
|
| 74 |
+ |
|
| 75 |
+ <div class="clearfix"></div> |
|
| 76 |
+ <!-- Orders --> |
|
| 77 |
+ <div class="orders"> |
|
| 78 |
+ <div class="row"> |
|
| 79 |
+ <!-- <div class="col-xl-8"> --> |
|
| 80 |
+ <div class="col-lg-12"> |
|
| 81 |
+ <div class="card"> |
|
| 82 |
+ <div class="card-body"> |
|
| 83 |
+ <div class="tableTitle"><h4 class="box-title">Add buttons to dashboard to launch applications with one click:</h4></div> |
|
| 84 |
+ </div> |
|
| 85 |
+ <div class="card-body--"> |
|
| 86 |
+ <div class="table-stats order-table ov-h"> |
|
| 87 |
+ <table id="linksTable" class="table"> |
|
| 88 |
+ <thead> |
|
| 89 |
+ <tr> |
|
| 90 |
+ <th class="columntitle">No</th> |
|
| 91 |
+ <th class="columntitle" title="The place of the button in the ordered list on the dashboard.">Order</th> |
|
| 92 |
+ <th class="databaseID">DB ID</th> |
|
| 93 |
+ <th class="columntitle" title="The name that will appear on the button.">Name on button</th> |
|
| 94 |
+ <th class="columntitle" title="The URL that will be opened by clicking on the button.">Link behind button</th> |
|
| 95 |
+ <th class="columntitle" title="The image that will appear on the button in front of the name. Allowed formats: jpg, jpeg, png, svg.">Image on button</th> |
|
| 96 |
+ <th class="columntitle"></th> |
|
| 97 |
+ <th class="columntitle"></th> |
|
| 98 |
+ </tr> |
|
| 99 |
+ </thead> |
|
| 100 |
+ <tbody id="buttonTableTbody"> |
|
| 101 |
+ |
|
| 102 |
+ <?php |
|
| 103 |
+ |
|
| 104 |
+ $selbttnquery = $mysqli->query("SELECT id, orderno, nameonbutton, buttonurl, imgname FROM buttons");
|
|
| 105 |
+ |
|
| 106 |
+ $geturls = []; |
|
| 107 |
+ while ($result_fetch = $selbttnquery->fetch_row()) {
|
|
| 108 |
+ $inddbid = $result_fetch[0]; |
|
| 109 |
+ $indorderno = $result_fetch[1]; |
|
| 110 |
+ $indnameonbutton = $result_fetch[2]; |
|
| 111 |
+ $indurl = $result_fetch[3]; |
|
| 112 |
+ $indimgname = $result_fetch[4]; |
|
| 113 |
+ $geturls[] = [$inddbid, $indorderno, $indnameonbutton, $indurl, $indimgname]; |
|
| 114 |
+ } |
|
| 115 |
+ |
|
| 116 |
+ $selbttnquery->close(); |
|
| 117 |
+ |
|
| 118 |
+ for ($r = 0; $r < count($geturls); $r++) {
|
|
| 119 |
+ echo '<tr class="btnTableRow"><td class="currentNo">'.($r + 1).'</td><td><input type="text" class="orderNumber" value="'.$geturls[$r][1].'" disabled="disabled" /></td><td class="databaseID">'.$geturls[$r][0].'</td><td><input type="text" class="nameOnButton" name="nameonbttn" value="'.$geturls[$r][2].'" disabled="disabled" /></td><td><input type="text" class="buttonLink" name="bttnlink" value="'.$geturls[$r][3].'" disabled="disabled" /></td><td><form class="buttonLogoForm" enctype="multipart/form-data"><input type="file" id="buttonImage_'.($r+1).'" class="compPicture" name="compPicture" /></form><span class="showimageurl">'.$geturls[$r][4].'</span></td><td><span class="deleterow ti-close" title="Delete button data from database."></span></td><td><input type="submit" class="saveLinkButton" name="addlinkbttn" value="Edit" title="Edit this row."/></td></tr>'; |
|
| 120 |
+ } |
|
| 121 |
+ |
|
| 122 |
+ ?> |
|
| 123 |
+ |
|
| 124 |
+ </tbody> |
|
| 125 |
+ </table> |
|
| 126 |
+ |
|
| 127 |
+ <input type="button" id="addNewButton" value="Add Button"/> |
|
| 128 |
+ |
|
| 129 |
+ </div> <!-- /.table-stats --> |
|
| 130 |
+ </div> |
|
| 131 |
+ </div> <!-- /.card --> |
|
| 132 |
+ </div> <!-- /.col-lg-12 --> |
|
| 133 |
+ |
|
| 134 |
+ </div> |
|
| 135 |
+ </div> |
|
| 136 |
+ <!-- /.orders --> |
|
| 137 |
+ |
|
| 138 |
+<?php include 'about.php'; ?> |
|
| 139 |
+ |
|
| 140 |
+ </div> |
|
| 141 |
+ <!-- /.content --> |
|
| 142 |
+ |
|
| 143 |
+ <div class="clearfix"></div> |
|
| 144 |
+ |
|
| 145 |
+<?php include 'footer.php'; ?> |
|
| 146 |
+ |
|
| 147 |
+ </div> |
|
| 148 |
+ <!-- /#right-panel --> |
|
| 149 |
+ |
|
| 150 |
+ <button id="upBttn"></button> |
|
| 151 |
+ |
|
| 152 |
+<script type="text/javascript"> |
|
| 153 |
+ |
|
| 154 |
+ $("#settingsdroparea").show();
|
|
| 155 |
+ $("#addbuttons").css("color", "#03A9F3");
|
|
| 156 |
+ |
|
| 157 |
+ $("#addNewButton").on("click", function() {
|
|
| 158 |
+ |
|
| 159 |
+ var firstrowno = $("#linksTable tr:last-child").closest('[class*="btnTableRow"]').find('[class*="currentNo"]').text();
|
|
| 160 |
+ if (firstrowno != '') {
|
|
| 161 |
+ var currentrowno = parseInt(firstrowno) + 1; |
|
| 162 |
+ } else {
|
|
| 163 |
+ var currentrowno = 1; |
|
| 164 |
+ } |
|
| 165 |
+ |
|
| 166 |
+ $("#linksTable").append('<tr class="btnTableRow"><td class="currentNo">'+currentrowno+'</td><td><input type="text" class="orderNumber" value="" title="The place of the button in the ordered list on the dashboard." /></td><td class="databaseID"></td><td><input type="text" class="nameOnButton" name="nameonbttn" title="The name that will appear on the button." /></td><td><input type="text" class="buttonLink" name="bttnlink" title="The URL that will be opened by clicking on the button." /></td><td><form class="buttonLogoForm" enctype="multipart/form-data"><input type="file" id="buttonImage_'+currentrowno+'" class="compPicture" name="compPicture" title="The image that will appear on the button in front of the name (allowed formats: jpg, jpeg, png, svg; 40px in height preferably)." /></form><span class="showimageurl"></span></td><td><span class="deleterow ti-close" title="Delete this button from the database."></span></td><td><input type="submit" class="saveLinkButton" name="addlinkbttn" value="Save" title="Save input data to the database." /></td></tr>');
|
|
| 167 |
+ |
|
| 168 |
+ }); |
|
| 169 |
+ |
|
| 170 |
+ $(".compPicture").attr("disabled", true);
|
|
| 171 |
+ |
|
| 172 |
+ $("#linksTable").on("change", ".compPicture", function() {
|
|
| 173 |
+ |
|
| 174 |
+ var formData = new FormData(); |
|
| 175 |
+ var fileData = $(this).closest('[class*="btnTableRow"]').find('[class*="compPicture"]').prop('files')[0];
|
|
| 176 |
+ formData.append('uploadedimage', fileData);
|
|
| 177 |
+ |
|
| 178 |
+ var rownb = $(this).closest('[class*="btnTableRow"]').find('[class*="currentNo"]').text();
|
|
| 179 |
+ var imagefileup = $(this).closest('[class*="btnTableRow"]').find('[class*="compPicture"]').val();
|
|
| 180 |
+ var extension = imagefileup.replace(/^.*\./, ''); |
|
| 181 |
+ |
|
| 182 |
+ if (extension == imagefileup) {
|
|
| 183 |
+ extension = ""; |
|
| 184 |
+ } else {
|
|
| 185 |
+ extension = extension.toLowerCase(); |
|
| 186 |
+ } |
|
| 187 |
+ |
|
| 188 |
+ var validExtensions = ["jpg", "jpeg", "png", "svg"]; |
|
| 189 |
+ |
|
| 190 |
+ if (fileData != '') {
|
|
| 191 |
+ |
|
| 192 |
+ if (jQuery.inArray(extension, validExtensions) != -1) {
|
|
| 193 |
+ |
|
| 194 |
+ $.ajax({
|
|
| 195 |
+ type: "POST", |
|
| 196 |
+ url: "upload-button-image.php", |
|
| 197 |
+ data: formData, |
|
| 198 |
+ dataType: "JSON", |
|
| 199 |
+ cache: false, |
|
| 200 |
+ processData: false, |
|
| 201 |
+ contentType: false, |
|
| 202 |
+ success: function(result) {
|
|
| 203 |
+ |
|
| 204 |
+ if (result.messageonsave == '') {
|
|
| 205 |
+ alert("File uploaded successfully !");
|
|
| 206 |
+ } else {
|
|
| 207 |
+ alert(result.messageonsave); |
|
| 208 |
+ } |
|
| 209 |
+ }, |
|
| 210 |
+ error: function() {
|
|
| 211 |
+ alert("An error occurred while uploading the file !");
|
|
| 212 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="compPicture"]').val("");
|
|
| 213 |
+ } |
|
| 214 |
+ }); |
|
| 215 |
+ |
|
| 216 |
+ } else {
|
|
| 217 |
+ alert('The file type is not supported ! Supported formats are "jpg", "jpeg" , "png" and "svg".');
|
|
| 218 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="compPicture"]').val("");
|
|
| 219 |
+ } |
|
| 220 |
+ } |
|
| 221 |
+ |
|
| 222 |
+ }); |
|
| 223 |
+ |
|
| 224 |
+ $("#linksTable").on("click", ".saveLinkButton", function() {
|
|
| 225 |
+ |
|
| 226 |
+ var currentrownb = $(this).closest('[class*="btnTableRow"]').find('[class*="currentNo"]').text();
|
|
| 227 |
+ |
|
| 228 |
+ if ($(this).val() == "Save") {
|
|
| 229 |
+ var ordernumber = $(this).closest('[class*="btnTableRow"]').find('[class*="orderNumber"]').val();
|
|
| 230 |
+ var databaseid = $(this).closest('[class*="btnTableRow"]').find('[class*="databaseID"]').text();
|
|
| 231 |
+ var roleofuser = "<?php print_r($_SESSION['userrole']); ?>"; |
|
| 232 |
+ var nameofuser = "<?php print_r($_SESSION['login']); ?>"; |
|
| 233 |
+ var nameonbttninit = $(this).closest('[class*="btnTableRow"]').find('[class*="nameOnButton"]').val();
|
|
| 234 |
+ var nameonbttnsec = nameonbttninit.replace(/'/g,"'"); |
|
| 235 |
+ var nameonbttn = nameonbttnsec.replace(/"/g, """); |
|
| 236 |
+ var link = $(this).closest('[class*="btnTableRow"]').find('[class*="buttonLink"]').val();
|
|
| 237 |
+ var indimgname = $(this).closest('[class*="btnTableRow"]').find('[class*="compPicture"]').val();
|
|
| 238 |
+ var currentPicName = indimgname.split('\\').pop();
|
|
| 239 |
+ |
|
| 240 |
+ if ((ordernumber != '') && (roleofuser != '') && (nameofuser != '') && (nameonbttn != '') && (link != '')) {
|
|
| 241 |
+ |
|
| 242 |
+ $.ajax({
|
|
| 243 |
+ type: "POST", |
|
| 244 |
+ url: "save-button.php", |
|
| 245 |
+ dataType: "JSON", |
|
| 246 |
+ data: {
|
|
| 247 |
+ ordno: ordernumber, |
|
| 248 |
+ dbid: databaseid, |
|
| 249 |
+ userrole: roleofuser, |
|
| 250 |
+ username: nameofuser, |
|
| 251 |
+ nameonbutton: nameonbttn, |
|
| 252 |
+ buttonurl: link, |
|
| 253 |
+ imgname: currentPicName |
|
| 254 |
+ }, |
|
| 255 |
+ success: function(result) {
|
|
| 256 |
+ location.reload(); |
|
| 257 |
+ }, |
|
| 258 |
+ error: function(result) {
|
|
| 259 |
+ alert(result.messageonsave); |
|
| 260 |
+ } |
|
| 261 |
+ }); |
|
| 262 |
+ |
|
| 263 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="orderNumber"]').attr("disabled", true);
|
|
| 264 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="nameOnButton"]').attr("disabled", true);
|
|
| 265 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="buttonLink"]').attr("disabled", true);
|
|
| 266 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="compPicture"]').attr("disabled", true);
|
|
| 267 |
+ $(this).attr("value", "Edit");
|
|
| 268 |
+ } else { alert("Please fill in at least the 'Order', 'Name on button' and 'Link behind button' fields."); }
|
|
| 269 |
+ |
|
| 270 |
+ } else {
|
|
| 271 |
+ |
|
| 272 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="orderNumber"]').attr("disabled", false);
|
|
| 273 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="nameOnButton"]').attr("disabled", false);
|
|
| 274 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="buttonLink"]').attr("disabled", false);
|
|
| 275 |
+ $(this).closest('[class*="btnTableRow"]').find('[class*="compPicture"]').attr("disabled", false);
|
|
| 276 |
+ $(this).attr("value", "Save");
|
|
| 277 |
+ $(this).prop("title", "Save this row.");
|
|
| 278 |
+ } |
|
| 279 |
+ }); |
|
| 280 |
+ |
|
| 281 |
+ |
|
| 282 |
+ $("#linksTable").on("click", ".deleterow", function(){
|
|
| 283 |
+ var iddb = $(this).closest('[class*="btnTableRow"]').find('[class*="databaseID"]').text();
|
|
| 284 |
+ |
|
| 285 |
+ if (confirm("Do you really want to delete this button from the database ?")) {
|
|
| 286 |
+ |
|
| 287 |
+ $.ajax({
|
|
| 288 |
+ type: "POST", |
|
| 289 |
+ url: "remove-button.php", |
|
| 290 |
+ dataType: "JSON", |
|
| 291 |
+ data: {
|
|
| 292 |
+ databaseId: iddb |
|
| 293 |
+ }, |
|
| 294 |
+ success: function(response) {
|
|
| 295 |
+ }, |
|
| 296 |
+ error: function(response) {
|
|
| 297 |
+ alert(response.messageondelete); |
|
| 298 |
+ } |
|
| 299 |
+ }); |
|
| 300 |
+ |
|
| 301 |
+ $(this).closest('[class*="btnTableRow"]').hide();
|
|
| 302 |
+ } |
|
| 303 |
+ }); |
|
| 304 |
+ |
|
| 305 |
+</script> |
|
| 306 |
+ |
|
| 307 |
+</body> |
|
| 308 |
+</html> |
|
| 309 |
+ |
|
| 310 |
+<?php |
|
| 311 |
+ |
|
| 312 |
+} elseif (empty($_SESSION['loggedtorspanel'])) {
|
|
| 313 |
+ |
|
| 314 |
+ header("Location: panel-login.php");
|
|
| 315 |
+ |
|
| 316 |
+} elseif (($_SESSION['loggedtorspanel'] == true) && ($_SESSION['userrole'] != 'superadmin')) {
|
|
| 317 |
+ |
|
| 318 |
+ header("Location: index.php");
|
|
| 319 |
+} |
|
| 320 |
+ |
|
| 321 |
+?> |