%s
',__METHOD__);
if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [GETquery:%s]
',__METHOD__,get_request('query','REQUEST'));
if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [Page:%s]
',__METHOD__,get_request('page','REQUEST'));
$this->template_id = $this->getTemplateChoice();
$this->page = get_request('page','REQUEST',false,1);
if ($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() {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
return new Queries($this->server_id);
}
/**
* Are default queries enabled?
*/
protected function haveDefaultTemplate() {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
$server = $this->getServer();
if ($server->getValue('query','disable_default'))
return false;
else
return true;
}
protected function drawTemplateChoice() {
if (DEBUGTMP) printf('%s
',__METHOD__);
$server = $this->getServer();
$this->drawTitle(_('Search'));
$this->drawSubTitle();
echo "\n";
$baseDNs = $server->getBaseDN();
echo '
';
echo '';
echo '';
}
private function visitStart() {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
$this->drawTitle(_('Search Results'));
$this->drawSubTitle();
echo '
';
}
private function visitEnd() {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
$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'
);
}
# Display the Javascript that enables us to show/hide DV entries
echo '';
echo "\n\n";
$this->drawBaseTabs();
switch(get_request('format','REQUEST',false,'table')) {
case 'list':
$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),
($show == $this->getAjaxRef($base) ? '' : 'none'));
echo '
';
echo '';
echo ' ';
echo ' ';
$this->drawResultsTable($base,count($results));
echo ' ';
echo ' ';
foreach ($results as $dn => $dndetails) {
$dndetails = array_change_key_case($dndetails);
# Temporarily set our DN, for rendering that leverages our DN (eg: JpegPhoto)
$this->template->setDN($dn);
echo '';
echo '';
printf(' | ',IMGDIR,get_icon($server->getIndex(),$dn));
printf('%s | ',
$server->getIndex(),rawurlencode(dn_unescape($dn)),htmlspecialchars(get_rdn($dn)));
echo ' ';
printf(' | dn | %s | ',
htmlspecialchars(dn_unescape($dn)));
# Iterate over each attribute for this entry
foreach (explode(',',$this->template->getAttrDisplayOrder()) 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 '';
$this->draw('Name',$afattrs[$attr]);
echo ' | ';
echo '';
$this->draw('CurrentValues',$afattrs[$attr]);
echo ' | ';
echo ' ';
}
echo ' ';
echo ' ';
}
echo ' |
';
echo '
';
echo '
';
echo "\n\n";
}
break;
case 'table':
# Display the results.
$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),
($show == $this->getAjaxRef($base) ? '' : 'none'));
echo '
';
echo '';
echo ' ';
echo ' ';
$this->drawResultsTable($base,count($results));
echo ' ';
echo ' ';
if (! $results) {
echo _('Search returned no results');
echo ' |
';
echo '
';
continue;
}
echo '';
echo '';
echo '';
echo '';
echo "\n\n";
echo '';
}
break;
default:
printf('Have ID [%s], run this query for page [%s]',$this->template_id,$this->page);
}
}
public function drawSubTitle($subtitle=null) {
if (is_null($subtitle)) {
$server = $this->getServer();
$subtitle = sprintf('%s: %s',_('Server'),$server->getName());
if ($this->template_id) {
$subtitle .= '
';
$subtitle .= sprintf('%s: %s',('Query'),$this->template->getID() != 'none' ? $this->template->getTitle() : _('Default'));
if ($this->template->getName())
$subtitle .= sprintf(' (%s)',$this->template->getName(false));
}
}
parent::drawSubTitle($subtitle);
}
private function getAFattrs() {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
$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) {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
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('%s | ',
$this->getAjaxRef($base),
$this->getAjaxRef($base),
($show == $this->getAjaxRef($base) ? '#F0F0F0' : '#E0E0E0'),
$base);
}
echo '
';
echo '
';
echo "\n\n";
}
private function drawResultsTable($base,$results) {
$server = $this->getServer();
echo '';
echo '';
printf('%s: %s
(%s %s) | ',_('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('[ %s ]',
$href,IMGDIR,_('export results'));
}
printf('[ %s:',IMGDIR,_('Format'));
foreach (array('list','table') as $f) {
echo ' ';
if (get_request('format','REQUEST') == $f) {
printf('%s',_($f));
} else {
$query_string = array_to_query_string($_GET,array('format','cmd'));
$query_string .= sprintf('&format=%s&show=%s',$f,$this->getAjaxRef($base));
printf('%s',htmlspecialchars($query_string),_($f));
}
}
echo ' ]';
echo ' ';
printf('%s: %s',_('Base DN'),$base);
echo ' ';
printf('%s: %s',_('Filter performed'),htmlspecialchars($this->template->resultsdata[$base]['filter']));
echo ' | ';
echo '
';
echo '
';
}
}
?>