Convert documentation to similar style as our web site uses.
[phpmyadmin/crack.git] / libraries / bookmark.lib.php
blob7d5e288271a35a53470f919778e79a7cf61ea9f5
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 */
9 /**
12 require_once './libraries/relation.lib.php';
14 /**
15 * Defines the bookmark parameters for the current user
17 * @uses $GLOBALS['server']
18 * @uses PMA_getRelationsParam()
19 * @uses $GLOBALS['cfg']['Server']['user']
20 * @uses $GLOBALS['cfg']['Server']['pmadb']
21 * @uses $GLOBALS['cfg']['Server']['bookmarktable']
22 * @return array the bookmark parameters for the current user
23 * @access public
25 function PMA_Bookmark_getParams()
27 static $cfgBookmark = null;
29 if (null !== $cfgBookmark) {
30 return $cfgBookmark;
33 $cfgRelation = PMA_getRelationsParam();
35 if ($cfgRelation['bookmarkwork']) {
36 $cfgBookmark = array(
37 'user' => $GLOBALS['cfg']['Server']['user'],
38 'db' => $GLOBALS['cfg']['Server']['pmadb'],
39 'table' => $GLOBALS['cfg']['Server']['bookmarktable'],
41 } else {
42 $cfgBookmark = false;
45 return $cfgBookmark;
46 } // end of the 'PMA_Bookmark_getParams()' function
49 /**
50 * Gets the list of bookmarks defined for the current database
52 * @uses PMA_backquote()
53 * @uses PMA_sqlAddslashes()
54 * @uses PMA_DBI_fetch_result()
55 * @uses PMA_DBI_QUERY_STORE
56 * @uses PMA_Bookmark_getParams()
57 * @global resource the controluser db connection handle
59 * @param string the current database name
61 * @return array the bookmarks list (key as index, label as value)
63 * @access public
65 function PMA_Bookmark_getList($db)
67 global $controllink;
69 $cfgBookmark = PMA_Bookmark_getParams();
71 if (empty($cfgBookmark)) {
72 return array();
75 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
76 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
77 . ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
78 . ' OR user = \'\')'
79 . ' ORDER BY label';
80 return PMA_DBI_fetch_result($query, 'id', 'label', $controllink, PMA_DBI_QUERY_STORE);
81 } // end of the 'PMA_Bookmark_getList()' function
84 /**
85 * Gets the sql command from a bookmark
87 * @uses PMA_backquote()
88 * @uses PMA_sqlAddslashes()
89 * @uses PMA_DBI_fetch_value()
90 * @uses PMA_Bookmark_getParams()
91 * @global resource the controluser db connection handle
93 * @param string the current database name
94 * @param mixed the id of the bookmark to get
95 * @param string which field to look up the $id
96 * @param boolean TRUE: get all bookmarks regardless of the owning user
98 * @return string the sql query
100 * @access public
102 function PMA_Bookmark_get($db, $id, $id_field = 'id', $action_bookmark_all = FALSE)
104 global $controllink;
106 $cfgBookmark = PMA_Bookmark_getParams();
108 if (empty($cfgBookmark)) {
109 return '';
112 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
113 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
114 . ($action_bookmark_all? '' : ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
115 . ' OR user = \'\')')
116 . ' AND ' . PMA_backquote($id_field) . ' = ' . $id;
117 return PMA_DBI_fetch_value($query, 0, 0, $controllink);
118 } // end of the 'PMA_Bookmark_get()' function
121 * Adds a bookmark
123 * @uses PMA_backquote()
124 * @uses PMA_sqlAddslashes()
125 * @uses PMA_DBI_query()
126 * @uses PMA_Bookmark_getParams()
127 * @global resource the controluser db connection handle
129 * @param array the properties of the bookmark to add; here,
130 * $fields['query'] is urlencoded
131 * @param boolean whether to make the bookmark available for all users
133 * @return boolean whether the INSERT succeeds or not
135 * @access public
137 function PMA_Bookmark_save($fields, $all_users = false)
139 global $controllink;
141 $cfgBookmark = PMA_Bookmark_getParams();
143 if (empty($cfgBookmark)) {
144 return false;
147 $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
148 . ' (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']) . '\')';
149 return PMA_DBI_query($query, $controllink);
150 } // end of the 'PMA_Bookmark_save()' function
154 * Deletes a bookmark
156 * @uses PMA_backquote()
157 * @uses PMA_sqlAddslashes()
158 * @uses PMA_DBI_try_query()
159 * @uses PMA_Bookmark_getParams()
160 * @global resource the controluser db connection handle
162 * @param string the current database name
163 * @param integer the id of the bookmark to get
165 * @access public
167 function PMA_Bookmark_delete($db, $id)
169 global $controllink;
171 $cfgBookmark = PMA_Bookmark_getParams();
173 if (empty($cfgBookmark)) {
174 return false;
177 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
178 . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
179 . ' OR user = \'\')'
180 . ' AND id = ' . $id;
181 return PMA_DBI_try_query($query, $controllink);
182 } // end of the 'PMA_Bookmark_delete()' function
186 * Bookmark Support
188 $GLOBALS['cfg']['Bookmark'] = PMA_Bookmark_getParams();