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