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

1.1       www         1: # The LearningOnline Network
                      2: # Pick a course
                      3: #
1.81    ! raeburn     4: # $Id: lonpickcourse.pm,v 1.80 2009/05/05 05:30:00 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.46      raeburn    37: use Apache::longroup;
1.78      raeburn    38: use Apache::courseclassifier;
1.47      www        39: use LONCAPA;
1.1       www        40: 
                     41: sub handler {
                     42:     my $r = shift;
1.8       www        43:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        44:     $r->send_http_header;
                     45:     return OK if $r->header_only;
                     46: 
                     47: # ------------------------------------------------------------ Print the screen
1.40      albertel   48: 
1.55      raeburn    49:     # Get parameters from query string
1.1       www        50:     &Apache::loncommon::get_unprocessed_cgi
1.55      raeburn    51:         ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
1.19      raeburn    52: 			       'cdomelement','cnameelement','roleelement',
1.78      raeburn    53:                                'multiple','type','setroles','fixeddom']);
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.'" />';
1.66      raeburn    75:         $submitopener = &processpick();
1.54      raeburn    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.78      raeburn    86:     if ($env{'form.numtitles'}) {
                     87:         $loaditem{'onload'} = 'setElements(); ';
                     88:     }
                     89: 
1.66      raeburn    90:     if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) && 
                     91:         ($env{'form.pickedcourse'})) {
1.78      raeburn    92:             $loaditem{'onload'} .= 'setSections()';
1.30      raeburn    93:     }
1.41      albertel   94:     $r->print(&Apache::loncommon::start_page($title,undef,
1.42      albertel   95: 					     {'add_entries' => \%loaditem,
1.41      albertel   96: 					      'no_nav_bar'  => 1, }));
1.55      raeburn    97: 
                     98:     if ($env{'form.form'} eq 'portform') {
                     99:         $lastaction = 'document.courselist.submit()';
1.67      raeburn   100:     } elsif ($env{'form.form'} eq 'cu' || ($env{'form.form'} eq 'studentform' &&
                    101:         !$multiple)) {
1.55      raeburn   102:         $lastaction = 
                    103:              'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
                    104:              'document.courselist.submit();';
1.34      albertel  105:     } else {
1.55      raeburn   106:         $lastaction = 'self.close()';
1.1       www       107:     }
1.19      raeburn   108: 
1.55      raeburn   109:     # if called to assign a role in a course to a user via CUSR
1.66      raeburn   110:     if ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') {
1.68      raeburn   111:         $r->print(&create_user_javascript($type));
1.55      raeburn   112:     }
1.54      raeburn   113: 
1.55      raeburn   114:     # print javascript functions for choosing a course 
                    115:     if ($env{'form.gosearch'} || $onlyown) {
1.58      raeburn   116:         $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
1.55      raeburn   117:     }
1.79      raeburn   118:     $r->print('<script type="text/javascript" language="Javascript">'.$jscript.
                    119:               '</script>');
1.55      raeburn   120:     $r->print($submitopener);
1.54      raeburn   121: 
1.55      raeburn   122: # ------------------------------------------ Display of filters to limit search
1.57      raeburn   123:     my $filter = {};
                    124:     my $action = '/adm/pickcourse';
1.79      raeburn   125:     my ($numtitles,$showroles,$nohost);
1.55      raeburn   126:     if (!$onlyown) {
                    127:         my $filterlist = ['domainfilter','descriptfilter',
1.79      raeburn   128:                           'instcodefilter'];
                    129:         if ($env{'form.form'} eq 'rules') {
                    130:             push(@{$filterlist},'personfilter');
                    131:             if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
                    132:                 if (&Apache::lonnet::homeserver($env{'form.personfilter'},
                    133:                                                  $env{'form.persondomfilter'}) eq 'no_host') {
                    134:                     $nohost = 1;
                    135:                 } else {
                    136:                     $showroles = 1;
                    137:                 } 
                    138:             }
                    139:         } else {
                    140:             push(@{$filterlist},'ownerfilter');
                    141:         }
1.55      raeburn   142:         # course ID filter for DCs only
                    143:         if ($env{'user.adv'} && $env{'form.domainfilter'} &&
                    144:             exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
                    145:             push(@{$filterlist},'coursefilter');
                    146:         }
                    147:         $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
1.78      raeburn   148:                                  $filter,$action,\$numtitles));
1.55      raeburn   149:     }
1.54      raeburn   150: 
                    151: # ---------------------------------------------------------------- Get the data
                    152:     if ($env{'form.gosearch'} || $onlyown) {
1.78      raeburn   153:         my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles);
1.79      raeburn   154:         if ($nohost) {
                    155:             $r->print ('<span class="LC_warning">'.
                    156:                        &mt('User does not exist - username: [_1], domain: [_2].',
                    157:                            '<b>'.$filter->{'personfilter'}.'</b>',
                    158:                            '<b>'.$filter->{'persondomfilter'}.'</b>').'</span>');
                    159:         } else {
                    160:             &display_matched_courses($r,$type,$multiple,$action,$showroles,%courses);
                    161:         }
1.54      raeburn   162:     }
                    163:     $r->print(&Apache::loncommon::end_page());
                    164:     return OK;
                    165: }
                    166: 
