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