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

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

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