3 # Display a form for editing an existing field or creating a new one
5 require './mysql-lib.pl';
7 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
8 $access{'edonly'} && &error($text{'dbase_ecannot'});
9 $desc = &text('field_in', "<tt>$in{'table'}</tt>", "<tt>$in{'db'}</tt>");
11 # Creating a new field
12 &ui_print_header($desc, $text{'field_title1'}, "", "create_field");
16 # Editing an existing field
17 &ui_print_header($desc, $text{'field_title2'}, "", "edit_field");
18 @desc = &table_structure($in{'db'}, $in{'table'});
19 $f = $desc[$in{'idx'}];
24 print &ui_form_start("save_field.cgi");
25 print &ui_hidden("db", $in{'db'});
26 print &ui_hidden("table", $in{'table'});
27 print &ui_hidden("new", $in{'type'});
28 print &ui_table_start($text{'field_header'}, undef, 2);
31 print &ui_table_row($text{'field_name'},
32 &ui_textbox("field", $f->{'field'}, 20));
33 print &ui_hidden("old", $f->{'field'}) if (!$in{'type'});
36 if ($type =~ /^(\S+)\((.*)\)(.*)/) {
41 print &ui_hidden("type", $type);
43 # New field .. just show chosen type
47 # Existing field .. allow type change
48 $tsel = &ui_select("newtype", $type, \@type_list)." ".
49 $text{'field_typewarn'};
51 print &ui_table_row($text{'field_type'}, $tsel);
53 if ($type eq 'enum' || $type eq 'set') {
55 local @ev = &split_enum($size);
56 print &ui_table_row($text{'field_enum'},
57 &ui_textarea("size", join("\n", @ev), 4, 20));
59 elsif ($type eq 'float' || $type eq 'double' || $type eq 'decimal') {
60 # Two values, for total and decimal
61 print &ui_table_row($text{'field_dual'},
62 &ui_textbox("size1", $size =~ /^(\d+)/ ? $1 : '', 5)."\n".
63 &ui_textbox("size2", $size =~ /(\d+)$/ ? $1 : '', 5));
65 elsif ($type eq 'date' || $type eq 'datetime' || $type eq 'time' ||
66 $type eq 'timestamp' || $type =~ /(blob|text)$/) {
69 elsif ($type ne 'varchar' && $type ne 'char' && $in{'type'}) {
70 # Size is optional for new fields of most types
71 print &ui_table_row($text{'field_size'},
72 &ui_opt_textbox("size", undef, 10, $text{'default'}));
76 print &ui_table_row($text{'field_size'},
77 &ui_textbox("size", $size, 10));
80 if ($type =~ /int$/) {
81 # Display unsigned/zerofill option
82 print &ui_table_row($text{'field_opts'},
83 &ui_radio("opts", $extra =~ /unsigned/ ? 'unsigned' :
84 $extra =~ /zerofill/ ? 'zerofill' : '',
85 [ [ '', $text{'field_none'} ],
86 [ 'unsigned', $text{'field_unsigned'} ],
87 [ 'zerofill', $text{'field_zerofill'} ] ]));
89 # Display auto-increment option
90 print &ui_table_row($text{'field_auto'},
91 &ui_radio("ext", $f->{'extra'} =~ /auto_increment/ ?
92 'auto_increment' : '',
93 [ [ 'auto_increment', $text{'yes'} ],
94 [ '', $text{'no'} ] ]));
96 elsif ($type eq 'float' || $type eq 'double' || $type eq 'decimal') {
97 # Display zerofill option
98 print &ui_table_row($text{'field_opts'},
99 &ui_radio("opts", $extra =~ /zerofill/ ? 'zerofill' : '',
100 [ [ '', $text{'field_none'} ],
101 [ 'zerofill', $text{'field_zerofill'} ] ]));
103 elsif ($type eq 'char' || $type eq 'varchar') {
104 # Display binary option
105 print &ui_table_row($text{'field_opts'},
106 &ui_radio("opts", $extra =~ /binary/ ? 'binary' : '',
107 [ [ '', $text{'field_ascii'} ],
108 [ 'binary', $text{'field_binary'} ] ]));
112 print &ui_table_row($text{'field_null'},
113 &ui_radio("null", $in{'type'} || $f->{'null'} eq 'YES' ? 1 : 0,
114 [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
117 $defmode = $f->{'default'} eq 'NULL' || !defined($f->{'default'}) ? 0 :
118 $f->{'default'} eq 'CURRENT_TIMESTAMP' ? 2 :
119 $f->{'default'} eq '' ? 3 : 1;
120 @defs = ( [ 0, 'NULL' ] );
123 push(@defs, [ 3, $text{'field_defdef'} ]);
125 elsif ($type eq 'char' || $type eq 'varchar') {
127 push(@defs, [ 3, $text{'field_defempty'} ]);
129 if ($type eq "timestamp") {
130 push(@defs, [ 2, $text{'field_current'} ]);
132 push(@defs, [ 1, $text{'field_defval'}." ".
133 &ui_textbox("default", $defmode == 1 ? $f->{'default'} : "", 40) ]);
134 print &ui_table_row($text{'field_default'},
135 &ui_radio("default_def", $defmode, \@defs));
137 # Part of primary key
138 print &ui_table_row($text{'field_key'},
139 &ui_yesno_radio("key", $f->{'key'} eq 'PRI' ? 1 : 0));
140 print &ui_hidden("oldkey", $f->{'key'} eq 'PRI' ? 1 : 0);
142 print &ui_table_end();
144 print &ui_form_end([ [ undef, $text{'create'} ] ]);
147 print &ui_form_end([ [ undef, $text{'save'} ],
148 @desc > 1 ? ( [ 'delete', $text{'delete'} ] ): ( ) ]);
151 &ui_print_footer("edit_table.cgi?db=$in{'db'}&table=".&urlize($in{'table'}),
152 $text{'table_return'},
153 "edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
154 "", $text{'index_return'});