More bug fixes to the query app. There is another part to further clean up regressions, but that will come after Christmas.

This commit is contained in:
robert%accettura.com 2005-12-24 04:25:44 +00:00
Родитель 5b75289252
Коммит 9a05e16246
2 изменённых файлов: 109 добавлений и 65 удалений

Просмотреть файл

@ -63,20 +63,19 @@ $db->SetFetchMode(ADODB_FETCH_ASSOC);
$query = new query; $query = new query;
$query_input = $query->getQueryInputs(); $query_input = $query->getQueryInputs();
$continuity_params = $query->continuityParams($query_input); $continuityParams = $query->continuityParams($query_input, null);
$columnHeaders = $query->columnHeaders($query_input, $continuity_params); $columnHeaders = $query->columnHeaders($query_input, $continuityParams);
$result = $query->doQuery($query_input['selected'], $result = $query->doQuery($query_input['selected'],
$query_input['where'], $query_input['where'],
$query_input['orderby'], $query_input['orderby'],
$query_input['ascdesc'],
$query_input['show'], $query_input['show'],
$query_input['page'], $query_input['page'],
$query_input['count'] $query_input['count']
); );
$output = $query->outputHTML($result, $query_input, $continuity_params, $columnHeaders); $output = $query->outputHTML($result, $query_input, $continuityParams, $columnHeaders);
// disconnect database // disconnect database
$db->Close(); $db->Close();
@ -101,7 +100,9 @@ if($result['totalResults'] < 2000){
$content->assign('column', $columnHeaders); $content->assign('column', $columnHeaders);
$content->assign('row', $output['data']); $content->assign('row', $output['data']);
$content->assign('continuity_params', $continuity_params[1]);
/* this particular continuity_params is for pagination (it doesn't include 'page') */
$content->assign('continuity_params', $query->continuityParams($query_input, array('page')));
/* Pagination */ /* Pagination */
$pages = ceil($result['totalResults']/$query_input['show']); $pages = ceil($result['totalResults']/$query_input['show']);
@ -127,4 +128,5 @@ if(ceil($result['totalResults']/$query_input['show']) < 20){
$content->assign('amt', 20); $content->assign('amt', 20);
} }
displayPage($content, 'query', 'query.tpl'); displayPage($content, 'query', 'query.tpl');
?> ?>

Просмотреть файл

