File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.62: download - view: text, annotated - select for diffs
Sat Mar 12 21:24:17 2022 UTC (2 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6907.
  - Assign unique name and id to "Visible input?" checkbox for each Link
    Protection item, and uncheck each one on page load on course's home server.
  - Uncheck "Visible input?" checkbox and set type to password for textbox
    for secret on form submission.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: lonconfigsettings.pm,v 1.62 2022/03/12 21:24:17 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,$confname,$values) = @_;
   44:     my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
   45:         $linkprot_check,$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:             if (($context eq 'course') && ($phase eq 'display') &&
  120:                 (grep(/^linkprot$/,@actions))) {
  121:                 my $allowed;
  122:                 my $home = &Apache::lonnet::homeserver($confname,$dom);
  123:                 unless ($home eq 'no_host') {
  124:                     my @ids=&Apache::lonnet::current_machine_ids();
  125:                     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  126:                 }
  127:                 if ($allowed) {
  128:                     my (@changeable,@settable);
  129:                     if (ref($values->{'linkprot'}) eq 'HASH') {
  130:                         if (keys(%{$values->{'linkprot'}})) {
  131:                             my @current = sort { $a <=> $b } keys(%{$values->{'linkprot'}});
  132:                             if (@current) {
  133:                                 for (my $i=0; $i<@current; $i++) {
  134:                                     my $num = $current[$i];
  135:                                     if (ref($values->{'linkprot'}->{$num}) eq 'HASH') {
  136:                                         if ($values->{'linkprot'}->{$num}->{'usable'}) {
  137:                                             push(@changeable,$i);
  138:                                         } else {
  139:                                             push(@settable,$i);
  140:                                         }
  141:                                     }
  142:                                 }
  143:                             }
  144:                         }
  145:                     }
  146:                     my ($numrules,$intargjs);
  147: $linkprot_check .= <<ENDJS;
  148: 
  149: var linkprotradio = '';
  150: var secretinput = ''; 
  151: var posscheck = '';
  152: 
  153: ENDJS
  154:                     if (@changeable) {
  155:                         foreach my $num (@changeable) {
  156:                             ($numrules,$intargjs) =
  157:                                 &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot',$num);
  158:                             $linkprot_check .= <<ENDJS;
  159: posscheck = '';
  160: linkprotradio = document.display.elements['linkprot_changesecret_$num'];
  161: if (linkprotradio.length) {
  162:     for (var i=0; i<linkprotradio.length; i++) {
  163:         if (linkprotradio[i].checked) {
  164:             if (linkprotradio[i].value == 1) {
  165:                 posscheck = 1;
  166:             }
  167:         }
  168:     }
  169: }
  170: 
  171: ENDJS
  172:                             if ($numrules) {
  173:                                 $linkprot_check .= <<ENDJS;
  174: if (posscheck) {
  175:     secretinput = document.display.elements['linkprot_secret_$num'].value;
  176:     $intargjs
  177: }
  178: 
  179: ENDJS
  180:                             }
  181:                             $linkprot_check .= <<ENDJS;
  182: if (posscheck) {
  183:     document.display.elements['linkprot_secret_$num'].type = 'password';
  184: }
  185: 
  186: ENDJS
  187:                         }
  188:                     }
  189:                     if (@settable) {
  190:                         foreach my $num (@settable) {
  191:                             ($numrules,$intargjs) =
  192:                                 &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot',$num);
  193:                             if ($numrules) {
  194:                                 $linkprot_check .= <<ENDJS;
  195: secretinput = document.display.elements['linkprot_secret_$num'].value;
  196: $intargjs
  197: 
  198: ENDJS
  199:                             }
  200:                             $linkprot_check .= <<ENDJS;
  201: document.display.elements['linkprot_secret_$num'].type = 'password';
  202: 
  203: ENDJS
  204:                         }
  205:                     }
  206:                     ($numrules,$intargjs) =
  207:                         &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot','add');
  208:                     if ($numrules) {
  209:                         $linkprot_check .= <<ENDJS
  210: secretinput = document.display.elements['linkprot_secret_add'].value;
  211: if (document.display.elements['linkprot_add'].checked) {
  212:     $intargjs      
  213: }
  214: 
  215: ENDJS
  216:                     }
  217:                     $linkprot_check .= <<ENDJS;
  218: document.display.elements['linkprot_secret_add'].type = 'password';
  219: 
  220: ENDJS
  221:                 }
  222:             }
  223:         }
  224:     }
  225:     my $alert = &mt('You must select at least one functionality type to display.');
  226:     &js_escape(\$alert);
  227:     my $js = '
  228: <script type="text/javascript">
  229: // <![CDATA[
  230: 
  231: function changePage(formname,newphase) {
  232:     formname.phase.value = newphase;
  233:     numchecked = 0;
  234:     if (formname == document.pickactions) {
  235:         if (formname.actions.length > 0) {
  236:             for (var i = 0; i<formname.actions.length; i++) {
  237:                 if (formname.actions[i].checked) {
  238:                     numchecked ++;
  239:                 }
  240:             }
  241:         } else {
  242:             if (formname.actions.checked) {
  243:                 numchecked ++;
  244:             }
  245:         }
  246:         if (numchecked > 0) {
  247:             formname.submit();
  248:         } else {
  249:             alert("'.$alert.'");
  250:             return;
  251:         }
  252:     }
  253:     '.$instcode_check.$call_category_check.$linkprot_check.'
  254:     formname.submit();
  255: }'."\n";
  256:     if ($phase eq 'pickactions') {
  257: 	$js .= &Apache::lonhtmlcommon::color_picker();
  258:         $js .=
  259:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
  260:     } elsif ($phase eq 'display') {
  261: 	$js .= &Apache::lonhtmlcommon::color_picker();
  262:         $js .= &color_pick_js()."\n";
  263:     }
  264:     $js .= &Apache::loncommon::viewport_size_js().'
  265: 
  266: // ]]>
  267: </script>
  268: ';
  269:     if ($jscript) {
  270:         $js .= "
  271: 
  272: $jscript
  273: 
  274: ";
  275:     }
  276:     my $additem;
  277:     if ($phase eq 'pickactions') {
  278:         my %loaditems = (
  279:                     'onload' => "setFormElements(document.pickactions);",
  280:                         );
  281:         $additem = {'add_entries' => \%loaditems,};
  282:     } elsif ($phase eq 'display') {
  283:         if ($context eq 'domain') {
  284:             my $onload;
  285:             if (grep(/^coursedefaults$/,@actions)) {
  286:                 $onload = "toggleDisplay(document.display,'cloneinstcode');".
  287:                           "toggleDisplay(document.display,'credits');".
  288:                           "toggleDisplay(document.display,'studentsubmission');";
  289:             }
  290:             if (grep(/^selfcreation$/,@actions)) {
  291:                 my $prefix = 'cancreate_emailverified';
  292:                 my $customclass = 'LC_selfcreate_email';
  293:                 my $classprefix = 'LC_canmodify_emailusername_';
  294:                 my $optionsprefix = 'LC_options_emailusername_';
  295:                 $onload .= "toggleRows(document.display,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
  296:                 my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
  297:                 my $hascustom;
  298:                 my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
  299:                 if (ref($emailrules) eq 'HASH') {
  300:                     if (keys(%{$emailrules}) > 0) {
  301:                         $hascustom = 'cancreate_emailrule';
  302:                     }
  303:                 }
  304:                 my @posstypes;
  305:                 if (ref($types) eq 'ARRAY') {
  306:                     @posstypes = @{$types};
  307:                     push(@posstypes,'default');
  308:                     foreach my $type (@posstypes) {
  309:                         $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
  310:                                                                "'cancreate_emaildomain','$type');";
  311:                     }
  312:                 } else {
  313:                     $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
  314:                                                        "'cancreate_emaildomain','default');";
  315:                 }
  316:             } 
  317:             if (grep(/^contacts$/,@actions)) {
  318:                 my $customclass = 'LC_helpdesk_override';
  319:                 my $optionsprefix = 'LC_options_helpdesk_';
  320:                 $onload .= "toggleHelpdeskRow(document.display,'overrides','$customclass','$optionsprefix');";
  321:             }
  322:             if (grep(/^lti$/,@actions)) {
  323:                 $onload .= "toggleLTI(document.display,'user','add');".
  324:                            "toggleLTI(document.display,'crs','add');".
  325:                            "toggleLTI(document.display,'sec','add');".
  326:                            "toggleLTI(document.display,'lcauth','add');".
  327:                            "toggleLTI(document.display,'lcmenu','add');".
  328:                            "toggleLTI(document.display,'passback','add');".
  329:                            "toggleLTI(document.display,'callback','add');";
  330:                 if (ref($values) eq 'HASH') {
  331:                     if (ref($values->{'lti'}) eq 'HASH') {
  332:                         my $numlti = scalar(keys(%{$values->{'lti'}}));
  333:                         for (my $i=0; $i<$numlti; $i++) {
  334:                             $onload .= "toggleLTI(document.display,'user','$i');".
  335:                                        "toggleLTI(document.display,'crs','$i');".
  336:                                        "toggleLTI(document.display,'sec','$i');".
  337:                                        "toggleLTI(document.display,'lcauth','$i');".
  338:                                        "toggleLTI(document.display,'lcmenu','$i');".
  339:                                        "toggleLTI(document.display,'passback','$i');".
  340:                                        "toggleLTI(document.display,'callback','$i');";
  341:                         }
  342:                     }
  343:                 }
  344:                 my %servers = &Apache::lonnet::get_servers($dom,'library');
  345:                 foreach my $server (keys(%servers)) {
  346:                     $onload .= "togglePrivKey(document.display,'$server');";
  347:                 }
  348:                 $onload .= "toggleLTIEncKey(document.display);";
  349:             }
  350:             if (grep(/^ltitools$/,@actions)) {
  351:                 $onload .= "toggleLTITools(document.display,'passback','add');".
  352:                            "toggleLTITools(document.display,'roster','add');".
  353:                            "toggleLTITools(document.display,'user','add');";
  354:                 if (ref($values) eq 'HASH') {
  355:                     if (ref($values->{'ltitools'}) eq 'HASH') {
  356:                         my $numltitools = scalar(keys(%{$values->{'ltitools'}}));
  357:                         for (my $i=0; $i<$numltitools; $i++) {
  358:                             $onload .= "toggleLTITools(document.display,'passback','$i');".
  359:                                        "toggleLTITools(document.display,'roster','$i');".
  360:                                        "toggleLTITools(document.display,'user','$i');";
  361:                         }
  362:                     }
  363:                 }
  364:             }
  365:             if (grep(/^wafproxy$/,@actions)) {
  366:                 $onload .= "toggleWAF();checkWAF();updateWAF();";
  367:             }
  368:             if (grep(/^proctoring$/,@actions)) {
  369:                 $onload .= "toggleProctoring(document.display,'proctorio');".
  370:                            "toggleProctoring(document.display,'examity');";
  371:             }
  372:             if (grep(/^scantron$/,@actions)) {
  373:                 $onload .= "toggleScantron(document.display);";
  374:             }
  375:             if (grep(/^autoupdate$/,@actions)) {
  376:                 $onload .= "toggleLastActiveDays(document.display);";
  377:             }
  378:             if (grep(/^autoenroll$/,@actions)) {
  379:                 $onload .= "toggleFailsafe(document.display);";
  380:             }
  381:             if (grep(/^login$/,@actions)) {
  382:                 my %domservers = &Apache::lonnet::get_servers($dom);
  383:                 foreach my $server (sort(keys(%domservers))) {
  384:                     $onload .= "toggleSamlOptions(document.display,'$server');";
  385:                 }
  386:             }
  387:             if ($onload) {
  388:                 my %loaditems = (
  389:                                   'onload' => $onload,
  390:                                 );
  391:                 $additem = {'add_entries' => \%loaditems,};
  392:             }
  393:         } elsif ($context eq 'course') {
  394:             my $onload;
  395:             if (grep(/^courseinfo$/,@actions)) {
  396:                 if (@code_order) {
  397:                     $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);";
  398:                 }
  399:             }
  400:             if (grep(/^linkprot$/,@actions)) {
  401:                 if (ref($values) eq 'HASH') {
  402:                     if (ref($values->{'linkprot'}) eq 'HASH') {
  403:                         my $ltiauth;
  404:                         if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
  405:                             $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
  406:                         } else {
  407:                             my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
  408:                             $ltiauth = $domdefs{'crsltiauth'};
  409:                         }
  410:                         my $ishome;
  411:                         my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
  412:                         unless (($chome eq 'no_host') || ($chome eq '')) {
  413:                             my @ids=&Apache::lonnet::current_machine_ids();
  414:                             foreach my $id (@ids) { if ($id eq $chome) { $ishome=1; } }
  415:                         }
  416:                         my $posslti = scalar(keys(%{$values->{'linkprot'}}));
  417:                         for (my $i=0; $i<=$posslti; $i++) {
  418:                             my $num = $i;
  419:                             if ($i == $posslti) {
  420:                                 $num = 'add';
  421:                             }
  422:                             if (ref($values->{'linkprot'}->{$i}) eq 'HASH') {
  423:                                 if ($values->{'linkprot'}->{$i}->{'usable'}) {
  424:                                     $onload .= "toggleLinkProt(document.display,'$num','secret');";
  425:                                 }
  426:                             }
  427:                             if ($ltiauth) {
  428:                                 $onload .= "toggleLinkProtReqUser(document.display,'requser','optional','1','block','$num');".
  429:                                            "toggleLinkProtReqUser(document.display,'mapuser','userfield','other','inline-block','$num');";
  430:                             }
  431:                             if ($ishome) {
  432:                                 $onload .= "uncheckLinkProtMakeVis('visible','$num');";
  433:                             }
  434:                         }
  435:                     }
  436:                 }
  437:             }
  438:             if ($onload) {
  439:                 my %loaditems = (
  440:                                   'onload' => $onload,
  441:                                 );
  442:                 $additem = {'add_entries' => \%loaditems,};
  443:             }
  444:         }
  445:     }
  446:     $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
  447:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
  448:     $r->print('
  449: <form name="parmform" action="">
  450: <input type="hidden" name="pres_marker" />
  451: <input type="hidden" name="pres_type" />
  452: <input type="hidden" name="pres_value" />
  453: </form>
  454: ');
  455:     if ($container) {
  456:        &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
  457:     }
  458:     $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
  459:               ' enctype="multipart/form-data">');
  460:     return;
  461: }
  462: 
  463: sub print_footer {
  464:     my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
  465:     $button_text = &mt($button_text);
  466:     $r->print('<input type="hidden" name="phase" value="" />');
  467:     if (defined($env{'form.origin'})) {
  468:         $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
  469:     }
  470:     if (($phase eq 'display') || ($phase eq 'process')) {
  471:         if (ref($actions) eq 'ARRAY') {
  472:             foreach my $item (@{$actions}) {
  473:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
  474:             }
  475:         }
  476:     }
  477:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  478:     if ($phase eq 'process') {
  479:         $r->print(
  480:             &Apache::lonhtmlcommon::actionbox(
  481:                 ['<a href='.$dest.'>'.$button_text.'</a>']));
  482:     } else {
  483:         my $onclick;
  484:         if ($phase eq 'display') {
  485:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  486:         } else {
  487:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  488:         }
  489:         my $showbutton = 1;
  490:         if (ref($parm_permission) eq 'HASH') {
  491:             unless (($parm_permission->{'process'}) || ($newphase eq 'display')) {
  492:                 $showbutton = 0;
  493:             }
  494:         }
  495:         if ($showbutton) {
  496:             $r->print('<p><input type="button" name="store" value="'.
  497:                       $button_text.'" onclick='.$onclick.' /></p>');
  498:         } 
  499:     }
  500:     if ($phase eq 'process') {
  501:         $r->print('</form>');
  502:         if ($container) {
  503:            &Apache::lonparmset::endSettingsScreen($r);
  504:         }
  505:         $r->print(&Apache::loncommon::end_page());
  506:     }
  507:     return;
  508: }
  509: 
  510: sub make_changes {
  511:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
  512:         $allitems,$container,$parm_permission) = @_;
  513:     my %brcrumtext = &get_crumb_text();
  514:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  515:     my ($numchanged,%changes,%disallowed);
  516:     &Apache::lonhtmlcommon::add_breadcrumb
  517:       ({href=>"javascript:changePage(document.$phase,'display')",
  518:         text=>$brcrumtext{$context}},
  519:        {href=>"javascript:changePage(document.$phase,'$phase')",
  520:         text=>"Updated"});
  521:     &print_header($r,$phase,$context,undef,$container);
  522:     my ($crstype,%lastact,$errors);
  523:     if ($context eq 'course') {
  524:         $crstype = &Apache::loncommon::course_type();
  525:     }
  526:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && 
  527:         (ref($prefs) eq 'HASH')) {
  528:         foreach my $item (@{$prefs_order}) {
  529:             if (grep(/^\Q$item\E$/,@actions)) {
  530:                 if ($context eq 'domain') {
  531:                     $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
  532:                               &Apache::domainprefs::process_changes($r,$dom,
  533:                                           $confname,$item,$roles,$values,\%lastact));
  534:                 } else {
  535:                     $changes{$item} = {};
  536:                     $errors =
  537:                         &Apache::courseprefs::process_changes($dom,$confname,$item,$values,
  538:                                                               $prefs->{$item},$changes{$item},
  539:                                                               $allitems,\%disallowed,$crstype);
  540:                     if (keys(%{$changes{$item}}) > 0) {
  541:                         $numchanged ++;
  542:                     }
  543:                 }
  544:             }
  545:         }
  546:     }
  547:     if ($context eq 'course') {
  548:         if ($numchanged) {
  549:             my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
  550:                                                           $prefs,$values,\%changes,$crstype);
  551:             $r->print(&Apache::loncommon::confirmwrapper($message));
  552:         } else {
  553:             if ($crstype eq 'Community') {
  554:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
  555:             } else {
  556:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
  557:             }
  558:         }
  559:         if (keys(%disallowed) > 0) {
  560:             $r->print('<p>');
  561:             foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
  562:                 if (ref($disallowed{$item}) eq 'HASH') {
  563:                     if (keys(%{$disallowed{$item}}) > 0) {
  564:                         $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
  565:                                                                            $prefs,$crstype));
  566:                     }
  567:                 }
  568:             }
  569:             $r->print('</p>');
  570:         }
  571:         if ($errors) {
  572:             $r->print('<p>'.$errors.'</p>');
  573:         }
  574:     }
  575:     $r->print('<p>');
  576:     my $footer_text = 'Back to configuration display';
  577:     if ($context eq 'course') {
  578:         $footer_text = 'Back to display/edit settings'; 
  579:     }
  580:     &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
  581:     $r->print('</p>');
  582:     return \%lastact;
  583: }
  584: 
  585: sub display_settings {
  586:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
  587:         $allitems,$crstype,$container,$parm_permission) = @_;
  588:     my %brcrumtext = &get_crumb_text();
  589:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  590:     &Apache::lonhtmlcommon::add_breadcrumb
  591:         ({href=>"javascript:changePage(document.$phase,'display')",
  592:           text=>"Display/Edit Settings"});
  593:     my $instcode;
  594:     if (ref($values) eq 'HASH') {
  595:         $instcode = $values->{'internal.coursecode'};
  596:     }
  597:     &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values);
  598:     my $divwidth = 900;
  599:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
  600:         if (@actions > 0) {
  601:             my $rowsum = 0;
  602:             my (%output,%rowtotal,@items,$got_check_uncheck);
  603:             foreach my $item (@{$prefs_order}) {
  604:                 if (grep(/^\Q$item\E$/,@actions)) {
  605:                     push(@items,$item);
  606:                     if ($context eq 'domain') {
  607:                         my $settings;
  608:                         if (ref($values) eq 'HASH') { 
  609:                             $settings = $values->{$item};
  610:                         }
  611:                         if (($item eq 'usersessions') || ($item eq 'ssl')) {
  612:                             unless ($got_check_uncheck) {
  613:                                 $r->print('<script type="text/javascript">'."\n".
  614:                                           '// <![CDATA['."\n".
  615:                                           &Apache::loncommon::check_uncheck_jscript()."\n".
  616:                                           '// ]]>'."\n".
  617:                                           '</script>'."\n");
  618:                                 $got_check_uncheck = 1;
  619:                             }
  620:                         } elsif ($item eq 'selfcreation') {
  621:                             if (ref($values) eq 'HASH') {
  622:                                 $settings = $values->{'usercreation'};
  623:                             }
  624:                         } elsif ($item eq 'defaults') {
  625:                             if (ref($values->{'inststatus'}) eq 'HASH') {
  626:                                 if (ref($values->{'defaults'}) eq 'HASH') {
  627:                                     $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
  628:                                 } else {
  629:                                     $settings = $values->{'inststatus'};
  630:                                 }
  631:                             } else {
  632:                                 my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
  633:                                 my $inststatus = {
  634:                                                    inststatustypes => $usertypes,
  635:                                                    inststatusorder => $types,
  636:                                                    inststatusguest => [], 
  637:                                                  };
  638:                                 if (ref($values->{defaults}) eq 'HASH') {
  639:                                     $settings = {%{$inststatus},%{$values->{'defaults'}}};
  640:                                 } else {
  641:                                     $settings = $inststatus;
  642:                                 }
  643:                             }
  644:                         } elsif ($item eq 'lti') {
  645:                             if (ref($values->{'ltisec'}) eq 'HASH') {
  646:                                 if (ref($values->{'lti'}) eq 'HASH') {
  647:                                     $settings = {%{$values->{'lti'}},%{$values->{'ltisec'}}};
  648:                                 } else {
  649:                                     $settings = $values->{'ltisec'};
  650:                                 }
  651:                             } elsif (ref($values->{'lti'}) eq 'HASH') {
  652:                                 $settings = $values->{'lti'};
  653:                             }
  654:                         }
  655:                         ($output{$item},$rowtotal{$item}) =
  656:                             &Apache::domainprefs::print_config_box($r,$dom,$confname,
  657:                                 $phase,$item,$prefs->{$item},$settings);
  658:                     } else {
  659:                         ($output{$item},$rowtotal{$item}) =
  660:                             &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase,
  661:                                 $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
  662:                     }
  663:                     $rowsum += $rowtotal{$item};
  664:                 }
  665:             }
  666:             $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
  667:             for (my $i=0; $i<@items; $i++) {
  668:                 $r->print($output{$items[$i]});
  669:             }
  670:             $r->print('</div>');
  671:             $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
  672:         } else {
  673:             $r->print('<input type="hidden" name="phase" value="" />'.
  674:                       '<span class="LC_error">'.&mt('No settings chosen').
  675:                       '</span>');
  676:         }
  677:         $r->print('</form>');
  678:     }
  679:     if ($container) {
  680:         &Apache::lonparmset::endSettingsScreen($r);
  681:     }
  682:     $r->print(&Apache::loncommon::end_page());
  683:     return;
  684: }
  685: 
  686: sub display_choices {
  687:     my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
  688:     if ($phase eq '') {
  689:         $phase = 'pickactions';
  690:     }
  691:     my %helphash;
  692:     &print_header($r,$phase,$context,undef,$container);
  693:     $r->print('<script type="text/javascript">'."\n".
  694:               '// <![CDATA['."\n".
  695:               &Apache::loncommon::check_uncheck_jscript()."\n".
  696:               '// ]]>'."\n".
  697:               '</script>'."\n");
  698:     my $heading = &mt('Settings to display/modify');
  699:     if (ref($parm_permission) eq 'HASH') {
  700:         unless ($parm_permission->{'process'}) {
  701:             $heading = &mt('Settings to display');
  702:         }
  703:     }
  704:     $r->print('<h3>'.$heading.'</h3>'.
  705:               '<div><input type="button" value="'.&mt('check all').'" '.
  706:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
  707:               ' />'.('&nbsp;'x2).
  708:               '<input type="button" value="'.&mt('uncheck all').'" '.
  709:               'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
  710:               "\n".
  711:               '</div><div class="LC_left_float">');
  712:     my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
  713:     if (ref($prefs_order) eq 'ARRAY') {
  714:         $numitems = @{$prefs_order};
  715:     }
  716:     my $numcols = 3;
  717:     $maxincol = int($numitems/$numcols);
  718:     if ($numitems%$numcols) {
  719:         $maxincol ++;
  720:     }
  721:     $firstthird = $maxincol;
  722:     $secondthird = $firstthird + $maxincol;
  723:     $count = 0;
  724:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
  725:         foreach my $item (@{$prefs_order}) {
  726:             $r->print('<h4>'.
  727:                       &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
  728:                       '<label><input type="checkbox" name="actions" value="'.$item.
  729:                       '" />&nbsp;'.&mt($prefs->{$item}->{'text'}).'</label></h4>');
  730:             $count ++;
  731:             if ((!$seconddiv) && ($count >= $firstthird)) {
  732:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  733:                 $seconddiv = 1;
  734:             }
  735:             if ((!$thirddiv) && ($count >= $secondthird)) {
  736:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  737:                 $thirddiv = 1;
  738:             }
  739:         }
  740:     }
  741:     $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
  742:     $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
  743:     $r->print('</form>');
  744:     if ($container) {
  745:         &Apache::lonparmset::endSettingsScreen($r);
  746:     }
  747:     $r->print(&Apache::loncommon::end_page());
  748:     return;
  749: }
  750: 
  751: sub color_pick_js {
  752:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  753:     my $output = <<"ENDCOL";
  754: 
  755:     $pjump_def
  756: 
  757:     function psub() {
  758:         modalWindow.close();
  759:         if (document.parmform.pres_marker.value!='') {
  760:             if (document.parmform.pres_type.value!='') {
  761:                 eval('document.display.'+
  762:                      document.parmform.pres_marker.value+
  763:                      '.value=document.parmform.pres_value.value;');
  764:             }
  765:         } else {
  766:             document.parmform.pres_value.value='';
  767:             document.parmform.pres_marker.value='';
  768:         }
  769:     }
  770: 
  771:     function get_id (span_id) {
  772:         if (document.getElementById) {
  773:             return document.getElementById(span_id);
  774:         }
  775:         if (document.all) {
  776:             return document.all[span_id];
  777:         }
  778:         return false;
  779:     }
  780: 
  781:     function colchg_span (span_id_str,new_color_item) {
  782:         var span_ref = get_id(span_id_str);
  783:         if (span_ref.style) { span_ref = span_ref.style; }
  784:         span_ref.background = new_color_item.value;
  785:         span_ref.backgroundColor = new_color_item.value;
  786:         span_ref.bgColor = new_color_item.value;
  787:     }
  788: 
  789: ENDCOL
  790:     return $output;
  791: }
  792: 
  793: sub get_crumb_text {
  794:     my %brcrumbtext = (
  795:                        domain => 'Domain Settings',
  796:                        course => 'Display/Edit Settings',
  797:                      );
  798:     return %brcrumbtext;
  799: }
  800: 
  801: 1;

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