1.66      raeburn   167: sub processpick {
                    168:     my $openerform = 'rolechoice';
                    169:     if ($env{'form.form'} eq 'studentform') {
                    170:         $openerform = $env{'form.form'};
                    171:     }
                    172:     my $process_pick = <<"ENDONE";
                    173: <script type="text/javascript">
                    174: function process_pick(dom) {
                    175:     var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
                    176:     var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
                    177:     var okDomain = 0;
                    178: ENDONE
                    179:     if ($openerform eq 'rolechoice') {
                    180:         $process_pick .= <<"ENDTWO";
                    181:     if (pickedDomain == dom) {
                    182:         if (pickedCourse != '') {
                    183:             var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
                    184:             opener.document.title='Role selected. Please stand by.';
                    185:             opener.status='Role selected. Please stand by.';
                    186:             opener.document.rolechoice.newrole.value=courseTarget
                    187:             opener.document.rolechoice.submit();
                    188:         }
                    189:     } 
                    190:     else {
                    191:         alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain");
                    192:     }
                    193: ENDTWO
                    194:     } else {
                    195:         $process_pick .= <<"ENDTHREE";
                    196:     if (pickedDomain != dom) {
                    197:         alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain");
                    198:         return;
                    199:     }
                    200: ENDTHREE
                    201:     }
                    202:     $process_pick .= "
                    203: }
                    204: 
                    205: </script>
                    206: ";
                    207:     return $process_pick;
                    208: }
                    209: 
1.55      raeburn   210: sub create_user_javascript {
                    211:     my ($type) = @_;
                    212:     my $output;
                    213:     #javascript for reporting sections and groups then closing
                    214:     if ($env{'form.pickedcourse'}) {
                    215:         my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
                    216:         my $sec_element = 'currsec';
                    217:         my $grplist_element = 'groups';
                    218:         my ($sections,$groups) =
                    219:           &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
                    220:         my $num_sections = scalar(@{$sections});
                    221:         my $seclist = join(',',@{$sections});
                    222:         my $num_groups = scalar(@{$groups});
                    223:         my $groupslist = join(',',@{$groups});
                    224:         $output = qq|
                    225: <script type="text/javascript">
                    226: function setSections() {
                    227:     opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
                    228:     window.opener.setSect('$seclist');
                    229:     self.close()
                    230: }
                    231: </script>
                    232: |;
                    233: ;
                    234:     }
                    235:     return $output;
                    236: }
                    237: 
1.54      raeburn   238: sub display_matched_courses {
1.79      raeburn   239:     my ($r,$type,$multiple,$action,$showroles,%courses) = @_;
1.55      raeburn   240:     if ($env{'form.form'} eq 'portform') {
                    241:         $action = '/adm/portfolio';
                    242:     }
1.68      raeburn   243:     my $numcourses = keys(%courses);
1.55      raeburn   244:     $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.68      raeburn   245:     if ($env{'form.form'} eq 'modifycourse') {
                    246:         if ($numcourses > 0) {
                    247:             my $cctitle = &Apache::lonnet::plaintext('cc',$type);
                    248:             my $dctitle = &Apache::lonnet::plaintext('dc');
                    249:             my $ccrolechk = ' checked="checked" ';
                    250:             my $menuchk = ' ';
                    251:             if ($env{'form.prevphase'} ne '') {
                    252:                  $ccrolechk = ' ';
                    253:                  $menuchk = ' checked="checked" ';
                    254:             }
                    255:             $r->print(
1.75      bisitz    256:                 '<fieldset>'
                    257:                .'<legend>'.&mt('Action').'</legend>'
                    258:                .'<div class="LC_nobreak"><label>'
                    259:                .'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>'
                    260:                .'&nbsp;'.&mt('Enter the course with the role of [_1].',$cctitle)
                    261:                .'</label></div>'
                    262:                .'<div class="LC_nobreak"><label>'
                    263:                .'<input type="radio" name="phase" value="menu"'.$menuchk.'/>&nbsp;'
                    264:                .&mt('View or modify course settings which only a [_1] may modify.',$dctitle)
                    265:                .'</label></div>'
                    266:                .'</fieldset>'
                    267:                .'<br />'
                    268:             );
1.68      raeburn   269:         }
                    270:     }
1.54      raeburn   271:     my %by_descrip;
                    272:     foreach my $course (keys(%courses)) {
                    273:         my $descr;
1.64      raeburn   274:         if (ref($courses{$course}) eq 'HASH') {
1.65      raeburn   275:             $descr = $courses{$course}{'description'};
1.64      raeburn   276:         } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54      raeburn   277:             $descr = &unescape($1);
1.34      albertel  278:         } else {
1.54      raeburn   279:             $descr = &unescape($courses{$course});
                    280:         }
                    281:         my $description = $descr;
                    282:         push (@{$by_descrip{$description}}, $course);
                    283:     }
