typo
[phpmyadmin/arisferyanto.git] / libraries / bookmark.lib.php
blob73a9665b9015726b54a0528d03c01a2892deae49
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
99 * @return string the sql query
101 * @access public
103 function PMA_Bookmark_get($db, $id, $id_field = 'id', $action_bookmark_all = FALSE)
105 global $controllink;
107 $cfgBookmark = PMA_Bookmark_getParams();
109 if (empty($cfgBookmark)) {
110 return '';
113 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
114 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
115 . ($action_bookmark_all? '' : ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
116 . ' OR user = \'\')')
117 . ' AND ' . PMA_backquote($id_field) . ' = ' . $id;
118 return PMA_DBI_fetch_value($query, 0, 0, $controllink);
119 } // end of the 'PMA_Bookmark_get()' function
122 * Adds a bookmark
124 * @uses PMA_backquote()
125 * @uses PMA_sqlAddslashes()
126 * @uses PMA_DBI_query()
127 * @uses PMA_Bookmark_getParams()
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
136 * @access public
138 function PMA_Bookmark_save($fields, $all_users = false)
140 global $controllink;
142 $cfgBookmark = PMA_Bookmark_getParams();
144 if (empty($cfgBookmark)) {
145 return false;
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
155 * Deletes a bookmark
157 * @uses PMA_backquote()
158 * @uses PMA_sqlAddslashes()
159 * @uses PMA_DBI_try_query()
160 * @uses PMA_Bookmark_getParams()
161 * @global resource the controluser db connection handle
163 * @param string the current database name
164 * @param integer the id of the bookmark to get
166 * @access public
168 function PMA_Bookmark_delete($db, $id)
170 global $controllink;
172 $cfgBookmark = PMA_Bookmark_getParams();
174 if (empty($cfgBookmark)) {
175 return false;
178 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
179 . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
180 . ' OR user = \'\')'
181 . ' AND id = ' . $id;
182 return PMA_DBI_try_query($query, $controllink);
183 } // end of the 'PMA_Bookmark_delete()' function
187 * Bookmark Support
189 $GLOBALS['cfg']['Bookmark'] = PMA_Bookmark_getParams();