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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.74    ! raeburn     4: # $Id: lonconfigsettings.pm,v 1.73 2024/07/14 16:05:27 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();
1.68      raeburn    40: use LONCAPA qw(:DEFAULT :match);
                     41: use File::Copy;
1.1       raeburn    42: 
                     43: sub print_header {
1.59      raeburn    44:     my ($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values) = @_;
1.30      raeburn    45:     my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
1.68      raeburn    46:         $linkprot_check,$ltitools_check,$crstype,@actions,@code_order);
1.30      raeburn    47:     if ($phase eq 'display') {
                     48:         @actions = &Apache::loncommon::get_env_multiple('form.actions');
                     49:     }
1.1       raeburn    50:     if ($context eq 'domain') {
1.12      raeburn    51:         ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
1.1       raeburn    52:         $action = '/adm/domainprefs';
1.8       raeburn    53:         if ($phase eq 'display') {
                     54:             if (grep(/^coursecategories$/,@actions)) {
                     55:                 $call_category_check = qq|
                     56:     if (formname == document.display) {
                     57:         if (!categoryCheck(formname)) {
                     58:             return;
                     59:         }
                     60:     }
                     61: |;
                     62:             }
                     63:         }
1.1       raeburn    64:     } else {
1.24      raeburn    65:         $crstype = &Apache::loncommon::course_type();
                     66:         if ($crstype eq 'Community') {
1.7       raeburn    67:             ($pagetitle,$brcrumtitle) = ('Community Configuration','Community Configuration');
                     68:         } else {
                     69:             ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
                     70:         }
1.1       raeburn    71:         $action = '/adm/courseprefs';
1.30      raeburn    72:         if ($phase eq 'display') {
                     73:             if (grep(/^courseinfo$/,@actions)) {
                     74:                 my %codedefaults;
                     75:                 &Apache::lonnet::auto_instcode_defaults($env{'request.role.domain'},\%codedefaults,
                     76:                                                         \@code_order);
                     77:                 if (@code_order) {
                     78:                    my $noinstcodestr = &mt('You indicated cloning based on category, but did not select any categories.');
1.31      damieng    79:                    &js_escape(\$noinstcodestr);
1.30      raeburn    80:                    $instcode_check = <<"ENDSCRIPT";
                     81:     if (formname == document.display) {
                     82:         if (formname.cloners_instcode.length) {
                     83:             for (var j=0; j<formname.cloners_instcode.length; j++) {
                     84:                 if (formname.cloners_instcode[j].checked) {
                     85:                     if (formname.cloners_instcode[j].value == 1) {
                     86:                         var codes;
                     87:                         if (document.getElementsByClassName) {
                     88:                             codes = document.getElementsByClassName('LC_cloners_instcodes');
                     89:                         } else {
                     90:                             codes = getElementsByClassName(document.body,'LC_cloners_instcodes');
                     91:                         }
                     92:                         if (codes.length) {
                     93:                             var gotcode = 0;
                     94:                             for (var i=0; i<codes.length; i++) {
                     95:                                 if (codes[i].selectedIndex != 0) {
1.71      raeburn    96:                                      gotcode = 1;
1.30      raeburn    97:                                      break;
                     98:                                 }
                     99:                             }
                    100:                             if (!gotcode) {
                    101:                                 for (var k=0; k<formname.cloners_instcode.length; k++) {
                    102:                                     if (formname.cloners_instcode[k].value == 0) {
                    103:                                         formname.cloners_instcode[k].checked = true;
                    104:                                     }
                    105:                                 }
                    106:                                 toggleCloners(document.display.cloners_instcode);
                    107:                                 alert('$noinstcodestr');
                    108:                                 return false;
                    109:                             }
                    110:                         }
                    111:                     }
                    112:                 }
                    113:             }
                    114:         }
                    115:     }
                    116: 
                    117: ENDSCRIPT
                    118:                 }
                    119:             }
1.68      raeburn   120:             if (($context eq 'course') && ((grep(/^linkprot$/,@actions)) ||
                    121:                 (grep(/^ltitools$/,@actions)))) {
1.59      raeburn   122:                 my $allowed;
                    123:                 my $home = &Apache::lonnet::homeserver($confname,$dom);
                    124:                 unless ($home eq 'no_host') {
                    125:                     my @ids=&Apache::lonnet::current_machine_ids();
                    126:                     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    127:                 }
                    128:                 if ($allowed) {
1.68      raeburn   129:                     if (grep((/^linkprot$/,@actions))) {
                    130:                         $linkprot_check = &ltisecret_js('linkprot',$dom,$values);
1.59      raeburn   131:                     }
1.68      raeburn   132:                     if (grep((/^ltitools$/,@actions))) {
                    133:                         $ltitools_check = &ltisecret_js('ltitools',$dom,$values);
1.59      raeburn   134:                     }
                    135:                 }
                    136:             }
1.30      raeburn   137:         }
1.1       raeburn   138:     }
                    139:     my $alert = &mt('You must select at least one functionality type to display.');
1.31      damieng   140:     &js_escape(\$alert);
1.1       raeburn   141:     my $js = '
                    142: <script type="text/javascript">
1.6       raeburn   143: // <![CDATA[
                    144: 
1.1       raeburn   145: function changePage(formname,newphase) {
                    146:     formname.phase.value = newphase;
                    147:     numchecked = 0;
                    148:     if (formname == document.pickactions) {
                    149:         if (formname.actions.length > 0) {
                    150:             for (var i = 0; i<formname.actions.length; i++) {
                    151:                 if (formname.actions[i].checked) {
                    152:                     numchecked ++;
                    153:                 }
                    154:             }
                    155:         } else {
                    156:             if (formname.actions.checked) {
                    157:                 numchecked ++;
                    158:             }
                    159:         }
                    160:         if (numchecked > 0) {
                    161:             formname.submit();
                    162:         } else {
                    163:             alert("'.$alert.'");
                    164:             return;
                    165:         }
                    166:     }
1.68      raeburn   167:     '.$instcode_check.$call_category_check.$linkprot_check.$ltitools_check.'
1.1       raeburn   168:     formname.submit();
                    169: }'."\n";
                    170:     if ($phase eq 'pickactions') {
1.22      foxr      171: 	$js .= &Apache::lonhtmlcommon::color_picker();
1.1       raeburn   172:         $js .=
1.12      raeburn   173:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
1.1       raeburn   174:     } elsif ($phase eq 'display') {
1.22      foxr      175: 	$js .= &Apache::lonhtmlcommon::color_picker();
1.1       raeburn   176:         $js .= &color_pick_js()."\n";
1.68      raeburn   177:         if ($context eq 'domain') {
                    178:             if (grep(/^(lti|ltitools)$/,@actions)) {
                    179:                  $js .= &ltisec_javascript($dom)."\n";
                    180:             }
                    181:         }
1.1       raeburn   182:     }
                    183:     $js .= &Apache::loncommon::viewport_size_js().'
1.6       raeburn   184: 
                    185: // ]]>
1.1       raeburn   186: </script>
                    187: ';
1.2       raeburn   188:     if ($jscript) {
                    189:         $js .= "
                    190: 
                    191: $jscript
                    192: 
                    193: ";
                    194:     }
