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

1.1       www         1: # The LearningOnline Network
                      2: # Pick a course
                      3: #
1.56    ! albertel    4: # $Id: lonpickcourse.pm,v 1.55 2006/11/09 22:18:28 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.47      www        38: use lib '/home/httpd/lib/perl/';
                     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.55      raeburn    53:                                'multiple','type','setroles']);
1.54      raeburn    54: 
1.55      raeburn    55:     my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
                     56:         $lastaction,$autosubmit,$submitopener);
                     57: 
                     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.'" />';
                     76:         $submitopener = &Apache::lonroles::processpick();
                     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.54      raeburn    82:     if ((($env{'form.form'} eq 'portform') && ($env{'user.adv'}))) {
                     83:         $onlyown = 1;
1.49      raeburn    84:     }
1.55      raeburn    85: 
                     86:     my %loaditem;
1.27      albertel   87:     if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) {
1.42      albertel   88:         $loaditem{'onload'} ="setSections()";
1.30      raeburn    89:     }
1.41      albertel   90:     $r->print(&Apache::loncommon::start_page($title,undef,
1.42      albertel   91: 					     {'add_entries' => \%loaditem,
1.41      albertel   92: 					      'no_nav_bar'  => 1, }));
1.55      raeburn    93: 
                     94:     if ($env{'form.form'} eq 'portform') {
                     95:         $lastaction = 'document.courselist.submit()';
                     96:     } elsif ($env{'form.form'} eq 'cu') {
                     97:         $lastaction = 
                     98:              'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
                     99:              'document.courselist.submit();';
1.34      albertel  100:     } else {
1.55      raeburn   101:         $lastaction = 'self.close()';
1.1       www       102:     }
1.19      raeburn   103: 
1.55      raeburn   104:     # if called to assign a role in a course to a user via CUSR
                    105:     if ($env{'form.form'} eq 'cu') {
                    106:         $r->print(&create_user_javascript($type)); 
                    107:     }
1.54      raeburn   108: 
1.55      raeburn   109:     # print javascript functions for choosing a course 
                    110:     if ($env{'form.gosearch'} || $onlyown) {
                    111:         $r->print(&gochoose_javascript($type,$autosubmit,$lastaction));
                    112:     }
                    113:     $r->print('<script type="text/javascript">'.$jscript.'</script>');
                    114:     $r->print($submitopener);
1.54      raeburn   115: 
1.55      raeburn   116: # ------------------------------------------ Display of filters to limit search
                    117:     my (%filter,%list);
                    118:     if (!$onlyown) {
                    119:         my $filterlist = ['domainfilter','descriptfilter',
                    120:                           'instcodefilter','ownerfilter',
                    121:                           'ownerdomfilter'];
                    122:         # course ID filter for DCs only
                    123:         if ($env{'user.adv'} && $env{'form.domainfilter'} &&
                    124:             exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
                    125:             push(@{$filterlist},'coursefilter');
                    126:         }
                    127:         $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
                    128:                                  \%filter,\%list));
                    129:     }
1.54      raeburn   130: 
                    131: # ---------------------------------------------------------------- Get the data
                    132:     if ($env{'form.gosearch'} || $onlyown) {
                    133:         my %courses = &search_courses($r,$type,$onlyown,\%filter);
                    134:         &display_matched_courses($r,$type,$multiple,%courses);
                    135:     }
                    136:     $r->print(&Apache::loncommon::end_page());
                    137:     return OK;
                    138: }
                    139: 
1.55      raeburn   140: sub create_user_javascript {
                    141:     my ($type) = @_;
                    142:     my $output;
                    143:     #javascript for reporting sections and groups then closing
                    144:     if ($env{'form.pickedcourse'}) {
                    145:         my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
                    146:         my $sec_element = 'currsec';
                    147:         my $grplist_element = 'groups';
                    148:         my ($sections,$groups) =
                    149:           &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
                    150:         my $num_sections = scalar(@{$sections});
                    151:         my $seclist = join(',',@{$sections});
                    152:         my $num_groups = scalar(@{$groups});
                    153:         my $groupslist = join(',',@{$groups});
                    154:         $output = qq|
                    155: <script type="text/javascript">
                    156: function setSections() {
                    157:     opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
                    158:     window.opener.setSect('$seclist');
                    159:     self.close()
                    160: }
                    161: </script>
                    162: |;
                    163: ;
                    164:     }
                    165:     return $output;
                    166: }
                    167: 
