From 46c100660bb72c80375630e5ec38c86e99955682 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 19 Aug 2009 22:18:00 +1000 Subject: [PATCH] Fix query default sorting and query form when no templates --- lib/Query.php | 11 +++++++---- lib/QueryRender.php | 37 ++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/Query.php b/lib/Query.php index f311f99..e1b85c8 100644 --- a/lib/Query.php +++ b/lib/Query.php @@ -129,14 +129,15 @@ class Query extends xmlTemplate { $server = $this->getServer(); $query = array(); + $query['size_limit'] = get_request('size_limit','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','size_limit')); + $query['format'] = get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display')); + $query['orderby'] = get_request('orderby','REQUEST',false,'dn'); # If this is a custom search, we need to populate are paramters if ($this->getID() == 'none') { $bases = get_request('base','REQUEST',false,null); $query['filter'] = get_request('filter','REQUEST',false,'objectClass=*'); $query['scope'] = get_request('scope','REQUEST',false,'sub'); - $query['size_limit'] = get_request('size_limit','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','size_limit')); - $query['format'] = get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display')); $attrs = get_request('display_attrs','REQUEST'); $attrs = preg_replace('/\s+/','',$attrs); @@ -169,7 +170,9 @@ class Query extends xmlTemplate { $this->resultsdata[$base]['filter'] = $query['filter']; $this->resultsdata[$base]['attrs'] = $query['attrs']; - if ($this->getAttrSortOrder()) + if ($this->getAttrSortOrder() == 'dn') + usort($this->results[$base],'pla_compare_dns'); + elseif ($this->getAttrSortOrder()) masort($this->results[$base],$this->getAttrSortOrder()); } } @@ -207,7 +210,7 @@ class Query extends xmlTemplate { array_push($result,$attribute->getName()); } else { - $display = preg_replace('/,\s+/',',',get_request('orderby','REQUEST',false,'')); + $display = preg_replace('/,\s+/',',',get_request('orderby','REQUEST',false,'dn')); if (trim($display)) $result = explode(',',$display); diff --git a/lib/QueryRender.php b/lib/QueryRender.php index 70e951d..4bb8686 100644 --- a/lib/QueryRender.php +++ b/lib/QueryRender.php @@ -30,7 +30,11 @@ class QueryRender extends PageRender { $this->template_id = $this->getTemplateChoice(); $this->page = get_request('page','REQUEST',false,1); - if ($this->template_id) { + # If we are the default template, make sure we pressed search + if ($this->template_id == 'none' && ! get_request('search','REQUEST')) + $this->drawTemplateChoice(); + + elseif ($this->template_id) { $templates = $this->getTemplates(); $this->template = $templates->getTemplate($this->template_id); $this->template->accept(); @@ -193,7 +197,7 @@ class QueryRender extends PageRender { echo ''; echo ''; - printf('
',_('Search')); + printf('
',_('Search')); echo ''; echo ''; @@ -285,23 +289,23 @@ function hideall(key,except) { switch(get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display'))) { case 'list': - foreach ($results as $dn => $dndetails) { + foreach ($results as $dndetails) { $dndetails = array_change_key_case($dndetails); # Temporarily set our DN, for rendering that leverages our DN (eg: JpegPhoto) - $this->template->setDN($dn); + $this->template->setDN($dndetails['dn']); echo ''; echo ''; - printf('',IMGDIR,get_icon($server->getIndex(),$dn)); + printf('',IMGDIR,get_icon($server->getIndex(),$dndetails['dn'])); printf('', - $server->getIndex(),rawurlencode(dn_unescape($dn)),htmlspecialchars(get_rdn($dn))); + $server->getIndex(),rawurlencode(dn_unescape($dndetails['dn'])),htmlspecialchars(get_rdn($dndetails['dn']))); echo ''; printf('', - htmlspecialchars(dn_unescape($dn))); + htmlspecialchars(dn_unescape($dndetails['dn']))); # Iterate over each attribute for this entry foreach (explode(',',$ado) as $attr) { @@ -371,24 +375,24 @@ function hideall(key,except) { echo ''; $j = 0; - foreach ($results as $dn => $dndetails) { + foreach ($results as $dndetails) { $j++; $dndetails = array_change_key_case($dndetails); # Temporarily set our DN, for rendering that leverages our DN (eg: JpegPhoto) - $this->template->setDN($dn); + $this->template->setDN($dndetails['dn']); printf('', $j%2 ? 'even' : 'odd',$j,$counter,$j,$counter); # Is mass action enabled. if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) - printf('',$j,$counter,$dn); + printf('',$j,$counter,$dndetails['dn']); - $href = sprintf('cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),rawurlencode($dn)); + $href = sprintf('cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),rawurlencode($dndetails['dn'])); printf('', htmlspecialchars($href), - IMGDIR,get_icon($server->getIndex(),$dn)); + IMGDIR,get_icon($server->getIndex(),$dndetails['dn'])); # We'll clone our attribute factory attributes, since we need to add the values to them for rendering. foreach (explode(',',$ado) as $attr) { @@ -400,9 +404,9 @@ function hideall(key,except) { # Special case for DNs if ($attr == 'dn') { - $dn_display = strlen($dn) > 40 - ? sprintf('%s...',htmlspecialchars($dn),htmlspecialchars(substr($dn,0,40))) - : htmlspecialchars($dn); + $dn_display = strlen($dndetails['dn']) > 40 + ? sprintf('%s...',htmlspecialchars($dndetails['dn']),htmlspecialchars(substr($dndetails['dn'],0,40))) + : htmlspecialchars($dndetails['dn']); printf('',htmlspecialchars($href),$dn_display); continue; @@ -483,13 +487,12 @@ function CheckAll(setbgcolor,form) { } public function drawSubTitle($subtitle=null) { - if (is_null($subtitle)) { $server = $this->getServer(); $subtitle = sprintf('%s: %s',_('Server'),$server->getName()); - if ($this->template_id) { + if ($this->template) { $subtitle .= '
'; $subtitle .= sprintf('%s: %s',('Query'),$this->template->getID() != 'none' ? $this->template->getTitle() : _('Default')); if ($this->template->getName())
iconicon%s
 dn%s
icon%s