Annotation of loncom/interface/domainprefs.pm, revision 1.77
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.77 ! raeburn 4: # $Id: domainprefs.pm,v 1.76 2008/12/11 13:53:44 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.69 raeburn 42: use LONCAPA::loncgi();
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;
1249: if (ref($settings->{defaultquota}) eq 'HASH') {
1250: $currdefquota = $settings->{defaultquota}->{$type};
1251: } else {
1252: $currdefquota = $settings->{$type};
1253: }
1.3 raeburn 1254: if (defined($usertypes->{$type})) {
1255: $typecount ++;
1256: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1257: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1258: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1259: '<td class="LC_left_item">';
1260: foreach my $item (@usertools) {
1261: my $checked = 'checked="checked" ';
1262: if (ref($settings->{$item}) eq 'HASH') {
1263: if ($settings->{$item}->{$type} == 0) {
1264: $checked = '';
1265: }
1266: }
1267: $datatable .= '<span class="LC_nobreak"><label>'.
1268: '<input type="checkbox" name="tools_'.$item.
1269: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1270: '</label></span> ';
1271: }
1272: $datatable .= '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1273: '<input type="text" name="quota_'.$type.
1.72 raeburn 1274: '" value="'.$currdefquota.
1.8 raeburn 1275: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 1276: }
1277: }
1278: }
1279: my $defaultquota = '20';
1280: if (ref($settings) eq 'HASH') {
1.72 raeburn 1281: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1282: $defaultquota = $settings->{'defaultquota'}->{'default'};
1283: } elsif (defined($settings->{'default'})) {
1.3 raeburn 1284: $defaultquota = $settings->{'default'};
1285: }
1286: }
1287: $typecount ++;
1288: $css_class = $typecount%2?' class="LC_odd_row"':'';
1289: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1290: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1291: '<td class="LC_left_item">';
1292: foreach my $item (@usertools) {
1293: my $checked = 'checked="checked" ';
1294: if (ref($settings->{$item}) eq 'HASH') {
1295: if ($settings->{$item}->{'default'} == 0) {
1296: $checked = '';
1297: }
1298: }
1299: $datatable .= '<span class="LC_nobreak"><label>'.
1300: '<input type="checkbox" name="tools_'.$item.
1301: '" value="default" '.$checked.'/>'.$titles{$item}.
1302: '</label></span> ';
1303: }
1304: $datatable .= '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.15 raeburn 1305: '<input type="text" name="defaultquota" value="'.
1.8 raeburn 1306: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.72 raeburn 1307: $typecount ++;
1308: $css_class = $typecount%2?' class="LC_odd_row"':'';
1309: $datatable .= '<tr'.$css_class.'>'.
1310: '<td><br/>'.&mt('LON-CAPA Advanced Users').'</td>'.
1311: '<td class="LC_left_item" colspan="2"><br />';
1312: foreach my $item (@usertools) {
1313: my $checked = 'checked="checked" ';
1314: if (ref($settings->{$item}) eq 'HASH') {
1315: if ($settings->{$item}->{'_LC_adv'} == 0) {
1316: $checked = '';
1317: }
1318: }
1319: $datatable .= '<span class="LC_nobreak"><label>'.
1320: '<input type="checkbox" name="tools_'.$item.
1321: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1322: '</label></span> ';
1323: }
1.77 ! raeburn 1324: $datatable .= '<span class="LC_nobreak">('.&mt('overrides affiliation').
! 1325: ')</span</td></tr>';
1.30 raeburn 1326: $$rowtotal += $typecount;
1.3 raeburn 1327: return $datatable;
1328: }
1329:
1330: sub print_autoenroll {
1.30 raeburn 1331: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1332: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 1333: my ($defdom,$runon,$runoff);
1.3 raeburn 1334: if (ref($settings) eq 'HASH') {
1335: if (exists($settings->{'run'})) {
1336: if ($settings->{'run'} eq '0') {
1337: $runoff = ' checked="checked" ';
1338: $runon = ' ';
1339: } else {
1340: $runon = ' checked="checked" ';
1341: $runoff = ' ';
1342: }
1343: } else {
1344: if ($autorun) {
1345: $runon = ' checked="checked" ';
1346: $runoff = ' ';
1347: } else {
1348: $runoff = ' checked="checked" ';
1349: $runon = ' ';
1350: }
1351: }
1352: if (exists($settings->{'sender_domain'})) {
1353: $defdom = $settings->{'sender_domain'};
1354: }
1.14 raeburn 1355: } else {
1356: if ($autorun) {
1357: $runon = ' checked="checked" ';
1358: $runoff = ' ';
1359: } else {
1360: $runoff = ' checked="checked" ';
1361: $runon = ' ';
1362: }
1.3 raeburn 1363: }
1364: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1365: my $notif_sender;
1366: if (ref($settings) eq 'HASH') {
1367: $notif_sender = $settings->{'sender_uname'};
1368: }
1.3 raeburn 1369: my $datatable='<tr class="LC_odd_row">'.
1370: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1371: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1372: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1373: $runon.' value="1" />'.&mt('Yes').'</label> '.
1374: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1375: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1376: '</tr><tr>'.
1377: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1378: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1379: &mt('username').': '.
1380: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1381: $notif_sender.'" size="10" /> '.&mt('domain').
1.8 raeburn 1382: ': '.$domform.'</span></td></tr>';
1.30 raeburn 1383: $$rowtotal += 2;
1.3 raeburn 1384: return $datatable;
1385: }
1386:
1387: sub print_autoupdate {
1.30 raeburn 1388: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1389: my $datatable;
1390: if ($position eq 'top') {
1391: my $updateon = ' ';
1392: my $updateoff = ' checked="checked" ';
1393: my $classlistson = ' ';
1394: my $classlistsoff = ' checked="checked" ';
1395: if (ref($settings) eq 'HASH') {
1396: if ($settings->{'run'} eq '1') {
1397: $updateon = $updateoff;
1398: $updateoff = ' ';
1399: }
1400: if ($settings->{'classlists'} eq '1') {
1401: $classlistson = $classlistsoff;
1402: $classlistsoff = ' ';
1403: }
1404: }
1405: my %title = (
1406: run => 'Auto-update active?',
1407: classlists => 'Update information in classlists?',
1408: );
1409: $datatable = '<tr class="LC_odd_row">'.
1410: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1411: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1412: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1413: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1414: '<label><input type="radio" name="autoupdate_run"'.
1415: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1416: '</tr><tr>'.
1417: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1418: '<td class="LC_right_item"><span class="LC_nobreak">'.
1419: '<label><input type="radio" name="classlists"'.
1420: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1421: '<label><input type="radio" name="classlists"'.
1422: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1423: '</tr>';
1.30 raeburn 1424: $$rowtotal += 2;
1.3 raeburn 1425: } else {
1.44 raeburn 1426: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.20 raeburn 1427: my @fields = ('lastname','firstname','middlename','gen',
1428: 'permanentemail','id');
1.33 raeburn 1429: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1430: my $numrows = 0;
1.26 raeburn 1431: if (ref($types) eq 'ARRAY') {
1432: if (@{$types} > 0) {
1433: $datatable =
1434: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1435: \@fields,$types,\$numrows);
1.30 raeburn 1436: $$rowtotal += @{$types};
1.26 raeburn 1437: }
1.3 raeburn 1438: }
1439: $datatable .=
1440: &usertype_update_row($settings,{'default' => $othertitle},
1441: \%fieldtitles,\@fields,['default'],
1442: \$numrows);
1.30 raeburn 1443: $$rowtotal ++;
1.3 raeburn 1444: }
1445: return $datatable;
1446: }
1447:
1.23 raeburn 1448: sub print_directorysrch {
1.30 raeburn 1449: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1450: my $srchon = ' ';
1451: my $srchoff = ' checked="checked" ';
1.25 raeburn 1452: my ($exacton,$containson,$beginson);
1.24 raeburn 1453: my $localon = ' ';
1454: my $localoff = ' checked="checked" ';
1.23 raeburn 1455: if (ref($settings) eq 'HASH') {
1456: if ($settings->{'available'} eq '1') {
1457: $srchon = $srchoff;
1458: $srchoff = ' ';
1459: }
1.24 raeburn 1460: if ($settings->{'localonly'} eq '1') {
1461: $localon = $localoff;
1462: $localoff = ' ';
1463: }
1.25 raeburn 1464: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1465: foreach my $type (@{$settings->{'searchtypes'}}) {
1466: if ($type eq 'exact') {
1467: $exacton = ' checked="checked" ';
1468: } elsif ($type eq 'contains') {
1469: $containson = ' checked="checked" ';
1470: } elsif ($type eq 'begins') {
1471: $beginson = ' checked="checked" ';
1472: }
1473: }
1474: } else {
1475: if ($settings->{'searchtypes'} eq 'exact') {
1476: $exacton = ' checked="checked" ';
1477: } elsif ($settings->{'searchtypes'} eq 'contains') {
1478: $containson = ' checked="checked" ';
1479: } elsif ($settings->{'searchtypes'} eq 'specify') {
1480: $exacton = ' checked="checked" ';
1481: $containson = ' checked="checked" ';
1482: }
1.23 raeburn 1483: }
1484: }
1485: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1486: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1487:
1488: my $numinrow = 4;
1.26 raeburn 1489: my $cansrchrow = 0;
1.23 raeburn 1490: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1491: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1492: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1493: '<input type="radio" name="dirsrch_available"'.
1494: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1495: '<label><input type="radio" name="dirsrch_available"'.
1496: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1497: '</tr><tr>'.
1.30 raeburn 1498: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1499: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1500: '<input type="radio" name="dirsrch_localonly"'.
1501: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1502: '<label><input type="radio" name="dirsrch_localonly"'.
1503: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1504: '</tr>';
1.30 raeburn 1505: $$rowtotal += 2;
1.26 raeburn 1506: if (ref($usertypes) eq 'HASH') {
1507: if (keys(%{$usertypes}) > 0) {
1508: $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
1509: $numinrow,$othertitle);
1510: $cansrchrow = 1;
1511: }
1512: }
1513: if ($cansrchrow) {
1.30 raeburn 1514: $$rowtotal ++;
1.26 raeburn 1515: $datatable .= '<tr>';
1516: } else {
1517: $datatable .= '<tr class="LC_odd_row">';
1518: }
1.30 raeburn 1519: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1520: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1521: foreach my $title (@{$titleorder}) {
1522: if (defined($searchtitles->{$title})) {
1523: my $check = ' ';
1.39 raeburn 1524: if (ref($settings) eq 'HASH') {
1525: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1526: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1527: $check = ' checked="checked" ';
1528: }
1.25 raeburn 1529: }
1530: }
1531: $datatable .= '<td class="LC_left_item">'.
1532: '<span class="LC_nobreak"><label>'.
1533: '<input type="checkbox" name="searchby" '.
1534: 'value="'.$title.'"'.$check.'/>'.
1535: $searchtitles->{$title}.'</label></span></td>';
1536: }
1537: }
1.26 raeburn 1538: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1539: $$rowtotal ++;
1.26 raeburn 1540: if ($cansrchrow) {
1541: $datatable .= '<tr class="LC_odd_row">';
1542: } else {
1543: $datatable .= '<tr>';
1544: }
1.30 raeburn 1545: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 1546: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1547: '<span class="LC_nobreak"><label>'.
1548: '<input type="checkbox" name="searchtypes" '.
1549: $exacton.' value="exact" />'.&mt('Exact match').
1550: '</label> '.
1551: '<label><input type="checkbox" name="searchtypes" '.
1552: $beginson.' value="begins" />'.&mt('Begins with').
1553: '</label> '.
1554: '<label><input type="checkbox" name="searchtypes" '.
1555: $containson.' value="contains" />'.&mt('Contains').
1556: '</label></span></td></tr>';
1.30 raeburn 1557: $$rowtotal ++;
1.25 raeburn 1558: return $datatable;
1559: }
1560:
1.28 raeburn 1561: sub print_contacts {
1.30 raeburn 1562: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 1563: my $datatable;
1564: my @contacts = ('adminemail','supportemail');
1565: my (%checked,%to,%otheremails);
1566: my @mailings = ('errormail','packagesmail','helpdeskmail');
1567: foreach my $type (@mailings) {
1568: $otheremails{$type} = '';
1569: }
1570: if (ref($settings) eq 'HASH') {
1571: foreach my $item (@contacts) {
1572: if (exists($settings->{$item})) {
1573: $to{$item} = $settings->{$item};
1574: }
1575: }
1576: foreach my $type (@mailings) {
1577: if (exists($settings->{$type})) {
1578: if (ref($settings->{$type}) eq 'HASH') {
1579: foreach my $item (@contacts) {
1580: if ($settings->{$type}{$item}) {
1581: $checked{$type}{$item} = ' checked="checked" ';
1582: }
1583: }
1584: $otheremails{$type} = $settings->{$type}{'others'};
1585: }
1586: }
1587: }
1588: } else {
1589: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1590: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1591: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1592: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1593: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
1594: }
1595: my ($titles,$short_titles) = &contact_titles();
1596: my $rownum = 0;
1597: my $css_class;
1598: foreach my $item (@contacts) {
1.69 raeburn 1599: $rownum ++;
1600: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 1601: $datatable .= '<tr'.$css_class.'>'.
1602: '<td><span class="LC_nobreak">'.$titles->{$item}.
1603: '</span></td><td class="LC_right_item">'.
1.28 raeburn 1604: '<input type="text" name="'.$item.'" value="'.
1605: $to{$item}.'" /></td></tr>';
1606: }
1607: foreach my $type (@mailings) {
1.69 raeburn 1608: $rownum ++;
1609: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 1610: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 1611: '<td><span class="LC_nobreak">'.
1612: $titles->{$type}.': </span></td>'.
1.28 raeburn 1613: '<td class="LC_left_item">'.
1614: '<span class="LC_nobreak">';
1615: foreach my $item (@contacts) {
1616: $datatable .= '<label>'.
1617: '<input type="checkbox" name="'.$type.'"'.
1618: $checked{$type}{$item}.
1619: ' value="'.$item.'" />'.$short_titles->{$item}.
1620: '</label> ';
1621: }
1622: $datatable .= '</span><br />'.&mt('Others').': '.
1623: '<input type="text" name="'.$type.'_others" '.
1624: 'value="'.$otheremails{$type}.'" />'.
1625: '</td></tr>'."\n";
1626: }
1.30 raeburn 1627: $$rowtotal += $rownum;
1.28 raeburn 1628: return $datatable;
1629: }
1630:
1631: sub contact_titles {
1632: my %titles = &Apache::lonlocal::texthash (
1633: 'supportemail' => 'Support E-mail address',
1.69 raeburn 1634: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 1635: 'errormail' => 'Error reports to be e-mailed to',
1636: 'packagesmail' => 'Package update alerts to be e-mailed to',
1637: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
1638: );
1639: my %short_titles = &Apache::lonlocal::texthash (
1640: adminemail => 'Admin E-mail address',
1641: supportemail => 'Support E-mail',
1642: );
1643: return (\%titles,\%short_titles);
1644: }
1645:
1.72 raeburn 1646: sub tool_titles {
1647: my %titles = &Apache::lonlocal::texthash (
1648: aboutme => 'Personal Home Page',
1649: blog => 'Blog',
1650: portfolio => 'Portfolio',
1651: );
1652: return %titles;
1653: }
1654:
1.27 raeburn 1655: sub print_usercreation {
1.30 raeburn 1656: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 1657: my $numinrow = 4;
1.28 raeburn 1658: my $datatable;
1659: if ($position eq 'top') {
1.30 raeburn 1660: $$rowtotal ++;
1.34 raeburn 1661: my $rowcount = 0;
1.32 raeburn 1662: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 1663: if (ref($rules) eq 'HASH') {
1664: if (keys(%{$rules}) > 0) {
1.32 raeburn 1665: $datatable .= &user_formats_row('username',$settings,$rules,
1666: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 1667: $$rowtotal ++;
1.32 raeburn 1668: $rowcount ++;
1669: }
1670: }
1671: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
1672: if (ref($idrules) eq 'HASH') {
1673: if (keys(%{$idrules}) > 0) {
1674: $datatable .= &user_formats_row('id',$settings,$idrules,
1675: $idruleorder,$numinrow,$rowcount);
1676: $$rowtotal ++;
1677: $rowcount ++;
1.28 raeburn 1678: }
1679: }
1.43 raeburn 1680: my ($emailrules,$emailruleorder) =
1681: &Apache::lonnet::inst_userrules($dom,'email');
1682: if (ref($emailrules) eq 'HASH') {
1683: if (keys(%{$emailrules}) > 0) {
1684: $datatable .= &user_formats_row('email',$settings,$emailrules,
1685: $emailruleorder,$numinrow,$rowcount);
1686: $$rowtotal ++;
1687: $rowcount ++;
1688: }
1689: }
1.39 raeburn 1690: if ($rowcount == 0) {
1691: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
1692: $$rowtotal ++;
1693: $rowcount ++;
1694: }
1.34 raeburn 1695: } elsif ($position eq 'middle') {
1.45 raeburn 1696: my @creators = ('author','course','selfcreate');
1.37 raeburn 1697: my ($rules,$ruleorder) =
1698: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 1699: my %lt = &usercreation_types();
1700: my %checked;
1.50 raeburn 1701: my @selfcreate;
1.34 raeburn 1702: if (ref($settings) eq 'HASH') {
1703: if (ref($settings->{'cancreate'}) eq 'HASH') {
1704: foreach my $item (@creators) {
1705: $checked{$item} = $settings->{'cancreate'}{$item};
1706: }
1.50 raeburn 1707: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
1708: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
1709: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
1710: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
1711: @selfcreate = ('email','login','sso');
1712: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
1713: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
1714: }
1715: }
1.34 raeburn 1716: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
1717: foreach my $item (@creators) {
1718: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
1719: $checked{$item} = 'none';
1720: }
1721: }
1722: }
1723: }
1724: my $rownum = 0;
1725: foreach my $item (@creators) {
1726: $rownum ++;
1.50 raeburn 1727: if ($item ne 'selfcreate') {
1728: if ($checked{$item} eq '') {
1.43 raeburn 1729: $checked{$item} = 'any';
1730: }
1.34 raeburn 1731: }
1732: my $css_class;
1733: if ($rownum%2) {
1734: $css_class = '';
1735: } else {
1736: $css_class = ' class="LC_odd_row" ';
1737: }
1738: $datatable .= '<tr'.$css_class.'>'.
1739: '<td><span class="LC_nobreak">'.$lt{$item}.
1740: '</span></td><td align="right">';
1.50 raeburn 1741: my @options;
1.45 raeburn 1742: if ($item eq 'selfcreate') {
1.43 raeburn 1743: push(@options,('email','login','sso'));
1744: } else {
1.50 raeburn 1745: @options = ('any');
1.43 raeburn 1746: if (ref($rules) eq 'HASH') {
1747: if (keys(%{$rules}) > 0) {
1748: push(@options,('official','unofficial'));
1749: }
1.37 raeburn 1750: }
1.50 raeburn 1751: push(@options,'none');
1.37 raeburn 1752: }
1753: foreach my $option (@options) {
1.50 raeburn 1754: my $type = 'radio';
1.34 raeburn 1755: my $check = ' ';
1.50 raeburn 1756: if ($item eq 'selfcreate') {
1757: $type = 'checkbox';
1758: if (grep(/^\Q$option\E$/,@selfcreate)) {
1759: $check = ' checked="checked" ';
1760: }
1761: } else {
1762: if ($checked{$item} eq $option) {
1763: $check = ' checked="checked" ';
1764: }
1.34 raeburn 1765: }
1766: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 1767: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 1768: $item.'" value="'.$option.'"'.$check.'/> '.
1769: $lt{$option}.'</label> </span>';
1770: }
1771: $datatable .= '</td></tr>';
1772: }
1.28 raeburn 1773: } else {
1774: my @contexts = ('author','course','domain');
1775: my @authtypes = ('int','krb4','krb5','loc');
1776: my %checked;
1777: if (ref($settings) eq 'HASH') {
1778: if (ref($settings->{'authtypes'}) eq 'HASH') {
1779: foreach my $item (@contexts) {
1780: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
1781: foreach my $auth (@authtypes) {
1782: if ($settings->{'authtypes'}{$item}{$auth}) {
1783: $checked{$item}{$auth} = ' checked="checked" ';
1784: }
1785: }
1786: }
1787: }
1.27 raeburn 1788: }
1.35 raeburn 1789: } else {
1790: foreach my $item (@contexts) {
1.36 raeburn 1791: foreach my $auth (@authtypes) {
1.35 raeburn 1792: $checked{$item}{$auth} = ' checked="checked" ';
1793: }
1794: }
1.27 raeburn 1795: }
1.28 raeburn 1796: my %title = &context_names();
1797: my %authname = &authtype_names();
1798: my $rownum = 0;
1799: my $css_class;
1800: foreach my $item (@contexts) {
1801: if ($rownum%2) {
1802: $css_class = '';
1803: } else {
1804: $css_class = ' class="LC_odd_row" ';
1805: }
1.30 raeburn 1806: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 1807: '<td>'.$title{$item}.
1808: '</td><td class="LC_left_item">'.
1809: '<span class="LC_nobreak">';
1810: foreach my $auth (@authtypes) {
1811: $datatable .= '<label>'.
1812: '<input type="checkbox" name="'.$item.'_auth" '.
1813: $checked{$item}{$auth}.' value="'.$auth.'" />'.
1814: $authname{$auth}.'</label> ';
1815: }
1816: $datatable .= '</span></td></tr>';
1817: $rownum ++;
1.27 raeburn 1818: }
1.30 raeburn 1819: $$rowtotal += $rownum;
1.27 raeburn 1820: }
1821: return $datatable;
1822: }
1823:
1.32 raeburn 1824: sub user_formats_row {
1825: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
1826: my $output;
1827: my %text = (
1828: 'username' => 'new usernames',
1829: 'id' => 'IDs',
1.45 raeburn 1830: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 1831: );
1832: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1833: $output = '<tr '.$css_class.'>'.
1.63 raeburn 1834: '<td><span class="LC_nobreak">';
1835: if ($type eq 'email') {
1836: $output .= &mt("Formats disallowed for $text{$type}: ");
1837: } else {
1838: $output .= &mt("Format rules to check for $text{$type}: ");
1839: }
1840: $output .= '</span></td>'.
1841: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 1842: my $rem;
1843: if (ref($ruleorder) eq 'ARRAY') {
1844: for (my $i=0; $i<@{$ruleorder}; $i++) {
1845: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
1846: my $rem = $i%($numinrow);
1847: if ($rem == 0) {
1848: if ($i > 0) {
1849: $output .= '</tr>';
1850: }
1851: $output .= '<tr>';
1852: }
1853: my $check = ' ';
1.39 raeburn 1854: if (ref($settings) eq 'HASH') {
1855: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
1856: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
1857: $check = ' checked="checked" ';
1858: }
1.27 raeburn 1859: }
1860: }
1861: $output .= '<td class="LC_left_item">'.
1862: '<span class="LC_nobreak"><label>'.
1.32 raeburn 1863: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 1864: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
1865: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
1866: }
1867: }
1868: $rem = @{$ruleorder}%($numinrow);
1869: }
1870: my $colsleft = $numinrow - $rem;
1871: if ($colsleft > 1 ) {
1872: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1873: ' </td>';
1874: } elsif ($colsleft == 1) {
1875: $output .= '<td class="LC_left_item"> </td>';
1876: }
1877: $output .= '</tr></table></td></tr>';
1878: return $output;
1879: }
1880:
1.34 raeburn 1881: sub usercreation_types {
1882: my %lt = &Apache::lonlocal::texthash (
1883: author => 'When adding a co-author',
1884: course => 'When adding a user to a course',
1.45 raeburn 1885: selfcreate => 'User creates own account',
1.34 raeburn 1886: any => 'Any',
1887: official => 'Institutional only ',
1888: unofficial => 'Non-institutional only',
1.43 raeburn 1889: email => 'Email address',
1890: login => 'Institutional Login',
1891: sso => 'SSO',
1.34 raeburn 1892: none => 'None',
1893: );
1894: return %lt;
1.48 raeburn 1895: }
1.34 raeburn 1896:
1.28 raeburn 1897: sub authtype_names {
1898: my %lt = &Apache::lonlocal::texthash(
1899: int => 'Internal',
1900: krb4 => 'Kerberos 4',
1901: krb5 => 'Kerberos 5',
1902: loc => 'Local',
1903: );
1904: return %lt;
1905: }
1906:
1907: sub context_names {
1908: my %context_title = &Apache::lonlocal::texthash(
1909: author => 'Creating users when an Author',
1910: course => 'Creating users when in a course',
1911: domain => 'Creating users when a Domain Coordinator',
1912: );
1913: return %context_title;
1914: }
1915:
1.33 raeburn 1916: sub print_usermodification {
1917: my ($position,$dom,$settings,$rowtotal) = @_;
1918: my $numinrow = 4;
1919: my ($context,$datatable,$rowcount);
1920: if ($position eq 'top') {
1921: $rowcount = 0;
1922: $context = 'author';
1923: foreach my $role ('ca','aa') {
1924: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1925: $numinrow,$rowcount);
1926: $$rowtotal ++;
1927: $rowcount ++;
1928: }
1.63 raeburn 1929: } elsif ($position eq 'middle') {
1.33 raeburn 1930: $context = 'course';
1931: $rowcount = 0;
1932: foreach my $role ('st','ep','ta','in','cr') {
1933: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1934: $numinrow,$rowcount);
1935: $$rowtotal ++;
1936: $rowcount ++;
1937: }
1.63 raeburn 1938: } elsif ($position eq 'bottom') {
1939: $context = 'selfcreate';
1940: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1941: $usertypes->{'default'} = $othertitle;
1942: if (ref($types) eq 'ARRAY') {
1943: push(@{$types},'default');
1944: $usertypes->{'default'} = $othertitle;
1945: foreach my $status (@{$types}) {
1946: $datatable .= &modifiable_userdata_row($context,$status,$settings,
1947: $numinrow,$rowcount,$usertypes);
1948: $$rowtotal ++;
1949: $rowcount ++;
1950: }
1951: }
1.33 raeburn 1952: }
1953: return $datatable;
1954: }
1955:
1.43 raeburn 1956: sub print_defaults {
1957: my ($dom,$rowtotal) = @_;
1.68 raeburn 1958: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1959: 'datelocale_def');
1.43 raeburn 1960: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1961: my $titles = &defaults_titles();
1962: my $rownum = 0;
1963: my ($datatable,$css_class);
1964: foreach my $item (@items) {
1965: if ($rownum%2) {
1966: $css_class = '';
1967: } else {
1968: $css_class = ' class="LC_odd_row" ';
1969: }
1970: $datatable .= '<tr'.$css_class.'>'.
1971: '<td><span class="LC_nobreak">'.$titles->{$item}.
1972: '</span></td><td class="LC_right_item">';
1973: if ($item eq 'auth_def') {
1974: my @authtypes = ('internal','krb4','krb5','localauth');
1975: my %shortauth = (
1976: internal => 'int',
1977: krb4 => 'krb4',
1978: krb5 => 'krb5',
1979: localauth => 'loc'
1980: );
1981: my %authnames = &authtype_names();
1982: foreach my $auth (@authtypes) {
1983: my $checked = ' ';
1984: if ($domdefaults{$item} eq $auth) {
1985: $checked = ' checked="checked" ';
1986: }
1987: $datatable .= '<label><input type="radio" name="'.$item.
1988: '" value="'.$auth.'"'.$checked.'/>'.
1989: $authnames{$shortauth{$auth}}.'</label> ';
1990: }
1.54 raeburn 1991: } elsif ($item eq 'timezone_def') {
1992: my $includeempty = 1;
1993: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 1994: } elsif ($item eq 'datelocale_def') {
1995: my $includeempty = 1;
1996: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 1997: } else {
1998: $datatable .= '<input type="text" name="'.$item.'" value="'.
1999: $domdefaults{$item}.'" />';
2000: }
2001: $datatable .= '</td></tr>';
2002: $rownum ++;
2003: }
2004: $$rowtotal += $rownum;
2005: return $datatable;
2006: }
2007:
2008: sub defaults_titles {
2009: my %titles = &Apache::lonlocal::texthash (
2010: 'auth_def' => 'Default authentication type',
2011: 'auth_arg_def' => 'Default authentication argument',
2012: 'lang_def' => 'Default language',
1.54 raeburn 2013: 'timezone_def' => 'Default timezone',
1.68 raeburn 2014: 'datelocale_def' => 'Default locale for dates',
1.43 raeburn 2015: );
2016: return (\%titles);
2017: }
2018:
1.46 raeburn 2019: sub print_scantronformat {
2020: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
2021: my $itemcount = 1;
1.60 raeburn 2022: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
2023: %confhash);
1.46 raeburn 2024: my $switchserver = &check_switchserver($dom,$confname);
2025: my %lt = &Apache::lonlocal::texthash (
2026: default => 'Default scantron format file error',
2027: custom => 'Custom scantron format file error',
2028: );
2029: my %scantronfiles = (
2030: default => 'default.tab',
2031: custom => 'custom.tab',
2032: );
2033: foreach my $key (keys(%scantronfiles)) {
2034: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
2035: .$scantronfiles{$key};
2036: }
2037: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
2038: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
2039: if (!$switchserver) {
2040: my $servadm = $r->dir_config('lonAdmEMail');
2041: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
2042: if ($configuserok eq 'ok') {
2043: if ($author_ok eq 'ok') {
2044: my %legacyfile = (
2045: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
2046: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
2047: );
2048: my %md5chk;
2049: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2050: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
2051: chomp($md5chk{$type});
1.46 raeburn 2052: }
2053: if ($md5chk{'default'} ne $md5chk{'custom'}) {
2054: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2055: ($scantronurls{$type},my $error) =
1.46 raeburn 2056: &legacy_scantronformat($r,$dom,$confname,
2057: $type,$legacyfile{$type},
2058: $scantronurls{$type},
2059: $scantronfiles{$type});
1.60 raeburn 2060: if ($error ne '') {
2061: $error{$type} = $error;
2062: }
2063: }
2064: if (keys(%error) == 0) {
2065: $is_custom = 1;
2066: $confhash{'scantron'}{'scantronformat'} =
2067: $scantronurls{'custom'};
2068: my $putresult =
2069: &Apache::lonnet::put_dom('configuration',
2070: \%confhash,$dom);
2071: if ($putresult ne 'ok') {
2072: $error{'custom'} =
2073: '<span class="LC_error">'.
2074: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2075: }
1.46 raeburn 2076: }
2077: } else {
1.60 raeburn 2078: ($scantronurls{'default'},my $error) =
1.46 raeburn 2079: &legacy_scantronformat($r,$dom,$confname,
2080: 'default',$legacyfile{'default'},
2081: $scantronurls{'default'},
2082: $scantronfiles{'default'});
1.60 raeburn 2083: if ($error eq '') {
2084: $confhash{'scantron'}{'scantronformat'} = '';
2085: my $putresult =
2086: &Apache::lonnet::put_dom('configuration',
2087: \%confhash,$dom);
2088: if ($putresult ne 'ok') {
2089: $error{'default'} =
2090: '<span class="LC_error">'.
2091: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2092: }
2093: } else {
2094: $error{'default'} = $error;
2095: }
1.46 raeburn 2096: }
2097: }
2098: }
2099: } else {
2100: $error{'default'} = &mt("Unable to copy default scantron formatfile to domain's RES space: [_1]",$switchserver);
2101: }
2102: }
2103: if (ref($settings) eq 'HASH') {
2104: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
2105: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
2106: if ((!@info) || ($info[0] eq 'no_such_dir')) {
2107: $scantronurl = '';
2108: } else {
2109: $scantronurl = $settings->{'scantronformat'};
2110: }
2111: $is_custom = 1;
2112: } else {
2113: $scantronurl = $scantronurls{'default'};
2114: }
2115: } else {
1.60 raeburn 2116: if ($is_custom) {
2117: $scantronurl = $scantronurls{'custom'};
2118: } else {
2119: $scantronurl = $scantronurls{'default'};
2120: }
1.46 raeburn 2121: }
2122: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2123: $datatable .= '<tr'.$css_class.'>';
2124: if (!$is_custom) {
1.65 raeburn 2125: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
2126: '<span class="LC_nobreak">';
1.46 raeburn 2127: if ($scantronurl) {
2128: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
2129: &mt('Default scantron format file').'</a>';
2130: } else {
2131: $datatable = &mt('File unavailable for display');
2132: }
1.65 raeburn 2133: $datatable .= '</span></td>';
1.60 raeburn 2134: if (keys(%error) == 0) {
2135: $datatable .= '<td valign="bottom">';
2136: if (!$switchserver) {
2137: $datatable .= &mt('Upload:').'<br />';
2138: }
2139: } else {
2140: my $errorstr;
2141: foreach my $key (sort(keys(%error))) {
2142: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2143: }
2144: $datatable .= '<td>'.$errorstr;
2145: }
1.46 raeburn 2146: } else {
2147: if (keys(%error) > 0) {
2148: my $errorstr;
2149: foreach my $key (sort(keys(%error))) {
2150: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2151: }
1.60 raeburn 2152: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 2153: } elsif ($scantronurl) {
1.65 raeburn 2154: $datatable .= '<td><span class="LC_nobreak">'.
2155: '<a href="'.$scantronurl.'" target="_blank">'.
2156: &mt('Custom scantron format file').'</a><label>'.
2157: '<input type="checkbox" name="scantronformat_del"'.
2158: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
2159: '<td><span class="LC_nobreak"> '.
2160: &mt('Replace:').'</span><br />';
1.46 raeburn 2161: }
2162: }
2163: if (keys(%error) == 0) {
2164: if ($switchserver) {
2165: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2166: } else {
1.65 raeburn 2167: $datatable .='<span class="LC_nobreak"> '.
2168: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 2169: }
2170: }
2171: $datatable .= '</td></tr>';
2172: $$rowtotal ++;
2173: return $datatable;
2174: }
2175:
2176: sub legacy_scantronformat {
2177: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
2178: my ($url,$error);
2179: my @statinfo = &Apache::lonnet::stat_file($newurl);
2180: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
2181: (my $result,$url) =
2182: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
2183: '','',$newfile);
2184: if ($result ne 'ok') {
2185: $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
2186: }
2187: }
2188: return ($url,$error);
2189: }
1.43 raeburn 2190:
1.49 raeburn 2191: sub print_coursecategories {
1.57 raeburn 2192: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
2193: my $datatable;
2194: if ($position eq 'top') {
2195: my $toggle_cats_crs = ' ';
2196: my $toggle_cats_dom = ' checked="checked" ';
2197: my $can_cat_crs = ' ';
2198: my $can_cat_dom = ' checked="checked" ';
2199: if (ref($settings) eq 'HASH') {
2200: if ($settings->{'togglecats'} eq 'crs') {
2201: $toggle_cats_crs = $toggle_cats_dom;
2202: $toggle_cats_dom = ' ';
2203: }
2204: if ($settings->{'categorize'} eq 'crs') {
2205: $can_cat_crs = $can_cat_dom;
2206: $can_cat_dom = ' ';
2207: }
2208: }
2209: my %title = &Apache::lonlocal::texthash (
2210: togglecats => 'Show/Hide a course in the catalog',
2211: categorize => 'Assign a category to a course',
2212: );
2213: my %level = &Apache::lonlocal::texthash (
2214: dom => 'Set in "Modify Course" (Domain)',
1.60 raeburn 2215: crs => 'Set in "Modify Parameters" (Course)',
1.57 raeburn 2216: );
2217: $datatable = '<tr class="LC_odd_row">'.
2218: '<td>'.$title{'togglecats'}.'</td>'.
2219: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2220: '<input type="radio" name="togglecats"'.
2221: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2222: '<label><input type="radio" name="togglecats"'.
2223: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
2224: '</tr><tr>'.
2225: '<td>'.$title{'categorize'}.'</td>'.
2226: '<td class="LC_right_item"><span class="LC_nobreak">'.
2227: '<label><input type="radio" name="categorize"'.
2228: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2229: '<label><input type="radio" name="categorize"'.
2230: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
2231: '</tr>';
2232: $$rowtotal += 2;
2233: } else {
2234: my $css_class;
2235: my $itemcount = 1;
2236: my $cathash;
2237: if (ref($settings) eq 'HASH') {
2238: $cathash = $settings->{'cats'};
2239: }
2240: if (ref($cathash) eq 'HASH') {
2241: my (@cats,@trails,%allitems,%idx,@jsarray);
2242: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
2243: \%allitems,\%idx,\@jsarray);
2244: my $maxdepth = scalar(@cats);
2245: my $colattrib = '';
2246: if ($maxdepth > 2) {
2247: $colattrib = ' colspan="2" ';
2248: }
2249: my @path;
2250: if (@cats > 0) {
2251: if (ref($cats[0]) eq 'ARRAY') {
2252: my $numtop = @{$cats[0]};
2253: my $maxnum = $numtop;
2254: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2255: $maxnum ++;
2256: }
2257: my $lastidx;
2258: for (my $i=0; $i<$numtop; $i++) {
2259: my $parent = $cats[0][$i];
2260: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2261: my $item = &escape($parent).'::0';
2262: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
2263: $lastidx = $idx{$item};
2264: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2265: .'<select name="'.$item.'"'.$chgstr.'>';
2266: for (my $k=0; $k<=$maxnum; $k++) {
2267: my $vpos = $k+1;
2268: my $selstr;
2269: if ($k == $i) {
2270: $selstr = ' selected="selected" ';
2271: }
2272: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2273: }
2274: $datatable .= '</select></td><td>';
2275: if ($parent eq 'instcode') {
2276: $datatable .= '<span class="LC_nobreak">'.&mt('Official courses')
2277: .'</span><br /><span class="LC_nobreak">('
2278: .&mt('with institutional codes').')</span></td>'
2279: .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'
2280: .&mt('Display').'</label> '
2281: .'<label><input type="radio" name="instcode" value="0" />'
2282: .&mt('Do not display').'</label></span></td>';
2283: } else {
2284: $datatable .= $parent
2285: .' <label><input type="checkbox" name="deletecategory" '
2286: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
2287: }
2288: my $depth = 1;
2289: push(@path,$parent);
2290: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
2291: pop(@path);
2292: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
2293: $itemcount ++;
2294: }
1.48 raeburn 2295: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 2296: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
2297: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 2298: for (my $k=0; $k<=$maxnum; $k++) {
2299: my $vpos = $k+1;
2300: my $selstr;
1.57 raeburn 2301: if ($k == $numtop) {
1.48 raeburn 2302: $selstr = ' selected="selected" ';
2303: }
2304: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2305: }
1.59 bisitz 2306: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 2307: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
2308: .'</tr>'."\n";
1.48 raeburn 2309: $itemcount ++;
1.57 raeburn 2310: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2311: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2312: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
2313: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
2314: '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
2315: for (my $k=0; $k<=$maxnum; $k++) {
2316: my $vpos = $k+1;
2317: my $selstr;
2318: if ($k == $maxnum) {
2319: $selstr = ' selected="selected" ';
2320: }
2321: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.48 raeburn 2322: }
1.57 raeburn 2323: $datatable .= '</select></span></td><td><span class="LC_nobreak">'
2324: .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('
2325: .&mt('with institutional codes').')</span></td>'
2326: .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'
2327: .&mt('Display').'</label> '
2328: .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'
2329: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 2330: }
2331: }
1.57 raeburn 2332: } else {
2333: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 2334: }
2335: } else {
1.57 raeburn 2336: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
2337: .&initialize_categories($itemcount);
1.48 raeburn 2338: }
1.57 raeburn 2339: $$rowtotal += $itemcount;
1.48 raeburn 2340: }
2341: return $datatable;
2342: }
2343:
1.69 raeburn 2344: sub print_serverstatuses {
2345: my ($dom,$settings,$rowtotal) = @_;
2346: my $datatable;
2347: my @pages = &serverstatus_pages();
2348: my (%namedaccess,%machineaccess);
2349: foreach my $type (@pages) {
2350: $namedaccess{$type} = '';
2351: $machineaccess{$type}= '';
2352: }
2353: if (ref($settings) eq 'HASH') {
2354: foreach my $type (@pages) {
2355: if (exists($settings->{$type})) {
2356: if (ref($settings->{$type}) eq 'HASH') {
2357: foreach my $key (keys(%{$settings->{$type}})) {
2358: if ($key eq 'namedusers') {
2359: $namedaccess{$type} = $settings->{$type}->{$key};
2360: } elsif ($key eq 'machines') {
2361: $machineaccess{$type} = $settings->{$type}->{$key};
2362: }
2363: }
2364: }
2365: }
2366: }
2367: }
2368: my $titles= &LONCAPA::loncgi::serverstatus_titles();
2369: my $rownum = 0;
2370: my $css_class;
2371: foreach my $type (@pages) {
2372: $rownum ++;
2373: $css_class = $rownum%2?' class="LC_odd_row"':'';
2374: $datatable .= '<tr'.$css_class.'>'.
2375: '<td><span class="LC_nobreak">'.
2376: $titles->{$type}.'</span></td>'.
2377: '<td class="LC_left_item">'.
2378: '<input type="text" name="'.$type.'_namedusers" '.
2379: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
2380: '<td class="LC_right_item">'.
2381: '<span class="LC_nobreak">'.
2382: '<input type="text" name="'.$type.'_machines" '.
2383: 'value="'.$machineaccess{$type}.'" size="10" />'.
2384: '</td></tr>'."\n";
2385: }
2386: $$rowtotal += $rownum;
2387: return $datatable;
2388: }
2389:
2390: sub serverstatus_pages {
2391: return ('userstatus','lonstatus','loncron','server-status','codeversions',
2392: 'clusterstatus','metadata_keywords','metadata_harvest',
2393: 'takeoffline','takeonline','showenv');
2394: }
2395:
1.49 raeburn 2396: sub coursecategories_javascript {
2397: my ($settings) = @_;
1.57 raeburn 2398: my ($output,$jstext,$cathash);
1.49 raeburn 2399: if (ref($settings) eq 'HASH') {
1.57 raeburn 2400: $cathash = $settings->{'cats'};
2401: }
2402: if (ref($cathash) eq 'HASH') {
1.49 raeburn 2403: my (@cats,@jsarray,%idx);
1.57 raeburn 2404: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 2405: if (@jsarray > 0) {
2406: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
2407: for (my $i=0; $i<@jsarray; $i++) {
2408: if (ref($jsarray[$i]) eq 'ARRAY') {
2409: my $catstr = join('","',@{$jsarray[$i]});
2410: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
2411: }
2412: }
2413: }
2414: } else {
2415: $jstext = ' var categories = Array(1);'."\n".
2416: ' categories[0] = Array("instcode_pos");'."\n";
2417: }
2418: $output = <<"ENDSCRIPT";
2419: <script type="text/javascript">
2420: function reorderCats(form,parent,item,idx) {
2421: var changedVal;
2422: $jstext
2423: var newpos = 'addcategory_pos';
2424: var current = new Array;
2425: if (parent == '') {
2426: var has_instcode = 0;
2427: var maxtop = categories[idx].length;
2428: for (var j=0; j<maxtop; j++) {
2429: if (categories[idx][j] == 'instcode::0') {
2430: has_instcode == 1;
2431: }
2432: }
2433: if (has_instcode == 0) {
2434: categories[idx][maxtop] = 'instcode_pos';
2435: }
2436: } else {
2437: newpos += '_'+parent;
2438: }
2439: var maxh = 1 + categories[idx].length;
2440: var current = new Array;
2441: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2442: if (item == newpos) {
2443: changedVal = newitemVal;
2444: } else {
2445: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2446: current[newitemVal] = newpos;
2447: }
2448: for (var i=0; i<categories[idx].length; i++) {
2449: var elementName = categories[idx][i];
2450: if (elementName != item) {
2451: if (form.elements[elementName]) {
2452: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2453: current[currVal] = elementName;
2454: }
2455: }
2456: }
2457: var oldVal;
2458: for (var j=0; j<maxh; j++) {
2459: if (current[j] == undefined) {
2460: oldVal = j;
2461: }
2462: }
2463: if (oldVal < changedVal) {
2464: for (var k=oldVal+1; k<=changedVal ; k++) {
2465: var elementName = current[k];
2466: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2467: }
2468: } else {
2469: for (var k=changedVal; k<oldVal; k++) {
2470: var elementName = current[k];
2471: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2472: }
2473: }
2474: return;
2475: }
2476: </script>
2477:
2478: ENDSCRIPT
2479: return $output;
2480: }
2481:
1.48 raeburn 2482: sub initialize_categories {
2483: my ($itemcount) = @_;
2484: my $datatable;
2485: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2486: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
2487:
1.48 raeburn 2488: $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
2489: .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
2490: .'<option value="1">2</option></select> '
2491: .&mt('Official courses (with institutional codes)')
2492: .'</span></td><td><span class="LC_nobreak">'
2493: .'<label><input type="radio" name="instcode" value="1" checked="checked" />'
2494: .&mt('Display').'</label> <label>'
2495: .'<input type="radio" name="instcode" value="0" />'.&mt('Do not display')
2496: .'</label></span></td></tr>';
2497: $itemcount ++;
2498: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2499: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 2500: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.53 raeburn 2501: .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
1.48 raeburn 2502: .'<option value="1" selected="selected">2</option></select> '
2503: .&mt('Add category').'</td><td>'.&mt('Name:')
2504: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
2505: return $datatable;
2506: }
2507:
2508: sub build_category_rows {
1.49 raeburn 2509: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
2510: my ($text,$name,$item,$chgstr);
1.48 raeburn 2511: if (ref($cats) eq 'ARRAY') {
2512: my $maxdepth = scalar(@{$cats});
2513: if (ref($cats->[$depth]) eq 'HASH') {
2514: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
2515: my $numchildren = @{$cats->[$depth]{$parent}};
2516: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
2517: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 2518: my ($idxnum,$parent_name,$parent_item);
2519: my $higher = $depth - 1;
2520: if ($higher == 0) {
2521: $parent_name = &escape($parent).'::'.$higher;
2522: } else {
2523: if (ref($path) eq 'ARRAY') {
2524: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2525: }
2526: }
2527: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 2528: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 2529: if ($j < $numchildren) {
1.48 raeburn 2530: $name = $cats->[$depth]{$parent}[$j];
2531: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 2532: $idxnum = $idx->{$item};
2533: } else {
2534: $name = $parent_name;
2535: $item = $parent_item;
1.48 raeburn 2536: }
1.49 raeburn 2537: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
2538: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 2539: for (my $i=0; $i<=$numchildren; $i++) {
2540: my $vpos = $i+1;
2541: my $selstr;
2542: if ($j == $i) {
2543: $selstr = ' selected="selected" ';
2544: }
2545: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
2546: }
2547: $text .= '</select> ';
2548: if ($j < $numchildren) {
2549: my $deeper = $depth+1;
2550: $text .= $name.' '
2551: .'<label><input type="checkbox" name="deletecategory" value="'
2552: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
2553: if(ref($path) eq 'ARRAY') {
2554: push(@{$path},$name);
1.49 raeburn 2555: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 2556: pop(@{$path});
2557: }
2558: } else {
1.59 bisitz 2559: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 2560: if ($j == $numchildren) {
2561: $text .= $name;
2562: } else {
2563: $text .= $item;
2564: }
2565: $text .= '" value="" />';
2566: }
2567: $text .= '</td></tr>';
2568: }
2569: $text .= '</table></td>';
2570: } else {
2571: my $higher = $depth-1;
2572: if ($higher == 0) {
2573: $name = &escape($parent).'::'.$higher;
2574: } else {
2575: if (ref($path) eq 'ARRAY') {
2576: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2577: }
2578: }
2579: my $colspan;
2580: if ($parent ne 'instcode') {
2581: $colspan = $maxdepth - $depth - 1;
2582: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
2583: }
2584: }
2585: }
2586: }
2587: return $text;
2588: }
2589:
1.33 raeburn 2590: sub modifiable_userdata_row {
1.63 raeburn 2591: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 2592: my $rolename;
1.63 raeburn 2593: if ($context eq 'selfcreate') {
2594: if (ref($usertypes) eq 'HASH') {
2595: $rolename = $usertypes->{$role};
2596: } else {
2597: $rolename = $role;
2598: }
1.33 raeburn 2599: } else {
1.63 raeburn 2600: if ($role eq 'cr') {
2601: $rolename = &mt('Custom role');
2602: } else {
2603: $rolename = &Apache::lonnet::plaintext($role);
2604: }
1.33 raeburn 2605: }
2606: my @fields = ('lastname','firstname','middlename','generation',
2607: 'permanentemail','id');
2608: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2609: my $output;
2610: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2611: $output = '<tr '.$css_class.'>'.
2612: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
2613: '<td class="LC_left_item" colspan="2"><table>';
2614: my $rem;
2615: my %checks;
2616: if (ref($settings) eq 'HASH') {
2617: if (ref($settings->{$context}) eq 'HASH') {
2618: if (ref($settings->{$context}->{$role}) eq 'HASH') {
2619: foreach my $field (@fields) {
2620: if ($settings->{$context}->{$role}->{$field}) {
2621: $checks{$field} = ' checked="checked" ';
2622: }
2623: }
2624: }
2625: }
2626: }
2627: for (my $i=0; $i<@fields; $i++) {
2628: my $rem = $i%($numinrow);
2629: if ($rem == 0) {
2630: if ($i > 0) {
2631: $output .= '</tr>';
2632: }
2633: $output .= '<tr>';
2634: }
2635: my $check = ' ';
2636: if (exists($checks{$fields[$i]})) {
2637: $check = $checks{$fields[$i]}
2638: } else {
2639: if ($role eq 'st') {
2640: if (ref($settings) ne 'HASH') {
2641: $check = ' checked="checked" ';
2642: }
2643: }
2644: }
2645: $output .= '<td class="LC_left_item">'.
2646: '<span class="LC_nobreak"><label>'.
2647: '<input type="checkbox" name="canmodify_'.$role.'" '.
2648: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
2649: '</label></span></td>';
2650: $rem = @fields%($numinrow);
2651: }
2652: my $colsleft = $numinrow - $rem;
2653: if ($colsleft > 1 ) {
2654: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2655: ' </td>';
2656: } elsif ($colsleft == 1) {
2657: $output .= '<td class="LC_left_item"> </td>';
2658: }
2659: $output .= '</tr></table></td></tr>';
2660: return $output;
2661: }
1.28 raeburn 2662:
1.25 raeburn 2663: sub users_cansearch_row {
2664: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
2665: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 2666: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
2667: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 2668: my $rem;
2669: if (ref($types) eq 'ARRAY') {
2670: for (my $i=0; $i<@{$types}; $i++) {
2671: if (defined($usertypes->{$types->[$i]})) {
2672: my $rem = $i%($numinrow);
2673: if ($rem == 0) {
2674: if ($i > 0) {
2675: $output .= '</tr>';
2676: }
2677: $output .= '<tr>';
1.23 raeburn 2678: }
1.26 raeburn 2679: my $check = ' ';
2680: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
2681: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
2682: $check = ' checked="checked" ';
2683: }
1.23 raeburn 2684: }
1.26 raeburn 2685: $output .= '<td class="LC_left_item">'.
2686: '<span class="LC_nobreak"><label>'.
2687: '<input type="checkbox" name="cansearch" '.
2688: 'value="'.$types->[$i].'"'.$check.'/>'.
2689: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 2690: }
2691: }
1.26 raeburn 2692:
2693: $rem = @{$types}%($numinrow);
1.23 raeburn 2694: }
2695: my $colsleft = $numinrow - $rem;
2696: if ($colsleft > 1) {
1.25 raeburn 2697: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 2698: } else {
1.25 raeburn 2699: $output .= '<td class="LC_left_item">';
1.23 raeburn 2700: }
2701: my $defcheck = ' ';
2702: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 2703: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
2704: $defcheck = ' checked="checked" ';
2705: }
1.23 raeburn 2706: }
1.25 raeburn 2707: $output .= '<span class="LC_nobreak"><label>'.
2708: '<input type="checkbox" name="cansearch" '.
2709: 'value="default"'.$defcheck.'/>'.
2710: $othertitle.'</label></span></td>'.
2711: '</tr></table></td></tr>';
2712: return $output;
1.23 raeburn 2713: }
2714:
2715: sub sorted_searchtitles {
2716: my %searchtitles = &Apache::lonlocal::texthash(
2717: 'uname' => 'username',
2718: 'lastname' => 'last name',
2719: 'lastfirst' => 'last name, first name',
2720: );
2721: my @titleorder = ('uname','lastname','lastfirst');
2722: return (\%searchtitles,\@titleorder);
2723: }
2724:
1.25 raeburn 2725: sub sorted_searchtypes {
2726: my %srchtypes_desc = (
2727: exact => 'is exact match',
2728: contains => 'contains ..',
2729: begins => 'begins with ..',
2730: );
2731: my @srchtypeorder = ('exact','begins','contains');
2732: return (\%srchtypes_desc,\@srchtypeorder);
2733: }
2734:
1.3 raeburn 2735: sub usertype_update_row {
2736: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
2737: my $datatable;
2738: my $numinrow = 4;
2739: foreach my $type (@{$types}) {
2740: if (defined($usertypes->{$type})) {
2741: $$rownums ++;
2742: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
2743: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
2744: '</td><td class="LC_left_item"><table>';
2745: for (my $i=0; $i<@{$fields}; $i++) {
2746: my $rem = $i%($numinrow);
2747: if ($rem == 0) {
2748: if ($i > 0) {
2749: $datatable .= '</tr>';
2750: }
2751: $datatable .= '<tr>';
2752: }
2753: my $check = ' ';
1.39 raeburn 2754: if (ref($settings) eq 'HASH') {
2755: if (ref($settings->{'fields'}) eq 'HASH') {
2756: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
2757: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
2758: $check = ' checked="checked" ';
2759: }
1.3 raeburn 2760: }
2761: }
2762: }
2763:
2764: if ($i == @{$fields}-1) {
2765: my $colsleft = $numinrow - $rem;
2766: if ($colsleft > 1) {
2767: $datatable .= '<td colspan="'.$colsleft.'">';
2768: } else {
2769: $datatable .= '<td>';
2770: }
2771: } else {
2772: $datatable .= '<td>';
2773: }
1.8 raeburn 2774: $datatable .= '<span class="LC_nobreak"><label>'.
2775: '<input type="checkbox" name="updateable_'.$type.
2776: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
2777: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 2778: }
2779: $datatable .= '</tr></table></td></tr>';
2780: }
2781: }
2782: return $datatable;
1.1 raeburn 2783: }
2784:
2785: sub modify_login {
1.9 raeburn 2786: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 2787: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 2788: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 2789: adminmail => 'Display administrator E-mail address',
1.43 raeburn 2790: newuser => 'Link for visitors to create a user account',
1.41 raeburn 2791: loginheader => 'Log-in box header');
1.3 raeburn 2792: my @offon = ('off','on');
1.6 raeburn 2793: my %loginhash;
1.9 raeburn 2794: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
2795: \%domconfig,\%loginhash);
1.43 raeburn 2796: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2797: foreach my $item (@toggles) {
2798: $loginhash{login}{$item} = $env{'form.'.$item};
2799: }
1.41 raeburn 2800: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 2801: if (ref($colchanges{'login'}) eq 'HASH') {
2802: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
2803: \%loginhash);
2804: }
1.1 raeburn 2805: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
2806: $dom);
2807: if ($putresult eq 'ok') {
1.43 raeburn 2808: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2809: my %defaultchecked = (
2810: 'coursecatalog' => 'on',
2811: 'adminmail' => 'off',
1.43 raeburn 2812: 'newuser' => 'off',
1.42 raeburn 2813: );
1.55 raeburn 2814: if (ref($domconfig{'login'}) eq 'HASH') {
2815: foreach my $item (@toggles) {
2816: if ($defaultchecked{$item} eq 'on') {
2817: if (($domconfig{'login'}{$item} eq '0') &&
2818: ($env{'form.'.$item} eq '1')) {
2819: $changes{$item} = 1;
2820: } elsif (($domconfig{'login'}{$item} eq '' ||
2821: $domconfig{'login'}{$item} eq '1') &&
2822: ($env{'form.'.$item} eq '0')) {
2823: $changes{$item} = 1;
2824: }
2825: } elsif ($defaultchecked{$item} eq 'off') {
2826: if (($domconfig{'login'}{$item} eq '1') &&
2827: ($env{'form.'.$item} eq '0')) {
2828: $changes{$item} = 1;
2829: } elsif (($domconfig{'login'}{$item} eq '' ||
2830: $domconfig{'login'}{$item} eq '0') &&
2831: ($env{'form.'.$item} eq '1')) {
2832: $changes{$item} = 1;
2833: }
1.42 raeburn 2834: }
2835: }
1.55 raeburn 2836: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
2837: ($env{'form.loginheader'} eq 'image')) {
2838: $changes{'loginheader'} = 1;
2839: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
2840: $domconfig{'login'}{'loginheader'} eq 'image') &&
2841: ($env{'form.loginheader'} eq 'text')) {
2842: $changes{'loginheader'} = 1;
2843: }
1.41 raeburn 2844: }
1.6 raeburn 2845: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 2846: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 2847: $resulttext = &mt('Changes made:').'<ul>';
2848: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 2849: if ($item eq 'loginheader') {
2850: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
2851: } else {
2852: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
2853: }
1.1 raeburn 2854: }
1.6 raeburn 2855: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 2856: } else {
2857: $resulttext = &mt('No changes made to log-in page settings');
2858: }
2859: } else {
1.11 albertel 2860: $resulttext = '<span class="LC_error">'.
2861: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2862: }
1.6 raeburn 2863: if ($errors) {
1.9 raeburn 2864: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 2865: $errors.'</ul>';
2866: }
2867: return $resulttext;
2868: }
2869:
2870: sub color_font_choices {
2871: my %choices =
2872: &Apache::lonlocal::texthash (
2873: img => "Header",
2874: bgs => "Background colors",
2875: links => "Link colors",
1.55 raeburn 2876: images => "Images",
1.6 raeburn 2877: font => "Font color",
1.76 raeburn 2878: pgbg => "Page",
1.6 raeburn 2879: tabbg => "Header",
2880: sidebg => "Border",
2881: link => "Link",
2882: alink => "Active link",
2883: vlink => "Visited link",
2884: );
2885: return %choices;
2886: }
2887:
2888: sub modify_rolecolors {
1.9 raeburn 2889: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 2890: my ($resulttext,%rolehash);
2891: $rolehash{'rolecolors'} = {};
1.55 raeburn 2892: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
2893: if ($domconfig{'rolecolors'} eq '') {
2894: $domconfig{'rolecolors'} = {};
2895: }
2896: }
1.9 raeburn 2897: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 2898: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
2899: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
2900: $dom);
2901: if ($putresult eq 'ok') {
2902: if (keys(%changes) > 0) {
1.41 raeburn 2903: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 2904: $resulttext = &display_colorchgs($dom,\%changes,$roles,
2905: $rolehash{'rolecolors'});
2906: } else {
2907: $resulttext = &mt('No changes made to default color schemes');
2908: }
2909: } else {
1.11 albertel 2910: $resulttext = '<span class="LC_error">'.
2911: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 2912: }
2913: if ($errors) {
2914: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
2915: $errors.'</ul>';
2916: }
2917: return $resulttext;
2918: }
2919:
2920: sub modify_colors {
1.9 raeburn 2921: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 2922: my (%changes,%choices);
1.51 raeburn 2923: my @bgs;
1.6 raeburn 2924: my @links = ('link','alink','vlink');
1.41 raeburn 2925: my @logintext;
1.6 raeburn 2926: my @images;
2927: my $servadm = $r->dir_config('lonAdmEMail');
2928: my $errors;
2929: foreach my $role (@{$roles}) {
2930: if ($role eq 'login') {
1.12 raeburn 2931: %choices = &login_choices();
1.41 raeburn 2932: @logintext = ('textcol','bgcol');
1.12 raeburn 2933: } else {
2934: %choices = &color_font_choices();
2935: }
2936: if ($role eq 'login') {
1.41 raeburn 2937: @images = ('img','logo','domlogo','login');
1.51 raeburn 2938: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 2939: } else {
2940: @images = ('img');
1.51 raeburn 2941: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 2942: }
2943: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 2944: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 2945: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
2946: }
1.46 raeburn 2947: my ($configuserok,$author_ok,$switchserver) =
2948: &config_check($dom,$confname,$servadm);
1.9 raeburn 2949: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 2950: if (ref($domconfig->{$role}) ne 'HASH') {
2951: $domconfig->{$role} = {};
2952: }
1.8 raeburn 2953: foreach my $img (@images) {
1.70 raeburn 2954: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
2955: if (defined($env{'form.login_showlogo_'.$img})) {
2956: $confhash->{$role}{'showlogo'}{$img} = 1;
2957: } else {
2958: $confhash->{$role}{'showlogo'}{$img} = 0;
2959: }
2960: }
1.18 albertel 2961: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
2962: && !defined($domconfig->{$role}{$img})
2963: && !$env{'form.'.$role.'_del_'.$img}
2964: && $env{'form.'.$role.'_import_'.$img}) {
2965: # import the old configured image from the .tab setting
2966: # if they haven't provided a new one
2967: $domconfig->{$role}{$img} =
2968: $env{'form.'.$role.'_import_'.$img};
2969: }
1.6 raeburn 2970: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 2971: my $error;
1.6 raeburn 2972: if ($configuserok eq 'ok') {
1.9 raeburn 2973: if ($switchserver) {
1.12 raeburn 2974: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 2975: } else {
2976: if ($author_ok eq 'ok') {
2977: my ($result,$logourl) =
2978: &publishlogo($r,'upload',$role.'_'.$img,
2979: $dom,$confname,$img,$width,$height);
2980: if ($result eq 'ok') {
2981: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 2982: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2983: } else {
1.12 raeburn 2984: $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 2985: }
2986: } else {
1.46 raeburn 2987: $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 2988: }
2989: }
2990: } else {
1.46 raeburn 2991: $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 2992: }
2993: if ($error) {
1.8 raeburn 2994: &Apache::lonnet::logthis($error);
1.11 albertel 2995: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 2996: }
2997: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 2998: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
2999: my $error;
3000: if ($configuserok eq 'ok') {
3001: # is confname an author?
3002: if ($switchserver eq '') {
3003: if ($author_ok eq 'ok') {
3004: my ($result,$logourl) =
3005: &publishlogo($r,'copy',$domconfig->{$role}{$img},
3006: $dom,$confname,$img,$width,$height);
3007: if ($result eq 'ok') {
3008: $confhash->{$role}{$img} = $logourl;
1.18 albertel 3009: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3010: }
3011: }
3012: }
3013: }
1.6 raeburn 3014: }
3015: }
3016: }
3017: if (ref($domconfig) eq 'HASH') {
3018: if (ref($domconfig->{$role}) eq 'HASH') {
3019: foreach my $img (@images) {
3020: if ($domconfig->{$role}{$img} ne '') {
3021: if ($env{'form.'.$role.'_del_'.$img}) {
3022: $confhash->{$role}{$img} = '';
1.12 raeburn 3023: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3024: } else {
1.9 raeburn 3025: if ($confhash->{$role}{$img} eq '') {
3026: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
3027: }
1.6 raeburn 3028: }
3029: } else {
3030: if ($env{'form.'.$role.'_del_'.$img}) {
3031: $confhash->{$role}{$img} = '';
1.12 raeburn 3032: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3033: }
3034: }
1.70 raeburn 3035: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
3036: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
3037: if ($confhash->{$role}{'showlogo'}{$img} ne
3038: $domconfig->{$role}{'showlogo'}{$img}) {
3039: $changes{$role}{'showlogo'}{$img} = 1;
3040: }
3041: } else {
3042: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3043: $changes{$role}{'showlogo'}{$img} = 1;
3044: }
3045: }
3046: }
3047: }
1.6 raeburn 3048: if ($domconfig->{$role}{'font'} ne '') {
3049: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
3050: $changes{$role}{'font'} = 1;
3051: }
3052: } else {
3053: if ($confhash->{$role}{'font'}) {
3054: $changes{$role}{'font'} = 1;
3055: }
3056: }
3057: foreach my $item (@bgs) {
3058: if ($domconfig->{$role}{$item} ne '') {
3059: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3060: $changes{$role}{'bgs'}{$item} = 1;
3061: }
3062: } else {
3063: if ($confhash->{$role}{$item}) {
3064: $changes{$role}{'bgs'}{$item} = 1;
3065: }
3066: }
3067: }
3068: foreach my $item (@links) {
3069: if ($domconfig->{$role}{$item} ne '') {
3070: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3071: $changes{$role}{'links'}{$item} = 1;
3072: }
3073: } else {
3074: if ($confhash->{$role}{$item}) {
3075: $changes{$role}{'links'}{$item} = 1;
3076: }
3077: }
3078: }
1.41 raeburn 3079: foreach my $item (@logintext) {
3080: if ($domconfig->{$role}{$item} ne '') {
3081: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3082: $changes{$role}{'logintext'}{$item} = 1;
3083: }
3084: } else {
3085: if ($confhash->{$role}{$item}) {
3086: $changes{$role}{'logintext'}{$item} = 1;
3087: }
3088: }
3089: }
1.6 raeburn 3090: } else {
3091: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3092: \@logintext,$confhash,\%changes);
1.6 raeburn 3093: }
3094: } else {
3095: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3096: \@logintext,$confhash,\%changes);
1.6 raeburn 3097: }
3098: }
3099: return ($errors,%changes);
3100: }
3101:
1.46 raeburn 3102: sub config_check {
3103: my ($dom,$confname,$servadm) = @_;
3104: my ($configuserok,$author_ok,$switchserver,%currroles);
3105: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
3106: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
3107: $confname,$servadm);
3108: if ($configuserok eq 'ok') {
3109: $switchserver = &check_switchserver($dom,$confname);
3110: if ($switchserver eq '') {
3111: $author_ok = &check_authorstatus($dom,$confname,%currroles);
3112: }
3113: }
3114: return ($configuserok,$author_ok,$switchserver);
3115: }
3116:
1.6 raeburn 3117: sub default_change_checker {
1.41 raeburn 3118: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 3119: foreach my $item (@{$links}) {
3120: if ($confhash->{$role}{$item}) {
3121: $changes->{$role}{'links'}{$item} = 1;
3122: }
3123: }
3124: foreach my $item (@{$bgs}) {
3125: if ($confhash->{$role}{$item}) {
3126: $changes->{$role}{'bgs'}{$item} = 1;
3127: }
3128: }
1.41 raeburn 3129: foreach my $item (@{$logintext}) {
3130: if ($confhash->{$role}{$item}) {
3131: $changes->{$role}{'logintext'}{$item} = 1;
3132: }
3133: }
1.6 raeburn 3134: foreach my $img (@{$images}) {
3135: if ($env{'form.'.$role.'_del_'.$img}) {
3136: $confhash->{$role}{$img} = '';
1.12 raeburn 3137: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 3138: }
1.70 raeburn 3139: if ($role eq 'login') {
3140: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3141: $changes->{$role}{'showlogo'}{$img} = 1;
3142: }
3143: }
1.6 raeburn 3144: }
3145: if ($confhash->{$role}{'font'}) {
3146: $changes->{$role}{'font'} = 1;
3147: }
1.48 raeburn 3148: }
1.6 raeburn 3149:
3150: sub display_colorchgs {
3151: my ($dom,$changes,$roles,$confhash) = @_;
3152: my (%choices,$resulttext);
3153: if (!grep(/^login$/,@{$roles})) {
3154: $resulttext = &mt('Changes made:').'<br />';
3155: }
3156: foreach my $role (@{$roles}) {
3157: if ($role eq 'login') {
3158: %choices = &login_choices();
3159: } else {
3160: %choices = &color_font_choices();
3161: }
3162: if (ref($changes->{$role}) eq 'HASH') {
3163: if ($role ne 'login') {
3164: $resulttext .= '<h4>'.&mt($role).'</h4>';
3165: }
3166: foreach my $key (sort(keys(%{$changes->{$role}}))) {
3167: if ($role ne 'login') {
3168: $resulttext .= '<ul>';
3169: }
3170: if (ref($changes->{$role}{$key}) eq 'HASH') {
3171: if ($role ne 'login') {
3172: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
3173: }
3174: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 3175: if (($role eq 'login') && ($key eq 'showlogo')) {
3176: if ($confhash->{$role}{$key}{$item}) {
3177: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
3178: } else {
3179: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
3180: }
3181: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 3182: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
3183: } else {
1.12 raeburn 3184: my $newitem = $confhash->{$role}{$item};
3185: if ($key eq 'images') {
3186: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
3187: }
3188: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 3189: }
3190: }
3191: if ($role ne 'login') {
3192: $resulttext .= '</ul></li>';
3193: }
3194: } else {
3195: if ($confhash->{$role}{$key} eq '') {
3196: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
3197: } else {
3198: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
3199: }
3200: }
3201: if ($role ne 'login') {
3202: $resulttext .= '</ul>';
3203: }
3204: }
3205: }
3206: }
1.3 raeburn 3207: return $resulttext;
1.1 raeburn 3208: }
3209:
1.9 raeburn 3210: sub thumb_dimensions {
3211: return ('200','50');
3212: }
3213:
1.16 raeburn 3214: sub check_dimensions {
3215: my ($inputfile) = @_;
3216: my ($fullwidth,$fullheight);
3217: if ($inputfile =~ m|^[/\w.\-]+$|) {
3218: if (open(PIPE,"identify $inputfile 2>&1 |")) {
3219: my $imageinfo = <PIPE>;
3220: if (!close(PIPE)) {
3221: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
3222: }
3223: chomp($imageinfo);
3224: my ($fullsize) =
1.21 raeburn 3225: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 3226: if ($fullsize) {
3227: ($fullwidth,$fullheight) = split(/x/,$fullsize);
3228: }
3229: }
3230: }
3231: return ($fullwidth,$fullheight);
3232: }
3233:
1.9 raeburn 3234: sub check_configuser {
3235: my ($uhome,$dom,$confname,$servadm) = @_;
3236: my ($configuserok,%currroles);
3237: if ($uhome eq 'no_host') {
3238: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
3239: my $configpass = &LONCAPA::Enrollment::create_password();
3240: $configuserok =
3241: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
3242: $configpass,'','','','','',undef,$servadm);
3243: } else {
3244: $configuserok = 'ok';
3245: %currroles =
3246: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
3247: }
3248: return ($configuserok,%currroles);
3249: }
3250:
3251: sub check_authorstatus {
3252: my ($dom,$confname,%currroles) = @_;
3253: my $author_ok;
1.40 raeburn 3254: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 3255: my $start = time;
3256: my $end = 0;
3257: $author_ok =
3258: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 3259: 'au',$end,$start,'','','domconfig');
1.9 raeburn 3260: } else {
3261: $author_ok = 'ok';
3262: }
3263: return $author_ok;
3264: }
3265:
3266: sub publishlogo {
1.46 raeburn 3267: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 3268: my ($output,$fname,$logourl);
3269: if ($action eq 'upload') {
3270: $fname=$env{'form.'.$formname.'.filename'};
3271: chop($env{'form.'.$formname});
3272: } else {
3273: ($fname) = ($formname =~ /([^\/]+)$/);
3274: }
1.46 raeburn 3275: if ($savefileas ne '') {
3276: $fname = $savefileas;
3277: }
1.9 raeburn 3278: $fname=&Apache::lonnet::clean_filename($fname);
3279: # See if there is anything left
3280: unless ($fname) { return ('error: no uploaded file'); }
3281: $fname="$subdir/$fname";
3282: my $filepath='/home/'.$confname.'/public_html';
3283: my ($fnamepath,$file,$fetchthumb);
3284: $file=$fname;
3285: if ($fname=~m|/|) {
3286: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
3287: }
3288: my @parts=split(/\//,$filepath.'/'.$fnamepath);
3289: my $count;
3290: for ($count=4;$count<=$#parts;$count++) {
3291: $filepath.="/$parts[$count]";
3292: if ((-e $filepath)!=1) {
3293: mkdir($filepath,02770);
3294: }
3295: }
3296: # Check for bad extension and disallow upload
3297: if ($file=~/\.(\w+)$/ &&
3298: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
3299: $output =
3300: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
3301: } elsif ($file=~/\.(\w+)$/ &&
3302: !defined(&Apache::loncommon::fileembstyle($1))) {
3303: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
3304: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 3305: $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 3306: } elsif (-d "$filepath/$file") {
3307: $output = &mt('File name is a directory name - rename the file and re-upload');
3308: } else {
3309: my $source = $filepath.'/'.$file;
3310: my $logfile;
3311: if (!open($logfile,">>$source".'.log')) {
3312: return (&mt('No write permission to Construction Space'));
3313: }
3314: print $logfile
3315: "\n================= Publish ".localtime()." ================\n".
3316: $env{'user.name'}.':'.$env{'user.domain'}."\n";
3317: # Save the file
3318: if (!open(FH,'>'.$source)) {
3319: &Apache::lonnet::logthis('Failed to create '.$source);
3320: return (&mt('Failed to create file'));
3321: }
3322: if ($action eq 'upload') {
3323: if (!print FH ($env{'form.'.$formname})) {
3324: &Apache::lonnet::logthis('Failed to write to '.$source);
3325: return (&mt('Failed to write file'));
3326: }
3327: } else {
3328: my $original = &Apache::lonnet::filelocation('',$formname);
3329: if(!copy($original,$source)) {
3330: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
3331: return (&mt('Failed to write file'));
3332: }
3333: }
3334: close(FH);
3335: chmod(0660, $source); # Permissions to rw-rw---.
3336:
3337: my $docroot=$r->dir_config('lonDocRoot');
3338: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
3339: my $copyfile=$targetdir.'/'.$file;
3340:
3341: my @parts=split(/\//,$targetdir);
3342: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
3343: for (my $count=5;$count<=$#parts;$count++) {
3344: $path.="/$parts[$count]";
3345: if (!-e $path) {
3346: print $logfile "\nCreating directory ".$path;
3347: mkdir($path,02770);
3348: }
3349: }
3350: my $versionresult;
3351: if (-e $copyfile) {
3352: $versionresult = &logo_versioning($targetdir,$file,$logfile);
3353: } else {
3354: $versionresult = 'ok';
3355: }
3356: if ($versionresult eq 'ok') {
3357: if (copy($source,$copyfile)) {
3358: print $logfile "\nCopied original source to ".$copyfile."\n";
3359: $output = 'ok';
3360: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
3361: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
3362: } else {
3363: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
3364: $output = &mt('Failed to copy file to RES space').", $!";
3365: }
3366: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
3367: my $inputfile = $filepath.'/'.$file;
3368: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 3369: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
3370: if ($fullwidth ne '' && $fullheight ne '') {
3371: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
3372: my $thumbsize = $thumbwidth.'x'.$thumbheight;
3373: system("convert -sample $thumbsize $inputfile $outfile");
3374: chmod(0660, $filepath.'/tn-'.$file);
3375: if (-e $outfile) {
3376: my $copyfile=$targetdir.'/tn-'.$file;
3377: if (copy($outfile,$copyfile)) {
3378: print $logfile "\nCopied source to ".$copyfile."\n";
3379: &write_metadata($dom,$confname,$formname,
3380: $targetdir,'tn-'.$file,$logfile);
3381: } else {
3382: print $logfile "\nUnable to write ".$copyfile.
3383: ':'.$!."\n";
3384: }
3385: }
1.9 raeburn 3386: }
3387: }
3388: }
3389: } else {
3390: $output = $versionresult;
3391: }
3392: }
3393: return ($output,$logourl);
3394: }
3395:
3396: sub logo_versioning {
3397: my ($targetdir,$file,$logfile) = @_;
3398: my $target = $targetdir.'/'.$file;
3399: my ($maxversion,$fn,$extn,$output);
3400: $maxversion = 0;
3401: if ($file =~ /^(.+)\.(\w+)$/) {
3402: $fn=$1;
3403: $extn=$2;
3404: }
3405: opendir(DIR,$targetdir);
3406: while (my $filename=readdir(DIR)) {
3407: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
3408: $maxversion=($1>$maxversion)?$1:$maxversion;
3409: }
3410: }
3411: $maxversion++;
3412: print $logfile "\nCreating old version ".$maxversion."\n";
3413: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
3414: if (copy($target,$copyfile)) {
3415: print $logfile "Copied old target to ".$copyfile."\n";
3416: $copyfile=$copyfile.'.meta';
3417: if (copy($target.'.meta',$copyfile)) {
3418: print $logfile "Copied old target metadata to ".$copyfile."\n";
3419: $output = 'ok';
3420: } else {
3421: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
3422: $output = &mt('Failed to copy old meta').", $!, ";
3423: }
3424: } else {
3425: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
3426: $output = &mt('Failed to copy old target').", $!, ";
3427: }
3428: return $output;
3429: }
3430:
3431: sub write_metadata {
3432: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
3433: my (%metadatafields,%metadatakeys,$output);
3434: $metadatafields{'title'}=$formname;
3435: $metadatafields{'creationdate'}=time;
3436: $metadatafields{'lastrevisiondate'}=time;
3437: $metadatafields{'copyright'}='public';
3438: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
3439: $env{'user.domain'};
3440: $metadatafields{'authorspace'}=$confname.':'.$dom;
3441: $metadatafields{'domain'}=$dom;
3442: {
3443: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
3444: my $mfh;
3445: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
3446: $output = &mt('Could not write metadata');
3447: }
3448: foreach (sort keys %metadatafields) {
3449: unless ($_=~/\./) {
3450: my $unikey=$_;
3451: $unikey=~/^([A-Za-z]+)/;
3452: my $tag=$1;
3453: $tag=~tr/A-Z/a-z/;
3454: print $mfh "\n\<$tag";
3455: foreach (split(/\,/,$metadatakeys{$unikey})) {
3456: my $value=$metadatafields{$unikey.'.'.$_};
3457: $value=~s/\"/\'\'/g;
3458: print $mfh ' '.$_.'="'.$value.'"';
3459: }
3460: print $mfh '>'.
3461: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
3462: .'</'.$tag.'>';
3463: }
3464: }
3465: $output = 'ok';
3466: print $logfile "\nWrote metadata";
3467: close($mfh);
3468: }
3469: }
3470:
3471: sub check_switchserver {
3472: my ($dom,$confname) = @_;
3473: my ($allowed,$switchserver);
3474: my $home = &Apache::lonnet::homeserver($confname,$dom);
3475: if ($home eq 'no_host') {
3476: $home = &Apache::lonnet::domain($dom,'primary');
3477: }
3478: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 3479: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3480: if (!$allowed) {
3481: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 3482: }
3483: return $switchserver;
3484: }
3485:
1.30 raeburn 3486: sub javascript_set_colnums {
3487: return <<END;
3488: function setDisplayColumns() {
3489: if (document.pickactions.width.value > 1100) {
3490: document.pickactions.numcols[1].checked = true;
3491: } else {
3492: document.pickactions.numcols[0].checked = true;
3493: }
3494: }
3495: END
3496: }
3497:
1.1 raeburn 3498: sub modify_quotas {
1.3 raeburn 3499: my ($dom,%domconfig) = @_;
1.72 raeburn 3500: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.1 raeburn 3501: my ($resulttext,%changes);
1.44 raeburn 3502: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.72 raeburn 3503: my @usertools = ('aboutme','blog','portfolio');
3504: my %titles = &tool_titles();
3505: my (%confhash,%toolshash);
1.1 raeburn 3506: foreach my $key (keys(%env)) {
3507: if ($key =~ /^form\.quota_(.+)$/) {
1.72 raeburn 3508: $confhash{'defaultquota'}{$1} = $env{$key};
3509: } elsif ($key =~ /^form\.tools_(.+)$/) {
3510: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
3511: }
3512: }
3513: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
3514: foreach my $item (@usertools) {
3515: foreach my $type (@{$types},'default','_LC_adv') {
3516: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
3517: $confhash{$item}{$type} = 1;
3518: } else {
3519: $confhash{$item}{$type} = 0;
3520: }
3521: if (ref($domconfig{'quotas'}) eq 'HASH') {
3522: if (ref($domconfig{'quotas'}{$item}) eq 'HASH') {
3523: if ($domconfig{'quotas'}{$item}{$type} ne $confhash{$item}{$type}) {
3524: $changes{$item}{$type} = 1;
3525: }
3526: } else {
3527: if (!$confhash{$item}{$type}) {
3528: $changes{$item}{$type} = 1;
3529: }
3530: }
3531: } else {
3532: if (!$confhash{$item}{$type}) {
3533: $changes{$item}{$type} = 1;
3534: }
3535: }
1.1 raeburn 3536: }
3537: }
3538: if (ref($domconfig{'quotas'}) eq 'HASH') {
1.72 raeburn 3539: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3540: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
3541: if (exists($confhash{'defaultquota'}{$key})) {
3542: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
3543: $changes{'defaultquota'}{$key} = 1;
3544: }
3545: } else {
3546: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
3547: }
3548: }
3549: } else {
3550: foreach my $key (keys(%{$domconfig{'quotas'}})) {
3551: if (exists($confhash{'defaultquota'}{$key})) {
3552: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
3553: $changes{'defaultquota'}{$key} = 1;
3554: }
3555: } else {
3556: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.1 raeburn 3557: }
3558: }
3559: }
3560: }
1.72 raeburn 3561: if (ref($confhash{'defaultquota'}) eq 'HASH') {
3562: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
1.55 raeburn 3563: if (ref($domconfig{'quotas'}) eq 'HASH') {
1.72 raeburn 3564: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3565: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
3566: $changes{'defaultquota'}{$key} = 1;
3567: }
3568: } else {
3569: if (!exists($domconfig{'quotas'}{$key})) {
3570: $changes{'defaultquota'}{$key} = 1;
3571: }
1.55 raeburn 3572: }
3573: } else {
1.72 raeburn 3574: $changes{'defaultquota'}{$key} = 1;
1.1 raeburn 3575: }
3576: }
3577: }
1.72 raeburn 3578:
3579: foreach my $key (keys(%confhash)) {
3580: $domdefaults{$key} = $confhash{$key};
3581: }
3582:
1.1 raeburn 3583: my %quotahash = (
1.72 raeburn 3584: quotas => { %confhash }
1.1 raeburn 3585: );
3586: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
3587: $dom);
3588: if ($putresult eq 'ok') {
3589: if (keys(%changes) > 0) {
1.72 raeburn 3590: my $cachetime = 24*60*60;
3591: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
3592:
1.1 raeburn 3593: $resulttext = &mt('Changes made:').'<ul>';
1.72 raeburn 3594: if (ref($changes{'defaultquota'}) eq 'HASH') {
3595: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
3596: foreach my $type (@{$types},'default') {
3597: if (defined($changes{'defaultquota'}{$type})) {
3598: my $typetitle = $usertypes->{$type};
3599: if ($type eq 'default') {
3600: $typetitle = $othertitle;
3601: }
3602: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
3603: }
3604: }
3605: $resulttext .= '</ul></li>';
3606: }
3607: foreach my $item (@usertools) {
3608: if (ref($changes{$item}) eq 'HASH') {
1.73 raeburn 3609: my $hashid = $env{'user.name'}.':'.$env{'user.domain'};
3610: &Apache::lonnet::devalidate_cache_new('usertools.'.$item,$hashid);
1.72 raeburn 3611: $resulttext .= '<li>'.$titles{$item}.'<ul>';
3612: foreach my $type (@{$types},'default','_LC_adv') {
3613: if ($changes{$item}{$type}) {
3614: my $typetitle = $usertypes->{$type};
3615: if ($type eq 'default') {
3616: $typetitle = $othertitle;
3617: } elsif ($type eq '_LC_adv') {
3618: $typetitle = 'LON-CAPA Advanced Users';
3619: }
3620: if ($confhash{$item}{$type}) {
3621: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
3622: } else {
3623: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
3624: }
3625: }
1.26 raeburn 3626: }
1.72 raeburn 3627: $resulttext .= '</ul></li>';
1.26 raeburn 3628: }
1.1 raeburn 3629: }
3630: $resulttext .= '</ul>';
3631: } else {
1.72 raeburn 3632: $resulttext = &mt('No changes made to availability of home pages, blogs, portfolios or default quotas');
1.1 raeburn 3633: }
3634: } else {
1.11 albertel 3635: $resulttext = '<span class="LC_error">'.
3636: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3637: }
1.3 raeburn 3638: return $resulttext;
1.1 raeburn 3639: }
3640:
1.3 raeburn 3641: sub modify_autoenroll {
3642: my ($dom,%domconfig) = @_;
1.1 raeburn 3643: my ($resulttext,%changes);
3644: my %currautoenroll;
3645: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
3646: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
3647: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
3648: }
3649: }
3650: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
3651: my %title = ( run => 'Auto-enrollment active',
3652: sender => 'Sender for notification messages');
3653: my @offon = ('off','on');
1.17 raeburn 3654: my $sender_uname = $env{'form.sender_uname'};
3655: my $sender_domain = $env{'form.sender_domain'};
3656: if ($sender_domain eq '') {
3657: $sender_uname = '';
3658: } elsif ($sender_uname eq '') {
3659: $sender_domain = '';
3660: }
1.1 raeburn 3661: my %autoenrollhash = (
3662: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 3663: sender_uname => $sender_uname,
3664: sender_domain => $sender_domain,
1.1 raeburn 3665:
3666: }
3667: );
1.4 raeburn 3668: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
3669: $dom);
1.1 raeburn 3670: if ($putresult eq 'ok') {
3671: if (exists($currautoenroll{'run'})) {
3672: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
3673: $changes{'run'} = 1;
3674: }
3675: } elsif ($autorun) {
3676: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 3677: $changes{'run'} = 1;
1.1 raeburn 3678: }
3679: }
1.17 raeburn 3680: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 3681: $changes{'sender'} = 1;
3682: }
1.17 raeburn 3683: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 3684: $changes{'sender'} = 1;
3685: }
3686: if (keys(%changes) > 0) {
3687: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 3688: if ($changes{'run'}) {
1.1 raeburn 3689: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
3690: }
3691: if ($changes{'sender'}) {
1.17 raeburn 3692: if ($sender_uname eq '' || $sender_domain eq '') {
3693: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
3694: } else {
3695: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
3696: }
1.1 raeburn 3697: }
3698: $resulttext .= '</ul>';
3699: } else {
3700: $resulttext = &mt('No changes made to auto-enrollment settings');
3701: }
3702: } else {
1.11 albertel 3703: $resulttext = '<span class="LC_error">'.
3704: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3705: }
1.3 raeburn 3706: return $resulttext;
1.1 raeburn 3707: }
3708:
3709: sub modify_autoupdate {
1.3 raeburn 3710: my ($dom,%domconfig) = @_;
1.1 raeburn 3711: my ($resulttext,%currautoupdate,%fields,%changes);
3712: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
3713: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
3714: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
3715: }
3716: }
3717: my @offon = ('off','on');
3718: my %title = &Apache::lonlocal::texthash (
3719: run => 'Auto-update:',
3720: classlists => 'Updates to user information in classlists?'
3721: );
1.44 raeburn 3722: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 3723: my %fieldtitles = &Apache::lonlocal::texthash (
3724: id => 'Student/Employee ID',
1.20 raeburn 3725: permanentemail => 'E-mail address',
1.1 raeburn 3726: lastname => 'Last Name',
3727: firstname => 'First Name',
3728: middlename => 'Middle Name',
3729: gen => 'Generation',
3730: );
3731: my $othertitle = &mt('All users');
3732: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 3733: $othertitle = &mt('Other users');
1.1 raeburn 3734: }
3735: foreach my $key (keys(%env)) {
3736: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
3737: push(@{$fields{$1}},$2);
3738: }
3739: }
3740: my %updatehash = (
3741: autoupdate => { run => $env{'form.autoupdate_run'},
3742: classlists => $env{'form.classlists'},
3743: fields => {%fields},
3744: }
3745: );
3746: foreach my $key (keys(%currautoupdate)) {
3747: if (($key eq 'run') || ($key eq 'classlists')) {
3748: if (exists($updatehash{autoupdate}{$key})) {
3749: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
3750: $changes{$key} = 1;
3751: }
3752: }
3753: } elsif ($key eq 'fields') {
3754: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 3755: foreach my $item (@{$types},'default') {
1.1 raeburn 3756: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
3757: my $change = 0;
3758: foreach my $type (@{$currautoupdate{$key}{$item}}) {
3759: if (!exists($fields{$item})) {
3760: $change = 1;
3761: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 3762: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 3763: $change = 1;
3764: }
3765: }
3766: }
3767: if ($change) {
3768: push(@{$changes{$key}},$item);
3769: }
1.26 raeburn 3770: }
1.1 raeburn 3771: }
3772: }
3773: }
3774: }
1.26 raeburn 3775: foreach my $item (@{$types},'default') {
3776: if (defined($fields{$item})) {
3777: if (ref($currautoupdate{'fields'}) eq 'HASH') {
3778: if (!exists($currautoupdate{'fields'}{$item})) {
3779: push(@{$changes{'fields'}},$item);
3780: }
3781: } else {
3782: push(@{$changes{'fields'}},$item);
1.1 raeburn 3783: }
3784: }
3785: }
3786: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
3787: $dom);
3788: if ($putresult eq 'ok') {
3789: if (keys(%changes) > 0) {
3790: $resulttext = &mt('Changes made:').'<ul>';
3791: foreach my $key (sort(keys(%changes))) {
3792: if (ref($changes{$key}) eq 'ARRAY') {
3793: foreach my $item (@{$changes{$key}}) {
3794: my @newvalues;
3795: foreach my $type (@{$fields{$item}}) {
3796: push(@newvalues,$fieldtitles{$type});
3797: }
1.3 raeburn 3798: my $newvaluestr;
3799: if (@newvalues > 0) {
3800: $newvaluestr = join(', ',@newvalues);
3801: } else {
3802: $newvaluestr = &mt('none');
1.6 raeburn 3803: }
1.1 raeburn 3804: if ($item eq 'default') {
1.26 raeburn 3805: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 3806: } else {
1.26 raeburn 3807: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 3808: }
3809: }
3810: } else {
3811: my $newvalue;
3812: if ($key eq 'run') {
3813: $newvalue = $offon[$env{'form.autoupdate_run'}];
3814: } else {
3815: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 3816: }
1.1 raeburn 3817: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
3818: }
3819: }
3820: $resulttext .= '</ul>';
3821: } else {
1.3 raeburn 3822: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 3823: }
3824: } else {
1.11 albertel 3825: $resulttext = '<span class="LC_error">'.
3826: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3827: }
1.3 raeburn 3828: return $resulttext;
1.1 raeburn 3829: }
3830:
1.23 raeburn 3831: sub modify_directorysrch {
3832: my ($dom,%domconfig) = @_;
3833: my ($resulttext,%changes);
3834: my %currdirsrch;
3835: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3836: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
3837: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
3838: }
3839: }
3840: my %title = ( available => 'Directory search available',
1.24 raeburn 3841: localonly => 'Other domains can search',
1.23 raeburn 3842: searchby => 'Search types',
3843: searchtypes => 'Search latitude');
3844: my @offon = ('off','on');
1.24 raeburn 3845: my @otherdoms = ('Yes','No');
1.23 raeburn 3846:
1.25 raeburn 3847: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 3848: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
3849: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
3850:
1.44 raeburn 3851: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 3852: if (keys(%{$usertypes}) == 0) {
3853: @cansearch = ('default');
3854: } else {
3855: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
3856: foreach my $type (@{$currdirsrch{'cansearch'}}) {
3857: if (!grep(/^\Q$type\E$/,@cansearch)) {
3858: push(@{$changes{'cansearch'}},$type);
3859: }
1.23 raeburn 3860: }
1.26 raeburn 3861: foreach my $type (@cansearch) {
3862: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
3863: push(@{$changes{'cansearch'}},$type);
3864: }
1.23 raeburn 3865: }
1.26 raeburn 3866: } else {
3867: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 3868: }
3869: }
3870:
3871: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
3872: foreach my $by (@{$currdirsrch{'searchby'}}) {
3873: if (!grep(/^\Q$by\E$/,@searchby)) {
3874: push(@{$changes{'searchby'}},$by);
3875: }
3876: }
3877: foreach my $by (@searchby) {
3878: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
3879: push(@{$changes{'searchby'}},$by);
3880: }
3881: }
3882: } else {
3883: push(@{$changes{'searchby'}},@searchby);
3884: }
1.25 raeburn 3885:
3886: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
3887: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
3888: if (!grep(/^\Q$type\E$/,@searchtypes)) {
3889: push(@{$changes{'searchtypes'}},$type);
3890: }
3891: }
3892: foreach my $type (@searchtypes) {
3893: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
3894: push(@{$changes{'searchtypes'}},$type);
3895: }
3896: }
3897: } else {
3898: if (exists($currdirsrch{'searchtypes'})) {
3899: foreach my $type (@searchtypes) {
3900: if ($type ne $currdirsrch{'searchtypes'}) {
3901: push(@{$changes{'searchtypes'}},$type);
3902: }
3903: }
3904: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
3905: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
3906: }
3907: } else {
3908: push(@{$changes{'searchtypes'}},@searchtypes);
3909: }
3910: }
3911:
1.23 raeburn 3912: my %dirsrch_hash = (
3913: directorysrch => { available => $env{'form.dirsrch_available'},
3914: cansearch => \@cansearch,
1.24 raeburn 3915: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 3916: searchby => \@searchby,
1.25 raeburn 3917: searchtypes => \@searchtypes,
1.23 raeburn 3918: }
3919: );
3920: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
3921: $dom);
3922: if ($putresult eq 'ok') {
3923: if (exists($currdirsrch{'available'})) {
3924: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
3925: $changes{'available'} = 1;
3926: }
3927: } else {
3928: if ($env{'form.dirsrch_available'} eq '1') {
3929: $changes{'available'} = 1;
3930: }
3931: }
1.24 raeburn 3932: if (exists($currdirsrch{'localonly'})) {
3933: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
3934: $changes{'localonly'} = 1;
3935: }
3936: } else {
3937: if ($env{'form.dirsrch_localonly'} eq '1') {
3938: $changes{'localonly'} = 1;
3939: }
3940: }
1.23 raeburn 3941: if (keys(%changes) > 0) {
3942: $resulttext = &mt('Changes made:').'<ul>';
3943: if ($changes{'available'}) {
3944: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
3945: }
1.24 raeburn 3946: if ($changes{'localonly'}) {
3947: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
3948: }
3949:
1.23 raeburn 3950: if (ref($changes{'cansearch'}) eq 'ARRAY') {
3951: my $chgtext;
1.26 raeburn 3952: if (ref($usertypes) eq 'HASH') {
3953: if (keys(%{$usertypes}) > 0) {
3954: foreach my $type (@{$types}) {
3955: if (grep(/^\Q$type\E$/,@cansearch)) {
3956: $chgtext .= $usertypes->{$type}.'; ';
3957: }
3958: }
3959: if (grep(/^default$/,@cansearch)) {
3960: $chgtext .= $othertitle;
3961: } else {
3962: $chgtext =~ s/\; $//;
3963: }
3964: $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 3965: }
3966: }
3967: }
3968: if (ref($changes{'searchby'}) eq 'ARRAY') {
3969: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3970: my $chgtext;
3971: foreach my $type (@{$titleorder}) {
3972: if (grep(/^\Q$type\E$/,@searchby)) {
3973: if (defined($searchtitles->{$type})) {
3974: $chgtext .= $searchtitles->{$type}.'; ';
3975: }
3976: }
3977: }
3978: $chgtext =~ s/\; $//;
3979: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
3980: }
1.25 raeburn 3981: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
3982: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
3983: my $chgtext;
3984: foreach my $type (@{$srchtypeorder}) {
3985: if (grep(/^\Q$type\E$/,@searchtypes)) {
3986: if (defined($srchtypes_desc->{$type})) {
3987: $chgtext .= $srchtypes_desc->{$type}.'; ';
3988: }
3989: }
3990: }
3991: $chgtext =~ s/\; $//;
3992: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 3993: }
3994: $resulttext .= '</ul>';
3995: } else {
3996: $resulttext = &mt('No changes made to institution directory search settings');
3997: }
3998: } else {
3999: $resulttext = '<span class="LC_error">'.
1.27 raeburn 4000: &mt('An error occurred: [_1]',$putresult).'</span>';
4001: }
4002: return $resulttext;
4003: }
4004:
1.28 raeburn 4005: sub modify_contacts {
4006: my ($dom,%domconfig) = @_;
4007: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
4008: if (ref($domconfig{'contacts'}) eq 'HASH') {
4009: foreach my $key (keys(%{$domconfig{'contacts'}})) {
4010: $currsetting{$key} = $domconfig{'contacts'}{$key};
4011: }
4012: }
4013: my (%others,%to);
4014: my @contacts = ('supportemail','adminemail');
4015: my @mailings = ('errormail','packagesmail','helpdeskmail');
4016: foreach my $type (@mailings) {
4017: @{$newsetting{$type}} =
4018: &Apache::loncommon::get_env_multiple('form.'.$type);
4019: foreach my $item (@contacts) {
4020: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
4021: $contacts_hash{contacts}{$type}{$item} = 1;
4022: } else {
4023: $contacts_hash{contacts}{$type}{$item} = 0;
4024: }
4025: }
4026: $others{$type} = $env{'form.'.$type.'_others'};
4027: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
4028: }
4029: foreach my $item (@contacts) {
4030: $to{$item} = $env{'form.'.$item};
4031: $contacts_hash{'contacts'}{$item} = $to{$item};
4032: }
4033: if (keys(%currsetting) > 0) {
4034: foreach my $item (@contacts) {
4035: if ($to{$item} ne $currsetting{$item}) {
4036: $changes{$item} = 1;
4037: }
4038: }
4039: foreach my $type (@mailings) {
4040: foreach my $item (@contacts) {
4041: if (ref($currsetting{$type}) eq 'HASH') {
4042: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
4043: push(@{$changes{$type}},$item);
4044: }
4045: } else {
4046: push(@{$changes{$type}},@{$newsetting{$type}});
4047: }
4048: }
4049: if ($others{$type} ne $currsetting{$type}{'others'}) {
4050: push(@{$changes{$type}},'others');
4051: }
4052: }
4053: } else {
4054: my %default;
4055: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4056: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4057: $default{'errormail'} = 'adminemail';
4058: $default{'packagesmail'} = 'adminemail';
4059: $default{'helpdeskmail'} = 'supportemail';
4060: foreach my $item (@contacts) {
4061: if ($to{$item} ne $default{$item}) {
4062: $changes{$item} = 1;
4063: }
4064: }
4065: foreach my $type (@mailings) {
4066: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
4067:
4068: push(@{$changes{$type}},@{$newsetting{$type}});
4069: }
4070: if ($others{$type} ne '') {
4071: push(@{$changes{$type}},'others');
4072: }
4073: }
4074: }
4075: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
4076: $dom);
4077: if ($putresult eq 'ok') {
4078: if (keys(%changes) > 0) {
4079: my ($titles,$short_titles) = &contact_titles();
4080: $resulttext = &mt('Changes made:').'<ul>';
4081: foreach my $item (@contacts) {
4082: if ($changes{$item}) {
4083: $resulttext .= '<li>'.$titles->{$item}.
4084: &mt(' set to: ').
4085: '<span class="LC_cusr_emph">'.
4086: $to{$item}.'</span></li>';
4087: }
4088: }
4089: foreach my $type (@mailings) {
4090: if (ref($changes{$type}) eq 'ARRAY') {
4091: $resulttext .= '<li>'.$titles->{$type}.': ';
4092: my @text;
4093: foreach my $item (@{$newsetting{$type}}) {
4094: push(@text,$short_titles->{$item});
4095: }
4096: if ($others{$type} ne '') {
4097: push(@text,$others{$type});
4098: }
4099: $resulttext .= '<span class="LC_cusr_emph">'.
4100: join(', ',@text).'</span></li>';
4101: }
4102: }
4103: $resulttext .= '</ul>';
4104: } else {
1.34 raeburn 4105: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 4106: }
4107: } else {
4108: $resulttext = '<span class="LC_error">'.
4109: &mt('An error occurred: [_1].',$putresult).'</span>';
4110: }
4111: return $resulttext;
4112: }
4113:
4114: sub modify_usercreation {
1.27 raeburn 4115: my ($dom,%domconfig) = @_;
1.34 raeburn 4116: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 4117: my $warningmsg;
1.27 raeburn 4118: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4119: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
4120: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
4121: }
4122: }
4123: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 4124: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 4125: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.45 raeburn 4126: my @contexts = ('author','course','selfcreate');
1.34 raeburn 4127: foreach my $item(@contexts) {
1.45 raeburn 4128: if ($item eq 'selfcreate') {
1.50 raeburn 4129: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 4130: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4131: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 4132: if (ref($cancreate{$item}) eq 'ARRAY') {
4133: if (grep(/^login$/,@{$cancreate{$item}})) {
4134: $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.');
4135: }
1.43 raeburn 4136: }
4137: }
1.50 raeburn 4138: } else {
4139: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 4140: }
1.34 raeburn 4141: }
4142: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
4143: foreach my $item (@contexts) {
1.50 raeburn 4144: if ($item eq 'selfcreate') {
4145: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
4146: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
4147: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
4148: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4149: push(@{$changes{'cancreate'}},$item);
4150: }
4151: }
4152: }
4153: } else {
4154: if ($curr_usercreation{'cancreate'}{$item} eq '') {
4155: if (@{$cancreate{$item}} > 0) {
4156: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4157: push(@{$changes{'cancreate'}},$item);
4158: }
4159: }
4160: } else {
4161: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
4162: if (@{$cancreate{$item}} < 3) {
4163: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4164: push(@{$changes{'cancreate'}},$item);
4165: }
4166: }
4167: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
4168: if (@{$cancreate{$item}} > 0) {
4169: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4170: push(@{$changes{'cancreate'}},$item);
4171: }
4172: }
4173: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
4174: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4175: push(@{$changes{'cancreate'}},$item);
4176: }
4177: }
4178: }
4179: }
4180: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4181: foreach my $type (@{$cancreate{$item}}) {
4182: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
4183: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
4184: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4185: push(@{$changes{'cancreate'}},$item);
4186: }
4187: }
4188: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
4189: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
4190: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
4191: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4192: push(@{$changes{'cancreate'}},$item);
4193: }
4194: }
4195: }
4196: }
4197: }
4198: } else {
4199: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
4200: push(@{$changes{'cancreate'}},$item);
4201: }
4202: }
1.27 raeburn 4203: }
1.34 raeburn 4204: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
4205: foreach my $item (@contexts) {
1.43 raeburn 4206: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 4207: if ($cancreate{$item} ne 'any') {
4208: push(@{$changes{'cancreate'}},$item);
4209: }
4210: } else {
4211: if ($cancreate{$item} ne 'none') {
4212: push(@{$changes{'cancreate'}},$item);
4213: }
1.27 raeburn 4214: }
4215: }
4216: } else {
1.43 raeburn 4217: foreach my $item (@contexts) {
1.34 raeburn 4218: push(@{$changes{'cancreate'}},$item);
4219: }
1.27 raeburn 4220: }
1.34 raeburn 4221:
1.27 raeburn 4222: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
4223: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
4224: if (!grep(/^\Q$type\E$/,@username_rule)) {
4225: push(@{$changes{'username_rule'}},$type);
4226: }
4227: }
4228: foreach my $type (@username_rule) {
4229: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
4230: push(@{$changes{'username_rule'}},$type);
4231: }
4232: }
4233: } else {
4234: push(@{$changes{'username_rule'}},@username_rule);
4235: }
4236:
1.32 raeburn 4237: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
4238: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
4239: if (!grep(/^\Q$type\E$/,@id_rule)) {
4240: push(@{$changes{'id_rule'}},$type);
4241: }
4242: }
4243: foreach my $type (@id_rule) {
4244: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
4245: push(@{$changes{'id_rule'}},$type);
4246: }
4247: }
4248: } else {
4249: push(@{$changes{'id_rule'}},@id_rule);
4250: }
4251:
1.43 raeburn 4252: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
4253: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
4254: if (!grep(/^\Q$type\E$/,@email_rule)) {
4255: push(@{$changes{'email_rule'}},$type);
4256: }
4257: }
4258: foreach my $type (@email_rule) {
4259: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
4260: push(@{$changes{'email_rule'}},$type);
4261: }
4262: }
4263: } else {
4264: push(@{$changes{'email_rule'}},@email_rule);
4265: }
4266:
4267: my @authen_contexts = ('author','course','domain');
1.28 raeburn 4268: my @authtypes = ('int','krb4','krb5','loc');
4269: my %authhash;
1.43 raeburn 4270: foreach my $item (@authen_contexts) {
1.28 raeburn 4271: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
4272: foreach my $auth (@authtypes) {
4273: if (grep(/^\Q$auth\E$/,@authallowed)) {
4274: $authhash{$item}{$auth} = 1;
4275: } else {
4276: $authhash{$item}{$auth} = 0;
4277: }
4278: }
4279: }
4280: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 4281: foreach my $item (@authen_contexts) {
1.28 raeburn 4282: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
4283: foreach my $auth (@authtypes) {
4284: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
4285: push(@{$changes{'authtypes'}},$item);
4286: last;
4287: }
4288: }
4289: }
4290: }
4291: } else {
1.43 raeburn 4292: foreach my $item (@authen_contexts) {
1.28 raeburn 4293: push(@{$changes{'authtypes'}},$item);
4294: }
4295: }
4296:
1.27 raeburn 4297: my %usercreation_hash = (
1.28 raeburn 4298: usercreation => {
1.34 raeburn 4299: cancreate => \%cancreate,
1.27 raeburn 4300: username_rule => \@username_rule,
1.32 raeburn 4301: id_rule => \@id_rule,
1.43 raeburn 4302: email_rule => \@email_rule,
1.32 raeburn 4303: authtypes => \%authhash,
1.27 raeburn 4304: }
4305: );
4306:
4307: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
4308: $dom);
1.50 raeburn 4309:
4310: my %selfcreatetypes = (
4311: sso => 'users authenticated by institutional single sign on',
4312: login => 'users authenticated by institutional log-in',
4313: email => 'users who provide a valid e-mail address for use as the username',
4314: );
1.27 raeburn 4315: if ($putresult eq 'ok') {
4316: if (keys(%changes) > 0) {
4317: $resulttext = &mt('Changes made:').'<ul>';
4318: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 4319: my %lt = &usercreation_types();
4320: foreach my $type (@{$changes{'cancreate'}}) {
1.43 raeburn 4321: my $chgtext = $lt{$type}.', ';
1.45 raeburn 4322: if ($type eq 'selfcreate') {
1.50 raeburn 4323: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 4324: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 4325: } else {
4326: $chgtext .= &mt('creation of a new account is permitted for:<ul>');
4327: foreach my $case (@{$cancreate{$type}}) {
4328: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
4329: }
4330: $chgtext .= '</ul>';
1.43 raeburn 4331: }
4332: } else {
4333: if ($cancreate{$type} eq 'none') {
4334: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
4335: } elsif ($cancreate{$type} eq 'any') {
4336: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
4337: } elsif ($cancreate{$type} eq 'official') {
4338: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
4339: } elsif ($cancreate{$type} eq 'unofficial') {
4340: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
4341: }
1.34 raeburn 4342: }
4343: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 4344: }
4345: }
4346: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 4347: my ($rules,$ruleorder) =
4348: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 4349: my $chgtext = '<ul>';
4350: foreach my $type (@username_rule) {
4351: if (ref($rules->{$type}) eq 'HASH') {
4352: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
4353: }
4354: }
4355: $chgtext .= '</ul>';
4356: if (@username_rule > 0) {
4357: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4358: } else {
1.28 raeburn 4359: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 4360: }
4361: }
1.32 raeburn 4362: if (ref($changes{'id_rule'}) eq 'ARRAY') {
4363: my ($idrules,$idruleorder) =
4364: &Apache::lonnet::inst_userrules($dom,'id');
4365: my $chgtext = '<ul>';
4366: foreach my $type (@id_rule) {
4367: if (ref($idrules->{$type}) eq 'HASH') {
4368: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
4369: }
4370: }
4371: $chgtext .= '</ul>';
4372: if (@id_rule > 0) {
4373: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4374: } else {
4375: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
4376: }
4377: }
1.43 raeburn 4378: if (ref($changes{'email_rule'}) eq 'ARRAY') {
4379: my ($emailrules,$emailruleorder) =
4380: &Apache::lonnet::inst_userrules($dom,'email');
4381: my $chgtext = '<ul>';
4382: foreach my $type (@email_rule) {
4383: if (ref($emailrules->{$type}) eq 'HASH') {
4384: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
4385: }
4386: }
4387: $chgtext .= '</ul>';
4388: if (@email_rule > 0) {
4389: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
4390: } else {
4391: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
4392: }
4393: }
4394:
1.28 raeburn 4395: my %authname = &authtype_names();
4396: my %context_title = &context_names();
4397: if (ref($changes{'authtypes'}) eq 'ARRAY') {
4398: my $chgtext = '<ul>';
4399: foreach my $type (@{$changes{'authtypes'}}) {
4400: my @allowed;
4401: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
4402: foreach my $auth (@authtypes) {
4403: if ($authhash{$type}{$auth}) {
4404: push(@allowed,$authname{$auth});
4405: }
4406: }
1.43 raeburn 4407: if (@allowed > 0) {
4408: $chgtext .= join(', ',@allowed).'</li>';
4409: } else {
4410: $chgtext .= &mt('none').'</li>';
4411: }
1.28 raeburn 4412: }
4413: $chgtext .= '</ul>';
4414: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
4415: $resulttext .= '</li>';
4416: }
1.27 raeburn 4417: $resulttext .= '</ul>';
4418: } else {
1.28 raeburn 4419: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 4420: }
4421: } else {
4422: $resulttext = '<span class="LC_error">'.
1.23 raeburn 4423: &mt('An error occurred: [_1]',$putresult).'</span>';
4424: }
1.43 raeburn 4425: if ($warningmsg ne '') {
4426: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
4427: }
1.23 raeburn 4428: return $resulttext;
4429: }
4430:
1.33 raeburn 4431: sub modify_usermodification {
4432: my ($dom,%domconfig) = @_;
4433: my ($resulttext,%curr_usermodification,%changes);
4434: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4435: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
4436: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
4437: }
4438: }
1.63 raeburn 4439: my @contexts = ('author','course','selfcreate');
1.33 raeburn 4440: my %context_title = (
4441: author => 'In author context',
4442: course => 'In course context',
1.63 raeburn 4443: selfcreate => 'When self creating account',
1.33 raeburn 4444: );
4445: my @fields = ('lastname','firstname','middlename','generation',
4446: 'permanentemail','id');
4447: my %roles = (
4448: author => ['ca','aa'],
4449: course => ['st','ep','ta','in','cr'],
4450: );
1.63 raeburn 4451: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4452: if (ref($types) eq 'ARRAY') {
4453: push(@{$types},'default');
4454: $usertypes->{'default'} = $othertitle;
4455: }
4456: $roles{'selfcreate'} = $types;
1.33 raeburn 4457: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4458: my %modifyhash;
4459: foreach my $context (@contexts) {
4460: foreach my $role (@{$roles{$context}}) {
4461: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
4462: foreach my $item (@fields) {
4463: if (grep(/^\Q$item\E$/,@modifiable)) {
4464: $modifyhash{$context}{$role}{$item} = 1;
4465: } else {
4466: $modifyhash{$context}{$role}{$item} = 0;
4467: }
4468: }
4469: }
4470: if (ref($curr_usermodification{$context}) eq 'HASH') {
4471: foreach my $role (@{$roles{$context}}) {
4472: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
4473: foreach my $field (@fields) {
4474: if ($modifyhash{$context}{$role}{$field} ne
4475: $curr_usermodification{$context}{$role}{$field}) {
4476: push(@{$changes{$context}},$role);
4477: last;
4478: }
4479: }
4480: }
4481: }
4482: } else {
4483: foreach my $context (@contexts) {
4484: foreach my $role (@{$roles{$context}}) {
4485: push(@{$changes{$context}},$role);
4486: }
4487: }
4488: }
4489: }
4490: my %usermodification_hash = (
4491: usermodification => \%modifyhash,
4492: );
4493: my $putresult = &Apache::lonnet::put_dom('configuration',
4494: \%usermodification_hash,$dom);
4495: if ($putresult eq 'ok') {
4496: if (keys(%changes) > 0) {
4497: $resulttext = &mt('Changes made: ').'<ul>';
4498: foreach my $context (@contexts) {
4499: if (ref($changes{$context}) eq 'ARRAY') {
4500: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
4501: if (ref($changes{$context}) eq 'ARRAY') {
4502: foreach my $role (@{$changes{$context}}) {
4503: my $rolename;
1.63 raeburn 4504: if ($context eq 'selfcreate') {
4505: $rolename = $role;
4506: if (ref($usertypes) eq 'HASH') {
4507: if ($usertypes->{$role} ne '') {
4508: $rolename = $usertypes->{$role};
4509: }
4510: }
1.33 raeburn 4511: } else {
1.63 raeburn 4512: if ($role eq 'cr') {
4513: $rolename = &mt('Custom');
4514: } else {
4515: $rolename = &Apache::lonnet::plaintext($role);
4516: }
1.33 raeburn 4517: }
4518: my @modifiable;
1.63 raeburn 4519: if ($context eq 'selfcreate') {
4520: $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): ');
4521: } else {
4522: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
4523: }
1.33 raeburn 4524: foreach my $field (@fields) {
4525: if ($modifyhash{$context}{$role}{$field}) {
4526: push(@modifiable,$fieldtitles{$field});
4527: }
4528: }
4529: if (@modifiable > 0) {
4530: $resulttext .= join(', ',@modifiable);
4531: } else {
4532: $resulttext .= &mt('none');
4533: }
4534: $resulttext .= '</li>';
4535: }
4536: $resulttext .= '</ul></li>';
4537: }
4538: }
4539: }
4540: $resulttext .= '</ul>';
4541: } else {
4542: $resulttext = &mt('No changes made to user modification settings');
4543: }
4544: } else {
4545: $resulttext = '<span class="LC_error">'.
4546: &mt('An error occurred: [_1]',$putresult).'</span>';
4547: }
4548: return $resulttext;
4549: }
4550:
1.43 raeburn 4551: sub modify_defaults {
4552: my ($dom,$r) = @_;
4553: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
4554: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.68 raeburn 4555: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
1.43 raeburn 4556: my @authtypes = ('internal','krb4','krb5','localauth');
4557: foreach my $item (@items) {
4558: $newvalues{$item} = $env{'form.'.$item};
4559: if ($item eq 'auth_def') {
4560: if ($newvalues{$item} ne '') {
4561: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
4562: push(@errors,$item);
4563: }
4564: }
4565: } elsif ($item eq 'lang_def') {
4566: if ($newvalues{$item} ne '') {
4567: if ($newvalues{$item} =~ /^(\w+)/) {
4568: my $langcode = $1;
4569: if (code2language($langcode) eq '') {
4570: push(@errors,$item);
4571: }
4572: } else {
4573: push(@errors,$item);
4574: }
4575: }
1.54 raeburn 4576: } elsif ($item eq 'timezone_def') {
4577: if ($newvalues{$item} ne '') {
1.62 raeburn 4578: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 4579: push(@errors,$item);
4580: }
4581: }
1.68 raeburn 4582: } elsif ($item eq 'datelocale_def') {
4583: if ($newvalues{$item} ne '') {
4584: my @datelocale_ids = DateTime::Locale->ids();
4585: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
4586: push(@errors,$item);
4587: }
4588: }
1.43 raeburn 4589: }
4590: if (grep(/^\Q$item\E$/,@errors)) {
4591: $newvalues{$item} = $domdefaults{$item};
4592: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
4593: $changes{$item} = 1;
4594: }
1.72 raeburn 4595: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 4596: }
4597: my %defaults_hash = (
1.72 raeburn 4598: defaults => \%newvalues,
4599: );
1.43 raeburn 4600: my $title = &defaults_titles();
4601: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
4602: $dom);
4603: if ($putresult eq 'ok') {
4604: if (keys(%changes) > 0) {
4605: $resulttext = &mt('Changes made:').'<ul>';
4606: my $version = $r->dir_config('lonVersion');
4607: 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";
4608: foreach my $item (sort(keys(%changes))) {
4609: my $value = $env{'form.'.$item};
4610: if ($value eq '') {
4611: $value = &mt('none');
4612: } elsif ($item eq 'auth_def') {
4613: my %authnames = &authtype_names();
4614: my %shortauth = (
4615: internal => 'int',
4616: krb4 => 'krb4',
4617: krb5 => 'krb5',
4618: localauth => 'loc',
4619: );
4620: $value = $authnames{$shortauth{$value}};
4621: }
4622: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
4623: $mailmsgtext .= "$title->{$item} set to $value\n";
4624: }
4625: $resulttext .= '</ul>';
4626: $mailmsgtext .= "\n";
4627: my $cachetime = 24*60*60;
1.72 raeburn 4628: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 4629: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 4630: my $sysmail = $r->dir_config('lonSysEMail');
4631: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
4632: }
1.43 raeburn 4633: } else {
1.54 raeburn 4634: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 4635: }
4636: } else {
4637: $resulttext = '<span class="LC_error">'.
4638: &mt('An error occurred: [_1]',$putresult).'</span>';
4639: }
4640: if (@errors > 0) {
4641: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
4642: foreach my $item (@errors) {
4643: $resulttext .= ' "'.$title->{$item}.'",';
4644: }
4645: $resulttext =~ s/,$//;
4646: }
4647: return $resulttext;
4648: }
4649:
1.46 raeburn 4650: sub modify_scantron {
1.48 raeburn 4651: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 4652: my ($resulttext,%confhash,%changes,$errors);
4653: my $custom = 'custom.tab';
4654: my $default = 'default.tab';
4655: my $servadm = $r->dir_config('lonAdmEMail');
4656: my ($configuserok,$author_ok,$switchserver) =
4657: &config_check($dom,$confname,$servadm);
4658: if ($env{'form.scantronformat.filename'} ne '') {
4659: my $error;
4660: if ($configuserok eq 'ok') {
4661: if ($switchserver) {
4662: $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
4663: } else {
4664: if ($author_ok eq 'ok') {
4665: my ($result,$scantronurl) =
4666: &publishlogo($r,'upload','scantronformat',$dom,
4667: $confname,'scantron','','',$custom);
4668: if ($result eq 'ok') {
4669: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 4670: $changes{'scantronformat'} = 1;
1.46 raeburn 4671: } else {
4672: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
4673: }
4674: } else {
4675: $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);
4676: }
4677: }
4678: } else {
4679: $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);
4680: }
4681: if ($error) {
4682: &Apache::lonnet::logthis($error);
4683: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4684: }
4685: }
1.48 raeburn 4686: if (ref($domconfig{'scantron'}) eq 'HASH') {
4687: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
4688: if ($env{'form.scantronformat_del'}) {
4689: $confhash{'scantron'}{'scantronformat'} = '';
4690: $changes{'scantronformat'} = 1;
1.46 raeburn 4691: }
4692: }
4693: }
4694: if (keys(%confhash) > 0) {
4695: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
4696: $dom);
4697: if ($putresult eq 'ok') {
4698: if (keys(%changes) > 0) {
1.48 raeburn 4699: if (ref($confhash{'scantron'}) eq 'HASH') {
4700: $resulttext = &mt('Changes made:').'<ul>';
4701: if ($confhash{'scantron'}{'scantronformat'} eq '') {
4702: $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
4703: } else {
4704: $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 4705: }
1.48 raeburn 4706: $resulttext .= '</ul>';
4707: } else {
4708: $resulttext = &mt('Changes made to scantron format file.');
1.46 raeburn 4709: }
4710: $resulttext .= '</ul>';
4711: &Apache::loncommon::devalidate_domconfig_cache($dom);
4712: } else {
4713: $resulttext = &mt('No changes made to scantron format file');
4714: }
4715: } else {
4716: $resulttext = '<span class="LC_error">'.
4717: &mt('An error occurred: [_1]',$putresult).'</span>';
4718: }
4719: } else {
4720: $resulttext = &mt('No changes made to scantron format file');
4721: }
4722: if ($errors) {
4723: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4724: $errors.'</ul>';
4725: }
4726: return $resulttext;
4727: }
4728:
1.48 raeburn 4729: sub modify_coursecategories {
4730: my ($dom,%domconfig) = @_;
1.57 raeburn 4731: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
4732: $cathash);
1.48 raeburn 4733: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 4734: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 4735: $cathash = $domconfig{'coursecategories'}{'cats'};
4736: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
4737: $changes{'togglecats'} = 1;
4738: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
4739: }
4740: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
4741: $changes{'categorize'} = 1;
4742: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
4743: }
4744: } else {
4745: $changes{'togglecats'} = 1;
4746: $changes{'categorize'} = 1;
4747: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
4748: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
4749: }
4750: if (ref($cathash) eq 'HASH') {
4751: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 4752: push (@deletecategory,'instcode::0');
4753: }
1.48 raeburn 4754: }
1.57 raeburn 4755: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
4756: if (ref($cathash) eq 'HASH') {
1.48 raeburn 4757: if (@deletecategory > 0) {
4758: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 4759: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 4760: foreach my $item (@deletecategory) {
1.57 raeburn 4761: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
4762: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 4763: $deletions{$item} = 1;
1.57 raeburn 4764: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 4765: }
4766: }
4767: }
1.57 raeburn 4768: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 4769: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 4770: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 4771: $reorderings{$item} = 1;
1.57 raeburn 4772: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 4773: }
4774: if ($env{'form.addcategory_name_'.$item} ne '') {
4775: my $newcat = $env{'form.addcategory_name_'.$item};
4776: my $newdepth = $depth+1;
4777: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 4778: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 4779: $adds{$newitem} = 1;
4780: }
4781: if ($env{'form.subcat_'.$item} ne '') {
4782: my $newcat = $env{'form.subcat_'.$item};
4783: my $newdepth = $depth+1;
4784: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 4785: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 4786: $adds{$newitem} = 1;
4787: }
4788: }
4789: }
4790: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 4791: if (ref($cathash) eq 'HASH') {
1.48 raeburn 4792: my $newitem = 'instcode::0';
1.57 raeburn 4793: if ($cathash->{$newitem} eq '') {
4794: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 4795: $adds{$newitem} = 1;
4796: }
4797: } else {
4798: my $newitem = 'instcode::0';
1.57 raeburn 4799: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 4800: $adds{$newitem} = 1;
4801: }
4802: }
4803: if ($env{'form.addcategory_name'} ne '') {
4804: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
1.57 raeburn 4805: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
1.48 raeburn 4806: $adds{$newitem} = 1;
4807: }
1.57 raeburn 4808: my $putresult;
1.48 raeburn 4809: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4810: if (keys(%deletions) > 0) {
4811: foreach my $key (keys(%deletions)) {
4812: if ($predelallitems{$key} ne '') {
4813: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
4814: }
4815: }
4816: }
4817: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 4818: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 4819: if (ref($chkcats[0]) eq 'ARRAY') {
4820: my $depth = 0;
4821: my $chg = 0;
4822: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
4823: my $name = $chkcats[0][$i];
4824: my $item;
4825: if ($name eq '') {
4826: $chg ++;
4827: } else {
4828: $item = &escape($name).'::0';
4829: if ($chg) {
1.57 raeburn 4830: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 4831: }
4832: $depth ++;
1.57 raeburn 4833: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 4834: $depth --;
4835: }
4836: }
4837: }
1.57 raeburn 4838: }
4839: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4840: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 4841: if ($putresult eq 'ok') {
1.57 raeburn 4842: my %title = (
4843: togglecats => 'Show/Hide a course in the catalog',
4844: categorize => 'Category assigned to course',
4845: );
4846: my %level = (
4847: dom => 'set from "Modify Course" (Domain)',
4848: crs => 'set from "Parameters" (Course)',
4849: );
1.48 raeburn 4850: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 4851: if ($changes{'togglecats'}) {
4852: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
4853: }
4854: if ($changes{'categorize'}) {
4855: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 4856: }
1.57 raeburn 4857: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
4858: my $cathash;
4859: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
4860: $cathash = $domconfig{'coursecategories'}{'cats'};
4861: } else {
4862: $cathash = {};
4863: }
4864: my (@cats,@trails,%allitems);
4865: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
4866: if (keys(%deletions) > 0) {
4867: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
4868: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
4869: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
4870: }
4871: $resulttext .= '</ul></li>';
4872: }
4873: if (keys(%reorderings) > 0) {
4874: my %sort_by_trail;
4875: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
4876: foreach my $key (keys(%reorderings)) {
4877: if ($allitems{$key} ne '') {
4878: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
4879: }
1.48 raeburn 4880: }
1.57 raeburn 4881: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
4882: $resulttext .= '<li>'.$trails[$trail].'</li>';
4883: }
4884: $resulttext .= '</ul></li>';
1.48 raeburn 4885: }
1.57 raeburn 4886: if (keys(%adds) > 0) {
4887: my %sort_by_trail;
4888: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
4889: foreach my $key (keys(%adds)) {
4890: if ($allitems{$key} ne '') {
4891: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
4892: }
4893: }
4894: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
4895: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 4896: }
1.57 raeburn 4897: $resulttext .= '</ul></li>';
1.48 raeburn 4898: }
4899: }
4900: $resulttext .= '</ul>';
4901: } else {
4902: $resulttext = '<span class="LC_error">'.
1.57 raeburn 4903: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 4904: }
4905: } else {
4906: $resulttext = &mt('No changes made to course categories');
4907: }
4908: return $resulttext;
4909: }
4910:
1.69 raeburn 4911: sub modify_serverstatuses {
4912: my ($dom,%domconfig) = @_;
4913: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
4914: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
4915: %currserverstatus = %{$domconfig{'serverstatuses'}};
4916: }
4917: my @pages = &serverstatus_pages();
4918: foreach my $type (@pages) {
4919: $newserverstatus{$type}{'namedusers'} = '';
4920: $newserverstatus{$type}{'machines'} = '';
4921: if (defined($env{'form.'.$type.'_namedusers'})) {
4922: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
4923: my @okusers;
4924: foreach my $user (@users) {
4925: my ($uname,$udom) = split(/:/,$user);
4926: if (($udom =~ /^$match_domain$/) &&
4927: (&Apache::lonnet::domain($udom)) &&
4928: ($uname =~ /^$match_username$/)) {
4929: if (!grep(/^\Q$user\E/,@okusers)) {
4930: push(@okusers,$user);
4931: }
4932: }
4933: }
4934: if (@okusers > 0) {
4935: @okusers = sort(@okusers);
4936: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
4937: }
4938: }
4939: if (defined($env{'form.'.$type.'_machines'})) {
4940: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
4941: my @okmachines;
4942: foreach my $ip (@machines) {
4943: my @parts = split(/\./,$ip);
4944: next if (@parts < 4);
4945: my $badip = 0;
4946: for (my $i=0; $i<4; $i++) {
4947: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
4948: $badip = 1;
4949: last;
4950: }
4951: }
4952: if (!$badip) {
4953: push(@okmachines,$ip);
4954: }
4955: }
4956: @okmachines = sort(@okmachines);
4957: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
4958: }
4959: }
4960: my %serverstatushash = (
4961: serverstatuses => \%newserverstatus,
4962: );
4963: my $putresult = &Apache::lonnet::put_dom('configuration',\%serverstatushash,
4964: $dom);
4965: my %changes;
4966: foreach my $type (@pages) {
4967: if (ref($currserverstatus{$type}) eq 'HASH') {
4968: my @currnamed = split(/,/,$currserverstatus{$type}{'namedusers'});
4969: my @newusers = split(/,/,$newserverstatus{$type}{'namedusers'});
4970: foreach my $item (@currnamed) {
4971: if (!grep(/^\Q$item\E$/,@newusers)) {
4972: $changes{$type}{'namedusers'} = 1;
4973: last;
4974: }
4975: }
4976: foreach my $item (@newusers) {
4977: if (!grep(/^\Q$item\E$/,@currnamed)) {
4978: $changes{$type}{'namedusers'} = 1;
4979: last;
4980: }
4981: }
4982: my @currmachines = split(/,/,$currserverstatus{$type}{'machines'});
4983: my @newmachines = split(/,/,$newserverstatus{$type}{'machines'});
4984: foreach my $item (@currmachines) {
4985: if (!grep(/^\Q$item\E$/,@newmachines)) {
4986: $changes{$type}{'machines'} = 1;
4987: last;
4988: }
4989: }
4990: foreach my $item (@newmachines) {
4991: if (!grep(/^\Q$item\E$/,@currmachines)) {
4992: $changes{$type}{'machines'} = 1;
4993: last;
4994: }
4995: }
4996:
4997: }
4998: }
4999: if (keys(%changes) > 0) {
5000: my $titles= &LONCAPA::loncgi::serverstatus_titles();
5001: my $putresult = &Apache::lonnet::put_dom('configuration',
5002: \%serverstatushash,$dom);
5003: if ($putresult eq 'ok') {
5004: $resulttext .= &mt('Changes made:').'<ul>';
5005: foreach my $type (@pages) {
5006: if (defined($changes{$type})) {
5007: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
5008: if (defined($changes{$type}{'namedusers'})) {
5009: if ($newserverstatus{$type}{'namedusers'} eq '') {
5010: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
5011: } else {
5012: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
5013: }
5014: } elsif (defined($changes{$type}{'machines'})) {
5015: if ($newserverstatus{$type}{'machines'} eq '') {
5016: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
5017: } else {
5018: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
5019: }
5020:
5021: }
5022: $resulttext .= '</ul></li>';
5023: }
5024: }
5025: $resulttext .= '</ul>';
5026: } else {
5027: $resulttext = '<span class="LC_error">'.
5028: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
5029:
5030: }
5031: } else {
5032: $resulttext = &mt('No changes made to access to server status pages');
5033: }
5034: return $resulttext;
5035: }
5036:
1.48 raeburn 5037: sub recurse_check {
5038: my ($chkcats,$categories,$depth,$name) = @_;
5039: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
5040: my $chg = 0;
5041: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
5042: my $category = $chkcats->[$depth]{$name}[$j];
5043: my $item;
5044: if ($category eq '') {
5045: $chg ++;
5046: } else {
5047: my $deeper = $depth + 1;
5048: $item = &escape($category).':'.&escape($name).':'.$depth;
5049: if ($chg) {
5050: $categories->{$item} -= $chg;
5051: }
5052: &recurse_check($chkcats,$categories,$deeper,$category);
5053: $deeper --;
5054: }
5055: }
5056: }
5057: return;
5058: }
5059:
5060: sub recurse_cat_deletes {
5061: my ($item,$coursecategories,$deletions) = @_;
5062: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
5063: my $subdepth = $depth + 1;
5064: if (ref($coursecategories) eq 'HASH') {
5065: foreach my $subitem (keys(%{$coursecategories})) {
5066: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
5067: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
5068: delete($coursecategories->{$subitem});
5069: $deletions->{$subitem} = 1;
5070: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
5071: }
5072: }
5073: }
5074: return;
5075: }
5076:
1.3 raeburn 5077: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>