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