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

1.1       www         1: # The LearningOnline Network
                      2: # Pick a course
                      3: #
1.31    ! albertel    4: # $Id: lonpickcourse.pm,v 1.30 2005/10/03 23:53:25 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.28      raeburn    57:                                'pickedcourse','instcodefilter',
                     58:                                'ownerfilter','coursefilter']);
1.5       www        59: # domain filter and selection
1.27      albertel   60:     my $domainfilter=$env{'form.domainfilter'};
1.1       www        61:     $domainfilter=~s/\W//g;
1.4       www        62:     unless ($domainfilter) { $domainfilter=''; }
                     63:     my $domainselectform=&Apache::loncommon::select_dom_form($domainfilter,
                     64:                                                           'domainfilter',1);
1.5       www        65: # description filter
1.27      albertel   66:     my $descriptfilter=$env{'form.descriptfilter'};
1.4       www        67:     unless ($descriptfilter) { $descriptfilter=''; }
1.16      albertel   68:     my $listdescript=&HTML::Entities::encode($descriptfilter,'<>&"');
1.20      raeburn    69: # institutional code filter
1.27      albertel   70:     my $instcodefilter=$env{'form.instcodefilter'};
1.20      raeburn    71:     unless ($instcodefilter) { $instcodefilter=''; }
                     72:     my $listinstcode=&HTML::Entities::encode($instcodefilter,'<>&"');
                     73: # course owner filter
1.27      albertel   74:     my $ownerfilter=$env{'form.ownerfilter'};
1.20      raeburn    75:     unless ($ownerfilter) { $ownerfilter=''; }
                     76:     my $listowner=&HTML::Entities::encode($ownerfilter,'<>&"');
1.28      raeburn    77: # course ID filter for DCs only
                     78:     my ($courseidtag,$coursefilter);
                     79:     if ($env{'user.adv'} && $domainfilter && exists($env{'user.role.dc./'.
                     80:                         $domainfilter.'/'})) {
                     81:         $coursefilter=$env{'form.coursefilter'};
                     82:         unless ($coursefilter) { $coursefilter=''; }
                     83:         my $listcourseid=&HTML::Entities::encode($coursefilter,'<>&"');
                     84:         $courseidtag = &mt('LON-CAPA course ID');
                     85:         $courseidtag .= qq|<input type="text" name="coursefilter" size="25" value="$listcourseid" />
                     86:         <br />
                     87:         |;
                     88:     }
1.5       www        89: # last course activity filter and selection
1.27      albertel   90:     my $sincefilter=$env{'form.sincefilter'};
1.5       www        91:     $sincefilter=~s/[^\d-]//g;
                     92:     unless ($sincefilter) { $sincefilter=-1; }
                     93:     my $sincefilterform=&Apache::loncommon::select_form($sincefilter,
                     94:        'sincefilter',('-1'=>'',
                     95:                       '86400' => 'today',
                     96:                       '604800' => 'last week',
                     97:                       '2592000' => 'last month',
                     98:                       '7776000' => 'last three months',
                     99:                       '15552000' => 'last six months',
1.9       albertel  100:                       '31104000' => 'last year',
                    101:                       'select_form_order' =>
                    102:                       ['-1','86400','604800','2592000','7776000',
                    103: 		      '15552000','31104000']));
1.19      raeburn   104: # if called from loncreateuser, report sections, then close
                    105:     my ($loaditem,$seclist);
                    106:     my $num_sections = 0;
1.27      albertel  107:     if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) {
1.19      raeburn   108:         $loaditem = 'onLoad="setSections()"';
1.27      albertel  109:         my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
1.19      raeburn   110:         my %sections_count = ();
                    111:         $num_sections = &Apache::loncommon::get_sections($cdom,$cnum,\%sections_count);
                    112:         my @sections = ();
                    113:         if ($num_sections > 0) {
1.31    ! albertel  114:             @sections = (sort {$a <=> $b} keys(%sections_count));
1.19      raeburn   115:             $seclist = join('","',@sections);
                    116:         }
                    117:     }
