/**
* Prints details about the current Git commit revision
*
* @return void
*/
function PMA_printGitRevision()
{
    if (!$GLOBALS['PMA_Config']->get('PMA_VERSION_GIT')) {
        $response = PMA_Response::getInstance();
        $response->isSuccess(false);
        return;
    }
    // load revision data from repo
    $GLOBALS['PMA_Config']->checkGitRevision();
    // if using a remote commit fast-forwarded, link to GitHub
    $commit_hash = substr($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'), 0, 7);
    $commit_hash = '<strong title="' . htmlspecialchars($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_MESSAGE')) . '">' . $commit_hash . '</strong>';
    if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) {
        $commit_hash = '<a href="' . PMA_linkURL('https://github.com/phpmyadmin/phpmyadmin/commit/' . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH')) . '" target="_blank">' . $commit_hash . '</a>';
    }
    $branch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH');
    if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH')) {
        $branch = '<a href="' . PMA_linkURL('https://github.com/phpmyadmin/phpmyadmin/tree/' . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH')) . '" target="_blank">' . $branch . '</a>';
    }
    if ($branch !== false) {
        $branch = sprintf(__('%1$s from %2$s branch'), $commit_hash, $branch);
    } else {
        $branch = $commit_hash . ' (' . __('no branch') . ')';
    }
    $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER');
    $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR');
    PMA_printListItem(__('Git revision:') . ' ' . $branch . ',<br /> ' . sprintf(__('committed on %1$s by %2$s'), PMA_Util::localisedDate(strtotime($committer['date'])), '<a href="' . PMA_linkURL('mailto:' . $committer['email']) . '">' . htmlspecialchars($committer['name']) . '</a>') . ($author != $committer ? ', <br />' . sprintf(__('authored on %1$s by %2$s'), PMA_Util::localisedDate(strtotime($author['date'])), '<a href="' . PMA_linkURL('mailto:' . $author['email']) . '">' . htmlspecialchars($author['name']) . '</a>') : ''), 'li_pma_version_git', null, null, null);
}
/**
 * Prints server state General information
 *
 * @param PMA_ServerStatusData $ServerStatusData Server status data
 *
 * @return string
 */
function PMA_getHtmlForServerStateGeneralInfo($ServerStatusData)
{
    $start_time = $GLOBALS['dbi']->fetchValue('SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']);
    $retval = '<h3>';
    $bytes_received = $ServerStatusData->status['Bytes_received'];
    $bytes_sent = $ServerStatusData->status['Bytes_sent'];
    $retval .= sprintf(__('Network traffic since startup: %s'), implode(' ', PMA_Util::formatByteDown($bytes_received + $bytes_sent, 3, 1)));
    $retval .= '</h3>';
    $retval .= '<p>';
    $retval .= sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'), PMA_Util::timespanFormat($ServerStatusData->status['Uptime']), PMA_Util::localisedDate($start_time)) . "\n";
    $retval .= '</p>';
    return $retval;
}
Ejemplo n.º 3
0
 /**
  * This function must be named "Footer" to work with the TCPDF library
  *
  * @return void
  */
 function Footer()
 {
     // Check if footer for this page already exists
     if (!isset($this->footerset[$this->page])) {
         $this->SetY(-15);
         $this->SetFont(PMA_PDF_FONT, '', 14);
         $this->Cell(0, 6, __('Page number:') . ' ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 'T', 0, 'C');
         $this->Cell(0, 6, PMA_Util::localisedDate(), 0, 1, 'R');
         $this->SetY(20);
         // set footerset
         $this->footerset[$this->page] = 1;
     }
 }
Ejemplo n.º 4
0
/**
 * Prints server state General information
 *
 * @param PMA_ServerStatusData $ServerStatusData Server status data
 *
 * @return string
 */
function PMA_getHtmlForServerStateGeneralInfo($ServerStatusData)
{
    $start_time = $GLOBALS['dbi']->fetchValue('SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']);
    $retval = '<h3>';
    $bytes_received = $ServerStatusData->status['Bytes_received'];
    $bytes_sent = $ServerStatusData->status['Bytes_sent'];
    $retval .= sprintf(__('Network traffic since startup: %s'), implode(' ', PMA_Util::formatByteDown($bytes_received + $bytes_sent, 3, 1)));
    $retval .= '</h3>';
    $retval .= '<p>';
    $retval .= sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'), PMA_Util::timespanFormat($ServerStatusData->status['Uptime']), PMA_Util::localisedDate($start_time)) . "\n";
    $retval .= '</p>';
    if ($GLOBALS['replication_info']['master']['status'] || $GLOBALS['replication_info']['slave']['status']) {
        $retval .= '<p class="notice">';
        if ($GLOBALS['replication_info']['master']['status'] && $GLOBALS['replication_info']['slave']['status']) {
            $retval .= __('This MySQL server works as <b>master</b> and ' . '<b>slave</b> in <b>replication</b> process.');
        } elseif ($GLOBALS['replication_info']['master']['status']) {
            $retval .= __('This MySQL server works as <b>master</b> ' . 'in <b>replication</b> process.');
        } elseif ($GLOBALS['replication_info']['slave']['status']) {
            $retval .= __('This MySQL server works as <b>slave</b> ' . 'in <b>replication</b> process.');
        }
        $retval .= '</p>';
    }
    /*
     * if the server works as master or slave in replication process,
     * display useful information
     */
    if ($GLOBALS['replication_info']['master']['status'] || $GLOBALS['replication_info']['slave']['status']) {
        $retval .= '<hr class="clearfloat" />';
        $retval .= '<h3><a name="replication">';
        $retval .= __('Replication status');
        $retval .= '</a></h3>';
        foreach ($GLOBALS['replication_types'] as $type) {
            if (isset($GLOBALS['replication_info'][$type]['status']) && $GLOBALS['replication_info'][$type]['status']) {
                $retval .= PMA_getHtmlForReplicationStatusTable($type);
            }
        }
    }
    return $retval;
}
 /**
  * Generates data dictionary pages.
  *
  * @param array $alltables Tables to document.
  *
  * @return void
  */
 public function dataDictionaryDoc($alltables)
 {
     // TOC
     $this->diagram->addpage($this->orientation);
     $this->diagram->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
     $this->diagram->Ln(15);
     $i = 1;
     foreach ($alltables as $table) {
         $this->diagram->PMA_links['doc'][$table]['-'] = $this->diagram->AddLink();
         $this->diagram->SetX(10);
         // $this->diagram->Ln(1);
         $this->diagram->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $this->diagram->PMA_links['doc'][$table]['-']);
         $this->diagram->SetX(10);
         $this->diagram->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $this->diagram->PMA_links['doc'][$table]['-']);
         // $this->diagram->Ln(1);
         $fields = $GLOBALS['dbi']->getColumns($this->db, $table);
         foreach ($fields as $row) {
             $this->diagram->SetX(20);
             $field_name = $row['Field'];
             $this->diagram->PMA_links['doc'][$table][$field_name] = $this->diagram->AddLink();
             //$this->diagram->Cell(
             //    0, 6, $field_name, 0, 1,
             //    'L', 0, $this->diagram->PMA_links['doc'][$table][$field_name]
             //);
         }
         $i++;
     }
     $this->diagram->PMA_links['RT']['-'] = $this->diagram->AddLink();
     $this->diagram->SetX(10);
     $this->diagram->Cell(0, 6, __('Page number:') . ' {00}', 0, 0, 'R', 0, $this->diagram->PMA_links['RT']['-']);
     $this->diagram->SetX(10);
     $this->diagram->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $this->diagram->PMA_links['RT']['-']);
     $z = 0;
     foreach ($alltables as $table) {
         $z++;
         $this->diagram->SetAutoPageBreak(true, 15);
         $this->diagram->addpage($this->orientation);
         $this->diagram->Bookmark($table);
         $this->diagram->SetAlias('{' . sprintf("%02d", $z) . '}', $this->diagram->PageNo());
         $this->diagram->PMA_links['RT'][$table]['-'] = $this->diagram->AddLink();
         $this->diagram->SetLink($this->diagram->PMA_links['doc'][$table]['-'], -1);
         $this->diagram->SetFont($this->_ff, 'B', 18);
         $this->diagram->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $this->diagram->PMA_links['RT'][$table]['-']);
         $this->diagram->SetFont($this->_ff, '', 8);
         $this->diagram->ln();
         $cfgRelation = PMA_getRelationsParam();
         $comments = PMA_getComments($this->db, $table);
         if ($cfgRelation['mimework']) {
             $mime_map = PMA_getMIME($this->db, $table, true);
         }
         /**
          * Gets table information
          */
         $showtable = $GLOBALS['dbi']->getTable($this->db, $table)->getStatusInfo();
         $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
         $create_time = isset($showtable['Create_time']) ? PMA_Util::localisedDate(strtotime($showtable['Create_time'])) : '';
         $update_time = isset($showtable['Update_time']) ? PMA_Util::localisedDate(strtotime($showtable['Update_time'])) : '';
         $check_time = isset($showtable['Check_time']) ? PMA_Util::localisedDate(strtotime($showtable['Check_time'])) : '';
         /**
          * Gets fields properties
          */
         $columns = $GLOBALS['dbi']->getColumns($this->db, $table);
         // Check if we can use Relations
         if (!empty($cfgRelation['relation'])) {
             // Find which tables are related with the current one and write it in
             // an array
             $res_rel = PMA_getForeigners($this->db, $table);
         }
         // end if
         /**
          * Displays the comments of the table if MySQL >= 3.23
          */
         $break = false;
         if (!empty($show_comment)) {
             $this->diagram->Cell(0, 3, __('Table comments:') . ' ' . $show_comment, 0, 1);
             $break = true;
         }
         if (!empty($create_time)) {
             $this->diagram->Cell(0, 3, __('Creation:') . ' ' . $create_time, 0, 1);
             $break = true;
         }
         if (!empty($update_time)) {
             $this->diagram->Cell(0, 3, __('Last update:') . ' ' . $update_time, 0, 1);
             $break = true;
         }
         if (!empty($check_time)) {
             $this->diagram->Cell(0, 3, __('Last check:') . ' ' . $check_time, 0, 1);
             $break = true;
         }
         if ($break == true) {
             $this->diagram->Cell(0, 3, '', 0, 1);
             $this->diagram->Ln();
         }
         $this->diagram->SetFont($this->_ff, 'B');
         if (isset($this->orientation) && $this->orientation == 'L') {
             $this->diagram->Cell(25, 8, __('Column'), 1, 0, 'C');
             $this->diagram->Cell(20, 8, __('Type'), 1, 0, 'C');
             $this->diagram->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $this->diagram->Cell(10, 8, __('Null'), 1, 0, 'C');
             $this->diagram->Cell(20, 8, __('Default'), 1, 0, 'C');
             $this->diagram->Cell(25, 8, __('Extra'), 1, 0, 'C');
             $this->diagram->Cell(45, 8, __('Links to'), 1, 0, 'C');
             if ($this->paper == 'A4') {
                 $comments_width = 67;
             } else {
                 // this is really intended for 'letter'
                 /**
                  * @todo find optimal width for all formats
                  */
                 $comments_width = 50;
             }
             $this->diagram->Cell($comments_width, 8, __('Comments'), 1, 0, 'C');
             $this->diagram->Cell(45, 8, 'MIME', 1, 1, 'C');
             $this->diagram->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
         } else {
             $this->diagram->Cell(20, 8, __('Column'), 1, 0, 'C');
             $this->diagram->Cell(20, 8, __('Type'), 1, 0, 'C');
             $this->diagram->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $this->diagram->Cell(10, 8, __('Null'), 1, 0, 'C');
             $this->diagram->Cell(15, 8, __('Default'), 1, 0, 'C');
             $this->diagram->Cell(15, 8, __('Extra'), 1, 0, 'C');
             $this->diagram->Cell(30, 8, __('Links to'), 1, 0, 'C');
             $this->diagram->Cell(30, 8, __('Comments'), 1, 0, 'C');
             $this->diagram->Cell(30, 8, 'MIME', 1, 1, 'C');
             $this->diagram->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
         }
         $this->diagram->SetFont($this->_ff, '');
         foreach ($columns as $row) {
             $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
             $type = $extracted_columnspec['print_type'];
             $attribute = $extracted_columnspec['attribute'];
             if (!isset($row['Default'])) {
                 if ($row['Null'] != '' && $row['Null'] != 'NO') {
                     $row['Default'] = 'NULL';
                 }
             }
             $field_name = $row['Field'];
             // $this->diagram->Ln();
             $this->diagram->PMA_links['RT'][$table][$field_name] = $this->diagram->AddLink();
             $this->diagram->Bookmark($field_name, 1, -1);
             $this->diagram->SetLink($this->diagram->PMA_links['doc'][$table][$field_name], -1);
             $foreigner = PMA_searchColumnInForeigners($res_rel, $field_name);
             $linksTo = '';
             if ($foreigner) {
                 $linksTo = '-> ';
                 if ($foreigner['foreign_db'] != $this->db) {
                     $linksTo .= $foreigner['foreign_db'] . '.';
                 }
                 $linksTo .= $foreigner['foreign_table'] . '.' . $foreigner['foreign_field'];
                 if (isset($foreigner['on_update'])) {
                     // not set for internal
                     $linksTo .= "\n" . 'ON UPDATE ' . $foreigner['on_update'];
                     $linksTo .= "\n" . 'ON DELETE ' . $foreigner['on_delete'];
                 }
             }
             $this->diagram_row = array($field_name, $type, $attribute, $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'), isset($row['Default']) ? $row['Default'] : '', $row['Extra'], $linksTo, isset($comments[$field_name]) ? $comments[$field_name] : '', isset($mime_map) && isset($mime_map[$field_name]) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '');
             $links = array();
             $links[0] = $this->diagram->PMA_links['RT'][$table][$field_name];
             if ($foreigner && isset($this->diagram->PMA_links['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']])) {
                 $links[6] = $this->diagram->PMA_links['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']];
             } else {
                 unset($links[6]);
             }
             $this->diagram->Row($this->diagram_row, $links);
         }
         // end foreach
         $this->diagram->SetFont($this->_ff, '', 14);
     }
     //end each
 }
 /**
  * Outputs export header
  *
  * @return bool Whether it succeeded
  */
 public function exportHeader()
 {
     global $crlf;
     global $cfg;
     $head = '% phpMyAdmin LaTeX Dump' . $crlf . '% version ' . PMA_VERSION . $crlf . '% http://www.phpmyadmin.net' . $crlf . '%' . $crlf . '% ' . __('Host:') . ' ' . $cfg['Server']['host'];
     if (!empty($cfg['Server']['port'])) {
         $head .= ':' . $cfg['Server']['port'];
     }
     $head .= $crlf . '% ' . __('Generation Time:') . ' ' . PMA_Util::localisedDate() . $crlf . '% ' . __('Server version:') . ' ' . PMA_MYSQL_STR_VERSION . $crlf . '% ' . __('PHP Version:') . ' ' . phpversion() . $crlf;
     return PMA_exportOutputHandler($head);
 }
Ejemplo n.º 7
0
/**
 * Prints server traffic information
 *
 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
 *
 * @return string
 */
function getServerTrafficHtml($ServerStatusData)
{
    $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
    $start_time = PMA_DBI_fetch_value('SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']);
    $retval = '<h3>';
    $retval .= sprintf(__('Network traffic since startup: %s'), implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1)));
    $retval .= '</h3>';
    $retval .= '<p>';
    $retval .= sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'), PMA_Util::timespanFormat($ServerStatusData->status['Uptime']), PMA_Util::localisedDate($start_time)) . "\n";
    $retval .= '</p>';
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<p class="notice">';
        if ($GLOBALS['server_master_status'] && $GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>master</b> and ' . '<b>slave</b> in <b>replication</b> process.');
        } elseif ($GLOBALS['server_master_status']) {
            $retval .= __('This MySQL server works as <b>master</b> ' . 'in <b>replication</b> process.');
        } elseif ($GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>slave</b> ' . 'in <b>replication</b> process.');
        }
        $retval .= ' ';
        $retval .= __('For further information about replication status on the server, ' . 'please visit the <a href="#replication">replication section</a>.');
        $retval .= '</p>';
    }
    /*
     * if the server works as master or slave in replication process,
     * display useful information
     */
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<hr class="clearfloat" />';
        $retval .= '<h3><a name="replication">';
        $retval .= __('Replication status');
        $retval .= '</a></h3>';
        foreach ($GLOBALS['replication_types'] as $type) {
            if (isset(${"server_{$type}_status"}) && ${"server_{$type}_status"}) {
                PMA_replication_print_status_table($type);
            }
        }
    }
    $retval .= '<table id="serverstatustraffic" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">';
    $retval .= __('Traffic') . '&nbsp;';
    $retval .= PMA_Util::showHint(__('On a busy server, the byte counters may overrun, so those statistics ' . 'as reported by the MySQL server may be incorrect.'));
    $retval .= '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Received') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Sent') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value"><?php echo';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown(($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent']) * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $retval .= '<table id="serverstatusconnections" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">' . __('Connections') . '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '<th>%</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('max. concurrent connections') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Max_used_connections'], 0);
    $retval .= '</td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Aborted') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'], 4, 0);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'] * $hour_factor, 4, 2);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber(100, 0, 2);
    $retval .= '%</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $url_params = array();
    $show_full_sql = !empty($_REQUEST['full']);
    if ($show_full_sql) {
        $url_params['full'] = 1;
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
    } else {
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
    }
    // This array contains display name and real column name of each
    // sortable column in the table
    $sortable_columns = array(array('column_name' => __('ID'), 'order_by_field' => 'Id'), array('column_name' => __('User'), 'order_by_field' => 'User'), array('column_name' => __('Host'), 'order_by_field' => 'Host'), array('column_name' => __('Database'), 'order_by_field' => 'db'), array('column_name' => __('Command'), 'order_by_field' => 'Command'), array('column_name' => __('Time'), 'order_by_field' => 'Time'), array('column_name' => __('Status'), 'order_by_field' => 'State'), array('column_name' => __('SQL query'), 'order_by_field' => 'Info'));
    $sortable_columns_count = count($sortable_columns);
    if (PMA_DRIZZLE) {
        $sql_query = "SELECT\n                p.id       AS Id,\n                p.username AS User,\n                p.host     AS Host,\n                p.db       AS db,\n                p.command  AS Command,\n                p.time     AS Time,\n                p.state    AS State,\n                " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int) $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info\n            FROM data_dictionary.PROCESSLIST p\n                " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' ' . $_REQUEST['sort_order'];
        }
    } else {
        $sql_query = $show_full_sql ? 'SHOW FULL PROCESSLIST' : 'SHOW PROCESSLIST';
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ORDER BY `' . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
        }
    }
    $result = PMA_DBI_query($sql_query);
    /**
     * Displays the page
     */
    $retval .= '<table id="tableprocesslist" class="data clearfloat noclick sortable">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th>' . __('Processes') . '</th>';
    foreach ($sortable_columns as $column) {
        $is_sorted = !empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order']) && $_REQUEST['order_by_field'] == $column['order_by_field'];
        $column['sort_order'] = 'ASC';
        if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
            $column['sort_order'] = 'DESC';
        }
        if ($is_sorted) {
            if ($_REQUEST['sort_order'] == 'ASC') {
                $asc_display_style = 'inline';
                $desc_display_style = 'none';
            } elseif ($_REQUEST['sort_order'] == 'DESC') {
                $desc_display_style = 'inline';
                $asc_display_style = 'none';
            }
        }
        $retval .= '<th>';
        $retval .= '<a href="server_status.php' . PMA_generate_common_url($column) . '" ';
        if ($is_sorted) {
            $retval .= 'onmouseout="$(\'.soimg\').toggle()" ' . 'onmouseover="$(\'.soimg\').toggle()"';
        }
        $retval .= '>';
        $retval .= $column['column_name'];
        if ($is_sorted) {
            $retval .= '<img class="icon ic_s_desc soimg" alt="' . __('Descending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $desc_display_style . '" />';
            $retval .= '<img class="icon ic_s_asc soimg hide" alt="' . __('Ascending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $asc_display_style . '" />';
        }
        $retval .= '</a>';
        if (!PMA_DRIZZLE && 0 === --$sortable_columns_count) {
            $retval .= '<a href="' . $full_text_link . '">';
            if ($show_full_sql) {
                $retval .= PMA_Util::getImage('s_partialtext.png', __('Truncate Shown Queries'));
            } else {
                $retval .= PMA_Util::getImage('s_fulltext.png', __('Show Full Queries'));
            }
            $retval .= '</a>';
        }
        $retval .= '</th>';
    }
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $odd_row = true;
    while ($process = PMA_DBI_fetch_assoc($result)) {
        // Array keys need to modify due to the way it has used
        // to display column values
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            foreach (array_keys($process) as $key) {
                $new_key = ucfirst(strtolower($key));
                $process[$new_key] = $process[$key];
                unset($process[$key]);
            }
        }
        $url_params['kill'] = $process['Id'];
        $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
        $retval .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
        $retval .= '<td><a href="' . $kill_process . '">' . __('Kill') . '</a></td>';
        $retval .= '<td class="value">' . $process['Id'] . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
        $retval .= '<td>' . (!isset($process['db']) || !strlen($process['db']) ? '<i>' . __('None') . '</i>' : htmlspecialchars($process['db'])) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
        $retval .= '<td class="value">' . $process['Time'] . '</td>';
        $retval .= '<td>' . (empty($process['State']) ? '---' : $process['State']) . '</td>';
        $retval .= '<td>';
        if (empty($process['Info'])) {
            $retval .= '---';
        } else {
            if (!$show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
                $retval .= htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
            } else {
                $retval .= PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
            }
        }
        $retval .= '</td>';
        $retval .= '</tr>';
        $odd_row = !$odd_row;
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
 /**
  * localised date test, globals are defined
  *
  * @param string $a Current timestamp
  * @param string $b Format
  * @param string $e Expected output
  *
  * @return void
  *
  * @dataProvider localisedDateDataProvider
  */
 public function testLocalisedDate($a, $b, $e)
 {
     $this->assertEquals($e, PMA_Util::localisedDate($a, $b));
 }
Ejemplo n.º 9
0
 /**
  * Returns $table's CREATE definition
  *
  * @param string $db            the database name
  * @param string $table         the table name
  * @param string $crlf          the end of line sequence
  * @param string $error_url     the url to go back in case of error
  * @param bool   $show_dates    whether to include creation/update/check
  *                              dates
  * @param bool   $add_semicolon whether to add semicolon and end-of-line at
  *                              the end
  * @param bool   $view          whether we're handling a view
  *
  * @return string resulting schema
  */
 public function getTableDef($db, $table, $crlf, $error_url, $show_dates = false, $add_semicolon = true, $view = false)
 {
     global $sql_drop_table, $sql_backquotes, $sql_constraints, $sql_constraints_query, $sql_drop_foreign_keys;
     $schema_create = '';
     $auto_increment = '';
     $new_crlf = $crlf;
     if (isset($GLOBALS['sql_compatibility'])) {
         $compat = $GLOBALS['sql_compatibility'];
     } else {
         $compat = 'NONE';
     }
     // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli
     $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db) . ' LIKE \'' . PMA_Util::sqlAddSlashes($table, true) . '\'', null, PMA_DBI_QUERY_STORE);
     if ($result != false) {
         if (PMA_DBI_num_rows($result) > 0) {
             $tmpres = PMA_DBI_fetch_assoc($result);
             if (PMA_DRIZZLE && $show_dates) {
                 // Drizzle doesn't give Create_time and Update_time in
                 // SHOW TABLE STATUS, add it
                 $sql = "SELECT\n                            TABLE_CREATION_TIME AS Create_time,\n                            TABLE_UPDATE_TIME AS Update_time\n                        FROM data_dictionary.TABLES\n                        WHERE TABLE_SCHEMA = '" . PMA_Util::sqlAddSlashes($db) . "'\n                          AND TABLE_NAME = '" . PMA_Util::sqlAddSlashes($table) . "'";
                 $tmpres = array_merge(PMA_DBI_fetch_single_row($sql), $tmpres);
             }
             // Here we optionally add the AUTO_INCREMENT next value,
             // but starting with MySQL 5.0.24, the clause is already included
             // in SHOW CREATE TABLE so we'll remove it below
             // It's required for Drizzle because SHOW CREATE TABLE uses
             // the value from table's creation time
             if (isset($GLOBALS['sql_auto_increment']) && !empty($tmpres['Auto_increment'])) {
                 $auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
             }
             if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
                 $schema_create .= $this->_exportComment(__('Creation') . ': ' . PMA_Util::localisedDate(strtotime($tmpres['Create_time'])));
                 $new_crlf = $this->_exportComment() . $crlf;
             }
             if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
                 $schema_create .= $this->_exportComment(__('Last update') . ': ' . PMA_Util::localisedDate(strtotime($tmpres['Update_time'])));
                 $new_crlf = $this->_exportComment() . $crlf;
             }
             if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
                 $schema_create .= $this->_exportComment(__('Last check') . ': ' . PMA_Util::localisedDate(strtotime($tmpres['Check_time'])));
                 $new_crlf = $this->_exportComment() . $crlf;
             }
         }
         PMA_DBI_free_result($result);
     }
     $schema_create .= $new_crlf;
     // no need to generate a DROP VIEW here, it was done earlier
     if (!empty($sql_drop_table) && !PMA_Table::isView($db, $table)) {
         $schema_create .= 'DROP TABLE IF EXISTS ' . PMA_Util::backquote($table, $sql_backquotes) . ';' . $crlf;
     }
     // Complete table dump,
     // Whether to quote table and column names or not
     // Drizzle always quotes names
     if (!PMA_DRIZZLE) {
         if ($sql_backquotes) {
             PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 1');
         } else {
             PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 0');
         }
     }
     // I don't see the reason why this unbuffered query could cause problems,
     // because SHOW CREATE TABLE returns only one row, and we free the
     // results below. Nonetheless, we got 2 user reports about this
     // (see bug 1562533) so I removed the unbuffered mode.
     // $result = PMA_DBI_query('SHOW CREATE TABLE ' . backquote($db)
     // . '.' . backquote($table), null, PMA_DBI_QUERY_UNBUFFERED);
     //
     // Note: SHOW CREATE TABLE, at least in MySQL 5.1.23, does not
     // produce a displayable result for the default value of a BIT
     // column, nor does the mysqldump command. See MySQL bug 35796
     $result = PMA_DBI_try_query('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table));
     // an error can happen, for example the table is crashed
     $tmp_error = PMA_DBI_getError();
     if ($tmp_error) {
         return $this->_exportComment(__('in use') . '(' . $tmp_error . ')');
     }
     if ($result != false && ($row = PMA_DBI_fetch_row($result))) {
         $create_query = $row[1];
         unset($row);
         // Convert end of line chars to one that we want (note that MySQL
         // doesn't return query it will accept in all cases)
         if (strpos($create_query, "(\r\n ")) {
             $create_query = str_replace("\r\n", $crlf, $create_query);
         } elseif (strpos($create_query, "(\n ")) {
             $create_query = str_replace("\n", $crlf, $create_query);
         } elseif (strpos($create_query, "(\r ")) {
             $create_query = str_replace("\r", $crlf, $create_query);
         }
         /*
          * Drop database name from VIEW creation.
          *
          * This is a bit tricky, but we need to issue SHOW CREATE TABLE with
          * database name, but we don't want name to show up in CREATE VIEW
          * statement.
          */
         if ($view) {
             $create_query = preg_replace('/' . PMA_Util::backquote($db) . '\\./', '', $create_query);
         }
         // Should we use IF NOT EXISTS?
         // It always must be OFF for MSSQL compatibility mode
         if (isset($GLOBALS['sql_if_not_exists']) && $compat != 'MSSQL') {
             $create_query = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $create_query);
         }
         // In MSSQL
         // 1. DATE field doesn't exists, we will use DATETIME instead
         // 2. UNSIGNED attribute doesn't exist
         // 3. No length on INT, TINYINT, SMALLINT, BIGINT and no precision on
         //    FLOAT fields
         // 4. No KEY and INDEX inside CREATE TABLE
         // 5. DOUBLE field doesn't exists, we will use FLOAT instead
         if ($compat == 'MSSQL') {
             // first we need  to replace all lines ended with '" DATE ...,\n'
             // last preg_replace preserve us from situation with date text
             // inside DEFAULT field value
             $create_query = preg_replace("/\" date DEFAULT NULL(,)?\n/", '" datetime DEFAULT NULL$1' . "\n", $create_query);
             $create_query = preg_replace("/\" date NOT NULL(,)?\n/", '" datetime NOT NULL$1' . "\n", $create_query);
             $create_query = preg_replace('/" date NOT NULL DEFAULT \'([^\'])/', '" datetime NOT NULL DEFAULT \'$1', $create_query);
             // next we need to replace all lines ended with ') UNSIGNED ...,'
             // last preg_replace preserve us from situation with unsigned text
             // inside DEFAULT field value
             $create_query = preg_replace("/\\) unsigned NOT NULL(,)?\n/", ') NOT NULL$1' . "\n", $create_query);
             $create_query = preg_replace("/\\) unsigned DEFAULT NULL(,)?\n/", ') DEFAULT NULL$1' . "\n", $create_query);
             $create_query = preg_replace('/\\) unsigned NOT NULL DEFAULT \'([^\'])/', ') NOT NULL DEFAULT \'$1', $create_query);
             // we need to replace all lines ended with
             // '" INT|TINYINT([0-9]{1,}) ...,' last preg_replace preserve us
             // from situation with int([0-9]{1,}) text inside DEFAULT field
             // value
             $create_query = preg_replace('/" (int|tinyint|smallint|bigint)\\([0-9]+\\) DEFAULT NULL(,)?\\n/', '" $1 DEFAULT NULL$2' . "\n", $create_query);
             $create_query = preg_replace('/" (int|tinyint|smallint|bigint)\\([0-9]+\\) NOT NULL(,)?\\n/', '" $1 NOT NULL$2' . "\n", $create_query);
             $create_query = preg_replace('/" (int|tinyint|smallint|bigint)\\([0-9]+\\) NOT NULL DEFAULT \'([^\'])/', '" $1 NOT NULL DEFAULT \'$2', $create_query);
             // we need to replace all lines ended with
             // '" FLOAT|DOUBLE([0-9,]{1,}) ...,'
             // last preg_replace preserve us from situation with
             // float([0-9,]{1,}) text inside DEFAULT field value
             $create_query = preg_replace('/" (float|double)(\\([0-9]+,[0-9,]+\\))? DEFAULT NULL(,)?\\n/', '" float DEFAULT NULL$3' . "\n", $create_query);
             $create_query = preg_replace('/" (float|double)(\\([0-9,]+,[0-9,]+\\))? NOT NULL(,)?\\n/', '" float NOT NULL$3' . "\n", $create_query);
             $create_query = preg_replace('/" (float|double)(\\([0-9,]+,[0-9,]+\\))? NOT NULL DEFAULT \'([^\'])/', '" float NOT NULL DEFAULT \'$3', $create_query);
             // @todo remove indexes from CREATE TABLE
         }
         // Drizzle (checked on 2011.03.13) returns ROW_FORMAT surrounded
         // with quotes, which is not accepted by parser
         if (PMA_DRIZZLE) {
             $create_query = preg_replace('/ROW_FORMAT=\'(\\S+)\'/', 'ROW_FORMAT=$1', $create_query);
         }
         // are there any constraints to cut out?
         if (preg_match('@CONSTRAINT|FOREIGN[\\s]+KEY@', $create_query)) {
             // Split the query into lines, so we can easily handle it.
             // We know lines are separated by $crlf (done few lines above).
             $sql_lines = explode($crlf, $create_query);
             $sql_count = count($sql_lines);
             // lets find first line with constraints
             for ($i = 0; $i < $sql_count; $i++) {
                 if (preg_match('@^[\\s]*(CONSTRAINT|FOREIGN[\\s]+KEY)@', $sql_lines[$i])) {
                     break;
                 }
             }
             // If we really found a constraint
             if ($i != $sql_count) {
                 // remove, from the end of create statement
                 $sql_lines[$i - 1] = preg_replace('@,$@', '', $sql_lines[$i - 1]);
                 // prepare variable for constraints
                 if (!isset($sql_constraints)) {
                     if (isset($GLOBALS['no_constraints_comments'])) {
                         $sql_constraints = '';
                     } else {
                         $sql_constraints = $crlf . $this->_exportComment() . $this->_exportComment(__('Constraints for dumped tables')) . $this->_exportComment();
                     }
                 }
                 // comments for current table
                 if (!isset($GLOBALS['no_constraints_comments'])) {
                     $sql_constraints .= $crlf . $this->_exportComment() . $this->_exportComment(__('Constraints for table') . ' ' . PMA_Util::backquoteCompat($table, $compat)) . $this->_exportComment();
                 }
                 // let's do the work
                 $sql_constraints_query .= 'ALTER TABLE ' . PMA_Util::backquoteCompat($table, $compat) . $crlf;
                 $sql_constraints .= 'ALTER TABLE ' . PMA_Util::backquoteCompat($table, $compat) . $crlf;
                 $sql_drop_foreign_keys .= 'ALTER TABLE ' . PMA_Util::backquoteCompat($db, $compat) . '.' . PMA_Util::backquoteCompat($table, $compat) . $crlf;
                 $first = true;
                 for ($j = $i; $j < $sql_count; $j++) {
                     if (preg_match('@CONSTRAINT|FOREIGN[\\s]+KEY@', $sql_lines[$j])) {
                         if (!$first) {
                             $sql_constraints .= $crlf;
                         }
                         if (strpos($sql_lines[$j], 'CONSTRAINT') === false) {
                             $tmp_str = preg_replace('/(FOREIGN[\\s]+KEY)/', 'ADD \\1', $sql_lines[$j]);
                             $sql_constraints_query .= $tmp_str;
                             $sql_constraints .= $tmp_str;
                         } else {
                             $tmp_str = preg_replace('/(CONSTRAINT)/', 'ADD \\1', $sql_lines[$j]);
                             $sql_constraints_query .= $tmp_str;
                             $sql_constraints .= $tmp_str;
                             preg_match('/(CONSTRAINT)([\\s])([\\S]*)([\\s])/', $sql_lines[$j], $matches);
                             if (!$first) {
                                 $sql_drop_foreign_keys .= ', ';
                             }
                             $sql_drop_foreign_keys .= 'DROP FOREIGN KEY ' . $matches[3];
                         }
                         $first = false;
                     } else {
                         break;
                     }
                 }
                 $sql_constraints .= ';' . $crlf;
                 $sql_constraints_query .= ';';
                 $create_query = implode($crlf, array_slice($sql_lines, 0, $i)) . $crlf . implode($crlf, array_slice($sql_lines, $j, $sql_count - 1));
                 unset($sql_lines);
             }
         }
         $schema_create .= $create_query;
     }
     // remove a possible "AUTO_INCREMENT = value" clause
     // that could be there starting with MySQL 5.0.24
     // in Drizzle it's useless as it contains the value given at table
     // creation time
     $schema_create = preg_replace('/AUTO_INCREMENT\\s*=\\s*([0-9])+/', '', $schema_create);
     $schema_create .= $compat != 'MSSQL' ? $auto_increment : '';
     PMA_DBI_free_result($result);
     return $schema_create . ($add_semicolon ? ';' . $crlf : '');
 }
Ejemplo n.º 10
0
 /**
  * Outputs export header. It is the first method to be called, so all
  * the required variables are initialized here.
  *
  * @return bool Whether it succeeded
  */
 public function exportHeader()
 {
     $this->initSpecificVariables();
     global $crlf, $cfg, $db;
     $table = $this->_getTable();
     $tables = $this->_getTables();
     $export_struct = isset($GLOBALS['xml_export_functions']) || isset($GLOBALS['xml_export_procedures']) || isset($GLOBALS['xml_export_tables']) || isset($GLOBALS['xml_export_triggers']) || isset($GLOBALS['xml_export_views']);
     $export_data = isset($GLOBALS['xml_export_contents']) ? true : false;
     if ($GLOBALS['output_charset_conversion']) {
         $charset = $GLOBALS['charset'];
     } else {
         $charset = 'utf-8';
     }
     $head = '<?xml version="1.0" encoding="' . $charset . '"?>' . $crlf . '<!--' . $crlf . '- phpMyAdmin XML Dump' . $crlf . '- version ' . PMA_VERSION . $crlf . '- https://www.phpmyadmin.net' . $crlf . '-' . $crlf . '- ' . __('Host:') . ' ' . $cfg['Server']['host'];
     if (!empty($cfg['Server']['port'])) {
         $head .= ':' . $cfg['Server']['port'];
     }
     $head .= $crlf . '- ' . __('Generation Time:') . ' ' . PMA_Util::localisedDate() . $crlf . '- ' . __('Server version:') . ' ' . PMA_MYSQL_STR_VERSION . $crlf . '- ' . __('PHP Version:') . ' ' . phpversion() . $crlf . '-->' . $crlf . $crlf;
     $head .= '<pma_xml_export version="1.0"' . ($export_struct ? ' xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"' : '') . '>' . $crlf;
     if ($export_struct) {
         if (PMA_DRIZZLE) {
             $result = $GLOBALS['dbi']->fetchResult("SELECT\n                        'utf8' AS DEFAULT_CHARACTER_SET_NAME,\n                        DEFAULT_COLLATION_NAME\n                    FROM data_dictionary.SCHEMAS\n                    WHERE SCHEMA_NAME = '" . PMA_Util::sqlAddSlashes($db) . "'");
         } else {
             $result = $GLOBALS['dbi']->fetchResult('SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`' . ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`' . ' = \'' . PMA_Util::sqlAddSlashes($db) . '\' LIMIT 1');
         }
         $db_collation = $result[0]['DEFAULT_COLLATION_NAME'];
         $db_charset = $result[0]['DEFAULT_CHARACTER_SET_NAME'];
         $head .= '    <!--' . $crlf;
         $head .= '    - Structure schemas' . $crlf;
         $head .= '    -->' . $crlf;
         $head .= '    <pma:structure_schemas>' . $crlf;
         $head .= '        <pma:database name="' . htmlspecialchars($db) . '" collation="' . $db_collation . '" charset="' . $db_charset . '">' . $crlf;
         if (count($tables) == 0) {
             $tables[] = $table;
         }
         foreach ($tables as $table) {
             // Export tables and views
             $result = $GLOBALS['dbi']->fetchResult('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0);
             $tbl = $result[$table][1];
             $is_view = $GLOBALS['dbi']->getTable($db, $table)->isView();
             if ($is_view) {
                 $type = 'view';
             } else {
                 $type = 'table';
             }
             if ($is_view && !isset($GLOBALS['xml_export_views'])) {
                 continue;
             }
             if (!$is_view && !isset($GLOBALS['xml_export_tables'])) {
                 continue;
             }
             $head .= '            <pma:' . $type . ' name="' . $table . '">' . $crlf;
             $tbl = "                " . htmlspecialchars($tbl);
             $tbl = str_replace("\n", "\n                ", $tbl);
             $head .= $tbl . ';' . $crlf;
             $head .= '            </pma:' . $type . '>' . $crlf;
             if (isset($GLOBALS['xml_export_triggers']) && $GLOBALS['xml_export_triggers']) {
                 // Export triggers
                 $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
                 if ($triggers) {
                     foreach ($triggers as $trigger) {
                         $code = $trigger['create'];
                         $head .= '            <pma:trigger name="' . $trigger['name'] . '">' . $crlf;
                         // Do some formatting
                         $code = mb_substr(rtrim($code), 0, -3);
                         $code = "                " . htmlspecialchars($code);
                         $code = str_replace("\n", "\n                ", $code);
                         $head .= $code . $crlf;
                         $head .= '            </pma:trigger>' . $crlf;
                     }
                     unset($trigger);
                     unset($triggers);
                 }
             }
         }
         if (isset($GLOBALS['xml_export_functions']) && $GLOBALS['xml_export_functions']) {
             // Export functions
             $functions = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'FUNCTION');
             if ($functions) {
                 foreach ($functions as $function) {
                     $head .= '            <pma:function name="' . $function . '">' . $crlf;
                     // Do some formatting
                     $sql = $GLOBALS['dbi']->getDefinition($db, 'FUNCTION', $function);
                     $sql = rtrim($sql);
                     $sql = "                " . htmlspecialchars($sql);
                     $sql = str_replace("\n", "\n                ", $sql);
                     $head .= $sql . $crlf;
                     $head .= '            </pma:function>' . $crlf;
                 }
                 unset($function);
                 unset($functions);
             }
         }
         if (isset($GLOBALS['xml_export_procedures']) && $GLOBALS['xml_export_procedures']) {
             // Export procedures
             $procedures = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'PROCEDURE');
             if ($procedures) {
                 foreach ($procedures as $procedure) {
                     $head .= '            <pma:procedure name="' . $procedure . '">' . $crlf;
                     // Do some formatting
                     $sql = $GLOBALS['dbi']->getDefinition($db, 'PROCEDURE', $procedure);
                     $sql = rtrim($sql);
                     $sql = "                " . htmlspecialchars($sql);
                     $sql = str_replace("\n", "\n                ", $sql);
                     $head .= $sql . $crlf;
                     $head .= '            </pma:procedure>' . $crlf;
                 }
                 unset($procedure);
                 unset($procedures);
             }
         }
         if (isset($GLOBALS['xml_export_events']) && $GLOBALS['xml_export_events']) {
             // Export events
             $events = $GLOBALS['dbi']->fetchResult("SELECT EVENT_NAME FROM information_schema.EVENTS " . "WHERE EVENT_SCHEMA='" . PMA_Util::sqlAddslashes($db) . "'");
             if ($events) {
                 foreach ($events as $event) {
                     $head .= '            <pma:event name="' . $event . '">' . $crlf;
                     $sql = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $event);
                     $sql = rtrim($sql);
                     $sql = "                " . htmlspecialchars($sql);
                     $sql = str_replace("\n", "\n                ", $sql);
                     $head .= $sql . $crlf;
                     $head .= '            </pma:event>' . $crlf;
                 }
                 unset($event);
                 unset($events);
             }
         }
         unset($result);
         $head .= '        </pma:database>' . $crlf;
         $head .= '    </pma:structure_schemas>' . $crlf;
         if ($export_data) {
             $head .= $crlf;
         }
     }
     return PMA_exportOutputHandler($head);
 }
Ejemplo n.º 11
0
     if ($cfg['Server']['verbose']) {
         $hostname = $cfg['Server']['verbose'];
     } else {
         $hostname = $cfg['Server']['host'];
         if (!empty($cfg['Server']['port'])) {
             $hostname .= $cfg['Server']['port'];
         }
     }
     $versions = "phpMyAdmin&nbsp;" . PMA_VERSION;
     $versions .= "&nbsp;/&nbsp;";
     $versions .= "MySQL&nbsp;" . PMA_MYSQL_STR_VERSION;
     echo "<h1>" . __('SQL result') . "</h1>";
     echo "<p>";
     echo "<strong>" . __('Host') . ":</strong> {$hostname}<br />";
     echo "<strong>" . __('Database') . ":</strong> " . htmlspecialchars($db) . "<br />";
     echo "<strong>" . __('Generation Time') . ":</strong> " . PMA_Util::localisedDate() . "<br />";
     echo "<strong>" . __('Generated by') . ":</strong> {$versions}<br />";
     echo "<strong>" . __('SQL query') . ":</strong> " . htmlspecialchars($full_sql_query) . ";";
     if (isset($num_rows)) {
         echo "<br />";
         echo "<strong>" . __('Rows') . ":</strong> {$num_rows}";
     }
     echo "</p>";
 } else {
     $response = PMA_Response::getInstance();
     $header = $response->getHeader();
     $scripts = $header->getScripts();
     $scripts->addFile('makegrid.js');
     $scripts->addFile('sql.js');
     unset($message);
     if (!$GLOBALS['is_ajax_request']) {
             }
             if (isset($showtable['Update_time'])) {
                 echo "\n";
                 echo '<tr>';
                 echo '<td>' . __('Last update') . '</td>';
                 echo '<td class="right">';
                 echo PMA_Util::localisedDate(strtotime($showtable['Update_time']));
                 echo '</td>';
                 echo '</tr>';
             }
             if (isset($showtable['Check_time'])) {
                 echo "\n";
                 echo '<tr>';
                 echo '<td>' . __('Last check') . '</td>';
                 echo '<td class="right">';
                 echo PMA_Util::localisedDate(strtotime($showtable['Check_time']));
                 echo '</td>';
                 echo '</tr>';
             }
             echo "\n";
             echo '</table>';
             echo '</td>';
             echo '</tr>';
             echo '</table>';
         }
         // end if ($nonisam == false)
     }
     // end if ($cfg['ShowStats'])
 }
 if ($multi_tables) {
     unset($num_rows, $show_comment);
/**
 * Function to get html for one of the db dates
 *
 * @param string $title the title 
 * @param string $date  which date to display
 *
 * @return string html content
 */
function PMA_getHtmlForOneDate($title, $date)
{
    $html = '<tr>' . '<td class="right">' . $title . '</td>' . '<td class="right">' . PMA_Util::localisedDate(strtotime($date)) . '</td>' . '</tr>';
    return $html;
}
Ejemplo n.º 14
0
                    <td class="right"><?php 
                echo PMA_Util::localisedDate(strtotime($sts_data['Update_time']));
                ?>
</td>
                </tr>
                <?php 
            }
            if (!empty($sts_data['Check_time'])) {
                ?>
                <tr>
                    <td class="right"><?php 
                echo __('Last check') . ': ';
                ?>
</td>
                    <td class="right"><?php 
                echo PMA_Util::localisedDate(strtotime($sts_data['Check_time']));
                ?>
</td>
                </tr>
                <?php 
            }
            ?>
            </table>
            <?php 
        }
        ?>
    </td>
