From 08954187537634e06800c2c32d88b7f33ec9af10 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 1 Sep 2006 08:33:50 +0000 Subject: [PATCH] Added in class member variables, fixed warnings about undefined values, prettied up the code to Campware coding conventions. --- .../modules/htmlUI/var/ui_search.class.php | 87 ++++++++++++------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/livesupport/src/modules/htmlUI/var/ui_search.class.php b/livesupport/src/modules/htmlUI/var/ui_search.class.php index 00df09760..cf88db71d 100644 --- a/livesupport/src/modules/htmlUI/var/ui_search.class.php +++ b/livesupport/src/modules/htmlUI/var/ui_search.class.php @@ -1,6 +1,12 @@ Base =& $uiBase; @@ -34,54 +40,67 @@ class uiSearch #print_r($this->criteria['form']); include dirname(__FILE__).'/formmask/metadata.inc.php'; $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'][$key] as $v){ - if ($v['type']) { + if (isset($v['type']) && $v['type']) { $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']]; - else + } else { $col2[$this->Base->_formElementEncode($v['element'])] = $mask2['relations']['standard']; + } } }; }; - for($n = 1; $n <= UI_SEARCH_MAX_ROWS; $n++) { - unset ($group); + for ($n = 1; $n <= UI_SEARCH_MAX_ROWS; $n++) { + unset($group); - if ($n > 1 && $n > $this->criteria['counter']) + if (($n > 1) && ($n > $counter) ) { $activerow = FALSE; - else $activerow = TRUE; + } else { + $activerow = TRUE; + } $form->addElement('static', 's1', NULL, "
"); - if ($activerow===FALSE) $form->addElement('static', 's1_style', NULL, ""); + if ($activerow === FALSE) { + $form->addElement('static', 's1_style', NULL, ""); + } $sel = &$form->createElement('hierselect', "row_$n", NULL); $sel->setOptions(array($col1, $col2)); $group[] = &$sel; $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); - else $group[] = &$form->createElement('hidden', "row_$n".'[active]', FALSE); + if ($activerow) { + $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)); - else $group[] = &$form->createElement('button', "dropRow_$n", tra('-'), array('onClick' => "SearchForm_dropRow('$n')", 'class' => UI_BUTTON_STYLE)); + if ($n === 1) { + $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->addElement('static', 's2', NULL, "
"); } $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(); $renderer =& new HTML_QuickForm_Renderer_Array(true, true); $form->accept($renderer); $output['dynform'] = $renderer->toArray(); #print_r($output); - #echo 'output:'; print_r($output); echo "\n"; + #echo 'output:'; print_r($output); echo "\n"; return $output; } @@ -89,7 +108,6 @@ class uiSearch function newSearch(&$formdata) { #print_r($formdata); - $this->results = NULL; $this->criteria['conditions'] = NULL; $this->criteria['offset'] = NULL; @@ -99,7 +117,6 @@ class uiSearch $this->criteria['limit'] = $formdata['limit']; $this->criteria['counter'] = 0; - $this->criteria['form']['operator'] = $formdata['operator']; ## $criteria['form'] is used for retransfer to form ## $this->criteria['form']['filetype'] = $formdata['filetype']; $this->criteria['form']['limit'] = $formdata['limit']; @@ -131,7 +148,6 @@ class uiSearch $output = $renderer->toArray(); #print_r($output); return $output; - } @@ -140,7 +156,6 @@ class uiSearch $this->results = NULL; $this->criteria['conditions'] = NULL; $this->criteria['offset'] = NULL; - $this->criteria['operator'] = UI_SIMPLESEARCH_OPERATOR; $this->criteria['filetype'] = UI_SIMPLESEARCH_FILETYPE; $this->criteria['limit'] = UI_SIMPLESEARCH_LIMIT; @@ -170,7 +185,8 @@ class uiSearch 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); $results = $this->Base->gb->localSearch($this->criteria, $this->Base->sessid); @@ -204,7 +220,7 @@ class uiSearch #print_r($this->results); $this->pagination($results); - + return TRUE; } @@ -214,8 +230,8 @@ class uiSearch if (sizeof($this->results['items']) == 0) { return FALSE; } - - $currp = ($this->criteria['offset'] / $this->criteria['limit']) + 1; # current page + $offset = isset($this->criteria['offset']) ? $this->criteria['offset'] : 0; + $currp = ($offset / $this->criteria['limit']) + 1; # current page $maxp = ceil($results['cnt'] / $this->criteria['limit']); # maximum page /* @@ -229,20 +245,25 @@ class uiSearch $deltaUpper = UI_SEARCHRESULTS_DELTA; $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++) { - if ($n <= 0) $deltaUpper++; ## correct upper boarder if page is near zero - elseif ($n <= $maxp) $this->results['pagination'][$n] = $n; + if ($n <= 0) { + $deltaUpper++; ## correct upper boarder if page is near zero + } elseif ($n <= $maxp) { + $this->results['pagination'][$n] = $n; + } } #array_pop($this->results['pagination']); $this->results['pagination'][1] ? NULL : $this->results['pagination'][1] = '|<<'; $this->results['pagination'][$maxp] ? NULL : $this->results['pagination'][$maxp] = '>>|'; - $this->results['next'] = $results['cnt'] > $this->criteria['offset'] + $this->criteria['limit'] ? TRUE : FALSE; - $this->results['prev'] = $this->criteria['offset'] > 0 ? TRUE : FALSE; + $this->results['next'] = ($results['cnt'] > $offset + $this->criteria['limit']) ? TRUE : FALSE; + $this->results['prev'] = ($offset > 0) ? TRUE : FALSE; ksort($this->results['pagination']); - + return TRUE; } @@ -251,11 +272,11 @@ class uiSearch { $this->criteria['offset'] = NULL; - if ($this->criteria['orderby'] == $by && !$this->criteria['desc']) + if ($this->criteria['orderby'] == $by && !$this->criteria['desc']) { $this->criteria['desc'] = TRUE; - else + } else { $this->criteria['desc'] = FALSE; - + } $this->criteria['orderby'] = $by; $this->setReload(); #$this->searchDB(); @@ -286,4 +307,4 @@ class uiSearch #$this->searchDB(); } } -?> +?> \ No newline at end of file