1.30      raeburn   118: # if called from rolefilter, setup for multiple course selections.
                    119:     my $multflag = 0;
                    120:     my $jscript;
                    121:     my $title = 'Selecting a course';
                    122:     if ($env{'form.form'} eq 'rolefilter') {
                    123:         $multflag = 1;
                    124:         $title = 'Selecting course(s)';
                    125:     }
                    126:     if ($multflag) {
                    127:         $jscript = &Apache::loncommon::check_uncheck_jscript();
                    128:     }
                    129:     $r->print(&Apache::loncommon::bodytag($title,undef,$loaditem,undef,undef,undef,undef,1));
1.8       www       130:     my %lt=&Apache::lonlocal::texthash(
                    131: 				       'cac' => 'Course Activity',
                    132: 				       'cde' => 'Course Description',
1.20      raeburn   133: 				       'cdo' => 'Course Domain',
                    134:                                        'cin' => 'Course Institutional Code',
                    135:                                        'cow' => "Course Owner's usename");
1.13      albertel  136:     my ($name_code,$name_input);
1.27      albertel  137:     if (defined($env{'form.cnameelement'}) && $env{'form.cnameelement'} ne '') {
                    138: 	$name_code = "opener.document.$env{'form.form'}.$env{'form.cnameelement'}.value=cdesc;";
1.13      albertel  139: 	$name_input ='<input type="hidden" name="cnameelement" value="'.
1.27      albertel  140: 	    $env{'form.cnameelement'}.'" />';
1.13      albertel  141:     }
1.18      raeburn   142:     my $submitopener = '';
                    143:     my $autosubmit = '';
                    144:     my $roleelement = '';
1.19      raeburn   145:     my $lastaction = 'self.close()';
1.27      albertel  146:     if ($env{'form.form'} eq 'cu') {
1.19      raeburn   147:         $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
                    148:                       'document.courselist.submit();';
                    149:     }
1.27      albertel  150:     my $roledom = $env{'form.roleelement'};
1.18      raeburn   151:     if ($roledom) {
                    152:         $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
                    153:         $submitopener = &Apache::lonroles::processpick($roledom);
                    154:         $autosubmit = 'process_pick("'.$roledom.'")';
                    155:     }
1.1       www       156:     $r->print(<<ENDSCRIPT);
                    157: <script>
