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