File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.15.2.2: download - view: text, annotated - select for diffs
Fri Dec 24 22:50:34 2010 UTC (13 years, 4 months ago) by raeburn
Branches: version_2_10_X
CVS tags: version_2_10_1, version_2_10_0_RC2, version_2_10_0, loncapaMITrelate_1
- Backport 1.16.

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

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