Annotation of loncom/interface/domainprefs.pm, revision 1.27
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.27 ! raeburn 4: # $Id: domainprefs.pm,v 1.26 2007/09/01 21:20:14 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.3 raeburn 64: my $phase = "display";
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',
! 71: 'usercreation'],$dom);
1.3 raeburn 72: my @prefs = (
1.6 raeburn 73: { text => 'Default color schemes',
74: help => 'Default_Color_Schemes',
75: action => 'rolecolors',
76: header => [{col1 => 'Student Settings',
77: col2 => '',},
78: {col1 => 'Coordinator Settings',
79: col2 => '',},
80: {col1 => 'Author Settings',
81: col2 => '',},
82: {col1 => 'Administrator Settings',
83: col2 => '',}],
84: },
1.3 raeburn 85: { text => 'Log-in page options',
86: help => 'Domain_Log-in_Page',
87: action => 'login',
88: header => [{col1 => 'Item',
1.6 raeburn 89: col2 => '',}],
1.3 raeburn 90: },
91: { text => 'Default quotas for user portfolios',
92: help => 'Default_User_Quota',
93: action => 'quotas',
94: header => [{col1 => 'User type',
95: col2 => 'Default quota'}],
96: },
97: { text => 'Auto-enrollment settings',
98: help => 'Domain_Auto_Enrollment',
99: action => 'autoenroll',
100: header => [{col1 => 'Configuration setting',
101: col2 => 'Value(s)'}],
102: },
103: { text => 'Auto-update settings',
104: help => 'Domain_Auto_Update',
105: action => 'autoupdate',
106: header => [{col1 => 'Setting',
107: col2 => 'Value',},
108: {col1 => 'User Population',
109: col2 => 'Updataeable user data'}],
1.23 raeburn 110: },
111: { text => 'Institutional directory searches',
112: help => 'Domain_Directory_Search',
113: action => 'directorysrch',
114: header => [{col1 => 'Setting',
115: col2 => 'Value',}],
116: },
1.27 ! raeburn 117: { text => 'User creation',
! 118: help => 'Domain_User_Creation',
! 119: action => 'usercreation',
! 120: header => [{col1 => 'Setting',
! 121: col2 => 'Value',}],
! 122: },
1.3 raeburn 123: );
1.6 raeburn 124: my @roles = ('student','coordinator','author','admin');
1.3 raeburn 125: &Apache::lonhtmlcommon::add_breadcrumb
126: ({href=>"javascript:changePage(document.$phase,'display')",
127: text=>"Domain Configuration"});
1.9 raeburn 128: my $confname = $dom.'-domainconfig';
1.3 raeburn 129: if ($phase eq 'process') {
1.1 raeburn 130: &Apache::lonhtmlcommon::add_breadcrumb
1.3 raeburn 131: ({href=>"javascript:changePage(document.$phase,'$phase')",
132: text=>"Updated"});
133: &print_header($r,$phase);
134: foreach my $item (@prefs) {
135: $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
1.9 raeburn 136: &process_changes($r,$dom,$confname,
137: $item->{'action'},\@roles,%domconfig));
1.3 raeburn 138: }
139: $r->print('<p>');
140: &print_footer($r,$phase,'display','Back to actions menu');
141: $r->print('</p>');
1.1 raeburn 142: } else {
1.3 raeburn 143: if ($phase eq '') {
144: $phase = 'display';
1.1 raeburn 145: }
1.3 raeburn 146: my %helphash;
147: my $numprefs = @prefs;
148: &print_header($r,$phase);
1.21 raeburn 149: if (keys(%domconfig) == 0) {
150: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
151: my $perlvarref = &LONCAPA::Configuration::read_conf('loncapa.conf');
152: my $hostid = $perlvarref->{'lonHostID'};
153: if ($hostid ne $primarylibserv) {
154: my %designhash = &Apache::loncommon::get_domainconf($dom);
155: my @loginimages = ('img','logo','domlogo');
156: my $custom_img_count = 0;
157: foreach my $img (@loginimages) {
158: if ($designhash{$dom.'.login.'.$img} ne '') {
159: $custom_img_count ++;
160: }
161: }
162: foreach my $role (@roles) {
163: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
164: $custom_img_count ++;
165: }
166: }
167: if ($custom_img_count > 0) {
168: my $switch_server = &check_switchserver($dom,$confname);
169: $r->print(&mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.&mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.&mt("Thereafter, you will be able to update settings from this screen when logged in to any server in the LON-CAPA network (with a DC role selected in the domain), although you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />'.$switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
170: return OK;
171: }
172: }
173: }
1.3 raeburn 174: $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
175: foreach my $item (@prefs) {
1.6 raeburn 176: if ($item->{'action'} eq 'login') {
1.3 raeburn 177: $r->print('</td><td width="6%"> </td><td align="left" valign="top" width="47%">');
178: }
1.9 raeburn 179: &print_config_box($r,$dom,$confname,$phase,$item->{'action'},
1.6 raeburn 180: $item,$domconfig{$item->{'action'}});
1.3 raeburn 181: }
182: $r->print('
183: </td>
184: </tr>
185: </table>');
1.13 albertel 186: &print_footer($r,$phase,'process','Save changes');
1.3 raeburn 187: }
188: return OK;
189: }
190:
191: sub process_changes {
1.9 raeburn 192: my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
1.3 raeburn 193: my $output;
194: if ($action eq 'login') {
1.9 raeburn 195: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 196: } elsif ($action eq 'rolecolors') {
1.9 raeburn 197: $output = &modify_rolecolors($r,$dom,$confname,$roles,
198: %domconfig);
1.3 raeburn 199: } elsif ($action eq 'quotas') {
200: $output = &modify_quotas($dom,%domconfig);
201: } elsif ($action eq 'autoenroll') {
202: $output = &modify_autoenroll($dom,%domconfig);
203: } elsif ($action eq 'autoupdate') {
204: $output = &modify_autoupdate($dom,%domconfig);
1.23 raeburn 205: } elsif ($action eq 'directorysrch') {
206: $output = &modify_directorysrch($dom,%domconfig);
1.27 ! raeburn 207: } elsif ($action eq 'usercreation') {
! 208: $output = &modify_user_creation($dom,%domconfig);
1.3 raeburn 209: }
210: return $output;
211: }
212:
213: sub print_config_box {
1.9 raeburn 214: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.3 raeburn 215: $r->print('
216: <table class="LC_nested_outer">
217: <tr>
1.22 raeburn 218: <th>'.&mt($item->{text}).' </th></tr>');
219: #
220: # FIXME - put the help link back in when the help files exist
221: # <th>'.&mt($item->{text}).' '.
222: # &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
223: # </tr>');
1.6 raeburn 224: if (($action eq 'autoupdate') || ($action eq 'rolecolors')) {
225: my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
1.3 raeburn 226: $r->print('
227: <tr>
228: <td>
229: <table class="LC_nested">
230: <tr class="LC_info_row">
1.6 raeburn 231: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
1.3 raeburn 232: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.6 raeburn 233: </tr>');
234: if ($action eq 'autoupdate') {
235: $r->print(&print_autoupdate('top',$dom,$settings));
236: } else {
1.9 raeburn 237: $r->print(&print_rolecolors($phase,'student',$dom,$confname,$settings));
1.6 raeburn 238: }
239: $r->print('
240: </table>
241: </td>
242: </tr>
243: <tr>
244: <td>
245: <table class="LC_nested">
246: <tr class="LC_info_row">
247: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
248: <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
249: </tr>');
250: if ($action eq 'autoupdate') {
251: $r->print(&print_autoupdate('bottom',$dom,$settings));
252: } else {
1.9 raeburn 253: $r->print(&print_rolecolors($phase,'coordinator',$dom,$confname,$settings).'
1.6 raeburn 254: </table>
255: </td>
256: </tr>
257: <tr>
258: <td>
259: <table class="LC_nested">
260: <tr class="LC_info_row">
261: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
262: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
1.3 raeburn 263: </tr>'.
1.9 raeburn 264: &print_rolecolors($phase,'author',$dom,$confname,$settings).'
1.3 raeburn 265: </table>
266: </td>
267: </tr>
268: <tr>
269: <td>
270: <table class="LC_nested">
271: <tr class="LC_info_row">
1.6 raeburn 272: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
273: <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
1.3 raeburn 274: </tr>'.
1.9 raeburn 275: &print_rolecolors($phase,'admin',$dom,$confname,$settings));
1.6 raeburn 276: }
1.3 raeburn 277: } else {
278: $r->print('
279: <tr>
280: <td>
281: <table class="LC_nested">
1.6 raeburn 282: <tr class="LC_info_row">');
1.24 raeburn 283: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.6 raeburn 284: $r->print('
285: <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>');
286: } else {
287: $r->print('
288: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>');
289: }
290: $r->print('
1.3 raeburn 291: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
292: </tr>');
293: if ($action eq 'login') {
1.9 raeburn 294: $r->print(&print_login($dom,$confname,$phase,$settings));
1.3 raeburn 295: } elsif ($action eq 'quotas') {
296: $r->print(&print_quotas($dom,$settings));
297: } elsif ($action eq 'autoenroll') {
298: $r->print(&print_autoenroll($dom,$settings));
1.23 raeburn 299: } elsif ($action eq 'directorysrch') {
300: $r->print(&print_directorysrch($dom,$settings));
1.27 ! raeburn 301: } elsif ($action eq 'usercreation') {
! 302: $r->print(&print_usercreation($dom,$settings));
! 303: }
1.3 raeburn 304: }
305: $r->print('
306: </table>
307: </td>
308: </tr>
309: </table><br />');
1.1 raeburn 310: return;
311: }
312:
313: sub print_header {
1.3 raeburn 314: my ($r,$phase) = @_;
1.6 raeburn 315: my $js = '
1.1 raeburn 316: <script type="text/javascript">
317: function changePage(formname,newphase) {
318: formname.phase.value = newphase;
319: formname.submit();
320: }
1.6 raeburn 321: '.
322: &color_pick_js().'
1.1 raeburn 323: </script>
1.6 raeburn 324: ';
1.2 albertel 325: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.3 raeburn 326: $js));
327: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6 raeburn 328: $r->print('
1.8 raeburn 329: <form name="parmform" action="">
1.6 raeburn 330: <input type="hidden" name="pres_marker" />
331: <input type="hidden" name="pres_type" />
332: <input type="hidden" name="pres_value" />
333: </form>
334: ');
335: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
336: ' enctype="multipart/form-data">');
1.1 raeburn 337: return;
338: }
339:
340: sub print_footer {
1.3 raeburn 341: my ($r,$phase,$newphase,$button_text) = @_;
342: $button_text = &mt($button_text);
343: $r->print('<input type="hidden" name="phase" value="" />');
344: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
345: if ($phase eq 'process') {
346: $r->print('<a href='.$dest.'>'.$button_text.'</a>');
347: } else {
348: $r->print('<input type="button" name="store" value="'.
349: $button_text.'" onclick='.$dest.' />');
350: }
351: $r->print('</form>');
1.1 raeburn 352: $r->print('<br />'.&Apache::loncommon::end_page());
353: return;
354: }
355:
1.3 raeburn 356: sub print_login {
1.9 raeburn 357: my ($dom,$confname,$phase,$settings) = @_;
1.6 raeburn 358: my %choices = &login_choices();
359: my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
360: $catalogon = ' checked="checked" ';
361: $adminmailoff = ' checked="checked" ';
362: my @images = ('img','logo','domlogo');
363: my @bgs = ('pgbg','mainbg','sidebg');
364: my @links = ('link','alink','vlink');
1.7 albertel 365: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 366: my %defaultdesign = %Apache::loncommon::defaultdesign;
367: my (%is_custom,%designs);
368: my %defaults = (
369: font => $defaultdesign{'login.font'},
370: );
371: foreach my $item (@images) {
372: $defaults{$item} = $defaultdesign{'login.'.$item};
373: }
374: foreach my $item (@bgs) {
375: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
376: }
377: foreach my $item (@links) {
378: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
379: }
1.3 raeburn 380: if (ref($settings) eq 'HASH') {
381: if ($settings->{'coursecatalog'} eq '0') {
1.1 raeburn 382: $catalogoff = $catalogon;
383: $catalogon = ' ';
384: }
1.3 raeburn 385: if ($settings->{'adminmail'} eq '1') {
1.1 raeburn 386: $adminmailon = $adminmailoff;
387: $adminmailoff = ' ';
388: }
1.6 raeburn 389: foreach my $item (@images) {
390: if ($settings->{$item} ne '') {
391: $designs{$item} = $settings->{$item};
392: $is_custom{$item} = 1;
393: }
394: }
395: if ($settings->{'font'} ne '') {
396: $designs{'font'} = $settings->{'font'};
397: $is_custom{'font'} = 1;
398: }
399: foreach my $item (@bgs) {
400: if ($settings->{$item} ne '') {
401: $designs{'bgs'}{$item} = $settings->{$item};
402: $is_custom{$item} = 1;
403: }
404: }
405: foreach my $item (@links) {
406: if ($settings->{$item} ne '') {
407: $designs{'links'}{$item} = $settings->{$item};
408: $is_custom{$item} = 1;
409: }
410: }
411: } else {
412: if ($designhash{$dom.'.login.font'} ne '') {
413: $designs{'font'} = $designhash{$dom.'.login.font'};
414: $is_custom{'font'} = 1;
415: }
1.8 raeburn 416: foreach my $item (@images) {
417: if ($designhash{$dom.'.login.'.$item} ne '') {
418: $designs{$item} = $designhash{$dom.'.login.'.$item};
419: $is_custom{$item} = 1;
420: }
421: }
1.6 raeburn 422: foreach my $item (@bgs) {
423: if ($designhash{$dom.'.login.'.$item} ne '') {
424: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
425: $is_custom{$item} = 1;
426: }
427: }
428: foreach my $item (@links) {
429: if ($designhash{$dom.'.login.'.$item} ne '') {
430: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
431: $is_custom{$item} = 1;
432: }
433: }
1.1 raeburn 434: }
1.6 raeburn 435: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
436: logo => 'Institution Logo',
437: domlogo => 'Domain Logo');
438: my $itemcount = 1;
439: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.3 raeburn 440: my $datatable =
1.6 raeburn 441: '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
442: '</td><td>'.
1.8 raeburn 443: '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
444: $catalogon.' value="1" />'.&mt('Yes').'</label> '.
445: '<label><input type="radio" name="coursecatalog"'.
446: $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.6 raeburn 447: '</tr>';
448: $itemcount ++;
449: $css_class = $itemcount%2?' class="LC_odd_row"':'';
450: $datatable .= '<tr'.$css_class.'>'.
451: '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
1.8 raeburn 452: '<td><span class="LC_nobreak">'.
453: '<label><input type="radio" name="adminmail"'.
454: $adminmailon.' value="1" />'.&mt('Yes').'</label> '.
455: '<label><input type="radio" name="adminmail"'.
456: $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
1.6 raeburn 457: $itemcount ++;
1.9 raeburn 458: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
1.6 raeburn 459: $datatable .= '</tr></table></td></tr>';
460: return $datatable;
461: }
462:
463: sub login_choices {
464: my %choices =
465: &Apache::lonlocal::texthash (
466: coursecatalog => 'Display Course Catalog link?',
467: adminmail => "Display Administrator's E-mail Address?",
468: img => "Header",
469: logo => "Main Logo",
470: domlogo => "Domain Logo",
471: bgs => "Background colors",
472: links => "Link colors",
473: font => "Font color",
474: pgbg => "Page",
475: mainbg => "Main panel",
476: sidebg => "Side panel",
477: link => "Link",
478: alink => "Active link",
479: vlink => "Visited link",
480: );
481: return %choices;
482: }
483:
484: sub print_rolecolors {
1.9 raeburn 485: my ($phase,$role,$dom,$confname,$settings) = @_;
1.6 raeburn 486: my %choices = &color_font_choices();
487: my @bgs = ('pgbg','tabbg','sidebg');
488: my @links = ('link','alink','vlink');
489: my @images = ('img');
490: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 491: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 492: my %defaultdesign = %Apache::loncommon::defaultdesign;
493: my (%is_custom,%designs);
494: my %defaults = (
495: img => $defaultdesign{$role.'.img'},
496: font => $defaultdesign{$role.'.font'},
497: );
498: foreach my $item (@bgs) {
499: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
500: }
501: foreach my $item (@links) {
502: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
503: }
504: if (ref($settings) eq 'HASH') {
505: if (ref($settings->{$role}) eq 'HASH') {
506: if ($settings->{$role}->{'img'} ne '') {
507: $designs{'img'} = $settings->{$role}->{'img'};
508: $is_custom{'img'} = 1;
509: }
510: if ($settings->{$role}->{'font'} ne '') {
511: $designs{'font'} = $settings->{$role}->{'font'};
512: $is_custom{'font'} = 1;
513: }
514: foreach my $item (@bgs) {
515: if ($settings->{$role}->{$item} ne '') {
516: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
517: $is_custom{$item} = 1;
518: }
519: }
520: foreach my $item (@links) {
521: if ($settings->{$role}->{$item} ne '') {
522: $designs{'links'}{$item} = $settings->{$role}->{$item};
523: $is_custom{$item} = 1;
524: }
525: }
526: }
527: } else {
528: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
529: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
530: $is_custom{'img'} = 1;
531: }
532: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
533: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
534: $is_custom{'font'} = 1;
535: }
536: foreach my $item (@bgs) {
537: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
538: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
539: $is_custom{$item} = 1;
540:
541: }
542: }
543: foreach my $item (@links) {
544: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
545: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
546: $is_custom{$item} = 1;
547: }
548: }
549: }
550: my $itemcount = 1;
1.9 raeburn 551: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
1.6 raeburn 552: $datatable .= '</tr></table></td></tr>';
553: return $datatable;
554: }
555:
556: sub display_color_options {
1.9 raeburn 557: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.6 raeburn 558: $images,$bgs,$links,$alt_text) = @_;
559: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
560: my $datatable = '<tr'.$css_class.'>'.
561: '<td>'.$choices->{'font'}.'</td>';
562: if (!$is_custom->{'font'}) {
563: $datatable .= '<td>'.&mt('Default in use:').' '.$defaults->{'font'}.'</td>';
564: } else {
565: $datatable .= '<td> </td>';
566: }
567: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 568: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 569: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 570: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
571: '</span></td></tr>';
1.9 raeburn 572: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 573: foreach my $img (@{$images}) {
1.18 albertel 574: $itemcount ++;
1.6 raeburn 575: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 576: $datatable .= '<tr'.$css_class.'>'.
1.6 raeburn 577: '<td>'.$choices->{$img}.'</td>';
1.18 albertel 578: my ($imgfile, $img_import);
1.6 raeburn 579: if ($designs->{$img} ne '') {
580: $imgfile = $designs->{$img};
1.18 albertel 581: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 582: } else {
583: $imgfile = $defaults->{$img};
584: }
585: if ($imgfile) {
1.9 raeburn 586: my ($showfile,$fullsize);
587: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 588: my $urldir = $1;
589: my $filename = $2;
590: my @info = &Apache::lonnet::stat_file($designs->{$img});
591: if (@info) {
592: my $thumbfile = 'tn-'.$filename;
593: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
594: if (@thumb) {
595: $showfile = $urldir.'/'.$thumbfile;
596: } else {
597: $showfile = $imgfile;
598: }
599: } else {
600: $showfile = '';
601: }
602: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 603: $showfile = $imgfile;
1.6 raeburn 604: my $imgdir = $1;
605: my $filename = $2;
606: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
607: $showfile = "/$imgdir/tn-".$filename;
608: } else {
609: my $input = "/home/httpd/html".$imgfile;
610: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
611: if (!-e $output) {
1.9 raeburn 612: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 613: my ($fullwidth,$fullheight) = &check_dimensions($input);
614: if ($fullwidth ne '' && $fullheight ne '') {
615: if ($fullwidth > $width && $fullheight > $height) {
616: my $size = $width.'x'.$height;
617: system("convert -sample $size $input $output");
618: $showfile = '/'.$imgdir.'/tn-'.$filename;
619: }
620: }
1.6 raeburn 621: }
622: }
1.16 raeburn 623: }
1.6 raeburn 624: if ($showfile) {
1.9 raeburn 625: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
626: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1.6 raeburn 627: $datatable.= '<td>';
628: if (!$is_custom->{$img}) {
629: $datatable .= &mt('Default in use:').'<br />';
630: }
1.18 albertel 631: if ($img_import) {
632: $datatable.= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
633: }
1.9 raeburn 634: $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
635: $showfile.'" alt="'.$alt_text->{$img}.
636: '" border="0" /></a></td>';
1.6 raeburn 637: if ($is_custom->{$img}) {
1.8 raeburn 638: $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
639: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
640: '</label> '.&mt('Replace:').'</span><br />';
1.6 raeburn 641: } else {
642: $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
643: }
644: } else {
645: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
646: &mt('Upload:');
647: }
648: } else {
649: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
650: &mt('Upload:');
651: }
1.9 raeburn 652: if ($switchserver) {
653: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
654: } else {
655: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
656: }
657: $datatable .= '</td></tr>';
1.6 raeburn 658: }
659: $itemcount ++;
660: $css_class = $itemcount%2?' class="LC_odd_row"':'';
661: $datatable .= '<tr'.$css_class.'>'.
662: '<td>'.$choices->{'bgs'}.'</td>';
663: my $bgs_def;
664: foreach my $item (@{$bgs}) {
665: if (!$is_custom->{$item}) {
666: $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
667: }
668: }
669: if ($bgs_def) {
1.8 raeburn 670: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 671: } else {
672: $datatable .= '<td> </td>';
673: }
674: $datatable .= '<td class="LC_right_item">'.
675: '<table border="0"><tr>';
676: foreach my $item (@{$bgs}) {
677: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
678: $datatable .= '<td align="center">'.$link;
679: if ($designs->{'bgs'}{$item}) {
680: $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px"> </span>';
681: }
682: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
683: '" /></td>';
684: }
685: $datatable .= '</tr></table></td></tr>';
686: $itemcount ++;
687: $css_class = $itemcount%2?' class="LC_odd_row"':'';
688: $datatable .= '<tr'.$css_class.'>'.
689: '<td>'.$choices->{'links'}.'</td>';
690: my $links_def;
691: foreach my $item (@{$links}) {
692: if (!$is_custom->{$item}) {
693: $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
694: }
695: }
696: if ($links_def) {
1.8 raeburn 697: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 698: } else {
699: $datatable .= '<td> </td>';
700: }
701: $datatable .= '<td class="LC_right_item">'.
702: '<table border="0"><tr>';
703: foreach my $item (@{$links}) {
704: $datatable .= '<td align="center">';
705: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
706: if ($designs->{'links'}{$item}) {
707: $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
708: $link.'</span>';
709: } else {
710: $datatable .= $link;
711: }
712: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
713: '" /></td>';
714: }
1.3 raeburn 715: return $datatable;
716: }
717:
1.6 raeburn 718: sub color_pick {
719: my ($phase,$role,$item,$desc,$curcol) = @_;
720: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
721: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
722: ');">'.$desc.'</a>';
723: return $link;
724: }
725:
726: sub color_pick_js {
727: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
728: my $output = <<"ENDCOL";
729: function pclose() {
730: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
731: parmwin.close();
732: }
733:
734: $pjump_def
735:
736: function psub() {
737: pclose();
738: if (document.parmform.pres_marker.value!='') {
739: if (document.parmform.pres_type.value!='') {
740: eval('document.display.'+
741: document.parmform.pres_marker.value+
742: '.value=document.parmform.pres_value.value;');
743: }
744: } else {
745: document.parmform.pres_value.value='';
746: document.parmform.pres_marker.value='';
747: }
748: }
749: ENDCOL
750: return $output;
751: }
752:
1.3 raeburn 753: sub print_quotas {
754: my ($dom,$settings) = @_;
755: my $datatable;
1.23 raeburn 756: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.3 raeburn 757: my $typecount = 0;
758: my $css_class;
1.26 raeburn 759: if (ref($types) eq 'ARRAY') {
1.23 raeburn 760: foreach my $type (@{$types}) {
1.3 raeburn 761: if (defined($usertypes->{$type})) {
762: $typecount ++;
763: $css_class = $typecount%2?' class="LC_odd_row"':'';
764: $datatable .= '<tr'.$css_class.'>'.
765: '<td>'.$usertypes->{$type}.'</td>'.
1.8 raeburn 766: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 767: '<input type="text" name="quota_'.$type.
768: '" value="'.$settings->{$type}.
1.8 raeburn 769: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 770: }
771: }
772: }
773: my $defaultquota = '20';
774: if (ref($settings) eq 'HASH') {
775: if (defined($settings->{'default'})) {
776: $defaultquota = $settings->{'default'};
777: }
778: }
779: $typecount ++;
780: $css_class = $typecount%2?' class="LC_odd_row"':'';
781: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 782: '<td>'.$othertitle.'</td>'.
1.8 raeburn 783: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.15 raeburn 784: '<input type="text" name="defaultquota" value="'.
1.8 raeburn 785: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.3 raeburn 786: return $datatable;
787: }
788:
789: sub print_autoenroll {
790: my ($dom,$settings) = @_;
791: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 792: my ($defdom,$runon,$runoff);
1.3 raeburn 793: if (ref($settings) eq 'HASH') {
794: if (exists($settings->{'run'})) {
795: if ($settings->{'run'} eq '0') {
796: $runoff = ' checked="checked" ';
797: $runon = ' ';
798: } else {
799: $runon = ' checked="checked" ';
800: $runoff = ' ';
801: }
802: } else {
803: if ($autorun) {
804: $runon = ' checked="checked" ';
805: $runoff = ' ';
806: } else {
807: $runoff = ' checked="checked" ';
808: $runon = ' ';
809: }
810: }
811: if (exists($settings->{'sender_domain'})) {
812: $defdom = $settings->{'sender_domain'};
813: }
1.14 raeburn 814: } else {
815: if ($autorun) {
816: $runon = ' checked="checked" ';
817: $runoff = ' ';
818: } else {
819: $runoff = ' checked="checked" ';
820: $runon = ' ';
821: }
1.3 raeburn 822: }
823: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
824: my $datatable='<tr class="LC_odd_row">'.
825: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 826: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 827: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 828: $runon.' value="1" />'.&mt('Yes').'</label> '.
829: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 830: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 831: '</tr><tr>'.
832: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 833: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 834: &mt('username').': '.
835: '<input type="text" name="sender_uname" value="'.
836: $settings->{'sender_uname'}.
837: '" size="10" /> '.&mt('domain').
1.8 raeburn 838: ': '.$domform.'</span></td></tr>';
1.3 raeburn 839: return $datatable;
840: }
841:
842: sub print_autoupdate {
843: my ($position,$dom,$settings) = @_;
844: my $datatable;
845: if ($position eq 'top') {
846: my $updateon = ' ';
847: my $updateoff = ' checked="checked" ';
848: my $classlistson = ' ';
849: my $classlistsoff = ' checked="checked" ';
850: if (ref($settings) eq 'HASH') {
851: if ($settings->{'run'} eq '1') {
852: $updateon = $updateoff;
853: $updateoff = ' ';
854: }
855: if ($settings->{'classlists'} eq '1') {
856: $classlistson = $classlistsoff;
857: $classlistsoff = ' ';
858: }
859: }
860: my %title = (
861: run => 'Auto-update active?',
862: classlists => 'Update information in classlists?',
863: );
864: $datatable = '<tr class="LC_odd_row">'.
865: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 866: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 867: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 868: $updateon.' value="1" />'.&mt('Yes').'</label> '.
869: '<label><input type="radio" name="autoupdate_run"'.
870: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 871: '</tr><tr>'.
872: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 873: '<td class="LC_right_item"><span class="LC_nobreak">'.
874: '<label><input type="radio" name="classlists"'.
875: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
876: '<label><input type="radio" name="classlists"'.
877: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 878: '</tr>';
879: } else {
1.23 raeburn 880: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.20 raeburn 881: my @fields = ('lastname','firstname','middlename','gen',
882: 'permanentemail','id');
1.3 raeburn 883: my %fieldtitles = &Apache::lonlocal::texthash (
884: id => 'Student/Employee ID',
1.20 raeburn 885: permanentemail => 'E-mail address',
1.3 raeburn 886: lastname => 'Last Name',
887: firstname => 'First Name',
888: middlename => 'Middle Name',
889: gen => 'Generation',
890: );
891: my $numrows = 0;
1.26 raeburn 892: if (ref($types) eq 'ARRAY') {
893: if (@{$types} > 0) {
894: $datatable =
895: &usertype_update_row($settings,$usertypes,\%fieldtitles,
896: \@fields,$types,\$numrows);
897: }
1.3 raeburn 898: }
899: $datatable .=
900: &usertype_update_row($settings,{'default' => $othertitle},
901: \%fieldtitles,\@fields,['default'],
902: \$numrows);
903: }
904: return $datatable;
905: }
906:
1.23 raeburn 907: sub print_directorysrch {
908: my ($dom,$settings) = @_;
909: my $srchon = ' ';
910: my $srchoff = ' checked="checked" ';
1.25 raeburn 911: my ($exacton,$containson,$beginson);
1.24 raeburn 912: my $localon = ' ';
913: my $localoff = ' checked="checked" ';
1.23 raeburn 914: if (ref($settings) eq 'HASH') {
915: if ($settings->{'available'} eq '1') {
916: $srchon = $srchoff;
917: $srchoff = ' ';
918: }
1.24 raeburn 919: if ($settings->{'localonly'} eq '1') {
920: $localon = $localoff;
921: $localoff = ' ';
922: }
1.25 raeburn 923: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
924: foreach my $type (@{$settings->{'searchtypes'}}) {
925: if ($type eq 'exact') {
926: $exacton = ' checked="checked" ';
927: } elsif ($type eq 'contains') {
928: $containson = ' checked="checked" ';
929: } elsif ($type eq 'begins') {
930: $beginson = ' checked="checked" ';
931: }
932: }
933: } else {
934: if ($settings->{'searchtypes'} eq 'exact') {
935: $exacton = ' checked="checked" ';
936: } elsif ($settings->{'searchtypes'} eq 'contains') {
937: $containson = ' checked="checked" ';
938: } elsif ($settings->{'searchtypes'} eq 'specify') {
939: $exacton = ' checked="checked" ';
940: $containson = ' checked="checked" ';
941: }
1.23 raeburn 942: }
943: }
944: my ($searchtitles,$titleorder) = &sorted_searchtitles();
945: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
946:
947: my $numinrow = 4;
1.26 raeburn 948: my $cansrchrow = 0;
1.23 raeburn 949: my $datatable='<tr class="LC_odd_row">'.
1.24 raeburn 950: '<td colspan="2">'.&mt('Directory search available?').'</td>'.
1.23 raeburn 951: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
952: '<input type="radio" name="dirsrch_available"'.
953: $srchon.' value="1" />'.&mt('Yes').'</label> '.
954: '<label><input type="radio" name="dirsrch_available"'.
955: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
956: '</tr><tr>'.
1.25 raeburn 957: '<td colspan="2">'.&mt('Other domains can search?').'</td>'.
1.24 raeburn 958: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
959: '<input type="radio" name="dirsrch_localonly"'.
960: $localoff.' value="0" />'.&mt('Yes').'</label> '.
961: '<label><input type="radio" name="dirsrch_localonly"'.
962: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 963: '</tr>';
1.26 raeburn 964: if (ref($usertypes) eq 'HASH') {
965: if (keys(%{$usertypes}) > 0) {
966: $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
967: $numinrow,$othertitle);
968: $cansrchrow = 1;
969: }
970: }
971: if ($cansrchrow) {
972: $datatable .= '<tr>';
973: } else {
974: $datatable .= '<tr class="LC_odd_row">';
975: }
976: $datatable .= '<td>'.&mt('Supported search methods').
1.25 raeburn 977: '</td><td class="LC_left_item" colspan="2"><table><tr>';
978: foreach my $title (@{$titleorder}) {
979: if (defined($searchtitles->{$title})) {
980: my $check = ' ';
981: if (ref($settings->{'searchby'}) eq 'ARRAY') {
982: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
983: $check = ' checked="checked" ';
984: }
985: }
986: $datatable .= '<td class="LC_left_item">'.
987: '<span class="LC_nobreak"><label>'.
988: '<input type="checkbox" name="searchby" '.
989: 'value="'.$title.'"'.$check.'/>'.
990: $searchtitles->{$title}.'</label></span></td>';
991: }
992: }
1.26 raeburn 993: $datatable .= '</tr></table></td></tr>';
994: if ($cansrchrow) {
995: $datatable .= '<tr class="LC_odd_row">';
996: } else {
997: $datatable .= '<tr>';
998: }
999: $datatable .= '<td>'.&mt('Search latitude').'</td>'.
1000: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1001: '<span class="LC_nobreak"><label>'.
1002: '<input type="checkbox" name="searchtypes" '.
1003: $exacton.' value="exact" />'.&mt('Exact match').
1004: '</label> '.
1005: '<label><input type="checkbox" name="searchtypes" '.
1006: $beginson.' value="begins" />'.&mt('Begins with').
1007: '</label> '.
1008: '<label><input type="checkbox" name="searchtypes" '.
1009: $containson.' value="contains" />'.&mt('Contains').
1010: '</label></span></td></tr>';
1011: return $datatable;
1012: }
1013:
1.27 ! raeburn 1014: sub print_usercreation {
! 1015: my ($dom,$settings) = @_;
! 1016: my $numinrow = 4;
! 1017: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom);
! 1018: my %checked;
! 1019: if (ref($settings) eq 'HASH') {
! 1020: if (ref($settings->{'cancreate'}) eq 'ARRAY') {
! 1021: foreach my $item (@{$settings->{'cancreate'}}) {
! 1022: $checked{$item} = ' checked="checked" ';
! 1023: }
! 1024: }
! 1025: }
! 1026: my $datatable = '<td>'.&mt('User creation other than by DC: ').'</td>'.
! 1027: '<td class="LC_left_item"><table><tr><td>'.
! 1028: '<span class="LC_nobreak"><label>'.
! 1029: '<input type="checkbox" name="can_createuser" '.
! 1030: $checked{'author'}.' value="author" />'.
! 1031: &mt('When adding a co-author/assistant author').
! 1032: '</label><span></td></tr>'.
! 1033: '<tr><td>'.
! 1034: '<span class="LC_nobreak"><label>'.
! 1035: '<input type="checkbox" name="can_createuser" '.
! 1036: $checked{'course'}.' value="course" />'.
! 1037: &mt('When adding users to a course').
! 1038: '</label><span></td></tr></table></td></tr>';
! 1039: if (ref($rules) eq 'HASH') {
! 1040: if (keys(%{$rules}) > 0) {
! 1041: $datatable .= &username_formats_row($settings,$rules,$ruleorder,
! 1042: $numinrow);
! 1043: }
! 1044: }
! 1045: return $datatable;
! 1046: }
! 1047:
! 1048: sub username_formats_row {
! 1049: my ($settings,$rules,$ruleorder,$numinrow) = @_;
! 1050: my $output = '<tr class="LC_odd_row">'.
! 1051: '<td>'.&mt('Format rules to check for new usernames').
! 1052: '</td><td class="LC_left_item" colspan="2"><table>';
! 1053: my $rem;
! 1054: if (ref($ruleorder) eq 'ARRAY') {
! 1055: for (my $i=0; $i<@{$ruleorder}; $i++) {
! 1056: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
! 1057: my $rem = $i%($numinrow);
! 1058: if ($rem == 0) {
! 1059: if ($i > 0) {
! 1060: $output .= '</tr>';
! 1061: }
! 1062: $output .= '<tr>';
! 1063: }
! 1064: my $check = ' ';
! 1065: if (ref($settings->{'username_rule'}) eq 'ARRAY') {
! 1066: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{'username_rule'}})) {
! 1067: $check = ' checked="checked" ';
! 1068: }
! 1069: }
! 1070: $output .= '<td class="LC_left_item">'.
! 1071: '<span class="LC_nobreak"><label>'.
! 1072: '<input type="checkbox" name="username_rule" '.
! 1073: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
! 1074: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
! 1075: }
! 1076: }
! 1077: $rem = @{$ruleorder}%($numinrow);
! 1078: }
! 1079: my $colsleft = $numinrow - $rem;
! 1080: if ($colsleft > 1 ) {
! 1081: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
! 1082: ' </td>';
! 1083: } elsif ($colsleft == 1) {
! 1084: $output .= '<td class="LC_left_item"> </td>';
! 1085: }
! 1086: $output .= '</tr></table></td></tr>';
! 1087: return $output;
! 1088: }
! 1089:
1.25 raeburn 1090: sub users_cansearch_row {
1091: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
1092: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 1093: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
1094: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 1095: my $rem;
1096: if (ref($types) eq 'ARRAY') {
1097: for (my $i=0; $i<@{$types}; $i++) {
1098: if (defined($usertypes->{$types->[$i]})) {
1099: my $rem = $i%($numinrow);
1100: if ($rem == 0) {
1101: if ($i > 0) {
1102: $output .= '</tr>';
1103: }
1104: $output .= '<tr>';
1.23 raeburn 1105: }
1.26 raeburn 1106: my $check = ' ';
1107: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1108: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
1109: $check = ' checked="checked" ';
1110: }
1.23 raeburn 1111: }
1.26 raeburn 1112: $output .= '<td class="LC_left_item">'.
1113: '<span class="LC_nobreak"><label>'.
1114: '<input type="checkbox" name="cansearch" '.
1115: 'value="'.$types->[$i].'"'.$check.'/>'.
1116: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 1117: }
1118: }
1.26 raeburn 1119:
1120: $rem = @{$types}%($numinrow);
1.23 raeburn 1121: }
1122: my $colsleft = $numinrow - $rem;
1123: if ($colsleft > 1) {
1.25 raeburn 1124: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 1125: } else {
1.25 raeburn 1126: $output .= '<td class="LC_left_item">';
1.23 raeburn 1127: }
1128: my $defcheck = ' ';
1129: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 1130: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
1131: $defcheck = ' checked="checked" ';
1132: }
1.23 raeburn 1133: }
1.25 raeburn 1134: $output .= '<span class="LC_nobreak"><label>'.
1135: '<input type="checkbox" name="cansearch" '.
1136: 'value="default"'.$defcheck.'/>'.
1137: $othertitle.'</label></span></td>'.
1138: '</tr></table></td></tr>';
1139: return $output;
1.23 raeburn 1140: }
1141:
1142: sub sorted_inst_types {
1143: my ($dom) = @_;
1144: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1.26 raeburn 1145: my $othertitle = &mt('All users');
1.23 raeburn 1146: my @types;
1147: if (ref($order) eq 'ARRAY') {
1148: @types = @{$order};
1149: }
1150: if (@types == 0) {
1151: if (ref($usertypes) eq 'HASH') {
1152: @types = sort(keys(%{$usertypes}));
1153: }
1154: }
1155: if (keys(%{$usertypes}) > 0) {
1156: $othertitle = &mt('Other users');
1157: }
1158: return ($othertitle,$usertypes,\@types);
1159: }
1160:
1161: sub sorted_searchtitles {
1162: my %searchtitles = &Apache::lonlocal::texthash(
1163: 'uname' => 'username',
1164: 'lastname' => 'last name',
1165: 'lastfirst' => 'last name, first name',
1166: );
1167: my @titleorder = ('uname','lastname','lastfirst');
1168: return (\%searchtitles,\@titleorder);
1169: }
1170:
1.25 raeburn 1171: sub sorted_searchtypes {
1172: my %srchtypes_desc = (
1173: exact => 'is exact match',
1174: contains => 'contains ..',
1175: begins => 'begins with ..',
1176: );
1177: my @srchtypeorder = ('exact','begins','contains');
1178: return (\%srchtypes_desc,\@srchtypeorder);
1179: }
1180:
1.3 raeburn 1181: sub usertype_update_row {
1182: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
1183: my $datatable;
1184: my $numinrow = 4;
1185: foreach my $type (@{$types}) {
1186: if (defined($usertypes->{$type})) {
1187: $$rownums ++;
1188: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
1189: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
1190: '</td><td class="LC_left_item"><table>';
1191: for (my $i=0; $i<@{$fields}; $i++) {
1192: my $rem = $i%($numinrow);
1193: if ($rem == 0) {
1194: if ($i > 0) {
1195: $datatable .= '</tr>';
1196: }
1197: $datatable .= '<tr>';
1198: }
1199: my $check = ' ';
1200: if (ref($settings->{'fields'}) eq 'HASH') {
1201: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
1202: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
1203: $check = ' checked="checked" ';
1204: }
1205: }
1206: }
1207:
1208: if ($i == @{$fields}-1) {
1209: my $colsleft = $numinrow - $rem;
1210: if ($colsleft > 1) {
1211: $datatable .= '<td colspan="'.$colsleft.'">';
1212: } else {
1213: $datatable .= '<td>';
1214: }
1215: } else {
1216: $datatable .= '<td>';
1217: }
1.8 raeburn 1218: $datatable .= '<span class="LC_nobreak"><label>'.
1219: '<input type="checkbox" name="updateable_'.$type.
1220: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
1221: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 1222: }
1223: $datatable .= '</tr></table></td></tr>';
1224: }
1225: }
1226: return $datatable;
1.1 raeburn 1227: }
1228:
1229: sub modify_login {
1.9 raeburn 1230: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 1231: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 1232: my %title = ( coursecatalog => 'Display course catalog',
1233: adminmail => 'Display administrator E-mail address');
1.3 raeburn 1234: my @offon = ('off','on');
1.6 raeburn 1235: my %loginhash;
1.9 raeburn 1236: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
1237: \%domconfig,\%loginhash);
1.6 raeburn 1238: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
1239: $loginhash{login}{adminmail} = $env{'form.adminmail'};
1240: if (ref($colchanges{'login'}) eq 'HASH') {
1241: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
1242: \%loginhash);
1243: }
1.1 raeburn 1244: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
1245: $dom);
1246: if ($putresult eq 'ok') {
1.3 raeburn 1247: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 1248: ($env{'form.coursecatalog'} eq '1')) {
1249: $changes{'coursecatalog'} = 1;
1.3 raeburn 1250: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
1251: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 1252: ($env{'form.coursecatalog'} eq '0')) {
1253: $changes{'coursecatalog'} = 1;
1254: }
1.3 raeburn 1255: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 1256: ($env{'form.adminmail'} eq '0')) {
1257: $changes{'adminmail'} = 1;
1258: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
1259: $domconfig{'login'}{'adminmail'} eq '0') &&
1260: ($env{'form.adminmail'} eq '1')) {
1261: $changes{'adminmail'} = 1;
1262: }
1.6 raeburn 1263: if (keys(%changes) > 0 || $colchgtext) {
1.1 raeburn 1264: $resulttext = &mt('Changes made:').'<ul>';
1265: foreach my $item (sort(keys(%changes))) {
1266: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
1267: }
1.6 raeburn 1268: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 1269: } else {
1270: $resulttext = &mt('No changes made to log-in page settings');
1271: }
1272: } else {
1.11 albertel 1273: $resulttext = '<span class="LC_error">'.
1274: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1275: }
1.6 raeburn 1276: if ($errors) {
1.9 raeburn 1277: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 1278: $errors.'</ul>';
1279: }
1280: return $resulttext;
1281: }
1282:
1283: sub color_font_choices {
1284: my %choices =
1285: &Apache::lonlocal::texthash (
1286: img => "Header",
1287: bgs => "Background colors",
1288: links => "Link colors",
1289: font => "Font color",
1290: pgbg => "Page",
1291: tabbg => "Header",
1292: sidebg => "Border",
1293: link => "Link",
1294: alink => "Active link",
1295: vlink => "Visited link",
1296: );
1297: return %choices;
1298: }
1299:
1300: sub modify_rolecolors {
1.9 raeburn 1301: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 1302: my ($resulttext,%rolehash);
1303: $rolehash{'rolecolors'} = {};
1.9 raeburn 1304: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 1305: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
1306: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
1307: $dom);
1308: if ($putresult eq 'ok') {
1309: if (keys(%changes) > 0) {
1310: $resulttext = &display_colorchgs($dom,\%changes,$roles,
1311: $rolehash{'rolecolors'});
1312: } else {
1313: $resulttext = &mt('No changes made to default color schemes');
1314: }
1315: } else {
1.11 albertel 1316: $resulttext = '<span class="LC_error">'.
1317: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 1318: }
1319: if ($errors) {
1320: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
1321: $errors.'</ul>';
1322: }
1323: return $resulttext;
1324: }
1325:
1326: sub modify_colors {
1.9 raeburn 1327: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 1328: my (%changes,%choices);
1.6 raeburn 1329: my @bgs = ('pgbg','mainbg','sidebg');
1330: my @links = ('link','alink','vlink');
1331: my @images;
1332: my $servadm = $r->dir_config('lonAdmEMail');
1333: my $errors;
1334: foreach my $role (@{$roles}) {
1335: if ($role eq 'login') {
1.12 raeburn 1336: %choices = &login_choices();
1337: } else {
1338: %choices = &color_font_choices();
1339: }
1340: if ($role eq 'login') {
1.6 raeburn 1341: @images = ('img','logo','domlogo');
1342: } else {
1343: @images = ('img');
1344: }
1345: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1346: foreach my $item (@bgs,@links) {
1347: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
1348: }
1.9 raeburn 1349: my ($configuserok,$author_ok,$switchserver,%currroles);
1350: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
1351: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
1352: $confname,$servadm);
1353: if ($configuserok eq 'ok') {
1354: $switchserver = &check_switchserver($dom,$confname);
1355: if ($switchserver eq '') {
1356: $author_ok = &check_authorstatus($dom,$confname,%currroles);
1357: }
1358: }
1359: my ($width,$height) = &thumb_dimensions();
1.8 raeburn 1360: foreach my $img (@images) {
1.18 albertel 1361: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
1362: && !defined($domconfig->{$role}{$img})
1363: && !$env{'form.'.$role.'_del_'.$img}
1364: && $env{'form.'.$role.'_import_'.$img}) {
1365: # import the old configured image from the .tab setting
1366: # if they haven't provided a new one
1367: $domconfig->{$role}{$img} =
1368: $env{'form.'.$role.'_import_'.$img};
1369: }
1.6 raeburn 1370: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 1371: my $error;
1.6 raeburn 1372: if ($configuserok eq 'ok') {
1.9 raeburn 1373: if ($switchserver) {
1.12 raeburn 1374: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 1375: } else {
1376: if ($author_ok eq 'ok') {
1377: my ($result,$logourl) =
1378: &publishlogo($r,'upload',$role.'_'.$img,
1379: $dom,$confname,$img,$width,$height);
1380: if ($result eq 'ok') {
1381: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 1382: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1383: } else {
1.12 raeburn 1384: $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 1385: }
1386: } else {
1.12 raeburn 1387: $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 1388: }
1389: }
1390: } else {
1.12 raeburn 1391: $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 1392: }
1393: if ($error) {
1.8 raeburn 1394: &Apache::lonnet::logthis($error);
1.11 albertel 1395: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 1396: }
1397: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 1398: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1399: my $error;
1400: if ($configuserok eq 'ok') {
1401: # is confname an author?
1402: if ($switchserver eq '') {
1403: if ($author_ok eq 'ok') {
1404: my ($result,$logourl) =
1405: &publishlogo($r,'copy',$domconfig->{$role}{$img},
1406: $dom,$confname,$img,$width,$height);
1407: if ($result eq 'ok') {
1408: $confhash->{$role}{$img} = $logourl;
1.18 albertel 1409: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1410: }
1411: }
1412: }
1413: }
1.6 raeburn 1414: }
1415: }
1416: }
1417: if (ref($domconfig) eq 'HASH') {
1418: if (ref($domconfig->{$role}) eq 'HASH') {
1419: foreach my $img (@images) {
1420: if ($domconfig->{$role}{$img} ne '') {
1421: if ($env{'form.'.$role.'_del_'.$img}) {
1422: $confhash->{$role}{$img} = '';
1.12 raeburn 1423: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1424: } else {
1.9 raeburn 1425: if ($confhash->{$role}{$img} eq '') {
1426: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
1427: }
1.6 raeburn 1428: }
1429: } else {
1430: if ($env{'form.'.$role.'_del_'.$img}) {
1431: $confhash->{$role}{$img} = '';
1.12 raeburn 1432: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1433: }
1434: }
1435: }
1436: if ($domconfig->{$role}{'font'} ne '') {
1437: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
1438: $changes{$role}{'font'} = 1;
1439: }
1440: } else {
1441: if ($confhash->{$role}{'font'}) {
1442: $changes{$role}{'font'} = 1;
1443: }
1444: }
1445: foreach my $item (@bgs) {
1446: if ($domconfig->{$role}{$item} ne '') {
1447: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1448: $changes{$role}{'bgs'}{$item} = 1;
1449: }
1450: } else {
1451: if ($confhash->{$role}{$item}) {
1452: $changes{$role}{'bgs'}{$item} = 1;
1453: }
1454: }
1455: }
1456: foreach my $item (@links) {
1457: if ($domconfig->{$role}{$item} ne '') {
1458: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1459: $changes{$role}{'links'}{$item} = 1;
1460: }
1461: } else {
1462: if ($confhash->{$role}{$item}) {
1463: $changes{$role}{'links'}{$item} = 1;
1464: }
1465: }
1466: }
1467: } else {
1468: &default_change_checker($role,\@images,\@links,\@bgs,
1469: $confhash,\%changes);
1470: }
1471: } else {
1472: &default_change_checker($role,\@images,\@links,\@bgs,
1473: $confhash,\%changes);
1474: }
1475: }
1476: return ($errors,%changes);
1477: }
1478:
1479: sub default_change_checker {
1480: my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
1481: foreach my $item (@{$links}) {
1482: if ($confhash->{$role}{$item}) {
1483: $changes->{$role}{'links'}{$item} = 1;
1484: }
1485: }
1486: foreach my $item (@{$bgs}) {
1487: if ($confhash->{$role}{$item}) {
1488: $changes->{$role}{'bgs'}{$item} = 1;
1489: }
1490: }
1491: foreach my $img (@{$images}) {
1492: if ($env{'form.'.$role.'_del_'.$img}) {
1493: $confhash->{$role}{$img} = '';
1.12 raeburn 1494: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 1495: }
1496: }
1497: if ($confhash->{$role}{'font'}) {
1498: $changes->{$role}{'font'} = 1;
1499: }
1500: }
1501:
1502: sub display_colorchgs {
1503: my ($dom,$changes,$roles,$confhash) = @_;
1504: my (%choices,$resulttext);
1.7 albertel 1505: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 1506: if (!grep(/^login$/,@{$roles})) {
1507: $resulttext = &mt('Changes made:').'<br />';
1508: }
1509: foreach my $role (@{$roles}) {
1510: if ($role eq 'login') {
1511: %choices = &login_choices();
1512: } else {
1513: %choices = &color_font_choices();
1514: }
1515: if (ref($changes->{$role}) eq 'HASH') {
1516: if ($role ne 'login') {
1517: $resulttext .= '<h4>'.&mt($role).'</h4>';
1518: }
1519: foreach my $key (sort(keys(%{$changes->{$role}}))) {
1520: if ($role ne 'login') {
1521: $resulttext .= '<ul>';
1522: }
1523: if (ref($changes->{$role}{$key}) eq 'HASH') {
1524: if ($role ne 'login') {
1525: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
1526: }
1527: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1528: if ($confhash->{$role}{$item} eq '') {
1529: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
1530: } else {
1.12 raeburn 1531: my $newitem = $confhash->{$role}{$item};
1532: if ($key eq 'images') {
1533: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
1534: }
1535: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 1536: }
1537: }
1538: if ($role ne 'login') {
1539: $resulttext .= '</ul></li>';
1540: }
1541: } else {
1542: if ($confhash->{$role}{$key} eq '') {
1543: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
1544: } else {
1545: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
1546: }
1547: }
1548: if ($role ne 'login') {
1549: $resulttext .= '</ul>';
1550: }
1551: }
1552: }
1553: }
1.3 raeburn 1554: return $resulttext;
1.1 raeburn 1555: }
1556:
1.9 raeburn 1557: sub thumb_dimensions {
1558: return ('200','50');
1559: }
1560:
1.16 raeburn 1561: sub check_dimensions {
1562: my ($inputfile) = @_;
1563: my ($fullwidth,$fullheight);
1564: if ($inputfile =~ m|^[/\w.\-]+$|) {
1565: if (open(PIPE,"identify $inputfile 2>&1 |")) {
1566: my $imageinfo = <PIPE>;
1567: if (!close(PIPE)) {
1568: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
1569: }
1570: chomp($imageinfo);
1571: my ($fullsize) =
1.21 raeburn 1572: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 1573: if ($fullsize) {
1574: ($fullwidth,$fullheight) = split(/x/,$fullsize);
1575: }
1576: }
1577: }
1578: return ($fullwidth,$fullheight);
1579: }
1580:
1.9 raeburn 1581: sub check_configuser {
1582: my ($uhome,$dom,$confname,$servadm) = @_;
1583: my ($configuserok,%currroles);
1584: if ($uhome eq 'no_host') {
1585: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1586: my $configpass = &LONCAPA::Enrollment::create_password();
1587: $configuserok =
1588: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
1589: $configpass,'','','','','',undef,$servadm);
1590: } else {
1591: $configuserok = 'ok';
1592: %currroles =
1593: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
1594: }
1595: return ($configuserok,%currroles);
1596: }
1597:
1598: sub check_authorstatus {
1599: my ($dom,$confname,%currroles) = @_;
1600: my $author_ok;
1601: if (!$currroles{':'.$dom.':au'}) {
1602: my $start = time;
1603: my $end = 0;
1604: $author_ok =
1605: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1606: 'au',$end,$start);
1607: } else {
1608: $author_ok = 'ok';
1609: }
1610: return $author_ok;
1611: }
1612:
1613: sub publishlogo {
1614: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
1615: my ($output,$fname,$logourl);
1616: if ($action eq 'upload') {
1617: $fname=$env{'form.'.$formname.'.filename'};
1618: chop($env{'form.'.$formname});
1619: } else {
1620: ($fname) = ($formname =~ /([^\/]+)$/);
1621: }
1622: $fname=&Apache::lonnet::clean_filename($fname);
1623: # See if there is anything left
1624: unless ($fname) { return ('error: no uploaded file'); }
1625: $fname="$subdir/$fname";
1626: my $filepath='/home/'.$confname.'/public_html';
1627: my ($fnamepath,$file,$fetchthumb);
1628: $file=$fname;
1629: if ($fname=~m|/|) {
1630: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
1631: }
1632: my @parts=split(/\//,$filepath.'/'.$fnamepath);
1633: my $count;
1634: for ($count=4;$count<=$#parts;$count++) {
1635: $filepath.="/$parts[$count]";
1636: if ((-e $filepath)!=1) {
1637: mkdir($filepath,02770);
1638: }
1639: }
1640: # Check for bad extension and disallow upload
1641: if ($file=~/\.(\w+)$/ &&
1642: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1643: $output =
1644: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
1645: } elsif ($file=~/\.(\w+)$/ &&
1646: !defined(&Apache::loncommon::fileembstyle($1))) {
1647: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
1648: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1649: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1650: } elsif (-d "$filepath/$file") {
1651: $output = &mt('File name is a directory name - rename the file and re-upload');
1652: } else {
1653: my $source = $filepath.'/'.$file;
1654: my $logfile;
1655: if (!open($logfile,">>$source".'.log')) {
1656: return (&mt('No write permission to Construction Space'));
1657: }
1658: print $logfile
1659: "\n================= Publish ".localtime()." ================\n".
1660: $env{'user.name'}.':'.$env{'user.domain'}."\n";
1661: # Save the file
1662: if (!open(FH,'>'.$source)) {
1663: &Apache::lonnet::logthis('Failed to create '.$source);
1664: return (&mt('Failed to create file'));
1665: }
1666: if ($action eq 'upload') {
1667: if (!print FH ($env{'form.'.$formname})) {
1668: &Apache::lonnet::logthis('Failed to write to '.$source);
1669: return (&mt('Failed to write file'));
1670: }
1671: } else {
1672: my $original = &Apache::lonnet::filelocation('',$formname);
1673: if(!copy($original,$source)) {
1674: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
1675: return (&mt('Failed to write file'));
1676: }
1677: }
1678: close(FH);
1679: chmod(0660, $source); # Permissions to rw-rw---.
1680:
1681: my $docroot=$r->dir_config('lonDocRoot');
1682: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
1683: my $copyfile=$targetdir.'/'.$file;
1684:
1685: my @parts=split(/\//,$targetdir);
1686: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
1687: for (my $count=5;$count<=$#parts;$count++) {
1688: $path.="/$parts[$count]";
1689: if (!-e $path) {
1690: print $logfile "\nCreating directory ".$path;
1691: mkdir($path,02770);
1692: }
1693: }
1694: my $versionresult;
1695: if (-e $copyfile) {
1696: $versionresult = &logo_versioning($targetdir,$file,$logfile);
1697: } else {
1698: $versionresult = 'ok';
1699: }
1700: if ($versionresult eq 'ok') {
1701: if (copy($source,$copyfile)) {
1702: print $logfile "\nCopied original source to ".$copyfile."\n";
1703: $output = 'ok';
1704: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
1705: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1706: } else {
1707: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1708: $output = &mt('Failed to copy file to RES space').", $!";
1709: }
1710: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
1711: my $inputfile = $filepath.'/'.$file;
1712: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 1713: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
1714: if ($fullwidth ne '' && $fullheight ne '') {
1715: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
1716: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1717: system("convert -sample $thumbsize $inputfile $outfile");
1718: chmod(0660, $filepath.'/tn-'.$file);
1719: if (-e $outfile) {
1720: my $copyfile=$targetdir.'/tn-'.$file;
1721: if (copy($outfile,$copyfile)) {
1722: print $logfile "\nCopied source to ".$copyfile."\n";
1723: &write_metadata($dom,$confname,$formname,
1724: $targetdir,'tn-'.$file,$logfile);
1725: } else {
1726: print $logfile "\nUnable to write ".$copyfile.
1727: ':'.$!."\n";
1728: }
1729: }
1.9 raeburn 1730: }
1731: }
1732: }
1733: } else {
1734: $output = $versionresult;
1735: }
1736: }
1737: return ($output,$logourl);
1738: }
1739:
1740: sub logo_versioning {
1741: my ($targetdir,$file,$logfile) = @_;
1742: my $target = $targetdir.'/'.$file;
1743: my ($maxversion,$fn,$extn,$output);
1744: $maxversion = 0;
1745: if ($file =~ /^(.+)\.(\w+)$/) {
1746: $fn=$1;
1747: $extn=$2;
1748: }
1749: opendir(DIR,$targetdir);
1750: while (my $filename=readdir(DIR)) {
1751: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
1752: $maxversion=($1>$maxversion)?$1:$maxversion;
1753: }
1754: }
1755: $maxversion++;
1756: print $logfile "\nCreating old version ".$maxversion."\n";
1757: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
1758: if (copy($target,$copyfile)) {
1759: print $logfile "Copied old target to ".$copyfile."\n";
1760: $copyfile=$copyfile.'.meta';
1761: if (copy($target.'.meta',$copyfile)) {
1762: print $logfile "Copied old target metadata to ".$copyfile."\n";
1763: $output = 'ok';
1764: } else {
1765: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1766: $output = &mt('Failed to copy old meta').", $!, ";
1767: }
1768: } else {
1769: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
1770: $output = &mt('Failed to copy old target').", $!, ";
1771: }
1772: return $output;
1773: }
1774:
1775: sub write_metadata {
1776: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
1777: my (%metadatafields,%metadatakeys,$output);
1778: $metadatafields{'title'}=$formname;
1779: $metadatafields{'creationdate'}=time;
1780: $metadatafields{'lastrevisiondate'}=time;
1781: $metadatafields{'copyright'}='public';
1782: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
1783: $env{'user.domain'};
1784: $metadatafields{'authorspace'}=$confname.':'.$dom;
1785: $metadatafields{'domain'}=$dom;
1786: {
1787: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
1788: my $mfh;
1789: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1790: $output = &mt('Could not write metadata');
1791: }
1792: foreach (sort keys %metadatafields) {
1793: unless ($_=~/\./) {
1794: my $unikey=$_;
1795: $unikey=~/^([A-Za-z]+)/;
1796: my $tag=$1;
1797: $tag=~tr/A-Z/a-z/;
1798: print $mfh "\n\<$tag";
1799: foreach (split(/\,/,$metadatakeys{$unikey})) {
1800: my $value=$metadatafields{$unikey.'.'.$_};
1801: $value=~s/\"/\'\'/g;
1802: print $mfh ' '.$_.'="'.$value.'"';
1803: }
1804: print $mfh '>'.
1805: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
1806: .'</'.$tag.'>';
1807: }
1808: }
1809: $output = 'ok';
1810: print $logfile "\nWrote metadata";
1811: close($mfh);
1812: }
1813: }
1814:
1815: sub check_switchserver {
1816: my ($dom,$confname) = @_;
1817: my ($allowed,$switchserver);
1818: my $home = &Apache::lonnet::homeserver($confname,$dom);
1819: if ($home eq 'no_host') {
1820: $home = &Apache::lonnet::domain($dom,'primary');
1821: }
1822: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 1823: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1824: if (!$allowed) {
1825: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 1826: }
1827: return $switchserver;
1828: }
1829:
1.1 raeburn 1830: sub modify_quotas {
1.3 raeburn 1831: my ($dom,%domconfig) = @_;
1.1 raeburn 1832: my ($resulttext,%changes);
1.26 raeburn 1833: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 1834: my %formhash;
1835: foreach my $key (keys(%env)) {
1836: if ($key =~ /^form\.quota_(.+)$/) {
1837: $formhash{$1} = $env{$key};
1838: }
1839: }
1.15 raeburn 1840: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 1841: if (ref($domconfig{'quotas'}) eq 'HASH') {
1842: foreach my $key (keys(%{$domconfig{'quotas'}})) {
1843: if (exists($formhash{$key})) {
1844: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
1845: $changes{$key} = 1;
1846: }
1847: } else {
1848: $formhash{$key} = $domconfig{'quotas'}{$key};
1849: }
1850: }
1851: }
1852: foreach my $key (keys(%formhash)) {
1853: if ($formhash{$key} ne '') {
1.3 raeburn 1854: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 1855: $changes{$key} = 1;
1856: }
1857: }
1858: }
1859: my %quotahash = (
1.3 raeburn 1860: quotas => {%formhash},
1.1 raeburn 1861: );
1862: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
1863: $dom);
1864: if ($putresult eq 'ok') {
1865: if (keys(%changes) > 0) {
1866: $resulttext = &mt('Changes made:').'<ul>';
1.26 raeburn 1867: foreach my $type (@{$types},'default') {
1868: if (defined($changes{$type})) {
1869: my $typetitle = $usertypes->{$type};
1870: if ($type eq 'default') {
1871: $typetitle = $othertitle;
1872: }
1873: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
1874: }
1.1 raeburn 1875: }
1876: $resulttext .= '</ul>';
1877: } else {
1878: $resulttext = &mt('No changes made to default quotas');
1879: }
1880: } else {
1.11 albertel 1881: $resulttext = '<span class="LC_error">'.
1882: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1883: }
1.3 raeburn 1884: return $resulttext;
1.1 raeburn 1885: }
1886:
1.3 raeburn 1887: sub modify_autoenroll {
1888: my ($dom,%domconfig) = @_;
1.1 raeburn 1889: my ($resulttext,%changes);
1890: my %currautoenroll;
1891: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
1892: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
1893: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
1894: }
1895: }
1896: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1897: my %title = ( run => 'Auto-enrollment active',
1898: sender => 'Sender for notification messages');
1899: my @offon = ('off','on');
1.17 raeburn 1900: my $sender_uname = $env{'form.sender_uname'};
1901: my $sender_domain = $env{'form.sender_domain'};
1902: if ($sender_domain eq '') {
1903: $sender_uname = '';
1904: } elsif ($sender_uname eq '') {
1905: $sender_domain = '';
1906: }
1.1 raeburn 1907: my %autoenrollhash = (
1908: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 1909: sender_uname => $sender_uname,
1910: sender_domain => $sender_domain,
1.1 raeburn 1911:
1912: }
1913: );
1.4 raeburn 1914: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
1915: $dom);
1.1 raeburn 1916: if ($putresult eq 'ok') {
1917: if (exists($currautoenroll{'run'})) {
1918: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
1919: $changes{'run'} = 1;
1920: }
1921: } elsif ($autorun) {
1922: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 1923: $changes{'run'} = 1;
1.1 raeburn 1924: }
1925: }
1.17 raeburn 1926: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 1927: $changes{'sender'} = 1;
1928: }
1.17 raeburn 1929: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 1930: $changes{'sender'} = 1;
1931: }
1932: if (keys(%changes) > 0) {
1933: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 1934: if ($changes{'run'}) {
1.1 raeburn 1935: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
1936: }
1937: if ($changes{'sender'}) {
1.17 raeburn 1938: if ($sender_uname eq '' || $sender_domain eq '') {
1939: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
1940: } else {
1941: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
1942: }
1.1 raeburn 1943: }
1944: $resulttext .= '</ul>';
1945: } else {
1946: $resulttext = &mt('No changes made to auto-enrollment settings');
1947: }
1948: } else {
1.11 albertel 1949: $resulttext = '<span class="LC_error">'.
1950: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1951: }
1.3 raeburn 1952: return $resulttext;
1.1 raeburn 1953: }
1954:
1955: sub modify_autoupdate {
1.3 raeburn 1956: my ($dom,%domconfig) = @_;
1.1 raeburn 1957: my ($resulttext,%currautoupdate,%fields,%changes);
1958: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
1959: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
1960: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
1961: }
1962: }
1963: my @offon = ('off','on');
1964: my %title = &Apache::lonlocal::texthash (
1965: run => 'Auto-update:',
1966: classlists => 'Updates to user information in classlists?'
1967: );
1.26 raeburn 1968: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1 raeburn 1969: my %fieldtitles = &Apache::lonlocal::texthash (
1970: id => 'Student/Employee ID',
1.20 raeburn 1971: permanentemail => 'E-mail address',
1.1 raeburn 1972: lastname => 'Last Name',
1973: firstname => 'First Name',
1974: middlename => 'Middle Name',
1975: gen => 'Generation',
1976: );
1977: my $othertitle = &mt('All users');
1978: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 1979: $othertitle = &mt('Other users');
1.1 raeburn 1980: }
1981: foreach my $key (keys(%env)) {
1982: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1983: push(@{$fields{$1}},$2);
1984: }
1985: }
1986: my %updatehash = (
1987: autoupdate => { run => $env{'form.autoupdate_run'},
1988: classlists => $env{'form.classlists'},
1989: fields => {%fields},
1990: }
1991: );
1992: foreach my $key (keys(%currautoupdate)) {
1993: if (($key eq 'run') || ($key eq 'classlists')) {
1994: if (exists($updatehash{autoupdate}{$key})) {
1995: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
1996: $changes{$key} = 1;
1997: }
1998: }
1999: } elsif ($key eq 'fields') {
2000: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 2001: foreach my $item (@{$types},'default') {
1.1 raeburn 2002: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
2003: my $change = 0;
2004: foreach my $type (@{$currautoupdate{$key}{$item}}) {
2005: if (!exists($fields{$item})) {
2006: $change = 1;
2007: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 2008: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 2009: $change = 1;
2010: }
2011: }
2012: }
2013: if ($change) {
2014: push(@{$changes{$key}},$item);
2015: }
1.26 raeburn 2016: }
1.1 raeburn 2017: }
2018: }
2019: }
2020: }
1.26 raeburn 2021: foreach my $item (@{$types},'default') {
2022: if (defined($fields{$item})) {
2023: if (ref($currautoupdate{'fields'}) eq 'HASH') {
2024: if (!exists($currautoupdate{'fields'}{$item})) {
2025: push(@{$changes{'fields'}},$item);
2026: }
2027: } else {
2028: push(@{$changes{'fields'}},$item);
1.1 raeburn 2029: }
2030: }
2031: }
2032: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
2033: $dom);
2034: if ($putresult eq 'ok') {
2035: if (keys(%changes) > 0) {
2036: $resulttext = &mt('Changes made:').'<ul>';
2037: foreach my $key (sort(keys(%changes))) {
2038: if (ref($changes{$key}) eq 'ARRAY') {
2039: foreach my $item (@{$changes{$key}}) {
2040: my @newvalues;
2041: foreach my $type (@{$fields{$item}}) {
2042: push(@newvalues,$fieldtitles{$type});
2043: }
1.3 raeburn 2044: my $newvaluestr;
2045: if (@newvalues > 0) {
2046: $newvaluestr = join(', ',@newvalues);
2047: } else {
2048: $newvaluestr = &mt('none');
1.6 raeburn 2049: }
1.1 raeburn 2050: if ($item eq 'default') {
1.26 raeburn 2051: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 2052: } else {
1.26 raeburn 2053: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 2054: }
2055: }
2056: } else {
2057: my $newvalue;
2058: if ($key eq 'run') {
2059: $newvalue = $offon[$env{'form.autoupdate_run'}];
2060: } else {
2061: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 2062: }
1.1 raeburn 2063: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
2064: }
2065: }
2066: $resulttext .= '</ul>';
2067: } else {
1.3 raeburn 2068: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 2069: }
2070: } else {
1.11 albertel 2071: $resulttext = '<span class="LC_error">'.
2072: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2073: }
1.3 raeburn 2074: return $resulttext;
1.1 raeburn 2075: }
2076:
1.23 raeburn 2077: sub modify_directorysrch {
2078: my ($dom,%domconfig) = @_;
2079: my ($resulttext,%changes);
2080: my %currdirsrch;
2081: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2082: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
2083: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
2084: }
2085: }
2086: my %title = ( available => 'Directory search available',
1.24 raeburn 2087: localonly => 'Other domains can search',
1.23 raeburn 2088: searchby => 'Search types',
2089: searchtypes => 'Search latitude');
2090: my @offon = ('off','on');
1.24 raeburn 2091: my @otherdoms = ('Yes','No');
1.23 raeburn 2092:
1.25 raeburn 2093: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 2094: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
2095: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
2096:
1.26 raeburn 2097: my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
2098: if (keys(%{$usertypes}) == 0) {
2099: @cansearch = ('default');
2100: } else {
2101: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
2102: foreach my $type (@{$currdirsrch{'cansearch'}}) {
2103: if (!grep(/^\Q$type\E$/,@cansearch)) {
2104: push(@{$changes{'cansearch'}},$type);
2105: }
1.23 raeburn 2106: }
1.26 raeburn 2107: foreach my $type (@cansearch) {
2108: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
2109: push(@{$changes{'cansearch'}},$type);
2110: }
1.23 raeburn 2111: }
1.26 raeburn 2112: } else {
2113: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 2114: }
2115: }
2116:
2117: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
2118: foreach my $by (@{$currdirsrch{'searchby'}}) {
2119: if (!grep(/^\Q$by\E$/,@searchby)) {
2120: push(@{$changes{'searchby'}},$by);
2121: }
2122: }
2123: foreach my $by (@searchby) {
2124: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
2125: push(@{$changes{'searchby'}},$by);
2126: }
2127: }
2128: } else {
2129: push(@{$changes{'searchby'}},@searchby);
2130: }
1.25 raeburn 2131:
2132: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
2133: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
2134: if (!grep(/^\Q$type\E$/,@searchtypes)) {
2135: push(@{$changes{'searchtypes'}},$type);
2136: }
2137: }
2138: foreach my $type (@searchtypes) {
2139: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
2140: push(@{$changes{'searchtypes'}},$type);
2141: }
2142: }
2143: } else {
2144: if (exists($currdirsrch{'searchtypes'})) {
2145: foreach my $type (@searchtypes) {
2146: if ($type ne $currdirsrch{'searchtypes'}) {
2147: push(@{$changes{'searchtypes'}},$type);
2148: }
2149: }
2150: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
2151: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
2152: }
2153: } else {
2154: push(@{$changes{'searchtypes'}},@searchtypes);
2155: }
2156: }
2157:
1.23 raeburn 2158: my %dirsrch_hash = (
2159: directorysrch => { available => $env{'form.dirsrch_available'},
2160: cansearch => \@cansearch,
1.24 raeburn 2161: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 2162: searchby => \@searchby,
1.25 raeburn 2163: searchtypes => \@searchtypes,
1.23 raeburn 2164: }
2165: );
2166: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
2167: $dom);
2168: if ($putresult eq 'ok') {
2169: if (exists($currdirsrch{'available'})) {
2170: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
2171: $changes{'available'} = 1;
2172: }
2173: } else {
2174: if ($env{'form.dirsrch_available'} eq '1') {
2175: $changes{'available'} = 1;
2176: }
2177: }
1.24 raeburn 2178: if (exists($currdirsrch{'localonly'})) {
2179: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
2180: $changes{'localonly'} = 1;
2181: }
2182: } else {
2183: if ($env{'form.dirsrch_localonly'} eq '1') {
2184: $changes{'localonly'} = 1;
2185: }
2186: }
1.23 raeburn 2187: if (keys(%changes) > 0) {
2188: $resulttext = &mt('Changes made:').'<ul>';
2189: if ($changes{'available'}) {
2190: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
2191: }
1.24 raeburn 2192: if ($changes{'localonly'}) {
2193: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
2194: }
2195:
1.23 raeburn 2196: if (ref($changes{'cansearch'}) eq 'ARRAY') {
2197: my $chgtext;
1.26 raeburn 2198: if (ref($usertypes) eq 'HASH') {
2199: if (keys(%{$usertypes}) > 0) {
2200: foreach my $type (@{$types}) {
2201: if (grep(/^\Q$type\E$/,@cansearch)) {
2202: $chgtext .= $usertypes->{$type}.'; ';
2203: }
2204: }
2205: if (grep(/^default$/,@cansearch)) {
2206: $chgtext .= $othertitle;
2207: } else {
2208: $chgtext =~ s/\; $//;
2209: }
2210: $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 2211: }
2212: }
2213: }
2214: if (ref($changes{'searchby'}) eq 'ARRAY') {
2215: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2216: my $chgtext;
2217: foreach my $type (@{$titleorder}) {
2218: if (grep(/^\Q$type\E$/,@searchby)) {
2219: if (defined($searchtitles->{$type})) {
2220: $chgtext .= $searchtitles->{$type}.'; ';
2221: }
2222: }
2223: }
2224: $chgtext =~ s/\; $//;
2225: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
2226: }
1.25 raeburn 2227: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
2228: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
2229: my $chgtext;
2230: foreach my $type (@{$srchtypeorder}) {
2231: if (grep(/^\Q$type\E$/,@searchtypes)) {
2232: if (defined($srchtypes_desc->{$type})) {
2233: $chgtext .= $srchtypes_desc->{$type}.'; ';
2234: }
2235: }
2236: }
2237: $chgtext =~ s/\; $//;
2238: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 2239: }
2240: $resulttext .= '</ul>';
2241: } else {
2242: $resulttext = &mt('No changes made to institution directory search settings');
2243: }
2244: } else {
2245: $resulttext = '<span class="LC_error">'.
1.27 ! raeburn 2246: &mt('An error occurred: [_1]',$putresult).'</span>';
! 2247: }
! 2248: return $resulttext;
! 2249: }
! 2250:
! 2251: sub modify_user_creation {
! 2252: my ($dom,%domconfig) = @_;
! 2253: my ($resulttext,%curr_usercreation,%changes);
! 2254: if (ref($domconfig{'usercreation'}) eq 'HASH') {
! 2255: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
! 2256: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
! 2257: }
! 2258: }
! 2259: my %title = &Apache::lonlocal::texthash (
! 2260: author => 'adding co-authors/assistant authors',
! 2261: course => 'adding users to a course',
! 2262: );
! 2263: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
! 2264: my @cancreate = &Apache::loncommon::get_env_multiple('form.can_createuser');
! 2265: if (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
! 2266: foreach my $type (@{$curr_usercreation{'cancreate'}}) {
! 2267: if (!grep(/^\Q$type\E$/,@cancreate)) {
! 2268: push(@{$changes{'cancreate'}},$type);
! 2269: }
! 2270: }
! 2271: foreach my $type (@cancreate) {
! 2272: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) {
! 2273: push(@{$changes{'cancreate'}},$type);
! 2274: }
! 2275: }
! 2276: } else {
! 2277: push(@{$changes{'cancreate'}},@cancreate);
! 2278: }
! 2279: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
! 2280: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
! 2281: if (!grep(/^\Q$type\E$/,@username_rule)) {
! 2282: push(@{$changes{'username_rule'}},$type);
! 2283: }
! 2284: }
! 2285: foreach my $type (@username_rule) {
! 2286: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
! 2287: push(@{$changes{'username_rule'}},$type);
! 2288: }
! 2289: }
! 2290: } else {
! 2291: push(@{$changes{'username_rule'}},@username_rule);
! 2292: }
! 2293:
! 2294: my %usercreation_hash = (
! 2295: usercreation => {
! 2296: cancreate => \@cancreate,
! 2297: username_rule => \@username_rule,
! 2298: }
! 2299: );
! 2300:
! 2301: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
! 2302: $dom);
! 2303: if ($putresult eq 'ok') {
! 2304: if (keys(%changes) > 0) {
! 2305: $resulttext = &mt('Changes made:').'<ul>';
! 2306: my $chgtext;
! 2307: if (ref($changes{'cancreate'}) eq 'ARRAY') {
! 2308: my $chgtext = '<ul>';
! 2309: foreach my $type (@cancreate) {
! 2310: $chgtext .= '<li>'.$title{$type}.'</li>';
! 2311: }
! 2312: $chgtext .= '</ul>';
! 2313: if (@cancreate > 0) {
! 2314: $resulttext .= '<li>'.&mt('Creation of new users is permitted by a Domain Coordinator, and also by other users when: ').$chgtext.'</li>';
! 2315: } else {
! 2316: $resulttext .= '<li>'.&mt("Creation of new users is now only allowed when the user's role is Domain Coordinator.").'</li>';
! 2317: }
! 2318: }
! 2319: if (ref($changes{'username_rule'}) eq 'ARRAY') {
! 2320: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom);
! 2321: my $chgtext = '<ul>';
! 2322: foreach my $type (@username_rule) {
! 2323: if (ref($rules->{$type}) eq 'HASH') {
! 2324: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
! 2325: }
! 2326: }
! 2327: $chgtext .= '</ul>';
! 2328: if (@username_rule > 0) {
! 2329: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
! 2330: } else {
! 2331: $resulttext .= '<li>'.&mt('There are now no username formats currenty restricted to verified users in the institutional directory.').'</li>';
! 2332: }
! 2333: }
! 2334: $resulttext .= '</ul>';
! 2335: } else {
! 2336: $resulttext = &mt('No changes made to log-in page settings');
! 2337: }
! 2338: } else {
! 2339: $resulttext = '<span class="LC_error">'.
1.23 raeburn 2340: &mt('An error occurred: [_1]',$putresult).'</span>';
2341: }
2342: return $resulttext;
2343: }
2344:
1.3 raeburn 2345: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>