update
[phpmyadmin/crack.git] / tbl_create.php3
blob202ca5d97df7f16592afb794734d101eca69fa31
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Get some core libraries
8 */
9 require('./libraries/grab_globals.lib.php3');
10 $js_to_run = 'functions.js';
11 require('./header.inc.php3');
14 /**
15 * Defines the url to return to in case of error in a sql statement
17 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
20 /**
21 * Selects the database to work with
23 PMA_mysql_select_db($db);
26 /**
27 * The form used to define the structure of the table has been submitted
29 $abort = false;
30 if (isset($submit)) {
31 $sql_query = $query_cpy = '';
33 // Transforms the radio button field_key into 3 arrays
34 $field_cnt = count($field_name);
35 for ($i = 0; $i < $field_cnt; ++$i) {
36 if (isset(${'field_key_' . $i})) {
37 if (${'field_key_' . $i} == 'primary_' . $i) {
38 $field_primary[] = $i;
40 if (${'field_key_' . $i} == 'index_' . $i) {
41 $field_index[] = $i;
43 if (${'field_key_' . $i} == 'unique_' . $i) {
44 $field_unique[] = $i;
46 } // end if
47 } // end for
48 // Builds the fields creation statements
49 for ($i = 0; $i < $field_cnt; $i++) {
50 if (empty($field_name[$i])) {
51 continue;
53 if (PMA_MYSQL_INT_VERSION < 32306) {
54 PMA_checkReservedWords($field_name[$i], $err_url);
56 $query = PMA_backquote($field_name[$i]) . ' ' . $field_type[$i];
57 if ($field_length[$i] != '') {
58 $query .= '(' . $field_length[$i] . ')';
60 if ($field_attribute[$i] != '') {
61 $query .= ' ' . $field_attribute[$i];
62 } else if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($field_charset[$i])) {
63 $query .= ' CHARACTER SET ' . $field_charset[$i];
65 if ($field_default[$i] != '') {
66 if (strtoupper($field_default[$i]) == 'NULL') {
67 $query .= ' DEFAULT NULL';
68 } else {
69 $query .= ' DEFAULT \'' . PMA_sqlAddslashes($field_default[$i]) . '\'';
72 if ($field_null[$i] != '') {
73 $query .= ' ' . $field_null[$i];
75 if ($field_extra[$i] != '') {
76 $query .= ' ' . $field_extra[$i];
78 $query .= ', ';
79 $sql_query .= $query;
80 $query_cpy .= "\n" . ' ' . $query;
81 } // end for
82 unset($field_cnt);
83 unset($query);
84 $sql_query = ereg_replace(', $', '', $sql_query);
85 $query_cpy = ereg_replace(', $', '', $query_cpy);
87 // Builds the primary keys statements
88 $primary = '';
89 $primary_cnt = (isset($field_primary) ? count($field_primary) : 0);
90 for ($i = 0; $i < $primary_cnt; $i++) {
91 $j = $field_primary[$i];
92 if (!empty($field_name[$j])) {
93 $primary .= PMA_backquote($field_name[$j]) . ', ';
95 } // end for
96 unset($primary_cnt);
97 $primary = ereg_replace(', $', '', $primary);
98 if (!empty($primary)) {
99 $sql_query .= ', PRIMARY KEY (' . $primary . ')';
100 $query_cpy .= ',' . "\n" . ' PRIMARY KEY (' . $primary . ')';
102 unset($primary);
104 // Builds the indexes statements
105 $index = '';
106 $index_cnt = (isset($field_index) ? count($field_index) : 0);
107 for ($i = 0;$i < $index_cnt; $i++) {
108 $j = $field_index[$i];
109 if (!empty($field_name[$j])) {
110 $index .= PMA_backquote($field_name[$j]) . ', ';
112 } // end for
113 unset($index_cnt);
114 $index = ereg_replace(', $', '', $index);
115 if (!empty($index)) {
116 $sql_query .= ', INDEX (' . $index . ')';
117 $query_cpy .= ',' . "\n" . ' INDEX (' . $index . ')';
119 unset($index);
121 // Builds the uniques statements
122 $unique = '';
123 $unique_cnt = (isset($field_unique) ? count($field_unique) : 0);
124 for ($i = 0; $i < $unique_cnt; $i++) {
125 $j = $field_unique[$i];
126 if (!empty($field_name[$j])) {
127 $unique .= PMA_backquote($field_name[$j]) . ', ';
129 } // end for
130 unset($unique_cnt);
131 $unique = ereg_replace(', $', '', $unique);
132 if (!empty($unique)) {
133 $sql_query .= ', UNIQUE (' . $unique . ')';
134 $query_cpy .= ',' . "\n" . ' UNIQUE (' . $unique . ')';
136 unset($unique);
138 // Builds the fulltextes statements
139 $fulltext = '';
140 $fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0);
141 for ($i = 0; $i < $fulltext_cnt; $i++) {
142 $j = $field_fulltext[$i];
143 if (!empty($field_name[$j])) {
144 $fulltext .= PMA_backquote($field_name[$j]) . ', ';
146 } // end for
148 $fulltext = ereg_replace(', $', '', $fulltext);
149 if (!empty($fulltext)) {
150 $sql_query .= ', FULLTEXT (' . $fulltext . ')';
151 $query_cpy .= ',' . "\n" . ' FULLTEXT (' . $fulltext . ')';
153 unset($fulltext);
155 // Builds the 'create table' statement
156 $sql_query = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $sql_query . ')';
157 $query_cpy = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $query_cpy . "\n" . ')';
159 // Adds table type, character set and comments
160 if (!empty($tbl_type) && ($tbl_type != 'Default')) {
161 $sql_query .= ' TYPE = ' . $tbl_type;
162 $query_cpy .= "\n" . 'TYPE = ' . $tbl_type;
164 if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_charset)) {
165 $sql_query .= ' CHARACTER SET = ' . $tbl_charset;
166 $query_cpy .= "\n" . 'CHARACTER SET = ' . $tbl_charset;
168 if (PMA_MYSQL_INT_VERSION >= 32300 && !empty($comment)) {
169 $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
170 $query_cpy .= "\n" . 'COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
173 // Executes the query
174 $error_create = false;
175 $result = PMA_mysql_query($sql_query) or $error_create = true;
177 if ($error_create == false) {
178 $sql_query = $query_cpy . ';';
179 unset($query_cpy);
180 $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
182 // garvin: If comments were sent, enable relation stuff
183 require('./libraries/relation.lib.php3');
184 require('./libraries/transformations.lib.php3');
186 $cfgRelation = PMA_getRelationsParam();
188 // garvin: Update comment table, if a comment was set.
189 if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
190 @reset($field_comments);
191 while(list($fieldindex, $fieldcomment) = each($field_comments)) {
192 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment);
196 // garvin: Update comment table for mime types [MIME]
197 if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
198 @reset($field_mimetype);
199 while(list($fieldindex, $mimetype) = each($field_mimetype)) {
200 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
204 include('./' . $cfg['DefaultTabTable']);
205 $abort = TRUE;
206 exit();
207 } else {
208 PMA_mysqlDie('', '', '', $err_url, FALSE);
209 // garvin: An error happened while inserting/updating a table definition.
210 // to prevent total loss of that data, we embed the form once again.
211 // The variable $regenerate will be used to restore data in tbl_properties.inc.php3
212 $num_fields = $orig_num_fields;
213 $regenerate = true;
215 } // end do create table
218 * Displays the form used to define the structure of the table
220 if ($abort == FALSE) {
221 if (isset($num_fields)) {
222 $num_fields = intval($num_fields);
224 // No table name
225 if (!isset($table) || trim($table) == '') {
226 PMA_mysqlDie($strTableEmpty, '', '', $err_url);
228 // No valid number of fields
229 else if (empty($num_fields) || !is_int($num_fields)) {
230 PMA_mysqlDie($strFieldsEmpty, '', '', $err_url);
232 // Table name and number of fields are valid -> show the form
233 else {
234 if (PMA_MYSQL_INT_VERSION < 32306) {
235 PMA_checkReservedWords($table, $err_url);
238 $action = 'tbl_create.php3';
239 include('./tbl_properties.inc.php3');
240 // Diplays the footer
241 echo "\n";
242 include('./footer.inc.php3');