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

1.1       www         1: # The LearningOnline Network
                      2: # Pick a course
                      3: #
1.64    ! raeburn     4: # $Id: lonpickcourse.pm,v 1.63 2007/03/20 15:39:11 albertel 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.46      raeburn    37: use Apache::longroup;
1.47      www        38: use LONCAPA;
1.1       www        39: 
                     40: sub handler {
                     41:     my $r = shift;
1.8       www        42:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        43:     $r->send_http_header;
                     44:     return OK if $r->header_only;
                     45: 
                     46: # ------------------------------------------------------------ Print the screen
1.40      albertel   47: 
1.55      raeburn    48:     # Get parameters from query string
1.1       www        49:     &Apache::loncommon::get_unprocessed_cgi
1.55      raeburn    50:         ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
1.19      raeburn    51: 			       'cdomelement','cnameelement','roleelement',
1.55      raeburn    52:                                'multiple','type','setroles']);
1.54      raeburn    53: 
1.55      raeburn    54:     my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
                     55:         $lastaction,$autosubmit,$submitopener);
                     56: 
1.57      raeburn    57:     # Get course type - Course or Non-standard Course.
1.54      raeburn    58:     $type = $env{'form.type'};
                     59:     if (!defined($env{'form.type'})) {
                     60:         $type = 'Course';
                     61:     }
                     62:     $title = &mt('Selecting a [_1]',$type);
                     63: 
                     64:     # Setup for multiple course selections, if flag for multiples set.
1.55      raeburn    65:     $multiple = $env{'form.multiple'};
                     66:     if ($multiple) {
                     67:         ($jscript,$multelement) = &multiples_tag();
                     68:         $title = &mt('Selecting [_1](s)',lc($type));
1.54      raeburn    69:     }
                     70: 
1.55      raeburn    71:     # if called when a DC is selecting a course 
1.54      raeburn    72:     my $roledom = $env{'form.roleelement'};
                     73:     if ($roledom) {
                     74:         $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
                     75:         $submitopener = &Apache::lonroles::processpick();
                     76:         $autosubmit = 'process_pick("'.$roledom.'")';
                     77:     }
                     78: 
                     79:     my $onlyown = 0;
1.55      raeburn    80:     # if called to assign course-based portfolio access control
1.59      raeburn    81:     if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
1.54      raeburn    82:         $onlyown = 1;
1.49      raeburn    83:     }
1.55      raeburn    84: 
                     85:     my %loaditem;
1.27      albertel   86:     if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) {
1.42      albertel   87:         $loaditem{'onload'} ="setSections()";
1.30      raeburn    88:     }
1.41      albertel   89:     $r->print(&Apache::loncommon::start_page($title,undef,
1.42      albertel   90: 					     {'add_entries' => \%loaditem,
1.41      albertel   91: 					      'no_nav_bar'  => 1, }));
1.55      raeburn    92: 
                     93:     if ($env{'form.form'} eq 'portform') {
                     94:         $lastaction = 'document.courselist.submit()';
                     95:     } elsif ($env{'form.form'} eq 'cu') {
                     96:         $lastaction = 
                     97:              'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
                     98:              'document.courselist.submit();';
1.34      albertel   99:     } else {
1.55      raeburn   100:         $lastaction = 'self.close()';
1.1       www       101:     }
1.19      raeburn   102: 
1.55      raeburn   103:     # if called to assign a role in a course to a user via CUSR
                    104:     if ($env{'form.form'} eq 'cu') {
                    105:         $r->print(&create_user_javascript($type)); 
                    106:     }
1.54      raeburn   107: 
1.55      raeburn   108:     # print javascript functions for choosing a course 
                    109:     if ($env{'form.gosearch'} || $onlyown) {
1.58      raeburn   110:         $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
1.55      raeburn   111:     }
                    112:     $r->print('<script type="text/javascript">'.$jscript.'</script>');
                    113:     $r->print($submitopener);
1.54      raeburn   114: 
1.55      raeburn   115: # ------------------------------------------ Display of filters to limit search
1.57      raeburn   116:     my $filter = {};
                    117:     my $action = '/adm/pickcourse';
