ossp-pkg/quos/quos.cgi
1.8
#!/usr/opkg/bin/perl -w
##
## OSSP quos - Query On Steroids
## Copyright (c) 2004 Ralf S. Engelschall <rse@engelschall.com>
## Copyright (c) 2004 The OSSP Project <http://www.ossp.org/>
##
## This file is part of OSSP quos, a Web user interface for querying
## a database which can be found at http://www.ossp.org/pkg/tool/quos/.
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
## USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
##
## quos.cgi: web user interface
##
require 5.008;
use strict;
use CGI;
use String::Divert;
use IO::File;
# internal handling of fatal errors
BEGIN {
$SIG{__DIE__} = sub {
my ($msg) = @_;
my $hint = '';
if ($msg =~ m|line\s+(\d+)|) {
my $line = $1;
my $io = new IO::File "<$0";
my @code = $io->getlines();
$io->close();
my $i = -1;
$hint = join("", map { s/^/sprintf("%d: ", $line+$i++)/se; $_; } @code[$line-2..$line]);
}
print STDOUT
"Content-Type: text/html; charset=ISO-8859-1\n" .
"\n" .
"<html>\n" .
" <head>\n" .
" <title>OSSP quos: GURU MEDITATION</title>\n" .
" <style type=\"text/css\">\n" .
" HTML {\n" .
" width: 100%;\n" .
" height: auto;\n" .
" }\n" .
" BODY {\n" .
" background: #cccccc;\n" .
" margin: 0 0 0 0;\n" .
" padding: 0 0 0 0;\n" .
" }\n" .
" DIV.canvas {\n" .
" background: #000000;\n" .
" border: 20px solid #000000;\n" .
" }\n" .
" DIV.error1 {\n" .
" border-top: 4px solid #cc3333;\n" .
" border-left: 4px solid #cc3333;\n" .
" border-right: 4px solid #cc3333;\n" .
" border-bottom: 4px solid #cc3333;\n" .
" padding: 10px 10px 10px 10px;\n" .
" font-family: sans-serif, helvetica, arial;\n" .
" background: #000000;\n" .
" color: #cc3333;\n" .
" }\n" .
" DIV.error2 {\n" .
" border-top: 4px solid #000000;\n" .
" border-left: 4px solid #000000;\n" .
" border-right: 4px solid #000000;\n" .
" border-bottom: 4px solid #000000;\n" .
" padding: 10px 10px 10px 10px;\n" .
" font-family: sans-serif, helvetica, arial;\n" .
" background: #000000;\n" .
" color: #cc3333;\n" .
" }\n" .
" SPAN.title {\n" .
" font-size: 200%;\n" .
" font-weight: bold;\n" .
" }\n" .
" TT.text {\n" .
" font-weight: bold;\n" .
" }\n" .
" </style>\n" .
" <script language=\"JavaScript\">\n" .
" var count = 0;\n" .
" function blinker() {\n" .
" var obj = document.getElementById('error');\n" .
" if (count++ % 2 == 0) {\n" .
" obj.className = 'error1';\n" .
" }\n" .
" else {\n" .
" obj.className = 'error2';\n" .
" }\n" .
" setTimeout('blinker()', 1000);\n" .
" }\n" .
" </script>\n" .
" </head>\n" .
" <body onLoad=\"setTimeout('blinker()', 1);\">\n" .
" <div class=\"canvas\">\n" .
" <div id=\"error\" class=\"error1\">\n" .
" <span class=\"title\">OSSP quos: GURU MEDITATION</span>\n" .
" <p>\n" .
" <tt class=\"text\">\n" .
" $msg<br>\n" .
" </tt>\n" .
" <pre>\n$hint</pre>\n" .
" </div>\n" .
" </div>\n" .
" </body>\n" .
"</html>\n";
exit(0);
};
}
# create objects
my $cgi = new CGI;
my $html = new String::Divert;
$html->overload(1);
##
## Read Config File
##
my $cfg = {
-cols => 4,
-rows => 7,
};
# FIXME
##
## Generate Canvas
##
# generate Javascript utility functions
$html .= "<script language=\"JavaScript\">\n" .
"<!--\n" .
"function colorize(obj, def) {\n" .
" if (obj.value == def) { obj.className = 'default'; }\n" .
" else { obj.className = 'changed'; }\n" .
" return true;\n" .
"}\n" .
"//-->\n" .
"</script>\n";
# generate outer canvas
$html .= "<table class=\"quos\">\n";
$html .= " "; $html->fold("quos");
$html .= "</table>\n";
$html >> "quos";
# generate browse part
$html .= "<tr>\n";
$html .= " <td class=\"browse\">\n";
$html .= " <span class=\"title\">Browse</span><br>\n";
$html .= " "; $html->fold("browse");
$html .= " </td>\n";
$html .= "</tr>\n";
# generate query part
$html .= "<tr>\n";
$html .= " <td class=\"query\">\n";
$html .= " <span class=\"title\">Query</span><br>\n";
$html .= " "; $html->fold("query");
$html .= " </td>\n";
$html .= "</tr>\n";
# generate view part
$html .= "<tr>\n";
$html .= " <td class=\"view\">\n";
$html .= " <span class=\"title\">View</span><br>\n";
$html .= " "; $html->fold("view");
$html .= " </td>\n";
$html .= "</tr>\n";
# generate result part
$html .= "<tr>\n";
$html .= " <td class=\"result\">\n";
$html .= " <span class=\"title\">Result</span><br>\n";
$html .= " "; $html->fold("result");
$html .= " </td>\n";
$html .= "</tr>\n";
##
## Generate Browser Part
##
$html >> "browse";
$html .= "FIXME";
$html << 1;
##
## Generate Query Part
##
$html >> "query";
my $nr_cols = ($cgi->param('nr_cols') || $cfg->{-cols});
my $nr_rows = ($cgi->param('nr_rows') || $cfg->{-rows});
# render outer form canvas
$html .= $cgi->start_form;
$html .= "<table>\n";
$html .= " <tr>\n";
$html .= " <td class=\"expr\">\n";
$html .= " "; $html->fold("query-form-expr");
$html .= " </td>\n";
$html .= " </tr>\n";
$html .= " <tr>\n";
$html .= " <td class=\"button\">\n";
$html .= " "; $html->fold("query-form-button");
$html .= " </td>\n";
$html .= " </tr>\n";
$html .= " <tr>\n";
$html .= " <td class=\"define\">\n";
$html .= " "; $html->fold("query-form-define");
$html .= " </td>\n";
$html .= " </tr>\n";
$html .= "</table>\n";
$html .= $cgi->end_form;
# render expression part
$html >> "query-form-expr";
$html .= "<table>\n";
for (my $i = 0; $i < $nr_cols; $i++) {
$html .= "<tr>\n";
for (my $j = $nr_cols - 1; $j >= 0; $j--) {
$html .= " <td>\n";
my $id = sprintf("lo%02d%02d", $j, $i);
$html .= " " . $cgi->popup_menu(
-id => $id,
-name => $id,
-values => [' ', '(', ')', '!', '&', '|'],
-default => ' ',
-class => 'default',
-onChange => "return colorize(this.form.$id, ' ');",
-onBlur => "return colorize(this.form.$id, ' ');",
) . "\n";
$html .= " </td>\n";
}
$html .= " <td>\n";
my $id = sprintf("fn%02d", $i);
$html .= " " . $cgi->popup_menu(
-id => $id,
-name => $id,
-values => ['', 'name', 'description', 'foo'], # FIXME
-default => '', # FIXME
-class => 'default',
-onChange => "return colorize(this.form.$id, '');",
-onBlur => "return colorize(this.form.$id, '');",
) . "\n";
$html .= " </td>\n";
$html .= " <td>\n";
$id = sprintf("fo%02d", $i);
$html .= " " . $cgi->popup_menu(
-id => $id,
-name => $id,
-values => ['', '==', '!=', '<', '<=', '>', '>=', '=~', '!~'],
-default => '',
-class => 'default',
-onChange => "return colorize(this.form.$id, '');",
-onBlur => "return colorize(this.form.$id, '');",
). "\n";
$html .= " </td>\n";
$html .= " <td>\n";
$id = sprintf("fv%02d", $i);
$html .= " " . $cgi->textfield(
-id => $id,
-name => $id,
-default => '',
-class => 'default',
-onChange => "return colorize(this.form.$id, '');",
-onBlur => "return colorize(this.form.$id, '');",
-onMouseOut => "return colorize(this.form.$id, '');",
);
$html .= " </td>\n";
$html .= "</tr>\n";
}
$html .= "</table>\n";
$html << 1;
# render button part
$html >> "query-form-button";
$html .= "<table>\n";
$html .= " <tr>\n";
$html .= " <td>";
$html .= " " . "← " . $cgi->popup_menu(
-name => "nr_cols",
-values => [ 0..9 ],
-default => $nr_cols,
) . "\n";
$html .= " " . "↓ " . $cgi->popup_menu(
-name => "nr_rows",
-values => [1..9],
-default => $nr_rows,
) . "\n";
$html .= " </td>\n";
$html .= " <td>\n";
$html .= " " . $cgi->submit(
-name => 'act_matrix_upd',
-value => 'update',
-class => 'update'
) . "\n";
$html .= " </td>\n";
$html .= " <td>\n";
$html .= " " . $cgi->submit(
-name => 'act_matrix_clear',
-value => 'clear',
-class => 'clear'
) . "\n";
$html .= " </td>\n";
$html .= " <td>\n";
$html .= " " . $cgi->submit(
-name => 'act_matrix_submit',
-value => 'submit',
-class => 'submit'
) . "\n";
$html .= " </td>\n";
$html .= " </tr>\n";
$html .= "</table>\n";
$html << 1;
# render define part
$html >> "query-form-define";
$html .= "<table>\n";
$html .= " <tr>\n";
$html .= " <td>\n";
$html .= " " . $cgi->popup_menu(
-id => "namexx",
-name => "namexx",
-values => ['HTML: by-group', 'HTML: by-xxx', 'TXT: by-group'], # FIXME
-default => 'HTML: by-group', # FIXME
-class => 'nameget',
) . "\n";
$html .= " </td>\n";
$html .= " <td>\n";
$html .= " " . $cgi->submit(
-name => 'act_matrix_clear',
-value => 'load',
-class => 'load'
) . "\n";
$html .= " </td>\n";
$html .= " <td>\n";
$html .= " " . $cgi->submit(
-name => 'act_matrix_submit',
-value => 'delete',
-class => 'delete'
) . "\n";
$html .= " </td>\n";
$html .= " </tr>\n";
$html .= " <tr>\n";
$html .= " <td>\n";
$html .= " " . $cgi->textfield(
-name => 'name_persquery',
-value => '',
-class => 'nameset'
) . "\n";
$html .= " </td>\n";
$html .= " <td>\n";
$html .= " " . $cgi->submit(
-name => 'act_matrix_clear',
-value => 'save',
-class => 'save'
) . "\n";
$html .= " </td>\n";
$html .= " <td>\n";
$html .= " " . $cgi->submit(
-name => 'act_matrix_hyperlink',
-value => 'hyperlink',
-class => 'hyperlink'
) . "\n";
$html .= " </td>\n";
$html .= " </tr>\n";
$html .= "</table>\n";
$html << 1;
$html << 1;
##
## Generate View Part
##
$html >> "view";
$html .= "FIXME";
$html << 1;
##
## Generate Result Part
##
$html >> "result";
$html .= "FIXME<br>";
foreach my $key ($cgi->param) {
$html .= "<strong>$key</strong> -> ";
my @values = $cgi->param($key);
$html .= join(", ", @values) . "<br>\n";
}
$html << 1;
##
## Generate HTTP Reponse
##
# read HTML skeleton
my $io = new IO::File "<quos.html"
or die "unable to read HTML skeleton file \"quos.html\"";
my $skel = '';
$skel .= $_ while (<$io>);
$io->close();
# undivert HTML output and wrap with skeleton
$html->undivert(0);
$skel =~ s|\%BODY\%|$html|s;
$html = $skel;
# create HTTP response
my $http = $cgi->header(
-type => 'text/html',
-expires => '+10s'
);
$http .= $html;
print STDOUT $http;
# die gracefully ;-)
exit(0);
__END__
=pod
=head1 NAME
B<OSSP quos> - Query On Steroids
=head1 DESCRIPTION
...FIXME...
=head1 LOGICAL LAYOUT
1. Browse
- Groups
. Hyperlinks
2. Query
- Groups
. Field (database schema)
. Operator (compare)
. Value (depends on compare)
3. View
- Selection predefined output format
- OSSP var based formatting string
- ordering
- save custom view
4. Result
- based on View
=cut