1.71      bisitz    284:  
1.54      raeburn   285:     if ($numcourses > 1 && $multiple) {
                    286:         $r->print('<input type="button" value="check all"
                    287:                   onclick="javascript:checkAll(document.courselist.course_id)" />
                    288:                   &nbsp;&nbsp;<input type="button" value="uncheck all"
                    289:                   onclick="javascript:uncheckAll(document.courselist.course_id)" />
                    290:                   <br /><br />');
                    291:     }
1.71      bisitz    292: 
                    293:     if (%courses) {
                    294:         $r->print(&Apache::loncommon::start_data_table());
                    295:         $r->print(&Apache::loncommon::start_data_table_header_row());
                    296:         $r->print('<th>'.&mt('Select').'</th>'
1.76      bisitz    297:                  .'<th>'.&mt('Course Title').'</th>'
1.71      bisitz    298:                  .'<th>'.&mt('Domain').'</th>'
                    299:                  .'<th>'.&mt('Course Code').'</th>'
1.72      raeburn   300:                  .'<th>'.&mt('Owner/Co-owner(s)').'</th>'
1.71      bisitz    301:                  .'<th>'.&mt('Type').'</th>'
                    302:                  );
1.79      raeburn   303:         if ($showroles) {
                    304:             $r->print('<th>'.&mt("Role(s) for [_1]",
                    305:                 &Apache::loncommon::plainname($env{'form.personfilter'},
                    306:                                               $env{'form.persondomfilter'},'firstname')).'</th>');
                    307:         }
1.71      bisitz    308:         $r->print(&Apache::loncommon::end_data_table_header_row());
                    309:     }
1.54      raeburn   310:     foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
                    311:         foreach my $course (@{$by_descrip{$description}}) {
1.72      raeburn   312:             $r->print(&Apache::loncommon::start_data_table_row());
1.54      raeburn   313:             my $cleandesc=&HTML::Entities::encode($description,'<>&"');
                    314:             $cleandesc=~s/'/\\'/g;
                    315:             my ($cdom,$cnum)=split(/\_/,$course);
1.64      raeburn   316:             my ($descr,$instcode,$ttype,@owners);
                    317:             if (ref($courses{$course}) eq 'HASH') {
                    318:                 $descr = $courses{$course}{'description'};
1.65      raeburn   319:                 $instcode =  $courses{$course}{'inst_code'};
1.64      raeburn   320:                 $ttype =  $courses{$course}{'type'};
                    321:                 push(@owners,&unescape($courses{$course}{'owner'}));
                    322:                 if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
                    323:                     foreach my $item (@{$courses{$course}{'co-owners'}}) {
                    324:                         push(@owners,&unescape($item));
                    325:                     }
                    326:                 }
                    327:             } else {
                    328:                 my $singleowner; 
                    329:                 ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
                    330:                 push(@owners,&unescape($singleowner));
                    331:             }
1.72      raeburn   332:             my $ownerstr = join(', ',@owners);
1.71      bisitz    333:             $r->print('<td>'.&course_chooser($multiple,$cdom,$cnum,$cleandesc).'</td>');
                    334:             $r->print('<td>'.$description.'</td>');
                    335:             $r->print('<td>');
                    336:             $r->print(&Apache::lonnet::domain($cdom,'description')?
                    337:                       $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
                    338:             $r->print('</td>');
                    339:             $r->print('<td>');
1.64      raeburn   340:             if ($instcode ne '') {
1.71      bisitz    341:                 $r->print(&unescape($instcode));
                    342:             } else {
                    343:                 $r->print('&nbsp;');
1.54      raeburn   344:             }
1.71      bisitz    345:             $r->print('</td>');
1.72      raeburn   346:             $r->print('<td>'.$ownerstr.'</td>');
1.71      bisitz    347:             $r->print('<td>');
1.64      raeburn   348:             if ($ttype ne '') {
1.71      bisitz    349:                 $r->print(&mt(&unescape($ttype)));
                    350:             } else {
                    351:                 $r->print('&nbsp;');
1.23      raeburn   352:             }
1.71      bisitz    353:             $r->print('</td>');
1.79      raeburn   354:             if ($showroles) {
                    355:                 $r->print('<td>');
                    356:                 my $rolestr;
                    357:                 if (ref($courses{$course}{'roles'}) eq 'ARRAY') {
                    358:                     my @roles = sort(@{$courses{$course}{'roles'}});
                    359:                     foreach my $role (@roles) {
                    360:                         if ($role =~ /^cr/) {
                    361:                             my (undef,$crdom,$crname,$crtitle) = split('/',$role);
                    362:                             $rolestr .= $crtitle.', ';
                    363:                         } else {
                    364:                             $rolestr .= &Apache::lonnet::plaintext($role,$ttype).', ';
                    365:                         }
                    366:                     }
                    367:                     $rolestr =~ s/\, $//;
                    368:                 }
                    369:                 $r->print($rolestr.'</td>');
                    370:             }
1.54      raeburn   371:             if ($multiple) { $r->print("</label>\n"); }
1.72      raeburn   372:             $r->print(&Apache::loncommon::end_data_table_row());
1.71      bisitz    373:             # $r->print("<br />\n");
1.19      raeburn   374:         }
                    375:     }
1.72      raeburn   376:     if (%courses) {
                    377:         $r->print(&Apache::loncommon::end_data_table());
                    378:     }
1.71      bisitz    379: 
1.54      raeburn   380:     if (!%courses) {
                    381:         $r->print(&mt('None found'));
                    382:     } elsif ($multiple) {
1.57      raeburn   383:         $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','')".'" />');
1.54      raeburn   384:     }
                    385:     $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
                    386:               "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
                    387:               '<input type="hidden" name="type" value="'.$type.'" />'."\n");
                    388:     if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
                    389:         $r->print('<input type="hidden" name="roleelement" value="'.
                    390:                   $env{'form.roleelement'}.'" />'."\n");
                    391:     }
