Remove old PLA files that are no longer required.
This commit is contained in:
307
lib/AJAXTree.php
307
lib/AJAXTree.php
@@ -1,307 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Classes and functions for the LDAP tree.
|
||||
*
|
||||
* @author The phpLDAPadmin development team
|
||||
* @package phpLDAPadmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements an AJAX based tree.
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Tree
|
||||
* @see HTMLTree Tree
|
||||
*/
|
||||
class AJAXTree extends HTMLTree {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected function draw_item($item,$level,$first_child=true,$last_child=true) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
|
||||
# Level pre-treatment
|
||||
$code = '';
|
||||
if (is_string($level)) {
|
||||
for ($i=0; $i<strlen($level); $i++) {
|
||||
if ($level[$i] == '0')
|
||||
$code .= '0';
|
||||
elseif ($level[$i] == '1')
|
||||
$code .= '1';
|
||||
}
|
||||
|
||||
} elseif ($level > 0)
|
||||
$code = '0' * $level;
|
||||
|
||||
$level = strlen($code);
|
||||
|
||||
# Get entry to display as node
|
||||
$entry = $this->getEntry($item);
|
||||
|
||||
# If the entry doesnt exist, we'll add it.
|
||||
if (! $entry) {
|
||||
$this->addEntry($item);
|
||||
$entry = $this->getEntry($item);
|
||||
}
|
||||
|
||||
# If the entry doesnt exist in the server, then return here with an empty string.
|
||||
if (! $entry)
|
||||
return '';
|
||||
|
||||
# Get our children.
|
||||
$child_count = $this->readChildrenNumber($entry->getDN());
|
||||
|
||||
$nb = 0;
|
||||
if ($first_child)
|
||||
$nb += 1;
|
||||
if ($last_child)
|
||||
$nb += 2;
|
||||
|
||||
$imgs['expand'] = array('tree_expand.png','tree_expand.png','tree_expand_corner.png',
|
||||
($level > 0) ? 'tree_expand_corner.png' : 'tree_expand_corner_first.png');
|
||||
|
||||
$imgs['collapse'] = array('tree_collapse.png','tree_collapse.png','tree_collapse_corner.png',
|
||||
($level > 0) ? 'tree_collapse_corner.png' : 'tree_collapse_corner_first.png');
|
||||
|
||||
$imgs['tree'] = array('tree_split.png','tree_split.png','tree_corner.png','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
|
||||
$parms['openclose'] = htmlspecialchars(sprintf('server_id=%s&dn=%s&code=%s%s',$this->getServerID(),$entry->getDNEncode(),$code,$new_code[$nb]));
|
||||
$parms['edit'] = htmlspecialchars(sprintf('cmd=template_engine&server_id=%s&dn=%s',$this->getServerID(),$entry->getDNEncode()));
|
||||
$href = sprintf('cmd.php?%s',$parms['edit']);
|
||||
|
||||
# Each node has a unique id based on dn
|
||||
$node_id = sprintf('node%s',base64_encode(sprintf('%s-%s',$server->getIndex(),$entry->getDN())));
|
||||
$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);
|
||||
|
||||
echo $this->get_indentation($code);
|
||||
|
||||
if (! $child_count)
|
||||
printf('<img id="jt%snode" src="%s/%s" alt="--" class="imgs" style="border: 0px; vertical-align:text-top;" />',$node_id,IMGDIR,$imgs['tree'][$nb]);
|
||||
|
||||
else {
|
||||
printf('<a href="#" onclick="return opencloseTreeNode(\'%s\',\'%s\',\'%s\');">',$node_id,$parms['openclose'],IMGDIR);
|
||||
|
||||
if ($entry->isOpened())
|
||||
printf('<img id="jt%snode" src="%s/%s" alt="+-" class="imgs" style="border: 0px; vertical-align:text-top;" />',$node_id,IMGDIR,$imgs['collapse'][$nb]);
|
||||
else
|
||||
printf('<img id="jt%snode" src="%s/%s" alt="+-" class="imgs" style="border: 0px; vertical-align:text-top;" />',$node_id,IMGDIR,$imgs['expand'][$nb]);
|
||||
|
||||
echo '</a>';
|
||||
}
|
||||
|
||||
printf('<a href="%s" onclick="return ajDISPLAY(\'BODY\',\'%s\',\'%s\');" title="%s" >',$href,$parms['edit'],_('Retrieving DN'),htmlspecialchars($entry->getDN()));
|
||||
printf('<span class="dnicon"><img id="jt%sfolder" src="%s/%s" alt="->" class="imgs" style="border: 0px; vertical-align:text-top;" /></span>',$node_id,IMGDIR,$entry->getIcon($server));
|
||||
echo '</a>';
|
||||
|
||||
echo ' ';
|
||||
printf('<a href="%s" onclick="return ajDISPLAY(\'BODY\',\'%s\',\'%s\');" title="%s" class="phplm">',$href,$parms['edit'],_('Retrieving DN'),htmlspecialchars($entry->getDN()));
|
||||
echo $this->get_formatted_dn($entry,$level-1);
|
||||
echo ($child_count ? (sprintf(' (%s%s)',$child_count,($entry->isSizeLimited() ? '+' : ''))) : '');
|
||||
echo '</a>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
printf('<div id="jt%sson" style="display: %s" class="treemenudiv">',$node_id,($entry->isOpened() ? 'block' : 'none'));
|
||||
if ($entry->isOpened())
|
||||
$this->draw_children($entry,$code.$new_code[$nb]);
|
||||
|
||||
echo '</div>';
|
||||
|
||||
if ($level == 0)
|
||||
echo '</td></tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand and draw a child entry, when it is clicked on. This is using AJAX just to render this section of the tree.
|
||||
*/
|
||||
public function draw_children($parent_entry,$code) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$children = array();
|
||||
|
||||
foreach ($parent_entry->getChildren() as $child) {
|
||||
if (! $this->getEntry($child))
|
||||
$this->addEntry($child);
|
||||
|
||||
array_push($children,$this->getEntry($child));
|
||||
}
|
||||
|
||||
$first_child = $this->create_before_child($parent_entry,$code);
|
||||
$last_child = $this->create_after_child($parent_entry,$code);
|
||||
|
||||
# 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();
|
||||
|
||||
echo $first_child;
|
||||
|
||||
for ($i=0; $i<count($children); $i++) {
|
||||
$first = ($i == 0) && (! $first_child);
|
||||
$last = ($i == (count($children)-1)) && (! $last_child);
|
||||
|
||||
if (is_object($children[$i]))
|
||||
$this->draw_item($children[$i]->getDN(),$code,$first,$last);
|
||||
else
|
||||
echo '<br/>problem getting DN entry from ldap';
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
echo $last_child;
|
||||
|
||||
# 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the indentation before a node
|
||||
*
|
||||
* @param $code a string of 0 and 1 ; $code == "000101" will return " | |"
|
||||
*/
|
||||
protected function get_indentation($code) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$indent = '';
|
||||
|
||||
for ($i=0; $i<strlen($code); $i++) {
|
||||
switch ($code[$i]) {
|
||||
case '0':
|
||||
$indent .= sprintf('<img src="%s/tree_space.png" alt=" " class="imgs" style="border: 0px; vertical-align:text-top;" />',IMGDIR);
|
||||
break;
|
||||
|
||||
case '1':
|
||||
$indent .= sprintf('<img src="%s/tree_vertline.png" alt="| " class="imgs" style="border: 0px; vertical-align:text-top;" />',IMGDIR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $indent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the javascript to support the tree.
|
||||
*/
|
||||
protected function draw_javascript() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
parent::draw_javascript();
|
||||
printf('<script type="text/javascript" src="%slayersmenu-browser_detection.js"></script>',JSDIR);
|
||||
printf('<script type="text/javascript" src="%sajax_tree.js"></script>',JSDIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the "Create New Entry" item before the children.
|
||||
*/
|
||||
private function create_before_child($entry,$level) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (strlen($level) == 0)
|
||||
return '';
|
||||
|
||||
$server = $this->getServer();
|
||||
$output = '';
|
||||
|
||||
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,IMGDIR.'/tree_split.png');
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the "Create New Entry" item after the children.
|
||||
*/
|
||||
private function create_after_child($entry,$level) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (strlen($level) == 0)
|
||||
return '';
|
||||
|
||||
$server = $this->getServer();
|
||||
$output = '';
|
||||
|
||||
if (! $server->isReadOnly() && ! $entry->isLeaf() && $this->getServer()->isShowCreateEnabled())
|
||||
$output = $this->draw_create_new_entry($entry,$level,IMGDIR.'/tree_corner.png');
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the "Create New Entry" item.
|
||||
*/
|
||||
private function draw_create_new_entry($entry,$level,$img) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$output = '';
|
||||
|
||||
$href = sprintf('cmd=template_engine&server_id=%s&container=%s',$this->getServerID(),$entry->getDNEncode());
|
||||
|
||||
$output .= $this->get_indentation($level);
|
||||
$output .= sprintf('<img src="%s" alt="--" class="imgs" style="border: 0px; vertical-align:text-top;" />',$img);
|
||||
$output .= sprintf('<a href="%s" title="%s">',htmlspecialchars($href),$entry->getDN());
|
||||
$output .= sprintf('<img src="%s/create.png" alt="->" class="imgs" style="border: 0px; vertical-align:text-top;" />',IMGDIR);
|
||||
$output .= '</a>';
|
||||
$output .= ' ';
|
||||
|
||||
if (isAjaxEnabled())
|
||||
$output .= sprintf('<a href="cmd.php?%s" title="%s" class="phplm" onclick="return ajDISPLAY(\'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() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($this->entries as $dn => $value)
|
||||
if ($value->isOpened())
|
||||
array_push($result,$value->getDN());
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
588
lib/HTMLTree.php
588
lib/HTMLTree.php
@@ -1,588 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Classes and functions for the LDAP tree.
|
||||
*
|
||||
* @author The phpLDAPadmin development team
|
||||
* @package phpLDAPadmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements a straight HTML tree - no AJAX rendering is used.
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Tree
|
||||
* @see AJAXTree Tree
|
||||
*/
|
||||
class HTMLTree extends Tree {
|
||||
protected $javascript = '';
|
||||
|
||||
/**
|
||||
* Required ABSTRACT methods
|
||||
*/
|
||||
/**
|
||||
* Displays the tree in HTML
|
||||
*
|
||||
* @param boolean Only display the tree, or include the server name and menu items
|
||||
*/
|
||||
public function draw($onlytree=false) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
static $js_drawn = false;
|
||||
$server = $this->getServer();
|
||||
|
||||
echo '<table class="tree" border="0">';
|
||||
if (! $onlytree)
|
||||
$this->draw_server_name();
|
||||
|
||||
$this->javascript = '';
|
||||
$javascript_id = 0;
|
||||
|
||||
/* Do we have what it takes to authenticate here, or do we need to
|
||||
* present the user with a login link (for 'cookie' and 'session' auth_types)?
|
||||
*/
|
||||
if ($server->isLoggedIn(null)) {
|
||||
if (! $onlytree) {
|
||||
$this->draw_menu();
|
||||
|
||||
if (($server->getAuthType() != 'config') ||
|
||||
$server->getValue('appearance', 'show_authz'))
|
||||
$this->draw_logged_in_user();
|
||||
else
|
||||
printf('<tr><td class="blank" colspan="%s"> </td></tr>',$this->getDepth()+3);
|
||||
|
||||
if ($server->isReadOnly())
|
||||
printf('<tr><td class="spacer"></td><td class="logged_in" colspan="%s">(%s)</td></tr>',$this->getDepth()+3-1,_('read only'));
|
||||
else
|
||||
printf('<tr><td class="blank" colspan="%s"> </td></tr>',$this->getDepth()+3);
|
||||
|
||||
printf('<tr><td> </td><td><div style="overflow: auto; %s%s" id="ajSID_%s_nodes">',
|
||||
$_SESSION[APPCONFIG]->getValue('appearance','tree_width') ? sprintf('width: %spx; ',$_SESSION[APPCONFIG]->getValue('appearance','tree_width')) : '',
|
||||
$_SESSION[APPCONFIG]->getValue('appearance','tree_height') ? sprintf('height: %spx; ',$_SESSION[APPCONFIG]->getValue('appearance','tree_height')) : '',
|
||||
$server->getIndex());
|
||||
}
|
||||
|
||||
echo '<table class="tree" border="0">';
|
||||
|
||||
if (! count($this->getBaseEntries())) {
|
||||
# We didnt get any baseDN entries in our tree?
|
||||
printf('<tr><td class="spacer"></td><td class="spacer"></td><td colspan="%s"><small>%s<br />%s<br /><b>%s</b></small></td></tr>',
|
||||
$this->getDepth()+3-2,
|
||||
_('Could not determine the root of your LDAP tree.'),
|
||||
_('It appears that the LDAP server has been configured to not reveal its root.'),
|
||||
_('Please specify it in config.php'));
|
||||
|
||||
echo '</table>';
|
||||
|
||||
if (! $onlytree)
|
||||
echo '</div></td></tr>';
|
||||
|
||||
echo '</table>';
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the LDAP server is not yet initialized
|
||||
* (ie, the base DN configured in config.php does not exist)
|
||||
*/
|
||||
foreach ($this->getBaseEntries() as $base) {
|
||||
if (! $base->isInLDAP()) {
|
||||
$js_drawn = false;
|
||||
$javascript_id++;
|
||||
|
||||
$rdn = explode('=',get_rdn($base->getDN()));
|
||||
printf('<tr><td class="spacer"></td><td class="spacer"></td><td><img src="%s/unknown.png" alt="" /></td><td colspan="%s">%s</td></tr>',
|
||||
IMGDIR,$this->getDepth()+3-3,pretty_print_dn($base->getDN()));
|
||||
|
||||
$this->javascript .= sprintf('<form id="create_base_form_%s_%s" method="post" action="cmd.php">',$server->getIndex(),$javascript_id);
|
||||
$this->javascript .= '<div>';
|
||||
$this->javascript .= '<input type="hidden" name="cmd" value="template_engine" />';
|
||||
$this->javascript .= sprintf('<input type="hidden" name="server_id" value="%s" />',$server->getIndex());
|
||||
$this->javascript .= sprintf('<input type="hidden" name="container" value="%s" />',htmlspecialchars($server->getContainer($base->getDN())));
|
||||
$this->javascript .= sprintf('<input type="hidden" name="rdn" value="%s" />',get_rdn($base->getDN()));
|
||||
$this->javascript .= sprintf('<input type="hidden" name="rdn_attribute[]" value="%s" />',$rdn[0]);
|
||||
$this->javascript .= sprintf('<input type="hidden" name="new_values[%s][]" value="%s" />',$rdn[0],$rdn[1]);
|
||||
$this->javascript .= '<input type="hidden" name="template" value="none" />';
|
||||
$this->javascript .= '<input type="hidden" name="create_base" value="true" />';
|
||||
$this->javascript .= '</div>';
|
||||
$this->javascript .= sprintf('</form>');
|
||||
|
||||
if (preg_match('/,/',$base->getDN()))
|
||||
printf('<tr><td class="spacer"></td><td class="spacer"></td><td class="spacer"></td><td colspan="%s"><small>%s</small></td></tr>',
|
||||
$this->getDepth()+3-3,_('This base cannot be created with PLA.'));
|
||||
else
|
||||
printf('<tr><td class="spacer"></td><td class="spacer"></td><td class="spacer"></td><td colspan="%s"><small>%s <a href="javascript:document.getElementById(\'create_base_form_%s_%s\').submit()">%s</a></small></td></tr>',
|
||||
$this->getDepth()+3-3,_('This base entry does not exist.'),$server->getIndex(),$javascript_id,_('Create it?'));
|
||||
|
||||
} else {
|
||||
$this->draw_item($base->getDN(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
echo '</table>';
|
||||
|
||||
if (! $onlytree)
|
||||
echo '</div></td></tr>';
|
||||
|
||||
# We are not logged in, draw a login... link.
|
||||
} else {
|
||||
switch ($server->getAuthType()) {
|
||||
case 'cookie':
|
||||
case 'http':
|
||||
case 'session':
|
||||
$this->draw_login_link();
|
||||
break;
|
||||
|
||||
case 'config':
|
||||
case 'proxy':
|
||||
case 'sasl':
|
||||
break;
|
||||
|
||||
default:
|
||||
die(sprintf('Error: %s hasnt been configured for auth_type %s',__METHOD__,$server->getAuthType()));
|
||||
}
|
||||
}
|
||||
|
||||
# Tree Footer.
|
||||
echo '</table>';
|
||||
echo "\n\n";
|
||||
|
||||
if (! $js_drawn) {
|
||||
$this->draw_javascript();
|
||||
$js_drawn = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the server name
|
||||
*/
|
||||
protected function draw_server_name() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
|
||||
echo '<tr class="server">';
|
||||
printf('<td class="icon"><img src="%s/server.png" alt="%s" /></td>',IMGDIR,_('Server'));
|
||||
printf('<td class="name" colspan="%s">',$this->getDepth()+3-1);
|
||||
printf('%s',$server->getName());
|
||||
|
||||
if (! is_null($server->inactivityTime())) {
|
||||
$m = sprintf(_('Inactivity will log you off at %s'),
|
||||
strftime('%H:%M',$server->inactivityTime()));
|
||||
printf(' <img width="14" height="14" src="%s/timeout.png" title="%s" alt="%s"/>',IMGDIR,$m,'Timeout');
|
||||
}
|
||||
echo '</td></tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the tree menu options
|
||||
*/
|
||||
protected function draw_menu() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$links = '';
|
||||
|
||||
if (is_array($_SESSION[APPCONFIG]->getValue('menu','session')))
|
||||
foreach ($_SESSION[APPCONFIG]->getValue('menu','session') as $link => $title) {
|
||||
if ($this->get_menu_item($link))
|
||||
$links .= sprintf('<td class="server_links">%s</td>',$this->get_menu_item($link));
|
||||
}
|
||||
|
||||
# Finally add our logout link.
|
||||
$links .= sprintf('<td class="server_links">%s</td>',$this->get_logout_menu_item());
|
||||
|
||||
# Draw the quick-links below the server name:
|
||||
if ($links) {
|
||||
printf('<tr><td class="spacer"></td><td colspan="%s" class="links">',$this->getDepth()+3-1);
|
||||
printf('<table><tr>%s</tr></table>',$links);
|
||||
echo '</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML for each tree menu option
|
||||
*/
|
||||
protected function get_menu_item($item) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
$menu = array();
|
||||
|
||||
switch($item) {
|
||||
case 'schema':
|
||||
if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','schema'))
|
||||
return '';
|
||||
|
||||
$menu['cmd'] = 'schema';
|
||||
$menu['ajax'] = _('Loading Schema');
|
||||
$menu['div'] = 'BODY';
|
||||
$menu['title'] = _('View schema for');
|
||||
$menu['img'] = 'schema-big.png';
|
||||
$menu['name'] = _('schema');
|
||||
|
||||
break;
|
||||
|
||||
case 'search':
|
||||
if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','query_engine'))
|
||||
return '';
|
||||
|
||||
$menu['cmd'] = 'query_engine';
|
||||
$menu['ajax'] = _('Loading Search');
|
||||
$menu['div'] = 'BODY';
|
||||
$menu['title'] = _('Search');
|
||||
$menu['img'] = 'search-big.png';
|
||||
$menu['name'] = _('search');
|
||||
|
||||
break;
|
||||
|
||||
case 'refresh':
|
||||
if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','refresh'))
|
||||
return '';
|
||||
|
||||
$menu['cmd'] = 'refresh';
|
||||
$menu['href'] = '&noheader=1&purge=1';
|
||||
$menu['ajax'] = _('Refreshing Tree');
|
||||
$menu['div'] = sprintf('SID_%s_nodes',$server->getIndex());
|
||||
$menu['title'] = _('Refresh');
|
||||
$menu['img'] = 'refresh-big.png';
|
||||
$menu['name'] = _('refresh');
|
||||
|
||||
break;
|
||||
|
||||
case 'server_info':
|
||||
if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','server_info'))
|
||||
return '';
|
||||
|
||||
$menu['cmd'] = 'server_info';
|
||||
$menu['ajax'] = _('Loading Info');
|
||||
$menu['div'] = 'BODY';
|
||||
$menu['title'] = _('Info');
|
||||
$menu['img'] = 'info-big.png';
|
||||
$menu['name'] = _('info');
|
||||
|
||||
break;
|
||||
|
||||
case 'monitor':
|
||||
if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','monitor'))
|
||||
return '';
|
||||
|
||||
$attrs = $server->getRootDSE();
|
||||
if (! $attrs || ! isset($attrs['monitorcontext']))
|
||||
return '';
|
||||
|
||||
$menu['cmd'] = 'monitor';
|
||||
$menu['ajax'] = _('Loading Monitor Info');
|
||||
$menu['div'] = 'BODY';
|
||||
$menu['title'] = _('Monitor');
|
||||
$menu['img'] = 'monitorserver-big.png';
|
||||
$menu['name'] = _('monitor');
|
||||
|
||||
break;
|
||||
|
||||
case 'import':
|
||||
if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','import_form') || ! $_SESSION[APPCONFIG]->isCommandAvailable('script','import') || $server->isReadOnly())
|
||||
return '';
|
||||
|
||||
$menu['cmd'] = 'import_form';
|
||||
$menu['ajax'] = _('Loading Import');
|
||||
$menu['div'] = 'BODY';
|
||||
$menu['title'] = _('Import');
|
||||
$menu['img'] = 'import-big.png';
|
||||
$menu['name'] = _('import');
|
||||
|
||||
break;
|
||||
|
||||
case 'export':
|
||||
if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') || ! $_SESSION[APPCONFIG]->isCommandAvailable('script','export'))
|
||||
return '';
|
||||
|
||||
$menu['cmd'] = 'export_form';
|
||||
$menu['ajax'] = _('Loading Export');
|
||||
$menu['div'] = 'BODY';
|
||||
$menu['title'] = _('Export');
|
||||
$menu['img'] = 'export-big.png';
|
||||
$menu['name'] = _('export');
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
$href_parms = htmlspecialchars(sprintf('cmd=%s&server_id=%s%s',$menu['cmd'],$server->getIndex(),isset($menu['href']) ? $menu['href'] : ''));
|
||||
|
||||
if (isAjaxEnabled())
|
||||
return sprintf('<a href="cmd.php?%s" onclick="return ajDISPLAY(\'%s\',\'%s\',\'%s\');" title="%s %s"><img src="%s/%s" alt="%s" /><br />%s</a>',
|
||||
$href_parms,$menu['div'],$href_parms,$menu['ajax'],$menu['title'],$server->getName(),IMGDIR,$menu['img'],$menu['name'],$menu['name']);
|
||||
else
|
||||
return sprintf('<a href="cmd.php?%s" title="%s %s"><img src="%s/%s" alt="%s" /><br />%s</a>',
|
||||
$href_parms,$menu['title'],$server->getName(),IMGDIR,$menu['img'],$menu['name'],$menu['name']);
|
||||
}
|
||||
|
||||
protected function get_logout_menu_item() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
$href = sprintf('cmd.php?cmd=logout&server_id=%s',$server->getIndex());
|
||||
|
||||
if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','logout') || in_array($server->getAuthType(),array('config','http','proxy','sasl')))
|
||||
return '';
|
||||
else
|
||||
return sprintf('<a href="%s" title="%s"><img src="%s/%s" alt="%s" /><br />%s</a>',
|
||||
htmlspecialchars($href),_('Logout of this server'),IMGDIR,'logout-big.png',_('logout'),_('logout'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the Logged in User
|
||||
*/
|
||||
protected function draw_logged_in_user() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
|
||||
$logged_in_dn = $server->displayLogin(null);
|
||||
echo '<tr>';
|
||||
echo '<td class="spacer"></td>';
|
||||
printf('<td class="logged_in" colspan="%s">%s: ',$this->getDepth()+3-1,_('Logged in as'));
|
||||
|
||||
if ($server->getContainerTop($logged_in_dn) == $logged_in_dn) {
|
||||
$logged_in_branch = '';
|
||||
$logged_in_dn_array = array();
|
||||
|
||||
} else {
|
||||
$logged_in_branch = preg_replace('/,'.$server->getContainerTop($logged_in_dn).'$/','',$logged_in_dn);
|
||||
$logged_in_dn_array = pla_explode_dn($logged_in_branch);
|
||||
}
|
||||
|
||||
$bases = $server->getContainerTop($logged_in_dn);
|
||||
if (is_array($bases) && count($bases))
|
||||
array_push($logged_in_dn_array,$bases);
|
||||
|
||||
$rdn = $logged_in_dn;
|
||||
|
||||
# Some sanity checking here, in case our DN doesnt look like a DN
|
||||
if (! is_array($logged_in_dn_array))
|
||||
$logged_in_dn_array = array($logged_in_dn);
|
||||
|
||||
if (trim($logged_in_dn)) {
|
||||
if ($server->dnExists($logged_in_dn))
|
||||
foreach ($logged_in_dn_array as $rdn_piece) {
|
||||
$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),rawurlencode($rdn));
|
||||
printf('<a href="%s">%s</a>',htmlspecialchars($href),pretty_print_dn($rdn_piece));
|
||||
|
||||
if ($rdn_piece != end($logged_in_dn_array))
|
||||
echo ',';
|
||||
|
||||
$rdn = substr($rdn,(1 + strpos($rdn,',')));
|
||||
}
|
||||
|
||||
else
|
||||
echo $logged_in_dn;
|
||||
|
||||
} else {
|
||||
echo 'Anonymous';
|
||||
}
|
||||
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively descend on the given dn and draw the tree in html
|
||||
*
|
||||
* @param dn $dn Current dn.
|
||||
* @param int $level Level to start drawing (start to -1)
|
||||
*/
|
||||
protected function draw_item($item,$level) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
|
||||
# Get entry to display as node
|
||||
$entry = $this->getEntry($item);
|
||||
|
||||
# If the entry doesnt exist, we'll add it.
|
||||
if (! $entry) {
|
||||
$this->addEntry($item);
|
||||
$entry = $this->getEntry($item);
|
||||
}
|
||||
|
||||
# If the entry doesnt exist in the server, then return here with an empty string.
|
||||
if (! $entry)
|
||||
return;
|
||||
|
||||
# Get our children.
|
||||
$child_count = $this->readChildrenNumber($item);
|
||||
|
||||
$rdn = get_rdn($item);
|
||||
$dnENCODE = rawurlencode($item);
|
||||
$href['expand'] = htmlspecialchars(sprintf('cmd.php?cmd=expand&server_id=%s&dn=%s',$server->getIndex(),$dnENCODE));
|
||||
$href['collapse'] = htmlspecialchars(sprintf('cmd.php?cmd=collapse&server_id=%s&dn=%s',$server->getIndex(),$dnENCODE));
|
||||
$href['edit'] = htmlspecialchars(sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),$dnENCODE));
|
||||
|
||||
echo '<tr class="option">';
|
||||
printf('<td class="spacer" colspan="%s"></td>',$level+2);
|
||||
|
||||
# Is this node expanded? (deciding whether to draw "+" or "-")
|
||||
if ($entry->isOpened())
|
||||
if (! $child_count && ! $this->getServer()->isShowCreateEnabled())
|
||||
printf('<td class="expander"><img src="%s/minus.png" alt="-" /></td>',IMGDIR);
|
||||
else
|
||||
printf('<td class="expander"><a href="%s"><img src="%s/minus.png" alt="-" /></a></td>',$href['collapse'],IMGDIR);
|
||||
else
|
||||
if (($child_count !== false) && (! $child_count) && (! $this->getServer()->isShowCreateEnabled()))
|
||||
printf('<td class="expander"><img src="%s/minus.png" alt="-" /></td>',IMGDIR);
|
||||
else
|
||||
printf('<td class="expander"><a href="%s"><img src="%s/plus.png" alt="+" /></a></td>',$href['expand'],IMGDIR);
|
||||
|
||||
printf('<td class="icon"><a href="%s" id="node_%s_%s"><img src="%s/%s" alt="img" /></a></td>',
|
||||
$href['edit'],$server->getIndex(),preg_replace('/=/','_',base64_encode($item)),IMGDIR,$entry->getIcon());
|
||||
|
||||
printf('<td class="phplm" colspan="%s" style="width: 100%%;"><span style="white-space: nowrap;">',$this->getDepth()+3-$level);
|
||||
printf('<a href="%s">%s</a>',$href['edit'],$this->get_formatted_dn($entry,$level));
|
||||
|
||||
if ($child_count)
|
||||
printf(' <span class="count">(%s)</span>',$child_count);
|
||||
|
||||
echo '</span></td></tr>';
|
||||
|
||||
if ($entry->isOpened()) {
|
||||
/* Draw the "create new" link at the top of the tree list if there are more than 10
|
||||
* entries in the listing for this node.
|
||||
*/
|
||||
if (!$server->isReadOnly() && (count($entry->getChildren()) > 10)
|
||||
&& $this->getServer()->isShowCreateEnabled()) {
|
||||
|
||||
$this->draw_create_link($rdn,$level,$dnENCODE);
|
||||
}
|
||||
|
||||
foreach ($entry->getChildren() as $dnChildEntry)
|
||||
$this->draw_item($dnChildEntry,$level+1);
|
||||
|
||||
# Always draw the "create new" link at the bottom of the listing
|
||||
if (! $server->isReadOnly() && ! $entry->isLeaf() && $this->getServer()->isShowCreateEnabled()) {
|
||||
$this->draw_create_link($rdn,$level,$dnENCODE);
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Leaving (%s,%s)',33,0,__FILE__,__LINE__,__METHOD__,$item,$level);
|
||||
}
|
||||
|
||||
protected function get_formatted_dn($entry,$level) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if ($level < 0)
|
||||
return pretty_print_dn($entry->getDN());
|
||||
else
|
||||
return draw_formatted_dn($this->getServer(),$entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the HTML to show the "create new entry here".
|
||||
*
|
||||
* @param dn $rdn
|
||||
* @param int $level
|
||||
* @param dn $encoded_dn
|
||||
*/
|
||||
protected function draw_create_link($rdn,$level,$encoded_dn) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
# print the "Create New object" link.
|
||||
$href = htmlspecialchars(sprintf('cmd.php?cmd=template_engine&server_id=%s&container=%s',$this->getServerID(),$encoded_dn));
|
||||
|
||||
echo '<tr>';
|
||||
printf('<td class="spacer" colspan="%s"></td>',$level+3);
|
||||
printf('<td class="icon"><a href="%s"><img src="%s/create.png" alt="%s" /></a></td>',$href,IMGDIR,_('new'));
|
||||
printf('<td class="link" colspan="%s"><a href="%s" title="%s %s">%s</a></td>',
|
||||
$this->getDepth()+3-$level,$href,_('Create a new entry in'),$rdn,_('Create new entry here'));
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw login link
|
||||
*/
|
||||
protected function draw_login_link() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
$href_parm = htmlspecialchars(sprintf('cmd=%s&server_id=%s',get_custom_file($server->getIndex(),'login_form',''),$server->getIndex()));
|
||||
|
||||
echo '<tr class="option"><td class="spacer"></td>';
|
||||
|
||||
if (isAjaxEnabled()) {
|
||||
printf('<td class="icon"><a href="cmd.php?%s" onclick="return ajDISPLAY(\'BODY\',\'%s\',\'%s\');" title="%s %s"><img src="%s/%s" alt="%s" /></a></td>',
|
||||
$href_parm,$href_parm,_('Loading Login'),_('Login to'),$server->getName(),IMGDIR,'login.png',_('login'));
|
||||
printf('<td class="logged_in" colspan="%s"><a href="cmd.php?%s" onclick="return ajDISPLAY(\'BODY\',\'%s\',\'%s\');" title="%s %s">%s</a></td>',
|
||||
$this->getDepth()+3-2,$href_parm,$href_parm,_('Loading Login'),_('Login to'),$server->getName(),_('login'));
|
||||
|
||||
} else {
|
||||
printf('<td class="icon"><a href="cmd.php?%s"><img src="%s/%s" alt="%s" /></a></td>',$href_parm,IMGDIR,'login.png',_('login'));
|
||||
printf('<td class="logged_in" colspan="%s"><a href="cmd.php?%s">%s...</a></td>',$this->getDepth()+3-2,$href_parm,_('Login'));
|
||||
}
|
||||
|
||||
echo '</tr>';
|
||||
|
||||
printf('<tr><td class="blank" colspan="%s"> </td></tr>',$this->getDepth()+3);
|
||||
printf('<tr><td class="blank" colspan="%s"> </td></tr>',$this->getDepth()+3);
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is javascript, draw it
|
||||
*/
|
||||
protected function draw_javascript() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if ($this->javascript) {
|
||||
echo "<!-- Forms for javascript submit to call to create base_dns -->\n";
|
||||
echo $this->javascript;
|
||||
echo "<!-- The end of the forms for javascript submit to call to create base_dns -->\n";
|
||||
$this->javascript = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out how deep the "opened" tree is.
|
||||
*/
|
||||
public function getDepth() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
|
||||
# If we are not logged in
|
||||
if (! $server->isLoggedIn(null))
|
||||
return 0;
|
||||
|
||||
static $depths = array();
|
||||
|
||||
if (! isset($depths[$server->getIndex()])) {
|
||||
$max = 0; # BaseDN are open, so we start at 1.
|
||||
|
||||
foreach ($this->entries as $dn) {
|
||||
$basedepth = count(pla_explode_dn($server->getContainerPath($dn->getDN(),'/')));
|
||||
$depth = 0;
|
||||
|
||||
$depth = count(pla_explode_dn($dn->getDN()))+1-$basedepth;
|
||||
|
||||
if ($depth > $max)
|
||||
$max = $depth;
|
||||
}
|
||||
|
||||
$depths[$server->getIndex()] = $max;
|
||||
}
|
||||
|
||||
return $depths[$server->getIndex()];
|
||||
}
|
||||
}
|
||||
?>
|
351
lib/Tree.php
351
lib/Tree.php
@@ -1,351 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Classes and functions for the LDAP tree.
|
||||
*
|
||||
* @author The phpLDAPadmin development team
|
||||
* @package phpLDAPadmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class which represents the LDAP tree view ; the draw() method
|
||||
* must be implemented by subclasses
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Tree
|
||||
* @see HTMLTree AJAXTree
|
||||
*/
|
||||
abstract class Tree {
|
||||
# Server that this tree represents
|
||||
private $server_id = null;
|
||||
# List of entries in the tree view cache
|
||||
protected $entries = array();
|
||||
|
||||
/**
|
||||
* Displays the LDAP tree
|
||||
*/
|
||||
abstract public function draw();
|
||||
|
||||
protected function __construct($server_id) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->server_id = $server_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the tree - this is used when we call this class directly
|
||||
* Tree::getInstance($index)
|
||||
*
|
||||
* @return object Tree
|
||||
*/
|
||||
static public function getInstance($server_id) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$tree = get_cached_item($server_id,'tree');
|
||||
|
||||
if (! $tree) {
|
||||
$server = $_SESSION[APPCONFIG]->getServer($server_id);
|
||||
|
||||
if (! $server)
|
||||
return null;
|
||||
|
||||
$treeclass = $_SESSION[APPCONFIG]->getValue('appearance','tree');
|
||||
$tree = new $treeclass($server_id);
|
||||
|
||||
# If we are not logged in, just return the empty tree.
|
||||
if (is_null($server->getLogin(null)))
|
||||
return $tree;
|
||||
|
||||
foreach ($server->getBaseDN(null) as $base) {
|
||||
if ($base) {
|
||||
$tree->addEntry($base);
|
||||
|
||||
if ($server->getValue('appearance','open_tree')) {
|
||||
$baseEntry = $tree->getEntry($base);
|
||||
$baseEntry->open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_cached_item($server_id,'tree','null',$tree);
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server ID for this tree
|
||||
*
|
||||
* @return int Server ID that this tree is for
|
||||
*/
|
||||
protected function getServerID() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->server_id);
|
||||
|
||||
return $this->server_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server Object for this tree
|
||||
*
|
||||
* @return object Server Object for this tree
|
||||
*/
|
||||
protected function getServer() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
return $_SESSION[APPCONFIG]->getServer($this->server_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entries that are BaseDN entries.
|
||||
*
|
||||
* @return array Base DN entries
|
||||
*/
|
||||
public function getBaseEntries() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach ($this->entries as $details)
|
||||
if ($details->isBaseDN() AND ((! $this->getServer()->getValue('server','hide_noaccess_base')) OR $details->isInLdap()))
|
||||
array_push($return,$details);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will take the DN, convert it to lowercase and strip unnessary
|
||||
* commas. This result will be used as the index for the tree object.
|
||||
* Any display of a DN should use the object->dn entry, not the index.
|
||||
* The reason we need to do this is because:
|
||||
* uid=User A,ou=People,c=AU and
|
||||
* uid=User B, ou=PeOpLe, c=au
|
||||
* are infact in the same branch, but PLA will show them inconsistently.
|
||||
*
|
||||
* @param dn DN to clean
|
||||
* @return dn Lowercase clean DN
|
||||
*/
|
||||
private function indexDN($dn) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$index = strtolower(implode(',',pla_explode_dn($dn)));
|
||||
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Result (%s)',1,0,__FILE__,__LINE__,__METHOD__,$index);
|
||||
|
||||
return $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a tree entry
|
||||
*
|
||||
* @param dn DN to retrieve
|
||||
* @return object Tree DN object
|
||||
*/
|
||||
public function getEntry($dn) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$dnlower = $this->indexDN($dn);
|
||||
|
||||
if (isset($this->entries[$dnlower]))
|
||||
return $this->entries[$dnlower];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an entry in the tree view ; the entry is added in the
|
||||
* children array of its parent
|
||||
*
|
||||
* @param dn DN to add
|
||||
* @param string $dn the dn of the entry to create
|
||||
*/
|
||||
public function addEntry($dn) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
$dnlower = $this->indexDN($dn);
|
||||
|
||||
# @todo Temporarily removed, some non-ascii char DNs that do exist, fail here for some reason?
|
||||
#if (! ($server->dnExists($dn)))
|
||||
# return;
|
||||
|
||||
if (isset($this->entries[$dnlower]))
|
||||
debug_dump_backtrace('Calling add entry to an entry that ALREADY exists?',1);
|
||||
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('New ENTRY (%s).',64,0,__FILE__,__LINE__,__METHOD__,$dn);
|
||||
|
||||
$tree_factory = new TreeItem($server->getIndex(),$dn);
|
||||
$tree_factory->setObjectClasses($server->getDNAttrValue($dn,'objectClass'));
|
||||
|
||||
if ((($isleaf = $server->getDNAttrValue($dn,'hassubordinates')) && ! strcasecmp($isleaf[0],'false')))
|
||||
$tree_factory->setLeaf();
|
||||
|
||||
$this->entries[$dnlower] = $tree_factory;
|
||||
|
||||
# Is this entry in a base entry?
|
||||
if (in_array_ignore_case($dn,$server->getBaseDN(null))) {
|
||||
$this->entries[$dnlower]->setBase();
|
||||
|
||||
# If the parent entry is not in the tree, we add it. This routine will in itself
|
||||
# recall this method until we get to the top of the tree (the base).
|
||||
} else {
|
||||
$parent_dn = $server->getContainer($dn);
|
||||
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Parent DNs (%s)',64,0,__FILE__,__LINE__,__METHOD__,$parent_dn);
|
||||
|
||||
if ($parent_dn) {
|
||||
$parent_entry = $this->getEntry($parent_dn);
|
||||
|
||||
if (! $parent_entry) {
|
||||
$this->addEntry($parent_dn);
|
||||
$parent_entry = $this->getEntry($parent_dn);
|
||||
}
|
||||
|
||||
# Update this DN's parent's children list as well.
|
||||
$parent_entry->addChild($dn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an entry from the tree view ; the entry is deleted from the
|
||||
* children array of its parent
|
||||
*
|
||||
* @param dn DN to remote
|
||||
*/
|
||||
public function delEntry($dn) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
$dnlower = $this->indexDN($dn);
|
||||
|
||||
if (isset($this->entries[$dnlower]))
|
||||
unset($this->entries[$dnlower]);
|
||||
|
||||
# Delete entry from parent's children as well.
|
||||
$parent_dn = $server->getContainer($dn);
|
||||
$parent_entry = $this->getEntry($parent_dn);
|
||||
|
||||
if ($parent_entry)
|
||||
$parent_entry->delChild($dn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename an entry in the tree
|
||||
*
|
||||
* @param dn Old DN
|
||||
* @param dn New DN
|
||||
*/
|
||||
public function renameEntry($dnOLD,$dnNEW) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
$dnlowerOLD = $this->indexDN($dnOLD);
|
||||
$dnlowerNEW = $this->indexDN($dnNEW);
|
||||
|
||||
$this->entries[$dnlowerNEW] = $this->entries[$dnlowerOLD];
|
||||
if ($dnlowerOLD != $dnlowerNEW)
|
||||
unset($this->entries[$dnlowerOLD]);
|
||||
$this->entries[$dnlowerNEW]->rename($dnNEW);
|
||||
|
||||
# Update the parent's children
|
||||
$parentNEW = $server->getContainer($dnNEW);
|
||||
$parentOLD = $server->getContainer($dnOLD);
|
||||
|
||||
$parent_entry = $this->getEntry($parentNEW);
|
||||
if ($parent_entry)
|
||||
$parent_entry->addChild($dnNEW);
|
||||
|
||||
$parent_entry = $this->getEntry($parentOLD);
|
||||
if ($parent_entry)
|
||||
$parent_entry->delChild($dnOLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the children of a tree entry
|
||||
*
|
||||
* @param dn DN of the entry
|
||||
* @param boolean LDAP Size Limit
|
||||
*/
|
||||
public function readChildren($dn,$nolimit=false) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$server = $this->getServer();
|
||||
$dnlower = $this->indexDN($dn);
|
||||
|
||||
if (! isset($this->entries[$dnlower]))
|
||||
debug_dump_backtrace('Reading children on an entry that isnt set? '.$dnlower,true);
|
||||
|
||||
$ldap['child_limit'] = $nolimit ? 0 : $_SESSION[APPCONFIG]->getValue('search','size_limit');
|
||||
$ldap['filter'] = $_SESSION[APPCONFIG]->getValue('appearance','tree_filter');
|
||||
$ldap['deref'] = $_SESSION[APPCONFIG]->getValue('deref','tree');
|
||||
|
||||
# Perform the query to get the children.
|
||||
$ldap['children'] = $server->getContainerContents($dn,null,$ldap['child_limit'],$ldap['filter'],$ldap['deref']);
|
||||
|
||||
if (! count($ldap['children'])) {
|
||||
$this->entries[$dnlower]->unsetSizeLimited();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Children of (%s) are (%s)',64,0,__FILE__,__LINE__,__METHOD__,$dn,$ldap['children']);
|
||||
|
||||
# Relax our execution time, it might take some time to load this
|
||||
if ($nolimit)
|
||||
@set_time_limit($_SESSION[APPCONFIG]->getValue('search','time_limit'));
|
||||
|
||||
$this->entries[$dnlower]->readingChildren(true);
|
||||
|
||||
foreach ($ldap['children'] as $child) {
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Adding (%s)',64,0,__FILE__,__LINE__,__METHOD__,$child);
|
||||
|
||||
if (! in_array($child,$this->entries[$dnlower]->getChildren()))
|
||||
$this->entries[$dnlower]->addChild($child);
|
||||
}
|
||||
|
||||
$this->entries[$dnlower]->readingChildren(false);
|
||||
|
||||
if (count($this->entries[$dnlower]->getChildren()) == $ldap['child_limit'])
|
||||
$this->entries[$dnlower]->setSizeLimited();
|
||||
else
|
||||
$this->entries[$dnlower]->unsetSizeLimited();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of children an entry has. Optionally autoread the child entry.
|
||||
*
|
||||
* @param dn DN of the entry
|
||||
* @param boolean LDAP Size Limit
|
||||
*/
|
||||
protected function readChildrenNumber($dn,$nolimit=false) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$dnlower = $this->indexDN($dn);
|
||||
|
||||
if (! isset($this->entries[$dnlower]))
|
||||
debug_dump_backtrace('Reading children on an entry that isnt set?',true);
|
||||
|
||||
# Read the entry if we havent got it yet.
|
||||
if (! $this->entries[$dnlower]->isLeaf() && ! $this->entries[$dnlower]->getChildren())
|
||||
$this->readChildren($dn,$nolimit);
|
||||
|
||||
return count($this->entries[$dnlower]->getChildren());
|
||||
}
|
||||
}
|
||||
?>
|
312
lib/TreeItem.php
312
lib/TreeItem.php
@@ -1,312 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Classes and functions for the LDAP tree.
|
||||
*
|
||||
* @author The phpLDAPadmin development team
|
||||
* @package phpLDAPadmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents an item in the tree.
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Tree
|
||||
*/
|
||||
class TreeItem {
|
||||
# This entry's DN
|
||||
protected $dn;
|
||||
# The server this entry belongs to.
|
||||
private $server_id;
|
||||
# The objectclasses in LDAP, used to deterimine the icon and template
|
||||
protected $objectclasses = array();
|
||||
# Is this a base entry?
|
||||
private $base_entry = false;
|
||||
# Array of dn - the children
|
||||
private $children = array();
|
||||
# An icon file path
|
||||
protected $icon;
|
||||
# Is the entry a leaf?
|
||||
private $leaf = false;
|
||||
# Is the node open?
|
||||
private $open = false;
|
||||
# Is the size of children limited?
|
||||
private $size_limited = true;
|
||||
# Last template used to edit this entry
|
||||
private $template = null;
|
||||
# Do we need to sort the children
|
||||
private $childsort = true;
|
||||
# Are we reading the children
|
||||
private $reading_children = false;
|
||||
|
||||
public function __construct($server_id,$dn) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->server_id = $server_id;
|
||||
$this->dn = $dn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DN of this tree item.
|
||||
*
|
||||
* @return DN The DN of this item.
|
||||
*/
|
||||
public function getDN() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->dn);
|
||||
|
||||
return $this->dn;
|
||||
}
|
||||
|
||||
public function getDNEncode() {
|
||||
return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->dn));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the RDN of this tree items DN.
|
||||
*
|
||||
* @return RDN The RDN of this items DN.
|
||||
*/
|
||||
public function getRDN() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
return get_rdn($this->getDn(),0,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this item as a LDAP base DN item.
|
||||
*/
|
||||
public function setBase() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->base_entry = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if this item is a base DN item.
|
||||
*/
|
||||
public function isBaseDN() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->base_entry);
|
||||
|
||||
return $this->base_entry;
|
||||
}
|
||||
|
||||
public function setObjectClasses($oc) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->objectclasses = $oc;
|
||||
}
|
||||
|
||||
public function getObjectClasses() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->objectclasses);
|
||||
|
||||
return $this->objectclasses;
|
||||
}
|
||||
|
||||
public function isInLDAP() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
return count($this->objectclasses) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null if the children have never be defined
|
||||
* or an array of the dn of the children
|
||||
*/
|
||||
public function getChildren() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->children);
|
||||
|
||||
if ($this->childsort && ! $this->reading_children) {
|
||||
usort($this->children,'pla_compare_dns');
|
||||
$this->childsort = false;
|
||||
}
|
||||
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
public function readingChildren($bool) {
|
||||
$this->reading_children = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the children require resorting
|
||||
*/
|
||||
public function isChildSorted() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->childsort);
|
||||
|
||||
return $this->childsort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the children as sorted
|
||||
*/
|
||||
public function childSorted() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->childsort = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a child to this DN entry.
|
||||
*
|
||||
* @param DN The DN to add.
|
||||
*/
|
||||
public function addChild($dn) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (in_array($dn,$this->children))
|
||||
return;
|
||||
|
||||
array_push($this->children,$dn);
|
||||
$this->childsort = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a child from this DN entry.
|
||||
*
|
||||
* @param DN The DN to add.
|
||||
*/
|
||||
public function delChild($dn) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if ($this->children) {
|
||||
# If the parent hasnt been opened in the tree, then there wont be any children.
|
||||
$index = array_search($dn,$this->children);
|
||||
|
||||
if ($index !== false)
|
||||
unset($this->children[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this DN.
|
||||
*
|
||||
* @param DN The DN to rename to.
|
||||
*/
|
||||
public function rename($dn) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->dn = $dn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if this item has been opened.
|
||||
*/
|
||||
public function isOpened() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->open);
|
||||
|
||||
return $this->open;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this node as closed.
|
||||
*/
|
||||
public function close() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->open = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the node ; the children of the node must have been defined
|
||||
*/
|
||||
public function open() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->open = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this node as a leaf.
|
||||
*/
|
||||
public function setLeaf() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->leaf = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if this node is a leaf.
|
||||
*/
|
||||
public function isLeaf() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->leaf);
|
||||
|
||||
return $this->leaf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path of the icon file used to represent this node ;
|
||||
* If the icon hasnt been set, it will call get_icon()
|
||||
*/
|
||||
public function getIcon() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->icon);
|
||||
|
||||
if (! $this->icon)
|
||||
$this->icon = get_icon($this->server_id,$this->dn,$this->objectclasses);
|
||||
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this node as a size limited (it wont have all its children).
|
||||
*/
|
||||
public function setSizeLimited() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->size_limited = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the size limited flag.
|
||||
*/
|
||||
public function unsetSizeLimited() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->size_limited = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if this node has hit an LDAP size limit (and thus doesnt have all its children).
|
||||
*/
|
||||
public function isSizeLimited() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
return $this->size_limited;
|
||||
}
|
||||
|
||||
public function setTemplate($template) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
public function getTemplate() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
return $this->template;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Classes and functions for the template engines.
|
||||
*
|
||||
* @author The phpLDAPadmin development team
|
||||
* @package phpLDAPadmin
|
||||
*/
|
||||
|
||||
/**/
|
||||
# To make it easier to debug this script, define these constants, which will add some __METHOD__ location displays to the rendered text.
|
||||
define('DEBUGTMP',0);
|
||||
define('DEBUGTMPSUB',0);
|
||||
|
||||
/**
|
||||
* Abstract Visitor class
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Templates
|
||||
*/
|
||||
abstract class Visitor {
|
||||
# The server that was used to configure the templates
|
||||
protected $server_id;
|
||||
|
||||
public function __call($method,$args) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (! in_array($method,array('get','visit','draw')))
|
||||
debug_dump_backtrace(sprintf('Incorrect use of method loading [%s]',$method),1);
|
||||
|
||||
$methods = array();
|
||||
|
||||
$fnct = array_shift($args);
|
||||
|
||||
$object = $args[0];
|
||||
$class = get_class($object);
|
||||
|
||||
$call = "$method$fnct$class";
|
||||
|
||||
array_push($methods,$call);
|
||||
|
||||
while ($class && ! method_exists($this,$call)) {
|
||||
if (defined('DEBUGTMP') && DEBUGTMP)
|
||||
printf('<font size=-2><i>Class (%s): Method doesnt exist (%s,%s)</i></font><br />',$class,get_class($this),$call);
|
||||
|
||||
$class = get_parent_class($class);
|
||||
$call = "$method$fnct$class";
|
||||
array_push($methods,$call);
|
||||
}
|
||||
|
||||
if (defined('DEBUGTMP') && DEBUGTMP)
|
||||
printf('<font size=-2><i>Calling Methods: %s</i></font><br />',implode('|',$methods));
|
||||
|
||||
if (defined('DEBUGTMP') && DEBUGTMP && method_exists($this,$call))
|
||||
printf('<font size=-2>Method Exists: %s::%s (%s)</font><br />',get_class($this),$call,$args);
|
||||
|
||||
if (method_exists($this,$call)) {
|
||||
$r = call_user_func_array(array($this,$call),$args);
|
||||
|
||||
if (isset($r))
|
||||
return $r;
|
||||
else
|
||||
return;
|
||||
|
||||
} elseif (DEBUG_ENABLED) {
|
||||
debug_log('Doesnt exist param (%s,%s)',1,0,__FILE__,__LINE__,__METHOD__,$method,$fnct);
|
||||
}
|
||||
|
||||
printf('<font size=-2><i>NO Methods: %s</i></font><br />',implode('|',$methods));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the LDAP server ID
|
||||
*
|
||||
* @return int Server ID
|
||||
*/
|
||||
public function getServerID() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->server_id);
|
||||
|
||||
if (isset($this->server_id))
|
||||
return $this->server_id;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this LDAP Server object
|
||||
*
|
||||
* @return object DataStore Server
|
||||
*/
|
||||
protected function getServer() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
return $_SESSION[APPCONFIG]->getServer($this->getServerID());
|
||||
}
|
||||
}
|
||||
?>
|
519
lib/page.php
519
lib/page.php
@@ -1,519 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Page Rendering Functions
|
||||
*
|
||||
* @author The phpLDAPadmin development team
|
||||
* @package phpLDAPadmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class controls the final output to the browser.
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Page
|
||||
*/
|
||||
class page {
|
||||
# pre-HTML headers
|
||||
protected $_pageheader;
|
||||
|
||||
# Items to get into the <head>
|
||||
protected $_head;
|
||||
|
||||
# Settings for this application
|
||||
protected $_app;
|
||||
|
||||
# Default values array.
|
||||
protected $_default;
|
||||
|
||||
public function __construct($index=null) {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
# If we done have a configuration, then our IMGDIR and CSS are not defined
|
||||
if (! defined('IMGDIR'))
|
||||
define('IMGDIR','images/default');
|
||||
if (! defined('CSSDIR'))
|
||||
define('CSSDIR','css/default');
|
||||
|
||||
$this->index = $index;
|
||||
|
||||
# To be defined in a configuration file.
|
||||
$this->_app['title'] = app_name();
|
||||
$this->_app['logo'] = IMGDIR.'/logo-small.png';
|
||||
|
||||
if (! is_null($index))
|
||||
$this->_app['urlcss'] = sprintf('%s/%s',CSSDIR,$_SESSION[APPCONFIG]->getValue('appearance','stylesheet'));
|
||||
else
|
||||
$this->_app['urlcss'] = sprintf('%s/%s',CSSDIR,'style.css');
|
||||
|
||||
# Default Values for configurable items.
|
||||
$this->_default['sysmsg']['error'] = IMGDIR.'/error-big.png';
|
||||
$this->_default['sysmsg']['warn'] = IMGDIR.'/warn-big.png';
|
||||
$this->_default['sysmsg']['info'] = IMGDIR.'/info-big.png';
|
||||
|
||||
# Capture any output so far (in case we send some headers below) - there shouldnt be any output anyway.
|
||||
$preOutput = '';
|
||||
|
||||
# Try and work around if php compression is on, or the user has set compression in the config.
|
||||
# type = 1 for user gzip, 0 for php.ini gzip.
|
||||
$obStatus = ob_get_status();
|
||||
if (isset($obStatus['type']) && $obStatus['type'] && $obStatus['status']) {
|
||||
$preOutput = ob_get_contents();
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
header('Content-type: text/html; charset="UTF-8"');
|
||||
if (isCompress()) {
|
||||
header('Content-Encoding: gzip');
|
||||
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED)
|
||||
debug_log('Sent COMPRESSED header to browser and discarded (%s)',129,0,__FILE__,__LINE__,__METHOD__,$preOutput);
|
||||
}
|
||||
|
||||
if (isset($_SESSION[APPCONFIG])
|
||||
&& $_SESSION[APPCONFIG]->getValue('appearance','compress')
|
||||
&& ini_get('zlib.output_compression'))
|
||||
$this->setsysmsg(array('title'=>_('Warning'),'body'=>_('WARNING: You cannot have PHP compression and application compression enabled at the same time. Please unset zlib.output_compression or set $config->custom->appearance[\'compress\']=false'),'type'=>'warn'));
|
||||
|
||||
# Turn back on output buffering.
|
||||
ob_start();
|
||||
|
||||
# Initial Values
|
||||
$this->_pageheader[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
|
||||
$this->_pageheader[] .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="auto">'."\n";
|
||||
}
|
||||
|
||||
/* Add to the HTML Header */
|
||||
public function head_add($html) {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->_head[] .= $html;
|
||||
}
|
||||
|
||||
/* Print out the HTML header */
|
||||
private function pageheader_print() {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
# HTML prepage requirements.
|
||||
foreach ($this->_pageheader as $line)
|
||||
echo $line."\n";
|
||||
|
||||
# Page Title
|
||||
echo '<head>';
|
||||
printf('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
|
||||
|
||||
$DNs = get_request('dn','REQUEST');
|
||||
if (is_array($DNs))
|
||||
$DNs = '';
|
||||
|
||||
if (isset($_SESSION[APPCONFIG]))
|
||||
printf('<title>%s (%s) - %s%s</title>',
|
||||
$this->_app['title'],
|
||||
app_version(),
|
||||
$DNs ? htmlspecialchars($DNs).' ' : '',
|
||||
$_SESSION[APPCONFIG]->getValue('appearance','page_title'));
|
||||
else
|
||||
printf('<title>%s - %s</title>',$this->_app['title'],app_version());
|
||||
|
||||
echo '<link rel="shortcut icon" href="images/favicon.ico" type="image/vnd.microsoft.icon" />';
|
||||
# Style sheet.
|
||||
printf('<link type="text/css" rel="stylesheet" href="%s" />',$this->_app['urlcss']);
|
||||
|
||||
if (defined('JSDIR')) {
|
||||
printf('<link type="text/css" rel="stylesheet" media="all" href="%sjscalendar/calendar-blue.css" title="blue" />',JSDIR);
|
||||
echo "\n";
|
||||
printf('<script type="text/javascript" src="%sajax_functions.js"></script>',JSDIR);
|
||||
printf('<script type="text/javascript" src="%sjscalendar/calendar.js"></script>',JSDIR);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
# HTML head requirements.
|
||||
if (is_array($this->_head) && count($this->_head))
|
||||
foreach ($this->_head as $line)
|
||||
echo $line."\n";
|
||||
|
||||
echo '</head>';
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
private function head_print() {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (isset($_SESSION[APPCONFIG]))
|
||||
$pagetitle = $_SESSION[APPCONFIG]->getValue('appearance','page_title') ? ' - '.$_SESSION[APPCONFIG]->getValue('appearance','page_title') : '';
|
||||
else
|
||||
$pagetitle = '';
|
||||
|
||||
echo '<tr class="pagehead">';
|
||||
|
||||
echo '<td colspan="3"><div id="ajHEAD"><table width="100%" border="0"><tr>';
|
||||
printf('<td style="text-align: left;"><a href="%s" onclick="target=\'_blank\';"><img src="%s" alt="Logo" class="logo" /></a></td>',get_href('sf'),$this->_app['logo']);
|
||||
|
||||
echo '<td class="imagetop">';
|
||||
$empty = true;
|
||||
if (function_exists('cmd_control_pane'))
|
||||
foreach (cmd_control_pane('top') as $cmddetails)
|
||||
if ((isset($cmddetails['enable']) && $cmddetails['enable']) || ! isset($cmddetails['enable'])) {
|
||||
if (! $empty)
|
||||
echo ' ';
|
||||
|
||||
printf('<a %s>%s</a>',$cmddetails['link'],$cmddetails['image']);
|
||||
|
||||
$empty = false;
|
||||
}
|
||||
|
||||
if ($empty)
|
||||
echo ' ';
|
||||
|
||||
echo '</td>';
|
||||
echo '</tr></table></div></td>';
|
||||
echo '</tr>';
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
private function control_print() {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
echo '<table class="control" width="100%" border="0">';
|
||||
echo '<tr><td>';
|
||||
|
||||
$empty = true;
|
||||
if (function_exists('cmd_control_pane'))
|
||||
foreach (cmd_control_pane('main') as $cmddetails)
|
||||
if ((isset($cmddetails['enable']) && trim($cmddetails['enable'])) || ! isset($cmddetails['enable'])) {
|
||||
if (! $empty)
|
||||
echo ' | ';
|
||||
|
||||
printf('<a %s>%s</a>',$cmddetails['link'],
|
||||
(isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->getValue('appearance','control_icons')) ? $cmddetails['image'] : $cmddetails['title']);
|
||||
|
||||
$empty = false;
|
||||
}
|
||||
|
||||
echo '</td>';
|
||||
if ($empty)
|
||||
echo '<td> </td>';
|
||||
|
||||
echo '</tr>';
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
protected function tree() {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (! isset($_SESSION[APPCONFIG]))
|
||||
return;
|
||||
|
||||
if (is_null($this->index))
|
||||
$this->index = min(array_keys($_SESSION[APPCONFIG]->getServerList()));
|
||||
|
||||
if (count($_SESSION[APPCONFIG]->getServerList()) > 1) {
|
||||
echo '<form id="server_select" action="cmd.php" method="post">';
|
||||
echo '<table class="server_select"><tr><td>';
|
||||
printf('%s:<br />%s',_('Server Select'),
|
||||
server_select_list($this->index,false,'index',true,sprintf("onchange=\"tree_unhide('index',%s)\"",$this->index)));
|
||||
echo '</td></tr></table>';
|
||||
echo '</form>';
|
||||
echo "\n\n";
|
||||
}
|
||||
|
||||
foreach ($_SESSION[APPCONFIG]->getServerList() as $index => $server) {
|
||||
printf('<div id="ajSID_%s" style="display: %s">',$server->getIndex(),($server->getIndex() == $this->index) ? 'block' : 'none');
|
||||
$tree = Tree::getInstance($server->getIndex());
|
||||
$tree->draw();
|
||||
echo '</div>';
|
||||
echo "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function block_add($side,$object) {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (! is_object($object))
|
||||
error(sprintf('block_add called with [%s], but it is not an object',serialize($object)));
|
||||
|
||||
$this->_block[$side][] = $object;
|
||||
}
|
||||
|
||||
private function block_print($side) {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (! isset($this->_block[$side]))
|
||||
return;
|
||||
|
||||
printf('<td class="%s" colspan="2">',$side);
|
||||
foreach ($this->_block[$side] as $object)
|
||||
echo $object->draw($side);
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
private function sysmsg() {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (isset($this->sysmsg)) {
|
||||
foreach ($this->sysmsg as $index => $details) {
|
||||
switch ($details['type']) {
|
||||
case 'error':
|
||||
$icon = $this->_default['sysmsg']['error'];
|
||||
break;
|
||||
|
||||
case 'warn':
|
||||
$icon = $this->_default['sysmsg']['warn'];
|
||||
break;
|
||||
|
||||
case 'info':
|
||||
default:
|
||||
$icon = $this->_default['sysmsg']['info'];
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($details['title']))
|
||||
printf('<tr><td class="icon" rowspan="2"><img src="%s" alt="%s" /></td><td class="head">%s</td></tr>',
|
||||
$icon,$details['type'],$details['title']);
|
||||
|
||||
if (isset($details['body']))
|
||||
if (is_array($details['body'])) {
|
||||
echo '<tr><td class="body">';
|
||||
foreach ($details['body'] as $line)
|
||||
printf('%s<br />',$line);
|
||||
echo '</td></tr>';
|
||||
|
||||
} else
|
||||
printf('<tr><td class="body">%s</td></tr>',$details['body']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function body($raw=false) {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
# Add the Session System Messages
|
||||
if (isset($_SESSION['sysmsg']) && is_array($_SESSION['sysmsg'])) {
|
||||
foreach ($_SESSION['sysmsg'] as $msg)
|
||||
$this->setsysmsg($msg);
|
||||
|
||||
unset($_SESSION['sysmsg']);
|
||||
}
|
||||
|
||||
if (isset($this->sysmsg)) {
|
||||
echo '<table class="sysmsg">';
|
||||
$this->sysmsg();
|
||||
echo '</table>';
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
if (isset($this->_block['body']))
|
||||
foreach ($this->_block['body'] as $object)
|
||||
echo $object->draw('body',$raw);
|
||||
}
|
||||
|
||||
private function footer_print() {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
printf('<tr class="foot"><td><small>%s</small></td><td colspan="2"><div id="ajFOOT">%s</div>%s</td></tr>',
|
||||
isCompress() ? '[C]' : ' ',
|
||||
app_version(),
|
||||
' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Only show a particular page frame - used by an AJAX call
|
||||
*/
|
||||
public function show($frame,$compress=false,$raw=false) {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
# If the body is called via AJAX, and compression is enable, we need to compress the output
|
||||
if ($compress && ob_get_level() && isCompress()) {
|
||||
ob_end_clean();
|
||||
ob_start();
|
||||
}
|
||||
|
||||
switch ($frame) {
|
||||
case 'BODY':
|
||||
$this->body($raw);
|
||||
break;
|
||||
|
||||
case 'TREE':
|
||||
$this->tree();
|
||||
break;
|
||||
|
||||
default:
|
||||
error(sprintf('show called with unknown frame [%s]',$frame),'error','index.php');
|
||||
}
|
||||
|
||||
if ($compress && ob_get_level() && isCompress()) {
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED)
|
||||
debug_log('Sending COMPRESSED output to browser[(%s),%s]',129,0,__FILE__,__LINE__,__METHOD__,
|
||||
strlen($output),$output);
|
||||
|
||||
print gzencode($output);
|
||||
}
|
||||
}
|
||||
|
||||
public function display($filter=array()) {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
# Control what is displayed.
|
||||
$display = array(
|
||||
'HEAD'=>true,
|
||||
'CONTROL'=>true,
|
||||
'TREE'=>true,
|
||||
'FOOT'=>true
|
||||
);
|
||||
|
||||
if ($_SESSION[APPCONFIG]->getValue('appearance','minimalMode')) {
|
||||
$display = array(
|
||||
'HEAD'=>false,
|
||||
'CONTROL'=>false,
|
||||
'TREE'=>true,
|
||||
'FOOT'=>false
|
||||
);
|
||||
}
|
||||
|
||||
$display = array_merge($display,$filter);
|
||||
|
||||
# HTML Header
|
||||
$this->pageheader_print();
|
||||
|
||||
# Start of body
|
||||
# Page Header
|
||||
echo '<body>';
|
||||
echo "\n";
|
||||
echo '<table class="page" border="0" width="100%">';
|
||||
|
||||
if ($display['HEAD'])
|
||||
$this->head_print();
|
||||
|
||||
# Control Line
|
||||
if ($display['CONTROL']) {
|
||||
echo '<tr class="control"><td colspan="3">';
|
||||
echo '<div id="ajCONTROL">';
|
||||
$this->control_print();
|
||||
echo '</div></td></tr>';
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
# Left Block
|
||||
echo '<tr>';
|
||||
|
||||
if ($display['TREE']) {
|
||||
echo '<td class="tree" colspan="2">';
|
||||
printf('<acronym title="%s"><img src="%s/plus.png" alt="" style="float: right;" onclick="if (document.getElementById(\'ajTREE\').style.display == \'none\') { document.getElementById(\'ajTREE\').style.display = \'block\' } else { document.getElementById(\'ajTREE\').style.display = \'none\' };"/></acronym>',_('Hide/Unhide the tree'),IMGDIR);
|
||||
echo '<div id="ajTREE">';
|
||||
$this->tree();
|
||||
echo '</div>';
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
echo '<td class="body" style="width: 80%;">';
|
||||
echo '<div id="ajBODY">';
|
||||
echo "\n";
|
||||
$this->body();
|
||||
echo '</div>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo "\n";
|
||||
|
||||
# Page Footer
|
||||
if ($display['FOOT'])
|
||||
$this->footer_print();
|
||||
|
||||
# Finish HTML
|
||||
echo '</table>';
|
||||
echo '</body>';
|
||||
echo '</html>';
|
||||
|
||||
# compress output
|
||||
if (ob_get_level() && isCompress()) {
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED)
|
||||
debug_log('Sending COMPRESSED output to browser[(%s),%s]',129,0,__FILE__,__LINE__,__METHOD__,
|
||||
strlen($output),$output);
|
||||
|
||||
print gzencode($output);
|
||||
}
|
||||
}
|
||||
|
||||
public function setsysmsg($data) {
|
||||
if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (! is_array($data))
|
||||
return;
|
||||
|
||||
if (isset($this->sysmsg))
|
||||
$msgnum = count($this->sysmsg) + 1;
|
||||
else
|
||||
$msgnum = 1;
|
||||
|
||||
foreach (array('title','body','type') as $index)
|
||||
if (isset($data[$index]))
|
||||
$this->sysmsg[$msgnum][$index] = $data[$index];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class draws a block.
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Page
|
||||
*/
|
||||
class block {
|
||||
private $title;
|
||||
private $body;
|
||||
private $foot;
|
||||
|
||||
public function setTitle($html) {
|
||||
$this->title = $html;
|
||||
}
|
||||
|
||||
public function setBody($html) {
|
||||
$this->body = $html;
|
||||
}
|
||||
|
||||
public function setFooter($html) {
|
||||
$this->foot = $html;
|
||||
}
|
||||
|
||||
public function draw($side,$raw=false) {
|
||||
$output = '';
|
||||
|
||||
if ($raw)
|
||||
$output .= $this->body;
|
||||
|
||||
else {
|
||||
$output .= sprintf('<table class="%s">',$side);
|
||||
|
||||
if (isset($this->title))
|
||||
$output .= sprintf('<tr><td class="head">%s</td></tr>',$this->title);
|
||||
|
||||
if (isset($this->body))
|
||||
$output .= sprintf('<tr><td>%s</td></tr>',$this->body);
|
||||
|
||||
if (isset($this->footer))
|
||||
$output .= sprintf('<tr><td class="foot">%s</td></tr>',$this->foot);
|
||||
|
||||
$output .= '</table>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,144 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Classes and functions for manipulating XML templates.
|
||||
*
|
||||
* @author The phpLDAPadmin development team
|
||||
* @package phpLDAPadmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* XML Parser
|
||||
*
|
||||
* This will read our XML file and convert it into variables for us to parse.
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage XML
|
||||
*/
|
||||
class xml2array {
|
||||
var $stack = array();
|
||||
var $stack_ref;
|
||||
var $arrOutput = array();
|
||||
var $resParser;
|
||||
var $strXmlData;
|
||||
|
||||
private function push_pos(&$pos) {
|
||||
$this->stack[count($this->stack)] = &$pos;
|
||||
$this->stack_ref = &$pos;
|
||||
}
|
||||
|
||||
private function pop_pos() {
|
||||
unset($this->stack[count($this->stack) - 1]);
|
||||
$this->stack_ref = &$this->stack[count($this->stack) - 1];
|
||||
}
|
||||
|
||||
public function parseXML($strInputXML,$filename) {
|
||||
$this->resParser = xml_parser_create();
|
||||
xml_set_object($this->resParser,$this);
|
||||
xml_set_element_handler($this->resParser,'tagOpen','tagClosed');
|
||||
|
||||
xml_set_character_data_handler($this->resParser,'tagData');
|
||||
|
||||
$this->push_pos($this->arrOutput);
|
||||
|
||||
$this->strXmlData = xml_parse($this->resParser,$strInputXML);
|
||||
|
||||
if (! $this->strXmlData)
|
||||
die(sprintf('XML error: %s at line %d in file %s',
|
||||
xml_error_string(xml_get_error_code($this->resParser)),
|
||||
xml_get_current_line_number($this->resParser),
|
||||
$filename));
|
||||
|
||||
xml_parser_free($this->resParser);
|
||||
|
||||
$output = array();
|
||||
foreach ($this->arrOutput as $key => $values)
|
||||
$output[$key] = $this->cleanXML($values);
|
||||
|
||||
#return $this->arrOutput;
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function tagOpen($parser,$name,$attrs) {
|
||||
$name = strtolower($name);
|
||||
|
||||
if (isset($this->stack_ref[$name])) {
|
||||
if (! isset($this->stack_ref[$name][0])) {
|
||||
$tmp = $this->stack_ref[$name];
|
||||
unset($this->stack_ref[$name]);
|
||||
$this->stack_ref[$name][0] = $tmp;
|
||||
}
|
||||
|
||||
$cnt = count($this->stack_ref[$name]);
|
||||
$this->stack_ref[$name][$cnt] = array();
|
||||
if (isset($attrs))
|
||||
$this->stack_ref[$name][$cnt] = $attrs;
|
||||
|
||||
$this->push_pos($this->stack_ref[$name][$cnt]);
|
||||
|
||||
} else {
|
||||
$this->stack_ref[$name]=array();
|
||||
|
||||
if (isset($attrs))
|
||||
$this->stack_ref[$name]=$attrs;
|
||||
|
||||
$this->push_pos($this->stack_ref[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
private function tagData($parser,$tagData) {
|
||||
if (trim($tagData) != '') {
|
||||
|
||||
if (isset($this->stack_ref['#text']))
|
||||
$this->stack_ref['#text'] .= $tagData;
|
||||
else
|
||||
$this->stack_ref['#text'] = $tagData;
|
||||
}
|
||||
}
|
||||
|
||||
private function tagClosed($parser,$name) {
|
||||
$this->pop_pos();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will parse an XML array and make a normal array.
|
||||
*
|
||||
* @return array - Clean XML data
|
||||
*/
|
||||
private function cleanXML($details) {
|
||||
# Quick processing for the final branch of the XML array.
|
||||
if (is_array($details) && isset($details['#text']))
|
||||
return $details['#text'];
|
||||
|
||||
elseif (is_array($details) && isset($details['ID']) && count($details) == 1)
|
||||
return $details['ID'];
|
||||
|
||||
$cleanXML = array();
|
||||
|
||||
# Quick processing for the final branch, when it holds the ID and values.
|
||||
if (is_array($details) && isset($details['ID']) && count($details) > 1) {
|
||||
$key = $details['ID'];
|
||||
unset($details['ID']);
|
||||
$cleanXML[$key] = $this->cleanXML($details);
|
||||
$details = array();
|
||||
}
|
||||
|
||||
# More detailed processing...
|
||||
if (is_array($details))
|
||||
foreach ($details as $key => $values)
|
||||
if (is_numeric($key) && isset($values['ID']) && count($values) > 1) {
|
||||
$key = $values['ID'];
|
||||
unset($values['ID']);
|
||||
$cleanXML[$key] = $this->cleanXML($values);
|
||||
|
||||
} elseif (isset($values['#text']))
|
||||
$cleanXML[$key] = $this->cleanXML($values);
|
||||
|
||||
elseif (is_array($values))
|
||||
$cleanXML[$key] = $this->cleanXML($values);
|
||||
|
||||
if (! $cleanXML)
|
||||
return $details;
|
||||
else
|
||||
return $cleanXML;
|
||||
}
|
||||
}
|
@@ -1,496 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Classes and functions for XML based templates.
|
||||
*
|
||||
* @author The phpLDAPadmin development team
|
||||
* @package phpLDAPadmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* XML Templates Class
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Templates
|
||||
*/
|
||||
abstract class xmlTemplates {
|
||||
# The server ID that these templates are configured for.
|
||||
protected $server_id;
|
||||
# Our array of the available templates.
|
||||
protected $templates = array();
|
||||
|
||||
function __construct($server_id) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->server_id = $server_id;
|
||||
$server = $_SESSION[APPCONFIG]->getServer($this->server_id);
|
||||
$custom_prefix = $server->getValue('custom','pages_prefix');
|
||||
$class = $this->getClassVars();
|
||||
$changed = false;
|
||||
|
||||
# Try to get the templates from our CACHE.
|
||||
if ($this->templates = get_cached_item($server_id,$class['item'])) {
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Using CACHED templates',4,0,__FILE__,__LINE__,__METHOD__);
|
||||
|
||||
# See if the template_time has expired to see if we should reload the templates.
|
||||
foreach ($this->templates as $index => $template) {
|
||||
# If the file no longer exists, we'll delete the template.
|
||||
if (! file_exists($template->getFileName())) {
|
||||
unset($this->templates[$index]);
|
||||
$changed = true;
|
||||
|
||||
system_message(array(
|
||||
'title'=>_('Template XML file removed.'),
|
||||
'body'=>sprintf('%s %s (%s)',_('Template XML file has removed'),$template->getName(false),$template->getType()),
|
||||
'type'=>'info','special'=>true));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($template->getReadTime() < (time()-$class['cachetime']))
|
||||
&& (filectime($template->getFileName()) > $template->getReadTime())) {
|
||||
|
||||
system_message(array(
|
||||
'title'=>_('Template XML file changed.'),
|
||||
'body'=>sprintf('%s %s (%s)',_('Template XML file has changed and been reread'),$template->getName(false),$template->getType()),
|
||||
'type'=>'info','special'=>true));
|
||||
|
||||
$changed = true;
|
||||
$this->templates[$index] = new $class['name']($this->server_id,$template->getName(false),$template->getFileName(),$template->getType(),$index);
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Templates refreshed',4,0,__FILE__,__LINE__,__METHOD__);
|
||||
|
||||
# See if there are any new template files
|
||||
$index = max(array_keys($this->templates))+1;
|
||||
foreach ($class['types'] as $type) {
|
||||
$dir = $class['dir'].$type;
|
||||
$dh = opendir($dir);
|
||||
if (! $type)
|
||||
$type = 'template';
|
||||
|
||||
while ($file = readdir($dh)) {
|
||||
# Ignore any files that are not XML files.
|
||||
if (! preg_match('/.xml$/',$file))
|
||||
continue;
|
||||
|
||||
# Ignore any files that are not the predefined custom files.
|
||||
if ($_SESSION[APPCONFIG]->getValue('appearance','custom_templates_only')
|
||||
&& ! preg_match("/^${custom_prefix}/",$file))
|
||||
continue;
|
||||
|
||||
$filename = sprintf('%s/%s',$dir,$file);
|
||||
|
||||
if (! in_array($filename,$this->getTemplateFiles())) {
|
||||
$templatename = preg_replace('/.xml$/','',$file);
|
||||
|
||||
$this->templates[$index] = new $class['name']($this->server_id,$templatename,$filename,$type,$index);
|
||||
$index++;
|
||||
|
||||
$changed = true;
|
||||
|
||||
system_message(array(
|
||||
'title'=>_('New Template XML found.'),
|
||||
'body'=>sprintf('%s %s (%s)',_('A new template XML file has been loaded'),$file,$type),
|
||||
'type'=>'info','special'=>true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Parsing templates',4,0,__FILE__,__LINE__,__METHOD__);
|
||||
|
||||
# Need to reset this, as get_cached_item() returns null if nothing cached.
|
||||
$this->templates = array();
|
||||
$changed = true;
|
||||
|
||||
$counter = 0;
|
||||
foreach ($class['types'] as $type) {
|
||||
$dir = $class['dir'].$type;
|
||||
$dh = opendir($class['dir'].$type);
|
||||
if (! $type)
|
||||
$type = 'template';
|
||||
|
||||
while ($file = readdir($dh)) {
|
||||
# Ignore any files that are not XML files.
|
||||
if (! preg_match('/.xml$/',$file))
|
||||
continue;
|
||||
|
||||
# Ignore any files that are not the predefined custom files.
|
||||
if ($_SESSION[APPCONFIG]->getValue('appearance','custom_templates_only')
|
||||
&& ! preg_match("/^${custom_prefix}/",$file))
|
||||
continue;
|
||||
|
||||
$filename = sprintf('%s/%s',$dir,$file);
|
||||
|
||||
# Store the template
|
||||
$templatename = preg_replace('/.xml$/','',$file);
|
||||
$this->templates[$counter] = new $class['name']($this->server_id,$templatename,$filename,$type,$counter);
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Templates loaded',4,0,__FILE__,__LINE__,__METHOD__);
|
||||
|
||||
if ($changed) {
|
||||
masort($this->templates,'title');
|
||||
set_cached_item($server_id,$class['item'],'null',$this->templates);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This will return our custom class variables, used by the parent to create objects.
|
||||
*/
|
||||
private function getClassVars() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$class = array();
|
||||
|
||||
switch (get_class($this)) {
|
||||
case 'Queries':
|
||||
$class['item'] = 'query';
|
||||
$class['name'] = 'Query';
|
||||
$class['cachetime'] = $_SESSION[APPCONFIG]->getValue('cache','query_time');
|
||||
$class['types'] = array('');
|
||||
$class['dir'] = QUERYDIR;
|
||||
|
||||
break;
|
||||
|
||||
case 'Templates':
|
||||
$class['item'] = 'template';
|
||||
$class['name'] = 'Template';
|
||||
$class['cachetime'] = $_SESSION[APPCONFIG]->getValue('cache','template_time');
|
||||
$class['types'] = array('creation','modification');
|
||||
$class['dir'] = TMPLDIR;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
debug_dump_backtrace(sprintf('Unknown class %s',get_class($this)),1);
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of templates by their type
|
||||
* This function should return a sorted list, as the array is built sorted.
|
||||
*
|
||||
* @param string Type of template, eg: creation, modification
|
||||
* @param boolean Exclude templates purposely disabled.
|
||||
* @return array List of templates of the type
|
||||
*/
|
||||
public function getTemplates($type=null,$container=null,$disabled=false) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$result = array();
|
||||
|
||||
if (is_array($this->templates))
|
||||
foreach ($this->templates as $details) {
|
||||
|
||||
# Clone this, as we'll disable some templates, as a result of the container being requested.
|
||||
$template = clone $details;
|
||||
if (! is_null($container) && ($regexp = $template->getRegExp()) && (! @preg_match('/'.$regexp.'/i',$container))) {
|
||||
$template->setInvalid(_('This template is not valid in this container'),true);
|
||||
|
||||
if ($_SESSION[APPCONFIG]->getValue('appearance','hide_template_regexp'))
|
||||
$template->setInvisible();
|
||||
}
|
||||
|
||||
if ($template->isVisible() && (! $disabled || ! $template->isAdminDisabled()))
|
||||
if (is_null($type) || (! is_null($type) && $template->isType($type)))
|
||||
array_push($result,$template);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a template by its ID
|
||||
*
|
||||
* @param string The template ID as it was when it was generated (normally used in $_REQUEST vars).
|
||||
* @return object Template (or default template if the ID doesnt exist)
|
||||
*/
|
||||
function getTemplate($templateid) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$class = $this->getClassVars();
|
||||
|
||||
foreach ($this->templates as $template)
|
||||
if ($template->getID() === $templateid)
|
||||
return clone $template;
|
||||
|
||||
# If we get here, the template ID didnt exist, so return a blank template, which be interpreted as the default template
|
||||
$object = new $class['name']($this->server_id,null,null,'default');
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of template filenames.
|
||||
*/
|
||||
private function getTemplateFiles() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($this->templates as $template)
|
||||
array_push($result,$template->getFileName());
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* XML Template Class
|
||||
*
|
||||
* @package phpLDAPadmin
|
||||
* @subpackage Templates
|
||||
*/
|
||||
abstract class xmlTemplate {
|
||||
# Server ID that the template is linked to
|
||||
protected $server_id;
|
||||
# Template unique ID
|
||||
protected $id;
|
||||
# Template name - as extracted from the filename
|
||||
protected $name;
|
||||
# Template type - creation/modification
|
||||
protected $type;
|
||||
# Time this object was created
|
||||
protected $readtime;
|
||||
# Template file name
|
||||
protected $filename;
|
||||
# The TEMPLATE attributes as per the template definition, or the DN entry
|
||||
protected $attributes = array();
|
||||
|
||||
public function __construct($server_id,$name=null,$filename=null,$type=null,$id=null) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$this->server_id = $server_id;
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->filename = $filename;
|
||||
$this->readtime = time();
|
||||
$this->id = $id;
|
||||
|
||||
# If there is no filename, then this template is a default template.
|
||||
if (is_null($filename))
|
||||
return;
|
||||
|
||||
# If we have a filename, parse the template file and build the object.
|
||||
$objXML = new xml2array();
|
||||
$xmldata = $objXML->parseXML(file_get_contents($filename),$filename);
|
||||
$this->storeTemplate($xmldata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an attribute ID
|
||||
*
|
||||
* @param string The Attribute being searched.
|
||||
* @return int Attribute ID in the array
|
||||
*/
|
||||
protected function getAttrID($attr) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
foreach ($this->attributes as $index => $attribute)
|
||||
if (strtolower($attr) == $attribute->getName() || in_array(strtolower($attr),$attribute->getAliases()))
|
||||
return $index;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Template filename.
|
||||
*/
|
||||
public function getFileName() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->filename);
|
||||
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the template by ID
|
||||
*/
|
||||
public function getID() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->id);
|
||||
|
||||
if ($this->name)
|
||||
return sprintf('%s:%s',$this->getName(false),$this->id);
|
||||
else
|
||||
return 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the template name
|
||||
*
|
||||
* @param boolean Force the name to be lowercase (default)
|
||||
*/
|
||||
public function getName($lower=true) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->name);
|
||||
|
||||
if ($lower)
|
||||
return strtolower($this->name);
|
||||
else
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Template read time.
|
||||
*/
|
||||
public function getReadTime() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->readtime);
|
||||
|
||||
return $this->readtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this LDAP Server object
|
||||
*
|
||||
* @return object DataStore Server
|
||||
*/
|
||||
protected function getServer() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
return $_SESSION[APPCONFIG]->getServer($this->getServerID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the LDAP server ID
|
||||
*
|
||||
* @return int Server ID
|
||||
*/
|
||||
protected function getServerID() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->server_id);
|
||||
|
||||
return $this->server_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a template is of a type
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isType($type) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->type);
|
||||
|
||||
if ($this->type == $type)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the template type
|
||||
*/
|
||||
public function getType() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->type);
|
||||
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template title
|
||||
*/
|
||||
public function getTitle() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (! isset($this->title) && ! isset($this->description))
|
||||
return '';
|
||||
|
||||
return isset($this->title) ? $this->title : $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add another attribute to this template
|
||||
*
|
||||
* @return int Attribute ID
|
||||
*/
|
||||
public function addAttribute($name,$value,$source=null) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
if (! is_array($value))
|
||||
debug_dump_backtrace('Value should be an array()',1);
|
||||
|
||||
$server = $this->getServer();
|
||||
|
||||
# Initialise the Attribute Factory.
|
||||
$attribute_factory = new AttributeFactory();
|
||||
|
||||
if (preg_match('/;/',$name))
|
||||
system_message(array(
|
||||
'title'=>'phpLDAPadmin doesnt support RFC3866.',
|
||||
'body'=>sprintf('%s {%s} (%s)','PLA might not do what you expect...',$name,(is_array($value) ? serialize($value) : $value)),
|
||||
'type'=>'warn'));
|
||||
|
||||
# If there isnt a schema item for this attribute
|
||||
$attribute = $attribute_factory->newAttribute($name,$value,$server->getIndex(),$source);
|
||||
|
||||
$attrid = $this->getAttrID($attribute->getName());
|
||||
|
||||
if (is_null($attrid))
|
||||
array_push($this->attributes,$attribute);
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attribute names
|
||||
*
|
||||
* @return array Array of attributes Names
|
||||
*/
|
||||
public function getAttributeNames() {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($this->attributes as $attribute)
|
||||
array_push($result,$attribute->getName());
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific Attribute
|
||||
*
|
||||
* @param string Name of attribute to retrieve
|
||||
* @return object Attribute
|
||||
*/
|
||||
public function getAttribute($name) {
|
||||
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
|
||||
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
|
||||
|
||||
foreach ($this->attributes as $attribute)
|
||||
if (($attribute->getName() == strtolower($name)) || in_array(strtolower($name),$attribute->getAliases()))
|
||||
return $attribute;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* May be overloaded in other classes
|
||||
*/
|
||||
public function isAdminDisabled() {}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user