1: # The LearningOnline Network
2: # Pick a course
3: #
4: # $Id: lonpickcourse.pm,v 1.14 2004/03/31 05:24:00 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::lonpickcourse;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon;
34: use Apache::loncoursedata;
35: use Apache::lonnet;
36: use Apache::lonlocal;
37:
38: sub handler {
39: my $r = shift;
40: &Apache::loncommon::content_type($r,'text/html');
41: $r->send_http_header;
42: return OK if $r->header_only;
43:
44: # ------------------------------------------------------------ Print the screen
45: $r->print(<<ENDDOCUMENT);
46: <html>
47: <head>
48: <title>The LearningOnline Network with CAPA</title>
49: </head>
50: ENDDOCUMENT
51: # Get parameters from query string
52: &Apache::loncommon::get_unprocessed_cgi
53: ($ENV{'QUERY_STRING'},['domainfilter','descriptfilter',
54: 'sincefilter','form','cnumelement',
55: 'cdomelement','cnameelement']);
56: # domain filter and selection
57: my $domainfilter=$ENV{'form.domainfilter'};
58: $domainfilter=~s/\W//g;
59: unless ($domainfilter) { $domainfilter=''; }
60: my $domainselectform=&Apache::loncommon::select_dom_form($domainfilter,
61: 'domainfilter',1);
62: # description filter
63: my $descriptfilter=$ENV{'form.descriptfilter'};
64: $descriptfilter=~s/[^\w\s]//g;
65: unless ($descriptfilter) { $descriptfilter=''; }
66:
67: # last course activity filter and selection
68: my $sincefilter=$ENV{'form.sincefilter'};
69: $sincefilter=~s/[^\d-]//g;
70: unless ($sincefilter) { $sincefilter=-1; }
71: my $sincefilterform=&Apache::loncommon::select_form($sincefilter,
72: 'sincefilter',('-1'=>'',
73: '86400' => 'today',
74: '604800' => 'last week',
75: '2592000' => 'last month',
76: '7776000' => 'last three months',
77: '15552000' => 'last six months',
78: '31104000' => 'last year',
79: 'select_form_order' =>
80: ['-1','86400','604800','2592000','7776000',
81: '15552000','31104000']));
82:
83: $r->print(&Apache::loncommon::bodytag("Selecting a Course"));
84: my %lt=&Apache::lonlocal::texthash(
85: 'cac' => 'Course Activity',
86: 'cde' => 'Course Description',
87: 'cdo' => 'Course Domain');
88: my ($name_code,$name_input);
89: if (defined($ENV{'form.cnameelement'}) && $ENV{'form.cnameelement'} ne '') {
90: $name_code = "opener.document.$ENV{'form.form'}.$ENV{'form.cnameelement'}.value=cdesc;";
91: $name_input ='<input type="hidden" name="cnameelement" value="'.
92: $ENV{'form.cnameelement'}.'" />';
93: }
94: $r->print(<<ENDSCRIPT);
95: <script>
96: function gochoose(cname,cdom,cdesc) {
97: $name_code
98: opener.document.$ENV{"form.form"}.$ENV{'form.cnumelement'}.value=cname;
99: var slct=opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'};
100: var i;
101: for (i=0;i<slct.length;i++) {
102: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
103: }
104: self.close();
105: }
106: </script>
107: <form method="post">
108: <input type="hidden" name="cnumelement" value="$ENV{'form.cnumelement'}" />
109: <input type="hidden" name="cdomelement" value="$ENV{'form.cdomelement'}" />
110: $name_input
111: <input type="hidden" name="form" value="$ENV{'form.form'}" />
112:
113: $lt{'cac'}: $sincefilterform
114: <br />
115: $lt{'cdo'}: $domainselectform
116: <br />
117: $lt{'cde'}:
118: <input type="text" name="descriptfilter" size="40" value="$descriptfilter" />
119: <p><input type="submit" name="gosearch" value="Search" /></p>
120: </form>
121: <hr />
122: ENDSCRIPT
123: # ---------------------------------------------------------------- Get the data
124: if ($ENV{'form.gosearch'}) {
125: $r->print(&mt('Searching').' ...<br /> <br />');
126: $r->rflush();
127: unless ($descriptfilter) { $descriptfilter='.'; }
128: my $timefilter=($sincefilter==-1?1:time-$sincefilter);
129: my %courses=
130: &Apache::lonnet::courseiddump
131: ($domainfilter,$descriptfilter,$timefilter);
132: $r->print('<form>');
133: my %by_descrip;
134: foreach my $course (keys %courses) {
135: $by_descrip{lc($courses{$course})}=$course;
136: }
137: foreach my $description (sort(keys(%by_descrip))) {
138: my $course=$by_descrip{$description};
139: my $cleandesc=&HTML::Entities::encode($courses{$course},'<>&"');
140: $cleandesc=~s/'/\\'/g;
141: my ($cdom,$cnum)=split(/\_/,$course);
142: $r->print('<input type="button" value="Select" onClick="gochoose('.
143: "'".$cnum."','".$cdom."','".$cleandesc."')".'" /> '.$courses{$course}.' ('.
144: ($Apache::lonnet::domaindescription{$cdom}?
145: $Apache::lonnet::domaindescription{$cdom}:$cdom).
146: ")<br />\n");
147: }
148: if (!%courses) { $r->print(&mt('None found')); }
149: $r->print('</form>');
150: }
151: $r->print('</body></html>');
152: return OK;
153: }
154:
155: 1;
156: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>