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

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

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