1.1       raeburn   195:     my $additem;
                    196:     if ($phase eq 'pickactions') {
                    197:         my %loaditems = (
1.12      raeburn   198:                     'onload' => "setFormElements(document.pickactions);",
1.1       raeburn   199:                         );
                    200:         $additem = {'add_entries' => \%loaditems,};
1.30      raeburn   201:     } elsif ($phase eq 'display') {
                    202:         if ($context eq 'domain') {
1.34      raeburn   203:             my $onload;
1.30      raeburn   204:             if (grep(/^coursedefaults$/,@actions)) {
1.34      raeburn   205:                 $onload = "toggleDisplay(document.display,'cloneinstcode');".
                    206:                           "toggleDisplay(document.display,'credits');".
                    207:                           "toggleDisplay(document.display,'studentsubmission');";
                    208:             }
                    209:             if (grep(/^selfcreation$/,@actions)) {
                    210:                 my $prefix = 'cancreate_emailverified';
1.36      raeburn   211:                 my $customclass = 'LC_selfcreate_email';
                    212:                 my $classprefix = 'LC_canmodify_emailusername_';
                    213:                 my $optionsprefix = 'LC_options_emailusername_';
                    214:                 $onload .= "toggleRows(document.display,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                    215:                 my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                    216:                 my $hascustom;
                    217:                 my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
                    218:                 if (ref($emailrules) eq 'HASH') {
                    219:                     if (keys(%{$emailrules}) > 0) {
                    220:                         $hascustom = 'cancreate_emailrule';
                    221:                     }
                    222:                 }
                    223:                 my @posstypes;
                    224:                 if (ref($types) eq 'ARRAY') {
                    225:                     @posstypes = @{$types};
                    226:                     push(@posstypes,'default');
                    227:                     foreach my $type (@posstypes) {
                    228:                         $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
                    229:                                                                "'cancreate_emaildomain','$type');";
1.34      raeburn   230:                     }
1.36      raeburn   231:                 } else {
                    232:                     $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
                    233:                                                        "'cancreate_emaildomain','default');";
1.34      raeburn   234:                 }
1.71      raeburn   235:             }
1.37      raeburn   236:             if (grep(/^contacts$/,@actions)) {
                    237:                 my $customclass = 'LC_helpdesk_override';
                    238:                 my $optionsprefix = 'LC_options_helpdesk_';
1.38      raeburn   239:                 $onload .= "toggleHelpdeskRow(document.display,'overrides','$customclass','$optionsprefix');";
1.34      raeburn   240:             }
1.40      raeburn   241:             if (grep(/^lti$/,@actions)) {
                    242:                 $onload .= "toggleLTI(document.display,'user','add');".
                    243:                            "toggleLTI(document.display,'crs','add');".
1.42      raeburn   244:                            "toggleLTI(document.display,'sec','add');".
1.43      raeburn   245:                            "toggleLTI(document.display,'lcauth','add');".
1.44      raeburn   246:                            "toggleLTI(document.display,'lcmenu','add');".
1.46      raeburn   247:                            "toggleLTI(document.display,'passback','add');".
                    248:                            "toggleLTI(document.display,'callback','add');";
1.40      raeburn   249:                 if (ref($values) eq 'HASH') {
                    250:                     if (ref($values->{'lti'}) eq 'HASH') {
                    251:                         my $numlti = scalar(keys(%{$values->{'lti'}}));
                    252:                         for (my $i=0; $i<$numlti; $i++) {
                    253:                             $onload .= "toggleLTI(document.display,'user','$i');".
                    254:                                        "toggleLTI(document.display,'crs','$i');".
1.42      raeburn   255:                                        "toggleLTI(document.display,'sec','$i');".
1.43      raeburn   256:                                        "toggleLTI(document.display,'lcauth','$i');".
1.44      raeburn   257:                                        "toggleLTI(document.display,'lcmenu','$i');".
1.46      raeburn   258:                                        "toggleLTI(document.display,'passback','$i');".
                    259:                                        "toggleLTI(document.display,'callback','$i');";
1.40      raeburn   260:                         }
                    261:                     }
1.41      raeburn   262:                 }
1.58      raeburn   263:                 my %servers = &Apache::lonnet::get_servers($dom,'library');
                    264:                 foreach my $server (keys(%servers)) {
1.68      raeburn   265:                     $onload .= "togglePrivKey(document.display,'ltisec','$server');";
1.58      raeburn   266:                 }
1.68      raeburn   267:                 $onload .= "toggleLTIEncKey(document.display,'ltisec');";
1.40      raeburn   268:             }
1.39      raeburn   269:             if (grep(/^ltitools$/,@actions)) {
                    270:                 $onload .= "toggleLTITools(document.display,'passback','add');".
1.41      raeburn   271:                            "toggleLTITools(document.display,'roster','add');".
1.74    ! raeburn   272:                            "toggleLTITools(document.display,'returnurl','add');".
1.41      raeburn   273:                            "toggleLTITools(document.display,'user','add');";
1.39      raeburn   274:                 if (ref($values) eq 'HASH') {
                    275:                     if (ref($values->{'ltitools'}) eq 'HASH') {
                    276:                         my $numltitools = scalar(keys(%{$values->{'ltitools'}}));
                    277:                         for (my $i=0; $i<$numltitools; $i++) {
                    278:                             $onload .= "toggleLTITools(document.display,'passback','$i');".
1.41      raeburn   279:                                        "toggleLTITools(document.display,'roster','$i');".
1.74    ! raeburn   280:                                        "toggleLTITools(document.display,'returnurl','$i');".
1.41      raeburn   281:                                        "toggleLTITools(document.display,'user','$i');";
1.39      raeburn   282:                         }
                    283:                     }
                    284:                 }
1.68      raeburn   285:                 my %servers = &Apache::lonnet::get_servers($dom,'library');
                    286:                 foreach my $server (keys(%servers)) {
                    287:                     $onload .= "togglePrivKey(document.display,'toolsec','$server');";
                    288:                 }
                    289:                 $onload .= "toggleLTIEncKey(document.display,'toolsec');";
1.39      raeburn   290:             }
1.48      raeburn   291:             if (grep(/^wafproxy$/,@actions)) {
                    292:                 $onload .= "toggleWAF();checkWAF();updateWAF();";
                    293:             }
1.47      raeburn   294:             if (grep(/^proctoring$/,@actions)) {
                    295:                 $onload .= "toggleProctoring(document.display,'proctorio');".
                    296:                            "toggleProctoring(document.display,'examity');";
                    297:             }
1.45      raeburn   298:             if (grep(/^scantron$/,@actions)) {
1.54      raeburn   299:                 $onload .= "toggleScantron(document.display);";
1.45      raeburn   300:             }
1.52      raeburn   301:             if (grep(/^autoupdate$/,@actions)) {
1.54      raeburn   302:                 $onload .= "toggleLastActiveDays(document.display);";
1.52      raeburn   303:             }
1.55      raeburn   304:             if (grep(/^autoenroll$/,@actions)) {
                    305:                 $onload .= "toggleFailsafe(document.display);";
                    306:             }
1.53      raeburn   307:             if (grep(/^login$/,@actions)) {
                    308:                 my %domservers = &Apache::lonnet::get_servers($dom);
                    309:                 foreach my $server (sort(keys(%domservers))) {
                    310:                     $onload .= "toggleSamlOptions(document.display,'$server');";
                    311:                 }
                    312:             }
1.34      raeburn   313:             if ($onload) {
1.30      raeburn   314:                 my %loaditems = (
1.35      raeburn   315:                                   'onload' => $onload,
1.30      raeburn   316:                                 );
                    317:                 $additem = {'add_entries' => \%loaditems,};
                    318:             }
                    319:         } elsif ($context eq 'course') {
1.68      raeburn   320:             my ($onload,$ishome,$crshome_checked);
1.30      raeburn   321:             if (grep(/^courseinfo$/,@actions)) {
1.56      raeburn   322:                 if (@code_order) {
                    323:                     $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);";
                    324:                 }
                    325:             }
1.60      raeburn   326:             if (grep(/^linkprot$/,@actions)) {
1.56      raeburn   327:                 if (ref($values) eq 'HASH') {
1.60      raeburn   328:                     if (ref($values->{'linkprot'}) eq 'HASH') {
1.57      raeburn   329:                         my $ltiauth;
                    330:                         if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
                    331:                             $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
                    332:                         } else {
                    333:                             my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
                    334:                             $ltiauth = $domdefs{'crsltiauth'};
                    335:                         }
1.68      raeburn   336:                         unless ($crshome_checked) {
                    337:                             $ishome = &is_home();
                    338:                             $crshome_checked = 1;
1.62      raeburn   339:                         }
1.60      raeburn   340:                         my $posslti = scalar(keys(%{$values->{'linkprot'}}));
1.57      raeburn   341:                         for (my $i=0; $i<=$posslti; $i++) {
                    342:                             my $num = $i;
                    343:                             if ($i == $posslti) {
                    344:                                 $num = 'add';
                    345:                             }
1.60      raeburn   346:                             if (ref($values->{'linkprot'}->{$i}) eq 'HASH') {
                    347:                                 if ($values->{'linkprot'}->{$i}->{'usable'}) {
1.68      raeburn   348:                                     $onload .= "toggleChgSecret(document.display,'$num','secret','linkprot');";
1.57      raeburn   349:                                 }
1.58      raeburn   350:                             }
1.70      raeburn   351:                             $onload .= "toggleLinkProtExtra(document.display,'returnurl','divurlparam','1','inline-block','$num');".
                    352:                                        "toggleLinkProtExtra(document.display,'passback','passbackparam','1','inline-block','$num');";
1.57      raeburn   353:                             if ($ltiauth) {
1.65      raeburn   354:                                 $onload .= "toggleLinkProtExtra(document.display,'requser','optional','1','block','$num');".
                    355:                                            "toggleLinkProtExtra(document.display,'mapuser','userfield','other','inline-block','$num');";
1.56      raeburn   356:                             }
1.62      raeburn   357:                             if ($ishome) {
1.68      raeburn   358:                                 $onload .= "uncheckLinkProtMakeVis('linkprot','visible','$num');";
                    359:                             }
                    360:                         }
                    361:                     }
                    362:                 }
                    363:             }
                    364:             if (grep(/^ltitools$/,@actions)) {
                    365:                 if (ref($values) eq 'HASH') {
                    366:                     if (ref($values->{'ltitools'}) eq 'HASH') {
                    367:                         unless ($crshome_checked) {
                    368:                             $ishome = &is_home();
                    369:                             $crshome_checked = 1;
                    370:                         }
                    371:                         my $possltitools = scalar(keys(%{$values->{'ltitools'}}));
                    372:                         for (my $i=0; $i<=$possltitools; $i++) {
                    373:                             my $num = $i;
                    374:                             if ($i == $possltitools) {
                    375:                                 $num = 'add';
                    376:                             }
                    377:                             if (ref($values->{'ltitools'}->{$i}) eq 'HASH') {
                    378:                                 if ($values->{'ltitools'}->{$i}->{'usable'}) {
                    379:                                     $onload .= "toggleChgSecret(document.display,'$num','secret','ltitools');";
                    380:                                 }
                    381:                             }
                    382:                             if ($ishome) {
                    383:                                 $onload .= "uncheckLinkProtMakeVis('ltitools','visible','$num');";
1.62      raeburn   384:                             }
1.56      raeburn   385:                         }
                    386:                     }
1.30      raeburn   387:                 }
                    388:             }
