Annotation of loncom/interface/lonconfigsettings.pm, revision 1.62

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.62    ! raeburn     4: # $Id: lonconfigsettings.pm,v 1.61 2022/03/10 19:35:18 raeburn Exp $
1.1       raeburn     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;
1.20      www        38: use Apache::lonparmset();
1.30      raeburn    39: use Apache::courseclassifier();
                     40: use LONCAPA qw(:DEFAULT :match); 
1.1       raeburn    41: 
                     42: sub print_header {
1.59      raeburn    43:     my ($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values) = @_;
1.30      raeburn    44:     my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
1.59      raeburn    45:         $linkprot_check,$crstype,@actions,@code_order);
1.30      raeburn    46:     if ($phase eq 'display') {
                     47:         @actions = &Apache::loncommon::get_env_multiple('form.actions');
                     48:     }
1.1       raeburn    49:     if ($context eq 'domain') {
1.12      raeburn    50:         ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
1.1       raeburn    51:         $action = '/adm/domainprefs';
1.8       raeburn    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:         }
1.1       raeburn    63:     } else {
1.24      raeburn    64:         $crstype = &Apache::loncommon::course_type();
                     65:         if ($crstype eq 'Community') {
1.7       raeburn    66:             ($pagetitle,$brcrumtitle) = ('Community Configuration','Community Configuration');
                     67:         } else {
                     68:             ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
                     69:         }
1.1       raeburn    70:         $action = '/adm/courseprefs';
1.30      raeburn    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.');
1.31      damieng    78:                    &js_escape(\$noinstcodestr);
1.30      raeburn    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:             }
1.59      raeburn   119:             if (($context eq 'course') && ($phase eq 'display') &&
1.60      raeburn   120:                 (grep(/^linkprot$/,@actions))) {
1.59      raeburn   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);
1.60      raeburn   129:                     if (ref($values->{'linkprot'}) eq 'HASH') {
                    130:                         if (keys(%{$values->{'linkprot'}})) {
                    131:                             my @current = sort { $a <=> $b } keys(%{$values->{'linkprot'}});
1.59      raeburn   132:                             if (@current) {
                    133:                                 for (my $i=0; $i<@current; $i++) {
                    134:                                     my $num = $current[$i];
1.60      raeburn   135:                                     if (ref($values->{'linkprot'}->{$num}) eq 'HASH') {
                    136:                                         if ($values->{'linkprot'}->{$num}->{'usable'}) {
1.59      raeburn   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 = ''; 
1.62    ! raeburn   151: var posscheck = '';
        !           152: 
1.59      raeburn   153: ENDJS
                    154:                     if (@changeable) {
                    155:                         foreach my $num (@changeable) {
                    156:                             ($numrules,$intargjs) =
                    157:                                 &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot',$num);
1.62    ! raeburn   158:                             $linkprot_check .= <<ENDJS;
        !           159: posscheck = '';
1.59      raeburn   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) {
1.62    ! raeburn   165:                 posscheck = 1;
1.59      raeburn   166:             }
                    167:         }
                    168:     }
                    169: }
1.62    ! raeburn   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: 
1.59      raeburn   179: ENDJS
                    180:                             }
1.62    ! raeburn   181:                             $linkprot_check .= <<ENDJS;
        !           182: if (posscheck) {
        !           183:     document.display.elements['linkprot_secret_$num'].type = 'password';
        !           184: }
        !           185: 
        !           186: ENDJS
1.59      raeburn   187:                         }
                    188:                     }
                    189:                     if (@settable) {
1.61      raeburn   190:                         foreach my $num (@settable) {
1.59      raeburn   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
1.62    ! raeburn   197: 
1.59      raeburn   198: ENDJS
                    199:                             }
1.62    ! raeburn   200:                             $linkprot_check .= <<ENDJS;
        !           201: document.display.elements['linkprot_secret_$num'].type = 'password';
        !           202: 
        !           203: ENDJS
1.59      raeburn   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: }
1.62    ! raeburn   214: 
1.59      raeburn   215: ENDJS
                    216:                     }
1.62    ! raeburn   217:                     $linkprot_check .= <<ENDJS;
        !           218: document.display.elements['linkprot_secret_add'].type = 'password';
        !           219: 
        !           220: ENDJS
1.59      raeburn   221:                 }
                    222:             }
1.30      raeburn   223:         }
1.1       raeburn   224:     }
                    225:     my $alert = &mt('You must select at least one functionality type to display.');