1.55      raeburn   392:     if ($env{'form.form'} eq 'portform') {
                    393:         $r->print('<input type="hidden" name="cnum" value="" />');
                    394:         $r->print('<input type="hidden" name="cdom" value="" />');
                    395:         $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
                    396:         $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57      raeburn   397:     } elsif ($env{'form.form'} eq 'modifycourse') {
1.78      raeburn   398:         $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
1.57      raeburn   399:     } else {
                    400:         $r->print('<input type="hidden" name="cnumelement" value="'.
                    401:                   $env{'form.cnumelement'}.'" />'."\n".  
                    402:                   '<input type="hidden" name="cdomelement" value="'.
                    403:                   $env{'form.cdomelement'}.'" />'."\n");
1.55      raeburn   404:     }
1.78      raeburn   405:     if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
                    406:         $r->print('<input type="hidden" name="fixeddom" value="'.
                    407:                   $env{'form.fixeddom'}.'" />');
                    408:     }
                    409:     if ($env{'form.numtitles'}) {
                    410:         $r->print('<input type="hidden" name="numtitles" value="'.
                    411:                   $env{'form.numtitles'}.'" />');
                    412:     }
1.54      raeburn   413:     $r->print("</form>\n");
                    414:     return;
                    415: }
                    416: 
                    417: sub multiples_tag {
1.55      raeburn   418:     my $jscript = &Apache::loncommon::check_uncheck_jscript();
                    419:     my $multelement = '<input type="hidden" name="multiple" value="1" />';
                    420:     return ($jscript,$multelement);
1.1       www       421: }
1.30      raeburn   422: 
1.54      raeburn   423: sub build_filters {
1.57      raeburn   424:     my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
1.81    ! raeburn   425:         $numtitlesref,$caller) = @_;
1.55      raeburn   426:     my $list;
1.57      raeburn   427:     my $formname;
1.78      raeburn   428:     my ($fixeddom,$codedom,$jscript);
1.57      raeburn   429:     if (defined($env{'form.form'})) {
1.81    ! raeburn   430:         $formname = $env{'form.form'};
        !           431:     } else {
        !           432:         $formname = $caller;
1.57      raeburn   433:     }
1.79      raeburn   434:     my ($domainselectform,$sincefilterform,$ownerdomselectform,$persondomselectform,
1.78      raeburn   435:         $instcodeform,$typeselectform,$instcodetitle);
1.55      raeburn   436:     foreach my $item (@{$filterlist}) {
1.54      raeburn   437:         $filter->{$item} = $env{'form.'.$item};
                    438:         if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
1.79      raeburn   439: 	    if ($item eq 'domainfilter') {
1.61      albertel  440: 		$filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
                    441: 	    } elsif ($item eq 'coursefilter') {
                    442: 		$filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
                    443: 	    } elsif ($item eq 'ownerfilter') {
                    444: 		$filter->{$item} = &LONCAPA::clean_username($filter->{$item});
1.79      raeburn   445:                 $filter->{'ownerdomfilter'} = 
                    446:                     &LONCAPA::clean_domain($env{'form.ownerdomfilter'});
                    447:                 $ownerdomselectform =
                    448:                     &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'},
                    449:                                                         'ownerdomfilter',1);
                    450:             } elsif ($item eq 'personfilter') {
                    451:                 $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
                    452:                 if ($env{'form.persondomfilter'} eq '') {
                    453:                     unless ($env{'form.gosearch'}) {
                    454:                         $filter->{'persondomfilter'} = $env{'request.role.domain'};
                    455:                     }
                    456:                 } else {
                    457:                     $filter->{'persondomfilter'} =
                    458:                         &LONCAPA::clean_domain($env{'form.persondomfilter'});
                    459:                 }
                    460:                 $persondomselectform =
                    461:                     &Apache::loncommon::select_dom_form($filter->{'persondomfilter'},
                    462:                                                         'persondomfilter',1);
1.61      albertel  463: 	    } else {
                    464: 		$filter->{$item} =~ s/\W//g;
                    465: 	    }
1.54      raeburn   466:             if (!$filter->{$item}) {
                    467:                 $filter->{$item} = '';
                    468:             }
                    469:         }
                    470:         if ($item eq 'domainfilter') {
1.63      albertel  471: 	    my $allow_blank = 1;
                    472: 	    if ($formname eq 'portform') {
                    473: 		$filter->{$item} ||= $env{'user.domain'};
                    474: 		$allow_blank=0;
1.67      raeburn   475: 	    } elsif ($formname eq 'studentform') {
                    476:                 $filter->{$item} ||= $env{'request.role.domain'};
                    477:                 $allow_blank=0;
                    478:             }
1.78      raeburn   479:             if ($env{'form.fixeddom'}) {
                    480:                 $domainselectform = '<input type="hidden" name="domainfilter"'.
                    481:                                     'value="'.$env{'request.role.domain'}.'" />'.
                    482:                                     &Apache::lonnet::domain($env{'request.role.domain'},
                    483:                                                             'description');
                    484:                 $codedom = $env{'request.role.domain'};
1.79      raeburn   485:             } else {
1.78      raeburn   486:                 $domainselectform =
                    487: 		    &Apache::loncommon::select_dom_form($filter->{$item},
                    488: 		    				        'domainfilter',
                    489: 						        $allow_blank);
                    490:                 $codedom = $filter->{'domainfilter'};
                    491:             }
1.54      raeburn   492:         } else {
                    493:             $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
                    494:         }
                    495:     }
                    496: 
                    497:     # last course activity filter and selection
                    498:     $filter->{'sincefilter'} = $env{'form.sincefilter'};
                    499:     $filter->{'sincefilter'} =~ s/[^\d-]//g;
                    500:     if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
                    501:     $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
                    502:        'sincefilter',('-1'=>'',
                    503:                       '86400' => 'today',
                    504:                       '604800' => 'last week',
                    505:                       '2592000' => 'last month',
                    506:                       '7776000' => 'last three months',
                    507:                       '15552000' => 'last six months',
                    508:                       '31104000' => 'last year',
                    509:                       'select_form_order' =>
                    510:                       ['-1','86400','604800','2592000','7776000',
                    511:                       '15552000','31104000']));
                    512: 
                    513:     my %lt = (
1.74      bisitz    514:               'cac' => &mt("$type Activity"),
1.76      bisitz    515:               'cde' => &mt("$type Title"),
1.74      bisitz    516:               'cdo' => &mt("$type Domain"),
1.78      raeburn   517:               'ins' => &mt('Institutional Code'),
                    518:               'inc' => &mt('Institutional Categorization'),
1.79      raeburn   519:               'cow' => &mt("$type Owner/Co-owner"),
                    520:               'cop' => &mt("$type Personnel Includes"),
1.54      raeburn   521:               'cog' => &mt('Course Type')
                    522:              );
