Annotation of loncom/interface/domainprefs.pm, revision 1.37
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.37 ! raeburn 4: # $Id: domainprefs.pm,v 1.36 2007/12/16 17:48:18 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');
1.37 ! raeburn 1336: my ($rules,$ruleorder) =
! 1337: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 1338: my %lt = &usercreation_types();
1339: my %checked;
1340: if (ref($settings) eq 'HASH') {
1341: if (ref($settings->{'cancreate'}) eq 'HASH') {
1342: foreach my $item (@creators) {
1343: $checked{$item} = $settings->{'cancreate'}{$item};
1344: }
1345: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
1346: foreach my $item (@creators) {
1347: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
1348: $checked{$item} = 'none';
1349: }
1350: }
1351: }
1352: }
1353: my $rownum = 0;
1354: foreach my $item (@creators) {
1355: $rownum ++;
1356: if ($checked{$item} eq '') {
1357: $checked{$item} = 'any';
1358: }
1359: my $css_class;
1360: if ($rownum%2) {
1361: $css_class = '';
1362: } else {
1363: $css_class = ' class="LC_odd_row" ';
1364: }
1365: $datatable .= '<tr'.$css_class.'>'.
1366: '<td><span class="LC_nobreak">'.$lt{$item}.
1367: '</span></td><td align="right">';
1.37 ! raeburn 1368: my @options = ('any');
! 1369: if (ref($rules) eq 'HASH') {
! 1370: if (keys(%{$rules}) > 0) {
! 1371: push(@options,('official','unofficial'));
! 1372: }
! 1373: }
! 1374: push(@options,'none');
! 1375: foreach my $option (@options) {
1.34 raeburn 1376: my $check = ' ';
1377: if ($checked{$item} eq $option) {
1378: $check = ' checked="checked" ';
1379: }
1380: $datatable .= '<span class="LC_nobreak"><label>'.
1381: '<input type="radio" name="can_createuser_'.
1382: $item.'" value="'.$option.'"'.$check.'/> '.
1383: $lt{$option}.'</label> </span>';
1384: }
1385: $datatable .= '</td></tr>';
1386: }
1.28 raeburn 1387: } else {
1388: my @contexts = ('author','course','domain');
1389: my @authtypes = ('int','krb4','krb5','loc');
1390: my %checked;
1391: if (ref($settings) eq 'HASH') {
1392: if (ref($settings->{'authtypes'}) eq 'HASH') {
1393: foreach my $item (@contexts) {
1394: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
1395: foreach my $auth (@authtypes) {
1396: if ($settings->{'authtypes'}{$item}{$auth}) {
1397: $checked{$item}{$auth} = ' checked="checked" ';
1398: }
1399: }
1400: }
1401: }
1.27 raeburn 1402: }
1.35 raeburn 1403: } else {
1404: foreach my $item (@contexts) {
1.36 raeburn 1405: foreach my $auth (@authtypes) {
1.35 raeburn 1406: $checked{$item}{$auth} = ' checked="checked" ';
1407: }
1408: }
1.27 raeburn 1409: }
1.28 raeburn 1410: my %title = &context_names();
1411: my %authname = &authtype_names();
1412: my $rownum = 0;
1413: my $css_class;
1414: foreach my $item (@contexts) {
1415: if ($rownum%2) {
1416: $css_class = '';
1417: } else {
1418: $css_class = ' class="LC_odd_row" ';
1419: }
1.30 raeburn 1420: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 1421: '<td>'.$title{$item}.
1422: '</td><td class="LC_left_item">'.
1423: '<span class="LC_nobreak">';
1424: foreach my $auth (@authtypes) {
1425: $datatable .= '<label>'.
1426: '<input type="checkbox" name="'.$item.'_auth" '.
1427: $checked{$item}{$auth}.' value="'.$auth.'" />'.
1428: $authname{$auth}.'</label> ';
1429: }
1430: $datatable .= '</span></td></tr>';
1431: $rownum ++;
1.27 raeburn 1432: }
1.30 raeburn 1433: $$rowtotal += $rownum;
1.27 raeburn 1434: }
1435: return $datatable;
1436: }
1437:
1.32 raeburn 1438: sub user_formats_row {
1439: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
1440: my $output;
1441: my %text = (
1442: 'username' => 'new usernames',
1443: 'id' => 'IDs',
1444: );
1445: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1446: $output = '<tr '.$css_class.'>'.
1447: '<td><span class="LC_nobreak">'.
1448: &mt("Format rules to check for $text{$type}: ").
1449: '</span></td>'.
1450: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 1451: my $rem;
1452: if (ref($ruleorder) eq 'ARRAY') {
1453: for (my $i=0; $i<@{$ruleorder}; $i++) {
1454: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
1455: my $rem = $i%($numinrow);
1456: if ($rem == 0) {
1457: if ($i > 0) {
1458: $output .= '</tr>';
1459: }
1460: $output .= '<tr>';
1461: }
1462: my $check = ' ';
1.32 raeburn 1463: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
1464: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
1.27 raeburn 1465: $check = ' checked="checked" ';
1466: }
1467: }
1468: $output .= '<td class="LC_left_item">'.
1469: '<span class="LC_nobreak"><label>'.
1.32 raeburn 1470: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 1471: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
1472: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
1473: }
1474: }
1475: $rem = @{$ruleorder}%($numinrow);
1476: }
1477: my $colsleft = $numinrow - $rem;
1478: if ($colsleft > 1 ) {
1479: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1480: ' </td>';
1481: } elsif ($colsleft == 1) {
1482: $output .= '<td class="LC_left_item"> </td>';
1483: }
1484: $output .= '</tr></table></td></tr>';
1485: return $output;
1486: }
1487:
1.34 raeburn 1488: sub usercreation_types {
1489: my %lt = &Apache::lonlocal::texthash (
1490: author => 'When adding a co-author',
1491: course => 'When adding a user to a course',
1492: any => 'Any',
1493: official => 'Institutional only ',
1494: unofficial => 'Non-institutional only',
1495: none => 'None',
1496: );
1497: return %lt;
1498: }
1499:
1.28 raeburn 1500: sub authtype_names {
1501: my %lt = &Apache::lonlocal::texthash(
1502: int => 'Internal',
1503: krb4 => 'Kerberos 4',
1504: krb5 => 'Kerberos 5',
1505: loc => 'Local',
1506: );
1507: return %lt;
1508: }
1509:
1510: sub context_names {
1511: my %context_title = &Apache::lonlocal::texthash(
1512: author => 'Creating users when an Author',
1513: course => 'Creating users when in a course',
1514: domain => 'Creating users when a Domain Coordinator',
1515: );
1516: return %context_title;
1517: }
1518:
1.33 raeburn 1519: sub print_usermodification {
1520: my ($position,$dom,$settings,$rowtotal) = @_;
1521: my $numinrow = 4;
1522: my ($context,$datatable,$rowcount);
1523: if ($position eq 'top') {
1524: $rowcount = 0;
1525: $context = 'author';
1526: foreach my $role ('ca','aa') {
1527: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1528: $numinrow,$rowcount);
1529: $$rowtotal ++;
1530: $rowcount ++;
1531: }
1532: } else {
1533: $context = 'course';
1534: $rowcount = 0;
1535: foreach my $role ('st','ep','ta','in','cr') {
1536: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1537: $numinrow,$rowcount);
1538: $$rowtotal ++;
1539: $rowcount ++;
1540: }
1541: }
1542: return $datatable;
1543: }
1544:
1545: sub modifiable_userdata_row {
1546: my ($context,$role,$settings,$numinrow,$rowcount) = @_;
1547: my $rolename;
1548: if ($role eq 'cr') {
1549: $rolename = &mt('Custom role');
1550: } else {
1551: $rolename = &Apache::lonnet::plaintext($role);
1552: }
1553: my @fields = ('lastname','firstname','middlename','generation',
1554: 'permanentemail','id');
1555: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1556: my $output;
1557: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1558: $output = '<tr '.$css_class.'>'.
1559: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
1560: '<td class="LC_left_item" colspan="2"><table>';
1561: my $rem;
1562: my %checks;
1563: if (ref($settings) eq 'HASH') {
1564: if (ref($settings->{$context}) eq 'HASH') {
1565: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1566: foreach my $field (@fields) {
1567: if ($settings->{$context}->{$role}->{$field}) {
1568: $checks{$field} = ' checked="checked" ';
1569: }
1570: }
1571: }
1572: }
1573: }
1574: for (my $i=0; $i<@fields; $i++) {
1575: my $rem = $i%($numinrow);
1576: if ($rem == 0) {
1577: if ($i > 0) {
1578: $output .= '</tr>';
1579: }
1580: $output .= '<tr>';
1581: }
1582: my $check = ' ';
1583: if (exists($checks{$fields[$i]})) {
1584: $check = $checks{$fields[$i]}
1585: } else {
1586: if ($role eq 'st') {
1587: if (ref($settings) ne 'HASH') {
1588: $check = ' checked="checked" ';
1589: }
1590: }
1591: }
1592: $output .= '<td class="LC_left_item">'.
1593: '<span class="LC_nobreak"><label>'.
1594: '<input type="checkbox" name="canmodify_'.$role.'" '.
1595: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
1596: '</label></span></td>';
1597: $rem = @fields%($numinrow);
1598: }
1599: my $colsleft = $numinrow - $rem;
1600: if ($colsleft > 1 ) {
1601: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1602: ' </td>';
1603: } elsif ($colsleft == 1) {
1604: $output .= '<td class="LC_left_item"> </td>';
1605: }
1606: $output .= '</tr></table></td></tr>';
1607: return $output;
1608: }
1.28 raeburn 1609:
1.25 raeburn 1610: sub users_cansearch_row {
1611: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
1612: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 1613: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
1614: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 1615: my $rem;
1616: if (ref($types) eq 'ARRAY') {
1617: for (my $i=0; $i<@{$types}; $i++) {
1618: if (defined($usertypes->{$types->[$i]})) {
1619: my $rem = $i%($numinrow);
1620: if ($rem == 0) {
1621: if ($i > 0) {
1622: $output .= '</tr>';
1623: }
1624: $output .= '<tr>';
1.23 raeburn 1625: }
1.26 raeburn 1626: my $check = ' ';
1627: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1628: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
1629: $check = ' checked="checked" ';
1630: }
1.23 raeburn 1631: }
1.26 raeburn 1632: $output .= '<td class="LC_left_item">'.
1633: '<span class="LC_nobreak"><label>'.
1634: '<input type="checkbox" name="cansearch" '.
1635: 'value="'.$types->[$i].'"'.$check.'/>'.
1636: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 1637: }
1638: }
1.26 raeburn 1639:
1640: $rem = @{$types}%($numinrow);
1.23 raeburn 1641: }
1642: my $colsleft = $numinrow - $rem;
1643: if ($colsleft > 1) {
1.25 raeburn 1644: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 1645: } else {
1.25 raeburn 1646: $output .= '<td class="LC_left_item">';
1.23 raeburn 1647: }
1648: my $defcheck = ' ';
1649: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 1650: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
1651: $defcheck = ' checked="checked" ';
1652: }
1.23 raeburn 1653: }
1.25 raeburn 1654: $output .= '<span class="LC_nobreak"><label>'.
1655: '<input type="checkbox" name="cansearch" '.
1656: 'value="default"'.$defcheck.'/>'.
1657: $othertitle.'</label></span></td>'.
1658: '</tr></table></td></tr>';
1659: return $output;
1.23 raeburn 1660: }
1661:
1662: sub sorted_inst_types {
1663: my ($dom) = @_;
1664: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1.26 raeburn 1665: my $othertitle = &mt('All users');
1.23 raeburn 1666: my @types;
1667: if (ref($order) eq 'ARRAY') {
1668: @types = @{$order};
1669: }
1670: if (@types == 0) {
1671: if (ref($usertypes) eq 'HASH') {
1672: @types = sort(keys(%{$usertypes}));
1673: }
1674: }
1675: if (keys(%{$usertypes}) > 0) {
1676: $othertitle = &mt('Other users');
1677: }
1678: return ($othertitle,$usertypes,\@types);
1679: }
1680:
1681: sub sorted_searchtitles {
1682: my %searchtitles = &Apache::lonlocal::texthash(
1683: 'uname' => 'username',
1684: 'lastname' => 'last name',
1685: 'lastfirst' => 'last name, first name',
1686: );
1687: my @titleorder = ('uname','lastname','lastfirst');
1688: return (\%searchtitles,\@titleorder);
1689: }
1690:
1.25 raeburn 1691: sub sorted_searchtypes {
1692: my %srchtypes_desc = (
1693: exact => 'is exact match',
1694: contains => 'contains ..',
1695: begins => 'begins with ..',
1696: );
1697: my @srchtypeorder = ('exact','begins','contains');
1698: return (\%srchtypes_desc,\@srchtypeorder);
1699: }
1700:
1.3 raeburn 1701: sub usertype_update_row {
1702: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
1703: my $datatable;
1704: my $numinrow = 4;
1705: foreach my $type (@{$types}) {
1706: if (defined($usertypes->{$type})) {
1707: $$rownums ++;
1708: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
1709: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
1710: '</td><td class="LC_left_item"><table>';
1711: for (my $i=0; $i<@{$fields}; $i++) {
1712: my $rem = $i%($numinrow);
1713: if ($rem == 0) {
1714: if ($i > 0) {
1715: $datatable .= '</tr>';
1716: }
1717: $datatable .= '<tr>';
1718: }
1719: my $check = ' ';
1720: if (ref($settings->{'fields'}) eq 'HASH') {
1721: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
1722: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
1723: $check = ' checked="checked" ';
1724: }
1725: }
1726: }
1727:
1728: if ($i == @{$fields}-1) {
1729: my $colsleft = $numinrow - $rem;
1730: if ($colsleft > 1) {
1731: $datatable .= '<td colspan="'.$colsleft.'">';
1732: } else {
1733: $datatable .= '<td>';
1734: }
1735: } else {
1736: $datatable .= '<td>';
1737: }
1.8 raeburn 1738: $datatable .= '<span class="LC_nobreak"><label>'.
1739: '<input type="checkbox" name="updateable_'.$type.
1740: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
1741: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 1742: }
1743: $datatable .= '</tr></table></td></tr>';
1744: }
1745: }
1746: return $datatable;
1.1 raeburn 1747: }
1748:
1749: sub modify_login {
1.9 raeburn 1750: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 1751: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 1752: my %title = ( coursecatalog => 'Display course catalog',
1753: adminmail => 'Display administrator E-mail address');
1.3 raeburn 1754: my @offon = ('off','on');
1.6 raeburn 1755: my %loginhash;
1.9 raeburn 1756: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
1757: \%domconfig,\%loginhash);
1.6 raeburn 1758: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
1759: $loginhash{login}{adminmail} = $env{'form.adminmail'};
1760: if (ref($colchanges{'login'}) eq 'HASH') {
1761: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
1762: \%loginhash);
1763: }
1.1 raeburn 1764: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
1765: $dom);
1766: if ($putresult eq 'ok') {
1.3 raeburn 1767: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 1768: ($env{'form.coursecatalog'} eq '1')) {
1769: $changes{'coursecatalog'} = 1;
1.3 raeburn 1770: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
1771: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 1772: ($env{'form.coursecatalog'} eq '0')) {
1773: $changes{'coursecatalog'} = 1;
1774: }
1.3 raeburn 1775: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 1776: ($env{'form.adminmail'} eq '0')) {
1777: $changes{'adminmail'} = 1;
1778: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
1779: $domconfig{'login'}{'adminmail'} eq '0') &&
1780: ($env{'form.adminmail'} eq '1')) {
1781: $changes{'adminmail'} = 1;
1782: }
1.6 raeburn 1783: if (keys(%changes) > 0 || $colchgtext) {
1.1 raeburn 1784: $resulttext = &mt('Changes made:').'<ul>';
1785: foreach my $item (sort(keys(%changes))) {
1786: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
1787: }
1.6 raeburn 1788: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 1789: } else {
1790: $resulttext = &mt('No changes made to log-in page settings');
1791: }
1792: } else {
1.11 albertel 1793: $resulttext = '<span class="LC_error">'.
1794: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1795: }
1.6 raeburn 1796: if ($errors) {
1.9 raeburn 1797: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 1798: $errors.'</ul>';
1799: }
1800: return $resulttext;
1801: }
1802:
1803: sub color_font_choices {
1804: my %choices =
1805: &Apache::lonlocal::texthash (
1806: img => "Header",
1807: bgs => "Background colors",
1808: links => "Link colors",
1809: font => "Font color",
1810: pgbg => "Page",
1811: tabbg => "Header",
1812: sidebg => "Border",
1813: link => "Link",
1814: alink => "Active link",
1815: vlink => "Visited link",
1816: );
1817: return %choices;
1818: }
1819:
1820: sub modify_rolecolors {
1.9 raeburn 1821: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 1822: my ($resulttext,%rolehash);
1823: $rolehash{'rolecolors'} = {};
1.9 raeburn 1824: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 1825: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
1826: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
1827: $dom);
1828: if ($putresult eq 'ok') {
1829: if (keys(%changes) > 0) {
1830: $resulttext = &display_colorchgs($dom,\%changes,$roles,
1831: $rolehash{'rolecolors'});
1832: } else {
1833: $resulttext = &mt('No changes made to default color schemes');
1834: }
1835: } else {
1.11 albertel 1836: $resulttext = '<span class="LC_error">'.
1837: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 1838: }
1839: if ($errors) {
1840: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
1841: $errors.'</ul>';
1842: }
1843: return $resulttext;
1844: }
1845:
1846: sub modify_colors {
1.9 raeburn 1847: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 1848: my (%changes,%choices);
1.6 raeburn 1849: my @bgs = ('pgbg','mainbg','sidebg');
1850: my @links = ('link','alink','vlink');
1851: my @images;
1852: my $servadm = $r->dir_config('lonAdmEMail');
1853: my $errors;
1854: foreach my $role (@{$roles}) {
1855: if ($role eq 'login') {
1.12 raeburn 1856: %choices = &login_choices();
1857: } else {
1858: %choices = &color_font_choices();
1859: }
1860: if ($role eq 'login') {
1.6 raeburn 1861: @images = ('img','logo','domlogo');
1862: } else {
1863: @images = ('img');
1864: }
1865: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1866: foreach my $item (@bgs,@links) {
1867: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
1868: }
1.9 raeburn 1869: my ($configuserok,$author_ok,$switchserver,%currroles);
1870: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
1871: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
1872: $confname,$servadm);
1873: if ($configuserok eq 'ok') {
1874: $switchserver = &check_switchserver($dom,$confname);
1875: if ($switchserver eq '') {
1876: $author_ok = &check_authorstatus($dom,$confname,%currroles);
1877: }
1878: }
1879: my ($width,$height) = &thumb_dimensions();
1.8 raeburn 1880: foreach my $img (@images) {
1.18 albertel 1881: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
1882: && !defined($domconfig->{$role}{$img})
1883: && !$env{'form.'.$role.'_del_'.$img}
1884: && $env{'form.'.$role.'_import_'.$img}) {
1885: # import the old configured image from the .tab setting
1886: # if they haven't provided a new one
1887: $domconfig->{$role}{$img} =
1888: $env{'form.'.$role.'_import_'.$img};
1889: }
1.6 raeburn 1890: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 1891: my $error;
1.6 raeburn 1892: if ($configuserok eq 'ok') {
1.9 raeburn 1893: if ($switchserver) {
1.12 raeburn 1894: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 1895: } else {
1896: if ($author_ok eq 'ok') {
1897: my ($result,$logourl) =
1898: &publishlogo($r,'upload',$role.'_'.$img,
1899: $dom,$confname,$img,$width,$height);
1900: if ($result eq 'ok') {
1901: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 1902: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1903: } else {
1.12 raeburn 1904: $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 1905: }
1906: } else {
1.12 raeburn 1907: $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 1908: }
1909: }
1910: } else {
1.12 raeburn 1911: $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 1912: }
1913: if ($error) {
1.8 raeburn 1914: &Apache::lonnet::logthis($error);
1.11 albertel 1915: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 1916: }
1917: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 1918: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1919: my $error;
1920: if ($configuserok eq 'ok') {
1921: # is confname an author?
1922: if ($switchserver eq '') {
1923: if ($author_ok eq 'ok') {
1924: my ($result,$logourl) =
1925: &publishlogo($r,'copy',$domconfig->{$role}{$img},
1926: $dom,$confname,$img,$width,$height);
1927: if ($result eq 'ok') {
1928: $confhash->{$role}{$img} = $logourl;
1.18 albertel 1929: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1930: }
1931: }
1932: }
1933: }
1.6 raeburn 1934: }
1935: }
1936: }
1937: if (ref($domconfig) eq 'HASH') {
1938: if (ref($domconfig->{$role}) eq 'HASH') {
1939: foreach my $img (@images) {
1940: if ($domconfig->{$role}{$img} ne '') {
1941: if ($env{'form.'.$role.'_del_'.$img}) {
1942: $confhash->{$role}{$img} = '';
1.12 raeburn 1943: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1944: } else {
1.9 raeburn 1945: if ($confhash->{$role}{$img} eq '') {
1946: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
1947: }
1.6 raeburn 1948: }
1949: } else {
1950: if ($env{'form.'.$role.'_del_'.$img}) {
1951: $confhash->{$role}{$img} = '';
1.12 raeburn 1952: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1953: }
1954: }
1955: }
1956: if ($domconfig->{$role}{'font'} ne '') {
1957: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
1958: $changes{$role}{'font'} = 1;
1959: }
1960: } else {
1961: if ($confhash->{$role}{'font'}) {
1962: $changes{$role}{'font'} = 1;
1963: }
1964: }
1965: foreach my $item (@bgs) {
1966: if ($domconfig->{$role}{$item} ne '') {
1967: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1968: $changes{$role}{'bgs'}{$item} = 1;
1969: }
1970: } else {
1971: if ($confhash->{$role}{$item}) {
1972: $changes{$role}{'bgs'}{$item} = 1;
1973: }
1974: }
1975: }
1976: foreach my $item (@links) {
1977: if ($domconfig->{$role}{$item} ne '') {
1978: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1979: $changes{$role}{'links'}{$item} = 1;
1980: }
1981: } else {
1982: if ($confhash->{$role}{$item}) {
1983: $changes{$role}{'links'}{$item} = 1;
1984: }
1985: }
1986: }
1987: } else {
1988: &default_change_checker($role,\@images,\@links,\@bgs,
1989: $confhash,\%changes);
1990: }
1991: } else {
1992: &default_change_checker($role,\@images,\@links,\@bgs,
1993: $confhash,\%changes);
1994: }
1995: }
1996: return ($errors,%changes);
1997: }
1998:
1999: sub default_change_checker {
2000: my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
2001: foreach my $item (@{$links}) {
2002: if ($confhash->{$role}{$item}) {
2003: $changes->{$role}{'links'}{$item} = 1;
2004: }
2005: }
2006: foreach my $item (@{$bgs}) {
2007: if ($confhash->{$role}{$item}) {
2008: $changes->{$role}{'bgs'}{$item} = 1;
2009: }
2010: }
2011: foreach my $img (@{$images}) {
2012: if ($env{'form.'.$role.'_del_'.$img}) {
2013: $confhash->{$role}{$img} = '';
1.12 raeburn 2014: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 2015: }
2016: }
2017: if ($confhash->{$role}{'font'}) {
2018: $changes->{$role}{'font'} = 1;
2019: }
2020: }
2021:
2022: sub display_colorchgs {
2023: my ($dom,$changes,$roles,$confhash) = @_;
2024: my (%choices,$resulttext);
1.7 albertel 2025: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 2026: if (!grep(/^login$/,@{$roles})) {
2027: $resulttext = &mt('Changes made:').'<br />';
2028: }
2029: foreach my $role (@{$roles}) {
2030: if ($role eq 'login') {
2031: %choices = &login_choices();
2032: } else {
2033: %choices = &color_font_choices();
2034: }
2035: if (ref($changes->{$role}) eq 'HASH') {
2036: if ($role ne 'login') {
2037: $resulttext .= '<h4>'.&mt($role).'</h4>';
2038: }
2039: foreach my $key (sort(keys(%{$changes->{$role}}))) {
2040: if ($role ne 'login') {
2041: $resulttext .= '<ul>';
2042: }
2043: if (ref($changes->{$role}{$key}) eq 'HASH') {
2044: if ($role ne 'login') {
2045: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
2046: }
2047: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
2048: if ($confhash->{$role}{$item} eq '') {
2049: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
2050: } else {
1.12 raeburn 2051: my $newitem = $confhash->{$role}{$item};
2052: if ($key eq 'images') {
2053: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
2054: }
2055: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 2056: }
2057: }
2058: if ($role ne 'login') {
2059: $resulttext .= '</ul></li>';
2060: }
2061: } else {
2062: if ($confhash->{$role}{$key} eq '') {
2063: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
2064: } else {
2065: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
2066: }
2067: }
2068: if ($role ne 'login') {
2069: $resulttext .= '</ul>';
2070: }
2071: }
2072: }
2073: }
1.3 raeburn 2074: return $resulttext;
1.1 raeburn 2075: }
2076:
1.9 raeburn 2077: sub thumb_dimensions {
2078: return ('200','50');
2079: }
2080:
1.16 raeburn 2081: sub check_dimensions {
2082: my ($inputfile) = @_;
2083: my ($fullwidth,$fullheight);
2084: if ($inputfile =~ m|^[/\w.\-]+$|) {
2085: if (open(PIPE,"identify $inputfile 2>&1 |")) {
2086: my $imageinfo = <PIPE>;
2087: if (!close(PIPE)) {
2088: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
2089: }
2090: chomp($imageinfo);
2091: my ($fullsize) =
1.21 raeburn 2092: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 2093: if ($fullsize) {
2094: ($fullwidth,$fullheight) = split(/x/,$fullsize);
2095: }
2096: }
2097: }
2098: return ($fullwidth,$fullheight);
2099: }
2100:
1.9 raeburn 2101: sub check_configuser {
2102: my ($uhome,$dom,$confname,$servadm) = @_;
2103: my ($configuserok,%currroles);
2104: if ($uhome eq 'no_host') {
2105: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
2106: my $configpass = &LONCAPA::Enrollment::create_password();
2107: $configuserok =
2108: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
2109: $configpass,'','','','','',undef,$servadm);
2110: } else {
2111: $configuserok = 'ok';
2112: %currroles =
2113: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
2114: }
2115: return ($configuserok,%currroles);
2116: }
2117:
2118: sub check_authorstatus {
2119: my ($dom,$confname,%currroles) = @_;
2120: my $author_ok;
1.37 ! raeburn 2121: if (!$currroles{$confname.':'.$dom.':au'}) {
1.9 raeburn 2122: my $start = time;
2123: my $end = 0;
2124: $author_ok =
2125: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
2126: 'au',$end,$start);
2127: } else {
2128: $author_ok = 'ok';
2129: }
2130: return $author_ok;
2131: }
2132:
2133: sub publishlogo {
2134: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
2135: my ($output,$fname,$logourl);
2136: if ($action eq 'upload') {
2137: $fname=$env{'form.'.$formname.'.filename'};
2138: chop($env{'form.'.$formname});
2139: } else {
2140: ($fname) = ($formname =~ /([^\/]+)$/);
2141: }
2142: $fname=&Apache::lonnet::clean_filename($fname);
2143: # See if there is anything left
2144: unless ($fname) { return ('error: no uploaded file'); }
2145: $fname="$subdir/$fname";
2146: my $filepath='/home/'.$confname.'/public_html';
2147: my ($fnamepath,$file,$fetchthumb);
2148: $file=$fname;
2149: if ($fname=~m|/|) {
2150: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
2151: }
2152: my @parts=split(/\//,$filepath.'/'.$fnamepath);
2153: my $count;
2154: for ($count=4;$count<=$#parts;$count++) {
2155: $filepath.="/$parts[$count]";
2156: if ((-e $filepath)!=1) {
2157: mkdir($filepath,02770);
2158: }
2159: }
2160: # Check for bad extension and disallow upload
2161: if ($file=~/\.(\w+)$/ &&
2162: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
2163: $output =
2164: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
2165: } elsif ($file=~/\.(\w+)$/ &&
2166: !defined(&Apache::loncommon::fileembstyle($1))) {
2167: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
2168: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
2169: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
2170: } elsif (-d "$filepath/$file") {
2171: $output = &mt('File name is a directory name - rename the file and re-upload');
2172: } else {
2173: my $source = $filepath.'/'.$file;
2174: my $logfile;
2175: if (!open($logfile,">>$source".'.log')) {
2176: return (&mt('No write permission to Construction Space'));
2177: }
2178: print $logfile
2179: "\n================= Publish ".localtime()." ================\n".
2180: $env{'user.name'}.':'.$env{'user.domain'}."\n";
2181: # Save the file
2182: if (!open(FH,'>'.$source)) {
2183: &Apache::lonnet::logthis('Failed to create '.$source);
2184: return (&mt('Failed to create file'));
2185: }
2186: if ($action eq 'upload') {
2187: if (!print FH ($env{'form.'.$formname})) {
2188: &Apache::lonnet::logthis('Failed to write to '.$source);
2189: return (&mt('Failed to write file'));
2190: }
2191: } else {
2192: my $original = &Apache::lonnet::filelocation('',$formname);
2193: if(!copy($original,$source)) {
2194: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
2195: return (&mt('Failed to write file'));
2196: }
2197: }
2198: close(FH);
2199: chmod(0660, $source); # Permissions to rw-rw---.
2200:
2201: my $docroot=$r->dir_config('lonDocRoot');
2202: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
2203: my $copyfile=$targetdir.'/'.$file;
2204:
2205: my @parts=split(/\//,$targetdir);
2206: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
2207: for (my $count=5;$count<=$#parts;$count++) {
2208: $path.="/$parts[$count]";
2209: if (!-e $path) {
2210: print $logfile "\nCreating directory ".$path;
2211: mkdir($path,02770);
2212: }
2213: }
2214: my $versionresult;
2215: if (-e $copyfile) {
2216: $versionresult = &logo_versioning($targetdir,$file,$logfile);
2217: } else {
2218: $versionresult = 'ok';
2219: }
2220: if ($versionresult eq 'ok') {
2221: if (copy($source,$copyfile)) {
2222: print $logfile "\nCopied original source to ".$copyfile."\n";
2223: $output = 'ok';
2224: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
2225: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
2226: } else {
2227: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
2228: $output = &mt('Failed to copy file to RES space').", $!";
2229: }
2230: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
2231: my $inputfile = $filepath.'/'.$file;
2232: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 2233: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
2234: if ($fullwidth ne '' && $fullheight ne '') {
2235: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
2236: my $thumbsize = $thumbwidth.'x'.$thumbheight;
2237: system("convert -sample $thumbsize $inputfile $outfile");
2238: chmod(0660, $filepath.'/tn-'.$file);
2239: if (-e $outfile) {
2240: my $copyfile=$targetdir.'/tn-'.$file;
2241: if (copy($outfile,$copyfile)) {
2242: print $logfile "\nCopied source to ".$copyfile."\n";
2243: &write_metadata($dom,$confname,$formname,
2244: $targetdir,'tn-'.$file,$logfile);
2245: } else {
2246: print $logfile "\nUnable to write ".$copyfile.
2247: ':'.$!."\n";
2248: }
2249: }
1.9 raeburn 2250: }
2251: }
2252: }
2253: } else {
2254: $output = $versionresult;
2255: }
2256: }
2257: return ($output,$logourl);
2258: }
2259:
2260: sub logo_versioning {
2261: my ($targetdir,$file,$logfile) = @_;
2262: my $target = $targetdir.'/'.$file;
2263: my ($maxversion,$fn,$extn,$output);
2264: $maxversion = 0;
2265: if ($file =~ /^(.+)\.(\w+)$/) {
2266: $fn=$1;
2267: $extn=$2;
2268: }
2269: opendir(DIR,$targetdir);
2270: while (my $filename=readdir(DIR)) {
2271: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
2272: $maxversion=($1>$maxversion)?$1:$maxversion;
2273: }
2274: }
2275: $maxversion++;
2276: print $logfile "\nCreating old version ".$maxversion."\n";
2277: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
2278: if (copy($target,$copyfile)) {
2279: print $logfile "Copied old target to ".$copyfile."\n";
2280: $copyfile=$copyfile.'.meta';
2281: if (copy($target.'.meta',$copyfile)) {
2282: print $logfile "Copied old target metadata to ".$copyfile."\n";
2283: $output = 'ok';
2284: } else {
2285: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
2286: $output = &mt('Failed to copy old meta').", $!, ";
2287: }
2288: } else {
2289: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
2290: $output = &mt('Failed to copy old target').", $!, ";
2291: }
2292: return $output;
2293: }
2294:
2295: sub write_metadata {
2296: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
2297: my (%metadatafields,%metadatakeys,$output);
2298: $metadatafields{'title'}=$formname;
2299: $metadatafields{'creationdate'}=time;
2300: $metadatafields{'lastrevisiondate'}=time;
2301: $metadatafields{'copyright'}='public';
2302: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
2303: $env{'user.domain'};
2304: $metadatafields{'authorspace'}=$confname.':'.$dom;
2305: $metadatafields{'domain'}=$dom;
2306: {
2307: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
2308: my $mfh;
2309: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
2310: $output = &mt('Could not write metadata');
2311: }
2312: foreach (sort keys %metadatafields) {
2313: unless ($_=~/\./) {
2314: my $unikey=$_;
2315: $unikey=~/^([A-Za-z]+)/;
2316: my $tag=$1;
2317: $tag=~tr/A-Z/a-z/;
2318: print $mfh "\n\<$tag";
2319: foreach (split(/\,/,$metadatakeys{$unikey})) {
2320: my $value=$metadatafields{$unikey.'.'.$_};
2321: $value=~s/\"/\'\'/g;
2322: print $mfh ' '.$_.'="'.$value.'"';
2323: }
2324: print $mfh '>'.
2325: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
2326: .'</'.$tag.'>';
2327: }
2328: }
2329: $output = 'ok';
2330: print $logfile "\nWrote metadata";
2331: close($mfh);
2332: }
2333: }
2334:
2335: sub check_switchserver {
2336: my ($dom,$confname) = @_;
2337: my ($allowed,$switchserver);
2338: my $home = &Apache::lonnet::homeserver($confname,$dom);
2339: if ($home eq 'no_host') {
2340: $home = &Apache::lonnet::domain($dom,'primary');
2341: }
2342: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 2343: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2344: if (!$allowed) {
2345: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 2346: }
2347: return $switchserver;
2348: }
2349:
1.30 raeburn 2350: sub javascript_set_colnums {
2351: return <<END;
2352: function setDisplayColumns() {
2353: if (document.pickactions.width.value > 1100) {
2354: document.pickactions.numcols[1].checked = true;
2355: } else {
2356: document.pickactions.numcols[0].checked = true;
2357: }
2358: }
2359: END
2360: }
2361:
1.1 raeburn 2362: sub modify_quotas {
1.3 raeburn 2363: my ($dom,%domconfig) = @_;
1.1 raeburn 2364: my ($resulttext,%changes);
1.26 raeburn 2365: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2366: my %formhash;
2367: foreach my $key (keys(%env)) {
2368: if ($key =~ /^form\.quota_(.+)$/) {
2369: $formhash{$1} = $env{$key};
2370: }
2371: }
1.15 raeburn 2372: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 2373: if (ref($domconfig{'quotas'}) eq 'HASH') {
2374: foreach my $key (keys(%{$domconfig{'quotas'}})) {
2375: if (exists($formhash{$key})) {
2376: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
2377: $changes{$key} = 1;
2378: }
2379: } else {
2380: $formhash{$key} = $domconfig{'quotas'}{$key};
2381: }
2382: }
2383: }
2384: foreach my $key (keys(%formhash)) {
2385: if ($formhash{$key} ne '') {
1.3 raeburn 2386: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 2387: $changes{$key} = 1;
2388: }
2389: }
2390: }
2391: my %quotahash = (
1.3 raeburn 2392: quotas => {%formhash},
1.1 raeburn 2393: );
2394: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
2395: $dom);
2396: if ($putresult eq 'ok') {
2397: if (keys(%changes) > 0) {
2398: $resulttext = &mt('Changes made:').'<ul>';
1.26 raeburn 2399: foreach my $type (@{$types},'default') {
2400: if (defined($changes{$type})) {
2401: my $typetitle = $usertypes->{$type};
2402: if ($type eq 'default') {
2403: $typetitle = $othertitle;
2404: }
2405: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
2406: }
1.1 raeburn 2407: }
2408: $resulttext .= '</ul>';
2409: } else {
2410: $resulttext = &mt('No changes made to default quotas');
2411: }
2412: } else {
1.11 albertel 2413: $resulttext = '<span class="LC_error">'.
2414: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2415: }
1.3 raeburn 2416: return $resulttext;
1.1 raeburn 2417: }
2418:
1.3 raeburn 2419: sub modify_autoenroll {
2420: my ($dom,%domconfig) = @_;
1.1 raeburn 2421: my ($resulttext,%changes);
2422: my %currautoenroll;
2423: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
2424: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
2425: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
2426: }
2427: }
2428: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2429: my %title = ( run => 'Auto-enrollment active',
2430: sender => 'Sender for notification messages');
2431: my @offon = ('off','on');
1.17 raeburn 2432: my $sender_uname = $env{'form.sender_uname'};
2433: my $sender_domain = $env{'form.sender_domain'};
2434: if ($sender_domain eq '') {
2435: $sender_uname = '';
2436: } elsif ($sender_uname eq '') {
2437: $sender_domain = '';
2438: }
1.1 raeburn 2439: my %autoenrollhash = (
2440: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 2441: sender_uname => $sender_uname,
2442: sender_domain => $sender_domain,
1.1 raeburn 2443:
2444: }
2445: );
1.4 raeburn 2446: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
2447: $dom);
1.1 raeburn 2448: if ($putresult eq 'ok') {
2449: if (exists($currautoenroll{'run'})) {
2450: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
2451: $changes{'run'} = 1;
2452: }
2453: } elsif ($autorun) {
2454: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 2455: $changes{'run'} = 1;
1.1 raeburn 2456: }
2457: }
1.17 raeburn 2458: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 2459: $changes{'sender'} = 1;
2460: }
1.17 raeburn 2461: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 2462: $changes{'sender'} = 1;
2463: }
2464: if (keys(%changes) > 0) {
2465: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 2466: if ($changes{'run'}) {
1.1 raeburn 2467: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
2468: }
2469: if ($changes{'sender'}) {
1.17 raeburn 2470: if ($sender_uname eq '' || $sender_domain eq '') {
2471: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
2472: } else {
2473: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
2474: }
1.1 raeburn 2475: }
2476: $resulttext .= '</ul>';
2477: } else {
2478: $resulttext = &mt('No changes made to auto-enrollment settings');
2479: }
2480: } else {
1.11 albertel 2481: $resulttext = '<span class="LC_error">'.
2482: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2483: }
1.3 raeburn 2484: return $resulttext;
1.1 raeburn 2485: }
2486:
2487: sub modify_autoupdate {
1.3 raeburn 2488: my ($dom,%domconfig) = @_;
1.1 raeburn 2489: my ($resulttext,%currautoupdate,%fields,%changes);
2490: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
2491: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
2492: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
2493: }
2494: }
2495: my @offon = ('off','on');
2496: my %title = &Apache::lonlocal::texthash (
2497: run => 'Auto-update:',
2498: classlists => 'Updates to user information in classlists?'
2499: );
1.26 raeburn 2500: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 2501: my %fieldtitles = &Apache::lonlocal::texthash (
2502: id => 'Student/Employee ID',
1.20 raeburn 2503: permanentemail => 'E-mail address',
1.1 raeburn 2504: lastname => 'Last Name',
2505: firstname => 'First Name',
2506: middlename => 'Middle Name',
2507: gen => 'Generation',
2508: );
2509: my $othertitle = &mt('All users');
2510: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 2511: $othertitle = &mt('Other users');
1.1 raeburn 2512: }
2513: foreach my $key (keys(%env)) {
2514: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
2515: push(@{$fields{$1}},$2);
2516: }
2517: }
2518: my %updatehash = (
2519: autoupdate => { run => $env{'form.autoupdate_run'},
2520: classlists => $env{'form.classlists'},
2521: fields => {%fields},
2522: }
2523: );
2524: foreach my $key (keys(%currautoupdate)) {
2525: if (($key eq 'run') || ($key eq 'classlists')) {
2526: if (exists($updatehash{autoupdate}{$key})) {
2527: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
2528: $changes{$key} = 1;
2529: }
2530: }
2531: } elsif ($key eq 'fields') {
2532: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 2533: foreach my $item (@{$types},'default') {
1.1 raeburn 2534: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
2535: my $change = 0;
2536: foreach my $type (@{$currautoupdate{$key}{$item}}) {
2537: if (!exists($fields{$item})) {
2538: $change = 1;
2539: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 2540: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 2541: $change = 1;
2542: }
2543: }
2544: }
2545: if ($change) {
2546: push(@{$changes{$key}},$item);
2547: }
1.26 raeburn 2548: }
1.1 raeburn 2549: }
2550: }
2551: }
2552: }
1.26 raeburn 2553: foreach my $item (@{$types},'default') {
2554: if (defined($fields{$item})) {
2555: if (ref($currautoupdate{'fields'}) eq 'HASH') {
2556: if (!exists($currautoupdate{'fields'}{$item})) {
2557: push(@{$changes{'fields'}},$item);
2558: }
2559: } else {
2560: push(@{$changes{'fields'}},$item);
1.1 raeburn 2561: }
2562: }
2563: }
2564: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
2565: $dom);
2566: if ($putresult eq 'ok') {
2567: if (keys(%changes) > 0) {
2568: $resulttext = &mt('Changes made:').'<ul>';
2569: foreach my $key (sort(keys(%changes))) {
2570: if (ref($changes{$key}) eq 'ARRAY') {
2571: foreach my $item (@{$changes{$key}}) {
2572: my @newvalues;
2573: foreach my $type (@{$fields{$item}}) {
2574: push(@newvalues,$fieldtitles{$type});
2575: }
1.3 raeburn 2576: my $newvaluestr;
2577: if (@newvalues > 0) {
2578: $newvaluestr = join(', ',@newvalues);
2579: } else {
2580: $newvaluestr = &mt('none');
1.6 raeburn 2581: }
1.1 raeburn 2582: if ($item eq 'default') {
1.26 raeburn 2583: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 2584: } else {
1.26 raeburn 2585: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 2586: }
2587: }
2588: } else {
2589: my $newvalue;
2590: if ($key eq 'run') {
2591: $newvalue = $offon[$env{'form.autoupdate_run'}];
2592: } else {
2593: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 2594: }
1.1 raeburn 2595: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
2596: }
2597: }
2598: $resulttext .= '</ul>';
2599: } else {
1.3 raeburn 2600: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 2601: }
2602: } else {
1.11 albertel 2603: $resulttext = '<span class="LC_error">'.
2604: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2605: }
1.3 raeburn 2606: return $resulttext;
1.1 raeburn 2607: }
2608:
1.23 raeburn 2609: sub modify_directorysrch {
2610: my ($dom,%domconfig) = @_;
2611: my ($resulttext,%changes);
2612: my %currdirsrch;
2613: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2614: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
2615: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
2616: }
2617: }
2618: my %title = ( available => 'Directory search available',
1.24 raeburn 2619: localonly => 'Other domains can search',
1.23 raeburn 2620: searchby => 'Search types',
2621: searchtypes => 'Search latitude');
2622: my @offon = ('off','on');
1.24 raeburn 2623: my @otherdoms = ('Yes','No');
1.23 raeburn 2624:
1.25 raeburn 2625: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 2626: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
2627: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
2628:
1.26 raeburn 2629: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
2630: if (keys(%{$usertypes}) == 0) {
2631: @cansearch = ('default');
2632: } else {
2633: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
2634: foreach my $type (@{$currdirsrch{'cansearch'}}) {
2635: if (!grep(/^\Q$type\E$/,@cansearch)) {
2636: push(@{$changes{'cansearch'}},$type);
2637: }
1.23 raeburn 2638: }
1.26 raeburn 2639: foreach my $type (@cansearch) {
2640: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
2641: push(@{$changes{'cansearch'}},$type);
2642: }
1.23 raeburn 2643: }
1.26 raeburn 2644: } else {
2645: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 2646: }
2647: }
2648:
2649: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
2650: foreach my $by (@{$currdirsrch{'searchby'}}) {
2651: if (!grep(/^\Q$by\E$/,@searchby)) {
2652: push(@{$changes{'searchby'}},$by);
2653: }
2654: }
2655: foreach my $by (@searchby) {
2656: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
2657: push(@{$changes{'searchby'}},$by);
2658: }
2659: }
2660: } else {
2661: push(@{$changes{'searchby'}},@searchby);
2662: }
1.25 raeburn 2663:
2664: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
2665: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
2666: if (!grep(/^\Q$type\E$/,@searchtypes)) {
2667: push(@{$changes{'searchtypes'}},$type);
2668: }
2669: }
2670: foreach my $type (@searchtypes) {
2671: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
2672: push(@{$changes{'searchtypes'}},$type);
2673: }
2674: }
2675: } else {
2676: if (exists($currdirsrch{'searchtypes'})) {
2677: foreach my $type (@searchtypes) {
2678: if ($type ne $currdirsrch{'searchtypes'}) {
2679: push(@{$changes{'searchtypes'}},$type);
2680: }
2681: }
2682: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
2683: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
2684: }
2685: } else {
2686: push(@{$changes{'searchtypes'}},@searchtypes);
2687: }
2688: }
2689:
1.23 raeburn 2690: my %dirsrch_hash = (
2691: directorysrch => { available => $env{'form.dirsrch_available'},
2692: cansearch => \@cansearch,
1.24 raeburn 2693: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 2694: searchby => \@searchby,
1.25 raeburn 2695: searchtypes => \@searchtypes,
1.23 raeburn 2696: }
2697: );
2698: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
2699: $dom);
2700: if ($putresult eq 'ok') {
2701: if (exists($currdirsrch{'available'})) {
2702: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
2703: $changes{'available'} = 1;
2704: }
2705: } else {
2706: if ($env{'form.dirsrch_available'} eq '1') {
2707: $changes{'available'} = 1;
2708: }
2709: }
1.24 raeburn 2710: if (exists($currdirsrch{'localonly'})) {
2711: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
2712: $changes{'localonly'} = 1;
2713: }
2714: } else {
2715: if ($env{'form.dirsrch_localonly'} eq '1') {
2716: $changes{'localonly'} = 1;
2717: }
2718: }
1.23 raeburn 2719: if (keys(%changes) > 0) {
2720: $resulttext = &mt('Changes made:').'<ul>';
2721: if ($changes{'available'}) {
2722: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
2723: }
1.24 raeburn 2724: if ($changes{'localonly'}) {
2725: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
2726: }
2727:
1.23 raeburn 2728: if (ref($changes{'cansearch'}) eq 'ARRAY') {
2729: my $chgtext;
1.26 raeburn 2730: if (ref($usertypes) eq 'HASH') {
2731: if (keys(%{$usertypes}) > 0) {
2732: foreach my $type (@{$types}) {
2733: if (grep(/^\Q$type\E$/,@cansearch)) {
2734: $chgtext .= $usertypes->{$type}.'; ';
2735: }
2736: }
2737: if (grep(/^default$/,@cansearch)) {
2738: $chgtext .= $othertitle;
2739: } else {
2740: $chgtext =~ s/\; $//;
2741: }
2742: $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 2743: }
2744: }
2745: }
2746: if (ref($changes{'searchby'}) eq 'ARRAY') {
2747: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2748: my $chgtext;
2749: foreach my $type (@{$titleorder}) {
2750: if (grep(/^\Q$type\E$/,@searchby)) {
2751: if (defined($searchtitles->{$type})) {
2752: $chgtext .= $searchtitles->{$type}.'; ';
2753: }
2754: }
2755: }
2756: $chgtext =~ s/\; $//;
2757: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
2758: }
1.25 raeburn 2759: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
2760: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
2761: my $chgtext;
2762: foreach my $type (@{$srchtypeorder}) {
2763: if (grep(/^\Q$type\E$/,@searchtypes)) {
2764: if (defined($srchtypes_desc->{$type})) {
2765: $chgtext .= $srchtypes_desc->{$type}.'; ';
2766: }
2767: }
2768: }
2769: $chgtext =~ s/\; $//;
2770: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 2771: }
2772: $resulttext .= '</ul>';
2773: } else {
2774: $resulttext = &mt('No changes made to institution directory search settings');
2775: }
2776: } else {
2777: $resulttext = '<span class="LC_error">'.
1.27 raeburn 2778: &mt('An error occurred: [_1]',$putresult).'</span>';
2779: }
2780: return $resulttext;
2781: }
2782:
1.28 raeburn 2783: sub modify_contacts {
2784: my ($dom,%domconfig) = @_;
2785: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
2786: if (ref($domconfig{'contacts'}) eq 'HASH') {
2787: foreach my $key (keys(%{$domconfig{'contacts'}})) {
2788: $currsetting{$key} = $domconfig{'contacts'}{$key};
2789: }
2790: }
2791: my (%others,%to);
2792: my @contacts = ('supportemail','adminemail');
2793: my @mailings = ('errormail','packagesmail','helpdeskmail');
2794: foreach my $type (@mailings) {
2795: @{$newsetting{$type}} =
2796: &Apache::loncommon::get_env_multiple('form.'.$type);
2797: foreach my $item (@contacts) {
2798: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
2799: $contacts_hash{contacts}{$type}{$item} = 1;
2800: } else {
2801: $contacts_hash{contacts}{$type}{$item} = 0;
2802: }
2803: }
2804: $others{$type} = $env{'form.'.$type.'_others'};
2805: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
2806: }
2807: foreach my $item (@contacts) {
2808: $to{$item} = $env{'form.'.$item};
2809: $contacts_hash{'contacts'}{$item} = $to{$item};
2810: }
2811: if (keys(%currsetting) > 0) {
2812: foreach my $item (@contacts) {
2813: if ($to{$item} ne $currsetting{$item}) {
2814: $changes{$item} = 1;
2815: }
2816: }
2817: foreach my $type (@mailings) {
2818: foreach my $item (@contacts) {
2819: if (ref($currsetting{$type}) eq 'HASH') {
2820: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
2821: push(@{$changes{$type}},$item);
2822: }
2823: } else {
2824: push(@{$changes{$type}},@{$newsetting{$type}});
2825: }
2826: }
2827: if ($others{$type} ne $currsetting{$type}{'others'}) {
2828: push(@{$changes{$type}},'others');
2829: }
2830: }
2831: } else {
2832: my %default;
2833: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2834: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2835: $default{'errormail'} = 'adminemail';
2836: $default{'packagesmail'} = 'adminemail';
2837: $default{'helpdeskmail'} = 'supportemail';
2838: foreach my $item (@contacts) {
2839: if ($to{$item} ne $default{$item}) {
2840: $changes{$item} = 1;
2841: }
2842: }
2843: foreach my $type (@mailings) {
2844: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
2845:
2846: push(@{$changes{$type}},@{$newsetting{$type}});
2847: }
2848: if ($others{$type} ne '') {
2849: push(@{$changes{$type}},'others');
2850: }
2851: }
2852: }
2853: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
2854: $dom);
2855: if ($putresult eq 'ok') {
2856: if (keys(%changes) > 0) {
2857: my ($titles,$short_titles) = &contact_titles();
2858: $resulttext = &mt('Changes made:').'<ul>';
2859: foreach my $item (@contacts) {
2860: if ($changes{$item}) {
2861: $resulttext .= '<li>'.$titles->{$item}.
2862: &mt(' set to: ').
2863: '<span class="LC_cusr_emph">'.
2864: $to{$item}.'</span></li>';
2865: }
2866: }
2867: foreach my $type (@mailings) {
2868: if (ref($changes{$type}) eq 'ARRAY') {
2869: $resulttext .= '<li>'.$titles->{$type}.': ';
2870: my @text;
2871: foreach my $item (@{$newsetting{$type}}) {
2872: push(@text,$short_titles->{$item});
2873: }
2874: if ($others{$type} ne '') {
2875: push(@text,$others{$type});
2876: }
2877: $resulttext .= '<span class="LC_cusr_emph">'.
2878: join(', ',@text).'</span></li>';
2879: }
2880: }
2881: $resulttext .= '</ul>';
2882: } else {
1.34 raeburn 2883: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 2884: }
2885: } else {
2886: $resulttext = '<span class="LC_error">'.
2887: &mt('An error occurred: [_1].',$putresult).'</span>';
2888: }
2889: return $resulttext;
2890: }
2891:
2892: sub modify_usercreation {
1.27 raeburn 2893: my ($dom,%domconfig) = @_;
1.34 raeburn 2894: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.27 raeburn 2895: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2896: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
2897: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
2898: }
2899: }
2900: my %title = &Apache::lonlocal::texthash (
2901: author => 'adding co-authors/assistant authors',
2902: course => 'adding users to a course',
2903: );
2904: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 2905: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.34 raeburn 2906: my @contexts = ('author','course');
2907: foreach my $item(@contexts) {
2908: $cancreate{$item} = $env{'form.can_createuser_'.$item};
2909: }
2910: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
2911: foreach my $item (@contexts) {
2912: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
2913: push(@{$changes{'cancreate'}},$item);
2914: }
1.27 raeburn 2915: }
1.34 raeburn 2916: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
2917: foreach my $item (@contexts) {
2918: if (grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
2919: if ($cancreate{$item} ne 'any') {
2920: push(@{$changes{'cancreate'}},$item);
2921: }
2922: } else {
2923: if ($cancreate{$item} ne 'none') {
2924: push(@{$changes{'cancreate'}},$item);
2925: }
1.27 raeburn 2926: }
2927: }
2928: } else {
1.34 raeburn 2929: foreach my $item ('author','course') {
2930: push(@{$changes{'cancreate'}},$item);
2931: }
1.27 raeburn 2932: }
1.34 raeburn 2933:
1.27 raeburn 2934: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
2935: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
2936: if (!grep(/^\Q$type\E$/,@username_rule)) {
2937: push(@{$changes{'username_rule'}},$type);
2938: }
2939: }
2940: foreach my $type (@username_rule) {
2941: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
2942: push(@{$changes{'username_rule'}},$type);
2943: }
2944: }
2945: } else {
2946: push(@{$changes{'username_rule'}},@username_rule);
2947: }
2948:
1.32 raeburn 2949: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
2950: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
2951: if (!grep(/^\Q$type\E$/,@id_rule)) {
2952: push(@{$changes{'id_rule'}},$type);
2953: }
2954: }
2955: foreach my $type (@id_rule) {
2956: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
2957: push(@{$changes{'id_rule'}},$type);
2958: }
2959: }
2960: } else {
2961: push(@{$changes{'id_rule'}},@id_rule);
2962: }
2963:
1.28 raeburn 2964: my @contexts = ('author','course','domain');
2965: my @authtypes = ('int','krb4','krb5','loc');
2966: my %authhash;
2967: foreach my $item (@contexts) {
2968: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
2969: foreach my $auth (@authtypes) {
2970: if (grep(/^\Q$auth\E$/,@authallowed)) {
2971: $authhash{$item}{$auth} = 1;
2972: } else {
2973: $authhash{$item}{$auth} = 0;
2974: }
2975: }
2976: }
2977: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
2978: foreach my $item (@contexts) {
2979: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
2980: foreach my $auth (@authtypes) {
2981: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
2982: push(@{$changes{'authtypes'}},$item);
2983: last;
2984: }
2985: }
2986: }
2987: }
2988: } else {
2989: foreach my $item (@contexts) {
2990: push(@{$changes{'authtypes'}},$item);
2991: }
2992: }
2993:
1.27 raeburn 2994: my %usercreation_hash = (
1.28 raeburn 2995: usercreation => {
1.34 raeburn 2996: cancreate => \%cancreate,
1.27 raeburn 2997: username_rule => \@username_rule,
1.32 raeburn 2998: id_rule => \@id_rule,
2999: authtypes => \%authhash,
1.27 raeburn 3000: }
3001: );
3002:
3003: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
3004: $dom);
3005: if ($putresult eq 'ok') {
3006: if (keys(%changes) > 0) {
3007: $resulttext = &mt('Changes made:').'<ul>';
3008: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 3009: my %lt = &usercreation_types();
3010: foreach my $type (@{$changes{'cancreate'}}) {
3011: my $chgtext;
3012: if ($cancreate{$type} eq 'none') {
3013: $chgtext = $lt{$type}.' '.&mt('creation of new users is not permitted, except by a Domain Coordinator.');
3014: } elsif ($cancreate{$type} eq 'any') {
3015: $chgtext = $lt{$type}.' '.&mt('creation of new users is permitted for both institutional and non-institutional usernames.');
3016: } elsif ($cancreate{$type} eq 'official') {
3017: $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for institutional usernames.',$lt{$type});
3018: } elsif ($cancreate{$type} eq 'unofficial') {
3019: $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for non-institutional usernames.',$lt{$type});
3020: }
3021: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 3022: }
3023: }
3024: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 3025: my ($rules,$ruleorder) =
3026: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 3027: my $chgtext = '<ul>';
3028: foreach my $type (@username_rule) {
3029: if (ref($rules->{$type}) eq 'HASH') {
3030: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
3031: }
3032: }
3033: $chgtext .= '</ul>';
3034: if (@username_rule > 0) {
3035: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3036: } else {
1.28 raeburn 3037: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 3038: }
3039: }
1.32 raeburn 3040: if (ref($changes{'id_rule'}) eq 'ARRAY') {
3041: my ($idrules,$idruleorder) =
3042: &Apache::lonnet::inst_userrules($dom,'id');
3043: my $chgtext = '<ul>';
3044: foreach my $type (@id_rule) {
3045: if (ref($idrules->{$type}) eq 'HASH') {
3046: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
3047: }
3048: }
3049: $chgtext .= '</ul>';
3050: if (@id_rule > 0) {
3051: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3052: } else {
3053: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
3054: }
3055: }
1.28 raeburn 3056: my %authname = &authtype_names();
3057: my %context_title = &context_names();
3058: if (ref($changes{'authtypes'}) eq 'ARRAY') {
3059: my $chgtext = '<ul>';
3060: foreach my $type (@{$changes{'authtypes'}}) {
3061: my @allowed;
3062: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
3063: foreach my $auth (@authtypes) {
3064: if ($authhash{$type}{$auth}) {
3065: push(@allowed,$authname{$auth});
3066: }
3067: }
3068: $chgtext .= join(', ',@allowed).'</li>';
3069: }
3070: $chgtext .= '</ul>';
3071: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
3072: $resulttext .= '</li>';
3073: }
1.27 raeburn 3074: $resulttext .= '</ul>';
3075: } else {
1.28 raeburn 3076: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 3077: }
3078: } else {
3079: $resulttext = '<span class="LC_error">'.
1.23 raeburn 3080: &mt('An error occurred: [_1]',$putresult).'</span>';
3081: }
3082: return $resulttext;
3083: }
3084:
1.33 raeburn 3085: sub modify_usermodification {
3086: my ($dom,%domconfig) = @_;
3087: my ($resulttext,%curr_usermodification,%changes);
3088: if (ref($domconfig{'usermodification'}) eq 'HASH') {
3089: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
3090: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
3091: }
3092: }
3093: my @contexts = ('author','course');
3094: my %context_title = (
3095: author => 'In author context',
3096: course => 'In course context',
3097: );
3098: my @fields = ('lastname','firstname','middlename','generation',
3099: 'permanentemail','id');
3100: my %roles = (
3101: author => ['ca','aa'],
3102: course => ['st','ep','ta','in','cr'],
3103: );
3104: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3105: my %modifyhash;
3106: foreach my $context (@contexts) {
3107: foreach my $role (@{$roles{$context}}) {
3108: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
3109: foreach my $item (@fields) {
3110: if (grep(/^\Q$item\E$/,@modifiable)) {
3111: $modifyhash{$context}{$role}{$item} = 1;
3112: } else {
3113: $modifyhash{$context}{$role}{$item} = 0;
3114: }
3115: }
3116: }
3117: if (ref($curr_usermodification{$context}) eq 'HASH') {
3118: foreach my $role (@{$roles{$context}}) {
3119: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
3120: foreach my $field (@fields) {
3121: if ($modifyhash{$context}{$role}{$field} ne
3122: $curr_usermodification{$context}{$role}{$field}) {
3123: push(@{$changes{$context}},$role);
3124: last;
3125: }
3126: }
3127: }
3128: }
3129: } else {
3130: foreach my $context (@contexts) {
3131: foreach my $role (@{$roles{$context}}) {
3132: push(@{$changes{$context}},$role);
3133: }
3134: }
3135: }
3136: }
3137: my %usermodification_hash = (
3138: usermodification => \%modifyhash,
3139: );
3140: my $putresult = &Apache::lonnet::put_dom('configuration',
3141: \%usermodification_hash,$dom);
3142: if ($putresult eq 'ok') {
3143: if (keys(%changes) > 0) {
3144: $resulttext = &mt('Changes made: ').'<ul>';
3145: foreach my $context (@contexts) {
3146: if (ref($changes{$context}) eq 'ARRAY') {
3147: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
3148: if (ref($changes{$context}) eq 'ARRAY') {
3149: foreach my $role (@{$changes{$context}}) {
3150: my $rolename;
3151: if ($role eq 'cr') {
3152: $rolename = &mt('Custom');
3153: } else {
3154: $rolename = &Apache::lonnet::plaintext($role);
3155: }
3156: my @modifiable;
3157: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
3158: foreach my $field (@fields) {
3159: if ($modifyhash{$context}{$role}{$field}) {
3160: push(@modifiable,$fieldtitles{$field});
3161: }
3162: }
3163: if (@modifiable > 0) {
3164: $resulttext .= join(', ',@modifiable);
3165: } else {
3166: $resulttext .= &mt('none');
3167: }
3168: $resulttext .= '</li>';
3169: }
3170: $resulttext .= '</ul></li>';
3171: }
3172: }
3173: }
3174: $resulttext .= '</ul>';
3175: } else {
3176: $resulttext = &mt('No changes made to user modification settings');
3177: }
3178: } else {
3179: $resulttext = '<span class="LC_error">'.
3180: &mt('An error occurred: [_1]',$putresult).'</span>';
3181: }
3182: return $resulttext;
3183: }
3184:
1.3 raeburn 3185: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>