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

1.1       www         1: # The LearningOnline Network
                      2: # Pick a course
                      3: #
1.20    ! raeburn     4: # $Id: lonpickcourse.pm,v 1.19 2004/11/23 18:03:04 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',
1.20    ! raeburn    56:                                'pickedcourse','instcodefilter','ownerfilter']);
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.20    ! raeburn    67: # institutional code filter
        !            68:     my $instcodefilter=$ENV{'form.instcodefilter'};
        !            69:     unless ($instcodefilter) { $instcodefilter=''; }
        !            70:     my $listinstcode=&HTML::Entities::encode($instcodefilter,'<>&"');
        !            71: # course owner filter
        !            72:     my $ownerfilter=$ENV{'form.ownerfilter'};
        !            73:     unless ($ownerfilter) { $ownerfilter=''; }
        !            74:     my $listowner=&HTML::Entities::encode($ownerfilter,'<>&"');
1.5       www        75: # last course activity filter and selection
1.1       www        76:     my $sincefilter=$ENV{'form.sincefilter'};
1.5       www        77:     $sincefilter=~s/[^\d-]//g;
                     78:     unless ($sincefilter) { $sincefilter=-1; }
                     79:     my $sincefilterform=&Apache::loncommon::select_form($sincefilter,
                     80:        'sincefilter',('-1'=>'',
                     81:                       '86400' => 'today',
                     82:                       '604800' => 'last week',
                     83:                       '2592000' => 'last month',
                     84:                       '7776000' => 'last three months',
                     85:                       '15552000' => 'last six months',
1.9       albertel   86:                       '31104000' => 'last year',
                     87:                       'select_form_order' =>
                     88:                       ['-1','86400','604800','2592000','7776000',
                     89: 		      '15552000','31104000']));
1.19      raeburn    90: # if called from loncreateuser, report sections, then close
                     91:     my ($loaditem,$seclist);
                     92:     my $num_sections = 0;
                     93:     my @sections = ();
                     94:     if ($ENV{'form.form'} eq 'cu' && $ENV{'form.pickedcourse'}) {
                     95:         $loaditem = 'onLoad="setSections()"';
                     96:         my ($cdom,$cnum) = split/_/,$ENV{'form.pickedcourse'};
                     97:         my %sections_count = ();
                     98:         $num_sections = &Apache::loncommon::get_sections($cdom,$cnum,\%sections_count);
                     99:         my @sections = ();
                    100:         if ($num_sections > 0) {
                    101:             @sections = (sort {$a <=> $b} keys %sections_count);
                    102:             $seclist = join('","',@sections);
                    103:         }
                    104:     }
                    105:     $r->print(&Apache::loncommon::bodytag("Selecting a Course",undef,$loaditem));
1.8       www       106:     my %lt=&Apache::lonlocal::texthash(
                    107: 				       'cac' => 'Course Activity',
                    108: 				       'cde' => 'Course Description',
1.20    ! raeburn   109: 				       'cdo' => 'Course Domain',
        !           110:                                        'cin' => 'Course Institutional Code',
        !           111:                                        'cow' => "Course Owner's usename");
1.13      albertel  112:     my ($name_code,$name_input);
                    113:     if (defined($ENV{'form.cnameelement'}) && $ENV{'form.cnameelement'} ne '') {
                    114: 	$name_code = "opener.document.$ENV{'form.form'}.$ENV{'form.cnameelement'}.value=cdesc;";
                    115: 	$name_input ='<input type="hidden" name="cnameelement" value="'.
                    116: 	    $ENV{'form.cnameelement'}.'" />';
                    117:     }
1.18      raeburn   118:     my $submitopener = '';
                    119:     my $autosubmit = '';
                    120:     my $roleelement = '';
1.19      raeburn   121:     my $lastaction = 'self.close()';
                    122:     if ($ENV{'form.form'} eq 'cu') {
                    123:         $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
                    124:                       'document.courselist.submit();';
                    125:     }
1.18      raeburn   126:     my $roledom = $ENV{'form.roleelement'};
                    127:     if ($roledom) {
                    128:         $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
                    129:         $submitopener = &Apache::lonroles::processpick($roledom);
                    130:         $autosubmit = 'process_pick("'.$roledom.'")';
                    131:     }
1.1       www       132:     $r->print(<<ENDSCRIPT);
                    133: <script>
1.13      albertel  134: function gochoose(cname,cdom,cdesc) {
                    135:     $name_code
1.19      raeburn   136:     var openerForm = "$ENV{'form.form'}";
                    137:     opener.document.$ENV{'form.form'}.$ENV{'form.cnumelement'}.value=cname;
                    138:     if (openerForm == 'cu' || openerForm == 'rolechoice') {
                    139:          opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'}.value=cdom;
                    140:     }
                    141:     else {
                    142:         var slct=opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'};
                    143:         var i;
                    144:         for (i=0;i<slct.length;i++) {
                    145:             if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
                    146:         }
1.1       www       147:     }
1.18      raeburn   148:     $autosubmit
1.19      raeburn   149:     $lastaction
                    150: }
                    151: 
                    152: function setSections() {
                    153:     var numSections = $num_sections
                    154:     var sectionsArray = new Array("$seclist")
                    155:     opener.document.$ENV{"form.form"}.currsec.length = 0
                    156:     if (numSections == 0) {
                    157:         opener.document.$ENV{"form.form"}.currsec.options[0] = new Option('No existing sections','-1',false,false)
                    158:     }
                    159:     else {
                    160:         for (var i=0; i<numSections; i++) {
                    161:             opener.document.$ENV{"form.form"}.currsec.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    162:         }
                    163:         opener.document.$ENV{"form.form"}.currsec.multiple=true
                    164:         if (numSections < 3) {
                    165:             opener.document.$ENV{"form.form"}.currsec.size=numSections;
                    166:         }
                    167:         else {
                    168:             opener.document.$ENV{"form.form"}.currsec.size=3;
                    169:         }
                    170:         opener.document.$ENV{"form.form"}.currsec.options[0].selected = false
                    171:     }
                    172:     self.close()
1.1       www       173: }
                    174: </script>