1.49      raeburn   523: 
1.65      raeburn   524:     $typeselectform =  '<select name="type" size="1">'."\n";
1.80      raeburn   525:     my $officialjs;
1.54      raeburn   526:     if ($type eq 'Course') {
1.78      raeburn   527:         if ($env{'form.fixeddom'}) {
1.80      raeburn   528:             $officialjs = 1;
1.78      raeburn   529:             ($instcodeform,$jscript,$$numtitlesref) = 
1.80      raeburn   530:                 &instcode_selectors($codedom,'filterpicker',$officialjs);
1.78      raeburn   531:         }
                    532:         if ($instcodeform eq '') {
                    533:             $instcodeform = 
1.57      raeburn   534:                 '<input type="text" name="instcodefilter" size="10" value="'.
                    535:                 $list->{'instcodefilter'}.'" />';
1.78      raeburn   536:             $instcodetitle = $lt{'ins'};
                    537:         } else {
                    538:             $instcodetitle = $lt{'inc'};
                    539:         }
                    540:         if ($env{'form.fixeddom'}) {
                    541:             $instcodetitle .= '<br />('.$codedom.')';
                    542:         }
                    543:         if ($jscript ne '') {
                    544:             $jscript = '<script type="text/javascript" language="Javascript">'.$jscript.
                    545:                        '</script>'."\n";
                    546:         }
1.54      raeburn   547:     }
1.57      raeburn   548:     foreach my $posstype ('Course','Non-standard Course') {
1.72      raeburn   549:         $typeselectform.='<option value="'.$posstype.'"'.
1.73      bisitz    550:             ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
1.54      raeburn   551:     }
                    552:     $typeselectform.="</select>";
1.57      raeburn   553:     my $output = qq|
                    554: <form method="post" name="filterpicker" action="$action">
                    555: <input type="hidden" name="form" value="$formname" />
                    556: |;
                    557:     if ($formname eq 'modifycourse') {
1.68      raeburn   558:         $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
                    559:                    '<input type="hidden" name="prevphase" value="'.
                    560:                    $env{'form.prevphase'}.'" />'."\n";
                    561:     } else {
1.57      raeburn   562:         my $name_input;
                    563:         if ($env{'form.cnameelement'} ne '') {
                    564:             $name_input = '<input type="hidden" name="cnameelement" value="'.
                    565:                           $env{'form.cnameelement'}.'" />';
                    566:         }
                    567:         $output .= qq|
1.27      albertel  568: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
                    569: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13      albertel  570: $name_input
1.18      raeburn   571: $roleelement
1.35      raeburn   572: $multelement
1.57      raeburn   573: |;
1.59      raeburn   574:         if ($formname eq 'portform') {
1.78      raeburn   575:             $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'."\n";
1.59      raeburn   576:         }
1.57      raeburn   577:     }
1.78      raeburn   578:     if ($env{'form.fixeddom'}) { 
                    579:         $output .= '<input type="hidden" name="fixeddom" value="'.$env{'form.fixeddom'}.'" />'."\n";
                    580:     }
1.74      bisitz    581:     $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
1.57      raeburn   582:     if ($sincefilterform) { 
1.74      bisitz    583:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
                    584:                   .$sincefilterform
                    585:                   .&Apache::lonhtmlcommon::row_closure();
1.57      raeburn   586:     }
                    587:     if ($domainselectform) {
1.74      bisitz    588:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
                    589:                   .$domainselectform
                    590:                   .&Apache::lonhtmlcommon::row_closure();
1.78      raeburn   591:     } 
1.57      raeburn   592:     if ($typeselectform) {
1.74      bisitz    593:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
                    594:                   .$typeselectform
                    595:                   .&Apache::lonhtmlcommon::row_closure();
1.57      raeburn   596:     }
                    597:     if ($instcodeform) {
1.78      raeburn   598:         $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
1.74      bisitz    599:                   .$instcodeform
                    600:                   .&Apache::lonhtmlcommon::row_closure();
1.57      raeburn   601:     }
                    602:     if (exists($filter->{'ownerfilter'})) {
1.79      raeburn   603:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
                    604:                    '<table><tr><td>'.&mt('Username').'<br />'.
                    605:                    '<input type="text" name="ownerfilter" size="20" value="'.
                    606:                    $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
                    607:                    $ownerdomselectform.'</td></tr></table>'.
                    608:                    &Apache::lonhtmlcommon::row_closure();
                    609:     }
                    610:     if (exists($filter->{'personfilter'})) {
                    611:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
                    612:                    '<table><tr><td>'.&mt('Username').'<br />'.
                    613:                    '<input type="text" name="personfilter" size="20" value="'.
                    614:                    $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
                    615:                    $persondomselectform.'</td></tr></table>'.
                    616:                    &Apache::lonhtmlcommon::row_closure();
1.57      raeburn   617:     }
                    618:     if (exists($filter->{'coursefilter'})) {
1.74      bisitz    619:         $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
                    620:                   .'<input type="text" name="coursefilter" size="25" value="'
                    621:                   .$list->{'coursefilter'}.'" />'
                    622:                   .&Apache::lonhtmlcommon::row_closure();
1.57      raeburn   623:     }
                    624:     if (exists($filter->{'descriptfilter'})) {
1.74      bisitz    625:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
                    626:                   .'<input type="text" name="descriptfilter" size="40" value="'
                    627:                   .$list->{'descriptfilter'}.'" />'
                    628:                   .&Apache::lonhtmlcommon::row_closure(1);
1.57      raeburn   629:     }
1.74      bisitz    630:     $output .= &Apache::lonhtmlcommon::end_pick_box();
1.70      raeburn   631:     $output .= '<p><input type="submit" name="gosearch" value="'. 
                    632:                &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
