Annotation of loncom/interface/domainprefs.pm, revision 1.8
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.8 ! raeburn 4: # $Id: domainprefs.pm,v 1.7 2007/04/04 00:10:01 albertel 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();
1.6 raeburn 40: use LONCAPA::Enrollment;
1.1 raeburn 41:
42: sub handler {
43: my $r=shift;
44: if ($r->header_only) {
45: &Apache::loncommon::content_type($r,'text/html');
46: $r->send_http_header;
47: return OK;
48: }
49:
50: my $dom = $env{'request.role.domain'};
1.5 albertel 51: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 52: if (&Apache::lonnet::allowed('mau',$dom)) {
53: &Apache::loncommon::content_type($r,'text/html');
54: $r->send_http_header;
55: } else {
56: $env{'user.error.msg'}=
57: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
58: return HTTP_NOT_ACCEPTABLE;
59: }
60: &Apache::lonhtmlcommon::clear_breadcrumbs();
61: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
62: ['phase']);
1.3 raeburn 63: my $phase = "display";
64: if ( exists($env{'form.phase'}) ) {
65: $phase = $env{'form.phase'};
66: }
67: my %domconfig =
1.6 raeburn 68: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
69: 'quotas','autoenroll','autoupdate'],$dom);
1.3 raeburn 70: my @prefs = (
1.6 raeburn 71: { text => 'Default color schemes',
72: help => 'Default_Color_Schemes',
73: action => 'rolecolors',
74: header => [{col1 => 'Student Settings',
75: col2 => '',},
76: {col1 => 'Coordinator Settings',
77: col2 => '',},
78: {col1 => 'Author Settings',
79: col2 => '',},
80: {col1 => 'Administrator Settings',
81: col2 => '',}],
82: },
1.3 raeburn 83: { text => 'Log-in page options',
84: help => 'Domain_Log-in_Page',
85: action => 'login',
86: header => [{col1 => 'Item',
1.6 raeburn 87: col2 => '',}],
1.3 raeburn 88: },
89: { text => 'Default quotas for user portfolios',
90: help => 'Default_User_Quota',
91: action => 'quotas',
92: header => [{col1 => 'User type',
93: col2 => 'Default quota'}],
94: },
95: { text => 'Auto-enrollment settings',
96: help => 'Domain_Auto_Enrollment',
97: action => 'autoenroll',
98: header => [{col1 => 'Configuration setting',
99: col2 => 'Value(s)'}],
100: },
101: { text => 'Auto-update settings',
102: help => 'Domain_Auto_Update',
103: action => 'autoupdate',
104: header => [{col1 => 'Setting',
105: col2 => 'Value',},
106: {col1 => 'User Population',
107: col2 => 'Updataeable user data'}],
108: },
109: );
1.6 raeburn 110: my @roles = ('student','coordinator','author','admin');
1.3 raeburn 111: &Apache::lonhtmlcommon::add_breadcrumb
112: ({href=>"javascript:changePage(document.$phase,'display')",
113: text=>"Domain Configuration"});
114: if ($phase eq 'process') {
1.1 raeburn 115: &Apache::lonhtmlcommon::add_breadcrumb
1.3 raeburn 116: ({href=>"javascript:changePage(document.$phase,'$phase')",
117: text=>"Updated"});
118: &print_header($r,$phase);
119: foreach my $item (@prefs) {
120: $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
1.6 raeburn 121: &process_changes($r,$dom,$item->{'action'},\@roles,%domconfig));
1.3 raeburn 122: }
123: $r->print('<p>');
124: &print_footer($r,$phase,'display','Back to actions menu');
125: $r->print('</p>');
1.1 raeburn 126: } else {
1.3 raeburn 127: if ($phase eq '') {
128: $phase = 'display';
1.1 raeburn 129: }
1.3 raeburn 130: my %helphash;
131: my $numprefs = @prefs;
132: &print_header($r,$phase);
133: $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
134: foreach my $item (@prefs) {
1.6 raeburn 135: if ($item->{'action'} eq 'login') {
1.3 raeburn 136: $r->print('</td><td width="6%"> </td><td align="left" valign="top" width="47%">');
137: }
1.6 raeburn 138: &print_config_box($r,$dom,$phase,$item->{'action'},
139: $item,$domconfig{$item->{'action'}});
1.3 raeburn 140: }
141: $r->print('
142: </td>
143: </tr>
144: </table>');
145: &print_footer($r,$phase,'process','Store changes');
146: }
147: return OK;
148: }
149:
150: sub process_changes {
1.6 raeburn 151: my ($r,$dom,$action,$roles,%domconfig) = @_;
1.3 raeburn 152: my $output;
153: if ($action eq 'login') {
1.6 raeburn 154: $output = &modify_login($r,$dom,%domconfig);
155: } elsif ($action eq 'rolecolors') {
156: $output = &modify_rolecolors($r,$dom,$roles,%domconfig);
1.3 raeburn 157: } elsif ($action eq 'quotas') {
158: $output = &modify_quotas($dom,%domconfig);
159: } elsif ($action eq 'autoenroll') {
160: $output = &modify_autoenroll($dom,%domconfig);
161: } elsif ($action eq 'autoupdate') {
162: $output = &modify_autoupdate($dom,%domconfig);
163: }
164: return $output;
165: }
166:
167: sub print_config_box {
1.6 raeburn 168: my ($r,$dom,$phase,$action,$item,$settings) = @_;
1.3 raeburn 169: $r->print('
170: <table class="LC_nested_outer">
171: <tr>
172: <th>'.&mt($item->{text}).' '.
173: &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
174: </tr>');
1.6 raeburn 175: if (($action eq 'autoupdate') || ($action eq 'rolecolors')) {
176: my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
1.3 raeburn 177: $r->print('
178: <tr>
179: <td>
180: <table class="LC_nested">
181: <tr class="LC_info_row">
1.6 raeburn 182: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
1.3 raeburn 183: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.6 raeburn 184: </tr>');
185: if ($action eq 'autoupdate') {
186: $r->print(&print_autoupdate('top',$dom,$settings));
187: } else {
188: $r->print(&print_rolecolors($phase,'student',$dom,$settings));
189: }
190: $r->print('
191: </table>
192: </td>
193: </tr>
194: <tr>
195: <td>
196: <table class="LC_nested">
197: <tr class="LC_info_row">
198: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
199: <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
200: </tr>');
201: if ($action eq 'autoupdate') {
202: $r->print(&print_autoupdate('bottom',$dom,$settings));
203: } else {
204: $r->print(&print_rolecolors($phase,'coordinator',$dom,$settings).'
205: </table>
206: </td>
207: </tr>
208: <tr>
209: <td>
210: <table class="LC_nested">
211: <tr class="LC_info_row">
212: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
213: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
1.3 raeburn 214: </tr>'.
1.6 raeburn 215: &print_rolecolors($phase,'author',$dom,$settings).'
1.3 raeburn 216: </table>
217: </td>
218: </tr>
219: <tr>
220: <td>
221: <table class="LC_nested">
222: <tr class="LC_info_row">
1.6 raeburn 223: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
224: <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
1.3 raeburn 225: </tr>'.
1.6 raeburn 226: &print_rolecolors($phase,'admin',$dom,$settings));
227: }
1.3 raeburn 228: } else {
229: $r->print('
230: <tr>
231: <td>
232: <table class="LC_nested">
1.6 raeburn 233: <tr class="LC_info_row">');
234: if ($action eq 'login') {
235: $r->print('
236: <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>');
237: } else {
238: $r->print('
239: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>');
240: }
241: $r->print('
1.3 raeburn 242: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
243: </tr>');
244: if ($action eq 'login') {
1.6 raeburn 245: $r->print(&print_login($dom,$phase,$settings));
1.3 raeburn 246: } elsif ($action eq 'quotas') {
247: $r->print(&print_quotas($dom,$settings));
248: } elsif ($action eq 'autoenroll') {
249: $r->print(&print_autoenroll($dom,$settings));
250: }
251: }
252: $r->print('
253: </table>
254: </td>
255: </tr>
256: </table><br />');
1.1 raeburn 257: return;
258: }
259:
260: sub print_header {
1.3 raeburn 261: my ($r,$phase) = @_;
1.6 raeburn 262: my $js = '
1.1 raeburn 263: <script type="text/javascript">
264: function changePage(formname,newphase) {
265: formname.phase.value = newphase;
266: formname.submit();
267: }
1.6 raeburn 268: '.
269: &color_pick_js().'
1.1 raeburn 270: </script>
1.6 raeburn 271: ';
1.2 albertel 272: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.3 raeburn 273: $js));
274: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6 raeburn 275: $r->print('
1.8 ! raeburn 276: <form name="parmform" action="">
1.6 raeburn 277: <input type="hidden" name="pres_marker" />
278: <input type="hidden" name="pres_type" />
279: <input type="hidden" name="pres_value" />
280: </form>
281: ');
282: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
283: ' enctype="multipart/form-data">');
1.1 raeburn 284: return;
285: }
286:
287: sub print_footer {
1.3 raeburn 288: my ($r,$phase,$newphase,$button_text) = @_;
289: $button_text = &mt($button_text);
290: $r->print('<input type="hidden" name="phase" value="" />');
291: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
292: if ($phase eq 'process') {
293: $r->print('<a href='.$dest.'>'.$button_text.'</a>');
294: } else {
295: $r->print('<input type="button" name="store" value="'.
296: $button_text.'" onclick='.$dest.' />');
297: }
298: $r->print('</form>');
1.1 raeburn 299: $r->print('<br />'.&Apache::loncommon::end_page());
300: return;
301: }
302:
1.3 raeburn 303: sub print_login {
1.6 raeburn 304: my ($dom,$phase,$settings) = @_;
305: my %choices = &login_choices();
306: my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
307: $catalogon = ' checked="checked" ';
308: $adminmailoff = ' checked="checked" ';
309: my @images = ('img','logo','domlogo');
310: my @bgs = ('pgbg','mainbg','sidebg');
311: my @links = ('link','alink','vlink');
1.7 albertel 312: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 313: my %defaultdesign = %Apache::loncommon::defaultdesign;
314: my (%is_custom,%designs);
315: my %defaults = (
316: font => $defaultdesign{'login.font'},
317: );
318: foreach my $item (@images) {
319: $defaults{$item} = $defaultdesign{'login.'.$item};
320: }
321: foreach my $item (@bgs) {
322: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
323: }
324: foreach my $item (@links) {
325: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
326: }
1.3 raeburn 327: if (ref($settings) eq 'HASH') {
328: if ($settings->{'coursecatalog'} eq '0') {
1.1 raeburn 329: $catalogoff = $catalogon;
330: $catalogon = ' ';
331: }
1.3 raeburn 332: if ($settings->{'adminmail'} eq '1') {
1.1 raeburn 333: $adminmailon = $adminmailoff;
334: $adminmailoff = ' ';
335: }
1.6 raeburn 336: foreach my $item (@images) {
337: if ($settings->{$item} ne '') {
338: $designs{$item} = $settings->{$item};
339: $is_custom{$item} = 1;
340: }
341: }
342: if ($settings->{'font'} ne '') {
343: $designs{'font'} = $settings->{'font'};
344: $is_custom{'font'} = 1;
345: }
346: foreach my $item (@bgs) {
347: if ($settings->{$item} ne '') {
348: $designs{'bgs'}{$item} = $settings->{$item};
349: $is_custom{$item} = 1;
350: }
351: }
352: foreach my $item (@links) {
353: if ($settings->{$item} ne '') {
354: $designs{'links'}{$item} = $settings->{$item};
355: $is_custom{$item} = 1;
356: }
357: }
358: } else {
359: if ($designhash{$dom.'.login.font'} ne '') {
360: $designs{'font'} = $designhash{$dom.'.login.font'};
361: $is_custom{'font'} = 1;
362: }
1.8 ! raeburn 363: foreach my $item (@images) {
! 364: if ($designhash{$dom.'.login.'.$item} ne '') {
! 365: $designs{$item} = $designhash{$dom.'.login.'.$item};
! 366: $is_custom{$item} = 1;
! 367: }
! 368: }
1.6 raeburn 369: foreach my $item (@bgs) {
370: if ($designhash{$dom.'.login.'.$item} ne '') {
371: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
372: $is_custom{$item} = 1;
373: }
374: }
375: foreach my $item (@links) {
376: if ($designhash{$dom.'.login.'.$item} ne '') {
377: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
378: $is_custom{$item} = 1;
379: }
380: }
1.1 raeburn 381: }
1.6 raeburn 382: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
383: logo => 'Institution Logo',
384: domlogo => 'Domain Logo');
385: my $itemcount = 1;
386: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.3 raeburn 387: my $datatable =
1.6 raeburn 388: '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
389: '</td><td>'.
1.8 ! raeburn 390: '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
! 391: $catalogon.' value="1" />'.&mt('Yes').'</label> '.
! 392: '<label><input type="radio" name="coursecatalog"'.
! 393: $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.6 raeburn 394: '</tr>';
395: $itemcount ++;
396: $css_class = $itemcount%2?' class="LC_odd_row"':'';
397: $datatable .= '<tr'.$css_class.'>'.
398: '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
1.8 ! raeburn 399: '<td><span class="LC_nobreak">'.
! 400: '<label><input type="radio" name="adminmail"'.
! 401: $adminmailon.' value="1" />'.&mt('Yes').'</label> '.
! 402: '<label><input type="radio" name="adminmail"'.
! 403: $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
1.6 raeburn 404: $itemcount ++;
405: $datatable .= &display_color_options($dom,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
406: $datatable .= '</tr></table></td></tr>';
407: return $datatable;
408: }
409:
410: sub login_choices {
411: my %choices =
412: &Apache::lonlocal::texthash (
413: coursecatalog => 'Display Course Catalog link?',
414: adminmail => "Display Administrator's E-mail Address?",
415: img => "Header",
416: logo => "Main Logo",
417: domlogo => "Domain Logo",
418: bgs => "Background colors",
419: links => "Link colors",
420: font => "Font color",
421: pgbg => "Page",
422: mainbg => "Main panel",
423: sidebg => "Side panel",
424: link => "Link",
425: alink => "Active link",
426: vlink => "Visited link",
427: );
428: return %choices;
429: }
430:
431: sub print_rolecolors {
432: my ($phase,$role,$dom,$settings) = @_;
433: my %choices = &color_font_choices();
434: my @bgs = ('pgbg','tabbg','sidebg');
435: my @links = ('link','alink','vlink');
436: my @images = ('img');
437: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 438: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 439: my %defaultdesign = %Apache::loncommon::defaultdesign;
440: my (%is_custom,%designs);
441: my %defaults = (
442: img => $defaultdesign{$role.'.img'},
443: font => $defaultdesign{$role.'.font'},
444: );
445: foreach my $item (@bgs) {
446: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
447: }
448: foreach my $item (@links) {
449: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
450: }
451: if (ref($settings) eq 'HASH') {
452: if (ref($settings->{$role}) eq 'HASH') {
453: if ($settings->{$role}->{'img'} ne '') {
454: $designs{'img'} = $settings->{$role}->{'img'};
455: $is_custom{'img'} = 1;
456: }
457: if ($settings->{$role}->{'font'} ne '') {
458: $designs{'font'} = $settings->{$role}->{'font'};
459: $is_custom{'font'} = 1;
460: }
461: foreach my $item (@bgs) {
462: if ($settings->{$role}->{$item} ne '') {
463: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
464: $is_custom{$item} = 1;
465: }
466: }
467: foreach my $item (@links) {
468: if ($settings->{$role}->{$item} ne '') {
469: $designs{'links'}{$item} = $settings->{$role}->{$item};
470: $is_custom{$item} = 1;
471: }
472: }
473: }
474: } else {
475: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
476: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
477: $is_custom{'img'} = 1;
478: }
479: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
480: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
481: $is_custom{'font'} = 1;
482: }
483: foreach my $item (@bgs) {
484: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
485: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
486: $is_custom{$item} = 1;
487:
488: }
489: }
490: foreach my $item (@links) {
491: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
492: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
493: $is_custom{$item} = 1;
494: }
495: }
496: }
497: my $itemcount = 1;
1.8 ! raeburn 498: my $datatable = &display_color_options($dom,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
1.6 raeburn 499: $datatable .= '</tr></table></td></tr>';
500: return $datatable;
501: }
502:
503: sub display_color_options {
504: my ($dom,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
505: $images,$bgs,$links,$alt_text) = @_;
506: my $configuname = $dom.'-domainconfig';
507: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
508: my $datatable = '<tr'.$css_class.'>'.
509: '<td>'.$choices->{'font'}.'</td>';
510: if (!$is_custom->{'font'}) {
511: $datatable .= '<td>'.&mt('Default in use:').' '.$defaults->{'font'}.'</td>';
512: } else {
513: $datatable .= '<td> </td>';
514: }
515: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 ! raeburn 516: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 517: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 ! raeburn 518: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
! 519: '</span></td></tr>';
1.6 raeburn 520: foreach my $img (@{$images}) {
521: $itemcount ++;
522: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 ! raeburn 523: $datatable .= '<tr'.$css_class.'>'.
1.6 raeburn 524: '<td>'.$choices->{$img}.'</td>';
525: my $imgfile;
526: if ($designs->{$img} ne '') {
527: $imgfile = $designs->{$img};
528: } else {
529: $imgfile = $defaults->{$img};
530: }
531: if ($imgfile) {
532: my $showfile;
533: if ($imgfile =~ m-^(/uploaded/\Q$dom\E/\Q$configuname\E/portfolio.*)/([^/]+)$-) {
534: my $urldir = $1;
535: my $filename = $2;
536: my @info = &Apache::lonnet::stat_file($designs->{$img});
537: if (@info) {
538: my $thumbfile = 'tn-'.$filename;
539: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
540: if (@thumb) {
541: $showfile = $urldir.'/'.$thumbfile;
542: } else {
543: $showfile = $imgfile;
544: }
545: } else {
546: $showfile = '';
547: }
548: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
549: my $imgdir = $1;
550: my $filename = $2;
551: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
552: $showfile = "/$imgdir/tn-".$filename;
553: } else {
554: my $input = "/home/httpd/html".$imgfile;
555: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
556: if (!-e $output) {
557: system("convert -sample 200x50 $input $output");
558: }
559: $showfile = '/'.$imgdir.'/tn-'.$filename;
560: }
561: }
562: if ($showfile) {
563: $datatable.= '<td>';
564: if (!$is_custom->{$img}) {
565: $datatable .= &mt('Default in use:').'<br />';
566: }
567: $datatable.= '<img src="'.$showfile.'" alt="'.
568: $alt_text->{$img}.'" /></td>';
569: if ($is_custom->{$img}) {
1.8 ! raeburn 570: $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
! 571: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
! 572: '</label> '.&mt('Replace:').'</span><br />';
1.6 raeburn 573: } else {
574: $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
575: }
576: } else {
577: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
578: &mt('Upload:');
579: }
580: } else {
581: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
582: &mt('Upload:');
583: }
1.8 ! raeburn 584: $datatable .= ' <input type="file" name="'.$role.'_'.$img.'" /></td></tr>';
1.6 raeburn 585: }
586: $itemcount ++;
587: $css_class = $itemcount%2?' class="LC_odd_row"':'';
588: $datatable .= '<tr'.$css_class.'>'.
589: '<td>'.$choices->{'bgs'}.'</td>';
590: my $bgs_def;
591: foreach my $item (@{$bgs}) {
592: if (!$is_custom->{$item}) {
593: $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
594: }
595: }
596: if ($bgs_def) {
1.8 ! raeburn 597: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 598: } else {
599: $datatable .= '<td> </td>';
600: }
601: $datatable .= '<td class="LC_right_item">'.
602: '<table border="0"><tr>';
603: foreach my $item (@{$bgs}) {
604: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
605: $datatable .= '<td align="center">'.$link;
606: if ($designs->{'bgs'}{$item}) {
607: $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px"> </span>';
608: }
609: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
610: '" /></td>';
611: }
612: $datatable .= '</tr></table></td></tr>';
613: $itemcount ++;
614: $css_class = $itemcount%2?' class="LC_odd_row"':'';
615: $datatable .= '<tr'.$css_class.'>'.
616: '<td>'.$choices->{'links'}.'</td>';
617: my $links_def;
618: foreach my $item (@{$links}) {
619: if (!$is_custom->{$item}) {
620: $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
621: }
622: }
623: if ($links_def) {
1.8 ! raeburn 624: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 625: } else {
626: $datatable .= '<td> </td>';
627: }
628: $datatable .= '<td class="LC_right_item">'.
629: '<table border="0"><tr>';
630: foreach my $item (@{$links}) {
631: $datatable .= '<td align="center">';
632: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
633: if ($designs->{'links'}{$item}) {
634: $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
635: $link.'</span>';
636: } else {
637: $datatable .= $link;
638: }
639: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
640: '" /></td>';
641: }
1.3 raeburn 642: return $datatable;
643: }
644:
1.6 raeburn 645: sub color_pick {
646: my ($phase,$role,$item,$desc,$curcol) = @_;
647: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
648: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
649: ');">'.$desc.'</a>';
650: return $link;
651: }
652:
653: sub color_pick_js {
654: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
655: my $output = <<"ENDCOL";
656: function pclose() {
657: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
658: parmwin.close();
659: }
660:
661: $pjump_def
662:
663: function psub() {
664: pclose();
665: if (document.parmform.pres_marker.value!='') {
666: if (document.parmform.pres_type.value!='') {
667: eval('document.display.'+
668: document.parmform.pres_marker.value+
669: '.value=document.parmform.pres_value.value;');
670: }
671: } else {
672: document.parmform.pres_value.value='';
673: document.parmform.pres_marker.value='';
674: }
675: }
676: ENDCOL
677: return $output;
678: }
679:
1.3 raeburn 680: sub print_quotas {
681: my ($dom,$settings) = @_;
682: my $datatable;
683: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
684: my $othertitle = "All users";
685: my @types;
686: if (ref($order) eq 'ARRAY') {
687: @types = @{$order};
688: }
689: if (@types == 0) {
690: if (ref($usertypes) eq 'HASH') {
691: @types = sort(keys(%{$usertypes}));
692: }
693: }
694: my $typecount = 0;
695: my $css_class;
696: if (@types > 0) {
697: foreach my $type (@types) {
698: if (defined($usertypes->{$type})) {
699: $typecount ++;
700: $css_class = $typecount%2?' class="LC_odd_row"':'';
701: $datatable .= '<tr'.$css_class.'>'.
702: '<td>'.$usertypes->{$type}.'</td>'.
1.8 ! raeburn 703: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 704: '<input type="text" name="quota_'.$type.
705: '" value="'.$settings->{$type}.
1.8 ! raeburn 706: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 707: }
708: }
709: $othertitle = "Other users";
710: }
711: my $defaultquota = '20';
712: if (ref($settings) eq 'HASH') {
713: if (defined($settings->{'default'})) {
714: $defaultquota = $settings->{'default'};
715: }
716: }
717: $typecount ++;
718: $css_class = $typecount%2?' class="LC_odd_row"':'';
719: $datatable .= '<tr'.$css_class.'>'.
720: '<td>'.&mt($othertitle).'</td>'.
1.8 ! raeburn 721: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 722: '<input type="text" name="default" value="'.
1.8 ! raeburn 723: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.3 raeburn 724: return $datatable;
725: }
726:
727: sub print_autoenroll {
728: my ($dom,$settings) = @_;
729: my $defdom = $dom;
730: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
731: my ($runon,$runoff);
732: if (ref($settings) eq 'HASH') {
733: if (exists($settings->{'run'})) {
734: if ($settings->{'run'} eq '0') {
735: $runoff = ' checked="checked" ';
736: $runon = ' ';
737: } else {
738: $runon = ' checked="checked" ';
739: $runoff = ' ';
740: }
741: } else {
742: if ($autorun) {
743: $runon = ' checked="checked" ';
744: $runoff = ' ';
745: } else {
746: $runoff = ' checked="checked" ';
747: $runon = ' ';
748: }
749: }
750: if (exists($settings->{'sender_domain'})) {
751: $defdom = $settings->{'sender_domain'};
752: }
753: }
754: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
755: my $datatable='<tr class="LC_odd_row">'.
756: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 ! raeburn 757: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 758: '<input type="radio" name="autoenroll_run"'.
1.8 ! raeburn 759: $runon.' value="1" />'.&mt('Yes').'</label> '.
! 760: '<label><input type="radio" name="autoenroll_run"'.
! 761: $runoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 762: '</tr><tr>'.
763: '<td>'.&mt('Notification messages - sender').
1.8 ! raeburn 764: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 765: &mt('username').': '.
766: '<input type="text" name="sender_uname" value="'.
767: $settings->{'sender_uname'}.
768: '" size="10" /> '.&mt('domain').
1.8 ! raeburn 769: ': '.$domform.'</span></td></tr>';
1.3 raeburn 770: return $datatable;
771: }
772:
773: sub print_autoupdate {
774: my ($position,$dom,$settings) = @_;
775: my $datatable;
776: if ($position eq 'top') {
777: my $updateon = ' ';
778: my $updateoff = ' checked="checked" ';
779: my $classlistson = ' ';
780: my $classlistsoff = ' checked="checked" ';
781: if (ref($settings) eq 'HASH') {
782: if ($settings->{'run'} eq '1') {
783: $updateon = $updateoff;
784: $updateoff = ' ';
785: }
786: if ($settings->{'classlists'} eq '1') {
787: $classlistson = $classlistsoff;
788: $classlistsoff = ' ';
789: }
790: }
791: my %title = (
792: run => 'Auto-update active?',
793: classlists => 'Update information in classlists?',
794: );
795: $datatable = '<tr class="LC_odd_row">'.
796: '<td>'.&mt($title{'run'}).'</td>'.
1.8 ! raeburn 797: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 798: '<input type="radio" name="autoupdate_run"'.
1.8 ! raeburn 799: $updateon.' value="1" />'.&mt('Yes').'</label> '.
! 800: '<label><input type="radio" name="autoupdate_run"'.
! 801: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 802: '</tr><tr>'.
803: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 ! raeburn 804: '<td class="LC_right_item"><span class="LC_nobreak">'.
! 805: '<label><input type="radio" name="classlists"'.
! 806: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
! 807: '<label><input type="radio" name="classlists"'.
! 808: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 809: '</tr>';
810: } else {
811: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
812: my @types;
813: if (ref($order) eq 'ARRAY') {
814: @types = @{$order};
815: }
816: if (@types == 0) {
817: if (ref($usertypes) eq 'HASH') {
818: @types = sort(keys(%{$usertypes}));
819: }
820: }
821: my $othertitle = &mt('All users');
822: if (keys(%{$usertypes}) > 0) {
823: $othertitle = &mt('Other users');
824: }
825: my @fields = ('lastname','firstname','middlename','gen','email','id');
826: my %fieldtitles = &Apache::lonlocal::texthash (
827: id => 'Student/Employee ID',
828: email => 'E-mail address',
829: lastname => 'Last Name',
830: firstname => 'First Name',
831: middlename => 'Middle Name',
832: gen => 'Generation',
833: );
834: my $numrows = 0;
835: if (@types > 0) {
836: $datatable =
837: &usertype_update_row($settings,$usertypes,\%fieldtitles,
838: \@fields,\@types,\$numrows);
839: }
840: $datatable .=
841: &usertype_update_row($settings,{'default' => $othertitle},
842: \%fieldtitles,\@fields,['default'],
843: \$numrows);
844: }
845: return $datatable;
846: }
847:
848: sub usertype_update_row {
849: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
850: my $datatable;
851: my $numinrow = 4;
852: foreach my $type (@{$types}) {
853: if (defined($usertypes->{$type})) {
854: $$rownums ++;
855: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
856: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
857: '</td><td class="LC_left_item"><table>';
858: for (my $i=0; $i<@{$fields}; $i++) {
859: my $rem = $i%($numinrow);
860: if ($rem == 0) {
861: if ($i > 0) {
862: $datatable .= '</tr>';
863: }
864: $datatable .= '<tr>';
865: }
866: my $check = ' ';
867: if (ref($settings->{'fields'}) eq 'HASH') {
868: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
869: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
870: $check = ' checked="checked" ';
871: }
872: }
873: }
874:
875: if ($i == @{$fields}-1) {
876: my $colsleft = $numinrow - $rem;
877: if ($colsleft > 1) {
878: $datatable .= '<td colspan="'.$colsleft.'">';
879: } else {
880: $datatable .= '<td>';
881: }
882: } else {
883: $datatable .= '<td>';
884: }
1.8 ! raeburn 885: $datatable .= '<span class="LC_nobreak"><label>'.
! 886: '<input type="checkbox" name="updateable_'.$type.
! 887: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
! 888: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 889: }
890: $datatable .= '</tr></table></td></tr>';
891: }
892: }
893: return $datatable;
1.1 raeburn 894: }
895:
896: sub modify_login {
1.6 raeburn 897: my ($r,$dom,%domconfig) = @_;
898: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 899: my %title = ( coursecatalog => 'Display course catalog',
900: adminmail => 'Display administrator E-mail address');
1.3 raeburn 901: my @offon = ('off','on');
1.6 raeburn 902: my %loginhash;
903: ($errors,%colchanges) = &modify_colors($r,$dom,['login'],\%domconfig,
904: \%loginhash);
905: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
906: $loginhash{login}{adminmail} = $env{'form.adminmail'};
907: if (ref($colchanges{'login'}) eq 'HASH') {
908: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
909: \%loginhash);
910: }
1.1 raeburn 911: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
912: $dom);
913: if ($putresult eq 'ok') {
1.3 raeburn 914: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 915: ($env{'form.coursecatalog'} eq '1')) {
916: $changes{'coursecatalog'} = 1;
1.3 raeburn 917: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
918: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 919: ($env{'form.coursecatalog'} eq '0')) {
920: $changes{'coursecatalog'} = 1;
921: }
1.3 raeburn 922: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 923: ($env{'form.adminmail'} eq '0')) {
924: $changes{'adminmail'} = 1;
925: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
926: $domconfig{'login'}{'adminmail'} eq '0') &&
927: ($env{'form.adminmail'} eq '1')) {
928: $changes{'adminmail'} = 1;
929: }
1.6 raeburn 930: if (keys(%changes) > 0 || $colchgtext) {
1.1 raeburn 931: $resulttext = &mt('Changes made:').'<ul>';
932: foreach my $item (sort(keys(%changes))) {
933: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
934: }
1.6 raeburn 935: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 936: } else {
937: $resulttext = &mt('No changes made to log-in page settings');
938: }
939: } else {
940: $resulttext = &mt('An error occurred: [_1]',$putresult);
941: }
1.6 raeburn 942: if ($errors) {
943: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
944: $errors.'</ul>';
945: }
946: return $resulttext;
947: }
948:
949: sub color_font_choices {
950: my %choices =
951: &Apache::lonlocal::texthash (
952: img => "Header",
953: bgs => "Background colors",
954: links => "Link colors",
955: font => "Font color",
956: pgbg => "Page",
957: tabbg => "Header",
958: sidebg => "Border",
959: link => "Link",
960: alink => "Active link",
961: vlink => "Visited link",
962: );
963: return %choices;
964: }
965:
966: sub modify_rolecolors {
967: my ($r,$dom,$roles,%domconfig) = @_;
968: my ($resulttext,%rolehash);
969: $rolehash{'rolecolors'} = {};
970: my ($errors,%changes) = &modify_colors($r,$dom,$roles,
971: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
972: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
973: $dom);
974: if ($putresult eq 'ok') {
975: if (keys(%changes) > 0) {
976: $resulttext = &display_colorchgs($dom,\%changes,$roles,
977: $rolehash{'rolecolors'});
978: } else {
979: $resulttext = &mt('No changes made to default color schemes');
980: }
981: } else {
982: $resulttext = &mt('An error occurred: [_1]',$putresult);
983: }
984: if ($errors) {
985: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
986: $errors.'</ul>';
987: }
988: return $resulttext;
989: }
990:
991: sub modify_colors {
992: my ($r,$dom,$roles,$domconfig,$confhash) = @_;
993: my %changes;
994: my @bgs = ('pgbg','mainbg','sidebg');
995: my @links = ('link','alink','vlink');
996: my @images;
997: my $configuname = $dom.'-domainconfig';
998: my $servadm = $r->dir_config('lonAdmEMail');
999: my $errors;
1000: foreach my $role (@{$roles}) {
1001: if ($role eq 'login') {
1002: @images = ('img','logo','domlogo');
1003: } else {
1004: @images = ('img');
1005: }
1006: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1007: foreach my $item (@bgs,@links) {
1008: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
1009: }
1.8 ! raeburn 1010: foreach my $img (@images) {
1.6 raeburn 1011: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1012: my $configuserok;
1013: if (&Apache::lonnet::homeserver($configuname,$dom) eq 'no_host') {
1014: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1015: my $configpass = &LONCAPA::Enrollment::create_password();
1016: $configuserok = &Apache::lonnet::modifyuser($dom,$configuname,'','internal',$configpass,'','','','','',undef,$servadm);
1017: } else {
1018: $configuserok = 'ok';
1019: }
1020: if ($configuserok eq 'ok') {
1021: my $result =
1022: &Apache::lonnet::userfileupload($role.'_'.$img,'',
1023: 'portfolio/'.$img,'','','',$configuname,$dom,'200','50');
1024: if ($result =~ m|(^/uploaded/.+)/([^/]+)$|) {
1025: my $urldir = $1;
1026: my $filename = $2;
1027: my $allowresult = &Apache::lonnet::make_public_indefinitely($result);
1028: if ($allowresult eq 'ok') {
1029: &Apache::lonnet::make_public_indefinitely($urldir.'/tn-'.$filename);
1030: $confhash->{$role}{$img} = $result;
1031: $changes{$role}{$img} = 1;
1032: }
1033: }
1034: } else {
1035: my $error = &mt("Upload of image [_1] for $role page(s) failed because a Domain Configuation user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$img,$configuname,$dom,$configuserok);
1.8 ! raeburn 1036: &Apache::lonnet::logthis($error);
! 1037: $errors .= '<li>'.$error.'</li>';
! 1038: }
! 1039: } elsif ($domconfig->{$role}{$img} ne '') {
! 1040: if ($domconfig->{$role}{$img} !~ m|^/uploaded/\Q$dom\E/\Q$dom\E\-domainconfig/portfolio/\$img/.+|) {
! 1041: #FIXME copy file to target directory
1.6 raeburn 1042: }
1043: }
1044: }
1045: if (ref($domconfig) eq 'HASH') {
1046: if (ref($domconfig->{$role}) eq 'HASH') {
1047: foreach my $img (@images) {
1048: if ($domconfig->{$role}{$img} ne '') {
1049: if ($env{'form.'.$role.'_del_'.$img}) {
1050: $confhash->{$role}{$img} = '';
1051: $changes{$role}{$img} = 1;
1052: } else {
1053: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
1054: }
1055: } else {
1056: if ($env{'form.'.$role.'_del_'.$img}) {
1057: $confhash->{$role}{$img} = '';
1058: $changes{$role}{$img} = 1;
1059: }
1060: }
1061: }
1062: if ($domconfig->{$role}{'font'} ne '') {
1063: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
1064: $changes{$role}{'font'} = 1;
1065: }
1066: } else {
1067: if ($confhash->{$role}{'font'}) {
1068: $changes{$role}{'font'} = 1;
1069: }
1070: }
1071: foreach my $item (@bgs) {
1072: if ($domconfig->{$role}{$item} ne '') {
1073: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1074: $changes{$role}{'bgs'}{$item} = 1;
1075: }
1076: } else {
1077: if ($confhash->{$role}{$item}) {
1078: $changes{$role}{'bgs'}{$item} = 1;
1079: }
1080: }
1081: }
1082: foreach my $item (@links) {
1083: if ($domconfig->{$role}{$item} ne '') {
1084: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1085: $changes{$role}{'links'}{$item} = 1;
1086: }
1087: } else {
1088: if ($confhash->{$role}{$item}) {
1089: $changes{$role}{'links'}{$item} = 1;
1090: }
1091: }
1092: }
1093: } else {
1094: &default_change_checker($role,\@images,\@links,\@bgs,
1095: $confhash,\%changes);
1096: }
1097: } else {
1098: &default_change_checker($role,\@images,\@links,\@bgs,
1099: $confhash,\%changes);
1100: }
1101: }
1102: return ($errors,%changes);
1103: }
1104:
1105: sub default_change_checker {
1106: my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
1107: foreach my $item (@{$links}) {
1108: if ($confhash->{$role}{$item}) {
1109: $changes->{$role}{'links'}{$item} = 1;
1110: }
1111: }
1112: foreach my $item (@{$bgs}) {
1113: if ($confhash->{$role}{$item}) {
1114: $changes->{$role}{'bgs'}{$item} = 1;
1115: }
1116: }
1117: foreach my $img (@{$images}) {
1118: if ($env{'form.'.$role.'_del_'.$img}) {
1119: $confhash->{$role}{$img} = '';
1120: $changes->{$role}{$img} = 1;
1121: }
1122: }
1123: if ($confhash->{$role}{'font'}) {
1124: $changes->{$role}{'font'} = 1;
1125: }
1126: }
1127:
1128: sub display_colorchgs {
1129: my ($dom,$changes,$roles,$confhash) = @_;
1130: my (%choices,$resulttext);
1.7 albertel 1131: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 1132: if (!grep(/^login$/,@{$roles})) {
1133: $resulttext = &mt('Changes made:').'<br />';
1134: }
1135: foreach my $role (@{$roles}) {
1136: if ($role eq 'login') {
1137: %choices = &login_choices();
1138: } else {
1139: %choices = &color_font_choices();
1140: }
1141: if (ref($changes->{$role}) eq 'HASH') {
1142: if ($role ne 'login') {
1143: $resulttext .= '<h4>'.&mt($role).'</h4>';
1144: }
1145: foreach my $key (sort(keys(%{$changes->{$role}}))) {
1146: if ($role ne 'login') {
1147: $resulttext .= '<ul>';
1148: }
1149: if (ref($changes->{$role}{$key}) eq 'HASH') {
1150: if ($role ne 'login') {
1151: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
1152: }
1153: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1154: if ($confhash->{$role}{$item} eq '') {
1155: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
1156: } else {
1157: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$confhash->{$role}{$item}).'</li>';
1158: }
1159: }
1160: if ($role ne 'login') {
1161: $resulttext .= '</ul></li>';
1162: }
1163: } else {
1164: if ($confhash->{$role}{$key} eq '') {
1165: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
1166: } else {
1167: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
1168: }
1169: }
1170: if ($role ne 'login') {
1171: $resulttext .= '</ul>';
1172: }
1173: }
1174: }
1175: }
1.3 raeburn 1176: return $resulttext;
1.1 raeburn 1177: }
1178:
1179: sub modify_quotas {
1.3 raeburn 1180: my ($dom,%domconfig) = @_;
1.1 raeburn 1181: my ($resulttext,%changes);
1.3 raeburn 1182: my ($usertypes,$order) =
1183: &Apache::lonnet::retrieve_inst_usertypes($dom);
1.1 raeburn 1184: my %formhash;
1185: foreach my $key (keys(%env)) {
1186: if ($key =~ /^form\.quota_(.+)$/) {
1187: $formhash{$1} = $env{$key};
1188: }
1189: }
1190: if (ref($domconfig{'quotas'}) eq 'HASH') {
1191: foreach my $key (keys(%{$domconfig{'quotas'}})) {
1192: if (exists($formhash{$key})) {
1193: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
1194: $changes{$key} = 1;
1195: }
1196: } else {
1197: $formhash{$key} = $domconfig{'quotas'}{$key};
1198: }
1199: }
1200: }
1201: foreach my $key (keys(%formhash)) {
1202: if ($formhash{$key} ne '') {
1.3 raeburn 1203: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 1204: $changes{$key} = 1;
1205: }
1206: }
1207: }
1208: my %quotahash = (
1.3 raeburn 1209: quotas => {%formhash},
1.1 raeburn 1210: );
1211: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
1212: $dom);
1213: if ($putresult eq 'ok') {
1214: if (keys(%changes) > 0) {
1215: $resulttext = &mt('Changes made:').'<ul>';
1216: foreach my $item (sort(keys(%changes))) {
1217: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
1218: }
1219: $resulttext .= '</ul>';
1220: } else {
1221: $resulttext = &mt('No changes made to default quotas');
1222: }
1223: } else {
1224: $resulttext = &mt('An error occurred: [_1]',$putresult);
1225: }
1.3 raeburn 1226: return $resulttext;
1.1 raeburn 1227: }
1228:
1.3 raeburn 1229: sub modify_autoenroll {
1230: my ($dom,%domconfig) = @_;
1.1 raeburn 1231: my ($resulttext,%changes);
1232: my %currautoenroll;
1233: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
1234: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
1235: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
1236: }
1237: }
1238: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1239: my %title = ( run => 'Auto-enrollment active',
1240: sender => 'Sender for notification messages');
1241: my @offon = ('off','on');
1242: my %autoenrollhash = (
1243: autoenroll => { run => $env{'form.autoenroll_run'},
1244: sender_uname => $env{'form.sender_uname'},
1245: sender_domain => $env{'form.sender_domain'},
1246:
1247: }
1248: );
1.4 raeburn 1249: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
1250: $dom);
1.1 raeburn 1251: if ($putresult eq 'ok') {
1252: if (exists($currautoenroll{'run'})) {
1253: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
1254: $changes{'run'} = 1;
1255: }
1256: } elsif ($autorun) {
1257: if ($env{'form.autoenroll_run'} ne '1') {
1258: $changes{'run'} = 1;
1259: }
1260: }
1261: if (exists($currautoenroll{sender_uname})) {
1262: if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {
1263: $changes{'sender'} = 1;
1264: }
1265: } else {
1266: $changes{'sender'} = 1;
1267: }
1268: if (exists($currautoenroll{sender_domain})) {
1269: if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {
1270: $changes{'sender'} = 1;
1271: }
1272: } else {
1273: $changes{'sender'} = 1;
1274: }
1275: if (keys(%changes) > 0) {
1276: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 1277: if ($changes{'run'}) {
1.1 raeburn 1278: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
1279: }
1280: if ($changes{'sender'}) {
1281: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';
1282: }
1283: $resulttext .= '</ul>';
1284: } else {
1285: $resulttext = &mt('No changes made to auto-enrollment settings');
1286: }
1287: } else {
1288: $resulttext = &mt('An error occurred: [_1]',$putresult);
1289: }
1.3 raeburn 1290: return $resulttext;
1.1 raeburn 1291: }
1292:
1293: sub modify_autoupdate {
1.3 raeburn 1294: my ($dom,%domconfig) = @_;
1.1 raeburn 1295: my ($resulttext,%currautoupdate,%fields,%changes);
1296: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
1297: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
1298: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
1299: }
1300: }
1301: my @offon = ('off','on');
1302: my %title = &Apache::lonlocal::texthash (
1303: run => 'Auto-update:',
1304: classlists => 'Updates to user information in classlists?'
1305: );
1306: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1307: my %fieldtitles = &Apache::lonlocal::texthash (
1308: id => 'Student/Employee ID',
1309: email => 'E-mail address',
1310: lastname => 'Last Name',
1311: firstname => 'First Name',
1312: middlename => 'Middle Name',
1313: gen => 'Generation',
1314: );
1315: my $othertitle = &mt('All users');
1316: if (keys(%{$usertypes}) > 0) {
1317: $othertitle = "Other users";
1318: }
1319: foreach my $key (keys(%env)) {
1320: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1321: push(@{$fields{$1}},$2);
1322: }
1323: }
1324: my %updatehash = (
1325: autoupdate => { run => $env{'form.autoupdate_run'},
1326: classlists => $env{'form.classlists'},
1327: fields => {%fields},
1328: }
1329: );
1330: foreach my $key (keys(%currautoupdate)) {
1331: if (($key eq 'run') || ($key eq 'classlists')) {
1332: if (exists($updatehash{autoupdate}{$key})) {
1333: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
1334: $changes{$key} = 1;
1335: }
1336: }
1337: } elsif ($key eq 'fields') {
1338: if (ref($currautoupdate{$key}) eq 'HASH') {
1339: foreach my $item (keys(%{$currautoupdate{$key}})) {
1340: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
1341: my $change = 0;
1342: foreach my $type (@{$currautoupdate{$key}{$item}}) {
1343: if (!exists($fields{$item})) {
1344: $change = 1;
1345: } elsif (ref($fields{$item}) eq 'ARRAY') {
1346: if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
1347: $change = 1;
1348: }
1349: }
1350: }
1351: if ($change) {
1352: push(@{$changes{$key}},$item);
1353: }
1354: }
1355: }
1356: }
1357: }
1358: }
1359: foreach my $key (keys(%fields)) {
1360: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1361: if (!exists($currautoupdate{'fields'}{$key})) {
1362: push(@{$changes{'fields'}},$key);
1363: }
1364: } else {
1365: push(@{$changes{'fields'}},$key);
1366: }
1367: }
1368: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
1369: $dom);
1370: if ($putresult eq 'ok') {
1371: if (keys(%changes) > 0) {
1372: $resulttext = &mt('Changes made:').'<ul>';
1373: foreach my $key (sort(keys(%changes))) {
1374: if (ref($changes{$key}) eq 'ARRAY') {
1375: foreach my $item (@{$changes{$key}}) {
1376: my @newvalues;
1377: foreach my $type (@{$fields{$item}}) {
1378: push(@newvalues,$fieldtitles{$type});
1379: }
1.3 raeburn 1380: my $newvaluestr;
1381: if (@newvalues > 0) {
1382: $newvaluestr = join(', ',@newvalues);
1383: } else {
1384: $newvaluestr = &mt('none');
1.6 raeburn 1385: }
1.1 raeburn 1386: if ($item eq 'default') {
1387: $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
1388: } else {
1389: $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
1390: }
1391: }
1392: } else {
1393: my $newvalue;
1394: if ($key eq 'run') {
1395: $newvalue = $offon[$env{'form.autoupdate_run'}];
1396: } else {
1397: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 1398: }
1.1 raeburn 1399: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
1400: }
1401: }
1402: $resulttext .= '</ul>';
1403: } else {
1.3 raeburn 1404: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 1405: }
1406: } else {
1407: $resulttext = &mt('An error occurred: [_1]',$putresult);
1408: }
1.3 raeburn 1409: return $resulttext;
1.1 raeburn 1410: }
1411:
1.3 raeburn 1412: 1;
1.1 raeburn 1413:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>