Annotation of loncom/interface/lonconfigsettings.pm, revision 1.21.4.7
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.21.4.7! raeburn 4: # $Id: lonconfigsettings.pm,v 1.21.4.6 2014/04/23 10:26:37 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
31: package Apache::lonconfigsettings;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon();
37: use Apache::lonlocal;
1.21.4.7! raeburn 38: use Apache::courseclassifier();
! 39: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 40:
41: sub print_header {
1.20 www 42: my ($r,$phase,$context,$jscript,$container) = @_;
1.21.4.7! raeburn 43: my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
! 44: $crstype,@actions,@code_order);
! 45: if ($phase eq 'display') {
! 46: @actions = &Apache::loncommon::get_env_multiple('form.actions');
! 47: }
1.1 raeburn 48: if ($context eq 'domain') {
1.12 raeburn 49: ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
1.1 raeburn 50: $action = '/adm/domainprefs';
1.8 raeburn 51: if ($phase eq 'display') {
52: if (grep(/^coursecategories$/,@actions)) {
53: $call_category_check = qq|
54: if (formname == document.display) {
55: if (!categoryCheck(formname)) {
56: return;
57: }
58: }
59: |;
60: }
61: }
1.1 raeburn 62: } else {
1.21.4.3 raeburn 63: $crstype = &Apache::loncommon::course_type();
64: if ($crstype eq 'Community') {
1.7 raeburn 65: ($pagetitle,$brcrumtitle) = ('Community Configuration','Community Configuration');
66: } else {
67: ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
68: }
1.1 raeburn 69: $action = '/adm/courseprefs';
1.21.4.7! raeburn 70: if ($phase eq 'display') {
! 71: if (grep(/^courseinfo$/,@actions)) {
! 72: my %codedefaults;
! 73: &Apache::lonnet::auto_instcode_defaults($env{'request.role.domain'},\%codedefaults,
! 74: \@code_order);
! 75: if (@code_order) {
! 76: my $noinstcodestr = &mt('You indicated cloning based on category, but did not select any categories.');
! 77: $instcode_check = <<"ENDSCRIPT";
! 78: if (formname == document.display) {
! 79: if (formname.cloners_instcode.length) {
! 80: for (var j=0; j<formname.cloners_instcode.length; j++) {
! 81: if (formname.cloners_instcode[j].checked) {
! 82: if (formname.cloners_instcode[j].value == 1) {
! 83: var codes;
! 84: if (document.getElementsByClassName) {
! 85: codes = document.getElementsByClassName('LC_cloners_instcodes');
! 86: } else {
! 87: codes = getElementsByClassName(document.body,'LC_cloners_instcodes');
! 88: }
! 89: if (codes.length) {
! 90: var gotcode = 0;
! 91: for (var i=0; i<codes.length; i++) {
! 92: if (codes[i].selectedIndex != 0) {
! 93: gotcode = 1;
! 94: break;
! 95: }
! 96: }
! 97: if (!gotcode) {
! 98: for (var k=0; k<formname.cloners_instcode.length; k++) {
! 99: if (formname.cloners_instcode[k].value == 0) {
! 100: formname.cloners_instcode[k].checked = true;
! 101: }
! 102: }
! 103: toggleCloners(document.display.cloners_instcode);
! 104: alert('$noinstcodestr');
! 105: return false;
! 106: }
! 107: }
! 108: }
! 109: }
! 110: }
! 111: }
! 112: }
! 113:
! 114: ENDSCRIPT
! 115: }
! 116: }
! 117: }
1.1 raeburn 118: }
119: my $alert = &mt('You must select at least one functionality type to display.');
120: my $js = '
121: <script type="text/javascript">
1.6 raeburn 122: // <![CDATA[
123:
1.1 raeburn 124: function changePage(formname,newphase) {
125: formname.phase.value = newphase;
126: numchecked = 0;
127: if (formname == document.pickactions) {
128: if (formname.actions.length > 0) {
129: for (var i = 0; i<formname.actions.length; i++) {
130: if (formname.actions[i].checked) {
131: numchecked ++;
132: }
133: }
134: } else {
135: if (formname.actions.checked) {
136: numchecked ++;
137: }
138: }
139: if (numchecked > 0) {
140: formname.submit();
141: } else {
142: alert("'.$alert.'");
143: return;
144: }
145: }
1.21.4.7! raeburn 146: '.$instcode_check.$call_category_check.'
1.1 raeburn 147: formname.submit();
148: }'."\n";
149: if ($phase eq 'pickactions') {
1.21.4.2 raeburn 150: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 151: $js .=
1.12 raeburn 152: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
1.1 raeburn 153: } elsif ($phase eq 'display') {
1.21.4.2 raeburn 154: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 155: $js .= &color_pick_js()."\n";
156: }
157: $js .= &Apache::loncommon::viewport_size_js().'
1.6 raeburn 158:
159: // ]]>
1.1 raeburn 160: </script>
161: ';
1.2 raeburn 162: if ($jscript) {
163: $js .= "
164:
165: $jscript
166:
167: ";
168: }
1.1 raeburn 169: my $additem;
170: if ($phase eq 'pickactions') {
171: my %loaditems = (
1.12 raeburn 172: 'onload' => "setFormElements(document.pickactions);",
1.1 raeburn 173: );
174: $additem = {'add_entries' => \%loaditems,};
1.21.4.7! raeburn 175: } elsif ($phase eq 'display') {
! 176: if ($context eq 'domain') {
! 177: if (grep(/^coursedefaults$/,@actions)) {
! 178: my %loaditems = (
! 179: ' onload' => "toggleDisplay(document.display,'cloneinstcode');".
! 180: "toggleDisplay(document.display,'credits');".
! 181: "toggleDisplay(document.display,'studentsubmission');",
! 182: );
! 183: $additem = {'add_entries' => \%loaditems,};
! 184: }
! 185: } elsif ($context eq 'course') {
! 186: if (grep(/^courseinfo$/,@actions)) {
! 187: if (@code_order) {
! 188: $additem = {
! 189: add_entries => {'onload' => "courseSet('','load');toggleCloners(document.display.cloners_instcode);"},
! 190: };
! 191: }
! 192: }
! 193: }
1.1 raeburn 194: }
195: $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
196: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
197: $r->print('
198: <form name="parmform" action="">
199: <input type="hidden" name="pres_marker" />
200: <input type="hidden" name="pres_type" />
201: <input type="hidden" name="pres_value" />
202: </form>
203: ');
204: $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
205: ' enctype="multipart/form-data">');
206: return;
207: }
208:
209: sub print_footer {
1.20 www 210: my ($r,$phase,$newphase,$button_text,$actions,$container) = @_;
1.1 raeburn 211: $button_text = &mt($button_text);
1.12 raeburn 212: $r->print('<input type="hidden" name="phase" value="" />');
1.5 raeburn 213: if (defined($env{'form.origin'})) {
214: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
215: }
1.1 raeburn 216: if (($phase eq 'display') || ($phase eq 'process')) {
217: if (ref($actions) eq 'ARRAY') {
218: foreach my $item (@{$actions}) {
1.16 raeburn 219: $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
1.1 raeburn 220: }
221: }
222: }
223: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
224: if ($phase eq 'process') {
1.21.4.2 raeburn 225: $r->print(
226: &Apache::lonhtmlcommon::actionbox(
227: ['<a href='.$dest.'>'.$button_text.'</a>']));
1.1 raeburn 228: } else {
229: my $onclick;
230: if ($phase eq 'display') {
231: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
232: } else {
233: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
234: }
235: $r->print('<p><input type="button" name="store" value="'.
236: $button_text.'" onclick='.$onclick.' /></p>');
237: }
238: if ($phase eq 'process') {
1.20 www 239: $r->print('</form>');
240: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 241: }
242: return;
243: }
244:
245: sub make_changes {
1.20 www 246: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,$allitems,$container) = @_;
1.1 raeburn 247: my %brcrumtext = &get_crumb_text();
248: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.4 raeburn 249: my ($numchanged,%changes,%disallowed);
1.1 raeburn 250: &Apache::lonhtmlcommon::add_breadcrumb
251: ({href=>"javascript:changePage(document.$phase,'display')",
252: text=>$brcrumtext{$context}},
253: {href=>"javascript:changePage(document.$phase,'$phase')",
254: text=>"Updated"});
1.20 www 255: &print_header($r,$phase,$context,undef,$container);
1.21.4.4 raeburn 256: my ($crstype,%lastact);
1.7 raeburn 257: if ($context eq 'course') {
258: $crstype = &Apache::loncommon::course_type();
259: }
1.1 raeburn 260: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') &&
261: (ref($prefs) eq 'HASH')) {
262: foreach my $item (@{$prefs_order}) {
263: if (grep(/^\Q$item\E$/,@actions)) {
264: if ($context eq 'domain') {
1.4 raeburn 265: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
266: &Apache::domainprefs::process_changes($r,$dom,
1.21.4.4 raeburn 267: $confname,$item,$roles,$values,\%lastact));
1.1 raeburn 268: } else {
1.4 raeburn 269: $changes{$item} = {};
270: &Apache::courseprefs::process_changes($dom,$item,$values,
271: $prefs->{$item},$changes{$item},
1.7 raeburn 272: $allitems,\%disallowed,$crstype);
1.4 raeburn 273: if (keys(%{$changes{$item}}) > 0) {
274: $numchanged ++;
275: }
1.1 raeburn 276: }
277: }
278: }
279: }
1.4 raeburn 280: if ($context eq 'course') {
281: if ($numchanged) {
1.11 wenzelju 282: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
283: $prefs,$values,\%changes,$crstype);
284: $r->print(&Apache::loncommon::confirmwrapper($message));
1.4 raeburn 285: } else {
1.7 raeburn 286: if ($crstype eq 'Community') {
1.11 wenzelju 287: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
1.7 raeburn 288: } else {
1.11 wenzelju 289: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
1.7 raeburn 290: }
1.4 raeburn 291: }
292: if (keys(%disallowed) > 0) {
293: $r->print('<p>');
294: foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
295: if (ref($disallowed{$item}) eq 'HASH') {
296: if (keys(%{$disallowed{$item}}) > 0) {
297: $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
1.7 raeburn 298: $prefs,$crstype));
1.4 raeburn 299: }
300: }
301: }
302: $r->print('</p>');
303: }
304: }
1.1 raeburn 305: $r->print('<p>');
1.4 raeburn 306: my $footer_text = 'Back to configuration display';
307: if ($context eq 'course') {
308: $footer_text = 'Back to display/edit settings';
309: }
1.20 www 310: &print_footer($r,$phase,'display',$footer_text,\@actions,$container);
1.1 raeburn 311: $r->print('</p>');
1.21.4.4 raeburn 312: return \%lastact;
1.1 raeburn 313: }
314:
315: sub display_settings {
1.3 raeburn 316: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.20 www 317: $allitems,$crstype,$container) = @_;
1.1 raeburn 318: my %brcrumtext = &get_crumb_text();
319: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
320: &Apache::lonhtmlcommon::add_breadcrumb
321: ({href=>"javascript:changePage(document.$phase,'display')",
1.4 raeburn 322: text=>"Display/Edit Settings"});
1.21.4.7! raeburn 323: my $instcode;
! 324: if (ref($values) eq 'HASH') {
! 325: $instcode = $values->{'internal.coursecode'};
! 326: }
! 327: &print_header($r,$phase,$context,$jscript,$container,$instcode);
1.12 raeburn 328: my $divwidth = 900;
1.1 raeburn 329: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
330: if (@actions > 0) {
331: my $rowsum = 0;
332: my (%output,%rowtotal,@items);
333: foreach my $item (@{$prefs_order}) {
334: if (grep(/^\Q$item\E$/,@actions)) {
335: push(@items,$item);
336: if ($context eq 'domain') {
1.21.4.6 raeburn 337: my $settings;
338: if (ref($values) eq 'HASH') {
339: $settings = $values->{$item};
340: }
1.15 raeburn 341: if ($item eq 'usersessions') {
342: $r->print('<script type="text/javascript">'."\n".
343: '// <![CDATA['."\n".
344: &Apache::loncommon::check_uncheck_jscript()."\n".
345: '// ]]>'."\n".
346: '</script>'."\n");
1.21.4.5 raeburn 347: } elsif ($item eq 'selfcreation') {
1.21.4.6 raeburn 348: if (ref($values) eq 'HASH') {
349: $settings = $values->{'usercreation'};
350: }
351: } elsif ($item eq 'defaults') {
352: if (ref($values->{'inststatus'}) eq 'HASH') {
353: if (ref($values->{'defaults'}) eq 'HASH') {
354: $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
355: } else {
356: $settings = $values->{'inststatus'};
357: }
358: } else {
359: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
360: my $inststatus = {
361: inststatustypes => $usertypes,
362: inststatusorder => $types,
363: inststatusguest => [],
364: };
365: if (ref($values->{defaults}) eq 'HASH') {
366: $settings = {%{$inststatus},%{$values->{'defaults'}}};
367: } else {
368: $settings = $inststatus;
369: }
370: }
1.15 raeburn 371: }
1.1 raeburn 372: ($output{$item},$rowtotal{$item}) =
373: &Apache::domainprefs::print_config_box($r,$dom,$confname,
1.21.4.5 raeburn 374: $phase,$item,$prefs->{$item},$settings);
1.1 raeburn 375: } else {
376: ($output{$item},$rowtotal{$item}) =
377: &Apache::courseprefs::print_config_box($r,$dom,$phase,
1.7 raeburn 378: $item,$prefs->{$item},$values,$allitems,$crstype);
1.1 raeburn 379: }
380: $rowsum += $rowtotal{$item};
381: }
382: }
1.12 raeburn 383: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
1.1 raeburn 384: for (my $i=0; $i<@items; $i++) {
385: $r->print($output{$items[$i]});
386: }
1.12 raeburn 387: $r->print('</div>');
1.20 www 388: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container));
1.1 raeburn 389: } else {
390: $r->print('<input type="hidden" name="phase" value="" />'.
1.12 raeburn 391: '<span class="LC_error">'.&mt('No settings chosen').
392: '</span>');
1.1 raeburn 393: }
394: $r->print('</form>');
395: }
396: $r->print(&Apache::loncommon::end_page());
397: return;
398: }
399:
400: sub display_choices {
1.20 www 401: my ($r,$phase,$context,$prefs_order,$prefs,$container) = @_;
1.1 raeburn 402: if ($phase eq '') {
403: $phase = 'pickactions';
404: }
405: my %helphash;
1.20 www 406: &print_header($r,$phase,$context,undef,$container);
1.1 raeburn 407: $r->print('<script type="text/javascript">'."\n".
1.6 raeburn 408: '// <![CDATA['."\n".
1.1 raeburn 409: &Apache::loncommon::check_uncheck_jscript()."\n".
1.6 raeburn 410: '// ]]>'."\n".
1.12 raeburn 411: '</script>'."\n");
412: $r->print('<h3>'.&mt('Settings to display/modify').'</h3>'.
1.13 raeburn 413: '<div><input type="button" value="'.&mt('check all').'" '.
1.1 raeburn 414: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
415: ' />'.(' 'x2).
416: '<input type="button" value="'.&mt('uncheck all').'" '.
1.12 raeburn 417: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
418: "\n".
1.13 raeburn 419: '</div><div class="LC_left_float">');
1.12 raeburn 420: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
1.1 raeburn 421: if (ref($prefs_order) eq 'ARRAY') {
422: $numitems = @{$prefs_order};
423: }
1.12 raeburn 424: my $numcols = 3;
425: $maxincol = int($numitems/$numcols);
426: if ($numitems%$numcols) {
427: $maxincol ++;
1.1 raeburn 428: }
1.14 raeburn 429: $firstthird = $maxincol;
430: $secondthird = $firstthird + $maxincol;
1.1 raeburn 431: $count = 0;
432: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
433: foreach my $item (@{$prefs_order}) {
434: $r->print('<h4>'.
435: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
436: '<label><input type="checkbox" name="actions" value="'.$item.
437: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
438: $count ++;
1.12 raeburn 439: if ((!$seconddiv) && ($count >= $firstthird)) {
1.1 raeburn 440: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
441: $seconddiv = 1;
442: }
1.12 raeburn 443: if ((!$thirddiv) && ($count >= $secondthird)) {
444: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
445: $thirddiv = 1;
1.13 raeburn 446: }
1.1 raeburn 447: }
1.12 raeburn 448: $r->print('</div><br clear="all" />');
1.1 raeburn 449: }
1.20 www 450: $r->print(&print_footer($r,$phase,'display','Display',undef,$container));
1.1 raeburn 451: $r->print('</form>');
452: $r->print(&Apache::loncommon::end_page());
453: return;
454: }
455:
456: sub color_pick_js {
457: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
458: my $output = <<"ENDCOL";
459:
460: $pjump_def
461:
462: function psub() {
1.21 www 463: modalWindow.close();
1.1 raeburn 464: if (document.parmform.pres_marker.value!='') {
465: if (document.parmform.pres_type.value!='') {
466: eval('document.display.'+
467: document.parmform.pres_marker.value+
468: '.value=document.parmform.pres_value.value;');
469: }
470: } else {
471: document.parmform.pres_value.value='';
472: document.parmform.pres_marker.value='';
473: }
474: }
475:
476: function get_id (span_id) {
477: if (document.getElementById) {
478: return document.getElementById(span_id);
479: }
480: if (document.all) {
481: return document.all[span_id];
482: }
483: return false;
484: }
485:
486: function colchg_span (span_id_str,new_color_item) {
487: var span_ref = get_id(span_id_str);
488: if (span_ref.style) { span_ref = span_ref.style; }
489: span_ref.background = new_color_item.value;
490: span_ref.backgroundColor = new_color_item.value;
491: span_ref.bgColor = new_color_item.value;
492: }
493:
494: ENDCOL
495: return $output;
496: }
497:
498: sub get_crumb_text {
499: my %brcrumbtext = (
500: domain => 'Domain Settings',
1.4 raeburn 501: course => 'Display/Edit Settings',
1.1 raeburn 502: );
503: return %brcrumbtext;
504: }
505:
506: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>