Conditional Ajax for DROP DATABASE
[phpmyadmin/crack.git] / libraries / bookmark.lib.php
blobdba279d9c5d8f6cf0d986b388e1f70cbdbc7ba97
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used with the bookmark feature
6 * @package phpMyAdmin
7 */
9 /**
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
18 * @access public
20 function PMA_Bookmark_getParams()
22 static $cfgBookmark = null;
24 if (null !== $cfgBookmark) {
25 return $cfgBookmark;
28 $cfgRelation = PMA_getRelationsParam();
30 if ($cfgRelation['bookmarkwork']) {
31 $cfgBookmark = array(
32 'user' => $GLOBALS['cfg']['Server']['user'],
33 'db' => $GLOBALS['cfg']['Server']['pmadb'],
34 'table' => $GLOBALS['cfg']['Server']['bookmarktable'],
36 } else {
37 $cfgBookmark = false;
40 return $cfgBookmark;
41 } // end of the 'PMA_Bookmark_getParams()' function
44 /**
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)
58 * @access public
60 function PMA_Bookmark_getList($db)
62 global $controllink;
64 $cfgBookmark = PMA_Bookmark_getParams();
66 if (empty($cfgBookmark)) {
67 return array();
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']) . '\''
73 . ' OR user = \'\')'
74 . ' ORDER BY label';
75 return PMA_DBI_fetch_result($query, 'id', 'label', $controllink, PMA_DBI_QUERY_STORE);
76 } // end of the 'PMA_Bookmark_getList()' function
79 /**
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
95 * @access public
97 function PMA_Bookmark_get($db, $id, $id_field = 'id', $action_bookmark_all = FALSE)
99 global $controllink;
101 $cfgBookmark = PMA_Bookmark_getParams();
103 if (empty($cfgBookmark)) {
104 return '';
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
116 * Adds a bookmark
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
130 * @access public
132 function PMA_Bookmark_save($fields, $all_users = false)
134 global $controllink;
136 $cfgBookmark = PMA_Bookmark_getParams();
138 if (empty($cfgBookmark)) {
139 return false;
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
149 * Deletes a bookmark
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
160 * @access public
162 function PMA_Bookmark_delete($db, $id)
164 global $controllink;
166 $cfgBookmark = PMA_Bookmark_getParams();
168 if (empty($cfgBookmark)) {
169 return false;
172 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
173 . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
174 . ' OR user = \'\')'
175 . ' AND id = ' . $id;
176 return PMA_DBI_try_query($query, $controllink);
177 } // end of the 'PMA_Bookmark_delete()' function
181 * Bookmark Support
183 $GLOBALS['cfg']['Bookmark'] = PMA_Bookmark_getParams();