@ -95,35 +95,44 @@ class query
/******************* /*******************
* SELECT * SELECT
*******************/ *******************/
$selected = array();
/* /*
If user defines what to select and were not counting, just If user defines what to select and were not counting, just
use their input. use their input.
*/ */
$selected = array();
if (isset($_GET['selected']) && !isset($_GET['count'])){ if (isset($_GET['selected']) && !isset($_GET['count'])){
$selected = array();
foreach($_GET['selected'] as $selectedChild){ foreach($_GET['selected'] as $selectedChild){
if(in_array(strtolower($selectedChild), $this->approved_selects)){ if(in_array(strtolower($selectedChild), $this->approved_selects)){
$selected[$selectedChild] = $config['fields'][$selectedChild]; $selected[] = array('field' => $selectedChild,
'title' => $config['fields'][$selectedChild]);
} }
} }
} else { } else {
// Otherwise, we do it for them // Otherwise, we do it for them
$selected = array('report_id' => 'Report ID', 'host_hostname' => 'Host'); $selected[] = array('field' => 'host_hostname',
'title' => 'Host');
}
if(!isset($_GET['count']) &&
$this->_searchQueryInput($selected, 'report_id') === false){
$artificialReportID = true;
$selected[] = array('field' => 'report_id',
'title' => 'Report ID');
} }
/******************* /*******************
* ORDER BY * ORDER BY
*******************/ *******************/
$orderby = array(); $orderby = array();
// The first priority is those who were recently specified (such as a menu header clicked).
if(isset($_GET['orderby']) && in_array(strtolower($_GET['orderby']), $this->approved_selects)){ if(isset($_GET['orderby']) && in_array(strtolower($_GET['orderby']), $this->approved_selects)){
$orderby[$_GET['orderby']] = $ascdesc; $orderby[$_GET['orderby']] = $ascdesc;
} }
// After, we append those who werere selected previously and order desc.
if(!isset($_GET['count'])){ if(!isset($_GET['count'])){
$orderby = array_merge($orderby, $this->calcOrderBy($selected)); $orderby = array_merge($orderby, $this->_calcOrderBy($selected, $orderby));
} }
// If we are counting, we need to add A column for it // If we are counting, we need to add A column for it
if (isset($_GET['count'])){ if (isset($_GET['count'])){
// set the count variable // set the count variable
@ -146,14 +155,6 @@ class query
$orderby['host_hostname'] = 'desc'; $orderby['host_hostname'] = 'desc';
} }
} }
print_r($orderby);
}
else {
if(!isset($selected['report_id'])){
$selected['report_id'] = "Report ID";
$artificialReportID = true;
}
// $selected['report_file_date'] = "Date";
} }
/******************* /*******************
* WHERE * WHERE
@ -186,7 +187,6 @@ print_r($orderby);
return array('selected' => $selected, return array('selected' => $selected,
'where' => $where, 'where' => $where,
'orderby' => $orderby, 'orderby' => $orderby,
'ascdesc' => $ascdesc,
'show' => $show, 'show' => $show,
'page' => $page, 'page' => $page,
'count' => $count, 'count' => $count,
@ -194,14 +194,14 @@ print_r($orderby);
); );
} }
function doQuery($select, $where, $orderby, $ascdesc, $show, $page, $count){ function doQuery($select, $where, $orderby, $show, $page, $count){
global $db; global $db;
/************ /************
* SELECT * SELECT
************/ ************/
$sql_select = 'SELECT '; $sql_select = 'SELECT ';
foreach($select as $select_child => $select_child_title){ foreach($select as $select_child){
// we don't $db->quote here since unless it's in our approved array (exactly), we drop it anyway. i.e. report_id is on our list, 'report_id' is not. // we don't $db->quote here since unless it's in our approved array (exactly), we drop it anyway. i.e. report_id is on our list, 'report_id' is not.
// we sanitize on our own // we sanitize on our own
if ($select_child == 'count'){ if ($select_child == 'count'){
@ -210,7 +210,7 @@ print_r($orderby);
$orderby = array_merge(array('count'=> 'DESC'), $orderby); $orderby = array_merge(array('count'=> 'DESC'), $orderby);
} }
} else { } else {
$sql_select .= $select_child; $sql_select .= $select_child['field'];
} }
$sql_select .= ', '; $sql_select .= ', ';
} }
@ -266,7 +266,8 @@ print_r($orderby);
/******************* /*******************
* ORDER BY * ORDER BY
*******************/ *******************/
if(isset($orderby)){ $sql_orderby = '';
if(isset($orderby) && sizeof($orderby) > 0){
$sql_orderby = 'ORDER BY '; $sql_orderby = 'ORDER BY ';
foreach($orderby as $orderChild => $orderDir){ foreach($orderby as $orderChild => $orderDir){
$sql_orderby .= $orderChild.' '.$orderDir; $sql_orderby .= $orderChild.' '.$orderDir;
@ -319,66 +320,81 @@ print_r($orderby);
return array('data' => $dbResult, 'totalResults' => sizeof($totalResults), 'reportList' => $totalResults); return array('data' => $dbResult, 'totalResults' => sizeof($totalResults), 'reportList' => $totalResults);
} }
function continuityParams($query_input){ function continuityParams($query_input, $omit){
reset($query_input['where']); reset($query_input['where']);
$standard = ''; $standard = '';
$complete = '';
foreach($query_input['where'] as $node => $item){ // if $omit is empty, make it a blank array
if(!($item[0] == 'report_id' && $query_input['artificialReportID'])){ if($omit == null){ $omit = array(); }
if(is_numeric($item[2])){
$standard .= $item[0].'='.$item[2].'&amp;';; // Where
} else { if(isset($query_input['where']) && sizeof($query_input['where']) > 0){
$standard .= $item[0].'='.urlencode($item[2]).'&amp;';; foreach($query_input['where'] as $node => $item){
} if(!($item[0] == 'report_id' && $query_input['artificialReportID'])){
} if(!in_array($item[0], $omit)){
} if(is_numeric($item[2])){
if(isset($query_input['selected']) && sizeof($query_input['selected']) > 0){ $standard .= $item[0].'='.$item[2].'&amp;';;
foreach($query_input['selected'] as $selected_node => $selected_item){ } else {
if(!($selected_node == 'report_id' && $query_input['artificialReportID'])){ $standard .= $item[0].'='.urlencode($item[2]).'&amp;';;
if($selected_node == 'count'){ }
$complete .= 'selected%5B%5D='.$selected_node.'&amp;';
} else {
$standard .= 'selected%5B%5D='.$selected_node.'&amp;';
} }
} }
} }
} }
// make complete = standard + complete // Selected
$complete = $standard.$complete; if(isset($query_input['selected']) && sizeof($query_input['selected']) > 0 && !in_array('selected', $omit)){
foreach($query_input['selected'] as $selectedNode){
if(!($selectedNode['field'] == 'report_id' && $query_input['artificialReportID'])){
$standard .= 'selected%5B%5D='.$selectedNode['field'].'&amp;';
}
}
}
// finish off complete // Orderby
if($query_input['count']){
$complete .= 'count=on'; // Count
if(isset($query_input['count']) && !in_array('count', $omit)){
$standard .= 'count=on'.'&amp;';
}
// Show
if(isset($query_input['show']) && !in_array('show', $omit)){
$standard .= 'show='.$query_input['show'].'&amp;';
}
// Page
if(isset($query_input['page']) && !in_array('page', $omit)){
$standard .= 'page='.$query_input['page'].'&amp;';
} }
// strip off any remaining &amp; that may be on the end // strip off any remaining &amp; that may be on the end
if(substr($standard, -5) == '&amp;'){ if(substr($standard, -5) == '&amp;'){
$standard = substr($standard, 0, -5); $standard = substr($standard, 0, -5);
} }
if(substr($complete, -5) == '&amp;'){
$complete = substr($complete, 0, -5);
}
// lets return // lets return
return array($standard, $complete); return $standard;
} }
function columnHeaders($query_input, $continuity_params){ function columnHeaders($query_input, $continuityParams){
$columnCount = 0; $columnCount = 0;
$column[$columnCount]['text'] = 'Detail'; $column[$columnCount]['text'] = 'Detail';
$columnCount++; $columnCount++;
foreach($query_input['selected'] as $title_name => $title){
if($title_name == 'report_id' && $query_input['artificialReportID']){
} else {
$column[$columnCount]['text'] = $title;
$o_orderby = $title_name; foreach($query_input['selected'] as $selectedChild){
if ($query_input['ascdesc'] == 'desc'){ if(!($selectedChild['field'] == 'report_id' && $query_input['artificialReportID'])){
$column[$columnCount]['text'] = $selectedChild['title'];
$o_orderby = $selectedChild['field'];
// Figure out if it should be an asc or desc link
if($selectedChild['field'] == $this->_firstChildKey($query_input['orderby']) && $query_input['orderby'][$selectedChild['field']] == 'desc'){
$o_ascdesc = 'asc'; $o_ascdesc = 'asc';
} else { } else {
$o_ascdesc = 'desc'; $o_ascdesc = 'desc';
} }
if((isset($query_input['count']) && $title_name == 'count') || !isset($query_input['count'])){ if((isset($query_input['count']) && $title_name == 'count') || !isset($query_input['count'])){
$column[$columnCount]['url'] = '?'.$continuity_params[1].'&amp;orderby='.$o_orderby.'&amp;ascdesc='.$o_ascdesc; $column[$columnCount]['url'] = '?'.$continuityParams.'&amp;orderby='.$o_orderby.'&amp;ascdesc='.$o_ascdesc;
} }
$columnCount++; $columnCount++;
} }
@ -431,15 +447,41 @@ print_r($orderby);
function outputCSV(){} function outputCSV(){}
function outputXLS(){} function outputXLS(){}
function outputRSS(){} function outputRSS(){}
function calcOrderBy($query){ function _calcOrderBy($selected, $orderby){
$result = array(); $result = array();
foreach($this->approved_selects as $selectNode){ foreach($this->approved_selects as $selectedChild){
if(array_key_exists($selectNode, $query)){ if($this->_searchQueryInput($selected, $selectedChild) !== false &&
$result[$selectNode] = 'desc'; !array_key_exists($selectedChild, $orderby))
{
$result[$selectedChild] = 'desc';
} }
} }
/*
foreach($selected as $selectedChild){
if(in_array($selectedChild['field'], $this->approved_selects) &&
!array_key_exists($selectedChild['field'], $orderby))
{
$result[$selectedChild['field']] = 'desc';
}
}
*/
return $result; return $result;
} }
function _searchQueryInput($input, $query){
for($i=0; $i< sizeof($input); $i++){
if ($input[$i]['field'] == $query){
return $i;
}
}
return false;
}
function _firstChildKey($keyOf){
$key = array_keys($keyOf);
return $key[0];
}
} }
?> ?>