Added in class member variables, fixed warnings about undefined values, prettied up the code to Campware coding conventions.
This commit is contained in:
parent
0a6d53d58d
commit
0895418753
1 changed files with 54 additions and 33 deletions
|
@ -1,6 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
class uiSearch
|
class uiSearch
|
||||||
{
|
{
|
||||||
|
var $Base;
|
||||||
|
var $prefix;
|
||||||
|
var $criteria;
|
||||||
|
var $reloadUrl;
|
||||||
|
var $results;
|
||||||
|
|
||||||
function uiSearch(&$uiBase)
|
function uiSearch(&$uiBase)
|
||||||
{
|
{
|
||||||
$this->Base =& $uiBase;
|
$this->Base =& $uiBase;
|
||||||
|
@ -34,48 +40,61 @@ class uiSearch
|
||||||
#print_r($this->criteria['form']);
|
#print_r($this->criteria['form']);
|
||||||
include dirname(__FILE__).'/formmask/metadata.inc.php';
|
include dirname(__FILE__).'/formmask/metadata.inc.php';
|
||||||
$form = new HTML_QuickForm('search', UI_STANDARD_FORM_METHOD, UI_HANDLER);
|
$form = new HTML_QuickForm('search', UI_STANDARD_FORM_METHOD, UI_HANDLER);
|
||||||
$form->setConstants(array('id'=>$id, 'counter'=>$this->criteria['counter'] ? $this->criteria['counter'] : 1));
|
$counter = isset($this->criteria['counter']) ? $this->criteria['counter'] : 1;
|
||||||
|
$form->setConstants(array('id'=>$id, 'counter'=>$counter));
|
||||||
|
|
||||||
foreach ($mask['pages'] as $key=>$val) {
|
foreach ($mask['pages'] as $key=>$val) {
|
||||||
foreach ($mask['pages'][$key] as $v){
|
foreach ($mask['pages'][$key] as $v){
|
||||||
if ($v['type']) {
|
if (isset($v['type']) && $v['type']) {
|
||||||
$col1[$this->Base->_formElementEncode($v['element'])] = tra($v['label']);
|
$col1[$this->Base->_formElementEncode($v['element'])] = tra($v['label']);
|
||||||
if (isset($val['relation']))
|
if (isset($val['relation'])) {
|
||||||
$col2[$this->Base->_formElementEncode($v['element'])] = $mask2['relations'][$v['relation']];
|
$col2[$this->Base->_formElementEncode($v['element'])] = $mask2['relations'][$v['relation']];
|
||||||
else
|
} else {
|
||||||
$col2[$this->Base->_formElementEncode($v['element'])] = $mask2['relations']['standard'];
|
$col2[$this->Base->_formElementEncode($v['element'])] = $mask2['relations']['standard'];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
for($n = 1; $n <= UI_SEARCH_MAX_ROWS; $n++) {
|
for ($n = 1; $n <= UI_SEARCH_MAX_ROWS; $n++) {
|
||||||
unset ($group);
|
unset($group);
|
||||||
|
|
||||||
if ($n > 1 && $n > $this->criteria['counter'])
|
if (($n > 1) && ($n > $counter) ) {
|
||||||
$activerow = FALSE;
|
$activerow = FALSE;
|
||||||
else $activerow = TRUE;
|
} else {
|
||||||
|
$activerow = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
$form->addElement('static', 's1', NULL, "<div id='searchRow_$n'>");
|
$form->addElement('static', 's1', NULL, "<div id='searchRow_$n'>");
|
||||||
|
|
||||||
if ($activerow===FALSE) $form->addElement('static', 's1_style', NULL, "<style type='text/css'>#searchRow_$n {display:none; height:0px}</style>");
|
if ($activerow === FALSE) {
|
||||||
|
$form->addElement('static', 's1_style', NULL, "<style type='text/css'>#searchRow_$n {display:none; height:0px}</style>");
|
||||||
|
}
|
||||||
|
|
||||||
$sel = &$form->createElement('hierselect', "row_$n", NULL);
|
$sel = &$form->createElement('hierselect', "row_$n", NULL);
|
||||||
$sel->setOptions(array($col1, $col2));
|
$sel->setOptions(array($col1, $col2));
|
||||||
$group[] = &$sel;
|
$group[] = &$sel;
|
||||||
$group[] = &$form->createElement('text', "row_$n".'[2]', NULL, array('size' => 25, 'maxlength' => UI_INPUT_STANDARD_MAXLENGTH));
|
$group[] = &$form->createElement('text', "row_$n".'[2]', NULL, array('size' => 25, 'maxlength' => UI_INPUT_STANDARD_MAXLENGTH));
|
||||||
|
|
||||||
if ($activerow) $group[] = &$form->createElement('hidden', "row_$n".'[active]', TRUE);
|
if ($activerow) {
|
||||||
else $group[] = &$form->createElement('hidden', "row_$n".'[active]', FALSE);
|
$group[] = &$form->createElement('hidden', "row_$n".'[active]', TRUE);
|
||||||
|
} else {
|
||||||
|
$group[] = &$form->createElement('hidden', "row_$n".'[active]', FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
if ($n === 1) $group[] = &$form->createElement('button', "addRow", tra('+'), array('onClick' => "SearchForm_addRow('$n')", 'class' => UI_BUTTON_STYLE));
|
if ($n === 1) {
|
||||||
else $group[] = &$form->createElement('button', "dropRow_$n", tra('-'), array('onClick' => "SearchForm_dropRow('$n')", 'class' => UI_BUTTON_STYLE));
|
$group[] = &$form->createElement('button', "addRow", tra('+'), array('onClick' => "SearchForm_addRow('$n')", 'class' => UI_BUTTON_STYLE));
|
||||||
|
} else {
|
||||||
|
$group[] = &$form->createElement('button', "dropRow_$n", tra('-'), array('onClick' => "SearchForm_dropRow('$n')", 'class' => UI_BUTTON_STYLE));
|
||||||
|
}
|
||||||
|
|
||||||
$form->addGroup($group);
|
$form->addGroup($group);
|
||||||
$form->addElement('static', 's2', NULL, "</div id='searchRow_$n'>");
|
$form->addElement('static', 's2', NULL, "</div id='searchRow_$n'>");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->Base->_parseArr2Form($form, $mask2['search']);
|
$this->Base->_parseArr2Form($form, $mask2['search']);
|
||||||
$form->setConstants($this->criteria['form']);
|
$constants = isset($this->criteria['form']) ? $this->criteria['form'] : null;
|
||||||
|
$form->setConstants($constants);
|
||||||
$form->validate();
|
$form->validate();
|
||||||
$renderer =& new HTML_QuickForm_Renderer_Array(true, true);
|
$renderer =& new HTML_QuickForm_Renderer_Array(true, true);
|
||||||
$form->accept($renderer);
|
$form->accept($renderer);
|
||||||
|
@ -89,7 +108,6 @@ class uiSearch
|
||||||
function newSearch(&$formdata)
|
function newSearch(&$formdata)
|
||||||
{
|
{
|
||||||
#print_r($formdata);
|
#print_r($formdata);
|
||||||
|
|
||||||
$this->results = NULL;
|
$this->results = NULL;
|
||||||
$this->criteria['conditions'] = NULL;
|
$this->criteria['conditions'] = NULL;
|
||||||
$this->criteria['offset'] = NULL;
|
$this->criteria['offset'] = NULL;
|
||||||
|
@ -99,7 +117,6 @@ class uiSearch
|
||||||
$this->criteria['limit'] = $formdata['limit'];
|
$this->criteria['limit'] = $formdata['limit'];
|
||||||
$this->criteria['counter'] = 0;
|
$this->criteria['counter'] = 0;
|
||||||
|
|
||||||
|
|
||||||
$this->criteria['form']['operator'] = $formdata['operator']; ## $criteria['form'] is used for retransfer to form ##
|
$this->criteria['form']['operator'] = $formdata['operator']; ## $criteria['form'] is used for retransfer to form ##
|
||||||
$this->criteria['form']['filetype'] = $formdata['filetype'];
|
$this->criteria['form']['filetype'] = $formdata['filetype'];
|
||||||
$this->criteria['form']['limit'] = $formdata['limit'];
|
$this->criteria['form']['limit'] = $formdata['limit'];
|
||||||
|
@ -131,7 +148,6 @@ class uiSearch
|
||||||
$output = $renderer->toArray();
|
$output = $renderer->toArray();
|
||||||
#print_r($output);
|
#print_r($output);
|
||||||
return $output;
|
return $output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,7 +156,6 @@ class uiSearch
|
||||||
$this->results = NULL;
|
$this->results = NULL;
|
||||||
$this->criteria['conditions'] = NULL;
|
$this->criteria['conditions'] = NULL;
|
||||||
$this->criteria['offset'] = NULL;
|
$this->criteria['offset'] = NULL;
|
||||||
|
|
||||||
$this->criteria['operator'] = UI_SIMPLESEARCH_OPERATOR;
|
$this->criteria['operator'] = UI_SIMPLESEARCH_OPERATOR;
|
||||||
$this->criteria['filetype'] = UI_SIMPLESEARCH_FILETYPE;
|
$this->criteria['filetype'] = UI_SIMPLESEARCH_FILETYPE;
|
||||||
$this->criteria['limit'] = UI_SIMPLESEARCH_LIMIT;
|
$this->criteria['limit'] = UI_SIMPLESEARCH_LIMIT;
|
||||||
|
@ -170,7 +185,8 @@ class uiSearch
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->results = array('page' => $this->criteria['offset'] / $this->criteria['limit']);
|
$offset = (isset($this->criteria['offset'])) ? $this->criteria['offset'] : 0;
|
||||||
|
$this->results = array('page' => $offset / $this->criteria['limit']);
|
||||||
|
|
||||||
//print_r($this->criteria);
|
//print_r($this->criteria);
|
||||||
$results = $this->Base->gb->localSearch($this->criteria, $this->Base->sessid);
|
$results = $this->Base->gb->localSearch($this->criteria, $this->Base->sessid);
|
||||||
|
@ -214,8 +230,8 @@ class uiSearch
|
||||||
if (sizeof($this->results['items']) == 0) {
|
if (sizeof($this->results['items']) == 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
$offset = isset($this->criteria['offset']) ? $this->criteria['offset'] : 0;
|
||||||
$currp = ($this->criteria['offset'] / $this->criteria['limit']) + 1; # current page
|
$currp = ($offset / $this->criteria['limit']) + 1; # current page
|
||||||
$maxp = ceil($results['cnt'] / $this->criteria['limit']); # maximum page
|
$maxp = ceil($results['cnt'] / $this->criteria['limit']); # maximum page
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -229,18 +245,23 @@ class uiSearch
|
||||||
$deltaUpper = UI_SEARCHRESULTS_DELTA;
|
$deltaUpper = UI_SEARCHRESULTS_DELTA;
|
||||||
$start = $currp;
|
$start = $currp;
|
||||||
|
|
||||||
if ($start + $maxp > 0) $deltaLower += $start - $maxp; ## correct lower boarder if page is near end
|
if ($start + $maxp > 0) {
|
||||||
|
$deltaLower += $start - $maxp; ## correct lower boarder if page is near end
|
||||||
|
}
|
||||||
|
|
||||||
for ($n = $start-$deltaLower; $n <= $start+$deltaUpper; $n++) {
|
for ($n = $start-$deltaLower; $n <= $start+$deltaUpper; $n++) {
|
||||||
if ($n <= 0) $deltaUpper++; ## correct upper boarder if page is near zero
|
if ($n <= 0) {
|
||||||
elseif ($n <= $maxp) $this->results['pagination'][$n] = $n;
|
$deltaUpper++; ## correct upper boarder if page is near zero
|
||||||
|
} elseif ($n <= $maxp) {
|
||||||
|
$this->results['pagination'][$n] = $n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#array_pop($this->results['pagination']);
|
#array_pop($this->results['pagination']);
|
||||||
$this->results['pagination'][1] ? NULL : $this->results['pagination'][1] = '|<<';
|
$this->results['pagination'][1] ? NULL : $this->results['pagination'][1] = '|<<';
|
||||||
$this->results['pagination'][$maxp] ? NULL : $this->results['pagination'][$maxp] = '>>|';
|
$this->results['pagination'][$maxp] ? NULL : $this->results['pagination'][$maxp] = '>>|';
|
||||||
$this->results['next'] = $results['cnt'] > $this->criteria['offset'] + $this->criteria['limit'] ? TRUE : FALSE;
|
$this->results['next'] = ($results['cnt'] > $offset + $this->criteria['limit']) ? TRUE : FALSE;
|
||||||
$this->results['prev'] = $this->criteria['offset'] > 0 ? TRUE : FALSE;
|
$this->results['prev'] = ($offset > 0) ? TRUE : FALSE;
|
||||||
ksort($this->results['pagination']);
|
ksort($this->results['pagination']);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -251,11 +272,11 @@ class uiSearch
|
||||||
{
|
{
|
||||||
$this->criteria['offset'] = NULL;
|
$this->criteria['offset'] = NULL;
|
||||||
|
|
||||||
if ($this->criteria['orderby'] == $by && !$this->criteria['desc'])
|
if ($this->criteria['orderby'] == $by && !$this->criteria['desc']) {
|
||||||
$this->criteria['desc'] = TRUE;
|
$this->criteria['desc'] = TRUE;
|
||||||
else
|
} else {
|
||||||
$this->criteria['desc'] = FALSE;
|
$this->criteria['desc'] = FALSE;
|
||||||
|
}
|
||||||
$this->criteria['orderby'] = $by;
|
$this->criteria['orderby'] = $by;
|
||||||
$this->setReload();
|
$this->setReload();
|
||||||
#$this->searchDB();
|
#$this->searchDB();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue