/** * Test case for expanding strings with escaping * * @param string $in string to evaluate * @param string $out expected output * * @return void * * @dataProvider provider */ public function testExpandEscape($in, $out) { $out = str_replace('PMA_VERSION', PMA_VERSION, $out); $this->assertEquals( htmlspecialchars($out), PMA_Util::expandUserString( $in, 'htmlspecialchars' ) ); }
/** * If the page is missing the title, this function * will set it to something reasonable * * @return string */ private function _getPageTitle() { if (empty($this->_title)) { if ($GLOBALS['server'] > 0) { if (!empty($GLOBALS['table'])) { $temp_title = $GLOBALS['cfg']['TitleTable']; } else { if (!empty($GLOBALS['db'])) { $temp_title = $GLOBALS['cfg']['TitleDatabase']; } elseif (!empty($GLOBALS['cfg']['Server']['host'])) { $temp_title = $GLOBALS['cfg']['TitleServer']; } else { $temp_title = $GLOBALS['cfg']['TitleDefault']; } } $this->_title = htmlspecialchars(PMA_Util::expandUserString($temp_title)); } else { $this->_title = 'phpMyAdmin'; } } return $this->_title; }
/** * return HTML for Sql Query Form Insert * * @param string $query query to display in the textarea * @param string $delimiter default delimiter to use * * @return string * * @usedby PMA_getHtmlForSqlQueryForm() */ function PMA_getHtmlForSqlQueryFormInsert($query = '', $delimiter = ';') { // enable auto select text in textarea if ($GLOBALS['cfg']['TextareaAutoSelect']) { $auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"'; } else { $auto_sel = ''; } $locking = ''; $height = $GLOBALS['cfg']['TextareaRows'] * 2; $table = ''; $db = ''; $fields_list = array(); if (!mb_strlen($GLOBALS['db'])) { // prepare for server related $legend = sprintf(__('Run SQL query/queries on server %s'), '"' . htmlspecialchars(!empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '"'); } elseif (!mb_strlen($GLOBALS['table'])) { // prepare for db related $db = $GLOBALS['db']; // if you want navigation: $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . PMA_URL_getCommon(array('db' => $db)) . '"'; $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; // else use // $tmp_db_link = htmlspecialchars($db); $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'); } } else { $table = $GLOBALS['table']; $db = $GLOBALS['db']; // Get the list and number of fields // we do a try_query here, because we could be in the query window, // trying to synchronize and the table has not yet been created $fields_list = $GLOBALS['dbi']->getColumns($db, $GLOBALS['table'], null, true); $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . PMA_URL_getCommon(array('db' => $db)) . '"'; $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; // else use // $tmp_db_link = htmlspecialchars($db); $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryTable'], 'backquote'); } } $legend .= ': ' . PMA_Util::showMySQLDocu('SELECT'); if (count($fields_list)) { $sqlquerycontainer_id = 'sqlquerycontainer'; } else { $sqlquerycontainer_id = 'sqlquerycontainerfull'; } $html = '<a id="querybox"></a>' . '<div id="queryboxcontainer">' . '<fieldset id="queryboxf">'; $html .= '<legend>' . $legend . '</legend>'; $html .= '<div id="queryfieldscontainer">'; $html .= '<div id="' . $sqlquerycontainer_id . '">' . '<textarea tabindex="100" name="sql_query" id="sqlquery"' . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"' . ' rows="' . $height . '"' . ' dir="' . $GLOBALS['text_dir'] . '"' . $auto_sel . $locking . '>' . htmlspecialchars($query) . '</textarea>'; // Add buttons to generate query easily for // select all, single select, insert, update and delete if (count($fields_list)) { $html .= '<input type="button" value="SELECT *" id="selectall"' . ' class="button sqlbutton" />'; $html .= '<input type="button" value="SELECT" id="select"' . ' class="button sqlbutton" />'; $html .= '<input type="button" value="INSERT" id="insert"' . ' class="button sqlbutton" />'; $html .= '<input type="button" value="UPDATE" id="update"' . ' class="button sqlbutton" />'; $html .= '<input type="button" value="DELETE" id="delete"' . ' class="button sqlbutton" />'; } $html .= '<input type="button" value="' . __('Clear') . '" id="clear"' . ' class="button sqlbutton" />'; $html .= '</div>' . "\n"; if (count($fields_list)) { $html .= '<div id="tablefieldscontainer">' . '<label>' . __('Columns') . '</label>' . '<select id="tablefields" name="dummy" ' . 'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" ' . 'multiple="multiple" ondblclick="insertValueQuery()">'; foreach ($fields_list as $field) { $html .= '<option value="' . PMA_Util::backquote(htmlspecialchars($field['Field'])) . '"'; if (isset($field['Field']) && mb_strlen($field['Field']) && isset($field['Comment'])) { $html .= ' title="' . htmlspecialchars($field['Comment']) . '"'; } $html .= '>' . htmlspecialchars($field['Field']) . '</option>' . "\n"; } $html .= '</select>' . '<div id="tablefieldinsertbuttoncontainer">'; if (PMA_Util::showIcons('ActionLinksMode')) { $html .= '<input type="button" class="button" name="insert"' . ' value="<<" onclick="insertValueQuery()"' . ' title="' . __('Insert') . '" />'; } else { $html .= '<input type="button" class="button" name="insert"' . ' value="' . __('Insert') . '"' . ' onclick="insertValueQuery()" />'; } $html .= '</div>' . "\n" . '</div>' . "\n"; } $html .= '<div class="clearfloat"></div>' . "\n"; $html .= '</div>' . "\n"; $cfgBookmark = PMA_Bookmark_getParams(); if ($cfgBookmark) { $html .= '<div id="bookmarkoptions">'; $html .= '<div class="formelement">'; $html .= '<label for="bkm_label">' . __('Bookmark this SQL query:') . '</label>'; $html .= '<input type="text" name="bkm_label" id="bkm_label"' . ' tabindex="110" value="" />'; $html .= '</div>'; $html .= '<div class="formelement">'; $html .= '<input type="checkbox" name="bkm_all_users" tabindex="111"' . ' id="id_bkm_all_users" value="true" />'; $html .= '<label for="id_bkm_all_users">' . __('Let every user access this bookmark') . '</label>'; $html .= '</div>'; $html .= '<div class="formelement">'; $html .= '<input type="checkbox" name="bkm_replace" tabindex="112"' . ' id="id_bkm_replace" value="true" />'; $html .= '<label for="id_bkm_replace">' . __('Replace existing bookmark of same name') . '</label>'; $html .= '</div>'; $html .= '</div>'; } $html .= '<div class="clearfloat"></div>' . "\n"; $html .= '</fieldset>' . "\n" . '</div>' . "\n"; $html .= '<fieldset id="queryboxfooter" class="tblFooters">' . "\n"; $html .= '<div class="formelement">' . "\n"; $html .= '</div>' . "\n"; $html .= '<div class="formelement">' . "\n"; $html .= '<label for="id_sql_delimiter">[ ' . __('Delimiter') . '</label>' . "\n"; $html .= '<input type="text" name="sql_delimiter" tabindex="131" size="3" ' . 'value="' . $delimiter . '" ' . 'id="id_sql_delimiter" /> ]'; $html .= '<input type="checkbox" name="show_query" value="1" ' . 'id="checkbox_show_query" tabindex="132" checked="checked" />' . '<label for="checkbox_show_query">' . __('Show this query here again') . '</label>'; $html .= '<input type="checkbox" name="retain_query_box" value="1" ' . 'id="retain_query_box" tabindex="133" ' . ($GLOBALS['cfg']['RetainQueryBox'] === false ? '' : ' checked="checked"') . ' />' . '<label for="retain_query_box">' . __('Retain query box') . '</label>'; $html .= '<input type="checkbox" name="rollback_query" value="1" ' . 'id="rollback_query" tabindex="134" />' . '<label for="rollback_query">' . __('Rollback when finished') . '</label>'; $html .= '</div>' . "\n"; $html .= '<input type="submit" id="button_submit_query" name="SQL"'; $html .= ' tabindex="200" value="' . __('Go') . '" />' . "\n"; $html .= '<div class="clearfloat"></div>' . "\n"; $html .= '</fieldset>' . "\n"; return $html; }
/** * Return the filename and MIME type for export file * * @param string $export_type type of export * @param string $remember_template whether to remember template * @param ExportPlugin $export_plugin the export plugin * @param string $compression compression asked * @param string $filename_template the filename template * * @return array the filename template and mime type */ function PMA_getExportFilenameAndMimetype($export_type, $remember_template, $export_plugin, $compression, $filename_template) { if ($export_type == 'server') { if (!empty($remember_template)) { $GLOBALS['PMA_Config']->setUserValue('pma_server_filename_template', 'Export/file_template_server', $filename_template); } } elseif ($export_type == 'database') { if (!empty($remember_template)) { $GLOBALS['PMA_Config']->setUserValue('pma_db_filename_template', 'Export/file_template_database', $filename_template); } } else { if (!empty($remember_template)) { $GLOBALS['PMA_Config']->setUserValue('pma_table_filename_template', 'Export/file_template_table', $filename_template); } } $filename = PMA_Util::expandUserString($filename_template); // remove dots in filename (coming from either the template or already // part of the filename) to avoid a remote code execution vulnerability $filename = PMA_sanitizeFilename($filename, $replaceDots = true); // Grab basic dump extension and mime type // Check if the user already added extension; // get the substring where the extension would be if it was included $extension_start_pos = mb_strlen($filename) - mb_strlen($export_plugin->getProperties()->getExtension()) - 1; $user_extension = mb_substr($filename, $extension_start_pos, mb_strlen($filename)); $required_extension = "." . $export_plugin->getProperties()->getExtension(); if (mb_strtolower($user_extension) != $required_extension) { $filename .= $required_extension; } $mime_type = $export_plugin->getProperties()->getMimeType(); // If dump is going to be compressed, set correct mime_type and add // compression to extension if ($compression == 'gzip') { $filename .= '.gz'; $mime_type = 'application/x-gzip'; } elseif ($compression == 'zip') { $filename .= '.zip'; $mime_type = 'application/zip'; } return array($filename, $mime_type); }
/** * Get initial values for Sql Query Form Insert * * @param string $query query to display in the textarea * * @return array ($legend, $query, $columns_list) * * @usedby PMA_getHtmlForSqlQueryFormInsert() */ function PMA_initQueryForm($query) { $columns_list = array(); if (!mb_strlen($GLOBALS['db'])) { // prepare for server related $legend = sprintf(__('Run SQL query/queries on server %s'), '"' . htmlspecialchars(!empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '"'); } elseif (!mb_strlen($GLOBALS['table'])) { // prepare for db related $db = $GLOBALS['db']; // if you want navigation: $tmp_db_link = '<a href="' . PMA_Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . PMA_URL_getCommon(array('db' => $db)) . '"'; $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'); } } else { $db = $GLOBALS['db']; // Get the list and number of fields // we do a try_query here, because we could be in the query window, // trying to synchronize and the table has not yet been created $columns_list = $GLOBALS['dbi']->getColumns($db, $GLOBALS['table'], null, true); $tmp_db_link = '<a href="' . PMA_Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . PMA_URL_getCommon(array('db' => $db)) . '"'; $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryTable'], 'backquote'); } } $legend .= ': ' . PMA_Util::showMySQLDocu('SELECT'); return array($legend, $query, $columns_list); }
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param string $export_mode 'create_table', 'triggers', 'create_view', * 'stand_in' * @param string $export_type 'server', 'database', 'table' * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * exportStructure() also for other * export types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * @param array $aliases Aliases of db/table/columns * * @return bool Whether it succeeded */ public function exportStructure($db, $table, $crlf, $error_url, $export_mode, $export_type, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $aliases = array()) { $db_alias = $db; $table_alias = $table; $this->initAlias($aliases, $db_alias, $table_alias); global $cfgRelation; /* We do not export triggers */ if ($export_mode == 'triggers') { return true; } /** * Get the unique keys in the table */ $unique_keys = array(); $keys = $GLOBALS['dbi']->getTableIndexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Gets fields properties */ $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations list($res_rel, $have_rel) = PMA_getRelationsAndStatus($do_relation && !empty($cfgRelation['relation']), $db, $table); /** * Displays the table structure */ $buffer = $crlf . '%' . $crlf . '% ' . __('Structure:') . ' ' . $table_alias . $crlf . '%' . $crlf . ' \\begin{longtable}{'; if (!PMA_exportOutputHandler($buffer)) { return false; } $alignment = '|l|c|c|c|'; if ($do_relation && $have_rel) { $alignment .= 'l|'; } if ($do_comments) { $alignment .= 'l|'; } if ($do_mime && $cfgRelation['mimework']) { $alignment .= 'l|'; } $buffer = $alignment . '} ' . $crlf; $header = ' \\hline '; $header .= '\\multicolumn{1}{|c|}{\\textbf{' . __('Column') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Type') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Null') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Default') . '}}'; if ($do_relation && $have_rel) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Links to') . '}}'; } if ($do_comments) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Comments') . '}}'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; $mime_map = PMA_getMIME($db, $table, true); } // Table caption for first page and label if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_Util::expandUserString($GLOBALS['latex_structure_caption'], array('texEscape', get_class($this), 'libraries/plugins/export/' . get_class($this) . ".class.php"), array('table' => $table_alias, 'database' => $db_alias)) . '} \\label{' . PMA_Util::expandUserString($GLOBALS['latex_structure_label'], null, array('table' => $table_alias, 'database' => $db_alias)) . '} \\\\' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf; // Table caption on next pages if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_Util::expandUserString($GLOBALS['latex_structure_continued_caption'], array('texEscape', get_class($this), 'libraries/plugins/export/' . get_class($this) . ".class.php"), array('table' => $table_alias, 'database' => $db_alias)) . '} \\\\ ' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } $fields = $GLOBALS['dbi']->getColumns($db, $table); foreach ($fields as $row) { $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']); $type = $extracted_columnspec['print_type']; if (empty($type)) { $type = ' '; } if (!isset($row['Default'])) { if ($row['Null'] != 'NO') { $row['Default'] = 'NULL'; } } $field_name = $col_as = $row['Field']; if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) { $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as]; } $local_buffer = $col_as . "" . $type . "" . ($row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes')) . "" . (isset($row['Default']) ? $row['Default'] : ''); if ($do_relation && $have_rel) { $local_buffer .= ""; $local_buffer .= $this->getRelationString($res_rel, $field_name, $db, $aliases); } if ($do_comments && $cfgRelation['commwork']) { $local_buffer .= ""; if (isset($comments[$field_name])) { $local_buffer .= $comments[$field_name]; } } if ($do_mime && $cfgRelation['mimework']) { $local_buffer .= ""; if (isset($mime_map[$field_name])) { $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']); } } $local_buffer = self::texEscape($local_buffer); if ($row['Key'] == 'PRI') { $pos = mb_strpos($local_buffer, ""); $local_buffer = '\\textit{' . mb_substr($local_buffer, 0, $pos) . '}' . mb_substr($local_buffer, $pos); } if (in_array($field_name, $unique_keys)) { $pos = mb_strpos($local_buffer, ""); $local_buffer = '\\textbf{' . mb_substr($local_buffer, 0, $pos) . '}' . mb_substr($local_buffer, $pos); } $buffer = str_replace("", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } } // end while $buffer = ' \\end{longtable}' . $crlf; return PMA_exportOutputHandler($buffer); }
if ($asfile) { $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']); if ($export_type == 'server') { if (isset($remember_template)) { $GLOBALS['PMA_Config']->setUserValue('pma_server_filename_template', 'Export/file_template_server', $filename_template); } } elseif ($export_type == 'database') { if (isset($remember_template)) { $GLOBALS['PMA_Config']->setUserValue('pma_db_filename_template', 'Export/file_template_database', $filename_template); } } else { if (isset($remember_template)) { $GLOBALS['PMA_Config']->setUserValue('pma_table_filename_template', 'Export/file_template_table', $filename_template); } } $filename = PMA_Util::expandUserString($filename_template); // remove dots in filename (coming from either the template or already // part of the filename) to avoid a remote code execution vulnerability $filename = PMA_sanitizeFilename($filename, $replaceDots = true); // Grab basic dump extension and mime type // Check if the user already added extension; // get the substring where the extension would be if it was included $extension_start_pos = strlen($filename) - strlen($export_plugin->getProperties()->getExtension()) - 1; $user_extension = substr($filename, $extension_start_pos, strlen($filename)); $required_extension = "." . $export_plugin->getProperties()->getExtension(); if (strtolower($user_extension) != $required_extension) { $filename .= $required_extension; } $mime_type = $export_plugin->getProperties()->getMimeType(); // If dump is going to be compressed, set correct mime_type and add // compression to extension
/** * Prints querybox fieldset * * @param string $query query to display in the textarea * @param boolean $is_querywindow if inside querywindow or not * @param string $delimiter default delimiter to use * * @return void * * @usedby PMA_sqlQueryForm() */ function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false, $delimiter = ';') { // enable auto select text in textarea if ($GLOBALS['cfg']['TextareaAutoSelect']) { $auto_sel = ' onclick="selectContent(this, sql_box_locked, true)"'; } else { $auto_sel = ''; } // enable locking if inside query window if ($is_querywindow) { $locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].' . 'checked = true;"'; $height = $GLOBALS['cfg']['TextareaRows'] * 1.25; } else { $locking = ''; $height = $GLOBALS['cfg']['TextareaRows'] * 2; } $table = ''; $db = ''; $fields_list = array(); if (!strlen($GLOBALS['db'])) { // prepare for server related $legend = sprintf(__('Run SQL query/queries on server %s'), '"' . htmlspecialchars(!empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '"'); } elseif (!strlen($GLOBALS['table'])) { // prepare for db related $db = $GLOBALS['db']; // if you want navigation: $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($db) . '"'; if ($is_querywindow) { $tmp_db_link .= ' target="_self"' . ' onclick="this.target=window.opener.frame_content.name"'; } $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; // else use // $tmp_db_link = htmlspecialchars($db); $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'); } } else { $table = $GLOBALS['table']; $db = $GLOBALS['db']; // Get the list and number of fields // we do a try_query here, because we could be in the query window, // trying to synchonize and the table has not yet been created $fields_list = PMA_DBI_get_columns($db, $GLOBALS['table'], null, true); $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($db) . '"'; if ($is_querywindow) { $tmp_db_link .= ' target="_self"' . ' onclick="this.target=window.opener.frame_content.name"'; } $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; // else use // $tmp_db_link = htmlspecialchars($db); $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryTable'], 'backquote'); } } $legend .= ': ' . PMA_Util::showMySQLDocu('SQL-Syntax', 'SELECT'); if (count($fields_list)) { $sqlquerycontainer_id = 'sqlquerycontainer'; } else { $sqlquerycontainer_id = 'sqlquerycontainerfull'; } echo '<a id="querybox"></a>' . "\n" . '<div id="queryboxcontainer">' . "\n" . '<fieldset id="queryboxf">' . "\n"; echo '<legend>' . $legend . '</legend>' . "\n"; echo '<div id="queryfieldscontainer">' . "\n"; echo '<div id="' . $sqlquerycontainer_id . '">' . "\n" . '<textarea tabindex="100" name="sql_query" id="sqlquery"' . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"' . ' rows="' . $height . '"' . ' dir="' . $GLOBALS['text_dir'] . '"' . $auto_sel . $locking . '>' . htmlspecialchars($query) . '</textarea>' . "\n"; // Add buttons to generate query easily for // select all, single select, insert, update and delete if (count($fields_list)) { echo '<input type="button" value="SELECT *" id="selectall" class="button sqlbutton" />'; echo '<input type="button" value="SELECT" id="select" class="button sqlbutton" />'; echo '<input type="button" value="INSERT" id="insert" class="button sqlbutton" />'; echo '<input type="button" value="UPDATE" id="update" class="button sqlbutton" />'; echo '<input type="button" value="DELETE" id="delete" class="button sqlbutton" />'; } echo '<input type="button" value="' . __('Clear') . '" id="clear" class="button sqlbutton" />'; echo '</div>' . "\n"; if (count($fields_list)) { echo '<div id="tablefieldscontainer">' . "\n" . '<label>' . __('Columns') . '</label>' . "\n" . '<select id="tablefields" name="dummy" ' . 'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" ' . 'multiple="multiple" ondblclick="insertValueQuery()">' . "\n"; foreach ($fields_list as $field) { echo '<option value="' . PMA_Util::backquote(htmlspecialchars($field['Field'])) . '"'; if (isset($field['Field']) && strlen($field['Field']) && isset($field['Comment'])) { echo ' title="' . htmlspecialchars($field['Comment']) . '"'; } echo '>' . htmlspecialchars($field['Field']) . '</option>' . "\n"; } echo '</select>' . "\n" . '<div id="tablefieldinsertbuttoncontainer">' . "\n"; if ($GLOBALS['cfg']['PropertiesIconic']) { echo '<input type="button" class="button" name="insert" value="<<"' . ' onclick="insertValueQuery()"' . ' title="' . __('Insert') . '" />' . "\n"; } else { echo '<input type="button" class="button" name="insert"' . ' value="' . __('Insert') . '"' . ' onclick="insertValueQuery()" />' . "\n"; } echo '</div>' . "\n" . '</div>' . "\n"; } echo '<div class="clearfloat"></div>' . "\n"; echo '</div>' . "\n"; if (!empty($GLOBALS['cfg']['Bookmark'])) { ?> <div id="bookmarkoptions"> <div class="formelement"> <label for="bkm_label"> <?php echo __('Bookmark this SQL query'); ?> :</label> <input type="text" name="bkm_label" id="bkm_label" tabindex="110" value="" /> </div> <div class="formelement"> <input type="checkbox" name="bkm_all_users" tabindex="111" id="id_bkm_all_users" value="true" /> <label for="id_bkm_all_users"> <?php echo __('Let every user access this bookmark'); ?> </label> </div> <div class="formelement"> <input type="checkbox" name="bkm_replace" tabindex="112" id="id_bkm_replace" value="true" /> <label for="id_bkm_replace"> <?php echo __('Replace existing bookmark of same name'); ?> </label> </div> </div> <?php } echo '<div class="clearfloat"></div>' . "\n"; echo '</fieldset>' . "\n" . '</div>' . "\n"; echo '<fieldset id="queryboxfooter" class="tblFooters">' . "\n"; echo '<div class="formelement">' . "\n"; if ($is_querywindow) { ?> <script type="text/javascript"> //<![CDATA[ document.writeln(' <input type="checkbox" name="LockFromUpdate" checked="checked" tabindex="120" id="checkbox_lock" /> <label for="checkbox_lock"><?php echo __('Do not overwrite this query from outside the window'); ?> </label> '); //]]> </script> <?php } echo '</div>' . "\n"; echo '<div class="formelement">' . "\n"; echo '<label for="id_sql_delimiter">[ ' . __('Delimiter') . '</label>' . "\n"; echo '<input type="text" name="sql_delimiter" tabindex="131" size="3" ' . 'value="' . $delimiter . '" ' . 'id="id_sql_delimiter" /> ]' . "\n"; echo '<input type="checkbox" name="show_query" value="1" ' . 'id="checkbox_show_query" tabindex="132" checked="checked" />' . "\n" . '<label for="checkbox_show_query">' . __('Show this query here again') . '</label>' . "\n"; if (!$is_querywindow) { echo '<input type="checkbox" name="retain_query_box" value="1" ' . 'id="retain_query_box" tabindex="133" ' . ($GLOBALS['cfg']['RetainQueryBox'] === false ? '' : ' checked="checked"') . ' />' . '<label for="retain_query_box">' . __('Retain query box') . '</label>'; } echo '</div>' . "\n"; echo '<input type="submit" id="button_submit_query" name="SQL" tabindex="200" value="' . __('Go') . '" />' . "\n"; echo '<div class="clearfloat"></div>' . "\n"; echo '</fieldset>' . "\n"; }
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param string $export_mode 'create_table', 'triggers', 'create_view', * 'stand_in' * @param string $export_type 'server', 'database', 'table' * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * exportStructure() also for other * export types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * * @return bool Whether it succeeded */ public function exportStructure($db, $table, $crlf, $error_url, $export_mode, $export_type, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false) { global $cfgRelation; /** * Get the unique keys in the table */ $unique_keys = array(); $keys = PMA_DBI_get_table_indexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !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 ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ $buffer = $crlf . '%' . $crlf . '% ' . __('Structure') . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{'; if (!PMA_exportOutputHandler($buffer)) { return false; } $columns_cnt = 4; $alignment = '|l|c|c|c|'; if ($do_relation && $have_rel) { $columns_cnt++; $alignment .= 'l|'; } if ($do_comments) { $columns_cnt++; $alignment .= 'l|'; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; $alignment .= 'l|'; } $buffer = $alignment . '} ' . $crlf; $header = ' \\hline '; $header .= '\\multicolumn{1}{|c|}{\\textbf{' . __('Column') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Type') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Null') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Default') . '}}'; if ($do_relation && $have_rel) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Links to') . '}}'; } if ($do_comments) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Comments') . '}}'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; $mime_map = PMA_getMIME($db, $table, true); } // Table caption for first page and label if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_Util::expandUserString($GLOBALS['latex_structure_caption'], array('texEscape', get_class($this), 'libraries/plugins/export/' . get_class($this) . ".class.php"), array('table' => $table, 'database' => $db)) . '} \\label{' . PMA_Util::expandUserString($GLOBALS['latex_structure_label'], null, array('table' => $table, 'database' => $db)) . '} \\\\' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf; // Table caption on next pages if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_Util::expandUserString($GLOBALS['latex_structure_continued_caption'], array('texEscape', get_class($this), 'libraries/plugins/export/' . get_class($this) . ".class.php"), array('table' => $table, 'database' => $db)) . '} \\\\ ' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } $fields = PMA_DBI_get_columns($db, $table); foreach ($fields as $row) { $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']); $type = $extracted_columnspec['print_type']; if (empty($type)) { $type = ' '; } if (!isset($row['Default'])) { if ($row['Null'] != 'NO') { $row['Default'] = 'NULL'; } } $field_name = $row['Field']; $local_buffer = $field_name . "" . $type . "" . ($row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes')) . "" . (isset($row['Default']) ? $row['Default'] : ''); if ($do_relation && $have_rel) { $local_buffer .= ""; if (isset($res_rel[$field_name])) { $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')'; } } if ($do_comments && $cfgRelation['commwork']) { $local_buffer .= ""; if (isset($comments[$field_name])) { $local_buffer .= $comments[$field_name]; } } if ($do_mime && $cfgRelation['mimework']) { $local_buffer .= ""; if (isset($mime_map[$field_name])) { $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']); } } $local_buffer = $this::texEscape($local_buffer); if ($row['Key'] == 'PRI') { $pos = strpos($local_buffer, ""); $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } if (in_array($field_name, $unique_keys)) { $pos = strpos($local_buffer, ""); $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } $buffer = str_replace("", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } } // end while $buffer = ' \\end{longtable}' . $crlf; return PMA_exportOutputHandler($buffer); }