home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phptriad / phptriad2-2-1.exe / htdocs / phpmyadmin / libraries / bookmark.lib.php next >
PHP Script  |  2002-01-06  |  5KB  |  159 lines

  1. <?php
  2. /* $Id: bookmark.lib.php,v 1.3 2001/11/23 01:04:57 loic1 Exp $ */
  3.  
  4.  
  5. /**
  6.  * Set of functions used with the bookmark feature
  7.  */
  8.  
  9.  
  10.  
  11. if (!defined('PMA_BOOKMARK_LIB_INCLUDED')){
  12.     define('PMA_BOOKMARK_LIB_INCLUDED', 1);
  13.  
  14.     /**
  15.      * Defines the bookmark parameters for the current user
  16.      *
  17.      * @return  array    the bookmark parameters for the current user
  18.      *
  19.      * @global  array    the list of settings for the current server
  20.      * @global  integer  the id of the current server
  21.      *
  22.      * @access  public
  23.      */
  24.     function PMA_getBookmarksParam()
  25.     {
  26.         global $cfgServer;
  27.         global $server;
  28.  
  29.         $cfgBookmark = '';
  30.  
  31.         // No server selected -> no bookmark table
  32.         if ($server == 0) {
  33.             return '';
  34.         }
  35.  
  36.         $cfgBookmark['user']  = $cfgServer['user'];
  37.         $cfgBookmark['db']    = $cfgServer['bookmarkdb'];
  38.         $cfgBookmark['table'] = $cfgServer['bookmarktable'];
  39.  
  40.         return $cfgBookmark;
  41.     } // end of the 'PMA_getBookmarksParam()' function
  42.  
  43.  
  44.     /**
  45.      * Gets the list of bookmarks defined for the current database
  46.      *
  47.      * @param   string   the current database name
  48.      * @param   array    the bookmark parameters for the current user
  49.      *
  50.      * @return  mixed    the bookmarks list if defined, false else
  51.      *
  52.      * @access  public
  53.      */
  54.     function PMA_listBookmarks($db, $cfgBookmark)
  55.     {
  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);
  63.         }
  64.  
  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;
  73.         }
  74.         // No bookmarks for the current database
  75.         else {
  76.             return FALSE;
  77.         }
  78.     } // end of the 'PMA_listBookmarks()' function
  79.  
  80.  
  81.     /**
  82.      * Gets the sql command from a bookmark
  83.      *
  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
  87.      *
  88.      * @return  string   the sql query
  89.      *
  90.      * @access  public
  91.      */
  92.     function PMA_queryBookmarks($db, $cfgBookmark, $id)
  93.     {
  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);
  102.         }
  103.         $bookmark_query = mysql_result($result, 0, 'query');
  104.  
  105.         return $bookmark_query;
  106.     } // end of the 'PMA_queryBookmarks()' function
  107.  
  108.  
  109.     /**
  110.      * Adds a bookmark
  111.      *
  112.      * @param   array    the properties of the bookmark to add
  113.      * @param   array    the bookmark parameters for the current user
  114.      *
  115.      * @access  public
  116.      */
  117.     function PMA_addBookmarks($fields, $cfgBookmark)
  118.     {
  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);
  125.         }
  126.     } // end of the 'PMA_addBookmarks()' function
  127.  
  128.  
  129.     /**
  130.      * Deletes a bookmark
  131.      *
  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
  135.      *
  136.      * @access  public
  137.      */
  138.     function PMA_deleteBookmarks($db, $cfgBookmark, $id)
  139.     {
  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);
  147.         }
  148.     } // end of the 'PMA_deleteBookmarks()' function
  149.  
  150.  
  151.     /**
  152.      * Bookmark Support
  153.      */
  154.     $cfgBookmark = PMA_getBookmarksParam();
  155.  
  156.  
  157. } // $__PMA_BOOKMARK_LIB__
  158. ?>
  159.