/** * Outputs HTML for forms * * @param bool $tabbed_form if true, use a form with tabs * @param bool $show_restore_default whether show "restore default" button * besides the input field * @param bool $show_buttons whether show submit and reset button * @param string $form_action action attribute for the form * @param array $hidden_fields array of form hidden fields (key: field * name) * * @return string HTML for forms */ public function getDisplay($tabbed_form = false, $show_restore_default = false, $show_buttons = true, $form_action = null, $hidden_fields = null) { static $js_lang_sent = false; $htmlOutput = ''; $js = array(); $js_default = array(); $htmlOutput .= PMA_displayFormTop($form_action, 'post', $hidden_fields); if ($tabbed_form) { $tabs = array(); foreach ($this->_forms as $form) { $tabs[$form->name] = PMA_lang("Form_{$form->name}"); } $htmlOutput .= PMA_displayTabsTop($tabs); } // validate only when we aren't displaying a "new server" form $is_new_server = false; foreach ($this->_forms as $form) { /* @var $form Form */ if ($form->index === 0) { $is_new_server = true; break; } } if (!$is_new_server) { $this->_validate(); } // user preferences $this->_loadUserprefsInfo(); // display forms $htmlOutput .= $this->_displayForms($show_restore_default, $js_default, $js, $show_buttons); if ($tabbed_form) { $htmlOutput .= PMA_displayTabsBottom(); } $htmlOutput .= PMA_displayFormBottom(); // if not already done, send strings used for validation to JavaScript if (!$js_lang_sent) { $js_lang_sent = true; $js_lang = array(); foreach ($this->_jsLangStrings as $strName => $strValue) { $js_lang[] = "'{$strName}': '" . Sanitize::jsFormat($strValue, false) . '\''; } $js[] = "\$.extend(PMA_messages, {\n\t" . implode(",\n\t", $js_lang) . '})'; } $js[] = "\$.extend(defaultValues, {\n\t" . implode(",\n\t", $js_default) . '})'; $htmlOutput .= PMA_displayJavascript($js); return $htmlOutput; }
/** * 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 string */ 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] = mb_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 (mb_strlen($buffer) == 14 || mb_strlen($buffer) == 8) { $offset = 4; } else { $offset = 2; } $aDate = array(); $aDate['year'] = (int) mb_substr($buffer, 0, $offset); $aDate['month'] = (int) mb_substr($buffer, $offset, 2); $aDate['day'] = (int) mb_substr($buffer, $offset + 2, 2); $aDate['hour'] = (int) mb_substr($buffer, $offset + 4, 2); $aDate['minute'] = (int) mb_substr($buffer, $offset + 6, 2); $aDate['second'] = (int) mb_substr($buffer, $offset + 8, 2); if (checkdate($aDate['month'], $aDate['day'], $aDate['year'])) { $timestamp = mktime($aDate['hour'], $aDate['minute'], $aDate['second'], $aDate['month'], $aDate['day'], $aDate['year']); } // If all fails, assume one of the dozens of valid strtime() syntaxes // (https://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\libraries\Util::localisedDate($timestamp, $options[1]); } elseif ($options[2] == 'utc') { $text = gmdate($options[1], $timestamp); } else { $text = 'INVALID DATE TYPE'; } return '<dfn onclick="alert(\'' . Sanitize::jsFormat($source, false) . '\');" title="' . htmlspecialchars($source) . '">' . htmlspecialchars($text) . '</dfn>'; } else { return htmlspecialchars($buffer); } }
/** * Prints javascript for upload with plugin, upload process bar * * @param int $upload_id The selected upload id * * @return string */ function PMA_getHtmlForImportWithPlugin($upload_id) { //some variable for javascript $ajax_url = "import_status.php?id=" . $upload_id . "&" . URL::getCommonRaw(array('import_status' => 1)); $promot_str = Sanitize::jsFormat(__('The file being uploaded is probably larger than ' . 'the maximum allowed size or this is a known bug in webkit ' . 'based (Safari, Google Chrome, Arora etc.) browsers.'), false); $statustext_str = Sanitize::escapeJsString(__('%s of %s')); $upload_str = Sanitize::jsFormat(__('Uploading your import fileā¦'), false); $second_str = Sanitize::jsFormat(__('%s/sec.'), false); $remaining_min = Sanitize::jsFormat(__('About %MIN min. %SEC sec. remaining.'), false); $remaining_second = Sanitize::jsFormat(__('About %SEC sec. remaining.'), false); $processed_str = Sanitize::jsFormat(__('The file is being processed, please be patient.'), false); $import_url = URL::getCommonRaw(array('import_status' => 1)); //start output $html = 'var finished = false; '; $html .= 'var percent = 0.0; '; $html .= 'var total = 0; '; $html .= 'var complete = 0; '; $html .= 'var original_title = ' . 'parent && parent.document ? parent.document.title : false; '; $html .= 'var import_start; '; $html .= 'var perform_upload = function () { '; $html .= 'new $.getJSON( '; $html .= ' "' . $ajax_url . '", '; $html .= ' {}, '; $html .= ' function(response) { '; $html .= ' finished = response.finished; '; $html .= ' percent = response.percent; '; $html .= ' total = response.total; '; $html .= ' complete = response.complete; '; $html .= ' if (total==0 && complete==0 && percent==0) { '; $img_tag = '<img src="' . $GLOBALS['pmaThemeImage'] . 'ajax_clock_small.gif"'; $html .= ' $("#upload_form_status_info").html(\'' . $img_tag . ' width="16" height="16" alt="ajax clock" /> ' . $promot_str . '\'); '; $html .= ' $("#upload_form_status").css("display", "none"); '; $html .= ' } else { '; $html .= ' var now = new Date(); '; $html .= ' now = Date.UTC( '; $html .= ' now.getFullYear(), '; $html .= ' now.getMonth(), '; $html .= ' now.getDate(), '; $html .= ' now.getHours(), '; $html .= ' now.getMinutes(), '; $html .= ' now.getSeconds()) '; $html .= ' + now.getMilliseconds() - 1000; '; $html .= ' var statustext = PMA_sprintf('; $html .= ' "' . $statustext_str . '", '; $html .= ' formatBytes( '; $html .= ' complete, 1, PMA_messages.strDecimalSeparator'; $html .= ' ), '; $html .= ' formatBytes('; $html .= ' total, 1, PMA_messages.strDecimalSeparator'; $html .= ' ) '; $html .= ' ); '; $html .= ' if ($("#importmain").is(":visible")) { '; // show progress UI $html .= ' $("#importmain").hide(); '; $html .= ' $("#import_form_status") '; $html .= ' .html(\'<div class="upload_progress">' . '<div class="upload_progress_bar_outer"><div class="percentage">' . '</div><div id="status" class="upload_progress_bar_inner">' . '<div class="percentage"></div></div></div><div>' . '<img src="' . $GLOBALS['pmaThemeImage'] . 'ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> ' . $upload_str . '</div><div id="statustext"></div></div>\') '; $html .= ' .show(); '; $html .= ' import_start = now; '; $html .= ' } '; $html .= ' else if (percent > 9 || complete > 2000000) { '; // calculate estimated time $html .= ' var used_time = now - import_start; '; $html .= ' var seconds = ' . 'parseInt(((total - complete) / complete) * used_time / 1000); '; $html .= ' var speed = PMA_sprintf("' . $second_str . '"'; $html .= ' , formatBytes(complete / used_time * 1000, 1,' . ' PMA_messages.strDecimalSeparator)); '; $html .= ' var minutes = parseInt(seconds / 60); '; $html .= ' seconds %= 60; '; $html .= ' var estimated_time; '; $html .= ' if (minutes > 0) { '; $html .= ' estimated_time = "' . $remaining_min . '"'; $html .= ' .replace("%MIN", minutes)'; $html .= ' .replace("%SEC", seconds); '; $html .= ' } '; $html .= ' else { '; $html .= ' estimated_time = "' . $remaining_second . '"'; $html .= ' .replace("%SEC", seconds); '; $html .= ' } '; $html .= ' statustext += "<br />" + speed + "<br /><br />" ' . '+ estimated_time; '; $html .= ' } '; $html .= ' var percent_str = Math.round(percent) + "%"; '; $html .= ' $("#status").animate({width: percent_str}, 150); '; $html .= ' $(".percentage").text(percent_str); '; // show percent in window title $html .= ' if (original_title !== false) { '; $html .= ' parent.document.title '; $html .= ' = percent_str + " - " + original_title; '; $html .= ' } '; $html .= ' else { '; $html .= ' document.title '; $html .= ' = percent_str + " - " + original_title; '; $html .= ' } '; $html .= ' $("#statustext").html(statustext); '; $html .= ' } '; $html .= ' if (finished == true) { '; $html .= ' if (original_title !== false) { '; $html .= ' parent.document.title = original_title; '; $html .= ' } '; $html .= ' else { '; $html .= ' document.title = original_title; '; $html .= ' } '; $html .= ' $("#importmain").hide(); '; // loads the message, either success or mysql error $html .= ' $("#import_form_status") '; $html .= ' .html(\'<img src="' . $GLOBALS['pmaThemeImage'] . 'ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> ' . $processed_str . '\')'; $html .= ' .show(); '; $html .= ' $("#import_form_status").load("import_status.php?' . 'message=true&' . $import_url . '"); '; $html .= ' PMA_reloadNavigation(); '; // if finished $html .= ' } '; $html .= ' else { '; $html .= ' setTimeout(perform_upload, 1000); '; $html .= ' } '; $html .= '}); '; $html .= '}; '; $html .= 'setTimeout(perform_upload, 1000); '; return $html; }
/** * Show index data * * @param string $table The table name * @param string $schema The schema name * @param boolean $print_mode Whether the output is for the print mode * * @return string HTML for showing index * * @access public */ public static function getHtmlForIndexes($table, $schema, $print_mode = false) { $indexes = Index::getFromTable($table, $schema); $no_indexes_class = count($indexes) > 0 ? ' hide' : ''; $no_indexes = "<div class='no_indexes_defined{$no_indexes_class}'>"; $no_indexes .= Message::notice(__('No index defined!'))->getDisplay(); $no_indexes .= '</div>'; if (!$print_mode) { $r = '<fieldset class="index_info">'; $r .= '<legend id="index_header">' . __('Indexes'); $r .= Util::showMySQLDocu('optimizing-database-structure'); $r .= '</legend>'; $r .= $no_indexes; if (count($indexes) < 1) { $r .= '</fieldset>'; return $r; } $r .= Index::findDuplicates($table, $schema); } else { $r = '<h3>' . __('Indexes') . '</h3>'; $r .= $no_indexes; if (count($indexes) < 1) { return $r; } } $r .= '<table id="table_index">'; $r .= '<thead>'; $r .= '<tr>'; if (!$print_mode) { $r .= '<th colspan="2" class="print_ignore">' . __('Action') . '</th>'; } $r .= '<th>' . __('Keyname') . '</th>'; $r .= '<th>' . __('Type') . '</th>'; $r .= '<th>' . __('Unique') . '</th>'; $r .= '<th>' . __('Packed') . '</th>'; $r .= '<th>' . __('Column') . '</th>'; $r .= '<th>' . __('Cardinality') . '</th>'; $r .= '<th>' . __('Collation') . '</th>'; $r .= '<th>' . __('Null') . '</th>'; $r .= '<th>' . __('Comment') . '</th>'; $r .= '</tr>'; $r .= '</thead>'; $r .= '<tbody>'; foreach ($indexes as $index) { $row_span = ' rowspan="' . $index->getColumnCount() . '" '; $r .= '<tr class="noclick" >'; if (!$print_mode) { $this_params = $GLOBALS['url_params']; $this_params['index'] = $index->getName(); $r .= '<td class="edit_index print_ignore'; $r .= ' ajax'; $r .= '" ' . $row_span . '>' . ' <a class="'; $r .= 'ajax'; $r .= '" href="tbl_indexes.php' . URL::getCommon($this_params) . '">' . Util::getIcon('b_edit.png', __('Edit')) . '</a>' . '</td>' . "\n"; $this_params = $GLOBALS['url_params']; if ($index->getName() == 'PRIMARY') { $this_params['sql_query'] = 'ALTER TABLE ' . Util::backquote($table) . ' DROP PRIMARY KEY;'; $this_params['message_to_show'] = __('The primary key has been dropped.'); $js_msg = Sanitize::jsFormat('ALTER TABLE ' . $table . ' DROP PRIMARY KEY'); } else { $this_params['sql_query'] = 'ALTER TABLE ' . Util::backquote($table) . ' DROP INDEX ' . Util::backquote($index->getName()) . ';'; $this_params['message_to_show'] = sprintf(__('Index %s has been dropped.'), htmlspecialchars($index->getName())); $js_msg = Sanitize::jsFormat('ALTER TABLE ' . $table . ' DROP INDEX ' . $index->getName() . ';'); } $r .= '<td ' . $row_span . ' class="print_ignore">'; $r .= '<input type="hidden" class="drop_primary_key_index_msg"' . ' value="' . $js_msg . '" />'; $r .= ' <a class="drop_primary_key_index_anchor'; $r .= ' ajax'; $r .= '" href="sql.php' . URL::getCommon($this_params) . '" >' . Util::getIcon('b_drop.png', __('Drop')) . '</a>' . '</td>' . "\n"; } if (!$print_mode) { $r .= '<th ' . $row_span . '>' . htmlspecialchars($index->getName()) . '</th>'; } else { $r .= '<td ' . $row_span . '>' . htmlspecialchars($index->getName()) . '</td>'; } $r .= '<td ' . $row_span . '>'; $type = $index->getType(); if (!empty($type)) { $r .= htmlspecialchars($type); } else { $r .= htmlspecialchars($index->getChoice()); } $r .= '</td>'; $r .= '<td ' . $row_span . '>' . $index->isUnique(true) . '</td>'; $r .= '<td ' . $row_span . '>' . $index->isPacked() . '</td>'; foreach ($index->getColumns() as $column) { if ($column->getSeqInIndex() > 1) { $r .= '<tr class="noclick" >'; } $r .= '<td>' . htmlspecialchars($column->getName()); if ($column->getSubPart()) { $r .= ' (' . htmlspecialchars($column->getSubPart()) . ')'; } $r .= '</td>'; $r .= '<td>' . htmlspecialchars($column->getCardinality()) . '</td>'; $r .= '<td>' . htmlspecialchars($column->getCollation()) . '</td>'; $r .= '<td>' . htmlspecialchars($column->getNull(true)) . '</td>'; if ($column->getSeqInIndex() == 1) { $r .= '<td ' . $row_span . '>' . htmlspecialchars($index->getComments()) . '</td>'; } $r .= '</tr>'; } // end foreach $index['Sequences'] } // end while $r .= '</tbody>'; $r .= '</table>'; if (!$print_mode) { $r .= '</fieldset>'; } return $r; }
/** * Test for Sanitize::jsFormat * * @return void */ public function testJsFormat() { $this->assertEquals("`foo`", Sanitize::jsFormat('foo')); }
/** * Get delete and kill links * * @param string $where_clause the where clause of the sql * @param boolean $clause_is_unique the unique condition of clause * @param string $url_sql_query the analyzed sql query * @param string $del_lnk the delete link of current row * @param array $row the current row * * @return array 3 element array * $del_url, $del_str, $js_conf * * @access private * * @see _getTableBody() */ private function _getDeleteAndKillLinks($where_clause, $clause_is_unique, $url_sql_query, $del_lnk, $row) { $goto = $this->__get('goto'); if ($del_lnk == self::DELETE_ROW) { // delete row case $_url_params = array('db' => $this->__get('db'), 'table' => $this->__get('table'), 'sql_query' => $url_sql_query, 'message_to_show' => __('The row has been deleted.'), 'goto' => empty($goto) ? 'tbl_sql.php' : $goto); $lnk_goto = 'sql.php' . URL::getCommon($_url_params, 'text'); $del_query = 'DELETE FROM ' . Util::backquote($this->__get('table')) . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1'); $_url_params = array('db' => $this->__get('db'), 'table' => $this->__get('table'), 'sql_query' => $del_query, 'message_to_show' => __('The row has been deleted.'), 'goto' => $lnk_goto); $del_url = 'sql.php' . URL::getCommon($_url_params); $js_conf = 'DELETE FROM ' . Sanitize::jsFormat($this->__get('table')) . ' WHERE ' . Sanitize::jsFormat($where_clause, false) . ($clause_is_unique ? '' : ' LIMIT 1'); $del_str = $this->_getActionLinkContent('b_drop.png', __('Delete')); } elseif ($del_lnk == self::KILL_PROCESS) { // kill process case $_url_params = array('db' => $this->__get('db'), 'table' => $this->__get('table'), 'sql_query' => $url_sql_query, 'goto' => 'index.php'); $lnk_goto = 'sql.php' . URL::getCommon($_url_params, 'text'); $kill = $GLOBALS['dbi']->getKillQuery($row[0]); $_url_params = array('db' => 'mysql', 'sql_query' => $kill, 'goto' => $lnk_goto); $del_url = 'sql.php' . URL::getCommon($_url_params); $js_conf = $kill; $del_str = Util::getIcon('b_drop.png', __('Kill')); } else { $del_url = $del_str = $js_conf = null; } return array($del_url, $del_str, $js_conf); }