6 * Get some core libraries
8 require('./grab_globals.inc.php3');
9 require('./header.inc.php3');
13 * The form used to define the field to add has been submitted
18 // Builds the field creation statement and alters the table
19 for ($i = 0; $i < count($field_name); ++
$i) {
20 $query .= backquote($field_name[$i]) . ' ' . $field_type[$i];
21 if ($field_length[$i] != ''
22 && !eregi('^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$', $field_type[$i])) {
23 if (get_magic_quotes_gpc()) {
24 $query .= '(' . stripslashes($field_length[$i]) . ')';
26 $query .= '(' . $field_length[$i] . ')';
29 if ($field_attribute[$i] != '') {
30 $query .= ' ' . $field_attribute[$i];
32 if ($field_default[$i] != '') {
33 if (strtoupper($field_default[$i]) == 'NULL') {
34 $query .= ' DEFAULT NULL';
35 } else if (get_magic_quotes_gpc()) {
36 $query .= ' DEFAULT \'' . sql_addslashes(stripslashes($field_default[$i])) . '\'';
38 $query .= ' DEFAULT \'' . sql_addslashes($field_default[$i]) . '\'';
41 if ($field_null[$i] != '') {
42 $query .= ' ' . $field_null[$i];
44 if ($field_extra[$i] != '') {
45 $query .= ' ' . $field_extra[$i];
48 if ($after_field != '--end--') {
49 // Only the first field can be added somewhere else than at the end
51 if ($after_field == '--first--') {
54 if (get_magic_quotes_gpc()) {
55 $query .= ' AFTER ' . backquote(stripslashes(urldecode($after_field)));
57 $query .= ' AFTER ' . backquote(urldecode($after_field));
61 if (get_magic_quotes_gpc()) {
62 $query .= ' AFTER ' . backquote(stripslashes($field_name[$i-1]));
64 $query .= ' AFTER ' . backquote($field_name[$i-1]);
70 $query = ereg_replace(', ADD $', '', $query);
72 $sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD ' . $query;
73 $result = mysql_query($sql_query) or mysql_die();
75 // Builds the primary keys statements and updates the table
77 if (isset($field_primary)) {
78 for ($i = 0; $i < count($field_primary); $i++
) {
79 $j = $field_primary[$i];
80 $primary .= backquote($field_name[$j]) . ', ';
82 $primary = ereg_replace(', $', '', $primary);
83 if (!empty($primary)) {
84 $sql_query .= "\n" . 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD PRIMARY KEY (' . $primary . ')';
85 $result = mysql_query('ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD PRIMARY KEY (' . $primary . ')') or mysql_die();
89 // Builds the indexes statements and updates the table
91 if (isset($field_index)) {
92 for ($i = 0; $i < count($field_index); $i++
) {
93 $j = $field_index[$i];
94 $index .= backquote($field_name[$j]) . ', ';
96 $index = ereg_replace(', $', '', $index);
98 $sql_query .= "\n" . 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD INDEX (' . $index . ')';
99 $result = mysql_query('ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD INDEX (' . $index . ')') or mysql_die();
103 // Builds the uniques statements and updates the table
105 if (isset($field_unique)) {
106 for ($i = 0; $i < count($field_unique); $i++
) {
107 $j = $field_unique[$i];
108 $unique .= backquote($field_name[$j]) . ', ';
110 $unique = ereg_replace(', $', '', $unique);
111 if (!empty($unique)) {
112 $sql_query .= "\n" . 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD UNIQUE (' . $unique . ')';
113 $result = mysql_query('ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD UNIQUE (' . $unique . ')') or mysql_die();
117 // Go back to table properties
118 $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
119 include('./tbl_properties.php3');
121 } // end do alter table
124 * Displays the form used to define the new field
127 $action = 'tbl_addfield.php3';
128 include('./tbl_properties.inc.php3');
130 // Diplays the footer
132 include('./footer.inc.php3');