#!/usr/local/bin/perl # drop_field.cgi # Drop a field from some table sub mytext($); require './postgresql-lib.pl'; &ReadParse(); &can_edit_db($in{'db'}) || &error(mytext('dbase_ecannot')); $desc = &text('table_header', "$in{'table'}", "$in{'db'}"); &ui_print_header($desc, mytext('fdrop_title'), "", "field_drop"); @desc = &table_structure($in{'db'}, $in{'table'}); local $table_shuffle; # If a field drop has been specified using this script if ( $in{'dropfld'} && $in{'dropfldok'} ) { # Drop the field by copying the other fields through a temp table &error_setup(mytext('fdrop_err')); local $i; local $fld_list = ""; if( @desc > 1 ) { for($i=0; $i{'field'}) ) { # Note PostgreSQL requires quotes for uppercase if( $fld_list eq "" ) { $fld_list = '"'.$r->{'field'}.'"'; } else { $fld_list = $fld_list . ', "' .$r->{'field'}.'"'; } } } } if( $fld_list ne "" ) { local $tmp_tbl = "webmin_tmp_table".$PROCESS_ID; local $qt = "e_table($in{'table'}); $table_shuffle = join '', "LOCK TABLE $qt;", "CREATE TABLE $tmp_tbl AS SELECT $fld_list FROM $qt;", "DROP TABLE $qt;", "ALTER TABLE $tmp_tbl RENAME TO $qt;"; &execute_sql_logged($in{'db'}, $table_shuffle); &webmin_log("delete", "table+field", $in{'table'}."+".$in{'dropfld'}, \%in); } @desc = &table_structure($in{'db'}, $in{'table'}); } # if a field drop has been specified # Display field selection screen $mid = int((@desc / 2)+0.5); print "
\n"; print "\n"; print "\n"; print "
\n"; &type_table(0, $mid); print "\n"; &type_table($mid, scalar(@desc)) if (@desc > 1); print "
\n"; print "\n"; print "\n"; print "'."\n"; print "
\n"; print "", &html_escape(mytext('fdrop_lose_data')), "", "\n"; print '
\n"; print "
\n"; &ui_print_footer("edit_table.cgi?db=$in{'db'}&table=$in{'table'}",mytext('table_return'), "edit_dbase.cgi?db=$in{'db'}", mytext('dbase_return'), "", mytext('index_return')); sub type_table { print "\n"; print " ", " ", " ", "\n"; local $i; for($i=$_[0]; $i<$_[1]; $i++) { local $r = $desc[$i]; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } print "
".mytext('table_field')."".mytext('table_type')."".mytext('table_arr')."".mytext('fdrop_header')."
",&html_escape($r->{'field'}),"",&html_escape($r->{'type'}),"",$r->{'arr'} eq 'YES' ? mytext('yes') : mytext('no'),"","
\n"; } sub mytext($) { my ($x) = @_; my $rv = $text{"$x"}; if( ! $rv ) { $rv = "$x"; # if unknown text, use the label } return $rv; }