Annotation of loncom/interface/lonpickcourse.pm, revision 1.18

1.1       www         1: # The LearningOnline Network
                      2: # Pick a course
                      3: #
1.18    ! raeburn     4: # $Id: lonpickcourse.pm,v 1.17 2004/06/29 14:56:32 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.18    ! raeburn    55: 			       'cdomelement','cnameelement','roleelement']);
1.5       www        56: # domain filter and selection
1.1       www        57:     my $domainfilter=$ENV{'form.domainfilter'};
                     58:     $domainfilter=~s/\W//g;
1.4       www        59:     unless ($domainfilter) { $domainfilter=''; }
                     60:     my $domainselectform=&Apache::loncommon::select_dom_form($domainfilter,
                     61:                                                           'domainfilter',1);
1.5       www        62: # description filter
1.1       www        63:     my $descriptfilter=$ENV{'form.descriptfilter'};
1.4       www        64:     unless ($descriptfilter) { $descriptfilter=''; }
1.16      albertel   65:     my $listdescript=&HTML::Entities::encode($descriptfilter,'<>&"');
1.5       www        66: # last course activity filter and selection
1.1       www        67:     my $sincefilter=$ENV{'form.sincefilter'};
1.5       www        68:     $sincefilter=~s/[^\d-]//g;
                     69:     unless ($sincefilter) { $sincefilter=-1; }
                     70:     my $sincefilterform=&Apache::loncommon::select_form($sincefilter,
                     71:        'sincefilter',('-1'=>'',
                     72:                       '86400' => 'today',
                     73:                       '604800' => 'last week',
                     74:                       '2592000' => 'last month',
                     75:                       '7776000' => 'last three months',
                     76:                       '15552000' => 'last six months',
1.9       albertel   77:                       '31104000' => 'last year',
                     78:                       'select_form_order' =>
                     79:                       ['-1','86400','604800','2592000','7776000',
                     80: 		      '15552000','31104000']));
1.1       www        81:        
                     82:     $r->print(&Apache::loncommon::bodytag("Selecting a Course"));
1.8       www        83:     my %lt=&Apache::lonlocal::texthash(
                     84: 				       'cac' => 'Course Activity',
                     85: 				       'cde' => 'Course Description',
                     86: 				       'cdo' => 'Course Domain');
1.13      albertel   87:     my ($name_code,$name_input);
                     88:     if (defined($ENV{'form.cnameelement'}) && $ENV{'form.cnameelement'} ne '') {
                     89: 	$name_code = "opener.document.$ENV{'form.form'}.$ENV{'form.cnameelement'}.value=cdesc;";
                     90: 	$name_input ='<input type="hidden" name="cnameelement" value="'.
                     91: 	    $ENV{'form.cnameelement'}.'" />';
                     92:     }
1.18    ! raeburn    93:     my $submitopener = '';
        !            94:     my $autosubmit = '';
        !            95:     my $roleelement = '';
        !            96:     my $roledom = $ENV{'form.roleelement'};
        !            97:     if ($roledom) {
        !            98:         $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
        !            99:         $submitopener = &Apache::lonroles::processpick($roledom);
        !           100:         $autosubmit = 'process_pick("'.$roledom.'")';
        !           101:     }
1.1       www       102:     $r->print(<<ENDSCRIPT);
                    103: <script>
1.13      albertel  104: function gochoose(cname,cdom,cdesc) {
                    105:     $name_code
                    106:     opener.document.$ENV{"form.form"}.$ENV{'form.cnumelement'}.value=cname;
1.1       www       107:     var slct=opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'};
                    108:     var i;
                    109:     for (i=0;i<slct.length;i++) {
1.7       www       110:         if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.1       www       111:     }
1.18    ! raeburn   112:     $autosubmit
1.1       www       113:     self.close();
                    114: }
                    115: </script>
1.18    ! raeburn   116: $submitopener
1.4       www       117: <form method="post">
1.5       www       118: <input type="hidden" name="cnumelement" value="$ENV{'form.cnumelement'}" />
                    119: <input type="hidden" name="cdomelement" value="$ENV{'form.cdomelement'}" />
1.13      albertel  120: $name_input
1.5       www       121: <input type="hidden" name="form" value="$ENV{'form.form'}" />
1.18    ! raeburn   122: $roleelement
1.8       www       123: $lt{'cac'}: $sincefilterform
1.4       www       124: <br />
1.8       www       125: $lt{'cdo'}: $domainselectform
1.4       www       126: <br />
1.8       www       127: $lt{'cde'}:
1.15      www       128: <input type="text" name="descriptfilter" size="40" value="$listdescript" />
1.5       www       129: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4       www       130: </form>
1.5       www       131: <hr />
1.1       www       132: ENDSCRIPT
1.2       www       133: # ---------------------------------------------------------------- Get the data
1.5       www       134:     if ($ENV{'form.gosearch'}) {
1.8       www       135:         $r->print(&mt('Searching').' ...<br />&nbsp;<br />');
1.6       www       136:         $r->rflush();
1.5       www       137: 	unless ($descriptfilter) { $descriptfilter='.'; }
                    138:         my $timefilter=($sincefilter==-1?1:time-$sincefilter);
                    139: 	my %courses=
                    140: 	    &Apache::lonnet::courseiddump
                    141: 	    ($domainfilter,$descriptfilter,$timefilter);
                    142: 	$r->print('<form>');
1.10      albertel  143: 	my %by_descrip;
                    144: 	foreach my $course (keys %courses) {
1.17      raeburn   145:             my $descr;
                    146:             if ($courses{$course} =~ m/^([^:]*):/) {
                    147:                 $descr = &Apache::lonnet::unescape($1);
                    148:             } else {
                    149:                 $descr = &Apache::lonnet::unescape($courses{$course});
                    150:             }
                    151:             $by_descrip{lc($descr)}=$course;
1.10      albertel  152: 	}
                    153: 	foreach my $description (sort(keys(%by_descrip))) {
                    154: 	    my $course=$by_descrip{$description};
1.17      raeburn   155: 	    my $cleandesc=&HTML::Entities::encode($description,'<>&"');
1.13      albertel  156: 	    $cleandesc=~s/'/\\'/g;
1.10      albertel  157: 	    my ($cdom,$cnum)=split(/\_/,$course);
1.5       www       158: 	    $r->print('<input type="button" value="Select" onClick="gochoose('.
1.17      raeburn   159: 		  "'".$cnum."','".$cdom."','".$cleandesc."')".'" /> '.$description.' ('.
1.3       www       160: 		  ($Apache::lonnet::domaindescription{$cdom}?
1.5       www       161:                    $Apache::lonnet::domaindescription{$cdom}:$cdom).
                    162:                  ")<br />\n");
                    163: 	}
1.12      albertel  164: 	if (!%courses) { $r->print(&mt('None found')); }
1.5       www       165:         $r->print('</form>');
1.2       www       166:     }
1.5       www       167:     $r->print('</body></html>');
1.1       www       168:     return OK;
1.18    ! raeburn   169: }
1.1       www       170: 
                    171: 1;
                    172: __END__

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