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

1.1       www         1: # The LearningOnline Network
                      2: # Pick a course
                      3: #
1.26    ! albertel    4: # $Id: lonpickcourse.pm,v 1.25 2005/01/28 19:26:54 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
1.26    ! albertel   45:     my $html=&Apache::lonxml::xmlbegin();
1.1       www        46:     $r->print(<<ENDDOCUMENT);
1.26    ! albertel   47: $html
1.1       www        48: <head>
                     49: <title>The LearningOnline Network with CAPA</title>
                     50: </head>
                     51: ENDDOCUMENT
1.5       www        52: # Get parameters from query string
1.1       www        53:     &Apache::loncommon::get_unprocessed_cgi
                     54:         ($ENV{'QUERY_STRING'},['domainfilter','descriptfilter',
1.13      albertel   55: 			       'sincefilter','form','cnumelement',
1.19      raeburn    56: 			       'cdomelement','cnameelement','roleelement',
1.20      raeburn    57:                                'pickedcourse','instcodefilter','ownerfilter']);
1.5       www        58: # domain filter and selection
1.1       www        59:     my $domainfilter=$ENV{'form.domainfilter'};
                     60:     $domainfilter=~s/\W//g;
1.4       www        61:     unless ($domainfilter) { $domainfilter=''; }
                     62:     my $domainselectform=&Apache::loncommon::select_dom_form($domainfilter,
                     63:                                                           'domainfilter',1);
1.5       www        64: # description filter
1.1       www        65:     my $descriptfilter=$ENV{'form.descriptfilter'};
1.4       www        66:     unless ($descriptfilter) { $descriptfilter=''; }
1.16      albertel   67:     my $listdescript=&HTML::Entities::encode($descriptfilter,'<>&"');
1.20      raeburn    68: # institutional code filter
                     69:     my $instcodefilter=$ENV{'form.instcodefilter'};
                     70:     unless ($instcodefilter) { $instcodefilter=''; }
                     71:     my $listinstcode=&HTML::Entities::encode($instcodefilter,'<>&"');
                     72: # course owner filter
                     73:     my $ownerfilter=$ENV{'form.ownerfilter'};
                     74:     unless ($ownerfilter) { $ownerfilter=''; }
                     75:     my $listowner=&HTML::Entities::encode($ownerfilter,'<>&"');
1.5       www        76: # last course activity filter and selection
1.1       www        77:     my $sincefilter=$ENV{'form.sincefilter'};
1.5       www        78:     $sincefilter=~s/[^\d-]//g;
                     79:     unless ($sincefilter) { $sincefilter=-1; }
                     80:     my $sincefilterform=&Apache::loncommon::select_form($sincefilter,
                     81:        'sincefilter',('-1'=>'',
                     82:                       '86400' => 'today',
                     83:                       '604800' => 'last week',
                     84:                       '2592000' => 'last month',
                     85:                       '7776000' => 'last three months',
                     86:                       '15552000' => 'last six months',
1.9       albertel   87:                       '31104000' => 'last year',
                     88:                       'select_form_order' =>
                     89:                       ['-1','86400','604800','2592000','7776000',
                     90: 		      '15552000','31104000']));
1.19      raeburn    91: # if called from loncreateuser, report sections, then close
                     92:     my ($loaditem,$seclist);
                     93:     my $num_sections = 0;
                     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) {
1.22      raeburn   157:         opener.document.$ENV{"form.form"}.currsec.multiple=false
                    158:         opener.document.$ENV{"form.form"}.currsec.size=1;
1.21      raeburn   159:         opener.document.$ENV{"form.form"}.currsec.options[0] = new Option('No existing sections','',false,false)
1.19      raeburn   160:     }
                    161:     else {
1.23      raeburn   162:         if (numSections == 1) {
                    163:             opener.document.$ENV{"form.form"}.currsec.multiple=false;
                    164:             opener.document.$ENV{"form.form"}.currsec.size=1;
                    165:             opener.document.$ENV{"form.form"}.currsec.options[0] = new Option('Select','',true,true);
                    166:             opener.document.$ENV{"form.form"}.currsec.options[1] = new Option('No section','',false,false) 
                    167:             opener.document.$ENV{"form.form"}.currsec.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
1.19      raeburn   168:         }
                    169:         else {
1.23      raeburn   170:             for (var i=0; i<numSections; i++) {
                    171:                 opener.document.$ENV{"form.form"}.currsec.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    172:             }
                    173:             opener.document.$ENV{"form.form"}.currsec.multiple=true
                    174:             if (numSections < 3) {
                    175:                 opener.document.$ENV{"form.form"}.currsec.size=numSections;
                    176:             }
                    177:             else {
                    178:                 opener.document.$ENV{"form.form"}.currsec.size=3;
                    179:             }
                    180:             opener.document.$ENV{"form.form"}.currsec.options[0].selected = false
1.19      raeburn   181:         }
                    182:     }
                    183:     self.close()