1.66      raeburn   389:             if (grep(/^appearance$/,@actions)) {
1.67      raeburn   390:                 $onload .= "toggleExtRes();";
                    391:             }
                    392:             if (grep(/^localization$/,@actions)) {
                    393:                 $onload .= "toggleTimeZone();";
1.66      raeburn   394:             }
1.72      raeburn   395:             if (grep(/^grading$/,@actions)) {
                    396:                 $onload .= 'toggleGrading(document.display);toggleHiddenTotalsSec(document.display);';
                    397:             }
1.56      raeburn   398:             if ($onload) {
                    399:                 my %loaditems = (
                    400:                                   'onload' => $onload,
                    401:                                 );
                    402:                 $additem = {'add_entries' => \%loaditems,};
                    403:             }
1.30      raeburn   404:         }
1.1       raeburn   405:     }
                    406:     $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
                    407:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
                    408:     $r->print('
                    409: <form name="parmform" action="">
                    410: <input type="hidden" name="pres_marker" />
                    411: <input type="hidden" name="pres_type" />
                    412: <input type="hidden" name="pres_value" />
                    413: </form>
                    414: ');
1.20      www       415:     if ($container) {
1.24      raeburn   416:        &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
1.20      www       417:     }
1.1       raeburn   418:     $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
                    419:               ' enctype="multipart/form-data">');
                    420:     return;
                    421: }
                    422: 
1.68      raeburn   423: sub ltisecret_js {
                    424:     my ($name,$dom,$values) = @_;
                    425:     return unless (ref($values) eq 'HASH');
                    426:     my $js;
                    427:     if (($name eq 'linkprot') || ($name eq 'ltitools')) {
                    428:         my (@changeable,@settable);
                    429:         if (ref($values->{$name}) eq 'HASH') {
                    430:             if (keys(%{$values->{$name}})) {
                    431:                 my @current = sort { $a <=> $b } keys(%{$values->{$name}});
                    432:                 if (@current) {
                    433:                     for (my $i=0; $i<@current; $i++) {
                    434:                         my $num = $current[$i];
                    435:                         if (ref($values->{$name}->{$num}) eq 'HASH') {
                    436:                             if ($values->{$name}->{$num}->{'usable'}) {
                    437:                                 push(@changeable,$i);
                    438:                             } else {
                    439:                                 push(@settable,$i);
                    440:                             }
                    441:                         }
                    442:                     }
                    443:                 }
                    444:             }
                    445:         }
                    446:         my ($numrules,$intargjs);
                    447: $js .= <<ENDJS;
                    448: 
                    449: var ${name}radio = '';
                    450: var ${name}secretinput = '';
                    451: var ${name}posscheck = '';
                    452: 
                    453: ENDJS
                    454:         if (@changeable) {
                    455:             foreach my $num (@changeable) {
                    456:                 ($numrules,$intargjs) =
                    457:                     &Apache::loncommon::passwd_validation_js($name.'secretinput',$dom,$name,$num);
                    458:                 $js .= <<"ENDJS";
                    459: ${name}posscheck = '';
                    460: ${name}radio = document.display.elements['${name}_changesecret_$num'];
                    461: if (${name}radio.length) {
                    462:     for (var i=0; i<${name}radio.length; i++) {
                    463:         if (${name}radio[i].checked) {
                    464:             if (${name}radio[i].value == 1) {
                    465:                 ${name}posscheck = 1;
                    466:             }
                    467:         }
                    468:     }
                    469: }
                    470: 
                    471: ENDJS
                    472:                 if ($numrules) {
                    473:                     $js .= <<"ENDJS";
                    474: if (${name}posscheck) {
                    475:     ${name}secretinput = document.display.elements['${name}_secret_$num'].value;
                    476:     $intargjs
                    477: }
                    478: 
                    479: ENDJS
                    480:                 }
                    481:                 $js .= <<"ENDJS";
                    482: if (${name}posscheck) {
                    483:     uncheckLinkProtMakeVis('$name','visible','$num');
                    484:     document.display.elements['${name}_secret_$num'].type = 'password';
                    485: }
                    486: 
                    487: ENDJS
                    488:             }
                    489:         }
                    490:         if (@settable) {
                    491:             foreach my $num (@settable) {
                    492:                 ($numrules,$intargjs) =
                    493:                     &Apache::loncommon::passwd_validation_js($name.'secretinput',$dom,$name,$num);
                    494:                 if ($numrules) {
                    495:                     $js .= <<ENDJS;
                    496: ${name}secretinput = document.display.elements['${name}_secret_$num'].value;
                    497: $intargjs
                    498: 
                    499: ENDJS
                    500:                 }
                    501:                 $js .= <<ENDJS;
                    502: uncheckLinkProtMakeVis('$name','visible','$num');
                    503: document.display.elements['${name}_secret_$num'].type = 'password';
                    504: 
                    505: ENDJS
                    506:             }
                    507:         }
                    508:         ($numrules,$intargjs) =
                    509:             &Apache::loncommon::passwd_validation_js($name.'secretinput',$dom,$name,'add');
                    510:         if ($numrules) {
                    511:             $js .= <<ENDJS
1.69      raeburn   512: ${name}secretinput = document.display.elements['${name}_secret_add'].value;
1.68      raeburn   513: if (document.display.elements['${name}_add'].checked) {
                    514:     $intargjs
                    515: }
                    516: 
                    517: ENDJS
                    518:         }
                    519:         $js .= <<ENDJS;
                    520: uncheckLinkProtMakeVis('$name','visible','add');
1.69      raeburn   521: document.display.elements['${name}_secret_add'].type = 'password';
1.68      raeburn   522: 
                    523: ENDJS
                    524:     }
                    525:     return $js;
                    526: }
                    527: 
                    528: sub is_home {
                    529:     my $ishome;
                    530:     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
                    531:     unless (($chome eq 'no_host') || ($chome eq '')) {
                    532:         my @ids=&Apache::lonnet::current_machine_ids();
                    533:         foreach my $id (@ids) {
                    534:             if ($id eq $chome) {
                    535:                 $ishome=1;
                    536:                 last;
                    537:             }
                    538:         }
                    539:     }
                    540:     return $ishome;
                    541: }
                    542: 