1.55      raeburn   118:     if (!$onlyown) {
                    119:         my $filterlist = ['domainfilter','descriptfilter',
                    120:                           'instcodefilter','ownerfilter',
                    121:                           'ownerdomfilter'];
                    122:         # course ID filter for DCs only
                    123:         if ($env{'user.adv'} && $env{'form.domainfilter'} &&
                    124:             exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
                    125:             push(@{$filterlist},'coursefilter');
                    126:         }
                    127:         $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
1.57      raeburn   128:                                  $filter,$action));
1.55      raeburn   129:     }
1.54      raeburn   130: 
                    131: # ---------------------------------------------------------------- Get the data
                    132:     if ($env{'form.gosearch'} || $onlyown) {
1.57      raeburn   133:         my %courses = &search_courses($r,$type,$onlyown,$filter);
                    134:         &display_matched_courses($r,$type,$multiple,$action,%courses);
1.54      raeburn   135:     }
                    136:     $r->print(&Apache::loncommon::end_page());
                    137:     return OK;
                    138: }
                    139: 
1.55      raeburn   140: sub create_user_javascript {
                    141:     my ($type) = @_;
                    142:     my $output;
                    143:     #javascript for reporting sections and groups then closing
                    144:     if ($env{'form.pickedcourse'}) {
                    145:         my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
                    146:         my $sec_element = 'currsec';
                    147:         my $grplist_element = 'groups';
                    148:         my ($sections,$groups) =
                    149:           &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
                    150:         my $num_sections = scalar(@{$sections});
                    151:         my $seclist = join(',',@{$sections});
                    152:         my $num_groups = scalar(@{$groups});
                    153:         my $groupslist = join(',',@{$groups});
                    154:         $output = qq|
                    155: <script type="text/javascript">
                    156: function setSections() {
                    157:     opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
                    158:     window.opener.setSect('$seclist');
                    159:     self.close()
                    160: }
                    161: </script>
                    162: |;
                    163: ;
                    164:     }
                    165:     return $output;
                    166: }
                    167: 
1.54      raeburn   168: sub display_matched_courses {
1.57      raeburn   169:     my ($r,$type,$multiple,$action,%courses) = @_;
1.55      raeburn   170:     if ($env{'form.form'} eq 'portform') {
                    171:         $action = '/adm/portfolio';
                    172:     }
                    173:     $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.54      raeburn   174:     my %by_descrip;
                    175:     my $numcourses = keys(%courses);
                    176:     foreach my $course (keys(%courses)) {
                    177:         my $descr;
1.64    ! raeburn   178:         if (ref($courses{$course}) eq 'HASH') {
        !           179:             $descr = &unescape($courses{$course}{'description'});
        !           180:         } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54      raeburn   181:             $descr = &unescape($1);
1.34      albertel  182:         } else {
1.54      raeburn   183:             $descr = &unescape($courses{$course});
                    184:         }
                    185:         my $description = $descr;
                    186:         push (@{$by_descrip{$description}}, $course);
                    187:     }
                    188:     if ($numcourses > 1 && $multiple) {
                    189:         $r->print('<input type="button" value="check all"
                    190:                   onclick="javascript:checkAll(document.courselist.course_id)" />
                    191:                   &nbsp;&nbsp;<input type="button" value="uncheck all"
                    192:                   onclick="javascript:uncheckAll(document.courselist.course_id)" />
                    193:                   <br /><br />');
                    194:     }
                    195:     foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
                    196:         foreach my $course (@{$by_descrip{$description}}) {
                    197:             my $cleandesc=&HTML::Entities::encode($description,'<>&"');
                    198:             $cleandesc=~s/'/\\'/g;
                    199:             my ($cdom,$cnum)=split(/\_/,$course);
1.64    ! raeburn   200:             my ($descr,$instcode,$ttype,@owners);
        !           201:             if (ref($courses{$course}) eq 'HASH') {
        !           202:                 $descr = $courses{$course}{'description'};
        !           203:                 $instcode =  $courses{$course}{'instcode'};
        !           204:                 $ttype =  $courses{$course}{'type'};
        !           205:                 push(@owners,&unescape($courses{$course}{'owner'}));
        !           206:                 if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
        !           207:                     foreach my $item (@{$courses{$course}{'co-owners'}}) {
        !           208:                         push(@owners,&unescape($item));
        !           209:                     }
        !           210:                 }
        !           211:             } else {
        !           212:                 my $singleowner; 
        !           213:                 ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
        !           214:                 push(@owners,&unescape($singleowner));
        !           215:             }
        !           216:             my $owner = join(', ',@owners);
1.54      raeburn   217:             $r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc));
                    218:             $r->print($description.'('.
1.62      albertel  219:                       (&Apache::lonnet::domain($cdom,'description')?
                    220:                        &Apache::lonnet::domain($cdom,'description'):$cdom).")");
