Annotation of loncom/interface/domainprefs.pm, revision 1.89
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.89 ! raeburn 4: # $Id: domainprefs.pm,v 1.88 2009/02/10 18:01:40 bisitz Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
31: package Apache::domainprefs;
32:
33: use strict;
34: use Apache::Constants qw(:common :http);
35: use Apache::lonnet;
36: use Apache::loncommon();
37: use Apache::lonhtmlcommon();
38: use Apache::lonlocal;
1.43 raeburn 39: use Apache::lonmsg();
1.69 raeburn 40: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 41: use LONCAPA::Enrollment;
1.81 raeburn 42: use LONCAPA::lonauthcgi();
1.9 raeburn 43: use File::Copy;
1.43 raeburn 44: use Locale::Language;
1.62 raeburn 45: use DateTime::TimeZone;
1.68 raeburn 46: use DateTime::Locale;
1.1 raeburn 47:
48: sub handler {
49: my $r=shift;
50: if ($r->header_only) {
51: &Apache::loncommon::content_type($r,'text/html');
52: $r->send_http_header;
53: return OK;
54: }
55:
56: my $dom = $env{'request.role.domain'};
1.5 albertel 57: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 58: if (&Apache::lonnet::allowed('mau',$dom)) {
59: &Apache::loncommon::content_type($r,'text/html');
60: $r->send_http_header;
61: } else {
62: $env{'user.error.msg'}=
63: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
64: return HTTP_NOT_ACCEPTABLE;
65: }
66: &Apache::lonhtmlcommon::clear_breadcrumbs();
67: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 68: ['phase','actions']);
1.30 raeburn 69: my $phase = 'pickactions';
1.3 raeburn 70: if ( exists($env{'form.phase'}) ) {
71: $phase = $env{'form.phase'};
72: }
73: my %domconfig =
1.6 raeburn 74: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.27 raeburn 75: 'quotas','autoenroll','autoupdate','directorysrch',
1.48 raeburn 76: 'usercreation','usermodification','contacts','defaults',
1.86 raeburn 77: 'scantron','coursecategories','serverstatuses',
78: 'requestcourses'],$dom);
1.43 raeburn 79: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.30 raeburn 80: 'autoupdate','directorysrch','contacts',
1.48 raeburn 81: 'usercreation','usermodification','scantron',
1.86 raeburn 82: 'requestcourses','coursecategories','serverstatuses');
1.30 raeburn 83: my %prefs = (
84: 'rolecolors' =>
85: { text => 'Default color schemes',
1.67 raeburn 86: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 87: header => [{col1 => 'Student Settings',
88: col2 => '',},
89: {col1 => 'Coordinator Settings',
90: col2 => '',},
91: {col1 => 'Author Settings',
92: col2 => '',},
93: {col1 => 'Administrator Settings',
94: col2 => '',}],
95: },
96: 'login' =>
97: { text => 'Log-in page options',
1.67 raeburn 98: help => 'Domain_Configuration_Login_Page',
1.30 raeburn 99: header => [{col1 => 'Item',
100: col2 => '',}],
101: },
1.43 raeburn 102: 'defaults' =>
1.54 raeburn 103: { text => 'Default authentication/language/timezone',
1.67 raeburn 104: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 105: header => [{col1 => 'Setting',
106: col2 => 'Value'}],
107: },
1.30 raeburn 108: 'quotas' =>
1.72 raeburn 109: { text => 'User blogs, home pages and portfolios',
1.67 raeburn 110: help => 'Domain_Configuration_Quotas',
1.77 raeburn 111: header => [{col1 => 'User affiliation',
1.72 raeburn 112: col2 => 'Available tools',
113: col3 => 'Portfolio quota',}],
1.30 raeburn 114: },
115: 'autoenroll' =>
116: { text => 'Auto-enrollment settings',
1.67 raeburn 117: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 118: header => [{col1 => 'Configuration setting',
119: col2 => 'Value(s)'}],
120: },
121: 'autoupdate' =>
122: { text => 'Auto-update settings',
1.67 raeburn 123: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 124: header => [{col1 => 'Setting',
125: col2 => 'Value',},
1.43 raeburn 126: {col1 => 'User population',
1.30 raeburn 127: col2 => 'Updataeable user data'}],
128: },
129: 'directorysrch' =>
130: { text => 'Institutional directory searches',
1.67 raeburn 131: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 132: header => [{col1 => 'Setting',
133: col2 => 'Value',}],
134: },
135: 'contacts' =>
136: { text => 'Contact Information',
1.67 raeburn 137: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 138: header => [{col1 => 'Setting',
139: col2 => 'Value',}],
140: },
141:
142: 'usercreation' =>
143: { text => 'User creation',
1.67 raeburn 144: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 145: header => [{col1 => 'Format rule type',
146: col2 => 'Format rules in force'},
1.34 raeburn 147: {col1 => 'User account creation',
148: col2 => 'Usernames which may be created',},
1.30 raeburn 149: {col1 => 'Context',
1.43 raeburn 150: col2 => 'Assignable authentication types'}],
1.30 raeburn 151: },
1.69 raeburn 152: 'usermodification' =>
1.33 raeburn 153: { text => 'User modification',
1.67 raeburn 154: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 155: header => [{col1 => 'Target user has role',
156: col2 => 'User information updateable in author context'},
157: {col1 => 'Target user has role',
1.63 raeburn 158: col2 => 'User information updateable in course context'},
159: {col1 => "Status of user",
160: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 161: },
1.69 raeburn 162: 'scantron' =>
1.46 raeburn 163: { text => 'Scantron format file',
1.67 raeburn 164: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 165: header => [ {col1 => 'Item',
166: col2 => '',
167: }],
168: },
1.86 raeburn 169: 'requestcourses' =>
170: {text => 'Request creation of courses',
171: help => 'Domain_Configuration_Request_Courses',
172: header => [{col1 => 'User affiliation',
173: col2 => 'Requestable course types',}],
174: },
1.69 raeburn 175: 'coursecategories' =>
1.48 raeburn 176: { text => 'Cataloging of courses',
1.67 raeburn 177: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 178: header => [{col1 => 'Category settings',
1.57 raeburn 179: col2 => '',},
180: {col1 => 'Categories',
181: col2 => '',
182: }],
1.69 raeburn 183: },
184: 'serverstatuses' =>
1.77 raeburn 185: {text => 'Access to server status pages',
1.69 raeburn 186: help => 'Domain_Configuration_Server_Status',
187: header => [{col1 => 'Status Page',
188: col2 => 'Other named users',
189: col3 => 'Specific IPs',
190: }],
191: },
1.3 raeburn 192: );
1.6 raeburn 193: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 194: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 195: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 196: ({href=>"javascript:changePage(document.$phase,'pickactions')",
197: text=>"Pick functionality"});
1.9 raeburn 198: my $confname = $dom.'-domainconfig';
1.3 raeburn 199: if ($phase eq 'process') {
1.1 raeburn 200: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 201: ({href=>"javascript:changePage(document.$phase,'display')",
202: text=>"Domain Configuration"},
203: {href=>"javascript:changePage(document.$phase,'$phase')",
1.3 raeburn 204: text=>"Updated"});
205: &print_header($r,$phase);
1.30 raeburn 206: foreach my $item (@prefs_order) {
207: if (grep(/^\Q$item\E$/,@actions)) {
208: $r->print('<h3>'.&mt($prefs{$item}{'text'}).'</h3>'.
209: &process_changes($r,$dom,$confname,$item,
210: \@roles,%domconfig));
211: }
1.3 raeburn 212: }
213: $r->print('<p>');
1.30 raeburn 214: &print_footer($r,$phase,'display','Back to configuration display',
215: \@actions);
1.3 raeburn 216: $r->print('</p>');
1.30 raeburn 217: } elsif ($phase eq 'display') {
218: &Apache::lonhtmlcommon::add_breadcrumb
219: ({href=>"javascript:changePage(document.$phase,'display')",
220: text=>"Domain Configuration"});
221: &print_header($r,$phase);
222: if (@actions > 0) {
223: my $rowsum = 0;
224: my (%output,%rowtotal,@items);
225: my $halfway = @actions/2;
226: foreach my $item (@prefs_order) {
227: if (grep(/^\Q$item\E$/,@actions)) {
228: push(@items,$item);
229: ($output{$item},$rowtotal{$item}) =
230: &print_config_box($r,$dom,$confname,$phase,
231: $item,$prefs{$item},
232: $domconfig{$item});
233: $rowsum += $rowtotal{$item};
234: }
235: }
236: my $colend;
237: my $halfway = $rowsum/2;
238: my $aggregate = 0;
239: my $sumleft = 0;
240: my $sumright = 0;
241: my $crossover;
242: for (my $i=0; $i<@items; $i++) {
243: $aggregate += $rowtotal{$items[$i]};
244: if ($aggregate > $halfway) {
245: $crossover = $i;
246: last;
247: }
248: }
249: for (my $i=0; $i<$crossover; $i++) {
250: $sumleft += $rowtotal{$items[$i]};
251: }
252: for (my $i=$crossover+1; $i<@items; $i++) {
253: $sumright += $rowtotal{$items[$i]};
254: }
255: if ((@items > 1) && ($env{'form.numcols'} == 2)) {
256: my $sumdiff = $sumright - $sumleft;
257: if ($sumdiff > 0) {
258: $colend = $crossover + 1;
259: } else {
260: $colend = $crossover;
261: }
262: } else {
263: $colend = @items;
264: }
265: $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');
266: for (my $i=0; $i<$colend; $i++) {
267: $r->print($output{$items[$i]});
268: }
269: $r->print('</td><td></td><td class="LC_right_col">');
270: if ($colend < @items) {
271: for (my $i=$colend; $i<@items; $i++) {
272: $r->print($output{$items[$i]});
273: }
274: }
275: $r->print('</td></tr></table></p>');
276: $r->print(&print_footer($r,$phase,'process','Save',\@actions));
277: } else {
278: $r->print('<input type="hidden" name="phase" value="" />'.
279: '<input type="hidden" name="numcols" value="'.
280: $env{'form.numcols'}.'" />'."\n".
1.75 bisitz 281: '<span class="LC_error">'.&mt('No settings chosen').
1.30 raeburn 282: '</span>');
283: }
284: $r->print('</form>');
285: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 286: } else {
1.3 raeburn 287: if ($phase eq '') {
1.30 raeburn 288: $phase = 'pickactions';
1.1 raeburn 289: }
1.30 raeburn 290: my %helphash;
1.3 raeburn 291: &print_header($r,$phase);
1.21 raeburn 292: if (keys(%domconfig) == 0) {
293: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 294: my @ids=&Apache::lonnet::current_machine_ids();
295: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 296: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 297: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 298: my $custom_img_count = 0;
299: foreach my $img (@loginimages) {
300: if ($designhash{$dom.'.login.'.$img} ne '') {
301: $custom_img_count ++;
302: }
303: }
304: foreach my $role (@roles) {
305: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
306: $custom_img_count ++;
307: }
308: }
309: if ($custom_img_count > 0) {
310: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 311: $r->print(
312: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
313: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
314: &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 />'.
315: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
316: if ($switch_server) {
1.30 raeburn 317: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 318: }
1.21 raeburn 319: return OK;
320: }
321: }
322: }
1.30 raeburn 323: $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');
324: $r->print('<script type="text/javascript">'."\n".
325: &Apache::loncommon::check_uncheck_jscript()."\n".
1.56 bisitz 326: '</script>'."\n".'<p><input type="button" value="'.&mt('check all').'" '.
1.30 raeburn 327: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
328: ' /> '.
1.56 bisitz 329: '<input type="button" value="'.&mt('uncheck all').'" '.
1.30 raeburn 330: 'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
1.38 raeburn 331: ' /></p><div class="LC_left_float">');
332: my ($numitems,$midpoint,$seconddiv,$count);
333: $numitems = @prefs_order;
334: $midpoint = int($numitems/2);
335: if ($numitems%2) {
336: $midpoint ++;
337: }
338: $count = 0;
1.30 raeburn 339: foreach my $item (@prefs_order) {
1.66 raeburn 340: $r->print('<h4>'.
341: &Apache::loncommon::help_open_topic($prefs{$item}->{'help'}).
342: '<label><input type="checkbox" name="actions" value="'.$item.
343: '" /> '.&mt($prefs{$item}->{'text'}).'</label></h4>');
1.38 raeburn 344: $count ++;
345: if ((!$seconddiv) && ($count >= $midpoint)) {
346: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
347: $seconddiv = 1;
348: }
1.30 raeburn 349: }
1.38 raeburn 350: $r->print('</div><div class="LC_clear_float_footer"></div><h3>'.
351: &mt('Display options').'</h3>'."\n".
1.30 raeburn 352: '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
1.48 raeburn 353: '<label><input type="radio" name="numcols" value="1" />'.
354: &mt('one column').'</label> <label>'.
355: '<input type="radio" name="numcols" value="2" />'.
1.30 raeburn 356: &mt('two columns').'</label></span></p>');
357: $r->print(&print_footer($r,$phase,'display','Go'));
358: $r->print('</form>');
359: $r->print(&Apache::loncommon::end_page());
1.3 raeburn 360: }
361: return OK;
362: }
363:
364: sub process_changes {
1.9 raeburn 365: my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
1.3 raeburn 366: my $output;
367: if ($action eq 'login') {
1.9 raeburn 368: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 369: } elsif ($action eq 'rolecolors') {
1.9 raeburn 370: $output = &modify_rolecolors($r,$dom,$confname,$roles,
371: %domconfig);
1.3 raeburn 372: } elsif ($action eq 'quotas') {
1.86 raeburn 373: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 374: } elsif ($action eq 'autoenroll') {
375: $output = &modify_autoenroll($dom,%domconfig);
376: } elsif ($action eq 'autoupdate') {
377: $output = &modify_autoupdate($dom,%domconfig);
1.23 raeburn 378: } elsif ($action eq 'directorysrch') {
379: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 380: } elsif ($action eq 'usercreation') {
1.28 raeburn 381: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 382: } elsif ($action eq 'usermodification') {
383: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 384: } elsif ($action eq 'contacts') {
385: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 386: } elsif ($action eq 'defaults') {
387: $output = &modify_defaults($dom,$r);
1.46 raeburn 388: } elsif ($action eq 'scantron') {
1.48 raeburn 389: $output = &modify_scantron($r,$dom,$confname,%domconfig);
390: } elsif ($action eq 'coursecategories') {
391: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 392: } elsif ($action eq 'serverstatuses') {
393: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 394: } elsif ($action eq 'requestcourses') {
395: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 396: }
397: return $output;
398: }
399:
400: sub print_config_box {
1.9 raeburn 401: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 402: my $rowtotal = 0;
1.49 raeburn 403: my $output;
404: if ($action eq 'coursecategories') {
405: $output = &coursecategories_javascript($settings);
406: }
407: $output .=
1.30 raeburn 408: '<table class="LC_nested_outer">
1.3 raeburn 409: <tr>
1.66 raeburn 410: <th align="left" valign="middle"><span class="LC_nobreak">'.
411: &mt($item->{text}).' '.
412: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
413: '</tr>';
1.30 raeburn 414: $rowtotal ++;
1.28 raeburn 415: if (($action eq 'autoupdate') || ($action eq 'rolecolors') ||
1.57 raeburn 416: ($action eq 'usercreation') || ($action eq 'usermodification') ||
417: ($action eq 'coursecategories')) {
1.64 raeburn 418: my $colspan = '';
419: if (($action eq 'rolecolors') || ($action eq 'coursecategories')) {
420: $colspan = ' colspan="2"';
421: }
1.30 raeburn 422: $output .= '
1.3 raeburn 423: <tr>
424: <td>
425: <table class="LC_nested">
426: <tr class="LC_info_row">
1.59 bisitz 427: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
428: <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 429: </tr>';
1.69 raeburn 430: $rowtotal ++;
1.6 raeburn 431: if ($action eq 'autoupdate') {
1.30 raeburn 432: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 433: } elsif ($action eq 'usercreation') {
1.33 raeburn 434: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
435: } elsif ($action eq 'usermodification') {
436: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 437: } elsif ($action eq 'coursecategories') {
438: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.6 raeburn 439: } else {
1.30 raeburn 440: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 441: }
1.30 raeburn 442: $output .= '
1.6 raeburn 443: </table>
444: </td>
445: </tr>
446: <tr>
447: <td>
448: <table class="LC_nested">
449: <tr class="LC_info_row">
1.59 bisitz 450: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 451: $output .= '
1.59 bisitz 452: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 453: </tr>';
454: $rowtotal ++;
1.6 raeburn 455: if ($action eq 'autoupdate') {
1.30 raeburn 456: $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
1.28 raeburn 457: } elsif ($action eq 'usercreation') {
1.34 raeburn 458: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
459: </table>
460: </td>
461: </tr>
462: <tr>
463: <td>
464: <table class="LC_nested">
465: <tr class="LC_info_row">
1.59 bisitz 466: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
467: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 468: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
469: $rowtotal ++;
1.33 raeburn 470: } elsif ($action eq 'usermodification') {
1.63 raeburn 471: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
472: </table>
473: </td>
474: </tr>
475: <tr>
476: <td>
477: <table class="LC_nested">
478: <tr class="LC_info_row">
479: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
480: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
481:
482: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
483: $rowtotal ++;
1.57 raeburn 484: } elsif ($action eq 'coursecategories') {
485: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.6 raeburn 486: } else {
1.30 raeburn 487: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 488: </table>
489: </td>
490: </tr>
491: <tr>
492: <td>
493: <table class="LC_nested">
494: <tr class="LC_info_row">
1.69 raeburn 495: <td class="LC_left_item"'.$colspan.' valign="top">'.
496: &mt($item->{'header'}->[2]->{'col1'}).'</td>
497: <td class="LC_right_item" valign="top">'.
498: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 499: </tr>'.
1.30 raeburn 500: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 501: </table>
502: </td>
503: </tr>
504: <tr>
505: <td>
506: <table class="LC_nested">
507: <tr class="LC_info_row">
1.59 bisitz 508: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
509: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 510: </tr>'.
1.30 raeburn 511: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
512: $rowtotal += 2;
1.6 raeburn 513: }
1.3 raeburn 514: } else {
1.30 raeburn 515: $output .= '
1.3 raeburn 516: <tr>
517: <td>
518: <table class="LC_nested">
1.30 raeburn 519: <tr class="LC_info_row">';
1.24 raeburn 520: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 521: $output .= '
1.59 bisitz 522: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 523: } elsif ($action eq 'serverstatuses') {
524: $output .= '
525: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
526: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
527:
1.6 raeburn 528: } else {
1.30 raeburn 529: $output .= '
1.69 raeburn 530: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
531: }
1.72 raeburn 532: if (defined($item->{'header'}->[0]->{'col3'})) {
533: $output .= '<td class="LC_left_item" valign="top">'.
534: &mt($item->{'header'}->[0]->{'col2'});
535: if ($action eq 'serverstatuses') {
536: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
537: }
1.69 raeburn 538: } else {
539: $output .= '<td class="LC_right_item" valign="top">'.
540: &mt($item->{'header'}->[0]->{'col2'});
541: }
542: $output .= '</td>';
543: if ($item->{'header'}->[0]->{'col3'}) {
544: $output .= '<td class="LC_right_item" valign="top">'.
545: &mt($item->{'header'}->[0]->{'col3'});
546: if ($action eq 'serverstatuses') {
547: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
548: }
549: $output .= '</td>';
1.6 raeburn 550: }
1.69 raeburn 551: $output .= '</tr>';
1.48 raeburn 552: $rowtotal ++;
1.3 raeburn 553: if ($action eq 'login') {
1.30 raeburn 554: $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
1.3 raeburn 555: } elsif ($action eq 'quotas') {
1.86 raeburn 556: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 557: } elsif ($action eq 'autoenroll') {
1.30 raeburn 558: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.23 raeburn 559: } elsif ($action eq 'directorysrch') {
1.30 raeburn 560: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 561: } elsif ($action eq 'contacts') {
1.30 raeburn 562: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 563: } elsif ($action eq 'defaults') {
564: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 565: } elsif ($action eq 'scantron') {
566: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 567: } elsif ($action eq 'serverstatuses') {
568: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.86 raeburn 569: } elsif ($action eq 'requestcourses') {
570: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.27 raeburn 571: }
1.3 raeburn 572: }
1.30 raeburn 573: $output .= '
1.3 raeburn 574: </table>
575: </td>
576: </tr>
1.30 raeburn 577: </table><br />';
578: return ($output,$rowtotal);
1.1 raeburn 579: }
580:
581: sub print_header {
1.3 raeburn 582: my ($r,$phase) = @_;
1.30 raeburn 583: my $alert = &mt('You must select at least one functionality type to display.');
1.6 raeburn 584: my $js = '
1.1 raeburn 585: <script type="text/javascript">
586: function changePage(formname,newphase) {
587: formname.phase.value = newphase;
1.30 raeburn 588: numchecked = 0;
589: if (formname == document.pickactions) {
590: if (formname.actions.length > 0) {
1.48 raeburn 591: for (var i = 0; i<formname.actions.length; i++) {
1.30 raeburn 592: if (formname.actions[i].checked) {
593: numchecked ++;
594: }
595: }
596: } else {
597: if (formname.actions.checked) {
598: numchecked ++;
599: }
600: }
601: if (numchecked > 0) {
602: formname.submit();
603: } else {
604: alert("'.$alert.'");
605: return;
606: }
607: }
1.1 raeburn 608: formname.submit();
1.30 raeburn 609: }'."\n";
610: if ($phase eq 'pickactions') {
611: $js .=
612: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox',numcols => 'radio',})."\n".
613: &javascript_set_colnums();
614: } elsif ($phase eq 'display') {
615: $js .= &color_pick_js()."\n";
616: }
1.31 raeburn 617: $js .= &Apache::loncommon::viewport_size_js().'
1.1 raeburn 618: </script>
1.6 raeburn 619: ';
1.30 raeburn 620: my $additem;
621: if ($phase eq 'pickactions') {
622: my %loaditems = (
1.31 raeburn 623: 'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
1.30 raeburn 624: );
625: $additem = {'add_entries' => \%loaditems,};
626: } else {
627: my %loaditems = (
1.31 raeburn 628: 'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);",
1.30 raeburn 629: );
630: $additem = {'add_entries' => \%loaditems,};
631: }
1.2 albertel 632: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.30 raeburn 633: $js,$additem));
1.3 raeburn 634: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6 raeburn 635: $r->print('
1.8 raeburn 636: <form name="parmform" action="">
1.6 raeburn 637: <input type="hidden" name="pres_marker" />
638: <input type="hidden" name="pres_type" />
639: <input type="hidden" name="pres_value" />
640: </form>
641: ');
642: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
643: ' enctype="multipart/form-data">');
1.1 raeburn 644: return;
645: }
646:
647: sub print_footer {
1.30 raeburn 648: my ($r,$phase,$newphase,$button_text,$actions) = @_;
1.3 raeburn 649: $button_text = &mt($button_text);
1.30 raeburn 650: $r->print('<input type="hidden" name="phase" value="" />'.
651: '<input type="hidden" name="width" value="'.
652: $env{'form.width'}.'" />'.
653: '<input type="hidden" name="height" value="'.
654: $env{'form.height'}.'" />');
655: if (($phase eq 'display') || ($phase eq 'process')) {
656: if (ref($actions) eq 'ARRAY') {
657: foreach my $item (@{$actions}) {
658: $r->print('<input type="hidden" name="actions" value="'.$item.'" />')."\n";
659: }
660: }
661: $r->print('<input type="hidden" name="numcols" value="'.$env{'form.numcols'}.'" />');
662: }
1.3 raeburn 663: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
664: if ($phase eq 'process') {
1.30 raeburn 665: $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
1.3 raeburn 666: } else {
1.30 raeburn 667: my $onclick;
668: if ($phase eq 'display') {
669: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
670: } else {
671: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
672: }
673: $r->print('<p><input type="button" name="store" value="'.
674: $button_text.'" onclick='.$onclick.' /></p>');
675: }
676: if ($phase eq 'process') {
677: $r->print('</form>'.&Apache::loncommon::end_page());
1.3 raeburn 678: }
1.1 raeburn 679: return;
680: }
681:
1.3 raeburn 682: sub print_login {
1.30 raeburn 683: my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
1.6 raeburn 684: my %choices = &login_choices();
1.42 raeburn 685: my %defaultchecked = (
1.43 raeburn 686: 'coursecatalog' => 'on',
687: 'adminmail' => 'off',
688: 'newuser' => 'off',
689: );
690: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 691: my (%checkedon,%checkedoff);
692: foreach my $item (@toggles) {
693: if ($defaultchecked{$item} eq 'on') {
694: $checkedon{$item} = ' checked="checked" ';
695: $checkedoff{$item} = ' ';
696: } elsif ($defaultchecked{$item} eq 'off') {
697: $checkedoff{$item} = ' checked="checked" ';
698: $checkedon{$item} = ' ';
699: }
700: }
701: my $loginheader = 'image';
1.41 raeburn 702: my @images = ('img','logo','domlogo','login');
703: my @logintext = ('textcol','bgcol');
1.6 raeburn 704: my @bgs = ('pgbg','mainbg','sidebg');
705: my @links = ('link','alink','vlink');
1.7 albertel 706: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 707: my %defaultdesign = %Apache::loncommon::defaultdesign;
708: my (%is_custom,%designs);
709: my %defaults = (
710: font => $defaultdesign{'login.font'},
711: );
712: foreach my $item (@images) {
713: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 714: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 715: }
716: foreach my $item (@bgs) {
717: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
718: }
1.41 raeburn 719: foreach my $item (@logintext) {
720: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
721: }
1.6 raeburn 722: foreach my $item (@links) {
723: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
724: }
1.3 raeburn 725: if (ref($settings) eq 'HASH') {
1.42 raeburn 726: foreach my $item (@toggles) {
727: if ($settings->{$item} eq '1') {
728: $checkedon{$item} = ' checked="checked" ';
729: $checkedoff{$item} = ' ';
730: } elsif ($settings->{$item} eq '0') {
731: $checkedoff{$item} = ' checked="checked" ';
732: $checkedon{$item} = ' ';
733: }
1.1 raeburn 734: }
1.6 raeburn 735: foreach my $item (@images) {
1.70 raeburn 736: if (defined($settings->{$item})) {
1.6 raeburn 737: $designs{$item} = $settings->{$item};
738: $is_custom{$item} = 1;
739: }
1.70 raeburn 740: if (defined($settings->{'showlogo'}{$item})) {
741: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
742: }
1.6 raeburn 743: }
1.41 raeburn 744: foreach my $item (@logintext) {
745: if ($settings->{$item} ne '') {
746: $designs{'logintext'}{$item} = $settings->{$item};
747: $is_custom{$item} = 1;
748: }
749: }
750: if ($settings->{'loginheader'} ne '') {
751: $loginheader = $settings->{'loginheader'};
752: }
1.6 raeburn 753: if ($settings->{'font'} ne '') {
754: $designs{'font'} = $settings->{'font'};
755: $is_custom{'font'} = 1;
756: }
757: foreach my $item (@bgs) {
758: if ($settings->{$item} ne '') {
759: $designs{'bgs'}{$item} = $settings->{$item};
760: $is_custom{$item} = 1;
761: }
762: }
763: foreach my $item (@links) {
764: if ($settings->{$item} ne '') {
765: $designs{'links'}{$item} = $settings->{$item};
766: $is_custom{$item} = 1;
767: }
768: }
769: } else {
770: if ($designhash{$dom.'.login.font'} ne '') {
771: $designs{'font'} = $designhash{$dom.'.login.font'};
772: $is_custom{'font'} = 1;
773: }
1.8 raeburn 774: foreach my $item (@images) {
775: if ($designhash{$dom.'.login.'.$item} ne '') {
776: $designs{$item} = $designhash{$dom.'.login.'.$item};
777: $is_custom{$item} = 1;
778: }
779: }
1.6 raeburn 780: foreach my $item (@bgs) {
781: if ($designhash{$dom.'.login.'.$item} ne '') {
782: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
783: $is_custom{$item} = 1;
784: }
785: }
786: foreach my $item (@links) {
787: if ($designhash{$dom.'.login.'.$item} ne '') {
788: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
789: $is_custom{$item} = 1;
790: }
791: }
1.1 raeburn 792: }
1.6 raeburn 793: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
794: logo => 'Institution Logo',
1.41 raeburn 795: domlogo => 'Domain Logo',
796: login => 'Login box');
1.6 raeburn 797: my $itemcount = 1;
1.42 raeburn 798: my ($css_class,$datatable);
799: foreach my $item (@toggles) {
800: $css_class = $itemcount%2?' class="LC_odd_row"':'';
801: $datatable .=
802: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
803: '</td><td>'.
804: '<span class="LC_nobreak"><label><input type="radio" name="'.
805: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
806: '</label> <label><input type="radio" name="'.$item.'"'.
807: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
808: '</tr>';
809: $itemcount ++;
810: }
1.41 raeburn 811: $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 812: $datatable .= '</tr></table></td></tr>';
813: return $datatable;
814: }
815:
816: sub login_choices {
817: my %choices =
818: &Apache::lonlocal::texthash (
819: coursecatalog => 'Display Course Catalog link?',
820: adminmail => "Display Administrator's E-mail Address?",
1.43 raeburn 821: newuser => "Link to create a user account",
1.6 raeburn 822: img => "Header",
823: logo => "Main Logo",
824: domlogo => "Domain Logo",
1.41 raeburn 825: login => "Log-in Header",
826: textcol => "Text color",
827: bgcol => "Box color",
1.6 raeburn 828: bgs => "Background colors",
829: links => "Link colors",
830: font => "Font color",
1.71 muellerd 831: pgbg => "Header",
832: mainbg => "Page",
1.74 muellerd 833: sidebg => "Login box",
1.6 raeburn 834: link => "Link",
835: alink => "Active link",
836: vlink => "Visited link",
837: );
838: return %choices;
839: }
840:
841: sub print_rolecolors {
1.30 raeburn 842: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 843: my %choices = &color_font_choices();
844: my @bgs = ('pgbg','tabbg','sidebg');
845: my @links = ('link','alink','vlink');
846: my @images = ('img');
847: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 848: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 849: my %defaultdesign = %Apache::loncommon::defaultdesign;
850: my (%is_custom,%designs);
851: my %defaults = (
852: img => $defaultdesign{$role.'.img'},
853: font => $defaultdesign{$role.'.font'},
854: );
855: foreach my $item (@bgs) {
856: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
857: }
858: foreach my $item (@links) {
859: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
860: }
861: if (ref($settings) eq 'HASH') {
862: if (ref($settings->{$role}) eq 'HASH') {
863: if ($settings->{$role}->{'img'} ne '') {
864: $designs{'img'} = $settings->{$role}->{'img'};
865: $is_custom{'img'} = 1;
866: }
867: if ($settings->{$role}->{'font'} ne '') {
868: $designs{'font'} = $settings->{$role}->{'font'};
869: $is_custom{'font'} = 1;
870: }
871: foreach my $item (@bgs) {
872: if ($settings->{$role}->{$item} ne '') {
873: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
874: $is_custom{$item} = 1;
875: }
876: }
877: foreach my $item (@links) {
878: if ($settings->{$role}->{$item} ne '') {
879: $designs{'links'}{$item} = $settings->{$role}->{$item};
880: $is_custom{$item} = 1;
881: }
882: }
883: }
884: } else {
885: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
886: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
887: $is_custom{'img'} = 1;
888: }
889: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
890: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
891: $is_custom{'font'} = 1;
892: }
893: foreach my $item (@bgs) {
894: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
895: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
896: $is_custom{$item} = 1;
897:
898: }
899: }
900: foreach my $item (@links) {
901: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
902: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
903: $is_custom{$item} = 1;
904: }
905: }
906: }
907: my $itemcount = 1;
1.30 raeburn 908: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 909: $datatable .= '</tr></table></td></tr>';
910: return $datatable;
911: }
912:
913: sub display_color_options {
1.9 raeburn 914: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.41 raeburn 915: $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_;
1.6 raeburn 916: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
917: my $datatable = '<tr'.$css_class.'>'.
918: '<td>'.$choices->{'font'}.'</td>';
919: if (!$is_custom->{'font'}) {
1.30 raeburn 920: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 921: } else {
922: $datatable .= '<td> </td>';
923: }
924: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 925: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 926: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 927: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 928: ' <span id="css_'.$role.'_font" style="background-color: '.
929: $designs->{'font'}.';"> </span>'.
1.8 raeburn 930: '</span></td></tr>';
1.9 raeburn 931: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 932: foreach my $img (@{$images}) {
1.18 albertel 933: $itemcount ++;
1.6 raeburn 934: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 935: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 936: '<td>'.$choices->{$img};
1.41 raeburn 937: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 938: if ($role eq 'login') {
939: if ($img eq 'login') {
940: $login_hdr_pick =
941: &login_header_options($img,$role,$defaults,$is_custom,$choices,
942: $loginheader);
943: $logincolors =
944: &login_text_colors($img,$role,$logintext,$phase,$choices,
945: $designs);
946: } elsif ($img ne 'domlogo') {
947: $datatable.= &logo_display_options($img,$defaults,$designs);
948: }
949: }
950: $datatable .= '</td>';
1.6 raeburn 951: if ($designs->{$img} ne '') {
952: $imgfile = $designs->{$img};
1.18 albertel 953: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 954: } else {
955: $imgfile = $defaults->{$img};
956: }
957: if ($imgfile) {
1.9 raeburn 958: my ($showfile,$fullsize);
959: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 960: my $urldir = $1;
961: my $filename = $2;
962: my @info = &Apache::lonnet::stat_file($designs->{$img});
963: if (@info) {
964: my $thumbfile = 'tn-'.$filename;
965: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
966: if (@thumb) {
967: $showfile = $urldir.'/'.$thumbfile;
968: } else {
969: $showfile = $imgfile;
970: }
971: } else {
972: $showfile = '';
973: }
974: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 975: $showfile = $imgfile;
1.6 raeburn 976: my $imgdir = $1;
977: my $filename = $2;
978: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
979: $showfile = "/$imgdir/tn-".$filename;
980: } else {
981: my $input = "/home/httpd/html".$imgfile;
982: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
983: if (!-e $output) {
1.9 raeburn 984: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 985: my ($fullwidth,$fullheight) = &check_dimensions($input);
986: if ($fullwidth ne '' && $fullheight ne '') {
987: if ($fullwidth > $width && $fullheight > $height) {
988: my $size = $width.'x'.$height;
989: system("convert -sample $size $input $output");
990: $showfile = '/'.$imgdir.'/tn-'.$filename;
991: }
992: }
1.6 raeburn 993: }
994: }
1.16 raeburn 995: }
1.6 raeburn 996: if ($showfile) {
1.40 raeburn 997: if ($showfile =~ m{^/(adm|res)/}) {
998: if ($showfile =~ m{^/res/}) {
999: my $local_showfile =
1000: &Apache::lonnet::filelocation('',$showfile);
1001: &Apache::lonnet::repcopy($local_showfile);
1002: }
1003: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1004: }
1005: if ($imgfile) {
1006: if ($imgfile =~ m{^/(adm|res)/}) {
1007: if ($imgfile =~ m{^/res/}) {
1008: my $local_imgfile =
1009: &Apache::lonnet::filelocation('',$imgfile);
1010: &Apache::lonnet::repcopy($local_imgfile);
1011: }
1012: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1013: } else {
1014: $fullsize = $imgfile;
1015: }
1016: }
1.41 raeburn 1017: $datatable .= '<td>';
1018: if ($img eq 'login') {
1019: $datatable .= $login_hdr_pick;
1.6 raeburn 1020: }
1.41 raeburn 1021: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1022: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1023: } else {
1024: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1025: &mt('Upload:');
1026: }
1027: } else {
1028: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1029: &mt('Upload:');
1030: }
1.9 raeburn 1031: if ($switchserver) {
1032: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1033: } else {
1034: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1035: }
1036: $datatable .= '</td></tr>';
1.6 raeburn 1037: }
1038: $itemcount ++;
1039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1040: $datatable .= '<tr'.$css_class.'>'.
1041: '<td>'.$choices->{'bgs'}.'</td>';
1042: my $bgs_def;
1043: foreach my $item (@{$bgs}) {
1044: if (!$is_custom->{$item}) {
1.70 raeburn 1045: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1046: }
1047: }
1048: if ($bgs_def) {
1.8 raeburn 1049: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1050: } else {
1051: $datatable .= '<td> </td>';
1052: }
1053: $datatable .= '<td class="LC_right_item">'.
1054: '<table border="0"><tr>';
1055: foreach my $item (@{$bgs}) {
1056: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1057: $datatable .= '<td align="center">'.$link;
1058: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1059: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1060: }
1061: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1062: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1063: }
1064: $datatable .= '</tr></table></td></tr>';
1065: $itemcount ++;
1066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1067: $datatable .= '<tr'.$css_class.'>'.
1068: '<td>'.$choices->{'links'}.'</td>';
1069: my $links_def;
1070: foreach my $item (@{$links}) {
1071: if (!$is_custom->{$item}) {
1.30 raeburn 1072: $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 1073: }
1074: }
1075: if ($links_def) {
1.8 raeburn 1076: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1077: } else {
1078: $datatable .= '<td> </td>';
1079: }
1080: $datatable .= '<td class="LC_right_item">'.
1081: '<table border="0"><tr>';
1082: foreach my $item (@{$links}) {
1.30 raeburn 1083: $datatable .= '<td align="center">'."\n".
1084: &color_pick($phase,$role,$item,$choices->{$item},
1085: $designs->{'links'}{$item});
1.6 raeburn 1086: if ($designs->{'links'}{$item}) {
1.30 raeburn 1087: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1088: }
1089: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1090: '" /></td>';
1091: }
1.30 raeburn 1092: $$rowtotal += $itemcount;
1.3 raeburn 1093: return $datatable;
1094: }
1095:
1.70 raeburn 1096: sub logo_display_options {
1097: my ($img,$defaults,$designs) = @_;
1098: my $checkedon;
1099: if (ref($defaults) eq 'HASH') {
1100: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1101: if ($defaults->{'showlogo'}{$img}) {
1102: $checkedon = 'checked="checked" ';
1103: }
1104: }
1105: }
1106: if (ref($designs) eq 'HASH') {
1107: if (ref($designs->{'showlogo'}) eq 'HASH') {
1108: if (defined($designs->{'showlogo'}{$img})) {
1109: if ($designs->{'showlogo'}{$img} == 0) {
1110: $checkedon = '';
1111: } elsif ($designs->{'showlogo'}{$img} == 1) {
1112: $checkedon = 'checked="checked" ';
1113: }
1114: }
1115: }
1116: }
1117: return '<br /><label> <input type="checkbox" name="'.
1118: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1119: &mt('show').'</label>'."\n";
1120: }
1121:
1.41 raeburn 1122: sub login_header_options {
1123: my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
1124: my $image_checked = ' checked="checked" ';
1125: my $text_checked = ' ';
1126: if ($loginheader eq 'text') {
1127: $image_checked = ' ';
1128: $text_checked = ' checked="checked" ';
1129: }
1130: my $output = '<span class="LC_nobreak"><label><input type="radio" name="'.
1131: 'loginheader" value="image" '.$image_checked.'/>'.
1132: &mt('use image').'</label> '.
1133: '<label><input type="radio" name="loginheader" value="text"'.
1134: $text_checked.'/>'.&mt('use text').'</label><br />'."\n";
1135: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1136: $output .= &mt('Text default(s)').':<br />';
1137: if (!$is_custom->{'textcol'}) {
1138: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1139: ' ';
1140: }
1141: if (!$is_custom->{'bgcol'}) {
1142: $output .= $choices->{'bgcol'}.': '.
1143: '<span id="css_'.$role.'_font" style="background-color: '.
1144: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1145: }
1146: $output .= '<br />';
1147: }
1148: $output .='<br />';
1149: return $output;
1150: }
1151:
1152: sub login_text_colors {
1153: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1154: my $color_menu = '<table border="0"><tr>';
1155: foreach my $item (@{$logintext}) {
1156: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1157: $color_menu .= '<td align="center">'.$link;
1158: if ($designs->{'logintext'}{$item}) {
1159: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1160: }
1161: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1162: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1163: '<td> </td>';
1164: }
1165: $color_menu .= '</tr></table><br />';
1166: return $color_menu;
1167: }
1168:
1169: sub image_changes {
1170: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1171: my $output;
1172: if (!$is_custom) {
1.70 raeburn 1173: if ($img ne 'domlogo') {
1.41 raeburn 1174: $output .= &mt('Default image:').'<br />';
1175: } else {
1176: $output .= &mt('Default in use:').'<br />';
1177: }
1178: }
1179: if ($img_import) {
1180: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1181: }
1182: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1183: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1184: if ($is_custom) {
1185: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1186: '<input type="checkbox" name="'.
1187: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1188: '</label> '.&mt('Replace:').'</span><br />';
1189: } else {
1190: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1191: }
1192: return $output;
1193: }
1194:
1.6 raeburn 1195: sub color_pick {
1196: my ($phase,$role,$item,$desc,$curcol) = @_;
1197: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1198: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1199: ');">'.$desc.'</a>';
1200: return $link;
1201: }
1202:
1203: sub color_pick_js {
1204: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1205: my $output = <<"ENDCOL";
1206: function pclose() {
1207: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
1208: parmwin.close();
1209: }
1210:
1211: $pjump_def
1212:
1213: function psub() {
1214: pclose();
1215: if (document.parmform.pres_marker.value!='') {
1216: if (document.parmform.pres_type.value!='') {
1217: eval('document.display.'+
1218: document.parmform.pres_marker.value+
1219: '.value=document.parmform.pres_value.value;');
1220: }
1221: } else {
1222: document.parmform.pres_value.value='';
1223: document.parmform.pres_marker.value='';
1224: }
1225: }
1.41 raeburn 1226:
1227: function get_id (span_id) {
1228: if (document.getElementById) {
1229: return document.getElementById(span_id);
1230: }
1231: if (document.all) {
1232: return document.all[span_id];
1233: }
1234: return false;
1235: }
1236:
1237: function colchg_span (span_id_str,new_color_item) {
1238: var span_ref = get_id(span_id_str);
1239: if (span_ref.style) { span_ref = span_ref.style; }
1240: span_ref.background = new_color_item.value;
1241: span_ref.backgroundColor = new_color_item.value;
1242: span_ref.bgColor = new_color_item.value;
1243: }
1244:
1.6 raeburn 1245: ENDCOL
1246: return $output;
1247: }
1248:
1.3 raeburn 1249: sub print_quotas {
1.86 raeburn 1250: my ($dom,$settings,$rowtotal,$action) = @_;
1251: my $context;
1252: if ($action eq 'quotas') {
1253: $context = 'tools';
1254: } else {
1255: $context = $action;
1256: }
1257: my ($datatable,$defaultquota,@usertools);
1.44 raeburn 1258: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1259: my $typecount = 0;
1260: my $css_class;
1.86 raeburn 1261: if ($context eq 'requestcourses') {
1262: @usertools = ('official','unofficial');
1263: } else {
1264: @usertools = ('aboutme','blog','portfolio');
1265: }
1.72 raeburn 1266: my %titles = &tool_titles();
1.26 raeburn 1267: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1268: foreach my $type (@{$types}) {
1.72 raeburn 1269: my $currdefquota;
1.86 raeburn 1270: unless ($context eq 'requestcourses') {
1271: if (ref($settings) eq 'HASH') {
1272: if (ref($settings->{defaultquota}) eq 'HASH') {
1273: $currdefquota = $settings->{defaultquota}->{$type};
1274: } else {
1275: $currdefquota = $settings->{$type};
1276: }
1.78 raeburn 1277: }
1.72 raeburn 1278: }
1.3 raeburn 1279: if (defined($usertypes->{$type})) {
1280: $typecount ++;
1281: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1282: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1283: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1284: '<td class="LC_left_item">';
1285: foreach my $item (@usertools) {
1.86 raeburn 1286: my $checked;
1287: unless ($context eq 'requestcourses') {
1288: $checked = 'checked="checked" ';
1289: }
1.78 raeburn 1290: if (ref($settings) eq 'HASH') {
1291: if (ref($settings->{$item}) eq 'HASH') {
1292: if ($settings->{$item}->{$type} == 0) {
1293: $checked = '';
1.86 raeburn 1294: } elsif ($settings->{$item}->{$type} == 1) {
1295: $checked = 'checked="checked" ';
1.78 raeburn 1296: }
1.72 raeburn 1297: }
1298: }
1299: $datatable .= '<span class="LC_nobreak"><label>'.
1.86 raeburn 1300: '<input type="checkbox" name="'.$context.'_'.$item.
1.72 raeburn 1301: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1302: '</label></span> ';
1303: }
1.86 raeburn 1304: $datatable .= '</td>';
1305: unless ($context eq 'requestcourses') {
1306: $datatable .=
1307: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1308: '<input type="text" name="quota_'.$type.
1.72 raeburn 1309: '" value="'.$currdefquota.
1.86 raeburn 1310: '" size="5" /> Mb</span></td>';
1311: }
1312: $datatable .= '</tr>';
1.3 raeburn 1313: }
1314: }
1315: }
1.86 raeburn 1316: unless ($context eq 'requestcourses') {
1317: $defaultquota = '20';
1318: if (ref($settings) eq 'HASH') {
1319: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1320: $defaultquota = $settings->{'defaultquota'}->{'default'};
1321: } elsif (defined($settings->{'default'})) {
1322: $defaultquota = $settings->{'default'};
1323: }
1.3 raeburn 1324: }
1325: }
1326: $typecount ++;
1327: $css_class = $typecount%2?' class="LC_odd_row"':'';
1328: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1329: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1330: '<td class="LC_left_item">';
1331: foreach my $item (@usertools) {
1.86 raeburn 1332: my $checked;
1333: unless ($context eq 'requestcourses') {
1334: $checked = 'checked="checked" ';
1335: }
1.78 raeburn 1336: if (ref($settings) eq 'HASH') {
1337: if (ref($settings->{$item}) eq 'HASH') {
1338: if ($settings->{$item}->{'default'} == 0) {
1339: $checked = '';
1.86 raeburn 1340: } elsif ($settings->{$item}->{'default'} == 1) {
1341: $checked = 'checked="checked" ';
1.78 raeburn 1342: }
1.72 raeburn 1343: }
1344: }
1345: $datatable .= '<span class="LC_nobreak"><label>'.
1.86 raeburn 1346: '<input type="checkbox" name="'.$context.'_'.$item.
1.72 raeburn 1347: '" value="default" '.$checked.'/>'.$titles{$item}.
1348: '</label></span> ';
1349: }
1.86 raeburn 1350: $datatable .= '</td>';
1351: unless ($context eq 'requestcourses') {
1352: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1353: '<input type="text" name="defaultquota" value="'.
1354: $defaultquota.'" size="5" /> Mb</span></td>';
1355: }
1356: $datatable .= '</tr>';
1.72 raeburn 1357: $typecount ++;
1358: $css_class = $typecount%2?' class="LC_odd_row"':'';
1359: $datatable .= '<tr'.$css_class.'>'.
1360: '<td><br/>'.&mt('LON-CAPA Advanced Users').'</td>'.
1361: '<td class="LC_left_item" colspan="2"><br />';
1362: foreach my $item (@usertools) {
1.86 raeburn 1363: my $checked;
1364: unless ($context eq 'requestcourses') {
1365: $checked = 'checked="checked" ';
1366: }
1.79 raeburn 1367: if (ref($settings) eq 'HASH') {
1368: if (ref($settings->{$item}) eq 'HASH') {
1369: if ($settings->{$item}->{'_LC_adv'} == 0) {
1370: $checked = '';
1.86 raeburn 1371: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1372: $checked = 'checked="checked" ';
1.79 raeburn 1373: }
1.72 raeburn 1374: }
1375: }
1376: $datatable .= '<span class="LC_nobreak"><label>'.
1.86 raeburn 1377: '<input type="checkbox" name="'.$context.'_'.$item.
1.72 raeburn 1378: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1379: '</label></span> ';
1380: }
1.77 raeburn 1381: $datatable .= '<span class="LC_nobreak">('.&mt('overrides affiliation').
1.84 raeburn 1382: ')</span></td></tr>';
1.30 raeburn 1383: $$rowtotal += $typecount;
1.3 raeburn 1384: return $datatable;
1385: }
1386:
1387: sub print_autoenroll {
1.30 raeburn 1388: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1389: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 1390: my ($defdom,$runon,$runoff);
1.3 raeburn 1391: if (ref($settings) eq 'HASH') {
1392: if (exists($settings->{'run'})) {
1393: if ($settings->{'run'} eq '0') {
1394: $runoff = ' checked="checked" ';
1395: $runon = ' ';
1396: } else {
1397: $runon = ' checked="checked" ';
1398: $runoff = ' ';
1399: }
1400: } else {
1401: if ($autorun) {
1402: $runon = ' checked="checked" ';
1403: $runoff = ' ';
1404: } else {
1405: $runoff = ' checked="checked" ';
1406: $runon = ' ';
1407: }
1408: }
1409: if (exists($settings->{'sender_domain'})) {
1410: $defdom = $settings->{'sender_domain'};
1411: }
1.14 raeburn 1412: } else {
1413: if ($autorun) {
1414: $runon = ' checked="checked" ';
1415: $runoff = ' ';
1416: } else {
1417: $runoff = ' checked="checked" ';
1418: $runon = ' ';
1419: }
1.3 raeburn 1420: }
1421: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1422: my $notif_sender;
1423: if (ref($settings) eq 'HASH') {
1424: $notif_sender = $settings->{'sender_uname'};
1425: }
1.3 raeburn 1426: my $datatable='<tr class="LC_odd_row">'.
1427: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1428: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1429: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1430: $runon.' value="1" />'.&mt('Yes').'</label> '.
1431: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1432: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1433: '</tr><tr>'.
1434: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1435: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1436: &mt('username').': '.
1437: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1438: $notif_sender.'" size="10" /> '.&mt('domain').
1.8 raeburn 1439: ': '.$domform.'</span></td></tr>';
1.30 raeburn 1440: $$rowtotal += 2;
1.3 raeburn 1441: return $datatable;
1442: }
1443:
1444: sub print_autoupdate {
1.30 raeburn 1445: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1446: my $datatable;
1447: if ($position eq 'top') {
1448: my $updateon = ' ';
1449: my $updateoff = ' checked="checked" ';
1450: my $classlistson = ' ';
1451: my $classlistsoff = ' checked="checked" ';
1452: if (ref($settings) eq 'HASH') {
1453: if ($settings->{'run'} eq '1') {
1454: $updateon = $updateoff;
1455: $updateoff = ' ';
1456: }
1457: if ($settings->{'classlists'} eq '1') {
1458: $classlistson = $classlistsoff;
1459: $classlistsoff = ' ';
1460: }
1461: }
1462: my %title = (
1463: run => 'Auto-update active?',
1464: classlists => 'Update information in classlists?',
1465: );
1466: $datatable = '<tr class="LC_odd_row">'.
1467: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1468: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1469: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1470: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1471: '<label><input type="radio" name="autoupdate_run"'.
1472: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1473: '</tr><tr>'.
1474: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1475: '<td class="LC_right_item"><span class="LC_nobreak">'.
1476: '<label><input type="radio" name="classlists"'.
1477: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1478: '<label><input type="radio" name="classlists"'.
1479: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1480: '</tr>';
1.30 raeburn 1481: $$rowtotal += 2;
1.3 raeburn 1482: } else {
1.44 raeburn 1483: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.20 raeburn 1484: my @fields = ('lastname','firstname','middlename','gen',
1485: 'permanentemail','id');
1.33 raeburn 1486: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1487: my $numrows = 0;
1.26 raeburn 1488: if (ref($types) eq 'ARRAY') {
1489: if (@{$types} > 0) {
1490: $datatable =
1491: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1492: \@fields,$types,\$numrows);
1.30 raeburn 1493: $$rowtotal += @{$types};
1.26 raeburn 1494: }
1.3 raeburn 1495: }
1496: $datatable .=
1497: &usertype_update_row($settings,{'default' => $othertitle},
1498: \%fieldtitles,\@fields,['default'],
1499: \$numrows);
1.30 raeburn 1500: $$rowtotal ++;
1.3 raeburn 1501: }
1502: return $datatable;
1503: }
1504:
1.23 raeburn 1505: sub print_directorysrch {
1.30 raeburn 1506: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1507: my $srchon = ' ';
1508: my $srchoff = ' checked="checked" ';
1.25 raeburn 1509: my ($exacton,$containson,$beginson);
1.24 raeburn 1510: my $localon = ' ';
1511: my $localoff = ' checked="checked" ';
1.23 raeburn 1512: if (ref($settings) eq 'HASH') {
1513: if ($settings->{'available'} eq '1') {
1514: $srchon = $srchoff;
1515: $srchoff = ' ';
1516: }
1.24 raeburn 1517: if ($settings->{'localonly'} eq '1') {
1518: $localon = $localoff;
1519: $localoff = ' ';
1520: }
1.25 raeburn 1521: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1522: foreach my $type (@{$settings->{'searchtypes'}}) {
1523: if ($type eq 'exact') {
1524: $exacton = ' checked="checked" ';
1525: } elsif ($type eq 'contains') {
1526: $containson = ' checked="checked" ';
1527: } elsif ($type eq 'begins') {
1528: $beginson = ' checked="checked" ';
1529: }
1530: }
1531: } else {
1532: if ($settings->{'searchtypes'} eq 'exact') {
1533: $exacton = ' checked="checked" ';
1534: } elsif ($settings->{'searchtypes'} eq 'contains') {
1535: $containson = ' checked="checked" ';
1536: } elsif ($settings->{'searchtypes'} eq 'specify') {
1537: $exacton = ' checked="checked" ';
1538: $containson = ' checked="checked" ';
1539: }
1.23 raeburn 1540: }
1541: }
1542: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1543: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1544:
1545: my $numinrow = 4;
1.26 raeburn 1546: my $cansrchrow = 0;
1.23 raeburn 1547: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1548: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1549: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1550: '<input type="radio" name="dirsrch_available"'.
1551: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1552: '<label><input type="radio" name="dirsrch_available"'.
1553: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1554: '</tr><tr>'.
1.30 raeburn 1555: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1556: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1557: '<input type="radio" name="dirsrch_localonly"'.
1558: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1559: '<label><input type="radio" name="dirsrch_localonly"'.
1560: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1561: '</tr>';
1.30 raeburn 1562: $$rowtotal += 2;
1.26 raeburn 1563: if (ref($usertypes) eq 'HASH') {
1564: if (keys(%{$usertypes}) > 0) {
1565: $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
1566: $numinrow,$othertitle);
1567: $cansrchrow = 1;
1568: }
1569: }
1570: if ($cansrchrow) {
1.30 raeburn 1571: $$rowtotal ++;
1.26 raeburn 1572: $datatable .= '<tr>';
1573: } else {
1574: $datatable .= '<tr class="LC_odd_row">';
1575: }
1.30 raeburn 1576: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1577: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1578: foreach my $title (@{$titleorder}) {
1579: if (defined($searchtitles->{$title})) {
1580: my $check = ' ';
1.39 raeburn 1581: if (ref($settings) eq 'HASH') {
1582: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1583: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1584: $check = ' checked="checked" ';
1585: }
1.25 raeburn 1586: }
1587: }
1588: $datatable .= '<td class="LC_left_item">'.
1589: '<span class="LC_nobreak"><label>'.
1590: '<input type="checkbox" name="searchby" '.
1591: 'value="'.$title.'"'.$check.'/>'.
1592: $searchtitles->{$title}.'</label></span></td>';
1593: }
1594: }
1.26 raeburn 1595: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1596: $$rowtotal ++;
1.26 raeburn 1597: if ($cansrchrow) {
1598: $datatable .= '<tr class="LC_odd_row">';
1599: } else {
1600: $datatable .= '<tr>';
1601: }
1.30 raeburn 1602: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 1603: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1604: '<span class="LC_nobreak"><label>'.
1605: '<input type="checkbox" name="searchtypes" '.
1606: $exacton.' value="exact" />'.&mt('Exact match').
1607: '</label> '.
1608: '<label><input type="checkbox" name="searchtypes" '.
1609: $beginson.' value="begins" />'.&mt('Begins with').
1610: '</label> '.
1611: '<label><input type="checkbox" name="searchtypes" '.
1612: $containson.' value="contains" />'.&mt('Contains').
1613: '</label></span></td></tr>';
1.30 raeburn 1614: $$rowtotal ++;
1.25 raeburn 1615: return $datatable;
1616: }
1617:
1.28 raeburn 1618: sub print_contacts {
1.30 raeburn 1619: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 1620: my $datatable;
1621: my @contacts = ('adminemail','supportemail');
1622: my (%checked,%to,%otheremails);
1.89 ! raeburn 1623: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail');
1.28 raeburn 1624: foreach my $type (@mailings) {
1625: $otheremails{$type} = '';
1626: }
1627: if (ref($settings) eq 'HASH') {
1628: foreach my $item (@contacts) {
1629: if (exists($settings->{$item})) {
1630: $to{$item} = $settings->{$item};
1631: }
1632: }
1633: foreach my $type (@mailings) {
1634: if (exists($settings->{$type})) {
1635: if (ref($settings->{$type}) eq 'HASH') {
1636: foreach my $item (@contacts) {
1637: if ($settings->{$type}{$item}) {
1638: $checked{$type}{$item} = ' checked="checked" ';
1639: }
1640: }
1641: $otheremails{$type} = $settings->{$type}{'others'};
1642: }
1.89 ! raeburn 1643: } elsif ($type eq 'lonstatusmail') {
! 1644: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 1645: }
1646: }
1647: } else {
1648: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1649: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1650: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1651: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 ! raeburn 1652: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
! 1653: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 1654: }
1655: my ($titles,$short_titles) = &contact_titles();
1656: my $rownum = 0;
1657: my $css_class;
1658: foreach my $item (@contacts) {
1.69 raeburn 1659: $rownum ++;
1660: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 1661: $datatable .= '<tr'.$css_class.'>'.
1662: '<td><span class="LC_nobreak">'.$titles->{$item}.
1663: '</span></td><td class="LC_right_item">'.
1.28 raeburn 1664: '<input type="text" name="'.$item.'" value="'.
1665: $to{$item}.'" /></td></tr>';
1666: }
1667: foreach my $type (@mailings) {
1.69 raeburn 1668: $rownum ++;
1669: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 1670: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 1671: '<td><span class="LC_nobreak">'.
1672: $titles->{$type}.': </span></td>'.
1.28 raeburn 1673: '<td class="LC_left_item">'.
1674: '<span class="LC_nobreak">';
1675: foreach my $item (@contacts) {
1676: $datatable .= '<label>'.
1677: '<input type="checkbox" name="'.$type.'"'.
1678: $checked{$type}{$item}.
1679: ' value="'.$item.'" />'.$short_titles->{$item}.
1680: '</label> ';
1681: }
1682: $datatable .= '</span><br />'.&mt('Others').': '.
1683: '<input type="text" name="'.$type.'_others" '.
1684: 'value="'.$otheremails{$type}.'" />'.
1685: '</td></tr>'."\n";
1686: }
1.30 raeburn 1687: $$rowtotal += $rownum;
1.28 raeburn 1688: return $datatable;
1689: }
1690:
1691: sub contact_titles {
1692: my %titles = &Apache::lonlocal::texthash (
1693: 'supportemail' => 'Support E-mail address',
1.69 raeburn 1694: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 1695: 'errormail' => 'Error reports to be e-mailed to',
1696: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 ! raeburn 1697: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
! 1698: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.28 raeburn 1699: );
1700: my %short_titles = &Apache::lonlocal::texthash (
1701: adminemail => 'Admin E-mail address',
1702: supportemail => 'Support E-mail',
1703: );
1704: return (\%titles,\%short_titles);
1705: }
1706:
1.72 raeburn 1707: sub tool_titles {
1708: my %titles = &Apache::lonlocal::texthash (
1.86 raeburn 1709: aboutme => 'Personal Home Page',
1710: blog => 'Blog',
1711: portfolio => 'Portfolio',
1.88 bisitz 1712: official => 'Official courses (with institutional codes)',
1713: unofficial => 'Unofficial courses',
1.86 raeburn 1714: );
1.72 raeburn 1715: return %titles;
1716: }
1717:
1.27 raeburn 1718: sub print_usercreation {
1.30 raeburn 1719: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 1720: my $numinrow = 4;
1.28 raeburn 1721: my $datatable;
1722: if ($position eq 'top') {
1.30 raeburn 1723: $$rowtotal ++;
1.34 raeburn 1724: my $rowcount = 0;
1.32 raeburn 1725: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 1726: if (ref($rules) eq 'HASH') {
1727: if (keys(%{$rules}) > 0) {
1.32 raeburn 1728: $datatable .= &user_formats_row('username',$settings,$rules,
1729: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 1730: $$rowtotal ++;
1.32 raeburn 1731: $rowcount ++;
1732: }
1733: }
1734: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
1735: if (ref($idrules) eq 'HASH') {
1736: if (keys(%{$idrules}) > 0) {
1737: $datatable .= &user_formats_row('id',$settings,$idrules,
1738: $idruleorder,$numinrow,$rowcount);
1739: $$rowtotal ++;
1740: $rowcount ++;
1.28 raeburn 1741: }
1742: }
1.43 raeburn 1743: my ($emailrules,$emailruleorder) =
1744: &Apache::lonnet::inst_userrules($dom,'email');
1745: if (ref($emailrules) eq 'HASH') {
1746: if (keys(%{$emailrules}) > 0) {
1747: $datatable .= &user_formats_row('email',$settings,$emailrules,
1748: $emailruleorder,$numinrow,$rowcount);
1749: $$rowtotal ++;
1750: $rowcount ++;
1751: }
1752: }
1.39 raeburn 1753: if ($rowcount == 0) {
1754: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
1755: $$rowtotal ++;
1756: $rowcount ++;
1757: }
1.34 raeburn 1758: } elsif ($position eq 'middle') {
1.45 raeburn 1759: my @creators = ('author','course','selfcreate');
1.37 raeburn 1760: my ($rules,$ruleorder) =
1761: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 1762: my %lt = &usercreation_types();
1763: my %checked;
1.50 raeburn 1764: my @selfcreate;
1.34 raeburn 1765: if (ref($settings) eq 'HASH') {
1766: if (ref($settings->{'cancreate'}) eq 'HASH') {
1767: foreach my $item (@creators) {
1768: $checked{$item} = $settings->{'cancreate'}{$item};
1769: }
1.50 raeburn 1770: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
1771: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
1772: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
1773: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
1774: @selfcreate = ('email','login','sso');
1775: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
1776: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
1777: }
1778: }
1.34 raeburn 1779: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
1780: foreach my $item (@creators) {
1781: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
1782: $checked{$item} = 'none';
1783: }
1784: }
1785: }
1786: }
1787: my $rownum = 0;
1788: foreach my $item (@creators) {
1789: $rownum ++;
1.50 raeburn 1790: if ($item ne 'selfcreate') {
1791: if ($checked{$item} eq '') {
1.43 raeburn 1792: $checked{$item} = 'any';
1793: }
1.34 raeburn 1794: }
1795: my $css_class;
1796: if ($rownum%2) {
1797: $css_class = '';
1798: } else {
1799: $css_class = ' class="LC_odd_row" ';
1800: }
1801: $datatable .= '<tr'.$css_class.'>'.
1802: '<td><span class="LC_nobreak">'.$lt{$item}.
1803: '</span></td><td align="right">';
1.50 raeburn 1804: my @options;
1.45 raeburn 1805: if ($item eq 'selfcreate') {
1.43 raeburn 1806: push(@options,('email','login','sso'));
1807: } else {
1.50 raeburn 1808: @options = ('any');
1.43 raeburn 1809: if (ref($rules) eq 'HASH') {
1810: if (keys(%{$rules}) > 0) {
1811: push(@options,('official','unofficial'));
1812: }
1.37 raeburn 1813: }
1.50 raeburn 1814: push(@options,'none');
1.37 raeburn 1815: }
1816: foreach my $option (@options) {
1.50 raeburn 1817: my $type = 'radio';
1.34 raeburn 1818: my $check = ' ';
1.50 raeburn 1819: if ($item eq 'selfcreate') {
1820: $type = 'checkbox';
1821: if (grep(/^\Q$option\E$/,@selfcreate)) {
1822: $check = ' checked="checked" ';
1823: }
1824: } else {
1825: if ($checked{$item} eq $option) {
1826: $check = ' checked="checked" ';
1827: }
1.34 raeburn 1828: }
1829: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 1830: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 1831: $item.'" value="'.$option.'"'.$check.'/> '.
1832: $lt{$option}.'</label> </span>';
1833: }
1834: $datatable .= '</td></tr>';
1835: }
1.28 raeburn 1836: } else {
1837: my @contexts = ('author','course','domain');
1838: my @authtypes = ('int','krb4','krb5','loc');
1839: my %checked;
1840: if (ref($settings) eq 'HASH') {
1841: if (ref($settings->{'authtypes'}) eq 'HASH') {
1842: foreach my $item (@contexts) {
1843: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
1844: foreach my $auth (@authtypes) {
1845: if ($settings->{'authtypes'}{$item}{$auth}) {
1846: $checked{$item}{$auth} = ' checked="checked" ';
1847: }
1848: }
1849: }
1850: }
1.27 raeburn 1851: }
1.35 raeburn 1852: } else {
1853: foreach my $item (@contexts) {
1.36 raeburn 1854: foreach my $auth (@authtypes) {
1.35 raeburn 1855: $checked{$item}{$auth} = ' checked="checked" ';
1856: }
1857: }
1.27 raeburn 1858: }
1.28 raeburn 1859: my %title = &context_names();
1860: my %authname = &authtype_names();
1861: my $rownum = 0;
1862: my $css_class;
1863: foreach my $item (@contexts) {
1864: if ($rownum%2) {
1865: $css_class = '';
1866: } else {
1867: $css_class = ' class="LC_odd_row" ';
1868: }
1.30 raeburn 1869: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 1870: '<td>'.$title{$item}.
1871: '</td><td class="LC_left_item">'.
1872: '<span class="LC_nobreak">';
1873: foreach my $auth (@authtypes) {
1874: $datatable .= '<label>'.
1875: '<input type="checkbox" name="'.$item.'_auth" '.
1876: $checked{$item}{$auth}.' value="'.$auth.'" />'.
1877: $authname{$auth}.'</label> ';
1878: }
1879: $datatable .= '</span></td></tr>';
1880: $rownum ++;
1.27 raeburn 1881: }
1.30 raeburn 1882: $$rowtotal += $rownum;
1.27 raeburn 1883: }
1884: return $datatable;
1885: }
1886:
1.32 raeburn 1887: sub user_formats_row {
1888: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
1889: my $output;
1890: my %text = (
1891: 'username' => 'new usernames',
1892: 'id' => 'IDs',
1.45 raeburn 1893: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 1894: );
1895: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1896: $output = '<tr '.$css_class.'>'.
1.63 raeburn 1897: '<td><span class="LC_nobreak">';
1898: if ($type eq 'email') {
1899: $output .= &mt("Formats disallowed for $text{$type}: ");
1900: } else {
1901: $output .= &mt("Format rules to check for $text{$type}: ");
1902: }
1903: $output .= '</span></td>'.
1904: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 1905: my $rem;
1906: if (ref($ruleorder) eq 'ARRAY') {
1907: for (my $i=0; $i<@{$ruleorder}; $i++) {
1908: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
1909: my $rem = $i%($numinrow);
1910: if ($rem == 0) {
1911: if ($i > 0) {
1912: $output .= '</tr>';
1913: }
1914: $output .= '<tr>';
1915: }
1916: my $check = ' ';
1.39 raeburn 1917: if (ref($settings) eq 'HASH') {
1918: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
1919: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
1920: $check = ' checked="checked" ';
1921: }
1.27 raeburn 1922: }
1923: }
1924: $output .= '<td class="LC_left_item">'.
1925: '<span class="LC_nobreak"><label>'.
1.32 raeburn 1926: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 1927: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
1928: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
1929: }
1930: }
1931: $rem = @{$ruleorder}%($numinrow);
1932: }
1933: my $colsleft = $numinrow - $rem;
1934: if ($colsleft > 1 ) {
1935: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1936: ' </td>';
1937: } elsif ($colsleft == 1) {
1938: $output .= '<td class="LC_left_item"> </td>';
1939: }
1940: $output .= '</tr></table></td></tr>';
1941: return $output;
1942: }
1943:
1.34 raeburn 1944: sub usercreation_types {
1945: my %lt = &Apache::lonlocal::texthash (
1946: author => 'When adding a co-author',
1947: course => 'When adding a user to a course',
1.45 raeburn 1948: selfcreate => 'User creates own account',
1.34 raeburn 1949: any => 'Any',
1950: official => 'Institutional only ',
1951: unofficial => 'Non-institutional only',
1.85 schafran 1952: email => 'E-mail address',
1.43 raeburn 1953: login => 'Institutional Login',
1954: sso => 'SSO',
1.34 raeburn 1955: none => 'None',
1956: );
1957: return %lt;
1.48 raeburn 1958: }
1.34 raeburn 1959:
1.28 raeburn 1960: sub authtype_names {
1961: my %lt = &Apache::lonlocal::texthash(
1962: int => 'Internal',
1963: krb4 => 'Kerberos 4',
1964: krb5 => 'Kerberos 5',
1965: loc => 'Local',
1966: );
1967: return %lt;
1968: }
1969:
1970: sub context_names {
1971: my %context_title = &Apache::lonlocal::texthash(
1972: author => 'Creating users when an Author',
1973: course => 'Creating users when in a course',
1974: domain => 'Creating users when a Domain Coordinator',
1975: );
1976: return %context_title;
1977: }
1978:
1.33 raeburn 1979: sub print_usermodification {
1980: my ($position,$dom,$settings,$rowtotal) = @_;
1981: my $numinrow = 4;
1982: my ($context,$datatable,$rowcount);
1983: if ($position eq 'top') {
1984: $rowcount = 0;
1985: $context = 'author';
1986: foreach my $role ('ca','aa') {
1987: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1988: $numinrow,$rowcount);
1989: $$rowtotal ++;
1990: $rowcount ++;
1991: }
1.63 raeburn 1992: } elsif ($position eq 'middle') {
1.33 raeburn 1993: $context = 'course';
1994: $rowcount = 0;
1995: foreach my $role ('st','ep','ta','in','cr') {
1996: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1997: $numinrow,$rowcount);
1998: $$rowtotal ++;
1999: $rowcount ++;
2000: }
1.63 raeburn 2001: } elsif ($position eq 'bottom') {
2002: $context = 'selfcreate';
2003: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2004: $usertypes->{'default'} = $othertitle;
2005: if (ref($types) eq 'ARRAY') {
2006: push(@{$types},'default');
2007: $usertypes->{'default'} = $othertitle;
2008: foreach my $status (@{$types}) {
2009: $datatable .= &modifiable_userdata_row($context,$status,$settings,
2010: $numinrow,$rowcount,$usertypes);
2011: $$rowtotal ++;
2012: $rowcount ++;
2013: }
2014: }
1.33 raeburn 2015: }
2016: return $datatable;
2017: }
2018:
1.43 raeburn 2019: sub print_defaults {
2020: my ($dom,$rowtotal) = @_;
1.68 raeburn 2021: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
2022: 'datelocale_def');
1.43 raeburn 2023: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
2024: my $titles = &defaults_titles();
2025: my $rownum = 0;
2026: my ($datatable,$css_class);
2027: foreach my $item (@items) {
2028: if ($rownum%2) {
2029: $css_class = '';
2030: } else {
2031: $css_class = ' class="LC_odd_row" ';
2032: }
2033: $datatable .= '<tr'.$css_class.'>'.
2034: '<td><span class="LC_nobreak">'.$titles->{$item}.
2035: '</span></td><td class="LC_right_item">';
2036: if ($item eq 'auth_def') {
2037: my @authtypes = ('internal','krb4','krb5','localauth');
2038: my %shortauth = (
2039: internal => 'int',
2040: krb4 => 'krb4',
2041: krb5 => 'krb5',
2042: localauth => 'loc'
2043: );
2044: my %authnames = &authtype_names();
2045: foreach my $auth (@authtypes) {
2046: my $checked = ' ';
2047: if ($domdefaults{$item} eq $auth) {
2048: $checked = ' checked="checked" ';
2049: }
2050: $datatable .= '<label><input type="radio" name="'.$item.
2051: '" value="'.$auth.'"'.$checked.'/>'.
2052: $authnames{$shortauth{$auth}}.'</label> ';
2053: }
1.54 raeburn 2054: } elsif ($item eq 'timezone_def') {
2055: my $includeempty = 1;
2056: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 2057: } elsif ($item eq 'datelocale_def') {
2058: my $includeempty = 1;
2059: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 2060: } else {
2061: $datatable .= '<input type="text" name="'.$item.'" value="'.
2062: $domdefaults{$item}.'" />';
2063: }
2064: $datatable .= '</td></tr>';
2065: $rownum ++;
2066: }
2067: $$rowtotal += $rownum;
2068: return $datatable;
2069: }
2070:
2071: sub defaults_titles {
2072: my %titles = &Apache::lonlocal::texthash (
2073: 'auth_def' => 'Default authentication type',
2074: 'auth_arg_def' => 'Default authentication argument',
2075: 'lang_def' => 'Default language',
1.54 raeburn 2076: 'timezone_def' => 'Default timezone',
1.68 raeburn 2077: 'datelocale_def' => 'Default locale for dates',
1.43 raeburn 2078: );
2079: return (\%titles);
2080: }
2081:
1.46 raeburn 2082: sub print_scantronformat {
2083: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
2084: my $itemcount = 1;
1.60 raeburn 2085: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
2086: %confhash);
1.46 raeburn 2087: my $switchserver = &check_switchserver($dom,$confname);
2088: my %lt = &Apache::lonlocal::texthash (
2089: default => 'Default scantron format file error',
2090: custom => 'Custom scantron format file error',
2091: );
2092: my %scantronfiles = (
2093: default => 'default.tab',
2094: custom => 'custom.tab',
2095: );
2096: foreach my $key (keys(%scantronfiles)) {
2097: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
2098: .$scantronfiles{$key};
2099: }
2100: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
2101: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
2102: if (!$switchserver) {
2103: my $servadm = $r->dir_config('lonAdmEMail');
2104: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
2105: if ($configuserok eq 'ok') {
2106: if ($author_ok eq 'ok') {
2107: my %legacyfile = (
2108: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
2109: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
2110: );
2111: my %md5chk;
2112: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2113: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
2114: chomp($md5chk{$type});
1.46 raeburn 2115: }
2116: if ($md5chk{'default'} ne $md5chk{'custom'}) {
2117: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2118: ($scantronurls{$type},my $error) =
1.46 raeburn 2119: &legacy_scantronformat($r,$dom,$confname,
2120: $type,$legacyfile{$type},
2121: $scantronurls{$type},
2122: $scantronfiles{$type});
1.60 raeburn 2123: if ($error ne '') {
2124: $error{$type} = $error;
2125: }
2126: }
2127: if (keys(%error) == 0) {
2128: $is_custom = 1;
2129: $confhash{'scantron'}{'scantronformat'} =
2130: $scantronurls{'custom'};
2131: my $putresult =
2132: &Apache::lonnet::put_dom('configuration',
2133: \%confhash,$dom);
2134: if ($putresult ne 'ok') {
2135: $error{'custom'} =
2136: '<span class="LC_error">'.
2137: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2138: }
1.46 raeburn 2139: }
2140: } else {
1.60 raeburn 2141: ($scantronurls{'default'},my $error) =
1.46 raeburn 2142: &legacy_scantronformat($r,$dom,$confname,
2143: 'default',$legacyfile{'default'},
2144: $scantronurls{'default'},
2145: $scantronfiles{'default'});
1.60 raeburn 2146: if ($error eq '') {
2147: $confhash{'scantron'}{'scantronformat'} = '';
2148: my $putresult =
2149: &Apache::lonnet::put_dom('configuration',
2150: \%confhash,$dom);
2151: if ($putresult ne 'ok') {
2152: $error{'default'} =
2153: '<span class="LC_error">'.
2154: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2155: }
2156: } else {
2157: $error{'default'} = $error;
2158: }
1.46 raeburn 2159: }
2160: }
2161: }
2162: } else {
2163: $error{'default'} = &mt("Unable to copy default scantron formatfile to domain's RES space: [_1]",$switchserver);
2164: }
2165: }
2166: if (ref($settings) eq 'HASH') {
2167: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
2168: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
2169: if ((!@info) || ($info[0] eq 'no_such_dir')) {
2170: $scantronurl = '';
2171: } else {
2172: $scantronurl = $settings->{'scantronformat'};
2173: }
2174: $is_custom = 1;
2175: } else {
2176: $scantronurl = $scantronurls{'default'};
2177: }
2178: } else {
1.60 raeburn 2179: if ($is_custom) {
2180: $scantronurl = $scantronurls{'custom'};
2181: } else {
2182: $scantronurl = $scantronurls{'default'};
2183: }
1.46 raeburn 2184: }
2185: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2186: $datatable .= '<tr'.$css_class.'>';
2187: if (!$is_custom) {
1.65 raeburn 2188: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
2189: '<span class="LC_nobreak">';
1.46 raeburn 2190: if ($scantronurl) {
2191: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
2192: &mt('Default scantron format file').'</a>';
2193: } else {
2194: $datatable = &mt('File unavailable for display');
2195: }
1.65 raeburn 2196: $datatable .= '</span></td>';
1.60 raeburn 2197: if (keys(%error) == 0) {
2198: $datatable .= '<td valign="bottom">';
2199: if (!$switchserver) {
2200: $datatable .= &mt('Upload:').'<br />';
2201: }
2202: } else {
2203: my $errorstr;
2204: foreach my $key (sort(keys(%error))) {
2205: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2206: }
2207: $datatable .= '<td>'.$errorstr;
2208: }
1.46 raeburn 2209: } else {
2210: if (keys(%error) > 0) {
2211: my $errorstr;
2212: foreach my $key (sort(keys(%error))) {
2213: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2214: }
1.60 raeburn 2215: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 2216: } elsif ($scantronurl) {
1.65 raeburn 2217: $datatable .= '<td><span class="LC_nobreak">'.
2218: '<a href="'.$scantronurl.'" target="_blank">'.
2219: &mt('Custom scantron format file').'</a><label>'.
2220: '<input type="checkbox" name="scantronformat_del"'.
2221: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
2222: '<td><span class="LC_nobreak"> '.
2223: &mt('Replace:').'</span><br />';
1.46 raeburn 2224: }
2225: }
2226: if (keys(%error) == 0) {
2227: if ($switchserver) {
2228: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2229: } else {
1.65 raeburn 2230: $datatable .='<span class="LC_nobreak"> '.
2231: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 2232: }
2233: }
2234: $datatable .= '</td></tr>';
2235: $$rowtotal ++;
2236: return $datatable;
2237: }
2238:
2239: sub legacy_scantronformat {
2240: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
2241: my ($url,$error);
2242: my @statinfo = &Apache::lonnet::stat_file($newurl);
2243: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
2244: (my $result,$url) =
2245: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
2246: '','',$newfile);
2247: if ($result ne 'ok') {
2248: $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
2249: }
2250: }
2251: return ($url,$error);
2252: }
1.43 raeburn 2253:
1.49 raeburn 2254: sub print_coursecategories {
1.57 raeburn 2255: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
2256: my $datatable;
2257: if ($position eq 'top') {
2258: my $toggle_cats_crs = ' ';
2259: my $toggle_cats_dom = ' checked="checked" ';
2260: my $can_cat_crs = ' ';
2261: my $can_cat_dom = ' checked="checked" ';
2262: if (ref($settings) eq 'HASH') {
2263: if ($settings->{'togglecats'} eq 'crs') {
2264: $toggle_cats_crs = $toggle_cats_dom;
2265: $toggle_cats_dom = ' ';
2266: }
2267: if ($settings->{'categorize'} eq 'crs') {
2268: $can_cat_crs = $can_cat_dom;
2269: $can_cat_dom = ' ';
2270: }
2271: }
2272: my %title = &Apache::lonlocal::texthash (
2273: togglecats => 'Show/Hide a course in the catalog',
2274: categorize => 'Assign a category to a course',
2275: );
2276: my %level = &Apache::lonlocal::texthash (
2277: dom => 'Set in "Modify Course" (Domain)',
1.60 raeburn 2278: crs => 'Set in "Modify Parameters" (Course)',
1.57 raeburn 2279: );
2280: $datatable = '<tr class="LC_odd_row">'.
2281: '<td>'.$title{'togglecats'}.'</td>'.
2282: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2283: '<input type="radio" name="togglecats"'.
2284: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2285: '<label><input type="radio" name="togglecats"'.
2286: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
2287: '</tr><tr>'.
2288: '<td>'.$title{'categorize'}.'</td>'.
2289: '<td class="LC_right_item"><span class="LC_nobreak">'.
2290: '<label><input type="radio" name="categorize"'.
2291: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2292: '<label><input type="radio" name="categorize"'.
2293: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
2294: '</tr>';
2295: $$rowtotal += 2;
2296: } else {
2297: my $css_class;
2298: my $itemcount = 1;
2299: my $cathash;
2300: if (ref($settings) eq 'HASH') {
2301: $cathash = $settings->{'cats'};
2302: }
2303: if (ref($cathash) eq 'HASH') {
2304: my (@cats,@trails,%allitems,%idx,@jsarray);
2305: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
2306: \%allitems,\%idx,\@jsarray);
2307: my $maxdepth = scalar(@cats);
2308: my $colattrib = '';
2309: if ($maxdepth > 2) {
2310: $colattrib = ' colspan="2" ';
2311: }
2312: my @path;
2313: if (@cats > 0) {
2314: if (ref($cats[0]) eq 'ARRAY') {
2315: my $numtop = @{$cats[0]};
2316: my $maxnum = $numtop;
2317: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2318: $maxnum ++;
2319: }
2320: my $lastidx;
2321: for (my $i=0; $i<$numtop; $i++) {
2322: my $parent = $cats[0][$i];
2323: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2324: my $item = &escape($parent).'::0';
2325: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
2326: $lastidx = $idx{$item};
2327: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2328: .'<select name="'.$item.'"'.$chgstr.'>';
2329: for (my $k=0; $k<=$maxnum; $k++) {
2330: my $vpos = $k+1;
2331: my $selstr;
2332: if ($k == $i) {
2333: $selstr = ' selected="selected" ';
2334: }
2335: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2336: }
2337: $datatable .= '</select></td><td>';
2338: if ($parent eq 'instcode') {
2339: $datatable .= '<span class="LC_nobreak">'.&mt('Official courses')
2340: .'</span><br /><span class="LC_nobreak">('
2341: .&mt('with institutional codes').')</span></td>'
2342: .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'
2343: .&mt('Display').'</label> '
2344: .'<label><input type="radio" name="instcode" value="0" />'
2345: .&mt('Do not display').'</label></span></td>';
2346: } else {
2347: $datatable .= $parent
2348: .' <label><input type="checkbox" name="deletecategory" '
2349: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
2350: }
2351: my $depth = 1;
2352: push(@path,$parent);
2353: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
2354: pop(@path);
2355: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
2356: $itemcount ++;
2357: }
1.48 raeburn 2358: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 2359: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
2360: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 2361: for (my $k=0; $k<=$maxnum; $k++) {
2362: my $vpos = $k+1;
2363: my $selstr;
1.57 raeburn 2364: if ($k == $numtop) {
1.48 raeburn 2365: $selstr = ' selected="selected" ';
2366: }
2367: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2368: }
1.59 bisitz 2369: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 2370: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
2371: .'</tr>'."\n";
1.48 raeburn 2372: $itemcount ++;
1.57 raeburn 2373: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2374: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2375: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
2376: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
2377: '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
2378: for (my $k=0; $k<=$maxnum; $k++) {
2379: my $vpos = $k+1;
2380: my $selstr;
2381: if ($k == $maxnum) {
2382: $selstr = ' selected="selected" ';
2383: }
2384: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.48 raeburn 2385: }
1.57 raeburn 2386: $datatable .= '</select></span></td><td><span class="LC_nobreak">'
2387: .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('
2388: .&mt('with institutional codes').')</span></td>'
2389: .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'
2390: .&mt('Display').'</label> '
2391: .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'
2392: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 2393: }
2394: }
1.57 raeburn 2395: } else {
2396: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 2397: }
2398: } else {
1.57 raeburn 2399: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
2400: .&initialize_categories($itemcount);
1.48 raeburn 2401: }
1.57 raeburn 2402: $$rowtotal += $itemcount;
1.48 raeburn 2403: }
2404: return $datatable;
2405: }
2406:
1.69 raeburn 2407: sub print_serverstatuses {
2408: my ($dom,$settings,$rowtotal) = @_;
2409: my $datatable;
2410: my @pages = &serverstatus_pages();
2411: my (%namedaccess,%machineaccess);
2412: foreach my $type (@pages) {
2413: $namedaccess{$type} = '';
2414: $machineaccess{$type}= '';
2415: }
2416: if (ref($settings) eq 'HASH') {
2417: foreach my $type (@pages) {
2418: if (exists($settings->{$type})) {
2419: if (ref($settings->{$type}) eq 'HASH') {
2420: foreach my $key (keys(%{$settings->{$type}})) {
2421: if ($key eq 'namedusers') {
2422: $namedaccess{$type} = $settings->{$type}->{$key};
2423: } elsif ($key eq 'machines') {
2424: $machineaccess{$type} = $settings->{$type}->{$key};
2425: }
2426: }
2427: }
2428: }
2429: }
2430: }
1.81 raeburn 2431: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 2432: my $rownum = 0;
2433: my $css_class;
2434: foreach my $type (@pages) {
2435: $rownum ++;
2436: $css_class = $rownum%2?' class="LC_odd_row"':'';
2437: $datatable .= '<tr'.$css_class.'>'.
2438: '<td><span class="LC_nobreak">'.
2439: $titles->{$type}.'</span></td>'.
2440: '<td class="LC_left_item">'.
2441: '<input type="text" name="'.$type.'_namedusers" '.
2442: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
2443: '<td class="LC_right_item">'.
2444: '<span class="LC_nobreak">'.
2445: '<input type="text" name="'.$type.'_machines" '.
2446: 'value="'.$machineaccess{$type}.'" size="10" />'.
2447: '</td></tr>'."\n";
2448: }
2449: $$rowtotal += $rownum;
2450: return $datatable;
2451: }
2452:
2453: sub serverstatus_pages {
2454: return ('userstatus','lonstatus','loncron','server-status','codeversions',
2455: 'clusterstatus','metadata_keywords','metadata_harvest',
2456: 'takeoffline','takeonline','showenv');
2457: }
2458:
1.49 raeburn 2459: sub coursecategories_javascript {
2460: my ($settings) = @_;
1.57 raeburn 2461: my ($output,$jstext,$cathash);
1.49 raeburn 2462: if (ref($settings) eq 'HASH') {
1.57 raeburn 2463: $cathash = $settings->{'cats'};
2464: }
2465: if (ref($cathash) eq 'HASH') {
1.49 raeburn 2466: my (@cats,@jsarray,%idx);
1.57 raeburn 2467: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 2468: if (@jsarray > 0) {
2469: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
2470: for (my $i=0; $i<@jsarray; $i++) {
2471: if (ref($jsarray[$i]) eq 'ARRAY') {
2472: my $catstr = join('","',@{$jsarray[$i]});
2473: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
2474: }
2475: }
2476: }
2477: } else {
2478: $jstext = ' var categories = Array(1);'."\n".
2479: ' categories[0] = Array("instcode_pos");'."\n";
2480: }
2481: $output = <<"ENDSCRIPT";
2482: <script type="text/javascript">
2483: function reorderCats(form,parent,item,idx) {
2484: var changedVal;
2485: $jstext
2486: var newpos = 'addcategory_pos';
2487: var current = new Array;
2488: if (parent == '') {
2489: var has_instcode = 0;
2490: var maxtop = categories[idx].length;
2491: for (var j=0; j<maxtop; j++) {
2492: if (categories[idx][j] == 'instcode::0') {
2493: has_instcode == 1;
2494: }
2495: }
2496: if (has_instcode == 0) {
2497: categories[idx][maxtop] = 'instcode_pos';
2498: }
2499: } else {
2500: newpos += '_'+parent;
2501: }
2502: var maxh = 1 + categories[idx].length;
2503: var current = new Array;
2504: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2505: if (item == newpos) {
2506: changedVal = newitemVal;
2507: } else {
2508: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2509: current[newitemVal] = newpos;
2510: }
2511: for (var i=0; i<categories[idx].length; i++) {
2512: var elementName = categories[idx][i];
2513: if (elementName != item) {
2514: if (form.elements[elementName]) {
2515: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2516: current[currVal] = elementName;
2517: }
2518: }
2519: }
2520: var oldVal;
2521: for (var j=0; j<maxh; j++) {
2522: if (current[j] == undefined) {
2523: oldVal = j;
2524: }
2525: }
2526: if (oldVal < changedVal) {
2527: for (var k=oldVal+1; k<=changedVal ; k++) {
2528: var elementName = current[k];
2529: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2530: }
2531: } else {
2532: for (var k=changedVal; k<oldVal; k++) {
2533: var elementName = current[k];
2534: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2535: }
2536: }
2537: return;
2538: }
2539: </script>
2540:
2541: ENDSCRIPT
2542: return $output;
2543: }
2544:
1.48 raeburn 2545: sub initialize_categories {
2546: my ($itemcount) = @_;
2547: my $datatable;
2548: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2549: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
2550:
1.48 raeburn 2551: $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
2552: .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
2553: .'<option value="1">2</option></select> '
2554: .&mt('Official courses (with institutional codes)')
2555: .'</span></td><td><span class="LC_nobreak">'
2556: .'<label><input type="radio" name="instcode" value="1" checked="checked" />'
2557: .&mt('Display').'</label> <label>'
2558: .'<input type="radio" name="instcode" value="0" />'.&mt('Do not display')
2559: .'</label></span></td></tr>';
2560: $itemcount ++;
2561: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2562: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 2563: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.53 raeburn 2564: .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
1.48 raeburn 2565: .'<option value="1" selected="selected">2</option></select> '
2566: .&mt('Add category').'</td><td>'.&mt('Name:')
2567: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
2568: return $datatable;
2569: }
2570:
2571: sub build_category_rows {
1.49 raeburn 2572: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
2573: my ($text,$name,$item,$chgstr);
1.48 raeburn 2574: if (ref($cats) eq 'ARRAY') {
2575: my $maxdepth = scalar(@{$cats});
2576: if (ref($cats->[$depth]) eq 'HASH') {
2577: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
2578: my $numchildren = @{$cats->[$depth]{$parent}};
2579: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
2580: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 2581: my ($idxnum,$parent_name,$parent_item);
2582: my $higher = $depth - 1;
2583: if ($higher == 0) {
2584: $parent_name = &escape($parent).'::'.$higher;
2585: } else {
2586: if (ref($path) eq 'ARRAY') {
2587: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2588: }
2589: }
2590: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 2591: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 2592: if ($j < $numchildren) {
1.48 raeburn 2593: $name = $cats->[$depth]{$parent}[$j];
2594: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 2595: $idxnum = $idx->{$item};
2596: } else {
2597: $name = $parent_name;
2598: $item = $parent_item;
1.48 raeburn 2599: }
1.49 raeburn 2600: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
2601: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 2602: for (my $i=0; $i<=$numchildren; $i++) {
2603: my $vpos = $i+1;
2604: my $selstr;
2605: if ($j == $i) {
2606: $selstr = ' selected="selected" ';
2607: }
2608: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
2609: }
2610: $text .= '</select> ';
2611: if ($j < $numchildren) {
2612: my $deeper = $depth+1;
2613: $text .= $name.' '
2614: .'<label><input type="checkbox" name="deletecategory" value="'
2615: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
2616: if(ref($path) eq 'ARRAY') {
2617: push(@{$path},$name);
1.49 raeburn 2618: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 2619: pop(@{$path});
2620: }
2621: } else {
1.59 bisitz 2622: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 2623: if ($j == $numchildren) {
2624: $text .= $name;
2625: } else {
2626: $text .= $item;
2627: }
2628: $text .= '" value="" />';
2629: }
2630: $text .= '</td></tr>';
2631: }
2632: $text .= '</table></td>';
2633: } else {
2634: my $higher = $depth-1;
2635: if ($higher == 0) {
2636: $name = &escape($parent).'::'.$higher;
2637: } else {
2638: if (ref($path) eq 'ARRAY') {
2639: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2640: }
2641: }
2642: my $colspan;
2643: if ($parent ne 'instcode') {
2644: $colspan = $maxdepth - $depth - 1;
2645: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
2646: }
2647: }
2648: }
2649: }
2650: return $text;
2651: }
2652:
1.33 raeburn 2653: sub modifiable_userdata_row {
1.63 raeburn 2654: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 2655: my $rolename;
1.63 raeburn 2656: if ($context eq 'selfcreate') {
2657: if (ref($usertypes) eq 'HASH') {
2658: $rolename = $usertypes->{$role};
2659: } else {
2660: $rolename = $role;
2661: }
1.33 raeburn 2662: } else {
1.63 raeburn 2663: if ($role eq 'cr') {
2664: $rolename = &mt('Custom role');
2665: } else {
2666: $rolename = &Apache::lonnet::plaintext($role);
2667: }
1.33 raeburn 2668: }
2669: my @fields = ('lastname','firstname','middlename','generation',
2670: 'permanentemail','id');
2671: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2672: my $output;
2673: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2674: $output = '<tr '.$css_class.'>'.
2675: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
2676: '<td class="LC_left_item" colspan="2"><table>';
2677: my $rem;
2678: my %checks;
2679: if (ref($settings) eq 'HASH') {
2680: if (ref($settings->{$context}) eq 'HASH') {
2681: if (ref($settings->{$context}->{$role}) eq 'HASH') {
2682: foreach my $field (@fields) {
2683: if ($settings->{$context}->{$role}->{$field}) {
2684: $checks{$field} = ' checked="checked" ';
2685: }
2686: }
2687: }
2688: }
2689: }
2690: for (my $i=0; $i<@fields; $i++) {
2691: my $rem = $i%($numinrow);
2692: if ($rem == 0) {
2693: if ($i > 0) {
2694: $output .= '</tr>';
2695: }
2696: $output .= '<tr>';
2697: }
2698: my $check = ' ';
2699: if (exists($checks{$fields[$i]})) {
2700: $check = $checks{$fields[$i]}
2701: } else {
2702: if ($role eq 'st') {
2703: if (ref($settings) ne 'HASH') {
2704: $check = ' checked="checked" ';
2705: }
2706: }
2707: }
2708: $output .= '<td class="LC_left_item">'.
2709: '<span class="LC_nobreak"><label>'.
2710: '<input type="checkbox" name="canmodify_'.$role.'" '.
2711: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
2712: '</label></span></td>';
2713: $rem = @fields%($numinrow);
2714: }
2715: my $colsleft = $numinrow - $rem;
2716: if ($colsleft > 1 ) {
2717: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2718: ' </td>';
2719: } elsif ($colsleft == 1) {
2720: $output .= '<td class="LC_left_item"> </td>';
2721: }
2722: $output .= '</tr></table></td></tr>';
2723: return $output;
2724: }
1.28 raeburn 2725:
1.25 raeburn 2726: sub users_cansearch_row {
2727: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
2728: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 2729: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
2730: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 2731: my $rem;
2732: if (ref($types) eq 'ARRAY') {
2733: for (my $i=0; $i<@{$types}; $i++) {
2734: if (defined($usertypes->{$types->[$i]})) {
2735: my $rem = $i%($numinrow);
2736: if ($rem == 0) {
2737: if ($i > 0) {
2738: $output .= '</tr>';
2739: }
2740: $output .= '<tr>';
1.23 raeburn 2741: }
1.26 raeburn 2742: my $check = ' ';
2743: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
2744: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
2745: $check = ' checked="checked" ';
2746: }
1.23 raeburn 2747: }
1.26 raeburn 2748: $output .= '<td class="LC_left_item">'.
2749: '<span class="LC_nobreak"><label>'.
2750: '<input type="checkbox" name="cansearch" '.
2751: 'value="'.$types->[$i].'"'.$check.'/>'.
2752: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 2753: }
2754: }
1.26 raeburn 2755:
2756: $rem = @{$types}%($numinrow);
1.23 raeburn 2757: }
2758: my $colsleft = $numinrow - $rem;
2759: if ($colsleft > 1) {
1.25 raeburn 2760: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 2761: } else {
1.25 raeburn 2762: $output .= '<td class="LC_left_item">';
1.23 raeburn 2763: }
2764: my $defcheck = ' ';
2765: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 2766: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
2767: $defcheck = ' checked="checked" ';
2768: }
1.23 raeburn 2769: }
1.25 raeburn 2770: $output .= '<span class="LC_nobreak"><label>'.
2771: '<input type="checkbox" name="cansearch" '.
2772: 'value="default"'.$defcheck.'/>'.
2773: $othertitle.'</label></span></td>'.
2774: '</tr></table></td></tr>';
2775: return $output;
1.23 raeburn 2776: }
2777:
2778: sub sorted_searchtitles {
2779: my %searchtitles = &Apache::lonlocal::texthash(
2780: 'uname' => 'username',
2781: 'lastname' => 'last name',
2782: 'lastfirst' => 'last name, first name',
2783: );
2784: my @titleorder = ('uname','lastname','lastfirst');
2785: return (\%searchtitles,\@titleorder);
2786: }
2787:
1.25 raeburn 2788: sub sorted_searchtypes {
2789: my %srchtypes_desc = (
2790: exact => 'is exact match',
2791: contains => 'contains ..',
2792: begins => 'begins with ..',
2793: );
2794: my @srchtypeorder = ('exact','begins','contains');
2795: return (\%srchtypes_desc,\@srchtypeorder);
2796: }
2797:
1.3 raeburn 2798: sub usertype_update_row {
2799: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
2800: my $datatable;
2801: my $numinrow = 4;
2802: foreach my $type (@{$types}) {
2803: if (defined($usertypes->{$type})) {
2804: $$rownums ++;
2805: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
2806: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
2807: '</td><td class="LC_left_item"><table>';
2808: for (my $i=0; $i<@{$fields}; $i++) {
2809: my $rem = $i%($numinrow);
2810: if ($rem == 0) {
2811: if ($i > 0) {
2812: $datatable .= '</tr>';
2813: }
2814: $datatable .= '<tr>';
2815: }
2816: my $check = ' ';
1.39 raeburn 2817: if (ref($settings) eq 'HASH') {
2818: if (ref($settings->{'fields'}) eq 'HASH') {
2819: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
2820: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
2821: $check = ' checked="checked" ';
2822: }
1.3 raeburn 2823: }
2824: }
2825: }
2826:
2827: if ($i == @{$fields}-1) {
2828: my $colsleft = $numinrow - $rem;
2829: if ($colsleft > 1) {
2830: $datatable .= '<td colspan="'.$colsleft.'">';
2831: } else {
2832: $datatable .= '<td>';
2833: }
2834: } else {
2835: $datatable .= '<td>';
2836: }
1.8 raeburn 2837: $datatable .= '<span class="LC_nobreak"><label>'.
2838: '<input type="checkbox" name="updateable_'.$type.
2839: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
2840: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 2841: }
2842: $datatable .= '</tr></table></td></tr>';
2843: }
2844: }
2845: return $datatable;
1.1 raeburn 2846: }
2847:
2848: sub modify_login {
1.9 raeburn 2849: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 2850: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 2851: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 2852: adminmail => 'Display administrator E-mail address',
1.43 raeburn 2853: newuser => 'Link for visitors to create a user account',
1.41 raeburn 2854: loginheader => 'Log-in box header');
1.3 raeburn 2855: my @offon = ('off','on');
1.6 raeburn 2856: my %loginhash;
1.9 raeburn 2857: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
2858: \%domconfig,\%loginhash);
1.43 raeburn 2859: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2860: foreach my $item (@toggles) {
2861: $loginhash{login}{$item} = $env{'form.'.$item};
2862: }
1.41 raeburn 2863: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 2864: if (ref($colchanges{'login'}) eq 'HASH') {
2865: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
2866: \%loginhash);
2867: }
1.1 raeburn 2868: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
2869: $dom);
2870: if ($putresult eq 'ok') {
1.43 raeburn 2871: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2872: my %defaultchecked = (
2873: 'coursecatalog' => 'on',
2874: 'adminmail' => 'off',
1.43 raeburn 2875: 'newuser' => 'off',
1.42 raeburn 2876: );
1.55 raeburn 2877: if (ref($domconfig{'login'}) eq 'HASH') {
2878: foreach my $item (@toggles) {
2879: if ($defaultchecked{$item} eq 'on') {
2880: if (($domconfig{'login'}{$item} eq '0') &&
2881: ($env{'form.'.$item} eq '1')) {
2882: $changes{$item} = 1;
2883: } elsif (($domconfig{'login'}{$item} eq '' ||
2884: $domconfig{'login'}{$item} eq '1') &&
2885: ($env{'form.'.$item} eq '0')) {
2886: $changes{$item} = 1;
2887: }
2888: } elsif ($defaultchecked{$item} eq 'off') {
2889: if (($domconfig{'login'}{$item} eq '1') &&
2890: ($env{'form.'.$item} eq '0')) {
2891: $changes{$item} = 1;
2892: } elsif (($domconfig{'login'}{$item} eq '' ||
2893: $domconfig{'login'}{$item} eq '0') &&
2894: ($env{'form.'.$item} eq '1')) {
2895: $changes{$item} = 1;
2896: }
1.42 raeburn 2897: }
2898: }
1.55 raeburn 2899: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
2900: ($env{'form.loginheader'} eq 'image')) {
2901: $changes{'loginheader'} = 1;
2902: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
2903: $domconfig{'login'}{'loginheader'} eq 'image') &&
2904: ($env{'form.loginheader'} eq 'text')) {
2905: $changes{'loginheader'} = 1;
2906: }
1.41 raeburn 2907: }
1.6 raeburn 2908: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 2909: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 2910: $resulttext = &mt('Changes made:').'<ul>';
2911: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 2912: if ($item eq 'loginheader') {
2913: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
2914: } else {
2915: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
2916: }
1.1 raeburn 2917: }
1.6 raeburn 2918: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 2919: } else {
2920: $resulttext = &mt('No changes made to log-in page settings');
2921: }
2922: } else {
1.11 albertel 2923: $resulttext = '<span class="LC_error">'.
2924: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2925: }
1.6 raeburn 2926: if ($errors) {
1.9 raeburn 2927: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 2928: $errors.'</ul>';
2929: }
2930: return $resulttext;
2931: }
2932:
2933: sub color_font_choices {
2934: my %choices =
2935: &Apache::lonlocal::texthash (
2936: img => "Header",
2937: bgs => "Background colors",
2938: links => "Link colors",
1.55 raeburn 2939: images => "Images",
1.6 raeburn 2940: font => "Font color",
1.76 raeburn 2941: pgbg => "Page",
1.6 raeburn 2942: tabbg => "Header",
2943: sidebg => "Border",
2944: link => "Link",
2945: alink => "Active link",
2946: vlink => "Visited link",
2947: );
2948: return %choices;
2949: }
2950:
2951: sub modify_rolecolors {
1.9 raeburn 2952: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 2953: my ($resulttext,%rolehash);
2954: $rolehash{'rolecolors'} = {};
1.55 raeburn 2955: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
2956: if ($domconfig{'rolecolors'} eq '') {
2957: $domconfig{'rolecolors'} = {};
2958: }
2959: }
1.9 raeburn 2960: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 2961: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
2962: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
2963: $dom);
2964: if ($putresult eq 'ok') {
2965: if (keys(%changes) > 0) {
1.41 raeburn 2966: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 2967: $resulttext = &display_colorchgs($dom,\%changes,$roles,
2968: $rolehash{'rolecolors'});
2969: } else {
2970: $resulttext = &mt('No changes made to default color schemes');
2971: }
2972: } else {
1.11 albertel 2973: $resulttext = '<span class="LC_error">'.
2974: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 2975: }
2976: if ($errors) {
2977: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
2978: $errors.'</ul>';
2979: }
2980: return $resulttext;
2981: }
2982:
2983: sub modify_colors {
1.9 raeburn 2984: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 2985: my (%changes,%choices);
1.51 raeburn 2986: my @bgs;
1.6 raeburn 2987: my @links = ('link','alink','vlink');
1.41 raeburn 2988: my @logintext;
1.6 raeburn 2989: my @images;
2990: my $servadm = $r->dir_config('lonAdmEMail');
2991: my $errors;
2992: foreach my $role (@{$roles}) {
2993: if ($role eq 'login') {
1.12 raeburn 2994: %choices = &login_choices();
1.41 raeburn 2995: @logintext = ('textcol','bgcol');
1.12 raeburn 2996: } else {
2997: %choices = &color_font_choices();
2998: }
2999: if ($role eq 'login') {
1.41 raeburn 3000: @images = ('img','logo','domlogo','login');
1.51 raeburn 3001: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 3002: } else {
3003: @images = ('img');
1.51 raeburn 3004: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 3005: }
3006: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 3007: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 3008: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
3009: }
1.46 raeburn 3010: my ($configuserok,$author_ok,$switchserver) =
3011: &config_check($dom,$confname,$servadm);
1.9 raeburn 3012: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 3013: if (ref($domconfig->{$role}) ne 'HASH') {
3014: $domconfig->{$role} = {};
3015: }
1.8 raeburn 3016: foreach my $img (@images) {
1.70 raeburn 3017: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
3018: if (defined($env{'form.login_showlogo_'.$img})) {
3019: $confhash->{$role}{'showlogo'}{$img} = 1;
3020: } else {
3021: $confhash->{$role}{'showlogo'}{$img} = 0;
3022: }
3023: }
1.18 albertel 3024: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
3025: && !defined($domconfig->{$role}{$img})
3026: && !$env{'form.'.$role.'_del_'.$img}
3027: && $env{'form.'.$role.'_import_'.$img}) {
3028: # import the old configured image from the .tab setting
3029: # if they haven't provided a new one
3030: $domconfig->{$role}{$img} =
3031: $env{'form.'.$role.'_import_'.$img};
3032: }
1.6 raeburn 3033: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 3034: my $error;
1.6 raeburn 3035: if ($configuserok eq 'ok') {
1.9 raeburn 3036: if ($switchserver) {
1.12 raeburn 3037: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 3038: } else {
3039: if ($author_ok eq 'ok') {
3040: my ($result,$logourl) =
3041: &publishlogo($r,'upload',$role.'_'.$img,
3042: $dom,$confname,$img,$width,$height);
3043: if ($result eq 'ok') {
3044: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 3045: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3046: } else {
1.12 raeburn 3047: $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 3048: }
3049: } else {
1.46 raeburn 3050: $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
1.6 raeburn 3051: }
3052: }
3053: } else {
1.46 raeburn 3054: $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
1.9 raeburn 3055: }
3056: if ($error) {
1.8 raeburn 3057: &Apache::lonnet::logthis($error);
1.11 albertel 3058: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 3059: }
3060: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 3061: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
3062: my $error;
3063: if ($configuserok eq 'ok') {
3064: # is confname an author?
3065: if ($switchserver eq '') {
3066: if ($author_ok eq 'ok') {
3067: my ($result,$logourl) =
3068: &publishlogo($r,'copy',$domconfig->{$role}{$img},
3069: $dom,$confname,$img,$width,$height);
3070: if ($result eq 'ok') {
3071: $confhash->{$role}{$img} = $logourl;
1.18 albertel 3072: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3073: }
3074: }
3075: }
3076: }
1.6 raeburn 3077: }
3078: }
3079: }
3080: if (ref($domconfig) eq 'HASH') {
3081: if (ref($domconfig->{$role}) eq 'HASH') {
3082: foreach my $img (@images) {
3083: if ($domconfig->{$role}{$img} ne '') {
3084: if ($env{'form.'.$role.'_del_'.$img}) {
3085: $confhash->{$role}{$img} = '';
1.12 raeburn 3086: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3087: } else {
1.9 raeburn 3088: if ($confhash->{$role}{$img} eq '') {
3089: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
3090: }
1.6 raeburn 3091: }
3092: } else {
3093: if ($env{'form.'.$role.'_del_'.$img}) {
3094: $confhash->{$role}{$img} = '';
1.12 raeburn 3095: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3096: }
3097: }
1.70 raeburn 3098: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
3099: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
3100: if ($confhash->{$role}{'showlogo'}{$img} ne
3101: $domconfig->{$role}{'showlogo'}{$img}) {
3102: $changes{$role}{'showlogo'}{$img} = 1;
3103: }
3104: } else {
3105: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3106: $changes{$role}{'showlogo'}{$img} = 1;
3107: }
3108: }
3109: }
3110: }
1.6 raeburn 3111: if ($domconfig->{$role}{'font'} ne '') {
3112: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
3113: $changes{$role}{'font'} = 1;
3114: }
3115: } else {
3116: if ($confhash->{$role}{'font'}) {
3117: $changes{$role}{'font'} = 1;
3118: }
3119: }
3120: foreach my $item (@bgs) {
3121: if ($domconfig->{$role}{$item} ne '') {
3122: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3123: $changes{$role}{'bgs'}{$item} = 1;
3124: }
3125: } else {
3126: if ($confhash->{$role}{$item}) {
3127: $changes{$role}{'bgs'}{$item} = 1;
3128: }
3129: }
3130: }
3131: foreach my $item (@links) {
3132: if ($domconfig->{$role}{$item} ne '') {
3133: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3134: $changes{$role}{'links'}{$item} = 1;
3135: }
3136: } else {
3137: if ($confhash->{$role}{$item}) {
3138: $changes{$role}{'links'}{$item} = 1;
3139: }
3140: }
3141: }
1.41 raeburn 3142: foreach my $item (@logintext) {
3143: if ($domconfig->{$role}{$item} ne '') {
3144: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3145: $changes{$role}{'logintext'}{$item} = 1;
3146: }
3147: } else {
3148: if ($confhash->{$role}{$item}) {
3149: $changes{$role}{'logintext'}{$item} = 1;
3150: }
3151: }
3152: }
1.6 raeburn 3153: } else {
3154: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3155: \@logintext,$confhash,\%changes);
1.6 raeburn 3156: }
3157: } else {
3158: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3159: \@logintext,$confhash,\%changes);
1.6 raeburn 3160: }
3161: }
3162: return ($errors,%changes);
3163: }
3164:
1.46 raeburn 3165: sub config_check {
3166: my ($dom,$confname,$servadm) = @_;
3167: my ($configuserok,$author_ok,$switchserver,%currroles);
3168: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
3169: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
3170: $confname,$servadm);
3171: if ($configuserok eq 'ok') {
3172: $switchserver = &check_switchserver($dom,$confname);
3173: if ($switchserver eq '') {
3174: $author_ok = &check_authorstatus($dom,$confname,%currroles);
3175: }
3176: }
3177: return ($configuserok,$author_ok,$switchserver);
3178: }
3179:
1.6 raeburn 3180: sub default_change_checker {
1.41 raeburn 3181: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 3182: foreach my $item (@{$links}) {
3183: if ($confhash->{$role}{$item}) {
3184: $changes->{$role}{'links'}{$item} = 1;
3185: }
3186: }
3187: foreach my $item (@{$bgs}) {
3188: if ($confhash->{$role}{$item}) {
3189: $changes->{$role}{'bgs'}{$item} = 1;
3190: }
3191: }
1.41 raeburn 3192: foreach my $item (@{$logintext}) {
3193: if ($confhash->{$role}{$item}) {
3194: $changes->{$role}{'logintext'}{$item} = 1;
3195: }
3196: }
1.6 raeburn 3197: foreach my $img (@{$images}) {
3198: if ($env{'form.'.$role.'_del_'.$img}) {
3199: $confhash->{$role}{$img} = '';
1.12 raeburn 3200: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 3201: }
1.70 raeburn 3202: if ($role eq 'login') {
3203: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3204: $changes->{$role}{'showlogo'}{$img} = 1;
3205: }
3206: }
1.6 raeburn 3207: }
3208: if ($confhash->{$role}{'font'}) {
3209: $changes->{$role}{'font'} = 1;
3210: }
1.48 raeburn 3211: }
1.6 raeburn 3212:
3213: sub display_colorchgs {
3214: my ($dom,$changes,$roles,$confhash) = @_;
3215: my (%choices,$resulttext);
3216: if (!grep(/^login$/,@{$roles})) {
3217: $resulttext = &mt('Changes made:').'<br />';
3218: }
3219: foreach my $role (@{$roles}) {
3220: if ($role eq 'login') {
3221: %choices = &login_choices();
3222: } else {
3223: %choices = &color_font_choices();
3224: }
3225: if (ref($changes->{$role}) eq 'HASH') {
3226: if ($role ne 'login') {
3227: $resulttext .= '<h4>'.&mt($role).'</h4>';
3228: }
3229: foreach my $key (sort(keys(%{$changes->{$role}}))) {
3230: if ($role ne 'login') {
3231: $resulttext .= '<ul>';
3232: }
3233: if (ref($changes->{$role}{$key}) eq 'HASH') {
3234: if ($role ne 'login') {
3235: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
3236: }
3237: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 3238: if (($role eq 'login') && ($key eq 'showlogo')) {
3239: if ($confhash->{$role}{$key}{$item}) {
3240: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
3241: } else {
3242: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
3243: }
3244: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 3245: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
3246: } else {
1.12 raeburn 3247: my $newitem = $confhash->{$role}{$item};
3248: if ($key eq 'images') {
3249: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
3250: }
3251: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 3252: }
3253: }
3254: if ($role ne 'login') {
3255: $resulttext .= '</ul></li>';
3256: }
3257: } else {
3258: if ($confhash->{$role}{$key} eq '') {
3259: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
3260: } else {
3261: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
3262: }
3263: }
3264: if ($role ne 'login') {
3265: $resulttext .= '</ul>';
3266: }
3267: }
3268: }
3269: }
1.3 raeburn 3270: return $resulttext;
1.1 raeburn 3271: }
3272:
1.9 raeburn 3273: sub thumb_dimensions {
3274: return ('200','50');
3275: }
3276:
1.16 raeburn 3277: sub check_dimensions {
3278: my ($inputfile) = @_;
3279: my ($fullwidth,$fullheight);
3280: if ($inputfile =~ m|^[/\w.\-]+$|) {
3281: if (open(PIPE,"identify $inputfile 2>&1 |")) {
3282: my $imageinfo = <PIPE>;
3283: if (!close(PIPE)) {
3284: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
3285: }
3286: chomp($imageinfo);
3287: my ($fullsize) =
1.21 raeburn 3288: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 3289: if ($fullsize) {
3290: ($fullwidth,$fullheight) = split(/x/,$fullsize);
3291: }
3292: }
3293: }
3294: return ($fullwidth,$fullheight);
3295: }
3296:
1.9 raeburn 3297: sub check_configuser {
3298: my ($uhome,$dom,$confname,$servadm) = @_;
3299: my ($configuserok,%currroles);
3300: if ($uhome eq 'no_host') {
3301: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
3302: my $configpass = &LONCAPA::Enrollment::create_password();
3303: $configuserok =
3304: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
3305: $configpass,'','','','','',undef,$servadm);
3306: } else {
3307: $configuserok = 'ok';
3308: %currroles =
3309: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
3310: }
3311: return ($configuserok,%currroles);
3312: }
3313:
3314: sub check_authorstatus {
3315: my ($dom,$confname,%currroles) = @_;
3316: my $author_ok;
1.40 raeburn 3317: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 3318: my $start = time;
3319: my $end = 0;
3320: $author_ok =
3321: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 3322: 'au',$end,$start,'','','domconfig');
1.9 raeburn 3323: } else {
3324: $author_ok = 'ok';
3325: }
3326: return $author_ok;
3327: }
3328:
3329: sub publishlogo {
1.46 raeburn 3330: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 3331: my ($output,$fname,$logourl);
3332: if ($action eq 'upload') {
3333: $fname=$env{'form.'.$formname.'.filename'};
3334: chop($env{'form.'.$formname});
3335: } else {
3336: ($fname) = ($formname =~ /([^\/]+)$/);
3337: }
1.46 raeburn 3338: if ($savefileas ne '') {
3339: $fname = $savefileas;
3340: }
1.9 raeburn 3341: $fname=&Apache::lonnet::clean_filename($fname);
3342: # See if there is anything left
3343: unless ($fname) { return ('error: no uploaded file'); }
3344: $fname="$subdir/$fname";
3345: my $filepath='/home/'.$confname.'/public_html';
3346: my ($fnamepath,$file,$fetchthumb);
3347: $file=$fname;
3348: if ($fname=~m|/|) {
3349: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
3350: }
3351: my @parts=split(/\//,$filepath.'/'.$fnamepath);
3352: my $count;
3353: for ($count=4;$count<=$#parts;$count++) {
3354: $filepath.="/$parts[$count]";
3355: if ((-e $filepath)!=1) {
3356: mkdir($filepath,02770);
3357: }
3358: }
3359: # Check for bad extension and disallow upload
3360: if ($file=~/\.(\w+)$/ &&
3361: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
3362: $output =
3363: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
3364: } elsif ($file=~/\.(\w+)$/ &&
3365: !defined(&Apache::loncommon::fileembstyle($1))) {
3366: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
3367: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 3368: $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 3369: } elsif (-d "$filepath/$file") {
3370: $output = &mt('File name is a directory name - rename the file and re-upload');
3371: } else {
3372: my $source = $filepath.'/'.$file;
3373: my $logfile;
3374: if (!open($logfile,">>$source".'.log')) {
3375: return (&mt('No write permission to Construction Space'));
3376: }
3377: print $logfile
3378: "\n================= Publish ".localtime()." ================\n".
3379: $env{'user.name'}.':'.$env{'user.domain'}."\n";
3380: # Save the file
3381: if (!open(FH,'>'.$source)) {
3382: &Apache::lonnet::logthis('Failed to create '.$source);
3383: return (&mt('Failed to create file'));
3384: }
3385: if ($action eq 'upload') {
3386: if (!print FH ($env{'form.'.$formname})) {
3387: &Apache::lonnet::logthis('Failed to write to '.$source);
3388: return (&mt('Failed to write file'));
3389: }
3390: } else {
3391: my $original = &Apache::lonnet::filelocation('',$formname);
3392: if(!copy($original,$source)) {
3393: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
3394: return (&mt('Failed to write file'));
3395: }
3396: }
3397: close(FH);
3398: chmod(0660, $source); # Permissions to rw-rw---.
3399:
3400: my $docroot=$r->dir_config('lonDocRoot');
3401: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
3402: my $copyfile=$targetdir.'/'.$file;
3403:
3404: my @parts=split(/\//,$targetdir);
3405: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
3406: for (my $count=5;$count<=$#parts;$count++) {
3407: $path.="/$parts[$count]";
3408: if (!-e $path) {
3409: print $logfile "\nCreating directory ".$path;
3410: mkdir($path,02770);
3411: }
3412: }
3413: my $versionresult;
3414: if (-e $copyfile) {
3415: $versionresult = &logo_versioning($targetdir,$file,$logfile);
3416: } else {
3417: $versionresult = 'ok';
3418: }
3419: if ($versionresult eq 'ok') {
3420: if (copy($source,$copyfile)) {
3421: print $logfile "\nCopied original source to ".$copyfile."\n";
3422: $output = 'ok';
3423: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
3424: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
3425: } else {
3426: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
3427: $output = &mt('Failed to copy file to RES space').", $!";
3428: }
3429: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
3430: my $inputfile = $filepath.'/'.$file;
3431: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 3432: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
3433: if ($fullwidth ne '' && $fullheight ne '') {
3434: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
3435: my $thumbsize = $thumbwidth.'x'.$thumbheight;
3436: system("convert -sample $thumbsize $inputfile $outfile");
3437: chmod(0660, $filepath.'/tn-'.$file);
3438: if (-e $outfile) {
3439: my $copyfile=$targetdir.'/tn-'.$file;
3440: if (copy($outfile,$copyfile)) {
3441: print $logfile "\nCopied source to ".$copyfile."\n";
3442: &write_metadata($dom,$confname,$formname,
3443: $targetdir,'tn-'.$file,$logfile);
3444: } else {
3445: print $logfile "\nUnable to write ".$copyfile.
3446: ':'.$!."\n";
3447: }
3448: }
1.9 raeburn 3449: }
3450: }
3451: }
3452: } else {
3453: $output = $versionresult;
3454: }
3455: }
3456: return ($output,$logourl);
3457: }
3458:
3459: sub logo_versioning {
3460: my ($targetdir,$file,$logfile) = @_;
3461: my $target = $targetdir.'/'.$file;
3462: my ($maxversion,$fn,$extn,$output);
3463: $maxversion = 0;
3464: if ($file =~ /^(.+)\.(\w+)$/) {
3465: $fn=$1;
3466: $extn=$2;
3467: }
3468: opendir(DIR,$targetdir);
3469: while (my $filename=readdir(DIR)) {
3470: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
3471: $maxversion=($1>$maxversion)?$1:$maxversion;
3472: }
3473: }
3474: $maxversion++;
3475: print $logfile "\nCreating old version ".$maxversion."\n";
3476: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
3477: if (copy($target,$copyfile)) {
3478: print $logfile "Copied old target to ".$copyfile."\n";
3479: $copyfile=$copyfile.'.meta';
3480: if (copy($target.'.meta',$copyfile)) {
3481: print $logfile "Copied old target metadata to ".$copyfile."\n";
3482: $output = 'ok';
3483: } else {
3484: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
3485: $output = &mt('Failed to copy old meta').", $!, ";
3486: }
3487: } else {
3488: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
3489: $output = &mt('Failed to copy old target').", $!, ";
3490: }
3491: return $output;
3492: }
3493:
3494: sub write_metadata {
3495: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
3496: my (%metadatafields,%metadatakeys,$output);
3497: $metadatafields{'title'}=$formname;
3498: $metadatafields{'creationdate'}=time;
3499: $metadatafields{'lastrevisiondate'}=time;
3500: $metadatafields{'copyright'}='public';
3501: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
3502: $env{'user.domain'};
3503: $metadatafields{'authorspace'}=$confname.':'.$dom;
3504: $metadatafields{'domain'}=$dom;
3505: {
3506: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
3507: my $mfh;
3508: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
3509: $output = &mt('Could not write metadata');
3510: }
3511: foreach (sort keys %metadatafields) {
3512: unless ($_=~/\./) {
3513: my $unikey=$_;
3514: $unikey=~/^([A-Za-z]+)/;
3515: my $tag=$1;
3516: $tag=~tr/A-Z/a-z/;
3517: print $mfh "\n\<$tag";
3518: foreach (split(/\,/,$metadatakeys{$unikey})) {
3519: my $value=$metadatafields{$unikey.'.'.$_};
3520: $value=~s/\"/\'\'/g;
3521: print $mfh ' '.$_.'="'.$value.'"';
3522: }
3523: print $mfh '>'.
3524: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
3525: .'</'.$tag.'>';
3526: }
3527: }
3528: $output = 'ok';
3529: print $logfile "\nWrote metadata";
3530: close($mfh);
3531: }
3532: }
3533:
3534: sub check_switchserver {
3535: my ($dom,$confname) = @_;
3536: my ($allowed,$switchserver);
3537: my $home = &Apache::lonnet::homeserver($confname,$dom);
3538: if ($home eq 'no_host') {
3539: $home = &Apache::lonnet::domain($dom,'primary');
3540: }
3541: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 3542: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3543: if (!$allowed) {
3544: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 3545: }
3546: return $switchserver;
3547: }
3548:
1.30 raeburn 3549: sub javascript_set_colnums {
3550: return <<END;
3551: function setDisplayColumns() {
3552: if (document.pickactions.width.value > 1100) {
3553: document.pickactions.numcols[1].checked = true;
3554: } else {
3555: document.pickactions.numcols[0].checked = true;
3556: }
3557: }
3558: END
3559: }
3560:
1.1 raeburn 3561: sub modify_quotas {
1.86 raeburn 3562: my ($dom,$action,%domconfig) = @_;
3563: my ($context,@usertools);
3564: if ($action eq 'quotas') {
3565: $context = 'tools';
3566: } else {
3567: $context = $action;
3568: }
3569: if ($context eq 'requestcourses') {
3570: @usertools = ('official','unofficial');
3571: } else {
3572: @usertools = ('aboutme','blog','portfolio');
3573: }
1.72 raeburn 3574: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.1 raeburn 3575: my ($resulttext,%changes);
1.44 raeburn 3576: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.72 raeburn 3577: my %titles = &tool_titles();
3578: my (%confhash,%toolshash);
1.1 raeburn 3579: foreach my $key (keys(%env)) {
1.86 raeburn 3580: unless ($context eq 'requestcourses') {
3581: if ($key =~ /^form\.quota_(.+)$/) {
3582: $confhash{'defaultquota'}{$1} = $env{$key};
3583: }
3584: }
3585: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.72 raeburn 3586: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
3587: }
3588: }
1.86 raeburn 3589: unless ($context eq 'requestcourses') {
3590: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
3591: }
1.72 raeburn 3592: foreach my $item (@usertools) {
3593: foreach my $type (@{$types},'default','_LC_adv') {
3594: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
3595: $confhash{$item}{$type} = 1;
3596: } else {
3597: $confhash{$item}{$type} = 0;
3598: }
1.86 raeburn 3599: if (ref($domconfig{$action}) eq 'HASH') {
3600: if (ref($domconfig{$action}{$item}) eq 'HASH') {
3601: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
3602: $changes{$item}{$type} = 1;
3603: }
3604: } else {
3605: if ($context eq 'requestcourses') {
3606: if ($confhash{$item}{$type}) {
3607: $changes{$item}{$type} = 1;
3608: }
3609: } else {
3610: if (!$confhash{$item}{$type}) {
3611: $changes{$item}{$type} = 1;
3612: }
3613: }
3614: }
3615: } else {
3616: if ($context eq 'requestcourses') {
3617: if ($confhash{$item}{$type}) {
1.72 raeburn 3618: $changes{$item}{$type} = 1;
3619: }
3620: } else {
3621: if (!$confhash{$item}{$type}) {
3622: $changes{$item}{$type} = 1;
3623: }
3624: }
3625: }
1.1 raeburn 3626: }
3627: }
1.86 raeburn 3628: unless ($context eq 'requestcourses') {
3629: if (ref($domconfig{'quotas'}) eq 'HASH') {
3630: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3631: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
3632: if (exists($confhash{'defaultquota'}{$key})) {
3633: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
3634: $changes{'defaultquota'}{$key} = 1;
3635: }
3636: } else {
3637: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 3638: }
3639: }
1.86 raeburn 3640: } else {
3641: foreach my $key (keys(%{$domconfig{'quotas'}})) {
3642: if (exists($confhash{'defaultquota'}{$key})) {
3643: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
3644: $changes{'defaultquota'}{$key} = 1;
3645: }
3646: } else {
3647: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 3648: }
1.1 raeburn 3649: }
3650: }
3651: }
1.86 raeburn 3652: if (ref($confhash{'defaultquota'}) eq 'HASH') {
3653: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
3654: if (ref($domconfig{'quotas'}) eq 'HASH') {
3655: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3656: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
3657: $changes{'defaultquota'}{$key} = 1;
3658: }
3659: } else {
3660: if (!exists($domconfig{'quotas'}{$key})) {
3661: $changes{'defaultquota'}{$key} = 1;
3662: }
1.72 raeburn 3663: }
3664: } else {
1.86 raeburn 3665: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 3666: }
1.1 raeburn 3667: }
3668: }
3669: }
1.72 raeburn 3670:
3671: foreach my $key (keys(%confhash)) {
3672: $domdefaults{$key} = $confhash{$key};
3673: }
3674:
1.1 raeburn 3675: my %quotahash = (
1.86 raeburn 3676: $action => { %confhash }
1.1 raeburn 3677: );
3678: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
3679: $dom);
3680: if ($putresult eq 'ok') {
3681: if (keys(%changes) > 0) {
1.72 raeburn 3682: my $cachetime = 24*60*60;
3683: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
3684:
1.1 raeburn 3685: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 3686: unless ($context eq 'requestcourses') {
3687: if (ref($changes{'defaultquota'}) eq 'HASH') {
3688: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
3689: foreach my $type (@{$types},'default') {
3690: if (defined($changes{'defaultquota'}{$type})) {
3691: my $typetitle = $usertypes->{$type};
3692: if ($type eq 'default') {
3693: $typetitle = $othertitle;
3694: }
3695: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 3696: }
3697: }
1.86 raeburn 3698: $resulttext .= '</ul></li>';
1.72 raeburn 3699: }
3700: }
1.80 raeburn 3701: my %newenv;
1.72 raeburn 3702: foreach my $item (@usertools) {
3703: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 3704: my $newacc =
3705: &Apache::lonnet::usertools_access($env{'user.name'},
3706: $env{'user.domain'},
1.86 raeburn 3707: $item,'reload',$context);
3708: if ($context eq 'requestcourses') {
3709: if ($env{'environment.canrequest.'.$item} ne $newacc) {
3710: $newenv{'environment.canrequest.'.$item} = $newacc;
3711: }
3712: } else {
3713: if ($env{'environment.availabletools.'.$item} ne $newacc) {
3714: $newenv{'environment.availabletools.'.$item} = $newacc;
3715: }
1.80 raeburn 3716: }
1.72 raeburn 3717: $resulttext .= '<li>'.$titles{$item}.'<ul>';
3718: foreach my $type (@{$types},'default','_LC_adv') {
3719: if ($changes{$item}{$type}) {
3720: my $typetitle = $usertypes->{$type};
3721: if ($type eq 'default') {
3722: $typetitle = $othertitle;
3723: } elsif ($type eq '_LC_adv') {
3724: $typetitle = 'LON-CAPA Advanced Users';
3725: }
3726: if ($confhash{$item}{$type}) {
3727: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
3728: } else {
3729: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
3730: }
3731: }
1.26 raeburn 3732: }
1.72 raeburn 3733: $resulttext .= '</ul></li>';
1.26 raeburn 3734: }
1.1 raeburn 3735: }
3736: $resulttext .= '</ul>';
1.80 raeburn 3737: if (keys(%newenv)) {
3738: &Apache::lonnet::appenv(\%newenv);
3739: }
1.1 raeburn 3740: } else {
1.86 raeburn 3741: if ($context eq 'requestcourses') {
3742: $resulttext = &mt('No changes made to rights to request creation of courses.');
3743: } else {
3744: $resulttext = &mt('No changes made to availability of home pages, blogs, portfolios or default quotas');
3745: }
1.1 raeburn 3746: }
3747: } else {
1.11 albertel 3748: $resulttext = '<span class="LC_error">'.
3749: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3750: }
1.3 raeburn 3751: return $resulttext;
1.1 raeburn 3752: }
3753:
1.3 raeburn 3754: sub modify_autoenroll {
3755: my ($dom,%domconfig) = @_;
1.1 raeburn 3756: my ($resulttext,%changes);
3757: my %currautoenroll;
3758: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
3759: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
3760: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
3761: }
3762: }
3763: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
3764: my %title = ( run => 'Auto-enrollment active',
3765: sender => 'Sender for notification messages');
3766: my @offon = ('off','on');
1.17 raeburn 3767: my $sender_uname = $env{'form.sender_uname'};
3768: my $sender_domain = $env{'form.sender_domain'};
3769: if ($sender_domain eq '') {
3770: $sender_uname = '';
3771: } elsif ($sender_uname eq '') {
3772: $sender_domain = '';
3773: }
1.1 raeburn 3774: my %autoenrollhash = (
3775: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 3776: sender_uname => $sender_uname,
3777: sender_domain => $sender_domain,
1.1 raeburn 3778:
3779: }
3780: );
1.4 raeburn 3781: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
3782: $dom);
1.1 raeburn 3783: if ($putresult eq 'ok') {
3784: if (exists($currautoenroll{'run'})) {
3785: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
3786: $changes{'run'} = 1;
3787: }
3788: } elsif ($autorun) {
3789: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 3790: $changes{'run'} = 1;
1.1 raeburn 3791: }
3792: }
1.17 raeburn 3793: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 3794: $changes{'sender'} = 1;
3795: }
1.17 raeburn 3796: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 3797: $changes{'sender'} = 1;
3798: }
3799: if (keys(%changes) > 0) {
3800: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 3801: if ($changes{'run'}) {
1.1 raeburn 3802: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
3803: }
3804: if ($changes{'sender'}) {
1.17 raeburn 3805: if ($sender_uname eq '' || $sender_domain eq '') {
3806: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
3807: } else {
3808: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
3809: }
1.1 raeburn 3810: }
3811: $resulttext .= '</ul>';
3812: } else {
3813: $resulttext = &mt('No changes made to auto-enrollment settings');
3814: }
3815: } else {
1.11 albertel 3816: $resulttext = '<span class="LC_error">'.
3817: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3818: }
1.3 raeburn 3819: return $resulttext;
1.1 raeburn 3820: }
3821:
3822: sub modify_autoupdate {
1.3 raeburn 3823: my ($dom,%domconfig) = @_;
1.1 raeburn 3824: my ($resulttext,%currautoupdate,%fields,%changes);
3825: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
3826: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
3827: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
3828: }
3829: }
3830: my @offon = ('off','on');
3831: my %title = &Apache::lonlocal::texthash (
3832: run => 'Auto-update:',
3833: classlists => 'Updates to user information in classlists?'
3834: );
1.44 raeburn 3835: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 3836: my %fieldtitles = &Apache::lonlocal::texthash (
3837: id => 'Student/Employee ID',
1.20 raeburn 3838: permanentemail => 'E-mail address',
1.1 raeburn 3839: lastname => 'Last Name',
3840: firstname => 'First Name',
3841: middlename => 'Middle Name',
3842: gen => 'Generation',
3843: );
3844: my $othertitle = &mt('All users');
3845: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 3846: $othertitle = &mt('Other users');
1.1 raeburn 3847: }
3848: foreach my $key (keys(%env)) {
3849: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
3850: push(@{$fields{$1}},$2);
3851: }
3852: }
3853: my %updatehash = (
3854: autoupdate => { run => $env{'form.autoupdate_run'},
3855: classlists => $env{'form.classlists'},
3856: fields => {%fields},
3857: }
3858: );
3859: foreach my $key (keys(%currautoupdate)) {
3860: if (($key eq 'run') || ($key eq 'classlists')) {
3861: if (exists($updatehash{autoupdate}{$key})) {
3862: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
3863: $changes{$key} = 1;
3864: }
3865: }
3866: } elsif ($key eq 'fields') {
3867: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 3868: foreach my $item (@{$types},'default') {
1.1 raeburn 3869: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
3870: my $change = 0;
3871: foreach my $type (@{$currautoupdate{$key}{$item}}) {
3872: if (!exists($fields{$item})) {
3873: $change = 1;
3874: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 3875: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 3876: $change = 1;
3877: }
3878: }
3879: }
3880: if ($change) {
3881: push(@{$changes{$key}},$item);
3882: }
1.26 raeburn 3883: }
1.1 raeburn 3884: }
3885: }
3886: }
3887: }
1.26 raeburn 3888: foreach my $item (@{$types},'default') {
3889: if (defined($fields{$item})) {
3890: if (ref($currautoupdate{'fields'}) eq 'HASH') {
3891: if (!exists($currautoupdate{'fields'}{$item})) {
3892: push(@{$changes{'fields'}},$item);
3893: }
3894: } else {
3895: push(@{$changes{'fields'}},$item);
1.1 raeburn 3896: }
3897: }
3898: }
3899: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
3900: $dom);
3901: if ($putresult eq 'ok') {
3902: if (keys(%changes) > 0) {
3903: $resulttext = &mt('Changes made:').'<ul>';
3904: foreach my $key (sort(keys(%changes))) {
3905: if (ref($changes{$key}) eq 'ARRAY') {
3906: foreach my $item (@{$changes{$key}}) {
3907: my @newvalues;
3908: foreach my $type (@{$fields{$item}}) {
3909: push(@newvalues,$fieldtitles{$type});
3910: }
1.3 raeburn 3911: my $newvaluestr;
3912: if (@newvalues > 0) {
3913: $newvaluestr = join(', ',@newvalues);
3914: } else {
3915: $newvaluestr = &mt('none');
1.6 raeburn 3916: }
1.1 raeburn 3917: if ($item eq 'default') {
1.26 raeburn 3918: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 3919: } else {
1.26 raeburn 3920: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 3921: }
3922: }
3923: } else {
3924: my $newvalue;
3925: if ($key eq 'run') {
3926: $newvalue = $offon[$env{'form.autoupdate_run'}];
3927: } else {
3928: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 3929: }
1.1 raeburn 3930: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
3931: }
3932: }
3933: $resulttext .= '</ul>';
3934: } else {
1.3 raeburn 3935: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 3936: }
3937: } else {
1.11 albertel 3938: $resulttext = '<span class="LC_error">'.
3939: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3940: }
1.3 raeburn 3941: return $resulttext;
1.1 raeburn 3942: }
3943:
1.23 raeburn 3944: sub modify_directorysrch {
3945: my ($dom,%domconfig) = @_;
3946: my ($resulttext,%changes);
3947: my %currdirsrch;
3948: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3949: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
3950: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
3951: }
3952: }
3953: my %title = ( available => 'Directory search available',
1.24 raeburn 3954: localonly => 'Other domains can search',
1.23 raeburn 3955: searchby => 'Search types',
3956: searchtypes => 'Search latitude');
3957: my @offon = ('off','on');
1.24 raeburn 3958: my @otherdoms = ('Yes','No');
1.23 raeburn 3959:
1.25 raeburn 3960: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 3961: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
3962: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
3963:
1.44 raeburn 3964: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 3965: if (keys(%{$usertypes}) == 0) {
3966: @cansearch = ('default');
3967: } else {
3968: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
3969: foreach my $type (@{$currdirsrch{'cansearch'}}) {
3970: if (!grep(/^\Q$type\E$/,@cansearch)) {
3971: push(@{$changes{'cansearch'}},$type);
3972: }
1.23 raeburn 3973: }
1.26 raeburn 3974: foreach my $type (@cansearch) {
3975: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
3976: push(@{$changes{'cansearch'}},$type);
3977: }
1.23 raeburn 3978: }
1.26 raeburn 3979: } else {
3980: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 3981: }
3982: }
3983:
3984: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
3985: foreach my $by (@{$currdirsrch{'searchby'}}) {
3986: if (!grep(/^\Q$by\E$/,@searchby)) {
3987: push(@{$changes{'searchby'}},$by);
3988: }
3989: }
3990: foreach my $by (@searchby) {
3991: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
3992: push(@{$changes{'searchby'}},$by);
3993: }
3994: }
3995: } else {
3996: push(@{$changes{'searchby'}},@searchby);
3997: }
1.25 raeburn 3998:
3999: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
4000: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
4001: if (!grep(/^\Q$type\E$/,@searchtypes)) {
4002: push(@{$changes{'searchtypes'}},$type);
4003: }
4004: }
4005: foreach my $type (@searchtypes) {
4006: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
4007: push(@{$changes{'searchtypes'}},$type);
4008: }
4009: }
4010: } else {
4011: if (exists($currdirsrch{'searchtypes'})) {
4012: foreach my $type (@searchtypes) {
4013: if ($type ne $currdirsrch{'searchtypes'}) {
4014: push(@{$changes{'searchtypes'}},$type);
4015: }
4016: }
4017: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
4018: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
4019: }
4020: } else {
4021: push(@{$changes{'searchtypes'}},@searchtypes);
4022: }
4023: }
4024:
1.23 raeburn 4025: my %dirsrch_hash = (
4026: directorysrch => { available => $env{'form.dirsrch_available'},
4027: cansearch => \@cansearch,
1.24 raeburn 4028: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 4029: searchby => \@searchby,
1.25 raeburn 4030: searchtypes => \@searchtypes,
1.23 raeburn 4031: }
4032: );
4033: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
4034: $dom);
4035: if ($putresult eq 'ok') {
4036: if (exists($currdirsrch{'available'})) {
4037: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
4038: $changes{'available'} = 1;
4039: }
4040: } else {
4041: if ($env{'form.dirsrch_available'} eq '1') {
4042: $changes{'available'} = 1;
4043: }
4044: }
1.24 raeburn 4045: if (exists($currdirsrch{'localonly'})) {
4046: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
4047: $changes{'localonly'} = 1;
4048: }
4049: } else {
4050: if ($env{'form.dirsrch_localonly'} eq '1') {
4051: $changes{'localonly'} = 1;
4052: }
4053: }
1.23 raeburn 4054: if (keys(%changes) > 0) {
4055: $resulttext = &mt('Changes made:').'<ul>';
4056: if ($changes{'available'}) {
4057: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
4058: }
1.24 raeburn 4059: if ($changes{'localonly'}) {
4060: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
4061: }
4062:
1.23 raeburn 4063: if (ref($changes{'cansearch'}) eq 'ARRAY') {
4064: my $chgtext;
1.26 raeburn 4065: if (ref($usertypes) eq 'HASH') {
4066: if (keys(%{$usertypes}) > 0) {
4067: foreach my $type (@{$types}) {
4068: if (grep(/^\Q$type\E$/,@cansearch)) {
4069: $chgtext .= $usertypes->{$type}.'; ';
4070: }
4071: }
4072: if (grep(/^default$/,@cansearch)) {
4073: $chgtext .= $othertitle;
4074: } else {
4075: $chgtext =~ s/\; $//;
4076: }
4077: $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 4078: }
4079: }
4080: }
4081: if (ref($changes{'searchby'}) eq 'ARRAY') {
4082: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4083: my $chgtext;
4084: foreach my $type (@{$titleorder}) {
4085: if (grep(/^\Q$type\E$/,@searchby)) {
4086: if (defined($searchtitles->{$type})) {
4087: $chgtext .= $searchtitles->{$type}.'; ';
4088: }
4089: }
4090: }
4091: $chgtext =~ s/\; $//;
4092: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
4093: }
1.25 raeburn 4094: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
4095: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
4096: my $chgtext;
4097: foreach my $type (@{$srchtypeorder}) {
4098: if (grep(/^\Q$type\E$/,@searchtypes)) {
4099: if (defined($srchtypes_desc->{$type})) {
4100: $chgtext .= $srchtypes_desc->{$type}.'; ';
4101: }
4102: }
4103: }
4104: $chgtext =~ s/\; $//;
4105: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 4106: }
4107: $resulttext .= '</ul>';
4108: } else {
4109: $resulttext = &mt('No changes made to institution directory search settings');
4110: }
4111: } else {
4112: $resulttext = '<span class="LC_error">'.
1.27 raeburn 4113: &mt('An error occurred: [_1]',$putresult).'</span>';
4114: }
4115: return $resulttext;
4116: }
4117:
1.28 raeburn 4118: sub modify_contacts {
4119: my ($dom,%domconfig) = @_;
4120: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
4121: if (ref($domconfig{'contacts'}) eq 'HASH') {
4122: foreach my $key (keys(%{$domconfig{'contacts'}})) {
4123: $currsetting{$key} = $domconfig{'contacts'}{$key};
4124: }
4125: }
4126: my (%others,%to);
4127: my @contacts = ('supportemail','adminemail');
1.89 ! raeburn 4128: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail');
1.28 raeburn 4129: foreach my $type (@mailings) {
4130: @{$newsetting{$type}} =
4131: &Apache::loncommon::get_env_multiple('form.'.$type);
4132: foreach my $item (@contacts) {
4133: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
4134: $contacts_hash{contacts}{$type}{$item} = 1;
4135: } else {
4136: $contacts_hash{contacts}{$type}{$item} = 0;
4137: }
4138: }
4139: $others{$type} = $env{'form.'.$type.'_others'};
4140: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
4141: }
4142: foreach my $item (@contacts) {
4143: $to{$item} = $env{'form.'.$item};
4144: $contacts_hash{'contacts'}{$item} = $to{$item};
4145: }
4146: if (keys(%currsetting) > 0) {
4147: foreach my $item (@contacts) {
4148: if ($to{$item} ne $currsetting{$item}) {
4149: $changes{$item} = 1;
4150: }
4151: }
4152: foreach my $type (@mailings) {
4153: foreach my $item (@contacts) {
4154: if (ref($currsetting{$type}) eq 'HASH') {
4155: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
4156: push(@{$changes{$type}},$item);
4157: }
4158: } else {
4159: push(@{$changes{$type}},@{$newsetting{$type}});
4160: }
4161: }
4162: if ($others{$type} ne $currsetting{$type}{'others'}) {
4163: push(@{$changes{$type}},'others');
4164: }
4165: }
4166: } else {
4167: my %default;
4168: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4169: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4170: $default{'errormail'} = 'adminemail';
4171: $default{'packagesmail'} = 'adminemail';
4172: $default{'helpdeskmail'} = 'supportemail';
1.89 ! raeburn 4173: $default{'lonstatusmail'} = 'adminemail';
1.28 raeburn 4174: foreach my $item (@contacts) {
4175: if ($to{$item} ne $default{$item}) {
4176: $changes{$item} = 1;
4177: }
4178: }
4179: foreach my $type (@mailings) {
4180: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
4181:
4182: push(@{$changes{$type}},@{$newsetting{$type}});
4183: }
4184: if ($others{$type} ne '') {
4185: push(@{$changes{$type}},'others');
4186: }
4187: }
4188: }
4189: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
4190: $dom);
4191: if ($putresult eq 'ok') {
4192: if (keys(%changes) > 0) {
4193: my ($titles,$short_titles) = &contact_titles();
4194: $resulttext = &mt('Changes made:').'<ul>';
4195: foreach my $item (@contacts) {
4196: if ($changes{$item}) {
4197: $resulttext .= '<li>'.$titles->{$item}.
4198: &mt(' set to: ').
4199: '<span class="LC_cusr_emph">'.
4200: $to{$item}.'</span></li>';
4201: }
4202: }
4203: foreach my $type (@mailings) {
4204: if (ref($changes{$type}) eq 'ARRAY') {
4205: $resulttext .= '<li>'.$titles->{$type}.': ';
4206: my @text;
4207: foreach my $item (@{$newsetting{$type}}) {
4208: push(@text,$short_titles->{$item});
4209: }
4210: if ($others{$type} ne '') {
4211: push(@text,$others{$type});
4212: }
4213: $resulttext .= '<span class="LC_cusr_emph">'.
4214: join(', ',@text).'</span></li>';
4215: }
4216: }
4217: $resulttext .= '</ul>';
4218: } else {
1.34 raeburn 4219: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 4220: }
4221: } else {
4222: $resulttext = '<span class="LC_error">'.
4223: &mt('An error occurred: [_1].',$putresult).'</span>';
4224: }
4225: return $resulttext;
4226: }
4227:
4228: sub modify_usercreation {
1.27 raeburn 4229: my ($dom,%domconfig) = @_;
1.34 raeburn 4230: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 4231: my $warningmsg;
1.27 raeburn 4232: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4233: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
4234: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
4235: }
4236: }
4237: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 4238: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 4239: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.45 raeburn 4240: my @contexts = ('author','course','selfcreate');
1.34 raeburn 4241: foreach my $item(@contexts) {
1.45 raeburn 4242: if ($item eq 'selfcreate') {
1.50 raeburn 4243: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 4244: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4245: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 4246: if (ref($cancreate{$item}) eq 'ARRAY') {
4247: if (grep(/^login$/,@{$cancreate{$item}})) {
4248: $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');
4249: }
1.43 raeburn 4250: }
4251: }
1.50 raeburn 4252: } else {
4253: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 4254: }
1.34 raeburn 4255: }
4256: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
4257: foreach my $item (@contexts) {
1.50 raeburn 4258: if ($item eq 'selfcreate') {
4259: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
4260: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
4261: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
4262: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4263: push(@{$changes{'cancreate'}},$item);
4264: }
4265: }
4266: }
4267: } else {
4268: if ($curr_usercreation{'cancreate'}{$item} eq '') {
4269: if (@{$cancreate{$item}} > 0) {
4270: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4271: push(@{$changes{'cancreate'}},$item);
4272: }
4273: }
4274: } else {
4275: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
4276: if (@{$cancreate{$item}} < 3) {
4277: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4278: push(@{$changes{'cancreate'}},$item);
4279: }
4280: }
4281: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
4282: if (@{$cancreate{$item}} > 0) {
4283: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4284: push(@{$changes{'cancreate'}},$item);
4285: }
4286: }
4287: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
4288: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4289: push(@{$changes{'cancreate'}},$item);
4290: }
4291: }
4292: }
4293: }
4294: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4295: foreach my $type (@{$cancreate{$item}}) {
4296: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
4297: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
4298: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4299: push(@{$changes{'cancreate'}},$item);
4300: }
4301: }
4302: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
4303: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
4304: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
4305: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4306: push(@{$changes{'cancreate'}},$item);
4307: }
4308: }
4309: }
4310: }
4311: }
4312: } else {
4313: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
4314: push(@{$changes{'cancreate'}},$item);
4315: }
4316: }
1.27 raeburn 4317: }
1.34 raeburn 4318: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
4319: foreach my $item (@contexts) {
1.43 raeburn 4320: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 4321: if ($cancreate{$item} ne 'any') {
4322: push(@{$changes{'cancreate'}},$item);
4323: }
4324: } else {
4325: if ($cancreate{$item} ne 'none') {
4326: push(@{$changes{'cancreate'}},$item);
4327: }
1.27 raeburn 4328: }
4329: }
4330: } else {
1.43 raeburn 4331: foreach my $item (@contexts) {
1.34 raeburn 4332: push(@{$changes{'cancreate'}},$item);
4333: }
1.27 raeburn 4334: }
1.34 raeburn 4335:
1.27 raeburn 4336: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
4337: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
4338: if (!grep(/^\Q$type\E$/,@username_rule)) {
4339: push(@{$changes{'username_rule'}},$type);
4340: }
4341: }
4342: foreach my $type (@username_rule) {
4343: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
4344: push(@{$changes{'username_rule'}},$type);
4345: }
4346: }
4347: } else {
4348: push(@{$changes{'username_rule'}},@username_rule);
4349: }
4350:
1.32 raeburn 4351: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
4352: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
4353: if (!grep(/^\Q$type\E$/,@id_rule)) {
4354: push(@{$changes{'id_rule'}},$type);
4355: }
4356: }
4357: foreach my $type (@id_rule) {
4358: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
4359: push(@{$changes{'id_rule'}},$type);
4360: }
4361: }
4362: } else {
4363: push(@{$changes{'id_rule'}},@id_rule);
4364: }
4365:
1.43 raeburn 4366: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
4367: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
4368: if (!grep(/^\Q$type\E$/,@email_rule)) {
4369: push(@{$changes{'email_rule'}},$type);
4370: }
4371: }
4372: foreach my $type (@email_rule) {
4373: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
4374: push(@{$changes{'email_rule'}},$type);
4375: }
4376: }
4377: } else {
4378: push(@{$changes{'email_rule'}},@email_rule);
4379: }
4380:
4381: my @authen_contexts = ('author','course','domain');
1.28 raeburn 4382: my @authtypes = ('int','krb4','krb5','loc');
4383: my %authhash;
1.43 raeburn 4384: foreach my $item (@authen_contexts) {
1.28 raeburn 4385: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
4386: foreach my $auth (@authtypes) {
4387: if (grep(/^\Q$auth\E$/,@authallowed)) {
4388: $authhash{$item}{$auth} = 1;
4389: } else {
4390: $authhash{$item}{$auth} = 0;
4391: }
4392: }
4393: }
4394: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 4395: foreach my $item (@authen_contexts) {
1.28 raeburn 4396: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
4397: foreach my $auth (@authtypes) {
4398: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
4399: push(@{$changes{'authtypes'}},$item);
4400: last;
4401: }
4402: }
4403: }
4404: }
4405: } else {
1.43 raeburn 4406: foreach my $item (@authen_contexts) {
1.28 raeburn 4407: push(@{$changes{'authtypes'}},$item);
4408: }
4409: }
4410:
1.27 raeburn 4411: my %usercreation_hash = (
1.28 raeburn 4412: usercreation => {
1.34 raeburn 4413: cancreate => \%cancreate,
1.27 raeburn 4414: username_rule => \@username_rule,
1.32 raeburn 4415: id_rule => \@id_rule,
1.43 raeburn 4416: email_rule => \@email_rule,
1.32 raeburn 4417: authtypes => \%authhash,
1.27 raeburn 4418: }
4419: );
4420:
4421: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
4422: $dom);
1.50 raeburn 4423:
4424: my %selfcreatetypes = (
4425: sso => 'users authenticated by institutional single sign on',
4426: login => 'users authenticated by institutional log-in',
4427: email => 'users who provide a valid e-mail address for use as the username',
4428: );
1.27 raeburn 4429: if ($putresult eq 'ok') {
4430: if (keys(%changes) > 0) {
4431: $resulttext = &mt('Changes made:').'<ul>';
4432: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 4433: my %lt = &usercreation_types();
4434: foreach my $type (@{$changes{'cancreate'}}) {
1.43 raeburn 4435: my $chgtext = $lt{$type}.', ';
1.45 raeburn 4436: if ($type eq 'selfcreate') {
1.50 raeburn 4437: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 4438: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 4439: } else {
4440: $chgtext .= &mt('creation of a new account is permitted for:<ul>');
4441: foreach my $case (@{$cancreate{$type}}) {
4442: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
4443: }
4444: $chgtext .= '</ul>';
1.43 raeburn 4445: }
4446: } else {
4447: if ($cancreate{$type} eq 'none') {
4448: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
4449: } elsif ($cancreate{$type} eq 'any') {
4450: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
4451: } elsif ($cancreate{$type} eq 'official') {
4452: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
4453: } elsif ($cancreate{$type} eq 'unofficial') {
4454: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
4455: }
1.34 raeburn 4456: }
4457: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 4458: }
4459: }
4460: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 4461: my ($rules,$ruleorder) =
4462: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 4463: my $chgtext = '<ul>';
4464: foreach my $type (@username_rule) {
4465: if (ref($rules->{$type}) eq 'HASH') {
4466: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
4467: }
4468: }
4469: $chgtext .= '</ul>';
4470: if (@username_rule > 0) {
4471: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4472: } else {
1.28 raeburn 4473: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 4474: }
4475: }
1.32 raeburn 4476: if (ref($changes{'id_rule'}) eq 'ARRAY') {
4477: my ($idrules,$idruleorder) =
4478: &Apache::lonnet::inst_userrules($dom,'id');
4479: my $chgtext = '<ul>';
4480: foreach my $type (@id_rule) {
4481: if (ref($idrules->{$type}) eq 'HASH') {
4482: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
4483: }
4484: }
4485: $chgtext .= '</ul>';
4486: if (@id_rule > 0) {
4487: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4488: } else {
4489: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
4490: }
4491: }
1.43 raeburn 4492: if (ref($changes{'email_rule'}) eq 'ARRAY') {
4493: my ($emailrules,$emailruleorder) =
4494: &Apache::lonnet::inst_userrules($dom,'email');
4495: my $chgtext = '<ul>';
4496: foreach my $type (@email_rule) {
4497: if (ref($emailrules->{$type}) eq 'HASH') {
4498: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
4499: }
4500: }
4501: $chgtext .= '</ul>';
4502: if (@email_rule > 0) {
4503: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
4504: } else {
4505: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
4506: }
4507: }
4508:
1.28 raeburn 4509: my %authname = &authtype_names();
4510: my %context_title = &context_names();
4511: if (ref($changes{'authtypes'}) eq 'ARRAY') {
4512: my $chgtext = '<ul>';
4513: foreach my $type (@{$changes{'authtypes'}}) {
4514: my @allowed;
4515: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
4516: foreach my $auth (@authtypes) {
4517: if ($authhash{$type}{$auth}) {
4518: push(@allowed,$authname{$auth});
4519: }
4520: }
1.43 raeburn 4521: if (@allowed > 0) {
4522: $chgtext .= join(', ',@allowed).'</li>';
4523: } else {
4524: $chgtext .= &mt('none').'</li>';
4525: }
1.28 raeburn 4526: }
4527: $chgtext .= '</ul>';
4528: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
4529: $resulttext .= '</li>';
4530: }
1.27 raeburn 4531: $resulttext .= '</ul>';
4532: } else {
1.28 raeburn 4533: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 4534: }
4535: } else {
4536: $resulttext = '<span class="LC_error">'.
1.23 raeburn 4537: &mt('An error occurred: [_1]',$putresult).'</span>';
4538: }
1.43 raeburn 4539: if ($warningmsg ne '') {
4540: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
4541: }
1.23 raeburn 4542: return $resulttext;
4543: }
4544:
1.33 raeburn 4545: sub modify_usermodification {
4546: my ($dom,%domconfig) = @_;
4547: my ($resulttext,%curr_usermodification,%changes);
4548: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4549: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
4550: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
4551: }
4552: }
1.63 raeburn 4553: my @contexts = ('author','course','selfcreate');
1.33 raeburn 4554: my %context_title = (
4555: author => 'In author context',
4556: course => 'In course context',
1.63 raeburn 4557: selfcreate => 'When self creating account',
1.33 raeburn 4558: );
4559: my @fields = ('lastname','firstname','middlename','generation',
4560: 'permanentemail','id');
4561: my %roles = (
4562: author => ['ca','aa'],
4563: course => ['st','ep','ta','in','cr'],
4564: );
1.63 raeburn 4565: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4566: if (ref($types) eq 'ARRAY') {
4567: push(@{$types},'default');
4568: $usertypes->{'default'} = $othertitle;
4569: }
4570: $roles{'selfcreate'} = $types;
1.33 raeburn 4571: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4572: my %modifyhash;
4573: foreach my $context (@contexts) {
4574: foreach my $role (@{$roles{$context}}) {
4575: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
4576: foreach my $item (@fields) {
4577: if (grep(/^\Q$item\E$/,@modifiable)) {
4578: $modifyhash{$context}{$role}{$item} = 1;
4579: } else {
4580: $modifyhash{$context}{$role}{$item} = 0;
4581: }
4582: }
4583: }
4584: if (ref($curr_usermodification{$context}) eq 'HASH') {
4585: foreach my $role (@{$roles{$context}}) {
4586: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
4587: foreach my $field (@fields) {
4588: if ($modifyhash{$context}{$role}{$field} ne
4589: $curr_usermodification{$context}{$role}{$field}) {
4590: push(@{$changes{$context}},$role);
4591: last;
4592: }
4593: }
4594: }
4595: }
4596: } else {
4597: foreach my $context (@contexts) {
4598: foreach my $role (@{$roles{$context}}) {
4599: push(@{$changes{$context}},$role);
4600: }
4601: }
4602: }
4603: }
4604: my %usermodification_hash = (
4605: usermodification => \%modifyhash,
4606: );
4607: my $putresult = &Apache::lonnet::put_dom('configuration',
4608: \%usermodification_hash,$dom);
4609: if ($putresult eq 'ok') {
4610: if (keys(%changes) > 0) {
4611: $resulttext = &mt('Changes made: ').'<ul>';
4612: foreach my $context (@contexts) {
4613: if (ref($changes{$context}) eq 'ARRAY') {
4614: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
4615: if (ref($changes{$context}) eq 'ARRAY') {
4616: foreach my $role (@{$changes{$context}}) {
4617: my $rolename;
1.63 raeburn 4618: if ($context eq 'selfcreate') {
4619: $rolename = $role;
4620: if (ref($usertypes) eq 'HASH') {
4621: if ($usertypes->{$role} ne '') {
4622: $rolename = $usertypes->{$role};
4623: }
4624: }
1.33 raeburn 4625: } else {
1.63 raeburn 4626: if ($role eq 'cr') {
4627: $rolename = &mt('Custom');
4628: } else {
4629: $rolename = &Apache::lonnet::plaintext($role);
4630: }
1.33 raeburn 4631: }
4632: my @modifiable;
1.63 raeburn 4633: if ($context eq 'selfcreate') {
4634: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1] ',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
4635: } else {
4636: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
4637: }
1.33 raeburn 4638: foreach my $field (@fields) {
4639: if ($modifyhash{$context}{$role}{$field}) {
4640: push(@modifiable,$fieldtitles{$field});
4641: }
4642: }
4643: if (@modifiable > 0) {
4644: $resulttext .= join(', ',@modifiable);
4645: } else {
4646: $resulttext .= &mt('none');
4647: }
4648: $resulttext .= '</li>';
4649: }
4650: $resulttext .= '</ul></li>';
4651: }
4652: }
4653: }
4654: $resulttext .= '</ul>';
4655: } else {
4656: $resulttext = &mt('No changes made to user modification settings');
4657: }
4658: } else {
4659: $resulttext = '<span class="LC_error">'.
4660: &mt('An error occurred: [_1]',$putresult).'</span>';
4661: }
4662: return $resulttext;
4663: }
4664:
1.43 raeburn 4665: sub modify_defaults {
4666: my ($dom,$r) = @_;
4667: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
4668: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.68 raeburn 4669: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
1.43 raeburn 4670: my @authtypes = ('internal','krb4','krb5','localauth');
4671: foreach my $item (@items) {
4672: $newvalues{$item} = $env{'form.'.$item};
4673: if ($item eq 'auth_def') {
4674: if ($newvalues{$item} ne '') {
4675: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
4676: push(@errors,$item);
4677: }
4678: }
4679: } elsif ($item eq 'lang_def') {
4680: if ($newvalues{$item} ne '') {
4681: if ($newvalues{$item} =~ /^(\w+)/) {
4682: my $langcode = $1;
4683: if (code2language($langcode) eq '') {
4684: push(@errors,$item);
4685: }
4686: } else {
4687: push(@errors,$item);
4688: }
4689: }
1.54 raeburn 4690: } elsif ($item eq 'timezone_def') {
4691: if ($newvalues{$item} ne '') {
1.62 raeburn 4692: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 4693: push(@errors,$item);
4694: }
4695: }
1.68 raeburn 4696: } elsif ($item eq 'datelocale_def') {
4697: if ($newvalues{$item} ne '') {
4698: my @datelocale_ids = DateTime::Locale->ids();
4699: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
4700: push(@errors,$item);
4701: }
4702: }
1.43 raeburn 4703: }
4704: if (grep(/^\Q$item\E$/,@errors)) {
4705: $newvalues{$item} = $domdefaults{$item};
4706: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
4707: $changes{$item} = 1;
4708: }
1.72 raeburn 4709: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 4710: }
4711: my %defaults_hash = (
1.72 raeburn 4712: defaults => \%newvalues,
4713: );
1.43 raeburn 4714: my $title = &defaults_titles();
4715: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
4716: $dom);
4717: if ($putresult eq 'ok') {
4718: if (keys(%changes) > 0) {
4719: $resulttext = &mt('Changes made:').'<ul>';
4720: my $version = $r->dir_config('lonVersion');
4721: my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
4722: foreach my $item (sort(keys(%changes))) {
4723: my $value = $env{'form.'.$item};
4724: if ($value eq '') {
4725: $value = &mt('none');
4726: } elsif ($item eq 'auth_def') {
4727: my %authnames = &authtype_names();
4728: my %shortauth = (
4729: internal => 'int',
4730: krb4 => 'krb4',
4731: krb5 => 'krb5',
4732: localauth => 'loc',
4733: );
4734: $value = $authnames{$shortauth{$value}};
4735: }
4736: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
4737: $mailmsgtext .= "$title->{$item} set to $value\n";
4738: }
4739: $resulttext .= '</ul>';
4740: $mailmsgtext .= "\n";
4741: my $cachetime = 24*60*60;
1.72 raeburn 4742: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 4743: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 4744: my $sysmail = $r->dir_config('lonSysEMail');
4745: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
4746: }
1.43 raeburn 4747: } else {
1.54 raeburn 4748: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 4749: }
4750: } else {
4751: $resulttext = '<span class="LC_error">'.
4752: &mt('An error occurred: [_1]',$putresult).'</span>';
4753: }
4754: if (@errors > 0) {
4755: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
4756: foreach my $item (@errors) {
4757: $resulttext .= ' "'.$title->{$item}.'",';
4758: }
4759: $resulttext =~ s/,$//;
4760: }
4761: return $resulttext;
4762: }
4763:
1.46 raeburn 4764: sub modify_scantron {
1.48 raeburn 4765: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 4766: my ($resulttext,%confhash,%changes,$errors);
4767: my $custom = 'custom.tab';
4768: my $default = 'default.tab';
4769: my $servadm = $r->dir_config('lonAdmEMail');
4770: my ($configuserok,$author_ok,$switchserver) =
4771: &config_check($dom,$confname,$servadm);
4772: if ($env{'form.scantronformat.filename'} ne '') {
4773: my $error;
4774: if ($configuserok eq 'ok') {
4775: if ($switchserver) {
4776: $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
4777: } else {
4778: if ($author_ok eq 'ok') {
4779: my ($result,$scantronurl) =
4780: &publishlogo($r,'upload','scantronformat',$dom,
4781: $confname,'scantron','','',$custom);
4782: if ($result eq 'ok') {
4783: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 4784: $changes{'scantronformat'} = 1;
1.46 raeburn 4785: } else {
4786: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
4787: }
4788: } else {
4789: $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$author_ok);
4790: }
4791: }
4792: } else {
4793: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$configuserok);
4794: }
4795: if ($error) {
4796: &Apache::lonnet::logthis($error);
4797: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4798: }
4799: }
1.48 raeburn 4800: if (ref($domconfig{'scantron'}) eq 'HASH') {
4801: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
4802: if ($env{'form.scantronformat_del'}) {
4803: $confhash{'scantron'}{'scantronformat'} = '';
4804: $changes{'scantronformat'} = 1;
1.46 raeburn 4805: }
4806: }
4807: }
4808: if (keys(%confhash) > 0) {
4809: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
4810: $dom);
4811: if ($putresult eq 'ok') {
4812: if (keys(%changes) > 0) {
1.48 raeburn 4813: if (ref($confhash{'scantron'}) eq 'HASH') {
4814: $resulttext = &mt('Changes made:').'<ul>';
4815: if ($confhash{'scantron'}{'scantronformat'} eq '') {
4816: $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
4817: } else {
4818: $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 4819: }
1.48 raeburn 4820: $resulttext .= '</ul>';
4821: } else {
4822: $resulttext = &mt('Changes made to scantron format file.');
1.46 raeburn 4823: }
4824: $resulttext .= '</ul>';
4825: &Apache::loncommon::devalidate_domconfig_cache($dom);
4826: } else {
4827: $resulttext = &mt('No changes made to scantron format file');
4828: }
4829: } else {
4830: $resulttext = '<span class="LC_error">'.
4831: &mt('An error occurred: [_1]',$putresult).'</span>';
4832: }
4833: } else {
4834: $resulttext = &mt('No changes made to scantron format file');
4835: }
4836: if ($errors) {
4837: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4838: $errors.'</ul>';
4839: }
4840: return $resulttext;
4841: }
4842:
1.48 raeburn 4843: sub modify_coursecategories {
4844: my ($dom,%domconfig) = @_;
1.57 raeburn 4845: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
4846: $cathash);
1.48 raeburn 4847: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 4848: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 4849: $cathash = $domconfig{'coursecategories'}{'cats'};
4850: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
4851: $changes{'togglecats'} = 1;
4852: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
4853: }
4854: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
4855: $changes{'categorize'} = 1;
4856: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
4857: }
4858: } else {
4859: $changes{'togglecats'} = 1;
4860: $changes{'categorize'} = 1;
1.87 raeburn 4861: $domconfig{'coursecategories'} = {
4862: togglecats => $env{'form.togglecats'},
4863: categorize => $env{'form.categorize'},
4864: };
1.57 raeburn 4865: }
4866: if (ref($cathash) eq 'HASH') {
4867: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 4868: push (@deletecategory,'instcode::0');
4869: }
1.48 raeburn 4870: }
1.57 raeburn 4871: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
4872: if (ref($cathash) eq 'HASH') {
1.48 raeburn 4873: if (@deletecategory > 0) {
4874: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 4875: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 4876: foreach my $item (@deletecategory) {
1.57 raeburn 4877: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
4878: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 4879: $deletions{$item} = 1;
1.57 raeburn 4880: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 4881: }
4882: }
4883: }
1.57 raeburn 4884: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 4885: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 4886: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 4887: $reorderings{$item} = 1;
1.57 raeburn 4888: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 4889: }
4890: if ($env{'form.addcategory_name_'.$item} ne '') {
4891: my $newcat = $env{'form.addcategory_name_'.$item};
4892: my $newdepth = $depth+1;
4893: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 4894: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 4895: $adds{$newitem} = 1;
4896: }
4897: if ($env{'form.subcat_'.$item} ne '') {
4898: my $newcat = $env{'form.subcat_'.$item};
4899: my $newdepth = $depth+1;
4900: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 4901: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 4902: $adds{$newitem} = 1;
4903: }
4904: }
4905: }
4906: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 4907: if (ref($cathash) eq 'HASH') {
1.48 raeburn 4908: my $newitem = 'instcode::0';
1.57 raeburn 4909: if ($cathash->{$newitem} eq '') {
4910: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 4911: $adds{$newitem} = 1;
4912: }
4913: } else {
4914: my $newitem = 'instcode::0';
1.57 raeburn 4915: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 4916: $adds{$newitem} = 1;
4917: }
4918: }
4919: if ($env{'form.addcategory_name'} ne '') {
4920: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
1.57 raeburn 4921: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
1.48 raeburn 4922: $adds{$newitem} = 1;
4923: }
1.57 raeburn 4924: my $putresult;
1.48 raeburn 4925: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4926: if (keys(%deletions) > 0) {
4927: foreach my $key (keys(%deletions)) {
4928: if ($predelallitems{$key} ne '') {
4929: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
4930: }
4931: }
4932: }
4933: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 4934: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 4935: if (ref($chkcats[0]) eq 'ARRAY') {
4936: my $depth = 0;
4937: my $chg = 0;
4938: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
4939: my $name = $chkcats[0][$i];
4940: my $item;
4941: if ($name eq '') {
4942: $chg ++;
4943: } else {
4944: $item = &escape($name).'::0';
4945: if ($chg) {
1.57 raeburn 4946: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 4947: }
4948: $depth ++;
1.57 raeburn 4949: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 4950: $depth --;
4951: }
4952: }
4953: }
1.57 raeburn 4954: }
4955: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4956: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 4957: if ($putresult eq 'ok') {
1.57 raeburn 4958: my %title = (
4959: togglecats => 'Show/Hide a course in the catalog',
4960: categorize => 'Category assigned to course',
4961: );
4962: my %level = (
4963: dom => 'set from "Modify Course" (Domain)',
4964: crs => 'set from "Parameters" (Course)',
4965: );
1.48 raeburn 4966: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 4967: if ($changes{'togglecats'}) {
4968: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
4969: }
4970: if ($changes{'categorize'}) {
4971: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 4972: }
1.57 raeburn 4973: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4974: my $cathash;
4975: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
4976: $cathash = $domconfig{'coursecategories'}{'cats'};
4977: } else {
4978: $cathash = {};
4979: }
4980: my (@cats,@trails,%allitems);
4981: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
4982: if (keys(%deletions) > 0) {
4983: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
4984: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
4985: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
4986: }
4987: $resulttext .= '</ul></li>';
4988: }
4989: if (keys(%reorderings) > 0) {
4990: my %sort_by_trail;
4991: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
4992: foreach my $key (keys(%reorderings)) {
4993: if ($allitems{$key} ne '') {
4994: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
4995: }
1.48 raeburn 4996: }
1.57 raeburn 4997: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
4998: $resulttext .= '<li>'.$trails[$trail].'</li>';
4999: }
5000: $resulttext .= '</ul></li>';
1.48 raeburn 5001: }
1.57 raeburn 5002: if (keys(%adds) > 0) {
5003: my %sort_by_trail;
5004: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
5005: foreach my $key (keys(%adds)) {
5006: if ($allitems{$key} ne '') {
5007: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
5008: }
5009: }
5010: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
5011: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 5012: }
1.57 raeburn 5013: $resulttext .= '</ul></li>';
1.48 raeburn 5014: }
5015: }
5016: $resulttext .= '</ul>';
5017: } else {
5018: $resulttext = '<span class="LC_error">'.
1.57 raeburn 5019: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 5020: }
5021: } else {
5022: $resulttext = &mt('No changes made to course categories');
5023: }
5024: return $resulttext;
5025: }
5026:
1.69 raeburn 5027: sub modify_serverstatuses {
5028: my ($dom,%domconfig) = @_;
5029: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
5030: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
5031: %currserverstatus = %{$domconfig{'serverstatuses'}};
5032: }
5033: my @pages = &serverstatus_pages();
5034: foreach my $type (@pages) {
5035: $newserverstatus{$type}{'namedusers'} = '';
5036: $newserverstatus{$type}{'machines'} = '';
5037: if (defined($env{'form.'.$type.'_namedusers'})) {
5038: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
5039: my @okusers;
5040: foreach my $user (@users) {
5041: my ($uname,$udom) = split(/:/,$user);
5042: if (($udom =~ /^$match_domain$/) &&
5043: (&Apache::lonnet::domain($udom)) &&
5044: ($uname =~ /^$match_username$/)) {
5045: if (!grep(/^\Q$user\E/,@okusers)) {
5046: push(@okusers,$user);
5047: }
5048: }
5049: }
5050: if (@okusers > 0) {
5051: @okusers = sort(@okusers);
5052: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
5053: }
5054: }
5055: if (defined($env{'form.'.$type.'_machines'})) {
5056: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
5057: my @okmachines;
5058: foreach my $ip (@machines) {
5059: my @parts = split(/\./,$ip);
5060: next if (@parts < 4);
5061: my $badip = 0;
5062: for (my $i=0; $i<4; $i++) {
5063: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
5064: $badip = 1;
5065: last;
5066: }
5067: }
5068: if (!$badip) {
5069: push(@okmachines,$ip);
5070: }
5071: }
5072: @okmachines = sort(@okmachines);
5073: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
5074: }
5075: }
5076: my %serverstatushash = (
5077: serverstatuses => \%newserverstatus,
5078: );
5079: my %changes;
5080: foreach my $type (@pages) {
1.83 raeburn 5081: foreach my $setting ('namedusers','machines') {
1.84 raeburn 5082: my (@current,@new);
1.83 raeburn 5083: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 5084: if ($currserverstatus{$type}{$setting} ne '') {
5085: @current = split(/,/,$currserverstatus{$type}{$setting});
5086: }
5087: }
5088: if ($newserverstatus{$type}{$setting} ne '') {
5089: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 5090: }
5091: if (@current > 0) {
5092: if (@new > 0) {
5093: foreach my $item (@current) {
5094: if (!grep(/^\Q$item\E$/,@new)) {
5095: $changes{$type}{$setting} = 1;
1.82 raeburn 5096: last;
5097: }
5098: }
1.84 raeburn 5099: foreach my $item (@new) {
5100: if (!grep(/^\Q$item\E$/,@current)) {
5101: $changes{$type}{$setting} = 1;
5102: last;
1.82 raeburn 5103: }
5104: }
5105: } else {
1.83 raeburn 5106: $changes{$type}{$setting} = 1;
1.69 raeburn 5107: }
1.83 raeburn 5108: } elsif (@new > 0) {
5109: $changes{$type}{$setting} = 1;
1.69 raeburn 5110: }
5111: }
5112: }
5113: if (keys(%changes) > 0) {
1.81 raeburn 5114: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5115: my $putresult = &Apache::lonnet::put_dom('configuration',
5116: \%serverstatushash,$dom);
5117: if ($putresult eq 'ok') {
5118: $resulttext .= &mt('Changes made:').'<ul>';
5119: foreach my $type (@pages) {
1.84 raeburn 5120: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 5121: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 5122: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 5123: if ($newserverstatus{$type}{'namedusers'} eq '') {
5124: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
5125: } else {
5126: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
5127: }
1.84 raeburn 5128: }
5129: if ($changes{$type}{'machines'}) {
1.69 raeburn 5130: if ($newserverstatus{$type}{'machines'} eq '') {
5131: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
5132: } else {
5133: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
5134: }
5135:
5136: }
5137: $resulttext .= '</ul></li>';
5138: }
5139: }
5140: $resulttext .= '</ul>';
5141: } else {
5142: $resulttext = '<span class="LC_error">'.
5143: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
5144:
5145: }
5146: } else {
5147: $resulttext = &mt('No changes made to access to server status pages');
5148: }
5149: return $resulttext;
5150: }
5151:
1.48 raeburn 5152: sub recurse_check {
5153: my ($chkcats,$categories,$depth,$name) = @_;
5154: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
5155: my $chg = 0;
5156: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
5157: my $category = $chkcats->[$depth]{$name}[$j];
5158: my $item;
5159: if ($category eq '') {
5160: $chg ++;
5161: } else {
5162: my $deeper = $depth + 1;
5163: $item = &escape($category).':'.&escape($name).':'.$depth;
5164: if ($chg) {
5165: $categories->{$item} -= $chg;
5166: }
5167: &recurse_check($chkcats,$categories,$deeper,$category);
5168: $deeper --;
5169: }
5170: }
5171: }
5172: return;
5173: }
5174:
5175: sub recurse_cat_deletes {
5176: my ($item,$coursecategories,$deletions) = @_;
5177: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
5178: my $subdepth = $depth + 1;
5179: if (ref($coursecategories) eq 'HASH') {
5180: foreach my $subitem (keys(%{$coursecategories})) {
5181: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
5182: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
5183: delete($coursecategories->{$subitem});
5184: $deletions->{$subitem} = 1;
5185: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
5186: }
5187: }
5188: }
5189: return;
5190: }
5191:
1.3 raeburn 5192: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>