1.31      damieng   226:     &js_escape(\$alert);
1.1       raeburn   227:     my $js = '
                    228: <script type="text/javascript">
1.6       raeburn   229: // <![CDATA[
                    230: 
1.1       raeburn   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:     }
1.59      raeburn   253:     '.$instcode_check.$call_category_check.$linkprot_check.'
1.1       raeburn   254:     formname.submit();
                    255: }'."\n";
                    256:     if ($phase eq 'pickactions') {
1.22      foxr      257: 	$js .= &Apache::lonhtmlcommon::color_picker();
1.1       raeburn   258:         $js .=
1.12      raeburn   259:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
1.1       raeburn   260:     } elsif ($phase eq 'display') {
1.22      foxr      261: 	$js .= &Apache::lonhtmlcommon::color_picker();
1.1       raeburn   262:         $js .= &color_pick_js()."\n";
                    263:     }
                    264:     $js .= &Apache::loncommon::viewport_size_js().'
1.6       raeburn   265: 
                    266: // ]]>
1.1       raeburn   267: </script>
                    268: ';
1.2       raeburn   269:     if ($jscript) {
                    270:         $js .= "
                    271: 
                    272: $jscript
                    273: 
                    274: ";
                    275:     }
1.1       raeburn   276:     my $additem;
                    277:     if ($phase eq 'pickactions') {
                    278:         my %loaditems = (
1.12      raeburn   279:                     'onload' => "setFormElements(document.pickactions);",
1.1       raeburn   280:                         );
                    281:         $additem = {'add_entries' => \%loaditems,};
1.30      raeburn   282:     } elsif ($phase eq 'display') {
                    283:         if ($context eq 'domain') {
1.34      raeburn   284:             my $onload;
1.30      raeburn   285:             if (grep(/^coursedefaults$/,@actions)) {
1.34      raeburn   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';
1.36      raeburn   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');";
1.34      raeburn   311:                     }
1.36      raeburn   312:                 } else {
                    313:                     $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
                    314:                                                        "'cancreate_emaildomain','default');";
1.34      raeburn   315:                 }
1.37      raeburn   316:             } 
                    317:             if (grep(/^contacts$/,@actions)) {
                    318:                 my $customclass = 'LC_helpdesk_override';
                    319:                 my $optionsprefix = 'LC_options_helpdesk_';
1.38      raeburn   320:                 $onload .= "toggleHelpdeskRow(document.display,'overrides','$customclass','$optionsprefix');";
1.34      raeburn   321:             }
1.40      raeburn   322:             if (grep(/^lti$/,@actions)) {
                    323:                 $onload .= "toggleLTI(document.display,'user','add');".
                    324:                            "toggleLTI(document.display,'crs','add');".
1.42      raeburn   325:                            "toggleLTI(document.display,'sec','add');".
1.43      raeburn   326:                            "toggleLTI(document.display,'lcauth','add');".
1.44      raeburn   327:                            "toggleLTI(document.display,'lcmenu','add');".
1.46      raeburn   328:                            "toggleLTI(document.display,'passback','add');".
                    329:                            "toggleLTI(document.display,'callback','add');";
1.40      raeburn   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');".
1.42      raeburn   336:                                        "toggleLTI(document.display,'sec','$i');".
1.43      raeburn   337:                                        "toggleLTI(document.display,'lcauth','$i');".
1.44      raeburn   338:                                        "toggleLTI(document.display,'lcmenu','$i');".
1.46      raeburn   339:                                        "toggleLTI(document.display,'passback','$i');".
                    340:                                        "toggleLTI(document.display,'callback','$i');";
1.40      raeburn   341:                         }
                    342:                     }
1.41      raeburn   343:                 }
1.58      raeburn   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);";
1.40      raeburn   349:             }
1.39      raeburn   350:             if (grep(/^ltitools$/,@actions)) {
                    351:                 $onload .= "toggleLTITools(document.display,'passback','add');".
1.41      raeburn   352:                            "toggleLTITools(document.display,'roster','add');".
                    353:                            "toggleLTITools(document.display,'user','add');";
1.39      raeburn   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');".
1.41      raeburn   359:                                        "toggleLTITools(document.display,'roster','$i');".
                    360:                                        "toggleLTITools(document.display,'user','$i');";
1.39      raeburn   361:                         }
                    362:                     }
                    363:                 }
                    364:             }
1.48      raeburn   365:             if (grep(/^wafproxy$/,@actions)) {
                    366:                 $onload .= "toggleWAF();checkWAF();updateWAF();";
                    367:             }