1.54      raeburn   168: sub display_matched_courses {
                    169:     my ($r,$type,$multiple,%courses) = @_;
1.55      raeburn   170:     my $action = '/adm/pickcourse';
                    171:     if ($env{'form.form'} eq 'portform') {
                    172:         $action = '/adm/portfolio';
                    173:     }
                    174:     $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.54      raeburn   175:     my %by_descrip;
                    176:     my $numcourses = keys(%courses);
                    177:     foreach my $course (keys(%courses)) {
                    178:         my $descr;
                    179:         if ($courses{$course} =~ m/^([^:]*):/i) {
                    180:             $descr = &unescape($1);
1.34      albertel  181:         } else {
1.54      raeburn   182:             $descr = &unescape($courses{$course});
                    183:         }
                    184:         my $description = $descr;
                    185:         push (@{$by_descrip{$description}}, $course);
                    186:     }
                    187:     if ($numcourses > 1 && $multiple) {
                    188:         $r->print('<input type="button" value="check all"
                    189:                   onclick="javascript:checkAll(document.courselist.course_id)" />
                    190:                   &nbsp;&nbsp;<input type="button" value="uncheck all"
                    191:                   onclick="javascript:uncheckAll(document.courselist.course_id)" />
                    192:                   <br /><br />');
                    193:     }
                    194:     foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
                    195:         foreach my $course (@{$by_descrip{$description}}) {
                    196:             my $cleandesc=&HTML::Entities::encode($description,'<>&"');
                    197:             $cleandesc=~s/'/\\'/g;
                    198:             my ($cdom,$cnum)=split(/\_/,$course);
                    199:             my ($descr,$instcode,$owner,$ttype) = split/:/,$courses{$course};
                    200:             $r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc));
                    201:             $r->print($description.'('.
                    202:                       ($Apache::lonnet::domaindescription{$cdom}?
                    203:                        $Apache::lonnet::domaindescription{$cdom}:$cdom).")");
                    204:             unless ($instcode eq '') {
                    205:                 $r->print(" - ".&unescape($instcode));
                    206:             }
                    207:             unless ($owner eq '') {
                    208:                 $r->print(", owner - ".&unescape($owner));
1.23      raeburn   209:             }
1.54      raeburn   210:             unless ($ttype eq '') {
1.55      raeburn   211:                 $r->print('('.&unescape($ttype).')');
1.23      raeburn   212:             }
1.54      raeburn   213:             if ($multiple) { $r->print("</label>\n"); }
                    214:             $r->print("<br />\n");
1.19      raeburn   215:         }
                    216:     }
1.54      raeburn   217:     if (!%courses) {
                    218:         $r->print(&mt('None found'));
                    219:     } elsif ($multiple) {
                    220:         $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','',1)".'" />');
                    221:     }
                    222:     $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
                    223:               "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
                    224:               '<input type="hidden" name="cnumelement" value="'.$env{'form.cnumelement'}.'" />'."\n".
                    225:               '<input type="hidden" name="cdomelement" value="'.$env{'form.cdomelement'}.'" />'."\n".
                    226:               '<input type="hidden" name="type" value="'.$type.'" />'."\n");
                    227:     if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
                    228:         $r->print('<input type="hidden" name="roleelement" value="'.
                    229:                   $env{'form.roleelement'}.'" />'."\n");
                    230:     }
1.55      raeburn   231:     if ($env{'form.form'} eq 'portform') {
                    232:         $r->print('<input type="hidden" name="cnum" value="" />');
                    233:         $r->print('<input type="hidden" name="cdom" value="" />');
                    234:         $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
                    235:         $r->print('<input type="hidden" name="action" value="rolepicker" />');
                    236:     }
