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

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

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