phpldapadmin/htdocs/entry_chooser.php

136 lines
4.9 KiB
PHP
Raw Permalink Normal View History

2009-06-30 08:05:37 +00:00
<?php
2009-06-30 09:29:51 +00:00
/**
* Display a selection (popup window) to pick a DN.
*
* @package phpLDAPadmin
* @subpackage Page
*/
/**
2009-06-30 09:29:51 +00:00
*/
2009-06-30 09:22:30 +00:00
2009-06-30 10:46:00 +00:00
include './common.php';
2009-06-30 08:07:14 +00:00
$www['page'] = new page();
$request = array();
$request['container'] = get_request('container','GET');
2010-02-24 15:03:10 +00:00
$request['form'] = get_request('form','GET');
$request['element'] = get_request('element','GET');
$request['rdn'] = get_request('rdn','GET');
2009-06-30 08:05:37 +00:00
2009-06-30 11:51:50 +00:00
echo '<div class="popup">';
printf('<h3 class="subtitle">%s</h3>',_('Entry Chooser'));
2009-06-30 09:22:30 +00:00
2010-02-24 15:03:10 +00:00
echo '<script type="text/javascript">';
echo ' function returnDN(dn) {';
2010-02-24 15:03:10 +00:00
printf(" eval ('o = opener.document.getElementById(\"%s\").%s;');",$request['form'],$request['element']);
echo ' o.value = dn;';
echo ' close();';
echo ' }';
echo '</script>';
2009-06-30 09:22:30 +00:00
2010-02-24 15:03:10 +00:00
echo '<table class="forminput" width="100%" border="0">';
if ($request['container']) {
2010-02-24 15:03:10 +00:00
printf('<tr><td class="heading" colspan="3">%s:</td><td>%s</td></tr>',_('Server'),$app['server']->getName());
printf('<tr><td class="heading" colspan="3">%s:</td><td>%s</td></tr>',_('Looking in'),$request['container']);
echo '<tr><td class="blank" colspan="4">&nbsp;</td></tr>';
2009-06-30 08:05:37 +00:00
}
# Has the user already begun to descend into a specific server tree?
if (isset($app['server']) && ! is_null($request['container'])) {
$tree = get_cached_item($app['server']->getIndex(),'tree');
2009-06-30 09:29:51 +00:00
$request['children'] = $app['server']->getContainerContents($request['container'],null,0,'(objectClass=*)',$_SESSION[APPCONFIG]->getValue('deref','tree'));
sort($request['children']);
2009-06-30 09:29:51 +00:00
foreach ($app['server']->getBaseDN() as $base) {
2009-06-30 10:46:00 +00:00
if (DEBUG_ENABLED)
2009-08-19 03:39:37 +00:00
debug_log('Comparing BaseDN [%s] with container [%s]',64,0,__FILE__,__LINE__,__METHOD__,$base,$request['container']);
2009-06-30 09:29:51 +00:00
if (! pla_compare_dns($request['container'],$base)) {
2009-06-30 09:29:51 +00:00
$parent_container = false;
2010-02-24 15:03:10 +00:00
$href['up'] = sprintf('entry_chooser.php?form=%s&element=%s&rdn=%s',$request['form'],$request['element'],rawurlencode($request['rdn']));
2009-06-30 09:29:51 +00:00
break;
} else {
$parent_container = $app['server']->getContainer($request['container']);
2010-02-24 15:03:10 +00:00
$href['up'] = sprintf('entry_chooser.php?form=%s&element=%s&rdn=%s&server_id=%s&container=%s',
$request['form'],$request['element'],$request['rdn'],$app['server']->getIndex(),rawurlencode($parent_container));
2009-06-30 09:29:51 +00:00
}
2009-06-30 08:05:37 +00:00
}
2009-06-30 10:46:00 +00:00
echo '<tr>';
2009-06-30 11:51:50 +00:00
echo '<td class="blank">&nbsp;</td>';
2009-06-30 11:52:55 +00:00
printf('<td class="icon"><a href="%s"><img src="%s/up.png" alt="Up" /></a></td>',$href['up'],IMGDIR);
2010-02-24 15:03:10 +00:00
printf('<td colspan="2"><a href="%s">%s...</a></td>',$href['up'],_('Back Up'));
2009-06-30 10:46:00 +00:00
echo '</tr>';
2009-06-30 09:29:51 +00:00
if (! count($request['children']))
2010-02-24 15:03:10 +00:00
printf('<td class="blank" colspan="2">&nbsp;</td><td colspan="2">(%s)</td>',_('no entries'));
2009-06-30 09:29:51 +00:00
2009-06-30 08:05:37 +00:00
else
foreach ($request['children'] as $dn) {
$href['return'] = sprintf("javascript:returnDN('%s%s')",($request['rdn'] ? sprintf('%s,',$request['rdn']) : ''),str_replace('\\','\\\\',$dn));
2010-02-24 15:03:10 +00:00
$href['expand'] = sprintf('entry_chooser.php?server_id=%s&form=%s&element=%s&rdn=%s&container=%s',
$app['server']->getIndex(),$request['form'],$request['element'],$request['rdn'],rawurlencode($dn));
2009-06-30 10:46:00 +00:00
echo '<tr>';
2009-06-30 11:51:50 +00:00
echo '<td class="blank">&nbsp;</td>';
2009-06-30 11:52:55 +00:00
printf('<td class="icon"><a href="%s"><img src="%s/plus.png" alt="Plus" /></a></td>',$href['expand'],IMGDIR);
2009-06-30 10:46:00 +00:00
$entry = $tree->getEntry($dn);
if (is_null($entry)) {
$tree->addEntry($dn);
$entry = $tree->getEntry($dn);
}
if ($entry)
$item = draw_formatted_dn($app['server'], $entry);
else
$item = $dn;
printf('<td colspan="2"><a href="%s">%s</a></td>',$href['return'], $item );
2009-06-30 10:46:00 +00:00
echo '</tr>';
echo "\n\n";
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:29:51 +00:00
# Draw the root of the selection tree (ie, list all the servers)
2009-06-30 09:29:51 +00:00
} else {
foreach ($_SESSION[APPCONFIG]->getServerList() as $index => $server) {
if ($server->isLoggedIn(null)) {
2010-02-24 15:03:10 +00:00
printf('<tr><td class="heading" colspan="3">%s:</td><td class="heading">%s</td></tr>',_('Server'),$server->getName());
foreach ($server->getBaseDN() as $dn) {
if (! $dn) {
2010-02-24 15:03:10 +00:00
printf('<tr><td class="blank">&nbsp;</td><td colspan="3">(%s)</td></tr>',_('Could not determine base DN'));
} else {
$href['return'] = sprintf("javascript:returnDN('%s%s')",($request['rdn'] ? sprintf('%s,',$request['rdn']) : ''),rawurlencode($dn));
2010-02-24 15:03:10 +00:00
$href['expand'] = htmlspecialchars(sprintf('entry_chooser.php?server_id=%s&form=%s&element=%s&rdn=%s&container=%s',
$server->getIndex(),$request['form'],$request['element'],$request['rdn'],rawurlencode($dn)));
echo '<tr>';
echo '<td class="blank">&nbsp;</td>';
2010-02-24 15:03:10 +00:00
printf('<td colspan="2" class="icon"><a href="%s"><img src="%s/plus.png" alt="Plus" /></a></td>',$href['expand'],IMGDIR);
printf('<td colspan="2"><a href="%s">%s</a></td>',$href['return'],$dn);
2009-06-30 08:07:14 +00:00
}
}
2010-02-24 15:03:10 +00:00
echo '<tr><td class="blank" colspan="4">&nbsp;</td></tr>';
2009-06-30 08:05:37 +00:00
}
}
}
2009-06-30 10:46:00 +00:00
echo '</table>';
echo '</div>';
# Capture the output and put into the body of the page.
$www['body'] = new block();
$www['body']->SetBody(ob_get_contents());
$www['page']->block_add('body',$www['body']);
ob_end_clean();
# Render the popup.
$www['page']->display(array('CONTROL'=>false,'FOOT'=>false,'HEAD'=>false,'TREE'=>false));
2009-06-30 08:05:37 +00:00
?>