1.64    ! raeburn   221:             if ($instcode ne '') {
1.54      raeburn   222:                 $r->print(" - ".&unescape($instcode));
                    223:             }
1.64    ! raeburn   224:             if (@owners > 1) {
        !           225:                 $r->print(', '.&mt('owners').' - ',join(', ',@owners)); 
        !           226:             } elsif (@owners == 1) {
        !           227:                 $r->print(', '.&mt('owner').' - '.$owner);
1.23      raeburn   228:             }
1.64    ! raeburn   229:             if ($ttype ne '') {
1.55      raeburn   230:                 $r->print('('.&unescape($ttype).')');
1.23      raeburn   231:             }
1.54      raeburn   232:             if ($multiple) { $r->print("</label>\n"); }
                    233:             $r->print("<br />\n");
1.19      raeburn   234:         }
                    235:     }
1.54      raeburn   236:     if (!%courses) {
                    237:         $r->print(&mt('None found'));
                    238:     } elsif ($multiple) {
1.57      raeburn   239:         $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','')".'" />');
1.54      raeburn   240:     }
                    241:     $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
                    242:               "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
                    243:               '<input type="hidden" name="type" value="'.$type.'" />'."\n");
                    244:     if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
                    245:         $r->print('<input type="hidden" name="roleelement" value="'.
                    246:                   $env{'form.roleelement'}.'" />'."\n");
                    247:     }
1.55      raeburn   248:     if ($env{'form.form'} eq 'portform') {
                    249:         $r->print('<input type="hidden" name="cnum" value="" />');
                    250:         $r->print('<input type="hidden" name="cdom" value="" />');
                    251:         $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
                    252:         $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57      raeburn   253:     } elsif ($env{'form.form'} eq 'modifycourse') {
                    254:         $r->print('<input type="hidden" name="phase" value="menu" />'."\n");
                    255:         $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form']));
                    256:     } else {
                    257:         $r->print('<input type="hidden" name="cnumelement" value="'.
                    258:                   $env{'form.cnumelement'}.'" />'."\n".  
                    259:                   '<input type="hidden" name="cdomelement" value="'.
                    260:                   $env{'form.cdomelement'}.'" />'."\n");
1.55      raeburn   261:     }
1.54      raeburn   262:     $r->print("</form>\n");
                    263:     return;
                    264: }
                    265: 
                    266: 
                    267: sub multiples_tag {
1.55      raeburn   268:     my $jscript = &Apache::loncommon::check_uncheck_jscript();
                    269:     my $multelement = '<input type="hidden" name="multiple" value="1" />';
                    270:     return ($jscript,$multelement);
1.1       www       271: }
1.30      raeburn   272: 
1.54      raeburn   273: sub build_filters {
1.57      raeburn   274:     my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
                    275:         $caller) = @_;
1.55      raeburn   276:     my $list;
1.57      raeburn   277:     my $formname;
                    278:     if (defined($env{'form.form'})) {
                    279:          $formname = $env{'form.form'};
                    280:     } else {
                    281:          $formname = $caller;
                    282:     }
