⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 relation.lib.php

📁 架設ROSE私服必備之物 ROSE數據庫
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php/* $Id: relation.lib.php 8677 2006-02-24 20:31:45Z lem9 $ */// vim: expandtab sw=4 ts=4 sts=4:require_once './libraries/Table.class.php';/** * Set of functions used with the relation and pdf feature *//** * Executes a query as controluser if possible, otherwise as normal user * * @param   string    the query to execute * @param   boolean   whether to display SQL error messages or not * * @return  integer   the result id * * @global  string    the URL of the page to show in case of error * @global  string    the name of db to come back to * @global  resource  the resource id of DB connect as controluser * @global  array     configuration infos about the relations stuff * * @access  public * * @author  Mike Beck <mikebeck@users.sourceforge.net> */ function PMA_query_as_cu($sql, $show_error = true, $options = 0) {    global $db, $controllink, $cfgRelation;    // Comparing resource ids works on PHP 5 because, when no controluser    // is defined, connecting with the same user for controllink does    // not create a new connection. However a new connection is created    // on PHP 4, so we cannot directly compare resource ids.    if ($controllink == $GLOBALS['userlink'] || PMA_MYSQL_INT_VERSION < 50000) {        PMA_DBI_select_db($cfgRelation['db'], $controllink);    }    if ($show_error) {        $result = PMA_DBI_query($sql, $controllink, $options);    } else {        $result = @PMA_DBI_try_query($sql, $controllink, $options);    } // end if... else...    // It makes no sense to restore database on control user    if ($controllink == $GLOBALS['userlink'] || PMA_MYSQL_INT_VERSION < 50000) {        PMA_DBI_select_db($db, $controllink);    }    if ($result) {        return $result;    } else {        return false;    } } // end of the "PMA_query_as_cu()" function/** * Defines the relation parameters for the current user * just a copy of the functions used for relations ;-) * but added some stuff to check what will work * * @param   boolean  whether to check validity of settings or not * * @return  array    the relation parameters for the current user * * @global  array    the list of settings for servers * @global  integer  the id of the current server * @global  string   the URL of the page to show in case of error * @global  string   the name of the current db * @global  string   the name of the current table * @global  array    configuration infos about the relations stuff * * @access  public * * @author  Mike Beck <mikebeck@users.sourceforge.net> */function PMA_getRelationsParam($verbose = false){    global $cfg, $server, $controllink, $cfgRelation;    $cfgRelation                = array();    $cfgRelation['relwork']     = false;    $cfgRelation['displaywork'] = false;    $cfgRelation['bookmarkwork']= false;    $cfgRelation['pdfwork']     = false;    $cfgRelation['commwork']    = false;    $cfgRelation['mimework']    = false;    $cfgRelation['historywork'] = false;    $cfgRelation['allworks']    = false;    // No server selected -> no bookmark table    // we return the array with the falses in it,    // to avoid some 'Unitialized string offset' errors later    if ($server == 0 || empty($cfg['Server']) || empty($cfg['Server']['pmadb'])      || ! PMA_DBI_select_db($cfg['Server']['pmadb'], $controllink)) {        if ($verbose == true) {            echo 'PMA Database ... '                 . '<font color="red"><b>' . $GLOBALS['strNotOK'] . '</b></font>'                 . '[ <a href="Documentation.html#pmadb">' . $GLOBALS['strDocu']                 . '</a> ]<br />' . "\n"                 . $GLOBALS['strGeneralRelationFeat']                 . ' <font color="green">' . $GLOBALS['strDisabled']                 . '</font>' . "\n";        }        $cfg['Server']['pmadb'] = false;        return $cfgRelation;    }    $cfgRelation['user']  = $cfg['Server']['user'];    $cfgRelation['db']    = $cfg['Server']['pmadb'];    //  Now I just check if all tables that i need are present so I can for    //  example enable relations but not pdf...    //  I was thinking of checking if they have all required columns but I    //  fear it might be too slow    $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($cfgRelation['db']);    $tab_rs    = PMA_query_as_cu($tab_query, false, PMA_DBI_QUERY_STORE);    if ($tab_rs) {        while ($curr_table = @PMA_DBI_fetch_row($tab_rs)) {            if ($curr_table[0] == $cfg['Server']['bookmarktable']) {                $cfgRelation['bookmark']        = $curr_table[0];            } elseif ($curr_table[0] == $cfg['Server']['relation']) {                $cfgRelation['relation']        = $curr_table[0];            } elseif ($curr_table[0] == $cfg['Server']['table_info']) {                $cfgRelation['table_info']      = $curr_table[0];            } elseif ($curr_table[0] == $cfg['Server']['table_coords']) {                $cfgRelation['table_coords']    = $curr_table[0];            } elseif ($curr_table[0] == $cfg['Server']['column_info']) {                $cfgRelation['column_info'] = $curr_table[0];            } elseif ($curr_table[0] == $cfg['Server']['pdf_pages']) {                $cfgRelation['pdf_pages']       = $curr_table[0];            } elseif ($curr_table[0] == $cfg['Server']['history']) {                $cfgRelation['history'] = $curr_table[0];            }        } // end while        PMA_DBI_free_result($tab_rs);    } else {        $cfg['Server']['pmadb'] = false;    }    if (isset($cfgRelation['relation'])) {        $cfgRelation['relwork']         = true;        if (isset($cfgRelation['table_info'])) {                $cfgRelation['displaywork'] = true;        }    }    if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) {        $cfgRelation['pdfwork']     = true;    }    if (isset($cfgRelation['column_info'])) {        $cfgRelation['commwork']    = true;        if ($cfg['Server']['verbose_check']) {            $mime_query  = 'SHOW FIELDS FROM '                . PMA_backquote($cfgRelation['db']) . '.'                . PMA_backquote($cfgRelation['column_info']);            $mime_rs     = PMA_query_as_cu($mime_query, false);            $mime_field_mimetype                = false;            $mime_field_transformation          = false;            $mime_field_transformation_options  = false;            while ($curr_mime_field = @PMA_DBI_fetch_row($mime_rs)) {                if ($curr_mime_field[0] == 'mimetype') {                    $mime_field_mimetype               = true;                } elseif ($curr_mime_field[0] == 'transformation') {                    $mime_field_transformation         = true;                } elseif ($curr_mime_field[0] == 'transformation_options') {                    $mime_field_transformation_options = true;                }            }            PMA_DBI_free_result($mime_rs);            if ($mime_field_mimetype == true                && $mime_field_transformation == true                && $mime_field_transformation_options == true) {                $cfgRelation['mimework'] = true;            }        } else {            $cfgRelation['mimework'] = true;        }    }    if (isset($cfgRelation['history'])) {        $cfgRelation['historywork']     = true;    }    if (isset($cfgRelation['bookmark'])) {        $cfgRelation['bookmarkwork']     = true;    }    if ($cfgRelation['relwork'] == true && $cfgRelation['displaywork'] == true        && $cfgRelation['pdfwork'] == true && $cfgRelation['commwork'] == true        && $cfgRelation['mimework'] == true && $cfgRelation['historywork'] == true        && $cfgRelation['bookmarkwork'] == true) {        $cfgRelation['allworks'] = true;    }    if ($verbose == true) {        $shit     = '<font color="red"><b>' . $GLOBALS['strNotOK']            . '</b></font> [ <a href="Documentation.html#%s">'            . $GLOBALS['strDocu'] . '</a> ]';        $hit      = '<font color="green"><b>' . $GLOBALS['strOK'] . '</b></font>';        $enabled  = '<font color="green">' . $GLOBALS['strEnabled'] . '</font>';        $disabled = '<font color="red">'   . $GLOBALS['strDisabled'] . '</font>';        echo '<table>' . "\n";        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'pmadb\'] ... </th><td align="right">'             . (($cfg['Server']['pmadb'] == false) ? sprintf($shit, 'pmadb') : $hit)             . '</td></tr>' . "\n";        echo '    <tr><td>&nbsp;</td></tr>' . "\n";        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'relation\'] ... </th><td align="right">'             . ((isset($cfgRelation['relation'])) ? $hit : sprintf($shit, 'relation'))             . '</td></tr>' . "\n";        echo '    <tr><td colspan=2 align="center">'. $GLOBALS['strGeneralRelationFeat'] . ': '             . (($cfgRelation['relwork'] == true) ? $enabled :  $disabled)             . '</td></tr>' . "\n";        echo '    <tr><td>&nbsp;</td></tr>' . "\n";        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'table_info\']   ... </th><td align="right">'             . (($cfgRelation['displaywork'] == false) ? sprintf($shit, 'table_info') : $hit)             . '</td></tr>' . "\n";        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strDisplayFeat'] . ': '             . (($cfgRelation['displaywork'] == true) ? $enabled : $disabled)             . '</td></tr>' . "\n";        echo '    <tr><td>&nbsp;</td></tr>' . "\n";        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'table_coords\'] ... </th><td align="right">'             . ((isset($cfgRelation['table_coords'])) ? $hit : sprintf($shit, 'table_coords'))             . '</td></tr>' . "\n";        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'pdf_pages\'] ... </th><td align="right">'             . ((isset($cfgRelation['pdf_pages'])) ? $hit : sprintf($shit, 'table_coords'))             . '</td></tr>' . "\n";        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strCreatePdfFeat'] . ': '             . (($cfgRelation['pdfwork'] == true) ? $enabled : $disabled)             . '</td></tr>' . "\n";        echo '    <tr><td>&nbsp;</td></tr>' . "\n";        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'column_info\'] ... </th><td align="right">'             . ((isset($cfgRelation['column_info'])) ? $hit : sprintf($shit, 'col_com'))             . '</td></tr>' . "\n";        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strColComFeat'] . ': '             . (($cfgRelation['commwork'] == true) ? $enabled : $disabled)             . '</td></tr>' . "\n";        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strBookmarkQuery'] . ': '             . (($cfgRelation['bookmarkwork'] == true) ? $enabled : $disabled)             . '</td></tr>' . "\n";        echo '    <tr><th align="left">MIME ...</th><td align="right">'             . (($cfgRelation['mimework'] == true) ? $hit : sprintf($shit, 'col_com'))             . '</td></tr>' . "\n";             if (($cfgRelation['commwork'] == true) && ($cfgRelation['mimework'] != true)) {                 echo '<tr><td colspan=2 align="left">' . $GLOBALS['strUpdComTab'] . '</td></tr>' . "\n";             }        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'history\'] ... </th><td align="right">'             . ((isset($cfgRelation['history'])) ? $hit : sprintf($shit, 'history'))             . '</td></tr>' . "\n";        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strQuerySQLHistory'] . ': '             . (($cfgRelation['historywork'] == true) ? $enabled : $disabled)             . '</td></tr>' . "\n";        echo '</table>' . "\n";    } // end if ($verbose == true) {    return $cfgRelation;} // end of the 'PMA_getRelationsParam()' function/** * Gets all Relations to foreign tables for a given table or * optionally a given column in a table * * @param   string   the name of the db to check for * @param   string   the name of the table to check for * @param   string   the name of the column to check for * @param   string   the source for foreign key information * * @return  array    db,table,column * * @global  array    the list of relations settings * @global  string   the URL of the page to show in case of error * * @access  public * * @author  Mike Beck <mikebeck@users.sourceforge.net> and Marc Delisle */function PMA_getForeigners($db, $table, $column = '', $source = 'both') {    global $cfgRelation;    if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {        $rel_query = '             SELECT master_field,                    foreign_db,                    foreign_table,                    foreign_field               FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '              WHERE master_db =  \'' . PMA_sqlAddslashes($db) . '\'                AND master_table = \'' . PMA_sqlAddslashes($table) . '\' ';        if (isset($column) && strlen($column)) {            $rel_query .= ' AND   master_field = \'' . PMA_sqlAddslashes($column) . '\'';        }        $relations     = PMA_query_as_cu($rel_query);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -