Translated using Weblate (Kurdish Sorani)
[phpmyadmin.git] / libraries / navigation / NavigationTree.class.php
blobe3549857cd6423673f27783ead07882fc73dab2c
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_Database_Container', 'root');
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 = $GLOBALS['dbi']->fetchValue(
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 (PMA_Util::showIcons('TableNavigationLinksMode')) {
580 $groups[$key]->icon = PMA_Util::getImage(
581 'b_group.png'
584 $groups[$key]->pos2 = $node->pos2;
585 $groups[$key]->pos3 = $node->pos3;
586 if ($node instanceof Node_Table_Container
587 || $node instanceof Node_View_Container
589 $tblGroup = '&amp;tbl_group='
590 . urlencode($key . $node->separator);
591 $groups[$key]->links = array(
592 'text' => $node->links['text'] . $tblGroup,
593 'icon' => $node->links['icon'] . $tblGroup
596 $node->addChild($groups[$key]);
597 foreach ($separators as $separator) {
598 // FIXME: this could be more efficient
599 foreach ($node->children as $child) {
600 $name_substring = substr(
601 $child->name, 0, strlen($key) + strlen($separator)
603 if (($name_substring == $key . $separator
604 || $child->name == $key)
605 && $child->type == Node::OBJECT
607 $class = get_class($child);
608 $new_child = PMA_NodeFactory::getInstance(
609 $class,
610 substr(
611 $child->name,
612 strlen($key) + strlen($separator)
615 $new_child->real_name = $child->real_name;
616 $new_child->icon = $child->icon;
617 $new_child->links = $child->links;
618 $new_child->pos2 = $child->pos2;
619 $new_child->pos3 = $child->pos3;
620 $groups[$key]->addChild($new_child);
621 foreach ($child->children as $elm) {
622 $new_child->addChild($elm);
624 $node->removeChild($child->name);
629 foreach ($prefixes as $key => $value) {
630 $this->groupNode($groups[$key]);
631 $groups[$key]->classes = "navGroup";
638 * Renders a state of the tree, used in light mode when
639 * either JavaScript and/or Ajax are disabled
641 * @return string HTML code for the navigation tree
643 public function renderState()
645 $this->_buildPath();
646 $retval = $this->_fastFilterHtml($this->_tree);
647 $retval .= $this->_getPageSelector($this->_tree);
648 $this->groupTree();
649 $retval .= "<div id='pma_navigation_tree_content'><ul>";
650 $children = $this->_tree->children;
651 usort($children, array('PMA_NavigationTree', 'sortNode'));
652 $this->_setVisibility();
653 for ($i=0; $i<count($children); $i++) {
654 if ($i == 0) {
655 $retval .= $this->_renderNode($children[0], true, 'first');
656 } else if ($i + 1 != count($children)) {
657 $retval .= $this->_renderNode($children[$i], true);
658 } else {
659 $retval .= $this->_renderNode($children[$i], true, 'last');
662 $retval .= "</ul></div>";
663 return $retval;
667 * Renders a part of the tree, used for Ajax
668 * requests in light mode
670 * @return string HTML code for the navigation tree
672 public function renderPath()
674 $node = $this->_buildPath();
675 if ($node === false) {
676 $retval = false;
677 } else {
678 $this->groupTree();
679 $retval = "<div class='list_container' style='display: none;'>";
680 $retval .= "<ul>";
681 $retval .= $this->_fastFilterHtml($node);
682 $retval .= $this->_getPageSelector($node);
683 $children = $node->children;
684 usort($children, array('PMA_NavigationTree', 'sortNode'));
685 for ($i=0; $i<count($children); $i++) {
686 if ($i + 1 != count($children)) {
687 $retval .= $this->_renderNode($children[$i], true);
688 } else {
689 $retval .= $this->_renderNode($children[$i], true, 'last');
692 $retval .= "</ul>";
693 $retval .= "</div>";
696 if (! empty($this->_searchClause) || ! empty($this->_searchClause2)) {
697 if (! empty($this->_searchClause2)) {
698 $results = $node->realParent()->getPresence(
699 $node->real_name,
700 $this->_searchClause2
702 } else {
703 $results = $this->_tree->getPresence(
704 'databases',
705 $this->_searchClause
709 $clientResults = 0;
710 if (! empty($_REQUEST['results'])) {
711 $clientResults = (int)$_REQUEST['results'];
713 $otherResults = $results - $clientResults;
714 if ($otherResults < 1) {
715 $otherResults = '';
716 } else {
717 $otherResults = sprintf(
718 _ngettext(
719 '%s other result found',
720 '%s other results found',
721 $otherResults
723 $otherResults
726 PMA_Response::getInstance()->addJSON(
727 'results',
728 $otherResults
731 return $retval;
735 * Renders the parameters that are required on the client
736 * side to know which page(s) we will be requesting data from
738 * @param Node $node The node to create the pagination parameters for
740 * @return string
742 private function _getPaginationParamsHtml($node)
744 $retval = '';
745 $paths = $node->getPaths();
746 if (isset($paths['aPath_clean'][2])) {
747 $retval .= "<span class='hide pos2_name'>";
748 $retval .= $paths['aPath_clean'][2];
749 $retval .= "</span>";
750 $retval .= "<span class='hide pos2_value'>";
751 $retval .= $node->pos2;
752 $retval .= "</span>";
754 if (isset($paths['aPath_clean'][4])) {
755 $retval .= "<span class='hide pos3_name'>";
756 $retval .= $paths['aPath_clean'][4];
757 $retval .= "</span>";
758 $retval .= "<span class='hide pos3_value'>";
759 $retval .= $node->pos3;
760 $retval .= "</span>";
762 return $retval;
766 * Renders a single node or a branch of the tree
768 * @param Node $node The node to render
769 * @param int|bool $recursive Bool: Whether to render a single node or a branch
770 * Int: How many levels deep to render
771 * @param string $class An additional class for the list item
773 * @return string HTML code for the tree node or branch
775 private function _renderNode($node, $recursive = -1, $class = '')
777 $retval = '';
778 $paths = $node->getPaths();
779 if ($node->hasSiblings()
780 || isset($_REQUEST['results'])
781 || $node->realParent() === false
783 if ( $node->type == Node::CONTAINER
784 && count($node->children) == 0
785 && $GLOBALS['is_ajax_request'] != true
787 return '';
789 $liClass = '';
790 if ($class || $node->classes) {
791 $liClass = " class='" . trim($class . ' ' . $node->classes) . "'";
793 $retval .= "<li$liClass>";
794 $sterile = array(
795 'events',
796 'triggers',
797 'functions',
798 'procedures',
799 'views',
800 'columns',
801 'indexes'
803 $parentName = '';
804 $parents = $node->parents(false, true);
805 if (count($parents)) {
806 $parentName = $parents[0]->real_name;
808 if ($node->is_group
809 || (! in_array($parentName, $sterile) && ! $node->isNew)
811 $loaded = '';
812 if ($node->is_group) {
813 $loaded = ' loaded';
815 $container = '';
816 if ($node->type == Node::CONTAINER) {
817 $container = ' container';
819 $retval .= "<div class='block'>";
820 $iClass = '';
821 if ($class == 'first') {
822 $iClass = " class='first'";
824 $retval .= "<i$iClass></i>";
825 if (strpos($class, 'last') === false) {
826 $retval .= "<b></b>";
828 $icon = PMA_Util::getImage('b_plus.png');
829 $match = 1;
830 foreach ($this->_aPath as $path) {
831 $match = 1;
832 foreach ($paths['aPath_clean'] as $key => $part) {
833 if (! isset($path[$key]) || $part != $path[$key]) {
834 $match = 0;
835 break;
838 if ($match) {
839 $loaded = ' loaded';
840 if (! $node->is_group) {
841 $icon = PMA_Util::getImage(
842 'b_minus.png'
845 break;
849 foreach ($this->_vPath as $path) {
850 $match = 1;
851 foreach ($paths['vPath_clean'] as $key => $part) {
852 if ((! isset($path[$key]) || $part != $path[$key])) {
853 $match = 0;
854 break;
857 if ($match) {
858 $loaded = ' loaded';
859 $icon = PMA_Util::getImage('b_minus.png');
860 break;
864 $retval .= "<a class='expander$loaded$container'";
865 $retval .= " href='#'>";
866 $retval .= "<span class='hide aPath'>";
867 $retval .= $paths['aPath'];
868 $retval .= "</span>";
869 $retval .= "<span class='hide vPath'>";
870 $retval .= $paths['vPath'];
871 $retval .= "</span>";
872 $retval .= "<span class='hide pos'>";
873 $retval .= $this->_pos;
874 $retval .= "</span>";
875 $retval .= $this->_getPaginationParamsHtml($node);
876 $retval .= $icon;
878 $retval .= "</a>";
879 $retval .= "</div>";
880 } else {
881 $retval .= "<div class='block'>";
882 $iClass = '';
883 if ($class == 'first') {
884 $iClass = " class='first'";
886 $retval .= "<i$iClass></i>";
887 $retval .= $this->_getPaginationParamsHtml($node);
888 $retval .= "</div>";
891 $linkClass = '';
892 $haveAjax = array(
893 'functions',
894 'procedures',
895 'events',
896 'triggers',
897 'indexes'
899 $parent = $node->parents(false, true);
900 $isNewView = $parent[0]->real_name == 'views' && $node->isNew == true;
901 if ($parent[0]->type == Node::CONTAINER
902 && (in_array($parent[0]->real_name, $haveAjax) || $isNewView)
904 $linkClass = ' class="ajax"';
907 if ($node->type == Node::CONTAINER) {
908 $retval .= "<i>";
910 if (PMA_Util::showIcons('TableNavigationLinksMode')) {
911 $retval .= "<div class='block'>";
912 if (isset($node->links['icon'])) {
913 $args = array();
914 foreach ($node->parents(true) as $parent) {
915 $args[] = urlencode($parent->real_name);
917 $link = vsprintf($node->links['icon'], $args);
918 $retval .= "<a$linkClass href='$link'>{$node->icon}</a>";
919 } else {
920 $retval .= "<u>{$node->icon}</u>";
922 $retval .= "</div>";
924 if (isset($node->links['text'])) {
925 $args = array();
926 foreach ($node->parents(true) as $parent) {
927 $args[] = urlencode($parent->real_name);
929 $link = vsprintf($node->links['text'], $args);
930 if ($node->type == Node::CONTAINER) {
931 $retval .= "<a href='$link'>";
932 $retval .= htmlspecialchars($node->name);
933 $retval .= "</a>";
934 } else {
935 $retval .= "<a$linkClass href='$link'>";
936 $retval .= htmlspecialchars($node->real_name);
937 $retval .= "</a>";
939 } else {
940 $retval .= "{$node->name}";
942 if ($node->type == Node::CONTAINER) {
943 $retval .= "</i>";
945 $retval .= $node->getHtmlForControlButtons();
946 $wrap = true;
947 } else {
948 $node->visible = true;
949 $wrap = false;
950 $retval .= $this->_getPaginationParamsHtml($node);
953 if ($recursive) {
954 $hide = '';
955 if ($node->visible == false) {
956 $hide = " style='display: none;'";
958 $children = $node->children;
959 usort($children, array('PMA_NavigationTree', 'sortNode'));
960 $buffer = '';
961 for ($i=0; $i<count($children); $i++) {
962 if ($i + 1 != count($children)) {
963 $buffer .= $this->_renderNode(
964 $children[$i],
965 true,
966 $children[$i]->classes
968 } else {
969 $buffer .= $this->_renderNode(
970 $children[$i],
971 true,
972 $children[$i]->classes . ' last'
976 if (! empty($buffer)) {
977 if ($wrap) {
978 $retval .= "<div$hide class='list_container'><ul>";
980 $retval .= $this->_fastFilterHtml($node);
981 $retval .= $this->_getPageSelector($node);
982 $retval .= $buffer;
983 if ($wrap) {
984 $retval .= "</ul></div>";
988 if ($node->hasSiblings() || isset($_REQUEST['results'])) {
989 $retval .= "</li>";
991 return $retval;
995 * Makes some nodes visible based on the which node is active
997 * @return nothing
999 private function _setVisibility()
1001 foreach ($this->_vPath as $path) {
1002 $node = $this->_tree;
1003 foreach ($path as $value) {
1004 $child = $node->getChild($value);
1005 if ($child !== false) {
1006 $child->visible = true;
1007 $node = $child;
1014 * Generates the HTML code for displaying the fast filter for tables
1016 * @param Node $node The node for which to generate the fast filter html
1018 * @return string LI element used for the fast filter
1020 private function _fastFilterHtml($node)
1022 $retval = '';
1023 $filter_min = (int)$GLOBALS['cfg']['NavigationTreeDisplayDbFilterMinimum'];
1024 if ($node === $this->_tree
1025 && $this->_tree->getPresence() >= $filter_min
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 .= ' accesskey="q"';
1036 // allow html5 placeholder attribute
1037 $placeholder_key = 'value';
1038 if (PMA_USR_BROWSER_AGENT !== 'IE'
1039 || PMA_USR_BROWSER_VER > 9
1041 $placeholder_key = 'placeholder';
1043 $retval .= " $placeholder_key='"
1044 . __('Filter databases by name or regex');
1045 $retval .= "' />";
1046 $retval .= '<span title="' . __('Clear fast filter') . '">X</span>';
1047 $retval .= "</form>";
1048 $retval .= "</li>";
1049 $retval .= "</ul>";
1050 } else if (($node->type == Node::CONTAINER
1051 && ( $node->real_name == 'tables'
1052 || $node->real_name == 'views'
1053 || $node->real_name == 'functions'
1054 || $node->real_name == 'procedures'
1055 || $node->real_name == 'events'))
1056 && $node->realParent()->getPresence($node->real_name) >= $filter_min
1058 $paths = $node->getPaths();
1059 $url_params = array(
1060 'pos' => $this->_pos,
1061 'aPath' => $paths['aPath'],
1062 'vPath' => $paths['vPath'],
1063 'pos2_name' => $node->real_name,
1064 'pos2_value' => 0
1066 $retval .= "<li class='fast_filter'>";
1067 $retval .= "<form class='ajax fast_filter'>";
1068 $retval .= PMA_getHiddenFields($url_params);
1069 $retval .= "<input class='searchClause' name='searchClause2'";
1070 // allow html5 placeholder attribute
1071 $placeholder_key = 'value';
1072 if (PMA_USR_BROWSER_AGENT !== 'IE'
1073 || PMA_USR_BROWSER_VER > 9
1075 $placeholder_key = 'placeholder';
1077 $retval .= " $placeholder_key='"
1078 . __('Filter by name or regex') . "' />";
1079 $retval .= "<span title='" . __('Clear fast filter') . "'>X</span>";
1080 $retval .= "</form>";
1081 $retval .= "</li>";
1083 return $retval;
1087 * Generates the HTML code for displaying the list pagination
1089 * @param Node $node The node for whose children the page
1090 * selector will be created
1092 * @return string
1094 private function _getPageSelector($node)
1096 $retval = '';
1097 if ($node === $this->_tree) {
1098 $retval .= PMA_Util::getListNavigator(
1099 $this->_tree->getPresence('databases', $this->_searchClause),
1100 $this->_pos,
1101 array('server' => $GLOBALS['server']),
1102 'navigation.php',
1103 'frame_navigation',
1104 $GLOBALS['cfg']['MaxNavigationItems'],
1105 'pos',
1106 array('dbselector')
1108 } else if ($node->type == Node::CONTAINER && ! $node->is_group) {
1109 $paths = $node->getPaths();
1111 $level = isset($paths['aPath_clean'][4]) ? 3 : 2;
1112 $_url_params = array(
1113 'aPath' => $paths['aPath'],
1114 'vPath' => $paths['vPath'],
1115 'pos' => $this->_pos,
1116 'server' => $GLOBALS['server'],
1117 'pos2_name' => $paths['aPath_clean'][2]
1119 if ($level == 3) {
1120 $pos = $node->pos3;
1121 $_url_params['pos2_value'] = $node->pos2;
1122 $_url_params['pos3_name'] = $paths['aPath_clean'][4];
1123 } else {
1124 $pos = $node->pos2;
1126 $num = $node->realParent()->getPresence(
1127 $node->real_name,
1128 $this->_searchClause2
1130 $retval .= PMA_Util::getListNavigator(
1131 $num,
1132 $pos,
1133 $_url_params,
1134 'navigation.php',
1135 'frame_navigation',
1136 $GLOBALS['cfg']['MaxNavigationItems'],
1137 'pos' . $level . '_value'
1140 return $retval;
1144 * Called by usort() for sorting the nodes in a container
1146 * @param Node $a The first element used in the comparison
1147 * @param Node $b The second element used in the comparison
1149 * @return int See strnatcmp() and strcmp()
1151 static public function sortNode($a, $b)
1153 if ($a->isNew) {
1154 return -1;
1155 } else if ($b->isNew) {
1156 return 1;
1158 if ($GLOBALS['cfg']['NaturalOrder']) {
1159 return strnatcasecmp($a->name, $b->name);
1160 } else {
1161 return strcasecmp($a->name, $b->name);