Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / phpmyadmin / libraries / navigation / NavigationTree.class.php
blobd92c694f82a1b28198019d05eec4023d4a7fe78d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Functionality for the navigation tree
6 * @package PhpMyAdmin-Navigation
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Displays a collapsible of database objects in the navigation frame
15 * @package PhpMyAdmin-Navigation
17 class PMA_NavigationTree
19 /**
20 * @var Node Reference to the root node of the tree
22 private $_tree;
24 /**
25 * @var array The actual paths to all expanded nodes in the tree
26 * This does not include nodes created after the grouping
27 * of nodes has been performed
29 private $_aPath = array();
31 /**
32 * @var array The virtual paths to all expanded nodes in the tree
33 * This includes nodes created after the grouping of
34 * nodes has been performed
36 private $_vPath = array();
38 /**
39 * @var int Position in the list of databases,
40 * used for pagination
42 private $_pos;
44 /**
45 * @var int The names of the type of items that are being paginated on
46 * the second level of the navigation tree. These may be
47 * tables, views, functions, procedures or events.
49 private $_pos2_name = array();
51 /**
52 * @var int The positions of nodes in the lists of tables, views,
53 * routines or events used for pagination
55 private $_pos2_value = array();
57 /**
58 * @var int The names of the type of items that are being paginated
59 * on the second level of the navigation tree.
60 * These may be columns or indexes
62 private $_pos3_name = array();
64 /**
65 * @var int The positions of nodes in the lists of columns or indexes
66 * used for pagination
68 private $_pos3_value = array();
70 /**
71 * @var string The search clause to use in SQL queries for
72 * fetching databases
73 * Used by the asynchronous fast filter
75 private $_searchClause = '';
77 /**
78 * @var string The search clause to use in SQL queries for
79 * fetching nodes
80 * Used by the asynchronous fast filter
82 private $_searchClause2 = '';
84 /**
85 * Initialises the class
87 * @return void
89 public function __construct()
91 // Save the position at which we are in the database list
92 if (isset($_REQUEST['pos'])) {
93 $this->_pos = (int) $_REQUEST['pos'];
95 if (! isset($this->_pos)) {
96 $this->_pos = $this->_getNavigationDbPos();
98 // Get the active node
99 if (isset($_REQUEST['aPath'])) {
100 $this->_aPath[0] = $this->_parsePath($_REQUEST['aPath']);
101 $this->_pos2_name[0] = $_REQUEST['pos2_name'];
102 $this->_pos2_value[0] = $_REQUEST['pos2_value'];
103 if (isset($_REQUEST['pos3_name'])) {
104 $this->_pos3_name[0] = $_REQUEST['pos3_name'];
105 $this->_pos3_value[0] = $_REQUEST['pos3_value'];
107 } else if (isset($_REQUEST['n0_aPath'])) {
108 $count = 0;
109 while (isset($_REQUEST['n' . $count . '_aPath'])) {
110 $this->_aPath[$count] = $this->_parsePath(
111 $_REQUEST['n' . $count . '_aPath']
113 $index = 'n' . $count . '_pos2_';
114 $this->_pos2_name[$count] = $_REQUEST[$index . 'name'];
115 $this->_pos2_value[$count] = $_REQUEST[$index . 'value'];
116 $index = 'n' . $count . '_pos3_';
117 if (isset($_REQUEST[$index])) {
118 $this->_pos3_name[$count] = $_REQUEST[$index . 'name'];
119 $this->_pos3_value[$count] = $_REQUEST[$index . 'value'];
121 $count++;
124 if (isset($_REQUEST['vPath'])) {
125 $this->_vPath[0] = $this->_parsePath($_REQUEST['vPath']);
126 } else if (isset($_REQUEST['n0_vPath'])) {
127 $count = 0;
128 while (isset($_REQUEST['n' . $count . '_vPath'])) {
129 $this->_vPath[$count] = $this->_parsePath(
130 $_REQUEST['n' . $count . '_vPath']
132 $count++;
135 if (isset($_REQUEST['searchClause'])) {
136 $this->_searchClause = $_REQUEST['searchClause'];
138 if (isset($_REQUEST['searchClause2'])) {
139 $this->_searchClause2 = $_REQUEST['searchClause2'];
141 // Initialise the tree by creating a root node
142 $node = PMA_NodeFactory::getInstance('Node', 'root', Node::CONTAINER);
143 $this->_tree = $node;
144 if ($GLOBALS['cfg']['NavigationTreeEnableGrouping']) {
145 $this->_tree->separator = $GLOBALS['cfg']['NavigationTreeDbSeparator'];
146 $this->_tree->separator_depth = 10000;
151 * Returns the database position for the page selector
153 * @return int
155 private function _getNavigationDbPos()
157 $retval = 0;
158 if (! empty($GLOBALS['db'])) {
159 $query = "SELECT (COUNT(`SCHEMA_NAME`) DIV %d) * %d ";
160 $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
161 $query .= "WHERE `SCHEMA_NAME` < '%s' ";
162 $query .= "ORDER BY `SCHEMA_NAME` ASC";
163 $retval = PMA_DBI_fetch_value(
164 sprintf(
165 $query,
166 (int)$GLOBALS['cfg']['MaxNavigationItems'],
167 (int)$GLOBALS['cfg']['MaxNavigationItems'],
168 PMA_Util::sqlAddSlashes($GLOBALS['db'])
172 return $retval;
176 * Converts an encoded path to a node in string format to an array
178 * @param string $string The path to parse
180 * @return array
182 private function _parsePath($string)
184 $path = explode('.', $string);
185 foreach ($path as $key => $value) {
186 $path[$key] = base64_decode($value);
188 return $path;
192 * Generates the tree structure so that it can be rendered later
194 * @return Node|false The active node or false in case of failure
196 private function _buildPath()
198 $retval = $this->_tree;
200 // Add all databases unconditionally
201 $data = $this->_tree->getData(
202 'databases',
203 $this->_pos,
204 $this->_searchClause
206 foreach ($data as $db) {
207 $node = PMA_NodeFactory::getInstance('Node_Database', $db);
208 $this->_tree->addChild($node);
211 // Whether build other parts of the tree depends
212 // on whether we have any paths in $this->_aPath
213 foreach ($this->_aPath as $key => $path) {
214 $retval = $this->_buildPathPart(
215 $path,
216 $this->_pos2_name[$key],
217 $this->_pos2_value[$key],
218 isset($this->_pos3_name[$key]) ? $this->_pos3_name[$key] : '',
219 isset($this->_pos3_value[$key]) ? $this->_pos3_value[$key] : ''
222 return $retval;
226 * Builds a branch of the tree
228 * @param array $path A paths pointing to the branch
229 * of the tree that needs to be built
230 * @param string $type2 The type of item being paginated on
231 * the second level of the tree
232 * @param int $pos2 The position for the pagination of
233 * the branch at the second level of the tree
234 * @param string $type3 The type of item being paginated on
235 * the third level of the tree
236 * @param int $pos3 The position for the pagination of
237 * the branch at the third level of the tree
239 * @return Node|false The active node or false in case of failure
241 private function _buildPathPart($path, $type2, $pos2, $type3, $pos3)
243 $retval = true;
244 if (count($path) > 1) {
245 array_shift($path); // remove 'root'
246 $db = $this->_tree->getChild($path[0]);
247 $retval = $db;
249 if ($db === false) {
250 return false;
253 $containers = $this->_addDbContainers($db, $type2, $pos2);
255 array_shift($path); // remove db
257 if ((count($path) > 0
258 && array_key_exists($path[0], $containers))
259 || count($containers) == 1
261 if (count($containers) == 1) {
262 $container = array_shift($containers);
263 } else {
264 $container = $db->getChild($path[0], true);
265 if ($container === false) {
266 return false;
269 $retval = $container;
271 if (count($container->children) <= 1) {
272 $dbData = $db->getData(
273 $container->real_name,
274 $pos2,
275 $this->_searchClause2
277 foreach ($dbData as $item) {
278 switch ($container->real_name) {
279 case 'events':
280 $node = PMA_NodeFactory::getInstance(
281 'Node_Event',
282 $item
284 break;
285 case 'functions':
286 $node = PMA_NodeFactory::getInstance(
287 'Node_Function',
288 $item
290 break;
291 case 'procedures':
292 $node = PMA_NodeFactory::getInstance(
293 'Node_Procedure',
294 $item
296 break;
297 case 'tables':
298 $node = PMA_NodeFactory::getInstance(
299 'Node_Table',
300 $item
302 break;
303 case 'views':
304 $node = PMA_NodeFactory::getInstance(
305 'Node_View',
306 $item
308 break;
309 default:
310 break;
312 if (isset($node)) {
313 if ($type2 == $container->real_name) {
314 $node->pos2 = $pos2;
316 $container->addChild($node);
320 if (count($path) > 1 && $path[0] != 'tables') {
321 $retval = false;
322 } else {
323 array_shift($path); // remove container
324 if (count($path) > 0) {
325 $table = $container->getChild($path[0], true);
326 if ($table === false) {
327 return false;
329 $retval = $table;
330 $containers = $this->_addTableContainers(
331 $table,
332 $pos2,
333 $type3,
334 $pos3
336 array_shift($path); // remove table
337 if (count($path) > 0
338 && array_key_exists($path[0], $containers)
340 $container = $table->getChild($path[0], true);
341 $retval = $container;
342 $tableData = $table->getData(
343 $container->real_name,
344 $pos3
346 foreach ($tableData as $item) {
347 switch ($container->real_name) {
348 case 'indexes':
349 $node = PMA_NodeFactory::getInstance(
350 'Node_Index',
351 $item
353 break;
354 case 'columns':
355 $node = PMA_NodeFactory::getInstance(
356 'Node_Column',
357 $item
359 break;
360 case 'triggers':
361 $node = PMA_NodeFactory::getInstance(
362 'Node_Trigger',
363 $item
365 break;
366 default:
367 break;
369 if (isset($node)) {
370 $node->pos2 = $container->parent->pos2;
371 if ($type3 == $container->real_name) {
372 $node->pos3 = $pos3;
374 $container->addChild($node);
382 return $retval;
386 * Adds containers to a node that is a table
388 * References to existing children are returned
389 * if this function is called twice on the same node
391 * @param Node $table The table node, new containers will be
392 * attached to this node
393 * @param int $pos2 The position for the pagination of
394 * the branch at the second level of the tree
395 * @param string $type3 The type of item being paginated on
396 * the third level of the tree
397 * @param int $pos3 The position for the pagination of
398 * the branch at the third level of the tree
400 * @return array An array of new nodes
402 private function _addTableContainers($table, $pos2, $type3, $pos3)
404 $retval = array();
405 if ($table->hasChildren(true) == 0) {
406 if ($table->getPresence('columns')) {
407 $retval['columns'] = PMA_NodeFactory::getInstance(
408 'Node_Column_Container'
411 if ($table->getPresence('indexes')) {
412 $retval['indexes'] = PMA_NodeFactory::getInstance(
413 'Node_Index_Container'
416 if ($table->getPresence('triggers')) {
417 $retval['triggers'] = PMA_NodeFactory::getInstance(
418 'Node_Trigger_Container'
421 // Add all new Nodes to the tree
422 foreach ($retval as $node) {
423 $node->pos2 = $pos2;
424 if ($type3 == $node->real_name) {
425 $node->pos3 = $pos3;
427 $table->addChild($node);
429 } else {
430 foreach ($table->children as $node) {
431 if ($type3 == $node->real_name) {
432 $node->pos3 = $pos3;
434 $retval[$node->real_name] = $node;
437 return $retval;
441 * Adds containers to a node that is a database
443 * References to existing children are returned
444 * if this function is called twice on the same node
446 * @param Node $db The database node, new containers will be
447 * attached to this node
448 * @param string $type The type of item being paginated on
449 * the second level of the tree
450 * @param int $pos2 The position for the pagination of
451 * the branch at the second level of the tree
453 * @return array An array of new nodes
455 private function _addDbContainers($db, $type, $pos2)
457 $retval = array();
458 if ($db->hasChildren(true) == 0) {
459 if ($db->getPresence('tables')) {
460 $retval['tables'] = PMA_NodeFactory::getInstance(
461 'Node_Table_Container'
464 if ($db->getPresence('views')) {
465 $retval['views'] = PMA_NodeFactory::getInstance(
466 'Node_View_Container'
469 if ($db->getPresence('functions')) {
470 $retval['functions'] = PMA_NodeFactory::getInstance(
471 'Node_Function_Container'
474 if ($db->getPresence('procedures')) {
475 $retval['procedures'] = PMA_NodeFactory::getInstance(
476 'Node_Procedure_Container'
479 if ($db->getPresence('events')) {
480 $retval['events'] = PMA_NodeFactory::getInstance(
481 'Node_Event_Container'
484 // Add all new Nodes to the tree
485 foreach ($retval as $node) {
486 if ($type == $node->real_name) {
487 $node->pos2 = $pos2;
489 $db->addChild($node);
491 } else {
492 foreach ($db->children as $node) {
493 if ($type == $node->real_name) {
494 $node->pos2 = $pos2;
496 $retval[$node->real_name] = $node;
499 return $retval;
503 * Recursively groups tree nodes given a separator
505 * @param mixed $node The node to group or null
506 * to group the whole tree. If
507 * passed as an argument, $node
508 * must be of type CONTAINER
510 * @return void
512 public function groupTree($node = null)
514 if (! isset($node)) {
515 $node = $this->_tree;
517 $this->groupNode($node);
518 foreach ($node->children as $child) {
519 $this->groupTree($child);
524 * Recursively groups tree nodes given a sperarator
526 * @param Node $node The node to group
528 * @return void
530 public function groupNode($node)
532 if ($node->type == Node::CONTAINER) {
533 $separators = array();
534 if (is_array($node->separator)) {
535 $separators = $node->separator;
536 } else if (strlen($node->separator)) {
537 $separators[] = $node->separator;
539 $prefixes = array();
540 if ($node->separator_depth > 0) {
541 foreach ($node->children as $child) {
542 $prefix_pos = false;
543 foreach ($separators as $separator) {
544 $sep_pos = strpos($child->name, $separator);
545 if ($sep_pos != false
546 && $sep_pos != strlen($child->name)
547 && $sep_pos != 0
548 && ($prefix_pos == false || $sep_pos < $prefix_pos)
550 $prefix_pos = $sep_pos;
553 if ($prefix_pos !== false) {
554 $prefix = substr($child->name, 0, $prefix_pos);
555 if (! isset($prefixes[$prefix])) {
556 $prefixes[$prefix] = 1;
557 } else {
558 $prefixes[$prefix]++;
563 foreach ($prefixes as $key => $value) {
564 if ($value == 1) {
565 unset($prefixes[$key]);
568 if (count($prefixes)) {
569 $groups = array();
570 foreach ($prefixes as $key => $value) {
571 $groups[$key] = new Node(
572 $key,
573 Node::CONTAINER,
574 true
576 $groups[$key]->separator = $node->separator;
577 $groups[$key]->separator_depth = $node->separator_depth - 1;
578 $groups[$key]->icon = '';
579 if ($GLOBALS['cfg']['NavigationBarIconic']) {
580 $groups[$key]->icon = PMA_Util::getImage(
581 'b_group.png'
584 $groups[$key]->pos2 = $node->pos2;
585 $groups[$key]->pos3 = $node->pos3;
586 $node->addChild($groups[$key]);
587 foreach ($separators as $separator) {
588 // FIXME: this could be more efficient
589 foreach ($node->children as $child) {
590 $name_substring = substr(
591 $child->name, 0, strlen($key) + strlen($separator)
593 if ($name_substring == $key . $separator
594 && $child->type == Node::OBJECT
596 $class = get_class($child);
597 $new_child = PMA_NodeFactory::getInstance(
598 $class,
599 substr(
600 $child->name,
601 strlen($key) + strlen($separator)
604 $new_child->real_name = $child->real_name;
605 $new_child->icon = $child->icon;
606 $new_child->links = $child->links;
607 $new_child->pos2 = $child->pos2;
608 $new_child->pos3 = $child->pos3;
609 $groups[$key]->addChild($new_child);
610 foreach ($child->children as $elm) {
611 $new_child->addChild($elm);
613 $node->removeChild($child->name);
618 foreach ($prefixes as $key => $value) {
619 $this->groupNode($groups[$key]);
620 $groups[$key]->classes = "navGroup";
627 * Renders a state of the tree, used in light mode when
628 * either JavaScript and/or Ajax are disabled
630 * @return string HTML code for the navigation tree
632 public function renderState()
634 $this->_buildPath();
635 $retval = $this->_fastFilterHtml($this->_tree);
636 $retval .= $this->_getPageSelector($this->_tree);
637 $this->groupTree();
638 $retval .= "<div><ul>";
639 $children = $this->_tree->children;
640 usort($children, array('PMA_NavigationTree', 'sortNode'));
641 $this->_setVisibility();
642 for ($i=0; $i<count($children); $i++) {
643 if ($i == 0) {
644 $retval .= $this->_renderNode($children[0], true, 'first');
645 } else if ($i + 1 != count($children)) {
646 $retval .= $this->_renderNode($children[$i], true);
647 } else {
648 $retval .= $this->_renderNode($children[$i], true, 'last');
651 $retval .= "</ul></div>";
652 return $retval;
656 * Renders a part of the tree, used for Ajax
657 * requests in light mode
659 * @return string HTML code for the navigation tree
661 public function renderPath()
663 $node = $this->_buildPath();
664 if ($node === false) {
665 $retval = false;
666 } else {
667 $this->groupTree();
668 $retval = "<div class='list_container' style='display: none;'>";
669 $retval .= "<ul>";
670 $retval .= $this->_fastFilterHtml($node);
671 $retval .= $this->_getPageSelector($node);
672 $children = $node->children;
673 usort($children, array('PMA_NavigationTree', 'sortNode'));
674 for ($i=0; $i<count($children); $i++) {
675 if ($i + 1 != count($children)) {
676 $retval .= $this->_renderNode($children[$i], true);
677 } else {
678 $retval .= $this->_renderNode($children[$i], true, 'last');
681 $retval .= "</ul>";
682 $retval .= "</div>";
685 if (! empty($this->_searchClause) || ! empty($this->_searchClause2)) {
686 if (! empty($this->_searchClause2)) {
687 $results = $node->realParent()->getPresence(
688 $node->real_name,
689 $this->_searchClause2
691 } else {
692 $results = $this->_tree->getPresence(
693 'databases',
694 $this->_searchClause
698 $clientResults = 0;
699 if (! empty($_REQUEST['results'])) {
700 $clientResults = (int)$_REQUEST['results'];
702 $otherResults = $results - $clientResults;
703 if ($otherResults < 1) {
704 $otherResults = '';
705 } else {
706 $otherResults = sprintf(
707 _ngettext(
708 '%s other result found',
709 '%s other results found',
710 $otherResults
712 $otherResults
715 PMA_Response::getInstance()->addJSON(
716 'results',
717 $otherResults
720 return $retval;
724 * Renders the parameters that are required on the client
725 * side to know which page(s) we will be requesting data from
727 * @param Node $node The node to create the pagination parameters for
729 * @return string
731 private function _getPaginationParamsHtml($node)
733 $retval = '';
734 $paths = $node->getPaths();
735 if (isset($paths['aPath_clean'][2])) {
736 $retval .= "<span class='hide pos2_name'>";
737 $retval .= $paths['aPath_clean'][2];
738 $retval .= "</span>";
739 $retval .= "<span class='hide pos2_value'>";
740 $retval .= $node->pos2;
741 $retval .= "</span>";
743 if (isset($paths['aPath_clean'][4])) {
744 $retval .= "<span class='hide pos3_name'>";
745 $retval .= $paths['aPath_clean'][4];
746 $retval .= "</span>";
747 $retval .= "<span class='hide pos3_value'>";
748 $retval .= $node->pos3;
749 $retval .= "</span>";
751 return $retval;
755 * Renders a single node or a branch of the tree
757 * @param Node $node The node to render
758 * @param int|bool $recursive Bool: Whether to render a single node or a branch
759 * Int: How many levels deep to render
760 * @param string $class An additional class for the list item
762 * @return string HTML code for the tree node or branch
764 private function _renderNode($node, $recursive = -1, $class = '')
766 $retval = '';
767 $paths = $node->getPaths();
768 if ($node->hasSiblings()
769 || isset($_REQUEST['results'])
770 || $node->realParent() === false
772 if ( $node->type == Node::CONTAINER
773 && count($node->children) == 0
774 && $GLOBALS['is_ajax_request'] != true
776 return '';
778 $liClass = '';
779 if ($class || $node->classes) {
780 $liClass = " class='" . trim($class . ' ' . $node->classes) . "'";
782 $retval .= "<li$liClass>";
783 $sterile = array(
784 'events',
785 'triggers',
786 'functions',
787 'procedures',
788 'views',
789 'columns',
790 'indexes'
792 $parentName = '';
793 $parents = $node->parents(false, true);
794 if (count($parents)) {
795 $parentName = $parents[0]->real_name;
797 if ($node->is_group
798 || (! in_array($parentName, $sterile) && ! $node->isNew)
800 $loaded = '';
801 if ($node->is_group) {
802 $loaded = ' loaded';
804 $container = '';
805 if ($node->type == Node::CONTAINER) {
806 $container = ' container';
808 $retval .= "<div class='block'>";
809 $iClass = '';
810 if ($class == 'first') {
811 $iClass = " class='first'";
813 $retval .= "<i$iClass></i>";
814 if (strpos($class, 'last') === false) {
815 $retval .= "<b></b>";
817 $icon = PMA_Util::getImage('b_plus.png');
818 $match = 1;
819 foreach ($this->_aPath as $path) {
820 $match = 1;
821 foreach ($paths['aPath_clean'] as $key => $part) {
822 if (! isset($path[$key]) || $part != $path[$key]) {
823 $match = 0;
824 break;
827 if ($match) {
828 $loaded = ' loaded';
829 if (! $node->is_group) {
830 $icon = PMA_Util::getImage(
831 'b_minus.png'
834 break;
838 foreach ($this->_vPath as $path) {
839 $match = 1;
840 foreach ($paths['vPath_clean'] as $key => $part) {
841 if ((! isset($path[$key]) || $part != $path[$key])) {
842 $match = 0;
843 break;
846 if ($match) {
847 $loaded = ' loaded';
848 $icon = PMA_Util::getImage('b_minus.png');
849 break;
853 $retval .= "<a class='expander$loaded$container'";
854 $retval .= " href='#'>";
855 $retval .= "<span class='hide aPath'>";
856 $retval .= $paths['aPath'];
857 $retval .= "</span>";
858 $retval .= "<span class='hide vPath'>";
859 $retval .= $paths['vPath'];
860 $retval .= "</span>";
861 $retval .= "<span class='hide pos'>";
862 $retval .= $this->_pos;
863 $retval .= "</span>";
864 $retval .= $this->_getPaginationParamsHtml($node);
865 $retval .= $icon;
867 $retval .= "</a>";
868 $retval .= "</div>";
869 } else {
870 $retval .= "<div class='block'>";
871 $iClass = '';
872 if ($class == 'first') {
873 $iClass = " class='first'";
875 $retval .= "<i$iClass></i>";
876 $retval .= $this->_getPaginationParamsHtml($node);
877 $retval .= "</div>";
880 $linkClass = '';
881 $haveAjax = array(
882 'functions',
883 'procedures',
884 'events',
885 'triggers',
886 'indexes'
888 $parent = $node->parents(false, true);
889 if ($parent[0]->type == Node::CONTAINER
890 && (in_array($parent[0]->real_name, $haveAjax)
891 || ($parent[0]->real_name == 'views'
892 && $node->isNew == true
896 $linkClass = ' class="ajax"';
899 if ($node->type == Node::CONTAINER) {
900 $retval .= "<i>";
902 if ($GLOBALS['cfg']['NavigationBarIconic']) {
903 $retval .= "<div class='block'>";
904 if (isset($node->links['icon'])) {
905 $args = array();
906 foreach ($node->parents(true) as $parent) {
907 $args[] = urlencode($parent->real_name);
909 $link = vsprintf($node->links['icon'], $args);
910 $retval .= "<a$linkClass href='$link'>{$node->icon}</a>";
911 } else {
912 $retval .= "<u>{$node->icon}</u>";
914 $retval .= "</div>";
916 if (isset($node->links['text'])) {
917 $args = array();
918 foreach ($node->parents(true) as $parent) {
919 $args[] = urlencode($parent->real_name);
921 $link = vsprintf($node->links['text'], $args);
922 if ($node->type == Node::CONTAINER) {
923 $retval .= "<a href='$link'>";
924 $retval .= htmlspecialchars($node->name);
925 $retval .= "</a>";
926 } else {
927 if ($GLOBALS['cfg']['ShowTooltip']) {
928 $title = $node->getComment();
929 if ($title) {
930 $title = ' title="'
931 . htmlentities($title, ENT_QUOTES, 'UTF-8')
932 . '"';
934 } else {
935 $title = '';
937 $retval .= "<a$linkClass$title href='$link'>";
938 $retval .= htmlspecialchars($node->real_name);
939 $retval .= "</a>";
941 } else {
942 $retval .= "{$node->name}";
944 if ($node->type == Node::CONTAINER) {
945 $retval .= "</i>";
947 $wrap = true;
948 } else {
949 $node->visible = true;
950 $wrap = false;
951 $retval .= $this->_getPaginationParamsHtml($node);
954 if ($recursive) {
955 $hide = '';
956 if ($node->visible == false) {
957 $hide = " style='display: none;'";
959 $children = $node->children;
960 usort($children, array('PMA_NavigationTree', 'sortNode'));
961 $buffer = '';
962 for ($i=0; $i<count($children); $i++) {
963 if ($i + 1 != count($children)) {
964 $buffer .= $this->_renderNode(
965 $children[$i],
966 true,
967 $children[$i]->classes
969 } else {
970 $buffer .= $this->_renderNode(
971 $children[$i],
972 true,
973 $children[$i]->classes . ' last'
977 if (! empty($buffer)) {
978 if ($wrap) {
979 $retval .= "<div$hide class='list_container'><ul>";
981 $retval .= $this->_fastFilterHtml($node);
982 $retval .= $this->_getPageSelector($node);
983 $retval .= $buffer;
984 if ($wrap) {
985 $retval .= "</ul></div>";
989 if ($node->hasSiblings() || isset($_REQUEST['results'])) {
990 $retval .= "</li>";
992 return $retval;
996 * Makes some nodes visible based on the which node is active
998 * @return nothing
1000 private function _setVisibility()
1002 foreach ($this->_vPath as $path) {
1003 $node = $this->_tree;
1004 foreach ($path as $value) {
1005 $child = $node->getChild($value);
1006 if ($child !== false) {
1007 $child->visible = true;
1008 $node = $child;
1015 * Generates the HTML code for displaying the fast filter for tables
1017 * @param Node $node The node for which to generate the fast filter html
1019 * @return string LI element used for the fast filter
1021 private function _fastFilterHtml($node)
1023 $retval = '';
1024 if ($node === $this->_tree
1025 && $this->_tree->getPresence() >= (int)$GLOBALS['cfg']['NavigationTreeDisplayDbFilterMinimum']
1027 $url_params = array(
1028 'pos' => 0
1030 $retval .= "<ul>";
1031 $retval .= "<li class='fast_filter db_fast_filter'>";
1032 $retval .= "<form class='ajax fast_filter'>";
1033 $retval .= PMA_getHiddenFields($url_params);
1034 $retval .= "<input class='searchClause' name='searchClause'";
1035 $retval .= " value='" . __('filter databases by name') . "' />";
1036 $retval .= "<span title='" . __('Clear Fast Filter') . "'>X</span>";
1037 $retval .= "</form>";
1038 $retval .= "</li>";
1039 $retval .= "</ul>";
1040 } else if (($node->type == Node::CONTAINER
1041 && ( $node->real_name == 'tables'
1042 || $node->real_name == 'views'
1043 || $node->real_name == 'functions'
1044 || $node->real_name == 'procedures'
1045 || $node->real_name == 'events')
1047 && $node->realParent()->getPresence($node->real_name) >= (int)$GLOBALS['cfg']['NavigationTreeDisplayItemFilterMinimum']
1049 $paths = $node->getPaths();
1050 $url_params = array(
1051 'pos' => $this->_pos,
1052 'aPath' => $paths['aPath'],
1053 'vPath' => $paths['vPath'],
1054 'pos2_name' => $node->real_name,
1055 'pos2_value' => 0
1057 $retval .= "<li class='fast_filter'>";
1058 $retval .= "<form class='ajax fast_filter'>";
1059 $retval .= PMA_getHiddenFields($url_params);
1060 $retval .= "<input class='searchClause' name='searchClause2'";
1061 $retval .= " value='" . __('filter items by name') . "' />";
1062 $retval .= "<span title='" . __('Clear Fast Filter') . "'>X</span>";
1063 $retval .= "</form>";
1064 $retval .= "</li>";
1066 return $retval;
1070 * Generates the HTML code for displaying the list pagination
1072 * @param Node $node The node for whose children the page
1073 * selector will be created
1075 * @return string
1077 private function _getPageSelector($node)
1079 $retval = '';
1080 if ($node === $this->_tree) {
1081 $retval .= PMA_Util::getListNavigator(
1082 $this->_tree->getPresence('databases', $this->_searchClause),
1083 $this->_pos,
1084 array('server' => $GLOBALS['server']),
1085 'navigation.php',
1086 'frame_navigation',
1087 $GLOBALS['cfg']['MaxNavigationItems'],
1088 'pos',
1089 array('dbselector')
1091 } else if ($node->type == Node::CONTAINER && ! $node->is_group) {
1092 $paths = $node->getPaths();
1094 $level = isset($paths['aPath_clean'][4]) ? 3 : 2;
1095 $_url_params = array(
1096 'aPath' => $paths['aPath'],
1097 'vPath' => $paths['vPath'],
1098 'pos' => $this->_pos,
1099 'server' => $GLOBALS['server'],
1100 'pos2_name' => $paths['aPath_clean'][2]
1102 if ($level == 3) {
1103 $pos = $node->pos3;
1104 $_url_params['pos2_value'] = $node->pos2;
1105 $_url_params['pos3_name'] = $paths['aPath_clean'][4];
1106 } else {
1107 $pos = $node->pos2;
1109 $num = $node->realParent()->getPresence(
1110 $node->real_name,
1111 $this->_searchClause2
1113 $retval .= PMA_Util::getListNavigator(
1114 $num,
1115 $pos,
1116 $_url_params,
1117 'navigation.php',
1118 'frame_navigation',
1119 $GLOBALS['cfg']['MaxNavigationItems'],
1120 'pos' . $level . '_value'
1123 return $retval;
1127 * Called by usort() for sorting the nodes in a container
1129 * @param Node $a The first element used in the comparison
1130 * @param Node $b The second element used in the comparison
1132 * @return int See strnatcmp() and strcmp()
1134 static public function sortNode($a, $b)
1136 if ($a->isNew) {
1137 return -1;
1138 } else if ($b->isNew) {
1139 return 1;
1141 if ($GLOBALS['cfg']['NaturalOrder']) {
1142 return strnatcasecmp($a->name, $b->name);
1143 } else {
1144 return strcasecmp($a->name, $b->name);