2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used with the bookmark feature
10 * Defines the bookmark parameters for the current user
12 * @uses $GLOBALS['server']
13 * @uses PMA_getRelationsParam()
14 * @uses $GLOBALS['cfg']['Server']['user']
15 * @uses $GLOBALS['cfg']['Server']['pmadb']
16 * @uses $GLOBALS['cfg']['Server']['bookmarktable']
17 * @return array the bookmark parameters for the current user
20 function PMA_Bookmark_getParams()
22 static $cfgBookmark = null;
24 if (null !== $cfgBookmark) {
28 $cfgRelation = PMA_getRelationsParam();
30 if ($cfgRelation['bookmarkwork']) {
32 'user' => $GLOBALS['cfg']['Server']['user'],
33 'db' => $GLOBALS['cfg']['Server']['pmadb'],
34 'table' => $GLOBALS['cfg']['Server']['bookmarktable'],
41 } // end of the 'PMA_Bookmark_getParams()' function
45 * Gets the list of bookmarks defined for the current database
47 * @uses PMA_backquote()
48 * @uses PMA_sqlAddslashes()
49 * @uses PMA_DBI_fetch_result()
50 * @uses PMA_DBI_QUERY_STORE
51 * @uses PMA_Bookmark_getParams()
52 * @global resource the controluser db connection handle
54 * @param string the current database name
56 * @return array the bookmarks list (key as index, label as value)
60 function PMA_Bookmark_getList($db)
64 $cfgBookmark = PMA_Bookmark_getParams();
66 if (empty($cfgBookmark)) {
70 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
71 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
72 . ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
75 return PMA_DBI_fetch_result($query, 'id', 'label', $controllink, PMA_DBI_QUERY_STORE
);
76 } // end of the 'PMA_Bookmark_getList()' function
80 * Gets the sql command from a bookmark
82 * @uses PMA_backquote()
83 * @uses PMA_sqlAddslashes()
84 * @uses PMA_DBI_fetch_value()
85 * @uses PMA_Bookmark_getParams()
86 * @global resource the controluser db connection handle
88 * @param string the current database name
89 * @param mixed the id of the bookmark to get
90 * @param string which field to look up the $id
91 * @param boolean TRUE: get all bookmarks regardless of the owning user
93 * @return string the sql query
97 function PMA_Bookmark_get($db, $id, $id_field = 'id', $action_bookmark_all = FALSE)
101 $cfgBookmark = PMA_Bookmark_getParams();
103 if (empty($cfgBookmark)) {
107 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
108 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
109 . ($action_bookmark_all?
'' : ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
110 . ' OR user = \'\')')
111 . ' AND ' . PMA_backquote($id_field) . ' = ' . $id;
112 return PMA_DBI_fetch_value($query, 0, 0, $controllink);
113 } // end of the 'PMA_Bookmark_get()' function
118 * @uses PMA_backquote()
119 * @uses PMA_sqlAddslashes()
120 * @uses PMA_DBI_query()
121 * @uses PMA_Bookmark_getParams()
122 * @global resource the controluser db connection handle
124 * @param array the properties of the bookmark to add; here,
125 * $fields['query'] is urlencoded
126 * @param boolean whether to make the bookmark available for all users
128 * @return boolean whether the INSERT succeeds or not
132 function PMA_Bookmark_save($fields, $all_users = false)
136 $cfgBookmark = PMA_Bookmark_getParams();
138 if (empty($cfgBookmark)) {
142 $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
143 . ' (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']) . '\')';
144 return PMA_DBI_query($query, $controllink);
145 } // end of the 'PMA_Bookmark_save()' function
151 * @uses PMA_backquote()
152 * @uses PMA_sqlAddslashes()
153 * @uses PMA_DBI_try_query()
154 * @uses PMA_Bookmark_getParams()
155 * @global resource the controluser db connection handle
157 * @param string the current database name
158 * @param integer the id of the bookmark to get
162 function PMA_Bookmark_delete($db, $id)
166 $cfgBookmark = PMA_Bookmark_getParams();
168 if (empty($cfgBookmark)) {
172 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
173 . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
175 . ' AND id = ' . $id;
176 return PMA_DBI_try_query($query, $controllink);
177 } // end of the 'PMA_Bookmark_delete()' function
183 $GLOBALS['cfg']['Bookmark'] = PMA_Bookmark_getParams();