#!/usr/local/bin/perl -w # This is a query and change of data use DBI; use CGI; $database = '***'; $hostname = '***'; $user = '***'; $password = '***'; $ss=''; $query = new CGI; print $query->header; $TITLE="Change Example"; $path_info = $query->path_info; # If no path information is provided, then we create # a side-by-side frame set if (!$path_info) { &print_frameset; exit 0; } #Start HTML page &print_html_header; &print_query if $path_info=~/query/; &print_response if $path_info=~/response/; &print_end; exit; #------------------------------------------- # Subroutines #------------------------------------------- sub print_html_header { print $query->start_html($TITLE); } #-------------------------------------------- sub print_end { print $query->end_html; } #-------------------------------------------- sub print_frameset { $script_name = $query->script_name; print <$TITLE EOF ; exit 0; } #----------------------------------------------- sub print_query { $script_name = $query->script_name; print "

Change

\n"; print $query->startform(-action=>"$script_name/response",-TARGET=>"response"); print "

What would like to change? ", $query->popup_menu(-name=>'keyword', -values=>['coordinates','texture']), "

"; print $query->submit; print $query->endform; print qq{

home}; } #-------------------------------------------------- sub print_response { print "

Values

\n"; unless ($query->param) { print "No query submitted yet."; return; } print "

Old ", $query->param(keyword),":"; if (($query->param(keyword)) eq 'coordinates') { #Query database--1------------------------------------------------ $dbh = DBI->connect ("DBI:mysql:$database:$hostname", $user,$password); $sth = $dbh->prepare("select fid,nid,xc,yc,zc from surfd,face,node where sidd=15 and enoseqs=1 and fids=fid and nidf=nid"); $sth->execute; $num=0; #print "
"; while ( @field = $sth->fetchrow) { @all[$num]=[@field]; $num++; } print "
"; $sth->finish; $dbh->disconnect; #Query database END--1------------------------------------------- #---printing coordinates------------------------ $k=0; while ($k<$num) { $j=1; while ($j<5) { print "$all[$k]->[$j++] "; } $k++; print "
"; } #--------END printing------------------------------------- print "
New coordinates (nid,x,y,z):
"; # # print $query->startform(-TARGET=>"response"); print $query->textfield(-name=>'nid', -default=>$all[0]->[1], -size=>10, -maxlength=>60); print $query->textfield(-name=>'x', -default=>$all[0]->[2], -size=>10, -maxlength=>60); print $query->textfield(-name=>'y', -default=>$all[0]->[3], -size=>10, -maxlength=>60); print $query->textfield(-name=>'z', -default=>$all[0]->[4], -size=>10, -maxlength=>60); print $query->submit (' Submit xyz '); print $query->endform; } elsif (($query->param(keyword)) eq 'texture') { #Query database--4----------------------------------------------- $dbh = DBI->connect ("DBI:mysql:$database:$hostname", $user,$password); $sth = $dbh->prepare("select fname from texta where tida=2"); $sth->execute; $name_texture = $sth->fetchrow; $sth->finish; $dbh->disconnect; #Query database END--4------------------------------------------- print qq{

See the old}; print "

New texture:
"; print $query->startform(-TARGET=>"response"); print $query->textfield(-name=>'filename', -default=>$name_texture, -size=>18, -maxlength=>90); print $query->submit ('Submit filename'); print $query->endform; } elsif (($query->param('filename')) ne '') { $dbh = DBI->connect ("DBI:mysql:$database:$hostname", $user, $password); $file_name=$query->param('filename'); $sth = $dbh->prepare("replace into texta (tida, fname) values (2,'$file_name')"); $sth->execute; $sth->finish; $dbh->disconnect; print "
Texture done"; print qq {


See the changes}; } else { $nid=$query->param('nid'); $x=$query->param('x'); $y=$query->param('y'); $z=$query->param('z'); $dbh = DBI->connect ("DBI:mysql:$database:$hostname", $user,$password); $sth = $dbh->prepare("replace into node (nid, xc,yc,zc) values ($nid,$x,$y,$z)"); $sth->execute; $sth->finish; $dbh->disconnect; print "
Coordinates changed"; print qq {


See the changes}; #Query database END--3------------------------------------------- } }