250 |
kaklik |
1 |
<?php |
|
|
2 |
/* $Id: bookmark.lib.php,v 2.16 2006/01/17 17:02:30 cybot_tm Exp $ */ |
|
|
3 |
// vim: expandtab sw=4 ts=4 sts=4: |
|
|
4 |
|
|
|
5 |
/** |
|
|
6 |
* Set of functions used with the bookmark feature |
|
|
7 |
*/ |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
/** |
|
|
11 |
* Defines the bookmark parameters for the current user |
|
|
12 |
* |
|
|
13 |
* @return array the bookmark parameters for the current user |
|
|
14 |
* |
|
|
15 |
* @global integer the id of the current server |
|
|
16 |
* |
|
|
17 |
* @access public |
|
|
18 |
*/ |
|
|
19 |
function PMA_getBookmarksParam() |
|
|
20 |
{ |
|
|
21 |
global $server; |
|
|
22 |
|
|
|
23 |
$cfgBookmark = ''; |
|
|
24 |
|
|
|
25 |
// No server selected -> no bookmark table |
|
|
26 |
if ($server == 0) { |
|
|
27 |
return ''; |
|
|
28 |
} |
|
|
29 |
|
|
|
30 |
$cfgBookmark['user'] = $GLOBALS['cfg']['Server']['user']; |
|
|
31 |
$cfgBookmark['db'] = $GLOBALS['cfg']['Server']['pmadb']; |
|
|
32 |
$cfgBookmark['table'] = $GLOBALS['cfg']['Server']['bookmarktable']; |
|
|
33 |
|
|
|
34 |
return $cfgBookmark; |
|
|
35 |
} // end of the 'PMA_getBookmarksParam()' function |
|
|
36 |
|
|
|
37 |
|
|
|
38 |
/** |
|
|
39 |
* Gets the list of bookmarks defined for the current database |
|
|
40 |
* |
|
|
41 |
* @global resource the controluser db connection handle |
|
|
42 |
* |
|
|
43 |
* @param string the current database name |
|
|
44 |
* @param array the bookmark parameters for the current user |
|
|
45 |
* |
|
|
46 |
* @return mixed the bookmarks list if defined, false else |
|
|
47 |
* |
|
|
48 |
* @access public |
|
|
49 |
*/ |
|
|
50 |
function PMA_listBookmarks($db, $cfgBookmark) |
|
|
51 |
{ |
|
|
52 |
global $controllink; |
|
|
53 |
|
|
|
54 |
$query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) |
|
|
55 |
. ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' |
|
|
56 |
. ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' |
|
|
57 |
. ' OR user = \'\')' |
|
|
58 |
. ' ORDER BY label'; |
|
|
59 |
$result = PMA_DBI_query($query, $controllink, PMA_DBI_QUERY_STORE); |
|
|
60 |
|
|
|
61 |
// There are some bookmarks -> store them |
|
|
62 |
// use the unique id as the key |
|
|
63 |
if ($result && PMA_DBI_num_rows($result) > 0) { |
|
|
64 |
while ($row = PMA_DBI_fetch_row($result)) { |
|
|
65 |
$bookmark_list[$row[1]] = $row[0]; |
|
|
66 |
} // end while |
|
|
67 |
return $bookmark_list; |
|
|
68 |
} |
|
|
69 |
// No bookmarks for the current database |
|
|
70 |
else { |
|
|
71 |
return FALSE; |
|
|
72 |
} |
|
|
73 |
} // end of the 'PMA_listBookmarks()' function |
|
|
74 |
|
|
|
75 |
|
|
|
76 |
/** |
|
|
77 |
* Gets the sql command from a bookmark |
|
|
78 |
* |
|
|
79 |
* @global resource the controluser db connection handle |
|
|
80 |
* |
|
|
81 |
* @param string the current database name |
|
|
82 |
* @param array the bookmark parameters for the current user |
|
|
83 |
* @param mixed the id of the bookmark to get |
|
|
84 |
* @param string which field to look up the $id |
|
|
85 |
* @param boolean TRUE: get all bookmarks regardless of the owning user |
|
|
86 |
* |
|
|
87 |
* @return string the sql query |
|
|
88 |
* |
|
|
89 |
* @access public |
|
|
90 |
*/ |
|
|
91 |
function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id', $action_bookmark_all = FALSE) |
|
|
92 |
{ |
|
|
93 |
global $controllink; |
|
|
94 |
|
|
|
95 |
if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) { |
|
|
96 |
return ''; |
|
|
97 |
} |
|
|
98 |
|
|
|
99 |
$query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) |
|
|
100 |
. ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' |
|
|
101 |
. ($action_bookmark_all? '' : ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' |
|
|
102 |
. ' OR user = \'\')' ) |
|
|
103 |
. ' AND ' . PMA_backquote($id_field) . ' = ' . $id; |
|
|
104 |
$result = PMA_DBI_try_query($query, $controllink); |
|
|
105 |
if (!$result) { |
|
|
106 |
return FALSE; |
|
|
107 |
} |
|
|
108 |
list($bookmark_query) = PMA_DBI_fetch_row($result) or array(FALSE); |
|
|
109 |
|
|
|
110 |
return $bookmark_query; |
|
|
111 |
} // end of the 'PMA_queryBookmarks()' function |
|
|
112 |
|
|
|
113 |
|
|
|
114 |
/** |
|
|
115 |
* Gets bookmarked DefaultQuery for a Table |
|
|
116 |
* |
|
|
117 |
* @global resource the controluser db connection handle |
|
|
118 |
* |
|
|
119 |
* @param string the current database name |
|
|
120 |
* @param array the bookmark parameters for the current user |
|
|
121 |
* @param array the list of all labels to look for |
|
|
122 |
* |
|
|
123 |
* @return array bookmark SQL statements |
|
|
124 |
* |
|
|
125 |
* @access public |
|
|
126 |
*/ |
|
|
127 |
function &PMA_queryDBBookmarks($db, $cfgBookmark, &$table_array) |
|
|
128 |
{ |
|
|
129 |
global $controllink; |
|
|
130 |
$bookmarks = array(); |
|
|
131 |
|
|
|
132 |
if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) { |
|
|
133 |
return $bookmarks; |
|
|
134 |
} |
|
|
135 |
|
|
|
136 |
$search_for = array(); |
|
|
137 |
foreach ($table_array AS $table => $table_sortkey) { |
|
|
138 |
$search_for[] = "'" . PMA_sqlAddslashes($table) . "'"; |
|
|
139 |
} |
|
|
140 |
|
|
|
141 |
$query = 'SELECT label, query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) |
|
|
142 |
. ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' |
|
|
143 |
. (count($search_for) > 0 ? ' AND label IN (' . implode(', ', $search_for) . ')' : ''); |
|
|
144 |
$result = PMA_DBI_try_query($query, $controllink, PMA_DBI_QUERY_STORE); |
|
|
145 |
if (!$result || PMA_DBI_num_rows($result) < 1) { |
|
|
146 |
return $bookmarks; |
|
|
147 |
} |
|
|
148 |
while ($row = PMA_DBI_fetch_assoc($result)) { |
|
|
149 |
$bookmarks[$row['label']] = $row['query']; |
|
|
150 |
} |
|
|
151 |
|
|
|
152 |
return $bookmarks; |
|
|
153 |
} // end of the 'PMA_queryBookmarks()' function |
|
|
154 |
|
|
|
155 |
/** |
|
|
156 |
* Adds a bookmark |
|
|
157 |
* |
|
|
158 |
* @global resource the controluser db connection handle |
|
|
159 |
* |
|
|
160 |
* @param array the properties of the bookmark to add |
|
|
161 |
* @param array the bookmark parameters for the current user |
|
|
162 |
* @param boolean whether to make the bookmark available for all users |
|
|
163 |
* |
|
|
164 |
* @return boolean whether the INSERT succeeds or not |
|
|
165 |
* |
|
|
166 |
* @access public |
|
|
167 |
*/ |
|
|
168 |
function PMA_addBookmarks($fields, $cfgBookmark, $all_users = false) |
|
|
169 |
{ |
|
|
170 |
global $controllink; |
|
|
171 |
|
|
|
172 |
$query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) |
|
|
173 |
. ' (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']) . '\')'; |
|
|
174 |
$result = PMA_DBI_query($query, $controllink); |
|
|
175 |
|
|
|
176 |
return TRUE; |
|
|
177 |
} // end of the 'PMA_addBookmarks()' function |
|
|
178 |
|
|
|
179 |
|
|
|
180 |
/** |
|
|
181 |
* Deletes a bookmark |
|
|
182 |
* |
|
|
183 |
* @global resource the controluser db connection handle |
|
|
184 |
* |
|
|
185 |
* @param string the current database name |
|
|
186 |
* @param array the bookmark parameters for the current user |
|
|
187 |
* @param integer the id of the bookmark to get |
|
|
188 |
* |
|
|
189 |
* @access public |
|
|
190 |
*/ |
|
|
191 |
function PMA_deleteBookmarks($db, $cfgBookmark, $id) |
|
|
192 |
{ |
|
|
193 |
global $controllink; |
|
|
194 |
|
|
|
195 |
$query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) |
|
|
196 |
. ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' |
|
|
197 |
. ' OR user = \'\')' |
|
|
198 |
. ' AND id = ' . $id; |
|
|
199 |
$result = PMA_DBI_try_query($query, $controllink); |
|
|
200 |
} // end of the 'PMA_deleteBookmarks()' function |
|
|
201 |
|
|
|
202 |
|
|
|
203 |
/** |
|
|
204 |
* Bookmark Support |
|
|
205 |
*/ |
|
|
206 |
$cfg['Bookmark'] = PMA_getBookmarksParam(); |
|
|
207 |
|
|
|
208 |
?> |