File:  [LON-CAPA] / loncom / interface / lonpickcourse.pm
Revision 1.60: download - view: text, annotated - select for diffs
Wed Nov 29 07:46:39 2006 UTC (17 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_3_X, HEAD
evb privilege - with this privilege users evade blocking of communication functionality defined by blocks placed by users with dcm privilege.

dcm privilege - this is now used to determine if link to block setting is displayed.

loncommon::findallcourses() now return a hash, where the keys are courseIDs instead of an array of courseIDs.  Places where findallcourses() was called - lonannounce, lonpickcourse changed accordingly.

loncommon::findallcourses() now reports courses for a user where the user's only role was a custom role.

lonnet::allowed() can now take a fourth optional argument ($role) which allows privs to be investigated for roles other than the user's currently active role

&blockcheck, &parse_block_record(), and &build_block_table() moved from lonmsgdisplay to loncommon, so they are available for evaluation of blocking state for other communication functions besides COM.

Each block record for a blocking event in a course is now a hash, with key=values of the hash being setter = username:domain of user who set block, title=event title for block, and blocks = hash of blocked features ('com','chat','boards','port','groups').

Backwards compatibility retained with previous : separated text for block record value.

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

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