Annotation of loncom/interface/lonpickcourse.pm, revision 1.19
1.1 www 1: # The LearningOnline Network
2: # Pick a course
3: #
1.19 ! raeburn 4: # $Id: lonpickcourse.pm,v 1.18 2004/11/12 23:29:56 raeburn Exp $
1.1 www 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;
1.8 www 36: use Apache::lonlocal;
1.1 www 37:
38: sub handler {
39: my $r = shift;
1.8 www 40: &Apache::loncommon::content_type($r,'text/html');
1.1 www 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
1.5 www 51: # Get parameters from query string
1.1 www 52: &Apache::loncommon::get_unprocessed_cgi
53: ($ENV{'QUERY_STRING'},['domainfilter','descriptfilter',
1.13 albertel 54: 'sincefilter','form','cnumelement',
1.19 ! raeburn 55: 'cdomelement','cnameelement','roleelement',
! 56: 'pickedcourse']);
1.5 www 57: # domain filter and selection
1.1 www 58: my $domainfilter=$ENV{'form.domainfilter'};
59: $domainfilter=~s/\W//g;
1.4 www 60: unless ($domainfilter) { $domainfilter=''; }
61: my $domainselectform=&Apache::loncommon::select_dom_form($domainfilter,
62: 'domainfilter',1);
1.5 www 63: # description filter
1.1 www 64: my $descriptfilter=$ENV{'form.descriptfilter'};
1.4 www 65: unless ($descriptfilter) { $descriptfilter=''; }
1.16 albertel 66: my $listdescript=&HTML::Entities::encode($descriptfilter,'<>&"');
1.5 www 67: # last course activity filter and selection
1.1 www 68: my $sincefilter=$ENV{'form.sincefilter'};
1.5 www 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',
1.9 albertel 78: '31104000' => 'last year',
79: 'select_form_order' =>
80: ['-1','86400','604800','2592000','7776000',
81: '15552000','31104000']));
1.19 ! raeburn 82: # if called from loncreateuser, report sections, then close
! 83: my ($loaditem,$seclist);
! 84: my $num_sections = 0;
! 85: my @sections = ();
! 86: if ($ENV{'form.form'} eq 'cu' && $ENV{'form.pickedcourse'}) {
! 87: $loaditem = 'onLoad="setSections()"';
! 88: my ($cdom,$cnum) = split/_/,$ENV{'form.pickedcourse'};
! 89: my %sections_count = ();
! 90: $num_sections = &Apache::loncommon::get_sections($cdom,$cnum,\%sections_count);
! 91: my @sections = ();
! 92: if ($num_sections > 0) {
! 93: @sections = (sort {$a <=> $b} keys %sections_count);
! 94: $seclist = join('","',@sections);
! 95: }
! 96: }
! 97: $r->print(&Apache::loncommon::bodytag("Selecting a Course",undef,$loaditem));
1.8 www 98: my %lt=&Apache::lonlocal::texthash(
99: 'cac' => 'Course Activity',
100: 'cde' => 'Course Description',
101: 'cdo' => 'Course Domain');
1.13 albertel 102: my ($name_code,$name_input);
103: if (defined($ENV{'form.cnameelement'}) && $ENV{'form.cnameelement'} ne '') {
104: $name_code = "opener.document.$ENV{'form.form'}.$ENV{'form.cnameelement'}.value=cdesc;";
105: $name_input ='<input type="hidden" name="cnameelement" value="'.
106: $ENV{'form.cnameelement'}.'" />';
107: }
1.18 raeburn 108: my $submitopener = '';
109: my $autosubmit = '';
110: my $roleelement = '';
1.19 ! raeburn 111: my $lastaction = 'self.close()';
! 112: if ($ENV{'form.form'} eq 'cu') {
! 113: $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
! 114: 'document.courselist.submit();';
! 115: }
1.18 raeburn 116: my $roledom = $ENV{'form.roleelement'};
117: if ($roledom) {
118: $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
119: $submitopener = &Apache::lonroles::processpick($roledom);
120: $autosubmit = 'process_pick("'.$roledom.'")';
121: }
1.1 www 122: $r->print(<<ENDSCRIPT);
123: <script>
1.13 albertel 124: function gochoose(cname,cdom,cdesc) {
125: $name_code
1.19 ! raeburn 126: var openerForm = "$ENV{'form.form'}";
! 127: opener.document.$ENV{'form.form'}.$ENV{'form.cnumelement'}.value=cname;
! 128: if (openerForm == 'cu' || openerForm == 'rolechoice') {
! 129: opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'}.value=cdom;
! 130: }
! 131: else {
! 132: var slct=opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'};
! 133: var i;
! 134: for (i=0;i<slct.length;i++) {
! 135: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
! 136: }
1.1 www 137: }
1.18 raeburn 138: $autosubmit
1.19 ! raeburn 139: $lastaction
! 140: }
! 141:
! 142: function setSections() {
! 143: var numSections = $num_sections
! 144: var sectionsArray = new Array("$seclist")
! 145: opener.document.$ENV{"form.form"}.currsec.length = 0
! 146: if (numSections == 0) {
! 147: opener.document.$ENV{"form.form"}.currsec.options[0] = new Option('No existing sections','-1',false,false)
! 148: }
! 149: else {
! 150: for (var i=0; i<numSections; i++) {
! 151: opener.document.$ENV{"form.form"}.currsec.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
! 152: }
! 153: opener.document.$ENV{"form.form"}.currsec.multiple=true
! 154: if (numSections < 3) {
! 155: opener.document.$ENV{"form.form"}.currsec.size=numSections;
! 156: }
! 157: else {
! 158: opener.document.$ENV{"form.form"}.currsec.size=3;
! 159: }
! 160: opener.document.$ENV{"form.form"}.currsec.options[0].selected = false
! 161: }
! 162: self.close()
1.1 www 163: }
164: </script>
1.18 raeburn 165: $submitopener
1.4 www 166: <form method="post">
1.5 www 167: <input type="hidden" name="cnumelement" value="$ENV{'form.cnumelement'}" />
168: <input type="hidden" name="cdomelement" value="$ENV{'form.cdomelement'}" />
1.13 albertel 169: $name_input
1.5 www 170: <input type="hidden" name="form" value="$ENV{'form.form'}" />
1.18 raeburn 171: $roleelement
1.8 www 172: $lt{'cac'}: $sincefilterform
1.4 www 173: <br />
1.8 www 174: $lt{'cdo'}: $domainselectform
1.4 www 175: <br />
1.8 www 176: $lt{'cde'}:
1.15 www 177: <input type="text" name="descriptfilter" size="40" value="$listdescript" />
1.5 www 178: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4 www 179: </form>
1.5 www 180: <hr />
1.1 www 181: ENDSCRIPT
1.2 www 182: # ---------------------------------------------------------------- Get the data
1.5 www 183: if ($ENV{'form.gosearch'}) {
1.8 www 184: $r->print(&mt('Searching').' ...<br /> <br />');
1.6 www 185: $r->rflush();
1.5 www 186: unless ($descriptfilter) { $descriptfilter='.'; }
187: my $timefilter=($sincefilter==-1?1:time-$sincefilter);
188: my %courses=
189: &Apache::lonnet::courseiddump
190: ($domainfilter,$descriptfilter,$timefilter);
1.19 ! raeburn 191: $r->print('<form name="courselist">');
1.10 albertel 192: my %by_descrip;
193: foreach my $course (keys %courses) {
1.17 raeburn 194: my $descr;
195: if ($courses{$course} =~ m/^([^:]*):/) {
196: $descr = &Apache::lonnet::unescape($1);
197: } else {
198: $descr = &Apache::lonnet::unescape($courses{$course});
199: }
200: $by_descrip{lc($descr)}=$course;
1.10 albertel 201: }
202: foreach my $description (sort(keys(%by_descrip))) {
203: my $course=$by_descrip{$description};
1.17 raeburn 204: my $cleandesc=&HTML::Entities::encode($description,'<>&"');
1.13 albertel 205: $cleandesc=~s/'/\\'/g;
1.10 albertel 206: my ($cdom,$cnum)=split(/\_/,$course);
1.5 www 207: $r->print('<input type="button" value="Select" onClick="gochoose('.
1.17 raeburn 208: "'".$cnum."','".$cdom."','".$cleandesc."')".'" /> '.$description.' ('.
1.3 www 209: ($Apache::lonnet::domaindescription{$cdom}?
1.5 www 210: $Apache::lonnet::domaindescription{$cdom}:$cdom).
211: ")<br />\n");
212: }
1.12 albertel 213: if (!%courses) { $r->print(&mt('None found')); }
1.19 ! raeburn 214: $r->print('<input type="hidden" name="form" value="'.$ENV{'form.form'}.'" />'."\n".
! 215: '<input type="hidden" name="pickedcourse" value="" />'."\n".
! 216: '<input type="hidden" name="cnumelement" value="'.$ENV{'form.cnumelement'}.'" />'."\n".
! 217: '<input type="hidden" name="cdomelement" value="'.$ENV{'form.cdomelement'}.'" />'."\n".
! 218: '</form>');
1.2 www 219: }
1.5 www 220: $r->print('</body></html>');
1.1 www 221: return OK;
1.18 raeburn 222: }
1.1 www 223:
224: 1;
225: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>