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