<?php
/* index.php
*
* Performs routing and initial layout for
* the MSSQL Administrator application.
*
* Author: Brad Westness
* http://www.bradwestness.com
*/
require_once("config.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head><title>MSSQL Administrator</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("form#table select").change(function(){
$("form#table").submit();
});
$("input.insert").focus(function(){
if(this.value == this.defaultValue){
$(this).val("");
}
});
$("input.data").focus(function(){
$(this).select();
});
$("input.delete").click(function(){
if(confirm("Are you sure you want to delete this record? There is no undo!")){
return true;
}
return false;
});
$(".height-50").each(function(id, element){
var height_50 = $(window).height() * .45;
if($(element).height() > height_50){
$(element).wrap("<div style='height:" +
height_50 + "px;border-bottom-width:1px' " +
"class='padding-bottom-10 " +
"padding-right-10 margin-bottom-10 " +
"overflow-auto' />");
}
});
});
</script>
</head>
<body>
<div class="page">
<h1>MSSQL Administrator</h1>
<div class="float-left width-33">
<?php
// show the table select dropdown
echo tableSelectForm();
?>
</div>
<div class="float-right width-66 last-unit">
<div class='width-100'>
<?php
// show the insert record form, if a table
// has been selected
if(isset($_GET["table"])){
$table = filter_var($_GET["table"], FILTER_SANITIZE_STRING);
echo recordInsertForm($table);
}
?>
</div>
</div>
<br class="clear-both width-100" />
<?php
// if an action has been specified (and a table is selected)
// perform the specified action
if(isset($_GET["action"]) && isset($_GET["table"])){
$action = filter_var($_GET["action"], FILTER_SANITIZE_STRING);
$table = filter_var($_GET["table"], FILTER_SANITIZE_STRING);
switch($action){
case "insert":
echo insertRecord($table);
break;
case "edit":
if(isset($_POST["identity_column"]) && isset($_POST["identity_id"])){
$column = filter_var($_POST["identity_column"], FILTER_SANITIZE_STRING);
$id = filter_var($_POST["identity_id"], FILTER_SANITIZE_NUMBER_INT);
echo updateRecord($table, $column, $id);
} elseif(isset($_GET["identity_column"]) && isset($_GET["identity_id"])){
$column = filter_var($_GET["identity_column"], FILTER_SANITIZE_STRING);
$id = filter_var($_GET["identity_id"], FILTER_SANITIZE_NUMBER_INT);
echo recordUpdateForm($table, $column, $id);
}
break;
case "delete":
if(isset($_POST["identity_column"]) && isset($_POST["identity_id"])){
$column = filter_var($_POST["identity_column"], FILTER_SANITIZE_STRING);
$id = filter_var($_POST["identity_id"], FILTER_SANITIZE_NUMBER_INT);
echo deleteRecord($table, $column, $id);
}
break;
}
}
?>
<br class="clear-both width-100" />
<?php
// show the data of the table, if a table has been specified
if(isset($_GET["table"])){
$table = filter_var($_GET["table"], FILTER_SANITIZE_STRING);
if($html = retrieveTable($table)){
echo $html;
}
}
?>
</div>
<div class='foot'>
<p>Copyright © <?php echo date("Y"); ?> <a href='http://www.bradwestness.com'>Brad Westness</a></p>
</div>
</body>
</html>