2009-06-30 10:46:00 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-07-01 06:09:17 +00:00
|
|
|
* Classes and functions for the LDAP tree.
|
|
|
|
*
|
2009-06-30 10:46:00 +00:00
|
|
|
* @author The phpLDAPadmin development team
|
2009-07-01 06:09:17 +00:00
|
|
|
* @package phpLDAPadmin
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class implements an AJAX based tree.
|
|
|
|
*
|
|
|
|
* @package phpLDAPadmin
|
|
|
|
* @subpackage Tree
|
|
|
|
* @see HTMLTree Tree
|
2009-06-30 10:46:00 +00:00
|
|
|
*/
|
2009-07-01 06:09:17 +00:00
|
|
|
class AJAXTree extends HTMLTree {
|
2009-06-30 10:46:00 +00:00
|
|
|
/**
|
2009-07-01 06:09:17 +00:00
|
|
|
* Draw a node of the tree
|
|
|
|
*
|
|
|
|
* @param dn The Base DN to draw
|
|
|
|
* @param string $level a string of 0 and 1 ; $level == "000101" will draw " | |<node>"
|
|
|
|
* @param boolean $first_child is the first child entry, which is normally the "Create New Entry" option
|
|
|
|
* @param boolean $last_child is the last child entry, which is normally the "Create New Entry" option
|
2009-06-30 10:46:00 +00:00
|
|
|
*/
|
2009-08-12 13:53:14 +00:00
|
|
|
protected function draw_item($item,$level,$first_child=true,$last_child=true) {
|
2009-08-19 03:39:37 +00:00
|
|
|
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
|
|
|
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
2009-06-30 10:46:00 +00:00
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
$server = $this->getServer();
|
2009-06-30 10:46:00 +00:00
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
# Level pre-treatment
|
2009-06-30 10:46:00 +00:00
|
|
|
$code = '';
|
|
|
|
if (is_string($level)) {
|
|
|
|
for ($i=0; $i<strlen($level); $i++) {
|
2009-07-01 06:09:17 +00:00
|
|
|
if ($level[$i] == '0')
|
2009-06-30 10:46:00 +00:00
|
|
|
$code .= '0';
|
2009-07-01 06:09:17 +00:00
|
|
|
elseif ($level[$i] == '1')
|
2009-06-30 10:46:00 +00:00
|
|
|
$code .= '1';
|
|
|
|
}
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
} elseif ($level > 0)
|
2009-06-30 10:46:00 +00:00
|
|
|
$code = '0' * $level;
|
2009-07-01 06:09:17 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
$level = strlen($code);
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
# Get entry to display as node
|
2009-08-12 13:53:14 +00:00
|
|
|
$entry = $this->getEntry($item);
|
2009-07-01 06:09:17 +00:00
|
|
|
|
|
|
|
# If the entry doesnt exist, we'll add it.
|
2009-06-30 10:46:00 +00:00
|
|
|
if (! $entry) {
|
2009-08-12 13:53:14 +00:00
|
|
|
$this->addEntry($item);
|
|
|
|
$entry = $this->getEntry($item);
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
# If the entry doesnt exist in the server, then return here with an empty string.
|
2009-06-30 10:46:00 +00:00
|
|
|
if (! $entry)
|
|
|
|
return '';
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
# Get our children.
|
2009-08-12 13:53:14 +00:00
|
|
|
$child_count = $this->readChildrenNumber($item);
|
2009-06-30 10:46:00 +00:00
|
|
|
|
|
|
|
$nb = 0;
|
2009-07-01 06:09:17 +00:00
|
|
|
if ($first_child)
|
|
|
|
$nb += 1;
|
|
|
|
if ($last_child)
|
|
|
|
$nb += 2;
|
|
|
|
|
|
|
|
$imgs['expand'] = array(JSDIR.'phplayersmenu/menuimages/tree_expand.png',
|
|
|
|
JSDIR.'phplayersmenu/menuimages/tree_expand.png',
|
|
|
|
JSDIR.'phplayersmenu/menuimages/tree_expand_corner.png',
|
|
|
|
($level > 0) ? JSDIR.'phplayersmenu/menuimages/tree_expand_corner.png' : JSDIR.'phplayersmenu/menuimages/tree_expand_corner_first.png');
|
|
|
|
|
|
|
|
$imgs['collapse'] = array(JSDIR.'phplayersmenu/menuimages/tree_collapse.png',
|
|
|
|
JSDIR.'phplayersmenu/menuimages/tree_collapse.png',
|
|
|
|
JSDIR.'phplayersmenu/menuimages/tree_collapse_corner.png',
|
|
|
|
($level > 0) ? JSDIR.'phplayersmenu/menuimages/tree_collapse_corner.png' : JSDIR.'phplayersmenu/menuimages/tree_collapse_corner_first.png');
|
|
|
|
|
|
|
|
$imgs['tree'] = array(JSDIR.'phplayersmenu/menuimages/tree_split.png',
|
|
|
|
JSDIR.'phplayersmenu/menuimages/tree_split.png',
|
|
|
|
JSDIR.'phplayersmenu/menuimages/tree_corner.png',
|
|
|
|
JSDIR.'phplayersmenu/menuimages/tree_corner.png');
|
|
|
|
|
|
|
|
/** Information on array[$nb]
|
|
|
|
* nb == 1 => the node is the first child
|
|
|
|
* nb == 2 => the node is the last child
|
|
|
|
* nb == 3 => the node is the unique child
|
|
|
|
* nb == 0 => the node is a child */
|
|
|
|
$new_code = array('1','1','0','0');
|
|
|
|
|
|
|
|
# Links
|
2009-08-12 13:53:14 +00:00
|
|
|
$parms['openclose'] = htmlspecialchars(sprintf('server_id=%s&dn=%s&code=%s%s',$this->getServerID(),rawurlencode($item),$code,$new_code[$nb]));
|
|
|
|
$parms['edit'] = htmlspecialchars(sprintf('cmd=template_engine&server_id=%s&dn=%s',$this->getServerID(),rawurlencode($item)));
|
2009-07-01 06:09:17 +00:00
|
|
|
$href = sprintf('cmd.php?%s',$parms['edit']);
|
|
|
|
|
|
|
|
# Each node has a unique id based on dn
|
2009-08-12 13:53:14 +00:00
|
|
|
$node_id = sprintf('node%s',base64_encode(sprintf('%s-%s',$server->getIndex(),$item)));
|
2009-06-30 10:46:00 +00:00
|
|
|
$node_id = str_replace('=','_',$node_id);
|
|
|
|
|
|
|
|
if ($level == 0)
|
|
|
|
printf('<tr><td class="spacer"></td><td colspan="%s">',$this->getDepth()+3-1);
|
|
|
|
|
|
|
|
printf('<div id="jt%s" class="treemenudiv">',$node_id);
|
2009-07-01 06:09:17 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
echo $this->get_indentation($code);
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
if (! $child_count)
|
|
|
|
printf('<img align="top" border="0" class="imgs" id="jt%snode" src="%s" alt="--" />',$node_id,$imgs['tree'][$nb]);
|
2009-06-30 10:46:00 +00:00
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
else {
|
|
|
|
printf('<a href="#" onclick="return opencloseTreeNode(\'%s\',\'%s\');">',$node_id,$parms['openclose']);
|
|
|
|
|
|
|
|
if ($entry->isOpened())
|
|
|
|
printf('<img align="top" border="0" class="imgs" id="jt%snode" src="%s" alt="+-" />',$node_id,$imgs['collapse'][$nb]);
|
|
|
|
else
|
|
|
|
printf('<img align="top" border="0" class="imgs" id="jt%snode" src="%s" alt="+-" />',$node_id,$imgs['expand'][$nb]);
|
|
|
|
|
|
|
|
echo '</a>';
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
|
2009-08-12 13:53:14 +00:00
|
|
|
printf('<a href="%s" onclick="return displayAJ(\'BODY\',\'%s\',\'%s\');" title="%s" >',$href,$parms['edit'],_('Retrieving DN'),htmlspecialchars($item));
|
2009-07-01 06:09:17 +00:00
|
|
|
printf('<span class="dnicon"><img align="top" border="0" class="imgs" id="jt%sfolder" src="%s/%s" alt="->" /></span>',$node_id,IMGDIR,$entry->getIcon($server));
|
2009-06-30 10:46:00 +00:00
|
|
|
echo '</a>';
|
2009-07-01 06:09:17 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
echo ' ';
|
2009-08-12 13:53:14 +00:00
|
|
|
printf('<a href="%s" onclick="return displayAJ(\'BODY\',\'%s\',\'%s\');" title="%s" class="phplm">',$href,$parms['edit'],_('Retrieving DN'),htmlspecialchars($item));
|
2009-07-01 06:09:17 +00:00
|
|
|
echo $this->get_formatted_dn($entry,$level-1);
|
|
|
|
echo ($child_count ? (sprintf(' (%s%s)',$child_count,($entry->isSizeLimited() ? '+' : ''))) : '');
|
2009-06-30 10:46:00 +00:00
|
|
|
echo '</a>';
|
2009-07-01 06:09:17 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
echo '</div>';
|
2009-07-01 06:09:17 +00:00
|
|
|
|
|
|
|
printf('<div id="jt%sson" style="display: %s" class="treemenudiv">',$node_id,($entry->isOpened() ? 'block' : 'none'));
|
|
|
|
if ($entry->isOpened())
|
2009-06-30 10:46:00 +00:00
|
|
|
$this->draw_children($entry,$code.$new_code[$nb]);
|
2009-07-01 06:09:17 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
echo '</div>';
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
if ($level == 0)
|
2009-06-30 10:46:00 +00:00
|
|
|
echo '</td></tr>';
|
|
|
|
}
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
/**
|
|
|
|
* Expand and draw a child entry, when it is clicked on. This is using AJAX just to render this section of the tree.
|
|
|
|
*/
|
2009-06-30 10:46:00 +00:00
|
|
|
public function draw_children($parent_entry,$code) {
|
2009-08-19 03:39:37 +00:00
|
|
|
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
|
|
|
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
2009-06-30 10:46:00 +00:00
|
|
|
|
|
|
|
$children = array();
|
2009-08-19 11:19:35 +00:00
|
|
|
|
2009-08-22 02:56:11 +00:00
|
|
|
foreach ($parent_entry->getChildren() as $child) {
|
2009-07-01 06:09:17 +00:00
|
|
|
if (! $this->getEntry($child))
|
|
|
|
$this->addEntry($child);
|
|
|
|
|
|
|
|
array_push($children,$this->getEntry($child));
|
|
|
|
}
|
2009-06-30 10:46:00 +00:00
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
$first_child = $this->create_before_child($parent_entry,$code);
|
|
|
|
$last_child = $this->create_after_child($parent_entry,$code);
|
2009-06-30 10:46:00 +00:00
|
|
|
|
2009-06-30 11:52:55 +00:00
|
|
|
# If compression is on, we need to compress this output - but only if called by draw_tree_node
|
|
|
|
if (function_exists('isCompress') && isCompress() && get_request('cmd','REQUEST') == 'draw_tree_node')
|
|
|
|
ob_start();
|
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
echo $first_child;
|
|
|
|
|
|
|
|
for ($i=0; $i<count($children); $i++) {
|
|
|
|
$first = ($i == 0) && (! $first_child);
|
|
|
|
$last = ($i == (count($children)-1)) && (! $last_child);
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
if (is_object($children[$i]))
|
2009-08-12 13:53:14 +00:00
|
|
|
$this->draw_item($children[$i]->getDN(),$code,$first,$last);
|
2009-07-01 06:09:17 +00:00
|
|
|
else
|
|
|
|
echo '<br/>problem getting DN entry from ldap';
|
|
|
|
|
|
|
|
echo "\n";
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo $last_child;
|
2009-06-30 11:52:55 +00:00
|
|
|
|
|
|
|
# If compression is on, we need to compress this output
|
|
|
|
if (function_exists('isCompress') && isCompress() && get_request('cmd','REQUEST') == 'draw_tree_node') {
|
|
|
|
$output = ob_get_clean();
|
|
|
|
echo gzencode($output);
|
|
|
|
}
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-07-01 06:09:17 +00:00
|
|
|
* Return the indentation before a node
|
|
|
|
*
|
2009-06-30 10:46:00 +00:00
|
|
|
* @param $code a string of 0 and 1 ; $code == "000101" will return " | |"
|
|
|
|
*/
|
|
|
|
protected function get_indentation($code) {
|
2009-08-19 03:39:37 +00:00
|
|
|
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
|
|
|
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
$indent = '';
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
for ($i=0; $i<strlen($code); $i++) {
|
|
|
|
switch ($code[$i]) {
|
|
|
|
case '0':
|
|
|
|
$indent .= sprintf('<img align="top" border="0" class="imgs" src="%s/phplayersmenu/menuimages/tree_space.png" alt=" " />',JSDIR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '1':
|
|
|
|
$indent .= sprintf('<img align="top" border="0" class="imgs" src="%s/phplayersmenu/menuimages/tree_vertline.png" alt="| " />',JSDIR);
|
|
|
|
break;
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $indent;
|
|
|
|
}
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
/**
|
|
|
|
* Draw the javascript to support the tree.
|
|
|
|
*/
|
2009-06-30 10:46:00 +00:00
|
|
|
protected function draw_javascript() {
|
2009-08-19 03:39:37 +00:00
|
|
|
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
|
|
|
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
printf('<script type="text/javascript" language="javascript" src="%sphplayersmenu/libjs/layersmenu-browser_detection.js"></script>',JSDIR);
|
|
|
|
printf('<script type="text/javascript" language="javascript" src="%sajaxtree.js"></script>',JSDIR);
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
/**
|
|
|
|
* Draw the "Create New Entry" item before the children.
|
|
|
|
*/
|
|
|
|
private function create_before_child($entry,$level) {
|
2009-08-19 03:39:37 +00:00
|
|
|
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
|
|
|
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
if (strlen($level) == 0)
|
|
|
|
return '';
|
2009-06-30 10:46:00 +00:00
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
$server = $this->getServer();
|
2009-06-30 10:46:00 +00:00
|
|
|
$output = '';
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
if (! $server->isReadOnly() && ! $entry->isLeaf() && (count($entry->getChildren()) > 10) && $this->getServer()->isShowCreateEnabled()
|
|
|
|
&& $_SESSION[APPCONFIG]->getValue('appearance','show_top_create'))
|
|
|
|
$output = $this->draw_create_new_entry($entry,$level,JSDIR.'phplayersmenu/menuimages/tree_split.png');
|
2009-06-30 10:46:00 +00:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
/**
|
|
|
|
* Draw the "Create New Entry" item after the children.
|
|
|
|
*/
|
|
|
|
private function create_after_child($entry,$level) {
|
2009-08-19 03:39:37 +00:00
|
|
|
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
|
|
|
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
if (strlen($level) == 0)
|
|
|
|
return '';
|
2009-06-30 10:46:00 +00:00
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
$server = $this->getServer();
|
2009-06-30 10:46:00 +00:00
|
|
|
$output = '';
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
if (! $server->isReadOnly() && ! $entry->isLeaf() && $this->getServer()->isShowCreateEnabled())
|
|
|
|
$output = $this->draw_create_new_entry($entry,$level,JSDIR.'phplayersmenu/menuimages/tree_corner.png');
|
2009-06-30 10:46:00 +00:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
2009-07-01 06:09:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the "Create New Entry" item.
|
|
|
|
*/
|
|
|
|
private function draw_create_new_entry($entry,$level,$img) {
|
2009-08-19 03:39:37 +00:00
|
|
|
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
|
|
|
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
$output = '';
|
|
|
|
|
|
|
|
$href = sprintf('cmd=template_engine&server_id=%s&container=%s',$this->getServerID(),rawurlencode($entry->getDN()));
|
|
|
|
|
|
|
|
$output .= $this->get_indentation($level);
|
|
|
|
$output .= sprintf('<img align="top" border="0" class="imgs" src="%s" alt="--" />',$img);
|
|
|
|
$output .= sprintf('<a href="%s" title="%s">',htmlspecialchars($href),$entry->getDN());
|
2009-07-08 10:10:57 +00:00
|
|
|
$output .= sprintf('<img align="top" border="0" class="imgs" src="%s/create.png" alt="->" />',IMGDIR);
|
2009-07-01 06:09:17 +00:00
|
|
|
$output .= '</a>';
|
|
|
|
$output .= ' ';
|
|
|
|
|
|
|
|
if (isAjaxEnabled())
|
|
|
|
$output .= sprintf('<a href="cmd.php?%s" title="%s" class="phplm" onclick="return displayAJ(\'BODY\',\'%s\',\'%s\');">',
|
|
|
|
htmlspecialchars($href),_('Create new entry here'),
|
|
|
|
htmlspecialchars($href),_('Loading'));
|
|
|
|
else
|
|
|
|
$output .= sprintf('<a href="cmd.php?%s" title="%s" class="phplm">',htmlspecialchars($href),_('Create new entry here'));
|
|
|
|
|
|
|
|
$output .= _('Create new entry here');
|
|
|
|
$output .= '</a>';
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List the items in the tree that are open
|
|
|
|
*
|
|
|
|
* @return array List of open nodes
|
|
|
|
*/
|
|
|
|
public function listOpenItems() {
|
2009-08-19 03:39:37 +00:00
|
|
|
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
|
|
|
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach ($this->entries as $dn => $value)
|
|
|
|
if ($value->isOpened())
|
|
|
|
array_push($result,$value->getDN());
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
?>
|