1.55      raeburn   283:     my ($domainselectform,$sincefilterform,$ownerdomselectform,
1.54      raeburn   284:         $instcodeform,$typeselectform);
1.55      raeburn   285:     foreach my $item (@{$filterlist}) {
1.54      raeburn   286:         $filter->{$item} = $env{'form.'.$item};
                    287:         if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
1.61      albertel  288: 	    if ($item eq 'domainfilter' || $item eq 'ownerdomfilter') {
                    289: 		$filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
                    290: 	    } elsif ($item eq 'coursefilter') {
                    291: 		$filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
                    292: 	    } elsif ($item eq 'ownerfilter') {
                    293: 		$filter->{$item} = &LONCAPA::clean_username($filter->{$item});
                    294: 	    } else {
                    295: 		$filter->{$item} =~ s/\W//g;
                    296: 	    }
1.54      raeburn   297:             if (!$filter->{$item}) {
                    298:                 $filter->{$item} = '';
                    299:             }
                    300:         }
                    301:         if ($item eq 'domainfilter') {
1.63      albertel  302: 	    my $allow_blank = 1;
                    303: 	    if ($formname eq 'portform') {
                    304: 		$filter->{$item} ||= $env{'user.domain'};
                    305: 		$allow_blank=0;
                    306: 	    }
1.54      raeburn   307:             $domainselectform =
1.63      albertel  308: 		&Apache::loncommon::select_dom_form($filter->{$item},
                    309: 						    'domainfilter',
                    310: 						    $allow_blank);
1.54      raeburn   311:         } elsif ($item eq 'ownerdomfilter') {
                    312:             $ownerdomselectform =
                    313:      &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
                    314:         } else {
                    315:             $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
                    316:         }
                    317:     }
                    318: 
                    319:     # last course activity filter and selection
                    320:     $filter->{'sincefilter'} = $env{'form.sincefilter'};
                    321:     $filter->{'sincefilter'} =~ s/[^\d-]//g;
                    322:     if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
                    323:     $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
                    324:        'sincefilter',('-1'=>'',
                    325:                       '86400' => 'today',
                    326:                       '604800' => 'last week',
                    327:                       '2592000' => 'last month',
                    328:                       '7776000' => 'last three months',
                    329:                       '15552000' => 'last six months',
                    330:                       '31104000' => 'last year',
                    331:                       'select_form_order' =>
                    332:                       ['-1','86400','604800','2592000','7776000',
                    333:                       '15552000','31104000']));
                    334: 
                    335:     my %lt = (
                    336:               'cac' => &mt('[_1] Activity',$type),
                    337:               'cde' => &mt('[_1] Description',$type),
                    338:               'cdo' => &mt('[_1] Domain',$type),
                    339:               'cin' => &mt('Course Institutional Code'),
                    340:               'cow' => &mt("[_1] Owner's Username",$type),
                    341:               'cod' => &mt("[_1] Owner's Domain", $type),
                    342:               'cog' => &mt('Course Type')
                    343:              );
1.49      raeburn   344: 
1.54      raeburn   345:     $typeselectform =  '<select name="type" size="1"';
                    346:     $typeselectform .= ">\n";
                    347:     if ($type eq 'Course') {
1.57      raeburn   348:         $instcodeform = 
                    349:                 '<input type="text" name="instcodefilter" size="10" value="'.
                    350:                 $list->{'instcodefilter'}.'" />';
1.54      raeburn   351:     }
1.57      raeburn   352:     foreach my $posstype ('Course','Non-standard Course') {
1.54      raeburn   353:         $typeselectform.='<option value="'.$posstype.'" "'.
                    354:             ($posstype eq $type ? 'selected="selected" ' : ''). ">$posstype</option>\n";
                    355:     }
                    356:     $typeselectform.="</select>";
