lang
[phpmyadmin/crack.git] / libraries / bookmark.lib.php3
blob63365ca502108054051c902c96dc5233f84364f5
1 <?php
2 /* $Id$ */
5 /**
6 * Set of functions used with the bookmark feature
7 */
11 if (!defined('PMA_BOOKMARK_LIB_INCLUDED')){
12 define('PMA_BOOKMARK_LIB_INCLUDED', 1);
14 /**
15 * Defines the bookmark parameters for the current user
17 * @return array the bookmark parameters for the current user
19 * @global integer the id of the current server
21 * @access public
23 function PMA_getBookmarksParam()
25 global $server;
27 $cfgBookmark = '';
29 // No server selected -> no bookmark table
30 if ($server == 0) {
31 return '';
34 $cfgBookmark['user'] = $GLOBALS['cfg']['Server']['user'];
35 $cfgBookmark['db'] = $GLOBALS['cfg']['Server']['pmadb'];
36 $cfgBookmark['table'] = $GLOBALS['cfg']['Server']['bookmarktable'];
38 return $cfgBookmark;
39 } // end of the 'PMA_getBookmarksParam()' function
42 /**
43 * Gets the list of bookmarks defined for the current database
45 * @param string the current database name
46 * @param array the bookmark parameters for the current user
48 * @return mixed the bookmarks list if defined, false else
50 * @access public
52 function PMA_listBookmarks($db, $cfgBookmark)
54 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
55 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
56 . ' AND user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'';
57 if (isset($GLOBALS['dbh'])) {
58 $result = PMA_mysql_query($query, $GLOBALS['dbh']);
59 } else {
60 $result = PMA_mysql_query($query);
63 // There is some bookmarks -> store them
64 if ($result > 0 && mysql_num_rows($result) > 0) {
65 $flag = 1;
66 while ($row = PMA_mysql_fetch_row($result)) {
67 $bookmark_list[$flag . ' - ' . $row[0]] = $row[1];
68 $flag++;
69 } // end while
70 return $bookmark_list;
72 // No bookmarks for the current database
73 else {
74 return FALSE;
76 } // end of the 'PMA_listBookmarks()' function
79 /**
80 * Gets the sql command from a bookmark
82 * @param string the current database name
83 * @param array the bookmark parameters for the current user
84 * @param integer the id of the bookmark to get
86 * @return string the sql query
88 * @access public
90 function PMA_queryBookmarks($db, $cfgBookmark, $id)
92 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
93 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
94 . ' AND user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
95 . ' AND id = ' . $id;
96 if (isset($GLOBALS['dbh'])) {
97 $result = PMA_mysql_query($query, $GLOBALS['dbh']);
98 } else {
99 $result = PMA_mysql_query($query);
101 $bookmark_query = PMA_mysql_result($result, 0, 'query');
103 return $bookmark_query;
104 } // end of the 'PMA_queryBookmarks()' function
108 * Adds a bookmark
110 * @param array the properties of the bookmark to add
111 * @param array the bookmark parameters for the current user
113 * @access public
115 function PMA_addBookmarks($fields, $cfgBookmark)
117 $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
118 . ' (id, dbase, user, query, label) VALUES (\'\', \'' . PMA_sqlAddslashes($fields['dbase']) . '\', \'' . PMA_sqlAddslashes($fields['user']) . '\', \'' . PMA_sqlAddslashes(urldecode($fields['query'])) . '\', \'' . PMA_sqlAddslashes($fields['label']) . '\')';
119 if (isset($GLOBALS['dbh'])) {
120 $result = PMA_mysql_query($query, $GLOBALS['dbh']);
121 } else {
122 $result = PMA_mysql_query($query);
124 } // end of the 'PMA_addBookmarks()' function
128 * Deletes a bookmark
130 * @param string the current database name
131 * @param array the bookmark parameters for the current user
132 * @param integer the id of the bookmark to get
134 * @access public
136 function PMA_deleteBookmarks($db, $cfgBookmark, $id)
138 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
139 . ' WHERE user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
140 . ' AND id = ' . $id;
141 if (isset($GLOBALS['dbh'])) {
142 $result = PMA_mysql_query($query, $GLOBALS['dbh']);
143 } else {
144 $result = PMA_mysql_query($query);
146 } // end of the 'PMA_deleteBookmarks()' function
150 * Bookmark Support
152 $cfg['Bookmark'] = PMA_getBookmarksParam();
155 } // $__PMA_BOOKMARK_LIB__