1.54      raeburn   237:     $r->print("</form>\n");
                    238:     return;
                    239: }
                    240: 
                    241: 
                    242: sub multiples_tag {
1.55      raeburn   243:     my $jscript = &Apache::loncommon::check_uncheck_jscript();
                    244:     my $multelement = '<input type="hidden" name="multiple" value="1" />';
                    245:     return ($jscript,$multelement);
1.1       www       246: }
1.30      raeburn   247: 
1.54      raeburn   248: sub build_filters {
1.55      raeburn   249:     my ($filterlist,$type,$roleelement,$multelement,$filter) = @_;
                    250:     my $list;
                    251:     my ($domainselectform,$sincefilterform,$ownerdomselectform,
1.54      raeburn   252:         $instcodeform,$typeselectform);
1.55      raeburn   253:     foreach my $item (@{$filterlist}) {
1.54      raeburn   254:         $filter->{$item} = $env{'form.'.$item};
                    255:         if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
                    256:             $filter->{$item} =~ s/\W//g;
                    257:             if (!$filter->{$item}) {
                    258:                 $filter->{$item} = '';
                    259:             }
                    260:         }
                    261:         if ($item eq 'domainfilter') {
                    262:             $domainselectform =
                    263:      &Apache::loncommon::select_dom_form($filter->{$item},'domainfilter',1);
                    264:         } elsif ($item eq 'ownerdomfilter') {
                    265:             $ownerdomselectform =
                    266:      &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
                    267:         } else {
                    268:             $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
                    269:         }
                    270:     }
                    271: 
                    272:     # last course activity filter and selection
                    273:     $filter->{'sincefilter'} = $env{'form.sincefilter'};
                    274:     $filter->{'sincefilter'} =~ s/[^\d-]//g;
                    275:     if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
                    276:     $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
                    277:        'sincefilter',('-1'=>'',
                    278:                       '86400' => 'today',
                    279:                       '604800' => 'last week',
                    280:                       '2592000' => 'last month',
                    281:                       '7776000' => 'last three months',
                    282:                       '15552000' => 'last six months',
                    283:                       '31104000' => 'last year',
                    284:                       'select_form_order' =>
                    285:                       ['-1','86400','604800','2592000','7776000',
                    286:                       '15552000','31104000']));
                    287: 
                    288:     my %lt = (
                    289:               'cac' => &mt('[_1] Activity',$type),
                    290:               'cde' => &mt('[_1] Description',$type),
                    291:               'cdo' => &mt('[_1] Domain',$type),
                    292:               'cin' => &mt('Course Institutional Code'),
                    293:               'cow' => &mt("[_1] Owner's Username",$type),
                    294:               'cod' => &mt("[_1] Owner's Domain", $type),
                    295:               'cog' => &mt('Course Type')
                    296:              );
1.49      raeburn   297: 
1.54      raeburn   298:     $typeselectform =  '<select name="type" size="1"';
                    299:     $typeselectform .= ">\n";
                    300:     if ($type eq 'Course') {
                    301:         $instcodeform = $lt{'cin'}.': <input type="text" name="instcodefilter"
                    302:  size="10" value="'.$list->{'instcodefilter'}.'" /><br />';
                    303:     }
                    304:     foreach my $posstype ('Course','Non-standard course') {
                    305:         $typeselectform.='<option value="'.$posstype.'" "'.
                    306:             ($posstype eq $type ? 'selected="selected" ' : ''). ">$posstype</option>\n";
                    307:     }
                    308:     $typeselectform.="</select>";
1.55      raeburn   309:     my $name_input;
                    310:     if ($env{'form.cnameelement'} ne '') {
                    311:         $name_input ='<input type="hidden" name="cnameelement" value="'.
                    312:                      $env{'form.cnameelement'}.'" />';
                    313:     }
                    314:     my $courseidtag;
                    315:     if (exists($filter->{'coursefilter'})) {
                    316:         $courseidtag=&mt('LON-CAPA course ID').
1.56    ! albertel  317:                      ': <input type="text" name="coursefilter" size="25" value="'.                     $list->{'coursefilter'}.'" /><br />';
1.55      raeburn   318:     }
1.54      raeburn   319:     my $output = <<"END";
1.48      raeburn   320: <form method="post" name="filterpicker" action="/adm/pickcourse">
1.27      albertel  321: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
                    322: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13      albertel  323: $name_input
