Annotation of loncom/interface/domainprefs.pm, revision 1.32
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.32 ! raeburn 4: # $Id: domainprefs.pm,v 1.31 2007/09/27 15:36:23 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;
39: use LONCAPA();
1.6 raeburn 40: use LONCAPA::Enrollment;
1.9 raeburn 41: use File::Copy;
1.1 raeburn 42:
43: sub handler {
44: my $r=shift;
45: if ($r->header_only) {
46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
48: return OK;
49: }
50:
51: my $dom = $env{'request.role.domain'};
1.5 albertel 52: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 53: if (&Apache::lonnet::allowed('mau',$dom)) {
54: &Apache::loncommon::content_type($r,'text/html');
55: $r->send_http_header;
56: } else {
57: $env{'user.error.msg'}=
58: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
59: return HTTP_NOT_ACCEPTABLE;
60: }
61: &Apache::lonhtmlcommon::clear_breadcrumbs();
62: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
63: ['phase']);
1.30 raeburn 64: my $phase = 'pickactions';
1.3 raeburn 65: if ( exists($env{'form.phase'}) ) {
66: $phase = $env{'form.phase'};
67: }
68: my %domconfig =
1.6 raeburn 69: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.27 raeburn 70: 'quotas','autoenroll','autoupdate','directorysrch',
1.28 raeburn 71: 'usercreation','contacts'],$dom);
1.30 raeburn 72: my @prefs_order = ('rolecolors','login','quotas','autoenroll',
73: 'autoupdate','directorysrch','contacts',
74: 'usercreation');
75: my %prefs = (
76: 'rolecolors' =>
77: { text => 'Default color schemes',
78: help => 'Default_Color_Schemes',
79: header => [{col1 => 'Student Settings',
80: col2 => '',},
81: {col1 => 'Coordinator Settings',
82: col2 => '',},
83: {col1 => 'Author Settings',
84: col2 => '',},
85: {col1 => 'Administrator Settings',
86: col2 => '',}],
87: },
88: 'login' =>
89: { text => 'Log-in page options',
90: help => 'Domain_Log-in_Page',
91: header => [{col1 => 'Item',
92: col2 => '',}],
93: },
94: 'quotas' =>
95: { text => 'Default quotas for user portfolios',
96: help => 'Default_User_Quota',
97: header => [{col1 => 'User type',
98: col2 => 'Default quota'}],
99: },
100: 'autoenroll' =>
101: { text => 'Auto-enrollment settings',
102: help => 'Domain_Auto_Enrollment',
103: header => [{col1 => 'Configuration setting',
104: col2 => 'Value(s)'}],
105: },
106: 'autoupdate' =>
107: { text => 'Auto-update settings',
108: help => 'Domain_Auto_Update',
109: header => [{col1 => 'Setting',
110: col2 => 'Value',},
111: {col1 => 'User Population',
112: col2 => 'Updataeable user data'}],
113: },
114: 'directorysrch' =>
115: { text => 'Institutional directory searches',
116: help => 'Domain_Directory_Search',
117: header => [{col1 => 'Setting',
118: col2 => 'Value',}],
119: },
120: 'contacts' =>
121: { text => 'Contact Information',
122: help => 'Domain_Contact_Information',
123: header => [{col1 => 'Setting',
124: col2 => 'Value',}],
125: },
126:
127: 'usercreation' =>
128: { text => 'User creation',
129: help => 'Domain_User_Creation',
130: header => [{col1 => 'Setting',
131: col2 => 'Value',},
132: {col1 => 'Context',
133: col2 => 'Assignable Authentication Types'}],
134: },
1.3 raeburn 135: );
1.6 raeburn 136: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 137: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 138: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 139: ({href=>"javascript:changePage(document.$phase,'pickactions')",
140: text=>"Pick functionality"});
1.9 raeburn 141: my $confname = $dom.'-domainconfig';
1.3 raeburn 142: if ($phase eq 'process') {
1.1 raeburn 143: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 144: ({href=>"javascript:changePage(document.$phase,'display')",
145: text=>"Domain Configuration"},
146: {href=>"javascript:changePage(document.$phase,'$phase')",
1.3 raeburn 147: text=>"Updated"});
148: &print_header($r,$phase);
1.30 raeburn 149: foreach my $item (@prefs_order) {
150: if (grep(/^\Q$item\E$/,@actions)) {
151: $r->print('<h3>'.&mt($prefs{$item}{'text'}).'</h3>'.
152: &process_changes($r,$dom,$confname,$item,
153: \@roles,%domconfig));
154: }
1.3 raeburn 155: }
156: $r->print('<p>');
1.30 raeburn 157: &print_footer($r,$phase,'display','Back to configuration display',
158: \@actions);
1.3 raeburn 159: $r->print('</p>');
1.30 raeburn 160: } elsif ($phase eq 'display') {
161: &Apache::lonhtmlcommon::add_breadcrumb
162: ({href=>"javascript:changePage(document.$phase,'display')",
163: text=>"Domain Configuration"});
164: &print_header($r,$phase);
165: if (@actions > 0) {
166: my $rowsum = 0;
167: my (%output,%rowtotal,@items);
168: my $halfway = @actions/2;
169: foreach my $item (@prefs_order) {
170: if (grep(/^\Q$item\E$/,@actions)) {
171: push(@items,$item);
172: ($output{$item},$rowtotal{$item}) =
173: &print_config_box($r,$dom,$confname,$phase,
174: $item,$prefs{$item},
175: $domconfig{$item});
176: $rowsum += $rowtotal{$item};
177: }
178: }
179: my $colend;
180: my $halfway = $rowsum/2;
181: my $aggregate = 0;
182: my $sumleft = 0;
183: my $sumright = 0;
184: my $crossover;
185: for (my $i=0; $i<@items; $i++) {
186: $aggregate += $rowtotal{$items[$i]};
187: if ($aggregate > $halfway) {
188: $crossover = $i;
189: last;
190: }
191: }
192: for (my $i=0; $i<$crossover; $i++) {
193: $sumleft += $rowtotal{$items[$i]};
194: }
195: for (my $i=$crossover+1; $i<@items; $i++) {
196: $sumright += $rowtotal{$items[$i]};
197: }
198: if ((@items > 1) && ($env{'form.numcols'} == 2)) {
199: my $sumdiff = $sumright - $sumleft;
200: if ($sumdiff > 0) {
201: $colend = $crossover + 1;
202: } else {
203: $colend = $crossover;
204: }
205: } else {
206: $colend = @items;
207: }
208: $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');
209: for (my $i=0; $i<$colend; $i++) {
210: $r->print($output{$items[$i]});
211: }
212: $r->print('</td><td></td><td class="LC_right_col">');
213: if ($colend < @items) {
214: for (my $i=$colend; $i<@items; $i++) {
215: $r->print($output{$items[$i]});
216: }
217: }
218: $r->print('</td></tr></table></p>');
219: $r->print(&print_footer($r,$phase,'process','Save',\@actions));
220: } else {
221: $r->print('<input type="hidden" name="phase" value="" />'.
222: '<input type="hidden" name="numcols" value="'.
223: $env{'form.numcols'}.'" />'."\n".
224: '<span clas="LC_error">'.&mt('No settings chosen').
225: '</span>');
226: }
227: $r->print('</form>');
228: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 229: } else {
1.3 raeburn 230: if ($phase eq '') {
1.30 raeburn 231: $phase = 'pickactions';
1.1 raeburn 232: }
1.30 raeburn 233: my %helphash;
1.3 raeburn 234: &print_header($r,$phase);
1.21 raeburn 235: if (keys(%domconfig) == 0) {
236: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 237: my @ids=&Apache::lonnet::current_machine_ids();
238: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 239: my %designhash = &Apache::loncommon::get_domainconf($dom);
240: my @loginimages = ('img','logo','domlogo');
241: my $custom_img_count = 0;
242: foreach my $img (@loginimages) {
243: if ($designhash{$dom.'.login.'.$img} ne '') {
244: $custom_img_count ++;
245: }
246: }
247: foreach my $role (@roles) {
248: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
249: $custom_img_count ++;
250: }
251: }
252: if ($custom_img_count > 0) {
253: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 254: $r->print(
255: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
256: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
257: &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 />'.
258: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
259: if ($switch_server) {
1.30 raeburn 260: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 261: }
1.21 raeburn 262: return OK;
263: }
264: }
265: }
1.30 raeburn 266: $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');
267: $r->print('<script type="text/javascript">'."\n".
268: &Apache::loncommon::check_uncheck_jscript()."\n".
269: '</script>'."\n".'<p><input type="button" value="check all" '.
270: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
271: ' /> '.
272: '<input type="button" value="uncheck all" '.
273: 'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
274: ' /></p>');
275: foreach my $item (@prefs_order) {
276: $r->print('<p><label><input type="checkbox" name="actions" value="'.$item.'" /> '.$prefs{$item}->{'text'}.'</label></p>');
277: }
278: $r->print('<h3>'.&mt('Display options').'</h3>'."\n".
279: '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
280: '<label><input type="radio" name="numcols" value="1">'.
281: &mt('one column').'</label> '.
282: '<input type="radio" name="numcols" value="2">'.
283: &mt('two columns').'</label></span></p>');
284: $r->print(&print_footer($r,$phase,'display','Go'));
285: $r->print('</form>');
286: $r->print(&Apache::loncommon::end_page());
1.3 raeburn 287: }
288: return OK;
289: }
290:
291: sub process_changes {
1.9 raeburn 292: my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
1.3 raeburn 293: my $output;
294: if ($action eq 'login') {
1.9 raeburn 295: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 296: } elsif ($action eq 'rolecolors') {
1.9 raeburn 297: $output = &modify_rolecolors($r,$dom,$confname,$roles,
298: %domconfig);
1.3 raeburn 299: } elsif ($action eq 'quotas') {
300: $output = &modify_quotas($dom,%domconfig);
301: } elsif ($action eq 'autoenroll') {
302: $output = &modify_autoenroll($dom,%domconfig);
303: } elsif ($action eq 'autoupdate') {
304: $output = &modify_autoupdate($dom,%domconfig);
1.23 raeburn 305: } elsif ($action eq 'directorysrch') {
306: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 307: } elsif ($action eq 'usercreation') {
1.28 raeburn 308: $output = &modify_usercreation($dom,%domconfig);
309: } elsif ($action eq 'contacts') {
310: $output = &modify_contacts($dom,%domconfig);
1.3 raeburn 311: }
312: return $output;
313: }
314:
315: sub print_config_box {
1.9 raeburn 316: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 317: my $rowtotal = 0;
318: my $output =
319: '<table class="LC_nested_outer">
1.3 raeburn 320: <tr>
1.30 raeburn 321: <th align="left"><span class="LC_nobreak">'.&mt($item->{text}).
322: ' </span></th></tr>';
1.22 raeburn 323: #
324: # FIXME - put the help link back in when the help files exist
325: # <th>'.&mt($item->{text}).' '.
326: # &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
327: # </tr>');
1.30 raeburn 328: $rowtotal ++;
1.28 raeburn 329: if (($action eq 'autoupdate') || ($action eq 'rolecolors') ||
330: ($action eq 'usercreation')) {
1.6 raeburn 331: my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
1.30 raeburn 332: $output .= '
1.3 raeburn 333: <tr>
334: <td>
335: <table class="LC_nested">
336: <tr class="LC_info_row">
1.6 raeburn 337: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
1.3 raeburn 338: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.30 raeburn 339: </tr>';
340: $rowtotal ++;
1.6 raeburn 341: if ($action eq 'autoupdate') {
1.30 raeburn 342: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 343: } elsif ($action eq 'usercreation') {
1.30 raeburn 344: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
1.6 raeburn 345: } else {
1.30 raeburn 346: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 347: }
1.30 raeburn 348: $output .= '
1.6 raeburn 349: </table>
350: </td>
351: </tr>
352: <tr>
353: <td>
354: <table class="LC_nested">
355: <tr class="LC_info_row">
356: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
357: <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
1.30 raeburn 358: </tr>';
359: $rowtotal ++;
1.6 raeburn 360: if ($action eq 'autoupdate') {
1.30 raeburn 361: $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
1.28 raeburn 362: } elsif ($action eq 'usercreation') {
1.30 raeburn 363: $output .= &print_usercreation('bottom',$dom,$settings,\$rowtotal);
1.6 raeburn 364: } else {
1.30 raeburn 365: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 366: </table>
367: </td>
368: </tr>
369: <tr>
370: <td>
371: <table class="LC_nested">
372: <tr class="LC_info_row">
373: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
374: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
1.3 raeburn 375: </tr>'.
1.30 raeburn 376: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 377: </table>
378: </td>
379: </tr>
380: <tr>
381: <td>
382: <table class="LC_nested">
383: <tr class="LC_info_row">
1.6 raeburn 384: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
385: <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
1.3 raeburn 386: </tr>'.
1.30 raeburn 387: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
388: $rowtotal += 2;
1.6 raeburn 389: }
1.3 raeburn 390: } else {
1.30 raeburn 391: $output .= '
1.3 raeburn 392: <tr>
393: <td>
394: <table class="LC_nested">
1.30 raeburn 395: <tr class="LC_info_row">';
1.24 raeburn 396: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 397: $output .= '
398: <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>';
1.6 raeburn 399: } else {
1.30 raeburn 400: $output .= '
401: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>';
1.6 raeburn 402: }
1.30 raeburn 403: $output .= '
1.3 raeburn 404: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.30 raeburn 405: </tr>';
406: $rowtotal ++;
1.3 raeburn 407: if ($action eq 'login') {
1.30 raeburn 408: $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
1.3 raeburn 409: } elsif ($action eq 'quotas') {
1.30 raeburn 410: $output .= &print_quotas($dom,$settings,\$rowtotal);
1.3 raeburn 411: } elsif ($action eq 'autoenroll') {
1.30 raeburn 412: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.23 raeburn 413: } elsif ($action eq 'directorysrch') {
1.30 raeburn 414: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 415: } elsif ($action eq 'contacts') {
1.30 raeburn 416: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.27 raeburn 417: }
1.3 raeburn 418: }
1.30 raeburn 419: $output .= '
1.3 raeburn 420: </table>
421: </td>
422: </tr>
1.30 raeburn 423: </table><br />';
424: return ($output,$rowtotal);
1.1 raeburn 425: }
426:
427: sub print_header {
1.3 raeburn 428: my ($r,$phase) = @_;
1.30 raeburn 429: my $alert = &mt('You must select at least one functionality type to display.');
1.6 raeburn 430: my $js = '
1.1 raeburn 431: <script type="text/javascript">
432: function changePage(formname,newphase) {
433: formname.phase.value = newphase;
1.30 raeburn 434: numchecked = 0;
435: if (formname == document.pickactions) {
436: if (formname.actions.length > 0) {
437: for (var i = 0; i <formname.actions.length; i++) {
438: if (formname.actions[i].checked) {
439: numchecked ++;
440: }
441: }
442: } else {
443: if (formname.actions.checked) {
444: numchecked ++;
445: }
446: }
447: if (numchecked > 0) {
448: formname.submit();
449: } else {
450: alert("'.$alert.'");
451: return;
452: }
453: }
1.1 raeburn 454: formname.submit();
1.30 raeburn 455: }'."\n";
456: if ($phase eq 'pickactions') {
457: $js .=
458: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox',numcols => 'radio',})."\n".
459: &javascript_set_colnums();
460: } elsif ($phase eq 'display') {
461: $js .= &color_pick_js()."\n";
462: }
1.31 raeburn 463: $js .= &Apache::loncommon::viewport_size_js().'
1.1 raeburn 464: </script>
1.6 raeburn 465: ';
1.30 raeburn 466: my $additem;
467: if ($phase eq 'pickactions') {
468: my %loaditems = (
1.31 raeburn 469: 'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
1.30 raeburn 470: );
471: $additem = {'add_entries' => \%loaditems,};
472: } else {
473: my %loaditems = (
1.31 raeburn 474: 'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);",
1.30 raeburn 475: );
476: $additem = {'add_entries' => \%loaditems,};
477: }
1.2 albertel 478: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.30 raeburn 479: $js,$additem));
1.3 raeburn 480: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6 raeburn 481: $r->print('
1.8 raeburn 482: <form name="parmform" action="">
1.6 raeburn 483: <input type="hidden" name="pres_marker" />
484: <input type="hidden" name="pres_type" />
485: <input type="hidden" name="pres_value" />
486: </form>
487: ');
488: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
489: ' enctype="multipart/form-data">');
1.1 raeburn 490: return;
491: }
492:
493: sub print_footer {
1.30 raeburn 494: my ($r,$phase,$newphase,$button_text,$actions) = @_;
1.3 raeburn 495: $button_text = &mt($button_text);
1.30 raeburn 496: $r->print('<input type="hidden" name="phase" value="" />'.
497: '<input type="hidden" name="width" value="'.
498: $env{'form.width'}.'" />'.
499: '<input type="hidden" name="height" value="'.
500: $env{'form.height'}.'" />');
501: if (($phase eq 'display') || ($phase eq 'process')) {
502: if (ref($actions) eq 'ARRAY') {
503: foreach my $item (@{$actions}) {
504: $r->print('<input type="hidden" name="actions" value="'.$item.'" />')."\n";
505: }
506: }
507: $r->print('<input type="hidden" name="numcols" value="'.$env{'form.numcols'}.'" />');
508: }
1.3 raeburn 509: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
510: if ($phase eq 'process') {
1.30 raeburn 511: $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
1.3 raeburn 512: } else {
1.30 raeburn 513: my $onclick;
514: if ($phase eq 'display') {
515: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
516: } else {
517: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
518: }
519: $r->print('<p><input type="button" name="store" value="'.
520: $button_text.'" onclick='.$onclick.' /></p>');
521: }
522: if ($phase eq 'process') {
523: $r->print('</form>'.&Apache::loncommon::end_page());
1.3 raeburn 524: }
1.1 raeburn 525: return;
526: }
527:
1.3 raeburn 528: sub print_login {
1.30 raeburn 529: my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
1.6 raeburn 530: my %choices = &login_choices();
531: my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
532: $catalogon = ' checked="checked" ';
533: $adminmailoff = ' checked="checked" ';
534: my @images = ('img','logo','domlogo');
535: my @bgs = ('pgbg','mainbg','sidebg');
536: my @links = ('link','alink','vlink');
1.7 albertel 537: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 538: my %defaultdesign = %Apache::loncommon::defaultdesign;
539: my (%is_custom,%designs);
540: my %defaults = (
541: font => $defaultdesign{'login.font'},
542: );
543: foreach my $item (@images) {
544: $defaults{$item} = $defaultdesign{'login.'.$item};
545: }
546: foreach my $item (@bgs) {
547: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
548: }
549: foreach my $item (@links) {
550: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
551: }
1.3 raeburn 552: if (ref($settings) eq 'HASH') {
553: if ($settings->{'coursecatalog'} eq '0') {
1.1 raeburn 554: $catalogoff = $catalogon;
555: $catalogon = ' ';
556: }
1.3 raeburn 557: if ($settings->{'adminmail'} eq '1') {
1.1 raeburn 558: $adminmailon = $adminmailoff;
559: $adminmailoff = ' ';
560: }
1.6 raeburn 561: foreach my $item (@images) {
562: if ($settings->{$item} ne '') {
563: $designs{$item} = $settings->{$item};
564: $is_custom{$item} = 1;
565: }
566: }
567: if ($settings->{'font'} ne '') {
568: $designs{'font'} = $settings->{'font'};
569: $is_custom{'font'} = 1;
570: }
571: foreach my $item (@bgs) {
572: if ($settings->{$item} ne '') {
573: $designs{'bgs'}{$item} = $settings->{$item};
574: $is_custom{$item} = 1;
575: }
576: }
577: foreach my $item (@links) {
578: if ($settings->{$item} ne '') {
579: $designs{'links'}{$item} = $settings->{$item};
580: $is_custom{$item} = 1;
581: }
582: }
583: } else {
584: if ($designhash{$dom.'.login.font'} ne '') {
585: $designs{'font'} = $designhash{$dom.'.login.font'};
586: $is_custom{'font'} = 1;
587: }
1.8 raeburn 588: foreach my $item (@images) {
589: if ($designhash{$dom.'.login.'.$item} ne '') {
590: $designs{$item} = $designhash{$dom.'.login.'.$item};
591: $is_custom{$item} = 1;
592: }
593: }
1.6 raeburn 594: foreach my $item (@bgs) {
595: if ($designhash{$dom.'.login.'.$item} ne '') {
596: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
597: $is_custom{$item} = 1;
598: }
599: }
600: foreach my $item (@links) {
601: if ($designhash{$dom.'.login.'.$item} ne '') {
602: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
603: $is_custom{$item} = 1;
604: }
605: }
1.1 raeburn 606: }
1.6 raeburn 607: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
608: logo => 'Institution Logo',
609: domlogo => 'Domain Logo');
610: my $itemcount = 1;
611: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.3 raeburn 612: my $datatable =
1.6 raeburn 613: '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
614: '</td><td>'.
1.8 raeburn 615: '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
616: $catalogon.' value="1" />'.&mt('Yes').'</label> '.
617: '<label><input type="radio" name="coursecatalog"'.
618: $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.6 raeburn 619: '</tr>';
620: $itemcount ++;
621: $css_class = $itemcount%2?' class="LC_odd_row"':'';
622: $datatable .= '<tr'.$css_class.'>'.
623: '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
1.8 raeburn 624: '<td><span class="LC_nobreak">'.
625: '<label><input type="radio" name="adminmail"'.
626: $adminmailon.' value="1" />'.&mt('Yes').'</label> '.
627: '<label><input type="radio" name="adminmail"'.
628: $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
1.6 raeburn 629: $itemcount ++;
1.30 raeburn 630: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 631: $datatable .= '</tr></table></td></tr>';
632: return $datatable;
633: }
634:
635: sub login_choices {
636: my %choices =
637: &Apache::lonlocal::texthash (
638: coursecatalog => 'Display Course Catalog link?',
639: adminmail => "Display Administrator's E-mail Address?",
640: img => "Header",
641: logo => "Main Logo",
642: domlogo => "Domain Logo",
643: bgs => "Background colors",
644: links => "Link colors",
645: font => "Font color",
646: pgbg => "Page",
647: mainbg => "Main panel",
648: sidebg => "Side panel",
649: link => "Link",
650: alink => "Active link",
651: vlink => "Visited link",
652: );
653: return %choices;
654: }
655:
656: sub print_rolecolors {
1.30 raeburn 657: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 658: my %choices = &color_font_choices();
659: my @bgs = ('pgbg','tabbg','sidebg');
660: my @links = ('link','alink','vlink');
661: my @images = ('img');
662: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 663: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 664: my %defaultdesign = %Apache::loncommon::defaultdesign;
665: my (%is_custom,%designs);
666: my %defaults = (
667: img => $defaultdesign{$role.'.img'},
668: font => $defaultdesign{$role.'.font'},
669: );
670: foreach my $item (@bgs) {
671: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
672: }
673: foreach my $item (@links) {
674: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
675: }
676: if (ref($settings) eq 'HASH') {
677: if (ref($settings->{$role}) eq 'HASH') {
678: if ($settings->{$role}->{'img'} ne '') {
679: $designs{'img'} = $settings->{$role}->{'img'};
680: $is_custom{'img'} = 1;
681: }
682: if ($settings->{$role}->{'font'} ne '') {
683: $designs{'font'} = $settings->{$role}->{'font'};
684: $is_custom{'font'} = 1;
685: }
686: foreach my $item (@bgs) {
687: if ($settings->{$role}->{$item} ne '') {
688: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
689: $is_custom{$item} = 1;
690: }
691: }
692: foreach my $item (@links) {
693: if ($settings->{$role}->{$item} ne '') {
694: $designs{'links'}{$item} = $settings->{$role}->{$item};
695: $is_custom{$item} = 1;
696: }
697: }
698: }
699: } else {
700: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
701: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
702: $is_custom{'img'} = 1;
703: }
704: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
705: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
706: $is_custom{'font'} = 1;
707: }
708: foreach my $item (@bgs) {
709: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
710: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
711: $is_custom{$item} = 1;
712:
713: }
714: }
715: foreach my $item (@links) {
716: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
717: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
718: $is_custom{$item} = 1;
719: }
720: }
721: }
722: my $itemcount = 1;
1.30 raeburn 723: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 724: $datatable .= '</tr></table></td></tr>';
725: return $datatable;
726: }
727:
728: sub display_color_options {
1.9 raeburn 729: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.30 raeburn 730: $images,$bgs,$links,$alt_text,$rowtotal) = @_;
1.6 raeburn 731: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
732: my $datatable = '<tr'.$css_class.'>'.
733: '<td>'.$choices->{'font'}.'</td>';
734: if (!$is_custom->{'font'}) {
1.30 raeburn 735: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 736: } else {
737: $datatable .= '<td> </td>';
738: }
739: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 740: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 741: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 742: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 743: ' <span id="css_'.$role.'_font" style="background-color: '.
744: $designs->{'font'}.';"> </span>'.
1.8 raeburn 745: '</span></td></tr>';
1.9 raeburn 746: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 747: foreach my $img (@{$images}) {
1.18 albertel 748: $itemcount ++;
1.6 raeburn 749: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 750: $datatable .= '<tr'.$css_class.'>'.
1.6 raeburn 751: '<td>'.$choices->{$img}.'</td>';
1.18 albertel 752: my ($imgfile, $img_import);
1.6 raeburn 753: if ($designs->{$img} ne '') {
754: $imgfile = $designs->{$img};
1.18 albertel 755: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 756: } else {
757: $imgfile = $defaults->{$img};
758: }
759: if ($imgfile) {
1.9 raeburn 760: my ($showfile,$fullsize);
761: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 762: my $urldir = $1;
763: my $filename = $2;
764: my @info = &Apache::lonnet::stat_file($designs->{$img});
765: if (@info) {
766: my $thumbfile = 'tn-'.$filename;
767: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
768: if (@thumb) {
769: $showfile = $urldir.'/'.$thumbfile;
770: } else {
771: $showfile = $imgfile;
772: }
773: } else {
774: $showfile = '';
775: }
776: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 777: $showfile = $imgfile;
1.6 raeburn 778: my $imgdir = $1;
779: my $filename = $2;
780: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
781: $showfile = "/$imgdir/tn-".$filename;
782: } else {
783: my $input = "/home/httpd/html".$imgfile;
784: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
785: if (!-e $output) {
1.9 raeburn 786: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 787: my ($fullwidth,$fullheight) = &check_dimensions($input);
788: if ($fullwidth ne '' && $fullheight ne '') {
789: if ($fullwidth > $width && $fullheight > $height) {
790: my $size = $width.'x'.$height;
791: system("convert -sample $size $input $output");
792: $showfile = '/'.$imgdir.'/tn-'.$filename;
793: }
794: }
1.6 raeburn 795: }
796: }
1.16 raeburn 797: }
1.6 raeburn 798: if ($showfile) {
1.9 raeburn 799: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
800: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1.6 raeburn 801: $datatable.= '<td>';
802: if (!$is_custom->{$img}) {
803: $datatable .= &mt('Default in use:').'<br />';
804: }
1.18 albertel 805: if ($img_import) {
806: $datatable.= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
807: }
1.9 raeburn 808: $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
809: $showfile.'" alt="'.$alt_text->{$img}.
810: '" border="0" /></a></td>';
1.6 raeburn 811: if ($is_custom->{$img}) {
1.8 raeburn 812: $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
813: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
814: '</label> '.&mt('Replace:').'</span><br />';
1.6 raeburn 815: } else {
816: $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
817: }
818: } else {
819: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
820: &mt('Upload:');
821: }
822: } else {
823: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
824: &mt('Upload:');
825: }
1.9 raeburn 826: if ($switchserver) {
827: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
828: } else {
829: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
830: }
831: $datatable .= '</td></tr>';
1.6 raeburn 832: }
833: $itemcount ++;
834: $css_class = $itemcount%2?' class="LC_odd_row"':'';
835: $datatable .= '<tr'.$css_class.'>'.
836: '<td>'.$choices->{'bgs'}.'</td>';
837: my $bgs_def;
838: foreach my $item (@{$bgs}) {
839: if (!$is_custom->{$item}) {
1.30 raeburn 840: $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 841: }
842: }
843: if ($bgs_def) {
1.8 raeburn 844: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 845: } else {
846: $datatable .= '<td> </td>';
847: }
848: $datatable .= '<td class="LC_right_item">'.
849: '<table border="0"><tr>';
850: foreach my $item (@{$bgs}) {
851: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
852: $datatable .= '<td align="center">'.$link;
853: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 854: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 855: }
856: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.30 raeburn 857: '" onblur = "javascript:document.display.css_'.$role.'_'.$item.'.style.background-color = document.display.'.$role.'_'.$item.'.value;"/></td>';
1.6 raeburn 858: }
859: $datatable .= '</tr></table></td></tr>';
860: $itemcount ++;
861: $css_class = $itemcount%2?' class="LC_odd_row"':'';
862: $datatable .= '<tr'.$css_class.'>'.
863: '<td>'.$choices->{'links'}.'</td>';
864: my $links_def;
865: foreach my $item (@{$links}) {
866: if (!$is_custom->{$item}) {
1.30 raeburn 867: $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 868: }
869: }
870: if ($links_def) {
1.8 raeburn 871: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 872: } else {
873: $datatable .= '<td> </td>';
874: }
875: $datatable .= '<td class="LC_right_item">'.
876: '<table border="0"><tr>';
877: foreach my $item (@{$links}) {
1.30 raeburn 878: $datatable .= '<td align="center">'."\n".
879: &color_pick($phase,$role,$item,$choices->{$item},
880: $designs->{'links'}{$item});
1.6 raeburn 881: if ($designs->{'links'}{$item}) {
1.30 raeburn 882: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 883: }
884: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
885: '" /></td>';
886: }
1.30 raeburn 887: $$rowtotal += $itemcount;
1.3 raeburn 888: return $datatable;
889: }
890:
1.6 raeburn 891: sub color_pick {
892: my ($phase,$role,$item,$desc,$curcol) = @_;
893: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
894: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
895: ');">'.$desc.'</a>';
896: return $link;
897: }
898:
899: sub color_pick_js {
900: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
901: my $output = <<"ENDCOL";
902: function pclose() {
903: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
904: parmwin.close();
905: }
906:
907: $pjump_def
908:
909: function psub() {
910: pclose();
911: if (document.parmform.pres_marker.value!='') {
912: if (document.parmform.pres_type.value!='') {
913: eval('document.display.'+
914: document.parmform.pres_marker.value+
915: '.value=document.parmform.pres_value.value;');
916: }
917: } else {
918: document.parmform.pres_value.value='';
919: document.parmform.pres_marker.value='';
920: }
921: }
922: ENDCOL
923: return $output;
924: }
925:
1.3 raeburn 926: sub print_quotas {
1.30 raeburn 927: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 928: my $datatable;
1.23 raeburn 929: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.3 raeburn 930: my $typecount = 0;
931: my $css_class;
1.26 raeburn 932: if (ref($types) eq 'ARRAY') {
1.23 raeburn 933: foreach my $type (@{$types}) {
1.3 raeburn 934: if (defined($usertypes->{$type})) {
935: $typecount ++;
936: $css_class = $typecount%2?' class="LC_odd_row"':'';
937: $datatable .= '<tr'.$css_class.'>'.
938: '<td>'.$usertypes->{$type}.'</td>'.
1.8 raeburn 939: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 940: '<input type="text" name="quota_'.$type.
941: '" value="'.$settings->{$type}.
1.8 raeburn 942: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 943: }
944: }
945: }
946: my $defaultquota = '20';
947: if (ref($settings) eq 'HASH') {
948: if (defined($settings->{'default'})) {
949: $defaultquota = $settings->{'default'};
950: }
951: }
952: $typecount ++;
953: $css_class = $typecount%2?' class="LC_odd_row"':'';
954: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 955: '<td>'.$othertitle.'</td>'.
1.8 raeburn 956: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.15 raeburn 957: '<input type="text" name="defaultquota" value="'.
1.8 raeburn 958: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.30 raeburn 959: $$rowtotal += $typecount;
1.3 raeburn 960: return $datatable;
961: }
962:
963: sub print_autoenroll {
1.30 raeburn 964: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 965: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 966: my ($defdom,$runon,$runoff);
1.3 raeburn 967: if (ref($settings) eq 'HASH') {
968: if (exists($settings->{'run'})) {
969: if ($settings->{'run'} eq '0') {
970: $runoff = ' checked="checked" ';
971: $runon = ' ';
972: } else {
973: $runon = ' checked="checked" ';
974: $runoff = ' ';
975: }
976: } else {
977: if ($autorun) {
978: $runon = ' checked="checked" ';
979: $runoff = ' ';
980: } else {
981: $runoff = ' checked="checked" ';
982: $runon = ' ';
983: }
984: }
985: if (exists($settings->{'sender_domain'})) {
986: $defdom = $settings->{'sender_domain'};
987: }
1.14 raeburn 988: } else {
989: if ($autorun) {
990: $runon = ' checked="checked" ';
991: $runoff = ' ';
992: } else {
993: $runoff = ' checked="checked" ';
994: $runon = ' ';
995: }
1.3 raeburn 996: }
997: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
998: my $datatable='<tr class="LC_odd_row">'.
999: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1000: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1001: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1002: $runon.' value="1" />'.&mt('Yes').'</label> '.
1003: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1004: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1005: '</tr><tr>'.
1006: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1007: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1008: &mt('username').': '.
1009: '<input type="text" name="sender_uname" value="'.
1010: $settings->{'sender_uname'}.
1011: '" size="10" /> '.&mt('domain').
1.8 raeburn 1012: ': '.$domform.'</span></td></tr>';
1.30 raeburn 1013: $$rowtotal += 2;
1.3 raeburn 1014: return $datatable;
1015: }
1016:
1017: sub print_autoupdate {
1.30 raeburn 1018: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1019: my $datatable;
1020: if ($position eq 'top') {
1021: my $updateon = ' ';
1022: my $updateoff = ' checked="checked" ';
1023: my $classlistson = ' ';
1024: my $classlistsoff = ' checked="checked" ';
1025: if (ref($settings) eq 'HASH') {
1026: if ($settings->{'run'} eq '1') {
1027: $updateon = $updateoff;
1028: $updateoff = ' ';
1029: }
1030: if ($settings->{'classlists'} eq '1') {
1031: $classlistson = $classlistsoff;
1032: $classlistsoff = ' ';
1033: }
1034: }
1035: my %title = (
1036: run => 'Auto-update active?',
1037: classlists => 'Update information in classlists?',
1038: );
1039: $datatable = '<tr class="LC_odd_row">'.
1040: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1041: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1042: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1043: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1044: '<label><input type="radio" name="autoupdate_run"'.
1045: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1046: '</tr><tr>'.
1047: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1048: '<td class="LC_right_item"><span class="LC_nobreak">'.
1049: '<label><input type="radio" name="classlists"'.
1050: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1051: '<label><input type="radio" name="classlists"'.
1052: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1053: '</tr>';
1.30 raeburn 1054: $$rowtotal += 2;
1.3 raeburn 1055: } else {
1.23 raeburn 1056: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.20 raeburn 1057: my @fields = ('lastname','firstname','middlename','gen',
1058: 'permanentemail','id');
1.3 raeburn 1059: my %fieldtitles = &Apache::lonlocal::texthash (
1060: id => 'Student/Employee ID',
1.20 raeburn 1061: permanentemail => 'E-mail address',
1.3 raeburn 1062: lastname => 'Last Name',
1063: firstname => 'First Name',
1064: middlename => 'Middle Name',
1065: gen => 'Generation',
1066: );
1067: my $numrows = 0;
1.26 raeburn 1068: if (ref($types) eq 'ARRAY') {
1069: if (@{$types} > 0) {
1070: $datatable =
1071: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1072: \@fields,$types,\$numrows);
1.30 raeburn 1073: $$rowtotal += @{$types};
1.26 raeburn 1074: }
1.3 raeburn 1075: }
1076: $datatable .=
1077: &usertype_update_row($settings,{'default' => $othertitle},
1078: \%fieldtitles,\@fields,['default'],
1079: \$numrows);
1.30 raeburn 1080: $$rowtotal ++;
1.3 raeburn 1081: }
1082: return $datatable;
1083: }
1084:
1.23 raeburn 1085: sub print_directorysrch {
1.30 raeburn 1086: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1087: my $srchon = ' ';
1088: my $srchoff = ' checked="checked" ';
1.25 raeburn 1089: my ($exacton,$containson,$beginson);
1.24 raeburn 1090: my $localon = ' ';
1091: my $localoff = ' checked="checked" ';
1.23 raeburn 1092: if (ref($settings) eq 'HASH') {
1093: if ($settings->{'available'} eq '1') {
1094: $srchon = $srchoff;
1095: $srchoff = ' ';
1096: }
1.24 raeburn 1097: if ($settings->{'localonly'} eq '1') {
1098: $localon = $localoff;
1099: $localoff = ' ';
1100: }
1.25 raeburn 1101: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1102: foreach my $type (@{$settings->{'searchtypes'}}) {
1103: if ($type eq 'exact') {
1104: $exacton = ' checked="checked" ';
1105: } elsif ($type eq 'contains') {
1106: $containson = ' checked="checked" ';
1107: } elsif ($type eq 'begins') {
1108: $beginson = ' checked="checked" ';
1109: }
1110: }
1111: } else {
1112: if ($settings->{'searchtypes'} eq 'exact') {
1113: $exacton = ' checked="checked" ';
1114: } elsif ($settings->{'searchtypes'} eq 'contains') {
1115: $containson = ' checked="checked" ';
1116: } elsif ($settings->{'searchtypes'} eq 'specify') {
1117: $exacton = ' checked="checked" ';
1118: $containson = ' checked="checked" ';
1119: }
1.23 raeburn 1120: }
1121: }
1122: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1123: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1124:
1125: my $numinrow = 4;
1.26 raeburn 1126: my $cansrchrow = 0;
1.23 raeburn 1127: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1128: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1129: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1130: '<input type="radio" name="dirsrch_available"'.
1131: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1132: '<label><input type="radio" name="dirsrch_available"'.
1133: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1134: '</tr><tr>'.
1.30 raeburn 1135: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1136: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1137: '<input type="radio" name="dirsrch_localonly"'.
1138: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1139: '<label><input type="radio" name="dirsrch_localonly"'.
1140: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1141: '</tr>';
1.30 raeburn 1142: $$rowtotal += 2;
1.26 raeburn 1143: if (ref($usertypes) eq 'HASH') {
1144: if (keys(%{$usertypes}) > 0) {
1145: $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
1146: $numinrow,$othertitle);
1147: $cansrchrow = 1;
1148: }
1149: }
1150: if ($cansrchrow) {
1.30 raeburn 1151: $$rowtotal ++;
1.26 raeburn 1152: $datatable .= '<tr>';
1153: } else {
1154: $datatable .= '<tr class="LC_odd_row">';
1155: }
1.30 raeburn 1156: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1157: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1158: foreach my $title (@{$titleorder}) {
1159: if (defined($searchtitles->{$title})) {
1160: my $check = ' ';
1161: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1162: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1163: $check = ' checked="checked" ';
1164: }
1165: }
1166: $datatable .= '<td class="LC_left_item">'.
1167: '<span class="LC_nobreak"><label>'.
1168: '<input type="checkbox" name="searchby" '.
1169: 'value="'.$title.'"'.$check.'/>'.
1170: $searchtitles->{$title}.'</label></span></td>';
1171: }
1172: }
1.26 raeburn 1173: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1174: $$rowtotal ++;
1.26 raeburn 1175: if ($cansrchrow) {
1176: $datatable .= '<tr class="LC_odd_row">';
1177: } else {
1178: $datatable .= '<tr>';
1179: }
1.30 raeburn 1180: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 1181: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1182: '<span class="LC_nobreak"><label>'.
1183: '<input type="checkbox" name="searchtypes" '.
1184: $exacton.' value="exact" />'.&mt('Exact match').
1185: '</label> '.
1186: '<label><input type="checkbox" name="searchtypes" '.
1187: $beginson.' value="begins" />'.&mt('Begins with').
1188: '</label> '.
1189: '<label><input type="checkbox" name="searchtypes" '.
1190: $containson.' value="contains" />'.&mt('Contains').
1191: '</label></span></td></tr>';
1.30 raeburn 1192: $$rowtotal ++;
1.25 raeburn 1193: return $datatable;
1194: }
1195:
1.28 raeburn 1196: sub print_contacts {
1.30 raeburn 1197: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 1198: my $datatable;
1199: my @contacts = ('adminemail','supportemail');
1200: my (%checked,%to,%otheremails);
1201: my @mailings = ('errormail','packagesmail','helpdeskmail');
1202: foreach my $type (@mailings) {
1203: $otheremails{$type} = '';
1204: }
1205: if (ref($settings) eq 'HASH') {
1206: foreach my $item (@contacts) {
1207: if (exists($settings->{$item})) {
1208: $to{$item} = $settings->{$item};
1209: }
1210: }
1211: foreach my $type (@mailings) {
1212: if (exists($settings->{$type})) {
1213: if (ref($settings->{$type}) eq 'HASH') {
1214: foreach my $item (@contacts) {
1215: if ($settings->{$type}{$item}) {
1216: $checked{$type}{$item} = ' checked="checked" ';
1217: }
1218: }
1219: $otheremails{$type} = $settings->{$type}{'others'};
1220: }
1221: }
1222: }
1223: } else {
1224: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1225: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1226: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1227: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1228: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
1229: }
1230: my ($titles,$short_titles) = &contact_titles();
1231: my $rownum = 0;
1232: my $css_class;
1233: foreach my $item (@contacts) {
1234: if ($rownum%2) {
1235: $css_class = '';
1236: } else {
1237: $css_class = ' class="LC_odd_row" ';
1238: }
1.30 raeburn 1239: $datatable .= '<tr'.$css_class.'>'.
1240: '<td><span class="LC_nobreak">'.$titles->{$item}.
1241: '</span></td><td class="LC_right_item">'.
1.28 raeburn 1242: '<input type="text" name="'.$item.'" value="'.
1243: $to{$item}.'" /></td></tr>';
1244: $rownum ++;
1245: }
1246: foreach my $type (@mailings) {
1247: if ($rownum%2) {
1248: $css_class = '';
1249: } else {
1250: $css_class = ' class="LC_odd_row" ';
1251: }
1252: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 1253: '<td><span class="LC_nobreak">'.
1254: $titles->{$type}.': </span></td>'.
1.28 raeburn 1255: '<td class="LC_left_item">'.
1256: '<span class="LC_nobreak">';
1257: foreach my $item (@contacts) {
1258: $datatable .= '<label>'.
1259: '<input type="checkbox" name="'.$type.'"'.
1260: $checked{$type}{$item}.
1261: ' value="'.$item.'" />'.$short_titles->{$item}.
1262: '</label> ';
1263: }
1264: $datatable .= '</span><br />'.&mt('Others').': '.
1265: '<input type="text" name="'.$type.'_others" '.
1266: 'value="'.$otheremails{$type}.'" />'.
1267: '</td></tr>'."\n";
1268: $rownum ++;
1269: }
1.30 raeburn 1270: $$rowtotal += $rownum;
1.28 raeburn 1271: return $datatable;
1272: }
1273:
1274: sub contact_titles {
1275: my %titles = &Apache::lonlocal::texthash (
1276: 'supportemail' => 'Support E-mail address',
1277: 'adminemail' => 'Default Server Admin E-mail address',
1278: 'errormail' => 'Error reports to be e-mailed to',
1279: 'packagesmail' => 'Package update alerts to be e-mailed to',
1280: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
1281: );
1282: my %short_titles = &Apache::lonlocal::texthash (
1283: adminemail => 'Admin E-mail address',
1284: supportemail => 'Support E-mail',
1285: );
1286: return (\%titles,\%short_titles);
1287: }
1288:
1.27 raeburn 1289: sub print_usercreation {
1.30 raeburn 1290: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 1291: my $numinrow = 4;
1.28 raeburn 1292: my $datatable;
1293: my %lt = &Apache::lonlocal::texthash (
1294: nondc => 'User creation other than by Domain Coordinator: ',
1295: author => 'When adding a co-author/assistant author',
1296: course => 'When adding users to a course',
1297: );
1298: if ($position eq 'top') {
1299: my %checked;
1300: if (ref($settings) eq 'HASH') {
1301: if (ref($settings->{'cancreate'}) eq 'ARRAY') {
1302: foreach my $item (@{$settings->{'cancreate'}}) {
1303: $checked{$item} = ' checked="checked" ';
1304: }
1305: }
1306: }
1307: $datatable = '<tr class="LC_odd_row">'.
1.30 raeburn 1308: '<td><span class="LC_nobreak">'.$lt{'nondc'}.
1309: '</span></td><td class="LC_left_item"><table>';
1.28 raeburn 1310: foreach my $item ('author','course') {
1311: $datatable .= '<tr><td><span class="LC_nobreak"><label>'.
1312: '<input type="checkbox" name="can_createuser" '.
1313: $checked{$item}.' value="'.$item.'" />'.
1314: $lt{$item}.'</label><span></td></tr>';
1315: }
1316: $datatable .= '</table></td></tr>';
1.30 raeburn 1317: $$rowtotal ++;
1.32 ! raeburn 1318: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
! 1319: my $rowcount = 0;
1.28 raeburn 1320: if (ref($rules) eq 'HASH') {
1321: if (keys(%{$rules}) > 0) {
1.32 ! raeburn 1322: $datatable .= &user_formats_row('username',$settings,$rules,
! 1323: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 1324: $$rowtotal ++;
1.32 ! raeburn 1325: $rowcount ++;
! 1326: }
! 1327: }
! 1328: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
! 1329: if (ref($idrules) eq 'HASH') {
! 1330: if (keys(%{$idrules}) > 0) {
! 1331: $datatable .= &user_formats_row('id',$settings,$idrules,
! 1332: $idruleorder,$numinrow,$rowcount);
! 1333: $$rowtotal ++;
! 1334: $rowcount ++;
1.28 raeburn 1335: }
1336: }
1337: } else {
1338: my @contexts = ('author','course','domain');
1339: my @authtypes = ('int','krb4','krb5','loc');
1340: my %checked;
1341: if (ref($settings) eq 'HASH') {
1342: if (ref($settings->{'authtypes'}) eq 'HASH') {
1343: foreach my $item (@contexts) {
1344: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
1345: foreach my $auth (@authtypes) {
1346: if ($settings->{'authtypes'}{$item}{$auth}) {
1347: $checked{$item}{$auth} = ' checked="checked" ';
1348: }
1349: }
1350: }
1351: }
1.27 raeburn 1352: }
1353: }
1.28 raeburn 1354: my @authtypes = ('int','krb4','krb5','loc');
1355: my %title = &context_names();
1356: my %authname = &authtype_names();
1357: my $rownum = 0;
1358: my $css_class;
1359: foreach my $item (@contexts) {
1360: if ($rownum%2) {
1361: $css_class = '';
1362: } else {
1363: $css_class = ' class="LC_odd_row" ';
1364: }
1.30 raeburn 1365: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 1366: '<td>'.$title{$item}.
1367: '</td><td class="LC_left_item">'.
1368: '<span class="LC_nobreak">';
1369: foreach my $auth (@authtypes) {
1370: $datatable .= '<label>'.
1371: '<input type="checkbox" name="'.$item.'_auth" '.
1372: $checked{$item}{$auth}.' value="'.$auth.'" />'.
1373: $authname{$auth}.'</label> ';
1374: }
1375: $datatable .= '</span></td></tr>';
1376: $rownum ++;
1.27 raeburn 1377: }
1.30 raeburn 1378: $$rowtotal += $rownum;
1.27 raeburn 1379: }
1380: return $datatable;
1381: }
1382:
1.32 ! raeburn 1383: sub user_formats_row {
! 1384: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
! 1385: my $output;
! 1386: my %text = (
! 1387: 'username' => 'new usernames',
! 1388: 'id' => 'IDs',
! 1389: );
! 1390: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
! 1391: $output = '<tr '.$css_class.'>'.
! 1392: '<td><span class="LC_nobreak">'.
! 1393: &mt("Format rules to check for $text{$type}: ").
! 1394: '</span></td>'.
! 1395: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 1396: my $rem;
1397: if (ref($ruleorder) eq 'ARRAY') {
1398: for (my $i=0; $i<@{$ruleorder}; $i++) {
1399: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
1400: my $rem = $i%($numinrow);
1401: if ($rem == 0) {
1402: if ($i > 0) {
1403: $output .= '</tr>';
1404: }
1405: $output .= '<tr>';
1406: }
1407: my $check = ' ';
1.32 ! raeburn 1408: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
! 1409: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
1.27 raeburn 1410: $check = ' checked="checked" ';
1411: }
1412: }
1413: $output .= '<td class="LC_left_item">'.
1414: '<span class="LC_nobreak"><label>'.
1.32 ! raeburn 1415: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 1416: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
1417: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
1418: }
1419: }
1420: $rem = @{$ruleorder}%($numinrow);
1421: }
1422: my $colsleft = $numinrow - $rem;
1423: if ($colsleft > 1 ) {
1424: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1425: ' </td>';
1426: } elsif ($colsleft == 1) {
1427: $output .= '<td class="LC_left_item"> </td>';
1428: }
1429: $output .= '</tr></table></td></tr>';
1430: return $output;
1431: }
1432:
1.28 raeburn 1433: sub authtype_names {
1434: my %lt = &Apache::lonlocal::texthash(
1435: int => 'Internal',
1436: krb4 => 'Kerberos 4',
1437: krb5 => 'Kerberos 5',
1438: loc => 'Local',
1439: );
1440: return %lt;
1441: }
1442:
1443: sub context_names {
1444: my %context_title = &Apache::lonlocal::texthash(
1445: author => 'Creating users when an Author',
1446: course => 'Creating users when in a course',
1447: domain => 'Creating users when a Domain Coordinator',
1448: );
1449: return %context_title;
1450: }
1451:
1452:
1.25 raeburn 1453: sub users_cansearch_row {
1454: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
1455: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 1456: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
1457: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 1458: my $rem;
1459: if (ref($types) eq 'ARRAY') {
1460: for (my $i=0; $i<@{$types}; $i++) {
1461: if (defined($usertypes->{$types->[$i]})) {
1462: my $rem = $i%($numinrow);
1463: if ($rem == 0) {
1464: if ($i > 0) {
1465: $output .= '</tr>';
1466: }
1467: $output .= '<tr>';
1.23 raeburn 1468: }
1.26 raeburn 1469: my $check = ' ';
1470: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1471: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
1472: $check = ' checked="checked" ';
1473: }
1.23 raeburn 1474: }
1.26 raeburn 1475: $output .= '<td class="LC_left_item">'.
1476: '<span class="LC_nobreak"><label>'.
1477: '<input type="checkbox" name="cansearch" '.
1478: 'value="'.$types->[$i].'"'.$check.'/>'.
1479: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 1480: }
1481: }
1.26 raeburn 1482:
1483: $rem = @{$types}%($numinrow);
1.23 raeburn 1484: }
1485: my $colsleft = $numinrow - $rem;
1486: if ($colsleft > 1) {
1.25 raeburn 1487: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 1488: } else {
1.25 raeburn 1489: $output .= '<td class="LC_left_item">';
1.23 raeburn 1490: }
1491: my $defcheck = ' ';
1492: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 1493: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
1494: $defcheck = ' checked="checked" ';
1495: }
1.23 raeburn 1496: }
1.25 raeburn 1497: $output .= '<span class="LC_nobreak"><label>'.
1498: '<input type="checkbox" name="cansearch" '.
1499: 'value="default"'.$defcheck.'/>'.
1500: $othertitle.'</label></span></td>'.
1501: '</tr></table></td></tr>';
1502: return $output;
1.23 raeburn 1503: }
1504:
1505: sub sorted_inst_types {
1506: my ($dom) = @_;
1507: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1.26 raeburn 1508: my $othertitle = &mt('All users');
1.23 raeburn 1509: my @types;
1510: if (ref($order) eq 'ARRAY') {
1511: @types = @{$order};
1512: }
1513: if (@types == 0) {
1514: if (ref($usertypes) eq 'HASH') {
1515: @types = sort(keys(%{$usertypes}));
1516: }
1517: }
1518: if (keys(%{$usertypes}) > 0) {
1519: $othertitle = &mt('Other users');
1520: }
1521: return ($othertitle,$usertypes,\@types);
1522: }
1523:
1524: sub sorted_searchtitles {
1525: my %searchtitles = &Apache::lonlocal::texthash(
1526: 'uname' => 'username',
1527: 'lastname' => 'last name',
1528: 'lastfirst' => 'last name, first name',
1529: );
1530: my @titleorder = ('uname','lastname','lastfirst');
1531: return (\%searchtitles,\@titleorder);
1532: }
1533:
1.25 raeburn 1534: sub sorted_searchtypes {
1535: my %srchtypes_desc = (
1536: exact => 'is exact match',
1537: contains => 'contains ..',
1538: begins => 'begins with ..',
1539: );
1540: my @srchtypeorder = ('exact','begins','contains');
1541: return (\%srchtypes_desc,\@srchtypeorder);
1542: }
1543:
1.3 raeburn 1544: sub usertype_update_row {
1545: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
1546: my $datatable;
1547: my $numinrow = 4;
1548: foreach my $type (@{$types}) {
1549: if (defined($usertypes->{$type})) {
1550: $$rownums ++;
1551: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
1552: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
1553: '</td><td class="LC_left_item"><table>';
1554: for (my $i=0; $i<@{$fields}; $i++) {
1555: my $rem = $i%($numinrow);
1556: if ($rem == 0) {
1557: if ($i > 0) {
1558: $datatable .= '</tr>';
1559: }
1560: $datatable .= '<tr>';
1561: }
1562: my $check = ' ';
1563: if (ref($settings->{'fields'}) eq 'HASH') {
1564: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
1565: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
1566: $check = ' checked="checked" ';
1567: }
1568: }
1569: }
1570:
1571: if ($i == @{$fields}-1) {
1572: my $colsleft = $numinrow - $rem;
1573: if ($colsleft > 1) {
1574: $datatable .= '<td colspan="'.$colsleft.'">';
1575: } else {
1576: $datatable .= '<td>';
1577: }
1578: } else {
1579: $datatable .= '<td>';
1580: }
1.8 raeburn 1581: $datatable .= '<span class="LC_nobreak"><label>'.
1582: '<input type="checkbox" name="updateable_'.$type.
1583: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
1584: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 1585: }
1586: $datatable .= '</tr></table></td></tr>';
1587: }
1588: }
1589: return $datatable;
1.1 raeburn 1590: }
1591:
1592: sub modify_login {
1.9 raeburn 1593: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 1594: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 1595: my %title = ( coursecatalog => 'Display course catalog',
1596: adminmail => 'Display administrator E-mail address');
1.3 raeburn 1597: my @offon = ('off','on');
1.6 raeburn 1598: my %loginhash;
1.9 raeburn 1599: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
1600: \%domconfig,\%loginhash);
1.6 raeburn 1601: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
1602: $loginhash{login}{adminmail} = $env{'form.adminmail'};
1603: if (ref($colchanges{'login'}) eq 'HASH') {
1604: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
1605: \%loginhash);
1606: }
1.1 raeburn 1607: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
1608: $dom);
1609: if ($putresult eq 'ok') {
1.3 raeburn 1610: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 1611: ($env{'form.coursecatalog'} eq '1')) {
1612: $changes{'coursecatalog'} = 1;
1.3 raeburn 1613: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
1614: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 1615: ($env{'form.coursecatalog'} eq '0')) {
1616: $changes{'coursecatalog'} = 1;
1617: }
1.3 raeburn 1618: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 1619: ($env{'form.adminmail'} eq '0')) {
1620: $changes{'adminmail'} = 1;
1621: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
1622: $domconfig{'login'}{'adminmail'} eq '0') &&
1623: ($env{'form.adminmail'} eq '1')) {
1624: $changes{'adminmail'} = 1;
1625: }
1.6 raeburn 1626: if (keys(%changes) > 0 || $colchgtext) {
1.1 raeburn 1627: $resulttext = &mt('Changes made:').'<ul>';
1628: foreach my $item (sort(keys(%changes))) {
1629: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
1630: }
1.6 raeburn 1631: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 1632: } else {
1633: $resulttext = &mt('No changes made to log-in page settings');
1634: }
1635: } else {
1.11 albertel 1636: $resulttext = '<span class="LC_error">'.
1637: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1638: }
1.6 raeburn 1639: if ($errors) {
1.9 raeburn 1640: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 1641: $errors.'</ul>';
1642: }
1643: return $resulttext;
1644: }
1645:
1646: sub color_font_choices {
1647: my %choices =
1648: &Apache::lonlocal::texthash (
1649: img => "Header",
1650: bgs => "Background colors",
1651: links => "Link colors",
1652: font => "Font color",
1653: pgbg => "Page",
1654: tabbg => "Header",
1655: sidebg => "Border",
1656: link => "Link",
1657: alink => "Active link",
1658: vlink => "Visited link",
1659: );
1660: return %choices;
1661: }
1662:
1663: sub modify_rolecolors {
1.9 raeburn 1664: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 1665: my ($resulttext,%rolehash);
1666: $rolehash{'rolecolors'} = {};
1.9 raeburn 1667: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 1668: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
1669: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
1670: $dom);
1671: if ($putresult eq 'ok') {
1672: if (keys(%changes) > 0) {
1673: $resulttext = &display_colorchgs($dom,\%changes,$roles,
1674: $rolehash{'rolecolors'});
1675: } else {
1676: $resulttext = &mt('No changes made to default color schemes');
1677: }
1678: } else {
1.11 albertel 1679: $resulttext = '<span class="LC_error">'.
1680: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 1681: }
1682: if ($errors) {
1683: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
1684: $errors.'</ul>';
1685: }
1686: return $resulttext;
1687: }
1688:
1689: sub modify_colors {
1.9 raeburn 1690: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 1691: my (%changes,%choices);
1.6 raeburn 1692: my @bgs = ('pgbg','mainbg','sidebg');
1693: my @links = ('link','alink','vlink');
1694: my @images;
1695: my $servadm = $r->dir_config('lonAdmEMail');
1696: my $errors;
1697: foreach my $role (@{$roles}) {
1698: if ($role eq 'login') {
1.12 raeburn 1699: %choices = &login_choices();
1700: } else {
1701: %choices = &color_font_choices();
1702: }
1703: if ($role eq 'login') {
1.6 raeburn 1704: @images = ('img','logo','domlogo');
1705: } else {
1706: @images = ('img');
1707: }
1708: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1709: foreach my $item (@bgs,@links) {
1710: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
1711: }
1.9 raeburn 1712: my ($configuserok,$author_ok,$switchserver,%currroles);
1713: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
1714: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
1715: $confname,$servadm);
1716: if ($configuserok eq 'ok') {
1717: $switchserver = &check_switchserver($dom,$confname);
1718: if ($switchserver eq '') {
1719: $author_ok = &check_authorstatus($dom,$confname,%currroles);
1720: }
1721: }
1722: my ($width,$height) = &thumb_dimensions();
1.8 raeburn 1723: foreach my $img (@images) {
1.18 albertel 1724: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
1725: && !defined($domconfig->{$role}{$img})
1726: && !$env{'form.'.$role.'_del_'.$img}
1727: && $env{'form.'.$role.'_import_'.$img}) {
1728: # import the old configured image from the .tab setting
1729: # if they haven't provided a new one
1730: $domconfig->{$role}{$img} =
1731: $env{'form.'.$role.'_import_'.$img};
1732: }
1.6 raeburn 1733: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 1734: my $error;
1.6 raeburn 1735: if ($configuserok eq 'ok') {
1.9 raeburn 1736: if ($switchserver) {
1.12 raeburn 1737: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 1738: } else {
1739: if ($author_ok eq 'ok') {
1740: my ($result,$logourl) =
1741: &publishlogo($r,'upload',$role.'_'.$img,
1742: $dom,$confname,$img,$width,$height);
1743: if ($result eq 'ok') {
1744: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 1745: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1746: } else {
1.12 raeburn 1747: $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 1748: }
1749: } else {
1.12 raeburn 1750: $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuation user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
1.6 raeburn 1751: }
1752: }
1753: } else {
1.12 raeburn 1754: $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuation user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
1.9 raeburn 1755: }
1756: if ($error) {
1.8 raeburn 1757: &Apache::lonnet::logthis($error);
1.11 albertel 1758: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 1759: }
1760: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 1761: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1762: my $error;
1763: if ($configuserok eq 'ok') {
1764: # is confname an author?
1765: if ($switchserver eq '') {
1766: if ($author_ok eq 'ok') {
1767: my ($result,$logourl) =
1768: &publishlogo($r,'copy',$domconfig->{$role}{$img},
1769: $dom,$confname,$img,$width,$height);
1770: if ($result eq 'ok') {
1771: $confhash->{$role}{$img} = $logourl;
1.18 albertel 1772: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1773: }
1774: }
1775: }
1776: }
1.6 raeburn 1777: }
1778: }
1779: }
1780: if (ref($domconfig) eq 'HASH') {
1781: if (ref($domconfig->{$role}) eq 'HASH') {
1782: foreach my $img (@images) {
1783: if ($domconfig->{$role}{$img} ne '') {
1784: if ($env{'form.'.$role.'_del_'.$img}) {
1785: $confhash->{$role}{$img} = '';
1.12 raeburn 1786: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1787: } else {
1.9 raeburn 1788: if ($confhash->{$role}{$img} eq '') {
1789: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
1790: }
1.6 raeburn 1791: }
1792: } else {
1793: if ($env{'form.'.$role.'_del_'.$img}) {
1794: $confhash->{$role}{$img} = '';
1.12 raeburn 1795: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1796: }
1797: }
1798: }
1799: if ($domconfig->{$role}{'font'} ne '') {
1800: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
1801: $changes{$role}{'font'} = 1;
1802: }
1803: } else {
1804: if ($confhash->{$role}{'font'}) {
1805: $changes{$role}{'font'} = 1;
1806: }
1807: }
1808: foreach my $item (@bgs) {
1809: if ($domconfig->{$role}{$item} ne '') {
1810: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1811: $changes{$role}{'bgs'}{$item} = 1;
1812: }
1813: } else {
1814: if ($confhash->{$role}{$item}) {
1815: $changes{$role}{'bgs'}{$item} = 1;
1816: }
1817: }
1818: }
1819: foreach my $item (@links) {
1820: if ($domconfig->{$role}{$item} ne '') {
1821: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1822: $changes{$role}{'links'}{$item} = 1;
1823: }
1824: } else {
1825: if ($confhash->{$role}{$item}) {
1826: $changes{$role}{'links'}{$item} = 1;
1827: }
1828: }
1829: }
1830: } else {
1831: &default_change_checker($role,\@images,\@links,\@bgs,
1832: $confhash,\%changes);
1833: }
1834: } else {
1835: &default_change_checker($role,\@images,\@links,\@bgs,
1836: $confhash,\%changes);
1837: }
1838: }
1839: return ($errors,%changes);
1840: }
1841:
1842: sub default_change_checker {
1843: my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
1844: foreach my $item (@{$links}) {
1845: if ($confhash->{$role}{$item}) {
1846: $changes->{$role}{'links'}{$item} = 1;
1847: }
1848: }
1849: foreach my $item (@{$bgs}) {
1850: if ($confhash->{$role}{$item}) {
1851: $changes->{$role}{'bgs'}{$item} = 1;
1852: }
1853: }
1854: foreach my $img (@{$images}) {
1855: if ($env{'form.'.$role.'_del_'.$img}) {
1856: $confhash->{$role}{$img} = '';
1.12 raeburn 1857: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 1858: }
1859: }
1860: if ($confhash->{$role}{'font'}) {
1861: $changes->{$role}{'font'} = 1;
1862: }
1863: }
1864:
1865: sub display_colorchgs {
1866: my ($dom,$changes,$roles,$confhash) = @_;
1867: my (%choices,$resulttext);
1.7 albertel 1868: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 1869: if (!grep(/^login$/,@{$roles})) {
1870: $resulttext = &mt('Changes made:').'<br />';
1871: }
1872: foreach my $role (@{$roles}) {
1873: if ($role eq 'login') {
1874: %choices = &login_choices();
1875: } else {
1876: %choices = &color_font_choices();
1877: }
1878: if (ref($changes->{$role}) eq 'HASH') {
1879: if ($role ne 'login') {
1880: $resulttext .= '<h4>'.&mt($role).'</h4>';
1881: }
1882: foreach my $key (sort(keys(%{$changes->{$role}}))) {
1883: if ($role ne 'login') {
1884: $resulttext .= '<ul>';
1885: }
1886: if (ref($changes->{$role}{$key}) eq 'HASH') {
1887: if ($role ne 'login') {
1888: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
1889: }
1890: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1891: if ($confhash->{$role}{$item} eq '') {
1892: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
1893: } else {
1.12 raeburn 1894: my $newitem = $confhash->{$role}{$item};
1895: if ($key eq 'images') {
1896: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
1897: }
1898: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 1899: }
1900: }
1901: if ($role ne 'login') {
1902: $resulttext .= '</ul></li>';
1903: }
1904: } else {
1905: if ($confhash->{$role}{$key} eq '') {
1906: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
1907: } else {
1908: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
1909: }
1910: }
1911: if ($role ne 'login') {
1912: $resulttext .= '</ul>';
1913: }
1914: }
1915: }
1916: }
1.3 raeburn 1917: return $resulttext;
1.1 raeburn 1918: }
1919:
1.9 raeburn 1920: sub thumb_dimensions {
1921: return ('200','50');
1922: }
1923:
1.16 raeburn 1924: sub check_dimensions {
1925: my ($inputfile) = @_;
1926: my ($fullwidth,$fullheight);
1927: if ($inputfile =~ m|^[/\w.\-]+$|) {
1928: if (open(PIPE,"identify $inputfile 2>&1 |")) {
1929: my $imageinfo = <PIPE>;
1930: if (!close(PIPE)) {
1931: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
1932: }
1933: chomp($imageinfo);
1934: my ($fullsize) =
1.21 raeburn 1935: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 1936: if ($fullsize) {
1937: ($fullwidth,$fullheight) = split(/x/,$fullsize);
1938: }
1939: }
1940: }
1941: return ($fullwidth,$fullheight);
1942: }
1943:
1.9 raeburn 1944: sub check_configuser {
1945: my ($uhome,$dom,$confname,$servadm) = @_;
1946: my ($configuserok,%currroles);
1947: if ($uhome eq 'no_host') {
1948: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1949: my $configpass = &LONCAPA::Enrollment::create_password();
1950: $configuserok =
1951: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
1952: $configpass,'','','','','',undef,$servadm);
1953: } else {
1954: $configuserok = 'ok';
1955: %currroles =
1956: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
1957: }
1958: return ($configuserok,%currroles);
1959: }
1960:
1961: sub check_authorstatus {
1962: my ($dom,$confname,%currroles) = @_;
1963: my $author_ok;
1964: if (!$currroles{':'.$dom.':au'}) {
1965: my $start = time;
1966: my $end = 0;
1967: $author_ok =
1968: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1969: 'au',$end,$start);
1970: } else {
1971: $author_ok = 'ok';
1972: }
1973: return $author_ok;
1974: }
1975:
1976: sub publishlogo {
1977: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
1978: my ($output,$fname,$logourl);
1979: if ($action eq 'upload') {
1980: $fname=$env{'form.'.$formname.'.filename'};
1981: chop($env{'form.'.$formname});
1982: } else {
1983: ($fname) = ($formname =~ /([^\/]+)$/);
1984: }
1985: $fname=&Apache::lonnet::clean_filename($fname);
1986: # See if there is anything left
1987: unless ($fname) { return ('error: no uploaded file'); }
1988: $fname="$subdir/$fname";
1989: my $filepath='/home/'.$confname.'/public_html';
1990: my ($fnamepath,$file,$fetchthumb);
1991: $file=$fname;
1992: if ($fname=~m|/|) {
1993: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
1994: }
1995: my @parts=split(/\//,$filepath.'/'.$fnamepath);
1996: my $count;
1997: for ($count=4;$count<=$#parts;$count++) {
1998: $filepath.="/$parts[$count]";
1999: if ((-e $filepath)!=1) {
2000: mkdir($filepath,02770);
2001: }
2002: }
2003: # Check for bad extension and disallow upload
2004: if ($file=~/\.(\w+)$/ &&
2005: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
2006: $output =
2007: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
2008: } elsif ($file=~/\.(\w+)$/ &&
2009: !defined(&Apache::loncommon::fileembstyle($1))) {
2010: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
2011: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
2012: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
2013: } elsif (-d "$filepath/$file") {
2014: $output = &mt('File name is a directory name - rename the file and re-upload');
2015: } else {
2016: my $source = $filepath.'/'.$file;
2017: my $logfile;
2018: if (!open($logfile,">>$source".'.log')) {
2019: return (&mt('No write permission to Construction Space'));
2020: }
2021: print $logfile
2022: "\n================= Publish ".localtime()." ================\n".
2023: $env{'user.name'}.':'.$env{'user.domain'}."\n";
2024: # Save the file
2025: if (!open(FH,'>'.$source)) {
2026: &Apache::lonnet::logthis('Failed to create '.$source);
2027: return (&mt('Failed to create file'));
2028: }
2029: if ($action eq 'upload') {
2030: if (!print FH ($env{'form.'.$formname})) {
2031: &Apache::lonnet::logthis('Failed to write to '.$source);
2032: return (&mt('Failed to write file'));
2033: }
2034: } else {
2035: my $original = &Apache::lonnet::filelocation('',$formname);
2036: if(!copy($original,$source)) {
2037: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
2038: return (&mt('Failed to write file'));
2039: }
2040: }
2041: close(FH);
2042: chmod(0660, $source); # Permissions to rw-rw---.
2043:
2044: my $docroot=$r->dir_config('lonDocRoot');
2045: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
2046: my $copyfile=$targetdir.'/'.$file;
2047:
2048: my @parts=split(/\//,$targetdir);
2049: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
2050: for (my $count=5;$count<=$#parts;$count++) {
2051: $path.="/$parts[$count]";
2052: if (!-e $path) {
2053: print $logfile "\nCreating directory ".$path;
2054: mkdir($path,02770);
2055: }
2056: }
2057: my $versionresult;
2058: if (-e $copyfile) {
2059: $versionresult = &logo_versioning($targetdir,$file,$logfile);
2060: } else {
2061: $versionresult = 'ok';
2062: }
2063: if ($versionresult eq 'ok') {
2064: if (copy($source,$copyfile)) {
2065: print $logfile "\nCopied original source to ".$copyfile."\n";
2066: $output = 'ok';
2067: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
2068: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
2069: } else {
2070: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
2071: $output = &mt('Failed to copy file to RES space').", $!";
2072: }
2073: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
2074: my $inputfile = $filepath.'/'.$file;
2075: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 2076: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
2077: if ($fullwidth ne '' && $fullheight ne '') {
2078: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
2079: my $thumbsize = $thumbwidth.'x'.$thumbheight;
2080: system("convert -sample $thumbsize $inputfile $outfile");
2081: chmod(0660, $filepath.'/tn-'.$file);
2082: if (-e $outfile) {
2083: my $copyfile=$targetdir.'/tn-'.$file;
2084: if (copy($outfile,$copyfile)) {
2085: print $logfile "\nCopied source to ".$copyfile."\n";
2086: &write_metadata($dom,$confname,$formname,
2087: $targetdir,'tn-'.$file,$logfile);
2088: } else {
2089: print $logfile "\nUnable to write ".$copyfile.
2090: ':'.$!."\n";
2091: }
2092: }
1.9 raeburn 2093: }
2094: }
2095: }
2096: } else {
2097: $output = $versionresult;
2098: }
2099: }
2100: return ($output,$logourl);
2101: }
2102:
2103: sub logo_versioning {
2104: my ($targetdir,$file,$logfile) = @_;
2105: my $target = $targetdir.'/'.$file;
2106: my ($maxversion,$fn,$extn,$output);
2107: $maxversion = 0;
2108: if ($file =~ /^(.+)\.(\w+)$/) {
2109: $fn=$1;
2110: $extn=$2;
2111: }
2112: opendir(DIR,$targetdir);
2113: while (my $filename=readdir(DIR)) {
2114: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
2115: $maxversion=($1>$maxversion)?$1:$maxversion;
2116: }
2117: }
2118: $maxversion++;
2119: print $logfile "\nCreating old version ".$maxversion."\n";
2120: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
2121: if (copy($target,$copyfile)) {
2122: print $logfile "Copied old target to ".$copyfile."\n";
2123: $copyfile=$copyfile.'.meta';
2124: if (copy($target.'.meta',$copyfile)) {
2125: print $logfile "Copied old target metadata to ".$copyfile."\n";
2126: $output = 'ok';
2127: } else {
2128: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
2129: $output = &mt('Failed to copy old meta').", $!, ";
2130: }
2131: } else {
2132: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
2133: $output = &mt('Failed to copy old target').", $!, ";
2134: }
2135: return $output;
2136: }
2137:
2138: sub write_metadata {
2139: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
2140: my (%metadatafields,%metadatakeys,$output);
2141: $metadatafields{'title'}=$formname;
2142: $metadatafields{'creationdate'}=time;
2143: $metadatafields{'lastrevisiondate'}=time;
2144: $metadatafields{'copyright'}='public';
2145: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
2146: $env{'user.domain'};
2147: $metadatafields{'authorspace'}=$confname.':'.$dom;
2148: $metadatafields{'domain'}=$dom;
2149: {
2150: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
2151: my $mfh;
2152: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
2153: $output = &mt('Could not write metadata');
2154: }
2155: foreach (sort keys %metadatafields) {
2156: unless ($_=~/\./) {
2157: my $unikey=$_;
2158: $unikey=~/^([A-Za-z]+)/;
2159: my $tag=$1;
2160: $tag=~tr/A-Z/a-z/;
2161: print $mfh "\n\<$tag";
2162: foreach (split(/\,/,$metadatakeys{$unikey})) {
2163: my $value=$metadatafields{$unikey.'.'.$_};
2164: $value=~s/\"/\'\'/g;
2165: print $mfh ' '.$_.'="'.$value.'"';
2166: }
2167: print $mfh '>'.
2168: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
2169: .'</'.$tag.'>';
2170: }
2171: }
2172: $output = 'ok';
2173: print $logfile "\nWrote metadata";
2174: close($mfh);
2175: }
2176: }
2177:
2178: sub check_switchserver {
2179: my ($dom,$confname) = @_;
2180: my ($allowed,$switchserver);
2181: my $home = &Apache::lonnet::homeserver($confname,$dom);
2182: if ($home eq 'no_host') {
2183: $home = &Apache::lonnet::domain($dom,'primary');
2184: }
2185: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 2186: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2187: if (!$allowed) {
2188: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 2189: }
2190: return $switchserver;
2191: }
2192:
1.30 raeburn 2193: sub javascript_set_colnums {
2194: return <<END;
2195: function setDisplayColumns() {
2196: if (document.pickactions.width.value > 1100) {
2197: document.pickactions.numcols[1].checked = true;
2198: } else {
2199: document.pickactions.numcols[0].checked = true;
2200: }
2201: }
2202: END
2203: }
2204:
1.1 raeburn 2205: sub modify_quotas {
1.3 raeburn 2206: my ($dom,%domconfig) = @_;
1.1 raeburn 2207: my ($resulttext,%changes);
1.26 raeburn 2208: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2209: my %formhash;
2210: foreach my $key (keys(%env)) {
2211: if ($key =~ /^form\.quota_(.+)$/) {
2212: $formhash{$1} = $env{$key};
2213: }
2214: }
1.15 raeburn 2215: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 2216: if (ref($domconfig{'quotas'}) eq 'HASH') {
2217: foreach my $key (keys(%{$domconfig{'quotas'}})) {
2218: if (exists($formhash{$key})) {
2219: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
2220: $changes{$key} = 1;
2221: }
2222: } else {
2223: $formhash{$key} = $domconfig{'quotas'}{$key};
2224: }
2225: }
2226: }
2227: foreach my $key (keys(%formhash)) {
2228: if ($formhash{$key} ne '') {
1.3 raeburn 2229: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 2230: $changes{$key} = 1;
2231: }
2232: }
2233: }
2234: my %quotahash = (
1.3 raeburn 2235: quotas => {%formhash},
1.1 raeburn 2236: );
2237: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
2238: $dom);
2239: if ($putresult eq 'ok') {
2240: if (keys(%changes) > 0) {
2241: $resulttext = &mt('Changes made:').'<ul>';
1.26 raeburn 2242: foreach my $type (@{$types},'default') {
2243: if (defined($changes{$type})) {
2244: my $typetitle = $usertypes->{$type};
2245: if ($type eq 'default') {
2246: $typetitle = $othertitle;
2247: }
2248: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
2249: }
1.1 raeburn 2250: }
2251: $resulttext .= '</ul>';
2252: } else {
2253: $resulttext = &mt('No changes made to default quotas');
2254: }
2255: } else {
1.11 albertel 2256: $resulttext = '<span class="LC_error">'.
2257: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2258: }
1.3 raeburn 2259: return $resulttext;
1.1 raeburn 2260: }
2261:
1.3 raeburn 2262: sub modify_autoenroll {
2263: my ($dom,%domconfig) = @_;
1.1 raeburn 2264: my ($resulttext,%changes);
2265: my %currautoenroll;
2266: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
2267: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
2268: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
2269: }
2270: }
2271: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2272: my %title = ( run => 'Auto-enrollment active',
2273: sender => 'Sender for notification messages');
2274: my @offon = ('off','on');
1.17 raeburn 2275: my $sender_uname = $env{'form.sender_uname'};
2276: my $sender_domain = $env{'form.sender_domain'};
2277: if ($sender_domain eq '') {
2278: $sender_uname = '';
2279: } elsif ($sender_uname eq '') {
2280: $sender_domain = '';
2281: }
1.1 raeburn 2282: my %autoenrollhash = (
2283: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 2284: sender_uname => $sender_uname,
2285: sender_domain => $sender_domain,
1.1 raeburn 2286:
2287: }
2288: );
1.4 raeburn 2289: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
2290: $dom);
1.1 raeburn 2291: if ($putresult eq 'ok') {
2292: if (exists($currautoenroll{'run'})) {
2293: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
2294: $changes{'run'} = 1;
2295: }
2296: } elsif ($autorun) {
2297: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 2298: $changes{'run'} = 1;
1.1 raeburn 2299: }
2300: }
1.17 raeburn 2301: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 2302: $changes{'sender'} = 1;
2303: }
1.17 raeburn 2304: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 2305: $changes{'sender'} = 1;
2306: }
2307: if (keys(%changes) > 0) {
2308: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 2309: if ($changes{'run'}) {
1.1 raeburn 2310: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
2311: }
2312: if ($changes{'sender'}) {
1.17 raeburn 2313: if ($sender_uname eq '' || $sender_domain eq '') {
2314: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
2315: } else {
2316: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
2317: }
1.1 raeburn 2318: }
2319: $resulttext .= '</ul>';
2320: } else {
2321: $resulttext = &mt('No changes made to auto-enrollment settings');
2322: }
2323: } else {
1.11 albertel 2324: $resulttext = '<span class="LC_error">'.
2325: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2326: }
1.3 raeburn 2327: return $resulttext;
1.1 raeburn 2328: }
2329:
2330: sub modify_autoupdate {
1.3 raeburn 2331: my ($dom,%domconfig) = @_;
1.1 raeburn 2332: my ($resulttext,%currautoupdate,%fields,%changes);
2333: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
2334: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
2335: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
2336: }
2337: }
2338: my @offon = ('off','on');
2339: my %title = &Apache::lonlocal::texthash (
2340: run => 'Auto-update:',
2341: classlists => 'Updates to user information in classlists?'
2342: );
1.26 raeburn 2343: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2344: my %fieldtitles = &Apache::lonlocal::texthash (
2345: id => 'Student/Employee ID',
1.20 raeburn 2346: permanentemail => 'E-mail address',
1.1 raeburn 2347: lastname => 'Last Name',
2348: firstname => 'First Name',
2349: middlename => 'Middle Name',
2350: gen => 'Generation',
2351: );
2352: my $othertitle = &mt('All users');
2353: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 2354: $othertitle = &mt('Other users');
1.1 raeburn 2355: }
2356: foreach my $key (keys(%env)) {
2357: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
2358: push(@{$fields{$1}},$2);
2359: }
2360: }
2361: my %updatehash = (
2362: autoupdate => { run => $env{'form.autoupdate_run'},
2363: classlists => $env{'form.classlists'},
2364: fields => {%fields},
2365: }
2366: );
2367: foreach my $key (keys(%currautoupdate)) {
2368: if (($key eq 'run') || ($key eq 'classlists')) {
2369: if (exists($updatehash{autoupdate}{$key})) {
2370: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
2371: $changes{$key} = 1;
2372: }
2373: }
2374: } elsif ($key eq 'fields') {
2375: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 2376: foreach my $item (@{$types},'default') {
1.1 raeburn 2377: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
2378: my $change = 0;
2379: foreach my $type (@{$currautoupdate{$key}{$item}}) {
2380: if (!exists($fields{$item})) {
2381: $change = 1;
2382: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 2383: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 2384: $change = 1;
2385: }
2386: }
2387: }
2388: if ($change) {
2389: push(@{$changes{$key}},$item);
2390: }
1.26 raeburn 2391: }
1.1 raeburn 2392: }
2393: }
2394: }
2395: }
1.26 raeburn 2396: foreach my $item (@{$types},'default') {
2397: if (defined($fields{$item})) {
2398: if (ref($currautoupdate{'fields'}) eq 'HASH') {
2399: if (!exists($currautoupdate{'fields'}{$item})) {
2400: push(@{$changes{'fields'}},$item);
2401: }
2402: } else {
2403: push(@{$changes{'fields'}},$item);
1.1 raeburn 2404: }
2405: }
2406: }
2407: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
2408: $dom);
2409: if ($putresult eq 'ok') {
2410: if (keys(%changes) > 0) {
2411: $resulttext = &mt('Changes made:').'<ul>';
2412: foreach my $key (sort(keys(%changes))) {
2413: if (ref($changes{$key}) eq 'ARRAY') {
2414: foreach my $item (@{$changes{$key}}) {
2415: my @newvalues;
2416: foreach my $type (@{$fields{$item}}) {
2417: push(@newvalues,$fieldtitles{$type});
2418: }
1.3 raeburn 2419: my $newvaluestr;
2420: if (@newvalues > 0) {
2421: $newvaluestr = join(', ',@newvalues);
2422: } else {
2423: $newvaluestr = &mt('none');
1.6 raeburn 2424: }
1.1 raeburn 2425: if ($item eq 'default') {
1.26 raeburn 2426: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 2427: } else {
1.26 raeburn 2428: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 2429: }
2430: }
2431: } else {
2432: my $newvalue;
2433: if ($key eq 'run') {
2434: $newvalue = $offon[$env{'form.autoupdate_run'}];
2435: } else {
2436: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 2437: }
1.1 raeburn 2438: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
2439: }
2440: }
2441: $resulttext .= '</ul>';
2442: } else {
1.3 raeburn 2443: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 2444: }
2445: } else {
1.11 albertel 2446: $resulttext = '<span class="LC_error">'.
2447: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2448: }
1.3 raeburn 2449: return $resulttext;
1.1 raeburn 2450: }
2451:
1.23 raeburn 2452: sub modify_directorysrch {
2453: my ($dom,%domconfig) = @_;
2454: my ($resulttext,%changes);
2455: my %currdirsrch;
2456: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2457: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
2458: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
2459: }
2460: }
2461: my %title = ( available => 'Directory search available',
1.24 raeburn 2462: localonly => 'Other domains can search',
1.23 raeburn 2463: searchby => 'Search types',
2464: searchtypes => 'Search latitude');
2465: my @offon = ('off','on');
1.24 raeburn 2466: my @otherdoms = ('Yes','No');
1.23 raeburn 2467:
1.25 raeburn 2468: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 2469: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
2470: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
2471:
1.26 raeburn 2472: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
2473: if (keys(%{$usertypes}) == 0) {
2474: @cansearch = ('default');
2475: } else {
2476: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
2477: foreach my $type (@{$currdirsrch{'cansearch'}}) {
2478: if (!grep(/^\Q$type\E$/,@cansearch)) {
2479: push(@{$changes{'cansearch'}},$type);
2480: }
1.23 raeburn 2481: }
1.26 raeburn 2482: foreach my $type (@cansearch) {
2483: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
2484: push(@{$changes{'cansearch'}},$type);
2485: }
1.23 raeburn 2486: }
1.26 raeburn 2487: } else {
2488: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 2489: }
2490: }
2491:
2492: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
2493: foreach my $by (@{$currdirsrch{'searchby'}}) {
2494: if (!grep(/^\Q$by\E$/,@searchby)) {
2495: push(@{$changes{'searchby'}},$by);
2496: }
2497: }
2498: foreach my $by (@searchby) {
2499: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
2500: push(@{$changes{'searchby'}},$by);
2501: }
2502: }
2503: } else {
2504: push(@{$changes{'searchby'}},@searchby);
2505: }
1.25 raeburn 2506:
2507: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
2508: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
2509: if (!grep(/^\Q$type\E$/,@searchtypes)) {
2510: push(@{$changes{'searchtypes'}},$type);
2511: }
2512: }
2513: foreach my $type (@searchtypes) {
2514: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
2515: push(@{$changes{'searchtypes'}},$type);
2516: }
2517: }
2518: } else {
2519: if (exists($currdirsrch{'searchtypes'})) {
2520: foreach my $type (@searchtypes) {
2521: if ($type ne $currdirsrch{'searchtypes'}) {
2522: push(@{$changes{'searchtypes'}},$type);
2523: }
2524: }
2525: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
2526: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
2527: }
2528: } else {
2529: push(@{$changes{'searchtypes'}},@searchtypes);
2530: }
2531: }
2532:
1.23 raeburn 2533: my %dirsrch_hash = (
2534: directorysrch => { available => $env{'form.dirsrch_available'},
2535: cansearch => \@cansearch,
1.24 raeburn 2536: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 2537: searchby => \@searchby,
1.25 raeburn 2538: searchtypes => \@searchtypes,
1.23 raeburn 2539: }
2540: );
2541: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
2542: $dom);
2543: if ($putresult eq 'ok') {
2544: if (exists($currdirsrch{'available'})) {
2545: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
2546: $changes{'available'} = 1;
2547: }
2548: } else {
2549: if ($env{'form.dirsrch_available'} eq '1') {
2550: $changes{'available'} = 1;
2551: }
2552: }
1.24 raeburn 2553: if (exists($currdirsrch{'localonly'})) {
2554: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
2555: $changes{'localonly'} = 1;
2556: }
2557: } else {
2558: if ($env{'form.dirsrch_localonly'} eq '1') {
2559: $changes{'localonly'} = 1;
2560: }
2561: }
1.23 raeburn 2562: if (keys(%changes) > 0) {
2563: $resulttext = &mt('Changes made:').'<ul>';
2564: if ($changes{'available'}) {
2565: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
2566: }
1.24 raeburn 2567: if ($changes{'localonly'}) {
2568: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
2569: }
2570:
1.23 raeburn 2571: if (ref($changes{'cansearch'}) eq 'ARRAY') {
2572: my $chgtext;
1.26 raeburn 2573: if (ref($usertypes) eq 'HASH') {
2574: if (keys(%{$usertypes}) > 0) {
2575: foreach my $type (@{$types}) {
2576: if (grep(/^\Q$type\E$/,@cansearch)) {
2577: $chgtext .= $usertypes->{$type}.'; ';
2578: }
2579: }
2580: if (grep(/^default$/,@cansearch)) {
2581: $chgtext .= $othertitle;
2582: } else {
2583: $chgtext =~ s/\; $//;
2584: }
2585: $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 2586: }
2587: }
2588: }
2589: if (ref($changes{'searchby'}) eq 'ARRAY') {
2590: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2591: my $chgtext;
2592: foreach my $type (@{$titleorder}) {
2593: if (grep(/^\Q$type\E$/,@searchby)) {
2594: if (defined($searchtitles->{$type})) {
2595: $chgtext .= $searchtitles->{$type}.'; ';
2596: }
2597: }
2598: }
2599: $chgtext =~ s/\; $//;
2600: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
2601: }
1.25 raeburn 2602: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
2603: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
2604: my $chgtext;
2605: foreach my $type (@{$srchtypeorder}) {
2606: if (grep(/^\Q$type\E$/,@searchtypes)) {
2607: if (defined($srchtypes_desc->{$type})) {
2608: $chgtext .= $srchtypes_desc->{$type}.'; ';
2609: }
2610: }
2611: }
2612: $chgtext =~ s/\; $//;
2613: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 2614: }
2615: $resulttext .= '</ul>';
2616: } else {
2617: $resulttext = &mt('No changes made to institution directory search settings');
2618: }
2619: } else {
2620: $resulttext = '<span class="LC_error">'.
1.27 raeburn 2621: &mt('An error occurred: [_1]',$putresult).'</span>';
2622: }
2623: return $resulttext;
2624: }
2625:
1.28 raeburn 2626: sub modify_contacts {
2627: my ($dom,%domconfig) = @_;
2628: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
2629: if (ref($domconfig{'contacts'}) eq 'HASH') {
2630: foreach my $key (keys(%{$domconfig{'contacts'}})) {
2631: $currsetting{$key} = $domconfig{'contacts'}{$key};
2632: }
2633: }
2634: my (%others,%to);
2635: my @contacts = ('supportemail','adminemail');
2636: my @mailings = ('errormail','packagesmail','helpdeskmail');
2637: foreach my $type (@mailings) {
2638: @{$newsetting{$type}} =
2639: &Apache::loncommon::get_env_multiple('form.'.$type);
2640: foreach my $item (@contacts) {
2641: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
2642: $contacts_hash{contacts}{$type}{$item} = 1;
2643: } else {
2644: $contacts_hash{contacts}{$type}{$item} = 0;
2645: }
2646: }
2647: $others{$type} = $env{'form.'.$type.'_others'};
2648: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
2649: }
2650: foreach my $item (@contacts) {
2651: $to{$item} = $env{'form.'.$item};
2652: $contacts_hash{'contacts'}{$item} = $to{$item};
2653: }
2654: if (keys(%currsetting) > 0) {
2655: foreach my $item (@contacts) {
2656: if ($to{$item} ne $currsetting{$item}) {
2657: $changes{$item} = 1;
2658: }
2659: }
2660: foreach my $type (@mailings) {
2661: foreach my $item (@contacts) {
2662: if (ref($currsetting{$type}) eq 'HASH') {
2663: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
2664: push(@{$changes{$type}},$item);
2665: }
2666: } else {
2667: push(@{$changes{$type}},@{$newsetting{$type}});
2668: }
2669: }
2670: if ($others{$type} ne $currsetting{$type}{'others'}) {
2671: push(@{$changes{$type}},'others');
2672: }
2673: }
2674: } else {
2675: my %default;
2676: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2677: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2678: $default{'errormail'} = 'adminemail';
2679: $default{'packagesmail'} = 'adminemail';
2680: $default{'helpdeskmail'} = 'supportemail';
2681: foreach my $item (@contacts) {
2682: if ($to{$item} ne $default{$item}) {
2683: $changes{$item} = 1;
2684: }
2685: }
2686: foreach my $type (@mailings) {
2687: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
2688:
2689: push(@{$changes{$type}},@{$newsetting{$type}});
2690: }
2691: if ($others{$type} ne '') {
2692: push(@{$changes{$type}},'others');
2693: }
2694: }
2695: }
2696: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
2697: $dom);
2698: if ($putresult eq 'ok') {
2699: if (keys(%changes) > 0) {
2700: my ($titles,$short_titles) = &contact_titles();
2701: $resulttext = &mt('Changes made:').'<ul>';
2702: foreach my $item (@contacts) {
2703: if ($changes{$item}) {
2704: $resulttext .= '<li>'.$titles->{$item}.
2705: &mt(' set to: ').
2706: '<span class="LC_cusr_emph">'.
2707: $to{$item}.'</span></li>';
2708: }
2709: }
2710: foreach my $type (@mailings) {
2711: if (ref($changes{$type}) eq 'ARRAY') {
2712: $resulttext .= '<li>'.$titles->{$type}.': ';
2713: my @text;
2714: foreach my $item (@{$newsetting{$type}}) {
2715: push(@text,$short_titles->{$item});
2716: }
2717: if ($others{$type} ne '') {
2718: push(@text,$others{$type});
2719: }
2720: $resulttext .= '<span class="LC_cusr_emph">'.
2721: join(', ',@text).'</span></li>';
2722: }
2723: }
2724: $resulttext .= '</ul>';
2725: } else {
2726: $resulttext = &mt('No changes made to contact information.');
2727: }
2728: } else {
2729: $resulttext = '<span class="LC_error">'.
2730: &mt('An error occurred: [_1].',$putresult).'</span>';
2731: }
2732: return $resulttext;
2733: }
2734:
2735: sub modify_usercreation {
1.27 raeburn 2736: my ($dom,%domconfig) = @_;
1.28 raeburn 2737: my ($resulttext,%curr_usercreation,%changes,%authallowed);
1.27 raeburn 2738: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2739: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
2740: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
2741: }
2742: }
2743: my %title = &Apache::lonlocal::texthash (
2744: author => 'adding co-authors/assistant authors',
2745: course => 'adding users to a course',
2746: );
2747: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 ! raeburn 2748: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.27 raeburn 2749: my @cancreate = &Apache::loncommon::get_env_multiple('form.can_createuser');
2750: if (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
2751: foreach my $type (@{$curr_usercreation{'cancreate'}}) {
2752: if (!grep(/^\Q$type\E$/,@cancreate)) {
2753: push(@{$changes{'cancreate'}},$type);
2754: }
2755: }
2756: foreach my $type (@cancreate) {
2757: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) {
2758: push(@{$changes{'cancreate'}},$type);
2759: }
2760: }
2761: } else {
2762: push(@{$changes{'cancreate'}},@cancreate);
2763: }
2764: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
2765: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
2766: if (!grep(/^\Q$type\E$/,@username_rule)) {
2767: push(@{$changes{'username_rule'}},$type);
2768: }
2769: }
2770: foreach my $type (@username_rule) {
2771: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
2772: push(@{$changes{'username_rule'}},$type);
2773: }
2774: }
2775: } else {
2776: push(@{$changes{'username_rule'}},@username_rule);
2777: }
2778:
1.32 ! raeburn 2779: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
! 2780: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
! 2781: if (!grep(/^\Q$type\E$/,@id_rule)) {
! 2782: push(@{$changes{'id_rule'}},$type);
! 2783: }
! 2784: }
! 2785: foreach my $type (@id_rule) {
! 2786: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
! 2787: push(@{$changes{'id_rule'}},$type);
! 2788: }
! 2789: }
! 2790: } else {
! 2791: push(@{$changes{'id_rule'}},@id_rule);
! 2792: }
! 2793:
1.28 raeburn 2794: my @contexts = ('author','course','domain');
2795: my @authtypes = ('int','krb4','krb5','loc');
2796: my %authhash;
2797: foreach my $item (@contexts) {
2798: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
2799: foreach my $auth (@authtypes) {
2800: if (grep(/^\Q$auth\E$/,@authallowed)) {
2801: $authhash{$item}{$auth} = 1;
2802: } else {
2803: $authhash{$item}{$auth} = 0;
2804: }
2805: }
2806: }
2807: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
2808: foreach my $item (@contexts) {
2809: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
2810: foreach my $auth (@authtypes) {
2811: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
2812: push(@{$changes{'authtypes'}},$item);
2813: last;
2814: }
2815: }
2816: }
2817: }
2818: } else {
2819: foreach my $item (@contexts) {
2820: push(@{$changes{'authtypes'}},$item);
2821: }
2822: }
2823:
1.27 raeburn 2824: my %usercreation_hash = (
1.28 raeburn 2825: usercreation => {
1.27 raeburn 2826: cancreate => \@cancreate,
2827: username_rule => \@username_rule,
1.32 ! raeburn 2828: id_rule => \@id_rule,
! 2829: authtypes => \%authhash,
1.27 raeburn 2830: }
2831: );
2832:
2833: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
2834: $dom);
2835: if ($putresult eq 'ok') {
2836: if (keys(%changes) > 0) {
2837: $resulttext = &mt('Changes made:').'<ul>';
2838: if (ref($changes{'cancreate'}) eq 'ARRAY') {
2839: my $chgtext = '<ul>';
2840: foreach my $type (@cancreate) {
2841: $chgtext .= '<li>'.$title{$type}.'</li>';
2842: }
2843: $chgtext .= '</ul>';
2844: if (@cancreate > 0) {
2845: $resulttext .= '<li>'.&mt('Creation of new users is permitted by a Domain Coordinator, and also by other users when: ').$chgtext.'</li>';
2846: } else {
2847: $resulttext .= '<li>'.&mt("Creation of new users is now only allowed when the user's role is Domain Coordinator.").'</li>';
2848: }
2849: }
2850: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 ! raeburn 2851: my ($rules,$ruleorder) =
! 2852: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 2853: my $chgtext = '<ul>';
2854: foreach my $type (@username_rule) {
2855: if (ref($rules->{$type}) eq 'HASH') {
2856: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
2857: }
2858: }
2859: $chgtext .= '</ul>';
2860: if (@username_rule > 0) {
2861: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
2862: } else {
1.28 raeburn 2863: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 2864: }
2865: }
1.32 ! raeburn 2866: if (ref($changes{'id_rule'}) eq 'ARRAY') {
! 2867: my ($idrules,$idruleorder) =
! 2868: &Apache::lonnet::inst_userrules($dom,'id');
! 2869: my $chgtext = '<ul>';
! 2870: foreach my $type (@id_rule) {
! 2871: if (ref($idrules->{$type}) eq 'HASH') {
! 2872: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
! 2873: }
! 2874: }
! 2875: $chgtext .= '</ul>';
! 2876: if (@id_rule > 0) {
! 2877: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
! 2878: } else {
! 2879: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
! 2880: }
! 2881: }
1.28 raeburn 2882: my %authname = &authtype_names();
2883: my %context_title = &context_names();
2884: if (ref($changes{'authtypes'}) eq 'ARRAY') {
2885: my @unchanged;
2886: my $chgtext = '<ul>';
2887: foreach my $type (@{$changes{'authtypes'}}) {
2888: my @allowed;
2889: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
2890: foreach my $auth (@authtypes) {
2891: if ($authhash{$type}{$auth}) {
2892: push(@allowed,$authname{$auth});
2893: }
2894: }
2895: $chgtext .= join(', ',@allowed).'</li>';
2896: }
2897: $chgtext .= '</ul>';
2898: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
2899: $resulttext .= '</li>';
2900: }
1.27 raeburn 2901: $resulttext .= '</ul>';
2902: } else {
1.28 raeburn 2903: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 2904: }
2905: } else {
2906: $resulttext = '<span class="LC_error">'.
1.23 raeburn 2907: &mt('An error occurred: [_1]',$putresult).'</span>';
2908: }
2909: return $resulttext;
2910: }
2911:
1.3 raeburn 2912: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>