Documentation TYPO3 par Ameos

tbl_create.php

00001 <?php
00002 /* $Id: tbl_create.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 
00015 require_once('./libraries/common.lib.php');
00016 
00017 PMA_checkParameters(array('db', 'table'));
00018 
00022 $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
00023 
00024 
00028 PMA_mysql_select_db($db);
00029 
00030 
00034 $abort = false;
00035 if (isset($submit)) {
00036     $sql_query = $query_cpy = '';
00037 
00038     // Transforms the radio button field_key into 3 arrays
00039     $field_cnt = count($field_name);
00040     for ($i = 0; $i < $field_cnt; ++$i) {
00041         if (isset(${'field_key_' . $i})) {
00042             if (${'field_key_' . $i} == 'primary_' . $i) {
00043                 $field_primary[] = $i;
00044             }
00045             if (${'field_key_' . $i} == 'index_' . $i) {
00046                 $field_index[]   = $i;
00047             }
00048             if (${'field_key_' . $i} == 'unique_' . $i) {
00049                 $field_unique[]  = $i;
00050             }
00051         } // end if
00052     } // end for
00053     // Builds the fields creation statements
00054     for ($i = 0; $i < $field_cnt; $i++) {
00055         if (empty($field_name[$i])) {
00056             continue;
00057         }
00058         $query = PMA_backquote($field_name[$i]) . ' ' . $field_type[$i];
00059         if ($field_length[$i] != '') {
00060             $query .= '(' . $field_length[$i] . ')';
00061         }
00062         if ($field_attribute[$i] != '') {
00063             $query .= ' ' . $field_attribute[$i];
00064         } else if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($field_charset[$i])) {
00065             $query .= ' CHARACTER SET ' . $field_charset[$i];
00066         }
00067         if ($field_default[$i] != '') {
00068             if (strtoupper($field_default[$i]) == 'NULL') {
00069                 $query .= ' DEFAULT NULL';
00070             } else {
00071                 $query .= ' DEFAULT \'' . PMA_sqlAddslashes($field_default[$i]) . '\'';
00072             }
00073         }
00074         if ($field_null[$i] != '') {
00075             $query .= ' ' . $field_null[$i];
00076         }
00077         if ($field_extra[$i] != '') {
00078             $query .= ' ' . $field_extra[$i];
00079         }
00080         $query .= ', ';
00081         $sql_query .= $query;
00082         $query_cpy .= "\n" . '  ' . $query;
00083     } // end for
00084     unset($field_cnt);
00085     unset($query);
00086     $sql_query = preg_replace('@, $@', '', $sql_query);
00087     $query_cpy = preg_replace('@, $@', '', $query_cpy);
00088 
00089     // Builds the primary keys statements
00090     $primary     = '';
00091     $primary_cnt = (isset($field_primary) ? count($field_primary) : 0);
00092     for ($i = 0; $i < $primary_cnt; $i++) {
00093         $j = $field_primary[$i];
00094         if (!empty($field_name[$j])) {
00095             $primary .= PMA_backquote($field_name[$j]) . ', ';
00096         }
00097     } // end for
00098     unset($primary_cnt);
00099     $primary = preg_replace('@, $@', '', $primary);
00100     if (!empty($primary)) {
00101         $sql_query .= ', PRIMARY KEY (' . $primary . ')';
00102         $query_cpy .= ',' . "\n" . '  PRIMARY KEY (' . $primary . ')';
00103     }
00104     unset($primary);
00105 
00106     // Builds the indexes statements
00107     $index     = '';
00108     $index_cnt = (isset($field_index) ? count($field_index) : 0);
00109     for ($i = 0;$i < $index_cnt; $i++) {
00110         $j = $field_index[$i];
00111         if (!empty($field_name[$j])) {
00112             $index .= PMA_backquote($field_name[$j]) . ', ';
00113         }
00114     } // end for
00115     unset($index_cnt);
00116     $index = preg_replace('@, $@', '', $index);
00117     if (!empty($index)) {
00118         $sql_query .= ', INDEX (' . $index . ')';
00119         $query_cpy .= ',' . "\n" . '  INDEX (' . $index . ')';
00120     }
00121     unset($index);
00122 
00123     // Builds the uniques statements
00124     $unique     = '';
00125     $unique_cnt = (isset($field_unique) ? count($field_unique) : 0);
00126     for ($i = 0; $i < $unique_cnt; $i++) {
00127         $j = $field_unique[$i];
00128         if (!empty($field_name[$j])) {
00129            $unique .= PMA_backquote($field_name[$j]) . ', ';
00130         }
00131     } // end for
00132     unset($unique_cnt);
00133     $unique = preg_replace('@, $@', '', $unique);
00134     if (!empty($unique)) {
00135         $sql_query .= ', UNIQUE (' . $unique . ')';
00136         $query_cpy .= ',' . "\n" . '  UNIQUE (' . $unique . ')';
00137     }
00138     unset($unique);
00139 
00140     // Builds the fulltextes statements
00141     $fulltext     = '';
00142     $fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0);
00143     for ($i = 0; $i < $fulltext_cnt; $i++) {
00144         $j = $field_fulltext[$i];
00145         if (!empty($field_name[$j])) {
00146            $fulltext .= PMA_backquote($field_name[$j]) . ', ';
00147         }
00148     } // end for
00149 
00150     $fulltext = preg_replace('@, $@', '', $fulltext);
00151     if (!empty($fulltext)) {
00152         $sql_query .= ', FULLTEXT (' . $fulltext . ')';
00153         $query_cpy .= ',' . "\n" . '  FULLTEXT (' . $fulltext . ')';
00154     }
00155     unset($fulltext);
00156 
00157     // Builds the 'create table' statement
00158     $sql_query      = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $sql_query . ')';
00159     $query_cpy      = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $query_cpy . "\n" . ')';
00160 
00161     // Adds table type, character set and comments
00162     if (!empty($tbl_type) && ($tbl_type != 'Default')) {
00163         $sql_query .= ' TYPE = ' . $tbl_type;
00164         $query_cpy .= "\n" . 'TYPE = ' . $tbl_type;
00165     }
00166     if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_charset)) {
00167         $sql_query .= ' CHARACTER SET = ' . $tbl_charset;
00168         $query_cpy .= "\n" . 'CHARACTER SET = ' . $tbl_charset;
00169     }
00170 
00171     if (!empty($comment)) {
00172         $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
00173         $query_cpy .= "\n" . 'COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
00174     }
00175 
00176     // Executes the query
00177     $error_create = false;
00178     $result    = PMA_mysql_query($sql_query) or $error_create = true;
00179 
00180     if ($error_create == false) {
00181         $sql_query = $query_cpy . ';';
00182         unset($query_cpy);
00183         $message   = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
00184 
00185         // garvin: If comments were sent, enable relation stuff
00186         require_once('./libraries/relation.lib.php');
00187         require_once('./libraries/transformations.lib.php');
00188 
00189         $cfgRelation = PMA_getRelationsParam();
00190 
00191         // garvin: Update comment table, if a comment was set.
00192         if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
00193             foreach($field_comments AS $fieldindex => $fieldcomment) {
00194                 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment);
00195             }
00196         }
00197 
00198         // garvin: Update comment table for mime types [MIME]
00199         if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
00200             foreach($field_mimetype AS $fieldindex => $mimetype) {
00201                 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
00202             }
00203         }
00204 
00205         require('./' . $cfg['DefaultTabTable']);
00206         $abort = TRUE;
00207         exit();
00208     } else {
00209         PMA_mysqlDie('', '', '', $err_url, FALSE);
00210         // garvin: An error happened while inserting/updating a table definition.
00211         // to prevent total loss of that data, we embed the form once again.
00212         // The variable $regenerate will be used to restore data in tbl_properties.inc.php
00213         $num_fields = $orig_num_fields;
00214         $regenerate = true;
00215     }
00216 } // end do create table
00217 
00221 if ($abort == FALSE) {
00222     if (isset($num_fields)) {
00223         $num_fields = intval($num_fields);
00224     }
00225     // No table name
00226     if (!isset($table) || trim($table) == '') {
00227         PMA_mysqlDie($strTableEmpty, '', '', $err_url);
00228     }
00229     // No valid number of fields
00230     else if (empty($num_fields) || !is_int($num_fields)) {
00231         PMA_mysqlDie($strFieldsEmpty, '', '', $err_url);
00232     }
00233     // Table name and number of fields are valid -> show the form
00234     else {
00235         $action = 'tbl_create.php';
00236         require('./tbl_properties.inc.php');
00237         // Diplays the footer
00238         echo "\n";
00239         require_once('./footer.inc.php');
00240    }
00241 }
00242 
00243 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6