1.27      albertel  324: <input type="hidden" name="form" value="$env{'form.form'}" />
1.18      raeburn   325: $roleelement
1.35      raeburn   326: $multelement
1.8       www       327: $lt{'cac'}: $sincefilterform
1.4       www       328: <br />
1.8       www       329: $lt{'cdo'}: $domainselectform
1.4       www       330: <br />
1.48      raeburn   331: $lt{'cog'}: $typeselectform
1.20      raeburn   332: <br />
1.48      raeburn   333: $instcodeform
1.20      raeburn   334: $lt{'cow'}:
1.54      raeburn   335: <input type="text" name="ownerfilter" size="10" value="$list->{'ownerfilter'}" />
1.20      raeburn   336: <br />
1.52      raeburn   337: $lt{'cod'}: $ownerdomselectform
                    338: <br />
1.28      raeburn   339: $courseidtag
1.8       www       340: $lt{'cde'}:
1.54      raeburn   341: <input type="text" name="descriptfilter" size="40" value="$list->{'descriptfilter'}" />
1.5       www       342: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4       www       343: </form>
1.5       www       344: <hr />
1.54      raeburn   345: END
                    346:     return $output; 
                    347: }
                    348: 
                    349: sub search_courses {
                    350:     my ($r,$type,$onlyown,$filter) = @_;
                    351:     my %courses;
                    352:     if (!$onlyown) {
1.8       www       353:         $r->print(&mt('Searching').' ...<br />&nbsp;<br />');
1.6       www       354:         $r->rflush();
1.54      raeburn   355:         if (($filter->{'ownerfilter'} ne '') ||
                    356:             ($filter->{'ownerdomfilter'} ne '')) {
                    357:             $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
                    358:                                            $filter->{'ownerdomfilter'};
                    359:         }
                    360:         foreach my $item ('descriptfilter','instcodefilter','coursefilter',
                    361:                           'combownerfilter') {
                    362:             if (!$filter->{$item}) {
                    363:                 $filter->{$item}='.';
                    364:             }
1.52      raeburn   365:         }
                    366:         if ($type eq '') { $type = '.'; }
1.54      raeburn   367:         my $timefilter = 
                    368:            ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
                    369:         %courses = 
                    370:             &Apache::lonnet::courseiddump($filter->{'domainfilter'},
                    371:                                           $filter->{'descriptfilter'},
                    372:                                           $timefilter,
                    373:                                           $filter->{'instcodefilter'},
                    374:                                           $filter->{'combownerfilter'},
                    375:                                           $filter->{'coursefilter'},
                    376:                                           undef,undef,$type);
                    377:     } else {
                    378:         $r->print('<br />');
                    379:         foreach my $cid (sort(&Apache::loncommon::findallcourses())) {
                    380:             $courses{$cid} = $env{'course.'.$cid.'.description'};
1.36      raeburn   381:         }
1.2       www       382:     }
1.54      raeburn   383:     return %courses;
1.18      raeburn   384: }
1.1       www       385: 
1.30      raeburn   386: sub course_chooser {
1.35      raeburn   387:     my ($multiple,$cdom,$cnum,$cleandesc) = @_;
1.30      raeburn   388:     my $output; 
1.35      raeburn   389:     if ($multiple) {
1.32      albertel  390:         $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.30      raeburn   391:     } else {
                    392:         $output = '<input type="button" value="Select" onClick="gochoose('.
                    393:                   "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
                    394:     }
                    395:     return $output;
1.49      raeburn   396: }
                    397: 
