File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.75: download - view: text, annotated - select for diffs
Sat Jun 14 02:50:25 2025 UTC (2 weeks, 5 days ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Destination URL which differs from launch URL can be specified for an LTI
  Provider which does not support specifying this in another way (e.g., via
  custom parameter in launch payload, or as string appended to launch URL).

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

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