</tr>
        <?php 
    }
    ?>
Ejemplo n.º 15
0
/**
 * Get HTML snippet for display Row statistics table
 *
 * @param array   $showtable     show table array
 * @param string  $tbl_collation table collation
 * @param boolean $is_innodb     whether table is innob or not
 * @param boolean $mergetable    Checks if current table is a merge table
 * @param integer $avg_size      average size
 * @param string  $avg_unit      average unit
 *
 * @return string $html_output
 */
function getHtmlForRowStatsTable($showtable, $tbl_collation, $is_innodb, $mergetable, $avg_size, $avg_unit)
{
    $odd_row = false;
    $html_output = '<table id="tablerowstats" class="data">';
    $html_output .= '<caption class="tblHeaders">' . __('Row statistics') . '</caption>';
    $html_output .= '<tbody>';
    if (isset($showtable['Row_format'])) {
        if ($showtable['Row_format'] == 'Fixed') {
            $value = __('static');
        } elseif ($showtable['Row_format'] == 'Dynamic') {
            $value = __('dynamic');
        } else {
            $value = $showtable['Row_format'];
        }
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Format'), $value);
        $odd_row = !$odd_row;
    }
    if (!empty($showtable['Create_options'])) {
        if ($showtable['Create_options'] == 'partitioned') {
            $value = __('partitioned');
        } else {
            $value = $showtable['Create_options'];
        }
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Options'), $value);
        $odd_row = !$odd_row;
    }
    if (!empty($tbl_collation)) {
        $value = '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Collation'), $value);
        $odd_row = !$odd_row;
    }
    if (!$is_innodb && isset($showtable['Rows'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Rows'), PMA_Util::formatNumber($showtable['Rows'], 0));
        $odd_row = !$odd_row;
    }
    if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
        list($avg_row_length_value, $avg_row_length_unit) = PMA_Util::formatByteDown($showtable['Avg_row_length'], 6, 1);
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Row length'), $avg_row_length_value . ' ' . $avg_row_length_unit);
        unset($avg_row_length_value, $avg_row_length_unit);
        $odd_row = !$odd_row;
    }
    if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Row size'), $avg_size . ' ' . $avg_unit);
        $odd_row = !$odd_row;
    }
    if (isset($showtable['Auto_increment'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Next autoindex'), PMA_Util::formatNumber($showtable['Auto_increment'], 0));
        $odd_row = !$odd_row;
    }
    if (isset($showtable['Create_time'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Creation'), PMA_Util::localisedDate(strtotime($showtable['Create_time'])));
        $odd_row = !$odd_row;
    }
    if (isset($showtable['Update_time'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Last update'), PMA_Util::localisedDate(strtotime($showtable['Update_time'])));
        $odd_row = !$odd_row;
    }
    if (isset($showtable['Check_time'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Last check'), PMA_Util::localisedDate(strtotime($showtable['Check_time'])));
    }
    $html_output .= '</tbody>' . '</table>';
    return $html_output;
}
Ejemplo n.º 16
0
 /**
  * fills given tooltip arrays
  *
  * @param array &$tooltip_truename  tooltip data
  * @param array &$tooltip_aliasname tooltip data
  * @param array $table              tabledata
  *
  * @return void
  */
 public static function fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
 {
     if (strstr($table['Comment'], '; InnoDB free') === false) {
         if (!strstr($table['Comment'], 'InnoDB free') === false) {
             // here we have just InnoDB generated part
             $table['Comment'] = '';
         }
     } else {
         // remove InnoDB comment from end, just the minimal part
         // (*? is non greedy)
         $table['Comment'] = preg_replace('@; InnoDB free:.*?$@', '', $table['Comment']);
     }
     // views have VIEW as comment so it's not a real comment put by a user
     if ('VIEW' == $table['Comment']) {
         $table['Comment'] = '';
     }
     if (empty($table['Comment'])) {
         $table['Comment'] = $table['Name'];
     } else {
         // todo: why?
         $table['Comment'] .= ' ';
     }
     $tooltip_truename[$table['Name']] = $table['Name'];
     $tooltip_aliasname[$table['Name']] = $table['Comment'];
     if (isset($table['Create_time']) && !empty($table['Create_time'])) {
         $tooltip_aliasname[$table['Name']] .= ', ' . __('Creation') . ': ' . PMA_Util::localisedDate(strtotime($table['Create_time']));
     }
     if (!empty($table['Update_time'])) {
         $tooltip_aliasname[$table['Name']] .= ', ' . __('Last update') . ': ' . PMA_Util::localisedDate(strtotime($table['Update_time']));
     }
     if (!empty($table['Check_time'])) {
         $tooltip_aliasname[$table['Name']] .= ', ' . __('Last check') . ': ' . PMA_Util::localisedDate(strtotime($table['Check_time']));
     }
 }
 /**
  * Tests for PMA_getHtmlForRowStatistics() method.
  *
  * @return void
  * @test
  */
 public function testPMAGetHtmlForRowStatistics()
 {
     $showtable = array('Row_format' => "Fixed", 'Rows' => 10, 'Avg_row_length' => 123, 'Data_length' => 345, 'Auto_increment' => 1234, 'Create_time' => "today", 'Update_time' => "time2", 'Check_time' => "yesterday");
     $cell_align_left = "cell_align_left";
     $avg_size = 12;
     $avg_unit = 45;
     $mergetable = false;
     $html = PMA_getHtmlForRowStatistics($showtable, $cell_align_left, $avg_size, $avg_unit, $mergetable);
     $this->assertContains(__('Row Statistics:'), $html);
     //validation 1 : Row_format
     $this->assertContains(__('Format'), $html);
     $this->assertContains($cell_align_left, $html);
     //$showtable['Row_format'] == 'Fixed'
     $this->assertContains(__('static'), $html);
     //validation 2 : Avg_row_length
     $length = PMA_Util::formatNumber($showtable['Avg_row_length'], 0);
     $this->assertContains($length, $html);
     $this->assertContains(__('Row size'), $html);
     $this->assertContains($avg_size . ' ' . $avg_unit, $html);
     //validation 3 : Auto_increment
     $average = PMA_Util::formatNumber($showtable['Auto_increment'], 0);
     $this->assertContains($average, $html);
     $this->assertContains(__('Next autoindex'), $html);
     //validation 4 : Create_time
     $time = PMA_Util::localisedDate(strtotime($showtable['Create_time']));
     $this->assertContains(__('Creation'), $html);
     $this->assertContains($time, $html);
     //validation 5 : Update_time
     $time = PMA_Util::localisedDate(strtotime($showtable['Update_time']));
     $this->assertContains(__('Last update'), $html);
     $this->assertContains($time, $html);
     //validation 6 : Check_time
     $time = PMA_Util::localisedDate(strtotime($showtable['Check_time']));
     $this->assertContains(__('Last check'), $html);
     $this->assertContains($time, $html);
 }
Ejemplo n.º 18
0
 /**
  * Returns $table's CREATE definition
  *
  * @param string $db                        the database name
  * @param string $table                     the table name
  * @param string $crlf                      the end of line sequence
  * @param string $error_url                 the url to go back in case
  *                                          of error
  * @param bool   $show_dates                whether to include creation/
  *                                          update/check dates
  * @param bool   $add_semicolon             whether to add semicolon and
  *                                          end-of-line at the end
  * @param bool   $view                      whether we're handling a view
  * @param bool   $update_indexes_increments whether we need to update
  *                                          two global variables
  * @param array  $aliases                   Aliases of db/table/columns
  *
  * @return string resulting schema
  */
 public function getTableDef($db, $table, $crlf, $error_url, $show_dates = false, $add_semicolon = true, $view = false, $update_indexes_increments = true, $aliases = array())
 {
     global $sql_drop_table, $sql_backquotes, $sql_constraints, $sql_constraints_query, $sql_indexes, $sql_indexes_query, $sql_auto_increments, $sql_drop_foreign_keys;
     $db_alias = $db;
     $table_alias = $table;
     $this->initAlias($aliases, $db_alias, $table_alias);
     $schema_create = '';
     $auto_increment = '';
     $new_crlf = $crlf;
     if (isset($GLOBALS['sql_compatibility'])) {
         $compat = $GLOBALS['sql_compatibility'];
     } else {
         $compat = 'NONE';
     }
     // need to use PMA_DatabaseInterface::QUERY_STORE
     // with $GLOBALS['dbi']->numRows() in mysqli
     $result = $GLOBALS['dbi']->query('SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db) . ' WHERE Name = \'' . PMA_Util::sqlAddSlashes($table) . '\'', null, PMA_DatabaseInterface::QUERY_STORE);
     if ($result != false) {
         if ($GLOBALS['dbi']->numRows($result) > 0) {
             $tmpres = $GLOBALS['dbi']->fetchAssoc($result);
             if (PMA_DRIZZLE && $show_dates) {
                 // Drizzle doesn't give Create_time and Update_time in
                 // SHOW TABLE STATUS, add it
                 $sql = "SELECT\n                            TABLE_CREATION_TIME AS Create_time,\n                            TABLE_UPDATE_TIME AS Update_time\n                        FROM data_dictionary.TABLES\n                        WHERE TABLE_SCHEMA = '" . PMA_Util::sqlAddSlashes($db) . "'\n                          AND TABLE_NAME = '" . PMA_Util::sqlAddSlashes($table) . "'";
                 $tmpres = array_merge($GLOBALS['dbi']->fetchSingleRow($sql), $tmpres);
             }
             // Here we optionally add the AUTO_INCREMENT next value,
             // but starting with MySQL 5.0.24, the clause is already included
             // in SHOW CREATE TABLE so we'll remove it below
             // It's required for Drizzle because SHOW CREATE TABLE uses
             // the value from table's creation time
             if (isset($GLOBALS['sql_auto_increment']) && !empty($tmpres['Auto_increment'])) {
                 $auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
             }
             if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
                 $schema_create .= $this->_exportComment(__('Creation:') . ' ' . PMA_Util::localisedDate(strtotime($tmpres['Create_time'])));
                 $new_crlf = $this->_exportComment() . $crlf;
             }
             if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
                 $schema_create .= $this->_exportComment(__('Last update:') . ' ' . PMA_Util::localisedDate(strtotime($tmpres['Update_time'])));
                 $new_crlf = $this->_exportComment() . $crlf;
             }
             if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
                 $schema_create .= $this->_exportComment(__('Last check:') . ' ' . PMA_Util::localisedDate(strtotime($tmpres['Check_time'])));
                 $new_crlf = $this->_exportComment() . $crlf;
             }
         }
         $GLOBALS['dbi']->freeResult($result);
     }
     $schema_create .= $new_crlf;
     // no need to generate a DROP VIEW here, it was done earlier
     if (!empty($sql_drop_table) && !PMA_Table::isView($db, $table)) {
         $schema_create .= 'DROP TABLE IF EXISTS ' . PMA_Util::backquote($table_alias, $sql_backquotes) . ';' . $crlf;
     }
     // Complete table dump,
     // Whether to quote table and column names or not
     // Drizzle always quotes names
     if (!PMA_DRIZZLE) {
         if ($sql_backquotes) {
             $GLOBALS['dbi']->query('SET SQL_QUOTE_SHOW_CREATE = 1');
         } else {
             $GLOBALS['dbi']->query('SET SQL_QUOTE_SHOW_CREATE = 0');
         }
     }
     // I don't see the reason why this unbuffered query could cause problems,
     // because SHOW CREATE TABLE returns only one row, and we free the
     // results below. Nonetheless, we got 2 user reports about this
     // (see bug 1562533) so I removed the unbuffered mode.
     // $result = $GLOBALS['dbi']->query('SHOW CREATE TABLE ' . backquote($db)
     // . '.' . backquote($table), null, PMA_DatabaseInterface::QUERY_UNBUFFERED);
     //
     // Note: SHOW CREATE TABLE, at least in MySQL 5.1.23, does not
     // produce a displayable result for the default value of a BIT
     // column, nor does the mysqldump command. See MySQL bug 35796
     $result = $GLOBALS['dbi']->tryQuery('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table));
     // an error can happen, for example the table is crashed
     $tmp_error = $GLOBALS['dbi']->getError();
     if ($tmp_error) {
         return $this->_exportComment(__('in use') . '(' . $tmp_error . ')');
     }
     $warning = '';
     if ($result != false && ($row = $GLOBALS['dbi']->fetchRow($result))) {
         $create_query = $row[1];
         unset($row);
         // Convert end of line chars to one that we want (note that MySQL
         // doesn't return query it will accept in all cases)
         if (mb_strpos($create_query, "(\r\n ")) {
             $create_query = str_replace("\r\n", $crlf, $create_query);
         } elseif (mb_strpos($create_query, "(\n ")) {
             $create_query = str_replace("\n", $crlf, $create_query);
         } elseif (mb_strpos($create_query, "(\r ")) {
             $create_query = str_replace("\r", $crlf, $create_query);
         }
         /*
          * Drop database name from VIEW creation.
          *
          * This is a bit tricky, but we need to issue SHOW CREATE TABLE with
          * database name, but we don't want name to show up in CREATE VIEW
          * statement.
          */
         if ($view) {
             $create_query = preg_replace('/' . preg_quote(PMA_Util::backquote($db)) . '\\./', '', $create_query);
         }
         // substitute aliases in create query
         $create_query = $this->replaceWithAliases($create_query, $aliases, $db, $table, $flag);
         // One warning per view
         if ($flag && $view) {
             $warning = $this->_exportComment() . $this->_exportComment(__('It appears your database uses views;')) . $this->_exportComment(__('alias export may not work reliably in all cases.')) . $this->_exportComment();
         }
         // Should we use IF NOT EXISTS?
         if (isset($GLOBALS['sql_if_not_exists'])) {
             $create_query = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $create_query);
         }
         if ($compat == 'MSSQL') {
             $create_query = $this->_makeCreateTableMSSQLCompatible($create_query);
         }
         // Drizzle (checked on 2011.03.13) returns ROW_FORMAT surrounded
         // with quotes, which is not accepted by parser
         if (PMA_DRIZZLE) {
             $create_query = preg_replace('/ROW_FORMAT=\'(\\S+)\'/', 'ROW_FORMAT=$1', $create_query);
         }
         //are there any constraints to cut out?
         if (preg_match('@CONSTRAINT|KEY@', $create_query)) {
             $has_constraints = 0;
             $has_indexes = 0;
             //if there are constraints
             if (preg_match('@CONSTRAINT@', $create_query)) {
                 $has_constraints = 1;
                 // comments -> constraints for dumped tables
                 if (!isset($sql_constraints)) {
                     if (isset($GLOBALS['no_constraints_comments'])) {
                         $sql_constraints = '';
                     } else {
                         $sql_constraints = $crlf . $this->_exportComment() . $this->_exportComment(__('Constraints for dumped tables')) . $this->_exportComment();
                     }
                 }
                 // comments for current table
                 if (!isset($GLOBALS['no_constraints_comments'])) {
                     $sql_constraints .= $crlf . $this->_exportComment() . $this->_exportComment(__('Constraints for table') . ' ' . PMA_Util::backquoteCompat($table_alias, $compat)) . $this->_exportComment();
                 }
                 $sql_constraints_query .= 'ALTER TABLE ' . PMA_Util::backquoteCompat($table_alias, $compat) . $crlf;
                 $sql_constraints .= 'ALTER TABLE ' . PMA_Util::backquoteCompat($table_alias, $compat) . $crlf;
                 $sql_drop_foreign_keys .= 'ALTER TABLE ' . PMA_Util::backquoteCompat($db_alias, $compat) . '.' . PMA_Util::backquoteCompat($table_alias, $compat) . $crlf;
             }
             //if there are indexes
             // (look for KEY followed by whitespace to avoid matching
             //  keyworks like PACK_KEYS)
             if ($update_indexes_increments && preg_match('@KEY[\\s]+@', $create_query)) {
                 $has_indexes = 1;
                 // comments -> indexes for dumped tables
                 if (!isset($sql_indexes)) {
                     if (isset($GLOBALS['no_constraints_comments'])) {
                         $sql_indexes = '';
                     } else {
                         $sql_indexes = $crlf . $this->_exportComment() . $this->_exportComment(__('Indexes for dumped tables')) . $this->_exportComment();
                     }
                 }
                 // comments for current table
                 if (!isset($GLOBALS['no_constraints_comments'])) {
                     $sql_indexes .= $crlf . $this->_exportComment() . $this->_exportComment(__('Indexes for table') . ' ' . PMA_Util::backquoteCompat($table_alias, $compat)) . $this->_exportComment();
                 }
                 $sql_indexes_query .= 'ALTER TABLE ' . PMA_Util::backquoteCompat($table_alias, $compat) . $crlf;
                 $sql_indexes .= 'ALTER TABLE ' . PMA_Util::backquoteCompat($table_alias, $compat) . $crlf;
             }
             if ($update_indexes_increments && preg_match('@AUTO_INCREMENT@', $create_query)) {
                 // comments -> auto increments for dumped tables
                 if (!isset($sql_auto_increments)) {
                     if (isset($GLOBALS['no_constraints_comments'])) {
                         $sql_auto_increments = '';
                     } else {
                         $sql_auto_increments = $crlf . $this->_exportComment() . $this->_exportComment(__('AUTO_INCREMENT for dumped tables')) . $this->_exportComment();
                     }
                 }
                 // comments for current table
                 if (!isset($GLOBALS['no_constraints_comments'])) {
                     $sql_auto_increments .= $crlf . $this->_exportComment() . $this->_exportComment(__('AUTO_INCREMENT for table') . ' ' . PMA_Util::backquoteCompat($table_alias, $compat)) . $this->_exportComment();
                 }
                 $sql_auto_increments .= 'ALTER TABLE ' . PMA_Util::backquoteCompat($table_alias, $compat) . $crlf;
             }
             // Split the query into lines, so we can easily handle it.
             // We know lines are separated by $crlf (done few lines above).
             $sql_lines = explode($crlf, $create_query);
             $sql_count = count($sql_lines);
             // lets find first line with constraints
             $first_occur = -1;
             for ($i = 0; $i < $sql_count; $i++) {
                 if (preg_match('@[\\s]+(CONSTRAINT|KEY)@', $sql_lines[$i]) && $first_occur == -1) {
                     $first_occur = $i;
                 }
             }
             for ($k = 0; $k < $sql_count; $k++) {
                 if ($update_indexes_increments && preg_match('( AUTO_INCREMENT | AUTO_INCREMENT,| AUTO_INCREMENT$)', $sql_lines[$k])) {
                     //removes extra space at the beginning, if there is
                     $sql_lines[$k] = ltrim($sql_lines[$k], ' ');
                     //creates auto increment code
                     $sql_auto_increments .= "MODIFY " . $sql_lines[$k];
                     //removes auto increment code from table definition
                     $sql_lines[$k] = str_replace(" AUTO_INCREMENT", "", $sql_lines[$k]);
                 }
                 if (isset($GLOBALS['sql_auto_increment']) && $update_indexes_increments && preg_match('@[\\s]+(AUTO_INCREMENT=)@', $sql_lines[$k])) {
                     //adds auto increment value
                     $increment_value = mb_substr($sql_lines[$k], mb_strpos($sql_lines[$k], "AUTO_INCREMENT"));
                     $increment_value_array = explode(' ', $increment_value);
                     $sql_auto_increments .= $increment_value_array[0] . ";";
                 }
             }
             if ($sql_auto_increments != '') {
                 $sql_auto_increments = mb_substr($sql_auto_increments, 0, -1) . ';';
             }
             // If we really found a constraint
             if ($first_occur != $sql_count) {
                 // lets find first line
                 $sql_lines[$first_occur - 1] = preg_replace('@,$@', '', $sql_lines[$first_occur - 1]);
                 $first = true;
                 for ($j = $first_occur; $j < $sql_count; $j++) {
                     //removes extra space at the beginning, if there is
                     $sql_lines[$j] = ltrim($sql_lines[$j], ' ');
                     //if it's a constraint
                     if (preg_match('@CONSTRAINT|FOREIGN[\\s]+KEY@', $sql_lines[$j])) {
                         if (!$first) {
                             $sql_constraints .= $crlf;
                         }
                         $posConstraint = mb_strpos($sql_lines[$j], 'CONSTRAINT');
                         if ($posConstraint === false) {
                             $tmp_str = preg_replace('/(FOREIGN[\\s]+KEY)/', 'ADD \\1', $sql_lines[$j]);
                             $sql_constraints_query .= $tmp_str;
                             $sql_constraints .= $tmp_str;
                         } else {
                             $tmp_str = preg_replace('/(CONSTRAINT)/', 'ADD \\1', $sql_lines[$j]);
                             $sql_constraints_query .= $tmp_str;
                             $sql_constraints .= $tmp_str;
                             preg_match('/(CONSTRAINT)([\\s])([\\S]*)([\\s])/', $sql_lines[$j], $matches);
                             if (!$first) {
                                 $sql_drop_foreign_keys .= ', ';
                             }
                             $sql_drop_foreign_keys .= 'DROP FOREIGN KEY ' . $matches[3];
                         }
                         $first = false;
                     } else {
                         if ($update_indexes_increments && preg_match('@KEY[\\s]+@', $sql_lines[$j])) {
                             //if it's a index
                             $tmp_str = " ADD " . $sql_lines[$j];
                             $sql_indexes_query .= $tmp_str;
                             $sql_indexes .= $tmp_str;
                         } else {
                             break;
                         }
                     }
                 }
                 //removes superfluous comma at the end
                 $sql_indexes = rtrim($sql_indexes, ',');
                 $sql_indexes_query = rtrim($sql_indexes_query, ',');
                 //removes superfluous semicolon at the end
                 if ($has_constraints == 1) {
                     $sql_constraints .= ';' . $crlf;
                     $sql_constraints_query .= ';';
                 }
                 if ($has_indexes == 1) {
                     $sql_indexes .= ';' . $crlf;
                     $sql_indexes_query .= ';';
                 }
                 //remove indexes and constraints from the $create_query
                 $create_query = implode($crlf, array_slice($sql_lines, 0, $first_occur)) . $crlf . implode($crlf, array_slice($sql_lines, $j, $sql_count - 1));
                 unset($sql_lines);
             }
         }
         $schema_create .= $create_query;
     }
     // remove a possible "AUTO_INCREMENT = value" clause
     // that could be there starting with MySQL 5.0.24
     // in Drizzle it's useless as it contains the value given at table
     // creation time
     if (preg_match('/AUTO_INCREMENT\\s*=\\s*([0-9])+/', $schema_create)) {
         if ($compat == 'MSSQL' || $auto_increment == '') {
             $auto_increment = ' ';
         }
         $schema_create = preg_replace('/\\sAUTO_INCREMENT\\s*=\\s*([0-9])+\\s/', $auto_increment, $schema_create);
     }
     $GLOBALS['dbi']->freeResult($result);
     return $warning . $schema_create . ($add_semicolon ? ';' . $crlf : '');
 }
 /**
  * Does the actual work of each specific transformations plugin.
  *
  * @param string $buffer  text to be transformed
  * @param array  $options transformation options
  * @param string $meta    meta information
  *
  * @return void
  */
 public function applyTransformation($buffer, $options = array(), $meta = '')
 {
     // possibly use a global transform and feed it with special options
     // further operations on $buffer using the $options[] array.
     if (empty($options[0])) {
         $options[0] = 0;
     }
     if (empty($options[2])) {
         $options[2] = 'local';
     } else {
         $options[2] = strtolower($options[2]);
     }
     if (empty($options[1])) {
         if ($options[2] == 'local') {
             $options[1] = __('%B %d, %Y at %I:%M %p');
         } else {
             $options[1] = 'Y-m-d  H:i:s';
         }
     }
     $timestamp = -1;
     // INT columns will be treated as UNIX timestamps
     // and need to be detected before the verification for
     // MySQL TIMESTAMP
     if ($meta->type == 'int') {
         $timestamp = $buffer;
         // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14)
         // TIMESTAMP (2 | 4) not supported here.
         // (Note: prior to MySQL 4.1, TIMESTAMP has a display size
         // for example TIMESTAMP(8) means YYYYMMDD)
     } else {
         if (preg_match('/^(\\d{2}){3,7}$/', $buffer)) {
             if (strlen($buffer) == 14 || strlen($buffer) == 8) {
                 $offset = 4;
             } else {
                 $offset = 2;
             }
             $d = array();
             $d['year'] = substr($buffer, 0, $offset);
             $d['month'] = substr($buffer, $offset, 2);
             $d['day'] = substr($buffer, $offset + 2, 2);
             $d['hour'] = substr($buffer, $offset + 4, 2);
             $d['minute'] = substr($buffer, $offset + 6, 2);
             $d['second'] = substr($buffer, $offset + 8, 2);
             if (checkdate($d['month'], $d['day'], $d['year'])) {
                 $timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
             }
             // If all fails, assume one of the dozens of valid strtime() syntaxes
             // (http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html)
         } else {
             if (preg_match('/^[0-9]\\d{1,9}$/', $buffer)) {
                 $timestamp = (int) $buffer;
             } else {
                 $timestamp = strtotime($buffer);
             }
         }
     }
     // If all above failed, maybe it's a Unix timestamp already?
     if ($timestamp < 0 && preg_match('/^[1-9]\\d{1,9}$/', $buffer)) {
         $timestamp = $buffer;
     }
     // Reformat a valid timestamp
     if ($timestamp >= 0) {
         $timestamp -= $options[0] * 60 * 60;
         $source = $buffer;
         if ($options[2] == 'local') {
             $text = PMA_Util::localisedDate($timestamp, $options[1]);
         } elseif ($options[2] == 'utc') {
             $text = gmdate($options[1], $timestamp);
         } else {
             $text = 'INVALID DATE TYPE';
         }
         $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . $text . '</dfn>';
     }
     return $buffer;
 }
Ejemplo n.º 20
0
 /**
  * Generates data dictionary pages.
  *
  * @param array $alltables Tables to document.
  *
  * @return void
  */
 public function dataDictionaryDoc($alltables)
 {
     global $db, $pdf, $orientation, $paper;
     // TOC
     $pdf->addpage($_POST['orientation']);
     $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
     $pdf->Ln(15);
     $i = 1;
     foreach ($alltables as $table) {
         $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
         $pdf->SetX(10);
         // $pdf->Ln(1);
         $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
         $pdf->SetX(10);
         $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
         // $pdf->Ln(1);
         $fields = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $table);
         foreach ($fields as $row) {
             $pdf->SetX(20);
             $field_name = $row['Field'];
             $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
             //$pdf->Cell(
             //    0, 6, $field_name, 0, 1,
             //    'L', 0, $pdf->PMA_links['doc'][$table][$field_name]
             //);
         }
         $i++;
     }
     $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
     $pdf->SetX(10);
     $pdf->Cell(0, 6, __('Page number:') . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['RT']['-']);
     $pdf->SetX(10);
     $pdf->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
     $z = 0;
     foreach ($alltables as $table) {
         $z++;
         $pdf->SetAutoPageBreak(true, 15);
         $pdf->addpage($_POST['orientation']);
         $pdf->Bookmark($table);
         $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo());
         $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
         $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
         $pdf->SetFont($this->_ff, 'B', 18);
         $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
         $pdf->SetFont($this->_ff, '', 8);
         $pdf->ln();
         $cfgRelation = PMA_getRelationsParam();
         $comments = PMA_getComments($db, $table);
         if ($cfgRelation['mimework']) {
             $mime_map = PMA_getMIME($db, $table, true);
         }
         /**
          * Gets table informations
          */
         $showtable = PMA_Table::sGetStatusInfo($db, $table);
         $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
         $create_time = isset($showtable['Create_time']) ? PMA_Util::localisedDate(strtotime($showtable['Create_time'])) : '';
         $update_time = isset($showtable['Update_time']) ? PMA_Util::localisedDate(strtotime($showtable['Update_time'])) : '';
         $check_time = isset($showtable['Check_time']) ? PMA_Util::localisedDate(strtotime($showtable['Check_time'])) : '';
         /**
          * Gets table keys and retains them
          */
         $result = $GLOBALS['dbi']->query('SHOW KEYS FROM ' . PMA_Util::backquote($table) . ';');
         $primary = '';
         $indexes = array();
         $lastIndex = '';
         $indexes_info = array();
         $indexes_data = array();
         $pk_array = array();
         // will be use to emphasis prim. keys in the table
         // view
         while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
             // Backups the list of primary keys
             if ($row['Key_name'] == 'PRIMARY') {
                 $primary .= $row['Column_name'] . ', ';
                 $pk_array[$row['Column_name']] = 1;
             }
             // Retains keys informations
             if ($row['Key_name'] != $lastIndex) {
                 $indexes[] = $row['Key_name'];
                 $lastIndex = $row['Key_name'];
             }
             $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
             $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
             if (isset($row['Cardinality'])) {
                 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
             }
             // I don't know what does following column mean....
             // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
             $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
             $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
             if (isset($row['Sub_part'])) {
                 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
             }
         }
         // end while
         if ($result) {
             $GLOBALS['dbi']->freeResult($result);
         }
         /**
          * Gets fields properties
          */
         $columns = $GLOBALS['dbi']->getColumns($db, $table);
         // Check if we can use Relations
         if (!empty($cfgRelation['relation'])) {
             // Find which tables are related with the current one and write it in
             // an array
             $res_rel = PMA_getForeigners($db, $table);
             if (count($res_rel) > 0) {
                 $have_rel = true;
             } else {
                 $have_rel = false;
             }
         } else {
             $have_rel = false;
         }
         // end if
         /**
          * Displays the comments of the table if MySQL >= 3.23
          */
         $break = false;
         if (!empty($show_comment)) {
             $pdf->Cell(0, 3, __('Table comments:') . ' ' . $show_comment, 0, 1);
             $break = true;
         }
         if (!empty($create_time)) {
             $pdf->Cell(0, 3, __('Creation:') . ' ' . $create_time, 0, 1);
             $break = true;
         }
         if (!empty($update_time)) {
             $pdf->Cell(0, 3, __('Last update:') . ' ' . $update_time, 0, 1);
             $break = true;
         }
         if (!empty($check_time)) {
             $pdf->Cell(0, 3, __('Last check:') . ' ' . $check_time, 0, 1);
             $break = true;
         }
         if ($break == true) {
             $pdf->Cell(0, 3, '', 0, 1);
             $pdf->Ln();
         }
         $pdf->SetFont($this->_ff, 'B');
         if (isset($orientation) && $orientation == 'L') {
             $pdf->Cell(25, 8, __('Column'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Default'), 1, 0, 'C');
             $pdf->Cell(25, 8, __('Extra'), 1, 0, 'C');
             $pdf->Cell(45, 8, __('Links to'), 1, 0, 'C');
             if ($paper == 'A4') {
                 $comments_width = 67;
             } else {
                 // this is really intended for 'letter'
                 /**
                  * @todo find optimal width for all formats
                  */
                 $comments_width = 50;
             }
             $pdf->Cell($comments_width, 8, __('Comments'), 1, 0, 'C');
             $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
         } else {
             $pdf->Cell(20, 8, __('Column'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
             $pdf->Cell(15, 8, __('Default'), 1, 0, 'C');
             $pdf->Cell(15, 8, __('Extra'), 1, 0, 'C');
             $pdf->Cell(30, 8, __('Links to'), 1, 0, 'C');
             $pdf->Cell(30, 8, __('Comments'), 1, 0, 'C');
             $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
         }
         $pdf->SetFont($this->_ff, '');
         foreach ($columns as $row) {
             $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
             $type = $extracted_columnspec['print_type'];
             $attribute = $extracted_columnspec['attribute'];
             if (!isset($row['Default'])) {
                 if ($row['Null'] != '' && $row['Null'] != 'NO') {
                     $row['Default'] = 'NULL';
                 }
             }
             $field_name = $row['Field'];
             // $pdf->Ln();
             $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
             $pdf->Bookmark($field_name, 1, -1);
             $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
             $pdf_row = array($field_name, $type, $attribute, $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'), isset($row['Default']) ? $row['Default'] : '', $row['Extra'], isset($res_rel[$field_name]) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : '', isset($comments[$field_name]) ? $comments[$field_name] : '', isset($mime_map) && isset($mime_map[$field_name]) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '');
             $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
             if (isset($res_rel[$field_name]['foreign_table']) && isset($res_rel[$field_name]['foreign_field']) && isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])) {
                 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
             } else {
                 unset($links[6]);
             }
             $pdf->Row($pdf_row, $links);
         }
         // end foreach
         $pdf->SetFont($this->_ff, '', 14);
     }
     //end each
 }
Ejemplo n.º 21
0
/**
 * Get the HTML for the header of the page in print view if print view is selected.
 * Otherwise returns null.
 *
 * @param string $db        current database
 * @param string $sql_query current sql query
 * @param int    $num_rows  the number of rows in result
 *
 * @return string $header html for the header
 */
function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows)
{
    $response = PMA_Response::getInstance();
    $header = $response->getHeader();
    if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') {
        PMA_Util::checkParameters(array('db', 'sql_query'));
        $header->enablePrintView();
        if ($GLOBALS['cfg']['Server']['verbose']) {
            $hostname = $GLOBALS['cfg']['Server']['verbose'];
        } else {
            $hostname = $GLOBALS['cfg']['Server']['host'];
            if (!empty($GLOBALS['cfg']['Server']['port'])) {
                $hostname .= $GLOBALS['cfg']['Server']['port'];
            }
        }
        $versions = "phpMyAdmin&nbsp;" . PMA_VERSION;
        $versions .= "&nbsp;/&nbsp;";
        $versions .= "MySQL&nbsp;" . PMA_MYSQL_STR_VERSION;
        $print_view_header = '';
        $print_view_header .= "<h1>" . __('SQL result') . "</h1>";
        $print_view_header .= "<p>";
        $print_view_header .= "<strong>" . __('Host:') . "</strong> {$hostname}<br />";
        $print_view_header .= "<strong>" . __('Database:') . "</strong> " . htmlspecialchars($db) . "<br />";
        $print_view_header .= "<strong>" . __('Generation Time:') . "</strong> " . PMA_Util::localisedDate() . "<br />";
        $print_view_header .= "<strong>" . __('Generated by:') . "</strong> {$versions}<br />";
        $print_view_header .= "<strong>" . __('SQL query:') . "</strong> " . htmlspecialchars($sql_query) . ";";
        if (isset($num_rows)) {
            $print_view_header .= "<br />";
            $print_view_header .= "<strong>" . __('Rows:') . "</strong> {$num_rows}";
        }
        $print_view_header .= "</p>";
    } else {
        $print_view_header = null;
    }
    return $print_view_header;
}
Ejemplo n.º 22
0
 /**
  * Returns $table's CREATE definition
  *
  * @param string $db                        the database name
  * @param string $table                     the table name
  * @param string $crlf                      the end of line sequence
  * @param string $error_url                 the url to go back in case
  *                                          of error
  * @param bool   $show_dates                whether to include creation/
  *                                          update/check dates
  * @param bool   $add_semicolon             whether to add semicolon and
  *                                          end-of-line at the end
  * @param bool   $view                      whether we're handling a view
  * @param bool   $update_indexes_increments whether we need to update
  *                                          two global variables
  * @param array  $aliases                   Aliases of db/table/columns
  *
  * @return string resulting schema
  */
 public function getTableDef($db, $table, $crlf, $error_url, $show_dates = false, $add_semicolon = true, $view = false, $update_indexes_increments = true, $aliases = array())
 {
     global $sql_drop_table, $sql_backquotes, $sql_constraints, $sql_constraints_query, $sql_indexes, $sql_indexes_query, $sql_auto_increments, $sql_drop_foreign_keys;
     $db_alias = $db;
     $table_alias = $table;
     $this->initAlias($aliases, $db_alias, $table_alias);
     $schema_create = '';
     $auto_increment = '';
     $new_crlf = $crlf;
     if (isset($GLOBALS['sql_compatibility'])) {
         $compat = $GLOBALS['sql_compatibility'];
     } else {
         $compat = 'NONE';
     }
     // need to use PMA_DatabaseInterface::QUERY_STORE
     // with $GLOBALS['dbi']->numRows() in mysqli
     $result = $GLOBALS['dbi']->query('SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db) . ' WHERE Name = \'' . PMA_Util::sqlAddSlashes($table) . '\'', null, PMA_DatabaseInterface::QUERY_STORE);
     if ($result != false) {
         if ($GLOBALS['dbi']->numRows($result) > 0) {
             $tmpres = $GLOBALS['dbi']->fetchAssoc($result);
             // Here we optionally add the AUTO_INCREMENT next value,
             // but starting with MySQL 5.0.24, the clause is already included
             // in SHOW CREATE TABLE so we'll remove it below
             if (isset($GLOBALS['sql_auto_increment']) && !empty($tmpres['Auto_increment'])) {
                 $auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
             }
             if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
                 $schema_create .= $this->_exportComment(__('Creation:') . ' ' . PMA_Util::localisedDate(strtotime($tmpres['Create_time'])));
                 $new_crlf = $this->_exportComment() . $crlf;
             }
             if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
                 $schema_create .= $this->_exportComment(__('Last update:') . ' ' . PMA_Util::localisedDate(strtotime($tmpres['Update_time'])));
                 $new_crlf = $this->_exportComment() . $crlf;
             }
             if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
                 $schema_create .= $this->_exportComment(__('Last check:') . ' ' . PMA_Util::localisedDate(strtotime($tmpres['Check_time'])));
                 $new_crlf = $this->_exportComment() . $crlf;
             }
         }
         $GLOBALS['dbi']->freeResult($result);
     }
     $schema_create .= $new_crlf;
     // no need to generate a DROP VIEW here, it was done earlier
     if (!empty($sql_drop_table) && !$GLOBALS['dbi']->getTable($db, $table)->isView()) {
         $schema_create .= 'DROP TABLE IF EXISTS ' . PMA_Util::backquote($table_alias, $sql_backquotes) . ';' . $crlf;
     }
     // Complete table dump,
     // Whether to quote table and column names or not
     if ($sql_backquotes) {
         $GLOBALS['dbi']->query('SET SQL_QUOTE_SHOW_CREATE = 1');
     } else {
         $GLOBALS['dbi']->query('SET SQL_QUOTE_SHOW_CREATE = 0');
     }
     // I don't see the reason why this unbuffered query could cause problems,
     // because SHOW CREATE TABLE returns only one row, and we free the
     // results below. Nonetheless, we got 2 user reports about this
     // (see bug 1562533) so I removed the unbuffered mode.
     // $result = $GLOBALS['dbi']->query('SHOW CREATE TABLE ' . backquote($db)
     // . '.' . backquote($table), null, PMA_DatabaseInterface::QUERY_UNBUFFERED);
     //
     // Note: SHOW CREATE TABLE, at least in MySQL 5.1.23, does not
     // produce a displayable result for the default value of a BIT
     // column, nor does the mysqldump command. See MySQL bug 35796
     $result = $GLOBALS['dbi']->tryQuery('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table));
     // an error can happen, for example the table is crashed
     $tmp_error = $GLOBALS['dbi']->getError();
     if ($tmp_error) {
         return $this->_exportComment(__('in use') . '(' . $tmp_error . ')');
     }
     // Old mode is stored so it can be restored once exporting is done.
     $old_mode = SqlParser\Context::$MODE;
     $warning = '';
     if ($result != false && ($row = $GLOBALS['dbi']->fetchRow($result))) {
         $create_query = $row[1];
         unset($row);
         // Convert end of line chars to one that we want (note that MySQL
         // doesn't return query it will accept in all cases)
         if (mb_strpos($create_query, "(\r\n ")) {
             $create_query = str_replace("\r\n", $crlf, $create_query);
         } elseif (mb_strpos($create_query, "(\n ")) {
             $create_query = str_replace("\n", $crlf, $create_query);
         } elseif (mb_strpos($create_query, "(\r ")) {
             $create_query = str_replace("\r", $crlf, $create_query);
         }
         /*
          * Drop database name from VIEW creation.
          *
          * This is a bit tricky, but we need to issue SHOW CREATE TABLE with
          * database name, but we don't want name to show up in CREATE VIEW
          * statement.
          */
         if ($view) {
             $create_query = preg_replace('/' . preg_quote(PMA_Util::backquote($db)) . '\\./', '', $create_query);
         }
         // Substitute aliases in `CREATE` query.
         $create_query = $this->replaceWithAliases($create_query, $aliases, $db, $table, $flag);
         // One warning per view.
         if ($flag && $view) {
             $warning = $this->_exportComment() . $this->_exportComment(__('It appears your database uses views;')) . $this->_exportComment(__('alias export may not work reliably in all cases.')) . $this->_exportComment();
         }
         // Adding IF NOT EXISTS, if required.
         if (isset($GLOBALS['sql_if_not_exists'])) {
             $create_query = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $create_query);
         }
         // Making the query MSSQL compatible.
         if ($compat == 'MSSQL') {
             $create_query = $this->_makeCreateTableMSSQLCompatible($create_query);
         }
         // Views have no constraints, indexes, etc. They do not require any
         // analysis.
         if (!$view) {
             // Using appropriate quotes.
             if ($compat === 'MSSQL' || $sql_backquotes === '"') {
                 SqlParser\Context::$MODE |= SqlParser\Context::ANSI_QUOTES;
             }
             /**
              * Parser used for analysis.
              * @var SqlParser
              */
             $parser = new SqlParser\Parser($create_query);
         }
         if (!empty($parser->statements[0]->fields)) {
             /**
              * `CREATE TABLE` statement.
              * @var SqlParser\Statements\SelectStatement
              */
             $statement = $parser->statements[0];
             /**
              * Fragments containining definition of each constraint.
              * @var array
              */
             $constraints = array();
             /**
              * Fragments containining definition of each index.
              * @var array
              */
             $indexes = array();
             /**
              * Fragments containining definition of each FULLTEXT index.
              * @var array
              */
             $indexes_fulltext = array();
             /**
              * Fragments containining definition of each foreign key that will
              * be dropped.
              * @var array
              */
             $dropped = array();
             /**
              * Fragment containining definition of the `AUTO_INCREMENT`.
              * @var array
              */
             $auto_increment = array();
             // Scanning each field of the `CREATE` statement to fill the arrays
             // above.
             // If the field is used in any of the arrays above, it is removed
             // from the original definition.
             // Also, AUTO_INCREMENT attribute is removed.
             /** @var SqlParser\Components\CreateDefinition $field */
             foreach ($statement->fields as $key => $field) {
                 if ($field->isConstraint) {
                     // Creating the parts that add constraints.
                     $constraints[] = $field::build($field);
                     unset($statement->fields[$key]);
                 } elseif (!empty($field->key)) {
                     // Creating the parts that add indexes (must not be
                     // constraints).
                     if ($field->key->type === 'FULLTEXT KEY') {
                         $indexes_fulltext[] = $field->build($field);
                         unset($statement->fields[$key]);
                     } else {
                         if (empty($GLOBALS['sql_if_not_exists'])) {
                             $indexes[] = $field->build($field);
                             unset($statement->fields[$key]);
                         }
                     }
                 }
                 // Creating the parts that drop foreign keys.
                 if (!empty($field->key)) {
                     if ($field->key->type === 'FOREIGN KEY') {
                         $dropped[] = 'FOREIGN KEY ' . SqlParser\Context::escape($field->name);
                         unset($statement->fields[$key]);
                     }
                 }
                 // Dropping AUTO_INCREMENT.
                 if (!empty($field->options)) {
                     if ($field->options->has('AUTO_INCREMENT') && empty($GLOBALS['sql_if_not_exists'])) {
                         $auto_increment[] = $field::build($field);
                         $field->options->remove('AUTO_INCREMENT');
                     }
                 }
             }
             /**
              * The header of the `ALTER` statement (`ALTER TABLE tbl`).
              * @var string
              */
             $alter_header = 'ALTER TABLE ' . PMA_Util::backquoteCompat($table_alias, $compat, $sql_backquotes);
             /**
              * The footer of the `ALTER` statement (usually ';')
              * @var string
              */
             $alter_footer = ';' . $crlf;
             // Generating constraints-related query.
             if (!empty($constraints)) {
                 $sql_constraints_query = $alter_header . $crlf . '  ADD ' . implode(',' . $crlf . '  ADD ', $constraints) . $alter_footer;
                 $sql_constraints = $this->generateComment($crlf, $sql_constraints, __('Constraints for dumped tables'), __('Constraints for table'), $table_alias, $compat) . $sql_constraints_query;
             }
             // Generating indexes-related query.
             $sql_indexes_query = '';
             if (!empty($indexes)) {
                 $sql_indexes_query .= $alter_header . $crlf . '  ADD ' . implode(',' . $crlf . '  ADD ', $indexes) . $alter_footer;
             }
             if (!empty($indexes_fulltext)) {
                 // InnoDB supports one FULLTEXT index creation at a time.
                 // So FULLTEXT indexes are created one-by-one after other
                 // indexes where created.
                 $sql_indexes_query .= $alter_header . ' ADD ' . implode($alter_footer . $alter_header . ' ADD ', $indexes_fulltext) . $alter_footer;
             }
             if (!empty($indexes) || !empty($indexes_fulltext)) {
                 $sql_indexes = $this->generateComment($crlf, $sql_indexes, __('Indexes for dumped tables'), __('Indexes for table'), $table_alias, $compat) . $sql_indexes_query;
             }
             // Generating drop foreign keys-related query.
             if (!empty($dropped)) {
                 $sql_drop_foreign_keys = $alter_header . $crlf . '  DROP ' . implode(',' . $crlf . '  DROP ', $dropped) . $alter_footer;
             }
             // Generating auto-increment-related query.
             if (!empty($auto_increment) && $update_indexes_increments) {
                 $sql_auto_increments_query = $alter_header . $crlf . '  MODIFY ' . implode(',' . $crlf . '  MODIFY ', $auto_increment);
                 if (isset($GLOBALS['sql_auto_increment']) && $statement->entityOptions->has('AUTO_INCREMENT') !== false) {
                     $sql_auto_increments_query .= ', AUTO_INCREMENT=' . $statement->entityOptions->has('AUTO_INCREMENT');
                 }
                 $sql_auto_increments_query .= ';';
                 $sql_auto_increments = $this->generateComment($crlf, $sql_auto_increments, __('AUTO_INCREMENT for dumped tables'), __('AUTO_INCREMENT for table'), $table_alias, $compat) . $sql_auto_increments_query;
             }
             // Removing the `AUTO_INCREMENT` attribute from the `CREATE TABLE`
             // too.
             if (!empty($statement->entityOptions) && empty($GLOBALS['sql_if_not_exists'])) {
                 $statement->entityOptions->remove('AUTO_INCREMENT');
             }
             // Rebuilding the query.
             $create_query = $statement->build();
         }
         $schema_create .= $create_query;
     }
     $GLOBALS['dbi']->freeResult($result);
     // Restoring old mode.
     SqlParser\Context::$MODE = $old_mode;
     return $warning . $schema_create . ($add_semicolon ? ';' . $crlf : '');
 }
