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 * @return array the bookmark parameters for the current user
15 function PMA_Bookmark_getParams()
17 static $cfgBookmark = null;
19 if (null !== $cfgBookmark) {
23 $cfgRelation = PMA_getRelationsParam();
25 if ($cfgRelation['bookmarkwork']) {
27 'user' => $GLOBALS['cfg']['Server']['user'],
28 'db' => $GLOBALS['cfg']['Server']['pmadb'],
29 'table' => $GLOBALS['cfg']['Server']['bookmarktable'],
36 } // end of the 'PMA_Bookmark_getParams()' function
40 * Gets the list of bookmarks defined for the current database
42 * @global resource the controluser db connection handle
44 * @param string the current database name
46 * @return array the bookmarks list (key as index, label as value)
50 function PMA_Bookmark_getList($db)
54 $cfgBookmark = PMA_Bookmark_getParams();
56 if (empty($cfgBookmark)) {
60 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
61 . ' WHERE dbase = \'' . PMA_sqlAddSlashes($db) . '\''
62 . ' AND user = \'' . PMA_sqlAddSlashes($cfgBookmark['user']) . '\''
64 $per_user = PMA_DBI_fetch_result($query, 'id', 'label', $controllink, PMA_DBI_QUERY_STORE
);
66 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
67 . ' WHERE dbase = \'' . PMA_sqlAddSlashes($db) . '\''
70 $global = PMA_DBI_fetch_result($query, 'id', 'label', $controllink, PMA_DBI_QUERY_STORE
);
72 foreach ($global as $key => $val) {
73 $global[$key] = $val . ' (' . __('shared') . ')';
76 $ret = $global +
$per_user;
81 } // end of the 'PMA_Bookmark_getList()' function
85 * Gets the sql command from a bookmark
87 * @global resource the controluser db connection handle
89 * @param string the current database name
90 * @param mixed the id of the bookmark to get
91 * @param string which field to look up the $id
92 * @param boolean true: get all bookmarks regardless of the owning user
93 * @param boolean whether to ignore bookmarks with no user
95 * @return string the sql query
99 function PMA_Bookmark_get($db, $id, $id_field = 'id', $action_bookmark_all = false, $exact_user_match = false)
103 $cfgBookmark = PMA_Bookmark_getParams();
105 if (empty($cfgBookmark)) {
109 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
110 . ' WHERE dbase = \'' . PMA_sqlAddSlashes($db) . '\'';
112 if (!$action_bookmark_all) {
113 $query .= ' AND (user = \'' . PMA_sqlAddSlashes($cfgBookmark['user']) . '\'';
114 if (!$exact_user_match) {
115 $query .= ' OR user = \'\'';
120 $query .= ' AND ' . PMA_backquote($id_field) . ' = ' . $id;
122 return PMA_DBI_fetch_value($query, 0, 0, $controllink);
123 } // end of the 'PMA_Bookmark_get()' function
128 * @global resource the controluser db connection handle
130 * @param array the properties of the bookmark to add; here,
131 * $fields['query'] is urlencoded
132 * @param boolean whether to make the bookmark available for all users
134 * @return boolean whether the INSERT succeeds or not
138 function PMA_Bookmark_save($fields, $all_users = false)
142 $cfgBookmark = PMA_Bookmark_getParams();
144 if (empty($cfgBookmark)) {
148 $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
149 . ' (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']) . '\')';
150 return PMA_DBI_query($query, $controllink);
151 } // end of the 'PMA_Bookmark_save()' function
157 * @global resource the controluser db connection handle
159 * @param string the current database name
160 * @param integer the id of the bookmark to get
164 function PMA_Bookmark_delete($db, $id)
168 $cfgBookmark = PMA_Bookmark_getParams();
170 if (empty($cfgBookmark)) {
174 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
175 . ' WHERE (user = \'' . PMA_sqlAddSlashes($cfgBookmark['user']) . '\''
177 . ' AND id = ' . $id;
178 return PMA_DBI_try_query($query, $controllink);
179 } // end of the 'PMA_Bookmark_delete()' function
185 $GLOBALS['cfg']['Bookmark'] = PMA_Bookmark_getParams();