1.57      raeburn   357:     my $output = qq|
                    358: <form method="post" name="filterpicker" action="$action">
                    359: <input type="hidden" name="form" value="$formname" />
                    360: |;
                    361:     if ($formname eq 'modifycourse') {
                    362:         $output .= '<input type="hidden" name="phase" value="courselist" />';
                    363:     } else {     
                    364:         my $name_input;
                    365:         if ($env{'form.cnameelement'} ne '') {
                    366:             $name_input = '<input type="hidden" name="cnameelement" value="'.
                    367:                           $env{'form.cnameelement'}.'" />';
                    368:         }
                    369:         $output .= qq|
1.27      albertel  370: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
                    371: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13      albertel  372: $name_input
1.18      raeburn   373: $roleelement
1.35      raeburn   374: $multelement
1.57      raeburn   375: |;
1.59      raeburn   376:         if ($formname eq 'portform') {
                    377:             $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />';
                    378:         }
1.57      raeburn   379:     }
                    380:     if ($sincefilterform) { 
                    381:         $output .= $lt{'cac'}.': '.$sincefilterform.'<br />'."\n";
                    382:     }
                    383:     if ($domainselectform) {
                    384:         $output .= $lt{'cdo'}.': '.$domainselectform.'<br />'."\n";
                    385:     }
                    386:     if ($typeselectform) {
                    387:         $output .= $lt{'cog'}.': '.$typeselectform.'<br />'."\n";
                    388:     }
                    389:     if ($instcodeform) {
                    390:         $output .= $lt{'cin'}.': '.$instcodeform.'<br />'."\n";
                    391:     }
                    392:     if (exists($filter->{'ownerfilter'})) {
                    393:         $output .= $lt{'cow'}.': '.
                    394:                    '<input type="text" name="ownerfilter" size="10" value="'.
                    395:                    $list->{'ownerfilter'}.'" /><br />'."\n".
                    396:                    $lt{'cod'}.': '.$ownerdomselectform.'<br />'."\n";
                    397:     }
                    398:     if (exists($filter->{'coursefilter'})) {
                    399:         $output .= &mt('LON-CAPA course ID').': '.
                    400:                    '<input type="text" name="coursefilter" size="25" value="'.
                    401:                     $list->{'coursefilter'}.'" /><br />';
                    402:     }
                    403:     if (exists($filter->{'descriptfilter'})) {
                    404:         $output .=$lt{'cde'}.': '.
                    405:                   '<input type="text" name="descriptfilter" size="40" value="'.
                    406:                   $list->{'descriptfilter'}.'" />'."\n";
                    407:     }
                    408:     $output .= qq|
1.5       www       409: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4       www       410: </form>
1.5       www       411: <hr />
1.57      raeburn   412: |;
1.54      raeburn   413:     return $output; 
                    414: }
                    415: 
                    416: sub search_courses {
                    417:     my ($r,$type,$onlyown,$filter) = @_;
                    418:     my %courses;
                    419:     if (!$onlyown) {
1.8       www       420:         $r->print(&mt('Searching').' ...<br />&nbsp;<br />');
1.6       www       421:         $r->rflush();
1.54      raeburn   422:         if (($filter->{'ownerfilter'} ne '') ||
                    423:             ($filter->{'ownerdomfilter'} ne '')) {
                    424:             $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
                    425:                                            $filter->{'ownerdomfilter'};
                    426:         }
                    427:         foreach my $item ('descriptfilter','instcodefilter','coursefilter',
                    428:                           'combownerfilter') {
                    429:             if (!$filter->{$item}) {
                    430:                 $filter->{$item}='.';
                    431:             }
1.52      raeburn   432:         }
                    433:         if ($type eq '') { $type = '.'; }
1.54      raeburn   434:         my $timefilter = 
                    435:            ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
                    436:         %courses = 
                    437:             &Apache::lonnet::courseiddump($filter->{'domainfilter'},
                    438:                                           $filter->{'descriptfilter'},
                    439:                                           $timefilter,
                    440:                                           $filter->{'instcodefilter'},
                    441:                                           $filter->{'combownerfilter'},
                    442:                                           $filter->{'coursefilter'},
                    443:                                           undef,undef,$type);
                    444:     } else {
                    445:         $r->print('<br />');
1.60      raeburn   446:         my %coursehash = &Apache::loncommon::findallcourses(); 
                    447:         foreach my $cid (sort(keys(%coursehash))) {
1.54      raeburn   448:             $courses{$cid} = $env{'course.'.$cid.'.description'};
1.36      raeburn   449:         }
1.2       www       450:     }
1.54      raeburn   451:     return %courses;
1.18      raeburn   452: }
1.1       www       453: 
1.30      raeburn   454: sub course_chooser {
1.35      raeburn   455:     my ($multiple,$cdom,$cnum,$cleandesc) = @_;
1.30      raeburn   456:     my $output; 
1.35      raeburn   457:     if ($multiple) {
1.32      albertel  458:         $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.30      raeburn   459:     } else {
                    460:         $output = '<input type="button" value="Select" onClick="gochoose('.
                    461:                   "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
                    462:     }
                    463:     return $output;
1.49      raeburn   464: }
                    465: 
