You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
375 lines
9.6 KiB
375 lines
9.6 KiB
#!/usr/bin/perl
|
|
#
|
|
# $Id: ddl.pl,v 1.5 2006/12/07 19:43:14 ddoughty Exp $
|
|
#
|
|
# Source File: ddl.pl
|
|
|
|
# Get config
|
|
require 'sitecfg.pl';
|
|
|
|
&app_initialize;
|
|
|
|
print "Content-Type: text/html\n\n";
|
|
|
|
if (&get_session($FORM{'tid'})) {
|
|
&LanguageSupportInit();
|
|
|
|
&log_entry($SESSION{'clid'}, $SESSION{'uid'}, "3", "DDL $FORM{'dbfilepath'}");
|
|
print "<HTML>\n";
|
|
print "<BODY>\n";
|
|
if ($SESSION{'uac'} ne 'gadmin') {
|
|
print "<CENTER>\n";
|
|
print "You do not have privileges to make Database Structure Changes.\n";
|
|
print "</CENTER>\n";
|
|
} else {
|
|
if ($FORM{'editmode'} eq 'apply') {
|
|
if ($FORM{'def0'}) {
|
|
&apply_header_changes;
|
|
} else {
|
|
&apply_data_changes;
|
|
}
|
|
} else {
|
|
if ($FORM{'floctn'} eq 'dataroot') {
|
|
@frecs = &get_data($FORM{'dbfilepath'});
|
|
$tmpfile = join($pathsep, $dataroot, $FORM{'dbfilepath'});
|
|
} elsif ($FORM{'floctn'} eq 'questionroot') {
|
|
($fnm, $fxt) = split(/\./, $FORM{'dbfilepath'});
|
|
@frecs = &get_question_list($fnm, $fxt);
|
|
$tmpfile = join($pathsep, $questionroot, $FORM{'dbfilepath'});
|
|
} else {
|
|
@frecs = ();
|
|
}
|
|
if ($#frecs == -1) {
|
|
if ($FORM{'create'} ne '') {
|
|
$FORM{'create'} = "Y";
|
|
@flds = ();
|
|
$nrows = 10;
|
|
$ncols = 2;
|
|
if ($FORM{'editmode'} eq 'structure') {
|
|
&show_table;
|
|
} else {
|
|
print "<CENTER>\n";
|
|
print "$FORM{'dbfilepath'} does not exist.\n";
|
|
print "</CENTER>\n";
|
|
}
|
|
} else {
|
|
print "<CENTER>\n";
|
|
print "$FORM{'dbfilepath'} does not exist.\n";
|
|
print "</CENTER>\n";
|
|
}
|
|
} else {
|
|
@flds = split(/&/,$frecs[0]);
|
|
$fields = $frecs[0];
|
|
chomp($fields);
|
|
$nrows = $#flds + 10;
|
|
$ncols = 2;
|
|
if ($FORM{'editmode'} eq 'structure') {
|
|
&show_table;
|
|
} else {
|
|
&show_data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
print "</BODY>\n";
|
|
print "</HTML>\n";
|
|
}
|
|
|
|
sub apply_header_changes {
|
|
if ($FORM{'floctn'} eq 'dataroot') {
|
|
@frecs = &get_data($FORM{'dbfilepath'});
|
|
$tmpfile = join($pathsep, $dataroot, $FORM{'dbfilepath'});
|
|
$froot = $dataroot;
|
|
} elsif ($FORM{'floctn'} eq 'questionroot') {
|
|
($fnm, $fxt) = split(/\./, $FORM{'dbfilepath'});
|
|
@frecs = &get_question_list($fnm, $fxt);
|
|
$tmpfile = join($pathsep, $questionroot, $FORM{'dbfilepath'});
|
|
$froot = $questionroot;
|
|
} else {
|
|
@frecs = ();
|
|
}
|
|
if ($#frecs == -1) {
|
|
if($FORM{'create'} eq 'Y') {
|
|
open (TMPFILE, ">$tmpfile");
|
|
print TMPFILE "\n";
|
|
close TMPFILE;
|
|
$noldflds = 0;
|
|
} else {
|
|
print "<CENTER>\n";
|
|
print "$FORM{'dbfilepath'} does not exist.\n";
|
|
print "</CENTER>\n";
|
|
return;
|
|
}
|
|
} else {
|
|
chop ($frec[0]);
|
|
@flds = split(/&/,$frecs[0]);
|
|
for (0 .. $#flds) { $DEFINED_FIELDS{$_} = $flds[$_];}
|
|
$noldflds = $#flds;
|
|
}
|
|
$nnewflds = 0;
|
|
for (keys %FORM) {
|
|
if ($_ =~ /idx(.*)/ ) {
|
|
($trash, $idx) = split(/x/, $_);
|
|
$defidx = "def$idx";
|
|
$DEFINED_FIELDS{$_} = $FORM{$_};
|
|
$DEFINED_DEFAULTS{$_} = $FORM{$defidx};
|
|
$nnewflds++;
|
|
}
|
|
}
|
|
if ($nnewflds == 0) {
|
|
print "No changes were made.<BR>\n";
|
|
} else {
|
|
$nnewflds--;
|
|
$newrec = $DEFINED_FIELDS{'idx0'};
|
|
$newdef = "";
|
|
for (1 .. $nnewflds) {
|
|
$idx = "idx$_";
|
|
if ( $DEFINED_FIELDS{$idx} ne '') {
|
|
$newrec = join('&', $newrec, $DEFINED_FIELDS{$idx});
|
|
if($_ > $noldflds) {
|
|
if ($DEFINED_DEFAULTS{$idx} eq "") {
|
|
$newdef = join('&', $newdef, "");
|
|
} else {
|
|
$newdef = join('&', $newdef, $DEFINED_DEFAULTS{$idx});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
print "FILE HEADER:<BR>\n";
|
|
print "$frecs[0]<BR>\ \;<BR>\n";
|
|
print "CHANGED TO:<BR>\n";
|
|
print "$newrec<BR>\ \;<BR>\n";
|
|
print "WITH DEFAULT VALUES OF:<BR>\n";
|
|
print "$newdef<BR>\ \;<BR>\n";
|
|
print "Files Affected:<BR>\n";
|
|
&update_file_header($froot, $FORM{'dbfilepath'}, $newrec, $newdef);
|
|
}
|
|
if ($FORM{'dbrelated'} ne '') {
|
|
opendir (TMPDIR, $froot);
|
|
@dots = readdir(TMPDIR);
|
|
closedir TMPDIR;
|
|
if ($FORM{'dbrelated'} =~ /\*/ ) {
|
|
($segleft, $segright) = split(/\*/, $FORM{'dbrelated'});
|
|
foreach $dot (@dots) {
|
|
if ($dot =~ m/$segleft(.*)$segright/ ) {
|
|
if ($dot ne $FORM{'dbfilepath'}) {
|
|
&update_file_header($froot, $dot, $newrec, $newdef);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$dbrelated = join(';', "", $FORM{'dbrelated'}, "");
|
|
foreach $dot (@dots) {
|
|
if ($dbrelated =~ /;$dot;/ ) {
|
|
if ($dot ne $FORM{'dbfilepath'}) {
|
|
&update_file_header($froot, $dot, $newrec, $newdef);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
sub apply_data_changes {
|
|
if ($FORM{'floctn'} eq 'dataroot') {
|
|
@frecs = &get_data($FORM{'dbfilepath'});
|
|
$tmpfile = join($pathsep, $dataroot, $FORM{'dbfilepath'});
|
|
$froot = $dataroot;
|
|
} elsif ($FORM{'floctn'} eq 'questionroot') {
|
|
($fnm, $fxt) = split(/\./, $FORM{'dbfilepath'});
|
|
@frecs = &get_question_list($fnm, $fxt);
|
|
$tmpfile = join($pathsep, $questionroot, $FORM{'dbfilepath'});
|
|
$froot = $questionroot;
|
|
} else {
|
|
@frecs = ();
|
|
}
|
|
if ($#frecs == -1) {
|
|
if($FORM{'create'} eq 'Y') {
|
|
open (TMPFILE, ">$tmpfile");
|
|
print TMPFILE "\n";
|
|
close TMPFILE;
|
|
$noldflds = 0;
|
|
} else {
|
|
print "<CENTER>\n";
|
|
print "$FORM{'dbfilepath'} does not exist.\n";
|
|
print "</CENTER>\n";
|
|
return;
|
|
}
|
|
} else {
|
|
chop ($frec[0]);
|
|
@flds = split(/&/,$frecs[0]);
|
|
}
|
|
|
|
for (keys %FORM) {
|
|
if ($_ =~ /\-/) {
|
|
($rowidx, $colidx) = split(/\-/, $_);
|
|
$data[$rowidx][$colidx] = $FORM{$_};
|
|
}
|
|
}
|
|
open (TMPFILE, ">$tmpfile");
|
|
print "$FORM{'fields'}<br>\n";
|
|
print TMPFILE "$FORM{'fields'}\n";
|
|
for ($r=1; $r<= $FORM{'numrows'}+1; $r++) {
|
|
if ($FORM{$r} eq "on") { next; }
|
|
$rowdata = "";
|
|
for ($c=0; $c<=$FORM{'numcols'}; $c++) {
|
|
$rowdata .= $data[$r][$c]."&";
|
|
}
|
|
$rowdata = substr($rowdata, 0, -1);
|
|
$rowdata =~ tr/+/ /;
|
|
$tmprowdata = $rowdata;
|
|
$tmprowdata =~ tr /&//d;
|
|
if ($tmprowdata eq "") { next; }
|
|
print "$rowdata<br>\n";
|
|
print TMPFILE "$rowdata\n";
|
|
}
|
|
close TMPFILE;
|
|
print "<br><br>Data written to $tmpfile.<br>\n";
|
|
}
|
|
|
|
sub update_file_header {
|
|
$updfile = join($pathsep, $_[0], $_[1]);
|
|
open (TMPUPDFILE, "<$updfile");
|
|
@updlines = <TMPUPDFILE>;
|
|
close TMPUPDFILE;
|
|
$updline = $updlines[0];
|
|
chop($updline);
|
|
if($updline ne $newrec) {
|
|
open (TMPUPDFILE, ">$updfile");
|
|
$nLineNo = 0;
|
|
foreach $updline (@updlines) {
|
|
chop($updline);
|
|
if ($nLineNo == 0) {
|
|
print TMPUPDFILE "$_[2]\n";
|
|
} else {
|
|
print TMPUPDFILE "$updline$_[3]\n";
|
|
}
|
|
$nLineNo++;
|
|
}
|
|
close TMPUPDFILE;
|
|
}
|
|
print "$updfile<BR>\n";
|
|
}
|
|
|
|
sub show_table {
|
|
print "
|
|
<SCRIPT language=\"JavaScript\" src=\"$cgiroot/js/ddl.js\">
|
|
</SCRIPT>
|
|
<CENTER>
|
|
<B>File Structure: $tmpfile</B>
|
|
<FORM NAME=\"form1\" METHOD=POST ACTION=\"$cgiroot/ddl.pl\">
|
|
<INPUT TYPE=HIDDEN NAME=\"tid\" VALUE=\"$SESSION{'tid'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"dbfilepath\" VALUE=\"$FORM{'dbfilepath'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"dbrelated\" VALUE=\"$FORM{'dbrelated'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"create\" VALUE=\"$FORM{'create'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"floctn\" VALUE=\"$FORM{'floctn'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"editmode\" VALUE=\"apply\">
|
|
<TABLE cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
|
|
<TR>
|
|
<TD align\"left\">Column Name</TD>
|
|
<TD align\"left\">New Name</TD>
|
|
<TD align\"left\">Default Value</TD>
|
|
</TR>\n";
|
|
$i = 0;
|
|
foreach $fld (@flds) {
|
|
print "
|
|
<TR>
|
|
<TD align\"left\">$fld</TD>
|
|
<TD align\"left\">
|
|
<INPUT TYPE=\"TEXT\" NAME=\"idx$i\" SIZE=14 MAXLENGTH=12 VALUE=\"$fld\">
|
|
</TD>
|
|
<TD align\"left\">
|
|
<INPUT TYPE=\"TEXT\" NAME=\"def$i\" SIZE=30>
|
|
</TD>
|
|
</TR>\n";
|
|
$i++;
|
|
}
|
|
for $j (1 .. 5){
|
|
print "
|
|
<TR>
|
|
<TD align\"left\">New Column $i</TD>
|
|
<TD align\"left\">
|
|
<INPUT TYPE=\"TEXT\" NAME=\"idx$i\" SIZE=14 MAXLENGTH=12>
|
|
</TD>
|
|
<TD align\"left\">
|
|
<INPUT TYPE=\"TEXT\" NAME=\"def$i\" SIZE=30>
|
|
</TD>
|
|
</TR>\n";
|
|
$i++;
|
|
}
|
|
print "
|
|
<TR>
|
|
<TD colspan=\"3\" align=\"center\">
|
|
<INPUT TYPE=\"SUBMIT\" NAME=\"submit\" VALUE=\"Submit\">
|
|
</TD>
|
|
</TR>
|
|
</TABLE>
|
|
</CENTER>
|
|
</FORM>\n";
|
|
}
|
|
|
|
sub show_data {
|
|
$txamask = "";
|
|
print "
|
|
<SCRIPT language=\"JavaScript\" src=\"$cgiroot/js/ddl.js\">
|
|
</SCRIPT>
|
|
<CENTER>
|
|
<B>File Structure: $tmpfile</B>
|
|
<FORM NAME=\"form1\" METHOD=POST ACTION=\"$cgiroot/ddl.pl\">
|
|
<INPUT TYPE=HIDDEN NAME=\"tid\" VALUE=\"$SESSION{'tid'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"editmode\" VALUE=\"apply\">
|
|
<INPUT TYPE=HIDDEN NAME=\"dbfilepath\" VALUE=\"$FORM{'dbfilepath'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"dbrelated\" VALUE=\"$FORM{'dbrelated'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"floctn\" VALUE=\"$FORM{'floctn'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"startrow\" VALUE=\"$FORM{'startrow'}\">
|
|
<INPUT TYPE=HIDDEN NAME=\"numrows\" VALUE=\"$#frecs\">
|
|
<INPUT TYPE=HIDDEN NAME=\"numcols\" VALUE=\"$#flds\">
|
|
<INPUT TYPE=HIDDEN NAME=\"fields\" VALUE=\"$fields\">
|
|
<TABLE cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
|
|
<TR>
|
|
<TD align\"left\"><B>Del<B></TD>\n";
|
|
foreach $fld (@flds) {
|
|
print "<TD><B>$fld<B></TD>\n";
|
|
}
|
|
print "</TR>\n";
|
|
$i = 1;
|
|
shift @frecs;
|
|
foreach $frec (@frecs) {
|
|
if ($frec ne "\n") {
|
|
print "<TR>\n<TD><INPUT TYPE=\"CHECKBOX\" NAME=\"$i\"></TD>\n";
|
|
chop ($frec);
|
|
@data = split(/&/, $frec);
|
|
for (0 .. $#flds) {
|
|
print "<TD align\"left\">\n";
|
|
if ($data[$_] =~ /\;/ ) {
|
|
print "<TEXTAREA NAME=\"$i-$_\" ROWS=3 COLS=30>$data[$_]</TEXTAREA>\n";
|
|
$txamask = join('', $txamask, "<$_>");
|
|
} else {
|
|
print "<INPUT TYPE=\"TEXT\" NAME=\"$i-$_\" SIZE=25 VALUE=\"$data[$_]\">\n";
|
|
}
|
|
print "</TD>\n";
|
|
}
|
|
print "</TR>\n";
|
|
$i++;
|
|
}
|
|
}
|
|
print "<TR>\n<TD><INPUT TYPE=\"CHECKBOX\" NAME=\"$i\"></TD>\n";
|
|
for (0 .. $#flds) {
|
|
print "<TD align\"left\">\n";
|
|
if ($txamask =~ /<$_>/ ) {
|
|
print "<TEXTAREA NAME=\"$i-$_\" ROWS=3 COLS=30></TEXTAREA>\n";
|
|
} else {
|
|
print "<INPUT TYPE=\"TEXT\" NAME=\"$i-$_\" SIZE=25 VALUE=\"\">\n";
|
|
}
|
|
print "</TD>\n";
|
|
}
|
|
print "</TR>
|
|
<TR>
|
|
<TD colspan=\"3\" align=\"center\">
|
|
<INPUT TYPE=\"SUBMIT\" NAME=\"submit\" VALUE=\"Submit\">
|
|
</TD>
|
|
</TR>
|
|
</TABLE>
|
|
</CENTER>
|
|
</FORM>\n";
|
|
}
|
|
|