Annotation of loncom/interface/domainprefs.pm, revision 1.43
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.43 ! raeburn 4: # $Id: domainprefs.pm,v 1.42 2008/02/15 17:02:31 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;
1.43 ! raeburn 39: use Apache::lonmsg();
1.1 raeburn 40: use LONCAPA();
1.6 raeburn 41: use LONCAPA::Enrollment;
1.9 raeburn 42: use File::Copy;
1.43 ! raeburn 43: use Locale::Language;
1.1 raeburn 44:
45: sub handler {
46: my $r=shift;
47: if ($r->header_only) {
48: &Apache::loncommon::content_type($r,'text/html');
49: $r->send_http_header;
50: return OK;
51: }
52:
53: my $dom = $env{'request.role.domain'};
1.5 albertel 54: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 55: if (&Apache::lonnet::allowed('mau',$dom)) {
56: &Apache::loncommon::content_type($r,'text/html');
57: $r->send_http_header;
58: } else {
59: $env{'user.error.msg'}=
60: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
61: return HTTP_NOT_ACCEPTABLE;
62: }
63: &Apache::lonhtmlcommon::clear_breadcrumbs();
64: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
65: ['phase']);
1.30 raeburn 66: my $phase = 'pickactions';
1.3 raeburn 67: if ( exists($env{'form.phase'}) ) {
68: $phase = $env{'form.phase'};
69: }
70: my %domconfig =
1.6 raeburn 71: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.27 raeburn 72: 'quotas','autoenroll','autoupdate','directorysrch',
1.43 ! raeburn 73: 'usercreation','usermodification','contacts','defaults'],$dom);
! 74: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.30 raeburn 75: 'autoupdate','directorysrch','contacts',
1.33 raeburn 76: 'usercreation','usermodification');
1.30 raeburn 77: my %prefs = (
78: 'rolecolors' =>
79: { text => 'Default color schemes',
80: help => 'Default_Color_Schemes',
81: header => [{col1 => 'Student Settings',
82: col2 => '',},
83: {col1 => 'Coordinator Settings',
84: col2 => '',},
85: {col1 => 'Author Settings',
86: col2 => '',},
87: {col1 => 'Administrator Settings',
88: col2 => '',}],
89: },
90: 'login' =>
91: { text => 'Log-in page options',
92: help => 'Domain_Log-in_Page',
93: header => [{col1 => 'Item',
94: col2 => '',}],
95: },
1.43 ! raeburn 96: 'defaults' =>
! 97: { text => 'Default authentication/language',
! 98: help => '',
! 99: header => [{col1 => 'Setting',
! 100: col2 => 'Value'}],
! 101: },
1.30 raeburn 102: 'quotas' =>
103: { text => 'Default quotas for user portfolios',
104: help => 'Default_User_Quota',
105: header => [{col1 => 'User type',
106: col2 => 'Default quota'}],
107: },
108: 'autoenroll' =>
109: { text => 'Auto-enrollment settings',
110: help => 'Domain_Auto_Enrollment',
111: header => [{col1 => 'Configuration setting',
112: col2 => 'Value(s)'}],
113: },
114: 'autoupdate' =>
115: { text => 'Auto-update settings',
116: help => 'Domain_Auto_Update',
117: header => [{col1 => 'Setting',
118: col2 => 'Value',},
1.43 ! raeburn 119: {col1 => 'User population',
1.30 raeburn 120: col2 => 'Updataeable user data'}],
121: },
122: 'directorysrch' =>
123: { text => 'Institutional directory searches',
124: help => 'Domain_Directory_Search',
125: header => [{col1 => 'Setting',
126: col2 => 'Value',}],
127: },
128: 'contacts' =>
129: { text => 'Contact Information',
130: help => 'Domain_Contact_Information',
131: header => [{col1 => 'Setting',
132: col2 => 'Value',}],
133: },
134:
135: 'usercreation' =>
136: { text => 'User creation',
137: help => 'Domain_User_Creation',
1.43 ! raeburn 138: header => [{col1 => 'Format rule type',
! 139: col2 => 'Format rules in force'},
1.34 raeburn 140: {col1 => 'User account creation',
141: col2 => 'Usernames which may be created',},
1.30 raeburn 142: {col1 => 'Context',
1.43 ! raeburn 143: col2 => 'Assignable authentication types'}],
1.30 raeburn 144: },
1.33 raeburn 145: 'usermodification' =>
146: { text => 'User modification',
147: help => 'Domain_User_Modification',
148: header => [{col1 => 'Target user has role',
149: col2 => 'User information updateable in author context'},
150: {col1 => 'Target user has role',
151: col2 => 'User information updateable in course context'}],
152: },
1.3 raeburn 153: );
1.6 raeburn 154: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 155: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 156: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 157: ({href=>"javascript:changePage(document.$phase,'pickactions')",
158: text=>"Pick functionality"});
1.9 raeburn 159: my $confname = $dom.'-domainconfig';
1.3 raeburn 160: if ($phase eq 'process') {
1.1 raeburn 161: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 162: ({href=>"javascript:changePage(document.$phase,'display')",
163: text=>"Domain Configuration"},
164: {href=>"javascript:changePage(document.$phase,'$phase')",
1.3 raeburn 165: text=>"Updated"});
166: &print_header($r,$phase);
1.30 raeburn 167: foreach my $item (@prefs_order) {
168: if (grep(/^\Q$item\E$/,@actions)) {
169: $r->print('<h3>'.&mt($prefs{$item}{'text'}).'</h3>'.
170: &process_changes($r,$dom,$confname,$item,
171: \@roles,%domconfig));
172: }
1.3 raeburn 173: }
174: $r->print('<p>');
1.30 raeburn 175: &print_footer($r,$phase,'display','Back to configuration display',
176: \@actions);
1.3 raeburn 177: $r->print('</p>');
1.30 raeburn 178: } elsif ($phase eq 'display') {
179: &Apache::lonhtmlcommon::add_breadcrumb
180: ({href=>"javascript:changePage(document.$phase,'display')",
181: text=>"Domain Configuration"});
182: &print_header($r,$phase);
183: if (@actions > 0) {
184: my $rowsum = 0;
185: my (%output,%rowtotal,@items);
186: my $halfway = @actions/2;
187: foreach my $item (@prefs_order) {
188: if (grep(/^\Q$item\E$/,@actions)) {
189: push(@items,$item);
190: ($output{$item},$rowtotal{$item}) =
191: &print_config_box($r,$dom,$confname,$phase,
192: $item,$prefs{$item},
193: $domconfig{$item});
194: $rowsum += $rowtotal{$item};
195: }
196: }
197: my $colend;
198: my $halfway = $rowsum/2;
199: my $aggregate = 0;
200: my $sumleft = 0;
201: my $sumright = 0;
202: my $crossover;
203: for (my $i=0; $i<@items; $i++) {
204: $aggregate += $rowtotal{$items[$i]};
205: if ($aggregate > $halfway) {
206: $crossover = $i;
207: last;
208: }
209: }
210: for (my $i=0; $i<$crossover; $i++) {
211: $sumleft += $rowtotal{$items[$i]};
212: }
213: for (my $i=$crossover+1; $i<@items; $i++) {
214: $sumright += $rowtotal{$items[$i]};
215: }
216: if ((@items > 1) && ($env{'form.numcols'} == 2)) {
217: my $sumdiff = $sumright - $sumleft;
218: if ($sumdiff > 0) {
219: $colend = $crossover + 1;
220: } else {
221: $colend = $crossover;
222: }
223: } else {
224: $colend = @items;
225: }
226: $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');
227: for (my $i=0; $i<$colend; $i++) {
228: $r->print($output{$items[$i]});
229: }
230: $r->print('</td><td></td><td class="LC_right_col">');
231: if ($colend < @items) {
232: for (my $i=$colend; $i<@items; $i++) {
233: $r->print($output{$items[$i]});
234: }
235: }
236: $r->print('</td></tr></table></p>');
237: $r->print(&print_footer($r,$phase,'process','Save',\@actions));
238: } else {
239: $r->print('<input type="hidden" name="phase" value="" />'.
240: '<input type="hidden" name="numcols" value="'.
241: $env{'form.numcols'}.'" />'."\n".
242: '<span clas="LC_error">'.&mt('No settings chosen').
243: '</span>');
244: }
245: $r->print('</form>');
246: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 247: } else {
1.3 raeburn 248: if ($phase eq '') {
1.30 raeburn 249: $phase = 'pickactions';
1.1 raeburn 250: }
1.30 raeburn 251: my %helphash;
1.3 raeburn 252: &print_header($r,$phase);
1.21 raeburn 253: if (keys(%domconfig) == 0) {
254: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 255: my @ids=&Apache::lonnet::current_machine_ids();
256: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 257: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 258: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 259: my $custom_img_count = 0;
260: foreach my $img (@loginimages) {
261: if ($designhash{$dom.'.login.'.$img} ne '') {
262: $custom_img_count ++;
263: }
264: }
265: foreach my $role (@roles) {
266: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
267: $custom_img_count ++;
268: }
269: }
270: if ($custom_img_count > 0) {
271: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 272: $r->print(
273: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
274: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
275: &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 />'.
276: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
277: if ($switch_server) {
1.30 raeburn 278: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 279: }
1.21 raeburn 280: return OK;
281: }
282: }
283: }
1.30 raeburn 284: $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');
285: $r->print('<script type="text/javascript">'."\n".
286: &Apache::loncommon::check_uncheck_jscript()."\n".
287: '</script>'."\n".'<p><input type="button" value="check all" '.
288: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
289: ' /> '.
290: '<input type="button" value="uncheck all" '.
291: 'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
1.38 raeburn 292: ' /></p><div class="LC_left_float">');
293: my ($numitems,$midpoint,$seconddiv,$count);
294: $numitems = @prefs_order;
295: $midpoint = int($numitems/2);
296: if ($numitems%2) {
297: $midpoint ++;
298: }
299: $count = 0;
1.30 raeburn 300: foreach my $item (@prefs_order) {
1.38 raeburn 301: $r->print('<h4><label><input type="checkbox" name="actions" value="'.$item.'" /> '.$prefs{$item}->{'text'}.'</label></h4>');
302: $count ++;
303: if ((!$seconddiv) && ($count >= $midpoint)) {
304: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
305: $seconddiv = 1;
306: }
1.30 raeburn 307: }
1.38 raeburn 308: $r->print('</div><div class="LC_clear_float_footer"></div><h3>'.
309: &mt('Display options').'</h3>'."\n".
1.30 raeburn 310: '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
311: '<label><input type="radio" name="numcols" value="1">'.
312: &mt('one column').'</label> '.
313: '<input type="radio" name="numcols" value="2">'.
314: &mt('two columns').'</label></span></p>');
315: $r->print(&print_footer($r,$phase,'display','Go'));
316: $r->print('</form>');
317: $r->print(&Apache::loncommon::end_page());
1.3 raeburn 318: }
319: return OK;
320: }
321:
322: sub process_changes {
1.9 raeburn 323: my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
1.3 raeburn 324: my $output;
325: if ($action eq 'login') {
1.9 raeburn 326: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 327: } elsif ($action eq 'rolecolors') {
1.9 raeburn 328: $output = &modify_rolecolors($r,$dom,$confname,$roles,
329: %domconfig);
1.3 raeburn 330: } elsif ($action eq 'quotas') {
331: $output = &modify_quotas($dom,%domconfig);
332: } elsif ($action eq 'autoenroll') {
333: $output = &modify_autoenroll($dom,%domconfig);
334: } elsif ($action eq 'autoupdate') {
335: $output = &modify_autoupdate($dom,%domconfig);
1.23 raeburn 336: } elsif ($action eq 'directorysrch') {
337: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 338: } elsif ($action eq 'usercreation') {
1.28 raeburn 339: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 340: } elsif ($action eq 'usermodification') {
341: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 342: } elsif ($action eq 'contacts') {
343: $output = &modify_contacts($dom,%domconfig);
1.43 ! raeburn 344: } elsif ($action eq 'defaults') {
! 345: $output = &modify_defaults($dom,$r);
1.3 raeburn 346: }
347: return $output;
348: }
349:
350: sub print_config_box {
1.9 raeburn 351: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 352: my $rowtotal = 0;
353: my $output =
354: '<table class="LC_nested_outer">
1.3 raeburn 355: <tr>
1.30 raeburn 356: <th align="left"><span class="LC_nobreak">'.&mt($item->{text}).
357: ' </span></th></tr>';
1.22 raeburn 358: #
359: # FIXME - put the help link back in when the help files exist
360: # <th>'.&mt($item->{text}).' '.
361: # &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
362: # </tr>');
1.30 raeburn 363: $rowtotal ++;
1.28 raeburn 364: if (($action eq 'autoupdate') || ($action eq 'rolecolors') ||
1.33 raeburn 365: ($action eq 'usercreation') || ($action eq 'usermodification')) {
1.6 raeburn 366: my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
1.30 raeburn 367: $output .= '
1.3 raeburn 368: <tr>
369: <td>
370: <table class="LC_nested">
371: <tr class="LC_info_row">
1.6 raeburn 372: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
1.3 raeburn 373: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.30 raeburn 374: </tr>';
375: $rowtotal ++;
1.6 raeburn 376: if ($action eq 'autoupdate') {
1.30 raeburn 377: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 378: } elsif ($action eq 'usercreation') {
1.33 raeburn 379: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
380: } elsif ($action eq 'usermodification') {
381: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.6 raeburn 382: } else {
1.30 raeburn 383: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 384: }
1.30 raeburn 385: $output .= '
1.6 raeburn 386: </table>
387: </td>
388: </tr>
389: <tr>
390: <td>
391: <table class="LC_nested">
392: <tr class="LC_info_row">
393: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
394: <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
1.30 raeburn 395: </tr>';
396: $rowtotal ++;
1.6 raeburn 397: if ($action eq 'autoupdate') {
1.30 raeburn 398: $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
1.28 raeburn 399: } elsif ($action eq 'usercreation') {
1.34 raeburn 400: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
401: </table>
402: </td>
403: </tr>
404: <tr>
405: <td>
406: <table class="LC_nested">
407: <tr class="LC_info_row">
408: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
409: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td> </tr>'.
410: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
411: $rowtotal ++;
1.33 raeburn 412: } elsif ($action eq 'usermodification') {
413: $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal);
1.6 raeburn 414: } else {
1.30 raeburn 415: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 416: </table>
417: </td>
418: </tr>
419: <tr>
420: <td>
421: <table class="LC_nested">
422: <tr class="LC_info_row">
423: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
424: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
1.3 raeburn 425: </tr>'.
1.30 raeburn 426: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 427: </table>
428: </td>
429: </tr>
430: <tr>
431: <td>
432: <table class="LC_nested">
433: <tr class="LC_info_row">
1.6 raeburn 434: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
435: <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
1.3 raeburn 436: </tr>'.
1.30 raeburn 437: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
438: $rowtotal += 2;
1.6 raeburn 439: }
1.3 raeburn 440: } else {
1.30 raeburn 441: $output .= '
1.3 raeburn 442: <tr>
443: <td>
444: <table class="LC_nested">
1.30 raeburn 445: <tr class="LC_info_row">';
1.24 raeburn 446: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 447: $output .= '
448: <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>';
1.6 raeburn 449: } else {
1.30 raeburn 450: $output .= '
451: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>';
1.6 raeburn 452: }
1.30 raeburn 453: $output .= '
1.3 raeburn 454: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.30 raeburn 455: </tr>';
456: $rowtotal ++;
1.3 raeburn 457: if ($action eq 'login') {
1.30 raeburn 458: $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
1.3 raeburn 459: } elsif ($action eq 'quotas') {
1.30 raeburn 460: $output .= &print_quotas($dom,$settings,\$rowtotal);
1.3 raeburn 461: } elsif ($action eq 'autoenroll') {
1.30 raeburn 462: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.23 raeburn 463: } elsif ($action eq 'directorysrch') {
1.30 raeburn 464: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 465: } elsif ($action eq 'contacts') {
1.30 raeburn 466: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 ! raeburn 467: } elsif ($action eq 'defaults') {
! 468: $output .= &print_defaults($dom,\$rowtotal);
1.27 raeburn 469: }
1.3 raeburn 470: }
1.30 raeburn 471: $output .= '
1.3 raeburn 472: </table>
473: </td>
474: </tr>
1.30 raeburn 475: </table><br />';
476: return ($output,$rowtotal);
1.1 raeburn 477: }
478:
479: sub print_header {
1.3 raeburn 480: my ($r,$phase) = @_;
1.30 raeburn 481: my $alert = &mt('You must select at least one functionality type to display.');
1.6 raeburn 482: my $js = '
1.1 raeburn 483: <script type="text/javascript">
484: function changePage(formname,newphase) {
485: formname.phase.value = newphase;
1.30 raeburn 486: numchecked = 0;
487: if (formname == document.pickactions) {
488: if (formname.actions.length > 0) {
489: for (var i = 0; i <formname.actions.length; i++) {
490: if (formname.actions[i].checked) {
491: numchecked ++;
492: }
493: }
494: } else {
495: if (formname.actions.checked) {
496: numchecked ++;
497: }
498: }
499: if (numchecked > 0) {
500: formname.submit();
501: } else {
502: alert("'.$alert.'");
503: return;
504: }
505: }
1.1 raeburn 506: formname.submit();
1.30 raeburn 507: }'."\n";
508: if ($phase eq 'pickactions') {
509: $js .=
510: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox',numcols => 'radio',})."\n".
511: &javascript_set_colnums();
512: } elsif ($phase eq 'display') {
513: $js .= &color_pick_js()."\n";
514: }
1.31 raeburn 515: $js .= &Apache::loncommon::viewport_size_js().'
1.1 raeburn 516: </script>
1.6 raeburn 517: ';
1.30 raeburn 518: my $additem;
519: if ($phase eq 'pickactions') {
520: my %loaditems = (
1.31 raeburn 521: 'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
1.30 raeburn 522: );
523: $additem = {'add_entries' => \%loaditems,};
524: } else {
525: my %loaditems = (
1.31 raeburn 526: 'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);",
1.30 raeburn 527: );
528: $additem = {'add_entries' => \%loaditems,};
529: }
1.2 albertel 530: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.30 raeburn 531: $js,$additem));
1.3 raeburn 532: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6 raeburn 533: $r->print('
1.8 raeburn 534: <form name="parmform" action="">
1.6 raeburn 535: <input type="hidden" name="pres_marker" />
536: <input type="hidden" name="pres_type" />
537: <input type="hidden" name="pres_value" />
538: </form>
539: ');
540: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
541: ' enctype="multipart/form-data">');
1.1 raeburn 542: return;
543: }
544:
545: sub print_footer {
1.30 raeburn 546: my ($r,$phase,$newphase,$button_text,$actions) = @_;
1.3 raeburn 547: $button_text = &mt($button_text);
1.30 raeburn 548: $r->print('<input type="hidden" name="phase" value="" />'.
549: '<input type="hidden" name="width" value="'.
550: $env{'form.width'}.'" />'.
551: '<input type="hidden" name="height" value="'.
552: $env{'form.height'}.'" />');
553: if (($phase eq 'display') || ($phase eq 'process')) {
554: if (ref($actions) eq 'ARRAY') {
555: foreach my $item (@{$actions}) {
556: $r->print('<input type="hidden" name="actions" value="'.$item.'" />')."\n";
557: }
558: }
559: $r->print('<input type="hidden" name="numcols" value="'.$env{'form.numcols'}.'" />');
560: }
1.3 raeburn 561: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
562: if ($phase eq 'process') {
1.30 raeburn 563: $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
1.3 raeburn 564: } else {
1.30 raeburn 565: my $onclick;
566: if ($phase eq 'display') {
567: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
568: } else {
569: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
570: }
571: $r->print('<p><input type="button" name="store" value="'.
572: $button_text.'" onclick='.$onclick.' /></p>');
573: }
574: if ($phase eq 'process') {
575: $r->print('</form>'.&Apache::loncommon::end_page());
1.3 raeburn 576: }
1.1 raeburn 577: return;
578: }
579:
1.3 raeburn 580: sub print_login {
1.30 raeburn 581: my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
1.6 raeburn 582: my %choices = &login_choices();
1.42 raeburn 583: my %defaultchecked = (
1.43 ! raeburn 584: 'coursecatalog' => 'on',
! 585: 'adminmail' => 'off',
! 586: 'newuser' => 'off',
! 587: );
! 588: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 589: my (%checkedon,%checkedoff);
590: foreach my $item (@toggles) {
591: if ($defaultchecked{$item} eq 'on') {
592: $checkedon{$item} = ' checked="checked" ';
593: $checkedoff{$item} = ' ';
594: } elsif ($defaultchecked{$item} eq 'off') {
595: $checkedoff{$item} = ' checked="checked" ';
596: $checkedon{$item} = ' ';
597: }
598: }
599: my $loginheader = 'image';
1.41 raeburn 600: my @images = ('img','logo','domlogo','login');
601: my @logintext = ('textcol','bgcol');
1.6 raeburn 602: my @bgs = ('pgbg','mainbg','sidebg');
603: my @links = ('link','alink','vlink');
1.7 albertel 604: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 605: my %defaultdesign = %Apache::loncommon::defaultdesign;
606: my (%is_custom,%designs);
607: my %defaults = (
608: font => $defaultdesign{'login.font'},
609: );
610: foreach my $item (@images) {
611: $defaults{$item} = $defaultdesign{'login.'.$item};
612: }
613: foreach my $item (@bgs) {
614: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
615: }
1.41 raeburn 616: foreach my $item (@logintext) {
617: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
618: }
1.6 raeburn 619: foreach my $item (@links) {
620: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
621: }
1.3 raeburn 622: if (ref($settings) eq 'HASH') {
1.42 raeburn 623: foreach my $item (@toggles) {
624: if ($settings->{$item} eq '1') {
625: $checkedon{$item} = ' checked="checked" ';
626: $checkedoff{$item} = ' ';
627: } elsif ($settings->{$item} eq '0') {
628: $checkedoff{$item} = ' checked="checked" ';
629: $checkedon{$item} = ' ';
630: }
1.1 raeburn 631: }
1.6 raeburn 632: foreach my $item (@images) {
633: if ($settings->{$item} ne '') {
634: $designs{$item} = $settings->{$item};
635: $is_custom{$item} = 1;
636: }
637: }
1.41 raeburn 638: foreach my $item (@logintext) {
639: if ($settings->{$item} ne '') {
640: $designs{'logintext'}{$item} = $settings->{$item};
641: $is_custom{$item} = 1;
642: }
643: }
644: if ($settings->{'loginheader'} ne '') {
645: $loginheader = $settings->{'loginheader'};
646: }
1.6 raeburn 647: if ($settings->{'font'} ne '') {
648: $designs{'font'} = $settings->{'font'};
649: $is_custom{'font'} = 1;
650: }
651: foreach my $item (@bgs) {
652: if ($settings->{$item} ne '') {
653: $designs{'bgs'}{$item} = $settings->{$item};
654: $is_custom{$item} = 1;
655: }
656: }
657: foreach my $item (@links) {
658: if ($settings->{$item} ne '') {
659: $designs{'links'}{$item} = $settings->{$item};
660: $is_custom{$item} = 1;
661: }
662: }
663: } else {
664: if ($designhash{$dom.'.login.font'} ne '') {
665: $designs{'font'} = $designhash{$dom.'.login.font'};
666: $is_custom{'font'} = 1;
667: }
1.8 raeburn 668: foreach my $item (@images) {
669: if ($designhash{$dom.'.login.'.$item} ne '') {
670: $designs{$item} = $designhash{$dom.'.login.'.$item};
671: $is_custom{$item} = 1;
672: }
673: }
1.6 raeburn 674: foreach my $item (@bgs) {
675: if ($designhash{$dom.'.login.'.$item} ne '') {
676: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
677: $is_custom{$item} = 1;
678: }
679: }
680: foreach my $item (@links) {
681: if ($designhash{$dom.'.login.'.$item} ne '') {
682: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
683: $is_custom{$item} = 1;
684: }
685: }
1.1 raeburn 686: }
1.6 raeburn 687: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
688: logo => 'Institution Logo',
1.41 raeburn 689: domlogo => 'Domain Logo',
690: login => 'Login box');
1.6 raeburn 691: my $itemcount = 1;
1.42 raeburn 692: my ($css_class,$datatable);
693: foreach my $item (@toggles) {
694: $css_class = $itemcount%2?' class="LC_odd_row"':'';
695: $datatable .=
696: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
697: '</td><td>'.
698: '<span class="LC_nobreak"><label><input type="radio" name="'.
699: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
700: '</label> <label><input type="radio" name="'.$item.'"'.
701: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
702: '</tr>';
703: $itemcount ++;
704: }
1.41 raeburn 705: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader);
1.6 raeburn 706: $datatable .= '</tr></table></td></tr>';
707: return $datatable;
708: }
709:
710: sub login_choices {
711: my %choices =
712: &Apache::lonlocal::texthash (
713: coursecatalog => 'Display Course Catalog link?',
714: adminmail => "Display Administrator's E-mail Address?",
1.43 ! raeburn 715: newuser => "Link to create a user account",
1.6 raeburn 716: img => "Header",
717: logo => "Main Logo",
718: domlogo => "Domain Logo",
1.41 raeburn 719: login => "Log-in Header",
720: textcol => "Text color",
721: bgcol => "Box color",
1.6 raeburn 722: bgs => "Background colors",
723: links => "Link colors",
724: font => "Font color",
725: pgbg => "Page",
726: mainbg => "Main panel",
727: sidebg => "Side panel",
728: link => "Link",
729: alink => "Active link",
730: vlink => "Visited link",
731: );
732: return %choices;
733: }
734:
735: sub print_rolecolors {
1.30 raeburn 736: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 737: my %choices = &color_font_choices();
738: my @bgs = ('pgbg','tabbg','sidebg');
739: my @links = ('link','alink','vlink');
740: my @images = ('img');
741: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 742: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 743: my %defaultdesign = %Apache::loncommon::defaultdesign;
744: my (%is_custom,%designs);
745: my %defaults = (
746: img => $defaultdesign{$role.'.img'},
747: font => $defaultdesign{$role.'.font'},
748: );
749: foreach my $item (@bgs) {
750: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
751: }
752: foreach my $item (@links) {
753: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
754: }
755: if (ref($settings) eq 'HASH') {
756: if (ref($settings->{$role}) eq 'HASH') {
757: if ($settings->{$role}->{'img'} ne '') {
758: $designs{'img'} = $settings->{$role}->{'img'};
759: $is_custom{'img'} = 1;
760: }
761: if ($settings->{$role}->{'font'} ne '') {
762: $designs{'font'} = $settings->{$role}->{'font'};
763: $is_custom{'font'} = 1;
764: }
765: foreach my $item (@bgs) {
766: if ($settings->{$role}->{$item} ne '') {
767: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
768: $is_custom{$item} = 1;
769: }
770: }
771: foreach my $item (@links) {
772: if ($settings->{$role}->{$item} ne '') {
773: $designs{'links'}{$item} = $settings->{$role}->{$item};
774: $is_custom{$item} = 1;
775: }
776: }
777: }
778: } else {
779: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
780: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
781: $is_custom{'img'} = 1;
782: }
783: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
784: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
785: $is_custom{'font'} = 1;
786: }
787: foreach my $item (@bgs) {
788: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
789: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
790: $is_custom{$item} = 1;
791:
792: }
793: }
794: foreach my $item (@links) {
795: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
796: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
797: $is_custom{$item} = 1;
798: }
799: }
800: }
801: my $itemcount = 1;
1.30 raeburn 802: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 803: $datatable .= '</tr></table></td></tr>';
804: return $datatable;
805: }
806:
807: sub display_color_options {
1.9 raeburn 808: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.41 raeburn 809: $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_;
1.6 raeburn 810: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
811: my $datatable = '<tr'.$css_class.'>'.
812: '<td>'.$choices->{'font'}.'</td>';
813: if (!$is_custom->{'font'}) {
1.30 raeburn 814: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 815: } else {
816: $datatable .= '<td> </td>';
817: }
818: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 819: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 820: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 821: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 822: ' <span id="css_'.$role.'_font" style="background-color: '.
823: $designs->{'font'}.';"> </span>'.
1.8 raeburn 824: '</span></td></tr>';
1.9 raeburn 825: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 826: foreach my $img (@{$images}) {
1.18 albertel 827: $itemcount ++;
1.6 raeburn 828: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 829: $datatable .= '<tr'.$css_class.'>'.
1.6 raeburn 830: '<td>'.$choices->{$img}.'</td>';
1.41 raeburn 831: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.6 raeburn 832: if ($designs->{$img} ne '') {
833: $imgfile = $designs->{$img};
1.18 albertel 834: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 835: } else {
836: $imgfile = $defaults->{$img};
837: }
1.41 raeburn 838: if ($img eq 'login') {
839: $login_hdr_pick = &login_header_options($img,$role,$defaults,$is_custom,$choices,
840: $loginheader);
841: $logincolors =
842: &login_text_colors($img,$role,$logintext,$phase,$choices,$designs);
843: }
1.6 raeburn 844: if ($imgfile) {
1.9 raeburn 845: my ($showfile,$fullsize);
846: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 847: my $urldir = $1;
848: my $filename = $2;
849: my @info = &Apache::lonnet::stat_file($designs->{$img});
850: if (@info) {
851: my $thumbfile = 'tn-'.$filename;
852: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
853: if (@thumb) {
854: $showfile = $urldir.'/'.$thumbfile;
855: } else {
856: $showfile = $imgfile;
857: }
858: } else {
859: $showfile = '';
860: }
861: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 862: $showfile = $imgfile;
1.6 raeburn 863: my $imgdir = $1;
864: my $filename = $2;
865: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
866: $showfile = "/$imgdir/tn-".$filename;
867: } else {
868: my $input = "/home/httpd/html".$imgfile;
869: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
870: if (!-e $output) {
1.9 raeburn 871: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 872: my ($fullwidth,$fullheight) = &check_dimensions($input);
873: if ($fullwidth ne '' && $fullheight ne '') {
874: if ($fullwidth > $width && $fullheight > $height) {
875: my $size = $width.'x'.$height;
876: system("convert -sample $size $input $output");
877: $showfile = '/'.$imgdir.'/tn-'.$filename;
878: }
879: }
1.6 raeburn 880: }
881: }
1.16 raeburn 882: }
1.6 raeburn 883: if ($showfile) {
1.40 raeburn 884: if ($showfile =~ m{^/(adm|res)/}) {
885: if ($showfile =~ m{^/res/}) {
886: my $local_showfile =
887: &Apache::lonnet::filelocation('',$showfile);
888: &Apache::lonnet::repcopy($local_showfile);
889: }
890: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
891: }
892: if ($imgfile) {
893: if ($imgfile =~ m{^/(adm|res)/}) {
894: if ($imgfile =~ m{^/res/}) {
895: my $local_imgfile =
896: &Apache::lonnet::filelocation('',$imgfile);
897: &Apache::lonnet::repcopy($local_imgfile);
898: }
899: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
900: } else {
901: $fullsize = $imgfile;
902: }
903: }
1.41 raeburn 904: $datatable .= '<td>';
905: if ($img eq 'login') {
906: $datatable .= $login_hdr_pick;
1.6 raeburn 907: }
1.41 raeburn 908: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
909: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 910: } else {
911: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
912: &mt('Upload:');
913: }
914: } else {
915: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
916: &mt('Upload:');
917: }
1.9 raeburn 918: if ($switchserver) {
919: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
920: } else {
921: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
922: }
923: $datatable .= '</td></tr>';
1.6 raeburn 924: }
925: $itemcount ++;
926: $css_class = $itemcount%2?' class="LC_odd_row"':'';
927: $datatable .= '<tr'.$css_class.'>'.
928: '<td>'.$choices->{'bgs'}.'</td>';
929: my $bgs_def;
930: foreach my $item (@{$bgs}) {
931: if (!$is_custom->{$item}) {
1.30 raeburn 932: $bgs_def .= '<td>'.$choices->{$item}.' <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 933: }
934: }
935: if ($bgs_def) {
1.8 raeburn 936: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 937: } else {
938: $datatable .= '<td> </td>';
939: }
940: $datatable .= '<td class="LC_right_item">'.
941: '<table border="0"><tr>';
942: foreach my $item (@{$bgs}) {
943: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
944: $datatable .= '<td align="center">'.$link;
945: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 946: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 947: }
948: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 949: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 950: }
951: $datatable .= '</tr></table></td></tr>';
952: $itemcount ++;
953: $css_class = $itemcount%2?' class="LC_odd_row"':'';
954: $datatable .= '<tr'.$css_class.'>'.
955: '<td>'.$choices->{'links'}.'</td>';
956: my $links_def;
957: foreach my $item (@{$links}) {
958: if (!$is_custom->{$item}) {
1.30 raeburn 959: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 960: }
961: }
962: if ($links_def) {
1.8 raeburn 963: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 964: } else {
965: $datatable .= '<td> </td>';
966: }
967: $datatable .= '<td class="LC_right_item">'.
968: '<table border="0"><tr>';
969: foreach my $item (@{$links}) {
1.30 raeburn 970: $datatable .= '<td align="center">'."\n".
971: &color_pick($phase,$role,$item,$choices->{$item},
972: $designs->{'links'}{$item});
1.6 raeburn 973: if ($designs->{'links'}{$item}) {
1.30 raeburn 974: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 975: }
976: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
977: '" /></td>';
978: }
1.30 raeburn 979: $$rowtotal += $itemcount;
1.3 raeburn 980: return $datatable;
981: }
982:
1.41 raeburn 983: sub login_header_options {
984: my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
985: my $image_checked = ' checked="checked" ';
986: my $text_checked = ' ';
987: if ($loginheader eq 'text') {
988: $image_checked = ' ';
989: $text_checked = ' checked="checked" ';
990: }
991: my $output = '<span class="LC_nobreak"><label><input type="radio" name="'.
992: 'loginheader" value="image" '.$image_checked.'/>'.
993: &mt('use image').'</label> '.
994: '<label><input type="radio" name="loginheader" value="text"'.
995: $text_checked.'/>'.&mt('use text').'</label><br />'."\n";
996: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
997: $output .= &mt('Text default(s)').':<br />';
998: if (!$is_custom->{'textcol'}) {
999: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1000: ' ';
1001: }
1002: if (!$is_custom->{'bgcol'}) {
1003: $output .= $choices->{'bgcol'}.': '.
1004: '<span id="css_'.$role.'_font" style="background-color: '.
1005: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1006: }
1007: $output .= '<br />';
1008: }
1009: $output .='<br />';
1010: return $output;
1011: }
1012:
1013: sub login_text_colors {
1014: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1015: my $color_menu = '<table border="0"><tr>';
1016: foreach my $item (@{$logintext}) {
1017: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1018: $color_menu .= '<td align="center">'.$link;
1019: if ($designs->{'logintext'}{$item}) {
1020: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1021: }
1022: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1023: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1024: '<td> </td>';
1025: }
1026: $color_menu .= '</tr></table><br />';
1027: return $color_menu;
1028: }
1029:
1030: sub image_changes {
1031: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1032: my $output;
1033: if (!$is_custom) {
1034: if ($img eq 'login') {
1035: $output .= &mt('Default image:').'<br />';
1036: } else {
1037: $output .= &mt('Default in use:').'<br />';
1038: }
1039: }
1040: if ($img_import) {
1041: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1042: }
1043: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1044: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1045: if ($is_custom) {
1046: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1047: '<input type="checkbox" name="'.
1048: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1049: '</label> '.&mt('Replace:').'</span><br />';
1050: } else {
1051: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1052: }
1053: return $output;
1054: }
1055:
1.6 raeburn 1056: sub color_pick {
1057: my ($phase,$role,$item,$desc,$curcol) = @_;
1058: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1059: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1060: ');">'.$desc.'</a>';
1061: return $link;
1062: }
1063:
1064: sub color_pick_js {
1065: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1066: my $output = <<"ENDCOL";
1067: function pclose() {
1068: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
1069: parmwin.close();
1070: }
1071:
1072: $pjump_def
1073:
1074: function psub() {
1075: pclose();
1076: if (document.parmform.pres_marker.value!='') {
1077: if (document.parmform.pres_type.value!='') {
1078: eval('document.display.'+
1079: document.parmform.pres_marker.value+
1080: '.value=document.parmform.pres_value.value;');
1081: }
1082: } else {
1083: document.parmform.pres_value.value='';
1084: document.parmform.pres_marker.value='';
1085: }
1086: }
1.41 raeburn 1087:
1088: function get_id (span_id) {
1089: if (document.getElementById) {
1090: return document.getElementById(span_id);
1091: }
1092: if (document.all) {
1093: return document.all[span_id];
1094: }
1095: return false;
1096: }
1097:
1098: function colchg_span (span_id_str,new_color_item) {
1099: var span_ref = get_id(span_id_str);
1100: if (span_ref.style) { span_ref = span_ref.style; }
1101: span_ref.background = new_color_item.value;
1102: span_ref.backgroundColor = new_color_item.value;
1103: span_ref.bgColor = new_color_item.value;
1104: }
1105:
1.6 raeburn 1106: ENDCOL
1107: return $output;
1108: }
1109:
1.3 raeburn 1110: sub print_quotas {
1.30 raeburn 1111: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1112: my $datatable;
1.23 raeburn 1113: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.3 raeburn 1114: my $typecount = 0;
1115: my $css_class;
1.26 raeburn 1116: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1117: foreach my $type (@{$types}) {
1.3 raeburn 1118: if (defined($usertypes->{$type})) {
1119: $typecount ++;
1120: $css_class = $typecount%2?' class="LC_odd_row"':'';
1121: $datatable .= '<tr'.$css_class.'>'.
1122: '<td>'.$usertypes->{$type}.'</td>'.
1.8 raeburn 1123: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1124: '<input type="text" name="quota_'.$type.
1125: '" value="'.$settings->{$type}.
1.8 raeburn 1126: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 1127: }
1128: }
1129: }
1130: my $defaultquota = '20';
1131: if (ref($settings) eq 'HASH') {
1132: if (defined($settings->{'default'})) {
1133: $defaultquota = $settings->{'default'};
1134: }
1135: }
1136: $typecount ++;
1137: $css_class = $typecount%2?' class="LC_odd_row"':'';
1138: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1139: '<td>'.$othertitle.'</td>'.
1.8 raeburn 1140: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.15 raeburn 1141: '<input type="text" name="defaultquota" value="'.
1.8 raeburn 1142: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.30 raeburn 1143: $$rowtotal += $typecount;
1.3 raeburn 1144: return $datatable;
1145: }
1146:
1147: sub print_autoenroll {
1.30 raeburn 1148: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1149: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 1150: my ($defdom,$runon,$runoff);
1.3 raeburn 1151: if (ref($settings) eq 'HASH') {
1152: if (exists($settings->{'run'})) {
1153: if ($settings->{'run'} eq '0') {
1154: $runoff = ' checked="checked" ';
1155: $runon = ' ';
1156: } else {
1157: $runon = ' checked="checked" ';
1158: $runoff = ' ';
1159: }
1160: } else {
1161: if ($autorun) {
1162: $runon = ' checked="checked" ';
1163: $runoff = ' ';
1164: } else {
1165: $runoff = ' checked="checked" ';
1166: $runon = ' ';
1167: }
1168: }
1169: if (exists($settings->{'sender_domain'})) {
1170: $defdom = $settings->{'sender_domain'};
1171: }
1.14 raeburn 1172: } else {
1173: if ($autorun) {
1174: $runon = ' checked="checked" ';
1175: $runoff = ' ';
1176: } else {
1177: $runoff = ' checked="checked" ';
1178: $runon = ' ';
1179: }
1.3 raeburn 1180: }
1181: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1182: my $notif_sender;
1183: if (ref($settings) eq 'HASH') {
1184: $notif_sender = $settings->{'sender_uname'};
1185: }
1.3 raeburn 1186: my $datatable='<tr class="LC_odd_row">'.
1187: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1188: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1189: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1190: $runon.' value="1" />'.&mt('Yes').'</label> '.
1191: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1192: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1193: '</tr><tr>'.
1194: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1195: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1196: &mt('username').': '.
1197: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1198: $notif_sender.'" size="10" /> '.&mt('domain').
1.8 raeburn 1199: ': '.$domform.'</span></td></tr>';
1.30 raeburn 1200: $$rowtotal += 2;
1.3 raeburn 1201: return $datatable;
1202: }
1203:
1204: sub print_autoupdate {
1.30 raeburn 1205: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1206: my $datatable;
1207: if ($position eq 'top') {
1208: my $updateon = ' ';
1209: my $updateoff = ' checked="checked" ';
1210: my $classlistson = ' ';
1211: my $classlistsoff = ' checked="checked" ';
1212: if (ref($settings) eq 'HASH') {
1213: if ($settings->{'run'} eq '1') {
1214: $updateon = $updateoff;
1215: $updateoff = ' ';
1216: }
1217: if ($settings->{'classlists'} eq '1') {
1218: $classlistson = $classlistsoff;
1219: $classlistsoff = ' ';
1220: }
1221: }
1222: my %title = (
1223: run => 'Auto-update active?',
1224: classlists => 'Update information in classlists?',
1225: );
1226: $datatable = '<tr class="LC_odd_row">'.
1227: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1228: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1229: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1230: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1231: '<label><input type="radio" name="autoupdate_run"'.
1232: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1233: '</tr><tr>'.
1234: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1235: '<td class="LC_right_item"><span class="LC_nobreak">'.
1236: '<label><input type="radio" name="classlists"'.
1237: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1238: '<label><input type="radio" name="classlists"'.
1239: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1240: '</tr>';
1.30 raeburn 1241: $$rowtotal += 2;
1.3 raeburn 1242: } else {
1.23 raeburn 1243: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.20 raeburn 1244: my @fields = ('lastname','firstname','middlename','gen',
1245: 'permanentemail','id');
1.33 raeburn 1246: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1247: my $numrows = 0;
1.26 raeburn 1248: if (ref($types) eq 'ARRAY') {
1249: if (@{$types} > 0) {
1250: $datatable =
1251: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1252: \@fields,$types,\$numrows);
1.30 raeburn 1253: $$rowtotal += @{$types};
1.26 raeburn 1254: }
1.3 raeburn 1255: }
1256: $datatable .=
1257: &usertype_update_row($settings,{'default' => $othertitle},
1258: \%fieldtitles,\@fields,['default'],
1259: \$numrows);
1.30 raeburn 1260: $$rowtotal ++;
1.3 raeburn 1261: }
1262: return $datatable;
1263: }
1264:
1.23 raeburn 1265: sub print_directorysrch {
1.30 raeburn 1266: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1267: my $srchon = ' ';
1268: my $srchoff = ' checked="checked" ';
1.25 raeburn 1269: my ($exacton,$containson,$beginson);
1.24 raeburn 1270: my $localon = ' ';
1271: my $localoff = ' checked="checked" ';
1.23 raeburn 1272: if (ref($settings) eq 'HASH') {
1273: if ($settings->{'available'} eq '1') {
1274: $srchon = $srchoff;
1275: $srchoff = ' ';
1276: }
1.24 raeburn 1277: if ($settings->{'localonly'} eq '1') {
1278: $localon = $localoff;
1279: $localoff = ' ';
1280: }
1.25 raeburn 1281: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1282: foreach my $type (@{$settings->{'searchtypes'}}) {
1283: if ($type eq 'exact') {
1284: $exacton = ' checked="checked" ';
1285: } elsif ($type eq 'contains') {
1286: $containson = ' checked="checked" ';
1287: } elsif ($type eq 'begins') {
1288: $beginson = ' checked="checked" ';
1289: }
1290: }
1291: } else {
1292: if ($settings->{'searchtypes'} eq 'exact') {
1293: $exacton = ' checked="checked" ';
1294: } elsif ($settings->{'searchtypes'} eq 'contains') {
1295: $containson = ' checked="checked" ';
1296: } elsif ($settings->{'searchtypes'} eq 'specify') {
1297: $exacton = ' checked="checked" ';
1298: $containson = ' checked="checked" ';
1299: }
1.23 raeburn 1300: }
1301: }
1302: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1303: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1304:
1305: my $numinrow = 4;
1.26 raeburn 1306: my $cansrchrow = 0;
1.23 raeburn 1307: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1308: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1309: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1310: '<input type="radio" name="dirsrch_available"'.
1311: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1312: '<label><input type="radio" name="dirsrch_available"'.
1313: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1314: '</tr><tr>'.
1.30 raeburn 1315: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1316: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1317: '<input type="radio" name="dirsrch_localonly"'.
1318: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1319: '<label><input type="radio" name="dirsrch_localonly"'.
1320: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1321: '</tr>';
1.30 raeburn 1322: $$rowtotal += 2;
1.26 raeburn 1323: if (ref($usertypes) eq 'HASH') {
1324: if (keys(%{$usertypes}) > 0) {
1325: $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
1326: $numinrow,$othertitle);
1327: $cansrchrow = 1;
1328: }
1329: }
1330: if ($cansrchrow) {
1.30 raeburn 1331: $$rowtotal ++;
1.26 raeburn 1332: $datatable .= '<tr>';
1333: } else {
1334: $datatable .= '<tr class="LC_odd_row">';
1335: }
1.30 raeburn 1336: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1337: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1338: foreach my $title (@{$titleorder}) {
1339: if (defined($searchtitles->{$title})) {
1340: my $check = ' ';
1.39 raeburn 1341: if (ref($settings) eq 'HASH') {
1342: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1343: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1344: $check = ' checked="checked" ';
1345: }
1.25 raeburn 1346: }
1347: }
1348: $datatable .= '<td class="LC_left_item">'.
1349: '<span class="LC_nobreak"><label>'.
1350: '<input type="checkbox" name="searchby" '.
1351: 'value="'.$title.'"'.$check.'/>'.
1352: $searchtitles->{$title}.'</label></span></td>';
1353: }
1354: }
1.26 raeburn 1355: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1356: $$rowtotal ++;
1.26 raeburn 1357: if ($cansrchrow) {
1358: $datatable .= '<tr class="LC_odd_row">';
1359: } else {
1360: $datatable .= '<tr>';
1361: }
1.30 raeburn 1362: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 1363: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1364: '<span class="LC_nobreak"><label>'.
1365: '<input type="checkbox" name="searchtypes" '.
1366: $exacton.' value="exact" />'.&mt('Exact match').
1367: '</label> '.
1368: '<label><input type="checkbox" name="searchtypes" '.
1369: $beginson.' value="begins" />'.&mt('Begins with').
1370: '</label> '.
1371: '<label><input type="checkbox" name="searchtypes" '.
1372: $containson.' value="contains" />'.&mt('Contains').
1373: '</label></span></td></tr>';
1.30 raeburn 1374: $$rowtotal ++;
1.25 raeburn 1375: return $datatable;
1376: }
1377:
1.28 raeburn 1378: sub print_contacts {
1.30 raeburn 1379: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 1380: my $datatable;
1381: my @contacts = ('adminemail','supportemail');
1382: my (%checked,%to,%otheremails);
1383: my @mailings = ('errormail','packagesmail','helpdeskmail');
1384: foreach my $type (@mailings) {
1385: $otheremails{$type} = '';
1386: }
1387: if (ref($settings) eq 'HASH') {
1388: foreach my $item (@contacts) {
1389: if (exists($settings->{$item})) {
1390: $to{$item} = $settings->{$item};
1391: }
1392: }
1393: foreach my $type (@mailings) {
1394: if (exists($settings->{$type})) {
1395: if (ref($settings->{$type}) eq 'HASH') {
1396: foreach my $item (@contacts) {
1397: if ($settings->{$type}{$item}) {
1398: $checked{$type}{$item} = ' checked="checked" ';
1399: }
1400: }
1401: $otheremails{$type} = $settings->{$type}{'others'};
1402: }
1403: }
1404: }
1405: } else {
1406: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1407: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1408: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1409: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1410: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
1411: }
1412: my ($titles,$short_titles) = &contact_titles();
1413: my $rownum = 0;
1414: my $css_class;
1415: foreach my $item (@contacts) {
1416: if ($rownum%2) {
1417: $css_class = '';
1418: } else {
1419: $css_class = ' class="LC_odd_row" ';
1420: }
1.30 raeburn 1421: $datatable .= '<tr'.$css_class.'>'.
1422: '<td><span class="LC_nobreak">'.$titles->{$item}.
1423: '</span></td><td class="LC_right_item">'.
1.28 raeburn 1424: '<input type="text" name="'.$item.'" value="'.
1425: $to{$item}.'" /></td></tr>';
1426: $rownum ++;
1427: }
1428: foreach my $type (@mailings) {
1429: if ($rownum%2) {
1430: $css_class = '';
1431: } else {
1432: $css_class = ' class="LC_odd_row" ';
1433: }
1434: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 1435: '<td><span class="LC_nobreak">'.
1436: $titles->{$type}.': </span></td>'.
1.28 raeburn 1437: '<td class="LC_left_item">'.
1438: '<span class="LC_nobreak">';
1439: foreach my $item (@contacts) {
1440: $datatable .= '<label>'.
1441: '<input type="checkbox" name="'.$type.'"'.
1442: $checked{$type}{$item}.
1443: ' value="'.$item.'" />'.$short_titles->{$item}.
1444: '</label> ';
1445: }
1446: $datatable .= '</span><br />'.&mt('Others').': '.
1447: '<input type="text" name="'.$type.'_others" '.
1448: 'value="'.$otheremails{$type}.'" />'.
1449: '</td></tr>'."\n";
1450: $rownum ++;
1451: }
1.30 raeburn 1452: $$rowtotal += $rownum;
1.28 raeburn 1453: return $datatable;
1454: }
1455:
1456: sub contact_titles {
1457: my %titles = &Apache::lonlocal::texthash (
1458: 'supportemail' => 'Support E-mail address',
1459: 'adminemail' => 'Default Server Admin E-mail address',
1460: 'errormail' => 'Error reports to be e-mailed to',
1461: 'packagesmail' => 'Package update alerts to be e-mailed to',
1462: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
1463: );
1464: my %short_titles = &Apache::lonlocal::texthash (
1465: adminemail => 'Admin E-mail address',
1466: supportemail => 'Support E-mail',
1467: );
1468: return (\%titles,\%short_titles);
1469: }
1470:
1.27 raeburn 1471: sub print_usercreation {
1.30 raeburn 1472: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 1473: my $numinrow = 4;
1.28 raeburn 1474: my $datatable;
1475: if ($position eq 'top') {
1.30 raeburn 1476: $$rowtotal ++;
1.34 raeburn 1477: my $rowcount = 0;
1.32 raeburn 1478: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 1479: if (ref($rules) eq 'HASH') {
1480: if (keys(%{$rules}) > 0) {
1.32 raeburn 1481: $datatable .= &user_formats_row('username',$settings,$rules,
1482: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 1483: $$rowtotal ++;
1.32 raeburn 1484: $rowcount ++;
1485: }
1486: }
1487: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
1488: if (ref($idrules) eq 'HASH') {
1489: if (keys(%{$idrules}) > 0) {
1490: $datatable .= &user_formats_row('id',$settings,$idrules,
1491: $idruleorder,$numinrow,$rowcount);
1492: $$rowtotal ++;
1493: $rowcount ++;
1.28 raeburn 1494: }
1495: }
1.43 ! raeburn 1496: my ($emailrules,$emailruleorder) =
! 1497: &Apache::lonnet::inst_userrules($dom,'email');
! 1498: if (ref($emailrules) eq 'HASH') {
! 1499: if (keys(%{$emailrules}) > 0) {
! 1500: $datatable .= &user_formats_row('email',$settings,$emailrules,
! 1501: $emailruleorder,$numinrow,$rowcount);
! 1502: $$rowtotal ++;
! 1503: $rowcount ++;
! 1504: }
! 1505: }
1.39 raeburn 1506: if ($rowcount == 0) {
1507: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
1508: $$rowtotal ++;
1509: $rowcount ++;
1510: }
1.34 raeburn 1511: } elsif ($position eq 'middle') {
1.43 ! raeburn 1512: my @creators = ('author','course','selfenroll');
1.37 raeburn 1513: my ($rules,$ruleorder) =
1514: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 1515: my %lt = &usercreation_types();
1516: my %checked;
1517: if (ref($settings) eq 'HASH') {
1518: if (ref($settings->{'cancreate'}) eq 'HASH') {
1519: foreach my $item (@creators) {
1520: $checked{$item} = $settings->{'cancreate'}{$item};
1521: }
1522: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
1523: foreach my $item (@creators) {
1524: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
1525: $checked{$item} = 'none';
1526: }
1527: }
1528: }
1529: }
1530: my $rownum = 0;
1531: foreach my $item (@creators) {
1532: $rownum ++;
1533: if ($checked{$item} eq '') {
1.43 ! raeburn 1534: if ($item eq 'selfenroll') {
! 1535: $checked{$item} = 'none';
! 1536: } else {
! 1537: $checked{$item} = 'any';
! 1538: }
1.34 raeburn 1539: }
1540: my $css_class;
1541: if ($rownum%2) {
1542: $css_class = '';
1543: } else {
1544: $css_class = ' class="LC_odd_row" ';
1545: }
1546: $datatable .= '<tr'.$css_class.'>'.
1547: '<td><span class="LC_nobreak">'.$lt{$item}.
1548: '</span></td><td align="right">';
1.37 raeburn 1549: my @options = ('any');
1.43 ! raeburn 1550: if ($item eq 'selfenroll') {
! 1551: push(@options,('email','login','sso'));
! 1552: } else {
! 1553: if (ref($rules) eq 'HASH') {
! 1554: if (keys(%{$rules}) > 0) {
! 1555: push(@options,('official','unofficial'));
! 1556: }
1.37 raeburn 1557: }
1558: }
1559: push(@options,'none');
1560: foreach my $option (@options) {
1.34 raeburn 1561: my $check = ' ';
1562: if ($checked{$item} eq $option) {
1563: $check = ' checked="checked" ';
1564: }
1565: $datatable .= '<span class="LC_nobreak"><label>'.
1566: '<input type="radio" name="can_createuser_'.
1567: $item.'" value="'.$option.'"'.$check.'/> '.
1568: $lt{$option}.'</label> </span>';
1569: }
1570: $datatable .= '</td></tr>';
1571: }
1.28 raeburn 1572: } else {
1573: my @contexts = ('author','course','domain');
1574: my @authtypes = ('int','krb4','krb5','loc');
1575: my %checked;
1576: if (ref($settings) eq 'HASH') {
1577: if (ref($settings->{'authtypes'}) eq 'HASH') {
1578: foreach my $item (@contexts) {
1579: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
1580: foreach my $auth (@authtypes) {
1581: if ($settings->{'authtypes'}{$item}{$auth}) {
1582: $checked{$item}{$auth} = ' checked="checked" ';
1583: }
1584: }
1585: }
1586: }
1.27 raeburn 1587: }
1.35 raeburn 1588: } else {
1589: foreach my $item (@contexts) {
1.36 raeburn 1590: foreach my $auth (@authtypes) {
1.35 raeburn 1591: $checked{$item}{$auth} = ' checked="checked" ';
1592: }
1593: }
1.27 raeburn 1594: }
1.28 raeburn 1595: my %title = &context_names();
1596: my %authname = &authtype_names();
1597: my $rownum = 0;
1598: my $css_class;
1599: foreach my $item (@contexts) {
1600: if ($rownum%2) {
1601: $css_class = '';
1602: } else {
1603: $css_class = ' class="LC_odd_row" ';
1604: }
1.30 raeburn 1605: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 1606: '<td>'.$title{$item}.
1607: '</td><td class="LC_left_item">'.
1608: '<span class="LC_nobreak">';
1609: foreach my $auth (@authtypes) {
1610: $datatable .= '<label>'.
1611: '<input type="checkbox" name="'.$item.'_auth" '.
1612: $checked{$item}{$auth}.' value="'.$auth.'" />'.
1613: $authname{$auth}.'</label> ';
1614: }
1615: $datatable .= '</span></td></tr>';
1616: $rownum ++;
1.27 raeburn 1617: }
1.30 raeburn 1618: $$rowtotal += $rownum;
1.27 raeburn 1619: }
1620: return $datatable;
1621: }
1622:
1.32 raeburn 1623: sub user_formats_row {
1624: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
1625: my $output;
1626: my %text = (
1627: 'username' => 'new usernames',
1628: 'id' => 'IDs',
1.43 ! raeburn 1629: 'email' => 'e-mail addresses of self-enrollers',
1.32 raeburn 1630: );
1631: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1632: $output = '<tr '.$css_class.'>'.
1633: '<td><span class="LC_nobreak">'.
1634: &mt("Format rules to check for $text{$type}: ").
1635: '</span></td>'.
1636: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 1637: my $rem;
1638: if (ref($ruleorder) eq 'ARRAY') {
1639: for (my $i=0; $i<@{$ruleorder}; $i++) {
1640: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
1641: my $rem = $i%($numinrow);
1642: if ($rem == 0) {
1643: if ($i > 0) {
1644: $output .= '</tr>';
1645: }
1646: $output .= '<tr>';
1647: }
1648: my $check = ' ';
1.39 raeburn 1649: if (ref($settings) eq 'HASH') {
1650: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
1651: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
1652: $check = ' checked="checked" ';
1653: }
1.27 raeburn 1654: }
1655: }
1656: $output .= '<td class="LC_left_item">'.
1657: '<span class="LC_nobreak"><label>'.
1.32 raeburn 1658: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 1659: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
1660: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
1661: }
1662: }
1663: $rem = @{$ruleorder}%($numinrow);
1664: }
1665: my $colsleft = $numinrow - $rem;
1666: if ($colsleft > 1 ) {
1667: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1668: ' </td>';
1669: } elsif ($colsleft == 1) {
1670: $output .= '<td class="LC_left_item"> </td>';
1671: }
1672: $output .= '</tr></table></td></tr>';
1673: return $output;
1674: }
1675:
1.34 raeburn 1676: sub usercreation_types {
1677: my %lt = &Apache::lonlocal::texthash (
1678: author => 'When adding a co-author',
1679: course => 'When adding a user to a course',
1.43 ! raeburn 1680: selfenroll => 'When a user is self-enrolling',
1.34 raeburn 1681: any => 'Any',
1682: official => 'Institutional only ',
1683: unofficial => 'Non-institutional only',
1.43 ! raeburn 1684: email => 'Email address',
! 1685: login => 'Institutional Login',
! 1686: sso => 'SSO',
1.34 raeburn 1687: none => 'None',
1688: );
1689: return %lt;
1690: }
1691:
1.28 raeburn 1692: sub authtype_names {
1693: my %lt = &Apache::lonlocal::texthash(
1694: int => 'Internal',
1695: krb4 => 'Kerberos 4',
1696: krb5 => 'Kerberos 5',
1697: loc => 'Local',
1698: );
1699: return %lt;
1700: }
1701:
1702: sub context_names {
1703: my %context_title = &Apache::lonlocal::texthash(
1704: author => 'Creating users when an Author',
1705: course => 'Creating users when in a course',
1706: domain => 'Creating users when a Domain Coordinator',
1707: );
1708: return %context_title;
1709: }
1710:
1.33 raeburn 1711: sub print_usermodification {
1712: my ($position,$dom,$settings,$rowtotal) = @_;
1713: my $numinrow = 4;
1714: my ($context,$datatable,$rowcount);
1715: if ($position eq 'top') {
1716: $rowcount = 0;
1717: $context = 'author';
1718: foreach my $role ('ca','aa') {
1719: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1720: $numinrow,$rowcount);
1721: $$rowtotal ++;
1722: $rowcount ++;
1723: }
1724: } else {
1725: $context = 'course';
1726: $rowcount = 0;
1727: foreach my $role ('st','ep','ta','in','cr') {
1728: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1729: $numinrow,$rowcount);
1730: $$rowtotal ++;
1731: $rowcount ++;
1732: }
1733: }
1734: return $datatable;
1735: }
1736:
1.43 ! raeburn 1737: sub print_defaults {
! 1738: my ($dom,$rowtotal) = @_;
! 1739: my @items = ('auth_def','auth_arg_def','lang_def');
! 1740: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
! 1741: my $titles = &defaults_titles();
! 1742: my $rownum = 0;
! 1743: my ($datatable,$css_class);
! 1744: foreach my $item (@items) {
! 1745: if ($rownum%2) {
! 1746: $css_class = '';
! 1747: } else {
! 1748: $css_class = ' class="LC_odd_row" ';
! 1749: }
! 1750: $datatable .= '<tr'.$css_class.'>'.
! 1751: '<td><span class="LC_nobreak">'.$titles->{$item}.
! 1752: '</span></td><td class="LC_right_item">';
! 1753: if ($item eq 'auth_def') {
! 1754: my @authtypes = ('internal','krb4','krb5','localauth');
! 1755: my %shortauth = (
! 1756: internal => 'int',
! 1757: krb4 => 'krb4',
! 1758: krb5 => 'krb5',
! 1759: localauth => 'loc'
! 1760: );
! 1761: my %authnames = &authtype_names();
! 1762: foreach my $auth (@authtypes) {
! 1763: my $checked = ' ';
! 1764: if ($domdefaults{$item} eq $auth) {
! 1765: $checked = ' checked="checked" ';
! 1766: }
! 1767: $datatable .= '<label><input type="radio" name="'.$item.
! 1768: '" value="'.$auth.'"'.$checked.'/>'.
! 1769: $authnames{$shortauth{$auth}}.'</label> ';
! 1770: }
! 1771: } else {
! 1772: $datatable .= '<input type="text" name="'.$item.'" value="'.
! 1773: $domdefaults{$item}.'" />';
! 1774: }
! 1775: $datatable .= '</td></tr>';
! 1776: $rownum ++;
! 1777: }
! 1778: $$rowtotal += $rownum;
! 1779: return $datatable;
! 1780: }
! 1781:
! 1782: sub defaults_titles {
! 1783: my %titles = &Apache::lonlocal::texthash (
! 1784: 'auth_def' => 'Default authentication type',
! 1785: 'auth_arg_def' => 'Default authentication argument',
! 1786: 'lang_def' => 'Default language',
! 1787: );
! 1788: return (\%titles);
! 1789: }
! 1790:
! 1791:
1.33 raeburn 1792: sub modifiable_userdata_row {
1793: my ($context,$role,$settings,$numinrow,$rowcount) = @_;
1794: my $rolename;
1795: if ($role eq 'cr') {
1796: $rolename = &mt('Custom role');
1797: } else {
1798: $rolename = &Apache::lonnet::plaintext($role);
1799: }
1800: my @fields = ('lastname','firstname','middlename','generation',
1801: 'permanentemail','id');
1802: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1803: my $output;
1804: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1805: $output = '<tr '.$css_class.'>'.
1806: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
1807: '<td class="LC_left_item" colspan="2"><table>';
1808: my $rem;
1809: my %checks;
1810: if (ref($settings) eq 'HASH') {
1811: if (ref($settings->{$context}) eq 'HASH') {
1812: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1813: foreach my $field (@fields) {
1814: if ($settings->{$context}->{$role}->{$field}) {
1815: $checks{$field} = ' checked="checked" ';
1816: }
1817: }
1818: }
1819: }
1820: }
1821: for (my $i=0; $i<@fields; $i++) {
1822: my $rem = $i%($numinrow);
1823: if ($rem == 0) {
1824: if ($i > 0) {
1825: $output .= '</tr>';
1826: }
1827: $output .= '<tr>';
1828: }
1829: my $check = ' ';
1830: if (exists($checks{$fields[$i]})) {
1831: $check = $checks{$fields[$i]}
1832: } else {
1833: if ($role eq 'st') {
1834: if (ref($settings) ne 'HASH') {
1835: $check = ' checked="checked" ';
1836: }
1837: }
1838: }
1839: $output .= '<td class="LC_left_item">'.
1840: '<span class="LC_nobreak"><label>'.
1841: '<input type="checkbox" name="canmodify_'.$role.'" '.
1842: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
1843: '</label></span></td>';
1844: $rem = @fields%($numinrow);
1845: }
1846: my $colsleft = $numinrow - $rem;
1847: if ($colsleft > 1 ) {
1848: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1849: ' </td>';
1850: } elsif ($colsleft == 1) {
1851: $output .= '<td class="LC_left_item"> </td>';
1852: }
1853: $output .= '</tr></table></td></tr>';
1854: return $output;
1855: }
1.28 raeburn 1856:
1.25 raeburn 1857: sub users_cansearch_row {
1858: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
1859: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 1860: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
1861: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 1862: my $rem;
1863: if (ref($types) eq 'ARRAY') {
1864: for (my $i=0; $i<@{$types}; $i++) {
1865: if (defined($usertypes->{$types->[$i]})) {
1866: my $rem = $i%($numinrow);
1867: if ($rem == 0) {
1868: if ($i > 0) {
1869: $output .= '</tr>';
1870: }
1871: $output .= '<tr>';
1.23 raeburn 1872: }
1.26 raeburn 1873: my $check = ' ';
1874: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1875: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
1876: $check = ' checked="checked" ';
1877: }
1.23 raeburn 1878: }
1.26 raeburn 1879: $output .= '<td class="LC_left_item">'.
1880: '<span class="LC_nobreak"><label>'.
1881: '<input type="checkbox" name="cansearch" '.
1882: 'value="'.$types->[$i].'"'.$check.'/>'.
1883: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 1884: }
1885: }
1.26 raeburn 1886:
1887: $rem = @{$types}%($numinrow);
1.23 raeburn 1888: }
1889: my $colsleft = $numinrow - $rem;
1890: if ($colsleft > 1) {
1.25 raeburn 1891: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 1892: } else {
1.25 raeburn 1893: $output .= '<td class="LC_left_item">';
1.23 raeburn 1894: }
1895: my $defcheck = ' ';
1896: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 1897: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
1898: $defcheck = ' checked="checked" ';
1899: }
1.23 raeburn 1900: }
1.25 raeburn 1901: $output .= '<span class="LC_nobreak"><label>'.
1902: '<input type="checkbox" name="cansearch" '.
1903: 'value="default"'.$defcheck.'/>'.
1904: $othertitle.'</label></span></td>'.
1905: '</tr></table></td></tr>';
1906: return $output;
1.23 raeburn 1907: }
1908:
1909: sub sorted_inst_types {
1910: my ($dom) = @_;
1911: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1.26 raeburn 1912: my $othertitle = &mt('All users');
1.23 raeburn 1913: my @types;
1914: if (ref($order) eq 'ARRAY') {
1915: @types = @{$order};
1916: }
1917: if (@types == 0) {
1918: if (ref($usertypes) eq 'HASH') {
1919: @types = sort(keys(%{$usertypes}));
1920: }
1921: }
1922: if (keys(%{$usertypes}) > 0) {
1923: $othertitle = &mt('Other users');
1924: }
1925: return ($othertitle,$usertypes,\@types);
1926: }
1927:
1928: sub sorted_searchtitles {
1929: my %searchtitles = &Apache::lonlocal::texthash(
1930: 'uname' => 'username',
1931: 'lastname' => 'last name',
1932: 'lastfirst' => 'last name, first name',
1933: );
1934: my @titleorder = ('uname','lastname','lastfirst');
1935: return (\%searchtitles,\@titleorder);
1936: }
1937:
1.25 raeburn 1938: sub sorted_searchtypes {
1939: my %srchtypes_desc = (
1940: exact => 'is exact match',
1941: contains => 'contains ..',
1942: begins => 'begins with ..',
1943: );
1944: my @srchtypeorder = ('exact','begins','contains');
1945: return (\%srchtypes_desc,\@srchtypeorder);
1946: }
1947:
1.3 raeburn 1948: sub usertype_update_row {
1949: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
1950: my $datatable;
1951: my $numinrow = 4;
1952: foreach my $type (@{$types}) {
1953: if (defined($usertypes->{$type})) {
1954: $$rownums ++;
1955: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
1956: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
1957: '</td><td class="LC_left_item"><table>';
1958: for (my $i=0; $i<@{$fields}; $i++) {
1959: my $rem = $i%($numinrow);
1960: if ($rem == 0) {
1961: if ($i > 0) {
1962: $datatable .= '</tr>';
1963: }
1964: $datatable .= '<tr>';
1965: }
1966: my $check = ' ';
1.39 raeburn 1967: if (ref($settings) eq 'HASH') {
1968: if (ref($settings->{'fields'}) eq 'HASH') {
1969: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
1970: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
1971: $check = ' checked="checked" ';
1972: }
1.3 raeburn 1973: }
1974: }
1975: }
1976:
1977: if ($i == @{$fields}-1) {
1978: my $colsleft = $numinrow - $rem;
1979: if ($colsleft > 1) {
1980: $datatable .= '<td colspan="'.$colsleft.'">';
1981: } else {
1982: $datatable .= '<td>';
1983: }
1984: } else {
1985: $datatable .= '<td>';
1986: }
1.8 raeburn 1987: $datatable .= '<span class="LC_nobreak"><label>'.
1988: '<input type="checkbox" name="updateable_'.$type.
1989: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
1990: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 1991: }
1992: $datatable .= '</tr></table></td></tr>';
1993: }
1994: }
1995: return $datatable;
1.1 raeburn 1996: }
1997:
1998: sub modify_login {
1.9 raeburn 1999: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 2000: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 2001: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 2002: adminmail => 'Display administrator E-mail address',
1.43 ! raeburn 2003: newuser => 'Link for visitors to create a user account',
1.41 raeburn 2004: loginheader => 'Log-in box header');
1.3 raeburn 2005: my @offon = ('off','on');
1.6 raeburn 2006: my %loginhash;
1.9 raeburn 2007: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
2008: \%domconfig,\%loginhash);
1.43 ! raeburn 2009: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2010: foreach my $item (@toggles) {
2011: $loginhash{login}{$item} = $env{'form.'.$item};
2012: }
1.41 raeburn 2013: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 2014: if (ref($colchanges{'login'}) eq 'HASH') {
2015: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
2016: \%loginhash);
2017: }
1.1 raeburn 2018: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
2019: $dom);
2020: if ($putresult eq 'ok') {
1.43 ! raeburn 2021: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2022: my %defaultchecked = (
2023: 'coursecatalog' => 'on',
2024: 'adminmail' => 'off',
1.43 ! raeburn 2025: 'newuser' => 'off',
1.42 raeburn 2026: );
2027: foreach my $item (@toggles) {
2028: if ($defaultchecked{$item} eq 'on') {
2029: if (($domconfig{'login'}{$item} eq '0') &&
2030: ($env{'form.'.$item} eq '1')) {
2031: $changes{$item} = 1;
2032: } elsif (($domconfig{'login'}{$item} eq '' ||
2033: $domconfig{'login'}{$item} eq '1') &&
2034: ($env{'form.'.$item} eq '0')) {
2035: $changes{$item} = 1;
2036: }
2037: } elsif ($defaultchecked{$item} eq 'off') {
2038: if (($domconfig{'login'}{$item} eq '1') &&
2039: ($env{'form.'.$item} eq '0')) {
2040: $changes{$item} = 1;
2041: } elsif (($domconfig{'login'}{$item} eq '' ||
2042: $domconfig{'login'}{$item} eq '0') &&
2043: ($env{'form.'.$item} eq '1')) {
2044: $changes{$item} = 1;
2045: }
2046: }
1.1 raeburn 2047: }
1.41 raeburn 2048: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
2049: ($env{'form.loginheader'} eq 'image')) {
2050: $changes{'loginheader'} = 1;
2051: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
2052: $domconfig{'login'}{'loginheader'} eq 'image') &&
2053: ($env{'form.loginheader'} eq 'text')) {
2054: $changes{'loginheader'} = 1;
2055: }
1.6 raeburn 2056: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 2057: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 2058: $resulttext = &mt('Changes made:').'<ul>';
2059: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 2060: if ($item eq 'loginheader') {
2061: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
2062: } else {
2063: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
2064: }
1.1 raeburn 2065: }
1.6 raeburn 2066: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 2067: } else {
2068: $resulttext = &mt('No changes made to log-in page settings');
2069: }
2070: } else {
1.11 albertel 2071: $resulttext = '<span class="LC_error">'.
2072: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2073: }
1.6 raeburn 2074: if ($errors) {
1.9 raeburn 2075: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 2076: $errors.'</ul>';
2077: }
2078: return $resulttext;
2079: }
2080:
2081: sub color_font_choices {
2082: my %choices =
2083: &Apache::lonlocal::texthash (
2084: img => "Header",
2085: bgs => "Background colors",
2086: links => "Link colors",
2087: font => "Font color",
2088: pgbg => "Page",
2089: tabbg => "Header",
2090: sidebg => "Border",
2091: link => "Link",
2092: alink => "Active link",
2093: vlink => "Visited link",
2094: );
2095: return %choices;
2096: }
2097:
2098: sub modify_rolecolors {
1.9 raeburn 2099: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 2100: my ($resulttext,%rolehash);
2101: $rolehash{'rolecolors'} = {};
1.9 raeburn 2102: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 2103: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
2104: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
2105: $dom);
2106: if ($putresult eq 'ok') {
2107: if (keys(%changes) > 0) {
1.41 raeburn 2108: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 2109: $resulttext = &display_colorchgs($dom,\%changes,$roles,
2110: $rolehash{'rolecolors'});
2111: } else {
2112: $resulttext = &mt('No changes made to default color schemes');
2113: }
2114: } else {
1.11 albertel 2115: $resulttext = '<span class="LC_error">'.
2116: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 2117: }
2118: if ($errors) {
2119: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
2120: $errors.'</ul>';
2121: }
2122: return $resulttext;
2123: }
2124:
2125: sub modify_colors {
1.9 raeburn 2126: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 2127: my (%changes,%choices);
1.6 raeburn 2128: my @bgs = ('pgbg','mainbg','sidebg');
2129: my @links = ('link','alink','vlink');
1.41 raeburn 2130: my @logintext;
1.6 raeburn 2131: my @images;
2132: my $servadm = $r->dir_config('lonAdmEMail');
2133: my $errors;
2134: foreach my $role (@{$roles}) {
2135: if ($role eq 'login') {
1.12 raeburn 2136: %choices = &login_choices();
1.41 raeburn 2137: @logintext = ('textcol','bgcol');
1.12 raeburn 2138: } else {
2139: %choices = &color_font_choices();
2140: }
2141: if ($role eq 'login') {
1.41 raeburn 2142: @images = ('img','logo','domlogo','login');
1.6 raeburn 2143: } else {
2144: @images = ('img');
2145: }
2146: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 2147: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 2148: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
2149: }
1.9 raeburn 2150: my ($configuserok,$author_ok,$switchserver,%currroles);
2151: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
2152: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
2153: $confname,$servadm);
2154: if ($configuserok eq 'ok') {
2155: $switchserver = &check_switchserver($dom,$confname);
2156: if ($switchserver eq '') {
2157: $author_ok = &check_authorstatus($dom,$confname,%currroles);
2158: }
2159: }
2160: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 2161: if (ref($domconfig->{$role}) ne 'HASH') {
2162: $domconfig->{$role} = {};
2163: }
1.8 raeburn 2164: foreach my $img (@images) {
1.18 albertel 2165: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
2166: && !defined($domconfig->{$role}{$img})
2167: && !$env{'form.'.$role.'_del_'.$img}
2168: && $env{'form.'.$role.'_import_'.$img}) {
2169: # import the old configured image from the .tab setting
2170: # if they haven't provided a new one
2171: $domconfig->{$role}{$img} =
2172: $env{'form.'.$role.'_import_'.$img};
2173: }
1.6 raeburn 2174: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 2175: my $error;
1.6 raeburn 2176: if ($configuserok eq 'ok') {
1.9 raeburn 2177: if ($switchserver) {
1.12 raeburn 2178: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 2179: } else {
2180: if ($author_ok eq 'ok') {
2181: my ($result,$logourl) =
2182: &publishlogo($r,'upload',$role.'_'.$img,
2183: $dom,$confname,$img,$width,$height);
2184: if ($result eq 'ok') {
2185: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 2186: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2187: } else {
1.12 raeburn 2188: $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 2189: }
2190: } else {
1.12 raeburn 2191: $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 2192: }
2193: }
2194: } else {
1.12 raeburn 2195: $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 2196: }
2197: if ($error) {
1.8 raeburn 2198: &Apache::lonnet::logthis($error);
1.11 albertel 2199: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 2200: }
2201: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 2202: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
2203: my $error;
2204: if ($configuserok eq 'ok') {
2205: # is confname an author?
2206: if ($switchserver eq '') {
2207: if ($author_ok eq 'ok') {
2208: my ($result,$logourl) =
2209: &publishlogo($r,'copy',$domconfig->{$role}{$img},
2210: $dom,$confname,$img,$width,$height);
2211: if ($result eq 'ok') {
2212: $confhash->{$role}{$img} = $logourl;
1.18 albertel 2213: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2214: }
2215: }
2216: }
2217: }
1.6 raeburn 2218: }
2219: }
2220: }
2221: if (ref($domconfig) eq 'HASH') {
2222: if (ref($domconfig->{$role}) eq 'HASH') {
2223: foreach my $img (@images) {
2224: if ($domconfig->{$role}{$img} ne '') {
2225: if ($env{'form.'.$role.'_del_'.$img}) {
2226: $confhash->{$role}{$img} = '';
1.12 raeburn 2227: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2228: } else {
1.9 raeburn 2229: if ($confhash->{$role}{$img} eq '') {
2230: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
2231: }
1.6 raeburn 2232: }
2233: } else {
2234: if ($env{'form.'.$role.'_del_'.$img}) {
2235: $confhash->{$role}{$img} = '';
1.12 raeburn 2236: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2237: }
2238: }
2239: }
2240: if ($domconfig->{$role}{'font'} ne '') {
2241: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
2242: $changes{$role}{'font'} = 1;
2243: }
2244: } else {
2245: if ($confhash->{$role}{'font'}) {
2246: $changes{$role}{'font'} = 1;
2247: }
2248: }
2249: foreach my $item (@bgs) {
2250: if ($domconfig->{$role}{$item} ne '') {
2251: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2252: $changes{$role}{'bgs'}{$item} = 1;
2253: }
2254: } else {
2255: if ($confhash->{$role}{$item}) {
2256: $changes{$role}{'bgs'}{$item} = 1;
2257: }
2258: }
2259: }
2260: foreach my $item (@links) {
2261: if ($domconfig->{$role}{$item} ne '') {
2262: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2263: $changes{$role}{'links'}{$item} = 1;
2264: }
2265: } else {
2266: if ($confhash->{$role}{$item}) {
2267: $changes{$role}{'links'}{$item} = 1;
2268: }
2269: }
2270: }
1.41 raeburn 2271: foreach my $item (@logintext) {
2272: if ($domconfig->{$role}{$item} ne '') {
2273: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2274: $changes{$role}{'logintext'}{$item} = 1;
2275: }
2276: } else {
2277: if ($confhash->{$role}{$item}) {
2278: $changes{$role}{'logintext'}{$item} = 1;
2279: }
2280: }
2281: }
1.6 raeburn 2282: } else {
2283: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2284: \@logintext,$confhash,\%changes);
1.6 raeburn 2285: }
2286: } else {
2287: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2288: \@logintext,$confhash,\%changes);
1.6 raeburn 2289: }
2290: }
2291: return ($errors,%changes);
2292: }
2293:
2294: sub default_change_checker {
1.41 raeburn 2295: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 2296: foreach my $item (@{$links}) {
2297: if ($confhash->{$role}{$item}) {
2298: $changes->{$role}{'links'}{$item} = 1;
2299: }
2300: }
2301: foreach my $item (@{$bgs}) {
2302: if ($confhash->{$role}{$item}) {
2303: $changes->{$role}{'bgs'}{$item} = 1;
2304: }
2305: }
1.41 raeburn 2306: foreach my $item (@{$logintext}) {
2307: if ($confhash->{$role}{$item}) {
2308: $changes->{$role}{'logintext'}{$item} = 1;
2309: }
2310: }
1.6 raeburn 2311: foreach my $img (@{$images}) {
2312: if ($env{'form.'.$role.'_del_'.$img}) {
2313: $confhash->{$role}{$img} = '';
1.12 raeburn 2314: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 2315: }
2316: }
2317: if ($confhash->{$role}{'font'}) {
2318: $changes->{$role}{'font'} = 1;
2319: }
2320: }
2321:
2322: sub display_colorchgs {
2323: my ($dom,$changes,$roles,$confhash) = @_;
2324: my (%choices,$resulttext);
2325: if (!grep(/^login$/,@{$roles})) {
2326: $resulttext = &mt('Changes made:').'<br />';
2327: }
2328: foreach my $role (@{$roles}) {
2329: if ($role eq 'login') {
2330: %choices = &login_choices();
2331: } else {
2332: %choices = &color_font_choices();
2333: }
2334: if (ref($changes->{$role}) eq 'HASH') {
2335: if ($role ne 'login') {
2336: $resulttext .= '<h4>'.&mt($role).'</h4>';
2337: }
2338: foreach my $key (sort(keys(%{$changes->{$role}}))) {
2339: if ($role ne 'login') {
2340: $resulttext .= '<ul>';
2341: }
2342: if (ref($changes->{$role}{$key}) eq 'HASH') {
2343: if ($role ne 'login') {
2344: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
2345: }
2346: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
2347: if ($confhash->{$role}{$item} eq '') {
2348: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
2349: } else {
1.12 raeburn 2350: my $newitem = $confhash->{$role}{$item};
2351: if ($key eq 'images') {
2352: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
2353: }
2354: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 2355: }
2356: }
2357: if ($role ne 'login') {
2358: $resulttext .= '</ul></li>';
2359: }
2360: } else {
2361: if ($confhash->{$role}{$key} eq '') {
2362: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
2363: } else {
2364: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
2365: }
2366: }
2367: if ($role ne 'login') {
2368: $resulttext .= '</ul>';
2369: }
2370: }
2371: }
2372: }
1.3 raeburn 2373: return $resulttext;
1.1 raeburn 2374: }
2375:
1.9 raeburn 2376: sub thumb_dimensions {
2377: return ('200','50');
2378: }
2379:
1.16 raeburn 2380: sub check_dimensions {
2381: my ($inputfile) = @_;
2382: my ($fullwidth,$fullheight);
2383: if ($inputfile =~ m|^[/\w.\-]+$|) {
2384: if (open(PIPE,"identify $inputfile 2>&1 |")) {
2385: my $imageinfo = <PIPE>;
2386: if (!close(PIPE)) {
2387: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
2388: }
2389: chomp($imageinfo);
2390: my ($fullsize) =
1.21 raeburn 2391: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 2392: if ($fullsize) {
2393: ($fullwidth,$fullheight) = split(/x/,$fullsize);
2394: }
2395: }
2396: }
2397: return ($fullwidth,$fullheight);
2398: }
2399:
1.9 raeburn 2400: sub check_configuser {
2401: my ($uhome,$dom,$confname,$servadm) = @_;
2402: my ($configuserok,%currroles);
2403: if ($uhome eq 'no_host') {
2404: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
2405: my $configpass = &LONCAPA::Enrollment::create_password();
2406: $configuserok =
2407: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
2408: $configpass,'','','','','',undef,$servadm);
2409: } else {
2410: $configuserok = 'ok';
2411: %currroles =
2412: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
2413: }
2414: return ($configuserok,%currroles);
2415: }
2416:
2417: sub check_authorstatus {
2418: my ($dom,$confname,%currroles) = @_;
2419: my $author_ok;
1.40 raeburn 2420: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 2421: my $start = time;
2422: my $end = 0;
2423: $author_ok =
2424: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
2425: 'au',$end,$start);
2426: } else {
2427: $author_ok = 'ok';
2428: }
2429: return $author_ok;
2430: }
2431:
2432: sub publishlogo {
2433: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
2434: my ($output,$fname,$logourl);
2435: if ($action eq 'upload') {
2436: $fname=$env{'form.'.$formname.'.filename'};
2437: chop($env{'form.'.$formname});
2438: } else {
2439: ($fname) = ($formname =~ /([^\/]+)$/);
2440: }
2441: $fname=&Apache::lonnet::clean_filename($fname);
2442: # See if there is anything left
2443: unless ($fname) { return ('error: no uploaded file'); }
2444: $fname="$subdir/$fname";
2445: my $filepath='/home/'.$confname.'/public_html';
2446: my ($fnamepath,$file,$fetchthumb);
2447: $file=$fname;
2448: if ($fname=~m|/|) {
2449: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
2450: }
2451: my @parts=split(/\//,$filepath.'/'.$fnamepath);
2452: my $count;
2453: for ($count=4;$count<=$#parts;$count++) {
2454: $filepath.="/$parts[$count]";
2455: if ((-e $filepath)!=1) {
2456: mkdir($filepath,02770);
2457: }
2458: }
2459: # Check for bad extension and disallow upload
2460: if ($file=~/\.(\w+)$/ &&
2461: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
2462: $output =
2463: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
2464: } elsif ($file=~/\.(\w+)$/ &&
2465: !defined(&Apache::loncommon::fileembstyle($1))) {
2466: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
2467: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
2468: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
2469: } elsif (-d "$filepath/$file") {
2470: $output = &mt('File name is a directory name - rename the file and re-upload');
2471: } else {
2472: my $source = $filepath.'/'.$file;
2473: my $logfile;
2474: if (!open($logfile,">>$source".'.log')) {
2475: return (&mt('No write permission to Construction Space'));
2476: }
2477: print $logfile
2478: "\n================= Publish ".localtime()." ================\n".
2479: $env{'user.name'}.':'.$env{'user.domain'}."\n";
2480: # Save the file
2481: if (!open(FH,'>'.$source)) {
2482: &Apache::lonnet::logthis('Failed to create '.$source);
2483: return (&mt('Failed to create file'));
2484: }
2485: if ($action eq 'upload') {
2486: if (!print FH ($env{'form.'.$formname})) {
2487: &Apache::lonnet::logthis('Failed to write to '.$source);
2488: return (&mt('Failed to write file'));
2489: }
2490: } else {
2491: my $original = &Apache::lonnet::filelocation('',$formname);
2492: if(!copy($original,$source)) {
2493: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
2494: return (&mt('Failed to write file'));
2495: }
2496: }
2497: close(FH);
2498: chmod(0660, $source); # Permissions to rw-rw---.
2499:
2500: my $docroot=$r->dir_config('lonDocRoot');
2501: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
2502: my $copyfile=$targetdir.'/'.$file;
2503:
2504: my @parts=split(/\//,$targetdir);
2505: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
2506: for (my $count=5;$count<=$#parts;$count++) {
2507: $path.="/$parts[$count]";
2508: if (!-e $path) {
2509: print $logfile "\nCreating directory ".$path;
2510: mkdir($path,02770);
2511: }
2512: }
2513: my $versionresult;
2514: if (-e $copyfile) {
2515: $versionresult = &logo_versioning($targetdir,$file,$logfile);
2516: } else {
2517: $versionresult = 'ok';
2518: }
2519: if ($versionresult eq 'ok') {
2520: if (copy($source,$copyfile)) {
2521: print $logfile "\nCopied original source to ".$copyfile."\n";
2522: $output = 'ok';
2523: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
2524: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
2525: } else {
2526: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
2527: $output = &mt('Failed to copy file to RES space').", $!";
2528: }
2529: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
2530: my $inputfile = $filepath.'/'.$file;
2531: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 2532: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
2533: if ($fullwidth ne '' && $fullheight ne '') {
2534: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
2535: my $thumbsize = $thumbwidth.'x'.$thumbheight;
2536: system("convert -sample $thumbsize $inputfile $outfile");
2537: chmod(0660, $filepath.'/tn-'.$file);
2538: if (-e $outfile) {
2539: my $copyfile=$targetdir.'/tn-'.$file;
2540: if (copy($outfile,$copyfile)) {
2541: print $logfile "\nCopied source to ".$copyfile."\n";
2542: &write_metadata($dom,$confname,$formname,
2543: $targetdir,'tn-'.$file,$logfile);
2544: } else {
2545: print $logfile "\nUnable to write ".$copyfile.
2546: ':'.$!."\n";
2547: }
2548: }
1.9 raeburn 2549: }
2550: }
2551: }
2552: } else {
2553: $output = $versionresult;
2554: }
2555: }
2556: return ($output,$logourl);
2557: }
2558:
2559: sub logo_versioning {
2560: my ($targetdir,$file,$logfile) = @_;
2561: my $target = $targetdir.'/'.$file;
2562: my ($maxversion,$fn,$extn,$output);
2563: $maxversion = 0;
2564: if ($file =~ /^(.+)\.(\w+)$/) {
2565: $fn=$1;
2566: $extn=$2;
2567: }
2568: opendir(DIR,$targetdir);
2569: while (my $filename=readdir(DIR)) {
2570: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
2571: $maxversion=($1>$maxversion)?$1:$maxversion;
2572: }
2573: }
2574: $maxversion++;
2575: print $logfile "\nCreating old version ".$maxversion."\n";
2576: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
2577: if (copy($target,$copyfile)) {
2578: print $logfile "Copied old target to ".$copyfile."\n";
2579: $copyfile=$copyfile.'.meta';
2580: if (copy($target.'.meta',$copyfile)) {
2581: print $logfile "Copied old target metadata to ".$copyfile."\n";
2582: $output = 'ok';
2583: } else {
2584: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
2585: $output = &mt('Failed to copy old meta').", $!, ";
2586: }
2587: } else {
2588: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
2589: $output = &mt('Failed to copy old target').", $!, ";
2590: }
2591: return $output;
2592: }
2593:
2594: sub write_metadata {
2595: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
2596: my (%metadatafields,%metadatakeys,$output);
2597: $metadatafields{'title'}=$formname;
2598: $metadatafields{'creationdate'}=time;
2599: $metadatafields{'lastrevisiondate'}=time;
2600: $metadatafields{'copyright'}='public';
2601: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
2602: $env{'user.domain'};
2603: $metadatafields{'authorspace'}=$confname.':'.$dom;
2604: $metadatafields{'domain'}=$dom;
2605: {
2606: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
2607: my $mfh;
2608: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
2609: $output = &mt('Could not write metadata');
2610: }
2611: foreach (sort keys %metadatafields) {
2612: unless ($_=~/\./) {
2613: my $unikey=$_;
2614: $unikey=~/^([A-Za-z]+)/;
2615: my $tag=$1;
2616: $tag=~tr/A-Z/a-z/;
2617: print $mfh "\n\<$tag";
2618: foreach (split(/\,/,$metadatakeys{$unikey})) {
2619: my $value=$metadatafields{$unikey.'.'.$_};
2620: $value=~s/\"/\'\'/g;
2621: print $mfh ' '.$_.'="'.$value.'"';
2622: }
2623: print $mfh '>'.
2624: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
2625: .'</'.$tag.'>';
2626: }
2627: }
2628: $output = 'ok';
2629: print $logfile "\nWrote metadata";
2630: close($mfh);
2631: }
2632: }
2633:
2634: sub check_switchserver {
2635: my ($dom,$confname) = @_;
2636: my ($allowed,$switchserver);
2637: my $home = &Apache::lonnet::homeserver($confname,$dom);
2638: if ($home eq 'no_host') {
2639: $home = &Apache::lonnet::domain($dom,'primary');
2640: }
2641: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 2642: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2643: if (!$allowed) {
2644: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 2645: }
2646: return $switchserver;
2647: }
2648:
1.30 raeburn 2649: sub javascript_set_colnums {
2650: return <<END;
2651: function setDisplayColumns() {
2652: if (document.pickactions.width.value > 1100) {
2653: document.pickactions.numcols[1].checked = true;
2654: } else {
2655: document.pickactions.numcols[0].checked = true;
2656: }
2657: }
2658: END
2659: }
2660:
1.1 raeburn 2661: sub modify_quotas {
1.3 raeburn 2662: my ($dom,%domconfig) = @_;
1.1 raeburn 2663: my ($resulttext,%changes);
1.26 raeburn 2664: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2665: my %formhash;
2666: foreach my $key (keys(%env)) {
2667: if ($key =~ /^form\.quota_(.+)$/) {
2668: $formhash{$1} = $env{$key};
2669: }
2670: }
1.15 raeburn 2671: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 2672: if (ref($domconfig{'quotas'}) eq 'HASH') {
2673: foreach my $key (keys(%{$domconfig{'quotas'}})) {
2674: if (exists($formhash{$key})) {
2675: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
2676: $changes{$key} = 1;
2677: }
2678: } else {
2679: $formhash{$key} = $domconfig{'quotas'}{$key};
2680: }
2681: }
2682: }
2683: foreach my $key (keys(%formhash)) {
2684: if ($formhash{$key} ne '') {
1.3 raeburn 2685: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 2686: $changes{$key} = 1;
2687: }
2688: }
2689: }
2690: my %quotahash = (
1.3 raeburn 2691: quotas => {%formhash},
1.1 raeburn 2692: );
2693: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
2694: $dom);
2695: if ($putresult eq 'ok') {
2696: if (keys(%changes) > 0) {
2697: $resulttext = &mt('Changes made:').'<ul>';
1.26 raeburn 2698: foreach my $type (@{$types},'default') {
2699: if (defined($changes{$type})) {
2700: my $typetitle = $usertypes->{$type};
2701: if ($type eq 'default') {
2702: $typetitle = $othertitle;
2703: }
2704: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
2705: }
1.1 raeburn 2706: }
2707: $resulttext .= '</ul>';
2708: } else {
2709: $resulttext = &mt('No changes made to default quotas');
2710: }
2711: } else {
1.11 albertel 2712: $resulttext = '<span class="LC_error">'.
2713: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2714: }
1.3 raeburn 2715: return $resulttext;
1.1 raeburn 2716: }
2717:
1.3 raeburn 2718: sub modify_autoenroll {
2719: my ($dom,%domconfig) = @_;
1.1 raeburn 2720: my ($resulttext,%changes);
2721: my %currautoenroll;
2722: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
2723: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
2724: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
2725: }
2726: }
2727: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2728: my %title = ( run => 'Auto-enrollment active',
2729: sender => 'Sender for notification messages');
2730: my @offon = ('off','on');
1.17 raeburn 2731: my $sender_uname = $env{'form.sender_uname'};
2732: my $sender_domain = $env{'form.sender_domain'};
2733: if ($sender_domain eq '') {
2734: $sender_uname = '';
2735: } elsif ($sender_uname eq '') {
2736: $sender_domain = '';
2737: }
1.1 raeburn 2738: my %autoenrollhash = (
2739: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 2740: sender_uname => $sender_uname,
2741: sender_domain => $sender_domain,
1.1 raeburn 2742:
2743: }
2744: );
1.4 raeburn 2745: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
2746: $dom);
1.1 raeburn 2747: if ($putresult eq 'ok') {
2748: if (exists($currautoenroll{'run'})) {
2749: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
2750: $changes{'run'} = 1;
2751: }
2752: } elsif ($autorun) {
2753: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 2754: $changes{'run'} = 1;
1.1 raeburn 2755: }
2756: }
1.17 raeburn 2757: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 2758: $changes{'sender'} = 1;
2759: }
1.17 raeburn 2760: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 2761: $changes{'sender'} = 1;
2762: }
2763: if (keys(%changes) > 0) {
2764: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 2765: if ($changes{'run'}) {
1.1 raeburn 2766: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
2767: }
2768: if ($changes{'sender'}) {
1.17 raeburn 2769: if ($sender_uname eq '' || $sender_domain eq '') {
2770: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
2771: } else {
2772: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
2773: }
1.1 raeburn 2774: }
2775: $resulttext .= '</ul>';
2776: } else {
2777: $resulttext = &mt('No changes made to auto-enrollment settings');
2778: }
2779: } else {
1.11 albertel 2780: $resulttext = '<span class="LC_error">'.
2781: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2782: }
1.3 raeburn 2783: return $resulttext;
1.1 raeburn 2784: }
2785:
2786: sub modify_autoupdate {
1.3 raeburn 2787: my ($dom,%domconfig) = @_;
1.1 raeburn 2788: my ($resulttext,%currautoupdate,%fields,%changes);
2789: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
2790: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
2791: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
2792: }
2793: }
2794: my @offon = ('off','on');
2795: my %title = &Apache::lonlocal::texthash (
2796: run => 'Auto-update:',
2797: classlists => 'Updates to user information in classlists?'
2798: );
1.26 raeburn 2799: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2800: my %fieldtitles = &Apache::lonlocal::texthash (
2801: id => 'Student/Employee ID',
1.20 raeburn 2802: permanentemail => 'E-mail address',
1.1 raeburn 2803: lastname => 'Last Name',
2804: firstname => 'First Name',
2805: middlename => 'Middle Name',
2806: gen => 'Generation',
2807: );
2808: my $othertitle = &mt('All users');
2809: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 2810: $othertitle = &mt('Other users');
1.1 raeburn 2811: }
2812: foreach my $key (keys(%env)) {
2813: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
2814: push(@{$fields{$1}},$2);
2815: }
2816: }
2817: my %updatehash = (
2818: autoupdate => { run => $env{'form.autoupdate_run'},
2819: classlists => $env{'form.classlists'},
2820: fields => {%fields},
2821: }
2822: );
2823: foreach my $key (keys(%currautoupdate)) {
2824: if (($key eq 'run') || ($key eq 'classlists')) {
2825: if (exists($updatehash{autoupdate}{$key})) {
2826: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
2827: $changes{$key} = 1;
2828: }
2829: }
2830: } elsif ($key eq 'fields') {
2831: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 2832: foreach my $item (@{$types},'default') {
1.1 raeburn 2833: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
2834: my $change = 0;
2835: foreach my $type (@{$currautoupdate{$key}{$item}}) {
2836: if (!exists($fields{$item})) {
2837: $change = 1;
2838: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 2839: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 2840: $change = 1;
2841: }
2842: }
2843: }
2844: if ($change) {
2845: push(@{$changes{$key}},$item);
2846: }
1.26 raeburn 2847: }
1.1 raeburn 2848: }
2849: }
2850: }
2851: }
1.26 raeburn 2852: foreach my $item (@{$types},'default') {
2853: if (defined($fields{$item})) {
2854: if (ref($currautoupdate{'fields'}) eq 'HASH') {
2855: if (!exists($currautoupdate{'fields'}{$item})) {
2856: push(@{$changes{'fields'}},$item);
2857: }
2858: } else {
2859: push(@{$changes{'fields'}},$item);
1.1 raeburn 2860: }
2861: }
2862: }
2863: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
2864: $dom);
2865: if ($putresult eq 'ok') {
2866: if (keys(%changes) > 0) {
2867: $resulttext = &mt('Changes made:').'<ul>';
2868: foreach my $key (sort(keys(%changes))) {
2869: if (ref($changes{$key}) eq 'ARRAY') {
2870: foreach my $item (@{$changes{$key}}) {
2871: my @newvalues;
2872: foreach my $type (@{$fields{$item}}) {
2873: push(@newvalues,$fieldtitles{$type});
2874: }
1.3 raeburn 2875: my $newvaluestr;
2876: if (@newvalues > 0) {
2877: $newvaluestr = join(', ',@newvalues);
2878: } else {
2879: $newvaluestr = &mt('none');
1.6 raeburn 2880: }
1.1 raeburn 2881: if ($item eq 'default') {
1.26 raeburn 2882: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 2883: } else {
1.26 raeburn 2884: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 2885: }
2886: }
2887: } else {
2888: my $newvalue;
2889: if ($key eq 'run') {
2890: $newvalue = $offon[$env{'form.autoupdate_run'}];
2891: } else {
2892: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 2893: }
1.1 raeburn 2894: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
2895: }
2896: }
2897: $resulttext .= '</ul>';
2898: } else {
1.3 raeburn 2899: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 2900: }
2901: } else {
1.11 albertel 2902: $resulttext = '<span class="LC_error">'.
2903: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2904: }
1.3 raeburn 2905: return $resulttext;
1.1 raeburn 2906: }
2907:
1.23 raeburn 2908: sub modify_directorysrch {
2909: my ($dom,%domconfig) = @_;
2910: my ($resulttext,%changes);
2911: my %currdirsrch;
2912: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2913: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
2914: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
2915: }
2916: }
2917: my %title = ( available => 'Directory search available',
1.24 raeburn 2918: localonly => 'Other domains can search',
1.23 raeburn 2919: searchby => 'Search types',
2920: searchtypes => 'Search latitude');
2921: my @offon = ('off','on');
1.24 raeburn 2922: my @otherdoms = ('Yes','No');
1.23 raeburn 2923:
1.25 raeburn 2924: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 2925: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
2926: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
2927:
1.26 raeburn 2928: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
2929: if (keys(%{$usertypes}) == 0) {
2930: @cansearch = ('default');
2931: } else {
2932: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
2933: foreach my $type (@{$currdirsrch{'cansearch'}}) {
2934: if (!grep(/^\Q$type\E$/,@cansearch)) {
2935: push(@{$changes{'cansearch'}},$type);
2936: }
1.23 raeburn 2937: }
1.26 raeburn 2938: foreach my $type (@cansearch) {
2939: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
2940: push(@{$changes{'cansearch'}},$type);
2941: }
1.23 raeburn 2942: }
1.26 raeburn 2943: } else {
2944: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 2945: }
2946: }
2947:
2948: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
2949: foreach my $by (@{$currdirsrch{'searchby'}}) {
2950: if (!grep(/^\Q$by\E$/,@searchby)) {
2951: push(@{$changes{'searchby'}},$by);
2952: }
2953: }
2954: foreach my $by (@searchby) {
2955: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
2956: push(@{$changes{'searchby'}},$by);
2957: }
2958: }
2959: } else {
2960: push(@{$changes{'searchby'}},@searchby);
2961: }
1.25 raeburn 2962:
2963: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
2964: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
2965: if (!grep(/^\Q$type\E$/,@searchtypes)) {
2966: push(@{$changes{'searchtypes'}},$type);
2967: }
2968: }
2969: foreach my $type (@searchtypes) {
2970: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
2971: push(@{$changes{'searchtypes'}},$type);
2972: }
2973: }
2974: } else {
2975: if (exists($currdirsrch{'searchtypes'})) {
2976: foreach my $type (@searchtypes) {
2977: if ($type ne $currdirsrch{'searchtypes'}) {
2978: push(@{$changes{'searchtypes'}},$type);
2979: }
2980: }
2981: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
2982: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
2983: }
2984: } else {
2985: push(@{$changes{'searchtypes'}},@searchtypes);
2986: }
2987: }
2988:
1.23 raeburn 2989: my %dirsrch_hash = (
2990: directorysrch => { available => $env{'form.dirsrch_available'},
2991: cansearch => \@cansearch,
1.24 raeburn 2992: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 2993: searchby => \@searchby,
1.25 raeburn 2994: searchtypes => \@searchtypes,
1.23 raeburn 2995: }
2996: );
2997: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
2998: $dom);
2999: if ($putresult eq 'ok') {
3000: if (exists($currdirsrch{'available'})) {
3001: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
3002: $changes{'available'} = 1;
3003: }
3004: } else {
3005: if ($env{'form.dirsrch_available'} eq '1') {
3006: $changes{'available'} = 1;
3007: }
3008: }
1.24 raeburn 3009: if (exists($currdirsrch{'localonly'})) {
3010: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
3011: $changes{'localonly'} = 1;
3012: }
3013: } else {
3014: if ($env{'form.dirsrch_localonly'} eq '1') {
3015: $changes{'localonly'} = 1;
3016: }
3017: }
1.23 raeburn 3018: if (keys(%changes) > 0) {
3019: $resulttext = &mt('Changes made:').'<ul>';
3020: if ($changes{'available'}) {
3021: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
3022: }
1.24 raeburn 3023: if ($changes{'localonly'}) {
3024: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
3025: }
3026:
1.23 raeburn 3027: if (ref($changes{'cansearch'}) eq 'ARRAY') {
3028: my $chgtext;
1.26 raeburn 3029: if (ref($usertypes) eq 'HASH') {
3030: if (keys(%{$usertypes}) > 0) {
3031: foreach my $type (@{$types}) {
3032: if (grep(/^\Q$type\E$/,@cansearch)) {
3033: $chgtext .= $usertypes->{$type}.'; ';
3034: }
3035: }
3036: if (grep(/^default$/,@cansearch)) {
3037: $chgtext .= $othertitle;
3038: } else {
3039: $chgtext =~ s/\; $//;
3040: }
3041: $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 3042: }
3043: }
3044: }
3045: if (ref($changes{'searchby'}) eq 'ARRAY') {
3046: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3047: my $chgtext;
3048: foreach my $type (@{$titleorder}) {
3049: if (grep(/^\Q$type\E$/,@searchby)) {
3050: if (defined($searchtitles->{$type})) {
3051: $chgtext .= $searchtitles->{$type}.'; ';
3052: }
3053: }
3054: }
3055: $chgtext =~ s/\; $//;
3056: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
3057: }
1.25 raeburn 3058: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
3059: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
3060: my $chgtext;
3061: foreach my $type (@{$srchtypeorder}) {
3062: if (grep(/^\Q$type\E$/,@searchtypes)) {
3063: if (defined($srchtypes_desc->{$type})) {
3064: $chgtext .= $srchtypes_desc->{$type}.'; ';
3065: }
3066: }
3067: }
3068: $chgtext =~ s/\; $//;
3069: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 3070: }
3071: $resulttext .= '</ul>';
3072: } else {
3073: $resulttext = &mt('No changes made to institution directory search settings');
3074: }
3075: } else {
3076: $resulttext = '<span class="LC_error">'.
1.27 raeburn 3077: &mt('An error occurred: [_1]',$putresult).'</span>';
3078: }
3079: return $resulttext;
3080: }
3081:
1.28 raeburn 3082: sub modify_contacts {
3083: my ($dom,%domconfig) = @_;
3084: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
3085: if (ref($domconfig{'contacts'}) eq 'HASH') {
3086: foreach my $key (keys(%{$domconfig{'contacts'}})) {
3087: $currsetting{$key} = $domconfig{'contacts'}{$key};
3088: }
3089: }
3090: my (%others,%to);
3091: my @contacts = ('supportemail','adminemail');
3092: my @mailings = ('errormail','packagesmail','helpdeskmail');
3093: foreach my $type (@mailings) {
3094: @{$newsetting{$type}} =
3095: &Apache::loncommon::get_env_multiple('form.'.$type);
3096: foreach my $item (@contacts) {
3097: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
3098: $contacts_hash{contacts}{$type}{$item} = 1;
3099: } else {
3100: $contacts_hash{contacts}{$type}{$item} = 0;
3101: }
3102: }
3103: $others{$type} = $env{'form.'.$type.'_others'};
3104: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
3105: }
3106: foreach my $item (@contacts) {
3107: $to{$item} = $env{'form.'.$item};
3108: $contacts_hash{'contacts'}{$item} = $to{$item};
3109: }
3110: if (keys(%currsetting) > 0) {
3111: foreach my $item (@contacts) {
3112: if ($to{$item} ne $currsetting{$item}) {
3113: $changes{$item} = 1;
3114: }
3115: }
3116: foreach my $type (@mailings) {
3117: foreach my $item (@contacts) {
3118: if (ref($currsetting{$type}) eq 'HASH') {
3119: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
3120: push(@{$changes{$type}},$item);
3121: }
3122: } else {
3123: push(@{$changes{$type}},@{$newsetting{$type}});
3124: }
3125: }
3126: if ($others{$type} ne $currsetting{$type}{'others'}) {
3127: push(@{$changes{$type}},'others');
3128: }
3129: }
3130: } else {
3131: my %default;
3132: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3133: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3134: $default{'errormail'} = 'adminemail';
3135: $default{'packagesmail'} = 'adminemail';
3136: $default{'helpdeskmail'} = 'supportemail';
3137: foreach my $item (@contacts) {
3138: if ($to{$item} ne $default{$item}) {
3139: $changes{$item} = 1;
3140: }
3141: }
3142: foreach my $type (@mailings) {
3143: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
3144:
3145: push(@{$changes{$type}},@{$newsetting{$type}});
3146: }
3147: if ($others{$type} ne '') {
3148: push(@{$changes{$type}},'others');
3149: }
3150: }
3151: }
3152: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
3153: $dom);
3154: if ($putresult eq 'ok') {
3155: if (keys(%changes) > 0) {
3156: my ($titles,$short_titles) = &contact_titles();
3157: $resulttext = &mt('Changes made:').'<ul>';
3158: foreach my $item (@contacts) {
3159: if ($changes{$item}) {
3160: $resulttext .= '<li>'.$titles->{$item}.
3161: &mt(' set to: ').
3162: '<span class="LC_cusr_emph">'.
3163: $to{$item}.'</span></li>';
3164: }
3165: }
3166: foreach my $type (@mailings) {
3167: if (ref($changes{$type}) eq 'ARRAY') {
3168: $resulttext .= '<li>'.$titles->{$type}.': ';
3169: my @text;
3170: foreach my $item (@{$newsetting{$type}}) {
3171: push(@text,$short_titles->{$item});
3172: }
3173: if ($others{$type} ne '') {
3174: push(@text,$others{$type});
3175: }
3176: $resulttext .= '<span class="LC_cusr_emph">'.
3177: join(', ',@text).'</span></li>';
3178: }
3179: }
3180: $resulttext .= '</ul>';
3181: } else {
1.34 raeburn 3182: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 3183: }
3184: } else {
3185: $resulttext = '<span class="LC_error">'.
3186: &mt('An error occurred: [_1].',$putresult).'</span>';
3187: }
3188: return $resulttext;
3189: }
3190:
3191: sub modify_usercreation {
1.27 raeburn 3192: my ($dom,%domconfig) = @_;
1.34 raeburn 3193: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 ! raeburn 3194: my $warningmsg;
1.27 raeburn 3195: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3196: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
3197: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
3198: }
3199: }
3200: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 3201: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 ! raeburn 3202: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
! 3203: my @contexts = ('author','course','selfenroll');
1.34 raeburn 3204: foreach my $item(@contexts) {
3205: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 ! raeburn 3206: if ($item eq 'selfenroll') {
! 3207: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
! 3208: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
! 3209: if (($cancreate{$item} eq 'any') || ($cancreate{$item} eq 'login')) {
! 3210: $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');
! 3211: }
! 3212: }
! 3213: }
1.34 raeburn 3214: }
3215: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
3216: foreach my $item (@contexts) {
3217: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
3218: push(@{$changes{'cancreate'}},$item);
3219: }
1.27 raeburn 3220: }
1.34 raeburn 3221: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
3222: foreach my $item (@contexts) {
1.43 ! raeburn 3223: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 3224: if ($cancreate{$item} ne 'any') {
3225: push(@{$changes{'cancreate'}},$item);
3226: }
3227: } else {
3228: if ($cancreate{$item} ne 'none') {
3229: push(@{$changes{'cancreate'}},$item);
3230: }
1.27 raeburn 3231: }
3232: }
3233: } else {
1.43 ! raeburn 3234: foreach my $item (@contexts) {
1.34 raeburn 3235: push(@{$changes{'cancreate'}},$item);
3236: }
1.27 raeburn 3237: }
1.34 raeburn 3238:
1.27 raeburn 3239: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
3240: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
3241: if (!grep(/^\Q$type\E$/,@username_rule)) {
3242: push(@{$changes{'username_rule'}},$type);
3243: }
3244: }
3245: foreach my $type (@username_rule) {
3246: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
3247: push(@{$changes{'username_rule'}},$type);
3248: }
3249: }
3250: } else {
3251: push(@{$changes{'username_rule'}},@username_rule);
3252: }
3253:
1.32 raeburn 3254: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
3255: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
3256: if (!grep(/^\Q$type\E$/,@id_rule)) {
3257: push(@{$changes{'id_rule'}},$type);
3258: }
3259: }
3260: foreach my $type (@id_rule) {
3261: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
3262: push(@{$changes{'id_rule'}},$type);
3263: }
3264: }
3265: } else {
3266: push(@{$changes{'id_rule'}},@id_rule);
3267: }
3268:
1.43 ! raeburn 3269: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
! 3270: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
! 3271: if (!grep(/^\Q$type\E$/,@email_rule)) {
! 3272: push(@{$changes{'email_rule'}},$type);
! 3273: }
! 3274: }
! 3275: foreach my $type (@email_rule) {
! 3276: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
! 3277: push(@{$changes{'email_rule'}},$type);
! 3278: }
! 3279: }
! 3280: } else {
! 3281: push(@{$changes{'email_rule'}},@email_rule);
! 3282: }
! 3283:
! 3284: my @authen_contexts = ('author','course','domain');
1.28 raeburn 3285: my @authtypes = ('int','krb4','krb5','loc');
3286: my %authhash;
1.43 ! raeburn 3287: foreach my $item (@authen_contexts) {
1.28 raeburn 3288: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
3289: foreach my $auth (@authtypes) {
3290: if (grep(/^\Q$auth\E$/,@authallowed)) {
3291: $authhash{$item}{$auth} = 1;
3292: } else {
3293: $authhash{$item}{$auth} = 0;
3294: }
3295: }
3296: }
3297: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 ! raeburn 3298: foreach my $item (@authen_contexts) {
1.28 raeburn 3299: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
3300: foreach my $auth (@authtypes) {
3301: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
3302: push(@{$changes{'authtypes'}},$item);
3303: last;
3304: }
3305: }
3306: }
3307: }
3308: } else {
1.43 ! raeburn 3309: foreach my $item (@authen_contexts) {
1.28 raeburn 3310: push(@{$changes{'authtypes'}},$item);
3311: }
3312: }
3313:
1.27 raeburn 3314: my %usercreation_hash = (
1.28 raeburn 3315: usercreation => {
1.34 raeburn 3316: cancreate => \%cancreate,
1.27 raeburn 3317: username_rule => \@username_rule,
1.32 raeburn 3318: id_rule => \@id_rule,
1.43 ! raeburn 3319: email_rule => \@email_rule,
1.32 raeburn 3320: authtypes => \%authhash,
1.27 raeburn 3321: }
3322: );
3323:
3324: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
3325: $dom);
3326: if ($putresult eq 'ok') {
3327: if (keys(%changes) > 0) {
3328: $resulttext = &mt('Changes made:').'<ul>';
3329: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 3330: my %lt = &usercreation_types();
3331: foreach my $type (@{$changes{'cancreate'}}) {
1.43 ! raeburn 3332: my $chgtext = $lt{$type}.', ';
! 3333: if ($type eq 'selfenroll') {
! 3334: if ($cancreate{$type} eq 'none') {
! 3335: $chgtext .= &mt('creation of a new user account is not permitted.');
! 3336: } elsif ($cancreate{$type} eq 'any') {
! 3337: $chgtext .= &mt('creation of a new account is permitted for users authenticated by institutional log-in and SSO, and also for e-mail addresses used as usernames.');
! 3338: } elsif ($cancreate{$type} eq 'login') {
! 3339: $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional log-in.');
! 3340: } elsif ($cancreate{$type} eq 'sso') {
! 3341: $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional single sign on.');
! 3342: } elsif ($cancreate{$type} eq 'email') {
! 3343: $chgtext .= &mt('creation of a new account is only permitted for users who provide a valid e-mail address for use as the username.');
! 3344: }
! 3345: } else {
! 3346: if ($cancreate{$type} eq 'none') {
! 3347: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
! 3348: } elsif ($cancreate{$type} eq 'any') {
! 3349: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
! 3350: } elsif ($cancreate{$type} eq 'official') {
! 3351: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
! 3352: } elsif ($cancreate{$type} eq 'unofficial') {
! 3353: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
! 3354: }
1.34 raeburn 3355: }
3356: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 3357: }
3358: }
3359: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 3360: my ($rules,$ruleorder) =
3361: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 3362: my $chgtext = '<ul>';
3363: foreach my $type (@username_rule) {
3364: if (ref($rules->{$type}) eq 'HASH') {
3365: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
3366: }
3367: }
3368: $chgtext .= '</ul>';
3369: if (@username_rule > 0) {
3370: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3371: } else {
1.28 raeburn 3372: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 3373: }
3374: }
1.32 raeburn 3375: if (ref($changes{'id_rule'}) eq 'ARRAY') {
3376: my ($idrules,$idruleorder) =
3377: &Apache::lonnet::inst_userrules($dom,'id');
3378: my $chgtext = '<ul>';
3379: foreach my $type (@id_rule) {
3380: if (ref($idrules->{$type}) eq 'HASH') {
3381: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
3382: }
3383: }
3384: $chgtext .= '</ul>';
3385: if (@id_rule > 0) {
3386: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3387: } else {
3388: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
3389: }
3390: }
1.43 ! raeburn 3391: if (ref($changes{'email_rule'}) eq 'ARRAY') {
! 3392: my ($emailrules,$emailruleorder) =
! 3393: &Apache::lonnet::inst_userrules($dom,'email');
! 3394: my $chgtext = '<ul>';
! 3395: foreach my $type (@email_rule) {
! 3396: if (ref($emailrules->{$type}) eq 'HASH') {
! 3397: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
! 3398: }
! 3399: }
! 3400: $chgtext .= '</ul>';
! 3401: if (@email_rule > 0) {
! 3402: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
! 3403: } else {
! 3404: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
! 3405: }
! 3406: }
! 3407:
1.28 raeburn 3408: my %authname = &authtype_names();
3409: my %context_title = &context_names();
3410: if (ref($changes{'authtypes'}) eq 'ARRAY') {
3411: my $chgtext = '<ul>';
3412: foreach my $type (@{$changes{'authtypes'}}) {
3413: my @allowed;
3414: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
3415: foreach my $auth (@authtypes) {
3416: if ($authhash{$type}{$auth}) {
3417: push(@allowed,$authname{$auth});
3418: }
3419: }
1.43 ! raeburn 3420: if (@allowed > 0) {
! 3421: $chgtext .= join(', ',@allowed).'</li>';
! 3422: } else {
! 3423: $chgtext .= &mt('none').'</li>';
! 3424: }
1.28 raeburn 3425: }
3426: $chgtext .= '</ul>';
3427: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
3428: $resulttext .= '</li>';
3429: }
1.27 raeburn 3430: $resulttext .= '</ul>';
3431: } else {
1.28 raeburn 3432: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 3433: }
3434: } else {
3435: $resulttext = '<span class="LC_error">'.
1.23 raeburn 3436: &mt('An error occurred: [_1]',$putresult).'</span>';
3437: }
1.43 ! raeburn 3438: if ($warningmsg ne '') {
! 3439: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
! 3440: }
1.23 raeburn 3441: return $resulttext;
3442: }
3443:
1.33 raeburn 3444: sub modify_usermodification {
3445: my ($dom,%domconfig) = @_;
3446: my ($resulttext,%curr_usermodification,%changes);
3447: if (ref($domconfig{'usermodification'}) eq 'HASH') {
3448: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
3449: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
3450: }
3451: }
3452: my @contexts = ('author','course');
3453: my %context_title = (
3454: author => 'In author context',
3455: course => 'In course context',
3456: );
3457: my @fields = ('lastname','firstname','middlename','generation',
3458: 'permanentemail','id');
3459: my %roles = (
3460: author => ['ca','aa'],
3461: course => ['st','ep','ta','in','cr'],
3462: );
3463: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3464: my %modifyhash;
3465: foreach my $context (@contexts) {
3466: foreach my $role (@{$roles{$context}}) {
3467: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
3468: foreach my $item (@fields) {
3469: if (grep(/^\Q$item\E$/,@modifiable)) {
3470: $modifyhash{$context}{$role}{$item} = 1;
3471: } else {
3472: $modifyhash{$context}{$role}{$item} = 0;
3473: }
3474: }
3475: }
3476: if (ref($curr_usermodification{$context}) eq 'HASH') {
3477: foreach my $role (@{$roles{$context}}) {
3478: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
3479: foreach my $field (@fields) {
3480: if ($modifyhash{$context}{$role}{$field} ne
3481: $curr_usermodification{$context}{$role}{$field}) {
3482: push(@{$changes{$context}},$role);
3483: last;
3484: }
3485: }
3486: }
3487: }
3488: } else {
3489: foreach my $context (@contexts) {
3490: foreach my $role (@{$roles{$context}}) {
3491: push(@{$changes{$context}},$role);
3492: }
3493: }
3494: }
3495: }
3496: my %usermodification_hash = (
3497: usermodification => \%modifyhash,
3498: );
3499: my $putresult = &Apache::lonnet::put_dom('configuration',
3500: \%usermodification_hash,$dom);
3501: if ($putresult eq 'ok') {
3502: if (keys(%changes) > 0) {
3503: $resulttext = &mt('Changes made: ').'<ul>';
3504: foreach my $context (@contexts) {
3505: if (ref($changes{$context}) eq 'ARRAY') {
3506: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
3507: if (ref($changes{$context}) eq 'ARRAY') {
3508: foreach my $role (@{$changes{$context}}) {
3509: my $rolename;
3510: if ($role eq 'cr') {
3511: $rolename = &mt('Custom');
3512: } else {
3513: $rolename = &Apache::lonnet::plaintext($role);
3514: }
3515: my @modifiable;
3516: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
3517: foreach my $field (@fields) {
3518: if ($modifyhash{$context}{$role}{$field}) {
3519: push(@modifiable,$fieldtitles{$field});
3520: }
3521: }
3522: if (@modifiable > 0) {
3523: $resulttext .= join(', ',@modifiable);
3524: } else {
3525: $resulttext .= &mt('none');
3526: }
3527: $resulttext .= '</li>';
3528: }
3529: $resulttext .= '</ul></li>';
3530: }
3531: }
3532: }
3533: $resulttext .= '</ul>';
3534: } else {
3535: $resulttext = &mt('No changes made to user modification settings');
3536: }
3537: } else {
3538: $resulttext = '<span class="LC_error">'.
3539: &mt('An error occurred: [_1]',$putresult).'</span>';
3540: }
3541: return $resulttext;
3542: }
3543:
1.43 ! raeburn 3544: sub modify_defaults {
! 3545: my ($dom,$r) = @_;
! 3546: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
! 3547: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
! 3548: my @items = ('auth_def','auth_arg_def','lang_def');
! 3549: my @authtypes = ('internal','krb4','krb5','localauth');
! 3550: foreach my $item (@items) {
! 3551: $newvalues{$item} = $env{'form.'.$item};
! 3552: if ($item eq 'auth_def') {
! 3553: if ($newvalues{$item} ne '') {
! 3554: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
! 3555: push(@errors,$item);
! 3556: }
! 3557: }
! 3558: } elsif ($item eq 'lang_def') {
! 3559: if ($newvalues{$item} ne '') {
! 3560: if ($newvalues{$item} =~ /^(\w+)/) {
! 3561: my $langcode = $1;
! 3562: if (code2language($langcode) eq '') {
! 3563: push(@errors,$item);
! 3564: }
! 3565: } else {
! 3566: push(@errors,$item);
! 3567: }
! 3568: }
! 3569: }
! 3570: if (grep(/^\Q$item\E$/,@errors)) {
! 3571: $newvalues{$item} = $domdefaults{$item};
! 3572: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
! 3573: $changes{$item} = 1;
! 3574: }
! 3575: }
! 3576: my %defaults_hash = (
! 3577: defaults => { auth_def => $newvalues{'auth_def'},
! 3578: auth_arg_def => $newvalues{'auth_arg_def'},
! 3579: lang_def => $newvalues{'lang_def'},
! 3580: }
! 3581: );
! 3582: my $title = &defaults_titles();
! 3583: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
! 3584: $dom);
! 3585: if ($putresult eq 'ok') {
! 3586: if (keys(%changes) > 0) {
! 3587: $resulttext = &mt('Changes made:').'<ul>';
! 3588: my $version = $r->dir_config('lonVersion');
! 3589: my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
! 3590: foreach my $item (sort(keys(%changes))) {
! 3591: my $value = $env{'form.'.$item};
! 3592: if ($value eq '') {
! 3593: $value = &mt('none');
! 3594: } elsif ($item eq 'auth_def') {
! 3595: my %authnames = &authtype_names();
! 3596: my %shortauth = (
! 3597: internal => 'int',
! 3598: krb4 => 'krb4',
! 3599: krb5 => 'krb5',
! 3600: localauth => 'loc',
! 3601: );
! 3602: $value = $authnames{$shortauth{$value}};
! 3603: }
! 3604: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
! 3605: $mailmsgtext .= "$title->{$item} set to $value\n";
! 3606: }
! 3607: $resulttext .= '</ul>';
! 3608: $mailmsgtext .= "\n";
! 3609: my $cachetime = 24*60*60;
! 3610: &Apache::lonnet::do_cache_new('domdefaults',$dom,
! 3611: $defaults_hash{'defaults'},$cachetime);
! 3612: my $sysmail = $r->dir_config('lonSysEMail');
! 3613: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
! 3614: } else {
! 3615: $resulttext = &mt('No changes made to default authentication/language settings');
! 3616: }
! 3617: } else {
! 3618: $resulttext = '<span class="LC_error">'.
! 3619: &mt('An error occurred: [_1]',$putresult).'</span>';
! 3620: }
! 3621: if (@errors > 0) {
! 3622: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
! 3623: foreach my $item (@errors) {
! 3624: $resulttext .= ' "'.$title->{$item}.'",';
! 3625: }
! 3626: $resulttext =~ s/,$//;
! 3627: }
! 3628: return $resulttext;
! 3629: }
! 3630:
1.3 raeburn 3631: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>