1.55      raeburn   466: sub gochoose_javascript {
1.57      raeburn   467:     my ($type,$multiple,$autosubmit,$lastaction) = @_;
1.55      raeburn   468:     my %elements = (
                    469:                      'Course' => {
                    470:                                  name  => 'coursepick',
                    471:                                  total => 'coursetotal',
                    472:                                  list  => 'courselist',
                    473:                                  },
1.57      raeburn   474:                      'Non-standard Course' => {
1.55      raeburn   475:                                  name  => 'grouppick',
                    476:                                  total => 'grouptotal',
                    477:                                  list  => 'grouplist',
                    478:                               },
                    479:                     );
1.57      raeburn   480:     my $output .= qq|
1.55      raeburn   481: <script type="text/javascript">
1.57      raeburn   482: function gochoose(cname,cdom,cdesc) {
1.55      raeburn   483:     var openerForm = "$env{'form.form'}";
                    484:     courseCount = 0;
                    485:     var courses = '';
1.57      raeburn   486: |;
                    487:     if ($multiple) {
                    488:         $output .= <<"ENDSCRIPT";
                    489:     courseCount = 0;
                    490:     var courses = '';
                    491:     if (typeof(document.courselist.course_id.length) == 'undefined') {
                    492:         // only 1 course checkbox was created
                    493:         if (document.courselist.course_id.checked) {
                    494:             courses = courses + document.courselist.course_id.value + "&&";
                    495:             courseCount ++;
                    496:         }
                    497:     } else {
                    498:         for (var j=0; j<document.courselist.course_id.length; j++) {
                    499:             if (document.courselist.course_id[j].checked) {
                    500:                 courses = courses + document.courselist.course_id[j].value + "&&";
1.55      raeburn   501:                 courseCount ++;
                    502:             }
1.57      raeburn   503:         }
                    504:     }
                    505:     opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
                    506:     if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
                    507:         'undefined') {
                    508:         if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
                    509:             opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55      raeburn   510:         } else {
1.57      raeburn   511:             opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55      raeburn   512:         }
1.57      raeburn   513:     } else {
                    514:         for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
                    515:             if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
                    516:                 opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55      raeburn   517:             } else {
1.57      raeburn   518:                 opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54      raeburn   519:             }
1.55      raeburn   520:         }
1.57      raeburn   521:     }
                    522:     if (courseCount > 0) {
                    523:         courses = courses.substr(0,courses.length-2);
                    524:         opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
                    525:     }
                    526: ENDSCRIPT
                    527:     } else {
                    528:         my $name_code;
                    529:         if ($env{'form.cnameelement'} ne '') {
                    530:             $name_code = 'opener.document.'.$env{'form.form'}.'.'.
                    531:                           $env{'form.cnameelement'}.'.value=cdesc;';
1.55      raeburn   532:         }
1.57      raeburn   533:         $output .= qq|
1.55      raeburn   534:         $name_code
                    535:         opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
                    536:         var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
                    537:         if (slct.options == undefined) {
                    538:             opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
                    539:         }
                    540:         else {
                    541:             var i;
                    542:             for (i=0;i<slct.length;i++) {
                    543:                 if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54      raeburn   544:             }
                    545:         }
1.57      raeburn   546: |;
1.54      raeburn   547:     }
1.57      raeburn   548:     $output .= qq|
1.55      raeburn   549:     if (openerForm == 'portform') {
                    550:         document.courselist.cnum.value = cname;
                    551:         document.courselist.cdom.value = cdom;
                    552:     }
                    553:     $autosubmit
                    554:     $lastaction
