Skip to content

Commit

Permalink
. f cleaning the debuger mode setup
Browse files Browse the repository at this point in the history
  • Loading branch information
starstryder committed Mar 22, 2024
1 parent a5d150f commit c3917ea
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 444 deletions.
56 changes: 31 additions & 25 deletions csb/csb-admin/dashboards/settings/settings.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<?php
function doSwitch($db, $option) {
switch ($option) {
case "update":
$text = update($db);
break;
default:
$text['main'] = "<p>ERROR: No Option Selected. Did you try URL hacking?</p>";
$text['notes'] = "";
}
return array("main" => $text['main'], "notes" => $text['notes']);
}

function landing ($db, $msg="") {

global $BASE_URL;
$main = "";
$notes = "";

function Main () {
// Keep the duplicated code to check for form changes made above
// Request options table
$query = "SELECT * FROM options";
$result = $db->runQuery($query);
Expand All @@ -11,6 +26,7 @@ function Main () {
$options[$row['option_name']] = $row['option_value'];
}


// Check whether to check the debug mode checkbox
if ($options['debug_mode'] == 1) {
$debugModeChecked = "checked";
Expand All @@ -21,36 +37,22 @@ function Main () {

// Create Registration Form
$main = "
<h3 class='font-weight-bold'>Admin Settings</h3>
<form id='profile-form' action='".$_SERVER['REQUEST_URI']."' method='POST'>
<form id='profile-form' action='$BASE_URL/csb-admin/index.php?option=settings' method='POST'>
<input type='hidden' name='action' value='update'>
<input type='hidden' name='debug_mode' value='0'>
<label for='debug_mode'>Debug Mode:</label>
<input type='checkbox' name='debug_mode' id='debug_mode' class='mt-4' $debugModeChecked>
<input type='submit' value='Save Settings' class='btn btn-cq mt-4 right'>
</form>
";

if (isset($saved) && $saved) {
$main .= "<div class='text-success'>Settings saved!</div>";
unset($saved);
}
elseif (isset($saved) && !$saved) {
$main .= "<div class='text-danger'>Error saving settings!</div>";
unset($saved);
}

$notes = "
<h5 class='font-weight-bold'>Some Title Here</h5>
<p>
This should contain important info at some point.
</p>
$msg
";

return array("main" => $main, "notes" => $notes);
}

function Update () {
function update ($db) {

// Fetch old data to compare.
$query = "SELECT * FROM options";
$result = $db->runQuery($query);
Expand All @@ -63,6 +65,7 @@ function Update () {
}

$query = "";
$msg = "";

$tempDebugMode = $_POST['debug_mode'] == "on" ? "1" : "0";

Expand All @@ -73,13 +76,16 @@ function Update () {
$params[] = $tempDebugMode;
}

$msg = "<div class='clearfix' style='margin-bottom: 1em'></div>";
if ($changed) {
if ($db->update($query, $params_type, $params)) {
$saved = TRUE;
$msg .= "<div class='alert-success text-center align-content-center'>Settings saved.</div>";
} else {
$saved = FALSE;
$msg .= "<div class='alert-danger text-center align-content-center'>Error saving settings.<div>";
}
return $saved;
} else {
$msg .= "<div class='alert-info text-center align-content-center'>No changes made.</div>";
}
return null; // How did you get here?
$text = landing($db, $msg);
return array("main" => $text['main'], "notes" => $text['notes']);
}
22 changes: 18 additions & 4 deletions csb/csb-admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* ----------------------------------------------------------------------
Load all needed includes
---------------------------------------------------------------------- */
global $login;
require_once("../csb-loader.php");
require_once($DB_class);
require_once($BASE_DIR . "csb-accounts/auth.php");
Expand Down Expand Up @@ -51,14 +52,27 @@

// Set variables to populate the template
$menus = "<h4>Menus</h4>";
$main = "<h4>Admin Settings</h4>";
$main = "<h4>Dashboard: ";
$notes = "<h4>Instructions</h4>";

/* ----------------------------------------------------------------------
are they trying to save something they input?
---------------------------------------------------------------------- */
if (isset($_POST) && !empty($_POST)) {
$main .= "<p>a form was submitted</p>";
if (isset($_GET) && !empty($_GET)) {
if(isset($_GET['option'])) {
$option = $_GET['option'];
$main .= ucfirst($option)."</H4>";
require_once($BASE_DIR . "csb-admin/dashboards/$option/$option.php");
if (isset($_POST['action']) && !empty($_POST['action'])) {
$text = doSwitch($db, $_POST['action']);
} else {
$text = landing($db);
}
$main .= $text['main'];
$notes .= $text['notes'];
} else {
$main .= "<p>ERROR: No Option Selected. Did you try URL hacking?</p>";
}

} else {
// Display Key Information
Expand Down Expand Up @@ -86,7 +100,7 @@
$dashboardName = str_replace("-", " ", $dashboard);
//Make the first element of the dashboard name uppercase
$dashboardName = ucfirst($dashboardName);
$menus .= "<a href='" . $BASE_URL . "csb-admin/dashboards/" . $dashboard . "/" . $dashboard . ".php'>" . $dashboardName . "</a><br>";
$menus .= "<a href='./index.php?option=$dashboard'>$dashboardName </a><br>";
}
}

Expand Down
Loading

0 comments on commit c3917ea

Please sign in to comment.