File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.21.4.13.2.3: download - view: text, annotated - select for diffs
Sun Feb 20 19:43:12 2022 UTC (2 years, 3 months ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.21.4.13: preferred, unified
- For 2.11.4 (modified)
  Include changes in 1.58, 1.59, 1.60

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

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