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