added back in some basic started data This is added only on initial installation...
[openemr.git] / interface / main / myadmin / tbl_query_box.php
blob77392be0b79eba7a11e4d28b5604f2f09914aca2
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 // Check parameters
7 require_once('./libraries/common.lib.php');
8 require_once('./libraries/bookmark.lib.php');
10 if (!($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full'))) {
11 PMA_checkParameters(array('db','table','url_query'));
14 /**
15 * Defines the query to be displayed in the query textarea
17 if (isset($show_query) && $show_query == '1') {
18 // This script has been called by read_dump.php
19 if (isset($sql_query_cpy)) {
20 $query_to_display = $sql_query_cpy;
22 // Other cases
23 else {
24 $query_to_display = $sql_query;
26 } else {
27 $query_to_display = '';
29 unset($sql_query);
31 /**
32 * Get the list and number of fields
34 $fields_cnt = 0;
35 if (isset($db) && isset($table) && $table != '' && $db != '') {
36 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
37 $result = @PMA_mysql_query($local_query);
38 if (!$result) {
39 PMA_mysqlDie('', $local_query, '', $err_url);
41 else {
42 $fields_cnt = mysql_num_rows($result);
43 while ($row = PMA_mysql_fetch_array($result)) {
44 $fields_list[] = $row['Field'];
45 } // end while
46 mysql_free_result($result);
50 /**
51 * Work on the table
53 // loic1: defines wether file upload is available or not
54 // ($is_upload now defined in common.lib.php)
56 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full')) {
57 $locking = 'onKeyPress="document.sqlform.elements[\'LockFromUpdate\'].checked = true;"';
58 } else {
59 $locking = '';
62 $auto_sel = ($cfg['TextareaAutoSelect']
63 // 2003-02-05 rabus: This causes big trouble with Opera 7 for
64 // Windows, so let's disable it there...
65 && !(PMA_USR_OS == 'Win' && PMA_USR_BROWSER_AGENT == 'OPERA' && PMA_USR_BROWSER_VER >= 7))
66 ? "\n" . ' onfocus="if (typeof(document.layers) == \'undefined\' || typeof(textarea_selected) == \'undefined\') {textarea_selected = 1; document.sqlform.elements[\'sql_query\'].select();}"'
67 : '';
68 $auto_sel .= ' ' . $locking;
70 // garvin: If non-JS query window is embedded, display a list of databases to choose from.
71 // Apart from that, a non-js query window sucks badly.
73 if ($cfg['QueryFrame'] && (!$cfg['QueryFrameJS'] && !$db || ($cfg['QueryFrameJS'] && !$db))) {
74 /**
75 * Get the list and number of available databases.
77 if ($server > 0) {
78 PMA_availableDatabases(); // this function is defined in "common.lib.php"
79 } else {
80 $num_dbs = 0;
83 if ($num_dbs > 0) {
84 $queryframe_db_list = '<select size=1 name="db">';
85 for ($i = 0; $i < $num_dbs; $i++) {
86 $t_db = $dblist[$i];
87 $queryframe_db_list .= '<option value="' . htmlspecialchars($t_db) . '">' . htmlspecialchars($t_db) . '</option>';
89 $queryframe_db_list .= '</select>';
90 } else {
91 $queryframe_db_list = '';
93 } else {
94 $queryframe_db_list = '';
97 $form_items = 0;
99 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow) {
101 <script type="text/javascript">
102 <!--
103 document.writeln('<form method="post" target="phpmain' + <?php echo ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) ? 'opener.' : '');?>parent.frames.queryframe.document.hashform.hash.value + '" action="read_dump.php"<?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?> onsubmit="return checkSqlQuery(this)" name="sqlform">');
104 //-->
105 </script>
106 <noscript>
107 <form method="post" target="phpmain<?php echo md5($cfg['PmaAbsoluteUri']); ?>" action="read_dump.php"<?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?> name="sqlform">
108 </noscript>
109 <?php
110 } else {
112 <form method="post" action="read_dump.php"<?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?> onsubmit="return checkSqlQuery(this)" name="sqlform">
113 <?php
116 <input type="hidden" name="is_js_confirmed" value="0" />
117 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
118 <input type="hidden" name="pos" value="0" />
119 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
120 <input type="hidden" name="zero_rows" value="<?php echo $strSuccess; ?>" />
121 <input type="hidden" name="prev_sql_query" value="<?php echo ((!empty($query_to_display)) ? urlencode($query_to_display) : ''); ?>" />
122 <?php
123 if (!isset($is_inside_querywindow) ||
124 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full'))) {
126 <!-- Query box and bookmark support -->
127 <?php
128 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
130 <input type="hidden" name="focus_querywindow" value="true" />
131 <?php
134 <a name="querybox"></a>
135 <table cellpadding="1" cellspacing="1">
136 <tr>
137 <td>
138 <?php echo sprintf($strRunSQLQuery, htmlspecialchars($db)) . $queryframe_db_list . (isset($is_inside_querywindow) ? '<br />' : ' ') . PMA_showMySQLDocu('Reference', 'SELECT'); ?>
139 <br />
140 <textarea name="sql_query" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? ceil($cfg['TextareaCols'] * 1.25) : $cfg['TextareaCols'] * 2); ?>" wrap="virtual" dir="<?php echo $text_dir; ?>"<?php echo $auto_sel; ?>>
141 <?php
142 if (!empty($query_to_display)) {
143 echo htmlspecialchars($query_to_display);
144 } elseif (isset($table)) {
145 echo htmlspecialchars(str_replace('%d', PMA_backquote($db), str_replace('%t', PMA_backquote($table), $cfg['DefaultQueryTable'])));
146 } else {
147 echo htmlspecialchars(str_replace('%d', PMA_backquote($db), $cfg['DefaultQueryDatabase']));
149 ?></textarea>
150 </td>
151 <?php if (isset($table) && $fields_cnt > 0) { ?>
152 <td align="center" valign="top"><?php echo (isset($is_inside_querywindow) ? '<br />' : '') . $strFields; ?>:<br />
153 <select name="dummy" size="4" multiple>
154 <?php
155 echo "\n";
156 for ($i = 0 ; $i < $fields_cnt; $i++) {
157 echo ' '
158 . '<option value="' . PMA_backquote(htmlspecialchars($fields_list[$i])) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
161 </select><br /><br />
162 <input type="button" name="insert" value="<?php echo($strInsert); ?>" onclick="insertValueQuery()" />
163 </td>
164 <?php
167 </tr>
168 </table>
169 <input type="checkbox" name="show_query" value="1" id="checkbox_show_query" checked="checked" />&nbsp;
170 <label for="checkbox_show_query"><?php echo $strShowThisQuery; ?></label><br />
171 <?php
172 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
174 <script type="text/javascript">
175 document.writeln('<input type="checkbox" name="LockFromUpdate" value="1" id="checkbox_lock" />&nbsp;');
176 document.writeln(' <label for="checkbox_lock"><?php echo $strQueryWindowLock; ?></label><br />');
177 </script>
178 <?php
181 $form_items++;
183 </div>
184 <?php
185 } else {
187 <input type="hidden" name="sql_query" value="" />
188 <input type="hidden" name="show_query" value="1" />
189 <?php
192 // loic1: displays import dump feature only if file upload available
193 if ($is_upload && (!isset($is_inside_querywindow) ||
194 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full')))) {
195 $form_items++;
196 echo ' ' . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') || !isset($is_inside_querywindow) ? '<i>' . $strOr . '</i>' : '') . ' ' . $strLocationTextfile . '&nbsp;:<br />' . "\n";
198 <div style="margin-bottom: 5px">
199 <input type="file" name="sql_file" class="textfield" /><br />
200 <?php
201 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
203 <input type="hidden" name="focus_querywindow" value="true" />
204 <?php
207 $is_gzip = ($cfg['GZipDump'] && @function_exists('gzopen'));
208 $is_bzip = ($cfg['BZipDump'] && @function_exists('bzdecompress'));
209 if ($is_bzip || $is_gzip) {
210 echo ' ' . $strCompression . ':' . "\n"
211 . ' <input type="radio" id="radio_sql_file_compression_auto" name="sql_file_compression" value="" checked="checked" />' . "\n"
212 . ' <label for="radio_sql_file_compression_auto">' . $strAutodetect . '</label>&nbsp;&nbsp;&nbsp;' . "\n"
213 . ' <input type="radio" id="radio_sql_file_compression_plain" name="sql_file_compression" value="text/plain" />' . "\n"
214 . ' <label for="radio_sql_file_compression_plain">' . $strNone . '</label>&nbsp;&nbsp;&nbsp;' . "\n";
215 if ($is_gzip) {
216 echo ' <input type="radio" id="radio_sql_file_compression_gzip" name="sql_file_compression" value="application/x-gzip" />' . "\n"
217 . ' <label for="radio_sql_file_compression_gzip">' . $strGzip . '</label>&nbsp;&nbsp;&nbsp;' . "\n";
219 if ($is_bzip) {
220 echo ' <input type="radio" id="radio_sql_file_compression_bzip" name="sql_file_compression" value="application/x-bzip" />' . "\n"
221 . ' <label for="radio_sql_file_compression_bzip">' . $strBzip . '</label>&nbsp;&nbsp;&nbsp;' . "\n";
223 } else {
224 echo ' <input type="hidden" name="sql_file_compression" value="text/plain" />' . "\n";
227 </div>
228 <?php
229 } // end if
230 echo "\n";
232 // web-server upload directory
233 $is_upload_dir = false;
234 if (!empty($cfg['UploadDir']) && !isset($is_inside_querywindow) ||
235 (!empty($cfg['UploadDir']) && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full'))) {
237 if (substr($cfg['UploadDir'], -1) != '/') {
238 $cfg['UploadDir'] .= '/';
240 if ($handle = @opendir($cfg['UploadDir'])) {
241 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
243 <input type="hidden" name="focus_querywindow" value="true" />
244 <?php
247 $is_first = 0;
248 while ($file = @readdir($handle)) {
249 if (is_file($cfg['UploadDir'] . $file) && PMA_checkFileExtensions($file, '.sql')) {
250 if ($is_first == 0) {
251 $is_upload_dir = true;
252 echo "\n";
253 echo ' ' . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') || !isset($is_inside_querywindow) ? '<i>' . $strOr . '</i>' : '') . ' ' . $strWebServerUploadDirectory . '&nbsp;:<br />' . "\n";
254 echo ' <div style="margin-bottom: 5px">' . "\n";
255 echo ' <select size="1" name="sql_localfile">' . "\n";
256 echo ' <option value="" selected="selected"></option>' . "\n";
257 $form_items++;
258 } // end if (is_first)
259 echo ' <option value="' . htmlspecialchars($file) . '">' . htmlspecialchars($file) . '</option>' . "\n";
260 $is_first++;
261 } // end if (is_file)
262 } // end while
263 if ($is_first > 0) {
264 echo ' </select>' . "\n"
265 . ' </div>' . "\n\n";
266 } // end if (isfirst > 0)
267 @closedir($handle);
268 } else {
269 echo ' <div style="margin-bottom: 5px">' . "\n";
270 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
271 echo ' ' . $strWebServerUploadDirectoryError . "\n";
272 echo ' </div>' . "\n";
274 } // end if (web-server upload directory)
275 echo "\n";
277 // Encoding setting form appended by Y.Kawada
278 if (function_exists('PMA_set_enc_form')) {
279 echo PMA_set_enc_form(' ');
280 $form_items++;
283 // Charset conversion options
284 if (($is_upload || $is_upload_dir) &&
285 (!isset($is_inside_querywindow) ||
286 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full')))
287 && isset($db) && $db != ''){
288 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding) {
289 $form_items++;
290 echo ' <div style="margin-bottom: 5px">' . "\n";
291 $temp_charset = reset($cfg['AvailableCharsets']);
292 echo $strCharsetOfFile . "\n"
293 . ' <select name="charset_of_file" size="1">' . "\n"
294 . ' <option value="' . $temp_charset . '"';
295 if ($temp_charset == $charset) {
296 echo ' selected="selected"';
298 echo '>' . $temp_charset . '</option>' . "\n";
299 while ($temp_charset = next($cfg['AvailableCharsets'])) {
300 echo ' <option value="' . $temp_charset . '"';
301 if ($temp_charset == $charset) {
302 echo ' selected="selected"';
304 echo '>' . $temp_charset . '</option>' . "\n";
306 echo ' </select><br />' . "\n" . ' ';
307 echo ' </div>' . "\n";
308 } // end if (recoding)
311 // Bookmark Support
312 $bookmark_go = FALSE;
313 if (!isset($is_inside_querywindow) ||
314 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full'))) {
315 if ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table']) {
316 if (($bookmark_list = PMA_listBookmarks($db, $cfg['Bookmark'])) && count($bookmark_list) > 0) {
317 $form_items++;
318 echo " " . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') || !isset($is_inside_querywindow) ? "<i>$strOr</i>" : '') . " $strBookmarkQuery&nbsp;:<br />\n";
320 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
322 <input type="hidden" name="focus_querywindow" value="true" />
323 <?php
326 echo ' <div style="margin-bottom: 5px">' . "\n";
327 echo ' <select name="id_bookmark" style="vertical-align: middle">' . "\n";
328 echo ' <option value=""></option>' . "\n";
329 foreach($bookmark_list AS $key => $value) {
330 echo ' <option value="' . $value . '">' . htmlspecialchars($key) . '</option>' . "\n";
332 echo ' </select>' . "<br />\n";
333 echo ' ' . $strVar . ' (<a href="./Documentation.html#faqbookmark" target="documentation">' . $strDocu . '</a>): <input type="text" name="bookmark_variable" class="textfield" size="10" />' . "\n";
334 echo ' <input type="radio" name="action_bookmark" value="0" id="radio_bookmark0" checked="checked" style="vertical-align: middle" /><label for="radio_bookmark0">' . $strSubmit . '</label>' . "\n";
335 echo ' &nbsp;<input type="radio" name="action_bookmark" value="1" id="radio_bookmark1" style="vertical-align: middle" /><label for="radio_bookmark1">' . $strBookmarkView . '</label>' . "\n";
336 echo ' &nbsp;<input type="radio" name="action_bookmark" value="2" id="radio_bookmark2" style="vertical-align: middle" /><label for="radio_bookmark2">' . $strDelete . '</label>' . "\n";
337 echo ' <br />' . "\n";
338 echo ' </div>' . "\n";
339 $bookmark_go = TRUE;
344 if (!isset($is_inside_querywindow) || (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && (($querydisplay_tab == 'files') || $querydisplay_tab == 'sql' || $querydisplay_tab == 'full' || ($querydisplay_tab == 'history' && $bookmark_go)))) {
345 if ($form_items > 0) {
347 <table border="0">
348 <tr>
349 <td valign="top">
350 <input type="submit" name="SQL" value="<?php echo $strGo; ?>" />
351 </td>
352 <?php
353 if ( $cfg['Bookmark']['db']
354 && $cfg['Bookmark']['table']
355 && (!isset($is_inside_querywindow)
356 || ( isset($is_inside_querywindow)
357 && $is_inside_querywindow == TRUE
358 && isset($querydisplay_tab)
359 //&& $querydisplay_tab != 'history'))) {
360 && $querydisplay_tab == 'sql'))) {
362 <td valign="top">
363 <input type="submit" name="SQLbookmark" value="<?php echo $strGo . ' &amp; ' . $strBookmarkThis; ?>" />
364 </td>
366 <td>
367 <fieldset>
368 <legend><?php echo $strBookmarkOptions; ?></legend>
369 <?php echo $strBookmarkLabel; ?>: <input type="text" name="bkm_label" value="" /><br />
370 <input type="checkbox" name="bkm_all_users" id="id_bkm_all_users" value="true" /><label for="id_bkm_all_users"><?php echo $strBookmarkAllUsers; ?></label>
371 </fieldset>
372 </td>
373 <?php
376 </tr>
377 </table>
378 <?php
379 } else {
380 // TODO: Add a more complete warning that no items (like for file import) where found.
381 // (After 2.5.2 release!)
382 echo $strWebServerUploadDirectoryError;
386 </form>
387 <?php
388 if (!isset($is_inside_querywindow) ||
389 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full')) && isset($db) && $db != '') {
391 // loic1: displays import dump feature only if file upload available
392 $ldi_target = 'ldi_table.php?' . $url_query . (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? '&amp;focus_querywindow=true' : '');
394 if ($is_upload && isset($db) && isset($table)) {
396 <!-- Insert a text file -->
397 <br /><br />
398 <li>
399 <?php
400 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
403 <script type="text/javascript">
404 document.writeln('<div style="margin-bottom: 10px"><a href="<?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? '#' : $ldi_target); ?>" <?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? 'onclick="opener.parent.frames.phpmain\' + opener.parent.frames.queryframe.document.hashform.hash.value + \'.location.href = \\\'' . $ldi_target . '\\\'; return false;"' : ''); ?>><?php echo addslashes($strInsertTextfiles); ?></a></div>');
405 </script>
407 <?php
408 } else {
411 <script type="text/javascript">
412 document.writeln('<div style="margin-bottom: 10px"><a href="<?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? '#' : $ldi_target); ?>" <?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? 'onclick="opener.parent.frames.phpmain' . md5($cfg['PmaAbsoluteUri']) . '.location.href = \\\'' . $ldi_target . '\\\'; return false;"' : ''); ?>><?php echo addslashes($strInsertTextfiles); ?></a></div>');
413 </script>
415 <?php
419 <noscript>
420 <div style="margin-bottom: 10px"><a href="<?php echo $ldi_target; ?>"><?php echo $strInsertTextfiles; ?></a></div>
421 </noscript>
422 </li>
423 <?php
426 echo "\n";