1.1       www       184: }
                    185: </script>
1.18      raeburn   186: $submitopener
1.4       www       187: <form method="post">
1.5       www       188: <input type="hidden" name="cnumelement" value="$ENV{'form.cnumelement'}" />
                    189: <input type="hidden" name="cdomelement" value="$ENV{'form.cdomelement'}" />
1.13      albertel  190: $name_input
1.5       www       191: <input type="hidden" name="form" value="$ENV{'form.form'}" />
1.18      raeburn   192: $roleelement
1.8       www       193: $lt{'cac'}: $sincefilterform
1.4       www       194: <br />
1.8       www       195: $lt{'cdo'}: $domainselectform
1.4       www       196: <br />
1.20      raeburn   197: $lt{'cin'}:
                    198: <input type="text" name="instcodefilter" size="10" value="$listinstcode" />
                    199: <br />
                    200: $lt{'cow'}:
                    201: <input type="text" name="ownerfilter" size="10" value="$listowner" />
                    202: <br />
1.8       www       203: $lt{'cde'}:
1.15      www       204: <input type="text" name="descriptfilter" size="40" value="$listdescript" />
1.5       www       205: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4       www       206: </form>
1.5       www       207: <hr />
1.1       www       208: ENDSCRIPT
1.2       www       209: # ---------------------------------------------------------------- Get the data
1.5       www       210:     if ($ENV{'form.gosearch'}) {
1.8       www       211:         $r->print(&mt('Searching').' ...<br />&nbsp;<br />');
1.6       www       212:         $r->rflush();
1.5       www       213: 	unless ($descriptfilter) { $descriptfilter='.'; }
1.20      raeburn   214:         unless ($instcodefilter) { $instcodefilter='.'; }
                    215:         unless ($ownerfilter) { $ownerfilter='.'; }
1.5       www       216:         my $timefilter=($sincefilter==-1?1:time-$sincefilter);
                    217: 	my %courses=
                    218: 	    &Apache::lonnet::courseiddump
1.20      raeburn   219: 	    ($domainfilter,$descriptfilter,$timefilter,$instcodefilter,$ownerfilter);
1.19      raeburn   220: 	$r->print('<form name="courselist">');
1.10      albertel  221: 	my %by_descrip;
                    222: 	foreach my $course (keys %courses) {
1.17      raeburn   223:             my $descr;
                    224:             if ($courses{$course} =~ m/^([^:]*):/) {
                    225:                 $descr = &Apache::lonnet::unescape($1);
                    226:             } else {
                    227:                 $descr = &Apache::lonnet::unescape($courses{$course});
                    228:             }
1.24      raeburn   229:             my $description = lc($descr);
1.25      raeburn   230:             push (@{$by_descrip{$description}}, $course);
1.10      albertel  231: 	}
                    232: 	foreach my $description (sort(keys(%by_descrip))) {
1.24      raeburn   233:             foreach my $course (@{$by_descrip{$description}}) {
                    234: 	        my $cleandesc=&HTML::Entities::encode($description,'<>&"');
                    235: 	        $cleandesc=~s/'/\\'/g;
                    236: 	        my ($cdom,$cnum)=split(/\_/,$course);
                    237:                 my ($descr,$instcode,$owner) = split/:/,$courses{$course};
                    238: 	        $r->print('<input type="button" value="Select" onClick="gochoose('.
                    239: 		      "'".$cnum."','".$cdom."','".$cleandesc."')".'" /> '.$description.' ('.
                    240: 		      ($Apache::lonnet::domaindescription{$cdom}?
                    241:                        $Apache::lonnet::domaindescription{$cdom}:$cdom).")");
                    242:                 unless ($instcode eq '') {
                    243:                     $r->print(" - ".&Apache::lonnet::unescape($instcode));
                    244:                 }
                    245:                 unless ($owner eq '') {
                    246:                     $r->print(", owner - ".&Apache::lonnet::unescape($owner));
                    247:                 }
                    248:                 $r->print("<br />\n");
                    249:             }
1.5       www       250: 	}
1.12      albertel  251: 	if (!%courses) { $r->print(&mt('None found')); }
1.19      raeburn   252:         $r->print('<input type="hidden" name="form" value="'.$ENV{'form.form'}.'" />'."\n".
                    253:                    '<input type="hidden" name="pickedcourse" value="" />'."\n".
                    254:                    '<input type="hidden" name="cnumelement" value="'.$ENV{'form.cnumelement'}.'" />'."\n".
                    255:                    '<input type="hidden" name="cdomelement" value="'.$ENV{'form.cdomelement'}.'" />'."\n".
                    256:                    '</form>');
1.2       www       257:     }
1.5       www       258:     $r->print('</body></html>');
1.1       www       259:     return OK;
1.18      raeburn   260: }
1.1       www       261: 
                    262: 1;
                    263: __END__

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