#!/usr/local/bin/perl # edit_field.cgi # Display a form for editing an existing field or creating a new one require './mysql-lib.pl'; &ReadParse(); &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'}); $access{'edonly'} && &error($text{'dbase_ecannot'}); $desc = &text('field_in', "$in{'table'}", "$in{'db'}"); if ($in{'type'}) { # Creating a new field &ui_print_header($desc, $text{'field_title1'}, "", "create_field"); $type = $in{'type'}; } else { # Editing an existing field &ui_print_header($desc, $text{'field_title2'}, "", "edit_field"); @desc = &table_structure($in{'db'}, $in{'table'}); $f = $desc[$in{'idx'}]; $type = $f->{'type'}; } print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$text{'field_header'}
\n"; print "\n"; print "\n"; print "\n" if (!$in{'type'}); if ($type =~ /^(\S+)\((.*)\)(.*)/) { $type = $1; $size = $2; $extra = $3; } print "\n"; print "\n"; if ($in{'type'}) { # New field .. just show chosen type print "\n"; } else { # Existing field .. allow type change print "\n"; } if ($type eq 'enum' || $type eq 'set') { # List of values local @ev = &split_enum($size); print "\n"; print "\n"; } elsif ($type eq 'float' || $type eq 'double' || $type eq 'decimal') { # Two values print "\n"; printf "\n", $size =~ /(\d+)$/ ? $1 : ''; } elsif ($type eq 'date' || $type eq 'datetime' || $type eq 'time' || $type eq 'timestamp' || $type =~ /(blob|text)$/) { # No width! } elsif ($type ne 'varchar' && $type ne 'char' && $in{'type'}) { # Size is optional for new fields of most types print "\n"; print "\n"; } else { # One single value print "\n"; print "\n"; } if ($type =~ /int$/) { # Display unsigned/zerofill option print "\n"; printf "\n", $extra =~ /zerofill/ ? 'checked' : '', $text{'field_zerofill'}; # Display auto-increment option print "\n"; printf "\n", $f->{'extra'} =~ /auto_increment/ ? '' : 'checked', $text{'no'}; } elsif ($type eq 'float' || $type eq 'double' || $type eq 'decimal') { # Display zerofill option print "\n"; printf "\n", $extra =~ /zerofill/ ? 'checked' : '', $text{'field_zerofill'}; } elsif ($type eq 'char' || $type eq 'varchar') { # Display binary option print "\n"; printf "\n", $extra =~ /binary/ ? 'checked' : '', $text{'field_binary'}; } print "\n"; printf "\n", $in{'type'} || $f->{'null'} eq 'YES' ? '' : 'checked'; print "\n"; printf "\n", $f->{'default'} eq 'NULL' ? '' : $f->{'default'}; print "\n"; printf "\n", $f->{'key'} eq 'PRI' ? '' : 'checked', $text{'no'}; printf "\n", $f->{'key'} eq 'PRI' ? 1 : 0; print "
$text{'field_name'}
$text{'field_type'}$type
$text{'field_typewarn'}
$text{'field_enum'}
$text{'field_dual'}\n", $size =~ /^(\d+)/ ? $1 : ''; printf "
$text{'field_size'} ", "$text{'default'}\n"; print "\n"; print "
$text{'field_size'}
$text{'field_opts'} %s\n", $extra =~ /unsigned/ ? '' : 'checked', $text{'field_none'}; printf " %s\n", $extra =~ /unsigned/ && $extra !~ /zerofill/ ? 'checked' : '', $text{'field_unsigned'}; printf " %s
$text{'field_auto'} %s\n", 'auto_increment', $f->{'extra'} =~ /auto_increment/ ? 'checked' : '', $text{'yes'}; printf " %s
$text{'field_opts'} %s\n", $extra =~ /unsigned/ ? '' : 'checked', $text{'field_none'}; printf " %s
$text{'field_opts'} %s\n", $extra =~ /binary/ ? '' : 'checked', $text{'field_ascii'}; printf " %s
$text{'field_null'} $text{'yes'}\n", $in{'type'} || $f->{'null'} eq 'YES' ? 'checked' : ''; printf " $text{'no'}
$text{'field_default'}
$text{'field_key'} %s\n", $f->{'key'} eq 'PRI' ? 'checked' : '', $text{'yes'}; printf " %s
\n"; if ($in{'type'}) { print "\n"; } else { print " \n"; print "\n" if (@desc > 1); } print "
\n"; &ui_print_footer("edit_table.cgi?db=$in{'db'}&table=".&urlize($in{'table'}), $text{'table_return'}, "edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'}, "", $text{'index_return'});