File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.21.4.13.2.6: download - view: text, annotated - select for diffs
Tue Apr 5 16:43:34 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 rev. 1.64

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

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