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