From 04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 9 Jan 2020 10:55:03 +0100 Subject: phpmyadmin working --- srcs/phpmyadmin/libraries/classes/SqlQueryForm.php | 457 +++++++++++++++++++++ 1 file changed, 457 insertions(+) create mode 100644 srcs/phpmyadmin/libraries/classes/SqlQueryForm.php (limited to 'srcs/phpmyadmin/libraries/classes/SqlQueryForm.php') diff --git a/srcs/phpmyadmin/libraries/classes/SqlQueryForm.php b/srcs/phpmyadmin/libraries/classes/SqlQueryForm.php new file mode 100644 index 0000000..15aaaf7 --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/SqlQueryForm.php @@ -0,0 +1,457 @@ +' . "\n"; + + $html .= '' + . "\n" . Url::getHiddenInputs($db, $table) . "\n" + . '' . "\n" + . '' . "\n" + . '' + . "\n" . '' . "\n"; + + // display querybox + if ($display_tab === 'full' || $display_tab === 'sql') { + $html .= $this->getHtmlForInsert( + $query, + $delimiter + ); + } + + // Bookmark Support + if ($display_tab === 'full') { + $cfgBookmark = Bookmark::getParams($GLOBALS['cfg']['Server']['user']); + if ($cfgBookmark) { + $html .= $this->getHtmlForBookmark(); + } + } + + // Japanese encoding setting + if (Encoding::canConvertKanji()) { + $html .= Encoding::kanjiEncodingForm(); + } + + $html .= '' . "\n"; + // print an empty div, which will be later filled with + // the sql query results by ajax + $html .= '
'; + + return $html; + } + + /** + * Get initial values for Sql Query Form Insert + * + * @param string $query query to display in the textarea + * + * @return array ($legend, $query, $columns_list) + */ + public function init($query) + { + $columns_list = []; + if (strlen($GLOBALS['db']) === 0) { + // 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']) === 0) { + // prepare for db related + $db = $GLOBALS['db']; + // if you want navigation: + $tmp_db_link = ''; + $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); + if (empty($query)) { + $query = Util::expandUserString( + $GLOBALS['cfg']['DefaultQueryDatabase'], + 'backquote' + ); + } + } else { + $db = $GLOBALS['db']; + $table = $GLOBALS['table']; + // 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_tbl_link = ''; + $tmp_tbl_link .= htmlspecialchars($db) + . '.' . htmlspecialchars($table) . ''; + $legend = sprintf(__('Run SQL query/queries on table %s'), $tmp_tbl_link); + if (empty($query)) { + $query = Util::expandUserString( + $GLOBALS['cfg']['DefaultQueryTable'], + 'backquote' + ); + } + } + $legend .= ': ' . Util::showMySQLDocu('SELECT'); + + return [ + $legend, + $query, + $columns_list, + ]; + } + + /** + * 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 + */ + public function getHtmlForInsert( + $query = '', + $delimiter = ';' + ) { + // enable auto select text in textarea + if ($GLOBALS['cfg']['TextareaAutoSelect']) { + $auto_sel = ' onclick="Functions.selectContent(this, sqlBoxLocked, true);"'; + } else { + $auto_sel = ''; + } + + $locking = ''; + $height = $GLOBALS['cfg']['TextareaRows'] * 2; + + list($legend, $query, $columns_list) = $this->init($query); + + if (! empty($columns_list)) { + $sqlquerycontainer_id = 'sqlquerycontainer'; + } else { + $sqlquerycontainer_id = 'sqlquerycontainerfull'; + } + + $html = '' + . '
' + . '
'; + $html .= '' . $legend . ''; + $html .= '
'; + $html .= '
' + . ''; + $html .= '
'; + // Add buttons to generate query easily for + // select all, single select, insert, update and delete + if (! empty($columns_list)) { + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + } + $html .= ''; + if ($GLOBALS['cfg']['CodemirrorEnable']) { + $html .= ''; + } + $html .= ''; + + // parameter binding + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= Util::showDocu('faq', 'faq6-40'); + $html .= '
'; + $html .= '
'; + + $html .= '
' . "\n"; + + if (! empty($columns_list)) { + $html .= '
' + . '' + . '' + . '
'; + if (Util::showIcons('ActionLinksMode')) { + $html .= ''; + } else { + $html .= ''; + } + $html .= '
' . "\n" + . '
' . "\n"; + } + + $html .= '
' . "\n"; + $html .= '
' . "\n"; + + $cfgBookmark = Bookmark::getParams($GLOBALS['cfg']['Server']['user']); + if ($cfgBookmark) { + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + } + + $html .= '
' . "\n"; + $html .= '
' . "\n" + . '
' . "\n"; + + $html .= '
' . "\n"; + $html .= '
' . "\n"; + $html .= '
' . "\n"; + + $html .= '
'; + $html .= '' . "\n"; + $html .= ' ]'; + $html .= '
'; + + $html .= '
'; + $html .= '' + . ''; + $html .= '
'; + + $html .= '
'; + $html .= '' + . ''; + $html .= '
'; + + $html .= '
'; + $html .= '' + . ''; + $html .= '
'; + + // Disable/Enable foreign key checks + $html .= '
'; + $html .= Util::getFKCheckbox(); + $html .= '
'; + + $html .= '' . "\n"; + $html .= '
' . "\n"; + $html .= '
' . "\n"; + + return $html; + } + + /** + * return HTML for sql Query Form Bookmark + * + * @return string|null + */ + public function getHtmlForBookmark() + { + $bookmark_list = Bookmark::getList( + $GLOBALS['dbi'], + $GLOBALS['cfg']['Server']['user'], + $GLOBALS['db'] + ); + if (empty($bookmark_list) || count($bookmark_list) < 1) { + return null; + } + + $html = '
'; + $html .= ''; + $html .= __('Bookmarked SQL query') . '' . "\n"; + $html .= '
'; + $html .= ' ' . "\n"; + $html .= '
' . "\n"; + $html .= '
' . "\n"; + $html .= '' + . '' . "\n"; + $html .= '' + . '' . "\n"; + $html .= '' + . '' . "\n"; + $html .= '
' . "\n"; + $html .= '
' . "\n"; + $html .= '
' . "\n"; + $html .= __('Variables'); + $html .= Util::showDocu('faq', 'faqbookmark'); + $html .= '
'; + $html .= '
' . "\n"; + $html .= '
' . "\n"; + + $html .= '
'; + $html .= ''; + $html .= '
' . "\n"; + $html .= '
' . "\n"; + + return $html; + } +} -- cgit