File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.21.4.6: download - view: text, annotated - select for diffs
Wed Apr 23 10:26:37 2014 UTC (10 years ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_0_RC3, version_2_11_0
Diff to branchpoint 1.21: preferred, unified
- For 2.11
  - Backport 1.29.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: lonconfigsettings.pm,v 1.21.4.6 2014/04/23 10:26:37 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: 
   39: sub print_header {
   40:     my ($r,$phase,$context,$jscript,$container) = @_;
   41:     my ($pagetitle,$brcrumtitle,$action,$call_category_check,$crstype);
   42:     if ($context eq 'domain') {
   43:         ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
   44:         $action = '/adm/domainprefs';
   45:         if ($phase eq 'display') {
   46:             my @actions = &Apache::loncommon::get_env_multiple('form.actions');
   47:             if (grep(/^coursecategories$/,@actions)) {
   48:                 $call_category_check = qq|
   49:     if (formname == document.display) {
   50:         if (!categoryCheck(formname)) {
   51:             return;
   52:         }
   53:     }
   54: |;
   55:             }
   56:         }
   57:     } else {
   58:         $crstype = &Apache::loncommon::course_type();
   59:         if ($crstype eq 'Community') {
   60:             ($pagetitle,$brcrumtitle) = ('Community Configuration','Community Configuration');
   61:         } else {
   62:             ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
   63:         }
   64:         $action = '/adm/courseprefs';
   65:     }
   66:     my $alert = &mt('You must select at least one functionality type to display.');
   67:     my $js = '
   68: <script type="text/javascript">
   69: // <![CDATA[
   70: 
   71: function changePage(formname,newphase) {
   72:     formname.phase.value = newphase;
   73:     numchecked = 0;
   74:     if (formname == document.pickactions) {
   75:         if (formname.actions.length > 0) {
   76:             for (var i = 0; i<formname.actions.length; i++) {
   77:                 if (formname.actions[i].checked) {
   78:                     numchecked ++;
   79:                 }
   80:             }
   81:         } else {
   82:             if (formname.actions.checked) {
   83:                 numchecked ++;
   84:             }
   85:         }
   86:         if (numchecked > 0) {
   87:             formname.submit();
   88:         } else {
   89:             alert("'.$alert.'");
   90:             return;
   91:         }
   92:     }
   93:     '.$call_category_check.'
   94:     formname.submit();
   95: }'."\n";
   96:     if ($phase eq 'pickactions') {
   97:         $js .= &Apache::lonhtmlcommon::color_picker();
   98:         $js .=
   99:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
  100:     } elsif ($phase eq 'display') {
  101:         $js .= &Apache::lonhtmlcommon::color_picker();
  102:         $js .= &color_pick_js()."\n";
  103:     }
  104:     $js .= &Apache::loncommon::viewport_size_js().'
  105: 
  106: // ]]>
  107: </script>
  108: ';
  109:     if ($jscript) {
  110:         $js .= "
  111: 
  112: $jscript
  113: 
  114: ";
  115:     }
  116:     my $additem;
  117:     if ($phase eq 'pickactions') {
  118:         my %loaditems = (
  119:                     'onload' => "setFormElements(document.pickactions);",
  120:                         );
  121:         $additem = {'add_entries' => \%loaditems,};
  122:     }
  123:     $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
  124:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
  125:     $r->print('
  126: <form name="parmform" action="">
  127: <input type="hidden" name="pres_marker" />
  128: <input type="hidden" name="pres_type" />
  129: <input type="hidden" name="pres_value" />
  130: </form>
  131: ');
  132:     $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
  133:               ' enctype="multipart/form-data">');
  134:     return;
  135: }
  136: 
  137: sub print_footer {
  138:     my ($r,$phase,$newphase,$button_text,$actions,$container) = @_;
  139:     $button_text = &mt($button_text);
  140:     $r->print('<input type="hidden" name="phase" value="" />');
  141:     if (defined($env{'form.origin'})) {
  142:         $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
  143:     }
  144:     if (($phase eq 'display') || ($phase eq 'process')) {
  145:         if (ref($actions) eq 'ARRAY') {
  146:             foreach my $item (@{$actions}) {
  147:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
  148:             }
  149:         }
  150:     }
  151:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  152:     if ($phase eq 'process') {
  153:         $r->print(
  154:             &Apache::lonhtmlcommon::actionbox(
  155:                 ['<a href='.$dest.'>'.$button_text.'</a>']));
  156:     } else {
  157:         my $onclick;
  158:         if ($phase eq 'display') {
  159:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  160:         } else {
  161:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  162:         }
  163:         $r->print('<p><input type="button" name="store" value="'.
  164:                   $button_text.'" onclick='.$onclick.' /></p>');
  165:     }
  166:     if ($phase eq 'process') {
  167:         $r->print('</form>');
  168:         $r->print(&Apache::loncommon::end_page());
  169:     }
  170:     return;
  171: }
  172: 
  173: sub make_changes {
  174:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,$allitems,$container) = @_;
  175:     my %brcrumtext = &get_crumb_text();
  176:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  177:     my ($numchanged,%changes,%disallowed);
  178:     &Apache::lonhtmlcommon::add_breadcrumb
  179:       ({href=>"javascript:changePage(document.$phase,'display')",
  180:         text=>$brcrumtext{$context}},
  181:        {href=>"javascript:changePage(document.$phase,'$phase')",
  182:         text=>"Updated"});
  183:     &print_header($r,$phase,$context,undef,$container);
  184:     my ($crstype,%lastact);
  185:     if ($context eq 'course') {
  186:         $crstype = &Apache::loncommon::course_type();
  187:     }
  188:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && 
  189:         (ref($prefs) eq 'HASH')) {
  190:         foreach my $item (@{$prefs_order}) {
  191:             if (grep(/^\Q$item\E$/,@actions)) {
  192:                 if ($context eq 'domain') {
  193:                     $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
  194:                               &Apache::domainprefs::process_changes($r,$dom,
  195:                                           $confname,$item,$roles,$values,\%lastact));
  196:                 } else {
  197:                     $changes{$item} = {};
  198:                     &Apache::courseprefs::process_changes($dom,$item,$values,
  199:                                                           $prefs->{$item},$changes{$item},
  200:                                                           $allitems,\%disallowed,$crstype);
  201:                     if (keys(%{$changes{$item}}) > 0) {
  202:                         $numchanged ++;
  203:                     }
  204:                 }
  205:             }
  206:         }
  207:     }
  208:     if ($context eq 'course') {
  209:         if ($numchanged) {
  210:             my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
  211:                                                           $prefs,$values,\%changes,$crstype);
  212:             $r->print(&Apache::loncommon::confirmwrapper($message));
  213:         } else {
  214:             if ($crstype eq 'Community') {
  215:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
  216:             } else {
  217:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
  218:             }
  219:         }
  220:         if (keys(%disallowed) > 0) {
  221:             $r->print('<p>');
  222:             foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
  223:                 if (ref($disallowed{$item}) eq 'HASH') {
  224:                     if (keys(%{$disallowed{$item}}) > 0) {
  225:                         $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
  226:                                                                            $prefs,$crstype));
  227:                     }
  228:                 }
  229:             }
  230:             $r->print('</p>');
  231:         }
  232:     }
  233:     $r->print('<p>');
  234:     my $footer_text = 'Back to configuration display';
  235:     if ($context eq 'course') {
  236:         $footer_text = 'Back to display/edit settings'; 
  237:     }
  238:     &print_footer($r,$phase,'display',$footer_text,\@actions,$container);
  239:     $r->print('</p>');
  240:     return \%lastact;
  241: }
  242: 
  243: sub display_settings {
  244:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
  245:         $allitems,$crstype,$container) = @_;
  246:     my %brcrumtext = &get_crumb_text();
  247:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  248:     &Apache::lonhtmlcommon::add_breadcrumb
  249:         ({href=>"javascript:changePage(document.$phase,'display')",
  250:           text=>"Display/Edit Settings"});
  251:     &print_header($r,$phase,$context,$jscript,$container);
  252:     my $divwidth = 900;
  253:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
  254:         if (@actions > 0) {
  255:             my $rowsum = 0;
  256:             my (%output,%rowtotal,@items);
  257:             foreach my $item (@{$prefs_order}) {
  258:                 if (grep(/^\Q$item\E$/,@actions)) {
  259:                     push(@items,$item);
  260:                     if ($context eq 'domain') {
  261:                         my $settings;
  262:                         if (ref($values) eq 'HASH') {
  263:                             $settings = $values->{$item};
  264:                         }
  265:                         if ($item eq 'usersessions') {
  266:                             $r->print('<script type="text/javascript">'."\n".
  267:                                       '// <![CDATA['."\n".
  268:                                       &Apache::loncommon::check_uncheck_jscript()."\n".
  269:                                       '// ]]>'."\n".
  270:                                       '</script>'."\n");
  271:                         } elsif ($item eq 'selfcreation') {
  272:                             if (ref($values) eq 'HASH') {
  273:                                 $settings = $values->{'usercreation'};
  274:                             }
  275:                         } elsif ($item eq 'defaults') {
  276:                             if (ref($values->{'inststatus'}) eq 'HASH') {
  277:                                 if (ref($values->{'defaults'}) eq 'HASH') {
  278:                                     $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
  279:                                 } else {
  280:                                     $settings = $values->{'inststatus'};
  281:                                 }
  282:                             } else {
  283:                                 my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
  284:                                 my $inststatus = {
  285:                                                    inststatustypes => $usertypes,
  286:                                                    inststatusorder => $types,
  287:                                                    inststatusguest => [],
  288:                                                  };
  289:                                 if (ref($values->{defaults}) eq 'HASH') {
  290:                                     $settings = {%{$inststatus},%{$values->{'defaults'}}};
  291:                                 } else {
  292:                                     $settings = $inststatus;
  293:                                 }
  294:                             }
  295:                         }
  296:                         ($output{$item},$rowtotal{$item}) =
  297:                             &Apache::domainprefs::print_config_box($r,$dom,$confname,
  298:                                 $phase,$item,$prefs->{$item},$settings);
  299:                     } else {
  300:                         ($output{$item},$rowtotal{$item}) =
  301:                             &Apache::courseprefs::print_config_box($r,$dom,$phase,
  302:                                 $item,$prefs->{$item},$values,$allitems,$crstype);
  303:                     }
  304:                     $rowsum += $rowtotal{$item};
  305:                 }
  306:             }
  307:             $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
  308:             for (my $i=0; $i<@items; $i++) {
  309:                 $r->print($output{$items[$i]});
  310:             }
  311:             $r->print('</div>');
  312:             $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container));
  313:         } else {
  314:             $r->print('<input type="hidden" name="phase" value="" />'.
  315:                       '<span class="LC_error">'.&mt('No settings chosen').
  316:                       '</span>');
  317:         }
  318:         $r->print('</form>');
  319:     }
  320:     $r->print(&Apache::loncommon::end_page());
  321:     return;
  322: }
  323: 
  324: sub display_choices {
  325:     my ($r,$phase,$context,$prefs_order,$prefs,$container) = @_;
  326:     if ($phase eq '') {
  327:         $phase = 'pickactions';
  328:     }
  329:     my %helphash;
  330:     &print_header($r,$phase,$context,undef,$container);
  331:     $r->print('<script type="text/javascript">'."\n".
  332:               '// <![CDATA['."\n".
  333:               &Apache::loncommon::check_uncheck_jscript()."\n".
  334:               '// ]]>'."\n".
  335:               '</script>'."\n");
  336:     $r->print('<h3>'.&mt('Settings to display/modify').'</h3>'.
  337:               '<div><input type="button" value="'.&mt('check all').'" '.
  338:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
  339:               ' />'.('&nbsp;'x2).
  340:               '<input type="button" value="'.&mt('uncheck all').'" '.
  341:               'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
  342:               "\n".
  343:               '</div><div class="LC_left_float">');
  344:     my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
  345:     if (ref($prefs_order) eq 'ARRAY') {
  346:         $numitems = @{$prefs_order};
  347:     }
  348:     my $numcols = 3;
  349:     $maxincol = int($numitems/$numcols);
  350:     if ($numitems%$numcols) {
  351:         $maxincol ++;
  352:     }
  353:     $firstthird = $maxincol;
  354:     $secondthird = $firstthird + $maxincol;
  355:     $count = 0;
  356:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
  357:         foreach my $item (@{$prefs_order}) {
  358:             $r->print('<h4>'.
  359:                       &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
  360:                       '<label><input type="checkbox" name="actions" value="'.$item.
  361:                       '" />&nbsp;'.&mt($prefs->{$item}->{'text'}).'</label></h4>');
  362:             $count ++;
  363:             if ((!$seconddiv) && ($count >= $firstthird)) {
  364:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  365:                 $seconddiv = 1;
  366:             }
  367:             if ((!$thirddiv) && ($count >= $secondthird)) {
  368:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  369:                 $thirddiv = 1;
  370:             }
  371:         }
  372:         $r->print('</div><br clear="all" />');
  373:     }
  374:     $r->print(&print_footer($r,$phase,'display','Display',undef,$container));
  375:     $r->print('</form>');
  376:     $r->print(&Apache::loncommon::end_page());
  377:     return;
  378: }
  379: 
  380: sub color_pick_js {
  381:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  382:     my $output = <<"ENDCOL";
  383: 
  384:     $pjump_def
  385: 
  386:     function psub() {
  387:         modalWindow.close();
  388:         if (document.parmform.pres_marker.value!='') {
  389:             if (document.parmform.pres_type.value!='') {
  390:                 eval('document.display.'+
  391:                      document.parmform.pres_marker.value+
  392:                      '.value=document.parmform.pres_value.value;');
  393:             }
  394:         } else {
  395:             document.parmform.pres_value.value='';
  396:             document.parmform.pres_marker.value='';
  397:         }
  398:     }
  399: 
  400:     function get_id (span_id) {
  401:         if (document.getElementById) {
  402:             return document.getElementById(span_id);
  403:         }
  404:         if (document.all) {
  405:             return document.all[span_id];
  406:         }
  407:         return false;
  408:     }
  409: 
  410:     function colchg_span (span_id_str,new_color_item) {
  411:         var span_ref = get_id(span_id_str);
  412:         if (span_ref.style) { span_ref = span_ref.style; }
  413:         span_ref.background = new_color_item.value;
  414:         span_ref.backgroundColor = new_color_item.value;
  415:         span_ref.bgColor = new_color_item.value;
  416:     }
  417: 
  418: ENDCOL
  419:     return $output;
  420: }
  421: 
  422: sub get_crumb_text {
  423:     my %brcrumbtext = (
  424:                        domain => 'Domain Settings',
  425:                        course => 'Display/Edit Settings',
  426:                      );
  427:     return %brcrumbtext;
  428: }
  429: 
  430: 1;

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