2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used with the bookmark feature
11 * Defines the bookmark parameters for the current user
13 * @return array the bookmark parameters for the current user
15 * @global integer the id of the current server
19 function PMA_getBookmarksParam()
25 // No server selected -> no bookmark table
30 $cfgBookmark['user'] = $GLOBALS['cfg']['Server']['user'];
31 $cfgBookmark['db'] = $GLOBALS['cfg']['Server']['pmadb'];
32 $cfgBookmark['table'] = $GLOBALS['cfg']['Server']['bookmarktable'];
35 } // end of the 'PMA_getBookmarksParam()' function
39 * Gets the list of bookmarks defined for the current database
41 * @global resource the controluser db connection handle
43 * @param string the current database name
44 * @param array the bookmark parameters for the current user
46 * @return mixed the bookmarks list if defined, false else
50 function PMA_listBookmarks($db, $cfgBookmark)
54 if (empty($cfgBookmark['db']) ||
empty($cfgBookmark['table'])) {
58 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
59 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
60 . ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
63 $result = PMA_DBI_query($query, $controllink, PMA_DBI_QUERY_STORE
);
65 // There are some bookmarks -> store them
66 // use the unique id as the key
67 if ($result && PMA_DBI_num_rows($result) > 0) {
68 while ($row = PMA_DBI_fetch_row($result)) {
69 $bookmark_list[$row[1]] = $row[0];
71 return $bookmark_list;
73 // No bookmarks for the current database
77 } // end of the 'PMA_listBookmarks()' function
81 * Gets the sql command from a bookmark
83 * @global resource the controluser db connection handle
85 * @param string the current database name
86 * @param array the bookmark parameters for the current user
87 * @param mixed the id of the bookmark to get
88 * @param string which field to look up the $id
89 * @param boolean TRUE: get all bookmarks regardless of the owning user
90 * @param boolean whether to ignore bookmarks with no user
92 * @return string the sql query
96 function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id', $action_bookmark_all = FALSE, $exact_user_match = FALSE)
100 if (empty($cfgBookmark['db']) ||
empty($cfgBookmark['table'])) {
104 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
105 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'';
107 if (!$action_bookmark_all) {
108 $query .= ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'';
109 if (!$exact_user_match) {
110 $query .= ' OR user = \'\'';
115 $query .= ' AND ' . PMA_backquote($id_field) . ' = ' . $id;
117 $result = PMA_DBI_try_query($query, $controllink);
121 list($bookmark_query) = PMA_DBI_fetch_row($result) or array(FALSE);
123 return $bookmark_query;
124 } // end of the 'PMA_queryBookmarks()' function
129 * @global resource the controluser db connection handle
131 * @param array the properties of the bookmark to add
132 * @param array the bookmark parameters for the current user
133 * @param boolean whether to make the bookmark available for all users
135 * @return boolean whether the INSERT succeeds or not
139 function PMA_addBookmarks($fields, $cfgBookmark, $all_users = false)
143 $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
144 . ' (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']) . '\')';
145 $result = PMA_DBI_query($query, $controllink);
148 } // end of the 'PMA_addBookmarks()' function
154 * @global resource the controluser db connection handle
156 * @param string the current database name
157 * @param array the bookmark parameters for the current user
158 * @param integer the id of the bookmark to get
162 function PMA_deleteBookmarks($db, $cfgBookmark, $id)
166 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
167 . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
169 . ' AND id = ' . $id;
170 $result = PMA_DBI_try_query($query, $controllink);
171 } // end of the 'PMA_deleteBookmarks()' function
178 if (! isset($GLOBALS['cfgRelation'])) {
179 require_once './libraries/relation.lib.php';
180 $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
183 if ($GLOBALS['cfgRelation']['bookmarkwork']) {
184 $cfg['Bookmark'] = PMA_getBookmarksParam();
186 $cfg['Bookmark'] = array();