Annotation of loncom/interface/domainprefs.pm, revision 1.88
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.88 ! bisitz 4: # $Id: domainprefs.pm,v 1.87 2009/02/09 03:42:03 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
31: package Apache::domainprefs;
32:
33: use strict;
34: use Apache::Constants qw(:common :http);
35: use Apache::lonnet;
36: use Apache::loncommon();
37: use Apache::lonhtmlcommon();
38: use Apache::lonlocal;
1.43 raeburn 39: use Apache::lonmsg();
1.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);
1623: my @mailings = ('errormail','packagesmail','helpdeskmail');
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: }
1643: }
1644: }
1645: } else {
1646: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1647: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1648: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1649: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1650: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
1651: }
1652: my ($titles,$short_titles) = &contact_titles();
1653: my $rownum = 0;
1654: my $css_class;
1655: foreach my $item (@contacts) {
1.69 raeburn 1656: $rownum ++;
1657: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 1658: $datatable .= '<tr'.$css_class.'>'.
1659: '<td><span class="LC_nobreak">'.$titles->{$item}.
1660: '</span></td><td class="LC_right_item">'.
1.28 raeburn 1661: '<input type="text" name="'.$item.'" value="'.
1662: $to{$item}.'" /></td></tr>';
1663: }
1664: foreach my $type (@mailings) {
1.69 raeburn 1665: $rownum ++;
1666: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 1667: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 1668: '<td><span class="LC_nobreak">'.
1669: $titles->{$type}.': </span></td>'.
1.28 raeburn 1670: '<td class="LC_left_item">'.
1671: '<span class="LC_nobreak">';
1672: foreach my $item (@contacts) {
1673: $datatable .= '<label>'.
1674: '<input type="checkbox" name="'.$type.'"'.
1675: $checked{$type}{$item}.
1676: ' value="'.$item.'" />'.$short_titles->{$item}.
1677: '</label> ';
1678: }
1679: $datatable .= '</span><br />'.&mt('Others').': '.
1680: '<input type="text" name="'.$type.'_others" '.
1681: 'value="'.$otheremails{$type}.'" />'.
1682: '</td></tr>'."\n";
1683: }
1.30 raeburn 1684: $$rowtotal += $rownum;
1.28 raeburn 1685: return $datatable;
1686: }
1687:
1688: sub contact_titles {
1689: my %titles = &Apache::lonlocal::texthash (
1690: 'supportemail' => 'Support E-mail address',
1.69 raeburn 1691: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 1692: 'errormail' => 'Error reports to be e-mailed to',
1693: 'packagesmail' => 'Package update alerts to be e-mailed to',
1694: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
1695: );
1696: my %short_titles = &Apache::lonlocal::texthash (
1697: adminemail => 'Admin E-mail address',
1698: supportemail => 'Support E-mail',
1699: );
1700: return (\%titles,\%short_titles);
1701: }
1702:
1.72 raeburn 1703: sub tool_titles {
1704: my %titles = &Apache::lonlocal::texthash (
1.86 raeburn 1705: aboutme => 'Personal Home Page',
1706: blog => 'Blog',
1707: portfolio => 'Portfolio',
1.88 ! bisitz 1708: official => 'Official courses (with institutional codes)',
! 1709: unofficial => 'Unofficial courses',
1.86 raeburn 1710: );
1.72 raeburn 1711: return %titles;
1712: }
1713:
1.27 raeburn 1714: sub print_usercreation {
1.30 raeburn 1715: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 1716: my $numinrow = 4;
1.28 raeburn 1717: my $datatable;
1718: if ($position eq 'top') {
1.30 raeburn 1719: $$rowtotal ++;
1.34 raeburn 1720: my $rowcount = 0;
1.32 raeburn 1721: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 1722: if (ref($rules) eq 'HASH') {
1723: if (keys(%{$rules}) > 0) {
1.32 raeburn 1724: $datatable .= &user_formats_row('username',$settings,$rules,
1725: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 1726: $$rowtotal ++;
1.32 raeburn 1727: $rowcount ++;
1728: }
1729: }
1730: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
1731: if (ref($idrules) eq 'HASH') {
1732: if (keys(%{$idrules}) > 0) {
1733: $datatable .= &user_formats_row('id',$settings,$idrules,
1734: $idruleorder,$numinrow,$rowcount);
1735: $$rowtotal ++;
1736: $rowcount ++;
1.28 raeburn 1737: }
1738: }
1.43 raeburn 1739: my ($emailrules,$emailruleorder) =
1740: &Apache::lonnet::inst_userrules($dom,'email');
1741: if (ref($emailrules) eq 'HASH') {
1742: if (keys(%{$emailrules}) > 0) {
1743: $datatable .= &user_formats_row('email',$settings,$emailrules,
1744: $emailruleorder,$numinrow,$rowcount);
1745: $$rowtotal ++;
1746: $rowcount ++;
1747: }
1748: }
1.39 raeburn 1749: if ($rowcount == 0) {
1750: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
1751: $$rowtotal ++;
1752: $rowcount ++;
1753: }
1.34 raeburn 1754: } elsif ($position eq 'middle') {
1.45 raeburn 1755: my @creators = ('author','course','selfcreate');
1.37 raeburn 1756: my ($rules,$ruleorder) =
1757: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 1758: my %lt = &usercreation_types();
1759: my %checked;
1.50 raeburn 1760: my @selfcreate;
1.34 raeburn 1761: if (ref($settings) eq 'HASH') {
1762: if (ref($settings->{'cancreate'}) eq 'HASH') {
1763: foreach my $item (@creators) {
1764: $checked{$item} = $settings->{'cancreate'}{$item};
1765: }
1.50 raeburn 1766: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
1767: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
1768: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
1769: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
1770: @selfcreate = ('email','login','sso');
1771: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
1772: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
1773: }
1774: }
1.34 raeburn 1775: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
1776: foreach my $item (@creators) {
1777: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
1778: $checked{$item} = 'none';
1779: }
1780: }
1781: }
1782: }
1783: my $rownum = 0;
1784: foreach my $item (@creators) {
1785: $rownum ++;
1.50 raeburn 1786: if ($item ne 'selfcreate') {
1787: if ($checked{$item} eq '') {
1.43 raeburn 1788: $checked{$item} = 'any';
1789: }
1.34 raeburn 1790: }
1791: my $css_class;
1792: if ($rownum%2) {
1793: $css_class = '';
1794: } else {
1795: $css_class = ' class="LC_odd_row" ';
1796: }
1797: $datatable .= '<tr'.$css_class.'>'.
1798: '<td><span class="LC_nobreak">'.$lt{$item}.
1799: '</span></td><td align="right">';
1.50 raeburn 1800: my @options;
1.45 raeburn 1801: if ($item eq 'selfcreate') {
1.43 raeburn 1802: push(@options,('email','login','sso'));
1803: } else {
1.50 raeburn 1804: @options = ('any');
1.43 raeburn 1805: if (ref($rules) eq 'HASH') {
1806: if (keys(%{$rules}) > 0) {
1807: push(@options,('official','unofficial'));
1808: }
1.37 raeburn 1809: }
1.50 raeburn 1810: push(@options,'none');
1.37 raeburn 1811: }
1812: foreach my $option (@options) {
1.50 raeburn 1813: my $type = 'radio';
1.34 raeburn 1814: my $check = ' ';
1.50 raeburn 1815: if ($item eq 'selfcreate') {
1816: $type = 'checkbox';
1817: if (grep(/^\Q$option\E$/,@selfcreate)) {
1818: $check = ' checked="checked" ';
1819: }
1820: } else {
1821: if ($checked{$item} eq $option) {
1822: $check = ' checked="checked" ';
1823: }
1.34 raeburn 1824: }
1825: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 1826: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 1827: $item.'" value="'.$option.'"'.$check.'/> '.
1828: $lt{$option}.'</label> </span>';
1829: }
1830: $datatable .= '</td></tr>';
1831: }
1.28 raeburn 1832: } else {
1833: my @contexts = ('author','course','domain');
1834: my @authtypes = ('int','krb4','krb5','loc');
1835: my %checked;
1836: if (ref($settings) eq 'HASH') {
1837: if (ref($settings->{'authtypes'}) eq 'HASH') {
1838: foreach my $item (@contexts) {
1839: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
1840: foreach my $auth (@authtypes) {
1841: if ($settings->{'authtypes'}{$item}{$auth}) {
1842: $checked{$item}{$auth} = ' checked="checked" ';
1843: }
1844: }
1845: }
1846: }
1.27 raeburn 1847: }
1.35 raeburn 1848: } else {
1849: foreach my $item (@contexts) {
1.36 raeburn 1850: foreach my $auth (@authtypes) {
1.35 raeburn 1851: $checked{$item}{$auth} = ' checked="checked" ';
1852: }
1853: }
1.27 raeburn 1854: }
1.28 raeburn 1855: my %title = &context_names();
1856: my %authname = &authtype_names();
1857: my $rownum = 0;
1858: my $css_class;
1859: foreach my $item (@contexts) {
1860: if ($rownum%2) {
1861: $css_class = '';
1862: } else {
1863: $css_class = ' class="LC_odd_row" ';
1864: }
1.30 raeburn 1865: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 1866: '<td>'.$title{$item}.
1867: '</td><td class="LC_left_item">'.
1868: '<span class="LC_nobreak">';
1869: foreach my $auth (@authtypes) {
1870: $datatable .= '<label>'.
1871: '<input type="checkbox" name="'.$item.'_auth" '.
1872: $checked{$item}{$auth}.' value="'.$auth.'" />'.
1873: $authname{$auth}.'</label> ';
1874: }
1875: $datatable .= '</span></td></tr>';
1876: $rownum ++;
1.27 raeburn 1877: }
1.30 raeburn 1878: $$rowtotal += $rownum;
1.27 raeburn 1879: }
1880: return $datatable;
1881: }
1882:
1.32 raeburn 1883: sub user_formats_row {
1884: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
1885: my $output;
1886: my %text = (
1887: 'username' => 'new usernames',
1888: 'id' => 'IDs',
1.45 raeburn 1889: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 1890: );
1891: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1892: $output = '<tr '.$css_class.'>'.
1.63 raeburn 1893: '<td><span class="LC_nobreak">';
1894: if ($type eq 'email') {
1895: $output .= &mt("Formats disallowed for $text{$type}: ");
1896: } else {
1897: $output .= &mt("Format rules to check for $text{$type}: ");
1898: }
1899: $output .= '</span></td>'.
1900: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 1901: my $rem;
1902: if (ref($ruleorder) eq 'ARRAY') {
1903: for (my $i=0; $i<@{$ruleorder}; $i++) {
1904: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
1905: my $rem = $i%($numinrow);
1906: if ($rem == 0) {
1907: if ($i > 0) {
1908: $output .= '</tr>';
1909: }
1910: $output .= '<tr>';
1911: }
1912: my $check = ' ';
1.39 raeburn 1913: if (ref($settings) eq 'HASH') {
1914: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
1915: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
1916: $check = ' checked="checked" ';
1917: }
1.27 raeburn 1918: }
1919: }
1920: $output .= '<td class="LC_left_item">'.
1921: '<span class="LC_nobreak"><label>'.
1.32 raeburn 1922: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 1923: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
1924: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
1925: }
1926: }
1927: $rem = @{$ruleorder}%($numinrow);
1928: }
1929: my $colsleft = $numinrow - $rem;
1930: if ($colsleft > 1 ) {
1931: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1932: ' </td>';
1933: } elsif ($colsleft == 1) {
1934: $output .= '<td class="LC_left_item"> </td>';
1935: }
1936: $output .= '</tr></table></td></tr>';
1937: return $output;
1938: }
1939:
1.34 raeburn 1940: sub usercreation_types {
1941: my %lt = &Apache::lonlocal::texthash (
1942: author => 'When adding a co-author',
1943: course => 'When adding a user to a course',
1.45 raeburn 1944: selfcreate => 'User creates own account',
1.34 raeburn 1945: any => 'Any',
1946: official => 'Institutional only ',
1947: unofficial => 'Non-institutional only',
1.85 schafran 1948: email => 'E-mail address',
1.43 raeburn 1949: login => 'Institutional Login',
1950: sso => 'SSO',
1.34 raeburn 1951: none => 'None',
1952: );
1953: return %lt;
1.48 raeburn 1954: }
1.34 raeburn 1955:
1.28 raeburn 1956: sub authtype_names {
1957: my %lt = &Apache::lonlocal::texthash(
1958: int => 'Internal',
1959: krb4 => 'Kerberos 4',
1960: krb5 => 'Kerberos 5',
1961: loc => 'Local',
1962: );
1963: return %lt;
1964: }
1965:
1966: sub context_names {
1967: my %context_title = &Apache::lonlocal::texthash(
1968: author => 'Creating users when an Author',
1969: course => 'Creating users when in a course',
1970: domain => 'Creating users when a Domain Coordinator',
1971: );
1972: return %context_title;
1973: }
1974:
1.33 raeburn 1975: sub print_usermodification {
1976: my ($position,$dom,$settings,$rowtotal) = @_;
1977: my $numinrow = 4;
1978: my ($context,$datatable,$rowcount);
1979: if ($position eq 'top') {
1980: $rowcount = 0;
1981: $context = 'author';
1982: foreach my $role ('ca','aa') {
1983: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1984: $numinrow,$rowcount);
1985: $$rowtotal ++;
1986: $rowcount ++;
1987: }
1.63 raeburn 1988: } elsif ($position eq 'middle') {
1.33 raeburn 1989: $context = 'course';
1990: $rowcount = 0;
1991: foreach my $role ('st','ep','ta','in','cr') {
1992: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1993: $numinrow,$rowcount);
1994: $$rowtotal ++;
1995: $rowcount ++;
1996: }
1.63 raeburn 1997: } elsif ($position eq 'bottom') {
1998: $context = 'selfcreate';
1999: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2000: $usertypes->{'default'} = $othertitle;
2001: if (ref($types) eq 'ARRAY') {
2002: push(@{$types},'default');
2003: $usertypes->{'default'} = $othertitle;
2004: foreach my $status (@{$types}) {
2005: $datatable .= &modifiable_userdata_row($context,$status,$settings,
2006: $numinrow,$rowcount,$usertypes);
2007: $$rowtotal ++;
2008: $rowcount ++;
2009: }
2010: }
1.33 raeburn 2011: }
2012: return $datatable;
2013: }
2014:
1.43 raeburn 2015: sub print_defaults {
2016: my ($dom,$rowtotal) = @_;
1.68 raeburn 2017: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
2018: 'datelocale_def');
1.43 raeburn 2019: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
2020: my $titles = &defaults_titles();
2021: my $rownum = 0;
2022: my ($datatable,$css_class);
2023: foreach my $item (@items) {
2024: if ($rownum%2) {
2025: $css_class = '';
2026: } else {
2027: $css_class = ' class="LC_odd_row" ';
2028: }
2029: $datatable .= '<tr'.$css_class.'>'.
2030: '<td><span class="LC_nobreak">'.$titles->{$item}.
2031: '</span></td><td class="LC_right_item">';
2032: if ($item eq 'auth_def') {
2033: my @authtypes = ('internal','krb4','krb5','localauth');
2034: my %shortauth = (
2035: internal => 'int',
2036: krb4 => 'krb4',
2037: krb5 => 'krb5',
2038: localauth => 'loc'
2039: );
2040: my %authnames = &authtype_names();
2041: foreach my $auth (@authtypes) {
2042: my $checked = ' ';
2043: if ($domdefaults{$item} eq $auth) {
2044: $checked = ' checked="checked" ';
2045: }
2046: $datatable .= '<label><input type="radio" name="'.$item.
2047: '" value="'.$auth.'"'.$checked.'/>'.
2048: $authnames{$shortauth{$auth}}.'</label> ';
2049: }
1.54 raeburn 2050: } elsif ($item eq 'timezone_def') {
2051: my $includeempty = 1;
2052: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 2053: } elsif ($item eq 'datelocale_def') {
2054: my $includeempty = 1;
2055: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 2056: } else {
2057: $datatable .= '<input type="text" name="'.$item.'" value="'.
2058: $domdefaults{$item}.'" />';
2059: }
2060: $datatable .= '</td></tr>';
2061: $rownum ++;
2062: }
2063: $$rowtotal += $rownum;
2064: return $datatable;
2065: }
2066:
2067: sub defaults_titles {
2068: my %titles = &Apache::lonlocal::texthash (
2069: 'auth_def' => 'Default authentication type',
2070: 'auth_arg_def' => 'Default authentication argument',
2071: 'lang_def' => 'Default language',
1.54 raeburn 2072: 'timezone_def' => 'Default timezone',
1.68 raeburn 2073: 'datelocale_def' => 'Default locale for dates',
1.43 raeburn 2074: );
2075: return (\%titles);
2076: }
2077:
1.46 raeburn 2078: sub print_scantronformat {
2079: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
2080: my $itemcount = 1;
1.60 raeburn 2081: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
2082: %confhash);
1.46 raeburn 2083: my $switchserver = &check_switchserver($dom,$confname);
2084: my %lt = &Apache::lonlocal::texthash (
2085: default => 'Default scantron format file error',
2086: custom => 'Custom scantron format file error',
2087: );
2088: my %scantronfiles = (
2089: default => 'default.tab',
2090: custom => 'custom.tab',
2091: );
2092: foreach my $key (keys(%scantronfiles)) {
2093: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
2094: .$scantronfiles{$key};
2095: }
2096: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
2097: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
2098: if (!$switchserver) {
2099: my $servadm = $r->dir_config('lonAdmEMail');
2100: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
2101: if ($configuserok eq 'ok') {
2102: if ($author_ok eq 'ok') {
2103: my %legacyfile = (
2104: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
2105: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
2106: );
2107: my %md5chk;
2108: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2109: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
2110: chomp($md5chk{$type});
1.46 raeburn 2111: }
2112: if ($md5chk{'default'} ne $md5chk{'custom'}) {
2113: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2114: ($scantronurls{$type},my $error) =
1.46 raeburn 2115: &legacy_scantronformat($r,$dom,$confname,
2116: $type,$legacyfile{$type},
2117: $scantronurls{$type},
2118: $scantronfiles{$type});
1.60 raeburn 2119: if ($error ne '') {
2120: $error{$type} = $error;
2121: }
2122: }
2123: if (keys(%error) == 0) {
2124: $is_custom = 1;
2125: $confhash{'scantron'}{'scantronformat'} =
2126: $scantronurls{'custom'};
2127: my $putresult =
2128: &Apache::lonnet::put_dom('configuration',
2129: \%confhash,$dom);
2130: if ($putresult ne 'ok') {
2131: $error{'custom'} =
2132: '<span class="LC_error">'.
2133: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2134: }
1.46 raeburn 2135: }
2136: } else {
1.60 raeburn 2137: ($scantronurls{'default'},my $error) =
1.46 raeburn 2138: &legacy_scantronformat($r,$dom,$confname,
2139: 'default',$legacyfile{'default'},
2140: $scantronurls{'default'},
2141: $scantronfiles{'default'});
1.60 raeburn 2142: if ($error eq '') {
2143: $confhash{'scantron'}{'scantronformat'} = '';
2144: my $putresult =
2145: &Apache::lonnet::put_dom('configuration',
2146: \%confhash,$dom);
2147: if ($putresult ne 'ok') {
2148: $error{'default'} =
2149: '<span class="LC_error">'.
2150: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2151: }
2152: } else {
2153: $error{'default'} = $error;
2154: }
1.46 raeburn 2155: }
2156: }
2157: }
2158: } else {
2159: $error{'default'} = &mt("Unable to copy default scantron formatfile to domain's RES space: [_1]",$switchserver);
2160: }
2161: }
2162: if (ref($settings) eq 'HASH') {
2163: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
2164: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
2165: if ((!@info) || ($info[0] eq 'no_such_dir')) {
2166: $scantronurl = '';
2167: } else {
2168: $scantronurl = $settings->{'scantronformat'};
2169: }
2170: $is_custom = 1;
2171: } else {
2172: $scantronurl = $scantronurls{'default'};
2173: }
2174: } else {
1.60 raeburn 2175: if ($is_custom) {
2176: $scantronurl = $scantronurls{'custom'};
2177: } else {
2178: $scantronurl = $scantronurls{'default'};
2179: }
1.46 raeburn 2180: }
2181: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2182: $datatable .= '<tr'.$css_class.'>';
2183: if (!$is_custom) {
1.65 raeburn 2184: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
2185: '<span class="LC_nobreak">';
1.46 raeburn 2186: if ($scantronurl) {
2187: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
2188: &mt('Default scantron format file').'</a>';
2189: } else {
2190: $datatable = &mt('File unavailable for display');
2191: }
1.65 raeburn 2192: $datatable .= '</span></td>';
1.60 raeburn 2193: if (keys(%error) == 0) {
2194: $datatable .= '<td valign="bottom">';
2195: if (!$switchserver) {
2196: $datatable .= &mt('Upload:').'<br />';
2197: }
2198: } else {
2199: my $errorstr;
2200: foreach my $key (sort(keys(%error))) {
2201: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2202: }
2203: $datatable .= '<td>'.$errorstr;
2204: }
1.46 raeburn 2205: } else {
2206: if (keys(%error) > 0) {
2207: my $errorstr;
2208: foreach my $key (sort(keys(%error))) {
2209: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2210: }
1.60 raeburn 2211: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 2212: } elsif ($scantronurl) {
1.65 raeburn 2213: $datatable .= '<td><span class="LC_nobreak">'.
2214: '<a href="'.$scantronurl.'" target="_blank">'.
2215: &mt('Custom scantron format file').'</a><label>'.
2216: '<input type="checkbox" name="scantronformat_del"'.
2217: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
2218: '<td><span class="LC_nobreak"> '.
2219: &mt('Replace:').'</span><br />';
1.46 raeburn 2220: }
2221: }
2222: if (keys(%error) == 0) {
2223: if ($switchserver) {
2224: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2225: } else {
1.65 raeburn 2226: $datatable .='<span class="LC_nobreak"> '.
2227: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 2228: }
2229: }
2230: $datatable .= '</td></tr>';
2231: $$rowtotal ++;
2232: return $datatable;
2233: }
2234:
2235: sub legacy_scantronformat {
2236: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
2237: my ($url,$error);
2238: my @statinfo = &Apache::lonnet::stat_file($newurl);
2239: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
2240: (my $result,$url) =
2241: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
2242: '','',$newfile);
2243: if ($result ne 'ok') {
2244: $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
2245: }
2246: }
2247: return ($url,$error);
2248: }
1.43 raeburn 2249:
1.49 raeburn 2250: sub print_coursecategories {
1.57 raeburn 2251: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
2252: my $datatable;
2253: if ($position eq 'top') {
2254: my $toggle_cats_crs = ' ';
2255: my $toggle_cats_dom = ' checked="checked" ';
2256: my $can_cat_crs = ' ';
2257: my $can_cat_dom = ' checked="checked" ';
2258: if (ref($settings) eq 'HASH') {
2259: if ($settings->{'togglecats'} eq 'crs') {
2260: $toggle_cats_crs = $toggle_cats_dom;
2261: $toggle_cats_dom = ' ';
2262: }
2263: if ($settings->{'categorize'} eq 'crs') {
2264: $can_cat_crs = $can_cat_dom;
2265: $can_cat_dom = ' ';
2266: }
2267: }
2268: my %title = &Apache::lonlocal::texthash (
2269: togglecats => 'Show/Hide a course in the catalog',
2270: categorize => 'Assign a category to a course',
2271: );
2272: my %level = &Apache::lonlocal::texthash (
2273: dom => 'Set in "Modify Course" (Domain)',
1.60 raeburn 2274: crs => 'Set in "Modify Parameters" (Course)',
1.57 raeburn 2275: );
2276: $datatable = '<tr class="LC_odd_row">'.
2277: '<td>'.$title{'togglecats'}.'</td>'.
2278: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2279: '<input type="radio" name="togglecats"'.
2280: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2281: '<label><input type="radio" name="togglecats"'.
2282: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
2283: '</tr><tr>'.
2284: '<td>'.$title{'categorize'}.'</td>'.
2285: '<td class="LC_right_item"><span class="LC_nobreak">'.
2286: '<label><input type="radio" name="categorize"'.
2287: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2288: '<label><input type="radio" name="categorize"'.
2289: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
2290: '</tr>';
2291: $$rowtotal += 2;
2292: } else {
2293: my $css_class;
2294: my $itemcount = 1;
2295: my $cathash;
2296: if (ref($settings) eq 'HASH') {
2297: $cathash = $settings->{'cats'};
2298: }
2299: if (ref($cathash) eq 'HASH') {
2300: my (@cats,@trails,%allitems,%idx,@jsarray);
2301: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
2302: \%allitems,\%idx,\@jsarray);
2303: my $maxdepth = scalar(@cats);
2304: my $colattrib = '';
2305: if ($maxdepth > 2) {
2306: $colattrib = ' colspan="2" ';
2307: }
2308: my @path;
2309: if (@cats > 0) {
2310: if (ref($cats[0]) eq 'ARRAY') {
2311: my $numtop = @{$cats[0]};
2312: my $maxnum = $numtop;
2313: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2314: $maxnum ++;
2315: }
2316: my $lastidx;
2317: for (my $i=0; $i<$numtop; $i++) {
2318: my $parent = $cats[0][$i];
2319: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2320: my $item = &escape($parent).'::0';
2321: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
2322: $lastidx = $idx{$item};
2323: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2324: .'<select name="'.$item.'"'.$chgstr.'>';
2325: for (my $k=0; $k<=$maxnum; $k++) {
2326: my $vpos = $k+1;
2327: my $selstr;
2328: if ($k == $i) {
2329: $selstr = ' selected="selected" ';
2330: }
2331: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2332: }
2333: $datatable .= '</select></td><td>';
2334: if ($parent eq 'instcode') {
2335: $datatable .= '<span class="LC_nobreak">'.&mt('Official courses')
2336: .'</span><br /><span class="LC_nobreak">('
2337: .&mt('with institutional codes').')</span></td>'
2338: .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'
2339: .&mt('Display').'</label> '
2340: .'<label><input type="radio" name="instcode" value="0" />'
2341: .&mt('Do not display').'</label></span></td>';
2342: } else {
2343: $datatable .= $parent
2344: .' <label><input type="checkbox" name="deletecategory" '
2345: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
2346: }
2347: my $depth = 1;
2348: push(@path,$parent);
2349: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
2350: pop(@path);
2351: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
2352: $itemcount ++;
2353: }
1.48 raeburn 2354: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 2355: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
2356: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 2357: for (my $k=0; $k<=$maxnum; $k++) {
2358: my $vpos = $k+1;
2359: my $selstr;
1.57 raeburn 2360: if ($k == $numtop) {
1.48 raeburn 2361: $selstr = ' selected="selected" ';
2362: }
2363: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2364: }
1.59 bisitz 2365: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 2366: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
2367: .'</tr>'."\n";
1.48 raeburn 2368: $itemcount ++;
1.57 raeburn 2369: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2371: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
2372: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
2373: '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
2374: for (my $k=0; $k<=$maxnum; $k++) {
2375: my $vpos = $k+1;
2376: my $selstr;
2377: if ($k == $maxnum) {
2378: $selstr = ' selected="selected" ';
2379: }
2380: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.48 raeburn 2381: }
1.57 raeburn 2382: $datatable .= '</select></span></td><td><span class="LC_nobreak">'
2383: .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('
2384: .&mt('with institutional codes').')</span></td>'
2385: .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'
2386: .&mt('Display').'</label> '
2387: .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'
2388: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 2389: }
2390: }
1.57 raeburn 2391: } else {
2392: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 2393: }
2394: } else {
1.57 raeburn 2395: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
2396: .&initialize_categories($itemcount);
1.48 raeburn 2397: }
1.57 raeburn 2398: $$rowtotal += $itemcount;
1.48 raeburn 2399: }
2400: return $datatable;
2401: }
2402:
1.69 raeburn 2403: sub print_serverstatuses {
2404: my ($dom,$settings,$rowtotal) = @_;
2405: my $datatable;
2406: my @pages = &serverstatus_pages();
2407: my (%namedaccess,%machineaccess);
2408: foreach my $type (@pages) {
2409: $namedaccess{$type} = '';
2410: $machineaccess{$type}= '';
2411: }
2412: if (ref($settings) eq 'HASH') {
2413: foreach my $type (@pages) {
2414: if (exists($settings->{$type})) {
2415: if (ref($settings->{$type}) eq 'HASH') {
2416: foreach my $key (keys(%{$settings->{$type}})) {
2417: if ($key eq 'namedusers') {
2418: $namedaccess{$type} = $settings->{$type}->{$key};
2419: } elsif ($key eq 'machines') {
2420: $machineaccess{$type} = $settings->{$type}->{$key};
2421: }
2422: }
2423: }
2424: }
2425: }
2426: }
1.81 raeburn 2427: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 2428: my $rownum = 0;
2429: my $css_class;
2430: foreach my $type (@pages) {
2431: $rownum ++;
2432: $css_class = $rownum%2?' class="LC_odd_row"':'';
2433: $datatable .= '<tr'.$css_class.'>'.
2434: '<td><span class="LC_nobreak">'.
2435: $titles->{$type}.'</span></td>'.
2436: '<td class="LC_left_item">'.
2437: '<input type="text" name="'.$type.'_namedusers" '.
2438: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
2439: '<td class="LC_right_item">'.
2440: '<span class="LC_nobreak">'.
2441: '<input type="text" name="'.$type.'_machines" '.
2442: 'value="'.$machineaccess{$type}.'" size="10" />'.
2443: '</td></tr>'."\n";
2444: }
2445: $$rowtotal += $rownum;
2446: return $datatable;
2447: }
2448:
2449: sub serverstatus_pages {
2450: return ('userstatus','lonstatus','loncron','server-status','codeversions',
2451: 'clusterstatus','metadata_keywords','metadata_harvest',
2452: 'takeoffline','takeonline','showenv');
2453: }
2454:
1.49 raeburn 2455: sub coursecategories_javascript {
2456: my ($settings) = @_;
1.57 raeburn 2457: my ($output,$jstext,$cathash);
1.49 raeburn 2458: if (ref($settings) eq 'HASH') {
1.57 raeburn 2459: $cathash = $settings->{'cats'};
2460: }
2461: if (ref($cathash) eq 'HASH') {
1.49 raeburn 2462: my (@cats,@jsarray,%idx);
1.57 raeburn 2463: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 2464: if (@jsarray > 0) {
2465: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
2466: for (my $i=0; $i<@jsarray; $i++) {
2467: if (ref($jsarray[$i]) eq 'ARRAY') {
2468: my $catstr = join('","',@{$jsarray[$i]});
2469: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
2470: }
2471: }
2472: }
2473: } else {
2474: $jstext = ' var categories = Array(1);'."\n".
2475: ' categories[0] = Array("instcode_pos");'."\n";
2476: }
2477: $output = <<"ENDSCRIPT";
2478: <script type="text/javascript">
2479: function reorderCats(form,parent,item,idx) {
2480: var changedVal;
2481: $jstext
2482: var newpos = 'addcategory_pos';
2483: var current = new Array;
2484: if (parent == '') {
2485: var has_instcode = 0;
2486: var maxtop = categories[idx].length;
2487: for (var j=0; j<maxtop; j++) {
2488: if (categories[idx][j] == 'instcode::0') {
2489: has_instcode == 1;
2490: }
2491: }
2492: if (has_instcode == 0) {
2493: categories[idx][maxtop] = 'instcode_pos';
2494: }
2495: } else {
2496: newpos += '_'+parent;
2497: }
2498: var maxh = 1 + categories[idx].length;
2499: var current = new Array;
2500: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2501: if (item == newpos) {
2502: changedVal = newitemVal;
2503: } else {
2504: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2505: current[newitemVal] = newpos;
2506: }
2507: for (var i=0; i<categories[idx].length; i++) {
2508: var elementName = categories[idx][i];
2509: if (elementName != item) {
2510: if (form.elements[elementName]) {
2511: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2512: current[currVal] = elementName;
2513: }
2514: }
2515: }
2516: var oldVal;
2517: for (var j=0; j<maxh; j++) {
2518: if (current[j] == undefined) {
2519: oldVal = j;
2520: }
2521: }
2522: if (oldVal < changedVal) {
2523: for (var k=oldVal+1; k<=changedVal ; k++) {
2524: var elementName = current[k];
2525: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2526: }
2527: } else {
2528: for (var k=changedVal; k<oldVal; k++) {
2529: var elementName = current[k];
2530: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2531: }
2532: }
2533: return;
2534: }
2535: </script>
2536:
2537: ENDSCRIPT
2538: return $output;
2539: }
2540:
1.48 raeburn 2541: sub initialize_categories {
2542: my ($itemcount) = @_;
2543: my $datatable;
2544: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2545: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
2546:
1.48 raeburn 2547: $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
2548: .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
2549: .'<option value="1">2</option></select> '
2550: .&mt('Official courses (with institutional codes)')
2551: .'</span></td><td><span class="LC_nobreak">'
2552: .'<label><input type="radio" name="instcode" value="1" checked="checked" />'
2553: .&mt('Display').'</label> <label>'
2554: .'<input type="radio" name="instcode" value="0" />'.&mt('Do not display')
2555: .'</label></span></td></tr>';
2556: $itemcount ++;
2557: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2558: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 2559: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.53 raeburn 2560: .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
1.48 raeburn 2561: .'<option value="1" selected="selected">2</option></select> '
2562: .&mt('Add category').'</td><td>'.&mt('Name:')
2563: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
2564: return $datatable;
2565: }
2566:
2567: sub build_category_rows {
1.49 raeburn 2568: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
2569: my ($text,$name,$item,$chgstr);
1.48 raeburn 2570: if (ref($cats) eq 'ARRAY') {
2571: my $maxdepth = scalar(@{$cats});
2572: if (ref($cats->[$depth]) eq 'HASH') {
2573: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
2574: my $numchildren = @{$cats->[$depth]{$parent}};
2575: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
2576: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 2577: my ($idxnum,$parent_name,$parent_item);
2578: my $higher = $depth - 1;
2579: if ($higher == 0) {
2580: $parent_name = &escape($parent).'::'.$higher;
2581: } else {
2582: if (ref($path) eq 'ARRAY') {
2583: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2584: }
2585: }
2586: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 2587: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 2588: if ($j < $numchildren) {
1.48 raeburn 2589: $name = $cats->[$depth]{$parent}[$j];
2590: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 2591: $idxnum = $idx->{$item};
2592: } else {
2593: $name = $parent_name;
2594: $item = $parent_item;
1.48 raeburn 2595: }
1.49 raeburn 2596: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
2597: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 2598: for (my $i=0; $i<=$numchildren; $i++) {
2599: my $vpos = $i+1;
2600: my $selstr;
2601: if ($j == $i) {
2602: $selstr = ' selected="selected" ';
2603: }
2604: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
2605: }
2606: $text .= '</select> ';
2607: if ($j < $numchildren) {
2608: my $deeper = $depth+1;
2609: $text .= $name.' '
2610: .'<label><input type="checkbox" name="deletecategory" value="'
2611: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
2612: if(ref($path) eq 'ARRAY') {
2613: push(@{$path},$name);
1.49 raeburn 2614: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 2615: pop(@{$path});
2616: }
2617: } else {
1.59 bisitz 2618: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 2619: if ($j == $numchildren) {
2620: $text .= $name;
2621: } else {
2622: $text .= $item;
2623: }
2624: $text .= '" value="" />';
2625: }
2626: $text .= '</td></tr>';
2627: }
2628: $text .= '</table></td>';
2629: } else {
2630: my $higher = $depth-1;
2631: if ($higher == 0) {
2632: $name = &escape($parent).'::'.$higher;
2633: } else {
2634: if (ref($path) eq 'ARRAY') {
2635: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2636: }
2637: }
2638: my $colspan;
2639: if ($parent ne 'instcode') {
2640: $colspan = $maxdepth - $depth - 1;
2641: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
2642: }
2643: }
2644: }
2645: }
2646: return $text;
2647: }
2648:
1.33 raeburn 2649: sub modifiable_userdata_row {
1.63 raeburn 2650: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 2651: my $rolename;
1.63 raeburn 2652: if ($context eq 'selfcreate') {
2653: if (ref($usertypes) eq 'HASH') {
2654: $rolename = $usertypes->{$role};
2655: } else {
2656: $rolename = $role;
2657: }
1.33 raeburn 2658: } else {
1.63 raeburn 2659: if ($role eq 'cr') {
2660: $rolename = &mt('Custom role');
2661: } else {
2662: $rolename = &Apache::lonnet::plaintext($role);
2663: }
1.33 raeburn 2664: }
2665: my @fields = ('lastname','firstname','middlename','generation',
2666: 'permanentemail','id');
2667: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2668: my $output;
2669: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2670: $output = '<tr '.$css_class.'>'.
2671: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
2672: '<td class="LC_left_item" colspan="2"><table>';
2673: my $rem;
2674: my %checks;
2675: if (ref($settings) eq 'HASH') {
2676: if (ref($settings->{$context}) eq 'HASH') {
2677: if (ref($settings->{$context}->{$role}) eq 'HASH') {
2678: foreach my $field (@fields) {
2679: if ($settings->{$context}->{$role}->{$field}) {
2680: $checks{$field} = ' checked="checked" ';
2681: }
2682: }
2683: }
2684: }
2685: }
2686: for (my $i=0; $i<@fields; $i++) {
2687: my $rem = $i%($numinrow);
2688: if ($rem == 0) {
2689: if ($i > 0) {
2690: $output .= '</tr>';
2691: }
2692: $output .= '<tr>';
2693: }
2694: my $check = ' ';
2695: if (exists($checks{$fields[$i]})) {
2696: $check = $checks{$fields[$i]}
2697: } else {
2698: if ($role eq 'st') {
2699: if (ref($settings) ne 'HASH') {
2700: $check = ' checked="checked" ';
2701: }
2702: }
2703: }
2704: $output .= '<td class="LC_left_item">'.
2705: '<span class="LC_nobreak"><label>'.
2706: '<input type="checkbox" name="canmodify_'.$role.'" '.
2707: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
2708: '</label></span></td>';
2709: $rem = @fields%($numinrow);
2710: }
2711: my $colsleft = $numinrow - $rem;
2712: if ($colsleft > 1 ) {
2713: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2714: ' </td>';
2715: } elsif ($colsleft == 1) {
2716: $output .= '<td class="LC_left_item"> </td>';
2717: }
2718: $output .= '</tr></table></td></tr>';
2719: return $output;
2720: }
1.28 raeburn 2721:
1.25 raeburn 2722: sub users_cansearch_row {
2723: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
2724: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 2725: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
2726: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 2727: my $rem;
2728: if (ref($types) eq 'ARRAY') {
2729: for (my $i=0; $i<@{$types}; $i++) {
2730: if (defined($usertypes->{$types->[$i]})) {
2731: my $rem = $i%($numinrow);
2732: if ($rem == 0) {
2733: if ($i > 0) {
2734: $output .= '</tr>';
2735: }
2736: $output .= '<tr>';
1.23 raeburn 2737: }
1.26 raeburn 2738: my $check = ' ';
2739: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
2740: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
2741: $check = ' checked="checked" ';
2742: }
1.23 raeburn 2743: }
1.26 raeburn 2744: $output .= '<td class="LC_left_item">'.
2745: '<span class="LC_nobreak"><label>'.
2746: '<input type="checkbox" name="cansearch" '.
2747: 'value="'.$types->[$i].'"'.$check.'/>'.
2748: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 2749: }
2750: }
1.26 raeburn 2751:
2752: $rem = @{$types}%($numinrow);
1.23 raeburn 2753: }
2754: my $colsleft = $numinrow - $rem;
2755: if ($colsleft > 1) {
1.25 raeburn 2756: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 2757: } else {
1.25 raeburn 2758: $output .= '<td class="LC_left_item">';
1.23 raeburn 2759: }
2760: my $defcheck = ' ';
2761: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 2762: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
2763: $defcheck = ' checked="checked" ';
2764: }
1.23 raeburn 2765: }
1.25 raeburn 2766: $output .= '<span class="LC_nobreak"><label>'.
2767: '<input type="checkbox" name="cansearch" '.
2768: 'value="default"'.$defcheck.'/>'.
2769: $othertitle.'</label></span></td>'.
2770: '</tr></table></td></tr>';
2771: return $output;
1.23 raeburn 2772: }
2773:
2774: sub sorted_searchtitles {
2775: my %searchtitles = &Apache::lonlocal::texthash(
2776: 'uname' => 'username',
2777: 'lastname' => 'last name',
2778: 'lastfirst' => 'last name, first name',
2779: );
2780: my @titleorder = ('uname','lastname','lastfirst');
2781: return (\%searchtitles,\@titleorder);
2782: }
2783:
1.25 raeburn 2784: sub sorted_searchtypes {
2785: my %srchtypes_desc = (
2786: exact => 'is exact match',
2787: contains => 'contains ..',
2788: begins => 'begins with ..',
2789: );
2790: my @srchtypeorder = ('exact','begins','contains');
2791: return (\%srchtypes_desc,\@srchtypeorder);
2792: }
2793:
1.3 raeburn 2794: sub usertype_update_row {
2795: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
2796: my $datatable;
2797: my $numinrow = 4;
2798: foreach my $type (@{$types}) {
2799: if (defined($usertypes->{$type})) {
2800: $$rownums ++;
2801: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
2802: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
2803: '</td><td class="LC_left_item"><table>';
2804: for (my $i=0; $i<@{$fields}; $i++) {
2805: my $rem = $i%($numinrow);
2806: if ($rem == 0) {
2807: if ($i > 0) {
2808: $datatable .= '</tr>';
2809: }
2810: $datatable .= '<tr>';
2811: }
2812: my $check = ' ';
1.39 raeburn 2813: if (ref($settings) eq 'HASH') {
2814: if (ref($settings->{'fields'}) eq 'HASH') {
2815: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
2816: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
2817: $check = ' checked="checked" ';
2818: }
1.3 raeburn 2819: }
2820: }
2821: }
2822:
2823: if ($i == @{$fields}-1) {
2824: my $colsleft = $numinrow - $rem;
2825: if ($colsleft > 1) {
2826: $datatable .= '<td colspan="'.$colsleft.'">';
2827: } else {
2828: $datatable .= '<td>';
2829: }
2830: } else {
2831: $datatable .= '<td>';
2832: }
1.8 raeburn 2833: $datatable .= '<span class="LC_nobreak"><label>'.
2834: '<input type="checkbox" name="updateable_'.$type.
2835: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
2836: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 2837: }
2838: $datatable .= '</tr></table></td></tr>';
2839: }
2840: }
2841: return $datatable;
1.1 raeburn 2842: }
2843:
2844: sub modify_login {
1.9 raeburn 2845: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 2846: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 2847: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 2848: adminmail => 'Display administrator E-mail address',
1.43 raeburn 2849: newuser => 'Link for visitors to create a user account',
1.41 raeburn 2850: loginheader => 'Log-in box header');
1.3 raeburn 2851: my @offon = ('off','on');
1.6 raeburn 2852: my %loginhash;
1.9 raeburn 2853: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
2854: \%domconfig,\%loginhash);
1.43 raeburn 2855: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2856: foreach my $item (@toggles) {
2857: $loginhash{login}{$item} = $env{'form.'.$item};
2858: }
1.41 raeburn 2859: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 2860: if (ref($colchanges{'login'}) eq 'HASH') {
2861: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
2862: \%loginhash);
2863: }
1.1 raeburn 2864: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
2865: $dom);
2866: if ($putresult eq 'ok') {
1.43 raeburn 2867: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2868: my %defaultchecked = (
2869: 'coursecatalog' => 'on',
2870: 'adminmail' => 'off',
1.43 raeburn 2871: 'newuser' => 'off',
1.42 raeburn 2872: );
1.55 raeburn 2873: if (ref($domconfig{'login'}) eq 'HASH') {
2874: foreach my $item (@toggles) {
2875: if ($defaultchecked{$item} eq 'on') {
2876: if (($domconfig{'login'}{$item} eq '0') &&
2877: ($env{'form.'.$item} eq '1')) {
2878: $changes{$item} = 1;
2879: } elsif (($domconfig{'login'}{$item} eq '' ||
2880: $domconfig{'login'}{$item} eq '1') &&
2881: ($env{'form.'.$item} eq '0')) {
2882: $changes{$item} = 1;
2883: }
2884: } elsif ($defaultchecked{$item} eq 'off') {
2885: if (($domconfig{'login'}{$item} eq '1') &&
2886: ($env{'form.'.$item} eq '0')) {
2887: $changes{$item} = 1;
2888: } elsif (($domconfig{'login'}{$item} eq '' ||
2889: $domconfig{'login'}{$item} eq '0') &&
2890: ($env{'form.'.$item} eq '1')) {
2891: $changes{$item} = 1;
2892: }
1.42 raeburn 2893: }
2894: }
1.55 raeburn 2895: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
2896: ($env{'form.loginheader'} eq 'image')) {
2897: $changes{'loginheader'} = 1;
2898: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
2899: $domconfig{'login'}{'loginheader'} eq 'image') &&
2900: ($env{'form.loginheader'} eq 'text')) {
2901: $changes{'loginheader'} = 1;
2902: }
1.41 raeburn 2903: }
1.6 raeburn 2904: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 2905: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 2906: $resulttext = &mt('Changes made:').'<ul>';
2907: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 2908: if ($item eq 'loginheader') {
2909: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
2910: } else {
2911: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
2912: }
1.1 raeburn 2913: }
1.6 raeburn 2914: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 2915: } else {
2916: $resulttext = &mt('No changes made to log-in page settings');
2917: }
2918: } else {
1.11 albertel 2919: $resulttext = '<span class="LC_error">'.
2920: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2921: }
1.6 raeburn 2922: if ($errors) {
1.9 raeburn 2923: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 2924: $errors.'</ul>';
2925: }
2926: return $resulttext;
2927: }
2928:
2929: sub color_font_choices {
2930: my %choices =
2931: &Apache::lonlocal::texthash (
2932: img => "Header",
2933: bgs => "Background colors",
2934: links => "Link colors",
1.55 raeburn 2935: images => "Images",
1.6 raeburn 2936: font => "Font color",
1.76 raeburn 2937: pgbg => "Page",
1.6 raeburn 2938: tabbg => "Header",
2939: sidebg => "Border",
2940: link => "Link",
2941: alink => "Active link",
2942: vlink => "Visited link",
2943: );
2944: return %choices;
2945: }
2946:
2947: sub modify_rolecolors {
1.9 raeburn 2948: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 2949: my ($resulttext,%rolehash);
2950: $rolehash{'rolecolors'} = {};
1.55 raeburn 2951: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
2952: if ($domconfig{'rolecolors'} eq '') {
2953: $domconfig{'rolecolors'} = {};
2954: }
2955: }
1.9 raeburn 2956: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 2957: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
2958: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
2959: $dom);
2960: if ($putresult eq 'ok') {
2961: if (keys(%changes) > 0) {
1.41 raeburn 2962: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 2963: $resulttext = &display_colorchgs($dom,\%changes,$roles,
2964: $rolehash{'rolecolors'});
2965: } else {
2966: $resulttext = &mt('No changes made to default color schemes');
2967: }
2968: } else {
1.11 albertel 2969: $resulttext = '<span class="LC_error">'.
2970: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 2971: }
2972: if ($errors) {
2973: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
2974: $errors.'</ul>';
2975: }
2976: return $resulttext;
2977: }
2978:
2979: sub modify_colors {
1.9 raeburn 2980: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 2981: my (%changes,%choices);
1.51 raeburn 2982: my @bgs;
1.6 raeburn 2983: my @links = ('link','alink','vlink');
1.41 raeburn 2984: my @logintext;
1.6 raeburn 2985: my @images;
2986: my $servadm = $r->dir_config('lonAdmEMail');
2987: my $errors;
2988: foreach my $role (@{$roles}) {
2989: if ($role eq 'login') {
1.12 raeburn 2990: %choices = &login_choices();
1.41 raeburn 2991: @logintext = ('textcol','bgcol');
1.12 raeburn 2992: } else {
2993: %choices = &color_font_choices();
2994: }
2995: if ($role eq 'login') {
1.41 raeburn 2996: @images = ('img','logo','domlogo','login');
1.51 raeburn 2997: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 2998: } else {
2999: @images = ('img');
1.51 raeburn 3000: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 3001: }
3002: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 3003: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 3004: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
3005: }
1.46 raeburn 3006: my ($configuserok,$author_ok,$switchserver) =
3007: &config_check($dom,$confname,$servadm);
1.9 raeburn 3008: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 3009: if (ref($domconfig->{$role}) ne 'HASH') {
3010: $domconfig->{$role} = {};
3011: }
1.8 raeburn 3012: foreach my $img (@images) {
1.70 raeburn 3013: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
3014: if (defined($env{'form.login_showlogo_'.$img})) {
3015: $confhash->{$role}{'showlogo'}{$img} = 1;
3016: } else {
3017: $confhash->{$role}{'showlogo'}{$img} = 0;
3018: }
3019: }
1.18 albertel 3020: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
3021: && !defined($domconfig->{$role}{$img})
3022: && !$env{'form.'.$role.'_del_'.$img}
3023: && $env{'form.'.$role.'_import_'.$img}) {
3024: # import the old configured image from the .tab setting
3025: # if they haven't provided a new one
3026: $domconfig->{$role}{$img} =
3027: $env{'form.'.$role.'_import_'.$img};
3028: }
1.6 raeburn 3029: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 3030: my $error;
1.6 raeburn 3031: if ($configuserok eq 'ok') {
1.9 raeburn 3032: if ($switchserver) {
1.12 raeburn 3033: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 3034: } else {
3035: if ($author_ok eq 'ok') {
3036: my ($result,$logourl) =
3037: &publishlogo($r,'upload',$role.'_'.$img,
3038: $dom,$confname,$img,$width,$height);
3039: if ($result eq 'ok') {
3040: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 3041: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3042: } else {
1.12 raeburn 3043: $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 3044: }
3045: } else {
1.46 raeburn 3046: $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 3047: }
3048: }
3049: } else {
1.46 raeburn 3050: $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 3051: }
3052: if ($error) {
1.8 raeburn 3053: &Apache::lonnet::logthis($error);
1.11 albertel 3054: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 3055: }
3056: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 3057: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
3058: my $error;
3059: if ($configuserok eq 'ok') {
3060: # is confname an author?
3061: if ($switchserver eq '') {
3062: if ($author_ok eq 'ok') {
3063: my ($result,$logourl) =
3064: &publishlogo($r,'copy',$domconfig->{$role}{$img},
3065: $dom,$confname,$img,$width,$height);
3066: if ($result eq 'ok') {
3067: $confhash->{$role}{$img} = $logourl;
1.18 albertel 3068: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3069: }
3070: }
3071: }
3072: }
1.6 raeburn 3073: }
3074: }
3075: }
3076: if (ref($domconfig) eq 'HASH') {
3077: if (ref($domconfig->{$role}) eq 'HASH') {
3078: foreach my $img (@images) {
3079: if ($domconfig->{$role}{$img} ne '') {
3080: if ($env{'form.'.$role.'_del_'.$img}) {
3081: $confhash->{$role}{$img} = '';
1.12 raeburn 3082: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3083: } else {
1.9 raeburn 3084: if ($confhash->{$role}{$img} eq '') {
3085: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
3086: }
1.6 raeburn 3087: }
3088: } else {
3089: if ($env{'form.'.$role.'_del_'.$img}) {
3090: $confhash->{$role}{$img} = '';
1.12 raeburn 3091: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3092: }
3093: }
1.70 raeburn 3094: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
3095: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
3096: if ($confhash->{$role}{'showlogo'}{$img} ne
3097: $domconfig->{$role}{'showlogo'}{$img}) {
3098: $changes{$role}{'showlogo'}{$img} = 1;
3099: }
3100: } else {
3101: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3102: $changes{$role}{'showlogo'}{$img} = 1;
3103: }
3104: }
3105: }
3106: }
1.6 raeburn 3107: if ($domconfig->{$role}{'font'} ne '') {
3108: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
3109: $changes{$role}{'font'} = 1;
3110: }
3111: } else {
3112: if ($confhash->{$role}{'font'}) {
3113: $changes{$role}{'font'} = 1;
3114: }
3115: }
3116: foreach my $item (@bgs) {
3117: if ($domconfig->{$role}{$item} ne '') {
3118: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3119: $changes{$role}{'bgs'}{$item} = 1;
3120: }
3121: } else {
3122: if ($confhash->{$role}{$item}) {
3123: $changes{$role}{'bgs'}{$item} = 1;
3124: }
3125: }
3126: }
3127: foreach my $item (@links) {
3128: if ($domconfig->{$role}{$item} ne '') {
3129: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3130: $changes{$role}{'links'}{$item} = 1;
3131: }
3132: } else {
3133: if ($confhash->{$role}{$item}) {
3134: $changes{$role}{'links'}{$item} = 1;
3135: }
3136: }
3137: }
1.41 raeburn 3138: foreach my $item (@logintext) {
3139: if ($domconfig->{$role}{$item} ne '') {
3140: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3141: $changes{$role}{'logintext'}{$item} = 1;
3142: }
3143: } else {
3144: if ($confhash->{$role}{$item}) {
3145: $changes{$role}{'logintext'}{$item} = 1;
3146: }
3147: }
3148: }
1.6 raeburn 3149: } else {
3150: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3151: \@logintext,$confhash,\%changes);
1.6 raeburn 3152: }
3153: } else {
3154: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3155: \@logintext,$confhash,\%changes);
1.6 raeburn 3156: }
3157: }
3158: return ($errors,%changes);
3159: }
3160:
1.46 raeburn 3161: sub config_check {
3162: my ($dom,$confname,$servadm) = @_;
3163: my ($configuserok,$author_ok,$switchserver,%currroles);
3164: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
3165: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
3166: $confname,$servadm);
3167: if ($configuserok eq 'ok') {
3168: $switchserver = &check_switchserver($dom,$confname);
3169: if ($switchserver eq '') {
3170: $author_ok = &check_authorstatus($dom,$confname,%currroles);
3171: }
3172: }
3173: return ($configuserok,$author_ok,$switchserver);
3174: }
3175:
1.6 raeburn 3176: sub default_change_checker {
1.41 raeburn 3177: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 3178: foreach my $item (@{$links}) {
3179: if ($confhash->{$role}{$item}) {
3180: $changes->{$role}{'links'}{$item} = 1;
3181: }
3182: }
3183: foreach my $item (@{$bgs}) {
3184: if ($confhash->{$role}{$item}) {
3185: $changes->{$role}{'bgs'}{$item} = 1;
3186: }
3187: }
1.41 raeburn 3188: foreach my $item (@{$logintext}) {
3189: if ($confhash->{$role}{$item}) {
3190: $changes->{$role}{'logintext'}{$item} = 1;
3191: }
3192: }
1.6 raeburn 3193: foreach my $img (@{$images}) {
3194: if ($env{'form.'.$role.'_del_'.$img}) {
3195: $confhash->{$role}{$img} = '';
1.12 raeburn 3196: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 3197: }
1.70 raeburn 3198: if ($role eq 'login') {
3199: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3200: $changes->{$role}{'showlogo'}{$img} = 1;
3201: }
3202: }
1.6 raeburn 3203: }
3204: if ($confhash->{$role}{'font'}) {
3205: $changes->{$role}{'font'} = 1;
3206: }
1.48 raeburn 3207: }
1.6 raeburn 3208:
3209: sub display_colorchgs {
3210: my ($dom,$changes,$roles,$confhash) = @_;
3211: my (%choices,$resulttext);
3212: if (!grep(/^login$/,@{$roles})) {
3213: $resulttext = &mt('Changes made:').'<br />';
3214: }
3215: foreach my $role (@{$roles}) {
3216: if ($role eq 'login') {
3217: %choices = &login_choices();
3218: } else {
3219: %choices = &color_font_choices();
3220: }
3221: if (ref($changes->{$role}) eq 'HASH') {
3222: if ($role ne 'login') {
3223: $resulttext .= '<h4>'.&mt($role).'</h4>';
3224: }
3225: foreach my $key (sort(keys(%{$changes->{$role}}))) {
3226: if ($role ne 'login') {
3227: $resulttext .= '<ul>';
3228: }
3229: if (ref($changes->{$role}{$key}) eq 'HASH') {
3230: if ($role ne 'login') {
3231: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
3232: }
3233: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 3234: if (($role eq 'login') && ($key eq 'showlogo')) {
3235: if ($confhash->{$role}{$key}{$item}) {
3236: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
3237: } else {
3238: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
3239: }
3240: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 3241: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
3242: } else {
1.12 raeburn 3243: my $newitem = $confhash->{$role}{$item};
3244: if ($key eq 'images') {
3245: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
3246: }
3247: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 3248: }
3249: }
3250: if ($role ne 'login') {
3251: $resulttext .= '</ul></li>';
3252: }
3253: } else {
3254: if ($confhash->{$role}{$key} eq '') {
3255: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
3256: } else {
3257: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
3258: }
3259: }
3260: if ($role ne 'login') {
3261: $resulttext .= '</ul>';
3262: }
3263: }
3264: }
3265: }
1.3 raeburn 3266: return $resulttext;
1.1 raeburn 3267: }
3268:
1.9 raeburn 3269: sub thumb_dimensions {
3270: return ('200','50');
3271: }
3272:
1.16 raeburn 3273: sub check_dimensions {
3274: my ($inputfile) = @_;
3275: my ($fullwidth,$fullheight);
3276: if ($inputfile =~ m|^[/\w.\-]+$|) {
3277: if (open(PIPE,"identify $inputfile 2>&1 |")) {
3278: my $imageinfo = <PIPE>;
3279: if (!close(PIPE)) {
3280: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
3281: }
3282: chomp($imageinfo);
3283: my ($fullsize) =
1.21 raeburn 3284: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 3285: if ($fullsize) {
3286: ($fullwidth,$fullheight) = split(/x/,$fullsize);
3287: }
3288: }
3289: }
3290: return ($fullwidth,$fullheight);
3291: }
3292:
1.9 raeburn 3293: sub check_configuser {
3294: my ($uhome,$dom,$confname,$servadm) = @_;
3295: my ($configuserok,%currroles);
3296: if ($uhome eq 'no_host') {
3297: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
3298: my $configpass = &LONCAPA::Enrollment::create_password();
3299: $configuserok =
3300: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
3301: $configpass,'','','','','',undef,$servadm);
3302: } else {
3303: $configuserok = 'ok';
3304: %currroles =
3305: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
3306: }
3307: return ($configuserok,%currroles);
3308: }
3309:
3310: sub check_authorstatus {
3311: my ($dom,$confname,%currroles) = @_;
3312: my $author_ok;
1.40 raeburn 3313: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 3314: my $start = time;
3315: my $end = 0;
3316: $author_ok =
3317: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 3318: 'au',$end,$start,'','','domconfig');
1.9 raeburn 3319: } else {
3320: $author_ok = 'ok';
3321: }
3322: return $author_ok;
3323: }
3324:
3325: sub publishlogo {
1.46 raeburn 3326: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 3327: my ($output,$fname,$logourl);
3328: if ($action eq 'upload') {
3329: $fname=$env{'form.'.$formname.'.filename'};
3330: chop($env{'form.'.$formname});
3331: } else {
3332: ($fname) = ($formname =~ /([^\/]+)$/);
3333: }
1.46 raeburn 3334: if ($savefileas ne '') {
3335: $fname = $savefileas;
3336: }
1.9 raeburn 3337: $fname=&Apache::lonnet::clean_filename($fname);
3338: # See if there is anything left
3339: unless ($fname) { return ('error: no uploaded file'); }
3340: $fname="$subdir/$fname";
3341: my $filepath='/home/'.$confname.'/public_html';
3342: my ($fnamepath,$file,$fetchthumb);
3343: $file=$fname;
3344: if ($fname=~m|/|) {
3345: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
3346: }
3347: my @parts=split(/\//,$filepath.'/'.$fnamepath);
3348: my $count;
3349: for ($count=4;$count<=$#parts;$count++) {
3350: $filepath.="/$parts[$count]";
3351: if ((-e $filepath)!=1) {
3352: mkdir($filepath,02770);
3353: }
3354: }
3355: # Check for bad extension and disallow upload
3356: if ($file=~/\.(\w+)$/ &&
3357: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
3358: $output =
3359: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
3360: } elsif ($file=~/\.(\w+)$/ &&
3361: !defined(&Apache::loncommon::fileembstyle($1))) {
3362: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
3363: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 3364: $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 3365: } elsif (-d "$filepath/$file") {
3366: $output = &mt('File name is a directory name - rename the file and re-upload');
3367: } else {
3368: my $source = $filepath.'/'.$file;
3369: my $logfile;
3370: if (!open($logfile,">>$source".'.log')) {
3371: return (&mt('No write permission to Construction Space'));
3372: }
3373: print $logfile
3374: "\n================= Publish ".localtime()." ================\n".
3375: $env{'user.name'}.':'.$env{'user.domain'}."\n";
3376: # Save the file
3377: if (!open(FH,'>'.$source)) {
3378: &Apache::lonnet::logthis('Failed to create '.$source);
3379: return (&mt('Failed to create file'));
3380: }
3381: if ($action eq 'upload') {
3382: if (!print FH ($env{'form.'.$formname})) {
3383: &Apache::lonnet::logthis('Failed to write to '.$source);
3384: return (&mt('Failed to write file'));
3385: }
3386: } else {
3387: my $original = &Apache::lonnet::filelocation('',$formname);
3388: if(!copy($original,$source)) {
3389: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
3390: return (&mt('Failed to write file'));
3391: }
3392: }
3393: close(FH);
3394: chmod(0660, $source); # Permissions to rw-rw---.
3395:
3396: my $docroot=$r->dir_config('lonDocRoot');
3397: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
3398: my $copyfile=$targetdir.'/'.$file;
3399:
3400: my @parts=split(/\//,$targetdir);
3401: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
3402: for (my $count=5;$count<=$#parts;$count++) {
3403: $path.="/$parts[$count]";
3404: if (!-e $path) {
3405: print $logfile "\nCreating directory ".$path;
3406: mkdir($path,02770);
3407: }
3408: }
3409: my $versionresult;
3410: if (-e $copyfile) {
3411: $versionresult = &logo_versioning($targetdir,$file,$logfile);
3412: } else {
3413: $versionresult = 'ok';
3414: }
3415: if ($versionresult eq 'ok') {
3416: if (copy($source,$copyfile)) {
3417: print $logfile "\nCopied original source to ".$copyfile."\n";
3418: $output = 'ok';
3419: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
3420: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
3421: } else {
3422: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
3423: $output = &mt('Failed to copy file to RES space').", $!";
3424: }
3425: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
3426: my $inputfile = $filepath.'/'.$file;
3427: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 3428: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
3429: if ($fullwidth ne '' && $fullheight ne '') {
3430: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
3431: my $thumbsize = $thumbwidth.'x'.$thumbheight;
3432: system("convert -sample $thumbsize $inputfile $outfile");
3433: chmod(0660, $filepath.'/tn-'.$file);
3434: if (-e $outfile) {
3435: my $copyfile=$targetdir.'/tn-'.$file;
3436: if (copy($outfile,$copyfile)) {
3437: print $logfile "\nCopied source to ".$copyfile."\n";
3438: &write_metadata($dom,$confname,$formname,
3439: $targetdir,'tn-'.$file,$logfile);
3440: } else {
3441: print $logfile "\nUnable to write ".$copyfile.
3442: ':'.$!."\n";
3443: }
3444: }
1.9 raeburn 3445: }
3446: }
3447: }
3448: } else {
3449: $output = $versionresult;
3450: }
3451: }
3452: return ($output,$logourl);
3453: }
3454:
3455: sub logo_versioning {
3456: my ($targetdir,$file,$logfile) = @_;
3457: my $target = $targetdir.'/'.$file;
3458: my ($maxversion,$fn,$extn,$output);
3459: $maxversion = 0;
3460: if ($file =~ /^(.+)\.(\w+)$/) {
3461: $fn=$1;
3462: $extn=$2;
3463: }
3464: opendir(DIR,$targetdir);
3465: while (my $filename=readdir(DIR)) {
3466: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
3467: $maxversion=($1>$maxversion)?$1:$maxversion;
3468: }
3469: }
3470: $maxversion++;
3471: print $logfile "\nCreating old version ".$maxversion."\n";
3472: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
3473: if (copy($target,$copyfile)) {
3474: print $logfile "Copied old target to ".$copyfile."\n";
3475: $copyfile=$copyfile.'.meta';
3476: if (copy($target.'.meta',$copyfile)) {
3477: print $logfile "Copied old target metadata to ".$copyfile."\n";
3478: $output = 'ok';
3479: } else {
3480: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
3481: $output = &mt('Failed to copy old meta').", $!, ";
3482: }
3483: } else {
3484: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
3485: $output = &mt('Failed to copy old target').", $!, ";
3486: }
3487: return $output;
3488: }
3489:
3490: sub write_metadata {
3491: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
3492: my (%metadatafields,%metadatakeys,$output);
3493: $metadatafields{'title'}=$formname;
3494: $metadatafields{'creationdate'}=time;
3495: $metadatafields{'lastrevisiondate'}=time;
3496: $metadatafields{'copyright'}='public';
3497: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
3498: $env{'user.domain'};
3499: $metadatafields{'authorspace'}=$confname.':'.$dom;
3500: $metadatafields{'domain'}=$dom;
3501: {
3502: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
3503: my $mfh;
3504: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
3505: $output = &mt('Could not write metadata');
3506: }
3507: foreach (sort keys %metadatafields) {
3508: unless ($_=~/\./) {
3509: my $unikey=$_;
3510: $unikey=~/^([A-Za-z]+)/;
3511: my $tag=$1;
3512: $tag=~tr/A-Z/a-z/;
3513: print $mfh "\n\<$tag";
3514: foreach (split(/\,/,$metadatakeys{$unikey})) {
3515: my $value=$metadatafields{$unikey.'.'.$_};
3516: $value=~s/\"/\'\'/g;
3517: print $mfh ' '.$_.'="'.$value.'"';
3518: }
3519: print $mfh '>'.
3520: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
3521: .'</'.$tag.'>';
3522: }
3523: }
3524: $output = 'ok';
3525: print $logfile "\nWrote metadata";
3526: close($mfh);
3527: }
3528: }
3529:
3530: sub check_switchserver {
3531: my ($dom,$confname) = @_;
3532: my ($allowed,$switchserver);
3533: my $home = &Apache::lonnet::homeserver($confname,$dom);
3534: if ($home eq 'no_host') {
3535: $home = &Apache::lonnet::domain($dom,'primary');
3536: }
3537: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 3538: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3539: if (!$allowed) {
3540: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 3541: }
3542: return $switchserver;
3543: }
3544:
1.30 raeburn 3545: sub javascript_set_colnums {
3546: return <<END;
3547: function setDisplayColumns() {
3548: if (document.pickactions.width.value > 1100) {
3549: document.pickactions.numcols[1].checked = true;
3550: } else {
3551: document.pickactions.numcols[0].checked = true;
3552: }
3553: }
3554: END
3555: }
3556:
1.1 raeburn 3557: sub modify_quotas {
1.86 raeburn 3558: my ($dom,$action,%domconfig) = @_;
3559: my ($context,@usertools);
3560: if ($action eq 'quotas') {
3561: $context = 'tools';
3562: } else {
3563: $context = $action;
3564: }
3565: if ($context eq 'requestcourses') {
3566: @usertools = ('official','unofficial');
3567: } else {
3568: @usertools = ('aboutme','blog','portfolio');
3569: }
1.72 raeburn 3570: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.1 raeburn 3571: my ($resulttext,%changes);
1.44 raeburn 3572: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.72 raeburn 3573: my %titles = &tool_titles();
3574: my (%confhash,%toolshash);
1.1 raeburn 3575: foreach my $key (keys(%env)) {
1.86 raeburn 3576: unless ($context eq 'requestcourses') {
3577: if ($key =~ /^form\.quota_(.+)$/) {
3578: $confhash{'defaultquota'}{$1} = $env{$key};
3579: }
3580: }
3581: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.72 raeburn 3582: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
3583: }
3584: }
1.86 raeburn 3585: unless ($context eq 'requestcourses') {
3586: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
3587: }
1.72 raeburn 3588: foreach my $item (@usertools) {
3589: foreach my $type (@{$types},'default','_LC_adv') {
3590: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
3591: $confhash{$item}{$type} = 1;
3592: } else {
3593: $confhash{$item}{$type} = 0;
3594: }
1.86 raeburn 3595: if (ref($domconfig{$action}) eq 'HASH') {
3596: if (ref($domconfig{$action}{$item}) eq 'HASH') {
3597: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
3598: $changes{$item}{$type} = 1;
3599: }
3600: } else {
3601: if ($context eq 'requestcourses') {
3602: if ($confhash{$item}{$type}) {
3603: $changes{$item}{$type} = 1;
3604: }
3605: } else {
3606: if (!$confhash{$item}{$type}) {
3607: $changes{$item}{$type} = 1;
3608: }
3609: }
3610: }
3611: } else {
3612: if ($context eq 'requestcourses') {
3613: if ($confhash{$item}{$type}) {
1.72 raeburn 3614: $changes{$item}{$type} = 1;
3615: }
3616: } else {
3617: if (!$confhash{$item}{$type}) {
3618: $changes{$item}{$type} = 1;
3619: }
3620: }
3621: }
1.1 raeburn 3622: }
3623: }
1.86 raeburn 3624: unless ($context eq 'requestcourses') {
3625: if (ref($domconfig{'quotas'}) eq 'HASH') {
3626: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3627: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
3628: if (exists($confhash{'defaultquota'}{$key})) {
3629: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
3630: $changes{'defaultquota'}{$key} = 1;
3631: }
3632: } else {
3633: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 3634: }
3635: }
1.86 raeburn 3636: } else {
3637: foreach my $key (keys(%{$domconfig{'quotas'}})) {
3638: if (exists($confhash{'defaultquota'}{$key})) {
3639: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
3640: $changes{'defaultquota'}{$key} = 1;
3641: }
3642: } else {
3643: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 3644: }
1.1 raeburn 3645: }
3646: }
3647: }
1.86 raeburn 3648: if (ref($confhash{'defaultquota'}) eq 'HASH') {
3649: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
3650: if (ref($domconfig{'quotas'}) eq 'HASH') {
3651: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3652: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
3653: $changes{'defaultquota'}{$key} = 1;
3654: }
3655: } else {
3656: if (!exists($domconfig{'quotas'}{$key})) {
3657: $changes{'defaultquota'}{$key} = 1;
3658: }
1.72 raeburn 3659: }
3660: } else {
1.86 raeburn 3661: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 3662: }
1.1 raeburn 3663: }
3664: }
3665: }
1.72 raeburn 3666:
3667: foreach my $key (keys(%confhash)) {
3668: $domdefaults{$key} = $confhash{$key};
3669: }
3670:
1.1 raeburn 3671: my %quotahash = (
1.86 raeburn 3672: $action => { %confhash }
1.1 raeburn 3673: );
3674: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
3675: $dom);
3676: if ($putresult eq 'ok') {
3677: if (keys(%changes) > 0) {
1.72 raeburn 3678: my $cachetime = 24*60*60;
3679: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
3680:
1.1 raeburn 3681: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 3682: unless ($context eq 'requestcourses') {
3683: if (ref($changes{'defaultquota'}) eq 'HASH') {
3684: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
3685: foreach my $type (@{$types},'default') {
3686: if (defined($changes{'defaultquota'}{$type})) {
3687: my $typetitle = $usertypes->{$type};
3688: if ($type eq 'default') {
3689: $typetitle = $othertitle;
3690: }
3691: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 3692: }
3693: }
1.86 raeburn 3694: $resulttext .= '</ul></li>';
1.72 raeburn 3695: }
3696: }
1.80 raeburn 3697: my %newenv;
1.72 raeburn 3698: foreach my $item (@usertools) {
3699: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 3700: my $newacc =
3701: &Apache::lonnet::usertools_access($env{'user.name'},
3702: $env{'user.domain'},
1.86 raeburn 3703: $item,'reload',$context);
3704: if ($context eq 'requestcourses') {
3705: if ($env{'environment.canrequest.'.$item} ne $newacc) {
3706: $newenv{'environment.canrequest.'.$item} = $newacc;
3707: }
3708: } else {
3709: if ($env{'environment.availabletools.'.$item} ne $newacc) {
3710: $newenv{'environment.availabletools.'.$item} = $newacc;
3711: }
1.80 raeburn 3712: }
1.72 raeburn 3713: $resulttext .= '<li>'.$titles{$item}.'<ul>';
3714: foreach my $type (@{$types},'default','_LC_adv') {
3715: if ($changes{$item}{$type}) {
3716: my $typetitle = $usertypes->{$type};
3717: if ($type eq 'default') {
3718: $typetitle = $othertitle;
3719: } elsif ($type eq '_LC_adv') {
3720: $typetitle = 'LON-CAPA Advanced Users';
3721: }
3722: if ($confhash{$item}{$type}) {
3723: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
3724: } else {
3725: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
3726: }
3727: }
1.26 raeburn 3728: }
1.72 raeburn 3729: $resulttext .= '</ul></li>';
1.26 raeburn 3730: }
1.1 raeburn 3731: }
3732: $resulttext .= '</ul>';
1.80 raeburn 3733: if (keys(%newenv)) {
3734: &Apache::lonnet::appenv(\%newenv);
3735: }
1.1 raeburn 3736: } else {
1.86 raeburn 3737: if ($context eq 'requestcourses') {
3738: $resulttext = &mt('No changes made to rights to request creation of courses.');
3739: } else {
3740: $resulttext = &mt('No changes made to availability of home pages, blogs, portfolios or default quotas');
3741: }
1.1 raeburn 3742: }
3743: } else {
1.11 albertel 3744: $resulttext = '<span class="LC_error">'.
3745: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3746: }
1.3 raeburn 3747: return $resulttext;
1.1 raeburn 3748: }
3749:
1.3 raeburn 3750: sub modify_autoenroll {
3751: my ($dom,%domconfig) = @_;
1.1 raeburn 3752: my ($resulttext,%changes);
3753: my %currautoenroll;
3754: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
3755: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
3756: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
3757: }
3758: }
3759: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
3760: my %title = ( run => 'Auto-enrollment active',
3761: sender => 'Sender for notification messages');
3762: my @offon = ('off','on');
1.17 raeburn 3763: my $sender_uname = $env{'form.sender_uname'};
3764: my $sender_domain = $env{'form.sender_domain'};
3765: if ($sender_domain eq '') {
3766: $sender_uname = '';
3767: } elsif ($sender_uname eq '') {
3768: $sender_domain = '';
3769: }
1.1 raeburn 3770: my %autoenrollhash = (
3771: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 3772: sender_uname => $sender_uname,
3773: sender_domain => $sender_domain,
1.1 raeburn 3774:
3775: }
3776: );
1.4 raeburn 3777: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
3778: $dom);
1.1 raeburn 3779: if ($putresult eq 'ok') {
3780: if (exists($currautoenroll{'run'})) {
3781: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
3782: $changes{'run'} = 1;
3783: }
3784: } elsif ($autorun) {
3785: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 3786: $changes{'run'} = 1;
1.1 raeburn 3787: }
3788: }
1.17 raeburn 3789: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 3790: $changes{'sender'} = 1;
3791: }
1.17 raeburn 3792: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 3793: $changes{'sender'} = 1;
3794: }
3795: if (keys(%changes) > 0) {
3796: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 3797: if ($changes{'run'}) {
1.1 raeburn 3798: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
3799: }
3800: if ($changes{'sender'}) {
1.17 raeburn 3801: if ($sender_uname eq '' || $sender_domain eq '') {
3802: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
3803: } else {
3804: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
3805: }
1.1 raeburn 3806: }
3807: $resulttext .= '</ul>';
3808: } else {
3809: $resulttext = &mt('No changes made to auto-enrollment settings');
3810: }
3811: } else {
1.11 albertel 3812: $resulttext = '<span class="LC_error">'.
3813: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3814: }
1.3 raeburn 3815: return $resulttext;
1.1 raeburn 3816: }
3817:
3818: sub modify_autoupdate {
1.3 raeburn 3819: my ($dom,%domconfig) = @_;
1.1 raeburn 3820: my ($resulttext,%currautoupdate,%fields,%changes);
3821: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
3822: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
3823: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
3824: }
3825: }
3826: my @offon = ('off','on');
3827: my %title = &Apache::lonlocal::texthash (
3828: run => 'Auto-update:',
3829: classlists => 'Updates to user information in classlists?'
3830: );
1.44 raeburn 3831: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 3832: my %fieldtitles = &Apache::lonlocal::texthash (
3833: id => 'Student/Employee ID',
1.20 raeburn 3834: permanentemail => 'E-mail address',
1.1 raeburn 3835: lastname => 'Last Name',
3836: firstname => 'First Name',
3837: middlename => 'Middle Name',
3838: gen => 'Generation',
3839: );
3840: my $othertitle = &mt('All users');
3841: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 3842: $othertitle = &mt('Other users');
1.1 raeburn 3843: }
3844: foreach my $key (keys(%env)) {
3845: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
3846: push(@{$fields{$1}},$2);
3847: }
3848: }
3849: my %updatehash = (
3850: autoupdate => { run => $env{'form.autoupdate_run'},
3851: classlists => $env{'form.classlists'},
3852: fields => {%fields},
3853: }
3854: );
3855: foreach my $key (keys(%currautoupdate)) {
3856: if (($key eq 'run') || ($key eq 'classlists')) {
3857: if (exists($updatehash{autoupdate}{$key})) {
3858: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
3859: $changes{$key} = 1;
3860: }
3861: }
3862: } elsif ($key eq 'fields') {
3863: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 3864: foreach my $item (@{$types},'default') {
1.1 raeburn 3865: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
3866: my $change = 0;
3867: foreach my $type (@{$currautoupdate{$key}{$item}}) {
3868: if (!exists($fields{$item})) {
3869: $change = 1;
3870: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 3871: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 3872: $change = 1;
3873: }
3874: }
3875: }
3876: if ($change) {
3877: push(@{$changes{$key}},$item);
3878: }
1.26 raeburn 3879: }
1.1 raeburn 3880: }
3881: }
3882: }
3883: }
1.26 raeburn 3884: foreach my $item (@{$types},'default') {
3885: if (defined($fields{$item})) {
3886: if (ref($currautoupdate{'fields'}) eq 'HASH') {
3887: if (!exists($currautoupdate{'fields'}{$item})) {
3888: push(@{$changes{'fields'}},$item);
3889: }
3890: } else {
3891: push(@{$changes{'fields'}},$item);
1.1 raeburn 3892: }
3893: }
3894: }
3895: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
3896: $dom);
3897: if ($putresult eq 'ok') {
3898: if (keys(%changes) > 0) {
3899: $resulttext = &mt('Changes made:').'<ul>';
3900: foreach my $key (sort(keys(%changes))) {
3901: if (ref($changes{$key}) eq 'ARRAY') {
3902: foreach my $item (@{$changes{$key}}) {
3903: my @newvalues;
3904: foreach my $type (@{$fields{$item}}) {
3905: push(@newvalues,$fieldtitles{$type});
3906: }
1.3 raeburn 3907: my $newvaluestr;
3908: if (@newvalues > 0) {
3909: $newvaluestr = join(', ',@newvalues);
3910: } else {
3911: $newvaluestr = &mt('none');
1.6 raeburn 3912: }
1.1 raeburn 3913: if ($item eq 'default') {
1.26 raeburn 3914: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 3915: } else {
1.26 raeburn 3916: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 3917: }
3918: }
3919: } else {
3920: my $newvalue;
3921: if ($key eq 'run') {
3922: $newvalue = $offon[$env{'form.autoupdate_run'}];
3923: } else {
3924: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 3925: }
1.1 raeburn 3926: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
3927: }
3928: }
3929: $resulttext .= '</ul>';
3930: } else {
1.3 raeburn 3931: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 3932: }
3933: } else {
1.11 albertel 3934: $resulttext = '<span class="LC_error">'.
3935: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3936: }
1.3 raeburn 3937: return $resulttext;
1.1 raeburn 3938: }
3939:
1.23 raeburn 3940: sub modify_directorysrch {
3941: my ($dom,%domconfig) = @_;
3942: my ($resulttext,%changes);
3943: my %currdirsrch;
3944: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3945: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
3946: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
3947: }
3948: }
3949: my %title = ( available => 'Directory search available',
1.24 raeburn 3950: localonly => 'Other domains can search',
1.23 raeburn 3951: searchby => 'Search types',
3952: searchtypes => 'Search latitude');
3953: my @offon = ('off','on');
1.24 raeburn 3954: my @otherdoms = ('Yes','No');
1.23 raeburn 3955:
1.25 raeburn 3956: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 3957: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
3958: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
3959:
1.44 raeburn 3960: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 3961: if (keys(%{$usertypes}) == 0) {
3962: @cansearch = ('default');
3963: } else {
3964: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
3965: foreach my $type (@{$currdirsrch{'cansearch'}}) {
3966: if (!grep(/^\Q$type\E$/,@cansearch)) {
3967: push(@{$changes{'cansearch'}},$type);
3968: }
1.23 raeburn 3969: }
1.26 raeburn 3970: foreach my $type (@cansearch) {
3971: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
3972: push(@{$changes{'cansearch'}},$type);
3973: }
1.23 raeburn 3974: }
1.26 raeburn 3975: } else {
3976: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 3977: }
3978: }
3979:
3980: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
3981: foreach my $by (@{$currdirsrch{'searchby'}}) {
3982: if (!grep(/^\Q$by\E$/,@searchby)) {
3983: push(@{$changes{'searchby'}},$by);
3984: }
3985: }
3986: foreach my $by (@searchby) {
3987: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
3988: push(@{$changes{'searchby'}},$by);
3989: }
3990: }
3991: } else {
3992: push(@{$changes{'searchby'}},@searchby);
3993: }
1.25 raeburn 3994:
3995: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
3996: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
3997: if (!grep(/^\Q$type\E$/,@searchtypes)) {
3998: push(@{$changes{'searchtypes'}},$type);
3999: }
4000: }
4001: foreach my $type (@searchtypes) {
4002: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
4003: push(@{$changes{'searchtypes'}},$type);
4004: }
4005: }
4006: } else {
4007: if (exists($currdirsrch{'searchtypes'})) {
4008: foreach my $type (@searchtypes) {
4009: if ($type ne $currdirsrch{'searchtypes'}) {
4010: push(@{$changes{'searchtypes'}},$type);
4011: }
4012: }
4013: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
4014: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
4015: }
4016: } else {
4017: push(@{$changes{'searchtypes'}},@searchtypes);
4018: }
4019: }
4020:
1.23 raeburn 4021: my %dirsrch_hash = (
4022: directorysrch => { available => $env{'form.dirsrch_available'},
4023: cansearch => \@cansearch,
1.24 raeburn 4024: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 4025: searchby => \@searchby,
1.25 raeburn 4026: searchtypes => \@searchtypes,
1.23 raeburn 4027: }
4028: );
4029: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
4030: $dom);
4031: if ($putresult eq 'ok') {
4032: if (exists($currdirsrch{'available'})) {
4033: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
4034: $changes{'available'} = 1;
4035: }
4036: } else {
4037: if ($env{'form.dirsrch_available'} eq '1') {
4038: $changes{'available'} = 1;
4039: }
4040: }
1.24 raeburn 4041: if (exists($currdirsrch{'localonly'})) {
4042: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
4043: $changes{'localonly'} = 1;
4044: }
4045: } else {
4046: if ($env{'form.dirsrch_localonly'} eq '1') {
4047: $changes{'localonly'} = 1;
4048: }
4049: }
1.23 raeburn 4050: if (keys(%changes) > 0) {
4051: $resulttext = &mt('Changes made:').'<ul>';
4052: if ($changes{'available'}) {
4053: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
4054: }
1.24 raeburn 4055: if ($changes{'localonly'}) {
4056: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
4057: }
4058:
1.23 raeburn 4059: if (ref($changes{'cansearch'}) eq 'ARRAY') {
4060: my $chgtext;
1.26 raeburn 4061: if (ref($usertypes) eq 'HASH') {
4062: if (keys(%{$usertypes}) > 0) {
4063: foreach my $type (@{$types}) {
4064: if (grep(/^\Q$type\E$/,@cansearch)) {
4065: $chgtext .= $usertypes->{$type}.'; ';
4066: }
4067: }
4068: if (grep(/^default$/,@cansearch)) {
4069: $chgtext .= $othertitle;
4070: } else {
4071: $chgtext =~ s/\; $//;
4072: }
4073: $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 4074: }
4075: }
4076: }
4077: if (ref($changes{'searchby'}) eq 'ARRAY') {
4078: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4079: my $chgtext;
4080: foreach my $type (@{$titleorder}) {
4081: if (grep(/^\Q$type\E$/,@searchby)) {
4082: if (defined($searchtitles->{$type})) {
4083: $chgtext .= $searchtitles->{$type}.'; ';
4084: }
4085: }
4086: }
4087: $chgtext =~ s/\; $//;
4088: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
4089: }
1.25 raeburn 4090: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
4091: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
4092: my $chgtext;
4093: foreach my $type (@{$srchtypeorder}) {
4094: if (grep(/^\Q$type\E$/,@searchtypes)) {
4095: if (defined($srchtypes_desc->{$type})) {
4096: $chgtext .= $srchtypes_desc->{$type}.'; ';
4097: }
4098: }
4099: }
4100: $chgtext =~ s/\; $//;
4101: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 4102: }
4103: $resulttext .= '</ul>';
4104: } else {
4105: $resulttext = &mt('No changes made to institution directory search settings');
4106: }
4107: } else {
4108: $resulttext = '<span class="LC_error">'.
1.27 raeburn 4109: &mt('An error occurred: [_1]',$putresult).'</span>';
4110: }
4111: return $resulttext;
4112: }
4113:
1.28 raeburn 4114: sub modify_contacts {
4115: my ($dom,%domconfig) = @_;
4116: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
4117: if (ref($domconfig{'contacts'}) eq 'HASH') {
4118: foreach my $key (keys(%{$domconfig{'contacts'}})) {
4119: $currsetting{$key} = $domconfig{'contacts'}{$key};
4120: }
4121: }
4122: my (%others,%to);
4123: my @contacts = ('supportemail','adminemail');
4124: my @mailings = ('errormail','packagesmail','helpdeskmail');
4125: foreach my $type (@mailings) {
4126: @{$newsetting{$type}} =
4127: &Apache::loncommon::get_env_multiple('form.'.$type);
4128: foreach my $item (@contacts) {
4129: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
4130: $contacts_hash{contacts}{$type}{$item} = 1;
4131: } else {
4132: $contacts_hash{contacts}{$type}{$item} = 0;
4133: }
4134: }
4135: $others{$type} = $env{'form.'.$type.'_others'};
4136: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
4137: }
4138: foreach my $item (@contacts) {
4139: $to{$item} = $env{'form.'.$item};
4140: $contacts_hash{'contacts'}{$item} = $to{$item};
4141: }
4142: if (keys(%currsetting) > 0) {
4143: foreach my $item (@contacts) {
4144: if ($to{$item} ne $currsetting{$item}) {
4145: $changes{$item} = 1;
4146: }
4147: }
4148: foreach my $type (@mailings) {
4149: foreach my $item (@contacts) {
4150: if (ref($currsetting{$type}) eq 'HASH') {
4151: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
4152: push(@{$changes{$type}},$item);
4153: }
4154: } else {
4155: push(@{$changes{$type}},@{$newsetting{$type}});
4156: }
4157: }
4158: if ($others{$type} ne $currsetting{$type}{'others'}) {
4159: push(@{$changes{$type}},'others');
4160: }
4161: }
4162: } else {
4163: my %default;
4164: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4165: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4166: $default{'errormail'} = 'adminemail';
4167: $default{'packagesmail'} = 'adminemail';
4168: $default{'helpdeskmail'} = 'supportemail';
4169: foreach my $item (@contacts) {
4170: if ($to{$item} ne $default{$item}) {
4171: $changes{$item} = 1;
4172: }
4173: }
4174: foreach my $type (@mailings) {
4175: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
4176:
4177: push(@{$changes{$type}},@{$newsetting{$type}});
4178: }
4179: if ($others{$type} ne '') {
4180: push(@{$changes{$type}},'others');
4181: }
4182: }
4183: }
4184: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
4185: $dom);
4186: if ($putresult eq 'ok') {
4187: if (keys(%changes) > 0) {
4188: my ($titles,$short_titles) = &contact_titles();
4189: $resulttext = &mt('Changes made:').'<ul>';
4190: foreach my $item (@contacts) {
4191: if ($changes{$item}) {
4192: $resulttext .= '<li>'.$titles->{$item}.
4193: &mt(' set to: ').
4194: '<span class="LC_cusr_emph">'.
4195: $to{$item}.'</span></li>';
4196: }
4197: }
4198: foreach my $type (@mailings) {
4199: if (ref($changes{$type}) eq 'ARRAY') {
4200: $resulttext .= '<li>'.$titles->{$type}.': ';
4201: my @text;
4202: foreach my $item (@{$newsetting{$type}}) {
4203: push(@text,$short_titles->{$item});
4204: }
4205: if ($others{$type} ne '') {
4206: push(@text,$others{$type});
4207: }
4208: $resulttext .= '<span class="LC_cusr_emph">'.
4209: join(', ',@text).'</span></li>';
4210: }
4211: }
4212: $resulttext .= '</ul>';
4213: } else {
1.34 raeburn 4214: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 4215: }
4216: } else {
4217: $resulttext = '<span class="LC_error">'.
4218: &mt('An error occurred: [_1].',$putresult).'</span>';
4219: }
4220: return $resulttext;
4221: }
4222:
4223: sub modify_usercreation {
1.27 raeburn 4224: my ($dom,%domconfig) = @_;
1.34 raeburn 4225: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 4226: my $warningmsg;
1.27 raeburn 4227: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4228: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
4229: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
4230: }
4231: }
4232: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 4233: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 4234: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.45 raeburn 4235: my @contexts = ('author','course','selfcreate');
1.34 raeburn 4236: foreach my $item(@contexts) {
1.45 raeburn 4237: if ($item eq 'selfcreate') {
1.50 raeburn 4238: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 4239: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4240: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 4241: if (ref($cancreate{$item}) eq 'ARRAY') {
4242: if (grep(/^login$/,@{$cancreate{$item}})) {
4243: $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.');
4244: }
1.43 raeburn 4245: }
4246: }
1.50 raeburn 4247: } else {
4248: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 4249: }
1.34 raeburn 4250: }
4251: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
4252: foreach my $item (@contexts) {
1.50 raeburn 4253: if ($item eq 'selfcreate') {
4254: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
4255: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
4256: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
4257: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4258: push(@{$changes{'cancreate'}},$item);
4259: }
4260: }
4261: }
4262: } else {
4263: if ($curr_usercreation{'cancreate'}{$item} eq '') {
4264: if (@{$cancreate{$item}} > 0) {
4265: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4266: push(@{$changes{'cancreate'}},$item);
4267: }
4268: }
4269: } else {
4270: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
4271: if (@{$cancreate{$item}} < 3) {
4272: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4273: push(@{$changes{'cancreate'}},$item);
4274: }
4275: }
4276: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
4277: if (@{$cancreate{$item}} > 0) {
4278: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4279: push(@{$changes{'cancreate'}},$item);
4280: }
4281: }
4282: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
4283: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4284: push(@{$changes{'cancreate'}},$item);
4285: }
4286: }
4287: }
4288: }
4289: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4290: foreach my $type (@{$cancreate{$item}}) {
4291: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
4292: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
4293: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4294: push(@{$changes{'cancreate'}},$item);
4295: }
4296: }
4297: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
4298: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
4299: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
4300: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4301: push(@{$changes{'cancreate'}},$item);
4302: }
4303: }
4304: }
4305: }
4306: }
4307: } else {
4308: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
4309: push(@{$changes{'cancreate'}},$item);
4310: }
4311: }
1.27 raeburn 4312: }
1.34 raeburn 4313: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
4314: foreach my $item (@contexts) {
1.43 raeburn 4315: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 4316: if ($cancreate{$item} ne 'any') {
4317: push(@{$changes{'cancreate'}},$item);
4318: }
4319: } else {
4320: if ($cancreate{$item} ne 'none') {
4321: push(@{$changes{'cancreate'}},$item);
4322: }
1.27 raeburn 4323: }
4324: }
4325: } else {
1.43 raeburn 4326: foreach my $item (@contexts) {
1.34 raeburn 4327: push(@{$changes{'cancreate'}},$item);
4328: }
1.27 raeburn 4329: }
1.34 raeburn 4330:
1.27 raeburn 4331: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
4332: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
4333: if (!grep(/^\Q$type\E$/,@username_rule)) {
4334: push(@{$changes{'username_rule'}},$type);
4335: }
4336: }
4337: foreach my $type (@username_rule) {
4338: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
4339: push(@{$changes{'username_rule'}},$type);
4340: }
4341: }
4342: } else {
4343: push(@{$changes{'username_rule'}},@username_rule);
4344: }
4345:
1.32 raeburn 4346: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
4347: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
4348: if (!grep(/^\Q$type\E$/,@id_rule)) {
4349: push(@{$changes{'id_rule'}},$type);
4350: }
4351: }
4352: foreach my $type (@id_rule) {
4353: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
4354: push(@{$changes{'id_rule'}},$type);
4355: }
4356: }
4357: } else {
4358: push(@{$changes{'id_rule'}},@id_rule);
4359: }
4360:
1.43 raeburn 4361: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
4362: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
4363: if (!grep(/^\Q$type\E$/,@email_rule)) {
4364: push(@{$changes{'email_rule'}},$type);
4365: }
4366: }
4367: foreach my $type (@email_rule) {
4368: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
4369: push(@{$changes{'email_rule'}},$type);
4370: }
4371: }
4372: } else {
4373: push(@{$changes{'email_rule'}},@email_rule);
4374: }
4375:
4376: my @authen_contexts = ('author','course','domain');
1.28 raeburn 4377: my @authtypes = ('int','krb4','krb5','loc');
4378: my %authhash;
1.43 raeburn 4379: foreach my $item (@authen_contexts) {
1.28 raeburn 4380: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
4381: foreach my $auth (@authtypes) {
4382: if (grep(/^\Q$auth\E$/,@authallowed)) {
4383: $authhash{$item}{$auth} = 1;
4384: } else {
4385: $authhash{$item}{$auth} = 0;
4386: }
4387: }
4388: }
4389: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 4390: foreach my $item (@authen_contexts) {
1.28 raeburn 4391: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
4392: foreach my $auth (@authtypes) {
4393: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
4394: push(@{$changes{'authtypes'}},$item);
4395: last;
4396: }
4397: }
4398: }
4399: }
4400: } else {
1.43 raeburn 4401: foreach my $item (@authen_contexts) {
1.28 raeburn 4402: push(@{$changes{'authtypes'}},$item);
4403: }
4404: }
4405:
1.27 raeburn 4406: my %usercreation_hash = (
1.28 raeburn 4407: usercreation => {
1.34 raeburn 4408: cancreate => \%cancreate,
1.27 raeburn 4409: username_rule => \@username_rule,
1.32 raeburn 4410: id_rule => \@id_rule,
1.43 raeburn 4411: email_rule => \@email_rule,
1.32 raeburn 4412: authtypes => \%authhash,
1.27 raeburn 4413: }
4414: );
4415:
4416: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
4417: $dom);
1.50 raeburn 4418:
4419: my %selfcreatetypes = (
4420: sso => 'users authenticated by institutional single sign on',
4421: login => 'users authenticated by institutional log-in',
4422: email => 'users who provide a valid e-mail address for use as the username',
4423: );
1.27 raeburn 4424: if ($putresult eq 'ok') {
4425: if (keys(%changes) > 0) {
4426: $resulttext = &mt('Changes made:').'<ul>';
4427: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 4428: my %lt = &usercreation_types();
4429: foreach my $type (@{$changes{'cancreate'}}) {
1.43 raeburn 4430: my $chgtext = $lt{$type}.', ';
1.45 raeburn 4431: if ($type eq 'selfcreate') {
1.50 raeburn 4432: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 4433: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 4434: } else {
4435: $chgtext .= &mt('creation of a new account is permitted for:<ul>');
4436: foreach my $case (@{$cancreate{$type}}) {
4437: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
4438: }
4439: $chgtext .= '</ul>';
1.43 raeburn 4440: }
4441: } else {
4442: if ($cancreate{$type} eq 'none') {
4443: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
4444: } elsif ($cancreate{$type} eq 'any') {
4445: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
4446: } elsif ($cancreate{$type} eq 'official') {
4447: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
4448: } elsif ($cancreate{$type} eq 'unofficial') {
4449: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
4450: }
1.34 raeburn 4451: }
4452: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 4453: }
4454: }
4455: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 4456: my ($rules,$ruleorder) =
4457: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 4458: my $chgtext = '<ul>';
4459: foreach my $type (@username_rule) {
4460: if (ref($rules->{$type}) eq 'HASH') {
4461: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
4462: }
4463: }
4464: $chgtext .= '</ul>';
4465: if (@username_rule > 0) {
4466: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4467: } else {
1.28 raeburn 4468: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 4469: }
4470: }
1.32 raeburn 4471: if (ref($changes{'id_rule'}) eq 'ARRAY') {
4472: my ($idrules,$idruleorder) =
4473: &Apache::lonnet::inst_userrules($dom,'id');
4474: my $chgtext = '<ul>';
4475: foreach my $type (@id_rule) {
4476: if (ref($idrules->{$type}) eq 'HASH') {
4477: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
4478: }
4479: }
4480: $chgtext .= '</ul>';
4481: if (@id_rule > 0) {
4482: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4483: } else {
4484: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
4485: }
4486: }
1.43 raeburn 4487: if (ref($changes{'email_rule'}) eq 'ARRAY') {
4488: my ($emailrules,$emailruleorder) =
4489: &Apache::lonnet::inst_userrules($dom,'email');
4490: my $chgtext = '<ul>';
4491: foreach my $type (@email_rule) {
4492: if (ref($emailrules->{$type}) eq 'HASH') {
4493: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
4494: }
4495: }
4496: $chgtext .= '</ul>';
4497: if (@email_rule > 0) {
4498: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
4499: } else {
4500: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
4501: }
4502: }
4503:
1.28 raeburn 4504: my %authname = &authtype_names();
4505: my %context_title = &context_names();
4506: if (ref($changes{'authtypes'}) eq 'ARRAY') {
4507: my $chgtext = '<ul>';
4508: foreach my $type (@{$changes{'authtypes'}}) {
4509: my @allowed;
4510: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
4511: foreach my $auth (@authtypes) {
4512: if ($authhash{$type}{$auth}) {
4513: push(@allowed,$authname{$auth});
4514: }
4515: }
1.43 raeburn 4516: if (@allowed > 0) {
4517: $chgtext .= join(', ',@allowed).'</li>';
4518: } else {
4519: $chgtext .= &mt('none').'</li>';
4520: }
1.28 raeburn 4521: }
4522: $chgtext .= '</ul>';
4523: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
4524: $resulttext .= '</li>';
4525: }
1.27 raeburn 4526: $resulttext .= '</ul>';
4527: } else {
1.28 raeburn 4528: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 4529: }
4530: } else {
4531: $resulttext = '<span class="LC_error">'.
1.23 raeburn 4532: &mt('An error occurred: [_1]',$putresult).'</span>';
4533: }
1.43 raeburn 4534: if ($warningmsg ne '') {
4535: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
4536: }
1.23 raeburn 4537: return $resulttext;
4538: }
4539:
1.33 raeburn 4540: sub modify_usermodification {
4541: my ($dom,%domconfig) = @_;
4542: my ($resulttext,%curr_usermodification,%changes);
4543: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4544: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
4545: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
4546: }
4547: }
1.63 raeburn 4548: my @contexts = ('author','course','selfcreate');
1.33 raeburn 4549: my %context_title = (
4550: author => 'In author context',
4551: course => 'In course context',
1.63 raeburn 4552: selfcreate => 'When self creating account',
1.33 raeburn 4553: );
4554: my @fields = ('lastname','firstname','middlename','generation',
4555: 'permanentemail','id');
4556: my %roles = (
4557: author => ['ca','aa'],
4558: course => ['st','ep','ta','in','cr'],
4559: );
1.63 raeburn 4560: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4561: if (ref($types) eq 'ARRAY') {
4562: push(@{$types},'default');
4563: $usertypes->{'default'} = $othertitle;
4564: }
4565: $roles{'selfcreate'} = $types;
1.33 raeburn 4566: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4567: my %modifyhash;
4568: foreach my $context (@contexts) {
4569: foreach my $role (@{$roles{$context}}) {
4570: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
4571: foreach my $item (@fields) {
4572: if (grep(/^\Q$item\E$/,@modifiable)) {
4573: $modifyhash{$context}{$role}{$item} = 1;
4574: } else {
4575: $modifyhash{$context}{$role}{$item} = 0;
4576: }
4577: }
4578: }
4579: if (ref($curr_usermodification{$context}) eq 'HASH') {
4580: foreach my $role (@{$roles{$context}}) {
4581: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
4582: foreach my $field (@fields) {
4583: if ($modifyhash{$context}{$role}{$field} ne
4584: $curr_usermodification{$context}{$role}{$field}) {
4585: push(@{$changes{$context}},$role);
4586: last;
4587: }
4588: }
4589: }
4590: }
4591: } else {
4592: foreach my $context (@contexts) {
4593: foreach my $role (@{$roles{$context}}) {
4594: push(@{$changes{$context}},$role);
4595: }
4596: }
4597: }
4598: }
4599: my %usermodification_hash = (
4600: usermodification => \%modifyhash,
4601: );
4602: my $putresult = &Apache::lonnet::put_dom('configuration',
4603: \%usermodification_hash,$dom);
4604: if ($putresult eq 'ok') {
4605: if (keys(%changes) > 0) {
4606: $resulttext = &mt('Changes made: ').'<ul>';
4607: foreach my $context (@contexts) {
4608: if (ref($changes{$context}) eq 'ARRAY') {
4609: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
4610: if (ref($changes{$context}) eq 'ARRAY') {
4611: foreach my $role (@{$changes{$context}}) {
4612: my $rolename;
1.63 raeburn 4613: if ($context eq 'selfcreate') {
4614: $rolename = $role;
4615: if (ref($usertypes) eq 'HASH') {
4616: if ($usertypes->{$role} ne '') {
4617: $rolename = $usertypes->{$role};
4618: }
4619: }
1.33 raeburn 4620: } else {
1.63 raeburn 4621: if ($role eq 'cr') {
4622: $rolename = &mt('Custom');
4623: } else {
4624: $rolename = &Apache::lonnet::plaintext($role);
4625: }
1.33 raeburn 4626: }
4627: my @modifiable;
1.63 raeburn 4628: if ($context eq 'selfcreate') {
4629: $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): ');
4630: } else {
4631: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
4632: }
1.33 raeburn 4633: foreach my $field (@fields) {
4634: if ($modifyhash{$context}{$role}{$field}) {
4635: push(@modifiable,$fieldtitles{$field});
4636: }
4637: }
4638: if (@modifiable > 0) {
4639: $resulttext .= join(', ',@modifiable);
4640: } else {
4641: $resulttext .= &mt('none');
4642: }
4643: $resulttext .= '</li>';
4644: }
4645: $resulttext .= '</ul></li>';
4646: }
4647: }
4648: }
4649: $resulttext .= '</ul>';
4650: } else {
4651: $resulttext = &mt('No changes made to user modification settings');
4652: }
4653: } else {
4654: $resulttext = '<span class="LC_error">'.
4655: &mt('An error occurred: [_1]',$putresult).'</span>';
4656: }
4657: return $resulttext;
4658: }
4659:
1.43 raeburn 4660: sub modify_defaults {
4661: my ($dom,$r) = @_;
4662: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
4663: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.68 raeburn 4664: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
1.43 raeburn 4665: my @authtypes = ('internal','krb4','krb5','localauth');
4666: foreach my $item (@items) {
4667: $newvalues{$item} = $env{'form.'.$item};
4668: if ($item eq 'auth_def') {
4669: if ($newvalues{$item} ne '') {
4670: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
4671: push(@errors,$item);
4672: }
4673: }
4674: } elsif ($item eq 'lang_def') {
4675: if ($newvalues{$item} ne '') {
4676: if ($newvalues{$item} =~ /^(\w+)/) {
4677: my $langcode = $1;
4678: if (code2language($langcode) eq '') {
4679: push(@errors,$item);
4680: }
4681: } else {
4682: push(@errors,$item);
4683: }
4684: }
1.54 raeburn 4685: } elsif ($item eq 'timezone_def') {
4686: if ($newvalues{$item} ne '') {
1.62 raeburn 4687: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 4688: push(@errors,$item);
4689: }
4690: }
1.68 raeburn 4691: } elsif ($item eq 'datelocale_def') {
4692: if ($newvalues{$item} ne '') {
4693: my @datelocale_ids = DateTime::Locale->ids();
4694: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
4695: push(@errors,$item);
4696: }
4697: }
1.43 raeburn 4698: }
4699: if (grep(/^\Q$item\E$/,@errors)) {
4700: $newvalues{$item} = $domdefaults{$item};
4701: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
4702: $changes{$item} = 1;
4703: }
1.72 raeburn 4704: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 4705: }
4706: my %defaults_hash = (
1.72 raeburn 4707: defaults => \%newvalues,
4708: );
1.43 raeburn 4709: my $title = &defaults_titles();
4710: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
4711: $dom);
4712: if ($putresult eq 'ok') {
4713: if (keys(%changes) > 0) {
4714: $resulttext = &mt('Changes made:').'<ul>';
4715: my $version = $r->dir_config('lonVersion');
4716: 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";
4717: foreach my $item (sort(keys(%changes))) {
4718: my $value = $env{'form.'.$item};
4719: if ($value eq '') {
4720: $value = &mt('none');
4721: } elsif ($item eq 'auth_def') {
4722: my %authnames = &authtype_names();
4723: my %shortauth = (
4724: internal => 'int',
4725: krb4 => 'krb4',
4726: krb5 => 'krb5',
4727: localauth => 'loc',
4728: );
4729: $value = $authnames{$shortauth{$value}};
4730: }
4731: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
4732: $mailmsgtext .= "$title->{$item} set to $value\n";
4733: }
4734: $resulttext .= '</ul>';
4735: $mailmsgtext .= "\n";
4736: my $cachetime = 24*60*60;
1.72 raeburn 4737: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 4738: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 4739: my $sysmail = $r->dir_config('lonSysEMail');
4740: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
4741: }
1.43 raeburn 4742: } else {
1.54 raeburn 4743: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 4744: }
4745: } else {
4746: $resulttext = '<span class="LC_error">'.
4747: &mt('An error occurred: [_1]',$putresult).'</span>';
4748: }
4749: if (@errors > 0) {
4750: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
4751: foreach my $item (@errors) {
4752: $resulttext .= ' "'.$title->{$item}.'",';
4753: }
4754: $resulttext =~ s/,$//;
4755: }
4756: return $resulttext;
4757: }
4758:
1.46 raeburn 4759: sub modify_scantron {
1.48 raeburn 4760: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 4761: my ($resulttext,%confhash,%changes,$errors);
4762: my $custom = 'custom.tab';
4763: my $default = 'default.tab';
4764: my $servadm = $r->dir_config('lonAdmEMail');
4765: my ($configuserok,$author_ok,$switchserver) =
4766: &config_check($dom,$confname,$servadm);
4767: if ($env{'form.scantronformat.filename'} ne '') {
4768: my $error;
4769: if ($configuserok eq 'ok') {
4770: if ($switchserver) {
4771: $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
4772: } else {
4773: if ($author_ok eq 'ok') {
4774: my ($result,$scantronurl) =
4775: &publishlogo($r,'upload','scantronformat',$dom,
4776: $confname,'scantron','','',$custom);
4777: if ($result eq 'ok') {
4778: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 4779: $changes{'scantronformat'} = 1;
1.46 raeburn 4780: } else {
4781: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
4782: }
4783: } else {
4784: $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);
4785: }
4786: }
4787: } else {
4788: $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);
4789: }
4790: if ($error) {
4791: &Apache::lonnet::logthis($error);
4792: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4793: }
4794: }
1.48 raeburn 4795: if (ref($domconfig{'scantron'}) eq 'HASH') {
4796: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
4797: if ($env{'form.scantronformat_del'}) {
4798: $confhash{'scantron'}{'scantronformat'} = '';
4799: $changes{'scantronformat'} = 1;
1.46 raeburn 4800: }
4801: }
4802: }
4803: if (keys(%confhash) > 0) {
4804: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
4805: $dom);
4806: if ($putresult eq 'ok') {
4807: if (keys(%changes) > 0) {
1.48 raeburn 4808: if (ref($confhash{'scantron'}) eq 'HASH') {
4809: $resulttext = &mt('Changes made:').'<ul>';
4810: if ($confhash{'scantron'}{'scantronformat'} eq '') {
4811: $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
4812: } else {
4813: $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 4814: }
1.48 raeburn 4815: $resulttext .= '</ul>';
4816: } else {
4817: $resulttext = &mt('Changes made to scantron format file.');
1.46 raeburn 4818: }
4819: $resulttext .= '</ul>';
4820: &Apache::loncommon::devalidate_domconfig_cache($dom);
4821: } else {
4822: $resulttext = &mt('No changes made to scantron format file');
4823: }
4824: } else {
4825: $resulttext = '<span class="LC_error">'.
4826: &mt('An error occurred: [_1]',$putresult).'</span>';
4827: }
4828: } else {
4829: $resulttext = &mt('No changes made to scantron format file');
4830: }
4831: if ($errors) {
4832: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4833: $errors.'</ul>';
4834: }
4835: return $resulttext;
4836: }
4837:
1.48 raeburn 4838: sub modify_coursecategories {
4839: my ($dom,%domconfig) = @_;
1.57 raeburn 4840: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
4841: $cathash);
1.48 raeburn 4842: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 4843: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 4844: $cathash = $domconfig{'coursecategories'}{'cats'};
4845: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
4846: $changes{'togglecats'} = 1;
4847: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
4848: }
4849: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
4850: $changes{'categorize'} = 1;
4851: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
4852: }
4853: } else {
4854: $changes{'togglecats'} = 1;
4855: $changes{'categorize'} = 1;
1.87 raeburn 4856: $domconfig{'coursecategories'} = {
4857: togglecats => $env{'form.togglecats'},
4858: categorize => $env{'form.categorize'},
4859: };
1.57 raeburn 4860: }
4861: if (ref($cathash) eq 'HASH') {
4862: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 4863: push (@deletecategory,'instcode::0');
4864: }
1.48 raeburn 4865: }
1.57 raeburn 4866: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
4867: if (ref($cathash) eq 'HASH') {
1.48 raeburn 4868: if (@deletecategory > 0) {
4869: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 4870: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 4871: foreach my $item (@deletecategory) {
1.57 raeburn 4872: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
4873: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 4874: $deletions{$item} = 1;
1.57 raeburn 4875: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 4876: }
4877: }
4878: }
1.57 raeburn 4879: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 4880: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 4881: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 4882: $reorderings{$item} = 1;
1.57 raeburn 4883: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 4884: }
4885: if ($env{'form.addcategory_name_'.$item} ne '') {
4886: my $newcat = $env{'form.addcategory_name_'.$item};
4887: my $newdepth = $depth+1;
4888: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 4889: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 4890: $adds{$newitem} = 1;
4891: }
4892: if ($env{'form.subcat_'.$item} ne '') {
4893: my $newcat = $env{'form.subcat_'.$item};
4894: my $newdepth = $depth+1;
4895: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 4896: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 4897: $adds{$newitem} = 1;
4898: }
4899: }
4900: }
4901: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 4902: if (ref($cathash) eq 'HASH') {
1.48 raeburn 4903: my $newitem = 'instcode::0';
1.57 raeburn 4904: if ($cathash->{$newitem} eq '') {
4905: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 4906: $adds{$newitem} = 1;
4907: }
4908: } else {
4909: my $newitem = 'instcode::0';
1.57 raeburn 4910: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 4911: $adds{$newitem} = 1;
4912: }
4913: }
4914: if ($env{'form.addcategory_name'} ne '') {
4915: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
1.57 raeburn 4916: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
1.48 raeburn 4917: $adds{$newitem} = 1;
4918: }
1.57 raeburn 4919: my $putresult;
1.48 raeburn 4920: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4921: if (keys(%deletions) > 0) {
4922: foreach my $key (keys(%deletions)) {
4923: if ($predelallitems{$key} ne '') {
4924: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
4925: }
4926: }
4927: }
4928: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 4929: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 4930: if (ref($chkcats[0]) eq 'ARRAY') {
4931: my $depth = 0;
4932: my $chg = 0;
4933: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
4934: my $name = $chkcats[0][$i];
4935: my $item;
4936: if ($name eq '') {
4937: $chg ++;
4938: } else {
4939: $item = &escape($name).'::0';
4940: if ($chg) {
1.57 raeburn 4941: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 4942: }
4943: $depth ++;
1.57 raeburn 4944: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 4945: $depth --;
4946: }
4947: }
4948: }
1.57 raeburn 4949: }
4950: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4951: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 4952: if ($putresult eq 'ok') {
1.57 raeburn 4953: my %title = (
4954: togglecats => 'Show/Hide a course in the catalog',
4955: categorize => 'Category assigned to course',
4956: );
4957: my %level = (
4958: dom => 'set from "Modify Course" (Domain)',
4959: crs => 'set from "Parameters" (Course)',
4960: );
1.48 raeburn 4961: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 4962: if ($changes{'togglecats'}) {
4963: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
4964: }
4965: if ($changes{'categorize'}) {
4966: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 4967: }
1.57 raeburn 4968: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4969: my $cathash;
4970: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
4971: $cathash = $domconfig{'coursecategories'}{'cats'};
4972: } else {
4973: $cathash = {};
4974: }
4975: my (@cats,@trails,%allitems);
4976: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
4977: if (keys(%deletions) > 0) {
4978: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
4979: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
4980: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
4981: }
4982: $resulttext .= '</ul></li>';
4983: }
4984: if (keys(%reorderings) > 0) {
4985: my %sort_by_trail;
4986: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
4987: foreach my $key (keys(%reorderings)) {
4988: if ($allitems{$key} ne '') {
4989: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
4990: }
1.48 raeburn 4991: }
1.57 raeburn 4992: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
4993: $resulttext .= '<li>'.$trails[$trail].'</li>';
4994: }
4995: $resulttext .= '</ul></li>';
1.48 raeburn 4996: }
1.57 raeburn 4997: if (keys(%adds) > 0) {
4998: my %sort_by_trail;
4999: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
5000: foreach my $key (keys(%adds)) {
5001: if ($allitems{$key} ne '') {
5002: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
5003: }
5004: }
5005: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
5006: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 5007: }
1.57 raeburn 5008: $resulttext .= '</ul></li>';
1.48 raeburn 5009: }
5010: }
5011: $resulttext .= '</ul>';
5012: } else {
5013: $resulttext = '<span class="LC_error">'.
1.57 raeburn 5014: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 5015: }
5016: } else {
5017: $resulttext = &mt('No changes made to course categories');
5018: }
5019: return $resulttext;
5020: }
5021:
1.69 raeburn 5022: sub modify_serverstatuses {
5023: my ($dom,%domconfig) = @_;
5024: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
5025: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
5026: %currserverstatus = %{$domconfig{'serverstatuses'}};
5027: }
5028: my @pages = &serverstatus_pages();
5029: foreach my $type (@pages) {
5030: $newserverstatus{$type}{'namedusers'} = '';
5031: $newserverstatus{$type}{'machines'} = '';
5032: if (defined($env{'form.'.$type.'_namedusers'})) {
5033: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
5034: my @okusers;
5035: foreach my $user (@users) {
5036: my ($uname,$udom) = split(/:/,$user);
5037: if (($udom =~ /^$match_domain$/) &&
5038: (&Apache::lonnet::domain($udom)) &&
5039: ($uname =~ /^$match_username$/)) {
5040: if (!grep(/^\Q$user\E/,@okusers)) {
5041: push(@okusers,$user);
5042: }
5043: }
5044: }
5045: if (@okusers > 0) {
5046: @okusers = sort(@okusers);
5047: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
5048: }
5049: }
5050: if (defined($env{'form.'.$type.'_machines'})) {
5051: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
5052: my @okmachines;
5053: foreach my $ip (@machines) {
5054: my @parts = split(/\./,$ip);
5055: next if (@parts < 4);
5056: my $badip = 0;
5057: for (my $i=0; $i<4; $i++) {
5058: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
5059: $badip = 1;
5060: last;
5061: }
5062: }
5063: if (!$badip) {
5064: push(@okmachines,$ip);
5065: }
5066: }
5067: @okmachines = sort(@okmachines);
5068: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
5069: }
5070: }
5071: my %serverstatushash = (
5072: serverstatuses => \%newserverstatus,
5073: );
5074: my %changes;
5075: foreach my $type (@pages) {
1.83 raeburn 5076: foreach my $setting ('namedusers','machines') {
1.84 raeburn 5077: my (@current,@new);
1.83 raeburn 5078: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 5079: if ($currserverstatus{$type}{$setting} ne '') {
5080: @current = split(/,/,$currserverstatus{$type}{$setting});
5081: }
5082: }
5083: if ($newserverstatus{$type}{$setting} ne '') {
5084: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 5085: }
5086: if (@current > 0) {
5087: if (@new > 0) {
5088: foreach my $item (@current) {
5089: if (!grep(/^\Q$item\E$/,@new)) {
5090: $changes{$type}{$setting} = 1;
1.82 raeburn 5091: last;
5092: }
5093: }
1.84 raeburn 5094: foreach my $item (@new) {
5095: if (!grep(/^\Q$item\E$/,@current)) {
5096: $changes{$type}{$setting} = 1;
5097: last;
1.82 raeburn 5098: }
5099: }
5100: } else {
1.83 raeburn 5101: $changes{$type}{$setting} = 1;
1.69 raeburn 5102: }
1.83 raeburn 5103: } elsif (@new > 0) {
5104: $changes{$type}{$setting} = 1;
1.69 raeburn 5105: }
5106: }
5107: }
5108: if (keys(%changes) > 0) {
1.81 raeburn 5109: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5110: my $putresult = &Apache::lonnet::put_dom('configuration',
5111: \%serverstatushash,$dom);
5112: if ($putresult eq 'ok') {
5113: $resulttext .= &mt('Changes made:').'<ul>';
5114: foreach my $type (@pages) {
1.84 raeburn 5115: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 5116: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 5117: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 5118: if ($newserverstatus{$type}{'namedusers'} eq '') {
5119: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
5120: } else {
5121: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
5122: }
1.84 raeburn 5123: }
5124: if ($changes{$type}{'machines'}) {
1.69 raeburn 5125: if ($newserverstatus{$type}{'machines'} eq '') {
5126: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
5127: } else {
5128: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
5129: }
5130:
5131: }
5132: $resulttext .= '</ul></li>';
5133: }
5134: }
5135: $resulttext .= '</ul>';
5136: } else {
5137: $resulttext = '<span class="LC_error">'.
5138: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
5139:
5140: }
5141: } else {
5142: $resulttext = &mt('No changes made to access to server status pages');
5143: }
5144: return $resulttext;
5145: }
5146:
1.48 raeburn 5147: sub recurse_check {
5148: my ($chkcats,$categories,$depth,$name) = @_;
5149: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
5150: my $chg = 0;
5151: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
5152: my $category = $chkcats->[$depth]{$name}[$j];
5153: my $item;
5154: if ($category eq '') {
5155: $chg ++;
5156: } else {
5157: my $deeper = $depth + 1;
5158: $item = &escape($category).':'.&escape($name).':'.$depth;
5159: if ($chg) {
5160: $categories->{$item} -= $chg;
5161: }
5162: &recurse_check($chkcats,$categories,$deeper,$category);
5163: $deeper --;
5164: }
5165: }
5166: }
5167: return;
5168: }
5169:
5170: sub recurse_cat_deletes {
5171: my ($item,$coursecategories,$deletions) = @_;
5172: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
5173: my $subdepth = $depth + 1;
5174: if (ref($coursecategories) eq 'HASH') {
5175: foreach my $subitem (keys(%{$coursecategories})) {
5176: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
5177: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
5178: delete($coursecategories->{$subitem});
5179: $deletions->{$subitem} = 1;
5180: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
5181: }
5182: }
5183: }
5184: return;
5185: }
5186:
1.3 raeburn 5187: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>