template_id = $this->getTemplateChoice(); $this->page = get_request('page','REQUEST',false,1); # 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(); $this->visitStart(); $this->visitEnd(); } } /** * Get our templates applicable for this object */ protected function getTemplates() { return new Queries($this->server_id); } /** * Are default queries enabled? */ protected function haveDefaultTemplate() { $server = $this->getServer(); if ($server->getValue('query','disable_default')) return false; else return true; } protected function drawTemplateChoice() { $server = $this->getServer(); $this->drawTitle(_('Search')); $this->drawSubTitle(); echo "\n"; $baseDNs = $server->getBaseDN(); printf('',JSDIR); echo '
'; echo '
'; echo ''; printf('',$server->getIndex()); echo '
'; echo ''; echo ''; $templates = $this->getTemplates(); echo ''; printf('',_('The format to show the query results'),_('Display format')); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; printf('',_('Search')); echo '
 
%s'; echo ''; echo '
'; echo '
'; printf('
','block'); echo '
'; echo ''; printf('',_('Base DN')); printf(''; echo ''; echo ''; printf('',_('The scope in which to search'),_('Search scope')); echo ''; echo ''; echo ''; printf('', htmlspecialchars(_('Standard LDAP search filter. Example: (&(sn=Smith)(givenName=David))')),_('Search filter')); printf('', 'objectClass=*'); echo ''; echo ''; printf('', _('A list of attributes to display in the results (comma-separated)'),_('Show attributes')); printf('', implode(', ',$_SESSION[APPCONFIG]->getValue('search','result_attributes'))); echo ''; echo ''; printf('',_('Order by'),_('Order by')); printf('',''); echo ''; echo ''; printf('',_('Set the search results to 0 to retrieve all available records.'),_('Search Results')); printf('',$_SESSION[APPCONFIG]->getValue('search','size_limit')); echo ''; echo '
%s',count($baseDNs) == 1 ? $baseDNs[0] : ''); draw_chooser_link('advanced_search_form','base'); echo '
%s'; echo ''; echo '
%s
%s
%s
%s
'; echo '
'; echo '