1.47      raeburn   368:             if (grep(/^proctoring$/,@actions)) {
                    369:                 $onload .= "toggleProctoring(document.display,'proctorio');".
                    370:                            "toggleProctoring(document.display,'examity');";
                    371:             }
1.45      raeburn   372:             if (grep(/^scantron$/,@actions)) {
1.54      raeburn   373:                 $onload .= "toggleScantron(document.display);";
1.45      raeburn   374:             }
1.52      raeburn   375:             if (grep(/^autoupdate$/,@actions)) {
1.54      raeburn   376:                 $onload .= "toggleLastActiveDays(document.display);";
1.52      raeburn   377:             }
1.55      raeburn   378:             if (grep(/^autoenroll$/,@actions)) {
                    379:                 $onload .= "toggleFailsafe(document.display);";
                    380:             }
1.53      raeburn   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:             }
1.34      raeburn   387:             if ($onload) {
1.30      raeburn   388:                 my %loaditems = (
1.35      raeburn   389:                                   'onload' => $onload,
1.30      raeburn   390:                                 );
                    391:                 $additem = {'add_entries' => \%loaditems,};
                    392:             }
                    393:         } elsif ($context eq 'course') {
1.56      raeburn   394:             my $onload;
1.30      raeburn   395:             if (grep(/^courseinfo$/,@actions)) {
1.56      raeburn   396:                 if (@code_order) {
                    397:                     $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);";
                    398:                 }
                    399:             }
1.60      raeburn   400:             if (grep(/^linkprot$/,@actions)) {
1.56      raeburn   401:                 if (ref($values) eq 'HASH') {
1.60      raeburn   402:                     if (ref($values->{'linkprot'}) eq 'HASH') {
1.57      raeburn   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:                         }
1.62    ! raeburn   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:                         }
1.60      raeburn   416:                         my $posslti = scalar(keys(%{$values->{'linkprot'}}));
1.57      raeburn   417:                         for (my $i=0; $i<=$posslti; $i++) {
                    418:                             my $num = $i;
                    419:                             if ($i == $posslti) {
                    420:                                 $num = 'add';
                    421:                             }
1.60      raeburn   422:                             if (ref($values->{'linkprot'}->{$i}) eq 'HASH') {
                    423:                                 if ($values->{'linkprot'}->{$i}->{'usable'}) {
1.59      raeburn   424:                                     $onload .= "toggleLinkProt(document.display,'$num','secret');";
1.57      raeburn   425:                                 }
1.58      raeburn   426:                             }
1.57      raeburn   427:                             if ($ltiauth) {
1.59      raeburn   428:                                 $onload .= "toggleLinkProtReqUser(document.display,'requser','optional','1','block','$num');".
                    429:                                            "toggleLinkProtReqUser(document.display,'mapuser','userfield','other','inline-block','$num');";
1.56      raeburn   430:                             }
1.62    ! raeburn   431:                             if ($ishome) {
        !           432:                                 $onload .= "uncheckLinkProtMakeVis('visible','$num');";
        !           433:                             }
1.56      raeburn   434:                         }
                    435:                     }
1.30      raeburn   436:                 }
                    437:             }
1.56      raeburn   438:             if ($onload) {
                    439:                 my %loaditems = (
                    440:                                   'onload' => $onload,
                    441:                                 );
                    442:                 $additem = {'add_entries' => \%loaditems,};
                    443:             }
1.30      raeburn   444:         }
1.1       raeburn   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: ');
1.20      www       455:     if ($container) {
1.24      raeburn   456:        &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
1.20      www       457:     }
1.1       raeburn   458:     $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
                    459:               ' enctype="multipart/form-data">');
                    460:     return;
                    461: }
                    462: 
                    463: sub print_footer {
1.33      raeburn   464:     my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
1.1       raeburn   465:     $button_text = &mt($button_text);
1.12      raeburn   466:     $r->print('<input type="hidden" name="phase" value="" />');
1.5       raeburn   467:     if (defined($env{'form.origin'})) {
                    468:         $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
                    469:     }
1.1       raeburn   470:     if (($phase eq 'display') || ($phase eq 'process')) {
                    471:         if (ref($actions) eq 'ARRAY') {
                    472:             foreach my $item (@{$actions}) {
1.16      raeburn   473:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
1.1       raeburn   474:             }
                    475:         }
                    476:     }
                    477:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
                    478:     if ($phase eq 'process') {
1.23      bisitz    479:         $r->print(
                    480:             &Apache::lonhtmlcommon::actionbox(
                    481:                 ['<a href='.$dest.'>'.$button_text.'</a>']));
1.1       raeburn   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:         }
1.33      raeburn   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:         } 
1.1       raeburn   499:     }
                    500:     if ($phase eq 'process') {
1.20      www       501:         $r->print('</form>');
                    502:         if ($container) {
                    503:            &Apache::lonparmset::endSettingsScreen($r);
                    504:         }
                    505:         $r->print(&Apache::loncommon::end_page());
1.1       raeburn   506:     }
                    507:     return;
                    508: }
                    509: 
                    510: sub make_changes {
1.33      raeburn   511:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
                    512:         $allitems,$container,$parm_permission) = @_;