1.1       raeburn   543: sub print_footer {
1.33      raeburn   544:     my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
1.1       raeburn   545:     $button_text = &mt($button_text);
1.12      raeburn   546:     $r->print('<input type="hidden" name="phase" value="" />');
1.5       raeburn   547:     if (defined($env{'form.origin'})) {
                    548:         $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
                    549:     }
1.1       raeburn   550:     if (($phase eq 'display') || ($phase eq 'process')) {
                    551:         if (ref($actions) eq 'ARRAY') {
                    552:             foreach my $item (@{$actions}) {
1.16      raeburn   553:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
1.1       raeburn   554:             }
                    555:         }
                    556:     }
                    557:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
                    558:     if ($phase eq 'process') {
1.23      bisitz    559:         $r->print(
                    560:             &Apache::lonhtmlcommon::actionbox(
                    561:                 ['<a href='.$dest.'>'.$button_text.'</a>']));
1.1       raeburn   562:     } else {
                    563:         my $onclick;
                    564:         if ($phase eq 'display') {
                    565:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
                    566:         } else {
                    567:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
                    568:         }
1.33      raeburn   569:         my $showbutton = 1;
                    570:         if (ref($parm_permission) eq 'HASH') {
                    571:             unless (($parm_permission->{'process'}) || ($newphase eq 'display')) {
                    572:                 $showbutton = 0;
                    573:             }
                    574:         }
                    575:         if ($showbutton) {
                    576:             $r->print('<p><input type="button" name="store" value="'.
                    577:                       $button_text.'" onclick='.$onclick.' /></p>');
1.71      raeburn   578:         }
1.1       raeburn   579:     }
                    580:     if ($phase eq 'process') {
1.20      www       581:         $r->print('</form>');
                    582:         if ($container) {
                    583:            &Apache::lonparmset::endSettingsScreen($r);
                    584:         }
                    585:         $r->print(&Apache::loncommon::end_page());
1.1       raeburn   586:     }
                    587:     return;
                    588: }
                    589: 
                    590: sub make_changes {
1.33      raeburn   591:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
                    592:         $allitems,$container,$parm_permission) = @_;
1.1       raeburn   593:     my %brcrumtext = &get_crumb_text();
                    594:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.4       raeburn   595:     my ($numchanged,%changes,%disallowed);
1.1       raeburn   596:     &Apache::lonhtmlcommon::add_breadcrumb
                    597:       ({href=>"javascript:changePage(document.$phase,'display')",
                    598:         text=>$brcrumtext{$context}},
                    599:        {href=>"javascript:changePage(document.$phase,'$phase')",
                    600:         text=>"Updated"});
1.20      www       601:     &print_header($r,$phase,$context,undef,$container);
1.50      raeburn   602:     my ($crstype,%lastact,$errors);
1.7       raeburn   603:     if ($context eq 'course') {
                    604:         $crstype = &Apache::loncommon::course_type();
                    605:     }
1.1       raeburn   606:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && 
                    607:         (ref($prefs) eq 'HASH')) {
                    608:         foreach my $item (@{$prefs_order}) {
                    609:             if (grep(/^\Q$item\E$/,@actions)) {
                    610:                 if ($context eq 'domain') {
1.4       raeburn   611:                     $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
                    612:                               &Apache::domainprefs::process_changes($r,$dom,
1.27      raeburn   613:                                           $confname,$item,$roles,$values,\%lastact));
1.1       raeburn   614:                 } else {
1.4       raeburn   615:                     $changes{$item} = {};
1.50      raeburn   616:                     $errors =
1.51      raeburn   617:                         &Apache::courseprefs::process_changes($dom,$confname,$item,$values,
1.50      raeburn   618:                                                               $prefs->{$item},$changes{$item},
1.64      raeburn   619:                                                               $allitems,\%disallowed,$crstype,
                    620:                                                               \%lastact);
1.4       raeburn   621:                     if (keys(%{$changes{$item}}) > 0) {
                    622:                         $numchanged ++;
                    623:                     }
1.1       raeburn   624:                 }
                    625:             }
                    626:         }
                    627:     }
1.4       raeburn   628:     if ($context eq 'course') {
                    629:         if ($numchanged) {
1.11      wenzelju  630:             my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
                    631:                                                           $prefs,$values,\%changes,$crstype);
                    632:             $r->print(&Apache::loncommon::confirmwrapper($message));
1.4       raeburn   633:         } else {
1.7       raeburn   634:             if ($crstype eq 'Community') {
1.11      wenzelju  635:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
1.7       raeburn   636:             } else {
1.11      wenzelju  637:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
1.7       raeburn   638:             }
1.4       raeburn   639:         }
                    640:         if (keys(%disallowed) > 0) {
                    641:             $r->print('<p>');
                    642:             foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
                    643:                 if (ref($disallowed{$item}) eq 'HASH') {
                    644:                     if (keys(%{$disallowed{$item}}) > 0) {
                    645:                         $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
1.7       raeburn   646:                                                                            $prefs,$crstype));
1.4       raeburn   647:                     }
                    648:                 }
                    649:             }
                    650:             $r->print('</p>');
                    651:         }
1.50      raeburn   652:         if ($errors) {
                    653:             $r->print('<p>'.$errors.'</p>');
                    654:         }
1.4       raeburn   655:     }
1.1       raeburn   656:     $r->print('<p>');
1.4       raeburn   657:     my $footer_text = 'Back to configuration display';
                    658:     if ($context eq 'course') {
                    659:         $footer_text = 'Back to display/edit settings'; 
                    660:     }
1.73      raeburn   661:     $r->print('</p>');
1.33      raeburn   662:     &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
1.27      raeburn   663:     return \%lastact;
1.1       raeburn   664: }
                    665: 
                    666: sub display_settings {
1.3       raeburn   667:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.33      raeburn   668:         $allitems,$crstype,$container,$parm_permission) = @_;
1.1       raeburn   669:     my %brcrumtext = &get_crumb_text();
                    670:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
                    671:     &Apache::lonhtmlcommon::add_breadcrumb
                    672:         ({href=>"javascript:changePage(document.$phase,'display')",
1.4       raeburn   673:           text=>"Display/Edit Settings"});
1.30      raeburn   674:     my $instcode;
                    675:     if (ref($values) eq 'HASH') {
                    676:         $instcode = $values->{'internal.coursecode'};
                    677:     }
