PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/ASTRA_Demo_Server/udrive/home/admin/www/phpMyAdmin/tbl_create.php

https://github.com/shafiqissani/ASTRA-College-Website
PHP | 248 lines | 177 code | 31 blank | 40 comment | 62 complexity | 0042abaf493cd7071fb20192030848c5 MD5 | raw file
  1. <?php
  2. /* $Id: tbl_create.php 10144 2007-03-20 11:22:31Z cybot_tm $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. /**
  5. * Get some core libraries
  6. */
  7. require_once './libraries/common.lib.php';
  8. require_once './libraries/Table.class.php';
  9. $js_to_run = 'functions.js';
  10. if (isset($table)) {
  11. $table = PMA_sanitize($table);
  12. }
  13. require_once './libraries/header.inc.php';
  14. // Check parameters
  15. PMA_checkParameters(array('db', 'table'));
  16. /**
  17. * Defines the url to return to in case of error in a sql statement
  18. */
  19. $err_url = $cfg['DefaultTabTable'] . '?' . PMA_generate_common_url($db, $table);
  20. /**
  21. * Selects the database to work with
  22. */
  23. PMA_DBI_select_db($db);
  24. /**
  25. * The form used to define the structure of the table has been submitted
  26. */
  27. $abort = false;
  28. if (isset($submit_num_fields)) {
  29. $regenerate = true;
  30. $num_fields = $orig_num_fields + $added_fields;
  31. } elseif (isset($do_save_data)) {
  32. $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;
  39. }
  40. if (${'field_key_' . $i} == 'index_' . $i) {
  41. $field_index[] = $i;
  42. }
  43. if (${'field_key_' . $i} == 'unique_' . $i) {
  44. $field_unique[] = $i;
  45. }
  46. } // end if
  47. } // end for
  48. // Builds the fields creation statements
  49. for ($i = 0; $i < $field_cnt; $i++) {
  50. // '0' is also empty for php :-(
  51. if (empty($field_name[$i]) && $field_name[$i] != '0') {
  52. continue;
  53. }
  54. $query = PMA_Table::generateFieldSpec($field_name[$i], $field_type[$i], $field_length[$i], $field_attribute[$i], isset($field_collation[$i]) ? $field_collation[$i] : '', $field_null[$i], $field_default[$i], isset($field_default_current_timestamp[$i]), $field_extra[$i], isset($field_comments[$i]) ? $field_comments[$i] : '', $field_primary, $i);
  55. $query .= ', ';
  56. $sql_query .= $query;
  57. $query_cpy .= "\n" . ' ' . $query;
  58. } // end for
  59. unset($field_cnt);
  60. unset($query);
  61. $sql_query = preg_replace('@, $@', '', $sql_query);
  62. $query_cpy = preg_replace('@, $@', '', $query_cpy);
  63. // Builds the primary keys statements
  64. $primary = '';
  65. $primary_cnt = (isset($field_primary) ? count($field_primary) : 0);
  66. for ($i = 0; $i < $primary_cnt; $i++) {
  67. $j = $field_primary[$i];
  68. if (isset($field_name[$j]) && strlen($field_name[$j])) {
  69. $primary .= PMA_backquote($field_name[$j]) . ', ';
  70. }
  71. } // end for
  72. unset($primary_cnt);
  73. $primary = preg_replace('@, $@', '', $primary);
  74. if (strlen($primary)) {
  75. $sql_query .= ', PRIMARY KEY (' . $primary . ')';
  76. $query_cpy .= ',' . "\n" . ' PRIMARY KEY (' . $primary . ')';
  77. }
  78. unset($primary);
  79. // Builds the indexes statements
  80. $index = '';
  81. $index_cnt = (isset($field_index) ? count($field_index) : 0);
  82. for ($i = 0;$i < $index_cnt; $i++) {
  83. $j = $field_index[$i];
  84. if (isset($field_name[$j]) && strlen($field_name[$j])) {
  85. $index .= PMA_backquote($field_name[$j]) . ', ';
  86. }
  87. } // end for
  88. unset($index_cnt);
  89. $index = preg_replace('@, $@', '', $index);
  90. if (strlen($index)) {
  91. $sql_query .= ', INDEX (' . $index . ')';
  92. $query_cpy .= ',' . "\n" . ' INDEX (' . $index . ')';
  93. }
  94. unset($index);
  95. // Builds the uniques statements
  96. $unique = '';
  97. $unique_cnt = (isset($field_unique) ? count($field_unique) : 0);
  98. for ($i = 0; $i < $unique_cnt; $i++) {
  99. $j = $field_unique[$i];
  100. if (isset($field_name[$j]) && strlen($field_name[$j])) {
  101. $unique .= PMA_backquote($field_name[$j]) . ', ';
  102. }
  103. } // end for
  104. unset($unique_cnt);
  105. $unique = preg_replace('@, $@', '', $unique);
  106. if (strlen($unique)) {
  107. $sql_query .= ', UNIQUE (' . $unique . ')';
  108. $query_cpy .= ',' . "\n" . ' UNIQUE (' . $unique . ')';
  109. }
  110. unset($unique);
  111. // Builds the FULLTEXT statements
  112. $fulltext = '';
  113. $fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0);
  114. for ($i = 0; $i < $fulltext_cnt; $i++) {
  115. $j = $field_fulltext[$i];
  116. if (isset($field_name[$j]) && strlen($field_name[$j])) {
  117. $fulltext .= PMA_backquote($field_name[$j]) . ', ';
  118. }
  119. } // end for
  120. $fulltext = preg_replace('@, $@', '', $fulltext);
  121. if (strlen($fulltext)) {
  122. $sql_query .= ', FULLTEXT (' . $fulltext . ')';
  123. $query_cpy .= ',' . "\n" . ' FULLTEXT (' . $fulltext . ')';
  124. }
  125. unset($fulltext);
  126. // Builds the 'create table' statement
  127. $sql_query = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $sql_query . ')';
  128. $query_cpy = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $query_cpy . "\n" . ')';
  129. // Adds table type, character set and comments
  130. if (!empty($tbl_type) && ($tbl_type != 'Default')) {
  131. $sql_query .= ' ' . PMA_ENGINE_KEYWORD . ' = ' . $tbl_type;
  132. $query_cpy .= "\n" . PMA_ENGINE_KEYWORD . ' = ' . $tbl_type;
  133. }
  134. if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_collation)) {
  135. $sql_query .= PMA_generateCharsetQueryPart($tbl_collation);
  136. $query_cpy .= "\n" . PMA_generateCharsetQueryPart($tbl_collation);
  137. }
  138. if (!empty($comment)) {
  139. $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
  140. $query_cpy .= "\n" . 'COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
  141. }
  142. // Executes the query
  143. $error_create = false;
  144. $result = PMA_DBI_try_query($sql_query) or $error_create = true;
  145. if ($error_create == false) {
  146. $sql_query = $query_cpy . ';';
  147. unset($query_cpy);
  148. $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
  149. // garvin: If comments were sent, enable relation stuff
  150. require_once './libraries/relation.lib.php';
  151. require_once './libraries/transformations.lib.php';
  152. $cfgRelation = PMA_getRelationsParam();
  153. // garvin: Update comment table, if a comment was set.
  154. if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork'] && PMA_MYSQL_INT_VERSION < 40100) {
  155. foreach ($field_comments AS $fieldindex => $fieldcomment) {
  156. if (isset($field_name[$fieldindex]) && strlen($field_name[$fieldindex])) {
  157. PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, '', 'pmadb');
  158. }
  159. }
  160. }
  161. // garvin: Update comment table for mime types [MIME]
  162. if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
  163. foreach ($field_mimetype AS $fieldindex => $mimetype) {
  164. if (isset($field_name[$fieldindex]) && strlen($field_name[$fieldindex])) {
  165. PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
  166. }
  167. }
  168. }
  169. $message = $strTable . ' '
  170. . htmlspecialchars(PMA_backquote($db) . '.' . PMA_backquote($table))
  171. . ' ' . $strHasBeenCreated;
  172. $display_query = $sql_query;
  173. unset($sql_query);
  174. // do not switch to sql.php - as there is no row to be displayed on a new table
  175. if ($cfg['DefaultTabTable'] === 'sql.php') {
  176. require './tbl_structure.php';
  177. } else {
  178. require './' . $cfg['DefaultTabTable'];
  179. }
  180. exit;
  181. } else {
  182. PMA_mysqlDie('', '', '', $err_url, false);
  183. // garvin: An error happened while inserting/updating a table definition.
  184. // to prevent total loss of that data, we embed the form once again.
  185. // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php
  186. $num_fields = $orig_num_fields;
  187. $regenerate = true;
  188. }
  189. } // end do create table
  190. /**
  191. * Displays the form used to define the structure of the table
  192. */
  193. if ($abort == false) {
  194. if (isset($num_fields)) {
  195. $num_fields = intval($num_fields);
  196. }
  197. // No table name
  198. if (!isset($table) || trim($table) == '') {
  199. PMA_mysqlDie($strTableEmpty, '', '', $err_url);
  200. }
  201. // No valid number of fields
  202. elseif (empty($num_fields) || !is_int($num_fields)) {
  203. PMA_mysqlDie($strFieldsEmpty, '', '', $err_url);
  204. }
  205. // Does table exist?
  206. elseif (!(PMA_DBI_get_fields($db, $table) === false)) {
  207. PMA_mysqlDie(sprintf($strTableAlreadyExists, htmlspecialchars($table)), '', '', $err_url);
  208. }
  209. // Table name and number of fields are valid -> show the form
  210. else {
  211. $action = 'tbl_create.php';
  212. require './libraries/tbl_properties.inc.php';
  213. // Displays the footer
  214. require_once './libraries/footer.inc.php';
  215. }
  216. }
  217. ?>