6 * Set of functions used with the bookmark feature
11 if (!defined('PMA_BOOKMARK_LIB_INCLUDED')){
12 define('PMA_BOOKMARK_LIB_INCLUDED', 1);
15 * Defines the bookmark parameters for the current user
17 * @return array the bookmark parameters for the current user
19 * @global array the list of settings for the current server
20 * @global integer the id of the current server
24 function PMA_getBookmarksParam()
31 // No server selected -> no bookmark table
36 $cfgBookmark['user'] = $cfgServer['user'];
37 $cfgBookmark['db'] = $cfgServer['bookmarkdb'];
38 $cfgBookmark['table'] = $cfgServer['bookmarktable'];
41 } // end of the 'PMA_getBookmarksParam()' function
45 * Gets the list of bookmarks defined for the current database
47 * @param string the current database name
48 * @param array the bookmark parameters for the current user
50 * @return mixed the bookmarks list if defined, false else
54 function PMA_listBookmarks($db, $cfgBookmark)
56 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
57 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
58 . ' AND user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'';
59 if (isset($GLOBALS['dbh'])) {
60 $result = mysql_query($query, $GLOBALS['dbh']);
62 $result = mysql_query($query);
65 // There is some bookmarks -> store them
66 if ($result > 0 && mysql_num_rows($result) > 0) {
68 while ($row = mysql_fetch_row($result)) {
69 $bookmark_list[$flag . ' - ' . $row[0]] = $row[1];
72 return $bookmark_list;
74 // No bookmarks for the current database
78 } // end of the 'PMA_listBookmarks()' function
82 * Gets the sql command from a bookmark
84 * @param string the current database name
85 * @param array the bookmark parameters for the current user
86 * @param integer the id of the bookmark to get
88 * @return string the sql query
92 function PMA_queryBookmarks($db, $cfgBookmark, $id)
94 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
95 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
96 . ' AND user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
98 if (isset($GLOBALS['dbh'])) {
99 $result = mysql_query($query, $GLOBALS['dbh']);
101 $result = mysql_query($query);
103 $bookmark_query = mysql_result($result, 0, 'query');
105 return $bookmark_query;
106 } // end of the 'PMA_queryBookmarks()' function
112 * @param array the properties of the bookmark to add
113 * @param array the bookmark parameters for the current user
117 function PMA_addBookmarks($fields, $cfgBookmark)
119 $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
120 . ' (id, dbase, user, query, label) VALUES (\'\', \'' . PMA_sqlAddslashes($fields['dbase']) . '\', \'' . PMA_sqlAddslashes($fields['user']) . '\', \'' . PMA_sqlAddslashes(urldecode($fields['query'])) . '\', \'' . PMA_sqlAddslashes($fields['label']) . '\')';
121 if (isset($GLOBALS['dbh'])) {
122 $result = mysql_query($query, $GLOBALS['dbh']);
124 $result = mysql_query($query);
126 } // end of the 'PMA_addBookmarks()' function
132 * @param string the current database name
133 * @param array the bookmark parameters for the current user
134 * @param integer the id of the bookmark to get
138 function PMA_deleteBookmarks($db, $cfgBookmark, $id)
140 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
141 . ' WHERE user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
142 . ' AND id = ' . $id;
143 if (isset($GLOBALS['dbh'])) {
144 $result = mysql_query($query, $GLOBALS['dbh']);
146 $result = mysql_query($query);
148 } // end of the 'PMA_deleteBookmarks()' function
154 $cfgBookmark = PMA_getBookmarksParam();
157 } // $__PMA_BOOKMARK_LIB__