1.30      raeburn   158: function gochoose(cname,cdom,cdesc,multflag,caller) {
1.27      albertel  159:     var openerForm = "$env{'form.form'}";
1.30      raeburn   160:     courseCount = 0;
                    161:     var courses = '';
                    162:     if (multflag) {
                    163:         for (var j=0; j<document.courselist.course_id.length; j++) {
                    164:             if (document.courselist.course_id[j].checked) {
                    165:                 courses = courses + document.courselist.course_id[j].value + "&&";
                    166:                 courseCount ++;
                    167:             }
                    168:         }
                    169:         opener.document.$env{'form.form'}.coursetotal.value = courseCount;
                    170:         for (var j=0; j<opener.document.$env{'form.form'}.coursepick.length; j++) { 
                    171:             if (opener.document.$env{'form.form'}.coursepick[j].value == 'specific') {  
                    172:                 opener.document.$env{'form.form'}.coursepick[j].checked = true;
                    173:             }
                    174:             else {
                    175:                 opener.document.$env{'form.form'}.coursepick[j].checked = false;
                    176:             }
                    177:         }
                    178:         if (courseCount > 0) {
                    179:             courses = courses.substr(0,courses.length-2);
                    180:             opener.document.$env{'form.form'}.courselist.value = courses
                    181:         }
1.19      raeburn   182:     }
                    183:     else {
1.30      raeburn   184:         $name_code
                    185:         opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
                    186:         if (openerForm == 'cu') {
                    187:             opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
                    188:         }
                    189:         else {
                    190:             var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
                    191:             var i;
                    192:             for (i=0;i<slct.length;i++) {
                    193:                 if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
                    194:             }
1.19      raeburn   195:         }
1.1       www       196:     }
1.18      raeburn   197:     $autosubmit
1.19      raeburn   198:     $lastaction
                    199: }
                    200: 
                    201: function setSections() {
                    202:     var numSections = $num_sections
                    203:     var sectionsArray = new Array("$seclist")
1.27      albertel  204:     opener.document.$env{"form.form"}.currsec.length = 0
1.19      raeburn   205:     if (numSections == 0) {
1.27      albertel  206:         opener.document.$env{"form.form"}.currsec.multiple=false
                    207:         opener.document.$env{"form.form"}.currsec.size=1;
                    208:         opener.document.$env{"form.form"}.currsec.options[0] = new Option('No existing sections','',false,false)
1.19      raeburn   209:     }
                    210:     else {
1.23      raeburn   211:         if (numSections == 1) {
1.27      albertel  212:             opener.document.$env{"form.form"}.currsec.multiple=false;
                    213:             opener.document.$env{"form.form"}.currsec.size=1;
                    214:             opener.document.$env{"form.form"}.currsec.options[0] = new Option('Select','',true,true);
                    215:             opener.document.$env{"form.form"}.currsec.options[1] = new Option('No section','',false,false) 
                    216:             opener.document.$env{"form.form"}.currsec.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
1.19      raeburn   217:         }
                    218:         else {
1.23      raeburn   219:             for (var i=0; i<numSections; i++) {
1.27      albertel  220:                 opener.document.$env{"form.form"}.currsec.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
1.23      raeburn   221:             }
1.27      albertel  222:             opener.document.$env{"form.form"}.currsec.multiple=true
1.23      raeburn   223:             if (numSections < 3) {
1.27      albertel  224:                 opener.document.$env{"form.form"}.currsec.size=numSections;
1.23      raeburn   225:             }
                    226:             else {
1.27      albertel  227:                 opener.document.$env{"form.form"}.currsec.size=3;
1.23      raeburn   228:             }
1.27      albertel  229:             opener.document.$env{"form.form"}.currsec.options[0].selected = false
1.19      raeburn   230:         }
                    231:     }
                    232:     self.close()
1.1       www       233: }
1.30      raeburn   234: 
                    235: $jscript
1.1       www       236: </script>
1.18      raeburn   237: $submitopener
1.30      raeburn   238: <form method="post" name="filterpicker">
1.27      albertel  239: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
                    240: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13      albertel  241: $name_input
1.27      albertel  242: <input type="hidden" name="form" value="$env{'form.form'}" />
1.18      raeburn   243: $roleelement
1.8       www       244: $lt{'cac'}: $sincefilterform
1.4       www       245: <br />
1.8       www       246: $lt{'cdo'}: $domainselectform
1.4       www       247: <br />
1.20      raeburn   248: $lt{'cin'}:
                    249: <input type="text" name="instcodefilter" size="10" value="$listinstcode" />
                    250: <br />
                    251: $lt{'cow'}:
                    252: <input type="text" name="ownerfilter" size="10" value="$listowner" />
                    253: <br />
