2.2.4
[phpmyadmin/arisferyanto.git] / libraries / bookmark.lib.php3
blob00bba5807fb47476359bc849ce30254bda7146e2
1 <?php
2 /* $Id$ */
5 /**
6 * Set of functions used with the bookmark feature
7 */
11 if (!defined('PMA_BOOKMARK_LIB_INCLUDED')){
12 define('PMA_BOOKMARK_LIB_INCLUDED', 1);
14 /**
15 * Defines the bookmark parameters for the current user
17 * @return array the bookmark parameters for the current user
19 * @global array the list of settings for the current server
20 * @global integer the id of the current server
22 * @access public
24 function PMA_getBookmarksParam()
26 global $cfgServer;
27 global $server;
29 $cfgBookmark = '';
31 // No server selected -> no bookmark table
32 if ($server == 0) {
33 return '';
36 $cfgBookmark['user'] = $cfgServer['user'];
37 $cfgBookmark['db'] = $cfgServer['bookmarkdb'];
38 $cfgBookmark['table'] = $cfgServer['bookmarktable'];
40 return $cfgBookmark;
41 } // end of the 'PMA_getBookmarksParam()' function
44 /**
45 * Gets the list of bookmarks defined for the current database
47 * @param string the current database name
48 * @param array the bookmark parameters for the current user
50 * @return mixed the bookmarks list if defined, false else
52 * @access public
54 function PMA_listBookmarks($db, $cfgBookmark)
56 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
57 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
58 . ' AND user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'';
59 if (isset($GLOBALS['dbh'])) {
60 $result = mysql_query($query, $GLOBALS['dbh']);
61 } else {
62 $result = mysql_query($query);
65 // There is some bookmarks -> store them
66 if ($result > 0 && mysql_num_rows($result) > 0) {
67 $flag = 1;
68 while ($row = mysql_fetch_row($result)) {
69 $bookmark_list[$flag . ' - ' . $row[0]] = $row[1];
70 $flag++;
71 } // end while
72 return $bookmark_list;
74 // No bookmarks for the current database
75 else {
76 return FALSE;
78 } // end of the 'PMA_listBookmarks()' function
81 /**
82 * Gets the sql command from a bookmark
84 * @param string the current database name
85 * @param array the bookmark parameters for the current user
86 * @param integer the id of the bookmark to get
88 * @return string the sql query
90 * @access public
92 function PMA_queryBookmarks($db, $cfgBookmark, $id)
94 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
95 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\''
96 . ' AND user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
97 . ' AND id = ' . $id;
98 if (isset($GLOBALS['dbh'])) {
99 $result = mysql_query($query, $GLOBALS['dbh']);
100 } else {
101 $result = mysql_query($query);
103 $bookmark_query = mysql_result($result, 0, 'query');
105 return $bookmark_query;
106 } // end of the 'PMA_queryBookmarks()' function
110 * Adds a bookmark
112 * @param array the properties of the bookmark to add
113 * @param array the bookmark parameters for the current user
115 * @access public
117 function PMA_addBookmarks($fields, $cfgBookmark)
119 $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
120 . ' (id, dbase, user, query, label) VALUES (\'\', \'' . PMA_sqlAddslashes($fields['dbase']) . '\', \'' . PMA_sqlAddslashes($fields['user']) . '\', \'' . PMA_sqlAddslashes(urldecode($fields['query'])) . '\', \'' . PMA_sqlAddslashes($fields['label']) . '\')';
121 if (isset($GLOBALS['dbh'])) {
122 $result = mysql_query($query, $GLOBALS['dbh']);
123 } else {
124 $result = mysql_query($query);
126 } // end of the 'PMA_addBookmarks()' function
130 * Deletes a bookmark
132 * @param string the current database name
133 * @param array the bookmark parameters for the current user
134 * @param integer the id of the bookmark to get
136 * @access public
138 function PMA_deleteBookmarks($db, $cfgBookmark, $id)
140 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table'])
141 . ' WHERE user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\''
142 . ' AND id = ' . $id;
143 if (isset($GLOBALS['dbh'])) {
144 $result = mysql_query($query, $GLOBALS['dbh']);
145 } else {
146 $result = mysql_query($query);
148 } // end of the 'PMA_deleteBookmarks()' function
152 * Bookmark Support
154 $cfgBookmark = PMA_getBookmarksParam();
157 } // $__PMA_BOOKMARK_LIB__