1.18      raeburn   175: $submitopener
1.4       www       176: <form method="post">
1.5       www       177: <input type="hidden" name="cnumelement" value="$ENV{'form.cnumelement'}" />
                    178: <input type="hidden" name="cdomelement" value="$ENV{'form.cdomelement'}" />
1.13      albertel  179: $name_input
1.5       www       180: <input type="hidden" name="form" value="$ENV{'form.form'}" />
1.18      raeburn   181: $roleelement
1.8       www       182: $lt{'cac'}: $sincefilterform
1.4       www       183: <br />
1.8       www       184: $lt{'cdo'}: $domainselectform
1.4       www       185: <br />
1.20    ! raeburn   186: $lt{'cin'}:
        !           187: <input type="text" name="instcodefilter" size="10" value="$listinstcode" />
        !           188: <br />
        !           189: $lt{'cow'}:
        !           190: <input type="text" name="ownerfilter" size="10" value="$listowner" />
        !           191: <br />
1.8       www       192: $lt{'cde'}:
1.15      www       193: <input type="text" name="descriptfilter" size="40" value="$listdescript" />
1.5       www       194: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4       www       195: </form>
1.5       www       196: <hr />
1.1       www       197: ENDSCRIPT
1.2       www       198: # ---------------------------------------------------------------- Get the data
1.5       www       199:     if ($ENV{'form.gosearch'}) {
1.8       www       200:         $r->print(&mt('Searching').' ...<br />&nbsp;<br />');
1.6       www       201:         $r->rflush();
1.5       www       202: 	unless ($descriptfilter) { $descriptfilter='.'; }
1.20    ! raeburn   203:         unless ($instcodefilter) { $instcodefilter='.'; }
        !           204:         unless ($ownerfilter) { $ownerfilter='.'; }
1.5       www       205:         my $timefilter=($sincefilter==-1?1:time-$sincefilter);
                    206: 	my %courses=
                    207: 	    &Apache::lonnet::courseiddump
1.20    ! raeburn   208: 	    ($domainfilter,$descriptfilter,$timefilter,$instcodefilter,$ownerfilter);
1.19      raeburn   209: 	$r->print('<form name="courselist">');
1.10      albertel  210: 	my %by_descrip;
                    211: 	foreach my $course (keys %courses) {
1.17      raeburn   212:             my $descr;
                    213:             if ($courses{$course} =~ m/^([^:]*):/) {
                    214:                 $descr = &Apache::lonnet::unescape($1);
                    215:             } else {
                    216:                 $descr = &Apache::lonnet::unescape($courses{$course});
                    217:             }
                    218:             $by_descrip{lc($descr)}=$course;
1.10      albertel  219: 	}
                    220: 	foreach my $description (sort(keys(%by_descrip))) {
                    221: 	    my $course=$by_descrip{$description};
1.17      raeburn   222: 	    my $cleandesc=&HTML::Entities::encode($description,'<>&"');
1.13      albertel  223: 	    $cleandesc=~s/'/\\'/g;
1.10      albertel  224: 	    my ($cdom,$cnum)=split(/\_/,$course);
1.5       www       225: 	    $r->print('<input type="button" value="Select" onClick="gochoose('.
1.17      raeburn   226: 		  "'".$cnum."','".$cdom."','".$cleandesc."')".'" /> '.$description.' ('.
1.3       www       227: 		  ($Apache::lonnet::domaindescription{$cdom}?
1.5       www       228:                    $Apache::lonnet::domaindescription{$cdom}:$cdom).
                    229:                  ")<br />\n");
                    230: 	}
1.12      albertel  231: 	if (!%courses) { $r->print(&mt('None found')); }
1.19      raeburn   232:         $r->print('<input type="hidden" name="form" value="'.$ENV{'form.form'}.'" />'."\n".
                    233:                    '<input type="hidden" name="pickedcourse" value="" />'."\n".
                    234:                    '<input type="hidden" name="cnumelement" value="'.$ENV{'form.cnumelement'}.'" />'."\n".
                    235:                    '<input type="hidden" name="cdomelement" value="'.$ENV{'form.cdomelement'}.'" />'."\n".
                    236:                    '</form>');
1.2       www       237:     }
1.5       www       238:     $r->print('</body></html>');
1.1       www       239:     return OK;
1.18      raeburn   240: }
1.1       www       241: 
                    242: 1;
                    243: __END__

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