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