1.59      raeburn   678:     &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values);
1.12      raeburn   679:     my $divwidth = 900;
1.1       raeburn   680:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
                    681:         if (@actions > 0) {
                    682:             my $rowsum = 0;
1.68      raeburn   683:             my (%output,%rowtotal,@items,$got_check_uncheck,$got_change_secret);
1.1       raeburn   684:             foreach my $item (@{$prefs_order}) {
                    685:                 if (grep(/^\Q$item\E$/,@actions)) {
                    686:                     push(@items,$item);
                    687:                     if ($context eq 'domain') {
1.29      raeburn   688:                         my $settings;
1.71      raeburn   689:                         if (ref($values) eq 'HASH') {
1.29      raeburn   690:                             $settings = $values->{$item};
                    691:                         }
1.32      raeburn   692:                         if (($item eq 'usersessions') || ($item eq 'ssl')) {
                    693:                             unless ($got_check_uncheck) {
                    694:                                 $r->print('<script type="text/javascript">'."\n".
                    695:                                           '// <![CDATA['."\n".
                    696:                                           &Apache::loncommon::check_uncheck_jscript()."\n".
                    697:                                           '// ]]>'."\n".
                    698:                                           '</script>'."\n");
                    699:                                 $got_check_uncheck = 1;
                    700:                             }
1.28      raeburn   701:                         } elsif ($item eq 'selfcreation') {
1.29      raeburn   702:                             if (ref($values) eq 'HASH') {
                    703:                                 $settings = $values->{'usercreation'};
                    704:                             }
                    705:                         } elsif ($item eq 'defaults') {
                    706:                             if (ref($values->{'inststatus'}) eq 'HASH') {
                    707:                                 if (ref($values->{'defaults'}) eq 'HASH') {
                    708:                                     $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
                    709:                                 } else {
                    710:                                     $settings = $values->{'inststatus'};
                    711:                                 }
                    712:                             } else {
                    713:                                 my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                    714:                                 my $inststatus = {
                    715:                                                    inststatustypes => $usertypes,
                    716:                                                    inststatusorder => $types,
1.71      raeburn   717:                                                    inststatusguest => [],
1.29      raeburn   718:                                                  };
                    719:                                 if (ref($values->{defaults}) eq 'HASH') {
                    720:                                     $settings = {%{$inststatus},%{$values->{'defaults'}}};
                    721:                                 } else {
                    722:                                     $settings = $inststatus;
                    723:                                 }
                    724:                             }
1.68      raeburn   725:                         } elsif (($item eq 'lti') || ($item eq 'ltitools')) {
                    726:                             unless ($got_change_secret) {
                    727:                                 $r->print('<script type="text/javascript">'."\n".
                    728:                                           '// <![CDATA['."\n".
                    729:                                           &change_secret_js()."\n".
                    730:                                           '// ]]>'."\n".
                    731:                                           '</script>'."\n");
                    732:                                 $got_change_secret = 1;
                    733:                             }
                    734:                             if ($item eq 'lti') {
                    735:                                 if (ref($values->{'ltisec'}) eq 'HASH') {
                    736:                                     if (ref($values->{'lti'}) eq 'HASH') {
                    737:                                         $settings = {%{$values->{'lti'}},%{$values->{'ltisec'}}};
                    738:                                     } else {
                    739:                                         $settings = $values->{'ltisec'};
                    740:                                     }
                    741:                                 } elsif (ref($values->{'lti'}) eq 'HASH') {
                    742:                                     $settings = $values->{'lti'};
                    743:                                 }
                    744:                             } elsif ($item eq 'ltitools') {
                    745:                                 if (ref($values->{'toolsec'}) eq 'HASH') {
                    746:                                     if (ref($values->{'ltitools'}) eq 'HASH') {
                    747:                                         $settings = {%{$values->{'ltitools'}},%{$values->{'toolsec'}}};
                    748:                                     } else {
                    749:                                         $settings = $values->{'toolsec'};
                    750:                                     }
1.58      raeburn   751:                                 }
                    752:                             }
1.15      raeburn   753:                         }
1.1       raeburn   754:                         ($output{$item},$rowtotal{$item}) =
                    755:                             &Apache::domainprefs::print_config_box($r,$dom,$confname,
1.28      raeburn   756:                                 $phase,$item,$prefs->{$item},$settings);
1.1       raeburn   757:                     } else {
1.68      raeburn   758:                         unless ($got_change_secret) {
                    759:                             $r->print('<script type="text/javascript">'."\n".
                    760:                                       '// <![CDATA['."\n".
                    761:                                       &change_secret_js()."\n".
                    762:                                       '// ]]>'."\n".
                    763:                                       '</script>'."\n");
                    764:                             $got_change_secret = 1;
                    765:                         }
1.1       raeburn   766:                         ($output{$item},$rowtotal{$item}) =
1.56      raeburn   767:                             &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase,
1.33      raeburn   768:                                 $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
1.1       raeburn   769:                     }
                    770:                     $rowsum += $rowtotal{$item};
                    771:                 }
                    772:             }
1.12      raeburn   773:             $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
1.1       raeburn   774:             for (my $i=0; $i<@items; $i++) {
                    775:                 $r->print($output{$items[$i]});
                    776:             }
1.12      raeburn   777:             $r->print('</div>');
1.33      raeburn   778:             $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
1.1       raeburn   779:         } else {
                    780:             $r->print('<input type="hidden" name="phase" value="" />'.
1.12      raeburn   781:                       '<span class="LC_error">'.&mt('No settings chosen').
                    782:                       '</span>');
1.1       raeburn   783:         }
                    784:         $r->print('</form>');
                    785:     }
1.25      raeburn   786:     if ($container) {
                    787:         &Apache::lonparmset::endSettingsScreen($r);
                    788:     }
1.1       raeburn   789:     $r->print(&Apache::loncommon::end_page());
                    790:     return;
                    791: }
                    792: 
                    793: sub display_choices {
1.33      raeburn   794:     my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
1.1       raeburn   795:     if ($phase eq '') {
                    796:         $phase = 'pickactions';
                    797:     }
                    798:     my %helphash;
1.20      www       799:     &print_header($r,$phase,$context,undef,$container);
1.1       raeburn   800:     $r->print('<script type="text/javascript">'."\n".
1.6       raeburn   801:               '// <![CDATA['."\n".
1.1       raeburn   802:               &Apache::loncommon::check_uncheck_jscript()."\n".
1.6       raeburn   803:               '// ]]>'."\n".
1.12      raeburn   804:               '</script>'."\n");
1.33      raeburn   805:     my $heading = &mt('Settings to display/modify');
                    806:     if (ref($parm_permission) eq 'HASH') {
                    807:         unless ($parm_permission->{'process'}) {
                    808:             $heading = &mt('Settings to display');
                    809:         }
                    810:     }
                    811:     $r->print('<h3>'.$heading.'</h3>'.
1.13      raeburn   812:               '<div><input type="button" value="'.&mt('check all').'" '.
1.1       raeburn   813:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
                    814:               ' />'.('&nbsp;'x2).
                    815:               '<input type="button" value="'.&mt('uncheck all').'" '.
1.12      raeburn   816:               'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
                    817:               "\n".
1.13      raeburn   818:               '</div><div class="LC_left_float">');
1.12      raeburn   819:     my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
1.1       raeburn   820:     if (ref($prefs_order) eq 'ARRAY') {
                    821:         $numitems = @{$prefs_order};
                    822:     }
1.12      raeburn   823:     my $numcols = 3;
                    824:     $maxincol = int($numitems/$numcols);
                    825:     if ($numitems%$numcols) {
                    826:         $maxincol ++;
1.1       raeburn   827:     }
1.14      raeburn   828:     $firstthird = $maxincol;
                    829:     $secondthird = $firstthird + $maxincol;
1.1       raeburn   830:     $count = 0;
                    831:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
                    832:         foreach my $item (@{$prefs_order}) {
                    833:             $r->print('<h4>'.
                    834:                       &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
                    835:                       '<label><input type="checkbox" name="actions" value="'.$item.
                    836:                       '" />&nbsp;'.&mt($prefs->{$item}->{'text'}).'</label></h4>');
                    837:             $count ++;
1.12      raeburn   838:             if ((!$seconddiv) && ($count >= $firstthird)) {
1.1       raeburn   839:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
                    840:                 $seconddiv = 1;
                    841:             }
1.12      raeburn   842:             if ((!$thirddiv) && ($count >= $secondthird)) {
                    843:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
                    844:                 $thirddiv = 1;
1.13      raeburn   845:             }
1.1       raeburn   846:         }
                    847:     }
1.49      raeburn   848:     $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
1.33      raeburn   849:     $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
1.1       raeburn   850:     $r->print('</form>');
1.25      raeburn   851:     if ($container) {
                    852:         &Apache::lonparmset::endSettingsScreen($r);
                    853:     }
