.
************************************************************************
*/
/**
*
* admin.php, TSM Monitor
*
* admin backend
*
* @author Michael Clemens
* @package tsmmonitor
*/
include_once "includes/global.php";
include_once "includes/page_head.php";
if ($_SESSION["logindata"]["role"]!="admin") {
$_SESSION["logindata"] = "";
}
if ($_POST["css"] != "") {
$_SESSION['stylesheet'] = $_POST["css"];
}
?>
GETVars['qq'] != "logout" && $_SESSION["logindata"]["loggedin"]) {
if ($tsmmonitor->GETVars['qq'] != "" && $tsmmonitor->GETVars['qq'] != "overview") {
// show overview page
if ($tsmmonitor->GETVars['qq'] == "index") {
// do nothing
// show settings page
} else if ($tsmmonitor->GETVars['qq'] == "settings") {
$tmonpolld = new PollD($adodb);
$tmonpolld->adodb->setDebug($_SESSION["debug"]);
// If start/stop button was pressed
if ($_POST["PollDControl"] != "") {
if ($_POST["PollDControl"] == "Start") {
$tmonpolld->controlPollD("on");
} else if ($_POST["PollDControl"] == "Stop") {
$tmonpolld->controlPollD("off");
}
}
if ($tmonpolld->isEnabled()=="1") {
$polldenabled = "enabled and ".$tmonpolld->getStatus();
//$cellcolor = "green";
} else {
$polldenabled = "disabled";
//$cellcolor = "red";
}
echo "";
} else {
if ( ($_GET['action'] != "" && ($_GET['action'] == "edit" && $_GET['id'] != "")) || $_POST['Add'] == "Add") {
$i = 0;
// show Add New Entry Form
if ($_POST['Add'] == "Add") {
$sqlth = "SHOW COLUMNS from cfg_".$tsmmonitor->GETVars['qq'];
$sqlresth = $adodb->fetchArrayDB($sqlth);
echo "";
// show Edit Existing Entry Form
} else {
$tablearray = $tsmmonitor->getAdminTables("edit");
echo "";
}
// show List of all entries
} else {
// Process deletion of an item
if ( $_GET['id'] != "" && $_GET['action'] != "") {
if ($_GET['action'] == "delete") {
echo $_POST['hidfield'];
$sql = "DELETE from cfg_".$_GET['q']." where id='".$_GET['id']."' LIMIT 1";
$adodb->execDB($sql);
}
// Process update of an existing item or insert of a new one
} else if ($_POST['EditSave'] == "Save" || $_POST['AddSave'] == "Save") {
$sqlth = "SHOW COLUMNS from cfg_".$_GET['q'];
$sqlresth = $adodb->fetchArrayDB($sqlth);
$colarray = array();
$colarray['id'] = $_POST['id'];
$set = "";
$sqlcols = "";
$sqlvals = "";
// get all table fields to be selected
foreach ($sqlresth as $col) {
if ($col['Field'] != "id") {
if ($col['Field'] == "password") {
if ($_POST["txt".$col['Field']] != "") {
$val = md5($_POST["txt".$col['Field']]);
} else {
$val = "";
}
} else {
$val = $_POST["txt".$col['Field']];
}
if ($val != "") {
if ($_POST['AddSave'] == "Save") {
$colarray["`".$col['Field']."`"] = $val;
$sqlcols .= $col['Field'];
$sqlvals .= "'".$val."'";
$sqlcols .= ", ";
$sqlvals .= ", ";
} else if ($_POST['EditSave'] == "Save") {
$colarray["`".$col['Field']."`"] = $val;
$set .= $col['Field']."='".$val."'";
$set .= ", ";
}
}
}
}
$sqlcols = ereg_replace(", $", "", $sqlcols);
$sqlvals = ereg_replace(", $", "", $sqlvals);
if ($_POST['AddSave'] == "Save") {
$sql = "INSERT into cfg_".$_GET['q']." (".$sqlcols.") values (".$sqlvals.")";
} else if ($_POST['EditSave'] == "Save") {
$sql = "UPDATE cfg_".$_GET['q']." set ".$set." where id='".$_POST['id']."' LIMIT 1";
}
$adodb->updateDB("cfg_".$_GET['q'], $colarray, 'id');
}
echo "";
}
}
}
} else {
if (isset($_SESSION["logindata"])) {
$errormsg = "Login failed!";
} else {
$errormsg = "Login";
}
session_unset();
$_SESSION=array();
include_once "includes/login.php";
}
$_SESSION['from'] = $tsmmonitor->GETVars['qq'];
session_write_close(void);
?>
|