File:
[LON-CAPA] /
loncom /
interface /
lonconfigsettings.pm
Revision
1.36:
download - view:
text,
annotated -
select for diffs
Thu Aug 3 16:22:09 2017 UTC (6 years, 10 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Self-creation of user accounts using e-mail verification.
- Options set by domain coordinator for account requests verified by e-mail
for: processing, restrictions on permitted e-mail addresses, and choice
of username can be set to different values, depending on requester's
(self-reported) institutional status.
- Setting which status types can be self-reported by requesters using
e-mail verification moved from
"Default authentication/language/timezone/portal/types" panel to
"Users self-creating accounts" panel.
- Web form used to request account prompts user for appropriate responses
depending on self-reported status, and e-mail and username constraints.
1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: lonconfigsettings.pm,v 1.36 2017/08/03 16:22:09 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,$instcode,$dom) = @_;
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: my $onload;
181: if (grep(/^coursedefaults$/,@actions)) {
182: $onload = "toggleDisplay(document.display,'cloneinstcode');".
183: "toggleDisplay(document.display,'credits');".
184: "toggleDisplay(document.display,'studentsubmission');";
185: }
186: if (grep(/^selfcreation$/,@actions)) {
187: my $prefix = 'cancreate_emailverified';
188: my $customclass = 'LC_selfcreate_email';
189: my $classprefix = 'LC_canmodify_emailusername_';
190: my $optionsprefix = 'LC_options_emailusername_';
191: $onload .= "toggleRows(document.display,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
192: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
193: my $hascustom;
194: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
195: if (ref($emailrules) eq 'HASH') {
196: if (keys(%{$emailrules}) > 0) {
197: $hascustom = 'cancreate_emailrule';
198: }
199: }
200: my @posstypes;
201: if (ref($types) eq 'ARRAY') {
202: @posstypes = @{$types};
203: push(@posstypes,'default');
204: foreach my $type (@posstypes) {
205: $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
206: "'cancreate_emaildomain','$type');";
207: }
208: } else {
209: $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
210: "'cancreate_emaildomain','default');";
211: }
212: }
213: if ($onload) {
214: my %loaditems = (
215: 'onload' => $onload,
216: );
217: $additem = {'add_entries' => \%loaditems,};
218: }
219: } elsif ($context eq 'course') {
220: if (grep(/^courseinfo$/,@actions)) {
221: if (@code_order) {
222: $additem = {
223: add_entries => {'onload' => "courseSet('','load');toggleCloners(document.display.cloners_instcode);"},
224: };
225: }
226: }
227: }
228: }
229: $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
230: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
231: $r->print('
232: <form name="parmform" action="">
233: <input type="hidden" name="pres_marker" />
234: <input type="hidden" name="pres_type" />
235: <input type="hidden" name="pres_value" />
236: </form>
237: ');
238: if ($container) {
239: &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
240: }
241: $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
242: ' enctype="multipart/form-data">');
243: return;
244: }
245:
246: sub print_footer {
247: my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
248: $button_text = &mt($button_text);
249: $r->print('<input type="hidden" name="phase" value="" />');
250: if (defined($env{'form.origin'})) {
251: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
252: }
253: if (($phase eq 'display') || ($phase eq 'process')) {
254: if (ref($actions) eq 'ARRAY') {
255: foreach my $item (@{$actions}) {
256: $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
257: }
258: }
259: }
260: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
261: if ($phase eq 'process') {
262: $r->print(
263: &Apache::lonhtmlcommon::actionbox(
264: ['<a href='.$dest.'>'.$button_text.'</a>']));
265: } else {
266: my $onclick;
267: if ($phase eq 'display') {
268: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
269: } else {
270: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
271: }
272: my $showbutton = 1;
273: if (ref($parm_permission) eq 'HASH') {
274: unless (($parm_permission->{'process'}) || ($newphase eq 'display')) {
275: $showbutton = 0;
276: }
277: }
278: if ($showbutton) {
279: $r->print('<p><input type="button" name="store" value="'.
280: $button_text.'" onclick='.$onclick.' /></p>');
281: }
282: }
283: if ($phase eq 'process') {
284: $r->print('</form>');
285: if ($container) {
286: &Apache::lonparmset::endSettingsScreen($r);
287: }
288: $r->print(&Apache::loncommon::end_page());
289: }
290: return;
291: }
292:
293: sub make_changes {
294: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
295: $allitems,$container,$parm_permission) = @_;
296: my %brcrumtext = &get_crumb_text();
297: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
298: my ($numchanged,%changes,%disallowed);
299: &Apache::lonhtmlcommon::add_breadcrumb
300: ({href=>"javascript:changePage(document.$phase,'display')",
301: text=>$brcrumtext{$context}},
302: {href=>"javascript:changePage(document.$phase,'$phase')",
303: text=>"Updated"});
304: &print_header($r,$phase,$context,undef,$container);
305: my ($crstype,%lastact);
306: if ($context eq 'course') {
307: $crstype = &Apache::loncommon::course_type();
308: }
309: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') &&
310: (ref($prefs) eq 'HASH')) {
311: foreach my $item (@{$prefs_order}) {
312: if (grep(/^\Q$item\E$/,@actions)) {
313: if ($context eq 'domain') {
314: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
315: &Apache::domainprefs::process_changes($r,$dom,
316: $confname,$item,$roles,$values,\%lastact));
317: } else {
318: $changes{$item} = {};
319: &Apache::courseprefs::process_changes($dom,$item,$values,
320: $prefs->{$item},$changes{$item},
321: $allitems,\%disallowed,$crstype);
322: if (keys(%{$changes{$item}}) > 0) {
323: $numchanged ++;
324: }
325: }
326: }
327: }
328: }
329: if ($context eq 'course') {
330: if ($numchanged) {
331: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
332: $prefs,$values,\%changes,$crstype);
333: $r->print(&Apache::loncommon::confirmwrapper($message));
334: } else {
335: if ($crstype eq 'Community') {
336: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
337: } else {
338: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
339: }
340: }
341: if (keys(%disallowed) > 0) {
342: $r->print('<p>');
343: foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
344: if (ref($disallowed{$item}) eq 'HASH') {
345: if (keys(%{$disallowed{$item}}) > 0) {
346: $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
347: $prefs,$crstype));
348: }
349: }
350: }
351: $r->print('</p>');
352: }
353: }
354: $r->print('<p>');
355: my $footer_text = 'Back to configuration display';
356: if ($context eq 'course') {
357: $footer_text = 'Back to display/edit settings';
358: }
359: &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
360: $r->print('</p>');
361: return \%lastact;
362: }
363:
364: sub display_settings {
365: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
366: $allitems,$crstype,$container,$parm_permission) = @_;
367: my %brcrumtext = &get_crumb_text();
368: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
369: &Apache::lonhtmlcommon::add_breadcrumb
370: ({href=>"javascript:changePage(document.$phase,'display')",
371: text=>"Display/Edit Settings"});
372: my $instcode;
373: if (ref($values) eq 'HASH') {
374: $instcode = $values->{'internal.coursecode'};
375: }
376: &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom);
377: my $divwidth = 900;
378: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
379: if (@actions > 0) {
380: my $rowsum = 0;
381: my (%output,%rowtotal,@items,$got_check_uncheck);
382: foreach my $item (@{$prefs_order}) {
383: if (grep(/^\Q$item\E$/,@actions)) {
384: push(@items,$item);
385: if ($context eq 'domain') {
386: my $settings;
387: if (ref($values) eq 'HASH') {
388: $settings = $values->{$item};
389: }
390: if (($item eq 'usersessions') || ($item eq 'ssl')) {
391: unless ($got_check_uncheck) {
392: $r->print('<script type="text/javascript">'."\n".
393: '// <![CDATA['."\n".
394: &Apache::loncommon::check_uncheck_jscript()."\n".
395: '// ]]>'."\n".
396: '</script>'."\n");
397: $got_check_uncheck = 1;
398: }
399: } elsif ($item eq 'selfcreation') {
400: if (ref($values) eq 'HASH') {
401: $settings = $values->{'usercreation'};
402: }
403: } elsif ($item eq 'defaults') {
404: if (ref($values->{'inststatus'}) eq 'HASH') {
405: if (ref($values->{'defaults'}) eq 'HASH') {
406: $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
407: } else {
408: $settings = $values->{'inststatus'};
409: }
410: } else {
411: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
412: my $inststatus = {
413: inststatustypes => $usertypes,
414: inststatusorder => $types,
415: inststatusguest => [],
416: };
417: if (ref($values->{defaults}) eq 'HASH') {
418: $settings = {%{$inststatus},%{$values->{'defaults'}}};
419: } else {
420: $settings = $inststatus;
421: }
422: }
423: }
424: ($output{$item},$rowtotal{$item}) =
425: &Apache::domainprefs::print_config_box($r,$dom,$confname,
426: $phase,$item,$prefs->{$item},$settings);
427: } else {
428: ($output{$item},$rowtotal{$item}) =
429: &Apache::courseprefs::print_config_box($r,$dom,$phase,
430: $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
431: }
432: $rowsum += $rowtotal{$item};
433: }
434: }
435: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
436: for (my $i=0; $i<@items; $i++) {
437: $r->print($output{$items[$i]});
438: }
439: $r->print('</div>');
440: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
441: } else {
442: $r->print('<input type="hidden" name="phase" value="" />'.
443: '<span class="LC_error">'.&mt('No settings chosen').
444: '</span>');
445: }
446: $r->print('</form>');
447: }
448: if ($container) {
449: &Apache::lonparmset::endSettingsScreen($r);
450: }
451: $r->print(&Apache::loncommon::end_page());
452: return;
453: }
454:
455: sub display_choices {
456: my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
457: if ($phase eq '') {
458: $phase = 'pickactions';
459: }
460: my %helphash;
461: &print_header($r,$phase,$context,undef,$container);
462: $r->print('<script type="text/javascript">'."\n".
463: '// <![CDATA['."\n".
464: &Apache::loncommon::check_uncheck_jscript()."\n".
465: '// ]]>'."\n".
466: '</script>'."\n");
467: my $heading = &mt('Settings to display/modify');
468: if (ref($parm_permission) eq 'HASH') {
469: unless ($parm_permission->{'process'}) {
470: $heading = &mt('Settings to display');
471: }
472: }
473: $r->print('<h3>'.$heading.'</h3>'.
474: '<div><input type="button" value="'.&mt('check all').'" '.
475: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
476: ' />'.(' 'x2).
477: '<input type="button" value="'.&mt('uncheck all').'" '.
478: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
479: "\n".
480: '</div><div class="LC_left_float">');
481: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
482: if (ref($prefs_order) eq 'ARRAY') {
483: $numitems = @{$prefs_order};
484: }
485: my $numcols = 3;
486: $maxincol = int($numitems/$numcols);
487: if ($numitems%$numcols) {
488: $maxincol ++;
489: }
490: $firstthird = $maxincol;
491: $secondthird = $firstthird + $maxincol;
492: $count = 0;
493: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
494: foreach my $item (@{$prefs_order}) {
495: $r->print('<h4>'.
496: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
497: '<label><input type="checkbox" name="actions" value="'.$item.
498: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
499: $count ++;
500: if ((!$seconddiv) && ($count >= $firstthird)) {
501: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
502: $seconddiv = 1;
503: }
504: if ((!$thirddiv) && ($count >= $secondthird)) {
505: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
506: $thirddiv = 1;
507: }
508: }
509: $r->print('</div><br clear="all" />');
510: }
511: $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
512: $r->print('</form>');
513: if ($container) {
514: &Apache::lonparmset::endSettingsScreen($r);
515: }
516: $r->print(&Apache::loncommon::end_page());
517: return;
518: }
519:
520: sub color_pick_js {
521: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
522: my $output = <<"ENDCOL";
523:
524: $pjump_def
525:
526: function psub() {
527: modalWindow.close();
528: if (document.parmform.pres_marker.value!='') {
529: if (document.parmform.pres_type.value!='') {
530: eval('document.display.'+
531: document.parmform.pres_marker.value+
532: '.value=document.parmform.pres_value.value;');
533: }
534: } else {
535: document.parmform.pres_value.value='';
536: document.parmform.pres_marker.value='';
537: }
538: }
539:
540: function get_id (span_id) {
541: if (document.getElementById) {
542: return document.getElementById(span_id);
543: }
544: if (document.all) {
545: return document.all[span_id];
546: }
547: return false;
548: }
549:
550: function colchg_span (span_id_str,new_color_item) {
551: var span_ref = get_id(span_id_str);
552: if (span_ref.style) { span_ref = span_ref.style; }
553: span_ref.background = new_color_item.value;
554: span_ref.backgroundColor = new_color_item.value;
555: span_ref.bgColor = new_color_item.value;
556: }
557:
558: ENDCOL
559: return $output;
560: }
561:
562: sub get_crumb_text {
563: my %brcrumbtext = (
564: domain => 'Domain Settings',
565: course => 'Display/Edit Settings',
566: );
567: return %brcrumbtext;
568: }
569:
570: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>