1.28      raeburn   254: $courseidtag
1.8       www       255: $lt{'cde'}:
1.15      www       256: <input type="text" name="descriptfilter" size="40" value="$listdescript" />
1.5       www       257: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4       www       258: </form>
1.5       www       259: <hr />
1.1       www       260: ENDSCRIPT
1.2       www       261: # ---------------------------------------------------------------- Get the data
1.27      albertel  262:     if ($env{'form.gosearch'}) {
1.8       www       263:         $r->print(&mt('Searching').' ...<br />&nbsp;<br />');
1.6       www       264:         $r->rflush();
1.5       www       265: 	unless ($descriptfilter) { $descriptfilter='.'; }
1.20      raeburn   266:         unless ($instcodefilter) { $instcodefilter='.'; }
                    267:         unless ($ownerfilter) { $ownerfilter='.'; }
1.28      raeburn   268:         unless ($coursefilter) { $coursefilter='.'; }
1.5       www       269:         my $timefilter=($sincefilter==-1?1:time-$sincefilter);
                    270: 	my %courses=
                    271: 	    &Apache::lonnet::courseiddump
1.28      raeburn   272: 	    ($domainfilter,$descriptfilter,$timefilter,$instcodefilter,$ownerfilter,$coursefilter);
1.19      raeburn   273: 	$r->print('<form name="courselist">');
1.10      albertel  274: 	my %by_descrip;
1.31    ! albertel  275:         my $numcourses = keys(%courses);
        !           276: 	foreach my $course (keys(%courses)) {
1.17      raeburn   277:             my $descr;
                    278:             if ($courses{$course} =~ m/^([^:]*):/) {
                    279:                 $descr = &Apache::lonnet::unescape($1);
                    280:             } else {
                    281:                 $descr = &Apache::lonnet::unescape($courses{$course});
                    282:             }
1.24      raeburn   283:             my $description = lc($descr);
1.25      raeburn   284:             push (@{$by_descrip{$description}}, $course);
1.10      albertel  285: 	}
1.30      raeburn   286:         if ($numcourses > 1 && $multflag) {
                    287:             $r->print('<input type="button" value="check all"
                    288:                     onclick="javascript:checkAll(document.courselist.course_id)" />                    &nbsp;&nbsp;<input type="button" value="uncheck all"
                    289:                     onclick="javascript:uncheckAll(document.courselist.course_id)" />
                    290:                     <br /><br />');
                    291:         }
1.10      albertel  292: 	foreach my $description (sort(keys(%by_descrip))) {
1.24      raeburn   293:             foreach my $course (@{$by_descrip{$description}}) {
                    294: 	        my $cleandesc=&HTML::Entities::encode($description,'<>&"');
                    295: 	        $cleandesc=~s/'/\\'/g;
                    296: 	        my ($cdom,$cnum)=split(/\_/,$course);
                    297:                 my ($descr,$instcode,$owner) = split/:/,$courses{$course};
1.30      raeburn   298:                 $r->print(&course_chooser($multflag,$cdom,$cnum,$cleandesc));
                    299: 	        $r->print($description.'('.
1.24      raeburn   300: 		      ($Apache::lonnet::domaindescription{$cdom}?
                    301:                        $Apache::lonnet::domaindescription{$cdom}:$cdom).")");
                    302:                 unless ($instcode eq '') {
                    303:                     $r->print(" - ".&Apache::lonnet::unescape($instcode));
                    304:                 }
                    305:                 unless ($owner eq '') {
                    306:                     $r->print(", owner - ".&Apache::lonnet::unescape($owner));
                    307:                 }
                    308:                 $r->print("<br />\n");
                    309:             }
1.5       www       310: 	}
1.30      raeburn   311: 	if (!%courses) { 
                    312:             $r->print(&mt('None found'));
                    313:         } elsif ($multflag) {
                    314:             $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','',1)".'" />');
                    315:         }
1.27      albertel  316:         $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'."\n".
1.19      raeburn   317:                    '<input type="hidden" name="pickedcourse" value="" />'."\n".
1.27      albertel  318:                    '<input type="hidden" name="cnumelement" value="'.$env{'form.cnumelement'}.'" />'."\n".
                    319:                    '<input type="hidden" name="cdomelement" value="'.$env{'form.cdomelement'}.'" />'."\n".
1.19      raeburn   320:                    '</form>');
1.2       www       321:     }
1.5       www       322:     $r->print('</body></html>');
1.1       www       323:     return OK;
1.18      raeburn   324: }
1.1       www       325: 
1.30      raeburn   326: sub course_chooser {
                    327:     my ($multflag,$cdom,$cnum,$cleandesc) = @_;
                    328:     my $output; 
                    329:     if ($multflag) {
                    330:         $output = '<input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
                    331:     } else {
                    332:         $output = '<input type="button" value="Select" onClick="gochoose('.
                    333:                   "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
                    334:     }
                    335:     return $output;
                    336: } 
                    337: 
1.1       www       338: 1;
                    339: __END__

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