home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / db_operations.php < prev    next >
Encoding:
PHP Script  |  2004-10-22  |  17.1 KB  |  380 lines

  1. <?php
  2. /* $Id: db_operations.php,v 2.4 2004/10/22 09:41:57 nijel Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. require_once('./libraries/grab_globals.lib.php');
  6. require_once('./libraries/common.lib.php');
  7. require_once('./libraries/mysql_charsets.lib.php');
  8.  
  9. /**
  10.  * Rename database
  11.  */
  12. if (isset($db) &&
  13.     ((isset($db_rename) && $db_rename == 'true') ||
  14.     (isset($db_copy) && $db_copy == 'true'))) {
  15.  
  16.     require_once('./libraries/tbl_move_copy.php');
  17.  
  18.     if (isset($db_rename) && $db_rename == 'true') $move = TRUE;
  19.     else $move = FALSE;
  20.  
  21.     if (!isset($newname) || empty($newname)) {
  22.         $message = $strDatabaseEmpty;
  23.     } else {
  24.         $local_query = 'CREATE DATABASE ' . PMA_backquote($newname) . ';';
  25.         $sql_query = $local_query;
  26.         PMA_DBI_query($local_query);
  27.         $tables = PMA_DBI_get_tables($db);
  28.         foreach ($tables as $table) {
  29.             $back = $sql_query;
  30.             $sql_query = '';
  31.             PMA_table_move_copy($db, $table, $newname, $table, isset($what) ? $what : 'data', $move);
  32.             $sql_query = $back . $sql_query;
  33.         }
  34.         if ($move) {
  35.             $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
  36.             $sql_query .= "\n" . $local_query;
  37.             PMA_DBI_query($local_query);
  38.             $message    = sprintf($strRenameDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
  39.         } else {
  40.             $message    = sprintf($strCopyDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
  41.         }
  42.         $reload     = TRUE;
  43.  
  44.         /* Change database to be used */
  45.         if ($move) {
  46.             $db         = $newname;
  47.         } else {
  48.             $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
  49.             if (isset($switch_to_new) && $switch_to_new == 'true') {
  50.                 setcookie('pma_switch_to_new', 'true', 0, substr($pma_uri_parts['path'], 0, strrpos($pma_uri_parts['path'], '/')), '', ($pma_uri_parts['scheme'] == 'https'));
  51.                 $db         = $newname;
  52.             } else {
  53.                 setcookie('pma_switch_to_new', '', 0, substr($pma_uri_parts['path'], 0, strrpos($pma_uri_parts['path'], '/')), '', ($pma_uri_parts['scheme'] == 'https'));
  54.             }
  55.         }
  56.     }
  57. }
  58. /**
  59.  * Prepares the tables list if the user where not redirected to this script
  60.  * because there is no table in the database ($is_info is TRUE)
  61.  */
  62. if (empty($is_info)) {
  63.     require('./db_details_common.php');
  64.     $url_query .= '&goto=db_operations.php';
  65.  
  66.     // Gets the database structure
  67.     $sub_part = '_structure';
  68.     require('./db_details_db_info.php');
  69.     echo "\n";
  70. }
  71.  
  72. if (PMA_MYSQL_INT_VERSION >= 40101) {
  73.     $db_collation = PMA_getDbCollation($db);
  74. }
  75. ?>
  76.  
  77. <table border="0" cellpadding="2" cellspacing="0">
  78.     <!-- Create a new table -->
  79.         <form method="post" action="tbl_create.php" onsubmit="return (emptyFormElements(this, 'table') && checkFormElementInRange(this, 'num_fields', 1))">
  80.      <tr>
  81.      <td class="tblHeaders" colspan="3" nowrap="nowrap"><?php
  82.         echo PMA_generate_common_hidden_inputs($db);
  83.         if($cfg['PropertiesIconic']){ echo '<img src="' . $pmaThemeImage . 'b_newtbl.png" border="0" width="16" height="16" hspace="2" align="middle" />'; }
  84.         // if you want navigation:
  85.         $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url() . '&db=' . urlencode($GLOBALS['db']) . '">'
  86.                    . htmlspecialchars($GLOBALS['db']) . '</a>';
  87.         // else use
  88.         // $strDBLink = htmlspecialchars($db);
  89. echo '             ' . sprintf($strCreateNewTable, $strDBLink) . ': ' . "\n";
  90. echo '     </td></tr>';
  91. echo '     <tr bgcolor="'.$cfg['BgcolorOne'].'"><td nowrap="nowrap">';
  92. echo '             ' . $strName . ': ' . "\n";
  93. echo '     </td>';
  94. echo '     <td nowrap="nowrap">';
  95. echo '             ' . '<input type="text" name="table" maxlength="64" size="30" class="textfield" />';
  96. echo '     </td><td> </td></tr>';
  97. echo '     <tr bgcolor="'.$cfg['BgcolorOne'].'"><td nowrap="nowrap">';
  98. echo '             ' . $strFields . ': ' . "\n";
  99. echo '     </td>';
  100. echo '     <td nowrap="nowrap">';
  101. echo '             ' . '<input type="text" name="num_fields" size="2" class="textfield" />' . "\n";
  102. echo '     </td>';
  103. echo '     <td align="right">';
  104. echo '             ' . ' <input type="submit" value="' . $strGo . '" />' . "\n";
  105. echo '     </td> </tr>';
  106. echo '        </form>';
  107.  
  108. /**
  109.  * Settings for relations stuff
  110.  */
  111. require_once('./libraries/relation.lib.php');
  112. $cfgRelation = PMA_getRelationsParam();
  113.  
  114. /**
  115.  * Check if comments were updated
  116.  */
  117. if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
  118.     PMA_SetComment($db, '', '(db_comment)', $comment);
  119. }
  120.  
  121. echo '<table border="0" cellpadding="2" cellspacing="0">';
  122. if ($cfgRelation['commwork']) {
  123. ?>
  124.     <!-- Alter/Enter db-comment -->
  125.         <tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
  126.  
  127.         <tr>
  128.         <td colspan="3" class="tblHeaders"><?php
  129.     if ($cfg['PropertiesIconic']) {
  130.         echo '<img src="' . $pmaThemeImage . 'b_comment.png" border="0" width="16" height="16" hspace="2" align="middle" />';
  131.     }
  132.     echo $strDBComment;
  133.     $comment = PMA_getComments($db);
  134.         ?></td></tr>
  135.                                 <form method="post" action="db_operations.php">
  136.         <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
  137.                                   <td colspan="2" nowrap="nowrap">
  138.             <input type="hidden" name="db_comment" value="true" />
  139.             <?php echo PMA_generate_common_hidden_inputs($db); ?>
  140.             <input type="text" name="comment" class="textfield" size="30" value="<?php echo (isset($comment) && is_array($comment) ? htmlspecialchars(implode(' ', $comment)) : ''); ?>" /></td><td align="right">
  141.             <input type="submit" value="<?php echo $strGo; ?>" />
  142.          </td></tr>
  143.         </form>
  144. <?php
  145. }
  146. ?>
  147.     <!-- Rename database -->
  148.         <tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
  149.         <tr><td colspan="3" class="tblHeaders"><?php
  150.           if ($cfg['PropertiesIconic']) {
  151.               echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
  152.           }
  153.           echo $strDBRename.': ';
  154.           ?></td></tr>
  155.         <form method="post" action="db_operations.php"
  156.             onsubmit="return emptyFormElements(this, 'newname')">
  157.                                         <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><td colspan="2"><?php
  158.           echo '<input type="hidden" name="db_rename" value="true" />'
  159.              . PMA_generate_common_hidden_inputs($db);
  160.           ?><input type="text" name="newname" size="30" class="textfield" value="" /></td>
  161.             <td align="right"><input type="submit" value="<?php echo $strGo; ?>" /></td>
  162.         </form></tr>
  163.  
  164.     <!-- Copy database -->
  165.         <tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
  166.         <tr><td colspan="3" class="tblHeaders"><?php
  167.           if ($cfg['PropertiesIconic']) {
  168.               echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
  169.           }
  170.           echo $strDBCopy.': ';
  171.           ?></td></tr>
  172.         <form method="post" action="db_operations.php"
  173.             onsubmit="return emptyFormElements(this, 'newname')">
  174.                                         <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><td colspan="3"><?php
  175.           echo '<input type="hidden" name="db_copy" value="true" />'
  176.              . PMA_generate_common_hidden_inputs($db);
  177.           ?><input type="text" name="newname" size="30" class="textfield" value="" /></td>
  178.         </tr><tr>
  179.             <td nowrap="nowrap" bgcolor="<?php echo $cfg['BgcolorOne']; ?>" colspan="2">
  180.                 <input type="radio" name="what" value="structure" id="radio_copy_structure" style="vertical-align: middle" /><label for="radio_copy_structure"><?php echo $strStrucOnly; ?></label>  <br />
  181.                 <input type="radio" name="what" value="data" id="radio_copy_data" checked="checked" style="vertical-align: middle" /><label for="radio_copy_data"><?php echo $strStrucData; ?></label>  <br />
  182.                 <input type="radio" name="what" value="dataonly" id="radio_copy_dataonly" style="vertical-align: middle" /><label for="radio_copy_dataonly"><?php echo $strDataOnly; ?></label>  <br />
  183.  
  184.                 <input type="checkbox" name="auto_increment" value="1" id="checkbox_auto_increment" style="vertical-align: middle" /><label for="checkbox_auto_increment"><?php echo $strAddAutoIncrement; ?></label><br />
  185.                 <input type="checkbox" name="constraints" value="1" id="checkbox_constraints" style="vertical-align: middle" /><label for="checkbox_constraints"><?php echo $strAddConstraints; ?></label><br />
  186.                 <?php
  187.                     if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new']) && $_COOKIE['pma_switch_to_new'] == 'true') {
  188.                         $pma_switch_to_new = 'true';
  189.                     }
  190.                 ?>
  191.                 <input type="checkbox" name="switch_to_new" value="true" id="checkbox_switch"<?php echo ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true') ? ' checked="checked"' : ''); ?> style="vertical-align: middle" /><label for="checkbox_switch"><?php echo $strSwitchToDatabase; ?></label>  
  192.             </td>
  193.             <td align="<?php echo $cell_align_right; ?>" valign="bottom" bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
  194.                 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
  195.             </td>
  196.         </tr>
  197.     </form>
  198.  
  199. <?php
  200.  
  201. if (PMA_MYSQL_INT_VERSION >= 40101) {
  202.     // MySQL supports setting default charsets / collations for databases since
  203.     // version 4.1.1.
  204.     echo '    <!-- Change database charset -->' . "\n"
  205.        . '    <tr><td colspan="3"><img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png' . '" width="1" height="1" border="0" alt="" /></td></tr>' . "\n"
  206.        . '    <tr><td colspan="3" class="tblHeaders">';
  207.     if ($cfg['PropertiesIconic']) {
  208.         echo '<img src="' . $pmaThemeImage . 's_asci.png" border="0" width="16" height="16" hspace="2" align="middle" />';
  209.     }
  210.     echo '      <label for="select_db_collation">' . $strCollation . '</label>: ' . "\n"
  211.        . '    </td></tr>' . "\n"
  212.        . '        <form method="post" action="./db_operations.php">' . "\n"
  213.        . '    <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td colspan="2" nowrap="nowrap">'
  214.        . PMA_generate_common_hidden_inputs($db, $table, 3)
  215.        . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3)
  216.        . '    </td><td align="right">'
  217.        . '            <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
  218.        . '    </td></tr>' . "\n"
  219.        . '        </form>' . "\n"
  220.        . '         ' . "\n\n";
  221. }
  222.  
  223. if ($num_tables > 0
  224.     && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) {
  225.     echo '<tr><td colspan="3"><img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png' . '" width="1" height="1" border="0" alt="" /></td></tr>'
  226.         . '<tr><th colspan="3" class="tblHeadError"><div class="errorhead">' . $strError . '</div></th></tr>'
  227.         . '<tr><td colspan="3" class="tblError">'
  228.         . sprintf(wordwrap($strRelationNotWorking,65,'<br />'), '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">',  '</a>')
  229.         . '</td></tr>';
  230. } // end if
  231. ?>
  232. </table>
  233.  
  234. <form method="post" action="pdf_schema.php">
  235. <?php
  236. // is this OK to check for 'class' support?
  237. if ($num_tables > 0) {
  238.     $takeaway = $url_query . '&table=' . urlencode($table);
  239. }
  240.  
  241. if (($cfgRelation['pdfwork'] && $num_tables > 0) ||
  242.     ($num_tables > 0
  243.      && $cfgRelation['relwork'] && $cfgRelation['commwork']
  244.      && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
  245.     )) { ?>
  246. <hr /><table border="0" cellpadding="2" cellspacing="0">
  247. <?php
  248. }
  249.  
  250. if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?>
  251.     <!-- Work on PDF Pages -->
  252.     <tr>
  253.         <td colspan="3" class="tblHeaders">
  254.     <?php
  255.     if ($cfg['PropertiesIconic']) {
  256.         echo '<img src="' . $pmaThemeImage . 'b_pdfdoc.png" border="0" width="16" height="16" hspace="2" align="middle" />';
  257.     } ?>PDF</td>
  258.     </tr>
  259.  
  260.     <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
  261.         <td colspan="3">
  262.         <?php
  263.             echo '<a href="pdf_pages.php?' . $takeaway . '">';
  264.             if ($cfg['PropertiesIconic']) {
  265.                 echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
  266.             }
  267.             echo ''. $strEditPDFPages . '</a>';
  268.         ?>
  269.         </td>
  270.     </tr>
  271.  
  272.     <!-- PDF schema -->
  273.     <?php
  274.     // We only show this if we find something in the new pdf_pages table
  275.  
  276.     $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
  277.                 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
  278.     $test_rs    = PMA_query_as_cu($test_query, NULL, PMA_DBI_QUERY_STORE);
  279.  
  280.     if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?>
  281.     <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
  282.         <td colspan="3">
  283.         <?php
  284.          echo PMA_generate_common_hidden_inputs($db);
  285.          if ($cfg['PropertiesIconic']) {
  286.              echo '<img src="' . $pmaThemeImage . 'b_view.png" border="0" width="16" height="16" hspace="2" align="middle" />';
  287.          }
  288.          echo $strDisplayPDF; ?>: 
  289.         </td>
  290.     </tr>
  291.  
  292.     <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
  293.         <td width="20"> </td>
  294.         <td colspan="2">
  295.             <label for="pdf_page_number_opt"><?php echo $strPageNumber; ?></label>
  296.             <select name="pdf_page_number" id="pdf_page_number_opt">
  297.             <?php
  298.             while ($pages = @PMA_DBI_fetch_assoc($test_rs)) {
  299.                 echo '                <option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>' . "\n";
  300.             } // end while
  301.             PMA_DBI_free_result($test_rs);
  302.             unset($test_rs);
  303.             ?>
  304.             </select><br />
  305.  
  306.             <input type="checkbox" name="show_grid" id="show_grid_opt" /><label for="show_grid_opt"><?php echo $strShowGrid; ?></label><br />
  307.             <input type="checkbox" name="show_color" id="show_color_opt" checked="checked" /><label for="show_color_opt"><?php echo $strShowColor; ?></label><br />
  308.             <input type="checkbox" name="show_table_dimension" id="show_table_dim_opt" /><label for="show_table_dim_opt"><?php echo $strShowTableDimension; ?></label><br />
  309.             <input type="checkbox" name="all_tab_same_wide" id="all_tab_same_wide" /><label for="all_tab_same_wide"><?php echo $strAllTableSameWidth; ?></label><br />
  310.             <input type="checkbox" name="with_doc" id="with_doc" checked="checked" /><label for="with_doc"><?php echo $strDataDict; ?></label><br />
  311.  
  312.             <label for="orientation_opt"><?php echo $strShowDatadictAs; ?></label>
  313.             <select name="orientation" id="orientation_opt">
  314.                 <option value="L"><?php echo $strLandscape;?></option>
  315.                 <option value="P"><?php echo $strPortrait;?></option>
  316.             </select><br />
  317.  
  318.             <label for="paper_opt"><?php echo $strPaperSize; ?></label>
  319.             <select name="paper" id="paper_opt">
  320.             <?php
  321.                 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
  322.                     echo '<option value="' . $val . '"';
  323.                     if ($val == $cfg['PDFDefaultPageSize']) {
  324.                         echo ' selected="selected"';
  325.                     }
  326.                     echo ' >' . $val . '</option>' . "\n";
  327.                 }
  328.             ?>
  329.             </select>
  330.         </td>
  331.     </tr>
  332.  
  333.     <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
  334.         <td width="20"> </td>
  335.         <td colspan="3" align="right">  <input type="submit" value="<?php echo $strGo; ?>" /></td>
  336.     </tr>
  337.     <tr>
  338.         <td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td>
  339.     </tr>
  340.         <?php
  341.     }   // end if
  342. } // end if
  343.  
  344. if ($num_tables > 0
  345.     && $cfgRelation['relwork'] && $cfgRelation['commwork']
  346.     && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
  347.     ) {
  348. ?>
  349.     <!-- import docSQL files -->
  350.     <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
  351.         <td colspan="3">
  352.         <?php
  353.         echo '<a href="db_details_importdocsql.php?' . $takeaway . '">';
  354.         if ($cfg['PropertiesIconic']) {
  355.             echo '<img src="' . $pmaThemeImage . 'b_docsql.png" border="0" width="16" height="16" hspace="2" align="middle" />';
  356.         }
  357.         echo $strImportDocSQL . '</a>';
  358.         ?>
  359.         </td>
  360.     </tr>
  361.     <?php
  362. }
  363. echo "\n";
  364. if (($cfgRelation['pdfwork'] && $num_tables > 0) ||
  365.     ($num_tables > 0
  366.      && $cfgRelation['relwork'] && $cfgRelation['commwork']
  367.      && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
  368.     )) { ?>
  369. </table>
  370. </form>
  371. <?php
  372. }
  373.  
  374. /**
  375.  * Displays the footer
  376.  */
  377. echo "\n";
  378. require_once('./footer.inc.php');
  379. ?>
  380.