Annotation of loncom/interface/domainprefs.pm, revision 1.41.2.1
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.41.2.1! raeburn 4: # $Id: domainprefs.pm,v 1.41 2008/01/16 20:42:48 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);
1.41 raeburn 250: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 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();
1.41 raeburn 571: my ($catalogon,$catalogoff,$adminmailon,$adminmailoff,$loginheader);
1.6 raeburn 572: $catalogon = ' checked="checked" ';
573: $adminmailoff = ' checked="checked" ';
1.41 raeburn 574: $loginheader = 'image';
575: my @images = ('img','logo','domlogo','login');
576: my @logintext = ('textcol','bgcol');
1.6 raeburn 577: my @bgs = ('pgbg','mainbg','sidebg');
578: my @links = ('link','alink','vlink');
1.7 albertel 579: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 580: my %defaultdesign = %Apache::loncommon::defaultdesign;
581: my (%is_custom,%designs);
582: my %defaults = (
583: font => $defaultdesign{'login.font'},
584: );
585: foreach my $item (@images) {
586: $defaults{$item} = $defaultdesign{'login.'.$item};
587: }
588: foreach my $item (@bgs) {
589: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
590: }
1.41 raeburn 591: foreach my $item (@logintext) {
592: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
593: }
1.6 raeburn 594: foreach my $item (@links) {
595: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
596: }
1.3 raeburn 597: if (ref($settings) eq 'HASH') {
598: if ($settings->{'coursecatalog'} eq '0') {
1.1 raeburn 599: $catalogoff = $catalogon;
600: $catalogon = ' ';
601: }
1.3 raeburn 602: if ($settings->{'adminmail'} eq '1') {
1.1 raeburn 603: $adminmailon = $adminmailoff;
604: $adminmailoff = ' ';
605: }
1.6 raeburn 606: foreach my $item (@images) {
607: if ($settings->{$item} ne '') {
608: $designs{$item} = $settings->{$item};
609: $is_custom{$item} = 1;
610: }
611: }
1.41 raeburn 612: foreach my $item (@logintext) {
613: if ($settings->{$item} ne '') {
614: $designs{'logintext'}{$item} = $settings->{$item};
615: $is_custom{$item} = 1;
616: }
617: }
618: if ($settings->{'loginheader'} ne '') {
619: $loginheader = $settings->{'loginheader'};
620: }
1.6 raeburn 621: if ($settings->{'font'} ne '') {
622: $designs{'font'} = $settings->{'font'};
623: $is_custom{'font'} = 1;
624: }
625: foreach my $item (@bgs) {
626: if ($settings->{$item} ne '') {
627: $designs{'bgs'}{$item} = $settings->{$item};
628: $is_custom{$item} = 1;
629: }
630: }
631: foreach my $item (@links) {
632: if ($settings->{$item} ne '') {
633: $designs{'links'}{$item} = $settings->{$item};
634: $is_custom{$item} = 1;
635: }
636: }
637: } else {
638: if ($designhash{$dom.'.login.font'} ne '') {
639: $designs{'font'} = $designhash{$dom.'.login.font'};
640: $is_custom{'font'} = 1;
641: }
1.8 raeburn 642: foreach my $item (@images) {
643: if ($designhash{$dom.'.login.'.$item} ne '') {
644: $designs{$item} = $designhash{$dom.'.login.'.$item};
645: $is_custom{$item} = 1;
646: }
647: }
1.6 raeburn 648: foreach my $item (@bgs) {
649: if ($designhash{$dom.'.login.'.$item} ne '') {
650: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
651: $is_custom{$item} = 1;
652: }
653: }
654: foreach my $item (@links) {
655: if ($designhash{$dom.'.login.'.$item} ne '') {
656: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
657: $is_custom{$item} = 1;
658: }
659: }
1.1 raeburn 660: }
1.6 raeburn 661: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
662: logo => 'Institution Logo',
1.41 raeburn 663: domlogo => 'Domain Logo',
664: login => 'Login box');
1.6 raeburn 665: my $itemcount = 1;
666: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.3 raeburn 667: my $datatable =
1.6 raeburn 668: '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
669: '</td><td>'.
1.8 raeburn 670: '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
671: $catalogon.' value="1" />'.&mt('Yes').'</label> '.
672: '<label><input type="radio" name="coursecatalog"'.
673: $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.6 raeburn 674: '</tr>';
675: $itemcount ++;
676: $css_class = $itemcount%2?' class="LC_odd_row"':'';
677: $datatable .= '<tr'.$css_class.'>'.
678: '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
1.8 raeburn 679: '<td><span class="LC_nobreak">'.
680: '<label><input type="radio" name="adminmail"'.
681: $adminmailon.' value="1" />'.&mt('Yes').'</label> '.
682: '<label><input type="radio" name="adminmail"'.
683: $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
1.6 raeburn 684: $itemcount ++;
1.41 raeburn 685: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader);
1.6 raeburn 686: $datatable .= '</tr></table></td></tr>';
687: return $datatable;
688: }
689:
690: sub login_choices {
691: my %choices =
692: &Apache::lonlocal::texthash (
693: coursecatalog => 'Display Course Catalog link?',
694: adminmail => "Display Administrator's E-mail Address?",
695: img => "Header",
696: logo => "Main Logo",
697: domlogo => "Domain Logo",
1.41 raeburn 698: login => "Log-in Header",
699: textcol => "Text color",
700: bgcol => "Box color",
1.6 raeburn 701: bgs => "Background colors",
702: links => "Link colors",
703: font => "Font color",
704: pgbg => "Page",
705: mainbg => "Main panel",
706: sidebg => "Side panel",
707: link => "Link",
708: alink => "Active link",
709: vlink => "Visited link",
710: );
711: return %choices;
712: }
713:
714: sub print_rolecolors {
1.30 raeburn 715: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 716: my %choices = &color_font_choices();
717: my @bgs = ('pgbg','tabbg','sidebg');
718: my @links = ('link','alink','vlink');
719: my @images = ('img');
720: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 721: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 722: my %defaultdesign = %Apache::loncommon::defaultdesign;
723: my (%is_custom,%designs);
724: my %defaults = (
725: img => $defaultdesign{$role.'.img'},
726: font => $defaultdesign{$role.'.font'},
727: );
728: foreach my $item (@bgs) {
729: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
730: }
731: foreach my $item (@links) {
732: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
733: }
734: if (ref($settings) eq 'HASH') {
735: if (ref($settings->{$role}) eq 'HASH') {
736: if ($settings->{$role}->{'img'} ne '') {
737: $designs{'img'} = $settings->{$role}->{'img'};
738: $is_custom{'img'} = 1;
739: }
740: if ($settings->{$role}->{'font'} ne '') {
741: $designs{'font'} = $settings->{$role}->{'font'};
742: $is_custom{'font'} = 1;
743: }
744: foreach my $item (@bgs) {
745: if ($settings->{$role}->{$item} ne '') {
746: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
747: $is_custom{$item} = 1;
748: }
749: }
750: foreach my $item (@links) {
751: if ($settings->{$role}->{$item} ne '') {
752: $designs{'links'}{$item} = $settings->{$role}->{$item};
753: $is_custom{$item} = 1;
754: }
755: }
756: }
757: } else {
758: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
759: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
760: $is_custom{'img'} = 1;
761: }
762: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
763: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
764: $is_custom{'font'} = 1;
765: }
766: foreach my $item (@bgs) {
767: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
768: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
769: $is_custom{$item} = 1;
770:
771: }
772: }
773: foreach my $item (@links) {
774: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
775: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
776: $is_custom{$item} = 1;
777: }
778: }
779: }
780: my $itemcount = 1;
1.30 raeburn 781: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 782: $datatable .= '</tr></table></td></tr>';
783: return $datatable;
784: }
785:
786: sub display_color_options {
1.9 raeburn 787: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.41 raeburn 788: $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_;
1.6 raeburn 789: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
790: my $datatable = '<tr'.$css_class.'>'.
791: '<td>'.$choices->{'font'}.'</td>';
792: if (!$is_custom->{'font'}) {
1.30 raeburn 793: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 794: } else {
795: $datatable .= '<td> </td>';
796: }
797: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 798: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 799: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 800: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 801: ' <span id="css_'.$role.'_font" style="background-color: '.
802: $designs->{'font'}.';"> </span>'.
1.8 raeburn 803: '</span></td></tr>';
1.9 raeburn 804: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 805: foreach my $img (@{$images}) {
1.18 albertel 806: $itemcount ++;
1.6 raeburn 807: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 808: $datatable .= '<tr'.$css_class.'>'.
1.6 raeburn 809: '<td>'.$choices->{$img}.'</td>';
1.41 raeburn 810: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.6 raeburn 811: if ($designs->{$img} ne '') {
812: $imgfile = $designs->{$img};
1.18 albertel 813: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 814: } else {
815: $imgfile = $defaults->{$img};
816: }
1.41 raeburn 817: if ($img eq 'login') {
818: $login_hdr_pick = &login_header_options($img,$role,$defaults,$is_custom,$choices,
819: $loginheader);
820: $logincolors =
821: &login_text_colors($img,$role,$logintext,$phase,$choices,$designs);
822: }
1.6 raeburn 823: if ($imgfile) {
1.9 raeburn 824: my ($showfile,$fullsize);
825: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 826: my $urldir = $1;
827: my $filename = $2;
828: my @info = &Apache::lonnet::stat_file($designs->{$img});
829: if (@info) {
830: my $thumbfile = 'tn-'.$filename;
831: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
832: if (@thumb) {
833: $showfile = $urldir.'/'.$thumbfile;
834: } else {
835: $showfile = $imgfile;
836: }
837: } else {
838: $showfile = '';
839: }
840: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 841: $showfile = $imgfile;
1.6 raeburn 842: my $imgdir = $1;
843: my $filename = $2;
844: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
845: $showfile = "/$imgdir/tn-".$filename;
846: } else {
847: my $input = "/home/httpd/html".$imgfile;
848: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
849: if (!-e $output) {
1.9 raeburn 850: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 851: my ($fullwidth,$fullheight) = &check_dimensions($input);
852: if ($fullwidth ne '' && $fullheight ne '') {
853: if ($fullwidth > $width && $fullheight > $height) {
854: my $size = $width.'x'.$height;
855: system("convert -sample $size $input $output");
856: $showfile = '/'.$imgdir.'/tn-'.$filename;
857: }
858: }
1.6 raeburn 859: }
860: }
1.16 raeburn 861: }
1.6 raeburn 862: if ($showfile) {
1.40 raeburn 863: if ($showfile =~ m{^/(adm|res)/}) {
864: if ($showfile =~ m{^/res/}) {
865: my $local_showfile =
866: &Apache::lonnet::filelocation('',$showfile);
867: &Apache::lonnet::repcopy($local_showfile);
868: }
869: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
870: }
871: if ($imgfile) {
872: if ($imgfile =~ m{^/(adm|res)/}) {
873: if ($imgfile =~ m{^/res/}) {
874: my $local_imgfile =
875: &Apache::lonnet::filelocation('',$imgfile);
876: &Apache::lonnet::repcopy($local_imgfile);
877: }
878: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
879: } else {
880: $fullsize = $imgfile;
881: }
882: }
1.41 raeburn 883: $datatable .= '<td>';
884: if ($img eq 'login') {
885: $datatable .= $login_hdr_pick;
1.6 raeburn 886: }
1.41 raeburn 887: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
888: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 889: } else {
890: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
891: &mt('Upload:');
892: }
893: } else {
894: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
895: &mt('Upload:');
896: }
1.9 raeburn 897: if ($switchserver) {
898: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
899: } else {
900: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
901: }
902: $datatable .= '</td></tr>';
1.6 raeburn 903: }
904: $itemcount ++;
905: $css_class = $itemcount%2?' class="LC_odd_row"':'';
906: $datatable .= '<tr'.$css_class.'>'.
907: '<td>'.$choices->{'bgs'}.'</td>';
908: my $bgs_def;
909: foreach my $item (@{$bgs}) {
910: if (!$is_custom->{$item}) {
1.30 raeburn 911: $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 912: }
913: }
914: if ($bgs_def) {
1.8 raeburn 915: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 916: } else {
917: $datatable .= '<td> </td>';
918: }
919: $datatable .= '<td class="LC_right_item">'.
920: '<table border="0"><tr>';
921: foreach my $item (@{$bgs}) {
922: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
923: $datatable .= '<td align="center">'.$link;
924: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 925: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 926: }
927: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 928: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 929: }
930: $datatable .= '</tr></table></td></tr>';
931: $itemcount ++;
932: $css_class = $itemcount%2?' class="LC_odd_row"':'';
933: $datatable .= '<tr'.$css_class.'>'.
934: '<td>'.$choices->{'links'}.'</td>';
935: my $links_def;
936: foreach my $item (@{$links}) {
937: if (!$is_custom->{$item}) {
1.30 raeburn 938: $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 939: }
940: }
941: if ($links_def) {
1.8 raeburn 942: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 943: } else {
944: $datatable .= '<td> </td>';
945: }
946: $datatable .= '<td class="LC_right_item">'.
947: '<table border="0"><tr>';
948: foreach my $item (@{$links}) {
1.30 raeburn 949: $datatable .= '<td align="center">'."\n".
950: &color_pick($phase,$role,$item,$choices->{$item},
951: $designs->{'links'}{$item});
1.6 raeburn 952: if ($designs->{'links'}{$item}) {
1.30 raeburn 953: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 954: }
955: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
956: '" /></td>';
957: }
1.30 raeburn 958: $$rowtotal += $itemcount;
1.3 raeburn 959: return $datatable;
960: }
961:
1.41 raeburn 962: sub login_header_options {
963: my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
964: my $image_checked = ' checked="checked" ';
965: my $text_checked = ' ';
966: if ($loginheader eq 'text') {
967: $image_checked = ' ';
968: $text_checked = ' checked="checked" ';
969: }
970: my $output = '<span class="LC_nobreak"><label><input type="radio" name="'.
971: 'loginheader" value="image" '.$image_checked.'/>'.
972: &mt('use image').'</label> '.
973: '<label><input type="radio" name="loginheader" value="text"'.
974: $text_checked.'/>'.&mt('use text').'</label><br />'."\n";
975: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
976: $output .= &mt('Text default(s)').':<br />';
977: if (!$is_custom->{'textcol'}) {
978: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
979: ' ';
980: }
981: if (!$is_custom->{'bgcol'}) {
982: $output .= $choices->{'bgcol'}.': '.
983: '<span id="css_'.$role.'_font" style="background-color: '.
984: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
985: }
986: $output .= '<br />';
987: }
988: $output .='<br />';
989: return $output;
990: }
991:
992: sub login_text_colors {
993: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
994: my $color_menu = '<table border="0"><tr>';
995: foreach my $item (@{$logintext}) {
996: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
997: $color_menu .= '<td align="center">'.$link;
998: if ($designs->{'logintext'}{$item}) {
999: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1000: }
1001: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1002: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1003: '<td> </td>';
1004: }
1005: $color_menu .= '</tr></table><br />';
1006: return $color_menu;
1007: }
1008:
1009: sub image_changes {
1010: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1011: my $output;
1012: if (!$is_custom) {
1013: if ($img eq 'login') {
1014: $output .= &mt('Default image:').'<br />';
1015: } else {
1016: $output .= &mt('Default in use:').'<br />';
1017: }
1018: }
1019: if ($img_import) {
1020: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1021: }
1022: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1023: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1024: if ($is_custom) {
1025: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1026: '<input type="checkbox" name="'.
1027: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1028: '</label> '.&mt('Replace:').'</span><br />';
1029: } else {
1030: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1031: }
1032: return $output;
1033: }
1034:
1.6 raeburn 1035: sub color_pick {
1036: my ($phase,$role,$item,$desc,$curcol) = @_;
1037: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1038: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1039: ');">'.$desc.'</a>';
1040: return $link;
1041: }
1042:
1043: sub color_pick_js {
1044: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1045: my $output = <<"ENDCOL";
1046: function pclose() {
1047: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
1048: parmwin.close();
1049: }
1050:
1051: $pjump_def
1052:
1053: function psub() {
1054: pclose();
1055: if (document.parmform.pres_marker.value!='') {
1056: if (document.parmform.pres_type.value!='') {
1057: eval('document.display.'+
1058: document.parmform.pres_marker.value+
1059: '.value=document.parmform.pres_value.value;');
1060: }
1061: } else {
1062: document.parmform.pres_value.value='';
1063: document.parmform.pres_marker.value='';
1064: }
1065: }
1.41 raeburn 1066:
1067: function get_id (span_id) {
1068: if (document.getElementById) {
1069: return document.getElementById(span_id);
1070: }
1071: if (document.all) {
1072: return document.all[span_id];
1073: }
1074: return false;
1075: }
1076:
1077: function colchg_span (span_id_str,new_color_item) {
1078: var span_ref = get_id(span_id_str);
1079: if (span_ref.style) { span_ref = span_ref.style; }
1080: span_ref.background = new_color_item.value;
1081: span_ref.backgroundColor = new_color_item.value;
1082: span_ref.bgColor = new_color_item.value;
1083: }
1084:
1.6 raeburn 1085: ENDCOL
1086: return $output;
1087: }
1088:
1.3 raeburn 1089: sub print_quotas {
1.30 raeburn 1090: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1091: my $datatable;
1.23 raeburn 1092: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.3 raeburn 1093: my $typecount = 0;
1094: my $css_class;
1.26 raeburn 1095: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1096: foreach my $type (@{$types}) {
1.3 raeburn 1097: if (defined($usertypes->{$type})) {
1098: $typecount ++;
1099: $css_class = $typecount%2?' class="LC_odd_row"':'';
1100: $datatable .= '<tr'.$css_class.'>'.
1101: '<td>'.$usertypes->{$type}.'</td>'.
1.8 raeburn 1102: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1103: '<input type="text" name="quota_'.$type.
1104: '" value="'.$settings->{$type}.
1.8 raeburn 1105: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 1106: }
1107: }
1108: }
1109: my $defaultquota = '20';
1110: if (ref($settings) eq 'HASH') {
1111: if (defined($settings->{'default'})) {
1112: $defaultquota = $settings->{'default'};
1113: }
1114: }
1115: $typecount ++;
1116: $css_class = $typecount%2?' class="LC_odd_row"':'';
1117: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1118: '<td>'.$othertitle.'</td>'.
1.8 raeburn 1119: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.15 raeburn 1120: '<input type="text" name="defaultquota" value="'.
1.8 raeburn 1121: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.30 raeburn 1122: $$rowtotal += $typecount;
1.3 raeburn 1123: return $datatable;
1124: }
1125:
1126: sub print_autoenroll {
1.30 raeburn 1127: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1128: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 1129: my ($defdom,$runon,$runoff);
1.3 raeburn 1130: if (ref($settings) eq 'HASH') {
1131: if (exists($settings->{'run'})) {
1132: if ($settings->{'run'} eq '0') {
1133: $runoff = ' checked="checked" ';
1134: $runon = ' ';
1135: } else {
1136: $runon = ' checked="checked" ';
1137: $runoff = ' ';
1138: }
1139: } else {
1140: if ($autorun) {
1141: $runon = ' checked="checked" ';
1142: $runoff = ' ';
1143: } else {
1144: $runoff = ' checked="checked" ';
1145: $runon = ' ';
1146: }
1147: }
1148: if (exists($settings->{'sender_domain'})) {
1149: $defdom = $settings->{'sender_domain'};
1150: }
1.14 raeburn 1151: } else {
1152: if ($autorun) {
1153: $runon = ' checked="checked" ';
1154: $runoff = ' ';
1155: } else {
1156: $runoff = ' checked="checked" ';
1157: $runon = ' ';
1158: }
1.3 raeburn 1159: }
1160: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1161: my $notif_sender;
1162: if (ref($settings) eq 'HASH') {
1163: $notif_sender = $settings->{'sender_uname'};
1164: }
1.3 raeburn 1165: my $datatable='<tr class="LC_odd_row">'.
1166: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1167: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1168: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1169: $runon.' value="1" />'.&mt('Yes').'</label> '.
1170: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1171: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1172: '</tr><tr>'.
1173: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1174: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1175: &mt('username').': '.
1176: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1177: $notif_sender.'" size="10" /> '.&mt('domain').
1.8 raeburn 1178: ': '.$domform.'</span></td></tr>';
1.30 raeburn 1179: $$rowtotal += 2;
1.3 raeburn 1180: return $datatable;
1181: }
1182:
1183: sub print_autoupdate {
1.30 raeburn 1184: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1185: my $datatable;
1186: if ($position eq 'top') {
1187: my $updateon = ' ';
1188: my $updateoff = ' checked="checked" ';
1189: my $classlistson = ' ';
1190: my $classlistsoff = ' checked="checked" ';
1191: if (ref($settings) eq 'HASH') {
1192: if ($settings->{'run'} eq '1') {
1193: $updateon = $updateoff;
1194: $updateoff = ' ';
1195: }
1196: if ($settings->{'classlists'} eq '1') {
1197: $classlistson = $classlistsoff;
1198: $classlistsoff = ' ';
1199: }
1200: }
1201: my %title = (
1202: run => 'Auto-update active?',
1203: classlists => 'Update information in classlists?',
1204: );
1205: $datatable = '<tr class="LC_odd_row">'.
1206: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1207: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1208: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1209: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1210: '<label><input type="radio" name="autoupdate_run"'.
1211: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1212: '</tr><tr>'.
1213: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1214: '<td class="LC_right_item"><span class="LC_nobreak">'.
1215: '<label><input type="radio" name="classlists"'.
1216: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1217: '<label><input type="radio" name="classlists"'.
1218: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1219: '</tr>';
1.30 raeburn 1220: $$rowtotal += 2;
1.3 raeburn 1221: } else {
1.23 raeburn 1222: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.20 raeburn 1223: my @fields = ('lastname','firstname','middlename','gen',
1224: 'permanentemail','id');
1.33 raeburn 1225: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1226: my $numrows = 0;
1.26 raeburn 1227: if (ref($types) eq 'ARRAY') {
1228: if (@{$types} > 0) {
1229: $datatable =
1230: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1231: \@fields,$types,\$numrows);
1.30 raeburn 1232: $$rowtotal += @{$types};
1.26 raeburn 1233: }
1.3 raeburn 1234: }
1235: $datatable .=
1236: &usertype_update_row($settings,{'default' => $othertitle},
1237: \%fieldtitles,\@fields,['default'],
1238: \$numrows);
1.30 raeburn 1239: $$rowtotal ++;
1.3 raeburn 1240: }
1241: return $datatable;
1242: }
1243:
1.23 raeburn 1244: sub print_directorysrch {
1.30 raeburn 1245: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1246: my $srchon = ' ';
1247: my $srchoff = ' checked="checked" ';
1.25 raeburn 1248: my ($exacton,$containson,$beginson);
1.24 raeburn 1249: my $localon = ' ';
1250: my $localoff = ' checked="checked" ';
1.23 raeburn 1251: if (ref($settings) eq 'HASH') {
1252: if ($settings->{'available'} eq '1') {
1253: $srchon = $srchoff;
1254: $srchoff = ' ';
1255: }
1.24 raeburn 1256: if ($settings->{'localonly'} eq '1') {
1257: $localon = $localoff;
1258: $localoff = ' ';
1259: }
1.25 raeburn 1260: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1261: foreach my $type (@{$settings->{'searchtypes'}}) {
1262: if ($type eq 'exact') {
1263: $exacton = ' checked="checked" ';
1264: } elsif ($type eq 'contains') {
1265: $containson = ' checked="checked" ';
1266: } elsif ($type eq 'begins') {
1267: $beginson = ' checked="checked" ';
1268: }
1269: }
1270: } else {
1271: if ($settings->{'searchtypes'} eq 'exact') {
1272: $exacton = ' checked="checked" ';
1273: } elsif ($settings->{'searchtypes'} eq 'contains') {
1274: $containson = ' checked="checked" ';
1275: } elsif ($settings->{'searchtypes'} eq 'specify') {
1276: $exacton = ' checked="checked" ';
1277: $containson = ' checked="checked" ';
1278: }
1.23 raeburn 1279: }
1280: }
1281: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1282: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1283:
1284: my $numinrow = 4;
1.26 raeburn 1285: my $cansrchrow = 0;
1.23 raeburn 1286: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1287: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1288: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1289: '<input type="radio" name="dirsrch_available"'.
1290: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1291: '<label><input type="radio" name="dirsrch_available"'.
1292: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1293: '</tr><tr>'.
1.30 raeburn 1294: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1295: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1296: '<input type="radio" name="dirsrch_localonly"'.
1297: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1298: '<label><input type="radio" name="dirsrch_localonly"'.
1299: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1300: '</tr>';
1.30 raeburn 1301: $$rowtotal += 2;
1.26 raeburn 1302: if (ref($usertypes) eq 'HASH') {
1303: if (keys(%{$usertypes}) > 0) {
1304: $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
1305: $numinrow,$othertitle);
1306: $cansrchrow = 1;
1307: }
1308: }
1309: if ($cansrchrow) {
1.30 raeburn 1310: $$rowtotal ++;
1.26 raeburn 1311: $datatable .= '<tr>';
1312: } else {
1313: $datatable .= '<tr class="LC_odd_row">';
1314: }
1.30 raeburn 1315: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1316: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1317: foreach my $title (@{$titleorder}) {
1318: if (defined($searchtitles->{$title})) {
1319: my $check = ' ';
1.39 raeburn 1320: if (ref($settings) eq 'HASH') {
1321: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1322: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1323: $check = ' checked="checked" ';
1324: }
1.25 raeburn 1325: }
1326: }
1327: $datatable .= '<td class="LC_left_item">'.
1328: '<span class="LC_nobreak"><label>'.
1329: '<input type="checkbox" name="searchby" '.
1330: 'value="'.$title.'"'.$check.'/>'.
1331: $searchtitles->{$title}.'</label></span></td>';
1332: }
1333: }
1.26 raeburn 1334: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1335: $$rowtotal ++;
1.26 raeburn 1336: if ($cansrchrow) {
1337: $datatable .= '<tr class="LC_odd_row">';
1338: } else {
1339: $datatable .= '<tr>';
1340: }
1.30 raeburn 1341: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 1342: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1343: '<span class="LC_nobreak"><label>'.
1344: '<input type="checkbox" name="searchtypes" '.
1345: $exacton.' value="exact" />'.&mt('Exact match').
1346: '</label> '.
1347: '<label><input type="checkbox" name="searchtypes" '.
1348: $beginson.' value="begins" />'.&mt('Begins with').
1349: '</label> '.
1350: '<label><input type="checkbox" name="searchtypes" '.
1351: $containson.' value="contains" />'.&mt('Contains').
1352: '</label></span></td></tr>';
1.30 raeburn 1353: $$rowtotal ++;
1.25 raeburn 1354: return $datatable;
1355: }
1356:
1.28 raeburn 1357: sub print_contacts {
1.30 raeburn 1358: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 1359: my $datatable;
1360: my @contacts = ('adminemail','supportemail');
1361: my (%checked,%to,%otheremails);
1362: my @mailings = ('errormail','packagesmail','helpdeskmail');
1363: foreach my $type (@mailings) {
1364: $otheremails{$type} = '';
1365: }
1366: if (ref($settings) eq 'HASH') {
1367: foreach my $item (@contacts) {
1368: if (exists($settings->{$item})) {
1369: $to{$item} = $settings->{$item};
1370: }
1371: }
1372: foreach my $type (@mailings) {
1373: if (exists($settings->{$type})) {
1374: if (ref($settings->{$type}) eq 'HASH') {
1375: foreach my $item (@contacts) {
1376: if ($settings->{$type}{$item}) {
1377: $checked{$type}{$item} = ' checked="checked" ';
1378: }
1379: }
1380: $otheremails{$type} = $settings->{$type}{'others'};
1381: }
1382: }
1383: }
1384: } else {
1385: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1386: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1387: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1388: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1389: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
1390: }
1391: my ($titles,$short_titles) = &contact_titles();
1392: my $rownum = 0;
1393: my $css_class;
1394: foreach my $item (@contacts) {
1395: if ($rownum%2) {
1396: $css_class = '';
1397: } else {
1398: $css_class = ' class="LC_odd_row" ';
1399: }
1.30 raeburn 1400: $datatable .= '<tr'.$css_class.'>'.
1401: '<td><span class="LC_nobreak">'.$titles->{$item}.
1402: '</span></td><td class="LC_right_item">'.
1.28 raeburn 1403: '<input type="text" name="'.$item.'" value="'.
1404: $to{$item}.'" /></td></tr>';
1405: $rownum ++;
1406: }
1407: foreach my $type (@mailings) {
1408: if ($rownum%2) {
1409: $css_class = '';
1410: } else {
1411: $css_class = ' class="LC_odd_row" ';
1412: }
1413: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 1414: '<td><span class="LC_nobreak">'.
1415: $titles->{$type}.': </span></td>'.
1.28 raeburn 1416: '<td class="LC_left_item">'.
1417: '<span class="LC_nobreak">';
1418: foreach my $item (@contacts) {
1419: $datatable .= '<label>'.
1420: '<input type="checkbox" name="'.$type.'"'.
1421: $checked{$type}{$item}.
1422: ' value="'.$item.'" />'.$short_titles->{$item}.
1423: '</label> ';
1424: }
1425: $datatable .= '</span><br />'.&mt('Others').': '.
1426: '<input type="text" name="'.$type.'_others" '.
1427: 'value="'.$otheremails{$type}.'" />'.
1428: '</td></tr>'."\n";
1429: $rownum ++;
1430: }
1.30 raeburn 1431: $$rowtotal += $rownum;
1.28 raeburn 1432: return $datatable;
1433: }
1434:
1435: sub contact_titles {
1436: my %titles = &Apache::lonlocal::texthash (
1437: 'supportemail' => 'Support E-mail address',
1438: 'adminemail' => 'Default Server Admin E-mail address',
1439: 'errormail' => 'Error reports to be e-mailed to',
1440: 'packagesmail' => 'Package update alerts to be e-mailed to',
1441: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
1442: );
1443: my %short_titles = &Apache::lonlocal::texthash (
1444: adminemail => 'Admin E-mail address',
1445: supportemail => 'Support E-mail',
1446: );
1447: return (\%titles,\%short_titles);
1448: }
1449:
1.27 raeburn 1450: sub print_usercreation {
1.30 raeburn 1451: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 1452: my $numinrow = 4;
1.28 raeburn 1453: my $datatable;
1454: if ($position eq 'top') {
1.30 raeburn 1455: $$rowtotal ++;
1.34 raeburn 1456: my $rowcount = 0;
1.32 raeburn 1457: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 1458: if (ref($rules) eq 'HASH') {
1459: if (keys(%{$rules}) > 0) {
1.32 raeburn 1460: $datatable .= &user_formats_row('username',$settings,$rules,
1461: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 1462: $$rowtotal ++;
1.32 raeburn 1463: $rowcount ++;
1464: }
1465: }
1466: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
1467: if (ref($idrules) eq 'HASH') {
1468: if (keys(%{$idrules}) > 0) {
1469: $datatable .= &user_formats_row('id',$settings,$idrules,
1470: $idruleorder,$numinrow,$rowcount);
1471: $$rowtotal ++;
1472: $rowcount ++;
1.28 raeburn 1473: }
1474: }
1.39 raeburn 1475: if ($rowcount == 0) {
1476: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
1477: $$rowtotal ++;
1478: $rowcount ++;
1479: }
1.34 raeburn 1480: } elsif ($position eq 'middle') {
1481: my @creators = ('author','course');
1.37 raeburn 1482: my ($rules,$ruleorder) =
1483: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 1484: my %lt = &usercreation_types();
1485: my %checked;
1486: if (ref($settings) eq 'HASH') {
1487: if (ref($settings->{'cancreate'}) eq 'HASH') {
1488: foreach my $item (@creators) {
1489: $checked{$item} = $settings->{'cancreate'}{$item};
1490: }
1491: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
1492: foreach my $item (@creators) {
1493: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
1494: $checked{$item} = 'none';
1495: }
1496: }
1497: }
1498: }
1499: my $rownum = 0;
1500: foreach my $item (@creators) {
1501: $rownum ++;
1502: if ($checked{$item} eq '') {
1503: $checked{$item} = 'any';
1504: }
1505: my $css_class;
1506: if ($rownum%2) {
1507: $css_class = '';
1508: } else {
1509: $css_class = ' class="LC_odd_row" ';
1510: }
1511: $datatable .= '<tr'.$css_class.'>'.
1512: '<td><span class="LC_nobreak">'.$lt{$item}.
1513: '</span></td><td align="right">';
1.37 raeburn 1514: my @options = ('any');
1515: if (ref($rules) eq 'HASH') {
1516: if (keys(%{$rules}) > 0) {
1517: push(@options,('official','unofficial'));
1518: }
1519: }
1520: push(@options,'none');
1521: foreach my $option (@options) {
1.34 raeburn 1522: my $check = ' ';
1523: if ($checked{$item} eq $option) {
1524: $check = ' checked="checked" ';
1525: }
1526: $datatable .= '<span class="LC_nobreak"><label>'.
1527: '<input type="radio" name="can_createuser_'.
1528: $item.'" value="'.$option.'"'.$check.'/> '.
1529: $lt{$option}.'</label> </span>';
1530: }
1531: $datatable .= '</td></tr>';
1532: }
1.28 raeburn 1533: } else {
1534: my @contexts = ('author','course','domain');
1535: my @authtypes = ('int','krb4','krb5','loc');
1536: my %checked;
1537: if (ref($settings) eq 'HASH') {
1538: if (ref($settings->{'authtypes'}) eq 'HASH') {
1539: foreach my $item (@contexts) {
1540: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
1541: foreach my $auth (@authtypes) {
1542: if ($settings->{'authtypes'}{$item}{$auth}) {
1543: $checked{$item}{$auth} = ' checked="checked" ';
1544: }
1545: }
1546: }
1547: }
1.27 raeburn 1548: }
1.35 raeburn 1549: } else {
1550: foreach my $item (@contexts) {
1.36 raeburn 1551: foreach my $auth (@authtypes) {
1.35 raeburn 1552: $checked{$item}{$auth} = ' checked="checked" ';
1553: }
1554: }
1.27 raeburn 1555: }
1.28 raeburn 1556: my %title = &context_names();
1557: my %authname = &authtype_names();
1558: my $rownum = 0;
1559: my $css_class;
1560: foreach my $item (@contexts) {
1561: if ($rownum%2) {
1562: $css_class = '';
1563: } else {
1564: $css_class = ' class="LC_odd_row" ';
1565: }
1.30 raeburn 1566: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 1567: '<td>'.$title{$item}.
1568: '</td><td class="LC_left_item">'.
1569: '<span class="LC_nobreak">';
1570: foreach my $auth (@authtypes) {
1571: $datatable .= '<label>'.
1572: '<input type="checkbox" name="'.$item.'_auth" '.
1573: $checked{$item}{$auth}.' value="'.$auth.'" />'.
1574: $authname{$auth}.'</label> ';
1575: }
1576: $datatable .= '</span></td></tr>';
1577: $rownum ++;
1.27 raeburn 1578: }
1.30 raeburn 1579: $$rowtotal += $rownum;
1.27 raeburn 1580: }
1581: return $datatable;
1582: }
1583:
1.32 raeburn 1584: sub user_formats_row {
1585: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
1586: my $output;
1587: my %text = (
1588: 'username' => 'new usernames',
1589: 'id' => 'IDs',
1590: );
1591: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1592: $output = '<tr '.$css_class.'>'.
1593: '<td><span class="LC_nobreak">'.
1594: &mt("Format rules to check for $text{$type}: ").
1595: '</span></td>'.
1596: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 1597: my $rem;
1598: if (ref($ruleorder) eq 'ARRAY') {
1599: for (my $i=0; $i<@{$ruleorder}; $i++) {
1600: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
1601: my $rem = $i%($numinrow);
1602: if ($rem == 0) {
1603: if ($i > 0) {
1604: $output .= '</tr>';
1605: }
1606: $output .= '<tr>';
1607: }
1608: my $check = ' ';
1.39 raeburn 1609: if (ref($settings) eq 'HASH') {
1610: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
1611: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
1612: $check = ' checked="checked" ';
1613: }
1.27 raeburn 1614: }
1615: }
1616: $output .= '<td class="LC_left_item">'.
1617: '<span class="LC_nobreak"><label>'.
1.32 raeburn 1618: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 1619: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
1620: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
1621: }
1622: }
1623: $rem = @{$ruleorder}%($numinrow);
1624: }
1625: my $colsleft = $numinrow - $rem;
1626: if ($colsleft > 1 ) {
1627: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1628: ' </td>';
1629: } elsif ($colsleft == 1) {
1630: $output .= '<td class="LC_left_item"> </td>';
1631: }
1632: $output .= '</tr></table></td></tr>';
1633: return $output;
1634: }
1635:
1.34 raeburn 1636: sub usercreation_types {
1637: my %lt = &Apache::lonlocal::texthash (
1638: author => 'When adding a co-author',
1639: course => 'When adding a user to a course',
1640: any => 'Any',
1641: official => 'Institutional only ',
1642: unofficial => 'Non-institutional only',
1643: none => 'None',
1644: );
1645: return %lt;
1646: }
1647:
1.28 raeburn 1648: sub authtype_names {
1649: my %lt = &Apache::lonlocal::texthash(
1650: int => 'Internal',
1651: krb4 => 'Kerberos 4',
1652: krb5 => 'Kerberos 5',
1653: loc => 'Local',
1654: );
1655: return %lt;
1656: }
1657:
1658: sub context_names {
1659: my %context_title = &Apache::lonlocal::texthash(
1660: author => 'Creating users when an Author',
1661: course => 'Creating users when in a course',
1662: domain => 'Creating users when a Domain Coordinator',
1663: );
1664: return %context_title;
1665: }
1666:
1.33 raeburn 1667: sub print_usermodification {
1668: my ($position,$dom,$settings,$rowtotal) = @_;
1669: my $numinrow = 4;
1670: my ($context,$datatable,$rowcount);
1671: if ($position eq 'top') {
1672: $rowcount = 0;
1673: $context = 'author';
1674: foreach my $role ('ca','aa') {
1675: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1676: $numinrow,$rowcount);
1677: $$rowtotal ++;
1678: $rowcount ++;
1679: }
1680: } else {
1681: $context = 'course';
1682: $rowcount = 0;
1683: foreach my $role ('st','ep','ta','in','cr') {
1684: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1685: $numinrow,$rowcount);
1686: $$rowtotal ++;
1687: $rowcount ++;
1688: }
1689: }
1690: return $datatable;
1691: }
1692:
1693: sub modifiable_userdata_row {
1694: my ($context,$role,$settings,$numinrow,$rowcount) = @_;
1695: my $rolename;
1696: if ($role eq 'cr') {
1697: $rolename = &mt('Custom role');
1698: } else {
1699: $rolename = &Apache::lonnet::plaintext($role);
1700: }
1701: my @fields = ('lastname','firstname','middlename','generation',
1702: 'permanentemail','id');
1703: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1704: my $output;
1705: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1706: $output = '<tr '.$css_class.'>'.
1707: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
1708: '<td class="LC_left_item" colspan="2"><table>';
1709: my $rem;
1710: my %checks;
1711: if (ref($settings) eq 'HASH') {
1712: if (ref($settings->{$context}) eq 'HASH') {
1713: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1714: foreach my $field (@fields) {
1715: if ($settings->{$context}->{$role}->{$field}) {
1716: $checks{$field} = ' checked="checked" ';
1717: }
1718: }
1719: }
1720: }
1721: }
1722: for (my $i=0; $i<@fields; $i++) {
1723: my $rem = $i%($numinrow);
1724: if ($rem == 0) {
1725: if ($i > 0) {
1726: $output .= '</tr>';
1727: }
1728: $output .= '<tr>';
1729: }
1730: my $check = ' ';
1731: if (exists($checks{$fields[$i]})) {
1732: $check = $checks{$fields[$i]}
1733: } else {
1734: if ($role eq 'st') {
1735: if (ref($settings) ne 'HASH') {
1736: $check = ' checked="checked" ';
1737: }
1738: }
1739: }
1740: $output .= '<td class="LC_left_item">'.
1741: '<span class="LC_nobreak"><label>'.
1742: '<input type="checkbox" name="canmodify_'.$role.'" '.
1743: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
1744: '</label></span></td>';
1745: $rem = @fields%($numinrow);
1746: }
1747: my $colsleft = $numinrow - $rem;
1748: if ($colsleft > 1 ) {
1749: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1750: ' </td>';
1751: } elsif ($colsleft == 1) {
1752: $output .= '<td class="LC_left_item"> </td>';
1753: }
1754: $output .= '</tr></table></td></tr>';
1755: return $output;
1756: }
1.28 raeburn 1757:
1.25 raeburn 1758: sub users_cansearch_row {
1759: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
1760: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 1761: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
1762: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 1763: my $rem;
1764: if (ref($types) eq 'ARRAY') {
1765: for (my $i=0; $i<@{$types}; $i++) {
1766: if (defined($usertypes->{$types->[$i]})) {
1767: my $rem = $i%($numinrow);
1768: if ($rem == 0) {
1769: if ($i > 0) {
1770: $output .= '</tr>';
1771: }
1772: $output .= '<tr>';
1.23 raeburn 1773: }
1.26 raeburn 1774: my $check = ' ';
1775: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1776: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
1777: $check = ' checked="checked" ';
1778: }
1.23 raeburn 1779: }
1.26 raeburn 1780: $output .= '<td class="LC_left_item">'.
1781: '<span class="LC_nobreak"><label>'.
1782: '<input type="checkbox" name="cansearch" '.
1783: 'value="'.$types->[$i].'"'.$check.'/>'.
1784: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 1785: }
1786: }
1.26 raeburn 1787:
1788: $rem = @{$types}%($numinrow);
1.23 raeburn 1789: }
1790: my $colsleft = $numinrow - $rem;
1791: if ($colsleft > 1) {
1.25 raeburn 1792: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 1793: } else {
1.25 raeburn 1794: $output .= '<td class="LC_left_item">';
1.23 raeburn 1795: }
1796: my $defcheck = ' ';
1797: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 1798: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
1799: $defcheck = ' checked="checked" ';
1800: }
1.23 raeburn 1801: }
1.25 raeburn 1802: $output .= '<span class="LC_nobreak"><label>'.
1803: '<input type="checkbox" name="cansearch" '.
1804: 'value="default"'.$defcheck.'/>'.
1805: $othertitle.'</label></span></td>'.
1806: '</tr></table></td></tr>';
1807: return $output;
1.23 raeburn 1808: }
1809:
1810: sub sorted_inst_types {
1811: my ($dom) = @_;
1812: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1.26 raeburn 1813: my $othertitle = &mt('All users');
1.23 raeburn 1814: my @types;
1815: if (ref($order) eq 'ARRAY') {
1816: @types = @{$order};
1817: }
1818: if (@types == 0) {
1819: if (ref($usertypes) eq 'HASH') {
1820: @types = sort(keys(%{$usertypes}));
1821: }
1822: }
1823: if (keys(%{$usertypes}) > 0) {
1824: $othertitle = &mt('Other users');
1825: }
1826: return ($othertitle,$usertypes,\@types);
1827: }
1828:
1829: sub sorted_searchtitles {
1830: my %searchtitles = &Apache::lonlocal::texthash(
1831: 'uname' => 'username',
1832: 'lastname' => 'last name',
1833: 'lastfirst' => 'last name, first name',
1834: );
1835: my @titleorder = ('uname','lastname','lastfirst');
1836: return (\%searchtitles,\@titleorder);
1837: }
1838:
1.25 raeburn 1839: sub sorted_searchtypes {
1840: my %srchtypes_desc = (
1841: exact => 'is exact match',
1842: contains => 'contains ..',
1843: begins => 'begins with ..',
1844: );
1845: my @srchtypeorder = ('exact','begins','contains');
1846: return (\%srchtypes_desc,\@srchtypeorder);
1847: }
1848:
1.3 raeburn 1849: sub usertype_update_row {
1850: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
1851: my $datatable;
1852: my $numinrow = 4;
1853: foreach my $type (@{$types}) {
1854: if (defined($usertypes->{$type})) {
1855: $$rownums ++;
1856: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
1857: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
1858: '</td><td class="LC_left_item"><table>';
1859: for (my $i=0; $i<@{$fields}; $i++) {
1860: my $rem = $i%($numinrow);
1861: if ($rem == 0) {
1862: if ($i > 0) {
1863: $datatable .= '</tr>';
1864: }
1865: $datatable .= '<tr>';
1866: }
1867: my $check = ' ';
1.39 raeburn 1868: if (ref($settings) eq 'HASH') {
1869: if (ref($settings->{'fields'}) eq 'HASH') {
1870: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
1871: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
1872: $check = ' checked="checked" ';
1873: }
1.3 raeburn 1874: }
1875: }
1876: }
1877:
1878: if ($i == @{$fields}-1) {
1879: my $colsleft = $numinrow - $rem;
1880: if ($colsleft > 1) {
1881: $datatable .= '<td colspan="'.$colsleft.'">';
1882: } else {
1883: $datatable .= '<td>';
1884: }
1885: } else {
1886: $datatable .= '<td>';
1887: }
1.8 raeburn 1888: $datatable .= '<span class="LC_nobreak"><label>'.
1889: '<input type="checkbox" name="updateable_'.$type.
1890: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
1891: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 1892: }
1893: $datatable .= '</tr></table></td></tr>';
1894: }
1895: }
1896: return $datatable;
1.1 raeburn 1897: }
1898:
1899: sub modify_login {
1.9 raeburn 1900: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 1901: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 1902: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 1903: adminmail => 'Display administrator E-mail address',
1904: loginheader => 'Log-in box header');
1.3 raeburn 1905: my @offon = ('off','on');
1.6 raeburn 1906: my %loginhash;
1.9 raeburn 1907: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
1908: \%domconfig,\%loginhash);
1.6 raeburn 1909: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
1910: $loginhash{login}{adminmail} = $env{'form.adminmail'};
1.41 raeburn 1911: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 1912: if (ref($colchanges{'login'}) eq 'HASH') {
1913: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
1914: \%loginhash);
1915: }
1.1 raeburn 1916: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
1917: $dom);
1918: if ($putresult eq 'ok') {
1.3 raeburn 1919: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 1920: ($env{'form.coursecatalog'} eq '1')) {
1921: $changes{'coursecatalog'} = 1;
1.3 raeburn 1922: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
1923: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 1924: ($env{'form.coursecatalog'} eq '0')) {
1925: $changes{'coursecatalog'} = 1;
1926: }
1.3 raeburn 1927: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 1928: ($env{'form.adminmail'} eq '0')) {
1929: $changes{'adminmail'} = 1;
1930: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
1931: $domconfig{'login'}{'adminmail'} eq '0') &&
1932: ($env{'form.adminmail'} eq '1')) {
1933: $changes{'adminmail'} = 1;
1934: }
1.41 raeburn 1935: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
1936: ($env{'form.loginheader'} eq 'image')) {
1937: $changes{'loginheader'} = 1;
1938: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
1939: $domconfig{'login'}{'loginheader'} eq 'image') &&
1940: ($env{'form.loginheader'} eq 'text')) {
1941: $changes{'loginheader'} = 1;
1942: }
1.6 raeburn 1943: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 1944: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 1945: $resulttext = &mt('Changes made:').'<ul>';
1946: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 1947: if ($item eq 'loginheader') {
1948: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
1949: } else {
1950: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
1951: }
1.1 raeburn 1952: }
1.6 raeburn 1953: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 1954: } else {
1955: $resulttext = &mt('No changes made to log-in page settings');
1956: }
1957: } else {
1.11 albertel 1958: $resulttext = '<span class="LC_error">'.
1959: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1960: }
1.6 raeburn 1961: if ($errors) {
1.9 raeburn 1962: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 1963: $errors.'</ul>';
1964: }
1965: return $resulttext;
1966: }
1967:
1968: sub color_font_choices {
1969: my %choices =
1970: &Apache::lonlocal::texthash (
1971: img => "Header",
1972: bgs => "Background colors",
1973: links => "Link colors",
1974: font => "Font color",
1975: pgbg => "Page",
1976: tabbg => "Header",
1977: sidebg => "Border",
1978: link => "Link",
1979: alink => "Active link",
1980: vlink => "Visited link",
1981: );
1982: return %choices;
1983: }
1984:
1985: sub modify_rolecolors {
1.9 raeburn 1986: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 1987: my ($resulttext,%rolehash);
1988: $rolehash{'rolecolors'} = {};
1.9 raeburn 1989: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 1990: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
1991: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
1992: $dom);
1993: if ($putresult eq 'ok') {
1994: if (keys(%changes) > 0) {
1.41 raeburn 1995: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 1996: $resulttext = &display_colorchgs($dom,\%changes,$roles,
1997: $rolehash{'rolecolors'});
1998: } else {
1999: $resulttext = &mt('No changes made to default color schemes');
2000: }
2001: } else {
1.11 albertel 2002: $resulttext = '<span class="LC_error">'.
2003: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 2004: }
2005: if ($errors) {
2006: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
2007: $errors.'</ul>';
2008: }
2009: return $resulttext;
2010: }
2011:
2012: sub modify_colors {
1.9 raeburn 2013: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 2014: my (%changes,%choices);
1.41.2.1! raeburn 2015: my @bgs;
1.6 raeburn 2016: my @links = ('link','alink','vlink');
1.41 raeburn 2017: my @logintext;
1.6 raeburn 2018: my @images;
2019: my $servadm = $r->dir_config('lonAdmEMail');
2020: my $errors;
2021: foreach my $role (@{$roles}) {
2022: if ($role eq 'login') {
1.12 raeburn 2023: %choices = &login_choices();
1.41 raeburn 2024: @logintext = ('textcol','bgcol');
1.12 raeburn 2025: } else {
2026: %choices = &color_font_choices();
2027: }
2028: if ($role eq 'login') {
1.41 raeburn 2029: @images = ('img','logo','domlogo','login');
1.41.2.1! raeburn 2030: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 2031: } else {
2032: @images = ('img');
1.41.2.1! raeburn 2033: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 2034: }
2035: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 2036: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 2037: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
2038: }
1.9 raeburn 2039: my ($configuserok,$author_ok,$switchserver,%currroles);
2040: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
2041: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
2042: $confname,$servadm);
2043: if ($configuserok eq 'ok') {
2044: $switchserver = &check_switchserver($dom,$confname);
2045: if ($switchserver eq '') {
2046: $author_ok = &check_authorstatus($dom,$confname,%currroles);
2047: }
2048: }
2049: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 2050: if (ref($domconfig->{$role}) ne 'HASH') {
2051: $domconfig->{$role} = {};
2052: }
1.8 raeburn 2053: foreach my $img (@images) {
1.18 albertel 2054: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
2055: && !defined($domconfig->{$role}{$img})
2056: && !$env{'form.'.$role.'_del_'.$img}
2057: && $env{'form.'.$role.'_import_'.$img}) {
2058: # import the old configured image from the .tab setting
2059: # if they haven't provided a new one
2060: $domconfig->{$role}{$img} =
2061: $env{'form.'.$role.'_import_'.$img};
2062: }
1.6 raeburn 2063: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 2064: my $error;
1.6 raeburn 2065: if ($configuserok eq 'ok') {
1.9 raeburn 2066: if ($switchserver) {
1.12 raeburn 2067: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 2068: } else {
2069: if ($author_ok eq 'ok') {
2070: my ($result,$logourl) =
2071: &publishlogo($r,'upload',$role.'_'.$img,
2072: $dom,$confname,$img,$width,$height);
2073: if ($result eq 'ok') {
2074: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 2075: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2076: } else {
1.12 raeburn 2077: $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 2078: }
2079: } else {
1.12 raeburn 2080: $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 2081: }
2082: }
2083: } else {
1.12 raeburn 2084: $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 2085: }
2086: if ($error) {
1.8 raeburn 2087: &Apache::lonnet::logthis($error);
1.11 albertel 2088: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 2089: }
2090: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 2091: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
2092: my $error;
2093: if ($configuserok eq 'ok') {
2094: # is confname an author?
2095: if ($switchserver eq '') {
2096: if ($author_ok eq 'ok') {
2097: my ($result,$logourl) =
2098: &publishlogo($r,'copy',$domconfig->{$role}{$img},
2099: $dom,$confname,$img,$width,$height);
2100: if ($result eq 'ok') {
2101: $confhash->{$role}{$img} = $logourl;
1.18 albertel 2102: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2103: }
2104: }
2105: }
2106: }
1.6 raeburn 2107: }
2108: }
2109: }
2110: if (ref($domconfig) eq 'HASH') {
2111: if (ref($domconfig->{$role}) eq 'HASH') {
2112: foreach my $img (@images) {
2113: if ($domconfig->{$role}{$img} ne '') {
2114: if ($env{'form.'.$role.'_del_'.$img}) {
2115: $confhash->{$role}{$img} = '';
1.12 raeburn 2116: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2117: } else {
1.9 raeburn 2118: if ($confhash->{$role}{$img} eq '') {
2119: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
2120: }
1.6 raeburn 2121: }
2122: } else {
2123: if ($env{'form.'.$role.'_del_'.$img}) {
2124: $confhash->{$role}{$img} = '';
1.12 raeburn 2125: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2126: }
2127: }
2128: }
2129: if ($domconfig->{$role}{'font'} ne '') {
2130: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
2131: $changes{$role}{'font'} = 1;
2132: }
2133: } else {
2134: if ($confhash->{$role}{'font'}) {
2135: $changes{$role}{'font'} = 1;
2136: }
2137: }
2138: foreach my $item (@bgs) {
2139: if ($domconfig->{$role}{$item} ne '') {
2140: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2141: $changes{$role}{'bgs'}{$item} = 1;
2142: }
2143: } else {
2144: if ($confhash->{$role}{$item}) {
2145: $changes{$role}{'bgs'}{$item} = 1;
2146: }
2147: }
2148: }
2149: foreach my $item (@links) {
2150: if ($domconfig->{$role}{$item} ne '') {
2151: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2152: $changes{$role}{'links'}{$item} = 1;
2153: }
2154: } else {
2155: if ($confhash->{$role}{$item}) {
2156: $changes{$role}{'links'}{$item} = 1;
2157: }
2158: }
2159: }
1.41 raeburn 2160: foreach my $item (@logintext) {
2161: if ($domconfig->{$role}{$item} ne '') {
2162: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2163: $changes{$role}{'logintext'}{$item} = 1;
2164: }
2165: } else {
2166: if ($confhash->{$role}{$item}) {
2167: $changes{$role}{'logintext'}{$item} = 1;
2168: }
2169: }
2170: }
1.6 raeburn 2171: } else {
2172: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2173: \@logintext,$confhash,\%changes);
1.6 raeburn 2174: }
2175: } else {
2176: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2177: \@logintext,$confhash,\%changes);
1.6 raeburn 2178: }
2179: }
2180: return ($errors,%changes);
2181: }
2182:
2183: sub default_change_checker {
1.41 raeburn 2184: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 2185: foreach my $item (@{$links}) {
2186: if ($confhash->{$role}{$item}) {
2187: $changes->{$role}{'links'}{$item} = 1;
2188: }
2189: }
2190: foreach my $item (@{$bgs}) {
2191: if ($confhash->{$role}{$item}) {
2192: $changes->{$role}{'bgs'}{$item} = 1;
2193: }
2194: }
1.41 raeburn 2195: foreach my $item (@{$logintext}) {
2196: if ($confhash->{$role}{$item}) {
2197: $changes->{$role}{'logintext'}{$item} = 1;
2198: }
2199: }
1.6 raeburn 2200: foreach my $img (@{$images}) {
2201: if ($env{'form.'.$role.'_del_'.$img}) {
2202: $confhash->{$role}{$img} = '';
1.12 raeburn 2203: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 2204: }
2205: }
2206: if ($confhash->{$role}{'font'}) {
2207: $changes->{$role}{'font'} = 1;
2208: }
2209: }
2210:
2211: sub display_colorchgs {
2212: my ($dom,$changes,$roles,$confhash) = @_;
2213: my (%choices,$resulttext);
2214: if (!grep(/^login$/,@{$roles})) {
2215: $resulttext = &mt('Changes made:').'<br />';
2216: }
2217: foreach my $role (@{$roles}) {
2218: if ($role eq 'login') {
2219: %choices = &login_choices();
2220: } else {
2221: %choices = &color_font_choices();
2222: }
2223: if (ref($changes->{$role}) eq 'HASH') {
2224: if ($role ne 'login') {
2225: $resulttext .= '<h4>'.&mt($role).'</h4>';
2226: }
2227: foreach my $key (sort(keys(%{$changes->{$role}}))) {
2228: if ($role ne 'login') {
2229: $resulttext .= '<ul>';
2230: }
2231: if (ref($changes->{$role}{$key}) eq 'HASH') {
2232: if ($role ne 'login') {
2233: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
2234: }
2235: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
2236: if ($confhash->{$role}{$item} eq '') {
2237: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
2238: } else {
1.12 raeburn 2239: my $newitem = $confhash->{$role}{$item};
2240: if ($key eq 'images') {
2241: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
2242: }
2243: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 2244: }
2245: }
2246: if ($role ne 'login') {
2247: $resulttext .= '</ul></li>';
2248: }
2249: } else {
2250: if ($confhash->{$role}{$key} eq '') {
2251: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
2252: } else {
2253: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
2254: }
2255: }
2256: if ($role ne 'login') {
2257: $resulttext .= '</ul>';
2258: }
2259: }
2260: }
2261: }
1.3 raeburn 2262: return $resulttext;
1.1 raeburn 2263: }
2264:
1.9 raeburn 2265: sub thumb_dimensions {
2266: return ('200','50');
2267: }
2268:
1.16 raeburn 2269: sub check_dimensions {
2270: my ($inputfile) = @_;
2271: my ($fullwidth,$fullheight);
2272: if ($inputfile =~ m|^[/\w.\-]+$|) {
2273: if (open(PIPE,"identify $inputfile 2>&1 |")) {
2274: my $imageinfo = <PIPE>;
2275: if (!close(PIPE)) {
2276: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
2277: }
2278: chomp($imageinfo);
2279: my ($fullsize) =
1.21 raeburn 2280: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 2281: if ($fullsize) {
2282: ($fullwidth,$fullheight) = split(/x/,$fullsize);
2283: }
2284: }
2285: }
2286: return ($fullwidth,$fullheight);
2287: }
2288:
1.9 raeburn 2289: sub check_configuser {
2290: my ($uhome,$dom,$confname,$servadm) = @_;
2291: my ($configuserok,%currroles);
2292: if ($uhome eq 'no_host') {
2293: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
2294: my $configpass = &LONCAPA::Enrollment::create_password();
2295: $configuserok =
2296: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
2297: $configpass,'','','','','',undef,$servadm);
2298: } else {
2299: $configuserok = 'ok';
2300: %currroles =
2301: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
2302: }
2303: return ($configuserok,%currroles);
2304: }
2305:
2306: sub check_authorstatus {
2307: my ($dom,$confname,%currroles) = @_;
2308: my $author_ok;
1.40 raeburn 2309: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 2310: my $start = time;
2311: my $end = 0;
2312: $author_ok =
2313: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
2314: 'au',$end,$start);
2315: } else {
2316: $author_ok = 'ok';
2317: }
2318: return $author_ok;
2319: }
2320:
2321: sub publishlogo {
2322: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
2323: my ($output,$fname,$logourl);
2324: if ($action eq 'upload') {
2325: $fname=$env{'form.'.$formname.'.filename'};
2326: chop($env{'form.'.$formname});
2327: } else {
2328: ($fname) = ($formname =~ /([^\/]+)$/);
2329: }
2330: $fname=&Apache::lonnet::clean_filename($fname);
2331: # See if there is anything left
2332: unless ($fname) { return ('error: no uploaded file'); }
2333: $fname="$subdir/$fname";
2334: my $filepath='/home/'.$confname.'/public_html';
2335: my ($fnamepath,$file,$fetchthumb);
2336: $file=$fname;
2337: if ($fname=~m|/|) {
2338: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
2339: }
2340: my @parts=split(/\//,$filepath.'/'.$fnamepath);
2341: my $count;
2342: for ($count=4;$count<=$#parts;$count++) {
2343: $filepath.="/$parts[$count]";
2344: if ((-e $filepath)!=1) {
2345: mkdir($filepath,02770);
2346: }
2347: }
2348: # Check for bad extension and disallow upload
2349: if ($file=~/\.(\w+)$/ &&
2350: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
2351: $output =
2352: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
2353: } elsif ($file=~/\.(\w+)$/ &&
2354: !defined(&Apache::loncommon::fileembstyle($1))) {
2355: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
2356: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
2357: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
2358: } elsif (-d "$filepath/$file") {
2359: $output = &mt('File name is a directory name - rename the file and re-upload');
2360: } else {
2361: my $source = $filepath.'/'.$file;
2362: my $logfile;
2363: if (!open($logfile,">>$source".'.log')) {
2364: return (&mt('No write permission to Construction Space'));
2365: }
2366: print $logfile
2367: "\n================= Publish ".localtime()." ================\n".
2368: $env{'user.name'}.':'.$env{'user.domain'}."\n";
2369: # Save the file
2370: if (!open(FH,'>'.$source)) {
2371: &Apache::lonnet::logthis('Failed to create '.$source);
2372: return (&mt('Failed to create file'));
2373: }
2374: if ($action eq 'upload') {
2375: if (!print FH ($env{'form.'.$formname})) {
2376: &Apache::lonnet::logthis('Failed to write to '.$source);
2377: return (&mt('Failed to write file'));
2378: }
2379: } else {
2380: my $original = &Apache::lonnet::filelocation('',$formname);
2381: if(!copy($original,$source)) {
2382: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
2383: return (&mt('Failed to write file'));
2384: }
2385: }
2386: close(FH);
2387: chmod(0660, $source); # Permissions to rw-rw---.
2388:
2389: my $docroot=$r->dir_config('lonDocRoot');
2390: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
2391: my $copyfile=$targetdir.'/'.$file;
2392:
2393: my @parts=split(/\//,$targetdir);
2394: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
2395: for (my $count=5;$count<=$#parts;$count++) {
2396: $path.="/$parts[$count]";
2397: if (!-e $path) {
2398: print $logfile "\nCreating directory ".$path;
2399: mkdir($path,02770);
2400: }
2401: }
2402: my $versionresult;
2403: if (-e $copyfile) {
2404: $versionresult = &logo_versioning($targetdir,$file,$logfile);
2405: } else {
2406: $versionresult = 'ok';
2407: }
2408: if ($versionresult eq 'ok') {
2409: if (copy($source,$copyfile)) {
2410: print $logfile "\nCopied original source to ".$copyfile."\n";
2411: $output = 'ok';
2412: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
2413: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
2414: } else {
2415: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
2416: $output = &mt('Failed to copy file to RES space').", $!";
2417: }
2418: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
2419: my $inputfile = $filepath.'/'.$file;
2420: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 2421: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
2422: if ($fullwidth ne '' && $fullheight ne '') {
2423: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
2424: my $thumbsize = $thumbwidth.'x'.$thumbheight;
2425: system("convert -sample $thumbsize $inputfile $outfile");
2426: chmod(0660, $filepath.'/tn-'.$file);
2427: if (-e $outfile) {
2428: my $copyfile=$targetdir.'/tn-'.$file;
2429: if (copy($outfile,$copyfile)) {
2430: print $logfile "\nCopied source to ".$copyfile."\n";
2431: &write_metadata($dom,$confname,$formname,
2432: $targetdir,'tn-'.$file,$logfile);
2433: } else {
2434: print $logfile "\nUnable to write ".$copyfile.
2435: ':'.$!."\n";
2436: }
2437: }
1.9 raeburn 2438: }
2439: }
2440: }
2441: } else {
2442: $output = $versionresult;
2443: }
2444: }
2445: return ($output,$logourl);
2446: }
2447:
2448: sub logo_versioning {
2449: my ($targetdir,$file,$logfile) = @_;
2450: my $target = $targetdir.'/'.$file;
2451: my ($maxversion,$fn,$extn,$output);
2452: $maxversion = 0;
2453: if ($file =~ /^(.+)\.(\w+)$/) {
2454: $fn=$1;
2455: $extn=$2;
2456: }
2457: opendir(DIR,$targetdir);
2458: while (my $filename=readdir(DIR)) {
2459: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
2460: $maxversion=($1>$maxversion)?$1:$maxversion;
2461: }
2462: }
2463: $maxversion++;
2464: print $logfile "\nCreating old version ".$maxversion."\n";
2465: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
2466: if (copy($target,$copyfile)) {
2467: print $logfile "Copied old target to ".$copyfile."\n";
2468: $copyfile=$copyfile.'.meta';
2469: if (copy($target.'.meta',$copyfile)) {
2470: print $logfile "Copied old target metadata to ".$copyfile."\n";
2471: $output = 'ok';
2472: } else {
2473: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
2474: $output = &mt('Failed to copy old meta').", $!, ";
2475: }
2476: } else {
2477: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
2478: $output = &mt('Failed to copy old target').", $!, ";
2479: }
2480: return $output;
2481: }
2482:
2483: sub write_metadata {
2484: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
2485: my (%metadatafields,%metadatakeys,$output);
2486: $metadatafields{'title'}=$formname;
2487: $metadatafields{'creationdate'}=time;
2488: $metadatafields{'lastrevisiondate'}=time;
2489: $metadatafields{'copyright'}='public';
2490: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
2491: $env{'user.domain'};
2492: $metadatafields{'authorspace'}=$confname.':'.$dom;
2493: $metadatafields{'domain'}=$dom;
2494: {
2495: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
2496: my $mfh;
2497: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
2498: $output = &mt('Could not write metadata');
2499: }
2500: foreach (sort keys %metadatafields) {
2501: unless ($_=~/\./) {
2502: my $unikey=$_;
2503: $unikey=~/^([A-Za-z]+)/;
2504: my $tag=$1;
2505: $tag=~tr/A-Z/a-z/;
2506: print $mfh "\n\<$tag";
2507: foreach (split(/\,/,$metadatakeys{$unikey})) {
2508: my $value=$metadatafields{$unikey.'.'.$_};
2509: $value=~s/\"/\'\'/g;
2510: print $mfh ' '.$_.'="'.$value.'"';
2511: }
2512: print $mfh '>'.
2513: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
2514: .'</'.$tag.'>';
2515: }
2516: }
2517: $output = 'ok';
2518: print $logfile "\nWrote metadata";
2519: close($mfh);
2520: }
2521: }
2522:
2523: sub check_switchserver {
2524: my ($dom,$confname) = @_;
2525: my ($allowed,$switchserver);
2526: my $home = &Apache::lonnet::homeserver($confname,$dom);
2527: if ($home eq 'no_host') {
2528: $home = &Apache::lonnet::domain($dom,'primary');
2529: }
2530: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 2531: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2532: if (!$allowed) {
2533: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 2534: }
2535: return $switchserver;
2536: }
2537:
1.30 raeburn 2538: sub javascript_set_colnums {
2539: return <<END;
2540: function setDisplayColumns() {
2541: if (document.pickactions.width.value > 1100) {
2542: document.pickactions.numcols[1].checked = true;
2543: } else {
2544: document.pickactions.numcols[0].checked = true;
2545: }
2546: }
2547: END
2548: }
2549:
1.1 raeburn 2550: sub modify_quotas {
1.3 raeburn 2551: my ($dom,%domconfig) = @_;
1.1 raeburn 2552: my ($resulttext,%changes);
1.26 raeburn 2553: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2554: my %formhash;
2555: foreach my $key (keys(%env)) {
2556: if ($key =~ /^form\.quota_(.+)$/) {
2557: $formhash{$1} = $env{$key};
2558: }
2559: }
1.15 raeburn 2560: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 2561: if (ref($domconfig{'quotas'}) eq 'HASH') {
2562: foreach my $key (keys(%{$domconfig{'quotas'}})) {
2563: if (exists($formhash{$key})) {
2564: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
2565: $changes{$key} = 1;
2566: }
2567: } else {
2568: $formhash{$key} = $domconfig{'quotas'}{$key};
2569: }
2570: }
2571: }
2572: foreach my $key (keys(%formhash)) {
2573: if ($formhash{$key} ne '') {
1.3 raeburn 2574: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 2575: $changes{$key} = 1;
2576: }
2577: }
2578: }
2579: my %quotahash = (
1.3 raeburn 2580: quotas => {%formhash},
1.1 raeburn 2581: );
2582: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
2583: $dom);
2584: if ($putresult eq 'ok') {
2585: if (keys(%changes) > 0) {
2586: $resulttext = &mt('Changes made:').'<ul>';
1.26 raeburn 2587: foreach my $type (@{$types},'default') {
2588: if (defined($changes{$type})) {
2589: my $typetitle = $usertypes->{$type};
2590: if ($type eq 'default') {
2591: $typetitle = $othertitle;
2592: }
2593: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
2594: }
1.1 raeburn 2595: }
2596: $resulttext .= '</ul>';
2597: } else {
2598: $resulttext = &mt('No changes made to default quotas');
2599: }
2600: } else {
1.11 albertel 2601: $resulttext = '<span class="LC_error">'.
2602: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2603: }
1.3 raeburn 2604: return $resulttext;
1.1 raeburn 2605: }
2606:
1.3 raeburn 2607: sub modify_autoenroll {
2608: my ($dom,%domconfig) = @_;
1.1 raeburn 2609: my ($resulttext,%changes);
2610: my %currautoenroll;
2611: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
2612: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
2613: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
2614: }
2615: }
2616: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2617: my %title = ( run => 'Auto-enrollment active',
2618: sender => 'Sender for notification messages');
2619: my @offon = ('off','on');
1.17 raeburn 2620: my $sender_uname = $env{'form.sender_uname'};
2621: my $sender_domain = $env{'form.sender_domain'};
2622: if ($sender_domain eq '') {
2623: $sender_uname = '';
2624: } elsif ($sender_uname eq '') {
2625: $sender_domain = '';
2626: }
1.1 raeburn 2627: my %autoenrollhash = (
2628: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 2629: sender_uname => $sender_uname,
2630: sender_domain => $sender_domain,
1.1 raeburn 2631:
2632: }
2633: );
1.4 raeburn 2634: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
2635: $dom);
1.1 raeburn 2636: if ($putresult eq 'ok') {
2637: if (exists($currautoenroll{'run'})) {
2638: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
2639: $changes{'run'} = 1;
2640: }
2641: } elsif ($autorun) {
2642: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 2643: $changes{'run'} = 1;
1.1 raeburn 2644: }
2645: }
1.17 raeburn 2646: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 2647: $changes{'sender'} = 1;
2648: }
1.17 raeburn 2649: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 2650: $changes{'sender'} = 1;
2651: }
2652: if (keys(%changes) > 0) {
2653: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 2654: if ($changes{'run'}) {
1.1 raeburn 2655: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
2656: }
2657: if ($changes{'sender'}) {
1.17 raeburn 2658: if ($sender_uname eq '' || $sender_domain eq '') {
2659: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
2660: } else {
2661: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
2662: }
1.1 raeburn 2663: }
2664: $resulttext .= '</ul>';
2665: } else {
2666: $resulttext = &mt('No changes made to auto-enrollment settings');
2667: }
2668: } else {
1.11 albertel 2669: $resulttext = '<span class="LC_error">'.
2670: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2671: }
1.3 raeburn 2672: return $resulttext;
1.1 raeburn 2673: }
2674:
2675: sub modify_autoupdate {
1.3 raeburn 2676: my ($dom,%domconfig) = @_;
1.1 raeburn 2677: my ($resulttext,%currautoupdate,%fields,%changes);
2678: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
2679: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
2680: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
2681: }
2682: }
2683: my @offon = ('off','on');
2684: my %title = &Apache::lonlocal::texthash (
2685: run => 'Auto-update:',
2686: classlists => 'Updates to user information in classlists?'
2687: );
1.26 raeburn 2688: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2689: my %fieldtitles = &Apache::lonlocal::texthash (
2690: id => 'Student/Employee ID',
1.20 raeburn 2691: permanentemail => 'E-mail address',
1.1 raeburn 2692: lastname => 'Last Name',
2693: firstname => 'First Name',
2694: middlename => 'Middle Name',
2695: gen => 'Generation',
2696: );
2697: my $othertitle = &mt('All users');
2698: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 2699: $othertitle = &mt('Other users');
1.1 raeburn 2700: }
2701: foreach my $key (keys(%env)) {
2702: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
2703: push(@{$fields{$1}},$2);
2704: }
2705: }
2706: my %updatehash = (
2707: autoupdate => { run => $env{'form.autoupdate_run'},
2708: classlists => $env{'form.classlists'},
2709: fields => {%fields},
2710: }
2711: );
2712: foreach my $key (keys(%currautoupdate)) {
2713: if (($key eq 'run') || ($key eq 'classlists')) {
2714: if (exists($updatehash{autoupdate}{$key})) {
2715: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
2716: $changes{$key} = 1;
2717: }
2718: }
2719: } elsif ($key eq 'fields') {
2720: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 2721: foreach my $item (@{$types},'default') {
1.1 raeburn 2722: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
2723: my $change = 0;
2724: foreach my $type (@{$currautoupdate{$key}{$item}}) {
2725: if (!exists($fields{$item})) {
2726: $change = 1;
2727: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 2728: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 2729: $change = 1;
2730: }
2731: }
2732: }
2733: if ($change) {
2734: push(@{$changes{$key}},$item);
2735: }
1.26 raeburn 2736: }
1.1 raeburn 2737: }
2738: }
2739: }
2740: }
1.26 raeburn 2741: foreach my $item (@{$types},'default') {
2742: if (defined($fields{$item})) {
2743: if (ref($currautoupdate{'fields'}) eq 'HASH') {
2744: if (!exists($currautoupdate{'fields'}{$item})) {
2745: push(@{$changes{'fields'}},$item);
2746: }
2747: } else {
2748: push(@{$changes{'fields'}},$item);
1.1 raeburn 2749: }
2750: }
2751: }
2752: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
2753: $dom);
2754: if ($putresult eq 'ok') {
2755: if (keys(%changes) > 0) {
2756: $resulttext = &mt('Changes made:').'<ul>';
2757: foreach my $key (sort(keys(%changes))) {
2758: if (ref($changes{$key}) eq 'ARRAY') {
2759: foreach my $item (@{$changes{$key}}) {
2760: my @newvalues;
2761: foreach my $type (@{$fields{$item}}) {
2762: push(@newvalues,$fieldtitles{$type});
2763: }
1.3 raeburn 2764: my $newvaluestr;
2765: if (@newvalues > 0) {
2766: $newvaluestr = join(', ',@newvalues);
2767: } else {
2768: $newvaluestr = &mt('none');
1.6 raeburn 2769: }
1.1 raeburn 2770: if ($item eq 'default') {
1.26 raeburn 2771: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 2772: } else {
1.26 raeburn 2773: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 2774: }
2775: }
2776: } else {
2777: my $newvalue;
2778: if ($key eq 'run') {
2779: $newvalue = $offon[$env{'form.autoupdate_run'}];
2780: } else {
2781: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 2782: }
1.1 raeburn 2783: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
2784: }
2785: }
2786: $resulttext .= '</ul>';
2787: } else {
1.3 raeburn 2788: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 2789: }
2790: } else {
1.11 albertel 2791: $resulttext = '<span class="LC_error">'.
2792: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2793: }
1.3 raeburn 2794: return $resulttext;
1.1 raeburn 2795: }
2796:
1.23 raeburn 2797: sub modify_directorysrch {
2798: my ($dom,%domconfig) = @_;
2799: my ($resulttext,%changes);
2800: my %currdirsrch;
2801: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2802: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
2803: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
2804: }
2805: }
2806: my %title = ( available => 'Directory search available',
1.24 raeburn 2807: localonly => 'Other domains can search',
1.23 raeburn 2808: searchby => 'Search types',
2809: searchtypes => 'Search latitude');
2810: my @offon = ('off','on');
1.24 raeburn 2811: my @otherdoms = ('Yes','No');
1.23 raeburn 2812:
1.25 raeburn 2813: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 2814: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
2815: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
2816:
1.26 raeburn 2817: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
2818: if (keys(%{$usertypes}) == 0) {
2819: @cansearch = ('default');
2820: } else {
2821: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
2822: foreach my $type (@{$currdirsrch{'cansearch'}}) {
2823: if (!grep(/^\Q$type\E$/,@cansearch)) {
2824: push(@{$changes{'cansearch'}},$type);
2825: }
1.23 raeburn 2826: }
1.26 raeburn 2827: foreach my $type (@cansearch) {
2828: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
2829: push(@{$changes{'cansearch'}},$type);
2830: }
1.23 raeburn 2831: }
1.26 raeburn 2832: } else {
2833: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 2834: }
2835: }
2836:
2837: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
2838: foreach my $by (@{$currdirsrch{'searchby'}}) {
2839: if (!grep(/^\Q$by\E$/,@searchby)) {
2840: push(@{$changes{'searchby'}},$by);
2841: }
2842: }
2843: foreach my $by (@searchby) {
2844: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
2845: push(@{$changes{'searchby'}},$by);
2846: }
2847: }
2848: } else {
2849: push(@{$changes{'searchby'}},@searchby);
2850: }
1.25 raeburn 2851:
2852: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
2853: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
2854: if (!grep(/^\Q$type\E$/,@searchtypes)) {
2855: push(@{$changes{'searchtypes'}},$type);
2856: }
2857: }
2858: foreach my $type (@searchtypes) {
2859: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
2860: push(@{$changes{'searchtypes'}},$type);
2861: }
2862: }
2863: } else {
2864: if (exists($currdirsrch{'searchtypes'})) {
2865: foreach my $type (@searchtypes) {
2866: if ($type ne $currdirsrch{'searchtypes'}) {
2867: push(@{$changes{'searchtypes'}},$type);
2868: }
2869: }
2870: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
2871: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
2872: }
2873: } else {
2874: push(@{$changes{'searchtypes'}},@searchtypes);
2875: }
2876: }
2877:
1.23 raeburn 2878: my %dirsrch_hash = (
2879: directorysrch => { available => $env{'form.dirsrch_available'},
2880: cansearch => \@cansearch,
1.24 raeburn 2881: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 2882: searchby => \@searchby,
1.25 raeburn 2883: searchtypes => \@searchtypes,
1.23 raeburn 2884: }
2885: );
2886: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
2887: $dom);
2888: if ($putresult eq 'ok') {
2889: if (exists($currdirsrch{'available'})) {
2890: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
2891: $changes{'available'} = 1;
2892: }
2893: } else {
2894: if ($env{'form.dirsrch_available'} eq '1') {
2895: $changes{'available'} = 1;
2896: }
2897: }
1.24 raeburn 2898: if (exists($currdirsrch{'localonly'})) {
2899: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
2900: $changes{'localonly'} = 1;
2901: }
2902: } else {
2903: if ($env{'form.dirsrch_localonly'} eq '1') {
2904: $changes{'localonly'} = 1;
2905: }
2906: }
1.23 raeburn 2907: if (keys(%changes) > 0) {
2908: $resulttext = &mt('Changes made:').'<ul>';
2909: if ($changes{'available'}) {
2910: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
2911: }
1.24 raeburn 2912: if ($changes{'localonly'}) {
2913: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
2914: }
2915:
1.23 raeburn 2916: if (ref($changes{'cansearch'}) eq 'ARRAY') {
2917: my $chgtext;
1.26 raeburn 2918: if (ref($usertypes) eq 'HASH') {
2919: if (keys(%{$usertypes}) > 0) {
2920: foreach my $type (@{$types}) {
2921: if (grep(/^\Q$type\E$/,@cansearch)) {
2922: $chgtext .= $usertypes->{$type}.'; ';
2923: }
2924: }
2925: if (grep(/^default$/,@cansearch)) {
2926: $chgtext .= $othertitle;
2927: } else {
2928: $chgtext =~ s/\; $//;
2929: }
2930: $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 2931: }
2932: }
2933: }
2934: if (ref($changes{'searchby'}) eq 'ARRAY') {
2935: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2936: my $chgtext;
2937: foreach my $type (@{$titleorder}) {
2938: if (grep(/^\Q$type\E$/,@searchby)) {
2939: if (defined($searchtitles->{$type})) {
2940: $chgtext .= $searchtitles->{$type}.'; ';
2941: }
2942: }
2943: }
2944: $chgtext =~ s/\; $//;
2945: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
2946: }
1.25 raeburn 2947: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
2948: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
2949: my $chgtext;
2950: foreach my $type (@{$srchtypeorder}) {
2951: if (grep(/^\Q$type\E$/,@searchtypes)) {
2952: if (defined($srchtypes_desc->{$type})) {
2953: $chgtext .= $srchtypes_desc->{$type}.'; ';
2954: }
2955: }
2956: }
2957: $chgtext =~ s/\; $//;
2958: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 2959: }
2960: $resulttext .= '</ul>';
2961: } else {
2962: $resulttext = &mt('No changes made to institution directory search settings');
2963: }
2964: } else {
2965: $resulttext = '<span class="LC_error">'.
1.27 raeburn 2966: &mt('An error occurred: [_1]',$putresult).'</span>';
2967: }
2968: return $resulttext;
2969: }
2970:
1.28 raeburn 2971: sub modify_contacts {
2972: my ($dom,%domconfig) = @_;
2973: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
2974: if (ref($domconfig{'contacts'}) eq 'HASH') {
2975: foreach my $key (keys(%{$domconfig{'contacts'}})) {
2976: $currsetting{$key} = $domconfig{'contacts'}{$key};
2977: }
2978: }
2979: my (%others,%to);
2980: my @contacts = ('supportemail','adminemail');
2981: my @mailings = ('errormail','packagesmail','helpdeskmail');
2982: foreach my $type (@mailings) {
2983: @{$newsetting{$type}} =
2984: &Apache::loncommon::get_env_multiple('form.'.$type);
2985: foreach my $item (@contacts) {
2986: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
2987: $contacts_hash{contacts}{$type}{$item} = 1;
2988: } else {
2989: $contacts_hash{contacts}{$type}{$item} = 0;
2990: }
2991: }
2992: $others{$type} = $env{'form.'.$type.'_others'};
2993: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
2994: }
2995: foreach my $item (@contacts) {
2996: $to{$item} = $env{'form.'.$item};
2997: $contacts_hash{'contacts'}{$item} = $to{$item};
2998: }
2999: if (keys(%currsetting) > 0) {
3000: foreach my $item (@contacts) {
3001: if ($to{$item} ne $currsetting{$item}) {
3002: $changes{$item} = 1;
3003: }
3004: }
3005: foreach my $type (@mailings) {
3006: foreach my $item (@contacts) {
3007: if (ref($currsetting{$type}) eq 'HASH') {
3008: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
3009: push(@{$changes{$type}},$item);
3010: }
3011: } else {
3012: push(@{$changes{$type}},@{$newsetting{$type}});
3013: }
3014: }
3015: if ($others{$type} ne $currsetting{$type}{'others'}) {
3016: push(@{$changes{$type}},'others');
3017: }
3018: }
3019: } else {
3020: my %default;
3021: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3022: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3023: $default{'errormail'} = 'adminemail';
3024: $default{'packagesmail'} = 'adminemail';
3025: $default{'helpdeskmail'} = 'supportemail';
3026: foreach my $item (@contacts) {
3027: if ($to{$item} ne $default{$item}) {
3028: $changes{$item} = 1;
3029: }
3030: }
3031: foreach my $type (@mailings) {
3032: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
3033:
3034: push(@{$changes{$type}},@{$newsetting{$type}});
3035: }
3036: if ($others{$type} ne '') {
3037: push(@{$changes{$type}},'others');
3038: }
3039: }
3040: }
3041: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
3042: $dom);
3043: if ($putresult eq 'ok') {
3044: if (keys(%changes) > 0) {
3045: my ($titles,$short_titles) = &contact_titles();
3046: $resulttext = &mt('Changes made:').'<ul>';
3047: foreach my $item (@contacts) {
3048: if ($changes{$item}) {
3049: $resulttext .= '<li>'.$titles->{$item}.
3050: &mt(' set to: ').
3051: '<span class="LC_cusr_emph">'.
3052: $to{$item}.'</span></li>';
3053: }
3054: }
3055: foreach my $type (@mailings) {
3056: if (ref($changes{$type}) eq 'ARRAY') {
3057: $resulttext .= '<li>'.$titles->{$type}.': ';
3058: my @text;
3059: foreach my $item (@{$newsetting{$type}}) {
3060: push(@text,$short_titles->{$item});
3061: }
3062: if ($others{$type} ne '') {
3063: push(@text,$others{$type});
3064: }
3065: $resulttext .= '<span class="LC_cusr_emph">'.
3066: join(', ',@text).'</span></li>';
3067: }
3068: }
3069: $resulttext .= '</ul>';
3070: } else {
1.34 raeburn 3071: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 3072: }
3073: } else {
3074: $resulttext = '<span class="LC_error">'.
3075: &mt('An error occurred: [_1].',$putresult).'</span>';
3076: }
3077: return $resulttext;
3078: }
3079:
3080: sub modify_usercreation {
1.27 raeburn 3081: my ($dom,%domconfig) = @_;
1.34 raeburn 3082: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.27 raeburn 3083: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3084: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
3085: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
3086: }
3087: }
3088: my %title = &Apache::lonlocal::texthash (
3089: author => 'adding co-authors/assistant authors',
3090: course => 'adding users to a course',
3091: );
3092: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 3093: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.34 raeburn 3094: my @contexts = ('author','course');
3095: foreach my $item(@contexts) {
3096: $cancreate{$item} = $env{'form.can_createuser_'.$item};
3097: }
3098: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
3099: foreach my $item (@contexts) {
3100: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
3101: push(@{$changes{'cancreate'}},$item);
3102: }
1.27 raeburn 3103: }
1.34 raeburn 3104: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
3105: foreach my $item (@contexts) {
3106: if (grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
3107: if ($cancreate{$item} ne 'any') {
3108: push(@{$changes{'cancreate'}},$item);
3109: }
3110: } else {
3111: if ($cancreate{$item} ne 'none') {
3112: push(@{$changes{'cancreate'}},$item);
3113: }
1.27 raeburn 3114: }
3115: }
3116: } else {
1.34 raeburn 3117: foreach my $item ('author','course') {
3118: push(@{$changes{'cancreate'}},$item);
3119: }
1.27 raeburn 3120: }
1.34 raeburn 3121:
1.27 raeburn 3122: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
3123: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
3124: if (!grep(/^\Q$type\E$/,@username_rule)) {
3125: push(@{$changes{'username_rule'}},$type);
3126: }
3127: }
3128: foreach my $type (@username_rule) {
3129: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
3130: push(@{$changes{'username_rule'}},$type);
3131: }
3132: }
3133: } else {
3134: push(@{$changes{'username_rule'}},@username_rule);
3135: }
3136:
1.32 raeburn 3137: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
3138: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
3139: if (!grep(/^\Q$type\E$/,@id_rule)) {
3140: push(@{$changes{'id_rule'}},$type);
3141: }
3142: }
3143: foreach my $type (@id_rule) {
3144: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
3145: push(@{$changes{'id_rule'}},$type);
3146: }
3147: }
3148: } else {
3149: push(@{$changes{'id_rule'}},@id_rule);
3150: }
3151:
1.28 raeburn 3152: my @contexts = ('author','course','domain');
3153: my @authtypes = ('int','krb4','krb5','loc');
3154: my %authhash;
3155: foreach my $item (@contexts) {
3156: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
3157: foreach my $auth (@authtypes) {
3158: if (grep(/^\Q$auth\E$/,@authallowed)) {
3159: $authhash{$item}{$auth} = 1;
3160: } else {
3161: $authhash{$item}{$auth} = 0;
3162: }
3163: }
3164: }
3165: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
3166: foreach my $item (@contexts) {
3167: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
3168: foreach my $auth (@authtypes) {
3169: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
3170: push(@{$changes{'authtypes'}},$item);
3171: last;
3172: }
3173: }
3174: }
3175: }
3176: } else {
3177: foreach my $item (@contexts) {
3178: push(@{$changes{'authtypes'}},$item);
3179: }
3180: }
3181:
1.27 raeburn 3182: my %usercreation_hash = (
1.28 raeburn 3183: usercreation => {
1.34 raeburn 3184: cancreate => \%cancreate,
1.27 raeburn 3185: username_rule => \@username_rule,
1.32 raeburn 3186: id_rule => \@id_rule,
3187: authtypes => \%authhash,
1.27 raeburn 3188: }
3189: );
3190:
3191: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
3192: $dom);
3193: if ($putresult eq 'ok') {
3194: if (keys(%changes) > 0) {
3195: $resulttext = &mt('Changes made:').'<ul>';
3196: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 3197: my %lt = &usercreation_types();
3198: foreach my $type (@{$changes{'cancreate'}}) {
3199: my $chgtext;
3200: if ($cancreate{$type} eq 'none') {
3201: $chgtext = $lt{$type}.' '.&mt('creation of new users is not permitted, except by a Domain Coordinator.');
3202: } elsif ($cancreate{$type} eq 'any') {
3203: $chgtext = $lt{$type}.' '.&mt('creation of new users is permitted for both institutional and non-institutional usernames.');
3204: } elsif ($cancreate{$type} eq 'official') {
3205: $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for institutional usernames.',$lt{$type});
3206: } elsif ($cancreate{$type} eq 'unofficial') {
3207: $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for non-institutional usernames.',$lt{$type});
3208: }
3209: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 3210: }
3211: }
3212: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 3213: my ($rules,$ruleorder) =
3214: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 3215: my $chgtext = '<ul>';
3216: foreach my $type (@username_rule) {
3217: if (ref($rules->{$type}) eq 'HASH') {
3218: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
3219: }
3220: }
3221: $chgtext .= '</ul>';
3222: if (@username_rule > 0) {
3223: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3224: } else {
1.28 raeburn 3225: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 3226: }
3227: }
1.32 raeburn 3228: if (ref($changes{'id_rule'}) eq 'ARRAY') {
3229: my ($idrules,$idruleorder) =
3230: &Apache::lonnet::inst_userrules($dom,'id');
3231: my $chgtext = '<ul>';
3232: foreach my $type (@id_rule) {
3233: if (ref($idrules->{$type}) eq 'HASH') {
3234: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
3235: }
3236: }
3237: $chgtext .= '</ul>';
3238: if (@id_rule > 0) {
3239: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3240: } else {
3241: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
3242: }
3243: }
1.28 raeburn 3244: my %authname = &authtype_names();
3245: my %context_title = &context_names();
3246: if (ref($changes{'authtypes'}) eq 'ARRAY') {
3247: my $chgtext = '<ul>';
3248: foreach my $type (@{$changes{'authtypes'}}) {
3249: my @allowed;
3250: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
3251: foreach my $auth (@authtypes) {
3252: if ($authhash{$type}{$auth}) {
3253: push(@allowed,$authname{$auth});
3254: }
3255: }
3256: $chgtext .= join(', ',@allowed).'</li>';
3257: }
3258: $chgtext .= '</ul>';
3259: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
3260: $resulttext .= '</li>';
3261: }
1.27 raeburn 3262: $resulttext .= '</ul>';
3263: } else {
1.28 raeburn 3264: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 3265: }
3266: } else {
3267: $resulttext = '<span class="LC_error">'.
1.23 raeburn 3268: &mt('An error occurred: [_1]',$putresult).'</span>';
3269: }
3270: return $resulttext;
3271: }
3272:
1.33 raeburn 3273: sub modify_usermodification {
3274: my ($dom,%domconfig) = @_;
3275: my ($resulttext,%curr_usermodification,%changes);
3276: if (ref($domconfig{'usermodification'}) eq 'HASH') {
3277: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
3278: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
3279: }
3280: }
3281: my @contexts = ('author','course');
3282: my %context_title = (
3283: author => 'In author context',
3284: course => 'In course context',
3285: );
3286: my @fields = ('lastname','firstname','middlename','generation',
3287: 'permanentemail','id');
3288: my %roles = (
3289: author => ['ca','aa'],
3290: course => ['st','ep','ta','in','cr'],
3291: );
3292: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3293: my %modifyhash;
3294: foreach my $context (@contexts) {
3295: foreach my $role (@{$roles{$context}}) {
3296: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
3297: foreach my $item (@fields) {
3298: if (grep(/^\Q$item\E$/,@modifiable)) {
3299: $modifyhash{$context}{$role}{$item} = 1;
3300: } else {
3301: $modifyhash{$context}{$role}{$item} = 0;
3302: }
3303: }
3304: }
3305: if (ref($curr_usermodification{$context}) eq 'HASH') {
3306: foreach my $role (@{$roles{$context}}) {
3307: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
3308: foreach my $field (@fields) {
3309: if ($modifyhash{$context}{$role}{$field} ne
3310: $curr_usermodification{$context}{$role}{$field}) {
3311: push(@{$changes{$context}},$role);
3312: last;
3313: }
3314: }
3315: }
3316: }
3317: } else {
3318: foreach my $context (@contexts) {
3319: foreach my $role (@{$roles{$context}}) {
3320: push(@{$changes{$context}},$role);
3321: }
3322: }
3323: }
3324: }
3325: my %usermodification_hash = (
3326: usermodification => \%modifyhash,
3327: );
3328: my $putresult = &Apache::lonnet::put_dom('configuration',
3329: \%usermodification_hash,$dom);
3330: if ($putresult eq 'ok') {
3331: if (keys(%changes) > 0) {
3332: $resulttext = &mt('Changes made: ').'<ul>';
3333: foreach my $context (@contexts) {
3334: if (ref($changes{$context}) eq 'ARRAY') {
3335: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
3336: if (ref($changes{$context}) eq 'ARRAY') {
3337: foreach my $role (@{$changes{$context}}) {
3338: my $rolename;
3339: if ($role eq 'cr') {
3340: $rolename = &mt('Custom');
3341: } else {
3342: $rolename = &Apache::lonnet::plaintext($role);
3343: }
3344: my @modifiable;
3345: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
3346: foreach my $field (@fields) {
3347: if ($modifyhash{$context}{$role}{$field}) {
3348: push(@modifiable,$fieldtitles{$field});
3349: }
3350: }
3351: if (@modifiable > 0) {
3352: $resulttext .= join(', ',@modifiable);
3353: } else {
3354: $resulttext .= &mt('none');
3355: }
3356: $resulttext .= '</li>';
3357: }
3358: $resulttext .= '</ul></li>';
3359: }
3360: }
3361: }
3362: $resulttext .= '</ul>';
3363: } else {
3364: $resulttext = &mt('No changes made to user modification settings');
3365: }
3366: } else {
3367: $resulttext = '<span class="LC_error">'.
3368: &mt('An error occurred: [_1]',$putresult).'</span>';
3369: }
3370: return $resulttext;
3371: }
3372:
1.3 raeburn 3373: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>