1.1       raeburn   513:     my %brcrumtext = &get_crumb_text();
                    514:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.4       raeburn   515:     my ($numchanged,%changes,%disallowed);
1.1       raeburn   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"});
1.20      www       521:     &print_header($r,$phase,$context,undef,$container);
1.50      raeburn   522:     my ($crstype,%lastact,$errors);
1.7       raeburn   523:     if ($context eq 'course') {
                    524:         $crstype = &Apache::loncommon::course_type();
                    525:     }
1.1       raeburn   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') {
1.4       raeburn   531:                     $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
                    532:                               &Apache::domainprefs::process_changes($r,$dom,
1.27      raeburn   533:                                           $confname,$item,$roles,$values,\%lastact));
1.1       raeburn   534:                 } else {
1.4       raeburn   535:                     $changes{$item} = {};
1.50      raeburn   536:                     $errors =
1.51      raeburn   537:                         &Apache::courseprefs::process_changes($dom,$confname,$item,$values,
1.50      raeburn   538:                                                               $prefs->{$item},$changes{$item},
                    539:                                                               $allitems,\%disallowed,$crstype);
1.4       raeburn   540:                     if (keys(%{$changes{$item}}) > 0) {
                    541:                         $numchanged ++;
                    542:                     }
1.1       raeburn   543:                 }
                    544:             }
                    545:         }
                    546:     }
1.4       raeburn   547:     if ($context eq 'course') {
                    548:         if ($numchanged) {
1.11      wenzelju  549:             my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
                    550:                                                           $prefs,$values,\%changes,$crstype);
                    551:             $r->print(&Apache::loncommon::confirmwrapper($message));
1.4       raeburn   552:         } else {
1.7       raeburn   553:             if ($crstype eq 'Community') {
1.11      wenzelju  554:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
1.7       raeburn   555:             } else {
1.11      wenzelju  556:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
1.7       raeburn   557:             }
1.4       raeburn   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},
1.7       raeburn   565:                                                                            $prefs,$crstype));
1.4       raeburn   566:                     }
                    567:                 }
                    568:             }
                    569:             $r->print('</p>');
                    570:         }
1.50      raeburn   571:         if ($errors) {
                    572:             $r->print('<p>'.$errors.'</p>');
                    573:         }
1.4       raeburn   574:     }
1.1       raeburn   575:     $r->print('<p>');
1.4       raeburn   576:     my $footer_text = 'Back to configuration display';
                    577:     if ($context eq 'course') {
                    578:         $footer_text = 'Back to display/edit settings'; 
                    579:     }
1.33      raeburn   580:     &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
1.1       raeburn   581:     $r->print('</p>');
1.27      raeburn   582:     return \%lastact;
1.1       raeburn   583: }
                    584: 
                    585: sub display_settings {
1.3       raeburn   586:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.33      raeburn   587:         $allitems,$crstype,$container,$parm_permission) = @_;
1.1       raeburn   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')",
1.4       raeburn   592:           text=>"Display/Edit Settings"});
1.30      raeburn   593:     my $instcode;
                    594:     if (ref($values) eq 'HASH') {
                    595:         $instcode = $values->{'internal.coursecode'};
                    596:     }