1.78      raeburn   633:     return $jscript.$output;
                    634: }
                    635: 
                    636: sub instcode_selectors {
1.80      raeburn   637:     my ($codedom,$formname,$officialjs) = @_;
1.78      raeburn   638:     my ($output,@codetitles,%cat_titles,%cat_order,%cat_items);
                    639:     my ($jscript,$totcodes,$numtitles,$lasttitle) =
                    640:         &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
1.80      raeburn   641:                            \%cat_items,\@codetitles,\%cat_titles,\%cat_order,$officialjs);
1.78      raeburn   642:     if ($numtitles > 0) {
1.80      raeburn   643:         my $unofficial = ' checked="checked" ';
                    644:         my $official = '';
                    645:         if ($env{'form.official'}) {
                    646:             $official = $unofficial;
                    647:             $unofficial = '';
                    648:         }
                    649:         $output .= '<span class="LC_nobreak">'.&mt('Official course:').'&nbsp;<label>'.
                    650:                    '<input type="radio" name="official" value="1"'.$official.' />'.
                    651:                    &mt('Yes').'</label>'.('&nbsp;'x3).'<label>'.
                    652:                    '<input type="radio" name="official" value="0"'.$unofficial.
                    653:                    ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
                    654:                    &Apache::courseclassifier::build_instcode_selectors($numtitles,
                    655:                    $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".
                    656:                    '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
                    657:                    '<input type="hidden" name="state" value="listing" />'."\n";
1.78      raeburn   658:  
                    659:     }
                    660:     return ($output,$jscript,$numtitles);
1.54      raeburn   661: }
                    662: 
                    663: sub search_courses {
1.78      raeburn   664:     my ($r,$type,$onlyown,$filter,$numtitles) = @_;
1.79      raeburn   665:     my (%courses,%showcourses);
1.54      raeburn   666:     if (!$onlyown) {
1.71      bisitz    667:         $r->print(&mt('Searching ...').'<br />&nbsp;<br />');
1.6       www       668:         $r->rflush();
1.54      raeburn   669:         if (($filter->{'ownerfilter'} ne '') ||
                    670:             ($filter->{'ownerdomfilter'} ne '')) {
                    671:             $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
                    672:                                            $filter->{'ownerdomfilter'};
                    673:         }
1.80      raeburn   674:         foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
1.54      raeburn   675:             if (!$filter->{$item}) {
                    676:                 $filter->{$item}='.';
                    677:             }
1.52      raeburn   678:         }
1.54      raeburn   679:         my $timefilter = 
                    680:            ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
1.78      raeburn   681:         my ($instcodefilter,$regexpok);
                    682:         if ($numtitles) {
1.80      raeburn   683:             if ($env{'form.official'}) {
                    684:                 $instcodefilter = 
                    685:                     &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},
                    686:                                                                    $numtitles);
                    687:                 $regexpok = 1;
                    688:             }
1.78      raeburn   689:         } else {
                    690:             $instcodefilter = $filter->{'instcodefilter'};
                    691:         }
1.80      raeburn   692:         if ($instcodefilter eq '') { $instcodefilter = '.'; }
                    693:         if ($type eq '') { $type = '.'; }
1.54      raeburn   694:         %courses = 
                    695:             &Apache::lonnet::courseiddump($filter->{'domainfilter'},
                    696:                                           $filter->{'descriptfilter'},
                    697:                                           $timefilter,
1.78      raeburn   698:                                           $instcodefilter,
1.54      raeburn   699:                                           $filter->{'combownerfilter'},
                    700:                                           $filter->{'coursefilter'},
1.78      raeburn   701:                                           undef,undef,$type,$regexpok);
1.79      raeburn   702:         if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
                    703:             my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
                    704:                                                          $filter->{'persondomfilter'},
                    705:                                                          'userroles',undef,
                    706:                                                          ['cc','in','ad','ep','ta','cr'],
                    707:                                                          $filter->{'domainfilter'});
                    708:             foreach my $role (keys(%rolehash)) {
                    709:                 my ($cnum,$cdom,$courserole) = split(':',$role);
                    710:                 my $cid = $cdom.'_'.$cnum;
                    711:                 if (exists($courses{$cid})) {
                    712:                     if (ref($courses{$cid}) eq 'HASH') {
                    713:                         if (ref($courses{$cid}{roles}) eq 'ARRAY') {
                    714:                             if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) { 
                    715:                                 push (@{$courses{$cid}{roles}},$courserole);
                    716:                             }
                    717:                         } else {
                    718:                             $courses{$cid}{roles} = [$courserole];
                    719:                         }
                    720:                         $showcourses{$cid} = $courses{$cid};
                    721:                     }
                    722:                 }
                    723:             }
                    724:             %courses = %showcourses;
                    725:         }
