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