1.55      raeburn   398: sub gochoose_javascript {
                    399:     my ($type,$autosubmit,$lastaction) = @_;
                    400:     my %elements = (
                    401:                      'Course' => {
                    402:                                  name  => 'coursepick',
                    403:                                  total => 'coursetotal',
                    404:                                  list  => 'courselist',
                    405:                                  },
                    406:                      'Non-standard course' => {
                    407:                                  name  => 'grouppick',
                    408:                                  total => 'grouptotal',
                    409:                                  list  => 'grouplist',
                    410:                               },
                    411:                     );
                    412:     my $name_code;
                    413:     if ($env{'form.cnameelement'} ne '') {
                    414:         $name_code = 'opener.document.'.$env{'form.form'}.'.'.
                    415:                       $env{'form.cnameelement'}.'.value=cdesc;';
                    416:     }
                    417:     my $output .= <<"ENDSCRIPT";
                    418: <script type="text/javascript">
                    419: function gochoose(cname,cdom,cdesc,multiple,caller) {
                    420:     var openerForm = "$env{'form.form'}";
                    421:     courseCount = 0;
                    422:     var courses = '';
                    423:     if (multiple) {
                    424:         if (typeof(document.courselist.course_id.length) == 'undefined') {
                    425:             // only 1 course checkbox was created
                    426:             if (document.courselist.course_id.checked) {
                    427:                 courses = courses + document.courselist.course_id.value + "&&";
                    428:                 courseCount ++;
                    429:             }
                    430:         } else {
                    431:             for (var j=0; j<document.courselist.course_id.length; j++) {
                    432:                 if (document.courselist.course_id[j].checked) {
                    433:                     courses = courses + document.courselist.course_id[j].value + "&&";
                    434:                     courseCount ++;
                    435:                 }
                    436:             }
                    437:         }
                    438:         opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
                    439:         if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
                    440:             'undefined') {
                    441:             if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
                    442:                 opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
                    443:             } else {
                    444:                 opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
                    445:             }
1.54      raeburn   446:         } else {
1.55      raeburn   447:             for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
                    448:                 if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
                    449:                     opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
                    450:                 } else {
                    451:                     opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
                    452:                 }
1.54      raeburn   453:             }
1.55      raeburn   454:         }
                    455:         if (courseCount > 0) {
                    456:             courses = courses.substr(0,courses.length-2);
                    457:             opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
                    458:         }
                    459:     } else {
                    460:         $name_code
                    461:         opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
                    462:         var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
                    463:         if (slct.options == undefined) {
                    464:             opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
                    465:         }
                    466:         else {
                    467:             var i;
                    468:             for (i=0;i<slct.length;i++) {
                    469:                 if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54      raeburn   470:             }
                    471:         }
                    472:     }
1.55      raeburn   473:     if (openerForm == 'portform') {
                    474:         document.courselist.cnum.value = cname;
                    475:         document.courselist.cdom.value = cdom;
                    476:     }
                    477:     $autosubmit
                    478:     $lastaction
1.54      raeburn   479: }
1.55      raeburn   480: </script>
                    481: ENDSCRIPT
                    482:     return $output;
1.54      raeburn   483: }
                    484: 