1.54      raeburn   555: }
1.55      raeburn   556: </script>
1.57      raeburn   557: |;
1.55      raeburn   558:     return $output;
1.54      raeburn   559: }
                    560: 
1.55      raeburn   561: 1;
                    562: __END__
                    563: 
                    564: =pod
                    565: 
                    566: =head1 NAME
                    567: 
                    568: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.   
                    569: 
                    570: =head1 SYNOPSIS
                    571: 
                    572: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user. 
                    573: 
                    574: =head1 OVERVIEW
                    575: 
                    576: Two screens are typically displayed to the user.  The first is a set of criteria which are used to constrain the search for courses.
                    577: 
                    578: =head2 Search Criteria (Screen One)
                    579: 
                    580: =head3 Criteria:
                    581: 
                    582: =over 4
                    583: 
                    584: =item *
                    585: Course Activity - how recently was course last visited by anyone.
                    586: 
                    587: =item *
                    588: Course Domain - the domain of the course
                    589: 
                    590: =item *
1.57      raeburn   591: Course Type - Course or Non-standard Course
1.55      raeburn   592: 
                    593: =item *
                    594: Course Institutional Code - the institutional identifier assigned to the course
                    595: 
                    596: =item * 
                    597: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
                    598: 
                    599: =item *
                    600: Course Owner's Domain - the domain of the owner of the course
                    601: 
                    602: =item * 
                    603: Course Description - text which appears in the Course Description (or title), as set in the Course Parameters.
                    604: 
                    605: =item *
                    606: Course ID - the internal course number (course ID part after initial 'domain_') used by LON-CAPA (this criterion is only displayed to Domain Coordinators selecting a course in the same domain as their DC role).
                    607: 
                    608: =back
                    609: 
                    610: The criteria setting screen is not displayed if course picking is done by a user who does not have advanced privileges (as defined by $env{'user.adv'}).
                    611: 
                    612: =head2 Course Display (Screen Two)
                    613: 
                    614: A list of courses matching the search criteria is displayed.  If the user is not an advanced user, screen one will have been skipped and the courses displayed will be all courses in which the user has currently active roles. The information displayed for each course is:
                    615: 
                    616: =over 4
                    617: 
                    618: =item *
                    619: Course description
                    620: 
                    621: =item *
                    622: Domain description of course domain
                    623: 
                    624: =item *
                    625: Course institutional code
                    626: 
                    627: =item * 
                    628: Course owner (username:domain)   
                    629:  
                    630: =back
                    631: 
                    632: Depending on context, the display may include a single select box for each course, allowing selection of only a single course, or may include checkboxes allowing selection of more than one course.
                    633: 
                    634: Following selection, and/or submission, the course description, number and domain are transferred to the browser window from which the course picker window was opened.  In most cases, the child window containing the course picker screens will be closed.  However, in some cases closure will be delayed until a third screen has been displayed (e.g., setting of course-based conditional access controls for portfolio files).  In this case the page is generated via /adm/portfolio and the page features select boxes to allow the user to select roles, access types, sections and groups.
                    635: 
                    636: =head1 SUBROUTINES
                    637: 
                    638: =over 4
                    639: 
                    640: =item *
                    641: X<create_user_javascript()>
                    642: B<create_user_javascript($type)>:
                    643: 
1.57      raeburn   644: Input: 1 - $type  - the course type - Course or Non-standard Course
1.55      raeburn   645: 
                    646: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags 
                    647: 
                    648: Side Effects: None 
                    649: 
                    650: javascript code for reporting selected sections (as a string of comma separated sections) and groups in the selected course (as a comma separated list) then calling setSect() javscript function in the opener window (to populate section select box) then closing current window.
                    651: 
                    652: 
                    653: =item *
                    654: X<display_matched_courses()>
