function getPage($id) { global $cfg; switch ($id) { case 'bufferpool': if (PMA_MYSQL_INT_VERSION < 50002) { return FALSE; } // rabus: The following query is only possible because we know // that we are on MySQL 5 here (checked above)! // side note: I love MySQL 5 for this. :-) $res = PMA_DBI_query('SHOW STATUS WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\' OR Variable_name = \'Innodb_page_size\';'); $status = array(); while ($row = PMA_DBI_fetch_row($res)) { $status[$row[0]] = $row[1]; } PMA_DBI_free_result($res); unset($res, $row); $output = '<table>' . "\n" . ' <thead>' . "\n" . ' <tr>' . "\n" . ' <th colspan="4">' . "\n" . ' ' . $GLOBALS['strBufferPoolUsage'] . "\n" . ' </th>' . "\n" . ' </tr>' . "\n" . ' </thead>' . "\n" . ' <tfoot>' . "\n" . ' <tr>' . "\n" . ' <th>' . "\n" . ' ' . $GLOBALS['strTotalUC'] . "\n" . ' </th>' . "\n" . ' <th colspan="3">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_pages_total']) . ' ' . $GLOBALS['strInnoDBPages'] . ' / ' . join(' ', PMA_formatByteDown($status['Innodb_buffer_pool_pages_total'] * $status['Innodb_page_size'])) . "\n" . ' </th>' . "\n" . ' </tr>' . "\n" . ' </tfoot>' . "\n" . ' <tbody>' . "\n" . ' <tr>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . $GLOBALS['strFreePages'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_pages_free']) . "\n" . ' </td>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . $GLOBALS['strDirtyPages'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_pages_dirty']) . "\n" . ' </td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . $GLOBALS['strDataPages'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_pages_data']) . "\n" . ' </td>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . $GLOBALS['strPagesToBeFlushed'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_pages_flushed']) . "\n" . ' </td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . $GLOBALS['strBusyPages'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_pages_misc']) . "\n" . ' </td>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . $GLOBALS['strLatchedPages'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_pages_latched']) . "\n" . ' </td>' . "\n" . ' </tr>' . "\n" . ' </tbody>' . "\n" . '</table>' . "\n\n" . '<br />' . "\n\n" . '<table>' . "\n" . ' <thead>' . "\n" . ' <tr>' . "\n" . ' <th colspan="4">' . "\n" . ' ' . $GLOBALS['strBufferPoolActivity'] . "\n" . ' </th>' . "\n" . ' </tr>' . "\n" . ' </thead>' . "\n" . ' <tbody>' . "\n" . ' <tr>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . $GLOBALS['strReadRequests'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_read_requests']) . "\n" . ' </td>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . $GLOBALS['strWriteRequests'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_write_requests']) . "\n" . ' </td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . $GLOBALS['strBufferReadMisses'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_reads']) . "\n" . ' </td>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . $GLOBALS['strBufferWriteWaits'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . htmlspecialchars($status['Innodb_buffer_pool_wait_free']) . "\n" . ' </td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . $GLOBALS['strBufferReadMissesInPercent'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . ($status['Innodb_buffer_pool_read_requests'] == 0 ? '---' : htmlspecialchars(number_format($status['Innodb_buffer_pool_reads'] * 100 / $status['Innodb_buffer_pool_read_requests'], 2, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator'])) . ' %') . "\n" . ' </td>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . ' ' . $GLOBALS['strBufferWriteWaitsInPercent'] . ' ' . "\n" . ' </td>' . "\n" . ' <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . ' ' . ($status['Innodb_buffer_pool_write_requests'] == 0 ? '---' : htmlspecialchars(number_format($status['Innodb_buffer_pool_wait_free'] * 100 / $status['Innodb_buffer_pool_write_requests'], 2, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator'])) . ' %') . "\n" . ' </td>' . "\n" . ' </tr>' . "\n" . ' </tbody>' . "\n" . '</table>' . "\n"; return $output; case 'status': $res = PMA_DBI_query('SHOW INNODB STATUS;'); $row = PMA_DBI_fetch_row($res); PMA_DBI_free_result($res); return '<pre>' . "\n" . htmlspecialchars($row[0]) . "\n" . '</pre>' . "\n"; default: return FALSE; } }
/** * Sets the import plugin properties. * Called in the constructor. * * @return void */ protected function setProperties() { if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') { $GLOBALS['cfg']['Import']['ldi_local_option'] = false; $result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';'); if ($result != false && PMA_DBI_num_rows($result) > 0) { $tmp = PMA_DBI_fetch_row($result); if ($tmp[1] == 'ON') { $GLOBALS['cfg']['Import']['ldi_local_option'] = true; } } PMA_DBI_free_result($result); unset($result); } $generalOptions = parent::setProperties(); $this->properties->setText('CSV using LOAD DATA'); $this->properties->setExtension('ldi'); $leaf = new TextPropertyItem(); $leaf->setName("columns"); $leaf->setText(__('Column names: ')); $generalOptions->addProperty($leaf); $leaf = new BoolPropertyItem(); $leaf->setName("ignore"); $leaf->setText(__('Do not abort on INSERT error')); $generalOptions->addProperty($leaf); $leaf = new BoolPropertyItem(); $leaf->setName("local_option"); $leaf->setText(__('Use LOCAL keyword')); $generalOptions->addProperty($leaf); }
function PMA_analyseShowGrant($rs_usr, &$is_create_priv, &$db_to_create, &$is_reload_priv) { $re0 = '(^|(\\\\\\\\)+|[^\\])'; // non-escaped wildcards $re1 = '(^|[^\\])(\\\\)+'; // escaped wildcards while ($row = PMA_DBI_fetch_row($rs_usr)) { $show_grants_dbname = substr($row[0], strpos($row[0], ' ON ') + 4, strpos($row[0], '.', strpos($row[0], ' ON ')) - strpos($row[0], ' ON ') - 4); $show_grants_dbname = ereg_replace('^`(.*)`', '\\1', $show_grants_dbname); $show_grants_str = substr($row[0], 6, strpos($row[0], ' ON ') - 6); if ($show_grants_str == 'ALL' || $show_grants_str == 'ALL PRIVILEGES' || $show_grants_str == 'CREATE' || strpos($show_grants_str, 'CREATE')) { if ($show_grants_dbname == '*') { $is_create_priv = TRUE; $is_reload_priv = TRUE; $db_to_create = ''; break; } else { if (ereg($re0 . '%|_', $show_grants_dbname) && !ereg('\\\\%|\\\\_', $show_grants_dbname) || !PMA_DBI_try_query('USE ' . ereg_replace($re1 . '(%|_)', '\\1\\3', $show_grants_dbname)) && substr(PMA_DBI_getError(), 1, 4) != 1044) { $db_to_create = ereg_replace($re0 . '%', '\\1...', ereg_replace($re0 . '_', '\\1?', $show_grants_dbname)); $db_to_create = ereg_replace($re1 . '(%|_)', '\\1\\3', $db_to_create); $is_create_priv = TRUE; break; } } // end elseif } // end if } // end while }
function PMA_generateEngineDetails($variables, $like = NULL, $indent = 0) { global $cfg; $spaces = ''; for ($i = 0; $i < $indent; $i++) { $spaces .= ' '; } /** * Get the variables! */ if (!empty($variables)) { $sql_query = 'SHOW ' . (PMA_MYSQL_INT_VERSION >= 40102 ? 'GLOBAL ' : '') . 'VARIABLES' . (empty($like) ? '' : ' LIKE \'' . $like . '\'') . ';'; $res = PMA_DBI_query($sql_query); $mysql_vars = array(); while ($row = PMA_DBI_fetch_row($res)) { if (isset($variables[$row[0]])) { $mysql_vars[$row[0]] = $row[1]; } } PMA_DBI_free_result($res); unset($res, $row, $sql_query); } if (empty($mysql_vars)) { return $spaces . '<p>' . "\n" . $spaces . ' ' . $GLOBALS['strNoDetailsForEngine'] . "\n" . $spaces . '</p>' . "\n"; } $dt_table = $spaces . '<table>' . "\n"; $useBgcolorOne = TRUE; $has_content = FALSE; foreach ($variables as $var => $details) { if (!isset($mysql_vars[$var])) { continue; } if (!isset($details['type'])) { $details['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT; } $is_num = $details['type'] == PMA_ENGINE_DETAILS_TYPE_SIZE || $details['type'] == PMA_ENGINE_DETAILS_TYPE_NUMERIC; $bgcolor = $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; $dt_table .= $spaces . ' <tr>' . "\n" . $spaces . ' <td bgcolor="' . $bgcolor . '">' . "\n"; if (!empty($variables[$var]['desc'])) { $dt_table .= $spaces . ' ' . PMA_showHint($details['desc']) . "\n"; } $dt_table .= $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $bgcolor . '">' . "\n" . $spaces . ' ' . $details['title'] . ' ' . "\n" . $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $bgcolor . '"' . ($is_num ? ' align="right"' : '') . '>' . "\n" . $spaces . ' '; switch ($details['type']) { case PMA_ENGINE_DETAILS_TYPE_SIZE: $parsed_size = PMA_formatByteDown($mysql_vars[$var]); $dt_table .= $parsed_size[0] . ' ' . $parsed_size[1]; unset($parsed_size); break; default: $dt_table .= htmlspecialchars($mysql_vars[$var]); } $dt_table .= ' ' . "\n" . $spaces . ' </td>' . "\n" . $spaces . ' </tr>' . "\n"; $useBgcolorOne = !$useBgcolorOne; $has_content = TRUE; } if (!$has_content) { return ''; } return $dt_table; }
/** * returns JavaScript code for intializing vars * * @return string JavaScript code */ function get_script_contr() { PMA_DBI_select_db($GLOBALS['db']); $con["C_NAME"] = array(); $i = 0; $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($GLOBALS['db']), null, PMA_DBI_QUERY_STORE); while ($val = @PMA_DBI_fetch_row($alltab_rs)) { $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal'); //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - "; //print_r($row); if ($row !== false) { foreach ($row as $field => $value) { $con['C_NAME'][$i] = ''; $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]); $con['DCN'][$i] = urlencode($field); $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']); $con['SCN'][$i] = urlencode($value['foreign_field']); $i++; } } $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign'); //echo "<br> INNO "; //print_r($row); if ($row !== false) { foreach ($row as $field => $value) { $con['C_NAME'][$i] = ''; $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]); $con['DCN'][$i] = urlencode($field); $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']); $con['SCN'][$i] = urlencode($value['foreign_field']); $i++; } } } $ti = 0; $script_contr = '<script type="text/javascript">' . "\n" . '// <![CDATA[' . "\n" . 'var contr = new Array();' . "\n"; for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) { $js_var = ' contr[' . $ti . ']'; $script_contr .= $js_var . " = new Array();\n"; $js_var .= "['" . $con['C_NAME'][$i] . "']"; $script_contr .= $js_var . " = new Array();\n"; if (in_array($con['DTN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"]) && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) { $js_var .= "['" . $con['DTN'][$i] . "']"; $script_contr .= $js_var . " = new Array();\n"; $m_col = array(); //} $js_var .= "['" . $con['DCN'][$i] . "']"; $script_contr .= $js_var . " = new Array();\n"; //} $script_contr .= $js_var . "[0] = '" . $con['STN'][$i] . "';\n"; // $script_contr .= $js_var . "[1] = '" . $con['SCN'][$i] . "';\n"; // } $ti++; } $script_contr .= '// ]]>' . "\n" . '</script>' . "\n"; return $script_contr; }
/** * Function for displaying the table of an engine's parameters * * @param array List of MySQL variables and corresponding localized descriptions. * The array elements should have the following format: * $variable => array('title' => $title, 'desc' => $description); * @param string Prefix for the SHOW VARIABLES query. * @return string The table that was generated based on the given information. */ function PMA_generateEngineDetails($variables, $like = null) { /** * Get the variables! */ if (!empty($variables)) { $sql_query = 'SHOW ' . (PMA_MYSQL_INT_VERSION >= 40102 ? 'GLOBAL ' : '') . 'VARIABLES' . (empty($like) ? '' : ' LIKE \'' . $like . '\'') . ';'; $res = PMA_DBI_query($sql_query); $mysql_vars = array(); while ($row = PMA_DBI_fetch_row($res)) { if (isset($variables[$row[0]])) { $mysql_vars[$row[0]] = $row[1]; } } PMA_DBI_free_result($res); unset($res, $row, $sql_query); } if (empty($mysql_vars)) { return '<p>' . "\n" . ' ' . $GLOBALS['strNoDetailsForEngine'] . "\n" . '</p>' . "\n"; } $dt_table = '<table class="data" cellspacing="1">' . "\n"; $odd_row = false; $has_content = false; foreach ($variables as $var => $details) { if (!isset($mysql_vars[$var])) { continue; } if (!isset($details['type'])) { $details['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT; } $is_num = $details['type'] == PMA_ENGINE_DETAILS_TYPE_SIZE || $details['type'] == PMA_ENGINE_DETAILS_TYPE_NUMERIC; $dt_table .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n" . ' <td>' . "\n"; if (!empty($variables[$var]['desc'])) { $dt_table .= ' ' . PMA_showHint($details['desc']) . "\n"; } $dt_table .= ' </td>' . "\n" . ' <th>' . htmlspecialchars(empty($details['title']) ? $var : $details['title']) . "\n" . ' </th>' . "\n" . ' <td class="value">'; switch ($details['type']) { case PMA_ENGINE_DETAILS_TYPE_SIZE: $parsed_size = PMA_formatByteDown($mysql_vars[$var]); $dt_table .= $parsed_size[0] . ' ' . $parsed_size[1]; unset($parsed_size); break; case PMA_ENGINE_DETAILS_TYPE_NUMERIC: $dt_table .= PMA_formatNumber($mysql_vars[$var]) . ' '; break; default: $dt_table .= htmlspecialchars($mysql_vars[$var]) . ' '; } $dt_table .= '</td>' . "\n" . '</tr>' . "\n"; $odd_row = !$odd_row; $has_content = true; } if (!$has_content) { return ''; } $dt_table .= '</table>' . "\n"; return $dt_table; }
function PMA_analyseShowGrant($rs_usr, &$is_create_db_priv, &$db_to_create, &$is_reload_priv, &$dbs_where_create_table_allowed) { $re0 = '(^|(\\\\\\\\)+|[^\\])'; // non-escaped wildcards $re1 = '(^|[^\\])(\\\\)+'; // escaped wildcards while ($row = PMA_DBI_fetch_row($rs_usr)) { $show_grants_dbname = substr($row[0], strpos($row[0], ' ON ') + 4, strpos($row[0], '.', strpos($row[0], ' ON ')) - strpos($row[0], ' ON ') - 4); $show_grants_dbname = ereg_replace('^`(.*)`', '\\1', $show_grants_dbname); $show_grants_str = substr($row[0], 6, strpos($row[0], ' ON ') - 6); if ($show_grants_str == 'RELOAD') { $is_reload_priv = true; } /** * @todo if we find CREATE VIEW but not CREATE, do not offer * the create database dialog box */ if ($show_grants_str == 'ALL' || $show_grants_str == 'ALL PRIVILEGES' || $show_grants_str == 'CREATE' || strpos($show_grants_str, 'CREATE,') !== false) { if ($show_grants_dbname == '*') { // a global CREATE privilege $is_create_db_priv = true; $is_reload_priv = true; $db_to_create = ''; $dbs_where_create_table_allowed[] = '*'; break; } else { // this array may contain wildcards $dbs_where_create_table_allowed[] = $show_grants_dbname; // before MySQL 4.1.0, we cannot use backquotes around a dbname // for the USE command, so the USE will fail if the dbname contains // a "-" and we cannot detect if such a db already exists; // since 4.1.0, we need to use backquotes if the dbname contains a "-" // in a USE command if (PMA_MYSQL_INT_VERSION > 40100) { $dbname_to_test = PMA_backquote($show_grants_dbname); } else { $dbname_to_test = $show_grants_dbname; } if (ereg($re0 . '%|_', $show_grants_dbname) && !ereg('\\\\%|\\\\_', $show_grants_dbname) || !PMA_DBI_try_query('USE ' . ereg_replace($re1 . '(%|_)', '\\1\\3', $dbname_to_test), null, PMA_DBI_QUERY_STORE) && substr(PMA_DBI_getError(), 1, 4) != 1044) { $db_to_create = ereg_replace($re0 . '%', '\\1...', ereg_replace($re0 . '_', '\\1?', $show_grants_dbname)); $db_to_create = ereg_replace($re1 . '(%|_)', '\\1\\3', $db_to_create); $is_create_db_priv = true; /** * @todo collect $db_to_create into an array, to display a * drop-down in the "Create new database" dialog */ // we don't break, we want all possible databases //break; } // end if } // end elseif } // end if } // end while }
function get_script_contr() { global $db; PMA_DBI_select_db($db); $con["C_NAME"] = array(); $i = 0; $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db), NULL, PMA_DBI_QUERY_STORE); while ($val = @PMA_DBI_fetch_row($alltab_rs)) { $row = PMA_getForeigners($db, $val[0], '', 'internal'); //echo "<br> internal ".$db." - ".$val[0]." - "; //print_r($row ); if ($row !== false) { foreach ($row as $field => $value) { $con['C_NAME'][$i] = ''; $con['DTN'][$i] = urlencode($db . "." . $val[0]); $con['DCN'][$i] = urlencode($field); $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']); $con['SCN'][$i] = urlencode($value['foreign_field']); $i++; } } $row = PMA_getForeigners($db, $val[0], '', 'innodb'); //echo "<br> INNO "; //print_r($row ); if ($row !== false) { foreach ($row as $field => $value) { $con['C_NAME'][$i] = ''; $con['DTN'][$i] = urlencode($db . "." . $val[0]); $con['DCN'][$i] = urlencode($field); $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']); $con['SCN'][$i] = urlencode($value['foreign_field']); $i++; } } } $ti = 0; $script_contr = "<script>\n var contr = new Array();\n"; for ($i = 0; $i < sizeof($con["C_NAME"]); $i++) { $script_contr .= " contr[{$ti}] = new Array();\n"; $script_contr .= " contr[{$ti}]['" . $con['C_NAME'][$i] . "'] = new Array();\n"; if (in_array($con['DTN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"]) && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) { $script_contr .= " contr[{$ti}]['" . $con['C_NAME'][$i] . "']['" . $con['DTN'][$i] . "'] = new Array();\n"; $m_col = array(); //} $script_contr .= " contr[{$ti}]['" . $con['C_NAME'][$i] . "']['" . $con['DTN'][$i] . "']['" . $con['DCN'][$i] . "'] = new Array();\n"; //} $script_contr .= " contr[{$ti}]['" . $con['C_NAME'][$i] . "']['" . $con['DTN'][$i] . "']['" . $con['DCN'][$i] . "'][0] = '" . $con['STN'][$i] . "';\n"; // $script_contr .= " contr[{$ti}]['" . $con['C_NAME'][$i] . "']['" . $con['DTN'][$i] . "']['" . $con['DCN'][$i] . "'][1] = '" . $con['SCN'][$i] . "';\n"; // } $ti++; } $script_contr .= "</script>\n"; return $script_contr; }
/** * returns JavaScript code for intializing vars * * @return string JavaScript code */ function get_script_contr() { PMA_DBI_select_db($GLOBALS['db']); $con["C_NAME"] = array(); $i = 0; $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_Util::backquote($GLOBALS['db']), null, PMA_DBI_QUERY_STORE); while ($val = @PMA_DBI_fetch_row($alltab_rs)) { $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal'); //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - "; //print_r($row); if ($row !== false) { foreach ($row as $field => $value) { $con['C_NAME'][$i] = ''; $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]); $con['DCN'][$i] = urlencode($field); $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']); $con['SCN'][$i] = urlencode($value['foreign_field']); $i++; } } $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign'); //echo "<br> INNO "; //print_r($row); if ($row !== false) { foreach ($row as $field => $value) { $con['C_NAME'][$i] = ''; $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]); $con['DCN'][$i] = urlencode($field); $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']); $con['SCN'][$i] = urlencode($value['foreign_field']); $i++; } } } $ti = 0; $retval = array(); for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) { $c_name_i = $con['C_NAME'][$i]; $dtn_i = $con['DTN'][$i]; $retval[$ti] = array(); $retval[$ti][$c_name_i] = array(); if (in_array($dtn_i, $GLOBALS['PMD_URL']["TABLE_NAME"]) && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) { $retval[$ti][$c_name_i][$dtn_i] = array(); $retval[$ti][$c_name_i][$dtn_i][$con['DCN'][$i]] = array(0 => $con['STN'][$i], 1 => $con['SCN'][$i]); } $ti++; } return $retval; }
/** * Sets the import plugin properties. * Called in the constructor. * * @return void */ protected function setProperties() { if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') { $GLOBALS['cfg']['Import']['ldi_local_option'] = false; $result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';'); if ($result != false && PMA_DBI_num_rows($result) > 0) { $tmp = PMA_DBI_fetch_row($result); if ($tmp[1] == 'ON') { $GLOBALS['cfg']['Import']['ldi_local_option'] = true; } } PMA_DBI_free_result($result); unset($result); } $props = 'libraries/properties/'; include_once "{$props}/plugins/ImportPluginProperties.class.php"; include_once "{$props}/options/groups/OptionsPropertyRootGroup.class.php"; include_once "{$props}/options/groups/OptionsPropertyMainGroup.class.php"; include_once "{$props}/options/items/BoolPropertyItem.class.php"; include_once "{$props}/options/items/TextPropertyItem.class.php"; $importPluginProperties = new ImportPluginProperties(); $importPluginProperties->setText('CSV using LOAD DATA'); $importPluginProperties->setExtension('ldi'); $importPluginProperties->setOptionsText(__('Options')); // create the root group that will be the options field for // $importPluginProperties // this will be shown as "Format specific options" $importSpecificOptions = new OptionsPropertyRootGroup(); $importSpecificOptions->setName("Format Specific Options"); // general options main group $generalOptions = new OptionsPropertyMainGroup(); $generalOptions->setName("general_opts"); // create primary items and add them to the group $leaf = new BoolPropertyItem(); $leaf->setName("replace"); $leaf->setText(__('Replace table data with file')); $generalOptions->addProperty($leaf); // add the main group to the root group $importSpecificOptions->addProperty($generalOptions); // set the options for the import plugin property item $importPluginProperties->setOptions($importSpecificOptions); $this->properties = $importPluginProperties; }
/** * Converts GIS data to Well Known Text format * * @param binary $data GIS data * @param bool $includeSRID Add SRID to the WKT * * @return GIS data in Well Know Text format */ function PMA_asWKT($data, $includeSRID = false) { // Convert to WKT format $hex = bin2hex($data); $wktsql = "SELECT ASTEXT(x'" . $hex . "')"; if ($includeSRID) { $wktsql .= ", SRID(x'" . $hex . "')"; } $wktresult = PMA_DBI_try_query($wktsql, null, PMA_DBI_QUERY_STORE); $wktarr = PMA_DBI_fetch_row($wktresult, 0); $wktval = $wktarr[0]; if ($includeSRID) { $srid = $wktarr[1]; $wktval = "'" . $wktval . "'," . $srid; } @PMA_DBI_free_result($wktresult); return $wktval; }
/** * Prepares the displayable content of a data cell in Browse mode, * taking into account foreign key description field and transformations * * @uses is_array() * @uses PMA_backquote() * @uses PMA_DBI_try_query() * @uses PMA_DBI_num_rows() * @uses PMA_DBI_fetch_row() * @uses $GLOBALS['strLinkNotFound'] * @uses PMA_DBI_free_result() * @uses $GLOBALS['printview'] * @uses htmlspecialchars() * @uses PMA_generate_common_url() * @param string $mouse_events * @param string $class * @param string $condition_field * @param string $analyzed_sql * @param object $meta the meta-information about this field * @param string $map * @param string $data * @param string $transform_function * @param string $default_function * @param string $nowrap * @param string $where_comparison * @return string formatted data */ function PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison, $transform_options) { // continue the <td> tag started before calling this function: $result = $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap . '">'; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) { $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias']; if (isset($alias) && strlen($alias)) { $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column']; if ($alias == $meta->name) { // this change in the parameter does not matter // outside of the function $meta->name = $true_column; } // end if } // end if } // end foreach } // end if if (isset($map[$meta->name])) { // Field to display from the foreign table? if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) { $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . $where_comparison; $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE); if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) { list($dispval) = PMA_DBI_fetch_row($dispresult, 0); } else { $dispval = $GLOBALS['strLinkNotFound']; } @PMA_DBI_free_result($dispresult); } else { $dispval = ''; } // end if... else... if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') { $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[->' . $dispval . ']</code>'; } else { if ('K' == $_SESSION['tmp_user_values']['relational_display']) { // user chose "relational key" in the display options, so // the title contains the display field $title = !empty($dispval) ? ' title="' . htmlspecialchars($dispval) . '"' : ''; } else { $title = ' title="' . htmlspecialchars($data) . '"'; } $_url_params = array('db' => $map[$meta->name][3], 'table' => $map[$meta->name][0], 'pos' => '0', 'sql_query' => 'SELECT * FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . $where_comparison); $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params) . '"' . $title . '>'; if ($transform_function != $default_function) { // always apply a transformation on the real data, // not on the display field $result .= $transform_function($data, $transform_options, $meta); } else { if ('D' == $_SESSION['tmp_user_values']['relational_display']) { // user chose "relational display field" in the // display options, so show display field in the cell $result .= $transform_function($dispval, array(), $meta); } else { // otherwise display data in the cell $result .= $transform_function($data, array(), $meta); } } $result .= '</a>'; } } else { $result .= $transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta); } $result .= '</td>' . "\n"; return $result; }
/** * Get list of replicated databases on master server * * @param mixed mysql link * * @return array array of replicated databases */ function PMA_replication_master_replicated_dbs($link = null) { $data = PMA_DBI_fetch_result('SHOW MASTER STATUS', null, null, $link); // let's find out, which databases are replicated $do_db = array(); $ignore_db = array(); if (!empty($data[0]['Binlog_Do_DB'])) { $do_db = explode(',', $data[0]['Binlog_Do_DB']); } if (!empty($data[0]['Binlog_Ignore_DB'])) { $ignore_db = explode(',', $data[0]['Binlog_Ignore_DB']); } $tmp_alldbs = PMA_DBI_query('SHOW DATABASES;', $link); while ($tmp_row = PMA_DBI_fetch_row($tmp_alldbs)) { if ($tmp_row[0] == 'information_schema') { continue; } if (count($do_db) == 0) { if (array_search($tmp_row[0], $ignore_db) !== false) { continue; } $dblist[] = $tmp_row[0]; } else { if (array_search($tmp_row[0], $do_db) !== false) { $dblist[] = $tmp_row[0]; } } } // end while return $link; }
/** * Outputs the content of a table in SQL format * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param string $sql_query SQL query for obtaining data * * @return bool Whether it succeeded */ public function exportData($db, $table, $crlf, $error_url, $sql_query) { global $current_row, $sql_backquotes; if (isset($GLOBALS['sql_compatibility'])) { $compat = $GLOBALS['sql_compatibility']; } else { $compat = 'NONE'; } $formatted_table_name = isset($GLOBALS['sql_backquotes']) ? PMA_Util::backquoteCompat($table, $compat) : '\'' . $table . '\''; // Do not export data for a VIEW // (For a VIEW, this is called only when exporting a single VIEW) if (PMA_Table::isView($db, $table)) { $head = $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment('VIEW ' . ' ' . $formatted_table_name) . $this->_exportComment(__('Data') . ': ' . __('None')) . $this->_exportComment() . $this->_possibleCRLF(); if (!PMA_exportOutputHandler($head)) { return false; } return true; } // analyze the query to get the true column names, not the aliases // (this fixes an undefined index, also if Complete inserts // are used, we did not get the true column name in case of aliases) $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query)); $result = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); // a possible error: the table has crashed $tmp_error = PMA_DBI_getError(); if ($tmp_error) { return PMA_exportOutputHandler($this->_exportComment(__('Error reading data:') . ' (' . $tmp_error . ')')); } if ($result != false) { $fields_cnt = PMA_DBI_num_fields($result); // Get field information $fields_meta = PMA_DBI_get_fields_meta($result); $field_flags = array(); for ($j = 0; $j < $fields_cnt; $j++) { $field_flags[$j] = PMA_DBI_field_flags($result, $j); } for ($j = 0; $j < $fields_cnt; $j++) { if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) { $field_set[$j] = PMA_Util::backquoteCompat($analyzed_sql[0]['select_expr'][$j]['column'], $compat, $sql_backquotes); } else { $field_set[$j] = PMA_Util::backquoteCompat($fields_meta[$j]->name, $compat, $sql_backquotes); } } if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') { // update $schema_insert = 'UPDATE '; if (isset($GLOBALS['sql_ignore'])) { $schema_insert .= 'IGNORE '; } // avoid EOL blank $schema_insert .= PMA_Util::backquoteCompat($table, $compat, $sql_backquotes) . ' SET'; } else { // insert or replace if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'REPLACE') { $sql_command = 'REPLACE'; } else { $sql_command = 'INSERT'; } // delayed inserts? if (isset($GLOBALS['sql_delayed'])) { $insert_delayed = ' DELAYED'; } else { $insert_delayed = ''; } // insert ignore? if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'INSERT' && isset($GLOBALS['sql_ignore'])) { $insert_delayed .= ' IGNORE'; } //truncate table before insert if (isset($GLOBALS['sql_truncate']) && $GLOBALS['sql_truncate'] && $sql_command == 'INSERT') { $truncate = 'TRUNCATE TABLE ' . PMA_Util::backquoteCompat($table, $compat, $sql_backquotes) . ";"; $truncatehead = $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment(__('Truncate table before insert') . ' ' . $formatted_table_name) . $this->_exportComment() . $crlf; PMA_exportOutputHandler($truncatehead); PMA_exportOutputHandler($truncate); } else { $truncate = ''; } // scheme for inserting fields if ($GLOBALS['sql_insert_syntax'] == 'complete' || $GLOBALS['sql_insert_syntax'] == 'both') { $fields = implode(', ', $field_set); $schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_Util::backquoteCompat($table, $compat, $sql_backquotes) . ' (' . $fields . ') VALUES'; } else { $schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_Util::backquoteCompat($table, $compat, $sql_backquotes) . ' VALUES'; } } //\x08\\x09, not required $search = array("", "\n", "\r", ""); $replace = array('\\0', '\\n', '\\r', '\\Z'); $current_row = 0; $query_size = 0; if (($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') && (!isset($GLOBALS['sql_type']) || $GLOBALS['sql_type'] != 'UPDATE')) { $separator = ','; $schema_insert .= $crlf; } else { $separator = ';'; } while ($row = PMA_DBI_fetch_row($result)) { if ($current_row == 0) { $head = $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment(__('Dumping data for table') . ' ' . $formatted_table_name) . $this->_exportComment() . $crlf; if (!PMA_exportOutputHandler($head)) { return false; } } // We need to SET IDENTITY_INSERT ON for MSSQL if (isset($GLOBALS['sql_compatibility']) && $GLOBALS['sql_compatibility'] == 'MSSQL' && $current_row == 0) { if (!PMA_exportOutputHandler('SET IDENTITY_INSERT ' . PMA_Util::backquoteCompat($table, $compat) . ' ON ;' . $crlf)) { return false; } } $current_row++; for ($j = 0; $j < $fields_cnt; $j++) { // NULL if (!isset($row[$j]) || is_null($row[$j])) { $values[] = 'NULL'; } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && !$fields_meta[$j]->blob) { // a number // timestamp is numeric on some MySQL 4.1, BLOBs are // sometimes numeric $values[] = $row[$j]; } elseif (stristr($field_flags[$j], 'BINARY') && $fields_meta[$j]->blob && isset($GLOBALS['sql_hex_for_blob'])) { // a true BLOB // - mysqldump only generates hex data when the --hex-blob // option is used, for fields having the binary attribute // no hex is generated // - a TEXT field returns type blob but a real blob // returns also the 'binary' flag // empty blobs need to be different, but '0' is also empty // :-( if (empty($row[$j]) && $row[$j] != '0') { $values[] = '\'\''; } else { $values[] = '0x' . bin2hex($row[$j]); } } elseif ($fields_meta[$j]->type == 'bit') { // detection of 'bit' works only on mysqli extension $values[] = "b'" . PMA_Util::sqlAddSlashes(PMA_Util::printableBitValue($row[$j], $fields_meta[$j]->length)) . "'"; } else { // something else -> treat as a string $values[] = '\'' . str_replace($search, $replace, PMA_Util::sqlAddSlashes($row[$j])) . '\''; } // end if } // end for // should we make update? if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') { $insert_line = $schema_insert; for ($i = 0; $i < $fields_cnt; $i++) { if (0 == $i) { $insert_line .= ' '; } if ($i > 0) { // avoid EOL blank $insert_line .= ','; } $insert_line .= $field_set[$i] . ' = ' . $values[$i]; } list($tmp_unique_condition, $tmp_clause_is_unique) = PMA_Util::getUniqueCondition($result, $fields_cnt, $fields_meta, $row); $insert_line .= ' WHERE ' . $tmp_unique_condition; unset($tmp_unique_condition, $tmp_clause_is_unique); } else { // Extended inserts case if ($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') { if ($current_row == 1) { $insert_line = $schema_insert . '(' . implode(', ', $values) . ')'; } else { $insert_line = '(' . implode(', ', $values) . ')'; $sql_max_size = $GLOBALS['sql_max_query_size']; if (isset($sql_max_size) && $sql_max_size > 0 && $query_size + strlen($insert_line) > $sql_max_size) { if (!PMA_exportOutputHandler(';' . $crlf)) { return false; } $query_size = 0; $current_row = 1; $insert_line = $schema_insert . $insert_line; } } $query_size += strlen($insert_line); // Other inserts case } else { $insert_line = $schema_insert . '(' . implode(', ', $values) . ')'; } } unset($values); if (!PMA_exportOutputHandler(($current_row == 1 ? '' : $separator . $crlf) . $insert_line)) { return false; } } // end while if ($current_row > 0) { if (!PMA_exportOutputHandler(';' . $crlf)) { return false; } } // We need to SET IDENTITY_INSERT OFF for MSSQL if (isset($GLOBALS['sql_compatibility']) && $GLOBALS['sql_compatibility'] == 'MSSQL' && $current_row > 0) { $outputSucceeded = PMA_exportOutputHandler($crlf . 'SET IDENTITY_INSERT ' . PMA_Util::backquoteCompat($table, $compat) . ' OFF;' . $crlf); if (!$outputSucceeded) { return false; } } } // end if ($result != false) PMA_DBI_free_result($result); return true; }
/** * Outputs the content of a table in CSV format * * @param string the database name * @param string the table name * @param string the end of line sequence * @param string the url to go back in case of error * @param string SQL query for obtaining data * * @return bool Whether it suceeded * * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { global $what; global $add_character; global $separator; global $enclosed; global $escaped; // Gets the data from the database $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); $fields_cnt = PMA_DBI_num_fields($result); // If required, get fields name at the first line if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') { $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { if ($enclosed == '') { $schema_insert .= stripslashes(PMA_DBI_field_name($result, $i)); } else { $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, stripslashes(PMA_DBI_field_name($result, $i))) . $enclosed; } $schema_insert .= $separator; } // end for $schema_insert = trim(substr($schema_insert, 0, -1)); if (!PMA_exportOutputHandler($schema_insert . $add_character)) { return FALSE; } } // end if // Format the data while ($row = PMA_DBI_fetch_row($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { $schema_insert .= $GLOBALS[$what . '_replace_null']; } else { if ($row[$j] == '0' || $row[$j] != '') { // loic1 : always enclose fields if ($what == 'excel') { $row[$j] = ereg_replace("\r(\n)?", "\n", $row[$j]); } if ($enclosed == '') { $schema_insert .= $row[$j]; } else { $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, $row[$j]) . $enclosed; } } else { $schema_insert .= ''; } } if ($j < $fields_cnt - 1) { $schema_insert .= $separator; } } // end for if (!PMA_exportOutputHandler($schema_insert . $add_character)) { return FALSE; } } // end while PMA_DBI_free_result($result); return TRUE; }
/** * Displays the privileges form table * * @param string $db the database * @param string $table the table * @param boolean $submit wheather to display the submit button or not * * @global array $cfg the phpMyAdmin configuration * @global ressource $user_link the database connection * * @return void */ function PMA_displayPrivTable($db = '*', $table = '*', $submit = true) { global $random_n; if ($db == '*') { $table = '*'; } if (isset($GLOBALS['username'])) { $username = $GLOBALS['username']; $hostname = $GLOBALS['hostname']; if ($db == '*') { $sql_query = "SELECT * FROM `mysql`.`user`" ." WHERE `User` = '" . PMA_sqlAddSlashes($username) . "'" ." AND `Host` = '" . PMA_sqlAddSlashes($hostname) . "';"; } elseif ($table == '*') { $sql_query = "SELECT * FROM `mysql`.`db`" ." WHERE `User` = '" . PMA_sqlAddSlashes($username) . "'" ." AND `Host` = '" . PMA_sqlAddSlashes($hostname) . "'" ." AND '" . PMA_unescape_mysql_wildcards($db) . "'" ." LIKE `Db`;"; } else { $sql_query = "SELECT `Table_priv`" ." FROM `mysql`.`tables_priv`" ." WHERE `User` = '" . PMA_sqlAddSlashes($username) . "'" ." AND `Host` = '" . PMA_sqlAddSlashes($hostname) . "'" ." AND `Db` = '" . PMA_unescape_mysql_wildcards($db) . "'" ." AND `Table_name` = '" . PMA_sqlAddSlashes($table) . "';"; } $row = PMA_DBI_fetch_single_row($sql_query); } if (empty($row)) { if ($table == '*') { if ($db == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;'; } elseif ($table == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;'; } $res = PMA_DBI_query($sql_query); while ($row1 = PMA_DBI_fetch_row($res)) { if (substr($row1[0], 0, 4) == 'max_') { $row[$row1[0]] = 0; } else { $row[$row1[0]] = 'N'; } } PMA_DBI_free_result($res); } else { $row = array('Table_priv' => ''); } } if (isset($row['Table_priv'])) { $row1 = PMA_DBI_fetch_single_row( 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';', 'ASSOC', $GLOBALS['userlink'] ); // note: in MySQL 5.0.3 we get "Create View', 'Show view'; // the View for Create is spelled with uppercase V // the view for Show is spelled with lowercase v // and there is a space between the words $av_grants = explode( '\',\'', substr( $row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3 ) ); unset($row1); $users_grants = explode(',', $row['Table_priv']); foreach ($av_grants as $current_grant) { $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N'; } unset($row['Table_priv'], $current_grant, $av_grants, $users_grants); // get collumns $res = PMA_DBI_try_query( 'SHOW COLUMNS FROM ' . PMA_backquote(PMA_unescape_mysql_wildcards($db)) . '.' . PMA_backquote($table) . ';' ); $columns = array(); if ($res) { while ($row1 = PMA_DBI_fetch_row($res)) { $columns[$row1[0]] = array( 'Select' => false, 'Insert' => false, 'Update' => false, 'References' => false ); } PMA_DBI_free_result($res); } unset($res, $row1); } // t a b l e - s p e c i f i c p r i v i l e g e s if (! empty($columns)) { $res = PMA_DBI_query( 'SELECT `Column_name`, `Column_priv`' .' FROM `mysql`.`columns_priv`' .' WHERE `User`' .' = \'' . PMA_sqlAddSlashes($username) . "'" .' AND `Host`' .' = \'' . PMA_sqlAddSlashes($hostname) . "'" .' AND `Db`' .' = \'' . PMA_sqlAddSlashes(PMA_unescape_mysql_wildcards($db)) . "'" .' AND `Table_name`' .' = \'' . PMA_sqlAddSlashes($table) . '\';' ); while ($row1 = PMA_DBI_fetch_row($res)) { $row1[1] = explode(',', $row1[1]); foreach ($row1[1] as $current) { $columns[$row1[0]][$current] = true; } } PMA_DBI_free_result($res); unset($res, $row1, $current); echo '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n" . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n" . '<fieldset id="fieldset_user_priv">' . "\n" . ' <legend>' . __('Table-specific privileges') . PMA_showHint(__('Note: MySQL privilege names are expressed in English')) . '</legend>' . "\n"; // privs that are attached to a specific column PMA_displayColumnPrivs( $columns, $row, 'Select_priv', 'SELECT', 'select', __('Allows reading data.'), 'Select' ); PMA_displayColumnPrivs( $columns, $row, 'Insert_priv', 'INSERT', 'insert', __('Allows inserting and replacing data.'), 'Insert' ); PMA_displayColumnPrivs( $columns, $row, 'Update_priv', 'UPDATE', 'update', __('Allows changing data.'), 'Update' ); PMA_displayColumnPrivs( $columns, $row, 'References_priv', 'REFERENCES', 'references', __('Has no effect in this MySQL version.'), 'References' ); // privs that are not attached to a specific column echo ' <div class="item">' . "\n"; foreach ($row as $current_grant => $current_grant_value) { $grant_type = substr($current_grant, 0, (strlen($current_grant) - 5)); if (in_array($grant_type, array('Select', 'Insert', 'Update', 'References'))) { continue; } // make a substitution to match the messages variables; // also we must substitute the grant we get, because we can't generate // a form variable containing blanks (those would get changed to // an underscore when receiving the POST) if ($current_grant == 'Create View_priv') { $tmp_current_grant = 'CreateView_priv'; $current_grant = 'Create_view_priv'; } elseif ($current_grant == 'Show view_priv') { $tmp_current_grant = 'ShowView_priv'; $current_grant = 'Show_view_priv'; } else { $tmp_current_grant = $current_grant; } echo ' <div class="item">' . "\n" . ' <input type="checkbox"' . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"') . ' name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="'; echo (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '"/>' . "\n"; echo ' <label for="checkbox_' . $current_grant . '"><code><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></code></label>' . "\n" . ' </div>' . "\n"; } // end foreach () echo ' </div>' . "\n"; // for Safari 2.0.2 echo ' <div class="clearfloat"></div>' . "\n"; } else { // g l o b a l o r d b - s p e c i f i c // $privTable_names = array(0 => __('Data'), 1 => __('Structure'), 2 => __('Administration')); // d a t a $privTable[0] = array( array('Select', 'SELECT', __('Allows reading data.')), array('Insert', 'INSERT', __('Allows inserting and replacing data.')), array('Update', 'UPDATE', __('Allows changing data.')), array('Delete', 'DELETE', __('Allows deleting data.')) ); if ($db == '*') { $privTable[0][] = array('File', 'FILE', __('Allows importing data from and exporting data into files.')); } // s t r u c t u r e $privTable[1] = array( array('Create', 'CREATE', ($table == '*' ? __('Allows creating new databases and tables.') : __('Allows creating new tables.'))), array('Alter', 'ALTER', __('Allows altering the structure of existing tables.')), array('Index', 'INDEX', __('Allows creating and dropping indexes.')), array('Drop', 'DROP', ($table == '*' ? __('Allows dropping databases and tables.') : __('Allows dropping tables.'))), array('Create_tmp_table', 'CREATE TEMPORARY TABLES', __('Allows creating temporary tables.')), array('Show_view', 'SHOW VIEW', __('Allows performing SHOW CREATE VIEW queries.')), array('Create_routine', 'CREATE ROUTINE', __('Allows creating stored routines.')), array('Alter_routine', 'ALTER ROUTINE', __('Allows altering and dropping stored routines.')), array('Execute', 'EXECUTE', __('Allows executing stored routines.')), ); // this one is for a db-specific priv: Create_view_priv if (isset($row['Create_view_priv'])) { $privTable[1][] = array('Create_view', 'CREATE VIEW', __('Allows creating new views.')); } // this one is for a table-specific priv: Create View_priv if (isset($row['Create View_priv'])) { $privTable[1][] = array('Create View', 'CREATE VIEW', __('Allows creating new views.')); } if (isset($row['Event_priv'])) { // MySQL 5.1.6 $privTable[1][] = array('Event', 'EVENT', __('Allows to set up events for the event scheduler')); $privTable[1][] = array('Trigger', 'TRIGGER', __('Allows creating and dropping triggers')); } // a d m i n i s t r a t i o n $privTable[2] = array( array('Grant', 'GRANT', __('Allows adding users and privileges without reloading the privilege tables.')), ); if ($db == '*') { $privTable[2][] = array('Super', 'SUPER', __('Allows connecting, even if maximum number of connections is reached; required for most administrative operations like setting global variables or killing threads of other users.')); $privTable[2][] = array('Process', 'PROCESS', __('Allows viewing processes of all users')); $privTable[2][] = array('Reload', 'RELOAD', __('Allows reloading server settings and flushing the server\'s caches.')); $privTable[2][] = array('Shutdown', 'SHUTDOWN', __('Allows shutting down the server.')); $privTable[2][] = array('Show_db', 'SHOW DATABASES', __('Gives access to the complete list of databases.')); } $privTable[2][] = array('Lock_tables', 'LOCK TABLES', __('Allows locking tables for the current thread.')); $privTable[2][] = array('References', 'REFERENCES', __('Has no effect in this MySQL version.')); if ($db == '*') { $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', __('Allows the user to ask where the slaves / masters are.')); $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', __('Needed for the replication slaves.')); $privTable[2][] = array('Create_user', 'CREATE USER', __('Allows creating, dropping and renaming user accounts.')); } echo '<input type="hidden" name="grant_count" value="' . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0)) . '" />' . "\n" . '<fieldset id="fieldset_user_global_rights">' . "\n" . ' <legend>' . "\n" . ' ' . ($db == '*' ? __('Global privileges') : ($table == '*' ? __('Database-specific privileges') : __('Table-specific privileges'))) . "\n" . ' (<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&checkall=1" onclick="setCheckboxes(\'addUsersForm_' . $random_n . '\', true); return false;">' . __('Check All') . '</a> /' . "\n" . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '" onclick="setCheckboxes(\'addUsersForm_' . $random_n . '\', false); return false;">' . __('Uncheck All') . '</a>)' . "\n" . ' </legend>' . "\n" . ' <p><small><i>' . __('Note: MySQL privilege names are expressed in English') . '</i></small></p>' . "\n"; // Output the Global privilege tables with checkboxes foreach ($privTable as $i => $table) { echo ' <fieldset>' . "\n" . ' <legend>' . __($privTable_names[$i]) . '</legend>' . "\n"; foreach ($table as $priv) { echo ' <div class="item">' . "\n" . ' <input type="checkbox"' . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0] . '_priv"' . ' value="Y" title="' . $priv[2] . '"' . ((! empty($GLOBALS['checkall']) || $row[$priv[0] . '_priv'] == 'Y') ? ' checked="checked"' : '') . '/>' . "\n" . ' <label for="checkbox_' . $priv[0] . '_priv"><code><dfn title="' . $priv[2] . '">' . $priv[1] . '</dfn></code></label>' . "\n" . ' </div>' . "\n"; } echo ' </fieldset>' . "\n"; } // The "Resource limits" box is not displayed for db-specific privs if ($db == '*') { echo ' <fieldset>' . "\n" . ' <legend>' . __('Resource limits') . '</legend>' . "\n" . ' <p><small><i>' . __('Note: Setting these options to 0 (zero) removes the limit.') . '</i></small></p>' . "\n" . ' <div class="item">' . "\n" . ' <label for="text_max_questions"><code><dfn title="' . __('Limits the number of queries the user may send to the server per hour.') . '">MAX QUERIES PER HOUR</dfn></code></label>' . "\n" . ' <input type="text" name="max_questions" id="text_max_questions" value="' . $row['max_questions'] . '" size="11" maxlength="11" title="' . __('Limits the number of queries the user may send to the server per hour.') . '" />' . "\n" . ' </div>' . "\n" . ' <div class="item">' . "\n" . ' <label for="text_max_updates"><code><dfn title="' . __('Limits the number of commands that change any table or database the user may execute per hour.') . '">MAX UPDATES PER HOUR</dfn></code></label>' . "\n" . ' <input type="text" name="max_updates" id="text_max_updates" value="' . $row['max_updates'] . '" size="11" maxlength="11" title="' . __('Limits the number of commands that change any table or database the user may execute per hour.') . '" />' . "\n" . ' </div>' . "\n" . ' <div class="item">' . "\n" . ' <label for="text_max_connections"><code><dfn title="' . __('Limits the number of new connections the user may open per hour.') . '">MAX CONNECTIONS PER HOUR</dfn></code></label>' . "\n" . ' <input type="text" name="max_connections" id="text_max_connections" value="' . $row['max_connections'] . '" size="11" maxlength="11" title="' . __('Limits the number of new connections the user may open per hour.') . '" />' . "\n" . ' </div>' . "\n" . ' <div class="item">' . "\n" . ' <label for="text_max_user_connections"><code><dfn title="' . __('Limits the number of simultaneous connections the user may have.') . '">MAX USER_CONNECTIONS</dfn></code></label>' . "\n" . ' <input type="text" name="max_user_connections" id="text_max_user_connections" value="' . $row['max_user_connections'] . '" size="11" maxlength="11" title="' . __('Limits the number of simultaneous connections the user may have.') . '" />' . "\n" . ' </div>' . "\n" . ' </fieldset>' . "\n"; } // for Safari 2.0.2 echo ' <div class="clearfloat"></div>' . "\n"; } echo '</fieldset>' . "\n"; if ($submit) { echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">' . "\n" . ' <input type="submit" name="update_privs" value="' . __('Go') . '" />' . "\n" . '</fieldset>' . "\n"; } } // end of the 'PMA_displayPrivTable()' function
/** * Outputs the content of a table in YAML format * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param string $sql_query SQL query for obtaining data * @return bool Whether it succeeded * * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $columns_cnt = PMA_DBI_num_fields($result); for ($i = 0; $i < $columns_cnt; $i++) { $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i)); } unset($i); $buffer = ''; $record_cnt = 0; while ($record = PMA_DBI_fetch_row($result)) { $record_cnt++; // Output table name as comment if this is the first record of the table if ($record_cnt == 1) { $buffer = '# ' . $db . '.' . $table . $crlf; $buffer .= '-' . $crlf; } else { $buffer = '-' . $crlf; } for ($i = 0; $i < $columns_cnt; $i++) { if (!isset($record[$i])) { continue; } $column = $columns[$i]; if (is_null($record[$i])) { $buffer .= ' ' . $column . ': null' . $crlf; continue; } if (is_numeric($record[$i])) { $buffer .= ' ' . $column . ': ' . $record[$i] . $crlf; continue; } $record[$i] = str_replace(array('\\', '"', "\n", "\r"), array('\\\\', '\\"', '\\n', '\\r'), $record[$i]); $buffer .= ' ' . $column . ': "' . $record[$i] . '"' . $crlf; } if (!PMA_exportOutputHandler($buffer)) { return false; } } PMA_DBI_free_result($result); return true; }
/** * Counts and displays the number of records in a table * * Last revision 13 July 2001: Patch for limiting dump size from * vinay@sanisoft.com & girish@sanisoft.com * * @param string the current database name * @param string the current table name * @param boolean whether to retain or to displays the result * * @return mixed the number of records if retain is required, true else * * @access public */ function PMA_countRecords($db, $table, $ret = FALSE) { global $err_url, $cfg; $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); $showtable = PMA_DBI_fetch_assoc($result); $num = isset($showtable['Rows']) ? $showtable['Rows'] : 0; if ($num < $cfg['MaxExactCount']) { unset($num); } PMA_DBI_free_result($result); if (!isset($num)) { $result = PMA_DBI_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); list($num) = $result ? PMA_DBI_fetch_row($result) : array(0); PMA_DBI_free_result($result); } if ($ret) { return $num; } else { echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']); return TRUE; } }
/** * Displays the body of the results table * * @param integer the link id associated to the query which results have * to be displayed * @param array which elements to display * @param array the list of relations * @param array the analyzed query * * @return boolean always true * * @global string $db the database name * @global string $table the table name * @global string $goto the url to go back in case of errors * @global boolean $dontlimitchars whether to limit the number of displayed * characters of text type fields or not * @global string $sql_query the sql query * @global integer $pos the current position in results * @global integer $session_max_rows the maximum number of rows per page * @global array $fields_meta the list of fields properties * @global integer $fields_cnt the total number of fields returned by * the sql query * @global array $vertical_display informations used with vertical display * mode * @global string $disp_direction the display mode * (horizontal/vertical/horizontalflipped) * @global integer $repeat_cells the number of row to display between two * table headers * @global array $highlight_columns collumn names to highlight * @gloabl array $row current row data * * @access private * * @see PMA_displayTable() */ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { global $db, $table, $goto, $dontlimitchars; global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt; global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns; global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin $url_sql_query = $sql_query; // query without conditions to shorten urls when needed, 200 is just // guess, it should depend on remaining url length if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' && strlen($sql_query) > 200) { $url_sql_query = 'SELECT '; if (isset($analyzed_sql[0]['queryflags']['distinct'])) { $url_sql_query .= ' DISTINCT '; } $url_sql_query .= $analyzed_sql[0]['select_expr_clause']; if (!empty($analyzed_sql[0]['from_clause'])) { $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause']; } } if (!is_array($map)) { $map = array(); } $row_no = 0; $vertical_display['edit'] = array(); $vertical_display['delete'] = array(); $vertical_display['data'] = array(); $vertical_display['row_delete'] = array(); // Correction uva 19991216 in the while below // Previous code assumed that all tables have keys, specifically that // the phpMyAdmin GUI should support row delete/edit only for such // tables. // Although always using keys is arguably the prescribed way of // defining a relational table, it is not required. This will in // particular be violated by the novice. // We want to encourage phpMyAdmin usage by such novices. So the code // below has been changed to conditionally work as before when the // table being displayed has one or more keys; but to display // delete/edit options correctly for tables without keys. // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row' // to get the NULL values // rabus: This function needs a little rework. // Using MYSQL_BOTH just pollutes the memory! // ne0x: Use function PMA_DBI_fetch_array() due to mysqli // compatibility. Now this function is wrapped. $odd_row = true; while ($row = PMA_DBI_fetch_row($dt_result)) { // lem9: "vertical display" mode stuff if ($row_no != 0 && $repeat_cells != 0 && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { echo '<tr>' . "\n"; if ($vertical_display['emptypre'] > 0) { echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n" . ' </th>' . "\n"; } foreach ($vertical_display['desc'] as $val) { echo $val; } if ($vertical_display['emptyafter'] > 0) { echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n" . ' </th>' . "\n"; } echo '</tr>' . "\n"; } // end if $class = $odd_row ? 'odd' : 'even'; $odd_row = !$odd_row; if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { // loic1: pointer code part echo ' <tr class="' . $class . '">' . "\n"; $class = ''; } // 1. Prepares the row (gets primary keys to use) // 1.1 Results from a "SELECT" statement -> builds the // "primary" key to use in links $uva_condition = urlencode(PMA_getUvaCondition($dt_result, $fields_cnt, $fields_meta, $row)); // 1.2 Defines the urls for the modify/delete link(s) $url_query = PMA_generate_common_url($db, $table) . '&pos=' . $pos . '&session_max_rows=' . $session_max_rows . '&disp_direction=' . $disp_direction . '&repeat_cells=' . $repeat_cells . '&dontlimitchars=' . $dontlimitchars; if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') { // We need to copy the value or else the == 'both' check will always return true if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') { $iconic_spacer = '<div class="nowrap">'; } else { $iconic_spacer = ''; } // 1.2.1 Modify link(s) if ($is_display['edit_lnk'] == 'ur') { // update row case $lnk_goto = 'sql.php'; $edit_url = 'tbl_change.php' . '?' . $url_query . '&primary_key=' . $uva_condition . '&sql_query=' . urlencode($url_sql_query) . '&goto=' . urlencode($lnk_goto); if ($GLOBALS['cfg']['PropertiesIconic'] === false) { $edit_str = $GLOBALS['strEdit']; } else { $edit_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" />'; if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') { $edit_str .= ' ' . $GLOBALS['strEdit'] . '</div>'; } } } // end if (1.2.1) if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db'] && isset($row[1]) && isset($row[0])) { $bookmark_go = '<a href="import.php?' . PMA_generate_common_url($row[1], '') . '&id_bookmark=' . $row[0] . '&action_bookmark=0' . '&action_bookmark_all=1' . '&SQL=' . $GLOBALS['strExecuteBookmarked'] . ' " title="' . $GLOBALS['strExecuteBookmarked'] . '">'; if ($GLOBALS['cfg']['PropertiesIconic'] === false) { $bookmark_go .= $GLOBALS['strExecuteBookmarked']; } else { $bookmark_go .= $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" />'; if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') { $bookmark_go .= ' ' . $GLOBALS['strExecuteBookmarked'] . '</div>'; } } $bookmark_go .= '</a>'; } else { $bookmark_go = ''; } // 1.2.2 Delete/Kill link(s) if ($is_display['del_lnk'] == 'dr') { // delete row case $lnk_goto = 'sql.php' . '?' . str_replace('&', '&', $url_query) . '&sql_query=' . urlencode($url_sql_query) . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted'])) . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto); $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . '+LIMIT+1'; $del_url = 'sql.php' . '?' . $url_query . '&sql_query=' . $del_query . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted'])) . '&goto=' . urlencode($lnk_goto); $js_conf = 'DELETE FROM ' . PMA_jsFormat($table) . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), false)) . ' LIMIT 1'; if ($GLOBALS['cfg']['PropertiesIconic'] === false) { $del_str = $GLOBALS['strDelete']; } else { $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" />'; if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') { $del_str .= ' ' . $GLOBALS['strDelete'] . '</div>'; } } } elseif ($is_display['del_lnk'] == 'kp') { // kill process case $lnk_goto = 'sql.php' . '?' . str_replace('&', '&', $url_query) . '&sql_query=' . urlencode($url_sql_query) . '&goto=main.php'; $del_url = 'sql.php?' . PMA_generate_common_url('mysql') . '&sql_query=' . urlencode('KILL ' . $row[0]) . '&goto=' . urlencode($lnk_goto); $del_query = urlencode('KILL ' . $row[0]); $js_conf = 'KILL ' . $row[0]; if ($GLOBALS['cfg']['PropertiesIconic'] === false) { $del_str = $GLOBALS['strKill']; } else { $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" />'; if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') { $del_str .= ' ' . $GLOBALS['strKill'] . '</div>'; } } } // end if (1.2.2) // 1.3 Displays the links at left if required if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { $doWriteModifyAt = 'left'; require './libraries/display_tbl_links.lib.php'; } // end if (1.3) } // end if (1) // 2. Displays the rows' values for ($i = 0; $i < $fields_cnt; ++$i) { $meta = $fields_meta[$i]; // loic1: To fix bug #474943 under php4, the row pointer will // depend on whether the "is_null" php4 function is // available or not $pointer = function_exists('is_null') ? $i : $meta->name; // garvin: See if this column should get highlight because it's used in the // where-query. if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) { $condition_field = true; } else { $condition_field = false; } $mouse_events = ''; if ($disp_direction == 'vertical' && (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1')) { if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) { $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"' . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" '; } if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) { $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" '; } else { $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" '; } } // end if // garvin: Wrap MIME-transformations. [MIME] $default_function = 'default_function'; // default_function $transform_function = $default_function; $transform_options = array(); if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) { $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']); if (file_exists('./libraries/transformations/' . $include_file)) { $transformfunction_name = preg_replace('@(\\.inc\\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']); require_once './libraries/transformations/' . $include_file; if (function_exists('PMA_transformation_' . $transformfunction_name)) { $transform_function = 'PMA_transformation_' . $transformfunction_name; $transform_options = PMA_transformation_getOptions(isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''); $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']); } } // end if file_exists } // end if transformation is set } // end if mime/transformation works. $transform_options['wrapper_link'] = '?' . (isset($url_query) ? $url_query : '') . '&primary_key=' . (isset($uva_condition) ? $uva_condition : '') . '&sql_query=' . (isset($sql_query) ? urlencode($url_sql_query) : '') . '&goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '') . '&transform_key=' . urlencode($meta->name); // n u m e r i c if ($meta->numeric == 1) { // lem9: if two fields have the same name (this is possible // with self-join queries, for example), using $meta->name // will show both fields NULL even if only one is NULL, // so use the $pointer // (works only if function_exists('is_null') // PS: why not always work with the number ($i), since // the default second parameter of // mysql_fetch_array() is MYSQL_BOTH, so we always get // associative and numeric indices? //if (!isset($row[$meta->name]) if (!isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n"; } elseif ($row[$i] != '') { $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . ' nowrap">'; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) { $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias']; if (isset($alias) && strlen($alias)) { $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column']; if ($alias == $meta->name) { $meta->name = $true_column; } // end if } // end if } // end while } if (isset($map[$meta->name])) { // Field to display from the foreign table? if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) { $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]; $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE); if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) { list($dispval) = PMA_DBI_fetch_row($dispresult, 0); } else { $dispval = $GLOBALS['strLinkNotFound']; } @PMA_DBI_free_result($dispresult); } else { $dispval = ''; } // end if... else... if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') { $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . ' <code>[->' . $dispval . ']</code>'; } else { $title = !empty($dispval) ? ' title="' . htmlspecialchars($dispval) . '"' : ''; $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?' . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0]) . '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars . '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]) . '"' . $title . '>' . ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . '</a>'; } } else { $vertical_display['data'][$row_no][$i] .= $transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta); } $vertical_display['data'][$row_no][$i] .= '</td>' . "\n"; } else { $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '"> </td>' . "\n"; } // b l o b } elseif ($GLOBALS['cfg']['ShowBlob'] == false && stristr($meta->type, 'BLOB')) { // loic1 : PMA_mysql_fetch_fields returns BLOB in place of // TEXT fields type, however TEXT fields must be displayed // even if $GLOBALS['cfg']['ShowBlob'] is false -> get the true type // of the fields. $field_flags = PMA_DBI_field_flags($dt_result, $i); if (stristr($field_flags, 'BINARY')) { $blobtext = '[BLOB'; if (!isset($row[$i]) || is_null($row[$i])) { $blobtext .= ' - NULL'; $blob_size = 0; } elseif (isset($row[$i])) { $blob_size = strlen($row[$i]); $display_blob_size = PMA_formatByteDown($blob_size, 3, 1); $blobtext .= ' - ' . $display_blob_size[0] . ' ' . $display_blob_size[1]; unset($display_blob_size); } $blobtext .= ']'; if (strpos($transform_function, 'octetstream')) { $blobtext = $row[$i]; } if ($blob_size > 0) { $blobtext = $default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta); } unset($blob_size); $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>'; } else { if (!isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n"; } elseif ($row[$i] != '') { // garvin: if a transform function for blob is set, none of these replacements will be made if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $dontlimitchars != 1) { $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...'; } // loic1: displays all space characters, 4 space // characters for tabulations and <cr>/<lf> $row[$i] = $default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta); $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $row[$i] . '</td>' . "\n"; } else { $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"> </td>' . "\n"; } } } else { if (!isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n"; } elseif ($row[$i] != '') { // loic1: support blanks in the key $relation_id = $row[$i]; // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars'] // lem9: (unless it's a link-type transformation) if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $dontlimitchars != 1 && !strpos($transform_function, 'link') === true) { $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...'; } // loic1: displays special characters from binaries $field_flags = PMA_DBI_field_flags($dt_result, $i); if (stristr($field_flags, 'BINARY')) { $row[$i] = str_replace("", '\\0', $row[$i]); $row[$i] = str_replace("", '\\b', $row[$i]); $row[$i] = str_replace("\n", '\\n', $row[$i]); $row[$i] = str_replace("\r", '\\r', $row[$i]); $row[$i] = str_replace("", '\\Z', $row[$i]); $row[$i] = $default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta); } else { $row[$i] = $default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta); } // garvin: transform functions may enable nowrapping: $function_nowrap = $transform_function . '_nowrap'; $bool_nowrap = $default_function != $transform_function && function_exists($function_nowrap) ? $function_nowrap($transform_options) : false; // loic1: do not wrap if date field type $nowrap = preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap ? ' nowrap' : ''; $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . $nowrap . ($condition_field ? ' condition' : '') . '">'; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) { $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias']; if (isset($alias) && strlen($alias)) { $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column']; if ($alias == $meta->name) { $meta->name = $true_column; } // end if } // end if } // end while } if (isset($map[$meta->name])) { // Field to display from the foreign table? if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) { $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\''; $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE); if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) { list($dispval) = PMA_DBI_fetch_row($dispresult); @PMA_DBI_free_result($dispresult); } else { $dispval = $GLOBALS['strLinkNotFound']; } } else { $dispval = ''; } $title = !empty($dispval) ? ' title="' . htmlspecialchars($dispval) . '"' : ''; $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?' . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0]) . '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars . '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>' . $row[$i] . '</a>'; } else { $vertical_display['data'][$row_no][$i] .= $row[$i]; } $vertical_display['data'][$row_no][$i] .= '</td>' . "\n"; } else { $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"> </td>' . "\n"; } } // lem9: output stored cell if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo $vertical_display['data'][$row_no][$i]; } if (isset($vertical_display['rowdata'][$i][$row_no])) { $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i]; } else { $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i]; } } // end for (2) // 3. Displays the modify/delete links on the right if required if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { $doWriteModifyAt = 'right'; require './libraries/display_tbl_links.lib.php'; } // end if (3) if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { ?> </tr> <?php } // end if // 4. Gather links of del_urls and edit_urls in an array for later // output if (!isset($vertical_display['edit'][$row_no])) { $vertical_display['edit'][$row_no] = ''; $vertical_display['delete'][$row_no] = ''; $vertical_display['row_delete'][$row_no] = ''; } $column_style_vertical = ''; if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) { $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"' . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"'; } $column_marker_vertical = ''; if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) { $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');'; } if (!empty($del_url) && $is_display['del_lnk'] != 'kp') { $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n" . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $uva_condition . ']"' . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"' . ' value="' . $del_query . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n" . ' </td>' . "\n"; } else { unset($vertical_display['row_delete'][$row_no]); } if (isset($edit_url)) { $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n" . PMA_linkOrButton($edit_url, $edit_str, array(), false) . $bookmark_go . ' </td>' . "\n"; } else { unset($vertical_display['edit'][$row_no]); } if (isset($del_url)) { $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n" . PMA_linkOrButton($del_url, $del_str, isset($js_conf) ? $js_conf : '', false) . ' </td>' . "\n"; } else { unset($vertical_display['delete'][$row_no]); } echo $disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped' ? "\n" : ''; $row_no++; } // end while if (isset($url_query)) { $GLOBALS['url_query'] = $url_query; } return true; }
/** * Ouputs the PDF document to a file * or sends the output to browser * * @param integer $pageNumber page number * * @global object The current PDF document * @global string The current database name * @global integer The current page number (from the * $cfg['Servers'][$i]['table_coords'] table) * @access private * * @return void * * @see PMA_Schema_PDF */ private function _showOutput($pageNumber) { global $pdf, $cfgRelation; // Get the name of this pdfpage to use as filename $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE page_nr = ' . $pageNumber; $_name_rs = PMA_query_as_controluser($_name_sql); if ($_name_rs) { $_name_row = PMA_DBI_fetch_row($_name_rs); $filename = $_name_row[0] . '.pdf'; } if (empty($filename)) { $filename = $pageNumber . '.pdf'; } $pdf->Download($filename); }
/** * Outputs the content of a table in CSV format * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param string $sql_query SQL query for obtaining data * @return bool Whether it succeeded * * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { global $what; global $csv_terminated; global $csv_separator; global $csv_enclosed; global $csv_escaped; // Gets the data from the database $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $fields_cnt = PMA_DBI_num_fields($result); // If required, get fields name at the first line if (isset($GLOBALS['csv_columns'])) { $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { if ($csv_enclosed == '') { $schema_insert .= stripslashes(PMA_DBI_field_name($result, $i)); } else { $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(PMA_DBI_field_name($result, $i))) . $csv_enclosed; } $schema_insert .= $csv_separator; } // end for $schema_insert = trim(substr($schema_insert, 0, -1)); if (!PMA_exportOutputHandler($schema_insert . $csv_terminated)) { return false; } } // end if // Format the data while ($row = PMA_DBI_fetch_row($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { $schema_insert .= $GLOBALS[$what . '_null']; } elseif ($row[$j] == '0' || $row[$j] != '') { // always enclose fields if ($what == 'excel') { $row[$j] = preg_replace("/\r(\n)?/", "\n", $row[$j]); } // remove CRLF characters within field if (isset($GLOBALS[$what . '_removeCRLF']) && $GLOBALS[$what . '_removeCRLF']) { $row[$j] = str_replace("\n", "", str_replace("\r", "", $row[$j])); } if ($csv_enclosed == '') { $schema_insert .= $row[$j]; } else { // also double the escape string if found in the data if ($csv_escaped != $csv_enclosed) { $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, str_replace($csv_escaped, $csv_escaped . $csv_escaped, $row[$j])) . $csv_enclosed; } else { // avoid a problem when escape string equals enclose $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed; } } } else { $schema_insert .= ''; } if ($j < $fields_cnt - 1) { $schema_insert .= $csv_separator; } } // end for if (!PMA_exportOutputHandler($schema_insert . $csv_terminated)) { return false; } } // end while PMA_DBI_free_result($result); return true; }
/** * Outputs the content of a table * * @param string the database name * @param string the table name * @param string the end of line sequence * @param string the url to go back in case of error * @param string SQL query for obtaining data * * @return bool Whether it suceeded * * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); $columns_cnt = PMA_DBI_num_fields($result); for ($i = 0; $i < $columns_cnt; $i++) { $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i)); } unset($i); $buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return FALSE; } while ($record = PMA_DBI_fetch_row($result)) { $buffer = ' <' . $table . '>' . $crlf; for ($i = 0; $i < $columns_cnt; $i++) { if (isset($record[$i]) && !is_null($record[$i])) { $buffer .= ' <' . $columns[$i] . '>' . htmlspecialchars($record[$i]) . '</' . $columns[$i] . '>' . $crlf; } } $buffer .= ' </' . $table . '>' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return FALSE; } } PMA_DBI_free_result($result); return TRUE; }
if (isset($after_insert) && $after_insert == 'new_insert') { $goto = 'tbl_change.php?' . PMA_generate_common_url($db, $table, '&') . '&goto=' . urlencode($goto) . '&pos=' . $pos . '&session_max_rows=' . $session_max_rows . '&disp_direction=' . $disp_direction . '&repeat_cells=' . $repeat_cells . '&dontlimitchars=' . $dontlimitchars . '&after_insert=' . $after_insert . (empty($sql_query) ? '' : '&sql_query=' . urlencode($sql_query)); } elseif (isset($after_insert) && $after_insert == 'same_insert') { $goto = 'tbl_change.php?' . PMA_generate_common_url($db, $table, '&') . '&goto=' . urlencode($goto) . '&pos=' . $pos . '&session_max_rows=' . $session_max_rows . '&disp_direction=' . $disp_direction . '&repeat_cells=' . $repeat_cells . '&dontlimitchars=' . $dontlimitchars . '&after_insert=' . $after_insert . (empty($sql_query) ? '' : '&sql_query=' . urlencode($sql_query)); if (isset($primary_key)) { foreach ($primary_key as $pk) { $goto .= '&primary_key[]=' . $pk; } } } elseif (isset($after_insert) && $after_insert == 'edit_next') { $goto = 'tbl_change.php?' . PMA_generate_common_url($db, $table, '&') . '&goto=' . urlencode($goto) . '&pos=' . $pos . '&session_max_rows=' . $session_max_rows . '&disp_direction=' . $disp_direction . '&repeat_cells=' . $repeat_cells . '&dontlimitchars=' . $dontlimitchars . '&after_insert=' . $after_insert . (empty($sql_query) ? '' : '&sql_query=' . urlencode($sql_query)); if (isset($primary_key)) { foreach ($primary_key as $pk) { $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . str_replace('` =', '` >', urldecode($pk)) . ' LIMIT 1;'; $res = PMA_DBI_query($local_query); $row = PMA_DBI_fetch_row($res); $meta = PMA_DBI_get_fields_meta($res); $goto .= '&primary_key[]=' . urlencode(PMA_getUvaCondition($res, count($row), $meta, $row)); } } } elseif ($goto == 'sql.php') { $goto = 'sql.php?' . PMA_generate_common_url($db, $table, '&') . '&pos=' . $pos . '&session_max_rows=' . $session_max_rows . '&disp_direction=' . $disp_direction . '&repeat_cells=' . $repeat_cells . '&dontlimitchars=' . $dontlimitchars . '&sql_query=' . urlencode($sql_query); } elseif (!empty($goto)) { // Security checkings $is_gotofile = preg_replace('@^([^?]+).*$@', '\\1', $goto); if (!@file_exists('./' . $is_gotofile)) { $goto = !isset($table) || !strlen($table) ? 'db_details.php' : 'tbl_properties.php'; $is_gotofile = TRUE; } else { $is_gotofile = $is_gotofile == $goto; }
/** * Get HTML for Displays the initials * * @param array $array_initials array for all initials, even non A-Z * @param string $conditional_class if ajaxable 'Ajax' otherwise '' * * @return string HTML snippet */ function PMA_getHtmlForDisplayTheInitials($array_initials, $conditional_class) { // initialize to false the letters A-Z for ($letter_counter = 1; $letter_counter < 27; $letter_counter++) { if (!isset($array_initials[chr($letter_counter + 64)])) { $array_initials[chr($letter_counter + 64)] = false; } } $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(`User`,1)) FROM `user` ORDER BY `User` ASC', null, PMA_DBI_QUERY_STORE); while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) { $array_initials[$tmp_initial] = true; } // Display the initials, which can be any characters, not // just letters. For letters A-Z, we add the non-used letters // as greyed out. uksort($array_initials, "strnatcasecmp"); $html_output = '<table id="initials_table" <cellspacing="5">' . '<tr>'; foreach ($array_initials as $tmp_initial => $initial_was_found) { if (!empty($tmp_initial)) { if ($initial_was_found) { $html_output .= '<td>' . '<a class="' . $conditional_class . '"' . ' href="server_privileges.php?' . $GLOBALS['url_query'] . '&' . 'initial=' . urlencode($tmp_initial) . '">' . $tmp_initial . '</a>' . '</td>' . "\n"; } else { $html_output .= '<td>' . $tmp_initial . '</td>'; } } } $html_output .= '<td>' . '<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&showall=1" ' . 'class="nowrap">[' . __('Show all') . ']</a></td>' . "\n"; $html_output .= '</tr></table>'; return $html_output; }
// Special speedup for newer MySQL Versions (in 4.0 format changed) if (true === $cfg['SkipLockedTables']) { $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';'); // Blending out tables in use if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) { while ($tmp = PMA_DBI_fetch_row($db_info_result)) { // if in use memorize tablename if (preg_match('@in_use=[1-9]+@i', $tmp[1])) { $sot_cache[$tmp[0]] = true; } } PMA_DBI_free_result($db_info_result); if (isset($sot_cache)) { $db_info_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';', null, PMA_DBI_QUERY_STORE); if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) { while ($tmp = PMA_DBI_fetch_row($db_info_result)) { if (!isset($sot_cache[$tmp[0]])) { $sts_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\';'); $sts_tmp = PMA_DBI_fetch_assoc($sts_result); PMA_DBI_free_result($sts_result); unset($sts_result); if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) { $sts_tmp['Type'] =& $sts_tmp['Engine']; } if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB'] && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) { continue; } if ($cfg['ShowTooltip']) { PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp); } $tables[$sts_tmp['Name']] = $sts_tmp;
/** * this is just a backup, if all is fine this can be deleted later * * @deprecated */ protected function _checkAgainstPrivTables() { // 1. get allowed dbs from the "mysql.db" table // lem9: User can be blank (anonymous user) $local_query = " SELECT DISTINCT `Db` FROM `mysql`.`db` WHERE `Select_priv` = 'Y' AND `User` IN ('" . PMA_sqlAddslashes($GLOBALS['cfg']['Server']['user']) . "', '')"; $tmp_mydbs = PMA_DBI_fetch_result($local_query, null, null, $GLOBALS['controllink']); if ($tmp_mydbs) { // Will use as associative array of the following 2 code // lines: // the 1st is the only line intact from before // correction, // the 2nd replaces $dblist[] = $row['Db']; // Code following those 2 lines in correction continues // populating $dblist[], as previous code did. But it is // now populated with actual database names instead of // with regular expressions. $tmp_alldbs = PMA_DBI_query('SHOW DATABASES;', $GLOBALS['controllink']); // loic1: all databases cases - part 2 if (isset($tmp_mydbs['%'])) { while ($tmp_row = PMA_DBI_fetch_row($tmp_alldbs)) { $dblist[] = $tmp_row[0]; } // end while } else { while ($tmp_row = PMA_DBI_fetch_row($tmp_alldbs)) { $tmp_db = $tmp_row[0]; if (isset($tmp_mydbs[$tmp_db]) && $tmp_mydbs[$tmp_db] == 1) { $dblist[] = $tmp_db; $tmp_mydbs[$tmp_db] = 0; } elseif (!isset($dblist[$tmp_db])) { foreach ($tmp_mydbs as $tmp_matchpattern => $tmp_value) { // loic1: fixed bad regexp // TODO: db names may contain characters // that are regexp instructions $re = '(^|(\\\\\\\\)+|[^\])'; $tmp_regex = preg_replace('/' . addcslashes($re,'/') . '%/', '\\1.*', preg_replace('/' . addcslashes($re,'/') . '_/', '\\1.{1}', $tmp_matchpattern)); // Fixed db name matching // 2000-08-28 -- Benjamin Gandon if (preg_match('/^' . addcslashes($tmp_regex,'/') . '$/', $tmp_db)) { $dblist[] = $tmp_db; break; } } // end while } // end if ... elseif ... } // end while } // end else PMA_DBI_free_result($tmp_alldbs); unset($tmp_mydbs); } // end if // 2. get allowed dbs from the "mysql.tables_priv" table $local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($GLOBALS['cfg']['Server']['user']) . '\''; $rs = PMA_DBI_try_query($local_query, $GLOBALS['controllink']); if ($rs && @PMA_DBI_num_rows($rs)) { while ($row = PMA_DBI_fetch_assoc($rs)) { if (!in_array($row['Db'], $dblist)) { $dblist[] = $row['Db']; } } // end while PMA_DBI_free_result($rs); } // end if }
// end for break; case 'deleteCrap': foreach ($delrow as $current_row) { $d_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n" . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n" . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n" . ' AND pdf_page_number = ' . $chpage; PMA_query_as_cu($d_query, FALSE, $query_default_option); } break; } // end switch } // end if (isset($do)) // We will need an array of all tables in this db $selectboxall = array('--'); $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); while ($val = @PMA_DBI_fetch_row($alltab_rs)) { $selectboxall[] = $val[0]; } // Now first show some possibility to choose a page for the pdf $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''; $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option); if ($page_rs && PMA_DBI_num_rows($page_rs) > 0) { ?> <form method="get" action="pdf_pages.php" name="selpage"> <fieldset> <legend> <?php echo $strChoosePage . "\n"; ?> </legend> <?php
/** * Gets the sql command from a bookmark * * @global resource the controluser db connection handle * * @param string the current database name * @param array the bookmark parameters for the current user * @param mixed the id of the bookmark to get * @param string which field to look up the $id * @param boolean TRUE: get all bookmarks regardless of the owning user * * @return string the sql query * * @access public */ function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id', $action_bookmark_all = FALSE) { global $controllink; if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) { return ''; } $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' . ($action_bookmark_all ? '' : ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' . ' OR user = \'\')') . ' AND ' . PMA_backquote($id_field) . ' = ' . $id; $result = PMA_DBI_try_query($query, $controllink); if (!$result) { return FALSE; } list($bookmark_query) = PMA_DBI_fetch_row($result) or array(FALSE); return $bookmark_query; }
*/ if (!defined('PHPMYADMIN')) { exit; } /** * */ if ($plugin_param !== 'table') { return; } if (isset($plugin_list)) { if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') { $GLOBALS['cfg']['Import']['ldi_local_option'] = FALSE; $result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';'); if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { $tmp = PMA_DBI_fetch_row($result); if ($tmp[1] == 'ON') { $GLOBALS['cfg']['Import']['ldi_local_option'] = TRUE; } } PMA_DBI_free_result($result); unset($result); } $plugin_list['ldi'] = array('text' => __('CSV using LOAD DATA'), 'extension' => 'ldi', 'options' => array(array('type' => 'begin_group', 'name' => 'general_opts'), array('type' => 'bool', 'name' => 'replace', 'text' => __('Replace table data with file')), array('type' => 'bool', 'name' => 'ignore', 'text' => __('Do not abort on INSERT error')), array('type' => 'text', 'name' => 'terminated', 'text' => __('Columns terminated by'), 'size' => 2, 'len' => 2), array('type' => 'text', 'name' => 'enclosed', 'text' => __('Columns enclosed by'), 'size' => 2, 'len' => 2), array('type' => 'text', 'name' => 'escaped', 'text' => __('Columns escaped by'), 'size' => 2, 'len' => 2), array('type' => 'text', 'name' => 'new_line', 'text' => __('Lines terminated by'), 'size' => 2), array('type' => 'text', 'name' => 'columns', 'text' => __('Column names')), array('type' => 'bool', 'name' => 'local_option', 'text' => __('Use LOCAL keyword')), array('type' => 'end_group')), 'options_text' => __('Options')); /* We do not define function when plugin is just queried for information above */ return; } if ($import_file == 'none' || $compression != 'none' || $charset_conversion) { // We handle only some kind of data! $message = PMA_Message::error(__('This plugin does not support compressed imports!')); $error = TRUE;
//$tables = PMA_DBI_get_columns_full($GLOBALS['db']); /** * Prepares the form */ $tbl_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); $tbl_result_cnt = PMA_DBI_num_rows($tbl_result); if (0 == $tbl_result_cnt) { echo '<div class="warning">' . $strNoTablesFound . '</div>'; require_once './libs/footer.inc.php'; exit; } $i = 0; $k = 0; // The tables list gets from MySQL while ($i < $tbl_result_cnt) { list($tbl) = PMA_DBI_fetch_row($tbl_result); $fld_results = PMA_DBI_get_fields($db, $tbl); $fld_results_cnt = $fld_results ? count($fld_results) : 0; $j = 0; if (empty($tbl_names[$tbl]) && !empty($TableList)) { $tbl_names[$tbl] = ''; } else { $tbl_names[$tbl] = ' selected="selected"'; } // end if // The fields list per selected tables if ($tbl_names[$tbl] == ' selected="selected"') { $fld[$k++] = PMA_backquote($tbl) . '.*'; while ($j < $fld_results_cnt) { $fld[$k] = PMA_convert_display_charset($fld_results[$j]['Field']); $fld[$k] = PMA_backquote($tbl) . '.' . PMA_backquote($fld[$k]);