1.1       raeburn   854:     $r->print(&Apache::loncommon::end_page());
                    855:     return;
                    856: }
                    857: 
                    858: sub color_pick_js {
                    859:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
                    860:     my $output = <<"ENDCOL";
                    861: 
                    862:     $pjump_def
                    863: 
                    864:     function psub() {
1.21      www       865:         modalWindow.close();
1.1       raeburn   866:         if (document.parmform.pres_marker.value!='') {
                    867:             if (document.parmform.pres_type.value!='') {
                    868:                 eval('document.display.'+
                    869:                      document.parmform.pres_marker.value+
                    870:                      '.value=document.parmform.pres_value.value;');
                    871:             }
                    872:         } else {
                    873:             document.parmform.pres_value.value='';
                    874:             document.parmform.pres_marker.value='';
                    875:         }
                    876:     }
                    877: 
                    878:     function get_id (span_id) {
                    879:         if (document.getElementById) {
                    880:             return document.getElementById(span_id);
                    881:         }
                    882:         if (document.all) {
                    883:             return document.all[span_id];
                    884:         }
                    885:         return false;
                    886:     }
                    887: 
                    888:     function colchg_span (span_id_str,new_color_item) {
                    889:         var span_ref = get_id(span_id_str);
                    890:         if (span_ref.style) { span_ref = span_ref.style; }
                    891:         span_ref.background = new_color_item.value;
                    892:         span_ref.backgroundColor = new_color_item.value;
                    893:         span_ref.bgColor = new_color_item.value;
                    894:     }
                    895: 
                    896: ENDCOL
                    897:     return $output;
                    898: }
                    899: 
1.68      raeburn   900: sub ltisec_javascript {
                    901:     my ($dom) = @_;
                    902:     my %servers = &Apache::lonnet::get_servers($dom,'library');
                    903:     my $primary = &Apache::lonnet::domain($dom,'primary');
                    904:     my $course_servers = "'".join("','",keys(%servers))."'";
                    905:     my $output = <<"ENDJS";
                    906: 
                    907: function toggleLTIEncKey(form,context) {
                    908:     var shownhosts = new Array();
                    909:     var hiddenhosts = new Array();
                    910:     var forcourse = new Array($course_servers);
                    911:     var fromdomain = '$primary';
                    912:     var crsradio;
                    913:     if (context == 'ltisec') {
                    914:         crsradio = form.elements['ltisec_crslinkprot'];
                    915:     } else {
                    916:         crsradio = form.elements['toolsec_crs'];
                    917:     }
                    918:     if (crsradio.length) {
                    919:         for (var i=0; i<crsradio.length; i++) {
                    920:             if (crsradio[i].checked) {
                    921:                 if (crsradio[i].value == 1) {
                    922:                     if (forcourse.length > 0) {
                    923:                         for (var j=0; j<forcourse.length; j++) {
                    924:                             if (!shownhosts.includes(forcourse[j])) {
                    925:                                 shownhosts.push(forcourse[j]);
                    926:                             }
                    927:                         }
                    928:                     }
                    929:                 } else {
                    930:                     if (forcourse.length > 0) {
                    931:                         for (var j=0; j<forcourse.length; j++) {
                    932:                             if (!hiddenhosts.includes(forcourse[j])) {
                    933:                                 hiddenhosts.push(forcourse[j]);
                    934:                             }
                    935:                         }
                    936:                     }
                    937:                 }
                    938:             }
                    939:         }
                    940:     }
                    941:     var domradio;
                    942:     if (context == 'ltisec') {
                    943:         domradio = form.elements['ltisec_domlinkprot'];
                    944:     } else {
                    945:         domradio = form.elements['toolsec_dom'];
                    946:     }
                    947:     if (domradio.length) {
                    948:         for (var i=0; i<domradio.length; i++) {
                    949:             if (domradio[i].checked) {
                    950:                 if (domradio[i].value == 1) {
                    951:                     if (!shownhosts.includes(fromdomain)) {
                    952:                         shownhosts.push(fromdomain);
                    953:                     }
                    954:                 } else {
                    955:                     if (!hiddenhosts.includes(fromdomain)) {
                    956:                         hiddenhosts.push(fromdomain);
                    957:                     }
                    958:                 }
                    959:             }
                    960:         }
                    961:     }
                    962:     if (context == 'ltisec') {
                    963:         var consumersradio = form.elements['ltisec_consumers'];
                    964:         if (consumersradio.length) {
                    965:             for (var i=0; i<consumersradio.length; i++) {
                    966:                 if (consumersradio[i].checked) {
                    967:                     if (consumersradio[i].value == 1) {
                    968:                         if (!shownhosts.includes(fromdomain)) {
                    969:                             shownhosts.push(fromdomain);
                    970:                         }
                    971:                     } else {
                    972:                         if (!hiddenhosts.includes(fromdomain)) {
                    973:                             hiddenhosts.push(fromdomain);
                    974:                         }
                    975:                     }
                    976:                 }
                    977:             }
                    978:         }
                    979:     }
                    980:     if (shownhosts.length > 0) {
                    981:         for (var i=0; i<shownhosts.length; i++) {
                    982:             if (document.getElementById(context+'_info_'+shownhosts[i])) {
                    983:                 document.getElementById(context+'_info_'+shownhosts[i]).style.display = 'block';
                    984:             }
                    985:         }
                    986:         if (document.getElementById(context+'_noprivkey')) {
                    987:             document.getElementById(context+'_noprivkey').style.display = 'none';
                    988:         }
                    989:     } else {
                    990:         if (document.getElementById(context+'_noprivkey')) {
                    991:             document.getElementById(context+'_noprivkey').style.display = 'inline-block';
                    992:         }
                    993:     }
                    994:     if (hiddenhosts.length > 0) {
                    995:         for (var i=0; i<hiddenhosts.length; i++) {
                    996:             if (!shownhosts.includes(hiddenhosts[i])) {
                    997:                 if (document.getElementById(context+'_info_'+hiddenhosts[i])) {
                    998:                     document.getElementById(context+'_info_'+hiddenhosts[i]).style.display = 'none';
                    999:                 }
                   1000:             }
                   1001:         }
                   1002:     }
                   1003:     return;
                   1004: }
                   1005: 
                   1006: function togglePrivKey(form,context,hostid) {
                   1007:     var radioname = '';
                   1008:     var currdivid = '';
                   1009:     var newdivid = '';
                   1010:     if ((document.getElementById(context+'_divcurrprivkey_'+hostid)) &&
                   1011:         (document.getElementById(context+'_divchgprivkey_'+hostid))) {
                   1012:         currdivid = document.getElementById(context+'_divcurrprivkey_'+hostid);
                   1013:         newdivid = document.getElementById(context+'_divchgprivkey_'+hostid);
                   1014:         radioname = form.elements[context+'_changeprivkey_'+hostid];
                   1015:         if (radioname) {
                   1016:             if (radioname.length > 0) {
                   1017:                 var setvis;
                   1018:                 for (var i=0; i<radioname.length; i++) {
                   1019:                     if (radioname[i].checked == true) {
                   1020:                         if (radioname[i].value == 1) {
                   1021:                             newdivid.style.display = 'inline-block';
                   1022:                             currdivid.style.display = 'none';
                   1023:                             setvis = 1;
                   1024:                         }
                   1025:                         break;
                   1026:                     }
                   1027:                 }
                   1028:                 if (!setvis) {
                   1029:                     newdivid.style.display = 'none';
                   1030:                     currdivid.style.display = 'inline-block';
                   1031:                 }
                   1032:             }
                   1033:         }
                   1034:     }
                   1035:     return;
                   1036: }
                   1037: 
                   1038: ENDJS
                   1039: 
                   1040: }
                   1041: 
                   1042: sub ltitools_javascript {
                   1043:     my ($settings) = @_;
                   1044:     my $togglejs = &ltitools_toggle_js();
                   1045:     unless (ref($settings) eq 'HASH') {
                   1046:         return $togglejs;
                   1047:     }
                   1048:     my (%ordered,$total,%jstext);
                   1049:     $total = 0;
                   1050:     foreach my $item (keys(%{$settings})) {
                   1051:         if (ref($settings->{$item}) eq 'HASH') {
                   1052:             my $num = $settings->{$item}{'order'};
                   1053:             $ordered{$num} = $item;
                   1054:         }
                   1055:     }
                   1056:     $total = scalar(keys(%{$settings}));
                   1057:     my @jsarray = ();
                   1058:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   1059:         push(@jsarray,$ordered{$item});
                   1060:     }
                   1061:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   1062:     return <<"ENDSCRIPT";
                   1063: <script type="text/javascript">
                   1064: // <![CDATA[
                   1065: function reorderLTITools(form,item) {
                   1066:     var changedVal;
                   1067: $jstext
                   1068:     var newpos = 'ltitools_add_pos';
                   1069:     var maxh = 1 + $total;
                   1070:     var current = new Array;
                   1071:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   1072:     if (item == newpos) {
                   1073:         changedVal = newitemVal;
                   1074:     } else {
                   1075:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   1076:         current[newitemVal] = newpos;
                   1077:     }
                   1078:     for (var i=0; i<ltitools.length; i++) {
                   1079:         var elementName = 'ltitools_'+ltitools[i];
                   1080:         if (elementName != item) {
                   1081:             if (form.elements[elementName]) {
                   1082:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   1083:                 current[currVal] = elementName;
                   1084:             }
                   1085:         }
                   1086:     }
                   1087:     var oldVal;
                   1088:     for (var j=0; j<maxh; j++) {
                   1089:         if (current[j] == undefined) {
                   1090:             oldVal = j;
                   1091:         }
                   1092:     }
                   1093:     if (oldVal < changedVal) {
                   1094:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   1095:            var elementName = current[k];
                   1096:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   1097:         }
                   1098:     } else {
                   1099:         for (var k=changedVal; k<oldVal; k++) {
                   1100:             var elementName = current[k];
                   1101:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   1102:         }
                   1103:     }
                   1104:     return;
                   1105: }
                   1106: 
                   1107: // ]]>
                   1108: </script>
                   1109: 
                   1110: $togglejs
                   1111: 
                   1112: ENDSCRIPT
                   1113: }
                   1114: 
                   1115: sub ltitools_toggle_js {
                   1116:     return <<"ENDSCRIPT";
                   1117: <script type="text/javascript">
                   1118: // <![CDATA[
                   1119: 
                   1120: function toggleLTITools(form,setting,item) {
                   1121:     var radioname = '';
                   1122:     var divid = '';
1.74    ! raeburn  1123:     if ((setting == 'passback') || (setting == 'roster') || (setting == 'returnurl')) {
1.68      raeburn  1124:         radioname = 'ltitools_'+setting+'_'+item;
1.74    ! raeburn  1125:         if (setting == 'returnurl') {
        !          1126:             divid = 'ltitools_course'+setting+'_'+item;
        !          1127:         } else {
        !          1128:             divid = 'ltitools_'+setting+'time_'+item;
        !          1129:         }
1.68      raeburn  1130:         var num = form.elements[radioname].length;
                   1131:         if (num) {
                   1132:             var setvis = '';
                   1133:             for (var i=0; i<num; i++) {
                   1134:                 if (form.elements[radioname][i].checked) {
                   1135:                     if (form.elements[radioname][i].value == '1') {
                   1136:                         if (document.getElementById(divid)) {
                   1137:                             document.getElementById(divid).style.display = 'inline-block';
                   1138:                         }
                   1139:                         setvis = 1;
                   1140:                     }
                   1141:                     break;
                   1142:                 }
                   1143:             }
                   1144:         }
                   1145:         if (!setvis) {
                   1146:             if (document.getElementById(divid)) {
                   1147:                 document.getElementById(divid).style.display = 'none';
                   1148:             }
                   1149:         }
                   1150:     }
                   1151:     if (setting == 'user') {
                   1152:         divid = 'ltitools_'+setting+'_div_'+item;
                   1153:         var checkid = 'ltitools_'+setting+'_field_'+item;
                   1154:         if (document.getElementById(divid)) {
                   1155:             if (document.getElementById(checkid)) {
                   1156:                 if (document.getElementById(checkid).checked) {
                   1157:                     document.getElementById(divid).style.display = 'inline-block';
                   1158:                 } else {
                   1159:                     document.getElementById(divid).style.display = 'none';
                   1160:                 }
                   1161:             }
                   1162:         }
                   1163:     }
                   1164:     return;
                   1165: }
                   1166: // ]]>
                   1167: </script>
                   1168: 
                   1169: ENDSCRIPT
                   1170: }
                   1171: 
