Database class integration. Create order_by() and limit_offset() functions.

This commit is contained in:
Nate
2019-07-01 17:30:03 -06:00
parent 32b04431f7
commit d075a083cf
11 changed files with 232 additions and 387 deletions
+14 -35
View File
@@ -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'>&nbsp;</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 "&nbsp;";
}
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";