Database class integration. Create order_by() and limit_offset() functions.
This commit is contained in:
@@ -32,26 +32,28 @@
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
//delete the message
|
||||
message::add($text['message-delete']);
|
||||
|
||||
//delete the data
|
||||
if (isset($_GET["id"]) && is_uuid($_GET["id"]) && permission_exists('bridge_delete')) {
|
||||
if (is_uuid($_GET["id"]) && permission_exists('bridge_delete')) {
|
||||
|
||||
//get the id
|
||||
$id = check_str($_GET["id"]);
|
||||
$bridge_uuid = $_GET["id"];
|
||||
|
||||
//delete bridge
|
||||
$sql = "delete from v_bridges ";
|
||||
$sql .= "where bridge_uuid = '$id' ";
|
||||
$sql .= "and domain_uuid = '$domain_uuid' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
unset($sql);
|
||||
$array['bridges'][0]['bridge_uuid'] = $bridge_uuid;
|
||||
$array['bridges'][0]['domain_uuid'] = $_SESSION['domain_uuid'];
|
||||
|
||||
$database = new database;
|
||||
$database->app_name = 'bridges';
|
||||
$database->app_uuid = 'a6a7c4c5-340a-43ce-bcbc-2ed9bab8659d';
|
||||
$database->delete($array);
|
||||
unset($array);
|
||||
|
||||
//add the message
|
||||
message::add($text['message-delete']);
|
||||
|
||||
//redirect the user
|
||||
header('Location: bridges.php');
|
||||
}
|
||||
|
||||
//redirect the user
|
||||
header('Location: bridges.php');
|
||||
|
||||
|
||||
?>
|
||||
|
||||
+17
-33
@@ -24,15 +24,11 @@
|
||||
//includes
|
||||
require_once "root.php";
|
||||
require_once "resources/require.php";
|
||||
require_once "resources/check_auth.php";
|
||||
|
||||
//check permissions
|
||||
require_once "resources/check_auth.php";
|
||||
if (permission_exists('bridge_add') || permission_exists('bridge_edit')) {
|
||||
//access granted
|
||||
}
|
||||
else {
|
||||
echo "access denied";
|
||||
exit;
|
||||
if (!permission_exists('bridge_add') && !permission_exists('bridge_edit')) {
|
||||
echo "access denied"; exit;
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
@@ -40,10 +36,10 @@
|
||||
$text = $language->get();
|
||||
|
||||
//action add or update
|
||||
if (isset($_REQUEST["id"])) {
|
||||
if (is_uuid($_REQUEST["id"])) {
|
||||
$action = "update";
|
||||
$bridge_uuid = check_str($_REQUEST["id"]);
|
||||
$id = check_str($_REQUEST["id"]);
|
||||
$bridge_uuid = $_REQUEST["id"];
|
||||
$id = $_REQUEST["id"];
|
||||
}
|
||||
else {
|
||||
$action = "add";
|
||||
@@ -51,10 +47,10 @@
|
||||
|
||||
//get http post variables and set them to php variables
|
||||
if (is_array($_POST)) {
|
||||
$bridge_uuid = check_str($_POST["bridge_uuid"]);
|
||||
$bridge_name = check_str($_POST["bridge_name"]);
|
||||
$bridge_destination = check_str($_POST["bridge_destination"]);
|
||||
$bridge_enabled = check_str($_POST["bridge_enabled"]);
|
||||
$bridge_uuid = $_POST["bridge_uuid"];
|
||||
$bridge_name = $_POST["bridge_name"];
|
||||
$bridge_destination = $_POST["bridge_destination"];
|
||||
$bridge_enabled = $_POST["bridge_enabled"];
|
||||
}
|
||||
|
||||
//process the user data and save it to the database
|
||||
@@ -62,7 +58,7 @@
|
||||
|
||||
//get the uuid from the POST
|
||||
if ($action == "update") {
|
||||
$bridge_uuid = check_str($_POST["bridge_uuid"]);
|
||||
$bridge_uuid = $_POST["bridge_uuid"];
|
||||
}
|
||||
|
||||
//check for all required data
|
||||
@@ -98,19 +94,10 @@
|
||||
//save to the data
|
||||
$database = new database;
|
||||
$database->app_name = 'bridges';
|
||||
$database->app_uuid = null;
|
||||
if (strlen($bridge_uuid) > 0) {
|
||||
$database->uuid($bridge_uuid);
|
||||
}
|
||||
$database->app_uuid = 'a6a7c4c5-340a-43ce-bcbc-2ed9bab8659d';
|
||||
$database->save($array);
|
||||
$message = $database->message;
|
||||
|
||||
//debug info
|
||||
//echo "<pre>";
|
||||
//print_r($message);
|
||||
//echo "</pre>";
|
||||
//exit;
|
||||
|
||||
//redirect the user
|
||||
if (isset($action)) {
|
||||
if ($action == "add") {
|
||||
@@ -126,21 +113,18 @@
|
||||
|
||||
//pre-populate the form
|
||||
if (is_array($_GET) && $_POST["persistformvar"] != "true") {
|
||||
$bridge_uuid = check_str($_GET["id"]);
|
||||
$parameters['bridge_uuid'] = $bridge_uuid;
|
||||
$bridge_uuid = $_GET["id"];
|
||||
$sql = "select * from v_bridges ";
|
||||
$sql .= "where bridge_uuid = :bridge_uuid ";
|
||||
//$sql .= "and domain_uuid = :domain_uuid ";
|
||||
$parameters['bridge_uuid'] = $bridge_uuid;
|
||||
$database = new database;
|
||||
//$database = $database->app_name = 'bridges';
|
||||
$result = $database->execute($sql, $parameters);
|
||||
//$message = $database->message;
|
||||
foreach ($result as $row) {
|
||||
$row = $database->select($sql, $parameters, 'row');
|
||||
if (is_array($row) && sizeof($row) != 0) {
|
||||
$bridge_name = $row["bridge_name"];
|
||||
$bridge_destination = $row["bridge_destination"];
|
||||
$bridge_enabled = $row["bridge_enabled"];
|
||||
}
|
||||
unset ($prep_statement);
|
||||
unset($sql, $parameters, $row);
|
||||
}
|
||||
|
||||
//show the header
|
||||
|
||||
+14
-35
@@ -31,12 +31,8 @@
|
||||
require_once "resources/paging.php";
|
||||
|
||||
//check permissions
|
||||
if (permission_exists('bridge_view')) {
|
||||
//access granted
|
||||
}
|
||||
else {
|
||||
echo "access denied";
|
||||
exit;
|
||||
if (!permission_exists('bridge_view')) {
|
||||
echo "access denied"; exit;
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
@@ -88,7 +84,7 @@
|
||||
$parameters['domain_uuid'] = $domain_uuid;
|
||||
|
||||
//add the search term
|
||||
$search = strtolower(check_str($_GET["search"]));
|
||||
$search = strtolower($_GET["search"]);
|
||||
if (strlen($search) > 0) {
|
||||
$sql_search = " (";
|
||||
$sql_search .= " lower(bridge_name) like :search ";
|
||||
@@ -100,7 +96,7 @@
|
||||
}
|
||||
|
||||
//prepare to page the results
|
||||
$sql = "select count(bridge_uuid) as num_rows from v_bridges ";
|
||||
$sql = "select count(bridge_uuid) from v_bridges ";
|
||||
if ($_GET['show'] == "all" && permission_exists('bridge_all')) {
|
||||
if (isset($sql_search)) {
|
||||
$sql .= "where ".$sql_search;
|
||||
@@ -112,9 +108,6 @@
|
||||
$sql .= "and ".$sql_search;
|
||||
}
|
||||
}
|
||||
if (strlen($order_by) > 0) {
|
||||
$sql .= "order by $order_by $order ";
|
||||
}
|
||||
$database = new database;
|
||||
$num_rows = $database->select($sql, $parameters, 'column');
|
||||
|
||||
@@ -142,12 +135,8 @@
|
||||
$sql .= "and ".$sql_search;
|
||||
}
|
||||
}
|
||||
if (strlen($order_by) > 0) {
|
||||
$sql .= "order by $order_by $order ";
|
||||
}
|
||||
if (is_numeric($rows_per_page) && is_numeric($offset)) {
|
||||
$sql .= "limit $rows_per_page offset $offset ";
|
||||
}
|
||||
$sql .= order_by($order_by, $order);
|
||||
$sql .= limit_offset($rows_per_page, $offset);
|
||||
$database = new database;
|
||||
$bridges = $database->select($sql, $parameters, 'all');
|
||||
//$message = $database->message;
|
||||
@@ -249,32 +238,22 @@
|
||||
echo " </td>\n";
|
||||
echo "</tr>\n";
|
||||
$x++;
|
||||
if ($c==0) { $c=1; } else { $c=0; }
|
||||
$c = $c == 1 ? 0 : 1;
|
||||
} //end foreach
|
||||
unset($sql, $bridges);
|
||||
} //end if results
|
||||
|
||||
echo "<tr>\n";
|
||||
echo "<td colspan='5' align='left'>\n";
|
||||
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
|
||||
echo " <tr>\n";
|
||||
echo " <td width='33.3%' nowrap='nowrap'> </td>\n";
|
||||
echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
|
||||
echo " <td class='list_control_icons'>";
|
||||
echo "</table>\n";
|
||||
if (permission_exists('bridge_add')) {
|
||||
echo "<a href='bridge_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
|
||||
echo "<div style='float: right;'>\n";
|
||||
echo " <a href='bridge_edit.php' alt=\"".$text['button-add']."\">".$v_link_label_add."</a>";
|
||||
echo "</div>\n";
|
||||
}
|
||||
else {
|
||||
echo " ";
|
||||
}
|
||||
echo " </td>\n";
|
||||
echo " </tr>\n";
|
||||
echo " </table>\n";
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
echo "</table>";
|
||||
echo "<br />\n";
|
||||
echo "<div align='center'>".$paging_controls."</div>\n";
|
||||
|
||||
echo "</form>\n";
|
||||
echo "<br /><br />";
|
||||
|
||||
//include the footer
|
||||
require_once "resources/footer.php";
|
||||
|
||||
Reference in New Issue
Block a user