Annotation of loncom/interface/domainprefs.pm, revision 1.61
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.61 ! raeburn 4: # $Id: domainprefs.pm,v 1.60 2008/07/06 22:14:46 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;
1.60 raeburn 1850: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
1851: %confhash);
1.46 raeburn 1852: my $switchserver = &check_switchserver($dom,$confname);
1853: my %lt = &Apache::lonlocal::texthash (
1854: default => 'Default scantron format file error',
1855: custom => 'Custom scantron format file error',
1856: );
1857: my %scantronfiles = (
1858: default => 'default.tab',
1859: custom => 'custom.tab',
1860: );
1861: foreach my $key (keys(%scantronfiles)) {
1862: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
1863: .$scantronfiles{$key};
1864: }
1865: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
1866: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
1867: if (!$switchserver) {
1868: my $servadm = $r->dir_config('lonAdmEMail');
1869: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
1870: if ($configuserok eq 'ok') {
1871: if ($author_ok eq 'ok') {
1872: my %legacyfile = (
1873: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
1874: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1875: );
1876: my %md5chk;
1877: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 1878: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
1879: chomp($md5chk{$type});
1.46 raeburn 1880: }
1881: if ($md5chk{'default'} ne $md5chk{'custom'}) {
1882: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 1883: ($scantronurls{$type},my $error) =
1.46 raeburn 1884: &legacy_scantronformat($r,$dom,$confname,
1885: $type,$legacyfile{$type},
1886: $scantronurls{$type},
1887: $scantronfiles{$type});
1.60 raeburn 1888: if ($error ne '') {
1889: $error{$type} = $error;
1890: }
1891: }
1892: if (keys(%error) == 0) {
1893: $is_custom = 1;
1894: $confhash{'scantron'}{'scantronformat'} =
1895: $scantronurls{'custom'};
1896: my $putresult =
1897: &Apache::lonnet::put_dom('configuration',
1898: \%confhash,$dom);
1899: if ($putresult ne 'ok') {
1900: $error{'custom'} =
1901: '<span class="LC_error">'.
1902: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
1903: }
1.46 raeburn 1904: }
1905: } else {
1.60 raeburn 1906: ($scantronurls{'default'},my $error) =
1.46 raeburn 1907: &legacy_scantronformat($r,$dom,$confname,
1908: 'default',$legacyfile{'default'},
1909: $scantronurls{'default'},
1910: $scantronfiles{'default'});
1.60 raeburn 1911: if ($error eq '') {
1912: $confhash{'scantron'}{'scantronformat'} = '';
1913: my $putresult =
1914: &Apache::lonnet::put_dom('configuration',
1915: \%confhash,$dom);
1916: if ($putresult ne 'ok') {
1917: $error{'default'} =
1918: '<span class="LC_error">'.
1919: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
1920: }
1921: } else {
1922: $error{'default'} = $error;
1923: }
1.46 raeburn 1924: }
1925: }
1926: }
1927: } else {
1928: $error{'default'} = &mt("Unable to copy default scantron formatfile to domain's RES space: [_1]",$switchserver);
1929: }
1930: }
1931: if (ref($settings) eq 'HASH') {
1932: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
1933: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
1934: if ((!@info) || ($info[0] eq 'no_such_dir')) {
1935: $scantronurl = '';
1936: } else {
1937: $scantronurl = $settings->{'scantronformat'};
1938: }
1939: $is_custom = 1;
1940: } else {
1941: $scantronurl = $scantronurls{'default'};
1942: }
1943: } else {
1.60 raeburn 1944: if ($is_custom) {
1945: $scantronurl = $scantronurls{'custom'};
1946: } else {
1947: $scantronurl = $scantronurls{'default'};
1948: }
1.46 raeburn 1949: }
1950: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1951: $datatable .= '<tr'.$css_class.'>';
1952: if (!$is_custom) {
1953: $datatable .= '<td>'.&mt('Default in use:').'<br />';
1954: if ($scantronurl) {
1955: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1956: &mt('Default scantron format file').'</a>';
1957: } else {
1958: $datatable = &mt('File unavailable for display');
1959: }
1.60 raeburn 1960: $datatable .= '</td>';
1961: if (keys(%error) == 0) {
1962: $datatable .= '<td valign="bottom">';
1963: if (!$switchserver) {
1964: $datatable .= &mt('Upload:').'<br />';
1965: }
1966: } else {
1967: my $errorstr;
1968: foreach my $key (sort(keys(%error))) {
1969: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
1970: }
1971: $datatable .= '<td>'.$errorstr;
1972: }
1.46 raeburn 1973: } else {
1974: if (keys(%error) > 0) {
1975: my $errorstr;
1976: foreach my $key (sort(keys(%error))) {
1977: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
1978: }
1.60 raeburn 1979: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 1980: } elsif ($scantronurl) {
1.61 ! raeburn 1981: $datatable .= '<td><a href="'.$scantronurl.'" target="_blank">'
! 1982: .&mt('Custom scantron format file').'</a>'
1.46 raeburn 1983: .'<span class="LC_nobreak"><label>'
1984: .'<input type="checkbox" name="scantronformat_del"'
1985: .'" value="1" />'.&mt('Delete?').'</label></td>'
1986: .'<td>'.&mt('Replace:').'</span><br />';
1987: }
1988: }
1989: if (keys(%error) == 0) {
1990: if ($switchserver) {
1991: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1992: } else {
1993: $datatable .=' <input type="file" name="scantronformat" />';
1994: }
1995: }
1996: $datatable .= '</td></tr>';
1997: $$rowtotal ++;
1998: return $datatable;
1999: }
2000:
2001: sub legacy_scantronformat {
2002: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
2003: my ($url,$error);
2004: my @statinfo = &Apache::lonnet::stat_file($newurl);
2005: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
2006: (my $result,$url) =
2007: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
2008: '','',$newfile);
2009: if ($result ne 'ok') {
2010: $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
2011: }
2012: }
2013: return ($url,$error);
2014: }
1.43 raeburn 2015:
1.49 raeburn 2016: sub print_coursecategories {
1.57 raeburn 2017: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
2018: my $datatable;
2019: if ($position eq 'top') {
2020: my $toggle_cats_crs = ' ';
2021: my $toggle_cats_dom = ' checked="checked" ';
2022: my $can_cat_crs = ' ';
2023: my $can_cat_dom = ' checked="checked" ';
2024: if (ref($settings) eq 'HASH') {
2025: if ($settings->{'togglecats'} eq 'crs') {
2026: $toggle_cats_crs = $toggle_cats_dom;
2027: $toggle_cats_dom = ' ';
2028: }
2029: if ($settings->{'categorize'} eq 'crs') {
2030: $can_cat_crs = $can_cat_dom;
2031: $can_cat_dom = ' ';
2032: }
2033: }
2034: my %title = &Apache::lonlocal::texthash (
2035: togglecats => 'Show/Hide a course in the catalog',
2036: categorize => 'Assign a category to a course',
2037: );
2038: my %level = &Apache::lonlocal::texthash (
2039: dom => 'Set in "Modify Course" (Domain)',
1.60 raeburn 2040: crs => 'Set in "Modify Parameters" (Course)',
1.57 raeburn 2041: );
2042: $datatable = '<tr class="LC_odd_row">'.
2043: '<td>'.$title{'togglecats'}.'</td>'.
2044: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2045: '<input type="radio" name="togglecats"'.
2046: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2047: '<label><input type="radio" name="togglecats"'.
2048: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
2049: '</tr><tr>'.
2050: '<td>'.$title{'categorize'}.'</td>'.
2051: '<td class="LC_right_item"><span class="LC_nobreak">'.
2052: '<label><input type="radio" name="categorize"'.
2053: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2054: '<label><input type="radio" name="categorize"'.
2055: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
2056: '</tr>';
2057: $$rowtotal += 2;
2058: } else {
2059: my $css_class;
2060: my $itemcount = 1;
2061: my $cathash;
2062: if (ref($settings) eq 'HASH') {
2063: $cathash = $settings->{'cats'};
2064: }
2065: if (ref($cathash) eq 'HASH') {
2066: my (@cats,@trails,%allitems,%idx,@jsarray);
2067: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
2068: \%allitems,\%idx,\@jsarray);
2069: my $maxdepth = scalar(@cats);
2070: my $colattrib = '';
2071: if ($maxdepth > 2) {
2072: $colattrib = ' colspan="2" ';
2073: }
2074: my @path;
2075: if (@cats > 0) {
2076: if (ref($cats[0]) eq 'ARRAY') {
2077: my $numtop = @{$cats[0]};
2078: my $maxnum = $numtop;
2079: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2080: $maxnum ++;
2081: }
2082: my $lastidx;
2083: for (my $i=0; $i<$numtop; $i++) {
2084: my $parent = $cats[0][$i];
2085: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2086: my $item = &escape($parent).'::0';
2087: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
2088: $lastidx = $idx{$item};
2089: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2090: .'<select name="'.$item.'"'.$chgstr.'>';
2091: for (my $k=0; $k<=$maxnum; $k++) {
2092: my $vpos = $k+1;
2093: my $selstr;
2094: if ($k == $i) {
2095: $selstr = ' selected="selected" ';
2096: }
2097: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2098: }
2099: $datatable .= '</select></td><td>';
2100: if ($parent eq 'instcode') {
2101: $datatable .= '<span class="LC_nobreak">'.&mt('Official courses')
2102: .'</span><br /><span class="LC_nobreak">('
2103: .&mt('with institutional codes').')</span></td>'
2104: .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'
2105: .&mt('Display').'</label> '
2106: .'<label><input type="radio" name="instcode" value="0" />'
2107: .&mt('Do not display').'</label></span></td>';
2108: } else {
2109: $datatable .= $parent
2110: .' <label><input type="checkbox" name="deletecategory" '
2111: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
2112: }
2113: my $depth = 1;
2114: push(@path,$parent);
2115: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
2116: pop(@path);
2117: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
2118: $itemcount ++;
2119: }
1.48 raeburn 2120: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 2121: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
2122: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 2123: for (my $k=0; $k<=$maxnum; $k++) {
2124: my $vpos = $k+1;
2125: my $selstr;
1.57 raeburn 2126: if ($k == $numtop) {
1.48 raeburn 2127: $selstr = ' selected="selected" ';
2128: }
2129: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2130: }
1.59 bisitz 2131: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 2132: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
2133: .'</tr>'."\n";
1.48 raeburn 2134: $itemcount ++;
1.57 raeburn 2135: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2136: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2137: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
2138: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
2139: '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
2140: for (my $k=0; $k<=$maxnum; $k++) {
2141: my $vpos = $k+1;
2142: my $selstr;
2143: if ($k == $maxnum) {
2144: $selstr = ' selected="selected" ';
2145: }
2146: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.48 raeburn 2147: }
1.57 raeburn 2148: $datatable .= '</select></span></td><td><span class="LC_nobreak">'
2149: .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('
2150: .&mt('with institutional codes').')</span></td>'
2151: .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'
2152: .&mt('Display').'</label> '
2153: .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'
2154: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 2155: }
2156: }
1.57 raeburn 2157: } else {
2158: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 2159: }
2160: } else {
1.57 raeburn 2161: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
2162: .&initialize_categories($itemcount);
1.48 raeburn 2163: }
1.57 raeburn 2164: $$rowtotal += $itemcount;
1.48 raeburn 2165: }
2166: return $datatable;
2167: }
2168:
1.49 raeburn 2169: sub coursecategories_javascript {
2170: my ($settings) = @_;
1.57 raeburn 2171: my ($output,$jstext,$cathash);
1.49 raeburn 2172: if (ref($settings) eq 'HASH') {
1.57 raeburn 2173: $cathash = $settings->{'cats'};
2174: }
2175: if (ref($cathash) eq 'HASH') {
1.49 raeburn 2176: my (@cats,@jsarray,%idx);
1.57 raeburn 2177: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 2178: if (@jsarray > 0) {
2179: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
2180: for (my $i=0; $i<@jsarray; $i++) {
2181: if (ref($jsarray[$i]) eq 'ARRAY') {
2182: my $catstr = join('","',@{$jsarray[$i]});
2183: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
2184: }
2185: }
2186: }
2187: } else {
2188: $jstext = ' var categories = Array(1);'."\n".
2189: ' categories[0] = Array("instcode_pos");'."\n";
2190: }
2191: $output = <<"ENDSCRIPT";
2192: <script type="text/javascript">
2193: function reorderCats(form,parent,item,idx) {
2194: var changedVal;
2195: $jstext
2196: var newpos = 'addcategory_pos';
2197: var current = new Array;
2198: if (parent == '') {
2199: var has_instcode = 0;
2200: var maxtop = categories[idx].length;
2201: for (var j=0; j<maxtop; j++) {
2202: if (categories[idx][j] == 'instcode::0') {
2203: has_instcode == 1;
2204: }
2205: }
2206: if (has_instcode == 0) {
2207: categories[idx][maxtop] = 'instcode_pos';
2208: }
2209: } else {
2210: newpos += '_'+parent;
2211: }
2212: var maxh = 1 + categories[idx].length;
2213: var current = new Array;
2214: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2215: if (item == newpos) {
2216: changedVal = newitemVal;
2217: } else {
2218: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2219: current[newitemVal] = newpos;
2220: }
2221: for (var i=0; i<categories[idx].length; i++) {
2222: var elementName = categories[idx][i];
2223: if (elementName != item) {
2224: if (form.elements[elementName]) {
2225: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2226: current[currVal] = elementName;
2227: }
2228: }
2229: }
2230: var oldVal;
2231: for (var j=0; j<maxh; j++) {
2232: if (current[j] == undefined) {
2233: oldVal = j;
2234: }
2235: }
2236: if (oldVal < changedVal) {
2237: for (var k=oldVal+1; k<=changedVal ; k++) {
2238: var elementName = current[k];
2239: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2240: }
2241: } else {
2242: for (var k=changedVal; k<oldVal; k++) {
2243: var elementName = current[k];
2244: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2245: }
2246: }
2247: return;
2248: }
2249: </script>
2250:
2251: ENDSCRIPT
2252: return $output;
2253: }
2254:
1.48 raeburn 2255: sub initialize_categories {
2256: my ($itemcount) = @_;
2257: my $datatable;
2258: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2259: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
2260:
1.48 raeburn 2261: $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
2262: .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
2263: .'<option value="1">2</option></select> '
2264: .&mt('Official courses (with institutional codes)')
2265: .'</span></td><td><span class="LC_nobreak">'
2266: .'<label><input type="radio" name="instcode" value="1" checked="checked" />'
2267: .&mt('Display').'</label> <label>'
2268: .'<input type="radio" name="instcode" value="0" />'.&mt('Do not display')
2269: .'</label></span></td></tr>';
2270: $itemcount ++;
2271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2272: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 2273: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.53 raeburn 2274: .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
1.48 raeburn 2275: .'<option value="1" selected="selected">2</option></select> '
2276: .&mt('Add category').'</td><td>'.&mt('Name:')
2277: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
2278: return $datatable;
2279: }
2280:
2281: sub build_category_rows {
1.49 raeburn 2282: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
2283: my ($text,$name,$item,$chgstr);
1.48 raeburn 2284: if (ref($cats) eq 'ARRAY') {
2285: my $maxdepth = scalar(@{$cats});
2286: if (ref($cats->[$depth]) eq 'HASH') {
2287: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
2288: my $numchildren = @{$cats->[$depth]{$parent}};
2289: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
2290: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 2291: my ($idxnum,$parent_name,$parent_item);
2292: my $higher = $depth - 1;
2293: if ($higher == 0) {
2294: $parent_name = &escape($parent).'::'.$higher;
2295: } else {
2296: if (ref($path) eq 'ARRAY') {
2297: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2298: }
2299: }
2300: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 2301: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 2302: if ($j < $numchildren) {
1.48 raeburn 2303: $name = $cats->[$depth]{$parent}[$j];
2304: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 2305: $idxnum = $idx->{$item};
2306: } else {
2307: $name = $parent_name;
2308: $item = $parent_item;
1.48 raeburn 2309: }
1.49 raeburn 2310: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
2311: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 2312: for (my $i=0; $i<=$numchildren; $i++) {
2313: my $vpos = $i+1;
2314: my $selstr;
2315: if ($j == $i) {
2316: $selstr = ' selected="selected" ';
2317: }
2318: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
2319: }
2320: $text .= '</select> ';
2321: if ($j < $numchildren) {
2322: my $deeper = $depth+1;
2323: $text .= $name.' '
2324: .'<label><input type="checkbox" name="deletecategory" value="'
2325: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
2326: if(ref($path) eq 'ARRAY') {
2327: push(@{$path},$name);
1.49 raeburn 2328: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 2329: pop(@{$path});
2330: }
2331: } else {
1.59 bisitz 2332: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 2333: if ($j == $numchildren) {
2334: $text .= $name;
2335: } else {
2336: $text .= $item;
2337: }
2338: $text .= '" value="" />';
2339: }
2340: $text .= '</td></tr>';
2341: }
2342: $text .= '</table></td>';
2343: } else {
2344: my $higher = $depth-1;
2345: if ($higher == 0) {
2346: $name = &escape($parent).'::'.$higher;
2347: } else {
2348: if (ref($path) eq 'ARRAY') {
2349: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2350: }
2351: }
2352: my $colspan;
2353: if ($parent ne 'instcode') {
2354: $colspan = $maxdepth - $depth - 1;
2355: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
2356: }
2357: }
2358: }
2359: }
2360: return $text;
2361: }
2362:
1.33 raeburn 2363: sub modifiable_userdata_row {
2364: my ($context,$role,$settings,$numinrow,$rowcount) = @_;
2365: my $rolename;
2366: if ($role eq 'cr') {
2367: $rolename = &mt('Custom role');
2368: } else {
2369: $rolename = &Apache::lonnet::plaintext($role);
2370: }
2371: my @fields = ('lastname','firstname','middlename','generation',
2372: 'permanentemail','id');
2373: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2374: my $output;
2375: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2376: $output = '<tr '.$css_class.'>'.
2377: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
2378: '<td class="LC_left_item" colspan="2"><table>';
2379: my $rem;
2380: my %checks;
2381: if (ref($settings) eq 'HASH') {
2382: if (ref($settings->{$context}) eq 'HASH') {
2383: if (ref($settings->{$context}->{$role}) eq 'HASH') {
2384: foreach my $field (@fields) {
2385: if ($settings->{$context}->{$role}->{$field}) {
2386: $checks{$field} = ' checked="checked" ';
2387: }
2388: }
2389: }
2390: }
2391: }
2392: for (my $i=0; $i<@fields; $i++) {
2393: my $rem = $i%($numinrow);
2394: if ($rem == 0) {
2395: if ($i > 0) {
2396: $output .= '</tr>';
2397: }
2398: $output .= '<tr>';
2399: }
2400: my $check = ' ';
2401: if (exists($checks{$fields[$i]})) {
2402: $check = $checks{$fields[$i]}
2403: } else {
2404: if ($role eq 'st') {
2405: if (ref($settings) ne 'HASH') {
2406: $check = ' checked="checked" ';
2407: }
2408: }
2409: }
2410: $output .= '<td class="LC_left_item">'.
2411: '<span class="LC_nobreak"><label>'.
2412: '<input type="checkbox" name="canmodify_'.$role.'" '.
2413: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
2414: '</label></span></td>';
2415: $rem = @fields%($numinrow);
2416: }
2417: my $colsleft = $numinrow - $rem;
2418: if ($colsleft > 1 ) {
2419: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2420: ' </td>';
2421: } elsif ($colsleft == 1) {
2422: $output .= '<td class="LC_left_item"> </td>';
2423: }
2424: $output .= '</tr></table></td></tr>';
2425: return $output;
2426: }
1.28 raeburn 2427:
1.25 raeburn 2428: sub users_cansearch_row {
2429: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
2430: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 2431: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
2432: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 2433: my $rem;
2434: if (ref($types) eq 'ARRAY') {
2435: for (my $i=0; $i<@{$types}; $i++) {
2436: if (defined($usertypes->{$types->[$i]})) {
2437: my $rem = $i%($numinrow);
2438: if ($rem == 0) {
2439: if ($i > 0) {
2440: $output .= '</tr>';
2441: }
2442: $output .= '<tr>';
1.23 raeburn 2443: }
1.26 raeburn 2444: my $check = ' ';
2445: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
2446: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
2447: $check = ' checked="checked" ';
2448: }
1.23 raeburn 2449: }
1.26 raeburn 2450: $output .= '<td class="LC_left_item">'.
2451: '<span class="LC_nobreak"><label>'.
2452: '<input type="checkbox" name="cansearch" '.
2453: 'value="'.$types->[$i].'"'.$check.'/>'.
2454: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 2455: }
2456: }
1.26 raeburn 2457:
2458: $rem = @{$types}%($numinrow);
1.23 raeburn 2459: }
2460: my $colsleft = $numinrow - $rem;
2461: if ($colsleft > 1) {
1.25 raeburn 2462: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 2463: } else {
1.25 raeburn 2464: $output .= '<td class="LC_left_item">';
1.23 raeburn 2465: }
2466: my $defcheck = ' ';
2467: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 2468: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
2469: $defcheck = ' checked="checked" ';
2470: }
1.23 raeburn 2471: }
1.25 raeburn 2472: $output .= '<span class="LC_nobreak"><label>'.
2473: '<input type="checkbox" name="cansearch" '.
2474: 'value="default"'.$defcheck.'/>'.
2475: $othertitle.'</label></span></td>'.
2476: '</tr></table></td></tr>';
2477: return $output;
1.23 raeburn 2478: }
2479:
2480: sub sorted_searchtitles {
2481: my %searchtitles = &Apache::lonlocal::texthash(
2482: 'uname' => 'username',
2483: 'lastname' => 'last name',
2484: 'lastfirst' => 'last name, first name',
2485: );
2486: my @titleorder = ('uname','lastname','lastfirst');
2487: return (\%searchtitles,\@titleorder);
2488: }
2489:
1.25 raeburn 2490: sub sorted_searchtypes {
2491: my %srchtypes_desc = (
2492: exact => 'is exact match',
2493: contains => 'contains ..',
2494: begins => 'begins with ..',
2495: );
2496: my @srchtypeorder = ('exact','begins','contains');
2497: return (\%srchtypes_desc,\@srchtypeorder);
2498: }
2499:
1.3 raeburn 2500: sub usertype_update_row {
2501: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
2502: my $datatable;
2503: my $numinrow = 4;
2504: foreach my $type (@{$types}) {
2505: if (defined($usertypes->{$type})) {
2506: $$rownums ++;
2507: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
2508: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
2509: '</td><td class="LC_left_item"><table>';
2510: for (my $i=0; $i<@{$fields}; $i++) {
2511: my $rem = $i%($numinrow);
2512: if ($rem == 0) {
2513: if ($i > 0) {
2514: $datatable .= '</tr>';
2515: }
2516: $datatable .= '<tr>';
2517: }
2518: my $check = ' ';
1.39 raeburn 2519: if (ref($settings) eq 'HASH') {
2520: if (ref($settings->{'fields'}) eq 'HASH') {
2521: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
2522: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
2523: $check = ' checked="checked" ';
2524: }
1.3 raeburn 2525: }
2526: }
2527: }
2528:
2529: if ($i == @{$fields}-1) {
2530: my $colsleft = $numinrow - $rem;
2531: if ($colsleft > 1) {
2532: $datatable .= '<td colspan="'.$colsleft.'">';
2533: } else {
2534: $datatable .= '<td>';
2535: }
2536: } else {
2537: $datatable .= '<td>';
2538: }
1.8 raeburn 2539: $datatable .= '<span class="LC_nobreak"><label>'.
2540: '<input type="checkbox" name="updateable_'.$type.
2541: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
2542: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 2543: }
2544: $datatable .= '</tr></table></td></tr>';
2545: }
2546: }
2547: return $datatable;
1.1 raeburn 2548: }
2549:
2550: sub modify_login {
1.9 raeburn 2551: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 2552: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 2553: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 2554: adminmail => 'Display administrator E-mail address',
1.43 raeburn 2555: newuser => 'Link for visitors to create a user account',
1.41 raeburn 2556: loginheader => 'Log-in box header');
1.3 raeburn 2557: my @offon = ('off','on');
1.6 raeburn 2558: my %loginhash;
1.9 raeburn 2559: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
2560: \%domconfig,\%loginhash);
1.43 raeburn 2561: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2562: foreach my $item (@toggles) {
2563: $loginhash{login}{$item} = $env{'form.'.$item};
2564: }
1.41 raeburn 2565: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 2566: if (ref($colchanges{'login'}) eq 'HASH') {
2567: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
2568: \%loginhash);
2569: }
1.1 raeburn 2570: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
2571: $dom);
2572: if ($putresult eq 'ok') {
1.43 raeburn 2573: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2574: my %defaultchecked = (
2575: 'coursecatalog' => 'on',
2576: 'adminmail' => 'off',
1.43 raeburn 2577: 'newuser' => 'off',
1.42 raeburn 2578: );
1.55 raeburn 2579: if (ref($domconfig{'login'}) eq 'HASH') {
2580: foreach my $item (@toggles) {
2581: if ($defaultchecked{$item} eq 'on') {
2582: if (($domconfig{'login'}{$item} eq '0') &&
2583: ($env{'form.'.$item} eq '1')) {
2584: $changes{$item} = 1;
2585: } elsif (($domconfig{'login'}{$item} eq '' ||
2586: $domconfig{'login'}{$item} eq '1') &&
2587: ($env{'form.'.$item} eq '0')) {
2588: $changes{$item} = 1;
2589: }
2590: } elsif ($defaultchecked{$item} eq 'off') {
2591: if (($domconfig{'login'}{$item} eq '1') &&
2592: ($env{'form.'.$item} eq '0')) {
2593: $changes{$item} = 1;
2594: } elsif (($domconfig{'login'}{$item} eq '' ||
2595: $domconfig{'login'}{$item} eq '0') &&
2596: ($env{'form.'.$item} eq '1')) {
2597: $changes{$item} = 1;
2598: }
1.42 raeburn 2599: }
2600: }
1.55 raeburn 2601: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
2602: ($env{'form.loginheader'} eq 'image')) {
2603: $changes{'loginheader'} = 1;
2604: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
2605: $domconfig{'login'}{'loginheader'} eq 'image') &&
2606: ($env{'form.loginheader'} eq 'text')) {
2607: $changes{'loginheader'} = 1;
2608: }
1.41 raeburn 2609: }
1.6 raeburn 2610: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 2611: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 2612: $resulttext = &mt('Changes made:').'<ul>';
2613: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 2614: if ($item eq 'loginheader') {
2615: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
2616: } else {
2617: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
2618: }
1.1 raeburn 2619: }
1.6 raeburn 2620: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 2621: } else {
2622: $resulttext = &mt('No changes made to log-in page settings');
2623: }
2624: } else {
1.11 albertel 2625: $resulttext = '<span class="LC_error">'.
2626: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2627: }
1.6 raeburn 2628: if ($errors) {
1.9 raeburn 2629: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 2630: $errors.'</ul>';
2631: }
2632: return $resulttext;
2633: }
2634:
2635: sub color_font_choices {
2636: my %choices =
2637: &Apache::lonlocal::texthash (
2638: img => "Header",
2639: bgs => "Background colors",
2640: links => "Link colors",
1.55 raeburn 2641: images => "Images",
1.6 raeburn 2642: font => "Font color",
2643: pgbg => "Page",
2644: tabbg => "Header",
2645: sidebg => "Border",
2646: link => "Link",
2647: alink => "Active link",
2648: vlink => "Visited link",
2649: );
2650: return %choices;
2651: }
2652:
2653: sub modify_rolecolors {
1.9 raeburn 2654: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 2655: my ($resulttext,%rolehash);
2656: $rolehash{'rolecolors'} = {};
1.55 raeburn 2657: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
2658: if ($domconfig{'rolecolors'} eq '') {
2659: $domconfig{'rolecolors'} = {};
2660: }
2661: }
1.9 raeburn 2662: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 2663: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
2664: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
2665: $dom);
2666: if ($putresult eq 'ok') {
2667: if (keys(%changes) > 0) {
1.41 raeburn 2668: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 2669: $resulttext = &display_colorchgs($dom,\%changes,$roles,
2670: $rolehash{'rolecolors'});
2671: } else {
2672: $resulttext = &mt('No changes made to default color schemes');
2673: }
2674: } else {
1.11 albertel 2675: $resulttext = '<span class="LC_error">'.
2676: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 2677: }
2678: if ($errors) {
2679: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
2680: $errors.'</ul>';
2681: }
2682: return $resulttext;
2683: }
2684:
2685: sub modify_colors {
1.9 raeburn 2686: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 2687: my (%changes,%choices);
1.51 raeburn 2688: my @bgs;
1.6 raeburn 2689: my @links = ('link','alink','vlink');
1.41 raeburn 2690: my @logintext;
1.6 raeburn 2691: my @images;
2692: my $servadm = $r->dir_config('lonAdmEMail');
2693: my $errors;
2694: foreach my $role (@{$roles}) {
2695: if ($role eq 'login') {
1.12 raeburn 2696: %choices = &login_choices();
1.41 raeburn 2697: @logintext = ('textcol','bgcol');
1.12 raeburn 2698: } else {
2699: %choices = &color_font_choices();
2700: }
2701: if ($role eq 'login') {
1.41 raeburn 2702: @images = ('img','logo','domlogo','login');
1.51 raeburn 2703: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 2704: } else {
2705: @images = ('img');
1.51 raeburn 2706: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 2707: }
2708: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 2709: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 2710: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
2711: }
1.46 raeburn 2712: my ($configuserok,$author_ok,$switchserver) =
2713: &config_check($dom,$confname,$servadm);
1.9 raeburn 2714: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 2715: if (ref($domconfig->{$role}) ne 'HASH') {
2716: $domconfig->{$role} = {};
2717: }
1.8 raeburn 2718: foreach my $img (@images) {
1.18 albertel 2719: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
2720: && !defined($domconfig->{$role}{$img})
2721: && !$env{'form.'.$role.'_del_'.$img}
2722: && $env{'form.'.$role.'_import_'.$img}) {
2723: # import the old configured image from the .tab setting
2724: # if they haven't provided a new one
2725: $domconfig->{$role}{$img} =
2726: $env{'form.'.$role.'_import_'.$img};
2727: }
1.6 raeburn 2728: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 2729: my $error;
1.6 raeburn 2730: if ($configuserok eq 'ok') {
1.9 raeburn 2731: if ($switchserver) {
1.12 raeburn 2732: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 2733: } else {
2734: if ($author_ok eq 'ok') {
2735: my ($result,$logourl) =
2736: &publishlogo($r,'upload',$role.'_'.$img,
2737: $dom,$confname,$img,$width,$height);
2738: if ($result eq 'ok') {
2739: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 2740: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2741: } else {
1.12 raeburn 2742: $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 2743: }
2744: } else {
1.46 raeburn 2745: $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 2746: }
2747: }
2748: } else {
1.46 raeburn 2749: $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 2750: }
2751: if ($error) {
1.8 raeburn 2752: &Apache::lonnet::logthis($error);
1.11 albertel 2753: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 2754: }
2755: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 2756: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
2757: my $error;
2758: if ($configuserok eq 'ok') {
2759: # is confname an author?
2760: if ($switchserver eq '') {
2761: if ($author_ok eq 'ok') {
2762: my ($result,$logourl) =
2763: &publishlogo($r,'copy',$domconfig->{$role}{$img},
2764: $dom,$confname,$img,$width,$height);
2765: if ($result eq 'ok') {
2766: $confhash->{$role}{$img} = $logourl;
1.18 albertel 2767: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2768: }
2769: }
2770: }
2771: }
1.6 raeburn 2772: }
2773: }
2774: }
2775: if (ref($domconfig) eq 'HASH') {
2776: if (ref($domconfig->{$role}) eq 'HASH') {
2777: foreach my $img (@images) {
2778: if ($domconfig->{$role}{$img} ne '') {
2779: if ($env{'form.'.$role.'_del_'.$img}) {
2780: $confhash->{$role}{$img} = '';
1.12 raeburn 2781: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2782: } else {
1.9 raeburn 2783: if ($confhash->{$role}{$img} eq '') {
2784: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
2785: }
1.6 raeburn 2786: }
2787: } else {
2788: if ($env{'form.'.$role.'_del_'.$img}) {
2789: $confhash->{$role}{$img} = '';
1.12 raeburn 2790: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2791: }
2792: }
2793: }
2794: if ($domconfig->{$role}{'font'} ne '') {
2795: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
2796: $changes{$role}{'font'} = 1;
2797: }
2798: } else {
2799: if ($confhash->{$role}{'font'}) {
2800: $changes{$role}{'font'} = 1;
2801: }
2802: }
2803: foreach my $item (@bgs) {
2804: if ($domconfig->{$role}{$item} ne '') {
2805: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2806: $changes{$role}{'bgs'}{$item} = 1;
2807: }
2808: } else {
2809: if ($confhash->{$role}{$item}) {
2810: $changes{$role}{'bgs'}{$item} = 1;
2811: }
2812: }
2813: }
2814: foreach my $item (@links) {
2815: if ($domconfig->{$role}{$item} ne '') {
2816: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2817: $changes{$role}{'links'}{$item} = 1;
2818: }
2819: } else {
2820: if ($confhash->{$role}{$item}) {
2821: $changes{$role}{'links'}{$item} = 1;
2822: }
2823: }
2824: }
1.41 raeburn 2825: foreach my $item (@logintext) {
2826: if ($domconfig->{$role}{$item} ne '') {
2827: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2828: $changes{$role}{'logintext'}{$item} = 1;
2829: }
2830: } else {
2831: if ($confhash->{$role}{$item}) {
2832: $changes{$role}{'logintext'}{$item} = 1;
2833: }
2834: }
2835: }
1.6 raeburn 2836: } else {
2837: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2838: \@logintext,$confhash,\%changes);
1.6 raeburn 2839: }
2840: } else {
2841: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2842: \@logintext,$confhash,\%changes);
1.6 raeburn 2843: }
2844: }
2845: return ($errors,%changes);
2846: }
2847:
1.46 raeburn 2848: sub config_check {
2849: my ($dom,$confname,$servadm) = @_;
2850: my ($configuserok,$author_ok,$switchserver,%currroles);
2851: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
2852: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
2853: $confname,$servadm);
2854: if ($configuserok eq 'ok') {
2855: $switchserver = &check_switchserver($dom,$confname);
2856: if ($switchserver eq '') {
2857: $author_ok = &check_authorstatus($dom,$confname,%currroles);
2858: }
2859: }
2860: return ($configuserok,$author_ok,$switchserver);
2861: }
2862:
1.6 raeburn 2863: sub default_change_checker {
1.41 raeburn 2864: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 2865: foreach my $item (@{$links}) {
2866: if ($confhash->{$role}{$item}) {
2867: $changes->{$role}{'links'}{$item} = 1;
2868: }
2869: }
2870: foreach my $item (@{$bgs}) {
2871: if ($confhash->{$role}{$item}) {
2872: $changes->{$role}{'bgs'}{$item} = 1;
2873: }
2874: }
1.41 raeburn 2875: foreach my $item (@{$logintext}) {
2876: if ($confhash->{$role}{$item}) {
2877: $changes->{$role}{'logintext'}{$item} = 1;
2878: }
2879: }
1.6 raeburn 2880: foreach my $img (@{$images}) {
2881: if ($env{'form.'.$role.'_del_'.$img}) {
2882: $confhash->{$role}{$img} = '';
1.12 raeburn 2883: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 2884: }
2885: }
2886: if ($confhash->{$role}{'font'}) {
2887: $changes->{$role}{'font'} = 1;
2888: }
1.48 raeburn 2889: }
1.6 raeburn 2890:
2891: sub display_colorchgs {
2892: my ($dom,$changes,$roles,$confhash) = @_;
2893: my (%choices,$resulttext);
2894: if (!grep(/^login$/,@{$roles})) {
2895: $resulttext = &mt('Changes made:').'<br />';
2896: }
2897: foreach my $role (@{$roles}) {
2898: if ($role eq 'login') {
2899: %choices = &login_choices();
2900: } else {
2901: %choices = &color_font_choices();
2902: }
2903: if (ref($changes->{$role}) eq 'HASH') {
2904: if ($role ne 'login') {
2905: $resulttext .= '<h4>'.&mt($role).'</h4>';
2906: }
2907: foreach my $key (sort(keys(%{$changes->{$role}}))) {
2908: if ($role ne 'login') {
2909: $resulttext .= '<ul>';
2910: }
2911: if (ref($changes->{$role}{$key}) eq 'HASH') {
2912: if ($role ne 'login') {
2913: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
2914: }
2915: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
2916: if ($confhash->{$role}{$item} eq '') {
2917: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
2918: } else {
1.12 raeburn 2919: my $newitem = $confhash->{$role}{$item};
2920: if ($key eq 'images') {
2921: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
2922: }
2923: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 2924: }
2925: }
2926: if ($role ne 'login') {
2927: $resulttext .= '</ul></li>';
2928: }
2929: } else {
2930: if ($confhash->{$role}{$key} eq '') {
2931: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
2932: } else {
2933: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
2934: }
2935: }
2936: if ($role ne 'login') {
2937: $resulttext .= '</ul>';
2938: }
2939: }
2940: }
2941: }
1.3 raeburn 2942: return $resulttext;
1.1 raeburn 2943: }
2944:
1.9 raeburn 2945: sub thumb_dimensions {
2946: return ('200','50');
2947: }
2948:
1.16 raeburn 2949: sub check_dimensions {
2950: my ($inputfile) = @_;
2951: my ($fullwidth,$fullheight);
2952: if ($inputfile =~ m|^[/\w.\-]+$|) {
2953: if (open(PIPE,"identify $inputfile 2>&1 |")) {
2954: my $imageinfo = <PIPE>;
2955: if (!close(PIPE)) {
2956: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
2957: }
2958: chomp($imageinfo);
2959: my ($fullsize) =
1.21 raeburn 2960: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 2961: if ($fullsize) {
2962: ($fullwidth,$fullheight) = split(/x/,$fullsize);
2963: }
2964: }
2965: }
2966: return ($fullwidth,$fullheight);
2967: }
2968:
1.9 raeburn 2969: sub check_configuser {
2970: my ($uhome,$dom,$confname,$servadm) = @_;
2971: my ($configuserok,%currroles);
2972: if ($uhome eq 'no_host') {
2973: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
2974: my $configpass = &LONCAPA::Enrollment::create_password();
2975: $configuserok =
2976: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
2977: $configpass,'','','','','',undef,$servadm);
2978: } else {
2979: $configuserok = 'ok';
2980: %currroles =
2981: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
2982: }
2983: return ($configuserok,%currroles);
2984: }
2985:
2986: sub check_authorstatus {
2987: my ($dom,$confname,%currroles) = @_;
2988: my $author_ok;
1.40 raeburn 2989: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 2990: my $start = time;
2991: my $end = 0;
2992: $author_ok =
2993: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 2994: 'au',$end,$start,'','','domconfig');
1.9 raeburn 2995: } else {
2996: $author_ok = 'ok';
2997: }
2998: return $author_ok;
2999: }
3000:
3001: sub publishlogo {
1.46 raeburn 3002: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 3003: my ($output,$fname,$logourl);
3004: if ($action eq 'upload') {
3005: $fname=$env{'form.'.$formname.'.filename'};
3006: chop($env{'form.'.$formname});
3007: } else {
3008: ($fname) = ($formname =~ /([^\/]+)$/);
3009: }
1.46 raeburn 3010: if ($savefileas ne '') {
3011: $fname = $savefileas;
3012: }
1.9 raeburn 3013: $fname=&Apache::lonnet::clean_filename($fname);
3014: # See if there is anything left
3015: unless ($fname) { return ('error: no uploaded file'); }
3016: $fname="$subdir/$fname";
3017: my $filepath='/home/'.$confname.'/public_html';
3018: my ($fnamepath,$file,$fetchthumb);
3019: $file=$fname;
3020: if ($fname=~m|/|) {
3021: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
3022: }
3023: my @parts=split(/\//,$filepath.'/'.$fnamepath);
3024: my $count;
3025: for ($count=4;$count<=$#parts;$count++) {
3026: $filepath.="/$parts[$count]";
3027: if ((-e $filepath)!=1) {
3028: mkdir($filepath,02770);
3029: }
3030: }
3031: # Check for bad extension and disallow upload
3032: if ($file=~/\.(\w+)$/ &&
3033: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
3034: $output =
3035: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
3036: } elsif ($file=~/\.(\w+)$/ &&
3037: !defined(&Apache::loncommon::fileembstyle($1))) {
3038: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
3039: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 3040: $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 3041: } elsif (-d "$filepath/$file") {
3042: $output = &mt('File name is a directory name - rename the file and re-upload');
3043: } else {
3044: my $source = $filepath.'/'.$file;
3045: my $logfile;
3046: if (!open($logfile,">>$source".'.log')) {
3047: return (&mt('No write permission to Construction Space'));
3048: }
3049: print $logfile
3050: "\n================= Publish ".localtime()." ================\n".
3051: $env{'user.name'}.':'.$env{'user.domain'}."\n";
3052: # Save the file
3053: if (!open(FH,'>'.$source)) {
3054: &Apache::lonnet::logthis('Failed to create '.$source);
3055: return (&mt('Failed to create file'));
3056: }
3057: if ($action eq 'upload') {
3058: if (!print FH ($env{'form.'.$formname})) {
3059: &Apache::lonnet::logthis('Failed to write to '.$source);
3060: return (&mt('Failed to write file'));
3061: }
3062: } else {
3063: my $original = &Apache::lonnet::filelocation('',$formname);
3064: if(!copy($original,$source)) {
3065: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
3066: return (&mt('Failed to write file'));
3067: }
3068: }
3069: close(FH);
3070: chmod(0660, $source); # Permissions to rw-rw---.
3071:
3072: my $docroot=$r->dir_config('lonDocRoot');
3073: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
3074: my $copyfile=$targetdir.'/'.$file;
3075:
3076: my @parts=split(/\//,$targetdir);
3077: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
3078: for (my $count=5;$count<=$#parts;$count++) {
3079: $path.="/$parts[$count]";
3080: if (!-e $path) {
3081: print $logfile "\nCreating directory ".$path;
3082: mkdir($path,02770);
3083: }
3084: }
3085: my $versionresult;
3086: if (-e $copyfile) {
3087: $versionresult = &logo_versioning($targetdir,$file,$logfile);
3088: } else {
3089: $versionresult = 'ok';
3090: }
3091: if ($versionresult eq 'ok') {
3092: if (copy($source,$copyfile)) {
3093: print $logfile "\nCopied original source to ".$copyfile."\n";
3094: $output = 'ok';
3095: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
3096: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
3097: } else {
3098: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
3099: $output = &mt('Failed to copy file to RES space').", $!";
3100: }
3101: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
3102: my $inputfile = $filepath.'/'.$file;
3103: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 3104: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
3105: if ($fullwidth ne '' && $fullheight ne '') {
3106: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
3107: my $thumbsize = $thumbwidth.'x'.$thumbheight;
3108: system("convert -sample $thumbsize $inputfile $outfile");
3109: chmod(0660, $filepath.'/tn-'.$file);
3110: if (-e $outfile) {
3111: my $copyfile=$targetdir.'/tn-'.$file;
3112: if (copy($outfile,$copyfile)) {
3113: print $logfile "\nCopied source to ".$copyfile."\n";
3114: &write_metadata($dom,$confname,$formname,
3115: $targetdir,'tn-'.$file,$logfile);
3116: } else {
3117: print $logfile "\nUnable to write ".$copyfile.
3118: ':'.$!."\n";
3119: }
3120: }
1.9 raeburn 3121: }
3122: }
3123: }
3124: } else {
3125: $output = $versionresult;
3126: }
3127: }
3128: return ($output,$logourl);
3129: }
3130:
3131: sub logo_versioning {
3132: my ($targetdir,$file,$logfile) = @_;
3133: my $target = $targetdir.'/'.$file;
3134: my ($maxversion,$fn,$extn,$output);
3135: $maxversion = 0;
3136: if ($file =~ /^(.+)\.(\w+)$/) {
3137: $fn=$1;
3138: $extn=$2;
3139: }
3140: opendir(DIR,$targetdir);
3141: while (my $filename=readdir(DIR)) {
3142: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
3143: $maxversion=($1>$maxversion)?$1:$maxversion;
3144: }
3145: }
3146: $maxversion++;
3147: print $logfile "\nCreating old version ".$maxversion."\n";
3148: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
3149: if (copy($target,$copyfile)) {
3150: print $logfile "Copied old target to ".$copyfile."\n";
3151: $copyfile=$copyfile.'.meta';
3152: if (copy($target.'.meta',$copyfile)) {
3153: print $logfile "Copied old target metadata to ".$copyfile."\n";
3154: $output = 'ok';
3155: } else {
3156: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
3157: $output = &mt('Failed to copy old meta').", $!, ";
3158: }
3159: } else {
3160: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
3161: $output = &mt('Failed to copy old target').", $!, ";
3162: }
3163: return $output;
3164: }
3165:
3166: sub write_metadata {
3167: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
3168: my (%metadatafields,%metadatakeys,$output);
3169: $metadatafields{'title'}=$formname;
3170: $metadatafields{'creationdate'}=time;
3171: $metadatafields{'lastrevisiondate'}=time;
3172: $metadatafields{'copyright'}='public';
3173: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
3174: $env{'user.domain'};
3175: $metadatafields{'authorspace'}=$confname.':'.$dom;
3176: $metadatafields{'domain'}=$dom;
3177: {
3178: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
3179: my $mfh;
3180: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
3181: $output = &mt('Could not write metadata');
3182: }
3183: foreach (sort keys %metadatafields) {
3184: unless ($_=~/\./) {
3185: my $unikey=$_;
3186: $unikey=~/^([A-Za-z]+)/;
3187: my $tag=$1;
3188: $tag=~tr/A-Z/a-z/;
3189: print $mfh "\n\<$tag";
3190: foreach (split(/\,/,$metadatakeys{$unikey})) {
3191: my $value=$metadatafields{$unikey.'.'.$_};
3192: $value=~s/\"/\'\'/g;
3193: print $mfh ' '.$_.'="'.$value.'"';
3194: }
3195: print $mfh '>'.
3196: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
3197: .'</'.$tag.'>';
3198: }
3199: }
3200: $output = 'ok';
3201: print $logfile "\nWrote metadata";
3202: close($mfh);
3203: }
3204: }
3205:
3206: sub check_switchserver {
3207: my ($dom,$confname) = @_;
3208: my ($allowed,$switchserver);
3209: my $home = &Apache::lonnet::homeserver($confname,$dom);
3210: if ($home eq 'no_host') {
3211: $home = &Apache::lonnet::domain($dom,'primary');
3212: }
3213: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 3214: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3215: if (!$allowed) {
3216: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 3217: }
3218: return $switchserver;
3219: }
3220:
1.30 raeburn 3221: sub javascript_set_colnums {
3222: return <<END;
3223: function setDisplayColumns() {
3224: if (document.pickactions.width.value > 1100) {
3225: document.pickactions.numcols[1].checked = true;
3226: } else {
3227: document.pickactions.numcols[0].checked = true;
3228: }
3229: }
3230: END
3231: }
3232:
1.1 raeburn 3233: sub modify_quotas {
1.3 raeburn 3234: my ($dom,%domconfig) = @_;
1.1 raeburn 3235: my ($resulttext,%changes);
1.44 raeburn 3236: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 3237: my %formhash;
3238: foreach my $key (keys(%env)) {
3239: if ($key =~ /^form\.quota_(.+)$/) {
3240: $formhash{$1} = $env{$key};
3241: }
3242: }
1.15 raeburn 3243: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 3244: if (ref($domconfig{'quotas'}) eq 'HASH') {
3245: foreach my $key (keys(%{$domconfig{'quotas'}})) {
3246: if (exists($formhash{$key})) {
3247: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
3248: $changes{$key} = 1;
3249: }
3250: } else {
3251: $formhash{$key} = $domconfig{'quotas'}{$key};
3252: }
3253: }
3254: }
3255: foreach my $key (keys(%formhash)) {
3256: if ($formhash{$key} ne '') {
1.55 raeburn 3257: if (ref($domconfig{'quotas'}) eq 'HASH') {
3258: if (!exists($domconfig{'quotas'}{$key})) {
3259: $changes{$key} = 1;
3260: }
3261: } else {
1.1 raeburn 3262: $changes{$key} = 1;
3263: }
3264: }
3265: }
3266: my %quotahash = (
1.3 raeburn 3267: quotas => {%formhash},
1.1 raeburn 3268: );
3269: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
3270: $dom);
3271: if ($putresult eq 'ok') {
3272: if (keys(%changes) > 0) {
3273: $resulttext = &mt('Changes made:').'<ul>';
1.26 raeburn 3274: foreach my $type (@{$types},'default') {
3275: if (defined($changes{$type})) {
3276: my $typetitle = $usertypes->{$type};
3277: if ($type eq 'default') {
3278: $typetitle = $othertitle;
3279: }
3280: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
3281: }
1.1 raeburn 3282: }
3283: $resulttext .= '</ul>';
3284: } else {
3285: $resulttext = &mt('No changes made to default quotas');
3286: }
3287: } else {
1.11 albertel 3288: $resulttext = '<span class="LC_error">'.
3289: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3290: }
1.3 raeburn 3291: return $resulttext;
1.1 raeburn 3292: }
3293:
1.3 raeburn 3294: sub modify_autoenroll {
3295: my ($dom,%domconfig) = @_;
1.1 raeburn 3296: my ($resulttext,%changes);
3297: my %currautoenroll;
3298: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
3299: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
3300: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
3301: }
3302: }
3303: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
3304: my %title = ( run => 'Auto-enrollment active',
3305: sender => 'Sender for notification messages');
3306: my @offon = ('off','on');
1.17 raeburn 3307: my $sender_uname = $env{'form.sender_uname'};
3308: my $sender_domain = $env{'form.sender_domain'};
3309: if ($sender_domain eq '') {
3310: $sender_uname = '';
3311: } elsif ($sender_uname eq '') {
3312: $sender_domain = '';
3313: }
1.1 raeburn 3314: my %autoenrollhash = (
3315: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 3316: sender_uname => $sender_uname,
3317: sender_domain => $sender_domain,
1.1 raeburn 3318:
3319: }
3320: );
1.4 raeburn 3321: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
3322: $dom);
1.1 raeburn 3323: if ($putresult eq 'ok') {
3324: if (exists($currautoenroll{'run'})) {
3325: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
3326: $changes{'run'} = 1;
3327: }
3328: } elsif ($autorun) {
3329: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 3330: $changes{'run'} = 1;
1.1 raeburn 3331: }
3332: }
1.17 raeburn 3333: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 3334: $changes{'sender'} = 1;
3335: }
1.17 raeburn 3336: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 3337: $changes{'sender'} = 1;
3338: }
3339: if (keys(%changes) > 0) {
3340: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 3341: if ($changes{'run'}) {
1.1 raeburn 3342: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
3343: }
3344: if ($changes{'sender'}) {
1.17 raeburn 3345: if ($sender_uname eq '' || $sender_domain eq '') {
3346: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
3347: } else {
3348: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
3349: }
1.1 raeburn 3350: }
3351: $resulttext .= '</ul>';
3352: } else {
3353: $resulttext = &mt('No changes made to auto-enrollment settings');
3354: }
3355: } else {
1.11 albertel 3356: $resulttext = '<span class="LC_error">'.
3357: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3358: }
1.3 raeburn 3359: return $resulttext;
1.1 raeburn 3360: }
3361:
3362: sub modify_autoupdate {
1.3 raeburn 3363: my ($dom,%domconfig) = @_;
1.1 raeburn 3364: my ($resulttext,%currautoupdate,%fields,%changes);
3365: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
3366: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
3367: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
3368: }
3369: }
3370: my @offon = ('off','on');
3371: my %title = &Apache::lonlocal::texthash (
3372: run => 'Auto-update:',
3373: classlists => 'Updates to user information in classlists?'
3374: );
1.44 raeburn 3375: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 3376: my %fieldtitles = &Apache::lonlocal::texthash (
3377: id => 'Student/Employee ID',
1.20 raeburn 3378: permanentemail => 'E-mail address',
1.1 raeburn 3379: lastname => 'Last Name',
3380: firstname => 'First Name',
3381: middlename => 'Middle Name',
3382: gen => 'Generation',
3383: );
3384: my $othertitle = &mt('All users');
3385: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 3386: $othertitle = &mt('Other users');
1.1 raeburn 3387: }
3388: foreach my $key (keys(%env)) {
3389: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
3390: push(@{$fields{$1}},$2);
3391: }
3392: }
3393: my %updatehash = (
3394: autoupdate => { run => $env{'form.autoupdate_run'},
3395: classlists => $env{'form.classlists'},
3396: fields => {%fields},
3397: }
3398: );
3399: foreach my $key (keys(%currautoupdate)) {
3400: if (($key eq 'run') || ($key eq 'classlists')) {
3401: if (exists($updatehash{autoupdate}{$key})) {
3402: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
3403: $changes{$key} = 1;
3404: }
3405: }
3406: } elsif ($key eq 'fields') {
3407: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 3408: foreach my $item (@{$types},'default') {
1.1 raeburn 3409: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
3410: my $change = 0;
3411: foreach my $type (@{$currautoupdate{$key}{$item}}) {
3412: if (!exists($fields{$item})) {
3413: $change = 1;
3414: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 3415: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 3416: $change = 1;
3417: }
3418: }
3419: }
3420: if ($change) {
3421: push(@{$changes{$key}},$item);
3422: }
1.26 raeburn 3423: }
1.1 raeburn 3424: }
3425: }
3426: }
3427: }
1.26 raeburn 3428: foreach my $item (@{$types},'default') {
3429: if (defined($fields{$item})) {
3430: if (ref($currautoupdate{'fields'}) eq 'HASH') {
3431: if (!exists($currautoupdate{'fields'}{$item})) {
3432: push(@{$changes{'fields'}},$item);
3433: }
3434: } else {
3435: push(@{$changes{'fields'}},$item);
1.1 raeburn 3436: }
3437: }
3438: }
3439: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
3440: $dom);
3441: if ($putresult eq 'ok') {
3442: if (keys(%changes) > 0) {
3443: $resulttext = &mt('Changes made:').'<ul>';
3444: foreach my $key (sort(keys(%changes))) {
3445: if (ref($changes{$key}) eq 'ARRAY') {
3446: foreach my $item (@{$changes{$key}}) {
3447: my @newvalues;
3448: foreach my $type (@{$fields{$item}}) {
3449: push(@newvalues,$fieldtitles{$type});
3450: }
1.3 raeburn 3451: my $newvaluestr;
3452: if (@newvalues > 0) {
3453: $newvaluestr = join(', ',@newvalues);
3454: } else {
3455: $newvaluestr = &mt('none');
1.6 raeburn 3456: }
1.1 raeburn 3457: if ($item eq 'default') {
1.26 raeburn 3458: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 3459: } else {
1.26 raeburn 3460: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 3461: }
3462: }
3463: } else {
3464: my $newvalue;
3465: if ($key eq 'run') {
3466: $newvalue = $offon[$env{'form.autoupdate_run'}];
3467: } else {
3468: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 3469: }
1.1 raeburn 3470: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
3471: }
3472: }
3473: $resulttext .= '</ul>';
3474: } else {
1.3 raeburn 3475: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 3476: }
3477: } else {
1.11 albertel 3478: $resulttext = '<span class="LC_error">'.
3479: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3480: }
1.3 raeburn 3481: return $resulttext;
1.1 raeburn 3482: }
3483:
1.23 raeburn 3484: sub modify_directorysrch {
3485: my ($dom,%domconfig) = @_;
3486: my ($resulttext,%changes);
3487: my %currdirsrch;
3488: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3489: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
3490: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
3491: }
3492: }
3493: my %title = ( available => 'Directory search available',
1.24 raeburn 3494: localonly => 'Other domains can search',
1.23 raeburn 3495: searchby => 'Search types',
3496: searchtypes => 'Search latitude');
3497: my @offon = ('off','on');
1.24 raeburn 3498: my @otherdoms = ('Yes','No');
1.23 raeburn 3499:
1.25 raeburn 3500: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 3501: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
3502: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
3503:
1.44 raeburn 3504: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 3505: if (keys(%{$usertypes}) == 0) {
3506: @cansearch = ('default');
3507: } else {
3508: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
3509: foreach my $type (@{$currdirsrch{'cansearch'}}) {
3510: if (!grep(/^\Q$type\E$/,@cansearch)) {
3511: push(@{$changes{'cansearch'}},$type);
3512: }
1.23 raeburn 3513: }
1.26 raeburn 3514: foreach my $type (@cansearch) {
3515: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
3516: push(@{$changes{'cansearch'}},$type);
3517: }
1.23 raeburn 3518: }
1.26 raeburn 3519: } else {
3520: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 3521: }
3522: }
3523:
3524: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
3525: foreach my $by (@{$currdirsrch{'searchby'}}) {
3526: if (!grep(/^\Q$by\E$/,@searchby)) {
3527: push(@{$changes{'searchby'}},$by);
3528: }
3529: }
3530: foreach my $by (@searchby) {
3531: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
3532: push(@{$changes{'searchby'}},$by);
3533: }
3534: }
3535: } else {
3536: push(@{$changes{'searchby'}},@searchby);
3537: }
1.25 raeburn 3538:
3539: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
3540: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
3541: if (!grep(/^\Q$type\E$/,@searchtypes)) {
3542: push(@{$changes{'searchtypes'}},$type);
3543: }
3544: }
3545: foreach my $type (@searchtypes) {
3546: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
3547: push(@{$changes{'searchtypes'}},$type);
3548: }
3549: }
3550: } else {
3551: if (exists($currdirsrch{'searchtypes'})) {
3552: foreach my $type (@searchtypes) {
3553: if ($type ne $currdirsrch{'searchtypes'}) {
3554: push(@{$changes{'searchtypes'}},$type);
3555: }
3556: }
3557: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
3558: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
3559: }
3560: } else {
3561: push(@{$changes{'searchtypes'}},@searchtypes);
3562: }
3563: }
3564:
1.23 raeburn 3565: my %dirsrch_hash = (
3566: directorysrch => { available => $env{'form.dirsrch_available'},
3567: cansearch => \@cansearch,
1.24 raeburn 3568: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 3569: searchby => \@searchby,
1.25 raeburn 3570: searchtypes => \@searchtypes,
1.23 raeburn 3571: }
3572: );
3573: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
3574: $dom);
3575: if ($putresult eq 'ok') {
3576: if (exists($currdirsrch{'available'})) {
3577: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
3578: $changes{'available'} = 1;
3579: }
3580: } else {
3581: if ($env{'form.dirsrch_available'} eq '1') {
3582: $changes{'available'} = 1;
3583: }
3584: }
1.24 raeburn 3585: if (exists($currdirsrch{'localonly'})) {
3586: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
3587: $changes{'localonly'} = 1;
3588: }
3589: } else {
3590: if ($env{'form.dirsrch_localonly'} eq '1') {
3591: $changes{'localonly'} = 1;
3592: }
3593: }
1.23 raeburn 3594: if (keys(%changes) > 0) {
3595: $resulttext = &mt('Changes made:').'<ul>';
3596: if ($changes{'available'}) {
3597: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
3598: }
1.24 raeburn 3599: if ($changes{'localonly'}) {
3600: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
3601: }
3602:
1.23 raeburn 3603: if (ref($changes{'cansearch'}) eq 'ARRAY') {
3604: my $chgtext;
1.26 raeburn 3605: if (ref($usertypes) eq 'HASH') {
3606: if (keys(%{$usertypes}) > 0) {
3607: foreach my $type (@{$types}) {
3608: if (grep(/^\Q$type\E$/,@cansearch)) {
3609: $chgtext .= $usertypes->{$type}.'; ';
3610: }
3611: }
3612: if (grep(/^default$/,@cansearch)) {
3613: $chgtext .= $othertitle;
3614: } else {
3615: $chgtext =~ s/\; $//;
3616: }
3617: $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 3618: }
3619: }
3620: }
3621: if (ref($changes{'searchby'}) eq 'ARRAY') {
3622: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3623: my $chgtext;
3624: foreach my $type (@{$titleorder}) {
3625: if (grep(/^\Q$type\E$/,@searchby)) {
3626: if (defined($searchtitles->{$type})) {
3627: $chgtext .= $searchtitles->{$type}.'; ';
3628: }
3629: }
3630: }
3631: $chgtext =~ s/\; $//;
3632: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
3633: }
1.25 raeburn 3634: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
3635: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
3636: my $chgtext;
3637: foreach my $type (@{$srchtypeorder}) {
3638: if (grep(/^\Q$type\E$/,@searchtypes)) {
3639: if (defined($srchtypes_desc->{$type})) {
3640: $chgtext .= $srchtypes_desc->{$type}.'; ';
3641: }
3642: }
3643: }
3644: $chgtext =~ s/\; $//;
3645: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 3646: }
3647: $resulttext .= '</ul>';
3648: } else {
3649: $resulttext = &mt('No changes made to institution directory search settings');
3650: }
3651: } else {
3652: $resulttext = '<span class="LC_error">'.
1.27 raeburn 3653: &mt('An error occurred: [_1]',$putresult).'</span>';
3654: }
3655: return $resulttext;
3656: }
3657:
1.28 raeburn 3658: sub modify_contacts {
3659: my ($dom,%domconfig) = @_;
3660: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
3661: if (ref($domconfig{'contacts'}) eq 'HASH') {
3662: foreach my $key (keys(%{$domconfig{'contacts'}})) {
3663: $currsetting{$key} = $domconfig{'contacts'}{$key};
3664: }
3665: }
3666: my (%others,%to);
3667: my @contacts = ('supportemail','adminemail');
3668: my @mailings = ('errormail','packagesmail','helpdeskmail');
3669: foreach my $type (@mailings) {
3670: @{$newsetting{$type}} =
3671: &Apache::loncommon::get_env_multiple('form.'.$type);
3672: foreach my $item (@contacts) {
3673: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
3674: $contacts_hash{contacts}{$type}{$item} = 1;
3675: } else {
3676: $contacts_hash{contacts}{$type}{$item} = 0;
3677: }
3678: }
3679: $others{$type} = $env{'form.'.$type.'_others'};
3680: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
3681: }
3682: foreach my $item (@contacts) {
3683: $to{$item} = $env{'form.'.$item};
3684: $contacts_hash{'contacts'}{$item} = $to{$item};
3685: }
3686: if (keys(%currsetting) > 0) {
3687: foreach my $item (@contacts) {
3688: if ($to{$item} ne $currsetting{$item}) {
3689: $changes{$item} = 1;
3690: }
3691: }
3692: foreach my $type (@mailings) {
3693: foreach my $item (@contacts) {
3694: if (ref($currsetting{$type}) eq 'HASH') {
3695: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
3696: push(@{$changes{$type}},$item);
3697: }
3698: } else {
3699: push(@{$changes{$type}},@{$newsetting{$type}});
3700: }
3701: }
3702: if ($others{$type} ne $currsetting{$type}{'others'}) {
3703: push(@{$changes{$type}},'others');
3704: }
3705: }
3706: } else {
3707: my %default;
3708: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3709: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3710: $default{'errormail'} = 'adminemail';
3711: $default{'packagesmail'} = 'adminemail';
3712: $default{'helpdeskmail'} = 'supportemail';
3713: foreach my $item (@contacts) {
3714: if ($to{$item} ne $default{$item}) {
3715: $changes{$item} = 1;
3716: }
3717: }
3718: foreach my $type (@mailings) {
3719: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
3720:
3721: push(@{$changes{$type}},@{$newsetting{$type}});
3722: }
3723: if ($others{$type} ne '') {
3724: push(@{$changes{$type}},'others');
3725: }
3726: }
3727: }
3728: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
3729: $dom);
3730: if ($putresult eq 'ok') {
3731: if (keys(%changes) > 0) {
3732: my ($titles,$short_titles) = &contact_titles();
3733: $resulttext = &mt('Changes made:').'<ul>';
3734: foreach my $item (@contacts) {
3735: if ($changes{$item}) {
3736: $resulttext .= '<li>'.$titles->{$item}.
3737: &mt(' set to: ').
3738: '<span class="LC_cusr_emph">'.
3739: $to{$item}.'</span></li>';
3740: }
3741: }
3742: foreach my $type (@mailings) {
3743: if (ref($changes{$type}) eq 'ARRAY') {
3744: $resulttext .= '<li>'.$titles->{$type}.': ';
3745: my @text;
3746: foreach my $item (@{$newsetting{$type}}) {
3747: push(@text,$short_titles->{$item});
3748: }
3749: if ($others{$type} ne '') {
3750: push(@text,$others{$type});
3751: }
3752: $resulttext .= '<span class="LC_cusr_emph">'.
3753: join(', ',@text).'</span></li>';
3754: }
3755: }
3756: $resulttext .= '</ul>';
3757: } else {
1.34 raeburn 3758: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 3759: }
3760: } else {
3761: $resulttext = '<span class="LC_error">'.
3762: &mt('An error occurred: [_1].',$putresult).'</span>';
3763: }
3764: return $resulttext;
3765: }
3766:
3767: sub modify_usercreation {
1.27 raeburn 3768: my ($dom,%domconfig) = @_;
1.34 raeburn 3769: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 3770: my $warningmsg;
1.27 raeburn 3771: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3772: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
3773: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
3774: }
3775: }
3776: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 3777: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 3778: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.45 raeburn 3779: my @contexts = ('author','course','selfcreate');
1.34 raeburn 3780: foreach my $item(@contexts) {
1.45 raeburn 3781: if ($item eq 'selfcreate') {
1.50 raeburn 3782: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 3783: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
3784: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 3785: if (ref($cancreate{$item}) eq 'ARRAY') {
3786: if (grep(/^login$/,@{$cancreate{$item}})) {
3787: $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.');
3788: }
1.43 raeburn 3789: }
3790: }
1.50 raeburn 3791: } else {
3792: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 3793: }
1.34 raeburn 3794: }
3795: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
3796: foreach my $item (@contexts) {
1.50 raeburn 3797: if ($item eq 'selfcreate') {
3798: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
3799: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
3800: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
3801: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
3802: push(@{$changes{'cancreate'}},$item);
3803: }
3804: }
3805: }
3806: } else {
3807: if ($curr_usercreation{'cancreate'}{$item} eq '') {
3808: if (@{$cancreate{$item}} > 0) {
3809: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
3810: push(@{$changes{'cancreate'}},$item);
3811: }
3812: }
3813: } else {
3814: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
3815: if (@{$cancreate{$item}} < 3) {
3816: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
3817: push(@{$changes{'cancreate'}},$item);
3818: }
3819: }
3820: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
3821: if (@{$cancreate{$item}} > 0) {
3822: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
3823: push(@{$changes{'cancreate'}},$item);
3824: }
3825: }
3826: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
3827: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
3828: push(@{$changes{'cancreate'}},$item);
3829: }
3830: }
3831: }
3832: }
3833: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
3834: foreach my $type (@{$cancreate{$item}}) {
3835: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
3836: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
3837: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
3838: push(@{$changes{'cancreate'}},$item);
3839: }
3840: }
3841: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
3842: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
3843: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
3844: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
3845: push(@{$changes{'cancreate'}},$item);
3846: }
3847: }
3848: }
3849: }
3850: }
3851: } else {
3852: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
3853: push(@{$changes{'cancreate'}},$item);
3854: }
3855: }
1.27 raeburn 3856: }
1.34 raeburn 3857: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
3858: foreach my $item (@contexts) {
1.43 raeburn 3859: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 3860: if ($cancreate{$item} ne 'any') {
3861: push(@{$changes{'cancreate'}},$item);
3862: }
3863: } else {
3864: if ($cancreate{$item} ne 'none') {
3865: push(@{$changes{'cancreate'}},$item);
3866: }
1.27 raeburn 3867: }
3868: }
3869: } else {
1.43 raeburn 3870: foreach my $item (@contexts) {
1.34 raeburn 3871: push(@{$changes{'cancreate'}},$item);
3872: }
1.27 raeburn 3873: }
1.34 raeburn 3874:
1.27 raeburn 3875: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
3876: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
3877: if (!grep(/^\Q$type\E$/,@username_rule)) {
3878: push(@{$changes{'username_rule'}},$type);
3879: }
3880: }
3881: foreach my $type (@username_rule) {
3882: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
3883: push(@{$changes{'username_rule'}},$type);
3884: }
3885: }
3886: } else {
3887: push(@{$changes{'username_rule'}},@username_rule);
3888: }
3889:
1.32 raeburn 3890: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
3891: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
3892: if (!grep(/^\Q$type\E$/,@id_rule)) {
3893: push(@{$changes{'id_rule'}},$type);
3894: }
3895: }
3896: foreach my $type (@id_rule) {
3897: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
3898: push(@{$changes{'id_rule'}},$type);
3899: }
3900: }
3901: } else {
3902: push(@{$changes{'id_rule'}},@id_rule);
3903: }
3904:
1.43 raeburn 3905: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
3906: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
3907: if (!grep(/^\Q$type\E$/,@email_rule)) {
3908: push(@{$changes{'email_rule'}},$type);
3909: }
3910: }
3911: foreach my $type (@email_rule) {
3912: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
3913: push(@{$changes{'email_rule'}},$type);
3914: }
3915: }
3916: } else {
3917: push(@{$changes{'email_rule'}},@email_rule);
3918: }
3919:
3920: my @authen_contexts = ('author','course','domain');
1.28 raeburn 3921: my @authtypes = ('int','krb4','krb5','loc');
3922: my %authhash;
1.43 raeburn 3923: foreach my $item (@authen_contexts) {
1.28 raeburn 3924: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
3925: foreach my $auth (@authtypes) {
3926: if (grep(/^\Q$auth\E$/,@authallowed)) {
3927: $authhash{$item}{$auth} = 1;
3928: } else {
3929: $authhash{$item}{$auth} = 0;
3930: }
3931: }
3932: }
3933: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 3934: foreach my $item (@authen_contexts) {
1.28 raeburn 3935: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
3936: foreach my $auth (@authtypes) {
3937: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
3938: push(@{$changes{'authtypes'}},$item);
3939: last;
3940: }
3941: }
3942: }
3943: }
3944: } else {
1.43 raeburn 3945: foreach my $item (@authen_contexts) {
1.28 raeburn 3946: push(@{$changes{'authtypes'}},$item);
3947: }
3948: }
3949:
1.27 raeburn 3950: my %usercreation_hash = (
1.28 raeburn 3951: usercreation => {
1.34 raeburn 3952: cancreate => \%cancreate,
1.27 raeburn 3953: username_rule => \@username_rule,
1.32 raeburn 3954: id_rule => \@id_rule,
1.43 raeburn 3955: email_rule => \@email_rule,
1.32 raeburn 3956: authtypes => \%authhash,
1.27 raeburn 3957: }
3958: );
3959:
3960: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
3961: $dom);
1.50 raeburn 3962:
3963: my %selfcreatetypes = (
3964: sso => 'users authenticated by institutional single sign on',
3965: login => 'users authenticated by institutional log-in',
3966: email => 'users who provide a valid e-mail address for use as the username',
3967: );
1.27 raeburn 3968: if ($putresult eq 'ok') {
3969: if (keys(%changes) > 0) {
3970: $resulttext = &mt('Changes made:').'<ul>';
3971: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 3972: my %lt = &usercreation_types();
3973: foreach my $type (@{$changes{'cancreate'}}) {
1.43 raeburn 3974: my $chgtext = $lt{$type}.', ';
1.45 raeburn 3975: if ($type eq 'selfcreate') {
1.50 raeburn 3976: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 3977: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 3978: } else {
3979: $chgtext .= &mt('creation of a new account is permitted for:<ul>');
3980: foreach my $case (@{$cancreate{$type}}) {
3981: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
3982: }
3983: $chgtext .= '</ul>';
1.43 raeburn 3984: }
3985: } else {
3986: if ($cancreate{$type} eq 'none') {
3987: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
3988: } elsif ($cancreate{$type} eq 'any') {
3989: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
3990: } elsif ($cancreate{$type} eq 'official') {
3991: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
3992: } elsif ($cancreate{$type} eq 'unofficial') {
3993: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
3994: }
1.34 raeburn 3995: }
3996: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 3997: }
3998: }
3999: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 4000: my ($rules,$ruleorder) =
4001: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 4002: my $chgtext = '<ul>';
4003: foreach my $type (@username_rule) {
4004: if (ref($rules->{$type}) eq 'HASH') {
4005: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
4006: }
4007: }
4008: $chgtext .= '</ul>';
4009: if (@username_rule > 0) {
4010: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4011: } else {
1.28 raeburn 4012: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 4013: }
4014: }
1.32 raeburn 4015: if (ref($changes{'id_rule'}) eq 'ARRAY') {
4016: my ($idrules,$idruleorder) =
4017: &Apache::lonnet::inst_userrules($dom,'id');
4018: my $chgtext = '<ul>';
4019: foreach my $type (@id_rule) {
4020: if (ref($idrules->{$type}) eq 'HASH') {
4021: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
4022: }
4023: }
4024: $chgtext .= '</ul>';
4025: if (@id_rule > 0) {
4026: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4027: } else {
4028: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
4029: }
4030: }
1.43 raeburn 4031: if (ref($changes{'email_rule'}) eq 'ARRAY') {
4032: my ($emailrules,$emailruleorder) =
4033: &Apache::lonnet::inst_userrules($dom,'email');
4034: my $chgtext = '<ul>';
4035: foreach my $type (@email_rule) {
4036: if (ref($emailrules->{$type}) eq 'HASH') {
4037: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
4038: }
4039: }
4040: $chgtext .= '</ul>';
4041: if (@email_rule > 0) {
4042: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
4043: } else {
4044: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
4045: }
4046: }
4047:
1.28 raeburn 4048: my %authname = &authtype_names();
4049: my %context_title = &context_names();
4050: if (ref($changes{'authtypes'}) eq 'ARRAY') {
4051: my $chgtext = '<ul>';
4052: foreach my $type (@{$changes{'authtypes'}}) {
4053: my @allowed;
4054: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
4055: foreach my $auth (@authtypes) {
4056: if ($authhash{$type}{$auth}) {
4057: push(@allowed,$authname{$auth});
4058: }
4059: }
1.43 raeburn 4060: if (@allowed > 0) {
4061: $chgtext .= join(', ',@allowed).'</li>';
4062: } else {
4063: $chgtext .= &mt('none').'</li>';
4064: }
1.28 raeburn 4065: }
4066: $chgtext .= '</ul>';
4067: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
4068: $resulttext .= '</li>';
4069: }
1.27 raeburn 4070: $resulttext .= '</ul>';
4071: } else {
1.28 raeburn 4072: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 4073: }
4074: } else {
4075: $resulttext = '<span class="LC_error">'.
1.23 raeburn 4076: &mt('An error occurred: [_1]',$putresult).'</span>';
4077: }
1.43 raeburn 4078: if ($warningmsg ne '') {
4079: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
4080: }
1.23 raeburn 4081: return $resulttext;
4082: }
4083:
1.33 raeburn 4084: sub modify_usermodification {
4085: my ($dom,%domconfig) = @_;
4086: my ($resulttext,%curr_usermodification,%changes);
4087: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4088: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
4089: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
4090: }
4091: }
4092: my @contexts = ('author','course');
4093: my %context_title = (
4094: author => 'In author context',
4095: course => 'In course context',
4096: );
4097: my @fields = ('lastname','firstname','middlename','generation',
4098: 'permanentemail','id');
4099: my %roles = (
4100: author => ['ca','aa'],
4101: course => ['st','ep','ta','in','cr'],
4102: );
4103: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4104: my %modifyhash;
4105: foreach my $context (@contexts) {
4106: foreach my $role (@{$roles{$context}}) {
4107: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
4108: foreach my $item (@fields) {
4109: if (grep(/^\Q$item\E$/,@modifiable)) {
4110: $modifyhash{$context}{$role}{$item} = 1;
4111: } else {
4112: $modifyhash{$context}{$role}{$item} = 0;
4113: }
4114: }
4115: }
4116: if (ref($curr_usermodification{$context}) eq 'HASH') {
4117: foreach my $role (@{$roles{$context}}) {
4118: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
4119: foreach my $field (@fields) {
4120: if ($modifyhash{$context}{$role}{$field} ne
4121: $curr_usermodification{$context}{$role}{$field}) {
4122: push(@{$changes{$context}},$role);
4123: last;
4124: }
4125: }
4126: }
4127: }
4128: } else {
4129: foreach my $context (@contexts) {
4130: foreach my $role (@{$roles{$context}}) {
4131: push(@{$changes{$context}},$role);
4132: }
4133: }
4134: }
4135: }
4136: my %usermodification_hash = (
4137: usermodification => \%modifyhash,
4138: );
4139: my $putresult = &Apache::lonnet::put_dom('configuration',
4140: \%usermodification_hash,$dom);
4141: if ($putresult eq 'ok') {
4142: if (keys(%changes) > 0) {
4143: $resulttext = &mt('Changes made: ').'<ul>';
4144: foreach my $context (@contexts) {
4145: if (ref($changes{$context}) eq 'ARRAY') {
4146: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
4147: if (ref($changes{$context}) eq 'ARRAY') {
4148: foreach my $role (@{$changes{$context}}) {
4149: my $rolename;
4150: if ($role eq 'cr') {
4151: $rolename = &mt('Custom');
4152: } else {
4153: $rolename = &Apache::lonnet::plaintext($role);
4154: }
4155: my @modifiable;
4156: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
4157: foreach my $field (@fields) {
4158: if ($modifyhash{$context}{$role}{$field}) {
4159: push(@modifiable,$fieldtitles{$field});
4160: }
4161: }
4162: if (@modifiable > 0) {
4163: $resulttext .= join(', ',@modifiable);
4164: } else {
4165: $resulttext .= &mt('none');
4166: }
4167: $resulttext .= '</li>';
4168: }
4169: $resulttext .= '</ul></li>';
4170: }
4171: }
4172: }
4173: $resulttext .= '</ul>';
4174: } else {
4175: $resulttext = &mt('No changes made to user modification settings');
4176: }
4177: } else {
4178: $resulttext = '<span class="LC_error">'.
4179: &mt('An error occurred: [_1]',$putresult).'</span>';
4180: }
4181: return $resulttext;
4182: }
4183:
1.43 raeburn 4184: sub modify_defaults {
4185: my ($dom,$r) = @_;
4186: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
4187: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.54 raeburn 4188: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');
1.43 raeburn 4189: my @authtypes = ('internal','krb4','krb5','localauth');
4190: foreach my $item (@items) {
4191: $newvalues{$item} = $env{'form.'.$item};
4192: if ($item eq 'auth_def') {
4193: if ($newvalues{$item} ne '') {
4194: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
4195: push(@errors,$item);
4196: }
4197: }
4198: } elsif ($item eq 'lang_def') {
4199: if ($newvalues{$item} ne '') {
4200: if ($newvalues{$item} =~ /^(\w+)/) {
4201: my $langcode = $1;
4202: if (code2language($langcode) eq '') {
4203: push(@errors,$item);
4204: }
4205: } else {
4206: push(@errors,$item);
4207: }
4208: }
1.54 raeburn 4209: } elsif ($item eq 'timezone_def') {
4210: if ($newvalues{$item} ne '') {
4211: my @timezones = &DateTime::TimeZone->all_names;
4212: if (!grep(/^\Q$newvalues{$item}\E/,@timezones)) {
4213: push(@errors,$item);
4214: }
4215: }
1.43 raeburn 4216: }
4217: if (grep(/^\Q$item\E$/,@errors)) {
4218: $newvalues{$item} = $domdefaults{$item};
4219: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
4220: $changes{$item} = 1;
4221: }
4222: }
4223: my %defaults_hash = (
4224: defaults => { auth_def => $newvalues{'auth_def'},
4225: auth_arg_def => $newvalues{'auth_arg_def'},
4226: lang_def => $newvalues{'lang_def'},
1.54 raeburn 4227: timezone_def => $newvalues{'timezone_def'},
1.43 raeburn 4228: }
4229: );
4230: my $title = &defaults_titles();
4231: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
4232: $dom);
4233: if ($putresult eq 'ok') {
4234: if (keys(%changes) > 0) {
4235: $resulttext = &mt('Changes made:').'<ul>';
4236: my $version = $r->dir_config('lonVersion');
4237: 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";
4238: foreach my $item (sort(keys(%changes))) {
4239: my $value = $env{'form.'.$item};
4240: if ($value eq '') {
4241: $value = &mt('none');
4242: } elsif ($item eq 'auth_def') {
4243: my %authnames = &authtype_names();
4244: my %shortauth = (
4245: internal => 'int',
4246: krb4 => 'krb4',
4247: krb5 => 'krb5',
4248: localauth => 'loc',
4249: );
4250: $value = $authnames{$shortauth{$value}};
4251: }
4252: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
4253: $mailmsgtext .= "$title->{$item} set to $value\n";
4254: }
4255: $resulttext .= '</ul>';
4256: $mailmsgtext .= "\n";
4257: my $cachetime = 24*60*60;
4258: &Apache::lonnet::do_cache_new('domdefaults',$dom,
4259: $defaults_hash{'defaults'},$cachetime);
1.54 raeburn 4260: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'}) {
4261: my $sysmail = $r->dir_config('lonSysEMail');
4262: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
4263: }
1.43 raeburn 4264: } else {
1.54 raeburn 4265: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 4266: }
4267: } else {
4268: $resulttext = '<span class="LC_error">'.
4269: &mt('An error occurred: [_1]',$putresult).'</span>';
4270: }
4271: if (@errors > 0) {
4272: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
4273: foreach my $item (@errors) {
4274: $resulttext .= ' "'.$title->{$item}.'",';
4275: }
4276: $resulttext =~ s/,$//;
4277: }
4278: return $resulttext;
4279: }
4280:
1.46 raeburn 4281: sub modify_scantron {
1.48 raeburn 4282: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 4283: my ($resulttext,%confhash,%changes,$errors);
4284: my $custom = 'custom.tab';
4285: my $default = 'default.tab';
4286: my $servadm = $r->dir_config('lonAdmEMail');
4287: my ($configuserok,$author_ok,$switchserver) =
4288: &config_check($dom,$confname,$servadm);
4289: if ($env{'form.scantronformat.filename'} ne '') {
4290: my $error;
4291: if ($configuserok eq 'ok') {
4292: if ($switchserver) {
4293: $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
4294: } else {
4295: if ($author_ok eq 'ok') {
4296: my ($result,$scantronurl) =
4297: &publishlogo($r,'upload','scantronformat',$dom,
4298: $confname,'scantron','','',$custom);
4299: if ($result eq 'ok') {
4300: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 4301: $changes{'scantronformat'} = 1;
1.46 raeburn 4302: } else {
4303: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
4304: }
4305: } else {
4306: $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);
4307: }
4308: }
4309: } else {
4310: $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);
4311: }
4312: if ($error) {
4313: &Apache::lonnet::logthis($error);
4314: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4315: }
4316: }
1.48 raeburn 4317: if (ref($domconfig{'scantron'}) eq 'HASH') {
4318: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
4319: if ($env{'form.scantronformat_del'}) {
4320: $confhash{'scantron'}{'scantronformat'} = '';
4321: $changes{'scantronformat'} = 1;
1.46 raeburn 4322: }
4323: }
4324: }
4325: if (keys(%confhash) > 0) {
4326: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
4327: $dom);
4328: if ($putresult eq 'ok') {
4329: if (keys(%changes) > 0) {
1.48 raeburn 4330: if (ref($confhash{'scantron'}) eq 'HASH') {
4331: $resulttext = &mt('Changes made:').'<ul>';
4332: if ($confhash{'scantron'}{'scantronformat'} eq '') {
4333: $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
4334: } else {
4335: $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 4336: }
1.48 raeburn 4337: $resulttext .= '</ul>';
4338: } else {
4339: $resulttext = &mt('Changes made to scantron format file.');
1.46 raeburn 4340: }
4341: $resulttext .= '</ul>';
4342: &Apache::loncommon::devalidate_domconfig_cache($dom);
4343: } else {
4344: $resulttext = &mt('No changes made to scantron format file');
4345: }
4346: } else {
4347: $resulttext = '<span class="LC_error">'.
4348: &mt('An error occurred: [_1]',$putresult).'</span>';
4349: }
4350: } else {
4351: $resulttext = &mt('No changes made to scantron format file');
4352: }
4353: if ($errors) {
4354: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4355: $errors.'</ul>';
4356: }
4357: return $resulttext;
4358: }
4359:
1.48 raeburn 4360: sub modify_coursecategories {
4361: my ($dom,%domconfig) = @_;
1.57 raeburn 4362: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
4363: $cathash);
1.48 raeburn 4364: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 4365: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 4366: $cathash = $domconfig{'coursecategories'}{'cats'};
4367: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
4368: $changes{'togglecats'} = 1;
4369: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
4370: }
4371: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
4372: $changes{'categorize'} = 1;
4373: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
4374: }
4375: } else {
4376: $changes{'togglecats'} = 1;
4377: $changes{'categorize'} = 1;
4378: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
4379: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
4380: }
4381: if (ref($cathash) eq 'HASH') {
4382: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 4383: push (@deletecategory,'instcode::0');
4384: }
1.48 raeburn 4385: }
1.57 raeburn 4386: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
4387: if (ref($cathash) eq 'HASH') {
1.48 raeburn 4388: if (@deletecategory > 0) {
4389: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 4390: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 4391: foreach my $item (@deletecategory) {
1.57 raeburn 4392: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
4393: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 4394: $deletions{$item} = 1;
1.57 raeburn 4395: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 4396: }
4397: }
4398: }
1.57 raeburn 4399: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 4400: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 4401: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 4402: $reorderings{$item} = 1;
1.57 raeburn 4403: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 4404: }
4405: if ($env{'form.addcategory_name_'.$item} ne '') {
4406: my $newcat = $env{'form.addcategory_name_'.$item};
4407: my $newdepth = $depth+1;
4408: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 4409: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 4410: $adds{$newitem} = 1;
4411: }
4412: if ($env{'form.subcat_'.$item} ne '') {
4413: my $newcat = $env{'form.subcat_'.$item};
4414: my $newdepth = $depth+1;
4415: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 4416: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 4417: $adds{$newitem} = 1;
4418: }
4419: }
4420: }
4421: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 4422: if (ref($cathash) eq 'HASH') {
1.48 raeburn 4423: my $newitem = 'instcode::0';
1.57 raeburn 4424: if ($cathash->{$newitem} eq '') {
4425: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 4426: $adds{$newitem} = 1;
4427: }
4428: } else {
4429: my $newitem = 'instcode::0';
1.57 raeburn 4430: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 4431: $adds{$newitem} = 1;
4432: }
4433: }
4434: if ($env{'form.addcategory_name'} ne '') {
4435: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
1.57 raeburn 4436: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
1.48 raeburn 4437: $adds{$newitem} = 1;
4438: }
1.57 raeburn 4439: my $putresult;
1.48 raeburn 4440: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4441: if (keys(%deletions) > 0) {
4442: foreach my $key (keys(%deletions)) {
4443: if ($predelallitems{$key} ne '') {
4444: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
4445: }
4446: }
4447: }
4448: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 4449: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 4450: if (ref($chkcats[0]) eq 'ARRAY') {
4451: my $depth = 0;
4452: my $chg = 0;
4453: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
4454: my $name = $chkcats[0][$i];
4455: my $item;
4456: if ($name eq '') {
4457: $chg ++;
4458: } else {
4459: $item = &escape($name).'::0';
4460: if ($chg) {
1.57 raeburn 4461: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 4462: }
4463: $depth ++;
1.57 raeburn 4464: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 4465: $depth --;
4466: }
4467: }
4468: }
1.57 raeburn 4469: }
4470: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4471: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 4472: if ($putresult eq 'ok') {
1.57 raeburn 4473: my %title = (
4474: togglecats => 'Show/Hide a course in the catalog',
4475: categorize => 'Category assigned to course',
4476: );
4477: my %level = (
4478: dom => 'set from "Modify Course" (Domain)',
4479: crs => 'set from "Parameters" (Course)',
4480: );
1.48 raeburn 4481: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 4482: if ($changes{'togglecats'}) {
4483: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
4484: }
4485: if ($changes{'categorize'}) {
4486: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 4487: }
1.57 raeburn 4488: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4489: my $cathash;
4490: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
4491: $cathash = $domconfig{'coursecategories'}{'cats'};
4492: } else {
4493: $cathash = {};
4494: }
4495: my (@cats,@trails,%allitems);
4496: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
4497: if (keys(%deletions) > 0) {
4498: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
4499: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
4500: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
4501: }
4502: $resulttext .= '</ul></li>';
4503: }
4504: if (keys(%reorderings) > 0) {
4505: my %sort_by_trail;
4506: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
4507: foreach my $key (keys(%reorderings)) {
4508: if ($allitems{$key} ne '') {
4509: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
4510: }
1.48 raeburn 4511: }
1.57 raeburn 4512: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
4513: $resulttext .= '<li>'.$trails[$trail].'</li>';
4514: }
4515: $resulttext .= '</ul></li>';
1.48 raeburn 4516: }
1.57 raeburn 4517: if (keys(%adds) > 0) {
4518: my %sort_by_trail;
4519: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
4520: foreach my $key (keys(%adds)) {
4521: if ($allitems{$key} ne '') {
4522: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
4523: }
4524: }
4525: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
4526: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 4527: }
1.57 raeburn 4528: $resulttext .= '</ul></li>';
1.48 raeburn 4529: }
4530: }
4531: $resulttext .= '</ul>';
4532: } else {
4533: $resulttext = '<span class="LC_error">'.
1.57 raeburn 4534: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 4535: }
4536: } else {
4537: $resulttext = &mt('No changes made to course categories');
4538: }
4539: return $resulttext;
4540: }
4541:
4542: sub recurse_check {
4543: my ($chkcats,$categories,$depth,$name) = @_;
4544: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
4545: my $chg = 0;
4546: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
4547: my $category = $chkcats->[$depth]{$name}[$j];
4548: my $item;
4549: if ($category eq '') {
4550: $chg ++;
4551: } else {
4552: my $deeper = $depth + 1;
4553: $item = &escape($category).':'.&escape($name).':'.$depth;
4554: if ($chg) {
4555: $categories->{$item} -= $chg;
4556: }
4557: &recurse_check($chkcats,$categories,$deeper,$category);
4558: $deeper --;
4559: }
4560: }
4561: }
4562: return;
4563: }
4564:
4565: sub recurse_cat_deletes {
4566: my ($item,$coursecategories,$deletions) = @_;
4567: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
4568: my $subdepth = $depth + 1;
4569: if (ref($coursecategories) eq 'HASH') {
4570: foreach my $subitem (keys(%{$coursecategories})) {
4571: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
4572: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
4573: delete($coursecategories->{$subitem});
4574: $deletions->{$subitem} = 1;
4575: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
4576: }
4577: }
4578: }
4579: return;
4580: }
4581:
1.3 raeburn 4582: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>