1.54      raeburn   726:     } else {
                    727:         $r->print('<br />');
1.60      raeburn   728:         my %coursehash = &Apache::loncommon::findallcourses(); 
                    729:         foreach my $cid (sort(keys(%coursehash))) {
1.65      raeburn   730:             $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
1.36      raeburn   731:         }
1.2       www       732:     }
1.54      raeburn   733:     return %courses;
1.18      raeburn   734: }
1.1       www       735: 
1.30      raeburn   736: sub course_chooser {
1.35      raeburn   737:     my ($multiple,$cdom,$cnum,$cleandesc) = @_;
1.30      raeburn   738:     my $output; 
1.35      raeburn   739:     if ($multiple) {
1.32      albertel  740:         $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.30      raeburn   741:     } else {
1.71      bisitz    742:         $output = '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
1.30      raeburn   743:                   "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
                    744:     }
                    745:     return $output;
1.49      raeburn   746: }
                    747: 
1.55      raeburn   748: sub gochoose_javascript {
1.57      raeburn   749:     my ($type,$multiple,$autosubmit,$lastaction) = @_;
1.55      raeburn   750:     my %elements = (
                    751:                      'Course' => {
                    752:                                  name  => 'coursepick',
                    753:                                  total => 'coursetotal',
                    754:                                  list  => 'courselist',
                    755:                                  },
1.57      raeburn   756:                      'Non-standard Course' => {
1.55      raeburn   757:                                  name  => 'grouppick',
                    758:                                  total => 'grouptotal',
                    759:                                  list  => 'grouplist',
                    760:                               },
                    761:                     );
1.57      raeburn   762:     my $output .= qq|
1.55      raeburn   763: <script type="text/javascript">
1.57      raeburn   764: function gochoose(cname,cdom,cdesc) {
1.55      raeburn   765:     var openerForm = "$env{'form.form'}";
                    766:     courseCount = 0;
                    767:     var courses = '';
1.57      raeburn   768: |;
                    769:     if ($multiple) {
                    770:         $output .= <<"ENDSCRIPT";
                    771:     courseCount = 0;
                    772:     var courses = '';
                    773:     if (typeof(document.courselist.course_id.length) == 'undefined') {
                    774:         // only 1 course checkbox was created
                    775:         if (document.courselist.course_id.checked) {
                    776:             courses = courses + document.courselist.course_id.value + "&&";
                    777:             courseCount ++;
                    778:         }
                    779:     } else {
                    780:         for (var j=0; j<document.courselist.course_id.length; j++) {
                    781:             if (document.courselist.course_id[j].checked) {
                    782:                 courses = courses + document.courselist.course_id[j].value + "&&";
1.55      raeburn   783:                 courseCount ++;
                    784:             }
1.57      raeburn   785:         }
                    786:     }
                    787:     opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
                    788:     if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
                    789:         'undefined') {
                    790:         if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
                    791:             opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55      raeburn   792:         } else {
1.57      raeburn   793:             opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55      raeburn   794:         }
1.57      raeburn   795:     } else {
                    796:         for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
                    797:             if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
                    798:                 opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55      raeburn   799:             } else {
1.57      raeburn   800:                 opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54      raeburn   801:             }
1.55      raeburn   802:         }
1.57      raeburn   803:     }
                    804:     if (courseCount > 0) {
                    805:         courses = courses.substr(0,courses.length-2);
                    806:         opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
                    807:     }
                    808: ENDSCRIPT
                    809:     } else {
                    810:         my $name_code;
                    811:         if ($env{'form.cnameelement'} ne '') {
                    812:             $name_code = 'opener.document.'.$env{'form.form'}.'.'.
                    813:                           $env{'form.cnameelement'}.'.value=cdesc;';
1.55      raeburn   814:         }
1.57      raeburn   815:         $output .= qq|
1.55      raeburn   816:         $name_code
                    817:         opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
                    818:         var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
                    819:         if (slct.options == undefined) {
                    820:             opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
                    821:         }
                    822:         else {
                    823:             var i;
                    824:             for (i=0;i<slct.length;i++) {
                    825:                 if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54      raeburn   826:             }
                    827:         }
1.57      raeburn   828: |;
1.54      raeburn   829:     }
1.57      raeburn   830:     $output .= qq|
1.55      raeburn   831:     if (openerForm == 'portform') {
                    832:         document.courselist.cnum.value = cname;
                    833:         document.courselist.cdom.value = cdom;
                    834:     }
                    835:     $autosubmit
                    836:     $lastaction
1.54      raeburn   837: }
1.55      raeburn   838: </script>
1.57      raeburn   839: |;
1.55      raeburn   840:     return $output;
1.54      raeburn   841: }
                    842: 
