3.3.10-rc1
[phpmyadmin/crack.git] / libraries / bookmark.lib.php
blob760ded3a44dca345ba0c7cbd3327a623eed0c7da
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used with the bookmark feature
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
13 require_once './libraries/relation.lib.php';
15 /**
16 * Defines the bookmark parameters for the current user
18 * @uses $GLOBALS['server']
19 * @uses PMA_getRelationsParam()
20 * @uses $GLOBALS['cfg']['Server']['user']
21 * @uses $GLOBALS['cfg']['Server']['pmadb']
22 * @uses $GLOBALS['cfg']['Server']['bookmarktable']
23 * @return array the bookmark parameters for the current user
24 * @access public
26 function PMA_Bookmark_getParams()
28 static $cfgBookmark = null;
30 if (null !== $cfgBookmark) {
31 return $cfgBookmark;
34 $cfgRelation = PMA_getRelationsParam();
36 if ($cfgRelation['bookmarkwork']) {
37 $cfgBookmark = array(
38 'user' => $GLOBALS['cfg']['Server']['user'],
39 'db' => $GLOBALS['cfg']['Server']['pmadb'],
40 'table' => $GLOBALS['cfg']['Server']['bookmarktable'],
42 } else {
43 $cfgBookmark = false;
46 return $cfgBookmark;
47 } // end of the 'PMA_Bookmark_getParams()' function
50 /**
51 * Gets the list of bookmarks defined for the current database
53 * @uses PMA_backquote()
54 * @uses PMA_sqlAddslashes()
55 * @uses PMA_DBI_fetch_result()
56 * @uses PMA_DBI_QUERY_STORE
57 * @uses PMA_Bookmark_getParams()
58 * @global resource the controluser db connection handle
60 * @param string the current database name
62 * @return array the bookmarks list (key as index, label as value)
64 * @access public
66 function PMA_Bookmark_getList($db)
68 global $controllink;
70 $cfgBookmark = PMA_Bookmark_getParams();
72 if (empty($cfgBookmark)) {
73 return array();
76 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
77 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
78 . ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
79 . ' OR user = \'\')'
80 . ' ORDER BY label';
81 return PMA_DBI_fetch_result($query, 'id', 'label', $controllink, PMA_DBI_QUERY_STORE);
82 } // end of the 'PMA_Bookmark_getList()' function
85 /**
86 * Gets the sql command from a bookmark
88 * @uses PMA_backquote()
89 * @uses PMA_sqlAddslashes()
90 * @uses PMA_DBI_fetch_value()
91 * @uses PMA_Bookmark_getParams()
92 * @global resource the controluser db connection handle
94 * @param string the current database name
95 * @param mixed the id of the bookmark to get
96 * @param string which field to look up the $id
97 * @param boolean TRUE: get all bookmarks regardless of the owning user
98 * @param boolean whether to ignore bookmarks with no user
100 * @return string the sql query
102 * @access public
104 function PMA_Bookmark_get($db, $id, $id_field = 'id', $action_bookmark_all = FALSE, $exact_user_match = FALSE)
106 global $controllink;
108 $cfgBookmark = PMA_Bookmark_getParams();
110 if (empty($cfgBookmark)) {
111 return '';
114 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
115 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'';
117 if (!$action_bookmark_all) {
118 $query .= ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'';
119 if (!$exact_user_match) {
120 $query .= ' OR user = \'\'';
122 $query .= ')';
125 $query .= ' AND ' . PMA_backquote($id_field) . ' = ' . $id;
127 return PMA_DBI_fetch_value($query, 0, 0, $controllink);
128 } // end of the 'PMA_Bookmark_get()' function
131 * Adds a bookmark
133 * @uses PMA_backquote()
134 * @uses PMA_sqlAddslashes()
135 * @uses PMA_DBI_query()
136 * @uses PMA_Bookmark_getParams()
137 * @global resource the controluser db connection handle
139 * @param array the properties of the bookmark to add; here,
140 * $fields['query'] is urlencoded
141 * @param boolean whether to make the bookmark available for all users
143 * @return boolean whether the INSERT succeeds or not
145 * @access public
147 function PMA_Bookmark_save($fields, $all_users = false)
149 global $controllink;
151 $cfgBookmark = PMA_Bookmark_getParams();
153 if (empty($cfgBookmark)) {
154 return false;
157 $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
158 . ' (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']) . '\')';
159 return PMA_DBI_query($query, $controllink);
160 } // end of the 'PMA_Bookmark_save()' function
164 * Deletes a bookmark
166 * @uses PMA_backquote()
167 * @uses PMA_sqlAddslashes()
168 * @uses PMA_DBI_try_query()
169 * @uses PMA_Bookmark_getParams()
170 * @global resource the controluser db connection handle
172 * @param string the current database name
173 * @param integer the id of the bookmark to get
175 * @access public
177 function PMA_Bookmark_delete($db, $id)
179 global $controllink;
181 $cfgBookmark = PMA_Bookmark_getParams();
183 if (empty($cfgBookmark)) {
184 return false;
187 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
188 . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
189 . ' OR user = \'\')'
190 . ' AND id = ' . $id;
191 return PMA_DBI_try_query($query, $controllink);
192 } // end of the 'PMA_Bookmark_delete()' function
196 * Bookmark Support
198 $GLOBALS['cfg']['Bookmark'] = PMA_Bookmark_getParams();