#!/usr/local/bin/perl
alarm (300);
# File name: script_util.pl
# dbEase version 1.03
# MODIFICATIONS: Version upgrade to dbEase version 1.03
#
# MODIFICATIONS to script_util.pl
# 1. Display edit : script gets server name to display where the user
# should link to when linking to search srcipt. (09/29/98)
#
# Files affected as of (12/04/98) that instigated a version upgrade :
# 1. go_get.pl last modified (12/04/98)
# 2. idm.pl last modified (09/29/98)
# 3. db_util.pl last modified (09/29/98)
# 4. script_util.pl last modified (09/29/98)
# 5. search.pl last modified (12/01/98)
# Written by Kenneth Hubert ("production unit 6")
##
#
#PROPRIETARY NOTICE
#
# (C) 1998 Stratum New Media, Inc. All rights reserved. Any unauthorized use of
# this unpublished work (including reproduction) is prohibited.
# Stratum New Media owns all rights to this work and intends to maintain this
# information as proprietary and confidential. In the event of any inadvertent
# or deliberate and unauthorized use or publication of such work,
# Stratum New Media, Inc. will enforce any and all of its rights under all
# applicable laws.
#
# Stratum New Media provides this report for the sole purpose of permitting the
# recipient, a representative of InfiNet, to evaluate the proposal submitted.
# In consideration of receiving this report, the recipient and any other agents
# and representatives of InfiNet, agree to maintain the information in this
# report confidential, and refrain from disclosing such information to any
# third party or person outside the group directly responsible for this
# evaluation.
#
#
##############################################################
# Requires Perl 5.xx and CGI.pm
##############################################################
#
# This script provides an interface for deleting or modifing a table
# as well as performing the appropriate action.
# it expects an array of different poss. params:
# 'Search' -> 'SAVE' or 'SUBMIT' -> save a template or setup input types resp.
# 'Result' -> 'SAVE' or 'SUBMIT' -> save a template or
# setup rps, order by, and desc or ascending
# 'Start Over' -> for either Search or Result, does what it says
# 'tableName' -> if this doesn't exits ask user which table
# 'what to do' -> got tableName already what do i do Search or Result
# 'selected_search' -> 'SUBMIT' setup input types
# 'selected_result' -> 'SUBMIT' setup rps, order by, and desc or ascending
# 'SETUP Search Page' -> choose searchable fields
# 'SETUP Result Page' -> choose viewable fields
# 'VIEW' -> view what user has created.
use CGI;
use File::Copy;
$query = new CGI;
my $conf_file = "./dbEase.config";
require $conf_file;
my $dbh = &dbConnect();
###########################################################
#
# MAIN
#
############################################################
## to save a template
if ($query->param('Search') eq 'SAVE' ||
$query->param('Result') eq 'SAVE') {
&save();
}
## to start over
elsif ($query->param('Start Over')) {
&start_over();
}
## if no tableName let user choose one
elsif (!($query->param('tableName'))) {
&which_table();
}
## what are we doing result or search page
elsif ($query->param('what to do')) {
if ($query->param('what to do') eq 'Search Page') { &edit_search_html(); }
else { &edit_result_html(); }
}
## setup searchable field's input types
elsif ($query->param('selected_search') eq 'SUBMIT') {
&search_choices();
}
## setup order and rps (results per screen)
elsif ($query->param('selected_result') eq 'SUBMIT') {
&result_choices();
}
## modify search page
elsif ($query->param('Search') eq 'SUBMIT' ||
$query->param('EDIT_Search_Page')) {
&edit_search_html();
}
## modify results page
elsif ($query->param('Result') eq 'SUBMIT' ||
$query->param('EDIT_Result_Page')) {
&edit_result_html();
}
## choose searchable fields
elsif ($query->param('SETUP Search Page')) {
&search_fields()
}
## choose displayable fields
elsif ($query->param('SETUP Result Page')) {
&result_fields()
}
## view a buffer (result/search)
elsif ($query->param('VIEW')) {
$query->autoEscape('true');
my $script = $query->param('script');
my $str_to_pass = join '', "tableName=", $query->param('tableName');
$str_to_pass = join '', $str_to_pass, "&File=", $query->param('File');
## get ready to pass
my $parsed_str = $query->param('revisions');
$parsed_str =~ s/=>/AaRrWw/mg;
$parsed_str =~ s/=/EeQqLl/mg;
$parsed_str =~ s/&/AaMmPp/mg;
##
$str_to_pass = join '', $str_to_pass, "&textbox=", $parsed_str;
open(VIEW, "|$script") || die print"can't open $script :: $!";
print VIEW "$str_to_pass";
close(VIEW);
exit;
}
## was expecting a param but didn't get it
else {
print $query->header;
print $query->start_html(-title=>"Error",
-bgcolor=>"#ffffff");
print "
",
"A crucial parameter was not sent.
Try again.";
print $query->end_html;
exit;
}
############################################################
#
# sub search_fields provides a interface to choose searchable
# fields.
# sub search_fields expects at least 'SETUP Search Page'
# param to get this far. also will need
# 'tableName'
# if 'SETUP Search Page' == 'Change Input Types' go to that
# screen.
# if 'SETUP Search Page' == 'Change Searchable Fields' full
# fledged modification.
# Pass out "searchables" -> fields that will be searchable &
# 'selected_search' -> 'SUBMIT'
#
############################################################
sub search_fields {
## just want to change input types of existing searchable fields
if ($query->param('SETUP Search Page') eq 'Change Input Types') {
&search_choices();
}
print $query->header;
print $query->start_html(-title=>"Select Searchable Fields",
-bgcolor=>"#ffffff");
my $table = $query->param('tableName');
print "";
print "HELP
";
print "Select 'Searchable Fields' for $table.";
## we're changing the searchable fields
if ($query->param('SETUP Search Page') eq 'Change Searchable Fields') {
print "Fields that :- .. were Searchable and are selected again will remain in their original position.
- .. are not selected again will be removed, but any text around the removed field will remain.
- .. are new Seachable Fields will be placed at the end.
\n";
}
my $sth = $dbh->listfields($table);
my $noCols = $sth->numfields - 1;
my @colnames = $sth->name;
my @search_fields;
for ($i = 0; $i < $noCols; $i++) { push(@search_fields, $i); }
print $query->start_form(-action=>'./script_util.pl'), "\n";
print $query->hidden('tableName','$table');
if ($query->param('setup') eq 'follow') {
print $query->hidden('setup', 'follow');
}
## searchable fields with check boxes to select
my @ckboxes = $query->checkbox_group(-name =>"searchables",
-"values"=>[@search_fields],
-nolabels=>1);
print "\n";
print "| Select | Field Name |
\n";
for ($i = 0; $i < $noCols; $i++) {
print "| ", $ckboxes[$i],
" | ",$colnames[$i]," |
\n";
}
print "
";
print $query->submit( -name=>'selected_search', -value=>'SUBMIT');
print $query->end_form;
print $query->end_html;
exit;
}
############################################################
#
# sub search_choices provides an interface to choose input
# types of selected searchable fields.
# sub search_choices will need 'tableName' and
# 'SETUP Search Page'
# Passes 'input_type_for_(searchable fields name)' duh!
# 'match_(searchable fields name)' how above matches
# 'Search' -> 'SUBMIT'
#
############################################################
sub search_choices {
print $query->header;
print $query->start_html(-title=>"Set up Input Types",
-bgcolor=>"#ffffff");
my $table = $query->param('tableName');
print "";
print "HELP
";
print "Select 'Input Types' for each Searchable Field in $table.";
my $sth = $dbh->listfields($table);
my $noCols = $sth->numfields - 1;
my @colnames = $sth->name;
my @search_fields = $query->param('searchables');
## we're changing the input types
if ($query->param('SETUP Search Page') eq 'Change Input Types') {
@search_fields = split / /, $search_fields[0];
foreach $each(@search_fields) {
for ($i = 0; $i < $noCols; $i++) {
if ($each eq $colnames[$i]) {
push(@temp, $i);
last;
}
}
}
@search_fields = @temp;
}
my @coltype = $sth->type;
my @choices;
## setup choices for chars and reals & ints
my @char_choices = ('textbox', 'pop-up menu (char)');
my @int_real_choices = ('textbox', 'FROM/TO textboxes', 'pop-up menu (num)');
my @radio_butts;
my @buttons = ('equal ','not equal ','less than',
'greater than');
my @values = (' = ',' <> ',' <= ',' >=');
print $query->start_form(-action=>'./script_util.pl');
print $query->hidden('tableName', '$table');
## if user is following the path layed out for
## them need to pass some extra info
if ($query->param('setup') eq 'follow') {
print $query->hidden('setup', 'follow');
}
## setting up dispaly
print "\n";
print "| \nSearchable Field";
print " | \nInput Type";
print " | \nChoose how to match";
foreach $field(@search_fields) {
## give input type selections for each searchable field
if ($type{$coltype[$field]} eq 'char') { @choices = @char_choices; }
else { @choices = @int_real_choices; }
print "| \n$colnames[$field] :";
print " | \n";
print $query->popup_menu(-name=>"input_type_for_$colnames[$field]",
-"values"=>[@choices]), " | ";
if ($type{$coltype[$field]} ne 'char') {
## radio buttons for how the searchable will match
## (exact, contains, = ,!=, <=, >=).
@radio_butts = $query->radio_group( -name=>"match_$colnames[$field]",
-"values"=>[@values],
-nolabels=>"true");
print "| ",
"";
print $radio_butts[0], $buttons[0], " | ",
"",
$radio_butts[3], $buttons[3], " |
|---|
| ",
"",
$radio_butts[1], $buttons[1], " | ",
"",
$radio_butts[2], $buttons[2], " |
|---|
";
}
elsif ($type{$coltype[$field]} ne 'char') {
print $query->hidden("match_$colnames[$field]", 'LIKE');
}
else { print $query->hidden("match_$colnames[$field]", 'LIKE');}
}
print " |
|---|
|
|---|
\n",
"Note :";
print "| The 'less than' and 'greater than' choices for number matching are INCLUSIVE.\n";
print " |
|---|
|
|---|
\n
",
$query->submit(-label=>"SUBMIT", -name=>'Search', -value=>'SUBMIT');
print $query->end_form;
print $query->end_html;
exit;
}
###############################################################################
#
# sub edit_search_html provides an interface to modify any
# html stuff in template.
# sub edit_search_html should be passed 'tableName'
# could be passed :
# 'Search' == 'SUBMIT' -> search fields defned
# 'Search' == 'SAVE' -> to save buffer
# 'BACK' -> coming back from view screen
# 'changed_text' -> contents of edit buffer
# 'EDIT_Search_Page' == 'REVERT' duh!
# 'SETUP Search Page' == 'Change Input Types' ->
# duh!
# 'searchables' -> what are the existing
# searchable fields .. needed by
# sub search_choices
# 'SETUP Search Page'
# 'VIEW' == 'VIEW Page' duh!
# 'Start Over' == 'Start Over' duh!
# 'SETUP Search Page' ==
# 'Change Searchable Fields'
# -> to change the searchable fields
# 'revisions' == (the edit buffer)
#
# sub edit_search_html Passes most of these params back to other subs.
#
###############################################################################
sub edit_search_html {
my $editFile = '';
my $table = $query->param('tableName');
my $HTML = join '', $DIR, $table,"_Search_HTML.page";
## create file (template) if non-existent...
if (!(-e $HTML)) {
## ...if they specified search fields
if ($query->param('Search') eq 'SUBMIT') {
&create_Search_HTML_page();
}
## .. didn't specify search field lets go a do it.
else {
&search_fields();
}
print $query->header;
print $query->start_html(-title=>"EDIT Search Page",
-bgcolor=>"#ffffff");
## help
print "";
print "HELP
";
print "Edit $table Search HTML Page
";
## file should be there open it and put it edit buffer
open (SFILE, "$HTML") || die print "can't opem $HTML : $!";
while () {
$editFile = "$editFile$_";
if ($_ =~ //) {
@temp = split /|=>/, $_, 3;
if ($temp[1] !~ /START_FORM|END_FORM/) {
push (@searchable, $temp[1]);
}
}
}
close(SFILE);
}
## coming for viewing file and buffer may not be same show buffer in edit box
elsif ($query->param('BACK')) {
print $query->header;
print $query->start_html(-title=>"EDIT Search Page",
-bgcolor=>"#ffffff");
## help
print "";
print "HELP
";
print "Edit $table Search HTML Page
";
## contents of edit buffer passed to view screen which was passed by
## edit_search_html to the view in the first place.
$editFile = $query->param('changed_text');
my $find = $editFile;
my @temp = split //, $find;
for ($i = 2; $i < $#temp; $i++) {
my @temp2 = split /=>/, $temp[$i];
push(@searchable, $temp2[0]);
}
}
## file already exists but user changed something
elsif ($query->param('Search') eq 'SUBMIT') {
print $query->header;
print $query->start_html(-title=>"EDIT Search Page",
-bgcolor=>"#ffffff");
## help
print "";
print "HELP
";
print "Edit $table Search HTML Page
";
## get new 'input_type_for_(searchable fields name)' duh! and
# 'match_(searchable fields name)' how above matches
foreach $key($query->param()) {
$_ = $key;
## if param has input_type_for_ in it we need to do some work
if (s/input_type_for_//e) {
$itype = $query->param($key);
$temp = join '',"$_=>", $query->param($key);
push(@msql,$_);
push(@searchable,$_);
}
## get how to match param
elsif (s/match_//e) {
if ($itype eq 'pop-up menu (char)') {
$query->param($key, 'EXACT');
}
$temp = join '',$temp," match=>",$query->param($key),"";
push(@msql,$temp);
}
}
%msqlTags = @msql;
@key = keys %msqlTags;
my @on_screen =();
## open existing file and make changes
open (SFILE, "$HTML") || die print "can't opem $HTML : $!";
while () {
if ($_ =~ //) {
@temp = split /|<\/MSQL_TAG>/,$_,3;
if ($temp[1] !~ /START_FORM/) {
if ($temp[1] !~ /END_FORM/) {
@thiskey = split /=>/, $temp[1];
if (exists $msqlTags{$thiskey[0]}) {
$editFile = "$editFile$temp[0]$msqlTags{$thiskey[0]}$temp[2]";
push(@on_screen, $thiskey[0]);
}
else {$editFile = "$editFile$temp[0]$temp[2]"; }
}
else {
my @not_on_screen = ();
foreach $field(@key) {
if (!(grep { /$field/ } @on_screen)) {
push(@not_on_screen, $field);
}
}
foreach $field(@not_on_screen) {
$editFile =
join '', $editFile,
"| $field : \n | ",
$msqlTags{$field}, " |
|---|
\n";
}
$editFile = join '', $editFile, $temp[0], "",
$temp[1],"<\/MSQL_TAG>", $temp[2]; }
}
else { $editFile = join '', $editFile, $temp[0], "",
$temp[1],"<\/MSQL_TAG>", $temp[2]; }
}
else { $editFile = "$editFile$_"; }
}
close(SFILE);
print "
You must SAVE to make these changes permanent.
";
}
## file exist and user just wants to modify html or something
else {
print $query->header;
print $query->start_html(-title=>"EDIT Search Page",
-bgcolor=>"#ffffff");
print "";
print "HELP
";
print "Edit $table Search HTML Page
";
## open file and put in edit buffer
$editFile = "";
open (SFILE, "$HTML") || die print "can't open $HTML : $!";
while () {
$editFile = "$editFile$_";
if ($_ =~ //) {
@temp = split /|=>/g, $_;
if ($temp[1] !~ /START_FORM|END_FORM/) {
push (@searchable, $temp[1]);
}
}
}
close(SFILE);
}
## if user saved buffer them 'em it was saved
if ($query->param('Search') eq 'SAVE') {
print "
Changes to \"", $table, "_Search_HTML.page\" have been saved.
";
}
## if user is following setup path give a link to follow
elsif ($query->param('setup') eq 'follow') {
print "
Before you customize your Search page you can ",
"set up the Result page
";
}
## tell them want link to put in other pages
print "
Add this anchor to allow linking to search page:
\n";
print "<a href=\"",
"http://",$ENV{'SERVER_NAME'},"/dbEase/cgi-bin/search.pl?tableName=", $table,
"\">Link Name</a>";
## give them butoons
print $query->start_form(-action=>'./script_util.pl');
print $query->hidden('tableName', "$table");
print $query->hidden('File', "$HTML");
print $query->hidden('script','../search.pl');
print "| ";
## save button
print $query->submit(-name=>'Search', -value=>'SAVE');
print " | ";
## revert button (reverts back to most recently save version)
print $query->submit(-name=>'EDIT_Search_Page', -value=>'REVERT');
$query->param('searchables', "@searchable");
#for ($one = 0; $one <= $#searchable; $one++) {
print $query->hidden('searchables');#, "$searchable[$one]");
#}
print " | ";
## button to change input types of existing searchable fields
print $query->submit(-name=>'SETUP Search Page', -value=>'Change Input Types');
print "| ";
## button to view the contents of the buffer
print $query->submit(-name=>'VIEW', -value=>'VIEW Page');
print " | ";
## button to start from all over
## (default template with new searchables and input types)
print $query->submit(-name=>'Start Over', -value=>'Start Over');
print " | ";
## button to change searchable fields
print $query->submit(-name=>'SETUP Search Page', -value=>'Change Searchable Fields');
print " |
|---|
|
|---|
";
print $query->textarea(-name=>'revisions', -default=>"$editFile",
-rows=>30, -columns=>65, -override=>1,
-wrap=>virtual);
print $query->end_form();
print $query->end_html;
exit;
}
############################################################
#
# sub create_Search_HTML_page saves current buffer
#
# sub create_Search_HTML_page creates the /common/dbEase_v103/
# dir (if it doesn't already exist) and create the template
# for search page.
#
#
############################################################
sub create_Search_HTML_page {
my $table = $query->param('tableName');
my $HTML = join '', $DIR, $table,"_Search_HTML.page";
## make $DIR if non-existent
if (!(-e $DIR)) {
mkdir $DIR, 0774;
chmod 0774, $DIR;
}
## open and create $HTML (the search page template)
open (SFILE, "+>$HTML") || print $query->header,
$query->start_html(-title=>"ERROR",
-bgcolor=>"#ffffff"),
"
can't open $HTML :: $!
",
$query->end_html;
## print first part of default values to template
print SFILE $SEARCH1;
## get and process user info (params)
my $input_type;
foreach $key($query->param()) {
$_ = $key;
## if param contains 'input_type_for_' do some work on it
if (s/input_type_for_//e) {
print SFILE "";
print SFILE "| $_ : \n | $_=>", $query->param($key);
$input_type = $query->param($key);
}
## if param contains 'match_' its the match for above .. lets do some work
elsif (s/match_//e) {
if ($input_type eq 'textbox' ||
$input_type eq 'pop-up menu (num)') {
print SFILE " match=>",$query->param($key),
" |
\n";
}
elsif ($input_type eq 'pop-up menu (char)') {
print SFILE " match=>EXACT\n";
}
else {
print SFILE "\n";
}
}
}
print SFILE $SEARCH2;
close(SFILE);
return;
}
############################################################
#
# sub result_fields provides an interface to specify fields
# to be displayed on result screen.
# sub result_fields expects at least 'SETUP Result Page' and
# 'tableName' get this far.
# 'SETUP Result Page' == 'Change ORDER/RPS' -> gonna change
# order or rps (results per screen)
# 'SETUP Result Page' == 'Change Displayed Fields' ->
# gonna change display fields
# 'setup' == 'follow' -> is user following setup path
#
# sub result_fields Passes :
# "displayables" -> fields to show on result screen
# 'tableName' duh!
# 'setup' if playing follow the leader
# 'selected_result' == 'SUBMIT'
#
############################################################
sub result_fields {
## if user wants to chane order and/or rps go there
if ($query->param('SETUP Result Page') eq 'Change ORDER/RPS') {
&result_choices();
}
print $query->header;
print $query->start_html(-title=>"Select Displayed Fields",
-bgcolor=>"#ffffff");
## help
print "";
print "HELP
";
my $table = $query->param('tableName');
print "Select 'Displayed Fields' for $table.";
## if user is changing an exist Result Page tell 'em what is gonna happen
if ($query->param('SETUP Result Page') eq 'Change Displayed Fields') {
print "Fields that :- .. were in result page and are selected again will remain in their original position.
- .. are not selected again will be removed, but any text around the removed field will remain.
- .. are new to the result page will be placed at the end.
\n";
}
## get some db info
my $sth = $dbh->listfields($table);
my $noCols = $sth->numfields - 1;
my @colnames = $sth->name;
my @result_fields;
## set up array of result fields
for ($i = 0; $i < $noCols; $i++) { push(@result_fields, $i); }
push (@result_fields," all ");
print $query->start_form(-action=>'./script_util.pl'), "\n";
print $query->hidden('tableName','$table');
## if user is playing follow the leader give 'em something to follow
if ($query->param('setup') eq 'follow') {
print $query->hidden('setup', 'follow');
}
## checkboxes for fields t display
my @ckboxes = $query->checkbox_group(-name =>"displayables",
-"values"=>[@result_fields],
-nolabels=>1);
print "\n";
print "| Select | Field Name |
\n";
print "| ", $ckboxes[$noCols], " | ALL |
\n";
for ($i = 0; $i < $noCols; $i++) {
print "| ", $ckboxes[$i], " | ",$colnames[$i]," |
\n";
}
print "
";
## red candy-like button
print $query->submit( -name=>'selected_result', -value=>'SUBMIT');
print $query->end_form;
print $query->end_html;
exit;
}
############################################################
#
# sub result_choices provides an interface to specify how
# to order results and num. respults per
# screen.
# sub result_choices expects 'SETUP Result Page' and
# 'tableName to get this far.
#
# 'SETUP Result Page' could be 'Change ORDER/RPS' -> from
# edit screen.
# 'setup' == 'follow' -> follow the leader passes it along
# if playing
#
# sub result_choices Passes :
# 'tableName'
# 'displayed_fields' -> fields to be
# displayed
# 'asc_desc' -> order in ascending or
# descending order.
# "order_by" -> field to have results
# ordered by.
# "RPS" -> results to be displayed per
# screen
# 'Result' -> 'SUBMIT' the submit button
#
############################################################
sub result_choices {
print $query->header;
print $query->start_html(-title=>"Specify Order and Results per screen",
-bgcolor=>"#ffffff");
## help
print "";
print "HELP
";
my $table = $query->param('tableName');
print "Specify
How the Results will be ORDERED
and
How many Results Displayed per Screen (RPS).";
my @result_fields = $query->param('displayables');
my $sth = $dbh->listfields($table);
my $noCols = $sth->numfields - 1;
my @colnames = $sth->name;
## if changing order/rps of existing template (called from editting screen)
if ($query->param('SETUP Result Page') ne 'Change ORDER/RPS') {
my @temp;
my $tstr = join ' ', @result_fields;
if ($tstr =~ / all /) {
## get list of displayable fields
for ($each = 0; $each < $noCols; $each++) {
push(@temp, $colnames[$each]);
}
}
else { foreach $each(@result_fields) { push(@temp, $colnames[$each]); } }
@result_fields = @temp;
}
else {
@result_fields = split / /, $result_fields[0];
}
print $query->start_form(-action=>'./script_util.pl');
print $query->hidden('tableName', '$table');
## playing follow the leader ???
if ($query->param('setup') eq 'follow') {
print $query->hidden('setup', 'follow');
}
## pass 'displayed_fields'
print $query->hidden('displayed_fields', "@result_fields");
print "\n";
print "| \nOrder Results In | ";
## radio buttons for order asc/desc
print "\n", $query->radio_group(-name=>'asc_desc',
-"values"=>['Ascending Order',
'Descending Order'],
-default=>'Ascending Order',
-linebreak=>'true');
print " | \nBY";
print " | ";
## what field to order by
print $query->popup_menu(-name=>"order_by",
-"values"=>[@result_fields]), " |
";
print "
|
| Display | ";
## num of result to show per screen
print " ", $query->textfield(-name=>"RPS",
-size=>3,
-default=>5);
print " | Results Per Screen (RPS)";
print " |
|---|
\n",
## can't .. resist the .. bright colorful candy-like button
$query->submit(-label=>"SUBMIT", -name=>'Result', -value=>'SUBMIT');
print $query->end_form;
print $query->end_html;
exit;
}
###############################################################################
#
# sub edit_result_html provides an interface to modify any
# html in the result page.
#
# sub edit_result_html should be passed 'tableName'
# could be passed :
# 'Result' == 'SUBMIT' -> show result page
# 'Result' == 'SAVE' -> to save buffer
# 'BACK' -> coming back from view screen
# 'changed_text' -> contents of edit buffer
# 'EDIT_Result_Page' == 'REVERT' -> duh!
# 'SETUP Result Page' == 'Change Input Types' ->
# duh!
# 'Resultables' -> what are the existing
# Resultable fields .. needed by
# sub Result_choices
# 'SETUP Result Page'
# 'VIEW' == 'VIEW Page' duh!
# 'Start Over' == 'Start Over' duh!
# 'SETUP Result Page' ==
# 'Change Searchable Fields'
# -> to change the searchable fields
# 'revisions' == (the edit buffer)
# 'displayed_fields' -> fields to display
# 'asc_desc' -> ascending/descending order
# 'order_by' -> what field to order by
# 'RPS' -> results per screen
#
# sub edit_result_html Passes most of these params back to other subs.
#
###############################################################################
sub edit_result_html {
my $editFile = "";
my $table = $query->param('tableName');
my $HTML = join '', $DIR, $table,"_Result_HTML.page";
## if file does not exist create it.
if (!(-e $HTML)) {
if ($query->param('Result') eq 'SUBMIT') {
&create_Result_HTML_page();
}
## else user is cahanging something
else {
&result_fields();
}
print $query->header;
print $query->start_html(-title=>"EDIT Result Page",
-bgcolor=>"#ffffff");
## help
print "";
print "HELP
";
print "Edit $table Result HTML Page";
## open file and put in edit buffer
open (RFILE, "$HTML") || die print "can't opem $HTML : $!";
while () {
$editFile = "$editFile$_";
if ($_ =~ //) {
@temp = split /|=>/, $_, 3;
if ($temp[1] =~ /displayed fields/) {
$temp[2] =~ s/displayed fields|<\/MSQL_TAG>//g;
@displayable = split /, /, $temp[2];
}
}
}
close(RFILE);
}
## were comming back from a viewing put back what was originally in buffer
## not the file.
elsif ($query->param('BACK') eq 'BACK') {
print $query->header;
print $query->start_html(-title=>"EDIT Result Page",
-bgcolor=>"#ffffff");
print "";
print "HELP
";
print "Edit $table Result HTML Page";
$editFile = $query->param('changed_text');
my $find = $editFile;
my @temp = split /displayed fields=>/, $find;
@temp = split /<\/MSQL_TAG>/, $temp[1],2;
@displayable = split /, /, $temp[0];
}
## else put in buffer what is in the file and new changes
elsif ($query->param('Result') eq 'SUBMIT') {
print $query->header;
print $query->start_html(-title=>"EDIT Result Page",
-bgcolor=>"#ffffff");
print "";
print "HELP
";
print "Edit $table Result HTML Page";
## parsing stuff
my $temp_params = $query->param('displayed_fields');
$temp_params =~ s/ /, /g;
$temp_params =~ s/\n|\r//eg;
@displayable = split /, /, $temp_params;
my @on_screen = ();
$temp_params =
join '', "displayed fields=>$temp_params", "";
push(@msql,"displayed fields");
push(@msql,$temp_params);
## order ..
if ($query->param('asc_desc') eq 'Ascending Order') {
$temp_params = "ASC";
}
else { $temp_params = "DESC"; }
## .. by what field
$temp_params = join ' ', $query->param('order_by'), $temp_params;
## put some stuff in arrays and var for easy passing
$temp_params =
join '',"ORDER BY $temp_params", "";
push(@msql,"ORDER BY");
push(@msql,$temp_params);
$temp_params =
join '', "RPS=>", $query->param('RPS'), "";
push(@msql,"RPS");
push(@msql,$temp_params);
%msqlTags = @msql;
@key = keys %msqlTags;
## open file to put in buffer
open (RFILE, "$HTML") || die print "can't opem $HTML : $!";
while () {
if ($_ =~ //) {
## lots of parsing to find and to save certain info to vars
my @msql_call = split //,$_;
$editFile = "$editFile$msql_call[0]";
for ($i = 1; $i <= $#msql_call; $i++) {
@temp = split /<\/MSQL_TAG>/, $msql_call[$i],2;
if ($temp[0] =~ /=>/) {
my @temp2 = split /=>/, $temp[0];
$editFile = "$editFile$msqlTags{$temp2[0]}$temp[1]";
}
elsif ($temp[0] =~ /ORDER BY/) {
$editFile = "$editFile$msqlTags{'ORDER BY'}$temp[1]";
}
elsif ($temp[0] =~ /START_LOOP/) {
$editFile =
join '', $editFile, "", $temp[0],
"<\/MSQL_TAG>", $temp[1];
}
elsif ($temp[0] =~ /END_LOOP/) {
my @not_on_screen = ();
my @f = split /=>|<\/MSQL_TAG>/, $msqlTags{'displayed fields'};
@f = split /, /, $f[1];
foreach $field(@f) {
if (!(grep { /$field/ } @on_screen)) {
push(@not_on_screen, $field);
}
}
## keep track of what was and what now is to be displayed
foreach $field(@not_on_screen) {
$editFile =
join '', $editFile, "", $field, "<\/MSQL_TAG>\n";
}
$editFile =
join '', $editFile, "\n", $temp[0],
"<\/MSQL_TAG>", $temp[1];
}
else {
if ($msqlTags{'displayed fields'} =~ /$temp[0]/) {
$editFile =
join '', $editFile, "", $temp[0],
"<\/MSQL_TAG>", $temp[1];
push(@on_screen, $temp[0]);
}
else { $editFile = join '', $editFile, $temp[1]; }
}
}
}
else { $editFile = "$editFile$_"; }
}
close(RFILE);
print "
You must SAVE to make these changes permenent.";
}
## else just show existing file
else {
print $query->header;
print $query->start_html(-title=>"EDIT Result Page",
-bgcolor=>"#ffffff");
print "";
print "HELP
";
print "Edit $table Result HTML Page";
$editFile = "";
open (RFILE, "$HTML") || die print "can't opem $HTML : $!";
while () {
$editFile = "$editFile$_";
if ($_ =~ //) {
@temp = split /|=>/g, $_;
if ($temp[1] =~ /displayed fields/) {
$temp[2] =~ s/displayed fields|<\/MSQL_TAG>//g;
@displayable = split /, /, $temp[2];
}
}
}
close(RFILE);
}
## if user save file tell 'em that it was done
if ($query->param('Result') eq 'SAVE') {
print "
Changes to \"",
$table, "_Result_HTML.page\" have been saved.
";
}
## palying follow the leader ???
elsif ($query->param('setup') eq 'follow') {
print "
Before you customize your Result page you can ",
"insert some data to $table
";
}
## buttons, buttons, and more buttons .. which one to choose
print $query->start_form(-action=>'./script_util.pl');
print $query->hidden('tableName', "$table");
## file to be saved or viewed
print $query->hidden('File', "$HTML");
## script to use to view file ( ie ./go_get.pl -> for result page
## ./search.pl -> for search page
print $query->hidden('script','../go_get.pl');
print "| ";
## button to save
print $query->submit(-value=>'SAVE', -name=>'Result');
print " | ";
## button to revert back to most currently save results file
print $query->submit(-name=>'EDIT_Result_Page', -value=>'REVERT');
## displayable fields
print $query->hidden('displayables', "@displayable");
print " | ";
## button to change rps and/or order
print $query->submit(-name=>'SETUP Result Page', -value=>'Change ORDER/RPS');
print "| ";
## button to view page
print $query->submit(-name=>'VIEW', -value=>'VIEW Page');
print " | ";
## button to start over
print $query->submit(-name=>'Start Over', -value=>'Start Over');
print " | ";
## button to change fields to display
print $query->submit(-name=>'SETUP Result Page', -
value=>'Change Displayed Fields');
print " |
|---|
|
|---|
";
## currently what's in the buffer
print $query->textarea(-name=>'revisions', -default=>"$editFile",
-rows=>30, -columns=>65, -override=>1,
-wrap=>virtual);
print $query->end_form();
print $query->end_html;
exit;
}
############################################################
#
# sub create_Result_HTML_page saves current buffer
#
# sub create_Result_HTML_page creates the /common/dbEase_v103/
# dir (if it doesn't already exist) and create the template
# for result page.
#
############################################################
sub create_Result_HTML_page {
my $table = $query->param('tableName');
my $HTML = join '', $DIR, $table,"_Result_HTML.page";
## make $DIR if non-existent
if (!(-e $DIR)) {
mkdir $DIR, 0774;
chmod 0774, $DIR;
}
## open and create $HTML (the result page template)
open (RFILE, "+>$HTML") || print $query->header,
$query->start_html(-title=>"ERROR",
-bgcolor=>"#ffffff"),
"
can't create $HTML :: $!
",
$query->end_html;
## get and process user info (params) and throw in file
my $temp_params = $query->param('displayed_fields');
$temp_params =~ s/ /, /g;
print RFILE "displayed fields=>", $temp_params, "\n";
if ($query->param('asc_desc') eq 'Ascending Order') { $temp_params = "ASC"; }
else { $temp_params = "DESC"; }
$temp_params = join ' ', $query->param('order_by'), $temp_params;
print RFILE "ORDER BY ", $temp_params, "\n";
print RFILE "RPS=>", $query->param('RPS'), "\n";
print RFILE "\n";
print RFILE "\n\n";
## print first part of default values to template
print RFILE $RESULTS1;
## put rest of info into file
my @dispfields = split / /, $query->param('displayed_fields');
$temp_params = $query->param('order_by');
print RFILE "\n";
print RFILE "", $temp_params, "";
foreach $field(@dispfields) {
if ($field ne $temp_params) {
print RFILE "
\n";
print RFILE "", $field, "";
}
}
print RFILE "
$RESULTS2";
close(RFILE);
return;
}
############################################################
#
# sub save saves the file passed and returns to appropriate
# edit page.
#
############################################################
sub save {
my $HTML = $query->param('File');
open (SRFILE, "+>$HTML")
|| print "can't open $HTML :: $! Changes NOT Saved";
print SRFILE $query->param('revisions');
close(SRFILE);
if ($query->param('Search')) { &edit_search_html(); }
else { &edit_result_html(); }
exit;
}
############################################################
#
# sub which_table provides a user interface to select which
# table to create/modify the search/result
# page.
# gets call if param 'tableName' does not exist.
#
############################################################
sub which_table {
my $which = $query->param('sr');
print $query->header();
print $query->start_html(-title=>"Search/Result Page Setup/Edit",
-bgcolor=>"#ffffff");
print "";
print "HELP
";
print "Modify the $which Page.
";
## get tables in db
my @arr = $dbh->listtables;
## Added 20050404 by brettm to remove ticks around db namea
## This was caused by use of newer mysql perl module.
foreach (@arr){
s/^\`//g;
s/\`$//g;
}
@arr = sort { lc($a) cmp lc($b) }@arr;
my $script = join '_', "EDIT", $which, "Page";
print $query->start_form(-method=>GET,
-action=>'./script_util.pl');
## result or search ??
print $query->hidden("$script", "$which");
print "";
print "For which table ? \n";
## list of avaliable tables in db
print $query->popup_menu(-name=>"tableName",
-"values"=>[@arr]);
print "
";
## BUTTON
print $query->submit(-name=>"Modify"), "\n";
print $query->end_form;
print $query->end_html;
exit;
}
############################################################
#
# sub start_over deletes old file (search/results template)
# and starts anew.
#
# sub start_over expects 'tableName' and 'File'.
#
############################################################
sub start_over {
my $table = $query->param('tableName');
my @delfile = ($query->param('File'));
my $page;
## if user was already made aware what is going to happen go ahead and
## delete the file
if ($query->param('CONTINUE')) {
unlink @delfile;
if ($delfile[0] =~ /Result/) { &edit_result_html; }
else { &edit_search_html(); }
}
## if user was not made aware what is going to happen ..
## .. let 'em know
else {
print $query->header;
print $query->start_html(-title=>"Warning",
-bgcolor=>"#ffffff");
## help
print "";
print "HELP
";
## what to delete and where to go back to
if ($delfile[0] =~ /Result/) {
$page = "Result";
$edit = "EDIT_Result_Page";
}
else {
$page = "Search";
$edit = "EDIT_Search_Page";
}
print "",
"This action will DELETE your current $page Page for $table",
"
You will be required to recreate $table 's $page Page.
";
print "| " ,
$query->start_form(-method=>GET,
-action=>'./script_util.pl');
print $query->hidden('tableName','$table');
print $query->hidden('File', "$delfile[0]");
print $query->hidden('Start Over', 'Start Over');
## button do continue (ie delete existing file and recreate it
print $query->submit(-name=>'CONTINUE', value=>"CONTINUE"), "\n";
print $query->end_form;
print " | ",
$query->start_form(-method=>GET,
-action=>'./script_util.pl');
print $query->hidden('tableName','$table');
print $query->hidden("$edit","$edit");
## cancel the process
print $query->submit(-name=>"CANCEL", value=>"CANCEL"), "\n";
print $query->end_form, " |
|---|
\n";
print $query->end_html;
}
exit;
}
## ------ end o' script