Documentation TYPO3 par Ameos

tbl_alter.php

00001 <?php
00002 /* $Id: tbl_alter.php,v 2.3 2003/11/26 22:52:24 rabus Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 
00009 require_once('./libraries/grab_globals.lib.php');
00010 $js_to_run = 'functions.js';
00011 require_once('./header.inc.php');
00012 
00013 // Check parameters
00014 PMA_checkParameters(array('db', 'table'));
00015 
00019 $err_url = 'tbl_properties_structure.php?' . PMA_generate_common_url($db, $table);
00020 
00021 
00025 $abort = false;
00026 if (isset($submit)) {
00027     $field_cnt = count($field_orig);
00028     for ($i = 0; $i < $field_cnt; $i++) {
00029         // to "&quot;" in tbl_properties.php
00030         $field_orig[$i]     = urldecode($field_orig[$i]);
00031         if (strcmp(str_replace('"', '&quot;', $field_orig[$i]), $field_name[$i]) == 0) {
00032             $field_name[$i] = $field_orig[$i];
00033         }
00034         $field_default_orig[$i] = urldecode($field_default_orig[$i]);
00035         if (strcmp(str_replace('"', '&quot;', $field_default_orig[$i]), $field_default[$i]) == 0) {
00036             $field_default[$i]  = $field_default_orig[$i];
00037         }
00038         $field_length_orig[$i] = urldecode($field_length_orig[$i]);
00039         if (strcmp(str_replace('"', '&quot;', $field_length_orig[$i]), $field_length[$i]) == 0) {
00040             $field_length[$i] = $field_length_orig[$i];
00041         }
00042         if (!isset($query)) {
00043             $query = '';
00044         } else {
00045             $query .= ', CHANGE ';
00046         }
00047         $query .= PMA_backquote($field_orig[$i]) . ' ' . PMA_backquote($field_name[$i]) . ' ' . $field_type[$i];
00048         // Some field types shouldn't have lengths
00049         if ($field_length[$i] != ''
00050             && !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$@i', $field_type[$i])) {
00051             $query .= '(' . $field_length[$i] . ')';
00052         }
00053         if ($field_attribute[$i] != '') {
00054             $query .= ' ' . $field_attribute[$i];
00055         } else if (PMA_MYSQL_INT_VERSION >= 40100 && $field_charset[$i] != '') {
00056             $query .= ' CHARACTER SET ' . $field_charset[$i];
00057         }
00058         if ($field_default[$i] != '') {
00059             if (strtoupper($field_default[$i]) == 'NULL') {
00060                 $query .= ' DEFAULT NULL';
00061             } else {
00062                 $query .= ' DEFAULT \'' . PMA_sqlAddslashes($field_default[$i]) . '\'';
00063             }
00064         }
00065         if ($field_null[$i] != '') {
00066             $query .= ' ' . $field_null[$i];
00067         }
00068         if ($field_extra[$i] != '') {
00069             $query .= ' ' . $field_extra[$i];
00070         }
00071     } // end for
00072 
00073     // To allow replication, we first select the db to use and then run queries
00074     // on this db.
00075     $sql_query     = 'USE ' . PMA_backquote($db);
00076     $result        = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
00077     // Optimization fix - 2 May 2001 - Robbat2
00078     $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query;
00079     $error_create = false;
00080     $result    = PMA_mysql_query($sql_query) or $error_create = true;
00081 
00082     if ($error_create == false) {
00083         $message   = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
00084         $btnDrop   = 'Fake';
00085 
00086         // garvin: If comments were sent, enable relation stuff
00087         require_once('./libraries/relation.lib.php');
00088         require_once('./libraries/transformations.lib.php');
00089 
00090         $cfgRelation = PMA_getRelationsParam();
00091 
00092         // garvin: Update comment table, if a comment was set.
00093         if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
00094             foreach($field_comments AS $fieldindex => $fieldcomment) {
00095                 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, $field_orig[$fieldindex]);
00096             }
00097         }
00098 
00099         // garvin: Rename relations&display fields, if altered.
00100         if (($cfgRelation['displaywork'] || $cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) {
00101             foreach($field_orig AS $fieldindex => $fieldcontent) {
00102                 if ($field_name[$fieldindex] != $fieldcontent) {
00103                     if ($cfgRelation['displaywork']) {
00104                         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
00105                                       . ' SET     display_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
00106                                       . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\''
00107                                       . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00108                                       . ' AND display_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
00109                         $tb_rs    = PMA_query_as_cu($table_query);
00110                         unset($table_query);
00111                         unset($tb_rs);
00112                     }
00113 
00114                     if ($cfgRelation['relwork']) {
00115                         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
00116                                       . ' SET     master_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
00117                                       . ' WHERE master_db  = \'' . PMA_sqlAddslashes($db) . '\''
00118                                       . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
00119                                       . ' AND master_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
00120                         $tb_rs    = PMA_query_as_cu($table_query);
00121                         unset($table_query);
00122                         unset($tb_rs);
00123 
00124                         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
00125                                       . ' SET     foreign_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
00126                                       . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($db) . '\''
00127                                       . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
00128                                       . ' AND foreign_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
00129                         $tb_rs    = PMA_query_as_cu($table_query);
00130                         unset($table_query);
00131                         unset($tb_rs);
00132                     } // end if relwork
00133                 } // end if fieldname has changed
00134             } // end while check fieldnames
00135         } // end if relations/display has to be changed
00136 
00137         // garvin: Update comment table for mime types [MIME]
00138         if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
00139             foreach($field_mimetype AS $fieldindex => $mimetype) {
00140                 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
00141             }
00142         }
00143 
00144         $active_page = 'tbl_properties_structure.php';
00145         require('./tbl_properties_structure.php');
00146     } else {
00147         PMA_mysqlDie('', '', '', $err_url, FALSE);
00148         // garvin: An error happened while inserting/updating a table definition.
00149         // to prevent total loss of that data, we embed the form once again.
00150         // The variable $regenerate will be used to restore data in tbl_properties.inc.php
00151         if (isset($orig_field)) {
00152                 $field = $orig_field;
00153         }
00154 
00155         $regenerate = true;
00156     }
00157 }
00158 
00162 if ($abort == FALSE) {
00163     if (!isset($selected)) {
00164         PMA_checkParameters(array('field'));
00165         $selected[]   = $field;
00166         $selected_cnt = 1;
00167     } else { // from a multiple submit
00168         $selected_cnt = count($selected);
00169     }
00170 
00171     // TODO: optimize in case of multiple fields to modify
00172     for ($i = 0; $i < $selected_cnt; $i++) {
00173         if (!empty($submit_mult)) {
00174             $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE);
00175         } else {
00176             $field = PMA_sqlAddslashes($selected[$i], TRUE);
00177         }
00178         $local_query   = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . " LIKE '$field'";
00179         $result        = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
00180         $fields_meta[] = PMA_mysql_fetch_array($result);
00181         mysql_free_result($result);
00182     }
00183 
00184     $num_fields  = count($fields_meta);
00185     $action      = 'tbl_alter.php';
00186     require('./tbl_properties.inc.php');
00187 }
00188 
00189 
00193 require_once('./footer.inc.php');
00194 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6