Annotation of loncom/interface/domainprefs.pm, revision 1.29
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.29 ! raeburn 4: # $Id: domainprefs.pm,v 1.28 2007/09/16 17:26:56 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',
1.27 raeburn 70: 'quotas','autoenroll','autoupdate','directorysrch',
1.28 raeburn 71: 'usercreation','contacts'],$dom);
1.3 raeburn 72: my @prefs = (
1.6 raeburn 73: { text => 'Default color schemes',
74: help => 'Default_Color_Schemes',
75: action => 'rolecolors',
76: header => [{col1 => 'Student Settings',
77: col2 => '',},
78: {col1 => 'Coordinator Settings',
79: col2 => '',},
80: {col1 => 'Author Settings',
81: col2 => '',},
82: {col1 => 'Administrator Settings',
83: col2 => '',}],
84: },
1.3 raeburn 85: { text => 'Log-in page options',
86: help => 'Domain_Log-in_Page',
87: action => 'login',
88: header => [{col1 => 'Item',
1.6 raeburn 89: col2 => '',}],
1.3 raeburn 90: },
91: { text => 'Default quotas for user portfolios',
92: help => 'Default_User_Quota',
93: action => 'quotas',
94: header => [{col1 => 'User type',
95: col2 => 'Default quota'}],
96: },
97: { text => 'Auto-enrollment settings',
98: help => 'Domain_Auto_Enrollment',
99: action => 'autoenroll',
100: header => [{col1 => 'Configuration setting',
101: col2 => 'Value(s)'}],
102: },
103: { text => 'Auto-update settings',
104: help => 'Domain_Auto_Update',
105: action => 'autoupdate',
106: header => [{col1 => 'Setting',
107: col2 => 'Value',},
108: {col1 => 'User Population',
109: col2 => 'Updataeable user data'}],
1.23 raeburn 110: },
111: { text => 'Institutional directory searches',
112: help => 'Domain_Directory_Search',
113: action => 'directorysrch',
114: header => [{col1 => 'Setting',
115: col2 => 'Value',}],
116: },
1.28 raeburn 117: { text => 'Contact Information',
118: help => 'Domain_Contact_Information',
119: action => 'contacts',
120: header => [{col1 => 'Setting',
121: col2 => 'Value',}],
122: },
123:
1.27 raeburn 124: { text => 'User creation',
125: help => 'Domain_User_Creation',
126: action => 'usercreation',
127: header => [{col1 => 'Setting',
1.28 raeburn 128: col2 => 'Value',},
129: {col1 => 'Context',
130: col2 => 'Assignable Authentication Types'}],
1.27 raeburn 131: },
1.3 raeburn 132: );
1.6 raeburn 133: my @roles = ('student','coordinator','author','admin');
1.3 raeburn 134: &Apache::lonhtmlcommon::add_breadcrumb
135: ({href=>"javascript:changePage(document.$phase,'display')",
136: text=>"Domain Configuration"});
1.9 raeburn 137: my $confname = $dom.'-domainconfig';
1.3 raeburn 138: if ($phase eq 'process') {
1.1 raeburn 139: &Apache::lonhtmlcommon::add_breadcrumb
1.3 raeburn 140: ({href=>"javascript:changePage(document.$phase,'$phase')",
141: text=>"Updated"});
142: &print_header($r,$phase);
143: foreach my $item (@prefs) {
144: $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
1.9 raeburn 145: &process_changes($r,$dom,$confname,
146: $item->{'action'},\@roles,%domconfig));
1.3 raeburn 147: }
148: $r->print('<p>');
149: &print_footer($r,$phase,'display','Back to actions menu');
150: $r->print('</p>');
1.1 raeburn 151: } else {
1.3 raeburn 152: if ($phase eq '') {
153: $phase = 'display';
1.1 raeburn 154: }
1.3 raeburn 155: my %helphash;
156: my $numprefs = @prefs;
157: &print_header($r,$phase);
1.21 raeburn 158: if (keys(%domconfig) == 0) {
159: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 ! raeburn 160: my @ids=&Apache::lonnet::current_machine_ids();
! 161: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 162: my %designhash = &Apache::loncommon::get_domainconf($dom);
163: my @loginimages = ('img','logo','domlogo');
164: my $custom_img_count = 0;
165: foreach my $img (@loginimages) {
166: if ($designhash{$dom.'.login.'.$img} ne '') {
167: $custom_img_count ++;
168: }
169: }
170: foreach my $role (@roles) {
171: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
172: $custom_img_count ++;
173: }
174: }
175: if ($custom_img_count > 0) {
176: my $switch_server = &check_switchserver($dom,$confname);
1.29 ! raeburn 177: $r->print(
! 178: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
! 179: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
! 180: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
! 181: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
! 182: if ($switch_server) {
! 183: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
! 184: }
1.21 raeburn 185: return OK;
186: }
187: }
188: }
1.3 raeburn 189: $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
190: foreach my $item (@prefs) {
1.6 raeburn 191: if ($item->{'action'} eq 'login') {
1.3 raeburn 192: $r->print('</td><td width="6%"> </td><td align="left" valign="top" width="47%">');
193: }
1.9 raeburn 194: &print_config_box($r,$dom,$confname,$phase,$item->{'action'},
1.6 raeburn 195: $item,$domconfig{$item->{'action'}});
1.3 raeburn 196: }
197: $r->print('
198: </td>
199: </tr>
200: </table>');
1.13 albertel 201: &print_footer($r,$phase,'process','Save changes');
1.3 raeburn 202: }
203: return OK;
204: }
205:
206: sub process_changes {
1.9 raeburn 207: my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
1.3 raeburn 208: my $output;
209: if ($action eq 'login') {
1.9 raeburn 210: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 211: } elsif ($action eq 'rolecolors') {
1.9 raeburn 212: $output = &modify_rolecolors($r,$dom,$confname,$roles,
213: %domconfig);
1.3 raeburn 214: } elsif ($action eq 'quotas') {
215: $output = &modify_quotas($dom,%domconfig);
216: } elsif ($action eq 'autoenroll') {
217: $output = &modify_autoenroll($dom,%domconfig);
218: } elsif ($action eq 'autoupdate') {
219: $output = &modify_autoupdate($dom,%domconfig);
1.23 raeburn 220: } elsif ($action eq 'directorysrch') {
221: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 222: } elsif ($action eq 'usercreation') {
1.28 raeburn 223: $output = &modify_usercreation($dom,%domconfig);
224: } elsif ($action eq 'contacts') {
225: $output = &modify_contacts($dom,%domconfig);
1.3 raeburn 226: }
227: return $output;
228: }
229:
230: sub print_config_box {
1.9 raeburn 231: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.3 raeburn 232: $r->print('
233: <table class="LC_nested_outer">
234: <tr>
1.22 raeburn 235: <th>'.&mt($item->{text}).' </th></tr>');
236: #
237: # FIXME - put the help link back in when the help files exist
238: # <th>'.&mt($item->{text}).' '.
239: # &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
240: # </tr>');
1.28 raeburn 241: if (($action eq 'autoupdate') || ($action eq 'rolecolors') ||
242: ($action eq 'usercreation')) {
1.6 raeburn 243: my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
1.3 raeburn 244: $r->print('
245: <tr>
246: <td>
247: <table class="LC_nested">
248: <tr class="LC_info_row">
1.6 raeburn 249: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
1.3 raeburn 250: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.6 raeburn 251: </tr>');
252: if ($action eq 'autoupdate') {
253: $r->print(&print_autoupdate('top',$dom,$settings));
1.28 raeburn 254: } elsif ($action eq 'usercreation') {
255: $r->print(&print_usercreation('top',$dom,$settings));
1.6 raeburn 256: } else {
1.9 raeburn 257: $r->print(&print_rolecolors($phase,'student',$dom,$confname,$settings));
1.6 raeburn 258: }
259: $r->print('
260: </table>
261: </td>
262: </tr>
263: <tr>
264: <td>
265: <table class="LC_nested">
266: <tr class="LC_info_row">
267: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
268: <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
269: </tr>');
270: if ($action eq 'autoupdate') {
271: $r->print(&print_autoupdate('bottom',$dom,$settings));
1.28 raeburn 272: } elsif ($action eq 'usercreation') {
273: $r->print(&print_usercreation('bottom',$dom,$settings));
1.6 raeburn 274: } else {
1.9 raeburn 275: $r->print(&print_rolecolors($phase,'coordinator',$dom,$confname,$settings).'
1.6 raeburn 276: </table>
277: </td>
278: </tr>
279: <tr>
280: <td>
281: <table class="LC_nested">
282: <tr class="LC_info_row">
283: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
284: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
1.3 raeburn 285: </tr>'.
1.9 raeburn 286: &print_rolecolors($phase,'author',$dom,$confname,$settings).'
1.3 raeburn 287: </table>
288: </td>
289: </tr>
290: <tr>
291: <td>
292: <table class="LC_nested">
293: <tr class="LC_info_row">
1.6 raeburn 294: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
295: <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
1.3 raeburn 296: </tr>'.
1.9 raeburn 297: &print_rolecolors($phase,'admin',$dom,$confname,$settings));
1.6 raeburn 298: }
1.3 raeburn 299: } else {
300: $r->print('
301: <tr>
302: <td>
303: <table class="LC_nested">
1.6 raeburn 304: <tr class="LC_info_row">');
1.24 raeburn 305: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.6 raeburn 306: $r->print('
307: <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>');
308: } else {
309: $r->print('
310: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>');
311: }
312: $r->print('
1.3 raeburn 313: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
314: </tr>');
315: if ($action eq 'login') {
1.28 raeburn 316: $r->print(&print_login($dom,$confname,$phase,$settings));
1.3 raeburn 317: } elsif ($action eq 'quotas') {
1.28 raeburn 318: $r->print(&print_quotas($dom,$settings));
1.3 raeburn 319: } elsif ($action eq 'autoenroll') {
1.28 raeburn 320: $r->print(&print_autoenroll($dom,$settings));
1.23 raeburn 321: } elsif ($action eq 'directorysrch') {
1.28 raeburn 322: $r->print(&print_directorysrch($dom,$settings));
323: } elsif ($action eq 'contacts') {
324: $r->print(&print_contacts($dom,$settings));
1.27 raeburn 325: }
1.3 raeburn 326: }
327: $r->print('
328: </table>
329: </td>
330: </tr>
331: </table><br />');
1.1 raeburn 332: return;
333: }
334:
335: sub print_header {
1.3 raeburn 336: my ($r,$phase) = @_;
1.6 raeburn 337: my $js = '
1.1 raeburn 338: <script type="text/javascript">
339: function changePage(formname,newphase) {
340: formname.phase.value = newphase;
341: formname.submit();
342: }
1.6 raeburn 343: '.
344: &color_pick_js().'
1.1 raeburn 345: </script>
1.6 raeburn 346: ';
1.2 albertel 347: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.3 raeburn 348: $js));
349: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6 raeburn 350: $r->print('
1.8 raeburn 351: <form name="parmform" action="">
1.6 raeburn 352: <input type="hidden" name="pres_marker" />
353: <input type="hidden" name="pres_type" />
354: <input type="hidden" name="pres_value" />
355: </form>
356: ');
357: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
358: ' enctype="multipart/form-data">');
1.1 raeburn 359: return;
360: }
361:
362: sub print_footer {
1.3 raeburn 363: my ($r,$phase,$newphase,$button_text) = @_;
364: $button_text = &mt($button_text);
365: $r->print('<input type="hidden" name="phase" value="" />');
366: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
367: if ($phase eq 'process') {
368: $r->print('<a href='.$dest.'>'.$button_text.'</a>');
369: } else {
370: $r->print('<input type="button" name="store" value="'.
371: $button_text.'" onclick='.$dest.' />');
372: }
373: $r->print('</form>');
1.1 raeburn 374: $r->print('<br />'.&Apache::loncommon::end_page());
375: return;
376: }
377:
1.3 raeburn 378: sub print_login {
1.9 raeburn 379: my ($dom,$confname,$phase,$settings) = @_;
1.6 raeburn 380: my %choices = &login_choices();
381: my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
382: $catalogon = ' checked="checked" ';
383: $adminmailoff = ' checked="checked" ';
384: my @images = ('img','logo','domlogo');
385: my @bgs = ('pgbg','mainbg','sidebg');
386: my @links = ('link','alink','vlink');
1.7 albertel 387: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 388: my %defaultdesign = %Apache::loncommon::defaultdesign;
389: my (%is_custom,%designs);
390: my %defaults = (
391: font => $defaultdesign{'login.font'},
392: );
393: foreach my $item (@images) {
394: $defaults{$item} = $defaultdesign{'login.'.$item};
395: }
396: foreach my $item (@bgs) {
397: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
398: }
399: foreach my $item (@links) {
400: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
401: }
1.3 raeburn 402: if (ref($settings) eq 'HASH') {
403: if ($settings->{'coursecatalog'} eq '0') {
1.1 raeburn 404: $catalogoff = $catalogon;
405: $catalogon = ' ';
406: }
1.3 raeburn 407: if ($settings->{'adminmail'} eq '1') {
1.1 raeburn 408: $adminmailon = $adminmailoff;
409: $adminmailoff = ' ';
410: }
1.6 raeburn 411: foreach my $item (@images) {
412: if ($settings->{$item} ne '') {
413: $designs{$item} = $settings->{$item};
414: $is_custom{$item} = 1;
415: }
416: }
417: if ($settings->{'font'} ne '') {
418: $designs{'font'} = $settings->{'font'};
419: $is_custom{'font'} = 1;
420: }
421: foreach my $item (@bgs) {
422: if ($settings->{$item} ne '') {
423: $designs{'bgs'}{$item} = $settings->{$item};
424: $is_custom{$item} = 1;
425: }
426: }
427: foreach my $item (@links) {
428: if ($settings->{$item} ne '') {
429: $designs{'links'}{$item} = $settings->{$item};
430: $is_custom{$item} = 1;
431: }
432: }
433: } else {
434: if ($designhash{$dom.'.login.font'} ne '') {
435: $designs{'font'} = $designhash{$dom.'.login.font'};
436: $is_custom{'font'} = 1;
437: }
1.8 raeburn 438: foreach my $item (@images) {
439: if ($designhash{$dom.'.login.'.$item} ne '') {
440: $designs{$item} = $designhash{$dom.'.login.'.$item};
441: $is_custom{$item} = 1;
442: }
443: }
1.6 raeburn 444: foreach my $item (@bgs) {
445: if ($designhash{$dom.'.login.'.$item} ne '') {
446: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
447: $is_custom{$item} = 1;
448: }
449: }
450: foreach my $item (@links) {
451: if ($designhash{$dom.'.login.'.$item} ne '') {
452: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
453: $is_custom{$item} = 1;
454: }
455: }
1.1 raeburn 456: }
1.6 raeburn 457: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
458: logo => 'Institution Logo',
459: domlogo => 'Domain Logo');
460: my $itemcount = 1;
461: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.3 raeburn 462: my $datatable =
1.6 raeburn 463: '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
464: '</td><td>'.
1.8 raeburn 465: '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
466: $catalogon.' value="1" />'.&mt('Yes').'</label> '.
467: '<label><input type="radio" name="coursecatalog"'.
468: $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.6 raeburn 469: '</tr>';
470: $itemcount ++;
471: $css_class = $itemcount%2?' class="LC_odd_row"':'';
472: $datatable .= '<tr'.$css_class.'>'.
473: '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
1.8 raeburn 474: '<td><span class="LC_nobreak">'.
475: '<label><input type="radio" name="adminmail"'.
476: $adminmailon.' value="1" />'.&mt('Yes').'</label> '.
477: '<label><input type="radio" name="adminmail"'.
478: $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
1.6 raeburn 479: $itemcount ++;
1.9 raeburn 480: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
1.6 raeburn 481: $datatable .= '</tr></table></td></tr>';
482: return $datatable;
483: }
484:
485: sub login_choices {
486: my %choices =
487: &Apache::lonlocal::texthash (
488: coursecatalog => 'Display Course Catalog link?',
489: adminmail => "Display Administrator's E-mail Address?",
490: img => "Header",
491: logo => "Main Logo",
492: domlogo => "Domain Logo",
493: bgs => "Background colors",
494: links => "Link colors",
495: font => "Font color",
496: pgbg => "Page",
497: mainbg => "Main panel",
498: sidebg => "Side panel",
499: link => "Link",
500: alink => "Active link",
501: vlink => "Visited link",
502: );
503: return %choices;
504: }
505:
506: sub print_rolecolors {
1.9 raeburn 507: my ($phase,$role,$dom,$confname,$settings) = @_;
1.6 raeburn 508: my %choices = &color_font_choices();
509: my @bgs = ('pgbg','tabbg','sidebg');
510: my @links = ('link','alink','vlink');
511: my @images = ('img');
512: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 513: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 514: my %defaultdesign = %Apache::loncommon::defaultdesign;
515: my (%is_custom,%designs);
516: my %defaults = (
517: img => $defaultdesign{$role.'.img'},
518: font => $defaultdesign{$role.'.font'},
519: );
520: foreach my $item (@bgs) {
521: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
522: }
523: foreach my $item (@links) {
524: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
525: }
526: if (ref($settings) eq 'HASH') {
527: if (ref($settings->{$role}) eq 'HASH') {
528: if ($settings->{$role}->{'img'} ne '') {
529: $designs{'img'} = $settings->{$role}->{'img'};
530: $is_custom{'img'} = 1;
531: }
532: if ($settings->{$role}->{'font'} ne '') {
533: $designs{'font'} = $settings->{$role}->{'font'};
534: $is_custom{'font'} = 1;
535: }
536: foreach my $item (@bgs) {
537: if ($settings->{$role}->{$item} ne '') {
538: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
539: $is_custom{$item} = 1;
540: }
541: }
542: foreach my $item (@links) {
543: if ($settings->{$role}->{$item} ne '') {
544: $designs{'links'}{$item} = $settings->{$role}->{$item};
545: $is_custom{$item} = 1;
546: }
547: }
548: }
549: } else {
550: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
551: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
552: $is_custom{'img'} = 1;
553: }
554: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
555: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
556: $is_custom{'font'} = 1;
557: }
558: foreach my $item (@bgs) {
559: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
560: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
561: $is_custom{$item} = 1;
562:
563: }
564: }
565: foreach my $item (@links) {
566: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
567: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
568: $is_custom{$item} = 1;
569: }
570: }
571: }
572: my $itemcount = 1;
1.9 raeburn 573: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
1.6 raeburn 574: $datatable .= '</tr></table></td></tr>';
575: return $datatable;
576: }
577:
578: sub display_color_options {
1.9 raeburn 579: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.6 raeburn 580: $images,$bgs,$links,$alt_text) = @_;
581: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
582: my $datatable = '<tr'.$css_class.'>'.
583: '<td>'.$choices->{'font'}.'</td>';
584: if (!$is_custom->{'font'}) {
585: $datatable .= '<td>'.&mt('Default in use:').' '.$defaults->{'font'}.'</td>';
586: } else {
587: $datatable .= '<td> </td>';
588: }
589: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 590: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 591: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 592: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
593: '</span></td></tr>';
1.9 raeburn 594: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 595: foreach my $img (@{$images}) {
1.18 albertel 596: $itemcount ++;
1.6 raeburn 597: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 598: $datatable .= '<tr'.$css_class.'>'.
1.6 raeburn 599: '<td>'.$choices->{$img}.'</td>';
1.18 albertel 600: my ($imgfile, $img_import);
1.6 raeburn 601: if ($designs->{$img} ne '') {
602: $imgfile = $designs->{$img};
1.18 albertel 603: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 604: } else {
605: $imgfile = $defaults->{$img};
606: }
607: if ($imgfile) {
1.9 raeburn 608: my ($showfile,$fullsize);
609: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 610: my $urldir = $1;
611: my $filename = $2;
612: my @info = &Apache::lonnet::stat_file($designs->{$img});
613: if (@info) {
614: my $thumbfile = 'tn-'.$filename;
615: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
616: if (@thumb) {
617: $showfile = $urldir.'/'.$thumbfile;
618: } else {
619: $showfile = $imgfile;
620: }
621: } else {
622: $showfile = '';
623: }
624: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 625: $showfile = $imgfile;
1.6 raeburn 626: my $imgdir = $1;
627: my $filename = $2;
628: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
629: $showfile = "/$imgdir/tn-".$filename;
630: } else {
631: my $input = "/home/httpd/html".$imgfile;
632: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
633: if (!-e $output) {
1.9 raeburn 634: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 635: my ($fullwidth,$fullheight) = &check_dimensions($input);
636: if ($fullwidth ne '' && $fullheight ne '') {
637: if ($fullwidth > $width && $fullheight > $height) {
638: my $size = $width.'x'.$height;
639: system("convert -sample $size $input $output");
640: $showfile = '/'.$imgdir.'/tn-'.$filename;
641: }
642: }
1.6 raeburn 643: }
644: }
1.16 raeburn 645: }
1.6 raeburn 646: if ($showfile) {
1.9 raeburn 647: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
648: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1.6 raeburn 649: $datatable.= '<td>';
650: if (!$is_custom->{$img}) {
651: $datatable .= &mt('Default in use:').'<br />';
652: }
1.18 albertel 653: if ($img_import) {
654: $datatable.= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
655: }
1.9 raeburn 656: $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
657: $showfile.'" alt="'.$alt_text->{$img}.
658: '" border="0" /></a></td>';
1.6 raeburn 659: if ($is_custom->{$img}) {
1.8 raeburn 660: $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
661: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
662: '</label> '.&mt('Replace:').'</span><br />';
1.6 raeburn 663: } else {
664: $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
665: }
666: } else {
667: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
668: &mt('Upload:');
669: }
670: } else {
671: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
672: &mt('Upload:');
673: }
1.9 raeburn 674: if ($switchserver) {
675: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
676: } else {
677: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
678: }
679: $datatable .= '</td></tr>';
1.6 raeburn 680: }
681: $itemcount ++;
682: $css_class = $itemcount%2?' class="LC_odd_row"':'';
683: $datatable .= '<tr'.$css_class.'>'.
684: '<td>'.$choices->{'bgs'}.'</td>';
685: my $bgs_def;
686: foreach my $item (@{$bgs}) {
687: if (!$is_custom->{$item}) {
688: $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
689: }
690: }
691: if ($bgs_def) {
1.8 raeburn 692: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 693: } else {
694: $datatable .= '<td> </td>';
695: }
696: $datatable .= '<td class="LC_right_item">'.
697: '<table border="0"><tr>';
698: foreach my $item (@{$bgs}) {
699: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
700: $datatable .= '<td align="center">'.$link;
701: if ($designs->{'bgs'}{$item}) {
702: $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px"> </span>';
703: }
704: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
705: '" /></td>';
706: }
707: $datatable .= '</tr></table></td></tr>';
708: $itemcount ++;
709: $css_class = $itemcount%2?' class="LC_odd_row"':'';
710: $datatable .= '<tr'.$css_class.'>'.
711: '<td>'.$choices->{'links'}.'</td>';
712: my $links_def;
713: foreach my $item (@{$links}) {
714: if (!$is_custom->{$item}) {
715: $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
716: }
717: }
718: if ($links_def) {
1.8 raeburn 719: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 720: } else {
721: $datatable .= '<td> </td>';
722: }
723: $datatable .= '<td class="LC_right_item">'.
724: '<table border="0"><tr>';
725: foreach my $item (@{$links}) {
726: $datatable .= '<td align="center">';
727: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
728: if ($designs->{'links'}{$item}) {
729: $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
730: $link.'</span>';
731: } else {
732: $datatable .= $link;
733: }
734: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
735: '" /></td>';
736: }
1.3 raeburn 737: return $datatable;
738: }
739:
1.6 raeburn 740: sub color_pick {
741: my ($phase,$role,$item,$desc,$curcol) = @_;
742: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
743: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
744: ');">'.$desc.'</a>';
745: return $link;
746: }
747:
748: sub color_pick_js {
749: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
750: my $output = <<"ENDCOL";
751: function pclose() {
752: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
753: parmwin.close();
754: }
755:
756: $pjump_def
757:
758: function psub() {
759: pclose();
760: if (document.parmform.pres_marker.value!='') {
761: if (document.parmform.pres_type.value!='') {
762: eval('document.display.'+
763: document.parmform.pres_marker.value+
764: '.value=document.parmform.pres_value.value;');
765: }
766: } else {
767: document.parmform.pres_value.value='';
768: document.parmform.pres_marker.value='';
769: }
770: }
771: ENDCOL
772: return $output;
773: }
774:
1.3 raeburn 775: sub print_quotas {
776: my ($dom,$settings) = @_;
777: my $datatable;
1.23 raeburn 778: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.3 raeburn 779: my $typecount = 0;
780: my $css_class;
1.26 raeburn 781: if (ref($types) eq 'ARRAY') {
1.23 raeburn 782: foreach my $type (@{$types}) {
1.3 raeburn 783: if (defined($usertypes->{$type})) {
784: $typecount ++;
785: $css_class = $typecount%2?' class="LC_odd_row"':'';
786: $datatable .= '<tr'.$css_class.'>'.
787: '<td>'.$usertypes->{$type}.'</td>'.
1.8 raeburn 788: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 789: '<input type="text" name="quota_'.$type.
790: '" value="'.$settings->{$type}.
1.8 raeburn 791: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 792: }
793: }
794: }
795: my $defaultquota = '20';
796: if (ref($settings) eq 'HASH') {
797: if (defined($settings->{'default'})) {
798: $defaultquota = $settings->{'default'};
799: }
800: }
801: $typecount ++;
802: $css_class = $typecount%2?' class="LC_odd_row"':'';
803: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 804: '<td>'.$othertitle.'</td>'.
1.8 raeburn 805: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.15 raeburn 806: '<input type="text" name="defaultquota" value="'.
1.8 raeburn 807: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.3 raeburn 808: return $datatable;
809: }
810:
811: sub print_autoenroll {
812: my ($dom,$settings) = @_;
813: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 814: my ($defdom,$runon,$runoff);
1.3 raeburn 815: if (ref($settings) eq 'HASH') {
816: if (exists($settings->{'run'})) {
817: if ($settings->{'run'} eq '0') {
818: $runoff = ' checked="checked" ';
819: $runon = ' ';
820: } else {
821: $runon = ' checked="checked" ';
822: $runoff = ' ';
823: }
824: } else {
825: if ($autorun) {
826: $runon = ' checked="checked" ';
827: $runoff = ' ';
828: } else {
829: $runoff = ' checked="checked" ';
830: $runon = ' ';
831: }
832: }
833: if (exists($settings->{'sender_domain'})) {
834: $defdom = $settings->{'sender_domain'};
835: }
1.14 raeburn 836: } else {
837: if ($autorun) {
838: $runon = ' checked="checked" ';
839: $runoff = ' ';
840: } else {
841: $runoff = ' checked="checked" ';
842: $runon = ' ';
843: }
1.3 raeburn 844: }
845: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
846: my $datatable='<tr class="LC_odd_row">'.
847: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 848: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 849: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 850: $runon.' value="1" />'.&mt('Yes').'</label> '.
851: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 852: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 853: '</tr><tr>'.
854: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 855: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 856: &mt('username').': '.
857: '<input type="text" name="sender_uname" value="'.
858: $settings->{'sender_uname'}.
859: '" size="10" /> '.&mt('domain').
1.8 raeburn 860: ': '.$domform.'</span></td></tr>';
1.3 raeburn 861: return $datatable;
862: }
863:
864: sub print_autoupdate {
865: my ($position,$dom,$settings) = @_;
866: my $datatable;
867: if ($position eq 'top') {
868: my $updateon = ' ';
869: my $updateoff = ' checked="checked" ';
870: my $classlistson = ' ';
871: my $classlistsoff = ' checked="checked" ';
872: if (ref($settings) eq 'HASH') {
873: if ($settings->{'run'} eq '1') {
874: $updateon = $updateoff;
875: $updateoff = ' ';
876: }
877: if ($settings->{'classlists'} eq '1') {
878: $classlistson = $classlistsoff;
879: $classlistsoff = ' ';
880: }
881: }
882: my %title = (
883: run => 'Auto-update active?',
884: classlists => 'Update information in classlists?',
885: );
886: $datatable = '<tr class="LC_odd_row">'.
887: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 888: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 889: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 890: $updateon.' value="1" />'.&mt('Yes').'</label> '.
891: '<label><input type="radio" name="autoupdate_run"'.
892: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 893: '</tr><tr>'.
894: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 895: '<td class="LC_right_item"><span class="LC_nobreak">'.
896: '<label><input type="radio" name="classlists"'.
897: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
898: '<label><input type="radio" name="classlists"'.
899: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 900: '</tr>';
901: } else {
1.23 raeburn 902: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.20 raeburn 903: my @fields = ('lastname','firstname','middlename','gen',
904: 'permanentemail','id');
1.3 raeburn 905: my %fieldtitles = &Apache::lonlocal::texthash (
906: id => 'Student/Employee ID',
1.20 raeburn 907: permanentemail => 'E-mail address',
1.3 raeburn 908: lastname => 'Last Name',
909: firstname => 'First Name',
910: middlename => 'Middle Name',
911: gen => 'Generation',
912: );
913: my $numrows = 0;
1.26 raeburn 914: if (ref($types) eq 'ARRAY') {
915: if (@{$types} > 0) {
916: $datatable =
917: &usertype_update_row($settings,$usertypes,\%fieldtitles,
918: \@fields,$types,\$numrows);
919: }
1.3 raeburn 920: }
921: $datatable .=
922: &usertype_update_row($settings,{'default' => $othertitle},
923: \%fieldtitles,\@fields,['default'],
924: \$numrows);
925: }
926: return $datatable;
927: }
928:
1.23 raeburn 929: sub print_directorysrch {
930: my ($dom,$settings) = @_;
931: my $srchon = ' ';
932: my $srchoff = ' checked="checked" ';
1.25 raeburn 933: my ($exacton,$containson,$beginson);
1.24 raeburn 934: my $localon = ' ';
935: my $localoff = ' checked="checked" ';
1.23 raeburn 936: if (ref($settings) eq 'HASH') {
937: if ($settings->{'available'} eq '1') {
938: $srchon = $srchoff;
939: $srchoff = ' ';
940: }
1.24 raeburn 941: if ($settings->{'localonly'} eq '1') {
942: $localon = $localoff;
943: $localoff = ' ';
944: }
1.25 raeburn 945: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
946: foreach my $type (@{$settings->{'searchtypes'}}) {
947: if ($type eq 'exact') {
948: $exacton = ' checked="checked" ';
949: } elsif ($type eq 'contains') {
950: $containson = ' checked="checked" ';
951: } elsif ($type eq 'begins') {
952: $beginson = ' checked="checked" ';
953: }
954: }
955: } else {
956: if ($settings->{'searchtypes'} eq 'exact') {
957: $exacton = ' checked="checked" ';
958: } elsif ($settings->{'searchtypes'} eq 'contains') {
959: $containson = ' checked="checked" ';
960: } elsif ($settings->{'searchtypes'} eq 'specify') {
961: $exacton = ' checked="checked" ';
962: $containson = ' checked="checked" ';
963: }
1.23 raeburn 964: }
965: }
966: my ($searchtitles,$titleorder) = &sorted_searchtitles();
967: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
968:
969: my $numinrow = 4;
1.26 raeburn 970: my $cansrchrow = 0;
1.23 raeburn 971: my $datatable='<tr class="LC_odd_row">'.
1.24 raeburn 972: '<td colspan="2">'.&mt('Directory search available?').'</td>'.
1.23 raeburn 973: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
974: '<input type="radio" name="dirsrch_available"'.
975: $srchon.' value="1" />'.&mt('Yes').'</label> '.
976: '<label><input type="radio" name="dirsrch_available"'.
977: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
978: '</tr><tr>'.
1.25 raeburn 979: '<td colspan="2">'.&mt('Other domains can search?').'</td>'.
1.24 raeburn 980: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
981: '<input type="radio" name="dirsrch_localonly"'.
982: $localoff.' value="0" />'.&mt('Yes').'</label> '.
983: '<label><input type="radio" name="dirsrch_localonly"'.
984: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 985: '</tr>';
1.26 raeburn 986: if (ref($usertypes) eq 'HASH') {
987: if (keys(%{$usertypes}) > 0) {
988: $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
989: $numinrow,$othertitle);
990: $cansrchrow = 1;
991: }
992: }
993: if ($cansrchrow) {
994: $datatable .= '<tr>';
995: } else {
996: $datatable .= '<tr class="LC_odd_row">';
997: }
998: $datatable .= '<td>'.&mt('Supported search methods').
1.25 raeburn 999: '</td><td class="LC_left_item" colspan="2"><table><tr>';
1000: foreach my $title (@{$titleorder}) {
1001: if (defined($searchtitles->{$title})) {
1002: my $check = ' ';
1003: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1004: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1005: $check = ' checked="checked" ';
1006: }
1007: }
1008: $datatable .= '<td class="LC_left_item">'.
1009: '<span class="LC_nobreak"><label>'.
1010: '<input type="checkbox" name="searchby" '.
1011: 'value="'.$title.'"'.$check.'/>'.
1012: $searchtitles->{$title}.'</label></span></td>';
1013: }
1014: }
1.26 raeburn 1015: $datatable .= '</tr></table></td></tr>';
1016: if ($cansrchrow) {
1017: $datatable .= '<tr class="LC_odd_row">';
1018: } else {
1019: $datatable .= '<tr>';
1020: }
1021: $datatable .= '<td>'.&mt('Search latitude').'</td>'.
1022: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1023: '<span class="LC_nobreak"><label>'.
1024: '<input type="checkbox" name="searchtypes" '.
1025: $exacton.' value="exact" />'.&mt('Exact match').
1026: '</label> '.
1027: '<label><input type="checkbox" name="searchtypes" '.
1028: $beginson.' value="begins" />'.&mt('Begins with').
1029: '</label> '.
1030: '<label><input type="checkbox" name="searchtypes" '.
1031: $containson.' value="contains" />'.&mt('Contains').
1032: '</label></span></td></tr>';
1033: return $datatable;
1034: }
1035:
1.28 raeburn 1036: sub print_contacts {
1037: my ($dom,$settings) = @_;
1038: my $datatable;
1039: my @contacts = ('adminemail','supportemail');
1040: my (%checked,%to,%otheremails);
1041: my @mailings = ('errormail','packagesmail','helpdeskmail');
1042: foreach my $type (@mailings) {
1043: $otheremails{$type} = '';
1044: }
1045: if (ref($settings) eq 'HASH') {
1046: foreach my $item (@contacts) {
1047: if (exists($settings->{$item})) {
1048: $to{$item} = $settings->{$item};
1049: }
1050: }
1051: foreach my $type (@mailings) {
1052: if (exists($settings->{$type})) {
1053: if (ref($settings->{$type}) eq 'HASH') {
1054: foreach my $item (@contacts) {
1055: if ($settings->{$type}{$item}) {
1056: $checked{$type}{$item} = ' checked="checked" ';
1057: }
1058: }
1059: $otheremails{$type} = $settings->{$type}{'others'};
1060: }
1061: }
1062: }
1063: } else {
1064: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1065: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1066: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1067: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1068: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
1069: }
1070: my ($titles,$short_titles) = &contact_titles();
1071: my $rownum = 0;
1072: my $css_class;
1073: foreach my $item (@contacts) {
1074: if ($rownum%2) {
1075: $css_class = '';
1076: } else {
1077: $css_class = ' class="LC_odd_row" ';
1078: }
1079: $datatable .= '<tr'.$css_class.' ">'.
1080: '<td>'.$titles->{$item}.'</td>'.
1081: '<td class="LC_right_item">'.
1082: '<input type="text" name="'.$item.'" value="'.
1083: $to{$item}.'" /></td></tr>';
1084: $rownum ++;
1085: }
1086: foreach my $type (@mailings) {
1087: if ($rownum%2) {
1088: $css_class = '';
1089: } else {
1090: $css_class = ' class="LC_odd_row" ';
1091: }
1092: $datatable .= '<tr'.$css_class.'>'.
1093: '<td>'.$titles->{$type}.': </td>'.
1094: '<td class="LC_left_item">'.
1095: '<span class="LC_nobreak">';
1096: foreach my $item (@contacts) {
1097: $datatable .= '<label>'.
1098: '<input type="checkbox" name="'.$type.'"'.
1099: $checked{$type}{$item}.
1100: ' value="'.$item.'" />'.$short_titles->{$item}.
1101: '</label> ';
1102: }
1103: $datatable .= '</span><br />'.&mt('Others').': '.
1104: '<input type="text" name="'.$type.'_others" '.
1105: 'value="'.$otheremails{$type}.'" />'.
1106: '</td></tr>'."\n";
1107: $rownum ++;
1108: }
1109: return $datatable;
1110: }
1111:
1112: sub contact_titles {
1113: my %titles = &Apache::lonlocal::texthash (
1114: 'supportemail' => 'Support E-mail address',
1115: 'adminemail' => 'Default Server Admin E-mail address',
1116: 'errormail' => 'Error reports to be e-mailed to',
1117: 'packagesmail' => 'Package update alerts to be e-mailed to',
1118: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
1119: );
1120: my %short_titles = &Apache::lonlocal::texthash (
1121: adminemail => 'Admin E-mail address',
1122: supportemail => 'Support E-mail',
1123: );
1124: return (\%titles,\%short_titles);
1125: }
1126:
1.27 raeburn 1127: sub print_usercreation {
1.28 raeburn 1128: my ($position,$dom,$settings) = @_;
1.27 raeburn 1129: my $numinrow = 4;
1.28 raeburn 1130: my $rowcount = 0;
1.27 raeburn 1131: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom);
1.28 raeburn 1132: my $datatable;
1133: my %lt = &Apache::lonlocal::texthash (
1134: nondc => 'User creation other than by Domain Coordinator: ',
1135: author => 'When adding a co-author/assistant author',
1136: course => 'When adding users to a course',
1137: );
1138: if ($position eq 'top') {
1139: my %checked;
1140: if (ref($settings) eq 'HASH') {
1141: if (ref($settings->{'cancreate'}) eq 'ARRAY') {
1142: foreach my $item (@{$settings->{'cancreate'}}) {
1143: $checked{$item} = ' checked="checked" ';
1144: }
1145: }
1146: }
1147: $datatable = '<tr class="LC_odd_row">'.
1148: '<td>'.$lt{'nondc'}.'</td>'.
1149: '<td class="LC_left_item"><table>';
1150: foreach my $item ('author','course') {
1151: $datatable .= '<tr><td><span class="LC_nobreak"><label>'.
1152: '<input type="checkbox" name="can_createuser" '.
1153: $checked{$item}.' value="'.$item.'" />'.
1154: $lt{$item}.'</label><span></td></tr>';
1155: }
1156: $datatable .= '</table></td></tr>';
1157: $rowcount ++;
1158: if (ref($rules) eq 'HASH') {
1159: if (keys(%{$rules}) > 0) {
1160: $datatable .= &username_formats_row($settings,$rules,
1161: $ruleorder,$numinrow);
1162: $rowcount ++;
1163: }
1164: }
1165: } else {
1166: my @contexts = ('author','course','domain');
1167: my @authtypes = ('int','krb4','krb5','loc');
1168: my %checked;
1169: if (ref($settings) eq 'HASH') {
1170: if (ref($settings->{'authtypes'}) eq 'HASH') {
1171: foreach my $item (@contexts) {
1172: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
1173: foreach my $auth (@authtypes) {
1174: if ($settings->{'authtypes'}{$item}{$auth}) {
1175: $checked{$item}{$auth} = ' checked="checked" ';
1176: }
1177: }
1178: }
1179: }
1.27 raeburn 1180: }
1181: }
1.28 raeburn 1182: my @authtypes = ('int','krb4','krb5','loc');
1183: my %title = &context_names();
1184: my %authname = &authtype_names();
1185: my $rownum = 0;
1186: my $css_class;
1187: foreach my $item (@contexts) {
1188: if ($rownum%2) {
1189: $css_class = '';
1190: } else {
1191: $css_class = ' class="LC_odd_row" ';
1192: }
1193: $datatable .= '<tr'.$css_class.'">'.
1194: '<td>'.$title{$item}.
1195: '</td><td class="LC_left_item">'.
1196: '<span class="LC_nobreak">';
1197: foreach my $auth (@authtypes) {
1198: $datatable .= '<label>'.
1199: '<input type="checkbox" name="'.$item.'_auth" '.
1200: $checked{$item}{$auth}.' value="'.$auth.'" />'.
1201: $authname{$auth}.'</label> ';
1202: }
1203: $datatable .= '</span></td></tr>';
1204: $rownum ++;
1.27 raeburn 1205: }
1206: }
1207: return $datatable;
1208: }
1209:
1210: sub username_formats_row {
1211: my ($settings,$rules,$ruleorder,$numinrow) = @_;
1.28 raeburn 1212: my $output = '<tr>'.
1213: '<td>'.&mt('Format rules to check for new usernames: ').
1.27 raeburn 1214: '</td><td class="LC_left_item" colspan="2"><table>';
1215: my $rem;
1216: if (ref($ruleorder) eq 'ARRAY') {
1217: for (my $i=0; $i<@{$ruleorder}; $i++) {
1218: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
1219: my $rem = $i%($numinrow);
1220: if ($rem == 0) {
1221: if ($i > 0) {
1222: $output .= '</tr>';
1223: }
1224: $output .= '<tr>';
1225: }
1226: my $check = ' ';
1227: if (ref($settings->{'username_rule'}) eq 'ARRAY') {
1228: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{'username_rule'}})) {
1229: $check = ' checked="checked" ';
1230: }
1231: }
1232: $output .= '<td class="LC_left_item">'.
1233: '<span class="LC_nobreak"><label>'.
1234: '<input type="checkbox" name="username_rule" '.
1235: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
1236: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
1237: }
1238: }
1239: $rem = @{$ruleorder}%($numinrow);
1240: }
1241: my $colsleft = $numinrow - $rem;
1242: if ($colsleft > 1 ) {
1243: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1244: ' </td>';
1245: } elsif ($colsleft == 1) {
1246: $output .= '<td class="LC_left_item"> </td>';
1247: }
1248: $output .= '</tr></table></td></tr>';
1249: return $output;
1250: }
1251:
1.28 raeburn 1252: sub authtype_names {
1253: my %lt = &Apache::lonlocal::texthash(
1254: int => 'Internal',
1255: krb4 => 'Kerberos 4',
1256: krb5 => 'Kerberos 5',
1257: loc => 'Local',
1258: );
1259: return %lt;
1260: }
1261:
1262: sub context_names {
1263: my %context_title = &Apache::lonlocal::texthash(
1264: author => 'Creating users when an Author',
1265: course => 'Creating users when in a course',
1266: domain => 'Creating users when a Domain Coordinator',
1267: );
1268: return %context_title;
1269: }
1270:
1271:
1.25 raeburn 1272: sub users_cansearch_row {
1273: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
1274: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 1275: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
1276: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 1277: my $rem;
1278: if (ref($types) eq 'ARRAY') {
1279: for (my $i=0; $i<@{$types}; $i++) {
1280: if (defined($usertypes->{$types->[$i]})) {
1281: my $rem = $i%($numinrow);
1282: if ($rem == 0) {
1283: if ($i > 0) {
1284: $output .= '</tr>';
1285: }
1286: $output .= '<tr>';
1.23 raeburn 1287: }
1.26 raeburn 1288: my $check = ' ';
1289: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1290: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
1291: $check = ' checked="checked" ';
1292: }
1.23 raeburn 1293: }
1.26 raeburn 1294: $output .= '<td class="LC_left_item">'.
1295: '<span class="LC_nobreak"><label>'.
1296: '<input type="checkbox" name="cansearch" '.
1297: 'value="'.$types->[$i].'"'.$check.'/>'.
1298: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 1299: }
1300: }
1.26 raeburn 1301:
1302: $rem = @{$types}%($numinrow);
1.23 raeburn 1303: }
1304: my $colsleft = $numinrow - $rem;
1305: if ($colsleft > 1) {
1.25 raeburn 1306: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 1307: } else {
1.25 raeburn 1308: $output .= '<td class="LC_left_item">';
1.23 raeburn 1309: }
1310: my $defcheck = ' ';
1311: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 1312: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
1313: $defcheck = ' checked="checked" ';
1314: }
1.23 raeburn 1315: }
1.25 raeburn 1316: $output .= '<span class="LC_nobreak"><label>'.
1317: '<input type="checkbox" name="cansearch" '.
1318: 'value="default"'.$defcheck.'/>'.
1319: $othertitle.'</label></span></td>'.
1320: '</tr></table></td></tr>';
1321: return $output;
1.23 raeburn 1322: }
1323:
1324: sub sorted_inst_types {
1325: my ($dom) = @_;
1326: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1.26 raeburn 1327: my $othertitle = &mt('All users');
1.23 raeburn 1328: my @types;
1329: if (ref($order) eq 'ARRAY') {
1330: @types = @{$order};
1331: }
1332: if (@types == 0) {
1333: if (ref($usertypes) eq 'HASH') {
1334: @types = sort(keys(%{$usertypes}));
1335: }
1336: }
1337: if (keys(%{$usertypes}) > 0) {
1338: $othertitle = &mt('Other users');
1339: }
1340: return ($othertitle,$usertypes,\@types);
1341: }
1342:
1343: sub sorted_searchtitles {
1344: my %searchtitles = &Apache::lonlocal::texthash(
1345: 'uname' => 'username',
1346: 'lastname' => 'last name',
1347: 'lastfirst' => 'last name, first name',
1348: );
1349: my @titleorder = ('uname','lastname','lastfirst');
1350: return (\%searchtitles,\@titleorder);
1351: }
1352:
1.25 raeburn 1353: sub sorted_searchtypes {
1354: my %srchtypes_desc = (
1355: exact => 'is exact match',
1356: contains => 'contains ..',
1357: begins => 'begins with ..',
1358: );
1359: my @srchtypeorder = ('exact','begins','contains');
1360: return (\%srchtypes_desc,\@srchtypeorder);
1361: }
1362:
1.3 raeburn 1363: sub usertype_update_row {
1364: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
1365: my $datatable;
1366: my $numinrow = 4;
1367: foreach my $type (@{$types}) {
1368: if (defined($usertypes->{$type})) {
1369: $$rownums ++;
1370: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
1371: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
1372: '</td><td class="LC_left_item"><table>';
1373: for (my $i=0; $i<@{$fields}; $i++) {
1374: my $rem = $i%($numinrow);
1375: if ($rem == 0) {
1376: if ($i > 0) {
1377: $datatable .= '</tr>';
1378: }
1379: $datatable .= '<tr>';
1380: }
1381: my $check = ' ';
1382: if (ref($settings->{'fields'}) eq 'HASH') {
1383: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
1384: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
1385: $check = ' checked="checked" ';
1386: }
1387: }
1388: }
1389:
1390: if ($i == @{$fields}-1) {
1391: my $colsleft = $numinrow - $rem;
1392: if ($colsleft > 1) {
1393: $datatable .= '<td colspan="'.$colsleft.'">';
1394: } else {
1395: $datatable .= '<td>';
1396: }
1397: } else {
1398: $datatable .= '<td>';
1399: }
1.8 raeburn 1400: $datatable .= '<span class="LC_nobreak"><label>'.
1401: '<input type="checkbox" name="updateable_'.$type.
1402: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
1403: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 1404: }
1405: $datatable .= '</tr></table></td></tr>';
1406: }
1407: }
1408: return $datatable;
1.1 raeburn 1409: }
1410:
1411: sub modify_login {
1.9 raeburn 1412: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 1413: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 1414: my %title = ( coursecatalog => 'Display course catalog',
1415: adminmail => 'Display administrator E-mail address');
1.3 raeburn 1416: my @offon = ('off','on');
1.6 raeburn 1417: my %loginhash;
1.9 raeburn 1418: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
1419: \%domconfig,\%loginhash);
1.6 raeburn 1420: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
1421: $loginhash{login}{adminmail} = $env{'form.adminmail'};
1422: if (ref($colchanges{'login'}) eq 'HASH') {
1423: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
1424: \%loginhash);
1425: }
1.1 raeburn 1426: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
1427: $dom);
1428: if ($putresult eq 'ok') {
1.3 raeburn 1429: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 1430: ($env{'form.coursecatalog'} eq '1')) {
1431: $changes{'coursecatalog'} = 1;
1.3 raeburn 1432: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
1433: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 1434: ($env{'form.coursecatalog'} eq '0')) {
1435: $changes{'coursecatalog'} = 1;
1436: }
1.3 raeburn 1437: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 1438: ($env{'form.adminmail'} eq '0')) {
1439: $changes{'adminmail'} = 1;
1440: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
1441: $domconfig{'login'}{'adminmail'} eq '0') &&
1442: ($env{'form.adminmail'} eq '1')) {
1443: $changes{'adminmail'} = 1;
1444: }
1.6 raeburn 1445: if (keys(%changes) > 0 || $colchgtext) {
1.1 raeburn 1446: $resulttext = &mt('Changes made:').'<ul>';
1447: foreach my $item (sort(keys(%changes))) {
1448: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
1449: }
1.6 raeburn 1450: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 1451: } else {
1452: $resulttext = &mt('No changes made to log-in page settings');
1453: }
1454: } else {
1.11 albertel 1455: $resulttext = '<span class="LC_error">'.
1456: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1457: }
1.6 raeburn 1458: if ($errors) {
1.9 raeburn 1459: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 1460: $errors.'</ul>';
1461: }
1462: return $resulttext;
1463: }
1464:
1465: sub color_font_choices {
1466: my %choices =
1467: &Apache::lonlocal::texthash (
1468: img => "Header",
1469: bgs => "Background colors",
1470: links => "Link colors",
1471: font => "Font color",
1472: pgbg => "Page",
1473: tabbg => "Header",
1474: sidebg => "Border",
1475: link => "Link",
1476: alink => "Active link",
1477: vlink => "Visited link",
1478: );
1479: return %choices;
1480: }
1481:
1482: sub modify_rolecolors {
1.9 raeburn 1483: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 1484: my ($resulttext,%rolehash);
1485: $rolehash{'rolecolors'} = {};
1.9 raeburn 1486: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 1487: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
1488: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
1489: $dom);
1490: if ($putresult eq 'ok') {
1491: if (keys(%changes) > 0) {
1492: $resulttext = &display_colorchgs($dom,\%changes,$roles,
1493: $rolehash{'rolecolors'});
1494: } else {
1495: $resulttext = &mt('No changes made to default color schemes');
1496: }
1497: } else {
1.11 albertel 1498: $resulttext = '<span class="LC_error">'.
1499: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 1500: }
1501: if ($errors) {
1502: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
1503: $errors.'</ul>';
1504: }
1505: return $resulttext;
1506: }
1507:
1508: sub modify_colors {
1.9 raeburn 1509: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 1510: my (%changes,%choices);
1.6 raeburn 1511: my @bgs = ('pgbg','mainbg','sidebg');
1512: my @links = ('link','alink','vlink');
1513: my @images;
1514: my $servadm = $r->dir_config('lonAdmEMail');
1515: my $errors;
1516: foreach my $role (@{$roles}) {
1517: if ($role eq 'login') {
1.12 raeburn 1518: %choices = &login_choices();
1519: } else {
1520: %choices = &color_font_choices();
1521: }
1522: if ($role eq 'login') {
1.6 raeburn 1523: @images = ('img','logo','domlogo');
1524: } else {
1525: @images = ('img');
1526: }
1527: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1528: foreach my $item (@bgs,@links) {
1529: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
1530: }
1.9 raeburn 1531: my ($configuserok,$author_ok,$switchserver,%currroles);
1532: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
1533: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
1534: $confname,$servadm);
1535: if ($configuserok eq 'ok') {
1536: $switchserver = &check_switchserver($dom,$confname);
1537: if ($switchserver eq '') {
1538: $author_ok = &check_authorstatus($dom,$confname,%currroles);
1539: }
1540: }
1541: my ($width,$height) = &thumb_dimensions();
1.8 raeburn 1542: foreach my $img (@images) {
1.18 albertel 1543: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
1544: && !defined($domconfig->{$role}{$img})
1545: && !$env{'form.'.$role.'_del_'.$img}
1546: && $env{'form.'.$role.'_import_'.$img}) {
1547: # import the old configured image from the .tab setting
1548: # if they haven't provided a new one
1549: $domconfig->{$role}{$img} =
1550: $env{'form.'.$role.'_import_'.$img};
1551: }
1.6 raeburn 1552: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 1553: my $error;
1.6 raeburn 1554: if ($configuserok eq 'ok') {
1.9 raeburn 1555: if ($switchserver) {
1.12 raeburn 1556: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 1557: } else {
1558: if ($author_ok eq 'ok') {
1559: my ($result,$logourl) =
1560: &publishlogo($r,'upload',$role.'_'.$img,
1561: $dom,$confname,$img,$width,$height);
1562: if ($result eq 'ok') {
1563: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 1564: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1565: } else {
1.12 raeburn 1566: $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 1567: }
1568: } else {
1.12 raeburn 1569: $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 1570: }
1571: }
1572: } else {
1.12 raeburn 1573: $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 1574: }
1575: if ($error) {
1.8 raeburn 1576: &Apache::lonnet::logthis($error);
1.11 albertel 1577: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 1578: }
1579: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 1580: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1581: my $error;
1582: if ($configuserok eq 'ok') {
1583: # is confname an author?
1584: if ($switchserver eq '') {
1585: if ($author_ok eq 'ok') {
1586: my ($result,$logourl) =
1587: &publishlogo($r,'copy',$domconfig->{$role}{$img},
1588: $dom,$confname,$img,$width,$height);
1589: if ($result eq 'ok') {
1590: $confhash->{$role}{$img} = $logourl;
1.18 albertel 1591: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1592: }
1593: }
1594: }
1595: }
1.6 raeburn 1596: }
1597: }
1598: }
1599: if (ref($domconfig) eq 'HASH') {
1600: if (ref($domconfig->{$role}) eq 'HASH') {
1601: foreach my $img (@images) {
1602: if ($domconfig->{$role}{$img} ne '') {
1603: if ($env{'form.'.$role.'_del_'.$img}) {
1604: $confhash->{$role}{$img} = '';
1.12 raeburn 1605: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1606: } else {
1.9 raeburn 1607: if ($confhash->{$role}{$img} eq '') {
1608: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
1609: }
1.6 raeburn 1610: }
1611: } else {
1612: if ($env{'form.'.$role.'_del_'.$img}) {
1613: $confhash->{$role}{$img} = '';
1.12 raeburn 1614: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1615: }
1616: }
1617: }
1618: if ($domconfig->{$role}{'font'} ne '') {
1619: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
1620: $changes{$role}{'font'} = 1;
1621: }
1622: } else {
1623: if ($confhash->{$role}{'font'}) {
1624: $changes{$role}{'font'} = 1;
1625: }
1626: }
1627: foreach my $item (@bgs) {
1628: if ($domconfig->{$role}{$item} ne '') {
1629: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1630: $changes{$role}{'bgs'}{$item} = 1;
1631: }
1632: } else {
1633: if ($confhash->{$role}{$item}) {
1634: $changes{$role}{'bgs'}{$item} = 1;
1635: }
1636: }
1637: }
1638: foreach my $item (@links) {
1639: if ($domconfig->{$role}{$item} ne '') {
1640: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1641: $changes{$role}{'links'}{$item} = 1;
1642: }
1643: } else {
1644: if ($confhash->{$role}{$item}) {
1645: $changes{$role}{'links'}{$item} = 1;
1646: }
1647: }
1648: }
1649: } else {
1650: &default_change_checker($role,\@images,\@links,\@bgs,
1651: $confhash,\%changes);
1652: }
1653: } else {
1654: &default_change_checker($role,\@images,\@links,\@bgs,
1655: $confhash,\%changes);
1656: }
1657: }
1658: return ($errors,%changes);
1659: }
1660:
1661: sub default_change_checker {
1662: my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
1663: foreach my $item (@{$links}) {
1664: if ($confhash->{$role}{$item}) {
1665: $changes->{$role}{'links'}{$item} = 1;
1666: }
1667: }
1668: foreach my $item (@{$bgs}) {
1669: if ($confhash->{$role}{$item}) {
1670: $changes->{$role}{'bgs'}{$item} = 1;
1671: }
1672: }
1673: foreach my $img (@{$images}) {
1674: if ($env{'form.'.$role.'_del_'.$img}) {
1675: $confhash->{$role}{$img} = '';
1.12 raeburn 1676: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 1677: }
1678: }
1679: if ($confhash->{$role}{'font'}) {
1680: $changes->{$role}{'font'} = 1;
1681: }
1682: }
1683:
1684: sub display_colorchgs {
1685: my ($dom,$changes,$roles,$confhash) = @_;
1686: my (%choices,$resulttext);
1.7 albertel 1687: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 1688: if (!grep(/^login$/,@{$roles})) {
1689: $resulttext = &mt('Changes made:').'<br />';
1690: }
1691: foreach my $role (@{$roles}) {
1692: if ($role eq 'login') {
1693: %choices = &login_choices();
1694: } else {
1695: %choices = &color_font_choices();
1696: }
1697: if (ref($changes->{$role}) eq 'HASH') {
1698: if ($role ne 'login') {
1699: $resulttext .= '<h4>'.&mt($role).'</h4>';
1700: }
1701: foreach my $key (sort(keys(%{$changes->{$role}}))) {
1702: if ($role ne 'login') {
1703: $resulttext .= '<ul>';
1704: }
1705: if (ref($changes->{$role}{$key}) eq 'HASH') {
1706: if ($role ne 'login') {
1707: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
1708: }
1709: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1710: if ($confhash->{$role}{$item} eq '') {
1711: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
1712: } else {
1.12 raeburn 1713: my $newitem = $confhash->{$role}{$item};
1714: if ($key eq 'images') {
1715: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
1716: }
1717: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 1718: }
1719: }
1720: if ($role ne 'login') {
1721: $resulttext .= '</ul></li>';
1722: }
1723: } else {
1724: if ($confhash->{$role}{$key} eq '') {
1725: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
1726: } else {
1727: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
1728: }
1729: }
1730: if ($role ne 'login') {
1731: $resulttext .= '</ul>';
1732: }
1733: }
1734: }
1735: }
1.3 raeburn 1736: return $resulttext;
1.1 raeburn 1737: }
1738:
1.9 raeburn 1739: sub thumb_dimensions {
1740: return ('200','50');
1741: }
1742:
1.16 raeburn 1743: sub check_dimensions {
1744: my ($inputfile) = @_;
1745: my ($fullwidth,$fullheight);
1746: if ($inputfile =~ m|^[/\w.\-]+$|) {
1747: if (open(PIPE,"identify $inputfile 2>&1 |")) {
1748: my $imageinfo = <PIPE>;
1749: if (!close(PIPE)) {
1750: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
1751: }
1752: chomp($imageinfo);
1753: my ($fullsize) =
1.21 raeburn 1754: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 1755: if ($fullsize) {
1756: ($fullwidth,$fullheight) = split(/x/,$fullsize);
1757: }
1758: }
1759: }
1760: return ($fullwidth,$fullheight);
1761: }
1762:
1.9 raeburn 1763: sub check_configuser {
1764: my ($uhome,$dom,$confname,$servadm) = @_;
1765: my ($configuserok,%currroles);
1766: if ($uhome eq 'no_host') {
1767: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1768: my $configpass = &LONCAPA::Enrollment::create_password();
1769: $configuserok =
1770: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
1771: $configpass,'','','','','',undef,$servadm);
1772: } else {
1773: $configuserok = 'ok';
1774: %currroles =
1775: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
1776: }
1777: return ($configuserok,%currroles);
1778: }
1779:
1780: sub check_authorstatus {
1781: my ($dom,$confname,%currroles) = @_;
1782: my $author_ok;
1783: if (!$currroles{':'.$dom.':au'}) {
1784: my $start = time;
1785: my $end = 0;
1786: $author_ok =
1787: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1788: 'au',$end,$start);
1789: } else {
1790: $author_ok = 'ok';
1791: }
1792: return $author_ok;
1793: }
1794:
1795: sub publishlogo {
1796: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
1797: my ($output,$fname,$logourl);
1798: if ($action eq 'upload') {
1799: $fname=$env{'form.'.$formname.'.filename'};
1800: chop($env{'form.'.$formname});
1801: } else {
1802: ($fname) = ($formname =~ /([^\/]+)$/);
1803: }
1804: $fname=&Apache::lonnet::clean_filename($fname);
1805: # See if there is anything left
1806: unless ($fname) { return ('error: no uploaded file'); }
1807: $fname="$subdir/$fname";
1808: my $filepath='/home/'.$confname.'/public_html';
1809: my ($fnamepath,$file,$fetchthumb);
1810: $file=$fname;
1811: if ($fname=~m|/|) {
1812: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
1813: }
1814: my @parts=split(/\//,$filepath.'/'.$fnamepath);
1815: my $count;
1816: for ($count=4;$count<=$#parts;$count++) {
1817: $filepath.="/$parts[$count]";
1818: if ((-e $filepath)!=1) {
1819: mkdir($filepath,02770);
1820: }
1821: }
1822: # Check for bad extension and disallow upload
1823: if ($file=~/\.(\w+)$/ &&
1824: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1825: $output =
1826: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
1827: } elsif ($file=~/\.(\w+)$/ &&
1828: !defined(&Apache::loncommon::fileembstyle($1))) {
1829: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
1830: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1831: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1832: } elsif (-d "$filepath/$file") {
1833: $output = &mt('File name is a directory name - rename the file and re-upload');
1834: } else {
1835: my $source = $filepath.'/'.$file;
1836: my $logfile;
1837: if (!open($logfile,">>$source".'.log')) {
1838: return (&mt('No write permission to Construction Space'));
1839: }
1840: print $logfile
1841: "\n================= Publish ".localtime()." ================\n".
1842: $env{'user.name'}.':'.$env{'user.domain'}."\n";
1843: # Save the file
1844: if (!open(FH,'>'.$source)) {
1845: &Apache::lonnet::logthis('Failed to create '.$source);
1846: return (&mt('Failed to create file'));
1847: }
1848: if ($action eq 'upload') {
1849: if (!print FH ($env{'form.'.$formname})) {
1850: &Apache::lonnet::logthis('Failed to write to '.$source);
1851: return (&mt('Failed to write file'));
1852: }
1853: } else {
1854: my $original = &Apache::lonnet::filelocation('',$formname);
1855: if(!copy($original,$source)) {
1856: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
1857: return (&mt('Failed to write file'));
1858: }
1859: }
1860: close(FH);
1861: chmod(0660, $source); # Permissions to rw-rw---.
1862:
1863: my $docroot=$r->dir_config('lonDocRoot');
1864: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
1865: my $copyfile=$targetdir.'/'.$file;
1866:
1867: my @parts=split(/\//,$targetdir);
1868: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
1869: for (my $count=5;$count<=$#parts;$count++) {
1870: $path.="/$parts[$count]";
1871: if (!-e $path) {
1872: print $logfile "\nCreating directory ".$path;
1873: mkdir($path,02770);
1874: }
1875: }
1876: my $versionresult;
1877: if (-e $copyfile) {
1878: $versionresult = &logo_versioning($targetdir,$file,$logfile);
1879: } else {
1880: $versionresult = 'ok';
1881: }
1882: if ($versionresult eq 'ok') {
1883: if (copy($source,$copyfile)) {
1884: print $logfile "\nCopied original source to ".$copyfile."\n";
1885: $output = 'ok';
1886: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
1887: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1888: } else {
1889: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1890: $output = &mt('Failed to copy file to RES space').", $!";
1891: }
1892: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
1893: my $inputfile = $filepath.'/'.$file;
1894: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 1895: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
1896: if ($fullwidth ne '' && $fullheight ne '') {
1897: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
1898: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1899: system("convert -sample $thumbsize $inputfile $outfile");
1900: chmod(0660, $filepath.'/tn-'.$file);
1901: if (-e $outfile) {
1902: my $copyfile=$targetdir.'/tn-'.$file;
1903: if (copy($outfile,$copyfile)) {
1904: print $logfile "\nCopied source to ".$copyfile."\n";
1905: &write_metadata($dom,$confname,$formname,
1906: $targetdir,'tn-'.$file,$logfile);
1907: } else {
1908: print $logfile "\nUnable to write ".$copyfile.
1909: ':'.$!."\n";
1910: }
1911: }
1.9 raeburn 1912: }
1913: }
1914: }
1915: } else {
1916: $output = $versionresult;
1917: }
1918: }
1919: return ($output,$logourl);
1920: }
1921:
1922: sub logo_versioning {
1923: my ($targetdir,$file,$logfile) = @_;
1924: my $target = $targetdir.'/'.$file;
1925: my ($maxversion,$fn,$extn,$output);
1926: $maxversion = 0;
1927: if ($file =~ /^(.+)\.(\w+)$/) {
1928: $fn=$1;
1929: $extn=$2;
1930: }
1931: opendir(DIR,$targetdir);
1932: while (my $filename=readdir(DIR)) {
1933: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
1934: $maxversion=($1>$maxversion)?$1:$maxversion;
1935: }
1936: }
1937: $maxversion++;
1938: print $logfile "\nCreating old version ".$maxversion."\n";
1939: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
1940: if (copy($target,$copyfile)) {
1941: print $logfile "Copied old target to ".$copyfile."\n";
1942: $copyfile=$copyfile.'.meta';
1943: if (copy($target.'.meta',$copyfile)) {
1944: print $logfile "Copied old target metadata to ".$copyfile."\n";
1945: $output = 'ok';
1946: } else {
1947: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1948: $output = &mt('Failed to copy old meta').", $!, ";
1949: }
1950: } else {
1951: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
1952: $output = &mt('Failed to copy old target').", $!, ";
1953: }
1954: return $output;
1955: }
1956:
1957: sub write_metadata {
1958: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
1959: my (%metadatafields,%metadatakeys,$output);
1960: $metadatafields{'title'}=$formname;
1961: $metadatafields{'creationdate'}=time;
1962: $metadatafields{'lastrevisiondate'}=time;
1963: $metadatafields{'copyright'}='public';
1964: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
1965: $env{'user.domain'};
1966: $metadatafields{'authorspace'}=$confname.':'.$dom;
1967: $metadatafields{'domain'}=$dom;
1968: {
1969: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
1970: my $mfh;
1971: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1972: $output = &mt('Could not write metadata');
1973: }
1974: foreach (sort keys %metadatafields) {
1975: unless ($_=~/\./) {
1976: my $unikey=$_;
1977: $unikey=~/^([A-Za-z]+)/;
1978: my $tag=$1;
1979: $tag=~tr/A-Z/a-z/;
1980: print $mfh "\n\<$tag";
1981: foreach (split(/\,/,$metadatakeys{$unikey})) {
1982: my $value=$metadatafields{$unikey.'.'.$_};
1983: $value=~s/\"/\'\'/g;
1984: print $mfh ' '.$_.'="'.$value.'"';
1985: }
1986: print $mfh '>'.
1987: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
1988: .'</'.$tag.'>';
1989: }
1990: }
1991: $output = 'ok';
1992: print $logfile "\nWrote metadata";
1993: close($mfh);
1994: }
1995: }
1996:
1997: sub check_switchserver {
1998: my ($dom,$confname) = @_;
1999: my ($allowed,$switchserver);
2000: my $home = &Apache::lonnet::homeserver($confname,$dom);
2001: if ($home eq 'no_host') {
2002: $home = &Apache::lonnet::domain($dom,'primary');
2003: }
2004: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 2005: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2006: if (!$allowed) {
2007: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 2008: }
2009: return $switchserver;
2010: }
2011:
1.1 raeburn 2012: sub modify_quotas {
1.3 raeburn 2013: my ($dom,%domconfig) = @_;
1.1 raeburn 2014: my ($resulttext,%changes);
1.26 raeburn 2015: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2016: my %formhash;
2017: foreach my $key (keys(%env)) {
2018: if ($key =~ /^form\.quota_(.+)$/) {
2019: $formhash{$1} = $env{$key};
2020: }
2021: }
1.15 raeburn 2022: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 2023: if (ref($domconfig{'quotas'}) eq 'HASH') {
2024: foreach my $key (keys(%{$domconfig{'quotas'}})) {
2025: if (exists($formhash{$key})) {
2026: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
2027: $changes{$key} = 1;
2028: }
2029: } else {
2030: $formhash{$key} = $domconfig{'quotas'}{$key};
2031: }
2032: }
2033: }
2034: foreach my $key (keys(%formhash)) {
2035: if ($formhash{$key} ne '') {
1.3 raeburn 2036: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 2037: $changes{$key} = 1;
2038: }
2039: }
2040: }
2041: my %quotahash = (
1.3 raeburn 2042: quotas => {%formhash},
1.1 raeburn 2043: );
2044: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
2045: $dom);
2046: if ($putresult eq 'ok') {
2047: if (keys(%changes) > 0) {
2048: $resulttext = &mt('Changes made:').'<ul>';
1.26 raeburn 2049: foreach my $type (@{$types},'default') {
2050: if (defined($changes{$type})) {
2051: my $typetitle = $usertypes->{$type};
2052: if ($type eq 'default') {
2053: $typetitle = $othertitle;
2054: }
2055: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
2056: }
1.1 raeburn 2057: }
2058: $resulttext .= '</ul>';
2059: } else {
2060: $resulttext = &mt('No changes made to default quotas');
2061: }
2062: } else {
1.11 albertel 2063: $resulttext = '<span class="LC_error">'.
2064: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2065: }
1.3 raeburn 2066: return $resulttext;
1.1 raeburn 2067: }
2068:
1.3 raeburn 2069: sub modify_autoenroll {
2070: my ($dom,%domconfig) = @_;
1.1 raeburn 2071: my ($resulttext,%changes);
2072: my %currautoenroll;
2073: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
2074: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
2075: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
2076: }
2077: }
2078: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2079: my %title = ( run => 'Auto-enrollment active',
2080: sender => 'Sender for notification messages');
2081: my @offon = ('off','on');
1.17 raeburn 2082: my $sender_uname = $env{'form.sender_uname'};
2083: my $sender_domain = $env{'form.sender_domain'};
2084: if ($sender_domain eq '') {
2085: $sender_uname = '';
2086: } elsif ($sender_uname eq '') {
2087: $sender_domain = '';
2088: }
1.1 raeburn 2089: my %autoenrollhash = (
2090: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 2091: sender_uname => $sender_uname,
2092: sender_domain => $sender_domain,
1.1 raeburn 2093:
2094: }
2095: );
1.4 raeburn 2096: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
2097: $dom);
1.1 raeburn 2098: if ($putresult eq 'ok') {
2099: if (exists($currautoenroll{'run'})) {
2100: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
2101: $changes{'run'} = 1;
2102: }
2103: } elsif ($autorun) {
2104: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 2105: $changes{'run'} = 1;
1.1 raeburn 2106: }
2107: }
1.17 raeburn 2108: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 2109: $changes{'sender'} = 1;
2110: }
1.17 raeburn 2111: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 2112: $changes{'sender'} = 1;
2113: }
2114: if (keys(%changes) > 0) {
2115: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 2116: if ($changes{'run'}) {
1.1 raeburn 2117: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
2118: }
2119: if ($changes{'sender'}) {
1.17 raeburn 2120: if ($sender_uname eq '' || $sender_domain eq '') {
2121: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
2122: } else {
2123: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
2124: }
1.1 raeburn 2125: }
2126: $resulttext .= '</ul>';
2127: } else {
2128: $resulttext = &mt('No changes made to auto-enrollment settings');
2129: }
2130: } else {
1.11 albertel 2131: $resulttext = '<span class="LC_error">'.
2132: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2133: }
1.3 raeburn 2134: return $resulttext;
1.1 raeburn 2135: }
2136:
2137: sub modify_autoupdate {
1.3 raeburn 2138: my ($dom,%domconfig) = @_;
1.1 raeburn 2139: my ($resulttext,%currautoupdate,%fields,%changes);
2140: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
2141: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
2142: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
2143: }
2144: }
2145: my @offon = ('off','on');
2146: my %title = &Apache::lonlocal::texthash (
2147: run => 'Auto-update:',
2148: classlists => 'Updates to user information in classlists?'
2149: );
1.26 raeburn 2150: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2151: my %fieldtitles = &Apache::lonlocal::texthash (
2152: id => 'Student/Employee ID',
1.20 raeburn 2153: permanentemail => 'E-mail address',
1.1 raeburn 2154: lastname => 'Last Name',
2155: firstname => 'First Name',
2156: middlename => 'Middle Name',
2157: gen => 'Generation',
2158: );
2159: my $othertitle = &mt('All users');
2160: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 2161: $othertitle = &mt('Other users');
1.1 raeburn 2162: }
2163: foreach my $key (keys(%env)) {
2164: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
2165: push(@{$fields{$1}},$2);
2166: }
2167: }
2168: my %updatehash = (
2169: autoupdate => { run => $env{'form.autoupdate_run'},
2170: classlists => $env{'form.classlists'},
2171: fields => {%fields},
2172: }
2173: );
2174: foreach my $key (keys(%currautoupdate)) {
2175: if (($key eq 'run') || ($key eq 'classlists')) {
2176: if (exists($updatehash{autoupdate}{$key})) {
2177: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
2178: $changes{$key} = 1;
2179: }
2180: }
2181: } elsif ($key eq 'fields') {
2182: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 2183: foreach my $item (@{$types},'default') {
1.1 raeburn 2184: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
2185: my $change = 0;
2186: foreach my $type (@{$currautoupdate{$key}{$item}}) {
2187: if (!exists($fields{$item})) {
2188: $change = 1;
2189: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 2190: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 2191: $change = 1;
2192: }
2193: }
2194: }
2195: if ($change) {
2196: push(@{$changes{$key}},$item);
2197: }
1.26 raeburn 2198: }
1.1 raeburn 2199: }
2200: }
2201: }
2202: }
1.26 raeburn 2203: foreach my $item (@{$types},'default') {
2204: if (defined($fields{$item})) {
2205: if (ref($currautoupdate{'fields'}) eq 'HASH') {
2206: if (!exists($currautoupdate{'fields'}{$item})) {
2207: push(@{$changes{'fields'}},$item);
2208: }
2209: } else {
2210: push(@{$changes{'fields'}},$item);
1.1 raeburn 2211: }
2212: }
2213: }
2214: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
2215: $dom);
2216: if ($putresult eq 'ok') {
2217: if (keys(%changes) > 0) {
2218: $resulttext = &mt('Changes made:').'<ul>';
2219: foreach my $key (sort(keys(%changes))) {
2220: if (ref($changes{$key}) eq 'ARRAY') {
2221: foreach my $item (@{$changes{$key}}) {
2222: my @newvalues;
2223: foreach my $type (@{$fields{$item}}) {
2224: push(@newvalues,$fieldtitles{$type});
2225: }
1.3 raeburn 2226: my $newvaluestr;
2227: if (@newvalues > 0) {
2228: $newvaluestr = join(', ',@newvalues);
2229: } else {
2230: $newvaluestr = &mt('none');
1.6 raeburn 2231: }
1.1 raeburn 2232: if ($item eq 'default') {
1.26 raeburn 2233: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 2234: } else {
1.26 raeburn 2235: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 2236: }
2237: }
2238: } else {
2239: my $newvalue;
2240: if ($key eq 'run') {
2241: $newvalue = $offon[$env{'form.autoupdate_run'}];
2242: } else {
2243: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 2244: }
1.1 raeburn 2245: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
2246: }
2247: }
2248: $resulttext .= '</ul>';
2249: } else {
1.3 raeburn 2250: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 2251: }
2252: } else {
1.11 albertel 2253: $resulttext = '<span class="LC_error">'.
2254: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2255: }
1.3 raeburn 2256: return $resulttext;
1.1 raeburn 2257: }
2258:
1.23 raeburn 2259: sub modify_directorysrch {
2260: my ($dom,%domconfig) = @_;
2261: my ($resulttext,%changes);
2262: my %currdirsrch;
2263: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2264: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
2265: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
2266: }
2267: }
2268: my %title = ( available => 'Directory search available',
1.24 raeburn 2269: localonly => 'Other domains can search',
1.23 raeburn 2270: searchby => 'Search types',
2271: searchtypes => 'Search latitude');
2272: my @offon = ('off','on');
1.24 raeburn 2273: my @otherdoms = ('Yes','No');
1.23 raeburn 2274:
1.25 raeburn 2275: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 2276: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
2277: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
2278:
1.26 raeburn 2279: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
2280: if (keys(%{$usertypes}) == 0) {
2281: @cansearch = ('default');
2282: } else {
2283: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
2284: foreach my $type (@{$currdirsrch{'cansearch'}}) {
2285: if (!grep(/^\Q$type\E$/,@cansearch)) {
2286: push(@{$changes{'cansearch'}},$type);
2287: }
1.23 raeburn 2288: }
1.26 raeburn 2289: foreach my $type (@cansearch) {
2290: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
2291: push(@{$changes{'cansearch'}},$type);
2292: }
1.23 raeburn 2293: }
1.26 raeburn 2294: } else {
2295: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 2296: }
2297: }
2298:
2299: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
2300: foreach my $by (@{$currdirsrch{'searchby'}}) {
2301: if (!grep(/^\Q$by\E$/,@searchby)) {
2302: push(@{$changes{'searchby'}},$by);
2303: }
2304: }
2305: foreach my $by (@searchby) {
2306: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
2307: push(@{$changes{'searchby'}},$by);
2308: }
2309: }
2310: } else {
2311: push(@{$changes{'searchby'}},@searchby);
2312: }
1.25 raeburn 2313:
2314: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
2315: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
2316: if (!grep(/^\Q$type\E$/,@searchtypes)) {
2317: push(@{$changes{'searchtypes'}},$type);
2318: }
2319: }
2320: foreach my $type (@searchtypes) {
2321: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
2322: push(@{$changes{'searchtypes'}},$type);
2323: }
2324: }
2325: } else {
2326: if (exists($currdirsrch{'searchtypes'})) {
2327: foreach my $type (@searchtypes) {
2328: if ($type ne $currdirsrch{'searchtypes'}) {
2329: push(@{$changes{'searchtypes'}},$type);
2330: }
2331: }
2332: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
2333: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
2334: }
2335: } else {
2336: push(@{$changes{'searchtypes'}},@searchtypes);
2337: }
2338: }
2339:
1.23 raeburn 2340: my %dirsrch_hash = (
2341: directorysrch => { available => $env{'form.dirsrch_available'},
2342: cansearch => \@cansearch,
1.24 raeburn 2343: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 2344: searchby => \@searchby,
1.25 raeburn 2345: searchtypes => \@searchtypes,
1.23 raeburn 2346: }
2347: );
2348: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
2349: $dom);
2350: if ($putresult eq 'ok') {
2351: if (exists($currdirsrch{'available'})) {
2352: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
2353: $changes{'available'} = 1;
2354: }
2355: } else {
2356: if ($env{'form.dirsrch_available'} eq '1') {
2357: $changes{'available'} = 1;
2358: }
2359: }
1.24 raeburn 2360: if (exists($currdirsrch{'localonly'})) {
2361: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
2362: $changes{'localonly'} = 1;
2363: }
2364: } else {
2365: if ($env{'form.dirsrch_localonly'} eq '1') {
2366: $changes{'localonly'} = 1;
2367: }
2368: }
1.23 raeburn 2369: if (keys(%changes) > 0) {
2370: $resulttext = &mt('Changes made:').'<ul>';
2371: if ($changes{'available'}) {
2372: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
2373: }
1.24 raeburn 2374: if ($changes{'localonly'}) {
2375: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
2376: }
2377:
1.23 raeburn 2378: if (ref($changes{'cansearch'}) eq 'ARRAY') {
2379: my $chgtext;
1.26 raeburn 2380: if (ref($usertypes) eq 'HASH') {
2381: if (keys(%{$usertypes}) > 0) {
2382: foreach my $type (@{$types}) {
2383: if (grep(/^\Q$type\E$/,@cansearch)) {
2384: $chgtext .= $usertypes->{$type}.'; ';
2385: }
2386: }
2387: if (grep(/^default$/,@cansearch)) {
2388: $chgtext .= $othertitle;
2389: } else {
2390: $chgtext =~ s/\; $//;
2391: }
2392: $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23 raeburn 2393: }
2394: }
2395: }
2396: if (ref($changes{'searchby'}) eq 'ARRAY') {
2397: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2398: my $chgtext;
2399: foreach my $type (@{$titleorder}) {
2400: if (grep(/^\Q$type\E$/,@searchby)) {
2401: if (defined($searchtitles->{$type})) {
2402: $chgtext .= $searchtitles->{$type}.'; ';
2403: }
2404: }
2405: }
2406: $chgtext =~ s/\; $//;
2407: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
2408: }
1.25 raeburn 2409: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
2410: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
2411: my $chgtext;
2412: foreach my $type (@{$srchtypeorder}) {
2413: if (grep(/^\Q$type\E$/,@searchtypes)) {
2414: if (defined($srchtypes_desc->{$type})) {
2415: $chgtext .= $srchtypes_desc->{$type}.'; ';
2416: }
2417: }
2418: }
2419: $chgtext =~ s/\; $//;
2420: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 2421: }
2422: $resulttext .= '</ul>';
2423: } else {
2424: $resulttext = &mt('No changes made to institution directory search settings');
2425: }
2426: } else {
2427: $resulttext = '<span class="LC_error">'.
1.27 raeburn 2428: &mt('An error occurred: [_1]',$putresult).'</span>';
2429: }
2430: return $resulttext;
2431: }
2432:
1.28 raeburn 2433: sub modify_contacts {
2434: my ($dom,%domconfig) = @_;
2435: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
2436: if (ref($domconfig{'contacts'}) eq 'HASH') {
2437: foreach my $key (keys(%{$domconfig{'contacts'}})) {
2438: $currsetting{$key} = $domconfig{'contacts'}{$key};
2439: }
2440: }
2441: my (%others,%to);
2442: my @contacts = ('supportemail','adminemail');
2443: my @mailings = ('errormail','packagesmail','helpdeskmail');
2444: foreach my $type (@mailings) {
2445: @{$newsetting{$type}} =
2446: &Apache::loncommon::get_env_multiple('form.'.$type);
2447: foreach my $item (@contacts) {
2448: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
2449: $contacts_hash{contacts}{$type}{$item} = 1;
2450: } else {
2451: $contacts_hash{contacts}{$type}{$item} = 0;
2452: }
2453: }
2454: $others{$type} = $env{'form.'.$type.'_others'};
2455: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
2456: }
2457: foreach my $item (@contacts) {
2458: $to{$item} = $env{'form.'.$item};
2459: $contacts_hash{'contacts'}{$item} = $to{$item};
2460: }
2461: if (keys(%currsetting) > 0) {
2462: foreach my $item (@contacts) {
2463: if ($to{$item} ne $currsetting{$item}) {
2464: $changes{$item} = 1;
2465: }
2466: }
2467: foreach my $type (@mailings) {
2468: foreach my $item (@contacts) {
2469: if (ref($currsetting{$type}) eq 'HASH') {
2470: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
2471: push(@{$changes{$type}},$item);
2472: }
2473: } else {
2474: push(@{$changes{$type}},@{$newsetting{$type}});
2475: }
2476: }
2477: if ($others{$type} ne $currsetting{$type}{'others'}) {
2478: push(@{$changes{$type}},'others');
2479: }
2480: }
2481: } else {
2482: my %default;
2483: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2484: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2485: $default{'errormail'} = 'adminemail';
2486: $default{'packagesmail'} = 'adminemail';
2487: $default{'helpdeskmail'} = 'supportemail';
2488: foreach my $item (@contacts) {
2489: if ($to{$item} ne $default{$item}) {
2490: $changes{$item} = 1;
2491: }
2492: }
2493: foreach my $type (@mailings) {
2494: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
2495:
2496: push(@{$changes{$type}},@{$newsetting{$type}});
2497: }
2498: if ($others{$type} ne '') {
2499: push(@{$changes{$type}},'others');
2500: }
2501: }
2502: }
2503: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
2504: $dom);
2505: if ($putresult eq 'ok') {
2506: if (keys(%changes) > 0) {
2507: my ($titles,$short_titles) = &contact_titles();
2508: $resulttext = &mt('Changes made:').'<ul>';
2509: foreach my $item (@contacts) {
2510: if ($changes{$item}) {
2511: $resulttext .= '<li>'.$titles->{$item}.
2512: &mt(' set to: ').
2513: '<span class="LC_cusr_emph">'.
2514: $to{$item}.'</span></li>';
2515: }
2516: }
2517: foreach my $type (@mailings) {
2518: if (ref($changes{$type}) eq 'ARRAY') {
2519: $resulttext .= '<li>'.$titles->{$type}.': ';
2520: my @text;
2521: foreach my $item (@{$newsetting{$type}}) {
2522: push(@text,$short_titles->{$item});
2523: }
2524: if ($others{$type} ne '') {
2525: push(@text,$others{$type});
2526: }
2527: $resulttext .= '<span class="LC_cusr_emph">'.
2528: join(', ',@text).'</span></li>';
2529: }
2530: }
2531: $resulttext .= '</ul>';
2532: } else {
2533: $resulttext = &mt('No changes made to contact information.');
2534: }
2535: } else {
2536: $resulttext = '<span class="LC_error">'.
2537: &mt('An error occurred: [_1].',$putresult).'</span>';
2538: }
2539: return $resulttext;
2540: }
2541:
2542: sub modify_usercreation {
1.27 raeburn 2543: my ($dom,%domconfig) = @_;
1.28 raeburn 2544: my ($resulttext,%curr_usercreation,%changes,%authallowed);
1.27 raeburn 2545: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2546: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
2547: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
2548: }
2549: }
2550: my %title = &Apache::lonlocal::texthash (
2551: author => 'adding co-authors/assistant authors',
2552: course => 'adding users to a course',
2553: );
2554: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
2555: my @cancreate = &Apache::loncommon::get_env_multiple('form.can_createuser');
2556: if (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
2557: foreach my $type (@{$curr_usercreation{'cancreate'}}) {
2558: if (!grep(/^\Q$type\E$/,@cancreate)) {
2559: push(@{$changes{'cancreate'}},$type);
2560: }
2561: }
2562: foreach my $type (@cancreate) {
2563: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) {
2564: push(@{$changes{'cancreate'}},$type);
2565: }
2566: }
2567: } else {
2568: push(@{$changes{'cancreate'}},@cancreate);
2569: }
2570: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
2571: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
2572: if (!grep(/^\Q$type\E$/,@username_rule)) {
2573: push(@{$changes{'username_rule'}},$type);
2574: }
2575: }
2576: foreach my $type (@username_rule) {
2577: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
2578: push(@{$changes{'username_rule'}},$type);
2579: }
2580: }
2581: } else {
2582: push(@{$changes{'username_rule'}},@username_rule);
2583: }
2584:
1.28 raeburn 2585: my @contexts = ('author','course','domain');
2586: my @authtypes = ('int','krb4','krb5','loc');
2587: my %authhash;
2588: foreach my $item (@contexts) {
2589: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
2590: foreach my $auth (@authtypes) {
2591: if (grep(/^\Q$auth\E$/,@authallowed)) {
2592: $authhash{$item}{$auth} = 1;
2593: } else {
2594: $authhash{$item}{$auth} = 0;
2595: }
2596: }
2597: }
2598: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
2599: foreach my $item (@contexts) {
2600: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
2601: foreach my $auth (@authtypes) {
2602: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
2603: push(@{$changes{'authtypes'}},$item);
2604: last;
2605: }
2606: }
2607: }
2608: }
2609: } else {
2610: foreach my $item (@contexts) {
2611: push(@{$changes{'authtypes'}},$item);
2612: }
2613: }
2614:
1.27 raeburn 2615: my %usercreation_hash = (
1.28 raeburn 2616: usercreation => {
1.27 raeburn 2617: cancreate => \@cancreate,
2618: username_rule => \@username_rule,
1.28 raeburn 2619: authtypes => \%authhash,
1.27 raeburn 2620: }
2621: );
2622:
2623: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
2624: $dom);
2625: if ($putresult eq 'ok') {
2626: if (keys(%changes) > 0) {
2627: $resulttext = &mt('Changes made:').'<ul>';
2628: if (ref($changes{'cancreate'}) eq 'ARRAY') {
2629: my $chgtext = '<ul>';
2630: foreach my $type (@cancreate) {
2631: $chgtext .= '<li>'.$title{$type}.'</li>';
2632: }
2633: $chgtext .= '</ul>';
2634: if (@cancreate > 0) {
2635: $resulttext .= '<li>'.&mt('Creation of new users is permitted by a Domain Coordinator, and also by other users when: ').$chgtext.'</li>';
2636: } else {
2637: $resulttext .= '<li>'.&mt("Creation of new users is now only allowed when the user's role is Domain Coordinator.").'</li>';
2638: }
2639: }
2640: if (ref($changes{'username_rule'}) eq 'ARRAY') {
2641: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom);
2642: my $chgtext = '<ul>';
2643: foreach my $type (@username_rule) {
2644: if (ref($rules->{$type}) eq 'HASH') {
2645: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
2646: }
2647: }
2648: $chgtext .= '</ul>';
2649: if (@username_rule > 0) {
2650: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
2651: } else {
1.28 raeburn 2652: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 2653: }
2654: }
1.28 raeburn 2655: my %authname = &authtype_names();
2656: my %context_title = &context_names();
2657: if (ref($changes{'authtypes'}) eq 'ARRAY') {
2658: my @unchanged;
2659: my $chgtext = '<ul>';
2660: foreach my $type (@{$changes{'authtypes'}}) {
2661: my @allowed;
2662: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
2663: foreach my $auth (@authtypes) {
2664: if ($authhash{$type}{$auth}) {
2665: push(@allowed,$authname{$auth});
2666: }
2667: }
2668: $chgtext .= join(', ',@allowed).'</li>';
2669: }
2670: $chgtext .= '</ul>';
2671: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
2672: $resulttext .= '</li>';
2673: }
1.27 raeburn 2674: $resulttext .= '</ul>';
2675: } else {
1.28 raeburn 2676: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 2677: }
2678: } else {
2679: $resulttext = '<span class="LC_error">'.
1.23 raeburn 2680: &mt('An error occurred: [_1]',$putresult).'</span>';
2681: }
2682: return $resulttext;
2683: }
2684:
1.3 raeburn 2685: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>