File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.33: download - view: text, annotated - select for diffs
Tue Oct 11 22:58:55 2016 UTC (7 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- vpa priv allows Course Settings to be viewed, but not modified.
- users with vpa priv in a course receive "View parameter settings
  (due dates, etc) for resources and the course" item in the Main Menu,
  and a Settings item in the inline menu.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: lonconfigsettings.pm,v 1.33 2016/10/11 22:58:55 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: 
   42: sub print_header {
   43:     my ($r,$phase,$context,$jscript,$container) = @_;
   44:     my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
   45:         $crstype,@actions,@code_order);
   46:     if ($phase eq 'display') {
   47:         @actions = &Apache::loncommon::get_env_multiple('form.actions');
   48:     }
   49:     if ($context eq 'domain') {
   50:         ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
   51:         $action = '/adm/domainprefs';
   52:         if ($phase eq 'display') {
   53:             if (grep(/^coursecategories$/,@actions)) {
   54:                 $call_category_check = qq|
   55:     if (formname == document.display) {
   56:         if (!categoryCheck(formname)) {
   57:             return;
   58:         }
   59:     }
   60: |;
   61:             }
   62:         }
   63:     } else {
   64:         $crstype = &Apache::loncommon::course_type();
   65:         if ($crstype eq 'Community') {
   66:             ($pagetitle,$brcrumtitle) = ('Community Configuration','Community Configuration');
   67:         } else {
   68:             ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
   69:         }
   70:         $action = '/adm/courseprefs';
   71:         if ($phase eq 'display') {
   72:             if (grep(/^courseinfo$/,@actions)) {
   73:                 my %codedefaults;
   74:                 &Apache::lonnet::auto_instcode_defaults($env{'request.role.domain'},\%codedefaults,
   75:                                                         \@code_order);
   76:                 if (@code_order) {
   77:                    my $noinstcodestr = &mt('You indicated cloning based on category, but did not select any categories.');
   78:                    &js_escape(\$noinstcodestr);
   79:                    $instcode_check = <<"ENDSCRIPT";
   80:     if (formname == document.display) {
   81:         if (formname.cloners_instcode.length) {
   82:             for (var j=0; j<formname.cloners_instcode.length; j++) {
   83:                 if (formname.cloners_instcode[j].checked) {
   84:                     if (formname.cloners_instcode[j].value == 1) {
   85:                         var codes;
   86:                         if (document.getElementsByClassName) {
   87:                             codes = document.getElementsByClassName('LC_cloners_instcodes');
   88:                         } else {
   89:                             codes = getElementsByClassName(document.body,'LC_cloners_instcodes');
   90:                         }
   91:                         if (codes.length) {
   92:                             var gotcode = 0;
   93:                             for (var i=0; i<codes.length; i++) {
   94:                                 if (codes[i].selectedIndex != 0) {
   95:                                      gotcode = 1; 
   96:                                      break;
   97:                                 }
   98:                             }
   99:                             if (!gotcode) {
  100:                                 for (var k=0; k<formname.cloners_instcode.length; k++) {
  101:                                     if (formname.cloners_instcode[k].value == 0) {
  102:                                         formname.cloners_instcode[k].checked = true;
  103:                                     }
  104:                                 }
  105:                                 toggleCloners(document.display.cloners_instcode);
  106:                                 alert('$noinstcodestr');
  107:                                 return false;
  108:                             }
  109:                         }
  110:                     }
  111:                 }
  112:             }
  113:         }
  114:     }
  115: 
  116: ENDSCRIPT
  117:                 }
  118:             }
  119:         }
  120:     }
  121:     my $alert = &mt('You must select at least one functionality type to display.');
  122:     &js_escape(\$alert);
  123:     my $js = '
  124: <script type="text/javascript">
  125: // <![CDATA[
  126: 
  127: function changePage(formname,newphase) {
  128:     formname.phase.value = newphase;
  129:     numchecked = 0;
  130:     if (formname == document.pickactions) {
  131:         if (formname.actions.length > 0) {
  132:             for (var i = 0; i<formname.actions.length; i++) {
  133:                 if (formname.actions[i].checked) {
  134:                     numchecked ++;
  135:                 }
  136:             }
  137:         } else {
  138:             if (formname.actions.checked) {
  139:                 numchecked ++;
  140:             }
  141:         }
  142:         if (numchecked > 0) {
  143:             formname.submit();
  144:         } else {
  145:             alert("'.$alert.'");
  146:             return;
  147:         }
  148:     }
  149:     '.$instcode_check.$call_category_check.'
  150:     formname.submit();
  151: }'."\n";
  152:     if ($phase eq 'pickactions') {
  153: 	$js .= &Apache::lonhtmlcommon::color_picker();
  154:         $js .=
  155:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
  156:     } elsif ($phase eq 'display') {
  157: 	$js .= &Apache::lonhtmlcommon::color_picker();
  158:         $js .= &color_pick_js()."\n";
  159:     }
  160:     $js .= &Apache::loncommon::viewport_size_js().'
  161: 
  162: // ]]>
  163: </script>
  164: ';
  165:     if ($jscript) {
  166:         $js .= "
  167: 
  168: $jscript
  169: 
  170: ";
  171:     }
  172:     my $additem;
  173:     if ($phase eq 'pickactions') {
  174:         my %loaditems = (
  175:                     'onload' => "setFormElements(document.pickactions);",
  176:                         );
  177:         $additem = {'add_entries' => \%loaditems,};
  178:     } elsif ($phase eq 'display') {
  179:         if ($context eq 'domain') {
  180:             if (grep(/^coursedefaults$/,@actions)) {
  181:                 my %loaditems = (
  182:                     '             onload' => "toggleDisplay(document.display,'cloneinstcode');".
  183:                                              "toggleDisplay(document.display,'credits');".
  184:                                              "toggleDisplay(document.display,'studentsubmission');",
  185:                                 );
  186:                 $additem = {'add_entries' => \%loaditems,};
  187:             }
  188:         } elsif ($context eq 'course') {
  189:             if (grep(/^courseinfo$/,@actions)) {
  190:                 if (@code_order) { 
  191:                     $additem = {
  192:                                    add_entries => {'onload' => "courseSet('','load');toggleCloners(document.display.cloners_instcode);"},
  193:                                };
  194:                 }
  195:             }
  196:         }
  197:     }
  198:     $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
  199:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
  200:     $r->print('
  201: <form name="parmform" action="">
  202: <input type="hidden" name="pres_marker" />
  203: <input type="hidden" name="pres_type" />
  204: <input type="hidden" name="pres_value" />
  205: </form>
  206: ');
  207:     if ($container) {
  208:        &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
  209:     }
  210:     $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
  211:               ' enctype="multipart/form-data">');
  212:     return;
  213: }
  214: 
  215: sub print_footer {
  216:     my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
  217:     $button_text = &mt($button_text);
  218:     $r->print('<input type="hidden" name="phase" value="" />');
  219:     if (defined($env{'form.origin'})) {
  220:         $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
  221:     }
  222:     if (($phase eq 'display') || ($phase eq 'process')) {
  223:         if (ref($actions) eq 'ARRAY') {
  224:             foreach my $item (@{$actions}) {
  225:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
  226:             }
  227:         }
  228:     }
  229:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  230:     if ($phase eq 'process') {
  231:         $r->print(
  232:             &Apache::lonhtmlcommon::actionbox(
  233:                 ['<a href='.$dest.'>'.$button_text.'</a>']));
  234:     } else {
  235:         my $onclick;
  236:         if ($phase eq 'display') {
  237:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  238:         } else {
  239:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  240:         }
  241:         my $showbutton = 1;
  242:         if (ref($parm_permission) eq 'HASH') {
  243:             unless (($parm_permission->{'process'}) || ($newphase eq 'display')) {
  244:                 $showbutton = 0;
  245:             }
  246:         }
  247:         if ($showbutton) {
  248:             $r->print('<p><input type="button" name="store" value="'.
  249:                       $button_text.'" onclick='.$onclick.' /></p>');
  250:         } 
  251:     }
  252:     if ($phase eq 'process') {
  253:         $r->print('</form>');
  254:         if ($container) {
  255:            &Apache::lonparmset::endSettingsScreen($r);
  256:         }
  257:         $r->print(&Apache::loncommon::end_page());
  258:     }
  259:     return;
  260: }
  261: 
  262: sub make_changes {
  263:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
  264:         $allitems,$container,$parm_permission) = @_;
  265:     my %brcrumtext = &get_crumb_text();
  266:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  267:     my ($numchanged,%changes,%disallowed);
  268:     &Apache::lonhtmlcommon::add_breadcrumb
  269:       ({href=>"javascript:changePage(document.$phase,'display')",
  270:         text=>$brcrumtext{$context}},
  271:        {href=>"javascript:changePage(document.$phase,'$phase')",
  272:         text=>"Updated"});
  273:     &print_header($r,$phase,$context,undef,$container);
  274:     my ($crstype,%lastact);
  275:     if ($context eq 'course') {
  276:         $crstype = &Apache::loncommon::course_type();
  277:     }
  278:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && 
  279:         (ref($prefs) eq 'HASH')) {
  280:         foreach my $item (@{$prefs_order}) {
  281:             if (grep(/^\Q$item\E$/,@actions)) {
  282:                 if ($context eq 'domain') {
  283:                     $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
  284:                               &Apache::domainprefs::process_changes($r,$dom,
  285:                                           $confname,$item,$roles,$values,\%lastact));
  286:                 } else {
  287:                     $changes{$item} = {};
  288:                     &Apache::courseprefs::process_changes($dom,$item,$values,
  289:                                                           $prefs->{$item},$changes{$item},
  290:                                                           $allitems,\%disallowed,$crstype);
  291:                     if (keys(%{$changes{$item}}) > 0) {
  292:                         $numchanged ++;
  293:                     }
  294:                 }
  295:             }
  296:         }
  297:     }
  298:     if ($context eq 'course') {
  299:         if ($numchanged) {
  300:             my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
  301:                                                           $prefs,$values,\%changes,$crstype);
  302:             $r->print(&Apache::loncommon::confirmwrapper($message));
  303:         } else {
  304:             if ($crstype eq 'Community') {
  305:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
  306:             } else {
  307:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
  308:             }
  309:         }
  310:         if (keys(%disallowed) > 0) {
  311:             $r->print('<p>');
  312:             foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
  313:                 if (ref($disallowed{$item}) eq 'HASH') {
  314:                     if (keys(%{$disallowed{$item}}) > 0) {
  315:                         $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
  316:                                                                            $prefs,$crstype));
  317:                     }
  318:                 }
  319:             }
  320:             $r->print('</p>');
  321:         }
  322:     }
  323:     $r->print('<p>');
  324:     my $footer_text = 'Back to configuration display';
  325:     if ($context eq 'course') {
  326:         $footer_text = 'Back to display/edit settings'; 
  327:     }
  328:     &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
  329:     $r->print('</p>');
  330:     return \%lastact;
  331: }
  332: 
  333: sub display_settings {
  334:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
  335:         $allitems,$crstype,$container,$parm_permission) = @_;
  336:     my %brcrumtext = &get_crumb_text();
  337:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  338:     &Apache::lonhtmlcommon::add_breadcrumb
  339:         ({href=>"javascript:changePage(document.$phase,'display')",
  340:           text=>"Display/Edit Settings"});
  341:     my $instcode;
  342:     if (ref($values) eq 'HASH') {
  343:         $instcode = $values->{'internal.coursecode'};
  344:     }
  345:     &print_header($r,$phase,$context,$jscript,$container,$instcode);
  346:     my $divwidth = 900;
  347:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
  348:         if (@actions > 0) {
  349:             my $rowsum = 0;
  350:             my (%output,%rowtotal,@items,$got_check_uncheck);
  351:             foreach my $item (@{$prefs_order}) {
  352:                 if (grep(/^\Q$item\E$/,@actions)) {
  353:                     push(@items,$item);
  354:                     if ($context eq 'domain') {
  355:                         my $settings;
  356:                         if (ref($values) eq 'HASH') { 
  357:                             $settings = $values->{$item};
  358:                         }
  359:                         if (($item eq 'usersessions') || ($item eq 'ssl')) {
  360:                             unless ($got_check_uncheck) {
  361:                                 $r->print('<script type="text/javascript">'."\n".
  362:                                           '// <![CDATA['."\n".
  363:                                           &Apache::loncommon::check_uncheck_jscript()."\n".
  364:                                           '// ]]>'."\n".
  365:                                           '</script>'."\n");
  366:                                 $got_check_uncheck = 1;
  367:                             }
  368:                         } elsif ($item eq 'selfcreation') {
  369:                             if (ref($values) eq 'HASH') {
  370:                                 $settings = $values->{'usercreation'};
  371:                             }
  372:                         } elsif ($item eq 'defaults') {
  373:                             if (ref($values->{'inststatus'}) eq 'HASH') {
  374:                                 if (ref($values->{'defaults'}) eq 'HASH') {
  375:                                     $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
  376:                                 } else {
  377:                                     $settings = $values->{'inststatus'};
  378:                                 }
  379:                             } else {
  380:                                 my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
  381:                                 my $inststatus = {
  382:                                                    inststatustypes => $usertypes,
  383:                                                    inststatusorder => $types,
  384:                                                    inststatusguest => [], 
  385:                                                  };
  386:                                 if (ref($values->{defaults}) eq 'HASH') {
  387:                                     $settings = {%{$inststatus},%{$values->{'defaults'}}};
  388:                                 } else {
  389:                                     $settings = $inststatus;
  390:                                 }
  391:                             }
  392:                         }
  393:                         ($output{$item},$rowtotal{$item}) =
  394:                             &Apache::domainprefs::print_config_box($r,$dom,$confname,
  395:                                 $phase,$item,$prefs->{$item},$settings);
  396:                     } else {
  397:                         ($output{$item},$rowtotal{$item}) =
  398:                             &Apache::courseprefs::print_config_box($r,$dom,$phase,
  399:                                 $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
  400:                     }
  401:                     $rowsum += $rowtotal{$item};
  402:                 }
  403:             }
  404:             $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
  405:             for (my $i=0; $i<@items; $i++) {
  406:                 $r->print($output{$items[$i]});
  407:             }
  408:             $r->print('</div>');
  409:             $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
  410:         } else {
  411:             $r->print('<input type="hidden" name="phase" value="" />'.
  412:                       '<span class="LC_error">'.&mt('No settings chosen').
  413:                       '</span>');
  414:         }
  415:         $r->print('</form>');
  416:     }
  417:     if ($container) {
  418:         &Apache::lonparmset::endSettingsScreen($r);
  419:     }
  420:     $r->print(&Apache::loncommon::end_page());
  421:     return;
  422: }
  423: 
  424: sub display_choices {
  425:     my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
  426:     if ($phase eq '') {
  427:         $phase = 'pickactions';
  428:     }
  429:     my %helphash;
  430:     &print_header($r,$phase,$context,undef,$container);
  431:     $r->print('<script type="text/javascript">'."\n".
  432:               '// <![CDATA['."\n".
  433:               &Apache::loncommon::check_uncheck_jscript()."\n".
  434:               '// ]]>'."\n".
  435:               '</script>'."\n");
  436:     my $heading = &mt('Settings to display/modify');
  437:     if (ref($parm_permission) eq 'HASH') {
  438:         unless ($parm_permission->{'process'}) {
  439:             $heading = &mt('Settings to display');
  440:         }
  441:     }
  442:     $r->print('<h3>'.$heading.'</h3>'.
  443:               '<div><input type="button" value="'.&mt('check all').'" '.
  444:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
  445:               ' />'.('&nbsp;'x2).
  446:               '<input type="button" value="'.&mt('uncheck all').'" '.
  447:               'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
  448:               "\n".
  449:               '</div><div class="LC_left_float">');
  450:     my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
  451:     if (ref($prefs_order) eq 'ARRAY') {
  452:         $numitems = @{$prefs_order};
  453:     }
  454:     my $numcols = 3;
  455:     $maxincol = int($numitems/$numcols);
  456:     if ($numitems%$numcols) {
  457:         $maxincol ++;
  458:     }
  459:     $firstthird = $maxincol;
  460:     $secondthird = $firstthird + $maxincol;
  461:     $count = 0;
  462:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
  463:         foreach my $item (@{$prefs_order}) {
  464:             $r->print('<h4>'.
  465:                       &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
  466:                       '<label><input type="checkbox" name="actions" value="'.$item.
  467:                       '" />&nbsp;'.&mt($prefs->{$item}->{'text'}).'</label></h4>');
  468:             $count ++;
  469:             if ((!$seconddiv) && ($count >= $firstthird)) {
  470:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  471:                 $seconddiv = 1;
  472:             }
  473:             if ((!$thirddiv) && ($count >= $secondthird)) {
  474:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  475:                 $thirddiv = 1;
  476:             }
  477:         }
  478:         $r->print('</div><br clear="all" />');
  479:     }
  480:     $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
  481:     $r->print('</form>');
  482:     if ($container) {
  483:         &Apache::lonparmset::endSettingsScreen($r);
  484:     }
  485:     $r->print(&Apache::loncommon::end_page());
  486:     return;
  487: }
  488: 
  489: sub color_pick_js {
  490:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  491:     my $output = <<"ENDCOL";
  492: 
  493:     $pjump_def
  494: 
  495:     function psub() {
  496:         modalWindow.close();
  497:         if (document.parmform.pres_marker.value!='') {
  498:             if (document.parmform.pres_type.value!='') {
  499:                 eval('document.display.'+
  500:                      document.parmform.pres_marker.value+
  501:                      '.value=document.parmform.pres_value.value;');
  502:             }
  503:         } else {
  504:             document.parmform.pres_value.value='';
  505:             document.parmform.pres_marker.value='';
  506:         }
  507:     }
  508: 
  509:     function get_id (span_id) {
  510:         if (document.getElementById) {
  511:             return document.getElementById(span_id);
  512:         }
  513:         if (document.all) {
  514:             return document.all[span_id];
  515:         }
  516:         return false;
  517:     }
  518: 
  519:     function colchg_span (span_id_str,new_color_item) {
  520:         var span_ref = get_id(span_id_str);
  521:         if (span_ref.style) { span_ref = span_ref.style; }
  522:         span_ref.background = new_color_item.value;
  523:         span_ref.backgroundColor = new_color_item.value;
  524:         span_ref.bgColor = new_color_item.value;
  525:     }
  526: 
  527: ENDCOL
  528:     return $output;
  529: }
  530: 
  531: sub get_crumb_text {
  532:     my %brcrumbtext = (
  533:                        domain => 'Domain Settings',
  534:                        course => 'Display/Edit Settings',
  535:                      );
  536:     return %brcrumbtext;
  537: }
  538: 
  539: 1;

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