NodeDatabase.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Functionality for the navigation tree
  5. *
  6. * @package PhpMyAdmin-Navigation
  7. */
  8. namespace PhpMyAdmin\Navigation\Nodes;
  9. use PhpMyAdmin\Relation;
  10. use PhpMyAdmin\Url;
  11. use PhpMyAdmin\Util;
  12. /**
  13. * Represents a database node in the navigation tree
  14. *
  15. * @package PhpMyAdmin-Navigation
  16. */
  17. class NodeDatabase extends Node
  18. {
  19. /**
  20. * The number of hidden items in this database
  21. *
  22. * @var int
  23. */
  24. protected $hiddenCount = 0;
  25. /**
  26. * Initialises the class
  27. *
  28. * @param string $name An identifier for the new node
  29. * @param int $type Type of node, may be one of CONTAINER or OBJECT
  30. * @param bool $is_group Whether this object has been created
  31. * while grouping nodes
  32. */
  33. public function __construct($name, $type = Node::OBJECT, $is_group = false)
  34. {
  35. parent::__construct($name, $type, $is_group);
  36. $this->icon = Util::getImage(
  37. 's_db',
  38. __('Database operations')
  39. );
  40. $script_name = Util::getScriptNameForOption(
  41. $GLOBALS['cfg']['DefaultTabDatabase'],
  42. 'database'
  43. );
  44. $this->links = array(
  45. 'text' => $script_name
  46. . '?server=' . $GLOBALS['server']
  47. . '&amp;db=%1$s',
  48. 'icon' => 'db_operations.php?server=' . $GLOBALS['server']
  49. . '&amp;db=%1$s&amp;',
  50. 'title' => __('Structure'),
  51. );
  52. $this->classes = 'database';
  53. }
  54. /**
  55. * Returns the number of children of type $type present inside this container
  56. * This method is overridden by the PhpMyAdmin\Navigation\Nodes\NodeDatabase
  57. * and PhpMyAdmin\Navigation\Nodes\NodeTable classes
  58. *
  59. * @param string $type The type of item we are looking for
  60. * ('tables', 'views', etc)
  61. * @param string $searchClause A string used to filter the results of
  62. * the query
  63. * @param boolean $singleItem Whether to get presence of a single known
  64. * item or false in none
  65. *
  66. * @return int
  67. */
  68. public function getPresence($type = '', $searchClause = '', $singleItem = false)
  69. {
  70. $retval = 0;
  71. switch ($type) {
  72. case 'tables':
  73. $retval = $this->_getTableCount($searchClause, $singleItem);
  74. break;
  75. case 'views':
  76. $retval = $this->_getViewCount($searchClause, $singleItem);
  77. break;
  78. case 'procedures':
  79. $retval = $this->_getProcedureCount($searchClause, $singleItem);
  80. break;
  81. case 'functions':
  82. $retval = $this->_getFunctionCount($searchClause, $singleItem);
  83. break;
  84. case 'events':
  85. $retval = $this->_getEventCount($searchClause, $singleItem);
  86. break;
  87. default:
  88. break;
  89. }
  90. return $retval;
  91. }
  92. /**
  93. * Returns the number of tables or views present inside this database
  94. *
  95. * @param string $which tables|views
  96. * @param string $searchClause A string used to filter the results of
  97. * the query
  98. * @param boolean $singleItem Whether to get presence of a single known
  99. * item or false in none
  100. *
  101. * @return int
  102. */
  103. private function _getTableOrViewCount($which, $searchClause, $singleItem)
  104. {
  105. $db = $this->real_name;
  106. if ($which == 'tables') {
  107. $condition = 'IN';
  108. } else {
  109. $condition = 'NOT IN';
  110. }
  111. if (! $GLOBALS['cfg']['Server']['DisableIS']) {
  112. $db = $GLOBALS['dbi']->escapeString($db);
  113. $query = "SELECT COUNT(*) ";
  114. $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
  115. $query .= "WHERE `TABLE_SCHEMA`='$db' ";
  116. $query .= "AND `TABLE_TYPE`" . $condition . "('BASE TABLE', 'SYSTEM VERSIONED') ";
  117. if (! empty($searchClause)) {
  118. $query .= "AND " . $this->_getWhereClauseForSearch(
  119. $searchClause,
  120. $singleItem,
  121. 'TABLE_NAME'
  122. );
  123. }
  124. $retval = (int)$GLOBALS['dbi']->fetchValue($query);
  125. } else {
  126. $query = "SHOW FULL TABLES FROM ";
  127. $query .= Util::backquote($db);
  128. $query .= " WHERE `Table_type`" . $condition . "('BASE TABLE', 'SYSTEM VERSIONED') ";
  129. if (!empty($searchClause)) {
  130. $query .= "AND " . $this->_getWhereClauseForSearch(
  131. $searchClause,
  132. $singleItem,
  133. 'Tables_in_' . $db
  134. );
  135. }
  136. $retval = $GLOBALS['dbi']->numRows(
  137. $GLOBALS['dbi']->tryQuery($query)
  138. );
  139. }
  140. return $retval;
  141. }
  142. /**
  143. * Returns the number of tables present inside this database
  144. *
  145. * @param string $searchClause A string used to filter the results of
  146. * the query
  147. * @param boolean $singleItem Whether to get presence of a single known
  148. * item or false in none
  149. *
  150. * @return int
  151. */
  152. private function _getTableCount($searchClause, $singleItem)
  153. {
  154. return $this->_getTableOrViewCount(
  155. 'tables',
  156. $searchClause,
  157. $singleItem
  158. );
  159. }
  160. /**
  161. * Returns the number of views present inside this database
  162. *
  163. * @param string $searchClause A string used to filter the results of
  164. * the query
  165. * @param boolean $singleItem Whether to get presence of a single known
  166. * item or false in none
  167. *
  168. * @return int
  169. */
  170. private function _getViewCount($searchClause, $singleItem)
  171. {
  172. return $this->_getTableOrViewCount(
  173. 'views',
  174. $searchClause,
  175. $singleItem
  176. );
  177. }
  178. /**
  179. * Returns the number of procedures present inside this database
  180. *
  181. * @param string $searchClause A string used to filter the results of
  182. * the query
  183. * @param boolean $singleItem Whether to get presence of a single known
  184. * item or false in none
  185. *
  186. * @return int
  187. */
  188. private function _getProcedureCount($searchClause, $singleItem)
  189. {
  190. $db = $this->real_name;
  191. if (!$GLOBALS['cfg']['Server']['DisableIS']) {
  192. $db = $GLOBALS['dbi']->escapeString($db);
  193. $query = "SELECT COUNT(*) ";
  194. $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
  195. $query .= "WHERE `ROUTINE_SCHEMA` "
  196. . Util::getCollateForIS() . "='$db'";
  197. $query .= "AND `ROUTINE_TYPE`='PROCEDURE' ";
  198. if (!empty($searchClause)) {
  199. $query .= "AND " . $this->_getWhereClauseForSearch(
  200. $searchClause,
  201. $singleItem,
  202. 'ROUTINE_NAME'
  203. );
  204. }
  205. $retval = (int)$GLOBALS['dbi']->fetchValue($query);
  206. } else {
  207. $db = $GLOBALS['dbi']->escapeString($db);
  208. $query = "SHOW PROCEDURE STATUS WHERE `Db`='$db' ";
  209. if (!empty($searchClause)) {
  210. $query .= "AND " . $this->_getWhereClauseForSearch(
  211. $searchClause,
  212. $singleItem,
  213. 'Name'
  214. );
  215. }
  216. $retval = $GLOBALS['dbi']->numRows(
  217. $GLOBALS['dbi']->tryQuery($query)
  218. );
  219. }
  220. return $retval;
  221. }
  222. /**
  223. * Returns the number of functions present inside this database
  224. *
  225. * @param string $searchClause A string used to filter the results of
  226. * the query
  227. * @param boolean $singleItem Whether to get presence of a single known
  228. * item or false in none
  229. *
  230. * @return int
  231. */
  232. private function _getFunctionCount($searchClause, $singleItem)
  233. {
  234. $db = $this->real_name;
  235. if (!$GLOBALS['cfg']['Server']['DisableIS']) {
  236. $db = $GLOBALS['dbi']->escapeString($db);
  237. $query = "SELECT COUNT(*) ";
  238. $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
  239. $query .= "WHERE `ROUTINE_SCHEMA` "
  240. . Util::getCollateForIS() . "='$db' ";
  241. $query .= "AND `ROUTINE_TYPE`='FUNCTION' ";
  242. if (!empty($searchClause)) {
  243. $query .= "AND " . $this->_getWhereClauseForSearch(
  244. $searchClause,
  245. $singleItem,
  246. 'ROUTINE_NAME'
  247. );
  248. }
  249. $retval = (int)$GLOBALS['dbi']->fetchValue($query);
  250. } else {
  251. $db = $GLOBALS['dbi']->escapeString($db);
  252. $query = "SHOW FUNCTION STATUS WHERE `Db`='$db' ";
  253. if (!empty($searchClause)) {
  254. $query .= "AND " . $this->_getWhereClauseForSearch(
  255. $searchClause,
  256. $singleItem,
  257. 'Name'
  258. );
  259. }
  260. $retval = $GLOBALS['dbi']->numRows(
  261. $GLOBALS['dbi']->tryQuery($query)
  262. );
  263. }
  264. return $retval;
  265. }
  266. /**
  267. * Returns the number of events present inside this database
  268. *
  269. * @param string $searchClause A string used to filter the results of
  270. * the query
  271. * @param boolean $singleItem Whether to get presence of a single known
  272. * item or false in none
  273. *
  274. * @return int
  275. */
  276. private function _getEventCount($searchClause, $singleItem)
  277. {
  278. $db = $this->real_name;
  279. if (!$GLOBALS['cfg']['Server']['DisableIS']) {
  280. $db = $GLOBALS['dbi']->escapeString($db);
  281. $query = "SELECT COUNT(*) ";
  282. $query .= "FROM `INFORMATION_SCHEMA`.`EVENTS` ";
  283. $query .= "WHERE `EVENT_SCHEMA` "
  284. . Util::getCollateForIS() . "='$db' ";
  285. if (!empty($searchClause)) {
  286. $query .= "AND " . $this->_getWhereClauseForSearch(
  287. $searchClause,
  288. $singleItem,
  289. 'EVENT_NAME'
  290. );
  291. }
  292. $retval = (int)$GLOBALS['dbi']->fetchValue($query);
  293. } else {
  294. $db = Util::backquote($db);
  295. $query = "SHOW EVENTS FROM $db ";
  296. if (!empty($searchClause)) {
  297. $query .= "WHERE " . $this->_getWhereClauseForSearch(
  298. $searchClause,
  299. $singleItem,
  300. 'Name'
  301. );
  302. }
  303. $retval = $GLOBALS['dbi']->numRows(
  304. $GLOBALS['dbi']->tryQuery($query)
  305. );
  306. }
  307. return $retval;
  308. }
  309. /**
  310. * Returns the WHERE clause for searching inside a database
  311. *
  312. * @param string $searchClause A string used to filter the results of the query
  313. * @param boolean $singleItem Whether to get presence of a single known item
  314. * @param string $columnName Name of the column in the result set to match
  315. *
  316. * @return string WHERE clause for searching
  317. */
  318. private function _getWhereClauseForSearch(
  319. $searchClause,
  320. $singleItem,
  321. $columnName
  322. ) {
  323. $query = '';
  324. if ($singleItem) {
  325. $query .= Util::backquote($columnName) . " = ";
  326. $query .= "'" . $GLOBALS['dbi']->escapeString($searchClause) . "'";
  327. } else {
  328. $query .= Util::backquote($columnName) . " LIKE ";
  329. $query .= "'%" . $GLOBALS['dbi']->escapeString($searchClause)
  330. . "%'";
  331. }
  332. return $query;
  333. }
  334. /**
  335. * Returns the names of children of type $type present inside this container
  336. * This method is overridden by the PhpMyAdmin\Navigation\Nodes\NodeDatabase
  337. * and PhpMyAdmin\Navigation\Nodes\NodeTable classes
  338. *
  339. * @param string $type The type of item we are looking for
  340. * ('tables', 'views', etc)
  341. * @param int $pos The offset of the list within the results
  342. * @param string $searchClause A string used to filter the results of the query
  343. *
  344. * @return array
  345. */
  346. public function getData($type, $pos, $searchClause = '')
  347. {
  348. $retval = array();
  349. switch ($type) {
  350. case 'tables':
  351. $retval = $this->_getTables($pos, $searchClause);
  352. break;
  353. case 'views':
  354. $retval = $this->_getViews($pos, $searchClause);
  355. break;
  356. case 'procedures':
  357. $retval = $this->_getProcedures($pos, $searchClause);
  358. break;
  359. case 'functions':
  360. $retval = $this->_getFunctions($pos, $searchClause);
  361. break;
  362. case 'events':
  363. $retval = $this->_getEvents($pos, $searchClause);
  364. break;
  365. default:
  366. break;
  367. }
  368. // Remove hidden items so that they are not displayed in navigation tree
  369. $cfgRelation = $this->relation->getRelationsParam();
  370. if ($cfgRelation['navwork']) {
  371. $hiddenItems = $this->getHiddenItems(substr($type, 0, -1));
  372. foreach ($retval as $key => $item) {
  373. if (in_array($item, $hiddenItems)) {
  374. unset($retval[$key]);
  375. }
  376. }
  377. }
  378. return $retval;
  379. }
  380. /**
  381. * Return list of hidden items of given type
  382. *
  383. * @param string $type The type of items we are looking for
  384. * ('table', 'function', 'group', etc.)
  385. *
  386. * @return array Array containing hidden items of given type
  387. */
  388. public function getHiddenItems($type)
  389. {
  390. $db = $this->real_name;
  391. $cfgRelation = $this->relation->getRelationsParam();
  392. if (! $cfgRelation['navwork']) {
  393. return array();
  394. }
  395. $navTable = Util::backquote($cfgRelation['db'])
  396. . "." . Util::backquote($cfgRelation['navigationhiding']);
  397. $sqlQuery = "SELECT `item_name` FROM " . $navTable
  398. . " WHERE `username`='" . $cfgRelation['user'] . "'"
  399. . " AND `item_type`='" . $type
  400. . "'" . " AND `db_name`='" . $GLOBALS['dbi']->escapeString($db)
  401. . "'";
  402. $result = $this->relation->queryAsControlUser($sqlQuery, false);
  403. $hiddenItems = array();
  404. if ($result) {
  405. while ($row = $GLOBALS['dbi']->fetchArray($result)) {
  406. $hiddenItems[] = $row[0];
  407. }
  408. }
  409. $GLOBALS['dbi']->freeResult($result);
  410. return $hiddenItems;
  411. }
  412. /**
  413. * Returns the list of tables or views inside this database
  414. *
  415. * @param string $which tables|views
  416. * @param int $pos The offset of the list within the results
  417. * @param string $searchClause A string used to filter the results of the query
  418. *
  419. * @return array
  420. */
  421. private function _getTablesOrViews($which, $pos, $searchClause)
  422. {
  423. if ($which == 'tables') {
  424. $condition = 'IN';
  425. } else {
  426. $condition = 'NOT IN';
  427. }
  428. $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
  429. $retval = array();
  430. $db = $this->real_name;
  431. if (! $GLOBALS['cfg']['Server']['DisableIS']) {
  432. $escdDb = $GLOBALS['dbi']->escapeString($db);
  433. $query = "SELECT `TABLE_NAME` AS `name` ";
  434. $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
  435. $query .= "WHERE `TABLE_SCHEMA`='$escdDb' ";
  436. $query .= "AND `TABLE_TYPE`" . $condition . "('BASE TABLE', 'SYSTEM VERSIONED') ";
  437. if (! empty($searchClause)) {
  438. $query .= "AND `TABLE_NAME` LIKE '%";
  439. $query .= $GLOBALS['dbi']->escapeString($searchClause);
  440. $query .= "%'";
  441. }
  442. $query .= "ORDER BY `TABLE_NAME` ASC ";
  443. $query .= "LIMIT " . intval($pos) . ", $maxItems";
  444. $retval = $GLOBALS['dbi']->fetchResult($query);
  445. } else {
  446. $query = " SHOW FULL TABLES FROM ";
  447. $query .= Util::backquote($db);
  448. $query .= " WHERE `Table_type`" . $condition . "('BASE TABLE', 'SYSTEM VERSIONED') ";
  449. if (!empty($searchClause)) {
  450. $query .= "AND " . Util::backquote(
  451. "Tables_in_" . $db
  452. );
  453. $query .= " LIKE '%" . $GLOBALS['dbi']->escapeString(
  454. $searchClause
  455. );
  456. $query .= "%'";
  457. }
  458. $handle = $GLOBALS['dbi']->tryQuery($query);
  459. if ($handle !== false) {
  460. $count = 0;
  461. if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
  462. while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
  463. if ($count < $maxItems) {
  464. $retval[] = $arr[0];
  465. $count++;
  466. } else {
  467. break;
  468. }
  469. }
  470. }
  471. }
  472. }
  473. return $retval;
  474. }
  475. /**
  476. * Returns the list of tables inside this database
  477. *
  478. * @param int $pos The offset of the list within the results
  479. * @param string $searchClause A string used to filter the results of the query
  480. *
  481. * @return array
  482. */
  483. private function _getTables($pos, $searchClause)
  484. {
  485. return $this->_getTablesOrViews('tables', $pos, $searchClause);
  486. }
  487. /**
  488. * Returns the list of views inside this database
  489. *
  490. * @param int $pos The offset of the list within the results
  491. * @param string $searchClause A string used to filter the results of the query
  492. *
  493. * @return array
  494. */
  495. private function _getViews($pos, $searchClause)
  496. {
  497. return $this->_getTablesOrViews('views', $pos, $searchClause);
  498. }
  499. /**
  500. * Returns the list of procedures or functions inside this database
  501. *
  502. * @param string $routineType PROCEDURE|FUNCTION
  503. * @param int $pos The offset of the list within the results
  504. * @param string $searchClause A string used to filter the results of the query
  505. *
  506. * @return array
  507. */
  508. private function _getRoutines($routineType, $pos, $searchClause)
  509. {
  510. $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
  511. $retval = array();
  512. $db = $this->real_name;
  513. if (!$GLOBALS['cfg']['Server']['DisableIS']) {
  514. $escdDb = $GLOBALS['dbi']->escapeString($db);
  515. $query = "SELECT `ROUTINE_NAME` AS `name` ";
  516. $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
  517. $query .= "WHERE `ROUTINE_SCHEMA` "
  518. . Util::getCollateForIS() . "='$escdDb'";
  519. $query .= "AND `ROUTINE_TYPE`='" . $routineType . "' ";
  520. if (!empty($searchClause)) {
  521. $query .= "AND `ROUTINE_NAME` LIKE '%";
  522. $query .= $GLOBALS['dbi']->escapeString($searchClause);
  523. $query .= "%'";
  524. }
  525. $query .= "ORDER BY `ROUTINE_NAME` ASC ";
  526. $query .= "LIMIT " . intval($pos) . ", $maxItems";
  527. $retval = $GLOBALS['dbi']->fetchResult($query);
  528. } else {
  529. $escdDb = $GLOBALS['dbi']->escapeString($db);
  530. $query = "SHOW " . $routineType . " STATUS WHERE `Db`='$escdDb' ";
  531. if (!empty($searchClause)) {
  532. $query .= "AND `Name` LIKE '%";
  533. $query .= $GLOBALS['dbi']->escapeString($searchClause);
  534. $query .= "%'";
  535. }
  536. $handle = $GLOBALS['dbi']->tryQuery($query);
  537. if ($handle !== false) {
  538. $count = 0;
  539. if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
  540. while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
  541. if ($count < $maxItems) {
  542. $retval[] = $arr['Name'];
  543. $count++;
  544. } else {
  545. break;
  546. }
  547. }
  548. }
  549. }
  550. }
  551. return $retval;
  552. }
  553. /**
  554. * Returns the list of procedures inside this database
  555. *
  556. * @param int $pos The offset of the list within the results
  557. * @param string $searchClause A string used to filter the results of the query
  558. *
  559. * @return array
  560. */
  561. private function _getProcedures($pos, $searchClause)
  562. {
  563. return $this->_getRoutines('PROCEDURE', $pos, $searchClause);
  564. }
  565. /**
  566. * Returns the list of functions inside this database
  567. *
  568. * @param int $pos The offset of the list within the results
  569. * @param string $searchClause A string used to filter the results of the query
  570. *
  571. * @return array
  572. */
  573. private function _getFunctions($pos, $searchClause)
  574. {
  575. return $this->_getRoutines('FUNCTION', $pos, $searchClause);
  576. }
  577. /**
  578. * Returns the list of events inside this database
  579. *
  580. * @param int $pos The offset of the list within the results
  581. * @param string $searchClause A string used to filter the results of the query
  582. *
  583. * @return array
  584. */
  585. private function _getEvents($pos, $searchClause)
  586. {
  587. $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
  588. $retval = array();
  589. $db = $this->real_name;
  590. if (!$GLOBALS['cfg']['Server']['DisableIS']) {
  591. $escdDb = $GLOBALS['dbi']->escapeString($db);
  592. $query = "SELECT `EVENT_NAME` AS `name` ";
  593. $query .= "FROM `INFORMATION_SCHEMA`.`EVENTS` ";
  594. $query .= "WHERE `EVENT_SCHEMA` "
  595. . Util::getCollateForIS() . "='$escdDb' ";
  596. if (!empty($searchClause)) {
  597. $query .= "AND `EVENT_NAME` LIKE '%";
  598. $query .= $GLOBALS['dbi']->escapeString($searchClause);
  599. $query .= "%'";
  600. }
  601. $query .= "ORDER BY `EVENT_NAME` ASC ";
  602. $query .= "LIMIT " . intval($pos) . ", $maxItems";
  603. $retval = $GLOBALS['dbi']->fetchResult($query);
  604. } else {
  605. $escdDb = Util::backquote($db);
  606. $query = "SHOW EVENTS FROM $escdDb ";
  607. if (!empty($searchClause)) {
  608. $query .= "WHERE `Name` LIKE '%";
  609. $query .= $GLOBALS['dbi']->escapeString($searchClause);
  610. $query .= "%'";
  611. }
  612. $handle = $GLOBALS['dbi']->tryQuery($query);
  613. if ($handle !== false) {
  614. $count = 0;
  615. if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
  616. while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
  617. if ($count < $maxItems) {
  618. $retval[] = $arr['Name'];
  619. $count++;
  620. } else {
  621. break;
  622. }
  623. }
  624. }
  625. }
  626. }
  627. return $retval;
  628. }
  629. /**
  630. * Returns HTML for control buttons displayed infront of a node
  631. *
  632. * @return String HTML for control buttons
  633. */
  634. public function getHtmlForControlButtons()
  635. {
  636. $ret = '';
  637. $cfgRelation = $this->relation->getRelationsParam();
  638. if ($cfgRelation['navwork']) {
  639. if ($this->hiddenCount > 0) {
  640. $params = array(
  641. 'showUnhideDialog' => true,
  642. 'dbName' => $this->real_name,
  643. );
  644. $ret = '<span class="dbItemControls">'
  645. . '<a href="navigation.php" data-post="'
  646. . Url::getCommon($params, '', false) . '"'
  647. . ' class="showUnhide ajax">'
  648. . Util::getImage(
  649. 'show',
  650. __('Show hidden items')
  651. )
  652. . '</a></span>';
  653. }
  654. }
  655. return $ret;
  656. }
  657. /**
  658. * Sets the number of hidden items in this database
  659. *
  660. * @param int $count hidden item count
  661. *
  662. * @return void
  663. */
  664. public function setHiddenCount($count)
  665. {
  666. $this->hiddenCount = $count;
  667. }
  668. /**
  669. * Returns the number of hidden items in this database
  670. *
  671. * @return int hidden item count
  672. */
  673. public function getHiddenCount()
  674. {
  675. return $this->hiddenCount;
  676. }
  677. }