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