Documentation TYPO3 par Ameos

db_operations.php

00001 <?php
00002 /* $Id: db_operations.php,v 2.17 2005/07/22 16:25:22 lem9 Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 require_once('./libraries/grab_globals.lib.php');
00006 require_once('./libraries/common.lib.php');
00007 require_once('./libraries/mysql_charsets.lib.php');
00011 if (isset($db) &&
00012     ((isset($db_rename) && $db_rename == 'true') ||
00013     (isset($db_copy) && $db_copy == 'true'))) {
00014 
00015     require_once('./libraries/tbl_move_copy.php');
00016 
00017     $force_queryframe_reload = TRUE;
00018 
00019     if (isset($db_rename) && $db_rename == 'true') {
00020         $move = TRUE;
00021     } else {
00022         $move = FALSE;
00023     }
00024 
00025     if (!isset($newname) || empty($newname)) {
00026         $message = $strDatabaseEmpty;
00027     } else {
00028         if ($move ||
00029            (isset($create_database_before_copying) && $create_database_before_copying)) {
00030             $local_query = 'CREATE DATABASE ' . PMA_backquote($newname);
00031             if (isset($db_collation)) {
00032                 $local_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
00033             }
00034             $local_query .= ';';
00035             $sql_query = $local_query;
00036             PMA_DBI_query($local_query);
00037         }
00038 
00039         $tables_full = PMA_DBI_get_tables_full($db);
00040         foreach ($tables_full as $table => $tmp) {
00041             $back = $sql_query;
00042             $sql_query = '';
00043 
00044             // value of $what for this table only
00045             $this_what = $what;
00046 
00047             if (!isset($tables_full[$table]['Engine'])) {
00048                 $tables_full[$table]['Engine'] = $tables_full[$table]['Type'];
00049             }
00050             // do not copy the data from a Merge table
00051             // note: on the calling FORM, 'data' means 'structure and data'
00052             if ($tables_full[$table]['Engine'] == 'MRG_MyISAM') {
00053                 if ($this_what == 'data') {
00054                     $this_what = 'structure';
00055                 }
00056                 if ($this_what == 'dataonly') {
00057                     $this_what = 'nocopy';
00058                 }
00059             }
00060 
00061             if ($this_what != 'nocopy') {
00062                 PMA_table_move_copy($db, $table, $newname, $table, isset($this_what) ? $this_what : 'data', $move);
00063             }
00064 
00065             $sql_query = $back . $sql_query;
00066         }
00067         unset($table);
00068 
00069         // Duplicate the bookmarks for this db (done once for each db)
00070         if ($db != $newname) {
00071             $get_fields = array('user','label','query');
00072             $where_fields = array('dbase' => $db);
00073             $new_fields = array('dbase' => $newname);
00074             PMA_duplicate_table_info('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields);
00075         }
00076 
00077         if ($move) {
00078             // cleanup pmadb stuff for this db
00079             require_once('./libraries/relation_cleanup.lib.php');
00080             PMA_relationsCleanupDatabase($db);
00081 
00082             $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
00083             $sql_query .= "\n" . $local_query;
00084             PMA_DBI_query($local_query);
00085             $message    = sprintf($strRenameDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
00086         } else {
00087             $message    = sprintf($strCopyDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
00088         }
00089         $reload     = TRUE;
00090 
00091         /* Change database to be used */
00092         if ($move) {
00093             $db         = $newname;
00094         } else {
00095             $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
00096             if (isset($switch_to_new) && $switch_to_new == 'true') {
00097                 setcookie('pma_switch_to_new', 'true', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);
00098                 $db         = $newname;
00099             } else {
00100                 setcookie('pma_switch_to_new', '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);
00101             }
00102         }
00103     }
00104 }
00109 require_once('./libraries/relation.lib.php');
00110 $cfgRelation = PMA_getRelationsParam();
00111 
00116 if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
00117     PMA_SetComment($db, '', '(db_comment)', $comment);
00118 }
00119 
00124 if (empty($is_info)) {
00125     require('./db_details_common.php');
00126     $url_query .= '&amp;goto=db_operations.php';
00127 
00128     // Gets the database structure
00129     $sub_part = '_structure';
00130     require('./db_details_db_info.php');
00131     echo "\n";
00132 }
00133 
00134 if (PMA_MYSQL_INT_VERSION >= 40101) {
00135     $db_collation = PMA_getDbCollation($db);
00136 }
00137 if (PMA_MYSQL_INT_VERSION < 50002 || (PMA_MYSQL_INT_VERSION >= 50002 && $db != 'information_schema')) {
00138     $is_information_schema = FALSE;
00139 } else {
00140     $is_information_schema = TRUE;
00141 }
00142 
00143 if (!$is_information_schema) {
00144 ?>
00145 
00146 <table border="0" cellpadding="2" cellspacing="0">
00147     <!-- Create a new table -->
00148         <form method="post" action="tbl_create.php" onsubmit="return (emptyFormElements(this, 'table') && checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidFieldCount']); ?>', 1))">
00149      <tr>
00150      <td class="tblHeaders" colspan="3" nowrap="nowrap"><?php
00151         echo PMA_generate_common_hidden_inputs($db);
00152         if($cfg['PropertiesIconic']){ echo '<img src="' . $pmaThemeImage . 'b_newtbl.png" border="0" width="16" height="16" hspace="2" align="middle" />'; }
00153         // if you want navigation:
00154         $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url() . '&amp;db=' . urlencode($GLOBALS['db']) . '">'
00155                    . htmlspecialchars($GLOBALS['db']) . '</a>';
00156         // else use
00157         // $strDBLink = htmlspecialchars($db);
00158     echo '             ' . sprintf($strCreateNewTable, $strDBLink) . ':&nbsp;' . "\n";
00159     echo '     </td></tr>';
00160     echo '     <tr bgcolor="'.$cfg['BgcolorOne'].'"><td nowrap="nowrap">';
00161     echo '             ' . $strName . ':&nbsp;' . "\n";
00162     echo '     </td>';
00163     echo '     <td nowrap="nowrap">';
00164     echo '             ' . '<input type="text" name="table" maxlength="64" size="30" class="textfield" />';
00165     echo '     </td><td>&nbsp;</td></tr>';
00166     echo '     <tr bgcolor="'.$cfg['BgcolorOne'].'"><td nowrap="nowrap">';
00167     echo '             ' . $strFields . ':&nbsp;' . "\n";
00168     echo '     </td>';
00169     echo '     <td nowrap="nowrap">';
00170     echo '             ' . '<input type="text" name="num_fields" size="2" class="textfield" />' . "\n";
00171     echo '     </td>';
00172     echo '     <td align="right">';
00173     echo '             ' . '&nbsp;<input type="submit" value="' . $strGo . '" />' . "\n";
00174     echo '     </td> </tr>' . "\n";
00175     echo '        </form>' . "\n";
00176     echo '</table>' . "\n";
00177 
00178     echo '<table border="0" cellpadding="2" cellspacing="0">';
00179     if ($cfgRelation['commwork']) {
00180 ?>
00181     <!-- Alter/Enter db-comment -->
00182         <tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
00183 
00184         <tr>
00185         <td colspan="3" class="tblHeaders"><?php
00186         if ($cfg['PropertiesIconic']) {
00187             echo '<img src="' . $pmaThemeImage . 'b_comment.png" border="0" width="16" height="16" hspace="2" align="middle" />';
00188         }
00189         echo $strDBComment;
00190         $comment = PMA_getComments($db);
00191         ?></td></tr>
00192                                 <form method="post" action="db_operations.php">
00193         <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00194                                   <td colspan="2" nowrap="nowrap">
00195             <input type="hidden" name="db_comment" value="true" />
00196             <?php echo PMA_generate_common_hidden_inputs($db); ?>
00197             <input type="text" name="comment" class="textfield" size="30" value="<?php echo (isset($comment) && is_array($comment) ? htmlspecialchars(implode(' ', $comment)) : ''); ?>" /></td><td align="right">
00198             <input type="submit" value="<?php echo $strGo; ?>" />
00199          </td></tr>
00200         </form>
00201 <?php
00202     }
00203 ?>
00204     <!-- Rename database -->
00205         <tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
00206         <tr><td colspan="3" class="tblHeaders"><?php
00207           if ($cfg['PropertiesIconic']) {
00208               echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
00209           }
00210           echo $strDBRename.':&nbsp;';
00211           ?></td></tr>
00212         <form method="post" action="db_operations.php"
00213             onsubmit="return emptyFormElements(this, 'newname')">
00214                                         <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><td colspan="2"><?php
00215           echo '<input type="hidden" name="what" value="data" />';
00216           echo '<input type="hidden" name="db_rename" value="true" />'
00217              . PMA_generate_common_hidden_inputs($db);
00218           ?><input type="text" name="newname" size="30" class="textfield" value="" /></td>
00219             <td align="right"><input type="submit" value="<?php echo $strGo; ?>" /></td>
00220         </form></tr>
00221 
00222     <!-- Copy database -->
00223         <tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
00224         <tr><td colspan="3" class="tblHeaders"><?php
00225           if ($cfg['PropertiesIconic']) {
00226               echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
00227           }
00228           echo $strDBCopy.':&nbsp;';
00229           ?></td></tr>
00230         <form method="post" action="db_operations.php"
00231             onsubmit="return emptyFormElements(this, 'newname')">
00232         <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><td colspan="3">
00233 <?php
00234           if (isset($db_collation)) {
00235               echo '<input type="hidden" name="db_collation" value="' . $db_collation .'" />' . "\n";
00236           }
00237           echo '<input type="hidden" name="db_copy" value="true" />' . "\n"
00238              . PMA_generate_common_hidden_inputs($db);
00239           ?><input type="text" name="newname" size="30" class="textfield" value="" /></td>
00240         </tr><tr>
00241             <td nowrap="nowrap" bgcolor="<?php echo $cfg['BgcolorOne']; ?>" colspan="2">
00242                 <input type="radio" name="what" value="structure" id="radio_copy_structure" style="vertical-align: middle" /><label for="radio_copy_structure"><?php echo $strStrucOnly; ?></label>&nbsp;&nbsp;<br />
00243                 <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>&nbsp;&nbsp;<br />
00244                 <input type="radio" name="what" value="dataonly" id="radio_copy_dataonly" style="vertical-align: middle" /><label for="radio_copy_dataonly"><?php echo $strDataOnly; ?></label>&nbsp;&nbsp;<br />
00245                 
00246 
00247                 <input type="checkbox" name="create_database_before_copying" value="1" id="checkbox_create_database_before_copying" style="vertical-align: middle" checked="checked" /><label for="checkbox_create_database_before_copying"><?php echo $strCreateDatabaseBeforeCopying; ?></label><br />
00248                 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" style="vertical-align: middle" /><label for="checkbox_drop"><?php echo $strStrucDrop; ?></label>&nbsp;&nbsp;<br />
00249                 <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 />
00250                 <input type="checkbox" name="constraints" value="1" id="checkbox_constraints" style="vertical-align: middle" /><label for="checkbox_constraints"><?php echo $strAddConstraints; ?></label><br />
00251                 <?php
00252                     if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new']) && $_COOKIE['pma_switch_to_new'] == 'true') {
00253                         $pma_switch_to_new = 'true';
00254                     }
00255                 ?>
00256                 <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>&nbsp;&nbsp;
00257             </td>
00258             <td align="<?php echo $cell_align_right; ?>" valign="bottom" bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00259                 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
00260             </td>
00261         </tr>
00262     </form>
00263 
00264 <?php
00265 
00266     if (PMA_MYSQL_INT_VERSION >= 40101) {
00267     // MySQL supports setting default charsets / collations for databases since
00268     // version 4.1.1.
00269         echo '    <!-- Change database charset -->' . "\n"
00270            . '    <tr><td colspan="3"><img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png' . '" width="1" height="1" border="0" alt="" /></td></tr>' . "\n"
00271            . '    <tr><td colspan="3" class="tblHeaders">';
00272         if ($cfg['PropertiesIconic']) {
00273             echo '<img src="' . $pmaThemeImage . 's_asci.png" border="0" width="16" height="16" hspace="2" align="middle" />';
00274         }
00275         echo '      <label for="select_db_collation">' . $strCollation . '</label>:&nbsp;' . "\n"
00276            . '    </td></tr>' . "\n"
00277            . '        <form method="post" action="./db_operations.php">' . "\n"
00278            . '    <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td colspan="2" nowrap="nowrap">'
00279            . PMA_generate_common_hidden_inputs($db, $table, 3)
00280            . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3)
00281            . '    </td><td align="right">'
00282            . '            <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
00283            . '    </td></tr>' . "\n"
00284            . '        </form>' . "\n"
00285            . '         ' . "\n\n";
00286     }
00287 
00288     if ($num_tables > 0
00289         && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) {
00290         echo '<tr><td colspan="3"><img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png' . '" width="1" height="1" border="0" alt="" /></td></tr>'
00291             . '<tr><th colspan="3" class="tblHeadError"><div class="errorhead">' . $strError . '</div></th></tr>'
00292             . '<tr><td colspan="3" class="tblError">'
00293             . sprintf(wordwrap($strRelationNotWorking,65,'<br />'), '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">',  '</a>')
00294             . '</td></tr>';
00295     } // end if
00296 ?>
00297 </table>
00298 <?php
00299 } // end if (!$is_information_schema)
00300 // not sure about leaving the PDF dialog for information_schema
00301 
00302 ?>
00303 <form method="post" action="pdf_schema.php">
00304 <?php
00305 
00306 if ($num_tables > 0) {
00307     $takeaway = $url_query . '&amp;table=' . urlencode($table);
00308 }
00309 
00310 if (($cfgRelation['pdfwork'] && $num_tables > 0) ||
00311     ($num_tables > 0
00312      && $cfgRelation['relwork'] && $cfgRelation['commwork']
00313      && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
00314     )) { ?>
00315 <hr /><table border="0" cellpadding="2" cellspacing="0">
00316 <?php
00317 }
00318 
00319 if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?>
00320     <!-- Work on PDF Pages -->
00321     <tr>
00322         <td colspan="3" class="tblHeaders">
00323     <?php
00324     if ($cfg['PropertiesIconic']) {
00325         echo '<img src="' . $pmaThemeImage . 'b_pdfdoc.png" border="0" width="16" height="16" hspace="2" align="middle" />';
00326     } ?>PDF</td>
00327     </tr>
00328 
00329     <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00330         <td colspan="3">
00331         <?php
00332             echo '<a href="pdf_pages.php?' . $takeaway . '">';
00333             if ($cfg['PropertiesIconic']) {
00334                 echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
00335             }
00336             echo ''. $strEditPDFPages . '</a>';
00337         ?>
00338         </td>
00339     </tr>
00340 
00341     <!-- PDF schema -->
00342     <?php
00343     // We only show this if we find something in the new pdf_pages table
00344 
00345     $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
00346                 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
00347     $test_rs    = PMA_query_as_cu($test_query, NULL, PMA_DBI_QUERY_STORE);
00348 
00349     if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?>
00350     <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
00351         <td colspan="3">
00352         <?php
00353          echo PMA_generate_common_hidden_inputs($db);
00354          if ($cfg['PropertiesIconic']) {
00355              echo '<img src="' . $pmaThemeImage . 'b_view.png" border="0" width="16" height="16" hspace="2" align="middle" />';
00356          }
00357          echo $strDisplayPDF; ?>:&nbsp;
00358         </td>
00359     </tr>
00360 
00361     <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
00362         <td width="20">&nbsp;</td>
00363         <td colspan="2">
00364             <label for="pdf_page_number_opt"><?php echo $strPageNumber; ?></label>
00365             <select name="pdf_page_number" id="pdf_page_number_opt">
00366             <?php
00367             while ($pages = @PMA_DBI_fetch_assoc($test_rs)) {
00368                 echo '                <option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>' . "\n";
00369             } // end while
00370             PMA_DBI_free_result($test_rs);
00371             unset($test_rs);
00372             ?>
00373             </select><br />
00374 
00375             <input type="checkbox" name="show_grid" id="show_grid_opt" /><label for="show_grid_opt"><?php echo $strShowGrid; ?></label><br />
00376             <input type="checkbox" name="show_color" id="show_color_opt" checked="checked" /><label for="show_color_opt"><?php echo $strShowColor; ?></label><br />
00377             <input type="checkbox" name="show_table_dimension" id="show_table_dim_opt" /><label for="show_table_dim_opt"><?php echo $strShowTableDimension; ?></label><br />
00378             <input type="checkbox" name="all_tab_same_wide" id="all_tab_same_wide" /><label for="all_tab_same_wide"><?php echo $strAllTableSameWidth; ?></label><br />
00379             <input type="checkbox" name="with_doc" id="with_doc" checked="checked" /><label for="with_doc"><?php echo $strDataDict; ?></label><br />
00380 
00381             <label for="orientation_opt"><?php echo $strShowDatadictAs; ?></label>
00382             <select name="orientation" id="orientation_opt">
00383                 <option value="L"><?php echo $strLandscape;?></option>
00384                 <option value="P"><?php echo $strPortrait;?></option>
00385             </select><br />
00386 
00387             <label for="paper_opt"><?php echo $strPaperSize; ?></label>
00388             <select name="paper" id="paper_opt">
00389             <?php
00390                 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
00391                     echo '<option value="' . $val . '"';
00392                     if ($val == $cfg['PDFDefaultPageSize']) {
00393                         echo ' selected="selected"';
00394                     }
00395                     echo ' >' . $val . '</option>' . "\n";
00396                 }
00397             ?>
00398             </select>
00399         </td>
00400     </tr>
00401 
00402     <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
00403         <td width="20">&nbsp;</td>
00404         <td colspan="3" align="right">&nbsp;&nbsp;<input type="submit" value="<?php echo $strGo; ?>" /></td>
00405     </tr>
00406     <tr>
00407         <td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td>
00408     </tr>
00409         <?php
00410     }   // end if
00411 } // end if
00412 
00413 if ($num_tables > 0
00414     && $cfgRelation['relwork'] && $cfgRelation['commwork']
00415     && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
00416     ) {
00417 ?>
00418     <!-- import docSQL files -->
00419     <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00420         <td colspan="3">
00421         <?php
00422         echo '<a href="db_details_importdocsql.php?' . $takeaway . '">';
00423         if ($cfg['PropertiesIconic']) {
00424             echo '<img src="' . $pmaThemeImage . 'b_docsql.png" border="0" width="16" height="16" hspace="2" align="middle" />';
00425         }
00426         echo $strImportDocSQL . '</a>';
00427         ?>
00428         </td>
00429     </tr>
00430     <?php
00431 }
00432 echo "\n";
00433 if (($cfgRelation['pdfwork'] && $num_tables > 0) ||
00434     ($num_tables > 0
00435      && $cfgRelation['relwork'] && $cfgRelation['commwork']
00436      && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
00437     )) { ?>
00438 </table>
00439 </form>
00440 <?php
00441 }
00442 
00446 echo "\n";
00447 require_once('./footer.inc.php');
00448 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6