'; echo '
'; } private function visitStart() { $this->drawTitle(_('Search Results')); $this->drawSubTitle(); echo '
'; } private function visitEnd() { $server = $this->getServer(); $afattrs = $this->getAFAttrs(); # If Mass Actions Enabled if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) { $mass_actions = array( _('delete') => 'mass_delete', _('edit') => 'mass_edit' ); } $this->drawBaseTabs(); $ado = $this->template->getAttrDisplayOrder(); $counter = 0; $j = 0; foreach ($this->template->results as $base => $results) { $counter++; if (! $show = get_request('show','REQUEST')) $show = ($counter === 1 ? $this->getAjaxRef($base) : null); printf('
', $this->getAjaxRef($base), ($show == $this->getAjaxRef($base) ? 'block' : 'none')); echo ''; echo ''; echo '
'; echo '
'; echo '
'; $this->drawResultsTable($base,count($results)); echo '
'; echo '
'; $format = get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display')); if ($format === 'list') { 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($dndetails['dn']); echo ''; echo ''; printf('', IMGDIR, get_icon($server->getIndex(), $dndetails['dn'])); printf('', $server->getIndex(), $this->template->getDNEncode(), htmlspecialchars(get_rdn($dndetails['dn']))); echo ''; printf('', htmlspecialchars(dn_unescape($dndetails['dn']))); # Iterate over each attribute for this entry foreach (explode(',', $ado) as $attr) { # Ignore DN, we've already displayed it. if ($attr == 'dn') continue; if (!isset($dndetails[$attr])) continue; # Set our object with our values $afattrs[$attr]->clearValue(); if (is_array($dndetails[$attr])) $afattrs[$attr]->initValue($dndetails[$attr]); else $afattrs[$attr]->initValue(array($dndetails[$attr])); echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
icon%s
 dn%s
 '; $this->draw('Name', $afattrs[$attr]); echo ''; $this->draw('CurrentValues', $afattrs[$attr]); echo '
'; echo '
'; } } else { # Display the results. if (!$results) { echo _('Search returned no results'); } else { printf('
', $counter); echo '
'; printf('', $server->getIndex()); foreach ($this->template->resultsdata[$base]['attrs'] as $attr) printf('', $attr); echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; foreach (explode(',', $ado) as $attr) { echo ''; } echo ''; echo ''; echo ''; 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($dndetails['dn']); printf('', $j % 2 ? 'even' : 'odd', $j, $j); # Is mass action enabled. if ($_SESSION[APPCONFIG]->getValue('mass', 'enabled')) printf('', $j, $dndetails['dn']); $href = sprintf('cmd=template_engine&server_id=%s&dn=%s', $server->getIndex(), $this->template->getDNEncode()); printf('', htmlspecialchars($href), 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) { # If the entry is blank, we'll draw an empty box and continue. if (!isset($dndetails[$attr])) { echo ''; continue; } # Special case for DNs if ($attr == '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; } # Set our object with our values $afattrs[$attr]->clearValue(); if (is_array($dndetails[$attr])) $afattrs[$attr]->initValue($dndetails[$attr]); else $afattrs[$attr]->initValue(array($dndetails[$attr])); echo ''; } echo ''; } # Is mass action enabled. if ($_SESSION[APPCONFIG]->getValue('mass', 'enabled')) { printf('', ++$j % 2 ? 'odd' : 'even'); printf('', $counter); printf(''; echo ''; } echo ''; echo '
  '; $this->draw('Name', $afattrs[$attr]); echo '
icon %s'; $this->draw('CurrentValues', $afattrs[$attr]); echo '
', 2 + count(explode(',', $ado))); foreach ($mass_actions as $display => $action) { echo '  '; } echo '
'; echo '
'; echo "\n\n"; } } echo '
'; echo '
'; echo "\n\n"; } if (get_request('format','REQUEST',false,'table') == 'table') printf('',JSDIR); } public function drawSubTitle($subtitle=null) { return; } private function getAFattrs() { $attribute_factory = new AttributeFactory(); $results = array(); foreach (explode(',',$this->template->getAttrDisplayOrder()) as $attr) $results[$attr] = $attribute_factory->newAttribute($attr,array('values'=>array()),$this->getServerID()); return $results; } private function getAjaxRef($dn) { return preg_replace('/=/','.',base64_encode($dn)); } private function drawBaseTabs() { # Setup the Javascript to show/hide our DIVs. echo ''; echo "\n\n"; echo ''; echo ''; $counter = 0; foreach ($this->template->results as $base => $results) { if (! $show = get_request('show','REQUEST')) $show = ($counter++ === 0 ? $this->getAjaxRef($base) : null); printf('', $this->getAjaxRef($base), $this->getAjaxRef($base), ($show == $this->getAjaxRef($base) ? '#F0F0F0' : '#E0E0E0'), htmlspecialchars($base)); } echo ''; echo '
%s
'; echo "\n\n"; } private function drawResultsTable($base,$results) { $server = $this->getServer(); echo ''; echo ''; printf('',_('Entries found'), number_format($results),$this->template->resultsdata[$base]['time'],_('seconds')); if ($_SESSION[APPCONFIG]->isCommandAvailable('script','export') && $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form')) { $href = htmlspecialchars(sprintf('cmd.php?cmd=export_form&server_id=%s&scope=%s&dn=%s&filter=%s&attributes=%s', $server->getIndex(),$this->template->resultsdata[$base]['scope'], $base,rawurlencode($this->template->resultsdata[$base]['filter']), rawurlencode(implode(', ',$this->template->resultsdata[$base]['attrs'])))); printf(''; echo ''; echo '
%s: %s

(%s %s)
[ Save %s ]', $href,IMGDIR,_('export')); } printf('[ rename %s:',IMGDIR,_('Format')); foreach (array('list','table') as $f) { echo ' '; if (get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display')) == $f) { printf('%s',_($f)); } else { $query_string = htmlspecialchars(sprintf('%s&format=%s&show=%s&focusbase=%s',array_to_query_string($_GET,array('format','meth')),$f,$this->getAjaxRef($base),$base)); if (isAjaxEnabled()) printf('%s', $query_string,$query_string,_('Loading search'),_($f)); else printf('%s',$query_string,_($f)); } } echo ' ]'; echo '
'; printf('%s: %s',_('Base DN'), htmlspecialchars($base)); echo '
'; printf('%s: %s',_('Filter performed'),htmlspecialchars($this->template->resultsdata[$base]['filter'])); echo '
'; } } ?>