3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Get some core libraries
9 require('./libraries/grab_globals.lib.php3');
10 $js_to_run = 'functions.js';
11 require('./header.inc.php3');
15 if (!defined('PMA_COMMON_LIB_INCLUDED')) {
16 include('./libraries/common.lib.php3');
19 PMA_checkParameters(array('db', 'table'));
22 * Defines the url to return to in case of error in a sql statement
24 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
28 * Selects the database to work with
30 PMA_mysql_select_db($db);
34 * The form used to define the structure of the table has been submitted
38 $sql_query = $query_cpy = '';
40 // Transforms the radio button field_key into 3 arrays
41 $field_cnt = count($field_name);
42 for ($i = 0; $i < $field_cnt; ++
$i) {
43 if (isset($
{'field_key_' . $i})) {
44 if ($
{'field_key_' . $i} == 'primary_' . $i) {
45 $field_primary[] = $i;
47 if ($
{'field_key_' . $i} == 'index_' . $i) {
50 if ($
{'field_key_' . $i} == 'unique_' . $i) {
55 // Builds the fields creation statements
56 for ($i = 0; $i < $field_cnt; $i++
) {
57 if (empty($field_name[$i])) {
60 if (PMA_MYSQL_INT_VERSION
< 32306) {
61 PMA_checkReservedWords($field_name[$i], $err_url);
63 $query = PMA_backquote($field_name[$i]) . ' ' . $field_type[$i];
64 if ($field_length[$i] != '') {
65 $query .= '(' . $field_length[$i] . ')';
67 if ($field_attribute[$i] != '') {
68 $query .= ' ' . $field_attribute[$i];
69 } else if (PMA_MYSQL_INT_VERSION
>= 40100 && !empty($field_charset[$i])) {
70 $query .= ' CHARACTER SET ' . $field_charset[$i];
72 if ($field_default[$i] != '') {
73 if (strtoupper($field_default[$i]) == 'NULL') {
74 $query .= ' DEFAULT NULL';
76 $query .= ' DEFAULT \'' . PMA_sqlAddslashes($field_default[$i]) . '\'';
79 if ($field_null[$i] != '') {
80 $query .= ' ' . $field_null[$i];
82 if ($field_extra[$i] != '') {
83 $query .= ' ' . $field_extra[$i];
87 $query_cpy .= "\n" . ' ' . $query;
91 $sql_query = ereg_replace(', $', '', $sql_query);
92 $query_cpy = ereg_replace(', $', '', $query_cpy);
94 // Builds the primary keys statements
96 $primary_cnt = (isset($field_primary) ?
count($field_primary) : 0);
97 for ($i = 0; $i < $primary_cnt; $i++
) {
98 $j = $field_primary[$i];
99 if (!empty($field_name[$j])) {
100 $primary .= PMA_backquote($field_name[$j]) . ', ';
104 $primary = ereg_replace(', $', '', $primary);
105 if (!empty($primary)) {
106 $sql_query .= ', PRIMARY KEY (' . $primary . ')';
107 $query_cpy .= ',' . "\n" . ' PRIMARY KEY (' . $primary . ')';
111 // Builds the indexes statements
113 $index_cnt = (isset($field_index) ?
count($field_index) : 0);
114 for ($i = 0;$i < $index_cnt; $i++
) {
115 $j = $field_index[$i];
116 if (!empty($field_name[$j])) {
117 $index .= PMA_backquote($field_name[$j]) . ', ';
121 $index = ereg_replace(', $', '', $index);
122 if (!empty($index)) {
123 $sql_query .= ', INDEX (' . $index . ')';
124 $query_cpy .= ',' . "\n" . ' INDEX (' . $index . ')';
128 // Builds the uniques statements
130 $unique_cnt = (isset($field_unique) ?
count($field_unique) : 0);
131 for ($i = 0; $i < $unique_cnt; $i++
) {
132 $j = $field_unique[$i];
133 if (!empty($field_name[$j])) {
134 $unique .= PMA_backquote($field_name[$j]) . ', ';
138 $unique = ereg_replace(', $', '', $unique);
139 if (!empty($unique)) {
140 $sql_query .= ', UNIQUE (' . $unique . ')';
141 $query_cpy .= ',' . "\n" . ' UNIQUE (' . $unique . ')';
145 // Builds the fulltextes statements
147 $fulltext_cnt = (isset($field_fulltext) ?
count($field_fulltext) : 0);
148 for ($i = 0; $i < $fulltext_cnt; $i++
) {
149 $j = $field_fulltext[$i];
150 if (!empty($field_name[$j])) {
151 $fulltext .= PMA_backquote($field_name[$j]) . ', ';
155 $fulltext = ereg_replace(', $', '', $fulltext);
156 if (!empty($fulltext)) {
157 $sql_query .= ', FULLTEXT (' . $fulltext . ')';
158 $query_cpy .= ',' . "\n" . ' FULLTEXT (' . $fulltext . ')';
162 // Builds the 'create table' statement
163 $sql_query = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $sql_query . ')';
164 $query_cpy = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $query_cpy . "\n" . ')';
166 // Adds table type, character set and comments
167 if (!empty($tbl_type) && ($tbl_type != 'Default')) {
168 $sql_query .= ' TYPE = ' . $tbl_type;
169 $query_cpy .= "\n" . 'TYPE = ' . $tbl_type;
171 if (PMA_MYSQL_INT_VERSION
>= 40100 && !empty($tbl_charset)) {
172 $sql_query .= ' CHARACTER SET = ' . $tbl_charset;
173 $query_cpy .= "\n" . 'CHARACTER SET = ' . $tbl_charset;
175 if (PMA_MYSQL_INT_VERSION
>= 32300 && !empty($comment)) {
176 $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
177 $query_cpy .= "\n" . 'COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
180 // Executes the query
181 $error_create = false;
182 $result = PMA_mysql_query($sql_query) or $error_create = true;
184 if ($error_create == false) {
185 $sql_query = $query_cpy . ';';
187 $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
189 // garvin: If comments were sent, enable relation stuff
190 require('./libraries/relation.lib.php3');
191 require('./libraries/transformations.lib.php3');
193 $cfgRelation = PMA_getRelationsParam();
195 // garvin: Update comment table, if a comment was set.
196 if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
197 @reset
($field_comments);
198 while(list($fieldindex, $fieldcomment) = each($field_comments)) {
199 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment);
203 // garvin: Update comment table for mime types [MIME]
204 if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
205 @reset
($field_mimetype);
206 while(list($fieldindex, $mimetype) = each($field_mimetype)) {
207 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
211 include('./' . $cfg['DefaultTabTable']);
215 PMA_mysqlDie('', '', '', $err_url, FALSE);
216 // garvin: An error happened while inserting/updating a table definition.
217 // to prevent total loss of that data, we embed the form once again.
218 // The variable $regenerate will be used to restore data in tbl_properties.inc.php3
219 $num_fields = $orig_num_fields;
222 } // end do create table
225 * Displays the form used to define the structure of the table
227 if ($abort == FALSE) {
228 if (isset($num_fields)) {
229 $num_fields = intval($num_fields);
232 if (!isset($table) ||
trim($table) == '') {
233 PMA_mysqlDie($strTableEmpty, '', '', $err_url);
235 // No valid number of fields
236 else if (empty($num_fields) ||
!is_int($num_fields)) {
237 PMA_mysqlDie($strFieldsEmpty, '', '', $err_url);
239 // Table name and number of fields are valid -> show the form
241 if (PMA_MYSQL_INT_VERSION
< 32306) {
242 PMA_checkReservedWords($table, $err_url);
245 $action = 'tbl_create.php3';
246 include('./tbl_properties.inc.php3');
247 // Diplays the footer
249 include('./footer.inc.php3');