Ejemplo n.º 23
0
/**
 * return html for Row Statistic
 *
 * @param array $showtable       showing table information
 * @param int   $cell_align_left cell align left
 * @param int   $avg_size        avg size
 * @param int   $avg_unit        avg unit
 * @param bool  $mergetable      is merge table?
 *
 * @return string
 */
function PMA_getHtmlForRowStatistics($showtable, $cell_align_left, $avg_size, $avg_unit, $mergetable)
{
    $html = '<td width="20">&nbsp;</td>';
    // Rows Statistic
    $html .= "\n";
    $html .= '<td class="vtop">';
    $html .= '<big>' . __('Row Statistics:') . '</big>';
    $html .= '<table width="100%">';
    if (isset($showtable['Row_format'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Format') . '</td>';
        $html .= '<td class="' . $cell_align_left . '">';
        if ($showtable['Row_format'] == 'Fixed') {
            $html .= __('static');
        } elseif ($showtable['Row_format'] == 'Dynamic') {
            $html .= __('dynamic');
        } else {
            $html .= $showtable['Row_format'];
        }
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Rows'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Rows') . '</td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::formatNumber($showtable['Rows'], 0);
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Row length') . '&nbsp;&oslash;</td>';
        $html .= '<td>';
        $html .= PMA_Util::formatNumber($showtable['Avg_row_length'], 0);
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Row size') . '&nbsp;&oslash;</td>';
        $html .= '<td class="right">';
        $html .= $avg_size . ' ' . $avg_unit;
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Auto_increment'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Next autoindex') . ' </td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::formatNumber($showtable['Auto_increment'], 0);
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Create_time'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Creation') . '</td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::localisedDate(strtotime($showtable['Create_time']));
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Update_time'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Last update') . '</td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::localisedDate(strtotime($showtable['Update_time']));
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Check_time'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Last check') . '</td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::localisedDate(strtotime($showtable['Check_time']));
        $html .= '</td>';
        $html .= '</tr>';
    }
    return $html;
}
Ejemplo n.º 24
0
            if (! empty($cfg['Server']['port'])) {
                $hostname .= $cfg['Server']['port'];
            }
        }

        $versions  = "phpMyAdmin&nbsp;" . PMA_VERSION;
        $versions .= "&nbsp;/&nbsp;";
        $versions .= "MySQL&nbsp;" . PMA_MYSQL_STR_VERSION;

        echo "<h1>" . __('SQL result') . "</h1>";
        echo "<p>";
        echo "<strong>" . __('Host') . ":</strong> $hostname<br />";
        echo "<strong>" . __('Database') . ":</strong> "
            . htmlspecialchars($db) . "<br />";
        echo "<strong>" . __('Generation Time') . ":</strong> "
            . PMA_Util::localisedDate() . "<br />";
        echo "<strong>" . __('Generated by') . ":</strong> $versions<br />";
        echo "<strong>" . __('SQL query') . ":</strong> "
            . htmlspecialchars($full_sql_query) . ";";
        if (isset($num_rows)) {
            echo "<br />";
            echo "<strong>" . __('Rows') . ":</strong> $num_rows";
        }
        echo "</p>";
    } else {
        $response = PMA_Response::getInstance();
        $header = $response->getHeader();
        $scripts = $header->getScripts();
        $scripts->addFile('makegrid.js');
        $scripts->addFile('sql.js');