1.55      raeburn   843: 1;
                    844: __END__
                    845: 
                    846: =pod
                    847: 
                    848: =head1 NAME
                    849: 
                    850: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.   
                    851: 
                    852: =head1 SYNOPSIS
                    853: 
                    854: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user. 
                    855: 
                    856: =head1 OVERVIEW
                    857: 
                    858: Two screens are typically displayed to the user.  The first is a set of criteria which are used to constrain the search for courses.
                    859: 
                    860: =head2 Search Criteria (Screen One)
                    861: 
                    862: =head3 Criteria:
                    863: 
                    864: =over 4
                    865: 
                    866: =item *
                    867: Course Activity - how recently was course last visited by anyone.
                    868: 
                    869: =item *
                    870: Course Domain - the domain of the course
                    871: 
                    872: =item *
1.57      raeburn   873: Course Type - Course or Non-standard Course
1.55      raeburn   874: 
                    875: =item *
                    876: Course Institutional Code - the institutional identifier assigned to the course
                    877: 
                    878: =item * 
                    879: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
                    880: 
                    881: =item *
                    882: Course Owner's Domain - the domain of the owner of the course
                    883: 
                    884: =item * 
1.76      bisitz    885: Course Title - text which appears in the Course Title, as set in the Course Parameters.
1.55      raeburn   886: 
                    887: =item *
                    888: 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).
                    889: 
                    890: =back
                    891: 
                    892: 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'}).
                    893: 
                    894: =head2 Course Display (Screen Two)
                    895: 
                    896: 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:
                    897: 
                    898: =over 4
                    899: 
                    900: =item *
                    901: Course description
                    902: 
                    903: =item *
                    904: Domain description of course domain
                    905: 
                    906: =item *
                    907: Course institutional code
                    908: 
                    909: =item * 
                    910: Course owner (username:domain)   
                    911:  
                    912: =back
                    913: 
                    914: 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.
                    915: 
                    916: 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.
                    917: 
                    918: =head1 SUBROUTINES
                    919: 
                    920: =over 4
                    921: 
                    922: =item *
                    923: X<create_user_javascript()>
                    924: B<create_user_javascript($type)>:
                    925: 
1.57      raeburn   926: Input: 1 - $type  - the course type - Course or Non-standard Course
1.55      raeburn   927: 
                    928: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags 
                    929: 
                    930: Side Effects: None 
                    931: 
                    932: 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.
                    933: 
                    934: 
                    935: =item *
                    936: X<display_matched_courses()>
1.79      raeburn   937: B<display_matched_courses($r,$type,$multiple,$action,$showroles,%courses)>:
1.55      raeburn   938: 
1.79      raeburn   939: Input: 7 - request object, course type, multiple (0 or 1), form action, whether to show roles (for course personnel filter), hash of courses.
1.55      raeburn   940: 
                    941: Output: 0
                    942: 
                    943: 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.
                    944: 
                    945: =item *
                    946: X<multiples_tag()>
                    947: B<multiples_tag()>:
                    948: 
                    949: 
                    950: Input: 0
                    951: 
                    952: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
                    953: 
                    954: Side Effects: None
                    955: 
                    956: =item *
                    957: X<build_filters()>
1.81    ! raeburn   958: B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref,$caller)>:
1.55      raeburn   959: 
                    960: 
1.81    ! raeburn   961: Input: 7 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm).
1.55      raeburn   962: 
                    963: Output: 1 - $output - HTML for display of search criteria, and hidden form elements. 
                    964: 
                    965: Side Effects: None
                    966: 
                    967: =item *
                    968: X<search_courses()>
1.78      raeburn   969: B<search_courses($r,$type,$onlyown,$filter,$numtitles)>:
1.55      raeburn   970: 
                    971: 
1.78      raeburn   972: 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; for institutional codes - number of categories).  
1.55      raeburn   973: 
                    974: Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
                    975: 
                    976: Side Effects: None
                    977: 
                    978: 
                    979: =item *
                    980: X<course_chooser()>
                    981: B<course_chooser($multiple,$cdom,$cnum,$cleandesc)>:
                    982: 
                    983: Input: 4 - single (0) or multiple (1) courses; course domain, course number; course description. 
                    984: 
                    985: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user yo indicate course selection.
                    986: 
                    987: Side Effects: None
                    988: 
                    989: 
                    990: =item *
                    991: X<gochoose_javascript()>
1.57      raeburn   992: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>:
1.55      raeburn   993: 
1.66      raeburn   994: Input: 4 - course type; single (0) or multiple courses (1); in context of DC selecting a CC role in a course: javascript code from &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   995: 
                    996: Output: 1  $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
                    997: 
                    998: Side Effects: None
                    999: 
                   1000: javascript functions used when user selects a course(s). Different behavior depending on context:
                   1001: 
                   1002: =back
                   1003: 
                   1004: =over 8
                   1005: 
                   1006: =item
                   1007: 
                   1008: (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.
                   1009: 
                   1010: =item
                   1011: 
                   1012: (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.
                   1013: 
                   1014: =item
                   1015: 
                   1016: (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.
                   1017: 
                   1018: =item
1.54      raeburn  1019: 
1.55      raeburn  1020: (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  1021: 
1.55      raeburn  1022: =item
1.54      raeburn  1023: 
1.55      raeburn  1024: (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  1025: 
1.55      raeburn  1026: =item
1.54      raeburn  1027: 
1.55      raeburn  1028: (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  1029: 
1.55      raeburn  1030: =item
1.49      raeburn  1031: 
1.55      raeburn  1032: (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  1033: 
1.55      raeburn  1034: =back
                   1035:      
                   1036: =cut

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