[ Index ] |
|
Code source de phpMyAdmin 2.10.3 |
1 <?php 2 /* $Id: bookmark.lib.php 9763 2006-11-26 10:57:48Z lem9 $ */ 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 if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) { 55 return ''; 56 } 57 58 $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) 59 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' 60 . ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' 61 . ' OR user = \'\')' 62 . ' ORDER BY label'; 63 $result = PMA_DBI_query($query, $controllink, PMA_DBI_QUERY_STORE); 64 65 // There are some bookmarks -> store them 66 // use the unique id as the key 67 if ($result && PMA_DBI_num_rows($result) > 0) { 68 while ($row = PMA_DBI_fetch_row($result)) { 69 $bookmark_list[$row[1]] = $row[0]; 70 } // end while 71 return $bookmark_list; 72 } 73 // No bookmarks for the current database 74 else { 75 return FALSE; 76 } 77 } // end of the 'PMA_listBookmarks()' function 78 79 80 /** 81 * Gets the sql command from a bookmark 82 * 83 * @global resource the controluser db connection handle 84 * 85 * @param string the current database name 86 * @param array the bookmark parameters for the current user 87 * @param mixed the id of the bookmark to get 88 * @param string which field to look up the $id 89 * @param boolean TRUE: get all bookmarks regardless of the owning user 90 * 91 * @return string the sql query 92 * 93 * @access public 94 */ 95 function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id', $action_bookmark_all = FALSE) 96 { 97 global $controllink; 98 99 if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) { 100 return ''; 101 } 102 103 $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) 104 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' 105 . ($action_bookmark_all? '' : ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' 106 . ' OR user = \'\')' ) 107 . ' AND ' . PMA_backquote($id_field) . ' = ' . $id; 108 $result = PMA_DBI_try_query($query, $controllink); 109 if (!$result) { 110 return FALSE; 111 } 112 list($bookmark_query) = PMA_DBI_fetch_row($result) or array(FALSE); 113 114 return $bookmark_query; 115 } // end of the 'PMA_queryBookmarks()' function 116 117 118 /** 119 * Gets bookmarked DefaultQuery for a Table 120 * 121 * @global resource the controluser db connection handle 122 * 123 * @param string the current database name 124 * @param array the bookmark parameters for the current user 125 * @param array the list of all labels to look for 126 * 127 * @return array bookmark SQL statements 128 * 129 * @access public 130 */ 131 function &PMA_queryDBBookmarks($db, $cfgBookmark, &$table_array) 132 { 133 global $controllink; 134 $bookmarks = array(); 135 136 if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) { 137 return $bookmarks; 138 } 139 140 $search_for = array(); 141 foreach ($table_array AS $table => $table_sortkey) { 142 $search_for[] = "'" . PMA_sqlAddslashes($table) . "'"; 143 } 144 145 $query = 'SELECT label, query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) 146 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' 147 . (count($search_for) > 0 ? ' AND label IN (' . implode(', ', $search_for) . ')' : ''); 148 $result = PMA_DBI_try_query($query, $controllink, PMA_DBI_QUERY_STORE); 149 if (!$result || PMA_DBI_num_rows($result) < 1) { 150 return $bookmarks; 151 } 152 while ($row = PMA_DBI_fetch_assoc($result)) { 153 $bookmarks[$row['label']] = $row['query']; 154 } 155 156 return $bookmarks; 157 } // end of the 'PMA_queryBookmarks()' function 158 159 /** 160 * Adds a bookmark 161 * 162 * @global resource the controluser db connection handle 163 * 164 * @param array the properties of the bookmark to add 165 * @param array the bookmark parameters for the current user 166 * @param boolean whether to make the bookmark available for all users 167 * 168 * @return boolean whether the INSERT succeeds or not 169 * 170 * @access public 171 */ 172 function PMA_addBookmarks($fields, $cfgBookmark, $all_users = false) 173 { 174 global $controllink; 175 176 $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) 177 . ' (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']) . '\')'; 178 $result = PMA_DBI_query($query, $controllink); 179 180 return TRUE; 181 } // end of the 'PMA_addBookmarks()' function 182 183 184 /** 185 * Deletes a bookmark 186 * 187 * @global resource the controluser db connection handle 188 * 189 * @param string the current database name 190 * @param array the bookmark parameters for the current user 191 * @param integer the id of the bookmark to get 192 * 193 * @access public 194 */ 195 function PMA_deleteBookmarks($db, $cfgBookmark, $id) 196 { 197 global $controllink; 198 199 $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) 200 . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' 201 . ' OR user = \'\')' 202 . ' AND id = ' . $id; 203 $result = PMA_DBI_try_query($query, $controllink); 204 } // end of the 'PMA_deleteBookmarks()' function 205 206 207 /** 208 * Bookmark Support 209 */ 210 211 if (! isset($GLOBALS['cfgRelation'])) { 212 require_once './libraries/relation.lib.php'; 213 $GLOBALS['cfgRelation'] = PMA_getRelationsParam(); 214 } 215 216 if ($GLOBALS['cfgRelation']['bookmarkwork']) { 217 $cfg['Bookmark'] = PMA_getBookmarksParam(); 218 } else { 219 $cfg['Bookmark'] = array(); 220 } 221 222 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 15:18:20 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |