/ASTRA_Demo_Server/udrive/home/admin/www/phpMyAdmin/libraries/bookmark.lib.php

https://github.com/shafiqissani/ASTRA-College-Website · PHP · 222 lines · 103 code · 34 blank · 85 comment · 19 complexity · 0ade4ed0c3c5d8b305bcc7af049c1221 MD5 · raw file

  1. <?php
  2. /* $Id: bookmark.lib.php 9763 2006-11-26 10:57:48Z lem9 $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. /**
  5. * Set of functions used with the bookmark feature
  6. */
  7. /**
  8. * Defines the bookmark parameters for the current user
  9. *
  10. * @return array the bookmark parameters for the current user
  11. *
  12. * @global integer the id of the current server
  13. *
  14. * @access public
  15. */
  16. function PMA_getBookmarksParam()
  17. {
  18. global $server;
  19. $cfgBookmark = '';
  20. // No server selected -> no bookmark table
  21. if ($server == 0) {
  22. return '';
  23. }
  24. $cfgBookmark['user'] = $GLOBALS['cfg']['Server']['user'];
  25. $cfgBookmark['db'] = $GLOBALS['cfg']['Server']['pmadb'];
  26. $cfgBookmark['table'] = $GLOBALS['cfg']['Server']['bookmarktable'];
  27. return $cfgBookmark;
  28. } // end of the 'PMA_getBookmarksParam()' function
  29. /**
  30. * Gets the list of bookmarks defined for the current database
  31. *
  32. * @global resource the controluser db connection handle
  33. *
  34. * @param string the current database name
  35. * @param array the bookmark parameters for the current user
  36. *
  37. * @return mixed the bookmarks list if defined, false else
  38. *
  39. * @access public
  40. */
  41. function PMA_listBookmarks($db, $cfgBookmark)
  42. {
  43. global $controllink;
  44. if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) {
  45. return '';
  46. }
  47. $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
  48. . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
  49. . ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
  50. . ' OR user = \'\')'
  51. . ' ORDER BY label';
  52. $result = PMA_DBI_query($query, $controllink, PMA_DBI_QUERY_STORE);
  53. // There are some bookmarks -> store them
  54. // use the unique id as the key
  55. if ($result && PMA_DBI_num_rows($result) > 0) {
  56. while ($row = PMA_DBI_fetch_row($result)) {
  57. $bookmark_list[$row[1]] = $row[0];
  58. } // end while
  59. return $bookmark_list;
  60. }
  61. // No bookmarks for the current database
  62. else {
  63. return FALSE;
  64. }
  65. } // end of the 'PMA_listBookmarks()' function
  66. /**
  67. * Gets the sql command from a bookmark
  68. *
  69. * @global resource the controluser db connection handle
  70. *
  71. * @param string the current database name
  72. * @param array the bookmark parameters for the current user
  73. * @param mixed the id of the bookmark to get
  74. * @param string which field to look up the $id
  75. * @param boolean TRUE: get all bookmarks regardless of the owning user
  76. *
  77. * @return string the sql query
  78. *
  79. * @access public
  80. */
  81. function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id', $action_bookmark_all = FALSE)
  82. {
  83. global $controllink;
  84. if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) {
  85. return '';
  86. }
  87. $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
  88. . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
  89. . ($action_bookmark_all? '' : ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
  90. . ' OR user = \'\')' )
  91. . ' AND ' . PMA_backquote($id_field) . ' = ' . $id;
  92. $result = PMA_DBI_try_query($query, $controllink);
  93. if (!$result) {
  94. return FALSE;
  95. }
  96. list($bookmark_query) = PMA_DBI_fetch_row($result) or array(FALSE);
  97. return $bookmark_query;
  98. } // end of the 'PMA_queryBookmarks()' function
  99. /**
  100. * Gets bookmarked DefaultQuery for a Table
  101. *
  102. * @global resource the controluser db connection handle
  103. *
  104. * @param string the current database name
  105. * @param array the bookmark parameters for the current user
  106. * @param array the list of all labels to look for
  107. *
  108. * @return array bookmark SQL statements
  109. *
  110. * @access public
  111. */
  112. function &PMA_queryDBBookmarks($db, $cfgBookmark, &$table_array)
  113. {
  114. global $controllink;
  115. $bookmarks = array();
  116. if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) {
  117. return $bookmarks;
  118. }
  119. $search_for = array();
  120. foreach ($table_array AS $table => $table_sortkey) {
  121. $search_for[] = "'" . PMA_sqlAddslashes($table) . "'";
  122. }
  123. $query = 'SELECT label, query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
  124. . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
  125. . (count($search_for) > 0 ? ' AND label IN (' . implode(', ', $search_for) . ')' : '');
  126. $result = PMA_DBI_try_query($query, $controllink, PMA_DBI_QUERY_STORE);
  127. if (!$result || PMA_DBI_num_rows($result) < 1) {
  128. return $bookmarks;
  129. }
  130. while ($row = PMA_DBI_fetch_assoc($result)) {
  131. $bookmarks[$row['label']] = $row['query'];
  132. }
  133. return $bookmarks;
  134. } // end of the 'PMA_queryBookmarks()' function
  135. /**
  136. * Adds a bookmark
  137. *
  138. * @global resource the controluser db connection handle
  139. *
  140. * @param array the properties of the bookmark to add
  141. * @param array the bookmark parameters for the current user
  142. * @param boolean whether to make the bookmark available for all users
  143. *
  144. * @return boolean whether the INSERT succeeds or not
  145. *
  146. * @access public
  147. */
  148. function PMA_addBookmarks($fields, $cfgBookmark, $all_users = false)
  149. {
  150. global $controllink;
  151. $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
  152. . ' (id, dbase, user, query, label) VALUES (NULL, \'' . PMA_sqlAddslashes($fields['dbase']) . '\', \'' . ($all_users ? '' : PMA_sqlAddslashes($fields['user'])) . '\', \'' . PMA_sqlAddslashes(urldecode($fields['query'])) . '\', \'' . PMA_sqlAddslashes($fields['label']) . '\')';
  153. $result = PMA_DBI_query($query, $controllink);
  154. return TRUE;
  155. } // end of the 'PMA_addBookmarks()' function
  156. /**
  157. * Deletes a bookmark
  158. *
  159. * @global resource the controluser db connection handle
  160. *
  161. * @param string the current database name
  162. * @param array the bookmark parameters for the current user
  163. * @param integer the id of the bookmark to get
  164. *
  165. * @access public
  166. */
  167. function PMA_deleteBookmarks($db, $cfgBookmark, $id)
  168. {
  169. global $controllink;
  170. $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
  171. . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
  172. . ' OR user = \'\')'
  173. . ' AND id = ' . $id;
  174. $result = PMA_DBI_try_query($query, $controllink);
  175. } // end of the 'PMA_deleteBookmarks()' function
  176. /**
  177. * Bookmark Support
  178. */
  179. if (! isset($GLOBALS['cfgRelation'])) {
  180. require_once './libraries/relation.lib.php';
  181. $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
  182. }
  183. if ($GLOBALS['cfgRelation']['bookmarkwork']) {
  184. $cfg['Bookmark'] = PMA_getBookmarksParam();
  185. } else {
  186. $cfg['Bookmark'] = array();
  187. }
  188. ?>