1.59      raeburn   597:     &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values);
1.12      raeburn   598:     my $divwidth = 900;
1.1       raeburn   599:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
                    600:         if (@actions > 0) {
                    601:             my $rowsum = 0;
1.32      raeburn   602:             my (%output,%rowtotal,@items,$got_check_uncheck);
1.1       raeburn   603:             foreach my $item (@{$prefs_order}) {
                    604:                 if (grep(/^\Q$item\E$/,@actions)) {
                    605:                     push(@items,$item);
                    606:                     if ($context eq 'domain') {
1.29      raeburn   607:                         my $settings;
                    608:                         if (ref($values) eq 'HASH') { 
                    609:                             $settings = $values->{$item};
                    610:                         }
1.32      raeburn   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:                             }
1.28      raeburn   620:                         } elsif ($item eq 'selfcreation') {
1.29      raeburn   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:                             }
1.58      raeburn   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') {
1.59      raeburn   652:                                 $settings = $values->{'lti'};
1.58      raeburn   653:                             }
1.15      raeburn   654:                         }
1.1       raeburn   655:                         ($output{$item},$rowtotal{$item}) =
                    656:                             &Apache::domainprefs::print_config_box($r,$dom,$confname,
1.28      raeburn   657:                                 $phase,$item,$prefs->{$item},$settings);
1.1       raeburn   658:                     } else {
                    659:                         ($output{$item},$rowtotal{$item}) =
1.56      raeburn   660:                             &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase,
1.33      raeburn   661:                                 $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
1.1       raeburn   662:                     }
                    663:                     $rowsum += $rowtotal{$item};
                    664:                 }
                    665:             }
1.12      raeburn   666:             $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
1.1       raeburn   667:             for (my $i=0; $i<@items; $i++) {
                    668:                 $r->print($output{$items[$i]});
                    669:             }
1.12      raeburn   670:             $r->print('</div>');
1.33      raeburn   671:             $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
1.1       raeburn   672:         } else {
                    673:             $r->print('<input type="hidden" name="phase" value="" />'.
1.12      raeburn   674:                       '<span class="LC_error">'.&mt('No settings chosen').
                    675:                       '</span>');
1.1       raeburn   676:         }
                    677:         $r->print('</form>');
                    678:     }
1.25      raeburn   679:     if ($container) {
                    680:         &Apache::lonparmset::endSettingsScreen($r);
                    681:     }
1.1       raeburn   682:     $r->print(&Apache::loncommon::end_page());
                    683:     return;
                    684: }
                    685: 
                    686: sub display_choices {
1.33      raeburn   687:     my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
1.1       raeburn   688:     if ($phase eq '') {
                    689:         $phase = 'pickactions';
                    690:     }
                    691:     my %helphash;
1.20      www       692:     &print_header($r,$phase,$context,undef,$container);
1.1       raeburn   693:     $r->print('<script type="text/javascript">'."\n".
1.6       raeburn   694:               '// <![CDATA['."\n".
1.1       raeburn   695:               &Apache::loncommon::check_uncheck_jscript()."\n".
1.6       raeburn   696:               '// ]]>'."\n".
1.12      raeburn   697:               '</script>'."\n");
1.33      raeburn   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>'.
1.13      raeburn   705:               '<div><input type="button" value="'.&mt('check all').'" '.
1.1       raeburn   706:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
                    707:               ' />'.('&nbsp;'x2).
                    708:               '<input type="button" value="'.&mt('uncheck all').'" '.
1.12      raeburn   709:               'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
                    710:               "\n".
1.13      raeburn   711:               '</div><div class="LC_left_float">');
1.12      raeburn   712:     my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
1.1       raeburn   713:     if (ref($prefs_order) eq 'ARRAY') {
                    714:         $numitems = @{$prefs_order};
                    715:     }
1.12      raeburn   716:     my $numcols = 3;
                    717:     $maxincol = int($numitems/$numcols);
                    718:     if ($numitems%$numcols) {
                    719:         $maxincol ++;
1.1       raeburn   720:     }
1.14      raeburn   721:     $firstthird = $maxincol;
                    722:     $secondthird = $firstthird + $maxincol;
1.1       raeburn   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 ++;
1.12      raeburn   731:             if ((!$seconddiv) && ($count >= $firstthird)) {
1.1       raeburn   732:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
                    733:                 $seconddiv = 1;
                    734:             }
1.12      raeburn   735:             if ((!$thirddiv) && ($count >= $secondthird)) {
                    736:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
                    737:                 $thirddiv = 1;
1.13      raeburn   738:             }
1.1       raeburn   739:         }
                    740:     }
1.49      raeburn   741:     $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
1.33      raeburn   742:     $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
1.1       raeburn   743:     $r->print('</form>');
1.25      raeburn   744:     if ($container) {
                    745:         &Apache::lonparmset::endSettingsScreen($r);
                    746:     }
1.1       raeburn   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() {
1.21      www       758:         modalWindow.close();
1.1       raeburn   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',
1.4       raeburn   796:                        course => 'Display/Edit Settings',
1.1       raeburn   797:                      );
                    798:     return %brcrumbtext;
                    799: }
                    800: 
                    801: 1;

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