1.1       raeburn  1172: sub get_crumb_text {
                   1173:     my %brcrumbtext = (
                   1174:                        domain => 'Domain Settings',
1.4       raeburn  1175:                        course => 'Display/Edit Settings',
1.1       raeburn  1176:                      );
                   1177:     return %brcrumbtext;
                   1178: }
                   1179: 
1.68      raeburn  1180: sub publishlogo {
                   1181:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,
                   1182:         $savefileas,$modified) = @_;
                   1183:     my ($output,$fname,$logourl,$madethumb);
                   1184:     if ($action eq 'upload') {
                   1185:         $fname=$env{'form.'.$formname.'.filename'};
                   1186:         chop($env{'form.'.$formname});
                   1187:     } else {
                   1188:         ($fname) = ($formname =~ /([^\/]+)$/);
                   1189:     }
                   1190:     if ($savefileas ne '') {
                   1191:         $fname = $savefileas;
                   1192:     }
                   1193:     $fname=&Apache::lonnet::clean_filename($fname);
                   1194: # See if there is anything left
                   1195:     unless ($fname) { return ('error: no uploaded file'); }
                   1196:     $fname="$subdir/$fname";
                   1197:     my $docroot=$r->dir_config('lonDocRoot');
                   1198:     my $filepath="$docroot/priv";
                   1199:     my $relpath = "$dom/$confname";
                   1200:     my ($fnamepath,$file,$fetchthumb);
                   1201:     $file=$fname;
                   1202:     if ($fname=~m|/|) {
                   1203:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   1204:     }
                   1205:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
                   1206:     my $count;
                   1207:     for ($count=5;$count<=$#parts;$count++) {
                   1208:         $filepath.="/$parts[$count]";
                   1209:         if ((-e $filepath)!=1) {
                   1210:             mkdir($filepath,02770);
                   1211:         }
                   1212:     }
                   1213:     # Check for bad extension and disallow upload
                   1214:     if ($file=~/\.(\w+)$/ &&
                   1215:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   1216:         $output =
                   1217:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
                   1218:     } elsif ($file=~/\.(\w+)$/ &&
                   1219:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   1220:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   1221:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
                   1222:         $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   1223:     } elsif (-d "$filepath/$file") {
                   1224:         $output = &mt('Filename is a directory name - rename the file and re-upload');
                   1225:     } else {
                   1226:         my $source = $filepath.'/'.$file;
                   1227:         my $logfile;
                   1228:         if (!open($logfile,">>",$source.'.log')) {
                   1229:             return (&mt('No write permission to Authoring Space'));
                   1230:         }
                   1231:         print $logfile
                   1232: "\n================= Publish ".localtime()." ================\n".
                   1233: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   1234: # Save the file
                   1235:         if (!open(FH,">",$source)) {
                   1236:             &Apache::lonnet::logthis('Failed to create '.$source);
                   1237:             return (&mt('Failed to create file'));
                   1238:         }
                   1239:         if ($action eq 'upload') {
                   1240:             if (!print FH ($env{'form.'.$formname})) {
                   1241:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   1242:                 return (&mt('Failed to write file'));
                   1243:             }
                   1244:         } else {
                   1245:             my $original = &Apache::lonnet::filelocation('',$formname);
                   1246:             if(!copy($original,$source)) {
                   1247:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   1248:                 return (&mt('Failed to write file'));
                   1249:             }
                   1250:         }
                   1251:         close(FH);
                   1252:         chmod(0660, $source); # Permissions to rw-rw---.
                   1253: 
                   1254:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   1255:         my $copyfile=$targetdir.'/'.$file;
                   1256: 
                   1257:         my @parts=split(/\//,$targetdir);
                   1258:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   1259:         for (my $count=5;$count<=$#parts;$count++) {
                   1260:             $path.="/$parts[$count]";
                   1261:             if (!-e $path) {
                   1262:                 print $logfile "\nCreating directory ".$path;
                   1263:                 mkdir($path,02770);
                   1264:             }
                   1265:         }
                   1266:         my $versionresult;
                   1267:         if (-e $copyfile) {
                   1268:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   1269:         } else {
                   1270:             $versionresult = 'ok';
                   1271:         }
                   1272:         if ($versionresult eq 'ok') {
                   1273:             if (copy($source,$copyfile)) {
                   1274:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   1275:                 $output = 'ok';
                   1276:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
                   1277:                 if (ref($modified) eq 'ARRAY') {
                   1278:                     push(@{$modified},[$copyfile,$source]);
                   1279:                 }
                   1280:                 my $metaoutput =
                   1281:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   1282:             } else {
                   1283:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   1284:                 $output = &mt('Failed to copy file to RES space').", $!";
                   1285:             }
                   1286:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   1287:                 my $inputfile = $filepath.'/'.$file;
                   1288:                 my $outfile = $filepath.'/'.'tn-'.$file;
                   1289:                 my ($fullwidth,$fullheight) = &Apache::lonnet::check_dimensions($inputfile);
                   1290:                 if ($fullwidth ne '' && $fullheight ne '') {
                   1291:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   1292:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   1293:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   1294:                         system({$args[0]} @args);
                   1295:                         chmod(0660, $filepath.'/tn-'.$file);
                   1296:                         if (-e $outfile) {
                   1297:                             my $copyfile=$targetdir.'/tn-'.$file;
                   1298:                             if (copy($outfile,$copyfile)) {
                   1299:                                 print $logfile "\nCopied source to ".$copyfile."\n";
                   1300:                                 my $thumb_metaoutput =
                   1301:                                     &write_metadata($dom,$confname,$formname,
                   1302:                                                     $targetdir,'tn-'.$file,$logfile);
                   1303:                                 if (ref($modified) eq 'ARRAY') {
                   1304:                                     push(@{$modified},[$copyfile,$outfile]);
                   1305:                                 }
                   1306:                                 $madethumb = 1;
                   1307:                             } else {
                   1308:                                 print $logfile "\nUnable to write ".$copyfile.
                   1309:                                                ':'.$!."\n";
                   1310:                             }
                   1311:                         }
                   1312:                     }
                   1313:                 }
                   1314:             }
                   1315:         } else {
                   1316:             $output = $versionresult;
                   1317:         }
                   1318:     }
                   1319:     return ($output,$logourl,$madethumb);
                   1320: }
                   1321: 
                   1322: sub logo_versioning {
                   1323:     my ($targetdir,$file,$logfile) = @_;
                   1324:     my $target = $targetdir.'/'.$file;
                   1325:     my ($maxversion,$fn,$extn,$output);
                   1326:     $maxversion = 0;
                   1327:     if ($file =~ /^(.+)\.(\w+)$/) {
                   1328:         $fn=$1;
                   1329:         $extn=$2;
                   1330:     }
                   1331:     opendir(DIR,$targetdir);
                   1332:     while (my $filename=readdir(DIR)) {
                   1333:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   1334:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   1335:         }
                   1336:     }
                   1337:     $maxversion++;
                   1338:     print $logfile "\nCreating old version ".$maxversion."\n";
                   1339:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   1340:     if (copy($target,$copyfile)) {
                   1341:         print $logfile "Copied old target to ".$copyfile."\n";
                   1342:         $copyfile=$copyfile.'.meta';
                   1343:         if (copy($target.'.meta',$copyfile)) {
                   1344:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   1345:             $output = 'ok';
                   1346:         } else {
                   1347:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   1348:             $output = &mt('Failed to copy old meta').", $!, ";
                   1349:         }
                   1350:     } else {
                   1351:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   1352:         $output = &mt('Failed to copy old target').", $!, ";
                   1353:     }
                   1354:     return $output;
                   1355: }
                   1356: 
                   1357: sub write_metadata {
                   1358:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   1359:     my (%metadatafields,%metadatakeys,$output);
                   1360:     $metadatafields{'title'}=$formname;
                   1361:     $metadatafields{'creationdate'}=time;
                   1362:     $metadatafields{'lastrevisiondate'}=time;
                   1363:     $metadatafields{'copyright'}='public';
                   1364:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   1365:                                          $env{'user.domain'};
                   1366:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   1367:     $metadatafields{'domain'}=$dom;
                   1368:     {
                   1369:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   1370:         my $mfh;
                   1371:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
                   1372:             foreach (sort(keys(%metadatafields))) {
                   1373:                 unless ($_=~/\./) {
                   1374:                     my $unikey=$_;
                   1375:                     $unikey=~/^([A-Za-z]+)/;
                   1376:                     my $tag=$1;
                   1377:                     $tag=~tr/A-Z/a-z/;
                   1378:                     print $mfh "\n\<$tag";
                   1379:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   1380:                         my $value=$metadatafields{$unikey.'.'.$_};
                   1381:                         $value=~s/\"/\'\'/g;
                   1382:                         print $mfh ' '.$_.'="'.$value.'"';
                   1383:                     }
                   1384:                     print $mfh '>'.
                   1385:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   1386:                             .'</'.$tag.'>';
                   1387:                 }
                   1388:             }
                   1389:             $output = 'ok';
                   1390:             print $logfile "\nWrote metadata";
                   1391:             close($mfh);
                   1392:         } else {
                   1393:             print $logfile "\nFailed to open metadata file";
                   1394:             $output = &mt('Could not write metadata');
                   1395:         }
                   1396:     }
                   1397:     return $output;
                   1398: }
                   1399: 
                   1400: sub change_secret_js {
                   1401:     return <<"ENDSCRIPT";
                   1402: function toggleChgSecret(form,num,item,name) {
                   1403:     var radioname = '';
                   1404:     var currdivid = '';
                   1405:     var newdivid = '';
                   1406:     if ((document.getElementById(name+'_divcurr'+item+'_'+num)) &&
                   1407:         (document.getElementById(name+'_divchg'+item+'_'+num))) {
                   1408:         currdivid = document.getElementById(name+'_divcurr'+item+'_'+num);
                   1409:         newdivid = document.getElementById(name+'_divchg'+item+'_'+num);
                   1410:         radioname = form.elements[name+'_change'+item+'_'+num];
                   1411:         if (radioname) {
                   1412:             if (radioname.length > 0) {
                   1413:                 var setvis;
                   1414:                 for (var i=0; i<radioname.length; i++) {
                   1415:                     if (radioname[i].checked == true) {
                   1416:                         if (radioname[i].value == 1) {
                   1417:                             newdivid.style.display = 'inline-block';
                   1418:                             currdivid.style.display = 'none';
                   1419:                             setvis = 1;
                   1420:                         }
                   1421:                         break;
                   1422:                     }
                   1423:                 }
                   1424:                 if (!setvis) {
                   1425:                     newdivid.style.display = 'none';
                   1426:                     currdivid.style.display = 'inline-block';
                   1427:                 }
                   1428:             }
                   1429:         }
                   1430:     }
                   1431:     return;
                   1432: }
                   1433: 
                   1434: function uncheckLinkProtMakeVis(name,item,num) {
                   1435:     if (document.getElementById(name+'_'+item+'_'+num)) {
                   1436:         var currtype = document.getElementById(name+'_'+item+'_'+num).type;
                   1437:         if (currtype.toLowerCase() == 'checkbox') {
                   1438:             document.getElementById(name+'_'+item+'_'+num).checked = false;
                   1439:         }
                   1440:     }
                   1441:     return;
                   1442: }
                   1443: ENDSCRIPT
                   1444: 
                   1445: }
                   1446: 
1.1       raeburn  1447: 1;

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