Documentation TYPO3 par Ameos

mult_submits.inc.php

00001 <?php
00002 /* $Id: mult_submits.inc.php,v 2.14 2005/07/10 19:31:24 nijel Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 
00009 if (!empty($submit_mult)
00010     && ($submit_mult != $strWithChecked)
00011     && (  !empty($selected_db)
00012        || !empty($selected_tbl)
00013        || !empty($selected_fld)
00014        || !empty($rows_to_delete)
00015          )) {
00016 
00017     if (!empty($selected_db)) {
00018         $selected     = $selected_db;
00019         $what         = 'drop_db';
00020     } else if (!empty($selected_tbl)) {
00021         if ($submit_mult == $strPrintView) {
00022             require('./tbl_printview.php');
00023         } else {
00024            $selected = $selected_tbl;
00025            switch ($submit_mult) {
00026                case 'drop_db':
00027                    $what = 'drop_db';
00028                    break;
00029                case $strDrop:
00030                    $what = 'drop_tbl';
00031                    break;
00032                case $strEmpty:
00033                    $what = 'empty_tbl';
00034                    break;
00035                case $strCheckTable:
00036                    unset($submit_mult);
00037                    $query_type = 'check_tbl';
00038                    $mult_btn   = $strYes;
00039                    break;
00040                case $strOptimizeTable:
00041                    unset($submit_mult);
00042                    $query_type = 'optimize_tbl';
00043                    $mult_btn   = $strYes;
00044                    break;
00045                case $strRepairTable:
00046                    unset($submit_mult);
00047                    $query_type = 'repair_tbl';
00048                    $mult_btn   = $strYes;
00049                    break;
00050                case $strAnalyzeTable:
00051                    unset($submit_mult);
00052                    $query_type = 'analyze_tbl';
00053                    $mult_btn   = $strYes;
00054                    break;
00055            } // end switch
00056         }
00057     } else if (!empty($selected_fld)) {
00058         $selected     = $selected_fld;
00059         switch ($submit_mult) {
00060             case $strDrop:
00061                 $what     = 'drop_fld';
00062                 break;
00063             case $strPrimary:
00064                 // Gets table primary key
00065                 PMA_DBI_select_db($db);
00066                 $result      = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
00067                 $primary     = '';
00068                 while ($row = PMA_DBI_fetch_assoc($result)) {
00069                     // Backups the list of primary keys
00070                     if ($row['Key_name'] == 'PRIMARY') {
00071                         $primary .= $row['Column_name'] . ', ';
00072                     }
00073                 } // end while
00074                 PMA_DBI_free_result($result);
00075                 if (empty($primary)) {
00076                     // no primary key, so we can safely create new
00077                     unset($submit_mult);
00078                     $query_type = 'primary_fld';
00079                     $mult_btn   = $strYes;
00080                 } else {
00081                     // primary key exists, so lets as user
00082                     $what = 'primary_fld';
00083                 }
00084                 break;
00085             case $strIndex:
00086                 unset($submit_mult);
00087                 $query_type = 'index_fld';
00088                 $mult_btn   = $strYes;
00089                 break;
00090             case $strUnique:
00091                 unset($submit_mult);
00092                 $query_type = 'unique_fld';
00093                 $mult_btn   = $strYes;
00094                 break;
00095             case $strIdxFulltext:
00096                 unset($submit_mult);
00097                 $query_type = 'fulltext_fld';
00098                 $mult_btn   = $strYes;
00099                 break;
00100             case $strChange:
00101                 require('./tbl_alter.php');
00102                 break;
00103         }
00104     } else {
00105         $what = 'row_delete';
00106         $selected = $rows_to_delete;
00107     }
00108 } // end if
00109 
00110 
00114 if (!empty($submit_mult) && !empty($what)) {
00115     $js_to_run = 'functions.js';
00116     unset($message);
00117     if (!empty($table)) {
00118         require('./tbl_properties_common.php');
00119         $url_query .= '&amp;goto=tbl_properties.php&amp;back=tbl_properties.php';
00120         require('./tbl_properties_table_info.php');
00121     }
00122     elseif (!empty($db)) {
00123         require('./db_details_common.php');
00124         require('./db_details_db_info.php');
00125     }
00126     // Builds the query
00127     $full_query     = '';
00128     if ($what == 'drop_tbl') {
00129         $full_query_views = '';
00130     }
00131     $selected_cnt   = count($selected);
00132     $i = 0;
00133     foreach ($selected AS $idx => $sval) {
00134         switch ($what) {
00135             case 'row_delete':
00136                 $full_query .= htmlspecialchars(urldecode($sval))
00137                             . ';<br />';
00138                 break;
00139             case 'drop_db':
00140                 $full_query .= 'DROP DATABASE '
00141                             . PMA_backquote(htmlspecialchars(urldecode($sval)))
00142                             . ';<br />';
00143                 break;
00144 
00145             case 'drop_tbl':
00146                 $current = urldecode($sval);
00147                 if (!empty($views) && in_array($current, $views)) {
00148                     $full_query_views .= (empty($full_query_views) ? 'DROP VIEW ' : ', ')
00149                                        . PMA_backquote(htmlspecialchars($current));
00150                 } else {
00151                     $full_query .= (empty($full_query) ? 'DROP TABLE ' : ', ')
00152                                 . PMA_backquote(htmlspecialchars($current));
00153                 }
00154                 break;
00155 
00156             case 'empty_tbl':
00157                 if (PMA_MYSQL_INT_VERSION >= 40000) {
00158                     $full_query .= 'TRUNCATE ';
00159                 } else {
00160                     $full_query .= 'DELETE FROM ';
00161                 }
00162                 $full_query .= PMA_backquote(htmlspecialchars(urldecode($sval)))
00163                             . ';<br />';
00164                 break;
00165 
00166             case 'primary_fld':
00167                 if ($full_query == '') {
00168                     $full_query .= 'ALTER TABLE '
00169                                 . PMA_backquote(htmlspecialchars($table))
00170                                 . '<br />&nbsp;&nbsp;DROP PRIMARY KEY,'
00171                                 . '<br />&nbsp;&nbsp; ADD PRIMARY KEY('
00172                                 . '<br />&nbsp;&nbsp;&nbsp;&nbsp; '
00173                                 . PMA_backquote(htmlspecialchars(urldecode($sval)))
00174                                 . ',';
00175                 } else {
00176                     $full_query .= '<br />&nbsp;&nbsp;&nbsp;&nbsp; '
00177                                 . PMA_backquote(htmlspecialchars(urldecode($sval)))
00178                                 . ',';
00179                 }
00180                 if ($i == $selected_cnt-1) {
00181                     $full_query = preg_replace('@,$@', ');<br />', $full_query);
00182                 }
00183                 break;
00184                 
00185             case 'drop_fld':
00186                 if ($full_query == '') {
00187                     $full_query .= 'ALTER TABLE '
00188                                 . PMA_backquote(htmlspecialchars($table))
00189                                 . '<br />&nbsp;&nbsp;DROP '
00190                                 . PMA_backquote(htmlspecialchars(urldecode($sval)))
00191                                 . ',';
00192                 } else {
00193                     $full_query .= '<br />&nbsp;&nbsp;DROP '
00194                                 . PMA_backquote(htmlspecialchars(urldecode($sval)))
00195                                 . ',';
00196                 }
00197                 if ($i == $selected_cnt-1) {
00198                     $full_query = preg_replace('@,$@', ';<br />', $full_query);
00199                 }
00200                 break;
00201         } // end switch
00202         $i++;
00203     }
00204     if ($what == 'drop_tbl') {
00205         if (!empty($full_query)) {
00206             $full_query .= ';<br />' . "\n";
00207         }
00208         if (!empty($full_query_views)) {
00209             $full_query .= $full_query_views . ';<br />' . "\n";
00210         }
00211         unset($full_query_views);
00212     }
00213 
00214     // Displays the form
00215 ?>
00216 <!-- Do it really ? -->
00217 <table border="0" cellpadding="3" cellspacing="0">
00218     <tr>
00219         <th class="tblHeadError" align="left">
00220             <?php
00221     echo ($GLOBALS['cfg']['ErrorIconic'] ? '<img src="' . $GLOBALS['pmaThemeImage'] . 's_really.png" border="0" hspace="2" width="11" height="11" valign="middle" />' : '');
00222     echo $strDoYouReally . ':&nbsp;' . "\n";
00223             ?>
00224         </th>
00225     </tr>
00226     <tr>
00227         <td bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>">
00228            <?php
00229     echo '<tt>' . $full_query . '</tt>&nbsp;?<br/>' . "\n";
00230            ?>
00231         </td>
00232     </tr>
00233     <tr>
00234        <td align="right" nowrap="nowrap">
00235 <form action="<?php echo $action; ?>" method="post">
00236     <?php
00237     echo "\n";
00238     if (strpos(' ' . $action, 'db_details') == 1) {
00239         echo PMA_generate_common_hidden_inputs($db);
00240     } else if (strpos(' ' . $action, 'tbl_properties') == 1
00241               || $what == 'row_delete') {
00242         echo PMA_generate_common_hidden_inputs($db,$table);
00243     } else  {
00244         echo PMA_generate_common_hidden_inputs();
00245     }
00246     foreach ($selected AS $idx => $sval) {
00247         echo '    <input type="hidden" name="selected[]" value="' . htmlspecialchars($sval) . '" />' . "\n";
00248     }
00249     if ($what == 'drop_tbl' && !empty($views)) {
00250         foreach ($views as $current) {
00251             echo '    <input type="hidden" name="views[]" value="' . htmlspecialchars($current) . '" />' . "\n";
00252         }
00253     }
00254     ?>
00255     <input type="hidden" name="query_type" value="<?php echo $what; ?>" />
00256     <?php
00257     if ($what == 'row_delete') {
00258         echo '<input type="hidden" name="original_sql_query" value="' . htmlspecialchars($original_sql_query) . '" />' . "\n";
00259         echo '<input type="hidden" name="original_pos" value="' . $original_pos . '" />' . "\n";
00260         echo '<input type="hidden" name="original_url_query" value="' . htmlspecialchars($original_url_query) . '" />' . "\n";
00261         echo '<input type="hidden" name="disp_direction"   value="' . $disp_direction . '" />' . "\n";
00262         echo '<input type="hidden" name="repeat_cells"     value="' . $repeat_cells   . '" />' . "\n";
00263         echo '<input type="hidden" name="dontlimitchars"   value="' . $dontlimitchars . '" />' . "\n";
00264         echo '<input type="hidden" name="pos"              value="' . $pos . '" />' . "\n";
00265         echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
00266     }
00267     ?>
00268     <input type="submit" name="mult_btn" value="<?php echo $strYes; ?>" id="buttonYes" />
00269     <input type="submit" name="mult_btn" value="<?php echo $strNo; ?>" id="buttonNo" />
00270 </form>
00271         </td>
00272     </tr>
00273 </table>
00274     <?php
00275     echo"\n";
00276 
00277     require_once('./footer.inc.php');
00278 } // end if
00279 
00280 
00284 else if ($mult_btn == $strYes) {
00285 
00286     if ($query_type == 'drop_db' || $query_type == 'drop_tbl' || $query_type == 'drop_fld') {
00287         require_once('./libraries/relation_cleanup.lib.php');
00288     }
00289 
00290     $sql_query      = '';
00291     if ($query_type == 'drop_tbl') {
00292         $sql_query_views = '';
00293     }
00294     $selected_cnt   = count($selected);
00295     $run_parts      = FALSE; // whether to run query after each pass
00296     $use_sql        = FALSE; // whether to include sql.php at the end (to display results)
00297 
00298     if ($query_type == 'primary_fld') {
00299         // Gets table primary key
00300         PMA_DBI_select_db($db);
00301         $result      = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
00302         $primary     = '';
00303         while ($row = PMA_DBI_fetch_assoc($result)) {
00304             // Backups the list of primary keys
00305             if ($row['Key_name'] == 'PRIMARY') {
00306                 $primary .= $row['Column_name'] . ', ';
00307             }
00308         } // end while
00309         PMA_DBI_free_result($result);
00310     }
00311     
00312     for ($i = 0; $i < $selected_cnt; $i++) {
00313         switch ($query_type) {
00314             case 'row_delete':
00315                 $a_query = urldecode($selected[$i]);
00316                 $run_parts = TRUE;
00317                 break;
00318 
00319             case 'drop_db':
00320                 PMA_relationsCleanupDatabase($selected[$i]);
00321                 $a_query   = 'DROP DATABASE '
00322                            . PMA_backquote(urldecode($selected[$i]));
00323                 $reload    = 1;
00324                 $run_parts = TRUE;
00325                 break;
00326 
00327             case 'drop_tbl':
00328                 PMA_relationsCleanupTable($db, $selected[$i]);
00329                 $current = urldecode($selected[$i]);
00330                 if (!empty($views) && in_array($current, $views)) {
00331                     $sql_query_views .= (empty($sql_query_views) ? 'DROP VIEW ' : ', ')
00332                                       . PMA_backquote($current);
00333                 } else {
00334                     $sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ')
00335                                . PMA_backquote($current);
00336                 }
00337                 $reload    = 1;
00338                 break;
00339 
00340             case 'check_tbl':
00341                 $sql_query .= (empty($sql_query) ? 'CHECK TABLE ' : ', ')
00342                            . PMA_backquote(urldecode($selected[$i]));
00343                 $use_sql    = TRUE;
00344                 break;
00345 
00346             case 'optimize_tbl':
00347                 $sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ')
00348                            . PMA_backquote(urldecode($selected[$i]));
00349                 $use_sql    = TRUE;
00350                 break;
00351 
00352             case 'analyze_tbl':
00353                 $sql_query .= (empty($sql_query) ? 'ANALYZE TABLE ' : ', ')
00354                            . PMA_backquote(urldecode($selected[$i]));
00355                 $use_sql    = TRUE;
00356                 break;
00357 
00358             case 'repair_tbl':
00359                 $sql_query .= (empty($sql_query) ? 'REPAIR TABLE ' : ', ')
00360                            . PMA_backquote(urldecode($selected[$i]));
00361                 $use_sql    = TRUE;
00362                 break;
00363 
00364             case 'empty_tbl':
00365                 if (PMA_MYSQL_INT_VERSION >= 40000) {
00366                     $a_query = 'TRUNCATE ';
00367                 } else {
00368                     $a_query = 'DELETE FROM ';
00369                 }
00370                 $a_query .= PMA_backquote(htmlspecialchars(urldecode($selected[$i])));
00371                 $run_parts = TRUE;
00372                 break;
00373 
00374             case 'drop_fld':
00375                 PMA_relationsCleanupColumn($db, $table, $selected[$i]);
00376                 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) : ',')
00377                            . ' DROP ' . PMA_backquote(urldecode($selected[$i]))
00378                            . (($i == $selected_cnt-1) ? ';' : '');
00379                 break;
00380 
00381             case 'primary_fld':
00382                 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ( empty($primary) ? '' : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' : ', ')
00383                            . PMA_backquote(urldecode($selected[$i]))
00384                            . (($i == $selected_cnt-1) ? ');' : '');
00385                 break;
00386 
00387             case 'index_fld':
00388                 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX( ' : ', ')
00389                            . PMA_backquote(urldecode($selected[$i]))
00390                            . (($i == $selected_cnt-1) ? ');' : '');
00391                 break;
00392 
00393             case 'unique_fld':
00394                 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE( ' : ', ')
00395                            . PMA_backquote(urldecode($selected[$i]))
00396                            . (($i == $selected_cnt-1) ? ');' : '');
00397                 break;
00398 
00399             case 'fulltext_fld':
00400                 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT( ' : ', ')
00401                            . PMA_backquote(urldecode($selected[$i]))
00402                            . (($i == $selected_cnt-1) ? ');' : '');
00403                 break;
00404         } // end switch
00405 
00406         // All "DROP TABLE","DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
00407         // statements will be run at once below
00408         if ($run_parts) { 
00409             $sql_query .= $a_query . ';' . "\n";
00410             if ($query_type != 'drop_db') {
00411                 PMA_DBI_select_db($db);
00412             }
00413             $result = @PMA_DBI_query($a_query) or PMA_mysqlDie('', $a_query, FALSE, $err_url);
00414         } // end if
00415     } // end for
00416 
00417     if ($query_type == 'drop_tbl') {
00418         if (!empty($sql_query)) {
00419             $sql_query .= ';';
00420         } else if (!empty($sql_query_views)) {
00421             $sql_query = $sql_query_views . ';';
00422             unset($sql_query_views);
00423         }
00424     }
00425 
00426     if ($use_sql) {
00427         require('./sql.php');
00428     } elseif (!$run_parts) {
00429         PMA_DBI_select_db($db);
00430         $result = PMA_DBI_query($sql_query);
00431         if (!empty($sql_query_views)) {
00432             $sql_query .= ' ' . $sql_query_views . ';';
00433             PMA_DBI_query($sql_query_views);
00434             unset($sql_query_views);
00435         }
00436     }
00437 
00438 }
00439 
00440 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6