1.57      raeburn   655: B<display_matched_courses($r,$type,$multiple,$action,%courses)>:
1.55      raeburn   656: 
1.57      raeburn   657: Input: 5 - request object, course type, multiple (0 or 1), form action; hash of courses.
1.55      raeburn   658: 
                    659: Output: 0
                    660: 
                    661: Side Effects: prints select buttons (multiple = 0) or checkboxes (multiple = 1) and hidden form elements for selection of one or more courses which met search criteria.
                    662: 
                    663: =item *
                    664: X<multiples_tag()>
                    665: B<multiples_tag()>:
                    666: 
                    667: 
                    668: Input: 0
                    669: 
                    670: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
                    671: 
                    672: Side Effects: None
                    673: 
                    674: =item *
                    675: X<build_filters()>
1.57      raeburn   676: B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action)>:
1.55      raeburn   677: 
                    678: 
1.57      raeburn   679: Input: 6 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action.
1.55      raeburn   680: 
                    681: Output: 1 - $output - HTML for display of search criteria, and hidden form elements. 
                    682: 
                    683: Side Effects: None
                    684: 
                    685: =item *
                    686: X<search_courses()>
                    687: B<search_courses($r,$type,$onlyown,$filter)>:
                    688: 
                    689: 
                    690: Input: 5 -  request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values.
                    691: 
                    692: Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
                    693: 
                    694: Side Effects: None
                    695: 
                    696: 
                    697: =item *
                    698: X<course_chooser()>
                    699: B<course_chooser($multiple,$cdom,$cnum,$cleandesc)>:
                    700: 
                    701: Input: 4 - single (0) or multiple (1) courses; course domain, course number; course description. 
                    702: 
                    703: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user yo indicate course selection.
                    704: 
                    705: Side Effects: None
                    706: 
                    707: 
                    708: =item *
                    709: X<gochoose_javascript()>
1.57      raeburn   710: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>:
1.55      raeburn   711: 
1.57      raeburn   712: Input: 4 - course type; single (0) or multiple courses (1); in context of DC selecting a CC role in a course: javascript code from Apache::lonroles::processpick(); final action to take after user chooses course(s):  either close window, or submit form for display of next page etc.
1.55      raeburn   713: 
                    714: Output: 1  $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
                    715: 
                    716: Side Effects: None
                    717: 
                    718: javascript functions used when user selects a course(s). Different behavior depending on context:
                    719: 
                    720: =back
                    721: 
                    722: =over 8
                    723: 
                    724: =item
                    725: 
                    726: (a) Domain Coordinator using MAIL to select recipients of broadcast e-mail - && separated list of selected courses written to hidden form element in opener window. Child window closes.
                    727: 
                    728: =item
                    729: 
                    730: (b) Domain Coordinator choosing a course for adoption of a CC role from roles screen - write course identifying information to hidden form elements in opener window and automatically submit role selection form in opener window. Child window closes.
                    731: 
                    732: =item
                    733: 
                    734: (c) Domain Coordinator creating a course, and selecting a course to clone - course number and domain written to visible form elements in opener window. Child window closes.
                    735: 
                    736: =item
1.54      raeburn   737: 
1.55      raeburn   738: (d) User selecting a course for course-based conditional access control for a portfolio file - form is submitted, and new page is displayed for selection of roles, access types, sections and groups to be used in conditional ACL. New page is generated by /adm/portfolio. 
1.54      raeburn   739: 
1.55      raeburn   740: =item
1.54      raeburn   741: 
1.55      raeburn   742: (e) Domain Coordinator assigning a role to a user - form is submitted, and new page does an onload call to a javascript function to (a) write lists of sections and groups to hidden elements in opener window, (b) call function in opener window to dynamically populate select box showing current sections.
1.54      raeburn   743: 
1.55      raeburn   744: =item
1.54      raeburn   745: 
1.55      raeburn   746: (f) Author modifying a rights entry in a .rights file - selected course number and domain are witten to visible form elements in opener window.  Child window closes. 
1.54      raeburn   747: 
1.55      raeburn   748: =item
1.49      raeburn   749: 
1.55      raeburn   750: (g) Scantron Operator uploading a scantron file to a course - course number is written to visible form element in opener window. Child window closes.
1.30      raeburn   751: 
1.55      raeburn   752: =back
                    753:      
                    754: =cut

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