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