Annotation of loncom/interface/domainprefs.pm, revision 1.44
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.44 ! raeburn 4: # $Id: domainprefs.pm,v 1.43 2008/02/24 23:18:40 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.44 ! raeburn 1113: my ($othertitle,$usertypes,$types) = &Apache::loncommon::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.44 ! raeburn 1243: my ($othertitle,$usertypes,$types) = &Apache::loncommon::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();
1.44 ! raeburn 1303: my ($othertitle,$usertypes,$types) = &Apache::Loncommon::sorted_inst_types($dom);
1.23 raeburn 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_searchtitles {
1910: my %searchtitles = &Apache::lonlocal::texthash(
1911: 'uname' => 'username',
1912: 'lastname' => 'last name',
1913: 'lastfirst' => 'last name, first name',
1914: );
1915: my @titleorder = ('uname','lastname','lastfirst');
1916: return (\%searchtitles,\@titleorder);
1917: }
1918:
1.25 raeburn 1919: sub sorted_searchtypes {
1920: my %srchtypes_desc = (
1921: exact => 'is exact match',
1922: contains => 'contains ..',
1923: begins => 'begins with ..',
1924: );
1925: my @srchtypeorder = ('exact','begins','contains');
1926: return (\%srchtypes_desc,\@srchtypeorder);
1927: }
1928:
1.3 raeburn 1929: sub usertype_update_row {
1930: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
1931: my $datatable;
1932: my $numinrow = 4;
1933: foreach my $type (@{$types}) {
1934: if (defined($usertypes->{$type})) {
1935: $$rownums ++;
1936: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
1937: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
1938: '</td><td class="LC_left_item"><table>';
1939: for (my $i=0; $i<@{$fields}; $i++) {
1940: my $rem = $i%($numinrow);
1941: if ($rem == 0) {
1942: if ($i > 0) {
1943: $datatable .= '</tr>';
1944: }
1945: $datatable .= '<tr>';
1946: }
1947: my $check = ' ';
1.39 raeburn 1948: if (ref($settings) eq 'HASH') {
1949: if (ref($settings->{'fields'}) eq 'HASH') {
1950: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
1951: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
1952: $check = ' checked="checked" ';
1953: }
1.3 raeburn 1954: }
1955: }
1956: }
1957:
1958: if ($i == @{$fields}-1) {
1959: my $colsleft = $numinrow - $rem;
1960: if ($colsleft > 1) {
1961: $datatable .= '<td colspan="'.$colsleft.'">';
1962: } else {
1963: $datatable .= '<td>';
1964: }
1965: } else {
1966: $datatable .= '<td>';
1967: }
1.8 raeburn 1968: $datatable .= '<span class="LC_nobreak"><label>'.
1969: '<input type="checkbox" name="updateable_'.$type.
1970: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
1971: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 1972: }
1973: $datatable .= '</tr></table></td></tr>';
1974: }
1975: }
1976: return $datatable;
1.1 raeburn 1977: }
1978:
1979: sub modify_login {
1.9 raeburn 1980: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 1981: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 1982: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 1983: adminmail => 'Display administrator E-mail address',
1.43 raeburn 1984: newuser => 'Link for visitors to create a user account',
1.41 raeburn 1985: loginheader => 'Log-in box header');
1.3 raeburn 1986: my @offon = ('off','on');
1.6 raeburn 1987: my %loginhash;
1.9 raeburn 1988: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
1989: \%domconfig,\%loginhash);
1.43 raeburn 1990: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 1991: foreach my $item (@toggles) {
1992: $loginhash{login}{$item} = $env{'form.'.$item};
1993: }
1.41 raeburn 1994: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 1995: if (ref($colchanges{'login'}) eq 'HASH') {
1996: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
1997: \%loginhash);
1998: }
1.1 raeburn 1999: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
2000: $dom);
2001: if ($putresult eq 'ok') {
1.43 raeburn 2002: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2003: my %defaultchecked = (
2004: 'coursecatalog' => 'on',
2005: 'adminmail' => 'off',
1.43 raeburn 2006: 'newuser' => 'off',
1.42 raeburn 2007: );
2008: foreach my $item (@toggles) {
2009: if ($defaultchecked{$item} eq 'on') {
2010: if (($domconfig{'login'}{$item} eq '0') &&
2011: ($env{'form.'.$item} eq '1')) {
2012: $changes{$item} = 1;
2013: } elsif (($domconfig{'login'}{$item} eq '' ||
2014: $domconfig{'login'}{$item} eq '1') &&
2015: ($env{'form.'.$item} eq '0')) {
2016: $changes{$item} = 1;
2017: }
2018: } elsif ($defaultchecked{$item} eq 'off') {
2019: if (($domconfig{'login'}{$item} eq '1') &&
2020: ($env{'form.'.$item} eq '0')) {
2021: $changes{$item} = 1;
2022: } elsif (($domconfig{'login'}{$item} eq '' ||
2023: $domconfig{'login'}{$item} eq '0') &&
2024: ($env{'form.'.$item} eq '1')) {
2025: $changes{$item} = 1;
2026: }
2027: }
1.1 raeburn 2028: }
1.41 raeburn 2029: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
2030: ($env{'form.loginheader'} eq 'image')) {
2031: $changes{'loginheader'} = 1;
2032: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
2033: $domconfig{'login'}{'loginheader'} eq 'image') &&
2034: ($env{'form.loginheader'} eq 'text')) {
2035: $changes{'loginheader'} = 1;
2036: }
1.6 raeburn 2037: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 2038: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 2039: $resulttext = &mt('Changes made:').'<ul>';
2040: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 2041: if ($item eq 'loginheader') {
2042: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
2043: } else {
2044: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
2045: }
1.1 raeburn 2046: }
1.6 raeburn 2047: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 2048: } else {
2049: $resulttext = &mt('No changes made to log-in page settings');
2050: }
2051: } else {
1.11 albertel 2052: $resulttext = '<span class="LC_error">'.
2053: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2054: }
1.6 raeburn 2055: if ($errors) {
1.9 raeburn 2056: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 2057: $errors.'</ul>';
2058: }
2059: return $resulttext;
2060: }
2061:
2062: sub color_font_choices {
2063: my %choices =
2064: &Apache::lonlocal::texthash (
2065: img => "Header",
2066: bgs => "Background colors",
2067: links => "Link colors",
2068: font => "Font color",
2069: pgbg => "Page",
2070: tabbg => "Header",
2071: sidebg => "Border",
2072: link => "Link",
2073: alink => "Active link",
2074: vlink => "Visited link",
2075: );
2076: return %choices;
2077: }
2078:
2079: sub modify_rolecolors {
1.9 raeburn 2080: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 2081: my ($resulttext,%rolehash);
2082: $rolehash{'rolecolors'} = {};
1.9 raeburn 2083: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 2084: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
2085: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
2086: $dom);
2087: if ($putresult eq 'ok') {
2088: if (keys(%changes) > 0) {
1.41 raeburn 2089: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 2090: $resulttext = &display_colorchgs($dom,\%changes,$roles,
2091: $rolehash{'rolecolors'});
2092: } else {
2093: $resulttext = &mt('No changes made to default color schemes');
2094: }
2095: } else {
1.11 albertel 2096: $resulttext = '<span class="LC_error">'.
2097: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 2098: }
2099: if ($errors) {
2100: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
2101: $errors.'</ul>';
2102: }
2103: return $resulttext;
2104: }
2105:
2106: sub modify_colors {
1.9 raeburn 2107: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 2108: my (%changes,%choices);
1.6 raeburn 2109: my @bgs = ('pgbg','mainbg','sidebg');
2110: my @links = ('link','alink','vlink');
1.41 raeburn 2111: my @logintext;
1.6 raeburn 2112: my @images;
2113: my $servadm = $r->dir_config('lonAdmEMail');
2114: my $errors;
2115: foreach my $role (@{$roles}) {
2116: if ($role eq 'login') {
1.12 raeburn 2117: %choices = &login_choices();
1.41 raeburn 2118: @logintext = ('textcol','bgcol');
1.12 raeburn 2119: } else {
2120: %choices = &color_font_choices();
2121: }
2122: if ($role eq 'login') {
1.41 raeburn 2123: @images = ('img','logo','domlogo','login');
1.6 raeburn 2124: } else {
2125: @images = ('img');
2126: }
2127: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 2128: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 2129: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
2130: }
1.9 raeburn 2131: my ($configuserok,$author_ok,$switchserver,%currroles);
2132: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
2133: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
2134: $confname,$servadm);
2135: if ($configuserok eq 'ok') {
2136: $switchserver = &check_switchserver($dom,$confname);
2137: if ($switchserver eq '') {
2138: $author_ok = &check_authorstatus($dom,$confname,%currroles);
2139: }
2140: }
2141: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 2142: if (ref($domconfig->{$role}) ne 'HASH') {
2143: $domconfig->{$role} = {};
2144: }
1.8 raeburn 2145: foreach my $img (@images) {
1.18 albertel 2146: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
2147: && !defined($domconfig->{$role}{$img})
2148: && !$env{'form.'.$role.'_del_'.$img}
2149: && $env{'form.'.$role.'_import_'.$img}) {
2150: # import the old configured image from the .tab setting
2151: # if they haven't provided a new one
2152: $domconfig->{$role}{$img} =
2153: $env{'form.'.$role.'_import_'.$img};
2154: }
1.6 raeburn 2155: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 2156: my $error;
1.6 raeburn 2157: if ($configuserok eq 'ok') {
1.9 raeburn 2158: if ($switchserver) {
1.12 raeburn 2159: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 2160: } else {
2161: if ($author_ok eq 'ok') {
2162: my ($result,$logourl) =
2163: &publishlogo($r,'upload',$role.'_'.$img,
2164: $dom,$confname,$img,$width,$height);
2165: if ($result eq 'ok') {
2166: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 2167: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2168: } else {
1.12 raeburn 2169: $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 2170: }
2171: } else {
1.12 raeburn 2172: $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 2173: }
2174: }
2175: } else {
1.12 raeburn 2176: $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 2177: }
2178: if ($error) {
1.8 raeburn 2179: &Apache::lonnet::logthis($error);
1.11 albertel 2180: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 2181: }
2182: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 2183: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
2184: my $error;
2185: if ($configuserok eq 'ok') {
2186: # is confname an author?
2187: if ($switchserver eq '') {
2188: if ($author_ok eq 'ok') {
2189: my ($result,$logourl) =
2190: &publishlogo($r,'copy',$domconfig->{$role}{$img},
2191: $dom,$confname,$img,$width,$height);
2192: if ($result eq 'ok') {
2193: $confhash->{$role}{$img} = $logourl;
1.18 albertel 2194: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2195: }
2196: }
2197: }
2198: }
1.6 raeburn 2199: }
2200: }
2201: }
2202: if (ref($domconfig) eq 'HASH') {
2203: if (ref($domconfig->{$role}) eq 'HASH') {
2204: foreach my $img (@images) {
2205: if ($domconfig->{$role}{$img} ne '') {
2206: if ($env{'form.'.$role.'_del_'.$img}) {
2207: $confhash->{$role}{$img} = '';
1.12 raeburn 2208: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2209: } else {
1.9 raeburn 2210: if ($confhash->{$role}{$img} eq '') {
2211: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
2212: }
1.6 raeburn 2213: }
2214: } else {
2215: if ($env{'form.'.$role.'_del_'.$img}) {
2216: $confhash->{$role}{$img} = '';
1.12 raeburn 2217: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2218: }
2219: }
2220: }
2221: if ($domconfig->{$role}{'font'} ne '') {
2222: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
2223: $changes{$role}{'font'} = 1;
2224: }
2225: } else {
2226: if ($confhash->{$role}{'font'}) {
2227: $changes{$role}{'font'} = 1;
2228: }
2229: }
2230: foreach my $item (@bgs) {
2231: if ($domconfig->{$role}{$item} ne '') {
2232: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2233: $changes{$role}{'bgs'}{$item} = 1;
2234: }
2235: } else {
2236: if ($confhash->{$role}{$item}) {
2237: $changes{$role}{'bgs'}{$item} = 1;
2238: }
2239: }
2240: }
2241: foreach my $item (@links) {
2242: if ($domconfig->{$role}{$item} ne '') {
2243: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2244: $changes{$role}{'links'}{$item} = 1;
2245: }
2246: } else {
2247: if ($confhash->{$role}{$item}) {
2248: $changes{$role}{'links'}{$item} = 1;
2249: }
2250: }
2251: }
1.41 raeburn 2252: foreach my $item (@logintext) {
2253: if ($domconfig->{$role}{$item} ne '') {
2254: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2255: $changes{$role}{'logintext'}{$item} = 1;
2256: }
2257: } else {
2258: if ($confhash->{$role}{$item}) {
2259: $changes{$role}{'logintext'}{$item} = 1;
2260: }
2261: }
2262: }
1.6 raeburn 2263: } else {
2264: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2265: \@logintext,$confhash,\%changes);
1.6 raeburn 2266: }
2267: } else {
2268: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2269: \@logintext,$confhash,\%changes);
1.6 raeburn 2270: }
2271: }
2272: return ($errors,%changes);
2273: }
2274:
2275: sub default_change_checker {
1.41 raeburn 2276: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 2277: foreach my $item (@{$links}) {
2278: if ($confhash->{$role}{$item}) {
2279: $changes->{$role}{'links'}{$item} = 1;
2280: }
2281: }
2282: foreach my $item (@{$bgs}) {
2283: if ($confhash->{$role}{$item}) {
2284: $changes->{$role}{'bgs'}{$item} = 1;
2285: }
2286: }
1.41 raeburn 2287: foreach my $item (@{$logintext}) {
2288: if ($confhash->{$role}{$item}) {
2289: $changes->{$role}{'logintext'}{$item} = 1;
2290: }
2291: }
1.6 raeburn 2292: foreach my $img (@{$images}) {
2293: if ($env{'form.'.$role.'_del_'.$img}) {
2294: $confhash->{$role}{$img} = '';
1.12 raeburn 2295: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 2296: }
2297: }
2298: if ($confhash->{$role}{'font'}) {
2299: $changes->{$role}{'font'} = 1;
2300: }
2301: }
2302:
2303: sub display_colorchgs {
2304: my ($dom,$changes,$roles,$confhash) = @_;
2305: my (%choices,$resulttext);
2306: if (!grep(/^login$/,@{$roles})) {
2307: $resulttext = &mt('Changes made:').'<br />';
2308: }
2309: foreach my $role (@{$roles}) {
2310: if ($role eq 'login') {
2311: %choices = &login_choices();
2312: } else {
2313: %choices = &color_font_choices();
2314: }
2315: if (ref($changes->{$role}) eq 'HASH') {
2316: if ($role ne 'login') {
2317: $resulttext .= '<h4>'.&mt($role).'</h4>';
2318: }
2319: foreach my $key (sort(keys(%{$changes->{$role}}))) {
2320: if ($role ne 'login') {
2321: $resulttext .= '<ul>';
2322: }
2323: if (ref($changes->{$role}{$key}) eq 'HASH') {
2324: if ($role ne 'login') {
2325: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
2326: }
2327: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
2328: if ($confhash->{$role}{$item} eq '') {
2329: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
2330: } else {
1.12 raeburn 2331: my $newitem = $confhash->{$role}{$item};
2332: if ($key eq 'images') {
2333: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
2334: }
2335: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 2336: }
2337: }
2338: if ($role ne 'login') {
2339: $resulttext .= '</ul></li>';
2340: }
2341: } else {
2342: if ($confhash->{$role}{$key} eq '') {
2343: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
2344: } else {
2345: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
2346: }
2347: }
2348: if ($role ne 'login') {
2349: $resulttext .= '</ul>';
2350: }
2351: }
2352: }
2353: }
1.3 raeburn 2354: return $resulttext;
1.1 raeburn 2355: }
2356:
1.9 raeburn 2357: sub thumb_dimensions {
2358: return ('200','50');
2359: }
2360:
1.16 raeburn 2361: sub check_dimensions {
2362: my ($inputfile) = @_;
2363: my ($fullwidth,$fullheight);
2364: if ($inputfile =~ m|^[/\w.\-]+$|) {
2365: if (open(PIPE,"identify $inputfile 2>&1 |")) {
2366: my $imageinfo = <PIPE>;
2367: if (!close(PIPE)) {
2368: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
2369: }
2370: chomp($imageinfo);
2371: my ($fullsize) =
1.21 raeburn 2372: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 2373: if ($fullsize) {
2374: ($fullwidth,$fullheight) = split(/x/,$fullsize);
2375: }
2376: }
2377: }
2378: return ($fullwidth,$fullheight);
2379: }
2380:
1.9 raeburn 2381: sub check_configuser {
2382: my ($uhome,$dom,$confname,$servadm) = @_;
2383: my ($configuserok,%currroles);
2384: if ($uhome eq 'no_host') {
2385: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
2386: my $configpass = &LONCAPA::Enrollment::create_password();
2387: $configuserok =
2388: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
2389: $configpass,'','','','','',undef,$servadm);
2390: } else {
2391: $configuserok = 'ok';
2392: %currroles =
2393: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
2394: }
2395: return ($configuserok,%currroles);
2396: }
2397:
2398: sub check_authorstatus {
2399: my ($dom,$confname,%currroles) = @_;
2400: my $author_ok;
1.40 raeburn 2401: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 2402: my $start = time;
2403: my $end = 0;
2404: $author_ok =
2405: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
2406: 'au',$end,$start);
2407: } else {
2408: $author_ok = 'ok';
2409: }
2410: return $author_ok;
2411: }
2412:
2413: sub publishlogo {
2414: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
2415: my ($output,$fname,$logourl);
2416: if ($action eq 'upload') {
2417: $fname=$env{'form.'.$formname.'.filename'};
2418: chop($env{'form.'.$formname});
2419: } else {
2420: ($fname) = ($formname =~ /([^\/]+)$/);
2421: }
2422: $fname=&Apache::lonnet::clean_filename($fname);
2423: # See if there is anything left
2424: unless ($fname) { return ('error: no uploaded file'); }
2425: $fname="$subdir/$fname";
2426: my $filepath='/home/'.$confname.'/public_html';
2427: my ($fnamepath,$file,$fetchthumb);
2428: $file=$fname;
2429: if ($fname=~m|/|) {
2430: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
2431: }
2432: my @parts=split(/\//,$filepath.'/'.$fnamepath);
2433: my $count;
2434: for ($count=4;$count<=$#parts;$count++) {
2435: $filepath.="/$parts[$count]";
2436: if ((-e $filepath)!=1) {
2437: mkdir($filepath,02770);
2438: }
2439: }
2440: # Check for bad extension and disallow upload
2441: if ($file=~/\.(\w+)$/ &&
2442: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
2443: $output =
2444: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
2445: } elsif ($file=~/\.(\w+)$/ &&
2446: !defined(&Apache::loncommon::fileembstyle($1))) {
2447: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
2448: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
2449: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
2450: } elsif (-d "$filepath/$file") {
2451: $output = &mt('File name is a directory name - rename the file and re-upload');
2452: } else {
2453: my $source = $filepath.'/'.$file;
2454: my $logfile;
2455: if (!open($logfile,">>$source".'.log')) {
2456: return (&mt('No write permission to Construction Space'));
2457: }
2458: print $logfile
2459: "\n================= Publish ".localtime()." ================\n".
2460: $env{'user.name'}.':'.$env{'user.domain'}."\n";
2461: # Save the file
2462: if (!open(FH,'>'.$source)) {
2463: &Apache::lonnet::logthis('Failed to create '.$source);
2464: return (&mt('Failed to create file'));
2465: }
2466: if ($action eq 'upload') {
2467: if (!print FH ($env{'form.'.$formname})) {
2468: &Apache::lonnet::logthis('Failed to write to '.$source);
2469: return (&mt('Failed to write file'));
2470: }
2471: } else {
2472: my $original = &Apache::lonnet::filelocation('',$formname);
2473: if(!copy($original,$source)) {
2474: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
2475: return (&mt('Failed to write file'));
2476: }
2477: }
2478: close(FH);
2479: chmod(0660, $source); # Permissions to rw-rw---.
2480:
2481: my $docroot=$r->dir_config('lonDocRoot');
2482: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
2483: my $copyfile=$targetdir.'/'.$file;
2484:
2485: my @parts=split(/\//,$targetdir);
2486: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
2487: for (my $count=5;$count<=$#parts;$count++) {
2488: $path.="/$parts[$count]";
2489: if (!-e $path) {
2490: print $logfile "\nCreating directory ".$path;
2491: mkdir($path,02770);
2492: }
2493: }
2494: my $versionresult;
2495: if (-e $copyfile) {
2496: $versionresult = &logo_versioning($targetdir,$file,$logfile);
2497: } else {
2498: $versionresult = 'ok';
2499: }
2500: if ($versionresult eq 'ok') {
2501: if (copy($source,$copyfile)) {
2502: print $logfile "\nCopied original source to ".$copyfile."\n";
2503: $output = 'ok';
2504: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
2505: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
2506: } else {
2507: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
2508: $output = &mt('Failed to copy file to RES space').", $!";
2509: }
2510: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
2511: my $inputfile = $filepath.'/'.$file;
2512: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 2513: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
2514: if ($fullwidth ne '' && $fullheight ne '') {
2515: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
2516: my $thumbsize = $thumbwidth.'x'.$thumbheight;
2517: system("convert -sample $thumbsize $inputfile $outfile");
2518: chmod(0660, $filepath.'/tn-'.$file);
2519: if (-e $outfile) {
2520: my $copyfile=$targetdir.'/tn-'.$file;
2521: if (copy($outfile,$copyfile)) {
2522: print $logfile "\nCopied source to ".$copyfile."\n";
2523: &write_metadata($dom,$confname,$formname,
2524: $targetdir,'tn-'.$file,$logfile);
2525: } else {
2526: print $logfile "\nUnable to write ".$copyfile.
2527: ':'.$!."\n";
2528: }
2529: }
1.9 raeburn 2530: }
2531: }
2532: }
2533: } else {
2534: $output = $versionresult;
2535: }
2536: }
2537: return ($output,$logourl);
2538: }
2539:
2540: sub logo_versioning {
2541: my ($targetdir,$file,$logfile) = @_;
2542: my $target = $targetdir.'/'.$file;
2543: my ($maxversion,$fn,$extn,$output);
2544: $maxversion = 0;
2545: if ($file =~ /^(.+)\.(\w+)$/) {
2546: $fn=$1;
2547: $extn=$2;
2548: }
2549: opendir(DIR,$targetdir);
2550: while (my $filename=readdir(DIR)) {
2551: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
2552: $maxversion=($1>$maxversion)?$1:$maxversion;
2553: }
2554: }
2555: $maxversion++;
2556: print $logfile "\nCreating old version ".$maxversion."\n";
2557: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
2558: if (copy($target,$copyfile)) {
2559: print $logfile "Copied old target to ".$copyfile."\n";
2560: $copyfile=$copyfile.'.meta';
2561: if (copy($target.'.meta',$copyfile)) {
2562: print $logfile "Copied old target metadata to ".$copyfile."\n";
2563: $output = 'ok';
2564: } else {
2565: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
2566: $output = &mt('Failed to copy old meta').", $!, ";
2567: }
2568: } else {
2569: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
2570: $output = &mt('Failed to copy old target').", $!, ";
2571: }
2572: return $output;
2573: }
2574:
2575: sub write_metadata {
2576: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
2577: my (%metadatafields,%metadatakeys,$output);
2578: $metadatafields{'title'}=$formname;
2579: $metadatafields{'creationdate'}=time;
2580: $metadatafields{'lastrevisiondate'}=time;
2581: $metadatafields{'copyright'}='public';
2582: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
2583: $env{'user.domain'};
2584: $metadatafields{'authorspace'}=$confname.':'.$dom;
2585: $metadatafields{'domain'}=$dom;
2586: {
2587: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
2588: my $mfh;
2589: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
2590: $output = &mt('Could not write metadata');
2591: }
2592: foreach (sort keys %metadatafields) {
2593: unless ($_=~/\./) {
2594: my $unikey=$_;
2595: $unikey=~/^([A-Za-z]+)/;
2596: my $tag=$1;
2597: $tag=~tr/A-Z/a-z/;
2598: print $mfh "\n\<$tag";
2599: foreach (split(/\,/,$metadatakeys{$unikey})) {
2600: my $value=$metadatafields{$unikey.'.'.$_};
2601: $value=~s/\"/\'\'/g;
2602: print $mfh ' '.$_.'="'.$value.'"';
2603: }
2604: print $mfh '>'.
2605: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
2606: .'</'.$tag.'>';
2607: }
2608: }
2609: $output = 'ok';
2610: print $logfile "\nWrote metadata";
2611: close($mfh);
2612: }
2613: }
2614:
2615: sub check_switchserver {
2616: my ($dom,$confname) = @_;
2617: my ($allowed,$switchserver);
2618: my $home = &Apache::lonnet::homeserver($confname,$dom);
2619: if ($home eq 'no_host') {
2620: $home = &Apache::lonnet::domain($dom,'primary');
2621: }
2622: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 2623: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2624: if (!$allowed) {
2625: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 2626: }
2627: return $switchserver;
2628: }
2629:
1.30 raeburn 2630: sub javascript_set_colnums {
2631: return <<END;
2632: function setDisplayColumns() {
2633: if (document.pickactions.width.value > 1100) {
2634: document.pickactions.numcols[1].checked = true;
2635: } else {
2636: document.pickactions.numcols[0].checked = true;
2637: }
2638: }
2639: END
2640: }
2641:
1.1 raeburn 2642: sub modify_quotas {
1.3 raeburn 2643: my ($dom,%domconfig) = @_;
1.1 raeburn 2644: my ($resulttext,%changes);
1.44 ! raeburn 2645: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 2646: my %formhash;
2647: foreach my $key (keys(%env)) {
2648: if ($key =~ /^form\.quota_(.+)$/) {
2649: $formhash{$1} = $env{$key};
2650: }
2651: }
1.15 raeburn 2652: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 2653: if (ref($domconfig{'quotas'}) eq 'HASH') {
2654: foreach my $key (keys(%{$domconfig{'quotas'}})) {
2655: if (exists($formhash{$key})) {
2656: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
2657: $changes{$key} = 1;
2658: }
2659: } else {
2660: $formhash{$key} = $domconfig{'quotas'}{$key};
2661: }
2662: }
2663: }
2664: foreach my $key (keys(%formhash)) {
2665: if ($formhash{$key} ne '') {
1.3 raeburn 2666: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 2667: $changes{$key} = 1;
2668: }
2669: }
2670: }
2671: my %quotahash = (
1.3 raeburn 2672: quotas => {%formhash},
1.1 raeburn 2673: );
2674: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
2675: $dom);
2676: if ($putresult eq 'ok') {
2677: if (keys(%changes) > 0) {
2678: $resulttext = &mt('Changes made:').'<ul>';
1.26 raeburn 2679: foreach my $type (@{$types},'default') {
2680: if (defined($changes{$type})) {
2681: my $typetitle = $usertypes->{$type};
2682: if ($type eq 'default') {
2683: $typetitle = $othertitle;
2684: }
2685: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
2686: }
1.1 raeburn 2687: }
2688: $resulttext .= '</ul>';
2689: } else {
2690: $resulttext = &mt('No changes made to default quotas');
2691: }
2692: } else {
1.11 albertel 2693: $resulttext = '<span class="LC_error">'.
2694: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2695: }
1.3 raeburn 2696: return $resulttext;
1.1 raeburn 2697: }
2698:
1.3 raeburn 2699: sub modify_autoenroll {
2700: my ($dom,%domconfig) = @_;
1.1 raeburn 2701: my ($resulttext,%changes);
2702: my %currautoenroll;
2703: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
2704: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
2705: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
2706: }
2707: }
2708: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2709: my %title = ( run => 'Auto-enrollment active',
2710: sender => 'Sender for notification messages');
2711: my @offon = ('off','on');
1.17 raeburn 2712: my $sender_uname = $env{'form.sender_uname'};
2713: my $sender_domain = $env{'form.sender_domain'};
2714: if ($sender_domain eq '') {
2715: $sender_uname = '';
2716: } elsif ($sender_uname eq '') {
2717: $sender_domain = '';
2718: }
1.1 raeburn 2719: my %autoenrollhash = (
2720: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 2721: sender_uname => $sender_uname,
2722: sender_domain => $sender_domain,
1.1 raeburn 2723:
2724: }
2725: );
1.4 raeburn 2726: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
2727: $dom);
1.1 raeburn 2728: if ($putresult eq 'ok') {
2729: if (exists($currautoenroll{'run'})) {
2730: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
2731: $changes{'run'} = 1;
2732: }
2733: } elsif ($autorun) {
2734: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 2735: $changes{'run'} = 1;
1.1 raeburn 2736: }
2737: }
1.17 raeburn 2738: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 2739: $changes{'sender'} = 1;
2740: }
1.17 raeburn 2741: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 2742: $changes{'sender'} = 1;
2743: }
2744: if (keys(%changes) > 0) {
2745: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 2746: if ($changes{'run'}) {
1.1 raeburn 2747: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
2748: }
2749: if ($changes{'sender'}) {
1.17 raeburn 2750: if ($sender_uname eq '' || $sender_domain eq '') {
2751: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
2752: } else {
2753: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
2754: }
1.1 raeburn 2755: }
2756: $resulttext .= '</ul>';
2757: } else {
2758: $resulttext = &mt('No changes made to auto-enrollment settings');
2759: }
2760: } else {
1.11 albertel 2761: $resulttext = '<span class="LC_error">'.
2762: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2763: }
1.3 raeburn 2764: return $resulttext;
1.1 raeburn 2765: }
2766:
2767: sub modify_autoupdate {
1.3 raeburn 2768: my ($dom,%domconfig) = @_;
1.1 raeburn 2769: my ($resulttext,%currautoupdate,%fields,%changes);
2770: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
2771: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
2772: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
2773: }
2774: }
2775: my @offon = ('off','on');
2776: my %title = &Apache::lonlocal::texthash (
2777: run => 'Auto-update:',
2778: classlists => 'Updates to user information in classlists?'
2779: );
1.44 ! raeburn 2780: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 2781: my %fieldtitles = &Apache::lonlocal::texthash (
2782: id => 'Student/Employee ID',
1.20 raeburn 2783: permanentemail => 'E-mail address',
1.1 raeburn 2784: lastname => 'Last Name',
2785: firstname => 'First Name',
2786: middlename => 'Middle Name',
2787: gen => 'Generation',
2788: );
2789: my $othertitle = &mt('All users');
2790: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 2791: $othertitle = &mt('Other users');
1.1 raeburn 2792: }
2793: foreach my $key (keys(%env)) {
2794: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
2795: push(@{$fields{$1}},$2);
2796: }
2797: }
2798: my %updatehash = (
2799: autoupdate => { run => $env{'form.autoupdate_run'},
2800: classlists => $env{'form.classlists'},
2801: fields => {%fields},
2802: }
2803: );
2804: foreach my $key (keys(%currautoupdate)) {
2805: if (($key eq 'run') || ($key eq 'classlists')) {
2806: if (exists($updatehash{autoupdate}{$key})) {
2807: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
2808: $changes{$key} = 1;
2809: }
2810: }
2811: } elsif ($key eq 'fields') {
2812: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 2813: foreach my $item (@{$types},'default') {
1.1 raeburn 2814: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
2815: my $change = 0;
2816: foreach my $type (@{$currautoupdate{$key}{$item}}) {
2817: if (!exists($fields{$item})) {
2818: $change = 1;
2819: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 2820: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 2821: $change = 1;
2822: }
2823: }
2824: }
2825: if ($change) {
2826: push(@{$changes{$key}},$item);
2827: }
1.26 raeburn 2828: }
1.1 raeburn 2829: }
2830: }
2831: }
2832: }
1.26 raeburn 2833: foreach my $item (@{$types},'default') {
2834: if (defined($fields{$item})) {
2835: if (ref($currautoupdate{'fields'}) eq 'HASH') {
2836: if (!exists($currautoupdate{'fields'}{$item})) {
2837: push(@{$changes{'fields'}},$item);
2838: }
2839: } else {
2840: push(@{$changes{'fields'}},$item);
1.1 raeburn 2841: }
2842: }
2843: }
2844: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
2845: $dom);
2846: if ($putresult eq 'ok') {
2847: if (keys(%changes) > 0) {
2848: $resulttext = &mt('Changes made:').'<ul>';
2849: foreach my $key (sort(keys(%changes))) {
2850: if (ref($changes{$key}) eq 'ARRAY') {
2851: foreach my $item (@{$changes{$key}}) {
2852: my @newvalues;
2853: foreach my $type (@{$fields{$item}}) {
2854: push(@newvalues,$fieldtitles{$type});
2855: }
1.3 raeburn 2856: my $newvaluestr;
2857: if (@newvalues > 0) {
2858: $newvaluestr = join(', ',@newvalues);
2859: } else {
2860: $newvaluestr = &mt('none');
1.6 raeburn 2861: }
1.1 raeburn 2862: if ($item eq 'default') {
1.26 raeburn 2863: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 2864: } else {
1.26 raeburn 2865: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 2866: }
2867: }
2868: } else {
2869: my $newvalue;
2870: if ($key eq 'run') {
2871: $newvalue = $offon[$env{'form.autoupdate_run'}];
2872: } else {
2873: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 2874: }
1.1 raeburn 2875: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
2876: }
2877: }
2878: $resulttext .= '</ul>';
2879: } else {
1.3 raeburn 2880: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 2881: }
2882: } else {
1.11 albertel 2883: $resulttext = '<span class="LC_error">'.
2884: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2885: }
1.3 raeburn 2886: return $resulttext;
1.1 raeburn 2887: }
2888:
1.23 raeburn 2889: sub modify_directorysrch {
2890: my ($dom,%domconfig) = @_;
2891: my ($resulttext,%changes);
2892: my %currdirsrch;
2893: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2894: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
2895: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
2896: }
2897: }
2898: my %title = ( available => 'Directory search available',
1.24 raeburn 2899: localonly => 'Other domains can search',
1.23 raeburn 2900: searchby => 'Search types',
2901: searchtypes => 'Search latitude');
2902: my @offon = ('off','on');
1.24 raeburn 2903: my @otherdoms = ('Yes','No');
1.23 raeburn 2904:
1.25 raeburn 2905: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 2906: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
2907: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
2908:
1.44 ! raeburn 2909: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 2910: if (keys(%{$usertypes}) == 0) {
2911: @cansearch = ('default');
2912: } else {
2913: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
2914: foreach my $type (@{$currdirsrch{'cansearch'}}) {
2915: if (!grep(/^\Q$type\E$/,@cansearch)) {
2916: push(@{$changes{'cansearch'}},$type);
2917: }
1.23 raeburn 2918: }
1.26 raeburn 2919: foreach my $type (@cansearch) {
2920: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
2921: push(@{$changes{'cansearch'}},$type);
2922: }
1.23 raeburn 2923: }
1.26 raeburn 2924: } else {
2925: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 2926: }
2927: }
2928:
2929: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
2930: foreach my $by (@{$currdirsrch{'searchby'}}) {
2931: if (!grep(/^\Q$by\E$/,@searchby)) {
2932: push(@{$changes{'searchby'}},$by);
2933: }
2934: }
2935: foreach my $by (@searchby) {
2936: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
2937: push(@{$changes{'searchby'}},$by);
2938: }
2939: }
2940: } else {
2941: push(@{$changes{'searchby'}},@searchby);
2942: }
1.25 raeburn 2943:
2944: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
2945: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
2946: if (!grep(/^\Q$type\E$/,@searchtypes)) {
2947: push(@{$changes{'searchtypes'}},$type);
2948: }
2949: }
2950: foreach my $type (@searchtypes) {
2951: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
2952: push(@{$changes{'searchtypes'}},$type);
2953: }
2954: }
2955: } else {
2956: if (exists($currdirsrch{'searchtypes'})) {
2957: foreach my $type (@searchtypes) {
2958: if ($type ne $currdirsrch{'searchtypes'}) {
2959: push(@{$changes{'searchtypes'}},$type);
2960: }
2961: }
2962: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
2963: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
2964: }
2965: } else {
2966: push(@{$changes{'searchtypes'}},@searchtypes);
2967: }
2968: }
2969:
1.23 raeburn 2970: my %dirsrch_hash = (
2971: directorysrch => { available => $env{'form.dirsrch_available'},
2972: cansearch => \@cansearch,
1.24 raeburn 2973: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 2974: searchby => \@searchby,
1.25 raeburn 2975: searchtypes => \@searchtypes,
1.23 raeburn 2976: }
2977: );
2978: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
2979: $dom);
2980: if ($putresult eq 'ok') {
2981: if (exists($currdirsrch{'available'})) {
2982: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
2983: $changes{'available'} = 1;
2984: }
2985: } else {
2986: if ($env{'form.dirsrch_available'} eq '1') {
2987: $changes{'available'} = 1;
2988: }
2989: }
1.24 raeburn 2990: if (exists($currdirsrch{'localonly'})) {
2991: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
2992: $changes{'localonly'} = 1;
2993: }
2994: } else {
2995: if ($env{'form.dirsrch_localonly'} eq '1') {
2996: $changes{'localonly'} = 1;
2997: }
2998: }
1.23 raeburn 2999: if (keys(%changes) > 0) {
3000: $resulttext = &mt('Changes made:').'<ul>';
3001: if ($changes{'available'}) {
3002: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
3003: }
1.24 raeburn 3004: if ($changes{'localonly'}) {
3005: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
3006: }
3007:
1.23 raeburn 3008: if (ref($changes{'cansearch'}) eq 'ARRAY') {
3009: my $chgtext;
1.26 raeburn 3010: if (ref($usertypes) eq 'HASH') {
3011: if (keys(%{$usertypes}) > 0) {
3012: foreach my $type (@{$types}) {
3013: if (grep(/^\Q$type\E$/,@cansearch)) {
3014: $chgtext .= $usertypes->{$type}.'; ';
3015: }
3016: }
3017: if (grep(/^default$/,@cansearch)) {
3018: $chgtext .= $othertitle;
3019: } else {
3020: $chgtext =~ s/\; $//;
3021: }
3022: $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 3023: }
3024: }
3025: }
3026: if (ref($changes{'searchby'}) eq 'ARRAY') {
3027: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3028: my $chgtext;
3029: foreach my $type (@{$titleorder}) {
3030: if (grep(/^\Q$type\E$/,@searchby)) {
3031: if (defined($searchtitles->{$type})) {
3032: $chgtext .= $searchtitles->{$type}.'; ';
3033: }
3034: }
3035: }
3036: $chgtext =~ s/\; $//;
3037: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
3038: }
1.25 raeburn 3039: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
3040: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
3041: my $chgtext;
3042: foreach my $type (@{$srchtypeorder}) {
3043: if (grep(/^\Q$type\E$/,@searchtypes)) {
3044: if (defined($srchtypes_desc->{$type})) {
3045: $chgtext .= $srchtypes_desc->{$type}.'; ';
3046: }
3047: }
3048: }
3049: $chgtext =~ s/\; $//;
3050: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 3051: }
3052: $resulttext .= '</ul>';
3053: } else {
3054: $resulttext = &mt('No changes made to institution directory search settings');
3055: }
3056: } else {
3057: $resulttext = '<span class="LC_error">'.
1.27 raeburn 3058: &mt('An error occurred: [_1]',$putresult).'</span>';
3059: }
3060: return $resulttext;
3061: }
3062:
1.28 raeburn 3063: sub modify_contacts {
3064: my ($dom,%domconfig) = @_;
3065: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
3066: if (ref($domconfig{'contacts'}) eq 'HASH') {
3067: foreach my $key (keys(%{$domconfig{'contacts'}})) {
3068: $currsetting{$key} = $domconfig{'contacts'}{$key};
3069: }
3070: }
3071: my (%others,%to);
3072: my @contacts = ('supportemail','adminemail');
3073: my @mailings = ('errormail','packagesmail','helpdeskmail');
3074: foreach my $type (@mailings) {
3075: @{$newsetting{$type}} =
3076: &Apache::loncommon::get_env_multiple('form.'.$type);
3077: foreach my $item (@contacts) {
3078: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
3079: $contacts_hash{contacts}{$type}{$item} = 1;
3080: } else {
3081: $contacts_hash{contacts}{$type}{$item} = 0;
3082: }
3083: }
3084: $others{$type} = $env{'form.'.$type.'_others'};
3085: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
3086: }
3087: foreach my $item (@contacts) {
3088: $to{$item} = $env{'form.'.$item};
3089: $contacts_hash{'contacts'}{$item} = $to{$item};
3090: }
3091: if (keys(%currsetting) > 0) {
3092: foreach my $item (@contacts) {
3093: if ($to{$item} ne $currsetting{$item}) {
3094: $changes{$item} = 1;
3095: }
3096: }
3097: foreach my $type (@mailings) {
3098: foreach my $item (@contacts) {
3099: if (ref($currsetting{$type}) eq 'HASH') {
3100: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
3101: push(@{$changes{$type}},$item);
3102: }
3103: } else {
3104: push(@{$changes{$type}},@{$newsetting{$type}});
3105: }
3106: }
3107: if ($others{$type} ne $currsetting{$type}{'others'}) {
3108: push(@{$changes{$type}},'others');
3109: }
3110: }
3111: } else {
3112: my %default;
3113: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3114: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3115: $default{'errormail'} = 'adminemail';
3116: $default{'packagesmail'} = 'adminemail';
3117: $default{'helpdeskmail'} = 'supportemail';
3118: foreach my $item (@contacts) {
3119: if ($to{$item} ne $default{$item}) {
3120: $changes{$item} = 1;
3121: }
3122: }
3123: foreach my $type (@mailings) {
3124: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
3125:
3126: push(@{$changes{$type}},@{$newsetting{$type}});
3127: }
3128: if ($others{$type} ne '') {
3129: push(@{$changes{$type}},'others');
3130: }
3131: }
3132: }
3133: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
3134: $dom);
3135: if ($putresult eq 'ok') {
3136: if (keys(%changes) > 0) {
3137: my ($titles,$short_titles) = &contact_titles();
3138: $resulttext = &mt('Changes made:').'<ul>';
3139: foreach my $item (@contacts) {
3140: if ($changes{$item}) {
3141: $resulttext .= '<li>'.$titles->{$item}.
3142: &mt(' set to: ').
3143: '<span class="LC_cusr_emph">'.
3144: $to{$item}.'</span></li>';
3145: }
3146: }
3147: foreach my $type (@mailings) {
3148: if (ref($changes{$type}) eq 'ARRAY') {
3149: $resulttext .= '<li>'.$titles->{$type}.': ';
3150: my @text;
3151: foreach my $item (@{$newsetting{$type}}) {
3152: push(@text,$short_titles->{$item});
3153: }
3154: if ($others{$type} ne '') {
3155: push(@text,$others{$type});
3156: }
3157: $resulttext .= '<span class="LC_cusr_emph">'.
3158: join(', ',@text).'</span></li>';
3159: }
3160: }
3161: $resulttext .= '</ul>';
3162: } else {
1.34 raeburn 3163: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 3164: }
3165: } else {
3166: $resulttext = '<span class="LC_error">'.
3167: &mt('An error occurred: [_1].',$putresult).'</span>';
3168: }
3169: return $resulttext;
3170: }
3171:
3172: sub modify_usercreation {
1.27 raeburn 3173: my ($dom,%domconfig) = @_;
1.34 raeburn 3174: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 3175: my $warningmsg;
1.27 raeburn 3176: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3177: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
3178: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
3179: }
3180: }
3181: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 3182: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 3183: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
3184: my @contexts = ('author','course','selfenroll');
1.34 raeburn 3185: foreach my $item(@contexts) {
3186: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 3187: if ($item eq 'selfenroll') {
3188: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
3189: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
3190: if (($cancreate{$item} eq 'any') || ($cancreate{$item} eq 'login')) {
3191: $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.');
3192: }
3193: }
3194: }
1.34 raeburn 3195: }
3196: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
3197: foreach my $item (@contexts) {
3198: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
3199: push(@{$changes{'cancreate'}},$item);
3200: }
1.27 raeburn 3201: }
1.34 raeburn 3202: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
3203: foreach my $item (@contexts) {
1.43 raeburn 3204: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 3205: if ($cancreate{$item} ne 'any') {
3206: push(@{$changes{'cancreate'}},$item);
3207: }
3208: } else {
3209: if ($cancreate{$item} ne 'none') {
3210: push(@{$changes{'cancreate'}},$item);
3211: }
1.27 raeburn 3212: }
3213: }
3214: } else {
1.43 raeburn 3215: foreach my $item (@contexts) {
1.34 raeburn 3216: push(@{$changes{'cancreate'}},$item);
3217: }
1.27 raeburn 3218: }
1.34 raeburn 3219:
1.27 raeburn 3220: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
3221: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
3222: if (!grep(/^\Q$type\E$/,@username_rule)) {
3223: push(@{$changes{'username_rule'}},$type);
3224: }
3225: }
3226: foreach my $type (@username_rule) {
3227: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
3228: push(@{$changes{'username_rule'}},$type);
3229: }
3230: }
3231: } else {
3232: push(@{$changes{'username_rule'}},@username_rule);
3233: }
3234:
1.32 raeburn 3235: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
3236: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
3237: if (!grep(/^\Q$type\E$/,@id_rule)) {
3238: push(@{$changes{'id_rule'}},$type);
3239: }
3240: }
3241: foreach my $type (@id_rule) {
3242: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
3243: push(@{$changes{'id_rule'}},$type);
3244: }
3245: }
3246: } else {
3247: push(@{$changes{'id_rule'}},@id_rule);
3248: }
3249:
1.43 raeburn 3250: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
3251: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
3252: if (!grep(/^\Q$type\E$/,@email_rule)) {
3253: push(@{$changes{'email_rule'}},$type);
3254: }
3255: }
3256: foreach my $type (@email_rule) {
3257: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
3258: push(@{$changes{'email_rule'}},$type);
3259: }
3260: }
3261: } else {
3262: push(@{$changes{'email_rule'}},@email_rule);
3263: }
3264:
3265: my @authen_contexts = ('author','course','domain');
1.28 raeburn 3266: my @authtypes = ('int','krb4','krb5','loc');
3267: my %authhash;
1.43 raeburn 3268: foreach my $item (@authen_contexts) {
1.28 raeburn 3269: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
3270: foreach my $auth (@authtypes) {
3271: if (grep(/^\Q$auth\E$/,@authallowed)) {
3272: $authhash{$item}{$auth} = 1;
3273: } else {
3274: $authhash{$item}{$auth} = 0;
3275: }
3276: }
3277: }
3278: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 3279: foreach my $item (@authen_contexts) {
1.28 raeburn 3280: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
3281: foreach my $auth (@authtypes) {
3282: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
3283: push(@{$changes{'authtypes'}},$item);
3284: last;
3285: }
3286: }
3287: }
3288: }
3289: } else {
1.43 raeburn 3290: foreach my $item (@authen_contexts) {
1.28 raeburn 3291: push(@{$changes{'authtypes'}},$item);
3292: }
3293: }
3294:
1.27 raeburn 3295: my %usercreation_hash = (
1.28 raeburn 3296: usercreation => {
1.34 raeburn 3297: cancreate => \%cancreate,
1.27 raeburn 3298: username_rule => \@username_rule,
1.32 raeburn 3299: id_rule => \@id_rule,
1.43 raeburn 3300: email_rule => \@email_rule,
1.32 raeburn 3301: authtypes => \%authhash,
1.27 raeburn 3302: }
3303: );
3304:
3305: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
3306: $dom);
3307: if ($putresult eq 'ok') {
3308: if (keys(%changes) > 0) {
3309: $resulttext = &mt('Changes made:').'<ul>';
3310: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 3311: my %lt = &usercreation_types();
3312: foreach my $type (@{$changes{'cancreate'}}) {
1.43 raeburn 3313: my $chgtext = $lt{$type}.', ';
3314: if ($type eq 'selfenroll') {
3315: if ($cancreate{$type} eq 'none') {
3316: $chgtext .= &mt('creation of a new user account is not permitted.');
3317: } elsif ($cancreate{$type} eq 'any') {
3318: $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.');
3319: } elsif ($cancreate{$type} eq 'login') {
3320: $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional log-in.');
3321: } elsif ($cancreate{$type} eq 'sso') {
3322: $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional single sign on.');
3323: } elsif ($cancreate{$type} eq 'email') {
3324: $chgtext .= &mt('creation of a new account is only permitted for users who provide a valid e-mail address for use as the username.');
3325: }
3326: } else {
3327: if ($cancreate{$type} eq 'none') {
3328: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
3329: } elsif ($cancreate{$type} eq 'any') {
3330: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
3331: } elsif ($cancreate{$type} eq 'official') {
3332: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
3333: } elsif ($cancreate{$type} eq 'unofficial') {
3334: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
3335: }
1.34 raeburn 3336: }
3337: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 3338: }
3339: }
3340: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 3341: my ($rules,$ruleorder) =
3342: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 3343: my $chgtext = '<ul>';
3344: foreach my $type (@username_rule) {
3345: if (ref($rules->{$type}) eq 'HASH') {
3346: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
3347: }
3348: }
3349: $chgtext .= '</ul>';
3350: if (@username_rule > 0) {
3351: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3352: } else {
1.28 raeburn 3353: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 3354: }
3355: }
1.32 raeburn 3356: if (ref($changes{'id_rule'}) eq 'ARRAY') {
3357: my ($idrules,$idruleorder) =
3358: &Apache::lonnet::inst_userrules($dom,'id');
3359: my $chgtext = '<ul>';
3360: foreach my $type (@id_rule) {
3361: if (ref($idrules->{$type}) eq 'HASH') {
3362: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
3363: }
3364: }
3365: $chgtext .= '</ul>';
3366: if (@id_rule > 0) {
3367: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3368: } else {
3369: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
3370: }
3371: }
1.43 raeburn 3372: if (ref($changes{'email_rule'}) eq 'ARRAY') {
3373: my ($emailrules,$emailruleorder) =
3374: &Apache::lonnet::inst_userrules($dom,'email');
3375: my $chgtext = '<ul>';
3376: foreach my $type (@email_rule) {
3377: if (ref($emailrules->{$type}) eq 'HASH') {
3378: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
3379: }
3380: }
3381: $chgtext .= '</ul>';
3382: if (@email_rule > 0) {
3383: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
3384: } else {
3385: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
3386: }
3387: }
3388:
1.28 raeburn 3389: my %authname = &authtype_names();
3390: my %context_title = &context_names();
3391: if (ref($changes{'authtypes'}) eq 'ARRAY') {
3392: my $chgtext = '<ul>';
3393: foreach my $type (@{$changes{'authtypes'}}) {
3394: my @allowed;
3395: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
3396: foreach my $auth (@authtypes) {
3397: if ($authhash{$type}{$auth}) {
3398: push(@allowed,$authname{$auth});
3399: }
3400: }
1.43 raeburn 3401: if (@allowed > 0) {
3402: $chgtext .= join(', ',@allowed).'</li>';
3403: } else {
3404: $chgtext .= &mt('none').'</li>';
3405: }
1.28 raeburn 3406: }
3407: $chgtext .= '</ul>';
3408: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
3409: $resulttext .= '</li>';
3410: }
1.27 raeburn 3411: $resulttext .= '</ul>';
3412: } else {
1.28 raeburn 3413: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 3414: }
3415: } else {
3416: $resulttext = '<span class="LC_error">'.
1.23 raeburn 3417: &mt('An error occurred: [_1]',$putresult).'</span>';
3418: }
1.43 raeburn 3419: if ($warningmsg ne '') {
3420: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
3421: }
1.23 raeburn 3422: return $resulttext;
3423: }
3424:
1.33 raeburn 3425: sub modify_usermodification {
3426: my ($dom,%domconfig) = @_;
3427: my ($resulttext,%curr_usermodification,%changes);
3428: if (ref($domconfig{'usermodification'}) eq 'HASH') {
3429: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
3430: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
3431: }
3432: }
3433: my @contexts = ('author','course');
3434: my %context_title = (
3435: author => 'In author context',
3436: course => 'In course context',
3437: );
3438: my @fields = ('lastname','firstname','middlename','generation',
3439: 'permanentemail','id');
3440: my %roles = (
3441: author => ['ca','aa'],
3442: course => ['st','ep','ta','in','cr'],
3443: );
3444: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3445: my %modifyhash;
3446: foreach my $context (@contexts) {
3447: foreach my $role (@{$roles{$context}}) {
3448: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
3449: foreach my $item (@fields) {
3450: if (grep(/^\Q$item\E$/,@modifiable)) {
3451: $modifyhash{$context}{$role}{$item} = 1;
3452: } else {
3453: $modifyhash{$context}{$role}{$item} = 0;
3454: }
3455: }
3456: }
3457: if (ref($curr_usermodification{$context}) eq 'HASH') {
3458: foreach my $role (@{$roles{$context}}) {
3459: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
3460: foreach my $field (@fields) {
3461: if ($modifyhash{$context}{$role}{$field} ne
3462: $curr_usermodification{$context}{$role}{$field}) {
3463: push(@{$changes{$context}},$role);
3464: last;
3465: }
3466: }
3467: }
3468: }
3469: } else {
3470: foreach my $context (@contexts) {
3471: foreach my $role (@{$roles{$context}}) {
3472: push(@{$changes{$context}},$role);
3473: }
3474: }
3475: }
3476: }
3477: my %usermodification_hash = (
3478: usermodification => \%modifyhash,
3479: );
3480: my $putresult = &Apache::lonnet::put_dom('configuration',
3481: \%usermodification_hash,$dom);
3482: if ($putresult eq 'ok') {
3483: if (keys(%changes) > 0) {
3484: $resulttext = &mt('Changes made: ').'<ul>';
3485: foreach my $context (@contexts) {
3486: if (ref($changes{$context}) eq 'ARRAY') {
3487: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
3488: if (ref($changes{$context}) eq 'ARRAY') {
3489: foreach my $role (@{$changes{$context}}) {
3490: my $rolename;
3491: if ($role eq 'cr') {
3492: $rolename = &mt('Custom');
3493: } else {
3494: $rolename = &Apache::lonnet::plaintext($role);
3495: }
3496: my @modifiable;
3497: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
3498: foreach my $field (@fields) {
3499: if ($modifyhash{$context}{$role}{$field}) {
3500: push(@modifiable,$fieldtitles{$field});
3501: }
3502: }
3503: if (@modifiable > 0) {
3504: $resulttext .= join(', ',@modifiable);
3505: } else {
3506: $resulttext .= &mt('none');
3507: }
3508: $resulttext .= '</li>';
3509: }
3510: $resulttext .= '</ul></li>';
3511: }
3512: }
3513: }
3514: $resulttext .= '</ul>';
3515: } else {
3516: $resulttext = &mt('No changes made to user modification settings');
3517: }
3518: } else {
3519: $resulttext = '<span class="LC_error">'.
3520: &mt('An error occurred: [_1]',$putresult).'</span>';
3521: }
3522: return $resulttext;
3523: }
3524:
1.43 raeburn 3525: sub modify_defaults {
3526: my ($dom,$r) = @_;
3527: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
3528: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
3529: my @items = ('auth_def','auth_arg_def','lang_def');
3530: my @authtypes = ('internal','krb4','krb5','localauth');
3531: foreach my $item (@items) {
3532: $newvalues{$item} = $env{'form.'.$item};
3533: if ($item eq 'auth_def') {
3534: if ($newvalues{$item} ne '') {
3535: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
3536: push(@errors,$item);
3537: }
3538: }
3539: } elsif ($item eq 'lang_def') {
3540: if ($newvalues{$item} ne '') {
3541: if ($newvalues{$item} =~ /^(\w+)/) {
3542: my $langcode = $1;
3543: if (code2language($langcode) eq '') {
3544: push(@errors,$item);
3545: }
3546: } else {
3547: push(@errors,$item);
3548: }
3549: }
3550: }
3551: if (grep(/^\Q$item\E$/,@errors)) {
3552: $newvalues{$item} = $domdefaults{$item};
3553: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
3554: $changes{$item} = 1;
3555: }
3556: }
3557: my %defaults_hash = (
3558: defaults => { auth_def => $newvalues{'auth_def'},
3559: auth_arg_def => $newvalues{'auth_arg_def'},
3560: lang_def => $newvalues{'lang_def'},
3561: }
3562: );
3563: my $title = &defaults_titles();
3564: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
3565: $dom);
3566: if ($putresult eq 'ok') {
3567: if (keys(%changes) > 0) {
3568: $resulttext = &mt('Changes made:').'<ul>';
3569: my $version = $r->dir_config('lonVersion');
3570: 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";
3571: foreach my $item (sort(keys(%changes))) {
3572: my $value = $env{'form.'.$item};
3573: if ($value eq '') {
3574: $value = &mt('none');
3575: } elsif ($item eq 'auth_def') {
3576: my %authnames = &authtype_names();
3577: my %shortauth = (
3578: internal => 'int',
3579: krb4 => 'krb4',
3580: krb5 => 'krb5',
3581: localauth => 'loc',
3582: );
3583: $value = $authnames{$shortauth{$value}};
3584: }
3585: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
3586: $mailmsgtext .= "$title->{$item} set to $value\n";
3587: }
3588: $resulttext .= '</ul>';
3589: $mailmsgtext .= "\n";
3590: my $cachetime = 24*60*60;
3591: &Apache::lonnet::do_cache_new('domdefaults',$dom,
3592: $defaults_hash{'defaults'},$cachetime);
3593: my $sysmail = $r->dir_config('lonSysEMail');
3594: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
3595: } else {
3596: $resulttext = &mt('No changes made to default authentication/language settings');
3597: }
3598: } else {
3599: $resulttext = '<span class="LC_error">'.
3600: &mt('An error occurred: [_1]',$putresult).'</span>';
3601: }
3602: if (@errors > 0) {
3603: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
3604: foreach my $item (@errors) {
3605: $resulttext .= ' "'.$title->{$item}.'",';
3606: }
3607: $resulttext =~ s/,$//;
3608: }
3609: return $resulttext;
3610: }
3611:
1.3 raeburn 3612: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>