1.55      raeburn   485: 1;
                    486: __END__
                    487: 
                    488: =pod
                    489: 
                    490: =head1 NAME
                    491: 
                    492: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.   
                    493: 
                    494: =head1 SYNOPSIS
                    495: 
                    496: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user. 
                    497: 
                    498: =head1 OVERVIEW
                    499: 
                    500: Two screens are typically displayed to the user.  The first is a set of criteria which are used to constrain the search for courses.
                    501: 
                    502: =head2 Search Criteria (Screen One)
                    503: 
                    504: =head3 Criteria:
                    505: 
                    506: =over 4
                    507: 
                    508: =item *
                    509: Course Activity - how recently was course last visited by anyone.
                    510: 
                    511: =item *
                    512: Course Domain - the domain of the course
                    513: 
                    514: =item *
                    515: Course Type - Course or Non-standard course
                    516: 
                    517: =item *
                    518: Course Institutional Code - the institutional identifier assigned to the course
                    519: 
                    520: =item * 
                    521: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
                    522: 
                    523: =item *
                    524: Course Owner's Domain - the domain of the owner of the course
                    525: 
                    526: =item * 
                    527: Course Description - text which appears in the Course Description (or title), as set in the Course Parameters.
                    528: 
                    529: =item *
                    530: 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).
                    531: 
                    532: =back
                    533: 
                    534: 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'}).
                    535: 
                    536: =head2 Course Display (Screen Two)
                    537: 
                    538: 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:
                    539: 
                    540: =over 4
                    541: 
                    542: =item *
                    543: Course description
                    544: 
                    545: =item *
                    546: Domain description of course domain
                    547: 
                    548: =item *
                    549: Course institutional code
                    550: 
                    551: =item * 
                    552: Course owner (username:domain)   
                    553:  
                    554: =back
                    555: 
                    556: 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.
                    557: 
                    558: 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.
                    559: 
                    560: =head1 SUBROUTINES
                    561: 
                    562: =over 4
                    563: 
                    564: =item *
                    565: X<create_user_javascript()>
                    566: B<create_user_javascript($type)>:
                    567: 
                    568: Input: 1 - $type  - the course type - Course or Non-standard course
                    569: 
                    570: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags 
                    571: 
                    572: Side Effects: None 
                    573: 
                    574: 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.
                    575: 
                    576: 
                    577: =item *
                    578: X<display_matched_courses()>
                    579: B<display_matched_courses($r,$type,$multiple,%courses)>:
                    580: 
                    581: Input: 4 - request object, course type, multiple (0 or 1), hash of courses.
                    582: 
                    583: Output: 0
                    584: 
                    585: 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.
                    586: 
                    587: =item *
                    588: X<multiples_tag()>
                    589: B<multiples_tag()>:
                    590: 
                    591: 
                    592: Input: 0
                    593: 
                    594: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
                    595: 
                    596: Side Effects: None
                    597: 
                    598: =item *
                    599: X<build_filters()>
                    600: B<build_filters($filterlist,$type,$roleelement,$multelement,$filter)>:
                    601: 
                    602: 
                    603: Input: 5 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values.
                    604: 
                    605: Output: 1 - $output - HTML for display of search criteria, and hidden form elements. 
                    606: 
                    607: Side Effects: None
                    608: 
                    609: =item *
                    610: X<search_courses()>
                    611: B<search_courses($r,$type,$onlyown,$filter)>:
                    612: 
                    613: 
                    614: 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.
                    615: 
                    616: Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
                    617: 
                    618: Side Effects: None
                    619: 
                    620: 
                    621: =item *
                    622: X<course_chooser()>
                    623: B<course_chooser($multiple,$cdom,$cnum,$cleandesc)>:
                    624: 
                    625: Input: 4 - single (0) or multiple (1) courses; course domain, course number; course description. 
                    626: 
                    627: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user yo indicate course selection.
                    628: 
                    629: Side Effects: None
                    630: 
                    631: 
                    632: =item *
                    633: X<gochoose_javascript()>
                    634: B<gochoose_javascript($type,$autosubmit,$lastaction)>:
                    635: 
                    636: Input: 3 - course type; in context of DC selecting a CC role in a course: javascript code from Apache::lonroles::processpick(); final action to take after user chooses course(s):  either close window, or submit form for display of next page etc.
                    637: 
                    638: Output: 1  $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
                    639: 
                    640: Side Effects: None
                    641: 
                    642: javascript functions used when user selects a course(s). Different behavior depending on context:
                    643: 
                    644: =back
                    645: 
                    646: =over 8
                    647: 
                    648: =item
                    649: 
                    650: (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.
                    651: 
                    652: =item
                    653: 
                    654: (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.
                    655: 
                    656: =item
                    657: 
                    658: (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.
                    659: 
                    660: =item
1.54      raeburn   661: 
1.55      raeburn   662: (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   663: 
1.55      raeburn   664: =item
1.54      raeburn   665: 
1.55      raeburn   666: (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   667: 
1.55      raeburn   668: =item
1.54      raeburn   669: 
1.55      raeburn   670: (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   671: 
1.55      raeburn   672: =item
1.49      raeburn   673: 
1.55      raeburn   674: (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   675: 
1.55      raeburn   676: =back
                    677:      
                    678: =cut

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