Annotation of loncom/interface/domainprefs.pm, revision 1.4
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.4 ! raeburn 4: # $Id: domainprefs.pm,v 1.3 2007/03/01 18:03:18 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 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::domainprefs;
32:
33: use strict;
34: use Apache::Constants qw(:common :http);
35: use Apache::lonnet;
36: use Apache::loncommon();
37: use Apache::lonhtmlcommon();
38: use Apache::lonlocal;
39: use LONCAPA();
40:
41: sub handler {
42: my $r=shift;
43: if ($r->header_only) {
44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46: return OK;
47: }
48:
49: my $dom = $env{'request.role.domain'};
50: my $domdesc = $Apache::lonnet::domaindescription{$dom};
51: if (&Apache::lonnet::allowed('mau',$dom)) {
52: &Apache::loncommon::content_type($r,'text/html');
53: $r->send_http_header;
54: } else {
55: $env{'user.error.msg'}=
56: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
57: return HTTP_NOT_ACCEPTABLE;
58: }
59: &Apache::lonhtmlcommon::clear_breadcrumbs();
60: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
61: ['phase']);
1.3 raeburn 62: my $phase = "display";
63: if ( exists($env{'form.phase'}) ) {
64: $phase = $env{'form.phase'};
65: }
66: my %domconfig =
67: &Apache::lonnet::get_dom('configuration',['login','quotas',
68: 'autoenroll','autoupdate'],$dom);
69:
70: my @prefs = (
71: { text => 'Log-in page options',
72: help => 'Domain_Log-in_Page',
73: action => 'login',
74: header => [{col1 => 'Item',
75: col2 => 'Selection',}],
76: },
77: { text => 'Default quotas for user portfolios',
78: help => 'Default_User_Quota',
79: action => 'quotas',
80: header => [{col1 => 'User type',
81: col2 => 'Default quota'}],
82: },
83: { text => 'Auto-enrollment settings',
84: help => 'Domain_Auto_Enrollment',
85: action => 'autoenroll',
86: header => [{col1 => 'Configuration setting',
87: col2 => 'Value(s)'}],
88: },
89: { text => 'Auto-update settings',
90: help => 'Domain_Auto_Update',
91: action => 'autoupdate',
92: header => [{col1 => 'Setting',
93: col2 => 'Value',},
94: {col1 => 'User Population',
95: col2 => 'Updataeable user data'}],
96: },
97: );
98: &Apache::lonhtmlcommon::add_breadcrumb
99: ({href=>"javascript:changePage(document.$phase,'display')",
100: text=>"Domain Configuration"});
101: if ($phase eq 'process') {
1.1 raeburn 102: &Apache::lonhtmlcommon::add_breadcrumb
1.3 raeburn 103: ({href=>"javascript:changePage(document.$phase,'$phase')",
104: text=>"Updated"});
105: &print_header($r,$phase);
106: foreach my $item (@prefs) {
107: $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
108: &process_changes($dom,$item->{'action'},%domconfig));
109: }
110: $r->print('<p>');
111: &print_footer($r,$phase,'display','Back to actions menu');
112: $r->print('</p>');
1.1 raeburn 113: } else {
1.3 raeburn 114: if ($phase eq '') {
115: $phase = 'display';
1.1 raeburn 116: }
1.3 raeburn 117: my %helphash;
118: my $numprefs = @prefs;
119: &print_header($r,$phase);
120: $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
121: foreach my $item (@prefs) {
122: if ($item->{'action'} eq 'autoupdate') {
123: $r->print('</td><td width="6%"> </td><td align="left" valign="top" width="47%">');
124: }
125: &print_config_box($r,$dom,$item->{'action'},$item,
126: $domconfig{$item->{'action'}});
127: }
128: $r->print('
129: </table>
130: </td>
131: </tr>
132: </table>
133: </td>
134: </tr>
135: </table>');
136: &print_footer($r,$phase,'process','Store changes');
137: }
138: return OK;
139: }
140:
141: sub process_changes {
142: my ($dom,$action,%domconfig) = @_;
143: my $output;
144: if ($action eq 'login') {
145: $output = &modify_login($dom,%domconfig);
146: } elsif ($action eq 'quotas') {
147: $output = &modify_quotas($dom,%domconfig);
148: } elsif ($action eq 'autoenroll') {
149: $output = &modify_autoenroll($dom,%domconfig);
150: } elsif ($action eq 'autoupdate') {
151: $output = &modify_autoupdate($dom,%domconfig);
152: }
153: return $output;
154: }
155:
156: sub print_config_box {
157: my ($r,$dom,$action,$item,$settings) = @_;
158: $r->print('
159: <table class="LC_nested_outer">
160: <tr>
161: <th>'.&mt($item->{text}).' '.
162: &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
163: </tr>');
164: if ($action eq 'autoupdate') {
165: $r->print('
166: <tr>
167: <td>
168: <table class="LC_nested">
169: <tr class="LC_info_row">
170: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>
171: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
172: </tr>'.
173: &print_autoupdate('top',$dom,$settings).'
174: </table>
175: </td>
176: </tr>
177: <tr>
178: <td>
179: <table class="LC_nested">
180: <tr class="LC_info_row">
181: <td class="LC_left_item">'.$item->{'header'}->[1]->{'col1'}.'</td>
182: <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
183: </tr>'.
184: &print_autoupdate('bottom',$dom,$settings));
185: } else {
186: $r->print('
187: <tr>
188: <td>
189: <table class="LC_nested">
190: <tr class="LC_info_row">
191: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>
192: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
193: </tr>');
194: if ($action eq 'login') {
195: $r->print(&print_login($settings));
196: } elsif ($action eq 'quotas') {
197: $r->print(&print_quotas($dom,$settings));
198: } elsif ($action eq 'autoenroll') {
199: $r->print(&print_autoenroll($dom,$settings));
200: }
201: }
202: $r->print('
203: </table>
204: </td>
205: </tr>
206: </table><br />');
1.1 raeburn 207: return;
208: }
209:
210: sub print_header {
1.3 raeburn 211: my ($r,$phase) = @_;
1.1 raeburn 212: my $js = qq|
213: <script type="text/javascript">
214: function changePage(formname,newphase) {
215: formname.phase.value = newphase;
216: formname.submit();
217: }
218: </script>
219: |;
1.2 albertel 220: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.3 raeburn 221: $js));
222: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
223: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs">');
1.1 raeburn 224: return;
225: }
226:
227: sub print_footer {
1.3 raeburn 228: my ($r,$phase,$newphase,$button_text) = @_;
229: $button_text = &mt($button_text);
230: $r->print('<input type="hidden" name="phase" value="" />');
231: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
232: if ($phase eq 'process') {
233: $r->print('<a href='.$dest.'>'.$button_text.'</a>');
234: } else {
235: $r->print('<input type="button" name="store" value="'.
236: $button_text.'" onclick='.$dest.' />');
237: }
238: $r->print('</form>');
1.1 raeburn 239: $r->print('<br />'.&Apache::loncommon::end_page());
240: return;
241: }
242:
1.3 raeburn 243: sub print_login {
244: my ($settings) = @_;
1.1 raeburn 245: my $catalogon = ' checked="checked" ';
246: my $catalogoff;
247: my $adminmailon = ' ';
248: my $adminmailoff = ' checked="checked" ';
1.3 raeburn 249: if (ref($settings) eq 'HASH') {
250: if ($settings->{'coursecatalog'} eq '0') {
1.1 raeburn 251: $catalogoff = $catalogon;
252: $catalogon = ' ';
253: }
1.3 raeburn 254: if ($settings->{'adminmail'} eq '1') {
1.1 raeburn 255: $adminmailon = $adminmailoff;
256: $adminmailoff = ' ';
257: }
258: }
1.3 raeburn 259: my %choices =
260: &Apache::lonlocal::texthash(
261: coursecatalog => 'Display Course Catalog link?',
262: adminmail => "Display Administrator's E-mail Address?"
263: );
264: my $datatable =
265: '<tr class="LC_odd_row"><td>'.$choices{'coursecatalog'}.
266: '</td><td class="LC_right_item">'.
267: '<nobr><input type="radio" name="coursecatalog"'.
268: $catalogon.' value="1" />'.&mt('Yes').' '.
269: '<input type="radio" name="coursecatalog"'.
270: $catalogoff.'value="0" />'.&mt('No').'</nobr></td>'.
271: '</tr><tr>'.
272: '<td>'.$choices{'adminmail'}.'</td>'.
273: '<td class="LC_right_item"><nobr>'.
274: '<input type="radio" name="adminmail"'.
275: $adminmailon.' value="1" />'.&mt('Yes').' '.
276: '<input type="radio" name="adminmail"'.
277: $adminmailoff.'value="0" />'.&mt('No').'</nobr></td>'.
278: '</tr>';
279: return $datatable;
280: }
281:
282: sub print_quotas {
283: my ($dom,$settings) = @_;
284: my $datatable;
285: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
286: my $othertitle = "All users";
287: my @types;
288: if (ref($order) eq 'ARRAY') {
289: @types = @{$order};
290: }
291: if (@types == 0) {
292: if (ref($usertypes) eq 'HASH') {
293: @types = sort(keys(%{$usertypes}));
294: }
295: }
296: my $typecount = 0;
297: my $css_class;
298: if (@types > 0) {
299: foreach my $type (@types) {
300: if (defined($usertypes->{$type})) {
301: $typecount ++;
302: $css_class = $typecount%2?' class="LC_odd_row"':'';
303: $datatable .= '<tr'.$css_class.'>'.
304: '<td>'.$usertypes->{$type}.'</td>'.
305: '<td class="LC_right_item"><nobr>'.
306: '<input type="text" name="quota_'.$type.
307: '" value="'.$settings->{$type}.
308: '" size="5" /> Mb</nobr></td></tr>';
309: }
310: }
311: $othertitle = "Other users";
312: }
313: my $defaultquota = '20';
314: if (ref($settings) eq 'HASH') {
315: if (defined($settings->{'default'})) {
316: $defaultquota = $settings->{'default'};
317: }
318: }
319: $typecount ++;
320: $css_class = $typecount%2?' class="LC_odd_row"':'';
321: $datatable .= '<tr'.$css_class.'>'.
322: '<td>'.&mt($othertitle).'</td>'.
323: '<td class="LC_right_item"><nobr>'.
324: '<input type="text" name="default" value="'.
325: $defaultquota.'" size="5" /> Mb</nobr></td></tr>';
326: return $datatable;
327: }
328:
329: sub print_autoenroll {
330: my ($dom,$settings) = @_;
331: my $defdom = $dom;
332: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
333: my ($runon,$runoff);
334: if (ref($settings) eq 'HASH') {
335: if (exists($settings->{'run'})) {
336: if ($settings->{'run'} eq '0') {
337: $runoff = ' checked="checked" ';
338: $runon = ' ';
339: } else {
340: $runon = ' checked="checked" ';
341: $runoff = ' ';
342: }
343: } else {
344: if ($autorun) {
345: $runon = ' checked="checked" ';
346: $runoff = ' ';
347: } else {
348: $runoff = ' checked="checked" ';
349: $runon = ' ';
350: }
351: }
352: if (exists($settings->{'sender_domain'})) {
353: $defdom = $settings->{'sender_domain'};
354: }
355: }
356: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
357: my $datatable='<tr class="LC_odd_row">'.
358: '<td>'.&mt('Auto-enrollment active?').'</td>'.
359: '<td class="LC_right_item"><nobr>'.
360: '<input type="radio" name="autoenroll_run"'.
361: $runon.' value="1" />'.&mt('Yes').' '.
362: '<input type="radio" name="autoenroll_run"'.
363: $runoff.'value="0" />'.&mt('No').'</nobr></td>'.
364: '</tr><tr>'.
365: '<td>'.&mt('Notification messages - sender').
366: '</td><td class="LC_right_item"><nobr>'.
367: &mt('username').': '.
368: '<input type="text" name="sender_uname" value="'.
369: $settings->{'sender_uname'}.
370: '" size="10" /> '.&mt('domain').
371: ': '.$domform.'</nobr></td></tr>';
372: return $datatable;
373: }
374:
375: sub print_autoupdate {
376: my ($position,$dom,$settings) = @_;
377: my $datatable;
378: if ($position eq 'top') {
379: my $updateon = ' ';
380: my $updateoff = ' checked="checked" ';
381: my $classlistson = ' ';
382: my $classlistsoff = ' checked="checked" ';
383: if (ref($settings) eq 'HASH') {
384: if ($settings->{'run'} eq '1') {
385: $updateon = $updateoff;
386: $updateoff = ' ';
387: }
388: if ($settings->{'classlists'} eq '1') {
389: $classlistson = $classlistsoff;
390: $classlistsoff = ' ';
391: }
392: }
393: my %title = (
394: run => 'Auto-update active?',
395: classlists => 'Update information in classlists?',
396: );
397: $datatable = '<tr class="LC_odd_row">'.
398: '<td>'.&mt($title{'run'}).'</td>'.
399: '<td class="LC_right_item"><nobr>'.
400: '<input type="radio" name="autoupdate_run"'.
401: $updateon.' value="1" />'.&mt('Yes').' '.
402: '<input type="radio" name="autoupdate_run"'.
403: $updateoff.'value="0" />'.&mt('No').'</nobr></td>'.
404: '</tr><tr>'.
405: '<td>'.&mt($title{'classlists'}).'</td>'.
406: '<td class="LC_right_item"><nobr>'.
407: '<input type="radio" name="classlists"'.
408: $classlistson.' value="1" />'.&mt('Yes').' '.
409: '<input type="radio" name="classlists"'.
410: $classlistsoff.'value="0" />'.&mt('No').'</nobr></td>'.
411: '</tr>';
412: } else {
413: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
414: my @types;
415: if (ref($order) eq 'ARRAY') {
416: @types = @{$order};
417: }
418: if (@types == 0) {
419: if (ref($usertypes) eq 'HASH') {
420: @types = sort(keys(%{$usertypes}));
421: }
422: }
423: my $othertitle = &mt('All users');
424: if (keys(%{$usertypes}) > 0) {
425: $othertitle = &mt('Other users');
426: }
427: my @fields = ('lastname','firstname','middlename','gen','email','id');
428: my %fieldtitles = &Apache::lonlocal::texthash (
429: id => 'Student/Employee ID',
430: email => 'E-mail address',
431: lastname => 'Last Name',
432: firstname => 'First Name',
433: middlename => 'Middle Name',
434: gen => 'Generation',
435: );
436: my $numrows = 0;
437: if (@types > 0) {
438: $datatable =
439: &usertype_update_row($settings,$usertypes,\%fieldtitles,
440: \@fields,\@types,\$numrows);
441: }
442: $datatable .=
443: &usertype_update_row($settings,{'default' => $othertitle},
444: \%fieldtitles,\@fields,['default'],
445: \$numrows);
446: }
447: return $datatable;
448: }
449:
450: sub usertype_update_row {
451: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
452: my $datatable;
453: my $numinrow = 4;
454: foreach my $type (@{$types}) {
455: if (defined($usertypes->{$type})) {
456: $$rownums ++;
457: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
458: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
459: '</td><td class="LC_left_item"><table>';
460: for (my $i=0; $i<@{$fields}; $i++) {
461: my $rem = $i%($numinrow);
462: if ($rem == 0) {
463: if ($i > 0) {
464: $datatable .= '</tr>';
465: }
466: $datatable .= '<tr>';
467: }
468: my $check = ' ';
469: if (ref($settings->{'fields'}) eq 'HASH') {
470: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
471: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
472: $check = ' checked="checked" ';
473: }
474: }
475: }
476:
477: if ($i == @{$fields}-1) {
478: my $colsleft = $numinrow - $rem;
479: if ($colsleft > 1) {
480: $datatable .= '<td colspan="'.$colsleft.'">';
481: } else {
482: $datatable .= '<td>';
483: }
484: } else {
485: $datatable .= '<td>';
486: }
487: $datatable .= '<nobr><input type="checkbox" name="updateable_'.
488: $type.'_'.$fields->[$i].'" '.
489: '" value="1"'.$check.'/>'.
490: $fieldtitles->{$fields->[$i]}.'</nobr></td>';
491: }
492: $datatable .= '</tr></table></td></tr>';
493: }
494: }
495: return $datatable;
1.1 raeburn 496: }
497:
498: sub modify_login {
1.3 raeburn 499: my ($dom,%domconfig) = @_;
1.1 raeburn 500: my ($resulttext,%changes);
501: my %title = ( coursecatalog => 'Display course catalog',
502: adminmail => 'Display administrator E-mail address');
1.3 raeburn 503: my @offon = ('off','on');
1.1 raeburn 504: my %loginhash = (
1.4 ! raeburn 505: login => { coursecatalog => $env{'form.coursecatalog'},
! 506: adminmail => $env{'form.adminmail'},
1.1 raeburn 507: }
508: );
509: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
510: $dom);
511: if ($putresult eq 'ok') {
1.3 raeburn 512: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 513: ($env{'form.coursecatalog'} eq '1')) {
514: $changes{'coursecatalog'} = 1;
1.3 raeburn 515: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
516: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 517: ($env{'form.coursecatalog'} eq '0')) {
518: $changes{'coursecatalog'} = 1;
519: }
1.3 raeburn 520: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 521: ($env{'form.adminmail'} eq '0')) {
522: $changes{'adminmail'} = 1;
523: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
524: $domconfig{'login'}{'adminmail'} eq '0') &&
525: ($env{'form.adminmail'} eq '1')) {
526: $changes{'adminmail'} = 1;
527: }
528: if (keys(%changes) > 0) {
529: $resulttext = &mt('Changes made:').'<ul>';
530: foreach my $item (sort(keys(%changes))) {
531: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
532: }
533: $resulttext .= '</ul>';
534: } else {
535: $resulttext = &mt('No changes made to log-in page settings');
536: }
537: } else {
538: $resulttext = &mt('An error occurred: [_1]',$putresult);
539: }
1.3 raeburn 540: return $resulttext;
1.1 raeburn 541: }
542:
543: sub modify_quotas {
1.3 raeburn 544: my ($dom,%domconfig) = @_;
1.1 raeburn 545: my ($resulttext,%changes);
1.3 raeburn 546: my ($usertypes,$order) =
547: &Apache::lonnet::retrieve_inst_usertypes($dom);
1.1 raeburn 548: my %formhash;
549: foreach my $key (keys(%env)) {
550: if ($key =~ /^form\.quota_(.+)$/) {
551: $formhash{$1} = $env{$key};
552: }
553: }
554: if (ref($domconfig{'quotas'}) eq 'HASH') {
555: foreach my $key (keys(%{$domconfig{'quotas'}})) {
556: if (exists($formhash{$key})) {
557: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
558: $changes{$key} = 1;
559: }
560: } else {
561: $formhash{$key} = $domconfig{'quotas'}{$key};
562: }
563: }
564: }
565: foreach my $key (keys(%formhash)) {
566: if ($formhash{$key} ne '') {
1.3 raeburn 567: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 568: $changes{$key} = 1;
569: }
570: }
571: }
572: my %quotahash = (
1.3 raeburn 573: quotas => {%formhash},
1.1 raeburn 574: );
575: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
576: $dom);
577: if ($putresult eq 'ok') {
578: if (keys(%changes) > 0) {
579: $resulttext = &mt('Changes made:').'<ul>';
580: foreach my $item (sort(keys(%changes))) {
581: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
582: }
583: $resulttext .= '</ul>';
584: } else {
585: $resulttext = &mt('No changes made to default quotas');
586: }
587: } else {
588: $resulttext = &mt('An error occurred: [_1]',$putresult);
589: }
1.3 raeburn 590: return $resulttext;
1.1 raeburn 591: }
592:
1.3 raeburn 593: sub modify_autoenroll {
594: my ($dom,%domconfig) = @_;
1.1 raeburn 595: my ($resulttext,%changes);
596: my %currautoenroll;
597: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
598: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
599: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
600: }
601: }
602: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
603: my %title = ( run => 'Auto-enrollment active',
604: sender => 'Sender for notification messages');
605: my @offon = ('off','on');
606: my %autoenrollhash = (
607: autoenroll => { run => $env{'form.autoenroll_run'},
608: sender_uname => $env{'form.sender_uname'},
609: sender_domain => $env{'form.sender_domain'},
610:
611: }
612: );
1.4 ! raeburn 613: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
! 614: $dom);
1.1 raeburn 615: if ($putresult eq 'ok') {
616: if (exists($currautoenroll{'run'})) {
617: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
618: $changes{'run'} = 1;
619: }
620: } elsif ($autorun) {
621: if ($env{'form.autoenroll_run'} ne '1') {
622: $changes{'run'} = 1;
623: }
624: }
625: if (exists($currautoenroll{sender_uname})) {
626: if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {
627: $changes{'sender'} = 1;
628: }
629: } else {
630: $changes{'sender'} = 1;
631: }
632: if (exists($currautoenroll{sender_domain})) {
633: if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {
634: $changes{'sender'} = 1;
635: }
636: } else {
637: $changes{'sender'} = 1;
638: }
639: if (keys(%changes) > 0) {
640: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 641: if ($changes{'run'}) {
1.1 raeburn 642: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
643: }
644: if ($changes{'sender'}) {
645: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';
646: }
647: $resulttext .= '</ul>';
648: } else {
649: $resulttext = &mt('No changes made to auto-enrollment settings');
650: }
651: } else {
652: $resulttext = &mt('An error occurred: [_1]',$putresult);
653: }
1.3 raeburn 654: return $resulttext;
1.1 raeburn 655: }
656:
657: sub modify_autoupdate {
1.3 raeburn 658: my ($dom,%domconfig) = @_;
1.1 raeburn 659: my ($resulttext,%currautoupdate,%fields,%changes);
660: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
661: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
662: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
663: }
664: }
665: my @offon = ('off','on');
666: my %title = &Apache::lonlocal::texthash (
667: run => 'Auto-update:',
668: classlists => 'Updates to user information in classlists?'
669: );
670: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
671: my %fieldtitles = &Apache::lonlocal::texthash (
672: id => 'Student/Employee ID',
673: email => 'E-mail address',
674: lastname => 'Last Name',
675: firstname => 'First Name',
676: middlename => 'Middle Name',
677: gen => 'Generation',
678: );
679: my $othertitle = &mt('All users');
680: if (keys(%{$usertypes}) > 0) {
681: $othertitle = "Other users";
682: }
683: foreach my $key (keys(%env)) {
684: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
685: push(@{$fields{$1}},$2);
686: }
687: }
688: my %updatehash = (
689: autoupdate => { run => $env{'form.autoupdate_run'},
690: classlists => $env{'form.classlists'},
691: fields => {%fields},
692: }
693: );
694: foreach my $key (keys(%currautoupdate)) {
695: if (($key eq 'run') || ($key eq 'classlists')) {
696: if (exists($updatehash{autoupdate}{$key})) {
697: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
698: $changes{$key} = 1;
699: }
700: }
701: } elsif ($key eq 'fields') {
702: if (ref($currautoupdate{$key}) eq 'HASH') {
703: foreach my $item (keys(%{$currautoupdate{$key}})) {
704: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
705: my $change = 0;
706: foreach my $type (@{$currautoupdate{$key}{$item}}) {
707: if (!exists($fields{$item})) {
708: $change = 1;
709: } elsif (ref($fields{$item}) eq 'ARRAY') {
710: if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
711: $change = 1;
712: }
713: }
714: }
715: if ($change) {
716: push(@{$changes{$key}},$item);
717: }
718: }
719: }
720: }
721: }
722: }
723: foreach my $key (keys(%fields)) {
724: if (ref($currautoupdate{'fields'}) eq 'HASH') {
725: if (!exists($currautoupdate{'fields'}{$key})) {
726: push(@{$changes{'fields'}},$key);
727: }
728: } else {
729: push(@{$changes{'fields'}},$key);
730: }
731: }
732: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
733: $dom);
734: if ($putresult eq 'ok') {
735: if (keys(%changes) > 0) {
736: $resulttext = &mt('Changes made:').'<ul>';
737: foreach my $key (sort(keys(%changes))) {
738: if (ref($changes{$key}) eq 'ARRAY') {
739: foreach my $item (@{$changes{$key}}) {
740: my @newvalues;
741: foreach my $type (@{$fields{$item}}) {
742: push(@newvalues,$fieldtitles{$type});
743: }
1.3 raeburn 744: my $newvaluestr;
745: if (@newvalues > 0) {
746: $newvaluestr = join(', ',@newvalues);
747: } else {
748: $newvaluestr = &mt('none');
749: }
1.1 raeburn 750: if ($item eq 'default') {
751: $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
752: } else {
753: $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
754: }
755: }
756: } else {
757: my $newvalue;
758: if ($key eq 'run') {
759: $newvalue = $offon[$env{'form.autoupdate_run'}];
760: } else {
761: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 762: }
1.1 raeburn 763: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
764: }
765: }
766: $resulttext .= '</ul>';
767: } else {
1.3 raeburn 768: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 769: }
770: } else {
771: $resulttext = &mt('An error occurred: [_1]',$putresult);
772: }
1.3 raeburn 773: return $resulttext;
1.1 raeburn 774: }
775:
1.3 raeburn 776: 1;
1.1 raeburn 777:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>