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