Annotation of loncom/metadata_database/lonsql.pm, revision 1.4

1.1       harris41    1: # The LearningOnline Network with CAPA
                      2: # Metadata Database Handler
                      3: #
                      4: # 02/20/2001 Scott Harrison
                      5: 
                      6: package Apache::lonsql;
                      7: 
                      8: use strict;
1.2       harris41    9: use Opcode;
                     10: use Apache::lonnet;
                     11: use Apache::Constants qw(:common :http);
1.1       harris41   12: 
1.3       harris41   13: use CGI;
1.2       harris41   14: 
                     15: # ================================================================ Main handler
                     16: #
                     17: # Interactive call to screen
                     18: #
                     19: #
                     20: 
                     21: sub handler {
                     22:     my $r=shift;
1.3       harris41   23: 
                     24:     if ($r->header_only) {
                     25:       $r->content_type('text/html');
                     26:       $r->send_http_header;
                     27:       return OK;
                     28:     }
                     29: 
                     30: # ------------------------------------------------------------------- Open page
                     31: 
                     32:     my $query=new CGI;
                     33: 
                     34:     my $searchquery;
                     35:     my $searchresults;
1.4     ! harris41   36:     my @regexps;
        !            37:     my $logic;
        !            38:     my $logic_operator;
1.3       harris41   39: 
                     40:     if ($query->{'SUBMIT'}) {
1.4     ! harris41   41: 	$logic_operator=$query->{'logic'}->[0];
        !            42: 	$searchquery="<BR>Your search was:\n";
        !            43: 	$searchquery.="<BR><STRONG>$_</STRONG>: " . $query->{$_}->[0] . "\n" for ('title','author','subject','notes','abstract','mime','language','creationdate','lastrevisiondate','owner','copyright');
        !            44: 	for ('title','author','subject','notes','abstract','mime','language','creationdate','lastrevisiondate','owner','copyright') {
        !            45: 	    push @regexps, ($_ . " regexp '" . $query->{$_}->[0] . "'") if $query->{$_}->[0];
        !            46: 	}
        !            47:         $logic="where " . join(" $logic_operator ",@regexps) if @regexps;
1.3       harris41   48:     }
1.4     ! harris41   49:     my $sqlcommand="SELECT * FROM metadata $logic";
        !            50:     $searchquery.="<P><STRONG>SQL command:</STRONG> $sqlcommand</P>\n";
1.3       harris41   51: 
                     52:     $r->content_type('text/html');
                     53:     $r->header_out('Cache-control','no-cache');
                     54:     $r->header_out('Pragma','no-cache');
                     55:     $r->send_http_header;
1.2       harris41   56:     my $output=<<END;
                     57: 
1.3       harris41   58: <P>
                     59: <H1>MySQL search engine</H1>
                     60: <FORM METHOD="GET" ACTION="/adm/sqltest">
                     61: <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>
                     62: <TR><TD><STRONG>title</STRONG></TD>
                     63: <TD><INPUT TYPE="TEXT" NAME="title"></TD>
                     64: <TR><TD><STRONG>author</STRONG></TD>
                     65: <TD><INPUT TYPE="TEXT" NAME="author"></TD>
                     66: <TR><TD><STRONG>subject</STRONG></TD>
                     67: <TD><INPUT TYPE="TEXT" NAME="subject"></TD>
                     68: <TR><TD><STRONG>notes</STRONG></TD>
                     69: <TD><INPUT TYPE="TEXT" NAME="notes"></TD>
                     70: <TR><TD><STRONG>abstract</STRONG></TD>
                     71: <TD><INPUT TYPE="TEXT" NAME="abstract"></TD>
                     72: <TR><TD><STRONG>mime</STRONG></TD>
                     73: <TD><INPUT TYPE="TEXT" NAME="mime"></TD>
                     74: <TR><TD><STRONG>language</STRONG></TD>
                     75: <TD><INPUT TYPE="TEXT" NAME="language"></TD>
                     76: <TR><TD><STRONG>creationdate</STRONG></TD>
                     77: <TD><INPUT TYPE="TEXT" NAME="creationdate"></TD>
                     78: <TR><TD><STRONG>lastrevisiondate</STRONG></TD>
                     79: <TD><INPUT TYPE="TEXT" NAME="lastrevisiondate"></TD>
                     80: <TR><TD><STRONG>owner</STRONG></TD>
                     81: <TD><INPUT TYPE="TEXT" NAME="owner"></TD>
                     82: <TR><TD><STRONG>copyright</STRONG></TD>
                     83: <TD><INPUT TYPE="TEXT" NAME="copyright"></TD>
                     84: </TR>
                     85: </TABLE>
                     86: <SELECT NAME="logic">
                     87: <OPTION SELECTED>and</OPTION>
                     88: <OPTION>or</OPTION>
                     89: </SELECT>
                     90: <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="SEARCH MySQL DATABASE">
                     91: </P>
                     92: <P>
                     93: $searchquery
                     94: </P>
                     95: <P>
                     96: $searchresults
                     97: </P>
1.2       harris41   98: END
                     99:     $r->print($output);
                    100:     return OK;
                    101: }
1.1       harris41  102: 
                    103: 
                    104: 
                    105: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>