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