File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.57: download - view: text, annotated - select for diffs
Sun Feb 6 21:36:59 2022 UTC (2 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6907
  - Domain default to determine whether LTI launch of deep-linked URL requires
    student to authenticate; can be overridden for specific course(s).
  - If domain config permits it, link protection setting in a course can
    specify whether to accept username included in LTI payload, and action
    to take if username is not for an enrolled student.
  - Second arg passed to ltiauth::invalid_request() is text string stating why
    LTI launch was invalid.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: lonconfigsettings.pm,v 1.57 2022/02/06 21:36:59 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: # /home/httpd/html/adm/gpl.txt
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: #
   28: ###############################################################
   29: ##############################################################
   30: 
   31: package Apache::lonconfigsettings;
   32: 
   33: use strict;
   34: use Apache::lonnet;
   35: use Apache::loncommon();
   36: use Apache::lonhtmlcommon();
   37: use Apache::lonlocal;
   38: use Apache::lonparmset();
   39: use Apache::courseclassifier();
   40: use LONCAPA qw(:DEFAULT :match); 
   41: 
   42: sub print_header {
   43:     my ($r,$phase,$context,$jscript,$container,$instcode,$dom,$values) = @_;
   44:     my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
   45:         $crstype,@actions,@code_order);
   46:     if ($phase eq 'display') {
   47:         @actions = &Apache::loncommon::get_env_multiple('form.actions');
   48:     }
   49:     if ($context eq 'domain') {
   50:         ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
   51:         $action = '/adm/domainprefs';
   52:         if ($phase eq 'display') {
   53:             if (grep(/^coursecategories$/,@actions)) {
   54:                 $call_category_check = qq|
   55:     if (formname == document.display) {
   56:         if (!categoryCheck(formname)) {
   57:             return;
   58:         }
   59:     }
   60: |;
   61:             }
   62:         }
   63:     } else {
   64:         $crstype = &Apache::loncommon::course_type();
   65:         if ($crstype eq 'Community') {
   66:             ($pagetitle,$brcrumtitle) = ('Community Configuration','Community Configuration');
   67:         } else {
   68:             ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
   69:         }
   70:         $action = '/adm/courseprefs';
   71:         if ($phase eq 'display') {
   72:             if (grep(/^courseinfo$/,@actions)) {
   73:                 my %codedefaults;
   74:                 &Apache::lonnet::auto_instcode_defaults($env{'request.role.domain'},\%codedefaults,
   75:                                                         \@code_order);
   76:                 if (@code_order) {
   77:                    my $noinstcodestr = &mt('You indicated cloning based on category, but did not select any categories.');
   78:                    &js_escape(\$noinstcodestr);
   79:                    $instcode_check = <<"ENDSCRIPT";
   80:     if (formname == document.display) {
   81:         if (formname.cloners_instcode.length) {
   82:             for (var j=0; j<formname.cloners_instcode.length; j++) {
   83:                 if (formname.cloners_instcode[j].checked) {
   84:                     if (formname.cloners_instcode[j].value == 1) {
   85:                         var codes;
   86:                         if (document.getElementsByClassName) {
   87:                             codes = document.getElementsByClassName('LC_cloners_instcodes');
   88:                         } else {
   89:                             codes = getElementsByClassName(document.body,'LC_cloners_instcodes');
   90:                         }
   91:                         if (codes.length) {
   92:                             var gotcode = 0;
   93:                             for (var i=0; i<codes.length; i++) {
   94:                                 if (codes[i].selectedIndex != 0) {
   95:                                      gotcode = 1; 
   96:                                      break;
   97:                                 }
   98:                             }
   99:                             if (!gotcode) {
  100:                                 for (var k=0; k<formname.cloners_instcode.length; k++) {
  101:                                     if (formname.cloners_instcode[k].value == 0) {
  102:                                         formname.cloners_instcode[k].checked = true;
  103:                                     }
  104:                                 }
  105:                                 toggleCloners(document.display.cloners_instcode);
  106:                                 alert('$noinstcodestr');
  107:                                 return false;
  108:                             }
  109:                         }
  110:                     }
  111:                 }
  112:             }
  113:         }
  114:     }
  115: 
  116: ENDSCRIPT
  117:                 }
  118:             }
  119:         }
  120:     }
  121:     my $alert = &mt('You must select at least one functionality type to display.');
  122:     &js_escape(\$alert);
  123:     my $js = '
  124: <script type="text/javascript">
  125: // <![CDATA[
  126: 
  127: function changePage(formname,newphase) {
  128:     formname.phase.value = newphase;
  129:     numchecked = 0;
  130:     if (formname == document.pickactions) {
  131:         if (formname.actions.length > 0) {
  132:             for (var i = 0; i<formname.actions.length; i++) {
  133:                 if (formname.actions[i].checked) {
  134:                     numchecked ++;
  135:                 }
  136:             }
  137:         } else {
  138:             if (formname.actions.checked) {
  139:                 numchecked ++;
  140:             }
  141:         }
  142:         if (numchecked > 0) {
  143:             formname.submit();
  144:         } else {
  145:             alert("'.$alert.'");
  146:             return;
  147:         }
  148:     }
  149:     '.$instcode_check.$call_category_check.'
  150:     formname.submit();
  151: }'."\n";
  152:     if ($phase eq 'pickactions') {
  153: 	$js .= &Apache::lonhtmlcommon::color_picker();
  154:         $js .=
  155:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
  156:     } elsif ($phase eq 'display') {
  157: 	$js .= &Apache::lonhtmlcommon::color_picker();
  158:         $js .= &color_pick_js()."\n";
  159:     }
  160:     $js .= &Apache::loncommon::viewport_size_js().'
  161: 
  162: // ]]>
  163: </script>
  164: ';
  165:     if ($jscript) {
  166:         $js .= "
  167: 
  168: $jscript
  169: 
  170: ";
  171:     }
  172:     my $additem;
  173:     if ($phase eq 'pickactions') {
  174:         my %loaditems = (
  175:                     'onload' => "setFormElements(document.pickactions);",
  176:                         );
  177:         $additem = {'add_entries' => \%loaditems,};
  178:     } elsif ($phase eq 'display') {
  179:         if ($context eq 'domain') {
  180:             my $onload;
  181:             if (grep(/^coursedefaults$/,@actions)) {
  182:                 $onload = "toggleDisplay(document.display,'cloneinstcode');".
  183:                           "toggleDisplay(document.display,'credits');".
  184:                           "toggleDisplay(document.display,'studentsubmission');";
  185:             }
  186:             if (grep(/^selfcreation$/,@actions)) {
  187:                 my $prefix = 'cancreate_emailverified';
  188:                 my $customclass = 'LC_selfcreate_email';
  189:                 my $classprefix = 'LC_canmodify_emailusername_';
  190:                 my $optionsprefix = 'LC_options_emailusername_';
  191:                 $onload .= "toggleRows(document.display,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
  192:                 my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
  193:                 my $hascustom;
  194:                 my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
  195:                 if (ref($emailrules) eq 'HASH') {
  196:                     if (keys(%{$emailrules}) > 0) {
  197:                         $hascustom = 'cancreate_emailrule';
  198:                     }
  199:                 }
  200:                 my @posstypes;
  201:                 if (ref($types) eq 'ARRAY') {
  202:                     @posstypes = @{$types};
  203:                     push(@posstypes,'default');
  204:                     foreach my $type (@posstypes) {
  205:                         $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
  206:                                                                "'cancreate_emaildomain','$type');";
  207:                     }
  208:                 } else {
  209:                     $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
  210:                                                        "'cancreate_emaildomain','default');";
  211:                 }
  212:             } 
  213:             if (grep(/^contacts$/,@actions)) {
  214:                 my $customclass = 'LC_helpdesk_override';
  215:                 my $optionsprefix = 'LC_options_helpdesk_';
  216:                 $onload .= "toggleHelpdeskRow(document.display,'overrides','$customclass','$optionsprefix');";
  217:             }
  218:             if (grep(/^lti$/,@actions)) {
  219:                 $onload .= "toggleLTI(document.display,'user','add');".
  220:                            "toggleLTI(document.display,'crs','add');".
  221:                            "toggleLTI(document.display,'sec','add');".
  222:                            "toggleLTI(document.display,'lcauth','add');".
  223:                            "toggleLTI(document.display,'lcmenu','add');".
  224:                            "toggleLTI(document.display,'passback','add');".
  225:                            "toggleLTI(document.display,'callback','add');";
  226:                 if (ref($values) eq 'HASH') {
  227:                     if (ref($values->{'lti'}) eq 'HASH') {
  228:                         my $numlti = scalar(keys(%{$values->{'lti'}}));
  229:                         for (my $i=0; $i<$numlti; $i++) {
  230:                             $onload .= "toggleLTI(document.display,'user','$i');".
  231:                                        "toggleLTI(document.display,'crs','$i');".
  232:                                        "toggleLTI(document.display,'sec','$i');".
  233:                                        "toggleLTI(document.display,'lcauth','$i');".
  234:                                        "toggleLTI(document.display,'lcmenu','$i');".
  235:                                        "toggleLTI(document.display,'passback','$i');".
  236:                                        "toggleLTI(document.display,'callback','$i');";
  237:                         }
  238:                     }
  239:                 }
  240:             }
  241:             if (grep(/^ltitools$/,@actions)) {
  242:                 $onload .= "toggleLTITools(document.display,'passback','add');".
  243:                            "toggleLTITools(document.display,'roster','add');".
  244:                            "toggleLTITools(document.display,'user','add');";
  245:                 if (ref($values) eq 'HASH') {
  246:                     if (ref($values->{'ltitools'}) eq 'HASH') {
  247:                         my $numltitools = scalar(keys(%{$values->{'ltitools'}}));
  248:                         for (my $i=0; $i<$numltitools; $i++) {
  249:                             $onload .= "toggleLTITools(document.display,'passback','$i');".
  250:                                        "toggleLTITools(document.display,'roster','$i');".
  251:                                        "toggleLTITools(document.display,'user','$i');";
  252:                         }
  253:                     }
  254:                 }
  255:             }
  256:             if (grep(/^wafproxy$/,@actions)) {
  257:                 $onload .= "toggleWAF();checkWAF();updateWAF();";
  258:             }
  259:             if (grep(/^proctoring$/,@actions)) {
  260:                 $onload .= "toggleProctoring(document.display,'proctorio');".
  261:                            "toggleProctoring(document.display,'examity');";
  262:             }
  263:             if (grep(/^scantron$/,@actions)) {
  264:                 $onload .= "toggleScantron(document.display);";
  265:             }
  266:             if (grep(/^autoupdate$/,@actions)) {
  267:                 $onload .= "toggleLastActiveDays(document.display);";
  268:             }
  269:             if (grep(/^autoenroll$/,@actions)) {
  270:                 $onload .= "toggleFailsafe(document.display);";
  271:             }
  272:             if (grep(/^login$/,@actions)) {
  273:                 my %domservers = &Apache::lonnet::get_servers($dom);
  274:                 foreach my $server (sort(keys(%domservers))) {
  275:                     $onload .= "toggleSamlOptions(document.display,'$server');";
  276:                 }
  277:             }
  278:             if ($onload) {
  279:                 my %loaditems = (
  280:                                   'onload' => $onload,
  281:                                 );
  282:                 $additem = {'add_entries' => \%loaditems,};
  283:             }
  284:         } elsif ($context eq 'course') {
  285:             my $onload;
  286:             if (grep(/^courseinfo$/,@actions)) {
  287:                 if (@code_order) {
  288:                     $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);";
  289:                 }
  290:             }
  291:             if (grep(/^linkprotection$/,@actions)) {
  292:                 if (ref($values) eq 'HASH') {
  293:                     if (ref($values->{'linkprotection'}) eq 'HASH') {
  294:                         my $ltiauth;
  295:                         if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
  296:                             $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
  297:                         } else {
  298:                             my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
  299:                             $ltiauth = $domdefs{'crsltiauth'};
  300:                         }
  301:                         my $posslti = scalar(keys(%{$values->{'linkprotection'}}));
  302:                         for (my $i=0; $i<=$posslti; $i++) {
  303:                             my $num = $i;
  304:                             if ($i == $posslti) {
  305:                                 $num = 'add';
  306:                             }
  307:                             if (ref($values->{'linkprotection'}->{$i}) eq 'HASH') {
  308:                                 if ($values->{'linkprotection'}->{$i}->{'usable'}) {
  309:                                     $onload .= "toggleLTI(document.display,'$num','secret');";
  310:                                 }
  311:                             } 
  312:                             if ($ltiauth) {
  313:                                 $onload .= "toggleLTIReqUser(document.display,'requser','optional','1','block','$num');".
  314:                                            "toggleLTIReqUser(document.display,'mapuser','userfield','other','inline-block','$num');";
  315:                             }
  316:                         }
  317:                     }
  318:                 }
  319:             }
  320:             if ($onload) {
  321:                 my %loaditems = (
  322:                                   'onload' => $onload,
  323:                                 );
  324:                 $additem = {'add_entries' => \%loaditems,};
  325:             }
  326:         }
  327:     }
  328:     $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
  329:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
  330:     $r->print('
  331: <form name="parmform" action="">
  332: <input type="hidden" name="pres_marker" />
  333: <input type="hidden" name="pres_type" />
  334: <input type="hidden" name="pres_value" />
  335: </form>
  336: ');
  337:     if ($container) {
  338:        &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
  339:     }
  340:     $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
  341:               ' enctype="multipart/form-data">');
  342:     return;
  343: }
  344: 
  345: sub print_footer {
  346:     my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
  347:     $button_text = &mt($button_text);
  348:     $r->print('<input type="hidden" name="phase" value="" />');
  349:     if (defined($env{'form.origin'})) {
  350:         $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
  351:     }
  352:     if (($phase eq 'display') || ($phase eq 'process')) {
  353:         if (ref($actions) eq 'ARRAY') {
  354:             foreach my $item (@{$actions}) {
  355:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
  356:             }
  357:         }
  358:     }
  359:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  360:     if ($phase eq 'process') {
  361:         $r->print(
  362:             &Apache::lonhtmlcommon::actionbox(
  363:                 ['<a href='.$dest.'>'.$button_text.'</a>']));
  364:     } else {
  365:         my $onclick;
  366:         if ($phase eq 'display') {
  367:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  368:         } else {
  369:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  370:         }
  371:         my $showbutton = 1;
  372:         if (ref($parm_permission) eq 'HASH') {
  373:             unless (($parm_permission->{'process'}) || ($newphase eq 'display')) {
  374:                 $showbutton = 0;
  375:             }
  376:         }
  377:         if ($showbutton) {
  378:             $r->print('<p><input type="button" name="store" value="'.
  379:                       $button_text.'" onclick='.$onclick.' /></p>');
  380:         } 
  381:     }
  382:     if ($phase eq 'process') {
  383:         $r->print('</form>');
  384:         if ($container) {
  385:            &Apache::lonparmset::endSettingsScreen($r);
  386:         }
  387:         $r->print(&Apache::loncommon::end_page());
  388:     }
  389:     return;
  390: }
  391: 
  392: sub make_changes {
  393:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
  394:         $allitems,$container,$parm_permission) = @_;
  395:     my %brcrumtext = &get_crumb_text();
  396:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  397:     my ($numchanged,%changes,%disallowed);
  398:     &Apache::lonhtmlcommon::add_breadcrumb
  399:       ({href=>"javascript:changePage(document.$phase,'display')",
  400:         text=>$brcrumtext{$context}},
  401:        {href=>"javascript:changePage(document.$phase,'$phase')",
  402:         text=>"Updated"});
  403:     &print_header($r,$phase,$context,undef,$container);
  404:     my ($crstype,%lastact,$errors);
  405:     if ($context eq 'course') {
  406:         $crstype = &Apache::loncommon::course_type();
  407:     }
  408:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && 
  409:         (ref($prefs) eq 'HASH')) {
  410:         foreach my $item (@{$prefs_order}) {
  411:             if (grep(/^\Q$item\E$/,@actions)) {
  412:                 if ($context eq 'domain') {
  413:                     $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
  414:                               &Apache::domainprefs::process_changes($r,$dom,
  415:                                           $confname,$item,$roles,$values,\%lastact));
  416:                 } else {
  417:                     $changes{$item} = {};
  418:                     $errors =
  419:                         &Apache::courseprefs::process_changes($dom,$confname,$item,$values,
  420:                                                               $prefs->{$item},$changes{$item},
  421:                                                               $allitems,\%disallowed,$crstype);
  422:                     if (keys(%{$changes{$item}}) > 0) {
  423:                         $numchanged ++;
  424:                     }
  425:                 }
  426:             }
  427:         }
  428:     }
  429:     if ($context eq 'course') {
  430:         if ($numchanged) {
  431:             my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
  432:                                                           $prefs,$values,\%changes,$crstype);
  433:             $r->print(&Apache::loncommon::confirmwrapper($message));
  434:         } else {
  435:             if ($crstype eq 'Community') {
  436:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
  437:             } else {
  438:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
  439:             }
  440:         }
  441:         if (keys(%disallowed) > 0) {
  442:             $r->print('<p>');
  443:             foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
  444:                 if (ref($disallowed{$item}) eq 'HASH') {
  445:                     if (keys(%{$disallowed{$item}}) > 0) {
  446:                         $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
  447:                                                                            $prefs,$crstype));
  448:                     }
  449:                 }
  450:             }
  451:             $r->print('</p>');
  452:         }
  453:         if ($errors) {
  454:             $r->print('<p>'.$errors.'</p>');
  455:         }
  456:     }
  457:     $r->print('<p>');
  458:     my $footer_text = 'Back to configuration display';
  459:     if ($context eq 'course') {
  460:         $footer_text = 'Back to display/edit settings'; 
  461:     }
  462:     &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
  463:     $r->print('</p>');
  464:     return \%lastact;
  465: }
  466: 
  467: sub display_settings {
  468:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
  469:         $allitems,$crstype,$container,$parm_permission) = @_;
  470:     my %brcrumtext = &get_crumb_text();
  471:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  472:     &Apache::lonhtmlcommon::add_breadcrumb
  473:         ({href=>"javascript:changePage(document.$phase,'display')",
  474:           text=>"Display/Edit Settings"});
  475:     my $instcode;
  476:     if (ref($values) eq 'HASH') {
  477:         $instcode = $values->{'internal.coursecode'};
  478:     }
  479:     &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$values);
  480:     my $divwidth = 900;
  481:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
  482:         if (@actions > 0) {
  483:             my $rowsum = 0;
  484:             my (%output,%rowtotal,@items,$got_check_uncheck);
  485:             foreach my $item (@{$prefs_order}) {
  486:                 if (grep(/^\Q$item\E$/,@actions)) {
  487:                     push(@items,$item);
  488:                     if ($context eq 'domain') {
  489:                         my $settings;
  490:                         if (ref($values) eq 'HASH') { 
  491:                             $settings = $values->{$item};
  492:                         }
  493:                         if (($item eq 'usersessions') || ($item eq 'ssl')) {
  494:                             unless ($got_check_uncheck) {
  495:                                 $r->print('<script type="text/javascript">'."\n".
  496:                                           '// <![CDATA['."\n".
  497:                                           &Apache::loncommon::check_uncheck_jscript()."\n".
  498:                                           '// ]]>'."\n".
  499:                                           '</script>'."\n");
  500:                                 $got_check_uncheck = 1;
  501:                             }
  502:                         } elsif ($item eq 'selfcreation') {
  503:                             if (ref($values) eq 'HASH') {
  504:                                 $settings = $values->{'usercreation'};
  505:                             }
  506:                         } elsif ($item eq 'defaults') {
  507:                             if (ref($values->{'inststatus'}) eq 'HASH') {
  508:                                 if (ref($values->{'defaults'}) eq 'HASH') {
  509:                                     $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
  510:                                 } else {
  511:                                     $settings = $values->{'inststatus'};
  512:                                 }
  513:                             } else {
  514:                                 my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
  515:                                 my $inststatus = {
  516:                                                    inststatustypes => $usertypes,
  517:                                                    inststatusorder => $types,
  518:                                                    inststatusguest => [], 
  519:                                                  };
  520:                                 if (ref($values->{defaults}) eq 'HASH') {
  521:                                     $settings = {%{$inststatus},%{$values->{'defaults'}}};
  522:                                 } else {
  523:                                     $settings = $inststatus;
  524:                                 }
  525:                             }
  526:                         }
  527:                         ($output{$item},$rowtotal{$item}) =
  528:                             &Apache::domainprefs::print_config_box($r,$dom,$confname,
  529:                                 $phase,$item,$prefs->{$item},$settings);
  530:                     } else {
  531:                         ($output{$item},$rowtotal{$item}) =
  532:                             &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase,
  533:                                 $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
  534:                     }
  535:                     $rowsum += $rowtotal{$item};
  536:                 }
  537:             }
  538:             $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
  539:             for (my $i=0; $i<@items; $i++) {
  540:                 $r->print($output{$items[$i]});
  541:             }
  542:             $r->print('</div>');
  543:             $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
  544:         } else {
  545:             $r->print('<input type="hidden" name="phase" value="" />'.
  546:                       '<span class="LC_error">'.&mt('No settings chosen').
  547:                       '</span>');
  548:         }
  549:         $r->print('</form>');
  550:     }
  551:     if ($container) {
  552:         &Apache::lonparmset::endSettingsScreen($r);
  553:     }
  554:     $r->print(&Apache::loncommon::end_page());
  555:     return;
  556: }
  557: 
  558: sub display_choices {
  559:     my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
  560:     if ($phase eq '') {
  561:         $phase = 'pickactions';
  562:     }
  563:     my %helphash;
  564:     &print_header($r,$phase,$context,undef,$container);
  565:     $r->print('<script type="text/javascript">'."\n".
  566:               '// <![CDATA['."\n".
  567:               &Apache::loncommon::check_uncheck_jscript()."\n".
  568:               '// ]]>'."\n".
  569:               '</script>'."\n");
  570:     my $heading = &mt('Settings to display/modify');
  571:     if (ref($parm_permission) eq 'HASH') {
  572:         unless ($parm_permission->{'process'}) {
  573:             $heading = &mt('Settings to display');
  574:         }
  575:     }
  576:     $r->print('<h3>'.$heading.'</h3>'.
  577:               '<div><input type="button" value="'.&mt('check all').'" '.
  578:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
  579:               ' />'.('&nbsp;'x2).
  580:               '<input type="button" value="'.&mt('uncheck all').'" '.
  581:               'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
  582:               "\n".
  583:               '</div><div class="LC_left_float">');
  584:     my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
  585:     if (ref($prefs_order) eq 'ARRAY') {
  586:         $numitems = @{$prefs_order};
  587:     }
  588:     my $numcols = 3;
  589:     $maxincol = int($numitems/$numcols);
  590:     if ($numitems%$numcols) {
  591:         $maxincol ++;
  592:     }
  593:     $firstthird = $maxincol;
  594:     $secondthird = $firstthird + $maxincol;
  595:     $count = 0;
  596:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
  597:         foreach my $item (@{$prefs_order}) {
  598:             $r->print('<h4>'.
  599:                       &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
  600:                       '<label><input type="checkbox" name="actions" value="'.$item.
  601:                       '" />&nbsp;'.&mt($prefs->{$item}->{'text'}).'</label></h4>');
  602:             $count ++;
  603:             if ((!$seconddiv) && ($count >= $firstthird)) {
  604:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  605:                 $seconddiv = 1;
  606:             }
  607:             if ((!$thirddiv) && ($count >= $secondthird)) {
  608:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  609:                 $thirddiv = 1;
  610:             }
  611:         }
  612:     }
  613:     $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
  614:     $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
  615:     $r->print('</form>');
  616:     if ($container) {
  617:         &Apache::lonparmset::endSettingsScreen($r);
  618:     }
  619:     $r->print(&Apache::loncommon::end_page());
  620:     return;
  621: }
  622: 
  623: sub color_pick_js {
  624:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  625:     my $output = <<"ENDCOL";
  626: 
  627:     $pjump_def
  628: 
  629:     function psub() {
  630:         modalWindow.close();
  631:         if (document.parmform.pres_marker.value!='') {
  632:             if (document.parmform.pres_type.value!='') {
  633:                 eval('document.display.'+
  634:                      document.parmform.pres_marker.value+
  635:                      '.value=document.parmform.pres_value.value;');
  636:             }
  637:         } else {
  638:             document.parmform.pres_value.value='';
  639:             document.parmform.pres_marker.value='';
  640:         }
  641:     }
  642: 
  643:     function get_id (span_id) {
  644:         if (document.getElementById) {
  645:             return document.getElementById(span_id);
  646:         }
  647:         if (document.all) {
  648:             return document.all[span_id];
  649:         }
  650:         return false;
  651:     }
  652: 
  653:     function colchg_span (span_id_str,new_color_item) {
  654:         var span_ref = get_id(span_id_str);
  655:         if (span_ref.style) { span_ref = span_ref.style; }
  656:         span_ref.background = new_color_item.value;
  657:         span_ref.backgroundColor = new_color_item.value;
  658:         span_ref.bgColor = new_color_item.value;
  659:     }
  660: 
  661: ENDCOL
  662:     return $output;
  663: }
  664: 
  665: sub get_crumb_text {
  666:     my %brcrumbtext = (
  667:                        domain => 'Domain Settings',
  668:                        course => 'Display/Edit Settings',
  669:                      );
  670:     return %brcrumbtext;
  671: }
  672: 
  673: 1;

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