Annotation of loncom/interface/domainprefs.pm, revision 1.17
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.17 ! raeburn 4: # $Id: domainprefs.pm,v 1.16 2007/05/27 21:21:26 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();
1.6 raeburn 40: use LONCAPA::Enrollment;
1.9 raeburn 41: use File::Copy;
1.1 raeburn 42:
43: sub handler {
44: my $r=shift;
45: if ($r->header_only) {
46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
48: return OK;
49: }
50:
51: my $dom = $env{'request.role.domain'};
1.5 albertel 52: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 53: if (&Apache::lonnet::allowed('mau',$dom)) {
54: &Apache::loncommon::content_type($r,'text/html');
55: $r->send_http_header;
56: } else {
57: $env{'user.error.msg'}=
58: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
59: return HTTP_NOT_ACCEPTABLE;
60: }
61: &Apache::lonhtmlcommon::clear_breadcrumbs();
62: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
63: ['phase']);
1.3 raeburn 64: my $phase = "display";
65: if ( exists($env{'form.phase'}) ) {
66: $phase = $env{'form.phase'};
67: }
68: my %domconfig =
1.6 raeburn 69: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
70: 'quotas','autoenroll','autoupdate'],$dom);
1.3 raeburn 71: my @prefs = (
1.6 raeburn 72: { text => 'Default color schemes',
73: help => 'Default_Color_Schemes',
74: action => 'rolecolors',
75: header => [{col1 => 'Student Settings',
76: col2 => '',},
77: {col1 => 'Coordinator Settings',
78: col2 => '',},
79: {col1 => 'Author Settings',
80: col2 => '',},
81: {col1 => 'Administrator Settings',
82: col2 => '',}],
83: },
1.3 raeburn 84: { text => 'Log-in page options',
85: help => 'Domain_Log-in_Page',
86: action => 'login',
87: header => [{col1 => 'Item',
1.6 raeburn 88: col2 => '',}],
1.3 raeburn 89: },
90: { text => 'Default quotas for user portfolios',
91: help => 'Default_User_Quota',
92: action => 'quotas',
93: header => [{col1 => 'User type',
94: col2 => 'Default quota'}],
95: },
96: { text => 'Auto-enrollment settings',
97: help => 'Domain_Auto_Enrollment',
98: action => 'autoenroll',
99: header => [{col1 => 'Configuration setting',
100: col2 => 'Value(s)'}],
101: },
102: { text => 'Auto-update settings',
103: help => 'Domain_Auto_Update',
104: action => 'autoupdate',
105: header => [{col1 => 'Setting',
106: col2 => 'Value',},
107: {col1 => 'User Population',
108: col2 => 'Updataeable user data'}],
109: },
110: );
1.6 raeburn 111: my @roles = ('student','coordinator','author','admin');
1.3 raeburn 112: &Apache::lonhtmlcommon::add_breadcrumb
113: ({href=>"javascript:changePage(document.$phase,'display')",
114: text=>"Domain Configuration"});
1.9 raeburn 115: my $confname = $dom.'-domainconfig';
1.3 raeburn 116: if ($phase eq 'process') {
1.1 raeburn 117: &Apache::lonhtmlcommon::add_breadcrumb
1.3 raeburn 118: ({href=>"javascript:changePage(document.$phase,'$phase')",
119: text=>"Updated"});
120: &print_header($r,$phase);
121: foreach my $item (@prefs) {
122: $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
1.9 raeburn 123: &process_changes($r,$dom,$confname,
124: $item->{'action'},\@roles,%domconfig));
1.3 raeburn 125: }
126: $r->print('<p>');
127: &print_footer($r,$phase,'display','Back to actions menu');
128: $r->print('</p>');
1.1 raeburn 129: } else {
1.3 raeburn 130: if ($phase eq '') {
131: $phase = 'display';
1.1 raeburn 132: }
1.3 raeburn 133: my %helphash;
134: my $numprefs = @prefs;
135: &print_header($r,$phase);
136: $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
137: foreach my $item (@prefs) {
1.6 raeburn 138: if ($item->{'action'} eq 'login') {
1.3 raeburn 139: $r->print('</td><td width="6%"> </td><td align="left" valign="top" width="47%">');
140: }
1.9 raeburn 141: &print_config_box($r,$dom,$confname,$phase,$item->{'action'},
1.6 raeburn 142: $item,$domconfig{$item->{'action'}});
1.3 raeburn 143: }
144: $r->print('
145: </td>
146: </tr>
147: </table>');
1.13 albertel 148: &print_footer($r,$phase,'process','Save changes');
1.3 raeburn 149: }
150: return OK;
151: }
152:
153: sub process_changes {
1.9 raeburn 154: my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
1.3 raeburn 155: my $output;
156: if ($action eq 'login') {
1.9 raeburn 157: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 158: } elsif ($action eq 'rolecolors') {
1.9 raeburn 159: $output = &modify_rolecolors($r,$dom,$confname,$roles,
160: %domconfig);
1.3 raeburn 161: } elsif ($action eq 'quotas') {
162: $output = &modify_quotas($dom,%domconfig);
163: } elsif ($action eq 'autoenroll') {
164: $output = &modify_autoenroll($dom,%domconfig);
165: } elsif ($action eq 'autoupdate') {
166: $output = &modify_autoupdate($dom,%domconfig);
167: }
168: return $output;
169: }
170:
171: sub print_config_box {
1.9 raeburn 172: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.3 raeburn 173: $r->print('
174: <table class="LC_nested_outer">
175: <tr>
176: <th>'.&mt($item->{text}).' '.
177: &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
178: </tr>');
1.6 raeburn 179: if (($action eq 'autoupdate') || ($action eq 'rolecolors')) {
180: my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
1.3 raeburn 181: $r->print('
182: <tr>
183: <td>
184: <table class="LC_nested">
185: <tr class="LC_info_row">
1.6 raeburn 186: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
1.3 raeburn 187: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.6 raeburn 188: </tr>');
189: if ($action eq 'autoupdate') {
190: $r->print(&print_autoupdate('top',$dom,$settings));
191: } else {
1.9 raeburn 192: $r->print(&print_rolecolors($phase,'student',$dom,$confname,$settings));
1.6 raeburn 193: }
194: $r->print('
195: </table>
196: </td>
197: </tr>
198: <tr>
199: <td>
200: <table class="LC_nested">
201: <tr class="LC_info_row">
202: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
203: <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
204: </tr>');
205: if ($action eq 'autoupdate') {
206: $r->print(&print_autoupdate('bottom',$dom,$settings));
207: } else {
1.9 raeburn 208: $r->print(&print_rolecolors($phase,'coordinator',$dom,$confname,$settings).'
1.6 raeburn 209: </table>
210: </td>
211: </tr>
212: <tr>
213: <td>
214: <table class="LC_nested">
215: <tr class="LC_info_row">
216: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
217: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
1.3 raeburn 218: </tr>'.
1.9 raeburn 219: &print_rolecolors($phase,'author',$dom,$confname,$settings).'
1.3 raeburn 220: </table>
221: </td>
222: </tr>
223: <tr>
224: <td>
225: <table class="LC_nested">
226: <tr class="LC_info_row">
1.6 raeburn 227: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
228: <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
1.3 raeburn 229: </tr>'.
1.9 raeburn 230: &print_rolecolors($phase,'admin',$dom,$confname,$settings));
1.6 raeburn 231: }
1.3 raeburn 232: } else {
233: $r->print('
234: <tr>
235: <td>
236: <table class="LC_nested">
1.6 raeburn 237: <tr class="LC_info_row">');
238: if ($action eq 'login') {
239: $r->print('
240: <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>');
241: } else {
242: $r->print('
243: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>');
244: }
245: $r->print('
1.3 raeburn 246: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
247: </tr>');
248: if ($action eq 'login') {
1.9 raeburn 249: $r->print(&print_login($dom,$confname,$phase,$settings));
1.3 raeburn 250: } elsif ($action eq 'quotas') {
251: $r->print(&print_quotas($dom,$settings));
252: } elsif ($action eq 'autoenroll') {
253: $r->print(&print_autoenroll($dom,$settings));
254: }
255: }
256: $r->print('
257: </table>
258: </td>
259: </tr>
260: </table><br />');
1.1 raeburn 261: return;
262: }
263:
264: sub print_header {
1.3 raeburn 265: my ($r,$phase) = @_;
1.6 raeburn 266: my $js = '
1.1 raeburn 267: <script type="text/javascript">
268: function changePage(formname,newphase) {
269: formname.phase.value = newphase;
270: formname.submit();
271: }
1.6 raeburn 272: '.
273: &color_pick_js().'
1.1 raeburn 274: </script>
1.6 raeburn 275: ';
1.2 albertel 276: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.3 raeburn 277: $js));
278: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6 raeburn 279: $r->print('
1.8 raeburn 280: <form name="parmform" action="">
1.6 raeburn 281: <input type="hidden" name="pres_marker" />
282: <input type="hidden" name="pres_type" />
283: <input type="hidden" name="pres_value" />
284: </form>
285: ');
286: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
287: ' enctype="multipart/form-data">');
1.1 raeburn 288: return;
289: }
290:
291: sub print_footer {
1.3 raeburn 292: my ($r,$phase,$newphase,$button_text) = @_;
293: $button_text = &mt($button_text);
294: $r->print('<input type="hidden" name="phase" value="" />');
295: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
296: if ($phase eq 'process') {
297: $r->print('<a href='.$dest.'>'.$button_text.'</a>');
298: } else {
299: $r->print('<input type="button" name="store" value="'.
300: $button_text.'" onclick='.$dest.' />');
301: }
302: $r->print('</form>');
1.1 raeburn 303: $r->print('<br />'.&Apache::loncommon::end_page());
304: return;
305: }
306:
1.3 raeburn 307: sub print_login {
1.9 raeburn 308: my ($dom,$confname,$phase,$settings) = @_;
1.6 raeburn 309: my %choices = &login_choices();
310: my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
311: $catalogon = ' checked="checked" ';
312: $adminmailoff = ' checked="checked" ';
313: my @images = ('img','logo','domlogo');
314: my @bgs = ('pgbg','mainbg','sidebg');
315: my @links = ('link','alink','vlink');
1.7 albertel 316: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 317: my %defaultdesign = %Apache::loncommon::defaultdesign;
318: my (%is_custom,%designs);
319: my %defaults = (
320: font => $defaultdesign{'login.font'},
321: );
322: foreach my $item (@images) {
323: $defaults{$item} = $defaultdesign{'login.'.$item};
324: }
325: foreach my $item (@bgs) {
326: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
327: }
328: foreach my $item (@links) {
329: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
330: }
1.3 raeburn 331: if (ref($settings) eq 'HASH') {
332: if ($settings->{'coursecatalog'} eq '0') {
1.1 raeburn 333: $catalogoff = $catalogon;
334: $catalogon = ' ';
335: }
1.3 raeburn 336: if ($settings->{'adminmail'} eq '1') {
1.1 raeburn 337: $adminmailon = $adminmailoff;
338: $adminmailoff = ' ';
339: }
1.6 raeburn 340: foreach my $item (@images) {
341: if ($settings->{$item} ne '') {
342: $designs{$item} = $settings->{$item};
343: $is_custom{$item} = 1;
344: }
345: }
346: if ($settings->{'font'} ne '') {
347: $designs{'font'} = $settings->{'font'};
348: $is_custom{'font'} = 1;
349: }
350: foreach my $item (@bgs) {
351: if ($settings->{$item} ne '') {
352: $designs{'bgs'}{$item} = $settings->{$item};
353: $is_custom{$item} = 1;
354: }
355: }
356: foreach my $item (@links) {
357: if ($settings->{$item} ne '') {
358: $designs{'links'}{$item} = $settings->{$item};
359: $is_custom{$item} = 1;
360: }
361: }
362: } else {
363: if ($designhash{$dom.'.login.font'} ne '') {
364: $designs{'font'} = $designhash{$dom.'.login.font'};
365: $is_custom{'font'} = 1;
366: }
1.8 raeburn 367: foreach my $item (@images) {
368: if ($designhash{$dom.'.login.'.$item} ne '') {
369: $designs{$item} = $designhash{$dom.'.login.'.$item};
370: $is_custom{$item} = 1;
371: }
372: }
1.6 raeburn 373: foreach my $item (@bgs) {
374: if ($designhash{$dom.'.login.'.$item} ne '') {
375: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
376: $is_custom{$item} = 1;
377: }
378: }
379: foreach my $item (@links) {
380: if ($designhash{$dom.'.login.'.$item} ne '') {
381: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
382: $is_custom{$item} = 1;
383: }
384: }
1.1 raeburn 385: }
1.6 raeburn 386: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
387: logo => 'Institution Logo',
388: domlogo => 'Domain Logo');
389: my $itemcount = 1;
390: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.3 raeburn 391: my $datatable =
1.6 raeburn 392: '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
393: '</td><td>'.
1.8 raeburn 394: '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
395: $catalogon.' value="1" />'.&mt('Yes').'</label> '.
396: '<label><input type="radio" name="coursecatalog"'.
397: $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.6 raeburn 398: '</tr>';
399: $itemcount ++;
400: $css_class = $itemcount%2?' class="LC_odd_row"':'';
401: $datatable .= '<tr'.$css_class.'>'.
402: '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
1.8 raeburn 403: '<td><span class="LC_nobreak">'.
404: '<label><input type="radio" name="adminmail"'.
405: $adminmailon.' value="1" />'.&mt('Yes').'</label> '.
406: '<label><input type="radio" name="adminmail"'.
407: $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
1.6 raeburn 408: $itemcount ++;
1.9 raeburn 409: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
1.6 raeburn 410: $datatable .= '</tr></table></td></tr>';
411: return $datatable;
412: }
413:
414: sub login_choices {
415: my %choices =
416: &Apache::lonlocal::texthash (
417: coursecatalog => 'Display Course Catalog link?',
418: adminmail => "Display Administrator's E-mail Address?",
419: img => "Header",
420: logo => "Main Logo",
421: domlogo => "Domain Logo",
422: bgs => "Background colors",
423: links => "Link colors",
424: font => "Font color",
425: pgbg => "Page",
426: mainbg => "Main panel",
427: sidebg => "Side panel",
428: link => "Link",
429: alink => "Active link",
430: vlink => "Visited link",
431: );
432: return %choices;
433: }
434:
435: sub print_rolecolors {
1.9 raeburn 436: my ($phase,$role,$dom,$confname,$settings) = @_;
1.6 raeburn 437: my %choices = &color_font_choices();
438: my @bgs = ('pgbg','tabbg','sidebg');
439: my @links = ('link','alink','vlink');
440: my @images = ('img');
441: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 442: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 443: my %defaultdesign = %Apache::loncommon::defaultdesign;
444: my (%is_custom,%designs);
445: my %defaults = (
446: img => $defaultdesign{$role.'.img'},
447: font => $defaultdesign{$role.'.font'},
448: );
449: foreach my $item (@bgs) {
450: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
451: }
452: foreach my $item (@links) {
453: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
454: }
455: if (ref($settings) eq 'HASH') {
456: if (ref($settings->{$role}) eq 'HASH') {
457: if ($settings->{$role}->{'img'} ne '') {
458: $designs{'img'} = $settings->{$role}->{'img'};
459: $is_custom{'img'} = 1;
460: }
461: if ($settings->{$role}->{'font'} ne '') {
462: $designs{'font'} = $settings->{$role}->{'font'};
463: $is_custom{'font'} = 1;
464: }
465: foreach my $item (@bgs) {
466: if ($settings->{$role}->{$item} ne '') {
467: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
468: $is_custom{$item} = 1;
469: }
470: }
471: foreach my $item (@links) {
472: if ($settings->{$role}->{$item} ne '') {
473: $designs{'links'}{$item} = $settings->{$role}->{$item};
474: $is_custom{$item} = 1;
475: }
476: }
477: }
478: } else {
479: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
480: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
481: $is_custom{'img'} = 1;
482: }
483: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
484: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
485: $is_custom{'font'} = 1;
486: }
487: foreach my $item (@bgs) {
488: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
489: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
490: $is_custom{$item} = 1;
491:
492: }
493: }
494: foreach my $item (@links) {
495: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
496: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
497: $is_custom{$item} = 1;
498: }
499: }
500: }
501: my $itemcount = 1;
1.9 raeburn 502: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
1.6 raeburn 503: $datatable .= '</tr></table></td></tr>';
504: return $datatable;
505: }
506:
507: sub display_color_options {
1.9 raeburn 508: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.6 raeburn 509: $images,$bgs,$links,$alt_text) = @_;
510: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
511: my $datatable = '<tr'.$css_class.'>'.
512: '<td>'.$choices->{'font'}.'</td>';
513: if (!$is_custom->{'font'}) {
514: $datatable .= '<td>'.&mt('Default in use:').' '.$defaults->{'font'}.'</td>';
515: } else {
516: $datatable .= '<td> </td>';
517: }
518: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 519: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 520: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 521: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
522: '</span></td></tr>';
1.9 raeburn 523: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 524: foreach my $img (@{$images}) {
525: $itemcount ++;
526: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 527: $datatable .= '<tr'.$css_class.'>'.
1.6 raeburn 528: '<td>'.$choices->{$img}.'</td>';
529: my $imgfile;
530: if ($designs->{$img} ne '') {
531: $imgfile = $designs->{$img};
532: } else {
533: $imgfile = $defaults->{$img};
534: }
535: if ($imgfile) {
1.9 raeburn 536: my ($showfile,$fullsize);
537: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 538: my $urldir = $1;
539: my $filename = $2;
540: my @info = &Apache::lonnet::stat_file($designs->{$img});
541: if (@info) {
542: my $thumbfile = 'tn-'.$filename;
543: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
544: if (@thumb) {
545: $showfile = $urldir.'/'.$thumbfile;
546: } else {
547: $showfile = $imgfile;
548: }
549: } else {
550: $showfile = '';
551: }
552: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 553: $showfile = $imgfile;
1.6 raeburn 554: my $imgdir = $1;
555: my $filename = $2;
556: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
557: $showfile = "/$imgdir/tn-".$filename;
558: } else {
559: my $input = "/home/httpd/html".$imgfile;
560: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
561: if (!-e $output) {
1.9 raeburn 562: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 563: my ($fullwidth,$fullheight) = &check_dimensions($input);
564: if ($fullwidth ne '' && $fullheight ne '') {
565: if ($fullwidth > $width && $fullheight > $height) {
566: my $size = $width.'x'.$height;
567: system("convert -sample $size $input $output");
568: $showfile = '/'.$imgdir.'/tn-'.$filename;
569: }
570: }
1.6 raeburn 571: }
572: }
1.16 raeburn 573: }
1.6 raeburn 574: if ($showfile) {
1.9 raeburn 575: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
576: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1.6 raeburn 577: $datatable.= '<td>';
578: if (!$is_custom->{$img}) {
579: $datatable .= &mt('Default in use:').'<br />';
580: }
1.9 raeburn 581: $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
582: $showfile.'" alt="'.$alt_text->{$img}.
583: '" border="0" /></a></td>';
1.6 raeburn 584: if ($is_custom->{$img}) {
1.8 raeburn 585: $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
586: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
587: '</label> '.&mt('Replace:').'</span><br />';
1.6 raeburn 588: } else {
589: $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
590: }
591: } else {
592: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
593: &mt('Upload:');
594: }
595: } else {
596: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
597: &mt('Upload:');
598: }
1.9 raeburn 599: if ($switchserver) {
600: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
601: } else {
602: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
603: }
604: $datatable .= '</td></tr>';
1.6 raeburn 605: }
606: $itemcount ++;
607: $css_class = $itemcount%2?' class="LC_odd_row"':'';
608: $datatable .= '<tr'.$css_class.'>'.
609: '<td>'.$choices->{'bgs'}.'</td>';
610: my $bgs_def;
611: foreach my $item (@{$bgs}) {
612: if (!$is_custom->{$item}) {
613: $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
614: }
615: }
616: if ($bgs_def) {
1.8 raeburn 617: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 618: } else {
619: $datatable .= '<td> </td>';
620: }
621: $datatable .= '<td class="LC_right_item">'.
622: '<table border="0"><tr>';
623: foreach my $item (@{$bgs}) {
624: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
625: $datatable .= '<td align="center">'.$link;
626: if ($designs->{'bgs'}{$item}) {
627: $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px"> </span>';
628: }
629: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
630: '" /></td>';
631: }
632: $datatable .= '</tr></table></td></tr>';
633: $itemcount ++;
634: $css_class = $itemcount%2?' class="LC_odd_row"':'';
635: $datatable .= '<tr'.$css_class.'>'.
636: '<td>'.$choices->{'links'}.'</td>';
637: my $links_def;
638: foreach my $item (@{$links}) {
639: if (!$is_custom->{$item}) {
640: $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
641: }
642: }
643: if ($links_def) {
1.8 raeburn 644: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 645: } else {
646: $datatable .= '<td> </td>';
647: }
648: $datatable .= '<td class="LC_right_item">'.
649: '<table border="0"><tr>';
650: foreach my $item (@{$links}) {
651: $datatable .= '<td align="center">';
652: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
653: if ($designs->{'links'}{$item}) {
654: $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
655: $link.'</span>';
656: } else {
657: $datatable .= $link;
658: }
659: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
660: '" /></td>';
661: }
1.3 raeburn 662: return $datatable;
663: }
664:
1.6 raeburn 665: sub color_pick {
666: my ($phase,$role,$item,$desc,$curcol) = @_;
667: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
668: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
669: ');">'.$desc.'</a>';
670: return $link;
671: }
672:
673: sub color_pick_js {
674: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
675: my $output = <<"ENDCOL";
676: function pclose() {
677: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
678: parmwin.close();
679: }
680:
681: $pjump_def
682:
683: function psub() {
684: pclose();
685: if (document.parmform.pres_marker.value!='') {
686: if (document.parmform.pres_type.value!='') {
687: eval('document.display.'+
688: document.parmform.pres_marker.value+
689: '.value=document.parmform.pres_value.value;');
690: }
691: } else {
692: document.parmform.pres_value.value='';
693: document.parmform.pres_marker.value='';
694: }
695: }
696: ENDCOL
697: return $output;
698: }
699:
1.3 raeburn 700: sub print_quotas {
701: my ($dom,$settings) = @_;
702: my $datatable;
703: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
704: my $othertitle = "All users";
705: my @types;
706: if (ref($order) eq 'ARRAY') {
707: @types = @{$order};
708: }
709: if (@types == 0) {
710: if (ref($usertypes) eq 'HASH') {
711: @types = sort(keys(%{$usertypes}));
712: }
713: }
714: my $typecount = 0;
715: my $css_class;
716: if (@types > 0) {
717: foreach my $type (@types) {
718: if (defined($usertypes->{$type})) {
719: $typecount ++;
720: $css_class = $typecount%2?' class="LC_odd_row"':'';
721: $datatable .= '<tr'.$css_class.'>'.
722: '<td>'.$usertypes->{$type}.'</td>'.
1.8 raeburn 723: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 724: '<input type="text" name="quota_'.$type.
725: '" value="'.$settings->{$type}.
1.8 raeburn 726: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 727: }
728: }
729: $othertitle = "Other users";
730: }
731: my $defaultquota = '20';
732: if (ref($settings) eq 'HASH') {
733: if (defined($settings->{'default'})) {
734: $defaultquota = $settings->{'default'};
735: }
736: }
737: $typecount ++;
738: $css_class = $typecount%2?' class="LC_odd_row"':'';
739: $datatable .= '<tr'.$css_class.'>'.
740: '<td>'.&mt($othertitle).'</td>'.
1.8 raeburn 741: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.15 raeburn 742: '<input type="text" name="defaultquota" value="'.
1.8 raeburn 743: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.3 raeburn 744: return $datatable;
745: }
746:
747: sub print_autoenroll {
748: my ($dom,$settings) = @_;
749: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 ! raeburn 750: my ($defdom,$runon,$runoff);
1.3 raeburn 751: if (ref($settings) eq 'HASH') {
752: if (exists($settings->{'run'})) {
753: if ($settings->{'run'} eq '0') {
754: $runoff = ' checked="checked" ';
755: $runon = ' ';
756: } else {
757: $runon = ' checked="checked" ';
758: $runoff = ' ';
759: }
760: } else {
761: if ($autorun) {
762: $runon = ' checked="checked" ';
763: $runoff = ' ';
764: } else {
765: $runoff = ' checked="checked" ';
766: $runon = ' ';
767: }
768: }
769: if (exists($settings->{'sender_domain'})) {
770: $defdom = $settings->{'sender_domain'};
771: }
1.14 raeburn 772: } else {
773: if ($autorun) {
774: $runon = ' checked="checked" ';
775: $runoff = ' ';
776: } else {
777: $runoff = ' checked="checked" ';
778: $runon = ' ';
779: }
1.3 raeburn 780: }
781: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
782: my $datatable='<tr class="LC_odd_row">'.
783: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 784: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 785: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 786: $runon.' value="1" />'.&mt('Yes').'</label> '.
787: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 788: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 789: '</tr><tr>'.
790: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 791: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 792: &mt('username').': '.
793: '<input type="text" name="sender_uname" value="'.
794: $settings->{'sender_uname'}.
795: '" size="10" /> '.&mt('domain').
1.8 raeburn 796: ': '.$domform.'</span></td></tr>';
1.3 raeburn 797: return $datatable;
798: }
799:
800: sub print_autoupdate {
801: my ($position,$dom,$settings) = @_;
802: my $datatable;
803: if ($position eq 'top') {
804: my $updateon = ' ';
805: my $updateoff = ' checked="checked" ';
806: my $classlistson = ' ';
807: my $classlistsoff = ' checked="checked" ';
808: if (ref($settings) eq 'HASH') {
809: if ($settings->{'run'} eq '1') {
810: $updateon = $updateoff;
811: $updateoff = ' ';
812: }
813: if ($settings->{'classlists'} eq '1') {
814: $classlistson = $classlistsoff;
815: $classlistsoff = ' ';
816: }
817: }
818: my %title = (
819: run => 'Auto-update active?',
820: classlists => 'Update information in classlists?',
821: );
822: $datatable = '<tr class="LC_odd_row">'.
823: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 824: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 825: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 826: $updateon.' value="1" />'.&mt('Yes').'</label> '.
827: '<label><input type="radio" name="autoupdate_run"'.
828: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 829: '</tr><tr>'.
830: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 831: '<td class="LC_right_item"><span class="LC_nobreak">'.
832: '<label><input type="radio" name="classlists"'.
833: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
834: '<label><input type="radio" name="classlists"'.
835: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 836: '</tr>';
837: } else {
838: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
839: my @types;
840: if (ref($order) eq 'ARRAY') {
841: @types = @{$order};
842: }
843: if (@types == 0) {
844: if (ref($usertypes) eq 'HASH') {
845: @types = sort(keys(%{$usertypes}));
846: }
847: }
848: my $othertitle = &mt('All users');
849: if (keys(%{$usertypes}) > 0) {
850: $othertitle = &mt('Other users');
851: }
852: my @fields = ('lastname','firstname','middlename','gen','email','id');
853: my %fieldtitles = &Apache::lonlocal::texthash (
854: id => 'Student/Employee ID',
855: email => 'E-mail address',
856: lastname => 'Last Name',
857: firstname => 'First Name',
858: middlename => 'Middle Name',
859: gen => 'Generation',
860: );
861: my $numrows = 0;
862: if (@types > 0) {
863: $datatable =
864: &usertype_update_row($settings,$usertypes,\%fieldtitles,
865: \@fields,\@types,\$numrows);
866: }
867: $datatable .=
868: &usertype_update_row($settings,{'default' => $othertitle},
869: \%fieldtitles,\@fields,['default'],
870: \$numrows);
871: }
872: return $datatable;
873: }
874:
875: sub usertype_update_row {
876: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
877: my $datatable;
878: my $numinrow = 4;
879: foreach my $type (@{$types}) {
880: if (defined($usertypes->{$type})) {
881: $$rownums ++;
882: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
883: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
884: '</td><td class="LC_left_item"><table>';
885: for (my $i=0; $i<@{$fields}; $i++) {
886: my $rem = $i%($numinrow);
887: if ($rem == 0) {
888: if ($i > 0) {
889: $datatable .= '</tr>';
890: }
891: $datatable .= '<tr>';
892: }
893: my $check = ' ';
894: if (ref($settings->{'fields'}) eq 'HASH') {
895: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
896: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
897: $check = ' checked="checked" ';
898: }
899: }
900: }
901:
902: if ($i == @{$fields}-1) {
903: my $colsleft = $numinrow - $rem;
904: if ($colsleft > 1) {
905: $datatable .= '<td colspan="'.$colsleft.'">';
906: } else {
907: $datatable .= '<td>';
908: }
909: } else {
910: $datatable .= '<td>';
911: }
1.8 raeburn 912: $datatable .= '<span class="LC_nobreak"><label>'.
913: '<input type="checkbox" name="updateable_'.$type.
914: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
915: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 916: }
917: $datatable .= '</tr></table></td></tr>';
918: }
919: }
920: return $datatable;
1.1 raeburn 921: }
922:
923: sub modify_login {
1.9 raeburn 924: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 925: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 926: my %title = ( coursecatalog => 'Display course catalog',
927: adminmail => 'Display administrator E-mail address');
1.3 raeburn 928: my @offon = ('off','on');
1.6 raeburn 929: my %loginhash;
1.9 raeburn 930: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
931: \%domconfig,\%loginhash);
1.6 raeburn 932: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
933: $loginhash{login}{adminmail} = $env{'form.adminmail'};
934: if (ref($colchanges{'login'}) eq 'HASH') {
935: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
936: \%loginhash);
937: }
1.1 raeburn 938: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
939: $dom);
940: if ($putresult eq 'ok') {
1.3 raeburn 941: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 942: ($env{'form.coursecatalog'} eq '1')) {
943: $changes{'coursecatalog'} = 1;
1.3 raeburn 944: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
945: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 946: ($env{'form.coursecatalog'} eq '0')) {
947: $changes{'coursecatalog'} = 1;
948: }
1.3 raeburn 949: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 950: ($env{'form.adminmail'} eq '0')) {
951: $changes{'adminmail'} = 1;
952: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
953: $domconfig{'login'}{'adminmail'} eq '0') &&
954: ($env{'form.adminmail'} eq '1')) {
955: $changes{'adminmail'} = 1;
956: }
1.6 raeburn 957: if (keys(%changes) > 0 || $colchgtext) {
1.1 raeburn 958: $resulttext = &mt('Changes made:').'<ul>';
959: foreach my $item (sort(keys(%changes))) {
960: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
961: }
1.6 raeburn 962: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 963: } else {
964: $resulttext = &mt('No changes made to log-in page settings');
965: }
966: } else {
1.11 albertel 967: $resulttext = '<span class="LC_error">'.
968: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 969: }
1.6 raeburn 970: if ($errors) {
1.9 raeburn 971: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 972: $errors.'</ul>';
973: }
974: return $resulttext;
975: }
976:
977: sub color_font_choices {
978: my %choices =
979: &Apache::lonlocal::texthash (
980: img => "Header",
981: bgs => "Background colors",
982: links => "Link colors",
983: font => "Font color",
984: pgbg => "Page",
985: tabbg => "Header",
986: sidebg => "Border",
987: link => "Link",
988: alink => "Active link",
989: vlink => "Visited link",
990: );
991: return %choices;
992: }
993:
994: sub modify_rolecolors {
1.9 raeburn 995: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 996: my ($resulttext,%rolehash);
997: $rolehash{'rolecolors'} = {};
1.9 raeburn 998: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 999: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
1000: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
1001: $dom);
1002: if ($putresult eq 'ok') {
1003: if (keys(%changes) > 0) {
1004: $resulttext = &display_colorchgs($dom,\%changes,$roles,
1005: $rolehash{'rolecolors'});
1006: } else {
1007: $resulttext = &mt('No changes made to default color schemes');
1008: }
1009: } else {
1.11 albertel 1010: $resulttext = '<span class="LC_error">'.
1011: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 1012: }
1013: if ($errors) {
1014: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
1015: $errors.'</ul>';
1016: }
1017: return $resulttext;
1018: }
1019:
1020: sub modify_colors {
1.9 raeburn 1021: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 1022: my (%changes,%choices);
1.6 raeburn 1023: my @bgs = ('pgbg','mainbg','sidebg');
1024: my @links = ('link','alink','vlink');
1025: my @images;
1026: my $servadm = $r->dir_config('lonAdmEMail');
1027: my $errors;
1028: foreach my $role (@{$roles}) {
1029: if ($role eq 'login') {
1.12 raeburn 1030: %choices = &login_choices();
1031: } else {
1032: %choices = &color_font_choices();
1033: }
1034: if ($role eq 'login') {
1.6 raeburn 1035: @images = ('img','logo','domlogo');
1036: } else {
1037: @images = ('img');
1038: }
1039: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1040: foreach my $item (@bgs,@links) {
1041: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
1042: }
1.9 raeburn 1043: my ($configuserok,$author_ok,$switchserver,%currroles);
1044: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
1045: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
1046: $confname,$servadm);
1047: if ($configuserok eq 'ok') {
1048: $switchserver = &check_switchserver($dom,$confname);
1049: if ($switchserver eq '') {
1050: $author_ok = &check_authorstatus($dom,$confname,%currroles);
1051: }
1052: }
1053: my ($width,$height) = &thumb_dimensions();
1.8 raeburn 1054: foreach my $img (@images) {
1.6 raeburn 1055: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 1056: my $error;
1.6 raeburn 1057: if ($configuserok eq 'ok') {
1.9 raeburn 1058: if ($switchserver) {
1.12 raeburn 1059: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 1060: } else {
1061: if ($author_ok eq 'ok') {
1062: my ($result,$logourl) =
1063: &publishlogo($r,'upload',$role.'_'.$img,
1064: $dom,$confname,$img,$width,$height);
1065: if ($result eq 'ok') {
1066: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 1067: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1068: } else {
1.12 raeburn 1069: $error = &mt("Upload of [_1] image for $role page(s) failed because an error occurred publishing the file in RES space. Error was: [_2].",$choices{img},$result);
1.9 raeburn 1070: }
1071: } else {
1.12 raeburn 1072: $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuation user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
1.6 raeburn 1073: }
1074: }
1075: } else {
1.12 raeburn 1076: $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuation user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
1.9 raeburn 1077: }
1078: if ($error) {
1.8 raeburn 1079: &Apache::lonnet::logthis($error);
1.11 albertel 1080: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 1081: }
1082: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 1083: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1084: my $error;
1085: if ($configuserok eq 'ok') {
1086: # is confname an author?
1087: if ($switchserver eq '') {
1088: if ($author_ok eq 'ok') {
1089: my ($result,$logourl) =
1090: &publishlogo($r,'copy',$domconfig->{$role}{$img},
1091: $dom,$confname,$img,$width,$height);
1092: if ($result eq 'ok') {
1093: $confhash->{$role}{$img} = $logourl;
1094: }
1095: }
1096: }
1097: }
1.6 raeburn 1098: }
1099: }
1100: }
1101: if (ref($domconfig) eq 'HASH') {
1102: if (ref($domconfig->{$role}) eq 'HASH') {
1103: foreach my $img (@images) {
1104: if ($domconfig->{$role}{$img} ne '') {
1105: if ($env{'form.'.$role.'_del_'.$img}) {
1106: $confhash->{$role}{$img} = '';
1.12 raeburn 1107: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1108: } else {
1.9 raeburn 1109: if ($confhash->{$role}{$img} eq '') {
1110: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
1111: }
1.6 raeburn 1112: }
1113: } else {
1114: if ($env{'form.'.$role.'_del_'.$img}) {
1115: $confhash->{$role}{$img} = '';
1.12 raeburn 1116: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1117: }
1118: }
1119: }
1120: if ($domconfig->{$role}{'font'} ne '') {
1121: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
1122: $changes{$role}{'font'} = 1;
1123: }
1124: } else {
1125: if ($confhash->{$role}{'font'}) {
1126: $changes{$role}{'font'} = 1;
1127: }
1128: }
1129: foreach my $item (@bgs) {
1130: if ($domconfig->{$role}{$item} ne '') {
1131: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1132: $changes{$role}{'bgs'}{$item} = 1;
1133: }
1134: } else {
1135: if ($confhash->{$role}{$item}) {
1136: $changes{$role}{'bgs'}{$item} = 1;
1137: }
1138: }
1139: }
1140: foreach my $item (@links) {
1141: if ($domconfig->{$role}{$item} ne '') {
1142: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1143: $changes{$role}{'links'}{$item} = 1;
1144: }
1145: } else {
1146: if ($confhash->{$role}{$item}) {
1147: $changes{$role}{'links'}{$item} = 1;
1148: }
1149: }
1150: }
1151: } else {
1152: &default_change_checker($role,\@images,\@links,\@bgs,
1153: $confhash,\%changes);
1154: }
1155: } else {
1156: &default_change_checker($role,\@images,\@links,\@bgs,
1157: $confhash,\%changes);
1158: }
1159: }
1160: return ($errors,%changes);
1161: }
1162:
1163: sub default_change_checker {
1164: my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
1165: foreach my $item (@{$links}) {
1166: if ($confhash->{$role}{$item}) {
1167: $changes->{$role}{'links'}{$item} = 1;
1168: }
1169: }
1170: foreach my $item (@{$bgs}) {
1171: if ($confhash->{$role}{$item}) {
1172: $changes->{$role}{'bgs'}{$item} = 1;
1173: }
1174: }
1175: foreach my $img (@{$images}) {
1176: if ($env{'form.'.$role.'_del_'.$img}) {
1177: $confhash->{$role}{$img} = '';
1.12 raeburn 1178: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 1179: }
1180: }
1181: if ($confhash->{$role}{'font'}) {
1182: $changes->{$role}{'font'} = 1;
1183: }
1184: }
1185:
1186: sub display_colorchgs {
1187: my ($dom,$changes,$roles,$confhash) = @_;
1188: my (%choices,$resulttext);
1.7 albertel 1189: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 1190: if (!grep(/^login$/,@{$roles})) {
1191: $resulttext = &mt('Changes made:').'<br />';
1192: }
1193: foreach my $role (@{$roles}) {
1194: if ($role eq 'login') {
1195: %choices = &login_choices();
1196: } else {
1197: %choices = &color_font_choices();
1198: }
1199: if (ref($changes->{$role}) eq 'HASH') {
1200: if ($role ne 'login') {
1201: $resulttext .= '<h4>'.&mt($role).'</h4>';
1202: }
1203: foreach my $key (sort(keys(%{$changes->{$role}}))) {
1204: if ($role ne 'login') {
1205: $resulttext .= '<ul>';
1206: }
1207: if (ref($changes->{$role}{$key}) eq 'HASH') {
1208: if ($role ne 'login') {
1209: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
1210: }
1211: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1212: if ($confhash->{$role}{$item} eq '') {
1213: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
1214: } else {
1.12 raeburn 1215: my $newitem = $confhash->{$role}{$item};
1216: if ($key eq 'images') {
1217: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
1218: }
1219: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 1220: }
1221: }
1222: if ($role ne 'login') {
1223: $resulttext .= '</ul></li>';
1224: }
1225: } else {
1226: if ($confhash->{$role}{$key} eq '') {
1227: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
1228: } else {
1229: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
1230: }
1231: }
1232: if ($role ne 'login') {
1233: $resulttext .= '</ul>';
1234: }
1235: }
1236: }
1237: }
1.3 raeburn 1238: return $resulttext;
1.1 raeburn 1239: }
1240:
1.9 raeburn 1241: sub thumb_dimensions {
1242: return ('200','50');
1243: }
1244:
1.16 raeburn 1245: sub check_dimensions {
1246: my ($inputfile) = @_;
1247: my ($fullwidth,$fullheight);
1248: if ($inputfile =~ m|^[/\w.\-]+$|) {
1249: if (open(PIPE,"identify $inputfile 2>&1 |")) {
1250: my $imageinfo = <PIPE>;
1251: if (!close(PIPE)) {
1252: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
1253: }
1254: chomp($imageinfo);
1255: my ($fullsize) =
1256: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)\s+/);
1257: if ($fullsize) {
1258: ($fullwidth,$fullheight) = split(/x/,$fullsize);
1259: }
1260: }
1261: }
1262: return ($fullwidth,$fullheight);
1263: }
1264:
1.9 raeburn 1265: sub check_configuser {
1266: my ($uhome,$dom,$confname,$servadm) = @_;
1267: my ($configuserok,%currroles);
1268: if ($uhome eq 'no_host') {
1269: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1270: my $configpass = &LONCAPA::Enrollment::create_password();
1271: $configuserok =
1272: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
1273: $configpass,'','','','','',undef,$servadm);
1274: } else {
1275: $configuserok = 'ok';
1276: %currroles =
1277: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
1278: }
1279: return ($configuserok,%currroles);
1280: }
1281:
1282: sub check_authorstatus {
1283: my ($dom,$confname,%currroles) = @_;
1284: my $author_ok;
1285: if (!$currroles{':'.$dom.':au'}) {
1286: my $start = time;
1287: my $end = 0;
1288: $author_ok =
1289: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1290: 'au',$end,$start);
1291: } else {
1292: $author_ok = 'ok';
1293: }
1294: return $author_ok;
1295: }
1296:
1297: sub publishlogo {
1298: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
1299: my ($output,$fname,$logourl);
1300: if ($action eq 'upload') {
1301: $fname=$env{'form.'.$formname.'.filename'};
1302: chop($env{'form.'.$formname});
1303: } else {
1304: ($fname) = ($formname =~ /([^\/]+)$/);
1305: }
1306: $fname=&Apache::lonnet::clean_filename($fname);
1307: # See if there is anything left
1308: unless ($fname) { return ('error: no uploaded file'); }
1309: $fname="$subdir/$fname";
1310: my $filepath='/home/'.$confname.'/public_html';
1311: my ($fnamepath,$file,$fetchthumb);
1312: $file=$fname;
1313: if ($fname=~m|/|) {
1314: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
1315: }
1316: my @parts=split(/\//,$filepath.'/'.$fnamepath);
1317: my $count;
1318: for ($count=4;$count<=$#parts;$count++) {
1319: $filepath.="/$parts[$count]";
1320: if ((-e $filepath)!=1) {
1321: mkdir($filepath,02770);
1322: }
1323: }
1324: # Check for bad extension and disallow upload
1325: if ($file=~/\.(\w+)$/ &&
1326: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1327: $output =
1328: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
1329: } elsif ($file=~/\.(\w+)$/ &&
1330: !defined(&Apache::loncommon::fileembstyle($1))) {
1331: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
1332: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1333: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1334: } elsif (-d "$filepath/$file") {
1335: $output = &mt('File name is a directory name - rename the file and re-upload');
1336: } else {
1337: my $source = $filepath.'/'.$file;
1338: my $logfile;
1339: if (!open($logfile,">>$source".'.log')) {
1340: return (&mt('No write permission to Construction Space'));
1341: }
1342: print $logfile
1343: "\n================= Publish ".localtime()." ================\n".
1344: $env{'user.name'}.':'.$env{'user.domain'}."\n";
1345: # Save the file
1346: if (!open(FH,'>'.$source)) {
1347: &Apache::lonnet::logthis('Failed to create '.$source);
1348: return (&mt('Failed to create file'));
1349: }
1350: if ($action eq 'upload') {
1351: if (!print FH ($env{'form.'.$formname})) {
1352: &Apache::lonnet::logthis('Failed to write to '.$source);
1353: return (&mt('Failed to write file'));
1354: }
1355: } else {
1356: my $original = &Apache::lonnet::filelocation('',$formname);
1357: if(!copy($original,$source)) {
1358: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
1359: return (&mt('Failed to write file'));
1360: }
1361: }
1362: close(FH);
1363: chmod(0660, $source); # Permissions to rw-rw---.
1364:
1365: my $docroot=$r->dir_config('lonDocRoot');
1366: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
1367: my $copyfile=$targetdir.'/'.$file;
1368:
1369: my @parts=split(/\//,$targetdir);
1370: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
1371: for (my $count=5;$count<=$#parts;$count++) {
1372: $path.="/$parts[$count]";
1373: if (!-e $path) {
1374: print $logfile "\nCreating directory ".$path;
1375: mkdir($path,02770);
1376: }
1377: }
1378: my $versionresult;
1379: if (-e $copyfile) {
1380: $versionresult = &logo_versioning($targetdir,$file,$logfile);
1381: } else {
1382: $versionresult = 'ok';
1383: }
1384: if ($versionresult eq 'ok') {
1385: if (copy($source,$copyfile)) {
1386: print $logfile "\nCopied original source to ".$copyfile."\n";
1387: $output = 'ok';
1388: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
1389: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1390: } else {
1391: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1392: $output = &mt('Failed to copy file to RES space').", $!";
1393: }
1394: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
1395: my $inputfile = $filepath.'/'.$file;
1396: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 1397: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
1398: if ($fullwidth ne '' && $fullheight ne '') {
1399: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
1400: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1401: system("convert -sample $thumbsize $inputfile $outfile");
1402: chmod(0660, $filepath.'/tn-'.$file);
1403: if (-e $outfile) {
1404: my $copyfile=$targetdir.'/tn-'.$file;
1405: if (copy($outfile,$copyfile)) {
1406: print $logfile "\nCopied source to ".$copyfile."\n";
1407: &write_metadata($dom,$confname,$formname,
1408: $targetdir,'tn-'.$file,$logfile);
1409: } else {
1410: print $logfile "\nUnable to write ".$copyfile.
1411: ':'.$!."\n";
1412: }
1413: }
1.9 raeburn 1414: }
1415: }
1416: }
1417: } else {
1418: $output = $versionresult;
1419: }
1420: }
1421: return ($output,$logourl);
1422: }
1423:
1424: sub logo_versioning {
1425: my ($targetdir,$file,$logfile) = @_;
1426: my $target = $targetdir.'/'.$file;
1427: my ($maxversion,$fn,$extn,$output);
1428: $maxversion = 0;
1429: if ($file =~ /^(.+)\.(\w+)$/) {
1430: $fn=$1;
1431: $extn=$2;
1432: }
1433: opendir(DIR,$targetdir);
1434: while (my $filename=readdir(DIR)) {
1435: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
1436: $maxversion=($1>$maxversion)?$1:$maxversion;
1437: }
1438: }
1439: $maxversion++;
1440: print $logfile "\nCreating old version ".$maxversion."\n";
1441: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
1442: if (copy($target,$copyfile)) {
1443: print $logfile "Copied old target to ".$copyfile."\n";
1444: $copyfile=$copyfile.'.meta';
1445: if (copy($target.'.meta',$copyfile)) {
1446: print $logfile "Copied old target metadata to ".$copyfile."\n";
1447: $output = 'ok';
1448: } else {
1449: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1450: $output = &mt('Failed to copy old meta').", $!, ";
1451: }
1452: } else {
1453: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
1454: $output = &mt('Failed to copy old target').", $!, ";
1455: }
1456: return $output;
1457: }
1458:
1459: sub write_metadata {
1460: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
1461: my (%metadatafields,%metadatakeys,$output);
1462: $metadatafields{'title'}=$formname;
1463: $metadatafields{'creationdate'}=time;
1464: $metadatafields{'lastrevisiondate'}=time;
1465: $metadatafields{'copyright'}='public';
1466: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
1467: $env{'user.domain'};
1468: $metadatafields{'authorspace'}=$confname.':'.$dom;
1469: $metadatafields{'domain'}=$dom;
1470: {
1471: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
1472: my $mfh;
1473: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1474: $output = &mt('Could not write metadata');
1475: }
1476: foreach (sort keys %metadatafields) {
1477: unless ($_=~/\./) {
1478: my $unikey=$_;
1479: $unikey=~/^([A-Za-z]+)/;
1480: my $tag=$1;
1481: $tag=~tr/A-Z/a-z/;
1482: print $mfh "\n\<$tag";
1483: foreach (split(/\,/,$metadatakeys{$unikey})) {
1484: my $value=$metadatafields{$unikey.'.'.$_};
1485: $value=~s/\"/\'\'/g;
1486: print $mfh ' '.$_.'="'.$value.'"';
1487: }
1488: print $mfh '>'.
1489: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
1490: .'</'.$tag.'>';
1491: }
1492: }
1493: $output = 'ok';
1494: print $logfile "\nWrote metadata";
1495: close($mfh);
1496: }
1497: }
1498:
1499: sub check_switchserver {
1500: my ($dom,$confname) = @_;
1501: my ($allowed,$switchserver);
1502: my $home = &Apache::lonnet::homeserver($confname,$dom);
1503: if ($home eq 'no_host') {
1504: $home = &Apache::lonnet::domain($dom,'primary');
1505: }
1506: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 1507: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1508: if (!$allowed) {
1509: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 1510: }
1511: return $switchserver;
1512: }
1513:
1.1 raeburn 1514: sub modify_quotas {
1.3 raeburn 1515: my ($dom,%domconfig) = @_;
1.1 raeburn 1516: my ($resulttext,%changes);
1.3 raeburn 1517: my ($usertypes,$order) =
1518: &Apache::lonnet::retrieve_inst_usertypes($dom);
1.1 raeburn 1519: my %formhash;
1520: foreach my $key (keys(%env)) {
1521: if ($key =~ /^form\.quota_(.+)$/) {
1522: $formhash{$1} = $env{$key};
1523: }
1524: }
1.15 raeburn 1525: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 1526: if (ref($domconfig{'quotas'}) eq 'HASH') {
1527: foreach my $key (keys(%{$domconfig{'quotas'}})) {
1528: if (exists($formhash{$key})) {
1529: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
1530: $changes{$key} = 1;
1531: }
1532: } else {
1533: $formhash{$key} = $domconfig{'quotas'}{$key};
1534: }
1535: }
1536: }
1537: foreach my $key (keys(%formhash)) {
1538: if ($formhash{$key} ne '') {
1.3 raeburn 1539: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 1540: $changes{$key} = 1;
1541: }
1542: }
1543: }
1544: my %quotahash = (
1.3 raeburn 1545: quotas => {%formhash},
1.1 raeburn 1546: );
1547: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
1548: $dom);
1549: if ($putresult eq 'ok') {
1550: if (keys(%changes) > 0) {
1551: $resulttext = &mt('Changes made:').'<ul>';
1552: foreach my $item (sort(keys(%changes))) {
1553: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
1554: }
1555: $resulttext .= '</ul>';
1556: } else {
1557: $resulttext = &mt('No changes made to default quotas');
1558: }
1559: } else {
1.11 albertel 1560: $resulttext = '<span class="LC_error">'.
1561: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1562: }
1.3 raeburn 1563: return $resulttext;
1.1 raeburn 1564: }
1565:
1.3 raeburn 1566: sub modify_autoenroll {
1567: my ($dom,%domconfig) = @_;
1.1 raeburn 1568: my ($resulttext,%changes);
1569: my %currautoenroll;
1570: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
1571: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
1572: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
1573: }
1574: }
1575: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1576: my %title = ( run => 'Auto-enrollment active',
1577: sender => 'Sender for notification messages');
1578: my @offon = ('off','on');
1.17 ! raeburn 1579: my $sender_uname = $env{'form.sender_uname'};
! 1580: my $sender_domain = $env{'form.sender_domain'};
! 1581: if ($sender_domain eq '') {
! 1582: $sender_uname = '';
! 1583: } elsif ($sender_uname eq '') {
! 1584: $sender_domain = '';
! 1585: }
1.1 raeburn 1586: my %autoenrollhash = (
1587: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 ! raeburn 1588: sender_uname => $sender_uname,
! 1589: sender_domain => $sender_domain,
1.1 raeburn 1590:
1591: }
1592: );
1.4 raeburn 1593: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
1594: $dom);
1.1 raeburn 1595: if ($putresult eq 'ok') {
1596: if (exists($currautoenroll{'run'})) {
1597: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
1598: $changes{'run'} = 1;
1599: }
1600: } elsif ($autorun) {
1601: if ($env{'form.autoenroll_run'} ne '1') {
1602: $changes{'run'} = 1;
1603: }
1604: }
1.17 ! raeburn 1605: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 1606: $changes{'sender'} = 1;
1607: }
1.17 ! raeburn 1608: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 1609: $changes{'sender'} = 1;
1610: }
1611: if (keys(%changes) > 0) {
1612: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 1613: if ($changes{'run'}) {
1.1 raeburn 1614: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
1615: }
1616: if ($changes{'sender'}) {
1.17 ! raeburn 1617: if ($sender_uname eq '' || $sender_domain eq '') {
! 1618: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
! 1619: } else {
! 1620: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
! 1621: }
1.1 raeburn 1622: }
1623: $resulttext .= '</ul>';
1624: } else {
1625: $resulttext = &mt('No changes made to auto-enrollment settings');
1626: }
1627: } else {
1.11 albertel 1628: $resulttext = '<span class="LC_error">'.
1629: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1630: }
1.3 raeburn 1631: return $resulttext;
1.1 raeburn 1632: }
1633:
1634: sub modify_autoupdate {
1.3 raeburn 1635: my ($dom,%domconfig) = @_;
1.1 raeburn 1636: my ($resulttext,%currautoupdate,%fields,%changes);
1637: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
1638: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
1639: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
1640: }
1641: }
1642: my @offon = ('off','on');
1643: my %title = &Apache::lonlocal::texthash (
1644: run => 'Auto-update:',
1645: classlists => 'Updates to user information in classlists?'
1646: );
1647: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1648: my %fieldtitles = &Apache::lonlocal::texthash (
1649: id => 'Student/Employee ID',
1650: email => 'E-mail address',
1651: lastname => 'Last Name',
1652: firstname => 'First Name',
1653: middlename => 'Middle Name',
1654: gen => 'Generation',
1655: );
1656: my $othertitle = &mt('All users');
1657: if (keys(%{$usertypes}) > 0) {
1658: $othertitle = "Other users";
1659: }
1660: foreach my $key (keys(%env)) {
1661: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1662: push(@{$fields{$1}},$2);
1663: }
1664: }
1665: my %updatehash = (
1666: autoupdate => { run => $env{'form.autoupdate_run'},
1667: classlists => $env{'form.classlists'},
1668: fields => {%fields},
1669: }
1670: );
1671: foreach my $key (keys(%currautoupdate)) {
1672: if (($key eq 'run') || ($key eq 'classlists')) {
1673: if (exists($updatehash{autoupdate}{$key})) {
1674: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
1675: $changes{$key} = 1;
1676: }
1677: }
1678: } elsif ($key eq 'fields') {
1679: if (ref($currautoupdate{$key}) eq 'HASH') {
1680: foreach my $item (keys(%{$currautoupdate{$key}})) {
1681: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
1682: my $change = 0;
1683: foreach my $type (@{$currautoupdate{$key}{$item}}) {
1684: if (!exists($fields{$item})) {
1685: $change = 1;
1686: } elsif (ref($fields{$item}) eq 'ARRAY') {
1687: if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
1688: $change = 1;
1689: }
1690: }
1691: }
1692: if ($change) {
1693: push(@{$changes{$key}},$item);
1694: }
1695: }
1696: }
1697: }
1698: }
1699: }
1700: foreach my $key (keys(%fields)) {
1701: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1702: if (!exists($currautoupdate{'fields'}{$key})) {
1703: push(@{$changes{'fields'}},$key);
1704: }
1705: } else {
1706: push(@{$changes{'fields'}},$key);
1707: }
1708: }
1709: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
1710: $dom);
1711: if ($putresult eq 'ok') {
1712: if (keys(%changes) > 0) {
1713: $resulttext = &mt('Changes made:').'<ul>';
1714: foreach my $key (sort(keys(%changes))) {
1715: if (ref($changes{$key}) eq 'ARRAY') {
1716: foreach my $item (@{$changes{$key}}) {
1717: my @newvalues;
1718: foreach my $type (@{$fields{$item}}) {
1719: push(@newvalues,$fieldtitles{$type});
1720: }
1.3 raeburn 1721: my $newvaluestr;
1722: if (@newvalues > 0) {
1723: $newvaluestr = join(', ',@newvalues);
1724: } else {
1725: $newvaluestr = &mt('none');
1.6 raeburn 1726: }
1.1 raeburn 1727: if ($item eq 'default') {
1728: $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
1729: } else {
1730: $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
1731: }
1732: }
1733: } else {
1734: my $newvalue;
1735: if ($key eq 'run') {
1736: $newvalue = $offon[$env{'form.autoupdate_run'}];
1737: } else {
1738: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 1739: }
1.1 raeburn 1740: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
1741: }
1742: }
1743: $resulttext .= '</ul>';
1744: } else {
1.3 raeburn 1745: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 1746: }
1747: } else {
1.11 albertel 1748: $resulttext = '<span class="LC_error">'.
1749: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1750: }
1.3 raeburn 1751: return $resulttext;
1.1 raeburn 1752: }
1753:
1.3 raeburn 1754: 1;
1.1 raeburn 1755:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>