js checks for user_password
[phpmyadmin/crack.git] / tbl_create.php3
blob95720923141b9eee070250bab6f6e657e271f404
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];
63 if ($field_default[$i] != '') {
64 if (strtoupper($field_default[$i]) == 'NULL') {
65 $query .= ' DEFAULT NULL';
66 } else {
67 $query .= ' DEFAULT \'' . PMA_sqlAddslashes($field_default[$i]) . '\'';
70 if ($field_null[$i] != '') {
71 $query .= ' ' . $field_null[$i];
73 if ($field_extra[$i] != '') {
74 $query .= ' ' . $field_extra[$i];
76 $query .= ', ';
77 $sql_query .= $query;
78 $query_cpy .= "\n" . ' ' . $query;
79 } // end for
80 unset($field_cnt);
81 unset($query);
82 $sql_query = ereg_replace(', $', '', $sql_query);
83 $query_cpy = ereg_replace(', $', '', $query_cpy);
85 // Builds the primary keys statements
86 $primary = '';
87 $primary_cnt = (isset($field_primary) ? count($field_primary) : 0);
88 for ($i = 0; $i < $primary_cnt; $i++) {
89 $j = $field_primary[$i];
90 if (!empty($field_name[$j])) {
91 $primary .= PMA_backquote($field_name[$j]) . ', ';
93 } // end for
94 unset($primary_cnt);
95 $primary = ereg_replace(', $', '', $primary);
96 if (!empty($primary)) {
97 $sql_query .= ', PRIMARY KEY (' . $primary . ')';
98 $query_cpy .= ',' . "\n" . ' PRIMARY KEY (' . $primary . ')';
100 unset($primary);
102 // Builds the indexes statements
103 $index = '';
104 $index_cnt = (isset($field_index) ? count($field_index) : 0);
105 for ($i = 0;$i < $index_cnt; $i++) {
106 $j = $field_index[$i];
107 if (!empty($field_name[$j])) {
108 $index .= PMA_backquote($field_name[$j]) . ', ';
110 } // end for
111 unset($index_cnt);
112 $index = ereg_replace(', $', '', $index);
113 if (!empty($index)) {
114 $sql_query .= ', INDEX (' . $index . ')';
115 $query_cpy .= ',' . "\n" . ' INDEX (' . $index . ')';
117 unset($index);
119 // Builds the uniques statements
120 $unique = '';
121 $unique_cnt = (isset($field_unique) ? count($field_unique) : 0);
122 for ($i = 0; $i < $unique_cnt; $i++) {
123 $j = $field_unique[$i];
124 if (!empty($field_name[$j])) {
125 $unique .= PMA_backquote($field_name[$j]) . ', ';
127 } // end for
128 unset($unique_cnt);
129 $unique = ereg_replace(', $', '', $unique);
130 if (!empty($unique)) {
131 $sql_query .= ', UNIQUE (' . $unique . ')';
132 $query_cpy .= ',' . "\n" . ' UNIQUE (' . $unique . ')';
134 unset($unique);
136 // Builds the fulltextes statements
137 $fulltext = '';
138 $fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0);
139 for ($i = 0; $i < $fulltext_cnt; $i++) {
140 $j = $field_fulltext[$i];
141 if (!empty($field_name[$j])) {
142 $fulltext .= PMA_backquote($field_name[$j]) . ', ';
144 } // end for
146 $fulltext = ereg_replace(', $', '', $fulltext);
147 if (!empty($fulltext)) {
148 $sql_query .= ', FULLTEXT (' . $fulltext . ')';
149 $query_cpy .= ',' . "\n" . ' FULLTEXT (' . $fulltext . ')';
151 unset($fulltext);
153 // Builds the 'create table' statement
154 $sql_query = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $sql_query . ')';
155 $query_cpy = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $query_cpy . "\n" . ')';
157 // Adds table type and comments (2 May 2001 - Robbat2)
158 if (!empty($tbl_type) && ($tbl_type != 'Default')) {
159 $sql_query .= ' TYPE = ' . $tbl_type;
160 $query_cpy .= ' TYPE = ' . $tbl_type;
162 if (PMA_MYSQL_INT_VERSION >= 32300 && !empty($comment)) {
163 $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
164 $query_cpy .= "\n" . 'COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
167 // Executes the query
168 $error_create = false;
169 $result = PMA_mysql_query($sql_query) or $error_create = true;
171 if ($error_create == false) {
172 $sql_query = $query_cpy . ';';
173 unset($query_cpy);
174 $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
176 // garvin: If comments were sent, enable relation stuff
177 require('./libraries/relation.lib.php3');
178 require('./libraries/transformations.lib.php3');
180 $cfgRelation = PMA_getRelationsParam();
182 // garvin: Update comment table, if a comment was set.
183 if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
184 @reset($field_comments);
185 while(list($fieldindex, $fieldcomment) = each($field_comments)) {
186 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment);
190 // garvin: Update comment table for mime types [MIME]
191 if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
192 @reset($field_mimetype);
193 while(list($fieldindex, $mimetype) = each($field_mimetype)) {
194 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
198 include('./' . $cfg['DefaultTabTable']);
199 $abort = TRUE;
200 exit();
201 } else {
202 PMA_mysqlDie('', '', '', $err_url, FALSE);
203 // garvin: An error happened while inserting/updating a table definition.
204 // to prevent total loss of that data, we embed the form once again.
205 // The variable $regenerate will be used to restore data in tbl_properties.inc.php3
206 $num_fields = $orig_num_fields;
207 $regenerate = true;
209 } // end do create table
212 * Displays the form used to define the structure of the table
214 if ($abort == FALSE) {
215 if (isset($num_fields)) {
216 $num_fields = intval($num_fields);
218 // No table name
219 if (!isset($table) || trim($table) == '') {
220 PMA_mysqlDie($strTableEmpty, '', '', $err_url);
222 // No valid number of fields
223 else if (empty($num_fields) || !is_int($num_fields)) {
224 PMA_mysqlDie($strFieldsEmpty, '', '', $err_url);
226 // Table name and number of fields are valid -> show the form
227 else {
228 if (PMA_MYSQL_INT_VERSION < 32306) {
229 PMA_checkReservedWords($table, $err_url);
232 $action = 'tbl_create.php3';
233 include('./tbl_properties.inc.php3');
234 // Diplays the footer
235 echo "\n";
236 include('./footer.inc.php3');