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