Annotation of loncom/interface/domainprefs.pm, revision 1.103
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.103 ! raeburn 4: # $Id: domainprefs.pm,v 1.102 2009/08/11 23:24:29 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:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
48: for use by individuals affliated with the institution. Accordingly, each domain
49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
89: number of rows displayed on the page, and $action is the context (either quotas
90: or requestcourses).
91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
97: used by course owners to request creation of a course.
98:
99: Outputs: 1
100:
101: $datatable - HTML containing form elements which allow settings to be changed.
102:
103: In the case of course requests, radio buttons are displayed for each institutional
104: affiliate type (and also default, and _LC_adv) for each of the course types
105: (official, unofficial and community). In each case the radio buttons allow the
106: selection of one of four values:
107:
108: 0, approve, validate, autolimit=N (where N is blank, or a positive integer).
109: which have the following effects:
110:
111: 0
112:
113: =over
114:
115: - course requests are not allowed for this course types/affiliation
116:
117: =back
118:
119: approve
120:
121: =over
122:
123: - course requests must be approved by a Doman Coordinator in the
124: course's domain
125:
126: =back
127:
128: validate
129:
130: =over
131:
132: - an institutional validation (e.g., check requestor is instructor
133: of record) needs to be passed before the course will be created. The required
134: validation is in localenroll.pm on the primary library server for the course
135: domain.
136:
137: =back
138:
139: autolimit
140:
141: =over
142:
143: - course requests will be processed autoatically up to a limit of
144: N requests for the course type for the particular requestor.
145: If N is undefined, there is no limit to the number of course requests
146: which a course owner may submit and have processed automatically.
147:
148: =back
149:
150: =item modify_quotas()
151:
152: =back
153:
154: =cut
155:
1.1 raeburn 156: package Apache::domainprefs;
157:
158: use strict;
159: use Apache::Constants qw(:common :http);
160: use Apache::lonnet;
161: use Apache::loncommon();
162: use Apache::lonhtmlcommon();
163: use Apache::lonlocal;
1.43 raeburn 164: use Apache::lonmsg();
1.91 raeburn 165: use Apache::lonconfigsettings;
1.69 raeburn 166: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 167: use LONCAPA::Enrollment;
1.81 raeburn 168: use LONCAPA::lonauthcgi();
1.9 raeburn 169: use File::Copy;
1.43 raeburn 170: use Locale::Language;
1.62 raeburn 171: use DateTime::TimeZone;
1.68 raeburn 172: use DateTime::Locale;
1.1 raeburn 173:
174: sub handler {
175: my $r=shift;
176: if ($r->header_only) {
177: &Apache::loncommon::content_type($r,'text/html');
178: $r->send_http_header;
179: return OK;
180: }
181:
1.91 raeburn 182: my $context = 'domain';
1.1 raeburn 183: my $dom = $env{'request.role.domain'};
1.5 albertel 184: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 185: if (&Apache::lonnet::allowed('mau',$dom)) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: } else {
189: $env{'user.error.msg'}=
190: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
191: return HTTP_NOT_ACCEPTABLE;
192: }
193: &Apache::lonhtmlcommon::clear_breadcrumbs();
194: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 195: ['phase','actions']);
1.30 raeburn 196: my $phase = 'pickactions';
1.3 raeburn 197: if ( exists($env{'form.phase'}) ) {
198: $phase = $env{'form.phase'};
199: }
200: my %domconfig =
1.6 raeburn 201: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.27 raeburn 202: 'quotas','autoenroll','autoupdate','directorysrch',
1.48 raeburn 203: 'usercreation','usermodification','contacts','defaults',
1.86 raeburn 204: 'scantron','coursecategories','serverstatuses',
205: 'requestcourses'],$dom);
1.43 raeburn 206: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.30 raeburn 207: 'autoupdate','directorysrch','contacts',
1.48 raeburn 208: 'usercreation','usermodification','scantron',
1.86 raeburn 209: 'requestcourses','coursecategories','serverstatuses');
1.30 raeburn 210: my %prefs = (
211: 'rolecolors' =>
212: { text => 'Default color schemes',
1.67 raeburn 213: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 214: header => [{col1 => 'Student Settings',
215: col2 => '',},
216: {col1 => 'Coordinator Settings',
217: col2 => '',},
218: {col1 => 'Author Settings',
219: col2 => '',},
220: {col1 => 'Administrator Settings',
221: col2 => '',}],
222: },
223: 'login' =>
224: { text => 'Log-in page options',
1.67 raeburn 225: help => 'Domain_Configuration_Login_Page',
1.30 raeburn 226: header => [{col1 => 'Item',
227: col2 => '',}],
228: },
1.43 raeburn 229: 'defaults' =>
1.54 raeburn 230: { text => 'Default authentication/language/timezone',
1.67 raeburn 231: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 232: header => [{col1 => 'Setting',
233: col2 => 'Value'}],
234: },
1.30 raeburn 235: 'quotas' =>
1.90 weissno 236: { text => 'User blogs, personal information pages and portfolios',
1.67 raeburn 237: help => 'Domain_Configuration_Quotas',
1.77 raeburn 238: header => [{col1 => 'User affiliation',
1.72 raeburn 239: col2 => 'Available tools',
240: col3 => 'Portfolio quota',}],
1.30 raeburn 241: },
242: 'autoenroll' =>
243: { text => 'Auto-enrollment settings',
1.67 raeburn 244: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 245: header => [{col1 => 'Configuration setting',
246: col2 => 'Value(s)'}],
247: },
248: 'autoupdate' =>
249: { text => 'Auto-update settings',
1.67 raeburn 250: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 251: header => [{col1 => 'Setting',
252: col2 => 'Value',},
1.43 raeburn 253: {col1 => 'User population',
1.30 raeburn 254: col2 => 'Updataeable user data'}],
255: },
256: 'directorysrch' =>
257: { text => 'Institutional directory searches',
1.67 raeburn 258: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 259: header => [{col1 => 'Setting',
260: col2 => 'Value',}],
261: },
262: 'contacts' =>
263: { text => 'Contact Information',
1.67 raeburn 264: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 265: header => [{col1 => 'Setting',
266: col2 => 'Value',}],
267: },
268:
269: 'usercreation' =>
270: { text => 'User creation',
1.67 raeburn 271: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 272: header => [{col1 => 'Format rule type',
273: col2 => 'Format rules in force'},
1.34 raeburn 274: {col1 => 'User account creation',
275: col2 => 'Usernames which may be created',},
1.30 raeburn 276: {col1 => 'Context',
1.43 raeburn 277: col2 => 'Assignable authentication types'}],
1.30 raeburn 278: },
1.69 raeburn 279: 'usermodification' =>
1.33 raeburn 280: { text => 'User modification',
1.67 raeburn 281: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 282: header => [{col1 => 'Target user has role',
283: col2 => 'User information updateable in author context'},
284: {col1 => 'Target user has role',
1.63 raeburn 285: col2 => 'User information updateable in course context'},
286: {col1 => "Status of user",
287: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 288: },
1.69 raeburn 289: 'scantron' =>
1.95 www 290: { text => 'Bubblesheet format file',
1.67 raeburn 291: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 292: header => [ {col1 => 'Item',
293: col2 => '',
294: }],
295: },
1.86 raeburn 296: 'requestcourses' =>
297: {text => 'Request creation of courses',
298: help => 'Domain_Configuration_Request_Courses',
299: header => [{col1 => 'User affiliation',
1.102 raeburn 300: col2 => 'Availability/Processing of requests',},
301: {col1 => 'Setting',
302: col2 => 'Value'}],
1.86 raeburn 303: },
1.69 raeburn 304: 'coursecategories' =>
1.48 raeburn 305: { text => 'Cataloging of courses',
1.67 raeburn 306: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 307: header => [{col1 => 'Category settings',
1.57 raeburn 308: col2 => '',},
309: {col1 => 'Categories',
310: col2 => '',
311: }],
1.69 raeburn 312: },
313: 'serverstatuses' =>
1.77 raeburn 314: {text => 'Access to server status pages',
1.69 raeburn 315: help => 'Domain_Configuration_Server_Status',
316: header => [{col1 => 'Status Page',
317: col2 => 'Other named users',
318: col3 => 'Specific IPs',
319: }],
320: },
1.3 raeburn 321: );
1.6 raeburn 322: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 323: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 324: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 325: ({href=>"javascript:changePage(document.$phase,'pickactions')",
326: text=>"Pick functionality"});
1.9 raeburn 327: my $confname = $dom.'-domainconfig';
1.3 raeburn 328: if ($phase eq 'process') {
1.91 raeburn 329: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 330: } elsif ($phase eq 'display') {
1.91 raeburn 331: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname);
1.1 raeburn 332: } else {
1.21 raeburn 333: if (keys(%domconfig) == 0) {
334: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 335: my @ids=&Apache::lonnet::current_machine_ids();
336: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 337: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 338: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 339: my $custom_img_count = 0;
340: foreach my $img (@loginimages) {
341: if ($designhash{$dom.'.login.'.$img} ne '') {
342: $custom_img_count ++;
343: }
344: }
345: foreach my $role (@roles) {
346: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
347: $custom_img_count ++;
348: }
349: }
350: if ($custom_img_count > 0) {
1.94 raeburn 351: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 352: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 353: $r->print(
354: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
355: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
356: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
357: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
358: if ($switch_server) {
1.30 raeburn 359: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 360: }
1.91 raeburn 361: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 362: return OK;
363: }
364: }
365: }
1.91 raeburn 366: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 367: }
368: return OK;
369: }
370:
371: sub process_changes {
1.92 raeburn 372: my ($r,$dom,$confname,$action,$roles,$values) = @_;
373: my %domconfig;
374: if (ref($values) eq 'HASH') {
375: %domconfig = %{$values};
376: }
1.3 raeburn 377: my $output;
378: if ($action eq 'login') {
1.9 raeburn 379: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 380: } elsif ($action eq 'rolecolors') {
1.9 raeburn 381: $output = &modify_rolecolors($r,$dom,$confname,$roles,
382: %domconfig);
1.3 raeburn 383: } elsif ($action eq 'quotas') {
1.86 raeburn 384: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 385: } elsif ($action eq 'autoenroll') {
386: $output = &modify_autoenroll($dom,%domconfig);
387: } elsif ($action eq 'autoupdate') {
388: $output = &modify_autoupdate($dom,%domconfig);
1.23 raeburn 389: } elsif ($action eq 'directorysrch') {
390: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 391: } elsif ($action eq 'usercreation') {
1.28 raeburn 392: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 393: } elsif ($action eq 'usermodification') {
394: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 395: } elsif ($action eq 'contacts') {
396: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 397: } elsif ($action eq 'defaults') {
398: $output = &modify_defaults($dom,$r);
1.46 raeburn 399: } elsif ($action eq 'scantron') {
1.48 raeburn 400: $output = &modify_scantron($r,$dom,$confname,%domconfig);
401: } elsif ($action eq 'coursecategories') {
402: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 403: } elsif ($action eq 'serverstatuses') {
404: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 405: } elsif ($action eq 'requestcourses') {
406: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 407: }
408: return $output;
409: }
410:
411: sub print_config_box {
1.9 raeburn 412: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 413: my $rowtotal = 0;
1.49 raeburn 414: my $output;
415: if ($action eq 'coursecategories') {
416: $output = &coursecategories_javascript($settings);
1.91 raeburn 417: }
1.49 raeburn 418: $output .=
1.30 raeburn 419: '<table class="LC_nested_outer">
1.3 raeburn 420: <tr>
1.66 raeburn 421: <th align="left" valign="middle"><span class="LC_nobreak">'.
422: &mt($item->{text}).' '.
423: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
424: '</tr>';
1.30 raeburn 425: $rowtotal ++;
1.28 raeburn 426: if (($action eq 'autoupdate') || ($action eq 'rolecolors') ||
1.57 raeburn 427: ($action eq 'usercreation') || ($action eq 'usermodification') ||
1.102 raeburn 428: ($action eq 'coursecategories') || ($action eq 'requestcourses')) {
1.64 raeburn 429: my $colspan = '';
430: if (($action eq 'rolecolors') || ($action eq 'coursecategories')) {
431: $colspan = ' colspan="2"';
432: }
1.30 raeburn 433: $output .= '
1.3 raeburn 434: <tr>
435: <td>
436: <table class="LC_nested">
437: <tr class="LC_info_row">
1.59 bisitz 438: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
439: <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 440: </tr>';
1.69 raeburn 441: $rowtotal ++;
1.6 raeburn 442: if ($action eq 'autoupdate') {
1.30 raeburn 443: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 444: } elsif ($action eq 'usercreation') {
1.33 raeburn 445: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
446: } elsif ($action eq 'usermodification') {
447: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 448: } elsif ($action eq 'coursecategories') {
449: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.102 raeburn 450: } elsif ($action eq 'requestcourses') {
451: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.6 raeburn 452: } else {
1.30 raeburn 453: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 454: }
1.30 raeburn 455: $output .= '
1.6 raeburn 456: </table>
457: </td>
458: </tr>
459: <tr>
460: <td>
461: <table class="LC_nested">
462: <tr class="LC_info_row">
1.59 bisitz 463: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 464: $output .= '
1.59 bisitz 465: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 466: </tr>';
467: $rowtotal ++;
1.6 raeburn 468: if ($action eq 'autoupdate') {
1.30 raeburn 469: $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
1.28 raeburn 470: } elsif ($action eq 'usercreation') {
1.34 raeburn 471: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
472: </table>
473: </td>
474: </tr>
475: <tr>
476: <td>
477: <table class="LC_nested">
478: <tr class="LC_info_row">
1.59 bisitz 479: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
480: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 481: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
482: $rowtotal ++;
1.33 raeburn 483: } elsif ($action eq 'usermodification') {
1.63 raeburn 484: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
485: </table>
486: </td>
487: </tr>
488: <tr>
489: <td>
490: <table class="LC_nested">
491: <tr class="LC_info_row">
492: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
493: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
494:
495: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
496: $rowtotal ++;
1.57 raeburn 497: } elsif ($action eq 'coursecategories') {
498: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.102 raeburn 499: } elsif ($action eq 'requestcourses') {
500: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.6 raeburn 501: } else {
1.30 raeburn 502: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 503: </table>
504: </td>
505: </tr>
506: <tr>
507: <td>
508: <table class="LC_nested">
509: <tr class="LC_info_row">
1.69 raeburn 510: <td class="LC_left_item"'.$colspan.' valign="top">'.
511: &mt($item->{'header'}->[2]->{'col1'}).'</td>
512: <td class="LC_right_item" valign="top">'.
513: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 514: </tr>'.
1.30 raeburn 515: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 516: </table>
517: </td>
518: </tr>
519: <tr>
520: <td>
521: <table class="LC_nested">
522: <tr class="LC_info_row">
1.59 bisitz 523: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
524: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 525: </tr>'.
1.30 raeburn 526: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
527: $rowtotal += 2;
1.6 raeburn 528: }
1.3 raeburn 529: } else {
1.30 raeburn 530: $output .= '
1.3 raeburn 531: <tr>
532: <td>
533: <table class="LC_nested">
1.30 raeburn 534: <tr class="LC_info_row">';
1.24 raeburn 535: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 536: $output .= '
1.59 bisitz 537: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 538: } elsif ($action eq 'serverstatuses') {
539: $output .= '
540: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
541: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
542:
1.6 raeburn 543: } else {
1.30 raeburn 544: $output .= '
1.69 raeburn 545: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
546: }
1.72 raeburn 547: if (defined($item->{'header'}->[0]->{'col3'})) {
548: $output .= '<td class="LC_left_item" valign="top">'.
549: &mt($item->{'header'}->[0]->{'col2'});
550: if ($action eq 'serverstatuses') {
551: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
552: }
1.69 raeburn 553: } else {
554: $output .= '<td class="LC_right_item" valign="top">'.
555: &mt($item->{'header'}->[0]->{'col2'});
556: }
557: $output .= '</td>';
558: if ($item->{'header'}->[0]->{'col3'}) {
559: $output .= '<td class="LC_right_item" valign="top">'.
560: &mt($item->{'header'}->[0]->{'col3'});
561: if ($action eq 'serverstatuses') {
562: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
563: }
564: $output .= '</td>';
1.6 raeburn 565: }
1.69 raeburn 566: $output .= '</tr>';
1.48 raeburn 567: $rowtotal ++;
1.3 raeburn 568: if ($action eq 'login') {
1.30 raeburn 569: $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
1.3 raeburn 570: } elsif ($action eq 'quotas') {
1.86 raeburn 571: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 572: } elsif ($action eq 'autoenroll') {
1.30 raeburn 573: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.23 raeburn 574: } elsif ($action eq 'directorysrch') {
1.30 raeburn 575: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 576: } elsif ($action eq 'contacts') {
1.30 raeburn 577: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 578: } elsif ($action eq 'defaults') {
579: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 580: } elsif ($action eq 'scantron') {
581: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 582: } elsif ($action eq 'serverstatuses') {
583: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.27 raeburn 584: }
1.3 raeburn 585: }
1.30 raeburn 586: $output .= '
1.3 raeburn 587: </table>
588: </td>
589: </tr>
1.30 raeburn 590: </table><br />';
591: return ($output,$rowtotal);
1.1 raeburn 592: }
593:
1.3 raeburn 594: sub print_login {
1.30 raeburn 595: my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
1.6 raeburn 596: my %choices = &login_choices();
1.42 raeburn 597: my %defaultchecked = (
1.43 raeburn 598: 'coursecatalog' => 'on',
599: 'adminmail' => 'off',
600: 'newuser' => 'off',
601: );
602: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 603: my (%checkedon,%checkedoff);
604: foreach my $item (@toggles) {
605: if ($defaultchecked{$item} eq 'on') {
606: $checkedon{$item} = ' checked="checked" ';
607: $checkedoff{$item} = ' ';
608: } elsif ($defaultchecked{$item} eq 'off') {
609: $checkedoff{$item} = ' checked="checked" ';
610: $checkedon{$item} = ' ';
611: }
612: }
613: my $loginheader = 'image';
1.41 raeburn 614: my @images = ('img','logo','domlogo','login');
615: my @logintext = ('textcol','bgcol');
1.6 raeburn 616: my @bgs = ('pgbg','mainbg','sidebg');
617: my @links = ('link','alink','vlink');
1.7 albertel 618: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 619: my %defaultdesign = %Apache::loncommon::defaultdesign;
620: my (%is_custom,%designs);
621: my %defaults = (
622: font => $defaultdesign{'login.font'},
623: );
624: foreach my $item (@images) {
625: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 626: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 627: }
628: foreach my $item (@bgs) {
629: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
630: }
1.41 raeburn 631: foreach my $item (@logintext) {
632: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
633: }
1.6 raeburn 634: foreach my $item (@links) {
635: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
636: }
1.3 raeburn 637: if (ref($settings) eq 'HASH') {
1.42 raeburn 638: foreach my $item (@toggles) {
639: if ($settings->{$item} eq '1') {
640: $checkedon{$item} = ' checked="checked" ';
641: $checkedoff{$item} = ' ';
642: } elsif ($settings->{$item} eq '0') {
643: $checkedoff{$item} = ' checked="checked" ';
644: $checkedon{$item} = ' ';
645: }
1.1 raeburn 646: }
1.6 raeburn 647: foreach my $item (@images) {
1.70 raeburn 648: if (defined($settings->{$item})) {
1.6 raeburn 649: $designs{$item} = $settings->{$item};
650: $is_custom{$item} = 1;
651: }
1.70 raeburn 652: if (defined($settings->{'showlogo'}{$item})) {
653: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
654: }
1.6 raeburn 655: }
1.41 raeburn 656: foreach my $item (@logintext) {
657: if ($settings->{$item} ne '') {
658: $designs{'logintext'}{$item} = $settings->{$item};
659: $is_custom{$item} = 1;
660: }
661: }
662: if ($settings->{'loginheader'} ne '') {
663: $loginheader = $settings->{'loginheader'};
664: }
1.6 raeburn 665: if ($settings->{'font'} ne '') {
666: $designs{'font'} = $settings->{'font'};
667: $is_custom{'font'} = 1;
668: }
669: foreach my $item (@bgs) {
670: if ($settings->{$item} ne '') {
671: $designs{'bgs'}{$item} = $settings->{$item};
672: $is_custom{$item} = 1;
673: }
674: }
675: foreach my $item (@links) {
676: if ($settings->{$item} ne '') {
677: $designs{'links'}{$item} = $settings->{$item};
678: $is_custom{$item} = 1;
679: }
680: }
681: } else {
682: if ($designhash{$dom.'.login.font'} ne '') {
683: $designs{'font'} = $designhash{$dom.'.login.font'};
684: $is_custom{'font'} = 1;
685: }
1.8 raeburn 686: foreach my $item (@images) {
687: if ($designhash{$dom.'.login.'.$item} ne '') {
688: $designs{$item} = $designhash{$dom.'.login.'.$item};
689: $is_custom{$item} = 1;
690: }
691: }
1.6 raeburn 692: foreach my $item (@bgs) {
693: if ($designhash{$dom.'.login.'.$item} ne '') {
694: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
695: $is_custom{$item} = 1;
696: }
697: }
698: foreach my $item (@links) {
699: if ($designhash{$dom.'.login.'.$item} ne '') {
700: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
701: $is_custom{$item} = 1;
702: }
703: }
1.1 raeburn 704: }
1.6 raeburn 705: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
706: logo => 'Institution Logo',
1.41 raeburn 707: domlogo => 'Domain Logo',
708: login => 'Login box');
1.6 raeburn 709: my $itemcount = 1;
1.42 raeburn 710: my ($css_class,$datatable);
711: foreach my $item (@toggles) {
712: $css_class = $itemcount%2?' class="LC_odd_row"':'';
713: $datatable .=
714: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
715: '</td><td>'.
716: '<span class="LC_nobreak"><label><input type="radio" name="'.
717: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
718: '</label> <label><input type="radio" name="'.$item.'"'.
719: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
720: '</tr>';
721: $itemcount ++;
722: }
1.41 raeburn 723: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader);
1.6 raeburn 724: $datatable .= '</tr></table></td></tr>';
725: return $datatable;
726: }
727:
728: sub login_choices {
729: my %choices =
730: &Apache::lonlocal::texthash (
731: coursecatalog => 'Display Course Catalog link?',
732: adminmail => "Display Administrator's E-mail Address?",
1.43 raeburn 733: newuser => "Link to create a user account",
1.6 raeburn 734: img => "Header",
735: logo => "Main Logo",
736: domlogo => "Domain Logo",
1.41 raeburn 737: login => "Log-in Header",
738: textcol => "Text color",
739: bgcol => "Box color",
1.6 raeburn 740: bgs => "Background colors",
741: links => "Link colors",
742: font => "Font color",
1.71 muellerd 743: pgbg => "Header",
744: mainbg => "Page",
1.74 muellerd 745: sidebg => "Login box",
1.6 raeburn 746: link => "Link",
747: alink => "Active link",
748: vlink => "Visited link",
749: );
750: return %choices;
751: }
752:
753: sub print_rolecolors {
1.30 raeburn 754: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 755: my %choices = &color_font_choices();
756: my @bgs = ('pgbg','tabbg','sidebg');
757: my @links = ('link','alink','vlink');
758: my @images = ('img');
759: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 760: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 761: my %defaultdesign = %Apache::loncommon::defaultdesign;
762: my (%is_custom,%designs);
763: my %defaults = (
764: img => $defaultdesign{$role.'.img'},
765: font => $defaultdesign{$role.'.font'},
1.97 tempelho 766: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 767: );
768: foreach my $item (@bgs) {
769: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
770: }
771: foreach my $item (@links) {
772: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
773: }
774: if (ref($settings) eq 'HASH') {
775: if (ref($settings->{$role}) eq 'HASH') {
776: if ($settings->{$role}->{'img'} ne '') {
777: $designs{'img'} = $settings->{$role}->{'img'};
778: $is_custom{'img'} = 1;
779: }
780: if ($settings->{$role}->{'font'} ne '') {
781: $designs{'font'} = $settings->{$role}->{'font'};
782: $is_custom{'font'} = 1;
783: }
1.97 tempelho 784: if ($settings->{$role}->{'fontmenu'} ne '') {
785: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
786: $is_custom{'fontmenu'} = 1;
787: }
1.6 raeburn 788: foreach my $item (@bgs) {
789: if ($settings->{$role}->{$item} ne '') {
790: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
791: $is_custom{$item} = 1;
792: }
793: }
794: foreach my $item (@links) {
795: if ($settings->{$role}->{$item} ne '') {
796: $designs{'links'}{$item} = $settings->{$role}->{$item};
797: $is_custom{$item} = 1;
798: }
799: }
800: }
801: } else {
802: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
803: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
804: $is_custom{'img'} = 1;
805: }
1.97 tempelho 806: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
807: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
808: $is_custom{'fontmenu'} = 1;
809: }
1.6 raeburn 810: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
811: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
812: $is_custom{'font'} = 1;
813: }
814: foreach my $item (@bgs) {
815: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
816: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
817: $is_custom{$item} = 1;
818:
819: }
820: }
821: foreach my $item (@links) {
822: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
823: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
824: $is_custom{$item} = 1;
825: }
826: }
827: }
828: my $itemcount = 1;
1.30 raeburn 829: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 830: $datatable .= '</tr></table></td></tr>';
831: return $datatable;
832: }
833:
834: sub display_color_options {
1.9 raeburn 835: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.41 raeburn 836: $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_;
1.6 raeburn 837: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.97 tempelho 838: my $datatable = '<tr>'.
1.6 raeburn 839: '<td>'.$choices->{'font'}.'</td>';
840: if (!$is_custom->{'font'}) {
1.30 raeburn 841: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 842: } else {
843: $datatable .= '<td> </td>';
844: }
845: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 846: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 847: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 848: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 849: ' <span id="css_'.$role.'_font" style="background-color: '.
850: $designs->{'font'}.';"> </span>'.
1.8 raeburn 851: '</span></td></tr>';
1.97 tempelho 852: $datatable .= '<tr'.$css_class.'>'.
853: '<td>'.$choices->{'fontmenu'}.'</td>';
854: if (!$is_custom->{'fontmenu'}) {
855: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
856: } else {
857: $datatable .= '<td> </td>';
858: }
859: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
860: $datatable .= '<td><span class="LC_nobreak">'.
861: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
862: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
863: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
864: $designs->{'fontmenu'}.';"> </span>'.
865: '</span></td></tr>';
1.9 raeburn 866: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 867: foreach my $img (@{$images}) {
1.18 albertel 868: $itemcount ++;
1.6 raeburn 869: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 870: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 871: '<td>'.$choices->{$img};
1.41 raeburn 872: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 873: if ($role eq 'login') {
874: if ($img eq 'login') {
875: $login_hdr_pick =
876: &login_header_options($img,$role,$defaults,$is_custom,$choices,
877: $loginheader);
878: $logincolors =
879: &login_text_colors($img,$role,$logintext,$phase,$choices,
880: $designs);
881: } elsif ($img ne 'domlogo') {
882: $datatable.= &logo_display_options($img,$defaults,$designs);
883: }
884: }
885: $datatable .= '</td>';
1.6 raeburn 886: if ($designs->{$img} ne '') {
887: $imgfile = $designs->{$img};
1.18 albertel 888: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 889: } else {
890: $imgfile = $defaults->{$img};
891: }
892: if ($imgfile) {
1.9 raeburn 893: my ($showfile,$fullsize);
894: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 895: my $urldir = $1;
896: my $filename = $2;
897: my @info = &Apache::lonnet::stat_file($designs->{$img});
898: if (@info) {
899: my $thumbfile = 'tn-'.$filename;
900: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
901: if (@thumb) {
902: $showfile = $urldir.'/'.$thumbfile;
903: } else {
904: $showfile = $imgfile;
905: }
906: } else {
907: $showfile = '';
908: }
909: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 910: $showfile = $imgfile;
1.6 raeburn 911: my $imgdir = $1;
912: my $filename = $2;
913: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
914: $showfile = "/$imgdir/tn-".$filename;
915: } else {
916: my $input = "/home/httpd/html".$imgfile;
917: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
918: if (!-e $output) {
1.9 raeburn 919: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 920: my ($fullwidth,$fullheight) = &check_dimensions($input);
921: if ($fullwidth ne '' && $fullheight ne '') {
922: if ($fullwidth > $width && $fullheight > $height) {
923: my $size = $width.'x'.$height;
924: system("convert -sample $size $input $output");
925: $showfile = '/'.$imgdir.'/tn-'.$filename;
926: }
927: }
1.6 raeburn 928: }
929: }
1.16 raeburn 930: }
1.6 raeburn 931: if ($showfile) {
1.40 raeburn 932: if ($showfile =~ m{^/(adm|res)/}) {
933: if ($showfile =~ m{^/res/}) {
934: my $local_showfile =
935: &Apache::lonnet::filelocation('',$showfile);
936: &Apache::lonnet::repcopy($local_showfile);
937: }
938: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
939: }
940: if ($imgfile) {
941: if ($imgfile =~ m{^/(adm|res)/}) {
942: if ($imgfile =~ m{^/res/}) {
943: my $local_imgfile =
944: &Apache::lonnet::filelocation('',$imgfile);
945: &Apache::lonnet::repcopy($local_imgfile);
946: }
947: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
948: } else {
949: $fullsize = $imgfile;
950: }
951: }
1.41 raeburn 952: $datatable .= '<td>';
953: if ($img eq 'login') {
954: $datatable .= $login_hdr_pick;
1.6 raeburn 955: }
1.41 raeburn 956: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
957: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 958: } else {
959: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
960: &mt('Upload:');
961: }
962: } else {
963: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
964: &mt('Upload:');
965: }
1.9 raeburn 966: if ($switchserver) {
967: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
968: } else {
969: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
970: }
971: $datatable .= '</td></tr>';
1.6 raeburn 972: }
973: $itemcount ++;
974: $css_class = $itemcount%2?' class="LC_odd_row"':'';
975: $datatable .= '<tr'.$css_class.'>'.
976: '<td>'.$choices->{'bgs'}.'</td>';
977: my $bgs_def;
978: foreach my $item (@{$bgs}) {
979: if (!$is_custom->{$item}) {
1.70 raeburn 980: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 981: }
982: }
983: if ($bgs_def) {
1.8 raeburn 984: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 985: } else {
986: $datatable .= '<td> </td>';
987: }
988: $datatable .= '<td class="LC_right_item">'.
989: '<table border="0"><tr>';
990: foreach my $item (@{$bgs}) {
991: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
992: $datatable .= '<td align="center">'.$link;
993: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 994: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 995: }
996: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 997: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 998: }
999: $datatable .= '</tr></table></td></tr>';
1000: $itemcount ++;
1001: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1002: $datatable .= '<tr'.$css_class.'>'.
1003: '<td>'.$choices->{'links'}.'</td>';
1004: my $links_def;
1005: foreach my $item (@{$links}) {
1006: if (!$is_custom->{$item}) {
1.30 raeburn 1007: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1008: }
1009: }
1010: if ($links_def) {
1.8 raeburn 1011: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1012: } else {
1013: $datatable .= '<td> </td>';
1014: }
1015: $datatable .= '<td class="LC_right_item">'.
1016: '<table border="0"><tr>';
1017: foreach my $item (@{$links}) {
1.30 raeburn 1018: $datatable .= '<td align="center">'."\n".
1019: &color_pick($phase,$role,$item,$choices->{$item},
1020: $designs->{'links'}{$item});
1.6 raeburn 1021: if ($designs->{'links'}{$item}) {
1.30 raeburn 1022: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1023: }
1024: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1025: '" /></td>';
1026: }
1.30 raeburn 1027: $$rowtotal += $itemcount;
1.3 raeburn 1028: return $datatable;
1029: }
1030:
1.70 raeburn 1031: sub logo_display_options {
1032: my ($img,$defaults,$designs) = @_;
1033: my $checkedon;
1034: if (ref($defaults) eq 'HASH') {
1035: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1036: if ($defaults->{'showlogo'}{$img}) {
1037: $checkedon = 'checked="checked" ';
1038: }
1039: }
1040: }
1041: if (ref($designs) eq 'HASH') {
1042: if (ref($designs->{'showlogo'}) eq 'HASH') {
1043: if (defined($designs->{'showlogo'}{$img})) {
1044: if ($designs->{'showlogo'}{$img} == 0) {
1045: $checkedon = '';
1046: } elsif ($designs->{'showlogo'}{$img} == 1) {
1047: $checkedon = 'checked="checked" ';
1048: }
1049: }
1050: }
1051: }
1052: return '<br /><label> <input type="checkbox" name="'.
1053: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1054: &mt('show').'</label>'."\n";
1055: }
1056:
1.41 raeburn 1057: sub login_header_options {
1058: my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
1059: my $image_checked = ' checked="checked" ';
1060: my $text_checked = ' ';
1061: if ($loginheader eq 'text') {
1062: $image_checked = ' ';
1063: $text_checked = ' checked="checked" ';
1064: }
1065: my $output = '<span class="LC_nobreak"><label><input type="radio" name="'.
1066: 'loginheader" value="image" '.$image_checked.'/>'.
1067: &mt('use image').'</label> '.
1068: '<label><input type="radio" name="loginheader" value="text"'.
1069: $text_checked.'/>'.&mt('use text').'</label><br />'."\n";
1070: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1071: $output .= &mt('Text default(s)').':<br />';
1072: if (!$is_custom->{'textcol'}) {
1073: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1074: ' ';
1075: }
1076: if (!$is_custom->{'bgcol'}) {
1077: $output .= $choices->{'bgcol'}.': '.
1078: '<span id="css_'.$role.'_font" style="background-color: '.
1079: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1080: }
1081: $output .= '<br />';
1082: }
1083: $output .='<br />';
1084: return $output;
1085: }
1086:
1087: sub login_text_colors {
1088: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1089: my $color_menu = '<table border="0"><tr>';
1090: foreach my $item (@{$logintext}) {
1091: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1092: $color_menu .= '<td align="center">'.$link;
1093: if ($designs->{'logintext'}{$item}) {
1094: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1095: }
1096: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1097: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1098: '<td> </td>';
1099: }
1100: $color_menu .= '</tr></table><br />';
1101: return $color_menu;
1102: }
1103:
1104: sub image_changes {
1105: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1106: my $output;
1107: if (!$is_custom) {
1.70 raeburn 1108: if ($img ne 'domlogo') {
1.41 raeburn 1109: $output .= &mt('Default image:').'<br />';
1110: } else {
1111: $output .= &mt('Default in use:').'<br />';
1112: }
1113: }
1114: if ($img_import) {
1115: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1116: }
1117: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1118: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1119: if ($is_custom) {
1120: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1121: '<input type="checkbox" name="'.
1122: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1123: '</label> '.&mt('Replace:').'</span><br />';
1124: } else {
1125: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1126: }
1127: return $output;
1128: }
1129:
1.6 raeburn 1130: sub color_pick {
1131: my ($phase,$role,$item,$desc,$curcol) = @_;
1132: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1133: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1134: ');">'.$desc.'</a>';
1135: return $link;
1136: }
1137:
1.3 raeburn 1138: sub print_quotas {
1.86 raeburn 1139: my ($dom,$settings,$rowtotal,$action) = @_;
1140: my $context;
1141: if ($action eq 'quotas') {
1142: $context = 'tools';
1143: } else {
1144: $context = $action;
1145: }
1.101 raeburn 1146: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1147: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1148: my $typecount = 0;
1.101 raeburn 1149: my ($css_class,%titles);
1.86 raeburn 1150: if ($context eq 'requestcourses') {
1.98 raeburn 1151: @usertools = ('official','unofficial','community');
1.101 raeburn 1152: @options =('norequest','approve','autolimit','validate');
1153: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1154: %titles = &courserequest_titles();
1.86 raeburn 1155: } else {
1156: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 1157: %titles = &tool_titles();
1.86 raeburn 1158: }
1.26 raeburn 1159: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1160: foreach my $type (@{$types}) {
1.72 raeburn 1161: my $currdefquota;
1.86 raeburn 1162: unless ($context eq 'requestcourses') {
1163: if (ref($settings) eq 'HASH') {
1164: if (ref($settings->{defaultquota}) eq 'HASH') {
1165: $currdefquota = $settings->{defaultquota}->{$type};
1166: } else {
1167: $currdefquota = $settings->{$type};
1168: }
1.78 raeburn 1169: }
1.72 raeburn 1170: }
1.3 raeburn 1171: if (defined($usertypes->{$type})) {
1172: $typecount ++;
1173: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1174: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1175: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1176: '<td class="LC_left_item">';
1.101 raeburn 1177: if ($context eq 'requestcourses') {
1178: $datatable .= '<table><tr>';
1179: }
1180: my %cell;
1.72 raeburn 1181: foreach my $item (@usertools) {
1.101 raeburn 1182: if ($context eq 'requestcourses') {
1183: my ($curroption,$currlimit);
1184: if (ref($settings) eq 'HASH') {
1185: if (ref($settings->{$item}) eq 'HASH') {
1186: $curroption = $settings->{$item}->{$type};
1187: if ($curroption =~ /^autolimit=(\d*)$/) {
1188: $currlimit = $1;
1189: }
1190: }
1191: }
1192: if (!$curroption) {
1193: $curroption = 'norequest';
1194: }
1195: $datatable .= '<th>'.$titles{$item}.'</th>';
1196: foreach my $option (@options) {
1197: my $val = $option;
1198: if ($option eq 'norequest') {
1199: $val = 0;
1200: }
1201: if ($option eq 'validate') {
1202: my $canvalidate = 0;
1203: if (ref($validations{$item}) eq 'HASH') {
1204: if ($validations{$item}{$type}) {
1205: $canvalidate = 1;
1206: }
1207: }
1208: next if (!$canvalidate);
1209: }
1210: my $checked = '';
1211: if ($option eq $curroption) {
1212: $checked = ' checked="checked"';
1213: } elsif ($option eq 'autolimit') {
1214: if ($curroption =~ /^autolimit/) {
1215: $checked = ' checked="checked"';
1216: }
1217: }
1218: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1219: '<input type="radio" name="crsreq_'.$item.
1220: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1221: $titles{$option}.'</label> ';
1222: if ($option eq 'autolimit') {
1223: $cell{$item} .= '<input type="text" name="crsreq_'.
1224: $item.'_limit_'.$type.'" size="1" '.
1.103 ! raeburn 1225: 'value="'.$currlimit.'" />';
1.101 raeburn 1226: }
1227: $cell{$item} .= '</span> ';
1.103 ! raeburn 1228: if ($option eq 'autolimit') {
! 1229: $cell{$item} .= $titles{'unlimited'}
! 1230: }
1.101 raeburn 1231: }
1232: } else {
1233: my $checked = 'checked="checked" ';
1234: if (ref($settings) eq 'HASH') {
1235: if (ref($settings->{$item}) eq 'HASH') {
1236: if ($settings->{$item}->{$type} == 0) {
1237: $checked = '';
1238: } elsif ($settings->{$item}->{$type} == 1) {
1239: $checked = 'checked="checked" ';
1240: }
1.78 raeburn 1241: }
1.72 raeburn 1242: }
1.101 raeburn 1243: $datatable .= '<span class="LC_nobreak"><label>'.
1244: '<input type="checkbox" name="'.$context.'_'.$item.
1245: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1246: '</label></span> ';
1.72 raeburn 1247: }
1.101 raeburn 1248: }
1249: if ($context eq 'requestcourses') {
1250: $datatable .= '</tr><tr>';
1251: foreach my $item (@usertools) {
1252: $datatable .= '<td>'.$cell{$item}.'</td>';
1253: }
1254: $datatable .= '</tr></table>';
1.72 raeburn 1255: }
1.86 raeburn 1256: $datatable .= '</td>';
1257: unless ($context eq 'requestcourses') {
1258: $datatable .=
1259: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1260: '<input type="text" name="quota_'.$type.
1.72 raeburn 1261: '" value="'.$currdefquota.
1.86 raeburn 1262: '" size="5" /> Mb</span></td>';
1263: }
1264: $datatable .= '</tr>';
1.3 raeburn 1265: }
1266: }
1267: }
1.86 raeburn 1268: unless ($context eq 'requestcourses') {
1269: $defaultquota = '20';
1270: if (ref($settings) eq 'HASH') {
1271: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1272: $defaultquota = $settings->{'defaultquota'}->{'default'};
1273: } elsif (defined($settings->{'default'})) {
1274: $defaultquota = $settings->{'default'};
1275: }
1.3 raeburn 1276: }
1277: }
1278: $typecount ++;
1279: $css_class = $typecount%2?' class="LC_odd_row"':'';
1280: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1281: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1282: '<td class="LC_left_item">';
1.101 raeburn 1283: if ($context eq 'requestcourses') {
1284: $datatable .= '<table><tr>';
1285: }
1286: my %defcell;
1.72 raeburn 1287: foreach my $item (@usertools) {
1.101 raeburn 1288: if ($context eq 'requestcourses') {
1289: my ($curroption,$currlimit);
1290: if (ref($settings) eq 'HASH') {
1291: if (ref($settings->{$item}) eq 'HASH') {
1292: $curroption = $settings->{$item}->{'default'};
1293: if ($curroption =~ /^autolimit=(\d*)$/) {
1294: $currlimit = $1;
1295: }
1296: }
1297: }
1298: if (!$curroption) {
1299: $curroption = 'norequest';
1300: }
1301: $datatable .= '<th>'.$titles{$item}.'</th>';
1302: foreach my $option (@options) {
1303: my $val = $option;
1304: if ($option eq 'norequest') {
1305: $val = 0;
1306: }
1307: if ($option eq 'validate') {
1308: my $canvalidate = 0;
1309: if (ref($validations{$item}) eq 'HASH') {
1310: if ($validations{$item}{'default'}) {
1311: $canvalidate = 1;
1312: }
1313: }
1314: next if (!$canvalidate);
1315: }
1316: my $checked = '';
1317: if ($option eq $curroption) {
1318: $checked = ' checked="checked"';
1319: } elsif ($option eq 'autolimit') {
1320: if ($curroption =~ /^autolimit/) {
1321: $checked = ' checked="checked"';
1322: }
1323: }
1324: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1325: '<input type="radio" name="crsreq_'.$item.
1326: '_default" value="'.$val.'"'.$checked.' />'.
1327: $titles{$option}.'</label>';
1328: if ($option eq 'autolimit') {
1329: $defcell{$item} .= '<input type="text" name="crsreq_'.
1330: $item.'_limit_default" size="1" '.
1331: 'value="'.$currlimit.'" />';
1332: }
1333: $defcell{$item} .= '</span> ';
1334: }
1335: } else {
1336: my $checked = 'checked="checked" ';
1337: if (ref($settings) eq 'HASH') {
1338: if (ref($settings->{$item}) eq 'HASH') {
1339: if ($settings->{$item}->{'default'} == 0) {
1340: $checked = '';
1341: } elsif ($settings->{$item}->{'default'} == 1) {
1342: $checked = 'checked="checked" ';
1343: }
1.78 raeburn 1344: }
1.72 raeburn 1345: }
1.101 raeburn 1346: $datatable .= '<span class="LC_nobreak"><label>'.
1347: '<input type="checkbox" name="'.$context.'_'.$item.
1348: '" value="default" '.$checked.'/>'.$titles{$item}.
1349: '</label></span> ';
1350: }
1351: }
1352: if ($context eq 'requestcourses') {
1353: $datatable .= '</tr><tr>';
1354: foreach my $item (@usertools) {
1355: $datatable .= '<td>'.$defcell{$item}.'</td>';
1.72 raeburn 1356: }
1.101 raeburn 1357: $datatable .= '</tr></table>';
1.72 raeburn 1358: }
1.86 raeburn 1359: $datatable .= '</td>';
1360: unless ($context eq 'requestcourses') {
1361: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1362: '<input type="text" name="defaultquota" value="'.
1363: $defaultquota.'" size="5" /> Mb</span></td>';
1364: }
1365: $datatable .= '</tr>';
1.72 raeburn 1366: $typecount ++;
1367: $css_class = $typecount%2?' class="LC_odd_row"':'';
1368: $datatable .= '<tr'.$css_class.'>'.
1.98 raeburn 1369: '<td>'.&mt('LON-CAPA Advanced Users').
1370: ' <span class="LC_nobreak">('.
1371: &mt('overrides affiliation').')</span></td>'.
1.101 raeburn 1372: '<td class="LC_left_item" colspan="2">';
1373: if ($context eq 'requestcourses') {
1374: $datatable .= '<table><tr>';
1375: } else {
1376: $datatable .= '<br />';
1377: }
1378: my %advcell;
1.72 raeburn 1379: foreach my $item (@usertools) {
1.101 raeburn 1380: if ($context eq 'requestcourses') {
1381: my ($curroption,$currlimit);
1382: if (ref($settings) eq 'HASH') {
1383: if (ref($settings->{$item}) eq 'HASH') {
1384: $curroption = $settings->{$item}->{'_LC_adv'};
1385: if ($curroption =~ /^autolimit=(\d*)$/) {
1386: $currlimit = $1;
1387: }
1388: }
1389: }
1390: if (!$curroption) {
1391: $curroption = 'norequest';
1392: }
1393: $datatable .= '<th>'.$titles{$item}.'</th>';
1394: foreach my $option (@options) {
1395: my $val = $option;
1396: if ($option eq 'norequest') {
1397: $val = 0;
1398: }
1399: if ($option eq 'validate') {
1400: my $canvalidate = 0;
1401: if (ref($validations{$item}) eq 'HASH') {
1402: if ($validations{$item}{'_LC_adv'}) {
1403: $canvalidate = 1;
1404: }
1405: }
1406: next if (!$canvalidate);
1407: }
1408: my $checked = '';
1409: if ($option eq $curroption) {
1410: $checked = ' checked="checked"';
1411: } elsif ($option eq 'autolimit') {
1412: if ($curroption =~ /^autolimit/) {
1413: $checked = ' checked="checked"';
1414: }
1415: }
1416: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1417: '<input type="radio" name="crsreq_'.$item.
1418: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1419: $titles{$option}.'</label>';
1420: if ($option eq 'autolimit') {
1421: $advcell{$item} .= '<input type="text" name="crsreq_'.
1422: $item.'_limit__LC_adv" size="1" '.
1423: 'value="'.$currlimit.'" />';
1424: }
1425: $advcell{$item} .= '</span> ';
1426: }
1427: } else {
1428: my $checked = 'checked="checked" ';
1429: if (ref($settings) eq 'HASH') {
1430: if (ref($settings->{$item}) eq 'HASH') {
1431: if ($settings->{$item}->{'_LC_adv'} == 0) {
1432: $checked = '';
1433: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1434: $checked = 'checked="checked" ';
1435: }
1.79 raeburn 1436: }
1.72 raeburn 1437: }
1.101 raeburn 1438: $datatable .= '<span class="LC_nobreak"><label>'.
1439: '<input type="checkbox" name="'.$context.'_'.$item.
1440: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1441: '</label></span> ';
1442: }
1443: }
1444: if ($context eq 'requestcourses') {
1445: $datatable .= '</tr><tr>';
1446: foreach my $item (@usertools) {
1447: $datatable .= '<td>'.$advcell{$item}.'</td>';
1.72 raeburn 1448: }
1.101 raeburn 1449: $datatable .= '</tr></table>';
1.72 raeburn 1450: }
1.98 raeburn 1451: $datatable .= '</td></tr>';
1.30 raeburn 1452: $$rowtotal += $typecount;
1.3 raeburn 1453: return $datatable;
1454: }
1455:
1.102 raeburn 1456: sub print_courserequestmail {
1457: my ($dom,$settings,$rowtotal) = @_;
1458: my ($now,$datatable,%dompersonnel,@domcoord,@currapprove,$rows);
1459: $now = time;
1460: $rows = 0;
1461: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1462: foreach my $server (keys(%dompersonnel)) {
1463: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1464: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1465: if (!grep(/^$uname:$udom$/,@domcoord)) {
1466: push(@domcoord,$uname.':'.$udom);
1467: }
1468: }
1469: }
1470: if (ref($settings) eq 'HASH') {
1471: if (ref($settings->{'notify'}) eq 'HASH') {
1472: if ($settings->{'notify'}{'approval'} ne '') {
1473: @currapprove = split(',',$settings->{'notify'}{'approval'});
1474: }
1475: }
1476: }
1477: if (@currapprove) {
1478: foreach my $dc (@currapprove) {
1479: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1480: push(@domcoord,$dc);
1481: }
1482: }
1483: }
1484: @domcoord = sort(@domcoord);
1485: my $numinrow = 4;
1486: my $numdc = @domcoord;
1487: my $css_class = 'class="LC_odd_row"';
1488: $datatable = '<tr'.$css_class.'>'.
1489: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1490: ' </td>'.
1491: ' <td class="LC_left_item">';
1492: if (@domcoord > 0) {
1493: $datatable .= '<table>';
1494: for (my $i=0; $i<$numdc; $i++) {
1495: my $rem = $i%($numinrow);
1496: if ($rem == 0) {
1497: if ($i > 0) {
1498: $datatable .= '</tr>';
1499: }
1500: $datatable .= '<tr>';
1501: $rows ++;
1502: }
1503: my $check = ' ';
1504: if (grep(/^\Q$domcoord[$i]\E$/,@currapprove)) {
1505: $check = ' checked="checked" ';
1506: }
1507: my ($uname,$udom) = split(':',$domcoord[$i]);
1508: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1509: if ($i == $numdc-1) {
1510: my $colsleft = $numinrow-$rem;
1511: if ($colsleft > 1) {
1512: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1513: } else {
1514: $datatable .= '<td class="LC_left_item">';
1515: }
1516: } else {
1517: $datatable .= '<td class="LC_left_item">';
1518: }
1519: $datatable .= '<span class="LC_nobreak"><label>'.
1520: '<input type="checkbox" name="reqapprovalnotify" '.
1521: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1522: $fullname.'</label></span></td>';
1523: }
1524: $datatable .= '</tr></table>';
1525: } else {
1526: $datatable .= &mt('There are no active Domain Coordinators');
1527: $rows ++;
1528: }
1529: $datatable .='</td></tr>';
1530: $$rowtotal += $rows;
1531: return $datatable;
1532: }
1533:
1.3 raeburn 1534: sub print_autoenroll {
1.30 raeburn 1535: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1536: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 1537: my ($defdom,$runon,$runoff);
1.3 raeburn 1538: if (ref($settings) eq 'HASH') {
1539: if (exists($settings->{'run'})) {
1540: if ($settings->{'run'} eq '0') {
1541: $runoff = ' checked="checked" ';
1542: $runon = ' ';
1543: } else {
1544: $runon = ' checked="checked" ';
1545: $runoff = ' ';
1546: }
1547: } else {
1548: if ($autorun) {
1549: $runon = ' checked="checked" ';
1550: $runoff = ' ';
1551: } else {
1552: $runoff = ' checked="checked" ';
1553: $runon = ' ';
1554: }
1555: }
1556: if (exists($settings->{'sender_domain'})) {
1557: $defdom = $settings->{'sender_domain'};
1558: }
1.14 raeburn 1559: } else {
1560: if ($autorun) {
1561: $runon = ' checked="checked" ';
1562: $runoff = ' ';
1563: } else {
1564: $runoff = ' checked="checked" ';
1565: $runon = ' ';
1566: }
1.3 raeburn 1567: }
1568: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1569: my $notif_sender;
1570: if (ref($settings) eq 'HASH') {
1571: $notif_sender = $settings->{'sender_uname'};
1572: }
1.3 raeburn 1573: my $datatable='<tr class="LC_odd_row">'.
1574: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1575: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1576: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1577: $runon.' value="1" />'.&mt('Yes').'</label> '.
1578: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1579: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1580: '</tr><tr>'.
1581: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1582: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1583: &mt('username').': '.
1584: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1585: $notif_sender.'" size="10" /> '.&mt('domain').
1.8 raeburn 1586: ': '.$domform.'</span></td></tr>';
1.30 raeburn 1587: $$rowtotal += 2;
1.3 raeburn 1588: return $datatable;
1589: }
1590:
1591: sub print_autoupdate {
1.30 raeburn 1592: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1593: my $datatable;
1594: if ($position eq 'top') {
1595: my $updateon = ' ';
1596: my $updateoff = ' checked="checked" ';
1597: my $classlistson = ' ';
1598: my $classlistsoff = ' checked="checked" ';
1599: if (ref($settings) eq 'HASH') {
1600: if ($settings->{'run'} eq '1') {
1601: $updateon = $updateoff;
1602: $updateoff = ' ';
1603: }
1604: if ($settings->{'classlists'} eq '1') {
1605: $classlistson = $classlistsoff;
1606: $classlistsoff = ' ';
1607: }
1608: }
1609: my %title = (
1610: run => 'Auto-update active?',
1611: classlists => 'Update information in classlists?',
1612: );
1613: $datatable = '<tr class="LC_odd_row">'.
1614: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1615: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1616: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1617: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1618: '<label><input type="radio" name="autoupdate_run"'.
1619: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1620: '</tr><tr>'.
1621: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1622: '<td class="LC_right_item"><span class="LC_nobreak">'.
1623: '<label><input type="radio" name="classlists"'.
1624: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1625: '<label><input type="radio" name="classlists"'.
1626: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1627: '</tr>';
1.30 raeburn 1628: $$rowtotal += 2;
1.3 raeburn 1629: } else {
1.44 raeburn 1630: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.20 raeburn 1631: my @fields = ('lastname','firstname','middlename','gen',
1632: 'permanentemail','id');
1.33 raeburn 1633: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1634: my $numrows = 0;
1.26 raeburn 1635: if (ref($types) eq 'ARRAY') {
1636: if (@{$types} > 0) {
1637: $datatable =
1638: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1639: \@fields,$types,\$numrows);
1.30 raeburn 1640: $$rowtotal += @{$types};
1.26 raeburn 1641: }
1.3 raeburn 1642: }
1643: $datatable .=
1644: &usertype_update_row($settings,{'default' => $othertitle},
1645: \%fieldtitles,\@fields,['default'],
1646: \$numrows);
1.30 raeburn 1647: $$rowtotal ++;
1.3 raeburn 1648: }
1649: return $datatable;
1650: }
1651:
1.23 raeburn 1652: sub print_directorysrch {
1.30 raeburn 1653: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1654: my $srchon = ' ';
1655: my $srchoff = ' checked="checked" ';
1.25 raeburn 1656: my ($exacton,$containson,$beginson);
1.24 raeburn 1657: my $localon = ' ';
1658: my $localoff = ' checked="checked" ';
1.23 raeburn 1659: if (ref($settings) eq 'HASH') {
1660: if ($settings->{'available'} eq '1') {
1661: $srchon = $srchoff;
1662: $srchoff = ' ';
1663: }
1.24 raeburn 1664: if ($settings->{'localonly'} eq '1') {
1665: $localon = $localoff;
1666: $localoff = ' ';
1667: }
1.25 raeburn 1668: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1669: foreach my $type (@{$settings->{'searchtypes'}}) {
1670: if ($type eq 'exact') {
1671: $exacton = ' checked="checked" ';
1672: } elsif ($type eq 'contains') {
1673: $containson = ' checked="checked" ';
1674: } elsif ($type eq 'begins') {
1675: $beginson = ' checked="checked" ';
1676: }
1677: }
1678: } else {
1679: if ($settings->{'searchtypes'} eq 'exact') {
1680: $exacton = ' checked="checked" ';
1681: } elsif ($settings->{'searchtypes'} eq 'contains') {
1682: $containson = ' checked="checked" ';
1683: } elsif ($settings->{'searchtypes'} eq 'specify') {
1684: $exacton = ' checked="checked" ';
1685: $containson = ' checked="checked" ';
1686: }
1.23 raeburn 1687: }
1688: }
1689: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1690: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1691:
1692: my $numinrow = 4;
1.26 raeburn 1693: my $cansrchrow = 0;
1.23 raeburn 1694: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1695: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1696: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1697: '<input type="radio" name="dirsrch_available"'.
1698: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1699: '<label><input type="radio" name="dirsrch_available"'.
1700: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1701: '</tr><tr>'.
1.30 raeburn 1702: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1703: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1704: '<input type="radio" name="dirsrch_localonly"'.
1705: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1706: '<label><input type="radio" name="dirsrch_localonly"'.
1707: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1708: '</tr>';
1.30 raeburn 1709: $$rowtotal += 2;
1.26 raeburn 1710: if (ref($usertypes) eq 'HASH') {
1711: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 1712: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1713: $numinrow,$othertitle,'cansearch');
1.26 raeburn 1714: $cansrchrow = 1;
1715: }
1716: }
1717: if ($cansrchrow) {
1.30 raeburn 1718: $$rowtotal ++;
1.26 raeburn 1719: $datatable .= '<tr>';
1720: } else {
1721: $datatable .= '<tr class="LC_odd_row">';
1722: }
1.30 raeburn 1723: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1724: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1725: foreach my $title (@{$titleorder}) {
1726: if (defined($searchtitles->{$title})) {
1727: my $check = ' ';
1.93 raeburn 1728: if (ref($settings) eq 'HASH') {
1.39 raeburn 1729: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1730: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1731: $check = ' checked="checked" ';
1732: }
1.25 raeburn 1733: }
1734: }
1735: $datatable .= '<td class="LC_left_item">'.
1736: '<span class="LC_nobreak"><label>'.
1737: '<input type="checkbox" name="searchby" '.
1738: 'value="'.$title.'"'.$check.'/>'.
1739: $searchtitles->{$title}.'</label></span></td>';
1740: }
1741: }
1.26 raeburn 1742: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1743: $$rowtotal ++;
1.26 raeburn 1744: if ($cansrchrow) {
1745: $datatable .= '<tr class="LC_odd_row">';
1746: } else {
1747: $datatable .= '<tr>';
1748: }
1.30 raeburn 1749: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 1750: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1751: '<span class="LC_nobreak"><label>'.
1752: '<input type="checkbox" name="searchtypes" '.
1753: $exacton.' value="exact" />'.&mt('Exact match').
1754: '</label> '.
1755: '<label><input type="checkbox" name="searchtypes" '.
1756: $beginson.' value="begins" />'.&mt('Begins with').
1757: '</label> '.
1758: '<label><input type="checkbox" name="searchtypes" '.
1759: $containson.' value="contains" />'.&mt('Contains').
1760: '</label></span></td></tr>';
1.30 raeburn 1761: $$rowtotal ++;
1.25 raeburn 1762: return $datatable;
1763: }
1764:
1.28 raeburn 1765: sub print_contacts {
1.30 raeburn 1766: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 1767: my $datatable;
1768: my @contacts = ('adminemail','supportemail');
1769: my (%checked,%to,%otheremails);
1.102 raeburn 1770: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1771: 'requestsmail');
1.28 raeburn 1772: foreach my $type (@mailings) {
1773: $otheremails{$type} = '';
1774: }
1775: if (ref($settings) eq 'HASH') {
1776: foreach my $item (@contacts) {
1777: if (exists($settings->{$item})) {
1778: $to{$item} = $settings->{$item};
1779: }
1780: }
1781: foreach my $type (@mailings) {
1782: if (exists($settings->{$type})) {
1783: if (ref($settings->{$type}) eq 'HASH') {
1784: foreach my $item (@contacts) {
1785: if ($settings->{$type}{$item}) {
1786: $checked{$type}{$item} = ' checked="checked" ';
1787: }
1788: }
1789: $otheremails{$type} = $settings->{$type}{'others'};
1790: }
1.89 raeburn 1791: } elsif ($type eq 'lonstatusmail') {
1792: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 1793: }
1794: }
1795: } else {
1796: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1797: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1798: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1799: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 1800: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
1801: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 1802: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 1803: }
1804: my ($titles,$short_titles) = &contact_titles();
1805: my $rownum = 0;
1806: my $css_class;
1807: foreach my $item (@contacts) {
1.69 raeburn 1808: $rownum ++;
1809: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 1810: $datatable .= '<tr'.$css_class.'>'.
1811: '<td><span class="LC_nobreak">'.$titles->{$item}.
1812: '</span></td><td class="LC_right_item">'.
1.28 raeburn 1813: '<input type="text" name="'.$item.'" value="'.
1814: $to{$item}.'" /></td></tr>';
1815: }
1816: foreach my $type (@mailings) {
1.69 raeburn 1817: $rownum ++;
1818: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 1819: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 1820: '<td><span class="LC_nobreak">'.
1821: $titles->{$type}.': </span></td>'.
1.28 raeburn 1822: '<td class="LC_left_item">'.
1823: '<span class="LC_nobreak">';
1824: foreach my $item (@contacts) {
1825: $datatable .= '<label>'.
1826: '<input type="checkbox" name="'.$type.'"'.
1827: $checked{$type}{$item}.
1828: ' value="'.$item.'" />'.$short_titles->{$item}.
1829: '</label> ';
1830: }
1831: $datatable .= '</span><br />'.&mt('Others').': '.
1832: '<input type="text" name="'.$type.'_others" '.
1833: 'value="'.$otheremails{$type}.'" />'.
1834: '</td></tr>'."\n";
1835: }
1.30 raeburn 1836: $$rowtotal += $rownum;
1.28 raeburn 1837: return $datatable;
1838: }
1839:
1840: sub contact_titles {
1841: my %titles = &Apache::lonlocal::texthash (
1842: 'supportemail' => 'Support E-mail address',
1.69 raeburn 1843: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 1844: 'errormail' => 'Error reports to be e-mailed to',
1845: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 1846: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
1847: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 1848: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 1849: );
1850: my %short_titles = &Apache::lonlocal::texthash (
1851: adminemail => 'Admin E-mail address',
1852: supportemail => 'Support E-mail',
1853: );
1854: return (\%titles,\%short_titles);
1855: }
1856:
1.72 raeburn 1857: sub tool_titles {
1858: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 1859: aboutme => 'Personal Information Page',
1.86 raeburn 1860: blog => 'Blog',
1861: portfolio => 'Portfolio',
1.88 bisitz 1862: official => 'Official courses (with institutional codes)',
1863: unofficial => 'Unofficial courses',
1.98 raeburn 1864: community => 'Communities',
1.86 raeburn 1865: );
1.72 raeburn 1866: return %titles;
1867: }
1868:
1.101 raeburn 1869: sub courserequest_titles {
1870: my %titles = &Apache::lonlocal::texthash (
1871: official => 'Official',
1872: unofficial => 'Unofficial',
1873: community => 'Communities',
1874: norequest => 'Not allowed',
1875: approve => 'Approval by Dom. Coord.',
1876: validate => 'With validation',
1877: autolimit => 'Numerical limit',
1.103 ! raeburn 1878: unlimited => '(blank for unlimited)',
1.101 raeburn 1879: );
1880: return %titles;
1881: }
1882:
1883: sub courserequest_conditions {
1884: my %conditions = &Apache::lonlocal::texthash (
1885: approve => '(Processing of request subject to approval by Domain Coordinator).',
1886: validate => '(Processing of request subject to instittutional validation).',
1887: );
1888: return %conditions;
1889: }
1890:
1891:
1.27 raeburn 1892: sub print_usercreation {
1.30 raeburn 1893: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 1894: my $numinrow = 4;
1.28 raeburn 1895: my $datatable;
1896: if ($position eq 'top') {
1.30 raeburn 1897: $$rowtotal ++;
1.34 raeburn 1898: my $rowcount = 0;
1.32 raeburn 1899: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 1900: if (ref($rules) eq 'HASH') {
1901: if (keys(%{$rules}) > 0) {
1.32 raeburn 1902: $datatable .= &user_formats_row('username',$settings,$rules,
1903: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 1904: $$rowtotal ++;
1.32 raeburn 1905: $rowcount ++;
1906: }
1907: }
1908: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
1909: if (ref($idrules) eq 'HASH') {
1910: if (keys(%{$idrules}) > 0) {
1911: $datatable .= &user_formats_row('id',$settings,$idrules,
1912: $idruleorder,$numinrow,$rowcount);
1913: $$rowtotal ++;
1914: $rowcount ++;
1.28 raeburn 1915: }
1916: }
1.43 raeburn 1917: my ($emailrules,$emailruleorder) =
1918: &Apache::lonnet::inst_userrules($dom,'email');
1919: if (ref($emailrules) eq 'HASH') {
1920: if (keys(%{$emailrules}) > 0) {
1921: $datatable .= &user_formats_row('email',$settings,$emailrules,
1922: $emailruleorder,$numinrow,$rowcount);
1923: $$rowtotal ++;
1924: $rowcount ++;
1925: }
1926: }
1.39 raeburn 1927: if ($rowcount == 0) {
1928: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
1929: $$rowtotal ++;
1930: $rowcount ++;
1931: }
1.34 raeburn 1932: } elsif ($position eq 'middle') {
1.100 raeburn 1933: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 1934: my ($rules,$ruleorder) =
1935: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 1936: my %lt = &usercreation_types();
1937: my %checked;
1.50 raeburn 1938: my @selfcreate;
1.34 raeburn 1939: if (ref($settings) eq 'HASH') {
1940: if (ref($settings->{'cancreate'}) eq 'HASH') {
1941: foreach my $item (@creators) {
1942: $checked{$item} = $settings->{'cancreate'}{$item};
1943: }
1.50 raeburn 1944: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
1945: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
1946: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
1947: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
1948: @selfcreate = ('email','login','sso');
1949: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
1950: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
1951: }
1952: }
1.34 raeburn 1953: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
1954: foreach my $item (@creators) {
1955: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
1956: $checked{$item} = 'none';
1957: }
1958: }
1959: }
1960: }
1961: my $rownum = 0;
1962: foreach my $item (@creators) {
1963: $rownum ++;
1.50 raeburn 1964: if ($item ne 'selfcreate') {
1965: if ($checked{$item} eq '') {
1.43 raeburn 1966: $checked{$item} = 'any';
1967: }
1.34 raeburn 1968: }
1969: my $css_class;
1970: if ($rownum%2) {
1971: $css_class = '';
1972: } else {
1973: $css_class = ' class="LC_odd_row" ';
1974: }
1975: $datatable .= '<tr'.$css_class.'>'.
1976: '<td><span class="LC_nobreak">'.$lt{$item}.
1977: '</span></td><td align="right">';
1.50 raeburn 1978: my @options;
1.45 raeburn 1979: if ($item eq 'selfcreate') {
1.43 raeburn 1980: push(@options,('email','login','sso'));
1981: } else {
1.50 raeburn 1982: @options = ('any');
1.43 raeburn 1983: if (ref($rules) eq 'HASH') {
1984: if (keys(%{$rules}) > 0) {
1985: push(@options,('official','unofficial'));
1986: }
1.37 raeburn 1987: }
1.50 raeburn 1988: push(@options,'none');
1.37 raeburn 1989: }
1990: foreach my $option (@options) {
1.50 raeburn 1991: my $type = 'radio';
1.34 raeburn 1992: my $check = ' ';
1.50 raeburn 1993: if ($item eq 'selfcreate') {
1994: $type = 'checkbox';
1995: if (grep(/^\Q$option\E$/,@selfcreate)) {
1996: $check = ' checked="checked" ';
1997: }
1998: } else {
1999: if ($checked{$item} eq $option) {
2000: $check = ' checked="checked" ';
2001: }
1.34 raeburn 2002: }
2003: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 2004: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 2005: $item.'" value="'.$option.'"'.$check.'/> '.
2006: $lt{$option}.'</label> </span>';
2007: }
2008: $datatable .= '</td></tr>';
2009: }
1.93 raeburn 2010: my ($othertitle,$usertypes,$types) =
2011: &Apache::loncommon::sorted_inst_types($dom);
2012: if (ref($usertypes) eq 'HASH') {
2013: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 2014: my $createsettings;
2015: if (ref($settings) eq 'HASH') {
2016: $createsettings = $settings->{cancreate};
2017: }
2018: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 2019: $dom,$numinrow,$othertitle,
2020: 'statustocreate');
2021: $$rowtotal ++;
2022: }
2023: }
1.28 raeburn 2024: } else {
2025: my @contexts = ('author','course','domain');
2026: my @authtypes = ('int','krb4','krb5','loc');
2027: my %checked;
2028: if (ref($settings) eq 'HASH') {
2029: if (ref($settings->{'authtypes'}) eq 'HASH') {
2030: foreach my $item (@contexts) {
2031: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
2032: foreach my $auth (@authtypes) {
2033: if ($settings->{'authtypes'}{$item}{$auth}) {
2034: $checked{$item}{$auth} = ' checked="checked" ';
2035: }
2036: }
2037: }
2038: }
1.27 raeburn 2039: }
1.35 raeburn 2040: } else {
2041: foreach my $item (@contexts) {
1.36 raeburn 2042: foreach my $auth (@authtypes) {
1.35 raeburn 2043: $checked{$item}{$auth} = ' checked="checked" ';
2044: }
2045: }
1.27 raeburn 2046: }
1.28 raeburn 2047: my %title = &context_names();
2048: my %authname = &authtype_names();
2049: my $rownum = 0;
2050: my $css_class;
2051: foreach my $item (@contexts) {
2052: if ($rownum%2) {
2053: $css_class = '';
2054: } else {
2055: $css_class = ' class="LC_odd_row" ';
2056: }
1.30 raeburn 2057: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 2058: '<td>'.$title{$item}.
2059: '</td><td class="LC_left_item">'.
2060: '<span class="LC_nobreak">';
2061: foreach my $auth (@authtypes) {
2062: $datatable .= '<label>'.
2063: '<input type="checkbox" name="'.$item.'_auth" '.
2064: $checked{$item}{$auth}.' value="'.$auth.'" />'.
2065: $authname{$auth}.'</label> ';
2066: }
2067: $datatable .= '</span></td></tr>';
2068: $rownum ++;
1.27 raeburn 2069: }
1.30 raeburn 2070: $$rowtotal += $rownum;
1.27 raeburn 2071: }
2072: return $datatable;
2073: }
2074:
1.32 raeburn 2075: sub user_formats_row {
2076: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
2077: my $output;
2078: my %text = (
2079: 'username' => 'new usernames',
2080: 'id' => 'IDs',
1.45 raeburn 2081: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 2082: );
2083: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2084: $output = '<tr '.$css_class.'>'.
1.63 raeburn 2085: '<td><span class="LC_nobreak">';
2086: if ($type eq 'email') {
2087: $output .= &mt("Formats disallowed for $text{$type}: ");
2088: } else {
2089: $output .= &mt("Format rules to check for $text{$type}: ");
2090: }
2091: $output .= '</span></td>'.
2092: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 2093: my $rem;
2094: if (ref($ruleorder) eq 'ARRAY') {
2095: for (my $i=0; $i<@{$ruleorder}; $i++) {
2096: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
2097: my $rem = $i%($numinrow);
2098: if ($rem == 0) {
2099: if ($i > 0) {
2100: $output .= '</tr>';
2101: }
2102: $output .= '<tr>';
2103: }
2104: my $check = ' ';
1.39 raeburn 2105: if (ref($settings) eq 'HASH') {
2106: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
2107: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
2108: $check = ' checked="checked" ';
2109: }
1.27 raeburn 2110: }
2111: }
2112: $output .= '<td class="LC_left_item">'.
2113: '<span class="LC_nobreak"><label>'.
1.32 raeburn 2114: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 2115: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
2116: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
2117: }
2118: }
2119: $rem = @{$ruleorder}%($numinrow);
2120: }
2121: my $colsleft = $numinrow - $rem;
2122: if ($colsleft > 1 ) {
2123: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2124: ' </td>';
2125: } elsif ($colsleft == 1) {
2126: $output .= '<td class="LC_left_item"> </td>';
2127: }
2128: $output .= '</tr></table></td></tr>';
2129: return $output;
2130: }
2131:
1.34 raeburn 2132: sub usercreation_types {
2133: my %lt = &Apache::lonlocal::texthash (
2134: author => 'When adding a co-author',
2135: course => 'When adding a user to a course',
1.100 raeburn 2136: requestcrs => 'When requesting a course',
1.45 raeburn 2137: selfcreate => 'User creates own account',
1.34 raeburn 2138: any => 'Any',
2139: official => 'Institutional only ',
2140: unofficial => 'Non-institutional only',
1.85 schafran 2141: email => 'E-mail address',
1.43 raeburn 2142: login => 'Institutional Login',
2143: sso => 'SSO',
1.34 raeburn 2144: none => 'None',
2145: );
2146: return %lt;
1.48 raeburn 2147: }
1.34 raeburn 2148:
1.28 raeburn 2149: sub authtype_names {
2150: my %lt = &Apache::lonlocal::texthash(
2151: int => 'Internal',
2152: krb4 => 'Kerberos 4',
2153: krb5 => 'Kerberos 5',
2154: loc => 'Local',
2155: );
2156: return %lt;
2157: }
2158:
2159: sub context_names {
2160: my %context_title = &Apache::lonlocal::texthash(
2161: author => 'Creating users when an Author',
2162: course => 'Creating users when in a course',
2163: domain => 'Creating users when a Domain Coordinator',
2164: );
2165: return %context_title;
2166: }
2167:
1.33 raeburn 2168: sub print_usermodification {
2169: my ($position,$dom,$settings,$rowtotal) = @_;
2170: my $numinrow = 4;
2171: my ($context,$datatable,$rowcount);
2172: if ($position eq 'top') {
2173: $rowcount = 0;
2174: $context = 'author';
2175: foreach my $role ('ca','aa') {
2176: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2177: $numinrow,$rowcount);
2178: $$rowtotal ++;
2179: $rowcount ++;
2180: }
1.63 raeburn 2181: } elsif ($position eq 'middle') {
1.33 raeburn 2182: $context = 'course';
2183: $rowcount = 0;
2184: foreach my $role ('st','ep','ta','in','cr') {
2185: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2186: $numinrow,$rowcount);
2187: $$rowtotal ++;
2188: $rowcount ++;
2189: }
1.63 raeburn 2190: } elsif ($position eq 'bottom') {
2191: $context = 'selfcreate';
2192: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2193: $usertypes->{'default'} = $othertitle;
2194: if (ref($types) eq 'ARRAY') {
2195: push(@{$types},'default');
2196: $usertypes->{'default'} = $othertitle;
2197: foreach my $status (@{$types}) {
2198: $datatable .= &modifiable_userdata_row($context,$status,$settings,
2199: $numinrow,$rowcount,$usertypes);
2200: $$rowtotal ++;
2201: $rowcount ++;
2202: }
2203: }
1.33 raeburn 2204: }
2205: return $datatable;
2206: }
2207:
1.43 raeburn 2208: sub print_defaults {
2209: my ($dom,$rowtotal) = @_;
1.68 raeburn 2210: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
2211: 'datelocale_def');
1.43 raeburn 2212: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
2213: my $titles = &defaults_titles();
2214: my $rownum = 0;
2215: my ($datatable,$css_class);
2216: foreach my $item (@items) {
2217: if ($rownum%2) {
2218: $css_class = '';
2219: } else {
2220: $css_class = ' class="LC_odd_row" ';
2221: }
2222: $datatable .= '<tr'.$css_class.'>'.
2223: '<td><span class="LC_nobreak">'.$titles->{$item}.
2224: '</span></td><td class="LC_right_item">';
2225: if ($item eq 'auth_def') {
2226: my @authtypes = ('internal','krb4','krb5','localauth');
2227: my %shortauth = (
2228: internal => 'int',
2229: krb4 => 'krb4',
2230: krb5 => 'krb5',
2231: localauth => 'loc'
2232: );
2233: my %authnames = &authtype_names();
2234: foreach my $auth (@authtypes) {
2235: my $checked = ' ';
2236: if ($domdefaults{$item} eq $auth) {
2237: $checked = ' checked="checked" ';
2238: }
2239: $datatable .= '<label><input type="radio" name="'.$item.
2240: '" value="'.$auth.'"'.$checked.'/>'.
2241: $authnames{$shortauth{$auth}}.'</label> ';
2242: }
1.54 raeburn 2243: } elsif ($item eq 'timezone_def') {
2244: my $includeempty = 1;
2245: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 2246: } elsif ($item eq 'datelocale_def') {
2247: my $includeempty = 1;
2248: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 2249: } else {
2250: $datatable .= '<input type="text" name="'.$item.'" value="'.
2251: $domdefaults{$item}.'" />';
2252: }
2253: $datatable .= '</td></tr>';
2254: $rownum ++;
2255: }
2256: $$rowtotal += $rownum;
2257: return $datatable;
2258: }
2259:
2260: sub defaults_titles {
2261: my %titles = &Apache::lonlocal::texthash (
2262: 'auth_def' => 'Default authentication type',
2263: 'auth_arg_def' => 'Default authentication argument',
2264: 'lang_def' => 'Default language',
1.54 raeburn 2265: 'timezone_def' => 'Default timezone',
1.68 raeburn 2266: 'datelocale_def' => 'Default locale for dates',
1.43 raeburn 2267: );
2268: return (\%titles);
2269: }
2270:
1.46 raeburn 2271: sub print_scantronformat {
2272: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
2273: my $itemcount = 1;
1.60 raeburn 2274: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
2275: %confhash);
1.46 raeburn 2276: my $switchserver = &check_switchserver($dom,$confname);
2277: my %lt = &Apache::lonlocal::texthash (
1.95 www 2278: default => 'Default bubblesheet format file error',
2279: custom => 'Custom bubblesheet format file error',
1.46 raeburn 2280: );
2281: my %scantronfiles = (
2282: default => 'default.tab',
2283: custom => 'custom.tab',
2284: );
2285: foreach my $key (keys(%scantronfiles)) {
2286: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
2287: .$scantronfiles{$key};
2288: }
2289: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
2290: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
2291: if (!$switchserver) {
2292: my $servadm = $r->dir_config('lonAdmEMail');
2293: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
2294: if ($configuserok eq 'ok') {
2295: if ($author_ok eq 'ok') {
2296: my %legacyfile = (
2297: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
2298: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
2299: );
2300: my %md5chk;
2301: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2302: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
2303: chomp($md5chk{$type});
1.46 raeburn 2304: }
2305: if ($md5chk{'default'} ne $md5chk{'custom'}) {
2306: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2307: ($scantronurls{$type},my $error) =
1.46 raeburn 2308: &legacy_scantronformat($r,$dom,$confname,
2309: $type,$legacyfile{$type},
2310: $scantronurls{$type},
2311: $scantronfiles{$type});
1.60 raeburn 2312: if ($error ne '') {
2313: $error{$type} = $error;
2314: }
2315: }
2316: if (keys(%error) == 0) {
2317: $is_custom = 1;
2318: $confhash{'scantron'}{'scantronformat'} =
2319: $scantronurls{'custom'};
2320: my $putresult =
2321: &Apache::lonnet::put_dom('configuration',
2322: \%confhash,$dom);
2323: if ($putresult ne 'ok') {
2324: $error{'custom'} =
2325: '<span class="LC_error">'.
2326: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2327: }
1.46 raeburn 2328: }
2329: } else {
1.60 raeburn 2330: ($scantronurls{'default'},my $error) =
1.46 raeburn 2331: &legacy_scantronformat($r,$dom,$confname,
2332: 'default',$legacyfile{'default'},
2333: $scantronurls{'default'},
2334: $scantronfiles{'default'});
1.60 raeburn 2335: if ($error eq '') {
2336: $confhash{'scantron'}{'scantronformat'} = '';
2337: my $putresult =
2338: &Apache::lonnet::put_dom('configuration',
2339: \%confhash,$dom);
2340: if ($putresult ne 'ok') {
2341: $error{'default'} =
2342: '<span class="LC_error">'.
2343: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2344: }
2345: } else {
2346: $error{'default'} = $error;
2347: }
1.46 raeburn 2348: }
2349: }
2350: }
2351: } else {
1.95 www 2352: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 2353: }
2354: }
2355: if (ref($settings) eq 'HASH') {
2356: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
2357: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
2358: if ((!@info) || ($info[0] eq 'no_such_dir')) {
2359: $scantronurl = '';
2360: } else {
2361: $scantronurl = $settings->{'scantronformat'};
2362: }
2363: $is_custom = 1;
2364: } else {
2365: $scantronurl = $scantronurls{'default'};
2366: }
2367: } else {
1.60 raeburn 2368: if ($is_custom) {
2369: $scantronurl = $scantronurls{'custom'};
2370: } else {
2371: $scantronurl = $scantronurls{'default'};
2372: }
1.46 raeburn 2373: }
2374: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2375: $datatable .= '<tr'.$css_class.'>';
2376: if (!$is_custom) {
1.65 raeburn 2377: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
2378: '<span class="LC_nobreak">';
1.46 raeburn 2379: if ($scantronurl) {
2380: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
2381: &mt('Default scantron format file').'</a>';
2382: } else {
2383: $datatable = &mt('File unavailable for display');
2384: }
1.65 raeburn 2385: $datatable .= '</span></td>';
1.60 raeburn 2386: if (keys(%error) == 0) {
2387: $datatable .= '<td valign="bottom">';
2388: if (!$switchserver) {
2389: $datatable .= &mt('Upload:').'<br />';
2390: }
2391: } else {
2392: my $errorstr;
2393: foreach my $key (sort(keys(%error))) {
2394: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2395: }
2396: $datatable .= '<td>'.$errorstr;
2397: }
1.46 raeburn 2398: } else {
2399: if (keys(%error) > 0) {
2400: my $errorstr;
2401: foreach my $key (sort(keys(%error))) {
2402: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2403: }
1.60 raeburn 2404: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 2405: } elsif ($scantronurl) {
1.65 raeburn 2406: $datatable .= '<td><span class="LC_nobreak">'.
2407: '<a href="'.$scantronurl.'" target="_blank">'.
2408: &mt('Custom scantron format file').'</a><label>'.
2409: '<input type="checkbox" name="scantronformat_del"'.
2410: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
2411: '<td><span class="LC_nobreak"> '.
2412: &mt('Replace:').'</span><br />';
1.46 raeburn 2413: }
2414: }
2415: if (keys(%error) == 0) {
2416: if ($switchserver) {
2417: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2418: } else {
1.65 raeburn 2419: $datatable .='<span class="LC_nobreak"> '.
2420: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 2421: }
2422: }
2423: $datatable .= '</td></tr>';
2424: $$rowtotal ++;
2425: return $datatable;
2426: }
2427:
2428: sub legacy_scantronformat {
2429: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
2430: my ($url,$error);
2431: my @statinfo = &Apache::lonnet::stat_file($newurl);
2432: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
2433: (my $result,$url) =
2434: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
2435: '','',$newfile);
2436: if ($result ne 'ok') {
2437: $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
2438: }
2439: }
2440: return ($url,$error);
2441: }
1.43 raeburn 2442:
1.49 raeburn 2443: sub print_coursecategories {
1.57 raeburn 2444: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
2445: my $datatable;
2446: if ($position eq 'top') {
2447: my $toggle_cats_crs = ' ';
2448: my $toggle_cats_dom = ' checked="checked" ';
2449: my $can_cat_crs = ' ';
2450: my $can_cat_dom = ' checked="checked" ';
2451: if (ref($settings) eq 'HASH') {
2452: if ($settings->{'togglecats'} eq 'crs') {
2453: $toggle_cats_crs = $toggle_cats_dom;
2454: $toggle_cats_dom = ' ';
2455: }
2456: if ($settings->{'categorize'} eq 'crs') {
2457: $can_cat_crs = $can_cat_dom;
2458: $can_cat_dom = ' ';
2459: }
2460: }
2461: my %title = &Apache::lonlocal::texthash (
2462: togglecats => 'Show/Hide a course in the catalog',
2463: categorize => 'Assign a category to a course',
2464: );
2465: my %level = &Apache::lonlocal::texthash (
2466: dom => 'Set in "Modify Course" (Domain)',
1.60 raeburn 2467: crs => 'Set in "Modify Parameters" (Course)',
1.57 raeburn 2468: );
2469: $datatable = '<tr class="LC_odd_row">'.
2470: '<td>'.$title{'togglecats'}.'</td>'.
2471: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2472: '<input type="radio" name="togglecats"'.
2473: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2474: '<label><input type="radio" name="togglecats"'.
2475: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
2476: '</tr><tr>'.
2477: '<td>'.$title{'categorize'}.'</td>'.
2478: '<td class="LC_right_item"><span class="LC_nobreak">'.
2479: '<label><input type="radio" name="categorize"'.
2480: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2481: '<label><input type="radio" name="categorize"'.
2482: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
2483: '</tr>';
2484: $$rowtotal += 2;
2485: } else {
2486: my $css_class;
2487: my $itemcount = 1;
2488: my $cathash;
2489: if (ref($settings) eq 'HASH') {
2490: $cathash = $settings->{'cats'};
2491: }
2492: if (ref($cathash) eq 'HASH') {
2493: my (@cats,@trails,%allitems,%idx,@jsarray);
2494: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
2495: \%allitems,\%idx,\@jsarray);
2496: my $maxdepth = scalar(@cats);
2497: my $colattrib = '';
2498: if ($maxdepth > 2) {
2499: $colattrib = ' colspan="2" ';
2500: }
2501: my @path;
2502: if (@cats > 0) {
2503: if (ref($cats[0]) eq 'ARRAY') {
2504: my $numtop = @{$cats[0]};
2505: my $maxnum = $numtop;
2506: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2507: $maxnum ++;
2508: }
2509: my $lastidx;
2510: for (my $i=0; $i<$numtop; $i++) {
2511: my $parent = $cats[0][$i];
2512: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2513: my $item = &escape($parent).'::0';
2514: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
2515: $lastidx = $idx{$item};
2516: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2517: .'<select name="'.$item.'"'.$chgstr.'>';
2518: for (my $k=0; $k<=$maxnum; $k++) {
2519: my $vpos = $k+1;
2520: my $selstr;
2521: if ($k == $i) {
2522: $selstr = ' selected="selected" ';
2523: }
2524: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2525: }
2526: $datatable .= '</select></td><td>';
2527: if ($parent eq 'instcode') {
2528: $datatable .= '<span class="LC_nobreak">'.&mt('Official courses')
2529: .'</span><br /><span class="LC_nobreak">('
2530: .&mt('with institutional codes').')</span></td>'
2531: .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'
2532: .&mt('Display').'</label> '
2533: .'<label><input type="radio" name="instcode" value="0" />'
2534: .&mt('Do not display').'</label></span></td>';
2535: } else {
2536: $datatable .= $parent
2537: .' <label><input type="checkbox" name="deletecategory" '
2538: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
2539: }
2540: my $depth = 1;
2541: push(@path,$parent);
2542: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
2543: pop(@path);
2544: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
2545: $itemcount ++;
2546: }
1.48 raeburn 2547: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 2548: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
2549: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 2550: for (my $k=0; $k<=$maxnum; $k++) {
2551: my $vpos = $k+1;
2552: my $selstr;
1.57 raeburn 2553: if ($k == $numtop) {
1.48 raeburn 2554: $selstr = ' selected="selected" ';
2555: }
2556: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2557: }
1.59 bisitz 2558: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 2559: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
2560: .'</tr>'."\n";
1.48 raeburn 2561: $itemcount ++;
1.57 raeburn 2562: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2563: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2564: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
2565: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
2566: '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
2567: for (my $k=0; $k<=$maxnum; $k++) {
2568: my $vpos = $k+1;
2569: my $selstr;
2570: if ($k == $maxnum) {
2571: $selstr = ' selected="selected" ';
2572: }
2573: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.48 raeburn 2574: }
1.57 raeburn 2575: $datatable .= '</select></span></td><td><span class="LC_nobreak">'
2576: .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('
2577: .&mt('with institutional codes').')</span></td>'
2578: .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'
2579: .&mt('Display').'</label> '
2580: .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'
2581: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 2582: }
2583: }
1.57 raeburn 2584: } else {
2585: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 2586: }
2587: } else {
1.57 raeburn 2588: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
2589: .&initialize_categories($itemcount);
1.48 raeburn 2590: }
1.57 raeburn 2591: $$rowtotal += $itemcount;
1.48 raeburn 2592: }
2593: return $datatable;
2594: }
2595:
1.69 raeburn 2596: sub print_serverstatuses {
2597: my ($dom,$settings,$rowtotal) = @_;
2598: my $datatable;
2599: my @pages = &serverstatus_pages();
2600: my (%namedaccess,%machineaccess);
2601: foreach my $type (@pages) {
2602: $namedaccess{$type} = '';
2603: $machineaccess{$type}= '';
2604: }
2605: if (ref($settings) eq 'HASH') {
2606: foreach my $type (@pages) {
2607: if (exists($settings->{$type})) {
2608: if (ref($settings->{$type}) eq 'HASH') {
2609: foreach my $key (keys(%{$settings->{$type}})) {
2610: if ($key eq 'namedusers') {
2611: $namedaccess{$type} = $settings->{$type}->{$key};
2612: } elsif ($key eq 'machines') {
2613: $machineaccess{$type} = $settings->{$type}->{$key};
2614: }
2615: }
2616: }
2617: }
2618: }
2619: }
1.81 raeburn 2620: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 2621: my $rownum = 0;
2622: my $css_class;
2623: foreach my $type (@pages) {
2624: $rownum ++;
2625: $css_class = $rownum%2?' class="LC_odd_row"':'';
2626: $datatable .= '<tr'.$css_class.'>'.
2627: '<td><span class="LC_nobreak">'.
2628: $titles->{$type}.'</span></td>'.
2629: '<td class="LC_left_item">'.
2630: '<input type="text" name="'.$type.'_namedusers" '.
2631: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
2632: '<td class="LC_right_item">'.
2633: '<span class="LC_nobreak">'.
2634: '<input type="text" name="'.$type.'_machines" '.
2635: 'value="'.$machineaccess{$type}.'" size="10" />'.
2636: '</td></tr>'."\n";
2637: }
2638: $$rowtotal += $rownum;
2639: return $datatable;
2640: }
2641:
2642: sub serverstatus_pages {
2643: return ('userstatus','lonstatus','loncron','server-status','codeversions',
2644: 'clusterstatus','metadata_keywords','metadata_harvest',
2645: 'takeoffline','takeonline','showenv');
2646: }
2647:
1.49 raeburn 2648: sub coursecategories_javascript {
2649: my ($settings) = @_;
1.57 raeburn 2650: my ($output,$jstext,$cathash);
1.49 raeburn 2651: if (ref($settings) eq 'HASH') {
1.57 raeburn 2652: $cathash = $settings->{'cats'};
2653: }
2654: if (ref($cathash) eq 'HASH') {
1.49 raeburn 2655: my (@cats,@jsarray,%idx);
1.57 raeburn 2656: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 2657: if (@jsarray > 0) {
2658: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
2659: for (my $i=0; $i<@jsarray; $i++) {
2660: if (ref($jsarray[$i]) eq 'ARRAY') {
2661: my $catstr = join('","',@{$jsarray[$i]});
2662: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
2663: }
2664: }
2665: }
2666: } else {
2667: $jstext = ' var categories = Array(1);'."\n".
2668: ' categories[0] = Array("instcode_pos");'."\n";
2669: }
2670: $output = <<"ENDSCRIPT";
2671: <script type="text/javascript">
2672: function reorderCats(form,parent,item,idx) {
2673: var changedVal;
2674: $jstext
2675: var newpos = 'addcategory_pos';
2676: var current = new Array;
2677: if (parent == '') {
2678: var has_instcode = 0;
2679: var maxtop = categories[idx].length;
2680: for (var j=0; j<maxtop; j++) {
2681: if (categories[idx][j] == 'instcode::0') {
2682: has_instcode == 1;
2683: }
2684: }
2685: if (has_instcode == 0) {
2686: categories[idx][maxtop] = 'instcode_pos';
2687: }
2688: } else {
2689: newpos += '_'+parent;
2690: }
2691: var maxh = 1 + categories[idx].length;
2692: var current = new Array;
2693: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2694: if (item == newpos) {
2695: changedVal = newitemVal;
2696: } else {
2697: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2698: current[newitemVal] = newpos;
2699: }
2700: for (var i=0; i<categories[idx].length; i++) {
2701: var elementName = categories[idx][i];
2702: if (elementName != item) {
2703: if (form.elements[elementName]) {
2704: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2705: current[currVal] = elementName;
2706: }
2707: }
2708: }
2709: var oldVal;
2710: for (var j=0; j<maxh; j++) {
2711: if (current[j] == undefined) {
2712: oldVal = j;
2713: }
2714: }
2715: if (oldVal < changedVal) {
2716: for (var k=oldVal+1; k<=changedVal ; k++) {
2717: var elementName = current[k];
2718: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2719: }
2720: } else {
2721: for (var k=changedVal; k<oldVal; k++) {
2722: var elementName = current[k];
2723: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2724: }
2725: }
2726: return;
2727: }
2728: </script>
2729:
2730: ENDSCRIPT
2731: return $output;
2732: }
2733:
1.48 raeburn 2734: sub initialize_categories {
2735: my ($itemcount) = @_;
2736: my $datatable;
2737: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2738: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
2739:
1.48 raeburn 2740: $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
2741: .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
2742: .'<option value="1">2</option></select> '
2743: .&mt('Official courses (with institutional codes)')
2744: .'</span></td><td><span class="LC_nobreak">'
2745: .'<label><input type="radio" name="instcode" value="1" checked="checked" />'
2746: .&mt('Display').'</label> <label>'
2747: .'<input type="radio" name="instcode" value="0" />'.&mt('Do not display')
2748: .'</label></span></td></tr>';
2749: $itemcount ++;
2750: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2751: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 2752: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.53 raeburn 2753: .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
1.48 raeburn 2754: .'<option value="1" selected="selected">2</option></select> '
2755: .&mt('Add category').'</td><td>'.&mt('Name:')
2756: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
2757: return $datatable;
2758: }
2759:
2760: sub build_category_rows {
1.49 raeburn 2761: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
2762: my ($text,$name,$item,$chgstr);
1.48 raeburn 2763: if (ref($cats) eq 'ARRAY') {
2764: my $maxdepth = scalar(@{$cats});
2765: if (ref($cats->[$depth]) eq 'HASH') {
2766: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
2767: my $numchildren = @{$cats->[$depth]{$parent}};
2768: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
2769: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 2770: my ($idxnum,$parent_name,$parent_item);
2771: my $higher = $depth - 1;
2772: if ($higher == 0) {
2773: $parent_name = &escape($parent).'::'.$higher;
2774: } else {
2775: if (ref($path) eq 'ARRAY') {
2776: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2777: }
2778: }
2779: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 2780: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 2781: if ($j < $numchildren) {
1.48 raeburn 2782: $name = $cats->[$depth]{$parent}[$j];
2783: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 2784: $idxnum = $idx->{$item};
2785: } else {
2786: $name = $parent_name;
2787: $item = $parent_item;
1.48 raeburn 2788: }
1.49 raeburn 2789: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
2790: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 2791: for (my $i=0; $i<=$numchildren; $i++) {
2792: my $vpos = $i+1;
2793: my $selstr;
2794: if ($j == $i) {
2795: $selstr = ' selected="selected" ';
2796: }
2797: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
2798: }
2799: $text .= '</select> ';
2800: if ($j < $numchildren) {
2801: my $deeper = $depth+1;
2802: $text .= $name.' '
2803: .'<label><input type="checkbox" name="deletecategory" value="'
2804: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
2805: if(ref($path) eq 'ARRAY') {
2806: push(@{$path},$name);
1.49 raeburn 2807: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 2808: pop(@{$path});
2809: }
2810: } else {
1.59 bisitz 2811: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 2812: if ($j == $numchildren) {
2813: $text .= $name;
2814: } else {
2815: $text .= $item;
2816: }
2817: $text .= '" value="" />';
2818: }
2819: $text .= '</td></tr>';
2820: }
2821: $text .= '</table></td>';
2822: } else {
2823: my $higher = $depth-1;
2824: if ($higher == 0) {
2825: $name = &escape($parent).'::'.$higher;
2826: } else {
2827: if (ref($path) eq 'ARRAY') {
2828: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2829: }
2830: }
2831: my $colspan;
2832: if ($parent ne 'instcode') {
2833: $colspan = $maxdepth - $depth - 1;
2834: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
2835: }
2836: }
2837: }
2838: }
2839: return $text;
2840: }
2841:
1.33 raeburn 2842: sub modifiable_userdata_row {
1.63 raeburn 2843: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 2844: my $rolename;
1.63 raeburn 2845: if ($context eq 'selfcreate') {
2846: if (ref($usertypes) eq 'HASH') {
2847: $rolename = $usertypes->{$role};
2848: } else {
2849: $rolename = $role;
2850: }
1.33 raeburn 2851: } else {
1.63 raeburn 2852: if ($role eq 'cr') {
2853: $rolename = &mt('Custom role');
2854: } else {
2855: $rolename = &Apache::lonnet::plaintext($role);
2856: }
1.33 raeburn 2857: }
2858: my @fields = ('lastname','firstname','middlename','generation',
2859: 'permanentemail','id');
2860: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2861: my $output;
2862: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2863: $output = '<tr '.$css_class.'>'.
2864: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
2865: '<td class="LC_left_item" colspan="2"><table>';
2866: my $rem;
2867: my %checks;
2868: if (ref($settings) eq 'HASH') {
2869: if (ref($settings->{$context}) eq 'HASH') {
2870: if (ref($settings->{$context}->{$role}) eq 'HASH') {
2871: foreach my $field (@fields) {
2872: if ($settings->{$context}->{$role}->{$field}) {
2873: $checks{$field} = ' checked="checked" ';
2874: }
2875: }
2876: }
2877: }
2878: }
2879: for (my $i=0; $i<@fields; $i++) {
2880: my $rem = $i%($numinrow);
2881: if ($rem == 0) {
2882: if ($i > 0) {
2883: $output .= '</tr>';
2884: }
2885: $output .= '<tr>';
2886: }
2887: my $check = ' ';
2888: if (exists($checks{$fields[$i]})) {
2889: $check = $checks{$fields[$i]}
2890: } else {
2891: if ($role eq 'st') {
2892: if (ref($settings) ne 'HASH') {
2893: $check = ' checked="checked" ';
2894: }
2895: }
2896: }
2897: $output .= '<td class="LC_left_item">'.
2898: '<span class="LC_nobreak"><label>'.
2899: '<input type="checkbox" name="canmodify_'.$role.'" '.
2900: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
2901: '</label></span></td>';
2902: $rem = @fields%($numinrow);
2903: }
2904: my $colsleft = $numinrow - $rem;
2905: if ($colsleft > 1 ) {
2906: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2907: ' </td>';
2908: } elsif ($colsleft == 1) {
2909: $output .= '<td class="LC_left_item"> </td>';
2910: }
2911: $output .= '</tr></table></td></tr>';
2912: return $output;
2913: }
1.28 raeburn 2914:
1.93 raeburn 2915: sub insttypes_row {
2916: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
2917: my %lt = &Apache::lonlocal::texthash (
2918: cansearch => 'Users allowed to search',
2919: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
2920: );
2921: my $showdom;
2922: if ($context eq 'cansearch') {
2923: $showdom = ' ('.$dom.')';
2924: }
1.25 raeburn 2925: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 2926: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 2927: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 2928: my $rem;
2929: if (ref($types) eq 'ARRAY') {
2930: for (my $i=0; $i<@{$types}; $i++) {
2931: if (defined($usertypes->{$types->[$i]})) {
2932: my $rem = $i%($numinrow);
2933: if ($rem == 0) {
2934: if ($i > 0) {
2935: $output .= '</tr>';
2936: }
2937: $output .= '<tr>';
1.23 raeburn 2938: }
1.26 raeburn 2939: my $check = ' ';
1.99 raeburn 2940: if (ref($settings) eq 'HASH') {
2941: if (ref($settings->{$context}) eq 'ARRAY') {
2942: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
2943: $check = ' checked="checked" ';
2944: }
2945: } elsif ($context eq 'statustocreate') {
1.26 raeburn 2946: $check = ' checked="checked" ';
2947: }
1.23 raeburn 2948: }
1.26 raeburn 2949: $output .= '<td class="LC_left_item">'.
2950: '<span class="LC_nobreak"><label>'.
1.93 raeburn 2951: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 2952: 'value="'.$types->[$i].'"'.$check.'/>'.
2953: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 2954: }
2955: }
1.26 raeburn 2956:
2957: $rem = @{$types}%($numinrow);
1.23 raeburn 2958: }
2959: my $colsleft = $numinrow - $rem;
2960: if ($colsleft > 1) {
1.25 raeburn 2961: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 2962: } else {
1.25 raeburn 2963: $output .= '<td class="LC_left_item">';
1.23 raeburn 2964: }
2965: my $defcheck = ' ';
1.99 raeburn 2966: if (ref($settings) eq 'HASH') {
2967: if (ref($settings->{$context}) eq 'ARRAY') {
2968: if (grep(/^default$/,@{$settings->{$context}})) {
2969: $defcheck = ' checked="checked" ';
2970: }
2971: } elsif ($context eq 'statustocreate') {
1.26 raeburn 2972: $defcheck = ' checked="checked" ';
2973: }
1.23 raeburn 2974: }
1.25 raeburn 2975: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 2976: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 2977: 'value="default"'.$defcheck.'/>'.
2978: $othertitle.'</label></span></td>'.
2979: '</tr></table></td></tr>';
2980: return $output;
1.23 raeburn 2981: }
2982:
2983: sub sorted_searchtitles {
2984: my %searchtitles = &Apache::lonlocal::texthash(
2985: 'uname' => 'username',
2986: 'lastname' => 'last name',
2987: 'lastfirst' => 'last name, first name',
2988: );
2989: my @titleorder = ('uname','lastname','lastfirst');
2990: return (\%searchtitles,\@titleorder);
2991: }
2992:
1.25 raeburn 2993: sub sorted_searchtypes {
2994: my %srchtypes_desc = (
2995: exact => 'is exact match',
2996: contains => 'contains ..',
2997: begins => 'begins with ..',
2998: );
2999: my @srchtypeorder = ('exact','begins','contains');
3000: return (\%srchtypes_desc,\@srchtypeorder);
3001: }
3002:
1.3 raeburn 3003: sub usertype_update_row {
3004: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
3005: my $datatable;
3006: my $numinrow = 4;
3007: foreach my $type (@{$types}) {
3008: if (defined($usertypes->{$type})) {
3009: $$rownums ++;
3010: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
3011: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
3012: '</td><td class="LC_left_item"><table>';
3013: for (my $i=0; $i<@{$fields}; $i++) {
3014: my $rem = $i%($numinrow);
3015: if ($rem == 0) {
3016: if ($i > 0) {
3017: $datatable .= '</tr>';
3018: }
3019: $datatable .= '<tr>';
3020: }
3021: my $check = ' ';
1.39 raeburn 3022: if (ref($settings) eq 'HASH') {
3023: if (ref($settings->{'fields'}) eq 'HASH') {
3024: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
3025: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
3026: $check = ' checked="checked" ';
3027: }
1.3 raeburn 3028: }
3029: }
3030: }
3031:
3032: if ($i == @{$fields}-1) {
3033: my $colsleft = $numinrow - $rem;
3034: if ($colsleft > 1) {
3035: $datatable .= '<td colspan="'.$colsleft.'">';
3036: } else {
3037: $datatable .= '<td>';
3038: }
3039: } else {
3040: $datatable .= '<td>';
3041: }
1.8 raeburn 3042: $datatable .= '<span class="LC_nobreak"><label>'.
3043: '<input type="checkbox" name="updateable_'.$type.
3044: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
3045: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 3046: }
3047: $datatable .= '</tr></table></td></tr>';
3048: }
3049: }
3050: return $datatable;
1.1 raeburn 3051: }
3052:
3053: sub modify_login {
1.9 raeburn 3054: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 3055: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 3056: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 3057: adminmail => 'Display administrator E-mail address',
1.43 raeburn 3058: newuser => 'Link for visitors to create a user account',
1.41 raeburn 3059: loginheader => 'Log-in box header');
1.3 raeburn 3060: my @offon = ('off','on');
1.6 raeburn 3061: my %loginhash;
1.9 raeburn 3062: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
3063: \%domconfig,\%loginhash);
1.43 raeburn 3064: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3065: foreach my $item (@toggles) {
3066: $loginhash{login}{$item} = $env{'form.'.$item};
3067: }
1.41 raeburn 3068: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 3069: if (ref($colchanges{'login'}) eq 'HASH') {
3070: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
3071: \%loginhash);
3072: }
1.1 raeburn 3073: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
3074: $dom);
3075: if ($putresult eq 'ok') {
1.43 raeburn 3076: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3077: my %defaultchecked = (
3078: 'coursecatalog' => 'on',
3079: 'adminmail' => 'off',
1.43 raeburn 3080: 'newuser' => 'off',
1.42 raeburn 3081: );
1.55 raeburn 3082: if (ref($domconfig{'login'}) eq 'HASH') {
3083: foreach my $item (@toggles) {
3084: if ($defaultchecked{$item} eq 'on') {
3085: if (($domconfig{'login'}{$item} eq '0') &&
3086: ($env{'form.'.$item} eq '1')) {
3087: $changes{$item} = 1;
3088: } elsif (($domconfig{'login'}{$item} eq '' ||
3089: $domconfig{'login'}{$item} eq '1') &&
3090: ($env{'form.'.$item} eq '0')) {
3091: $changes{$item} = 1;
3092: }
3093: } elsif ($defaultchecked{$item} eq 'off') {
3094: if (($domconfig{'login'}{$item} eq '1') &&
3095: ($env{'form.'.$item} eq '0')) {
3096: $changes{$item} = 1;
3097: } elsif (($domconfig{'login'}{$item} eq '' ||
3098: $domconfig{'login'}{$item} eq '0') &&
3099: ($env{'form.'.$item} eq '1')) {
3100: $changes{$item} = 1;
3101: }
1.42 raeburn 3102: }
3103: }
1.55 raeburn 3104: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
3105: ($env{'form.loginheader'} eq 'image')) {
3106: $changes{'loginheader'} = 1;
3107: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
3108: $domconfig{'login'}{'loginheader'} eq 'image') &&
3109: ($env{'form.loginheader'} eq 'text')) {
3110: $changes{'loginheader'} = 1;
3111: }
1.41 raeburn 3112: }
1.6 raeburn 3113: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 3114: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 3115: $resulttext = &mt('Changes made:').'<ul>';
3116: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 3117: if ($item eq 'loginheader') {
3118: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
3119: } else {
3120: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
3121: }
1.1 raeburn 3122: }
1.6 raeburn 3123: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 3124: } else {
3125: $resulttext = &mt('No changes made to log-in page settings');
3126: }
3127: } else {
1.11 albertel 3128: $resulttext = '<span class="LC_error">'.
3129: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3130: }
1.6 raeburn 3131: if ($errors) {
1.9 raeburn 3132: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 3133: $errors.'</ul>';
3134: }
3135: return $resulttext;
3136: }
3137:
3138: sub color_font_choices {
3139: my %choices =
3140: &Apache::lonlocal::texthash (
3141: img => "Header",
3142: bgs => "Background colors",
3143: links => "Link colors",
1.55 raeburn 3144: images => "Images",
1.6 raeburn 3145: font => "Font color",
1.97 tempelho 3146: fontmenu => "Font Menu",
1.76 raeburn 3147: pgbg => "Page",
1.6 raeburn 3148: tabbg => "Header",
3149: sidebg => "Border",
3150: link => "Link",
3151: alink => "Active link",
3152: vlink => "Visited link",
3153: );
3154: return %choices;
3155: }
3156:
3157: sub modify_rolecolors {
1.9 raeburn 3158: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 3159: my ($resulttext,%rolehash);
3160: $rolehash{'rolecolors'} = {};
1.55 raeburn 3161: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
3162: if ($domconfig{'rolecolors'} eq '') {
3163: $domconfig{'rolecolors'} = {};
3164: }
3165: }
1.9 raeburn 3166: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 3167: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
3168: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
3169: $dom);
3170: if ($putresult eq 'ok') {
3171: if (keys(%changes) > 0) {
1.41 raeburn 3172: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 3173: $resulttext = &display_colorchgs($dom,\%changes,$roles,
3174: $rolehash{'rolecolors'});
3175: } else {
3176: $resulttext = &mt('No changes made to default color schemes');
3177: }
3178: } else {
1.11 albertel 3179: $resulttext = '<span class="LC_error">'.
3180: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 3181: }
3182: if ($errors) {
3183: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
3184: $errors.'</ul>';
3185: }
3186: return $resulttext;
3187: }
3188:
3189: sub modify_colors {
1.9 raeburn 3190: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 3191: my (%changes,%choices);
1.51 raeburn 3192: my @bgs;
1.6 raeburn 3193: my @links = ('link','alink','vlink');
1.41 raeburn 3194: my @logintext;
1.6 raeburn 3195: my @images;
3196: my $servadm = $r->dir_config('lonAdmEMail');
3197: my $errors;
3198: foreach my $role (@{$roles}) {
3199: if ($role eq 'login') {
1.12 raeburn 3200: %choices = &login_choices();
1.41 raeburn 3201: @logintext = ('textcol','bgcol');
1.12 raeburn 3202: } else {
3203: %choices = &color_font_choices();
3204: }
3205: if ($role eq 'login') {
1.41 raeburn 3206: @images = ('img','logo','domlogo','login');
1.51 raeburn 3207: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 3208: } else {
3209: @images = ('img');
1.51 raeburn 3210: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 3211: }
3212: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.97 tempelho 3213: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.41 raeburn 3214: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 3215: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
3216: }
1.46 raeburn 3217: my ($configuserok,$author_ok,$switchserver) =
3218: &config_check($dom,$confname,$servadm);
1.9 raeburn 3219: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 3220: if (ref($domconfig->{$role}) ne 'HASH') {
3221: $domconfig->{$role} = {};
3222: }
1.8 raeburn 3223: foreach my $img (@images) {
1.70 raeburn 3224: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
3225: if (defined($env{'form.login_showlogo_'.$img})) {
3226: $confhash->{$role}{'showlogo'}{$img} = 1;
3227: } else {
3228: $confhash->{$role}{'showlogo'}{$img} = 0;
3229: }
3230: }
1.18 albertel 3231: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
3232: && !defined($domconfig->{$role}{$img})
3233: && !$env{'form.'.$role.'_del_'.$img}
3234: && $env{'form.'.$role.'_import_'.$img}) {
3235: # import the old configured image from the .tab setting
3236: # if they haven't provided a new one
3237: $domconfig->{$role}{$img} =
3238: $env{'form.'.$role.'_import_'.$img};
3239: }
1.6 raeburn 3240: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 3241: my $error;
1.6 raeburn 3242: if ($configuserok eq 'ok') {
1.9 raeburn 3243: if ($switchserver) {
1.12 raeburn 3244: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 3245: } else {
3246: if ($author_ok eq 'ok') {
3247: my ($result,$logourl) =
3248: &publishlogo($r,'upload',$role.'_'.$img,
3249: $dom,$confname,$img,$width,$height);
3250: if ($result eq 'ok') {
3251: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 3252: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3253: } else {
1.12 raeburn 3254: $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 3255: }
3256: } else {
1.46 raeburn 3257: $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
1.6 raeburn 3258: }
3259: }
3260: } else {
1.46 raeburn 3261: $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
1.9 raeburn 3262: }
3263: if ($error) {
1.8 raeburn 3264: &Apache::lonnet::logthis($error);
1.11 albertel 3265: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 3266: }
3267: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 3268: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
3269: my $error;
3270: if ($configuserok eq 'ok') {
3271: # is confname an author?
3272: if ($switchserver eq '') {
3273: if ($author_ok eq 'ok') {
3274: my ($result,$logourl) =
3275: &publishlogo($r,'copy',$domconfig->{$role}{$img},
3276: $dom,$confname,$img,$width,$height);
3277: if ($result eq 'ok') {
3278: $confhash->{$role}{$img} = $logourl;
1.18 albertel 3279: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3280: }
3281: }
3282: }
3283: }
1.6 raeburn 3284: }
3285: }
3286: }
3287: if (ref($domconfig) eq 'HASH') {
3288: if (ref($domconfig->{$role}) eq 'HASH') {
3289: foreach my $img (@images) {
3290: if ($domconfig->{$role}{$img} ne '') {
3291: if ($env{'form.'.$role.'_del_'.$img}) {
3292: $confhash->{$role}{$img} = '';
1.12 raeburn 3293: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3294: } else {
1.9 raeburn 3295: if ($confhash->{$role}{$img} eq '') {
3296: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
3297: }
1.6 raeburn 3298: }
3299: } else {
3300: if ($env{'form.'.$role.'_del_'.$img}) {
3301: $confhash->{$role}{$img} = '';
1.12 raeburn 3302: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3303: }
3304: }
1.70 raeburn 3305: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
3306: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
3307: if ($confhash->{$role}{'showlogo'}{$img} ne
3308: $domconfig->{$role}{'showlogo'}{$img}) {
3309: $changes{$role}{'showlogo'}{$img} = 1;
3310: }
3311: } else {
3312: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3313: $changes{$role}{'showlogo'}{$img} = 1;
3314: }
3315: }
3316: }
3317: }
1.6 raeburn 3318: if ($domconfig->{$role}{'font'} ne '') {
3319: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
3320: $changes{$role}{'font'} = 1;
3321: }
3322: } else {
3323: if ($confhash->{$role}{'font'}) {
3324: $changes{$role}{'font'} = 1;
3325: }
3326: }
1.97 tempelho 3327: if ($domconfig->{$role}{'fontmenu'} ne '') {
3328: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
3329: $changes{$role}{'fontmenu'} = 1;
3330: }
3331: } else {
3332: if ($confhash->{$role}{'fontmenu'}) {
3333: $changes{$role}{'fontmenu'} = 1;
3334: }
3335: }
1.6 raeburn 3336: foreach my $item (@bgs) {
3337: if ($domconfig->{$role}{$item} ne '') {
3338: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3339: $changes{$role}{'bgs'}{$item} = 1;
3340: }
3341: } else {
3342: if ($confhash->{$role}{$item}) {
3343: $changes{$role}{'bgs'}{$item} = 1;
3344: }
3345: }
3346: }
3347: foreach my $item (@links) {
3348: if ($domconfig->{$role}{$item} ne '') {
3349: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3350: $changes{$role}{'links'}{$item} = 1;
3351: }
3352: } else {
3353: if ($confhash->{$role}{$item}) {
3354: $changes{$role}{'links'}{$item} = 1;
3355: }
3356: }
3357: }
1.41 raeburn 3358: foreach my $item (@logintext) {
3359: if ($domconfig->{$role}{$item} ne '') {
3360: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3361: $changes{$role}{'logintext'}{$item} = 1;
3362: }
3363: } else {
3364: if ($confhash->{$role}{$item}) {
3365: $changes{$role}{'logintext'}{$item} = 1;
3366: }
3367: }
3368: }
1.6 raeburn 3369: } else {
3370: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3371: \@logintext,$confhash,\%changes);
1.6 raeburn 3372: }
3373: } else {
3374: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3375: \@logintext,$confhash,\%changes);
1.6 raeburn 3376: }
3377: }
3378: return ($errors,%changes);
3379: }
3380:
1.46 raeburn 3381: sub config_check {
3382: my ($dom,$confname,$servadm) = @_;
3383: my ($configuserok,$author_ok,$switchserver,%currroles);
3384: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
3385: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
3386: $confname,$servadm);
3387: if ($configuserok eq 'ok') {
3388: $switchserver = &check_switchserver($dom,$confname);
3389: if ($switchserver eq '') {
3390: $author_ok = &check_authorstatus($dom,$confname,%currroles);
3391: }
3392: }
3393: return ($configuserok,$author_ok,$switchserver);
3394: }
3395:
1.6 raeburn 3396: sub default_change_checker {
1.41 raeburn 3397: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 3398: foreach my $item (@{$links}) {
3399: if ($confhash->{$role}{$item}) {
3400: $changes->{$role}{'links'}{$item} = 1;
3401: }
3402: }
3403: foreach my $item (@{$bgs}) {
3404: if ($confhash->{$role}{$item}) {
3405: $changes->{$role}{'bgs'}{$item} = 1;
3406: }
3407: }
1.41 raeburn 3408: foreach my $item (@{$logintext}) {
3409: if ($confhash->{$role}{$item}) {
3410: $changes->{$role}{'logintext'}{$item} = 1;
3411: }
3412: }
1.6 raeburn 3413: foreach my $img (@{$images}) {
3414: if ($env{'form.'.$role.'_del_'.$img}) {
3415: $confhash->{$role}{$img} = '';
1.12 raeburn 3416: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 3417: }
1.70 raeburn 3418: if ($role eq 'login') {
3419: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3420: $changes->{$role}{'showlogo'}{$img} = 1;
3421: }
3422: }
1.6 raeburn 3423: }
3424: if ($confhash->{$role}{'font'}) {
3425: $changes->{$role}{'font'} = 1;
3426: }
1.48 raeburn 3427: }
1.6 raeburn 3428:
3429: sub display_colorchgs {
3430: my ($dom,$changes,$roles,$confhash) = @_;
3431: my (%choices,$resulttext);
3432: if (!grep(/^login$/,@{$roles})) {
3433: $resulttext = &mt('Changes made:').'<br />';
3434: }
3435: foreach my $role (@{$roles}) {
3436: if ($role eq 'login') {
3437: %choices = &login_choices();
3438: } else {
3439: %choices = &color_font_choices();
3440: }
3441: if (ref($changes->{$role}) eq 'HASH') {
3442: if ($role ne 'login') {
3443: $resulttext .= '<h4>'.&mt($role).'</h4>';
3444: }
3445: foreach my $key (sort(keys(%{$changes->{$role}}))) {
3446: if ($role ne 'login') {
3447: $resulttext .= '<ul>';
3448: }
3449: if (ref($changes->{$role}{$key}) eq 'HASH') {
3450: if ($role ne 'login') {
3451: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
3452: }
3453: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 3454: if (($role eq 'login') && ($key eq 'showlogo')) {
3455: if ($confhash->{$role}{$key}{$item}) {
3456: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
3457: } else {
3458: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
3459: }
3460: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 3461: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
3462: } else {
1.12 raeburn 3463: my $newitem = $confhash->{$role}{$item};
3464: if ($key eq 'images') {
3465: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
3466: }
3467: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 3468: }
3469: }
3470: if ($role ne 'login') {
3471: $resulttext .= '</ul></li>';
3472: }
3473: } else {
3474: if ($confhash->{$role}{$key} eq '') {
3475: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
3476: } else {
3477: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
3478: }
3479: }
3480: if ($role ne 'login') {
3481: $resulttext .= '</ul>';
3482: }
3483: }
3484: }
3485: }
1.3 raeburn 3486: return $resulttext;
1.1 raeburn 3487: }
3488:
1.9 raeburn 3489: sub thumb_dimensions {
3490: return ('200','50');
3491: }
3492:
1.16 raeburn 3493: sub check_dimensions {
3494: my ($inputfile) = @_;
3495: my ($fullwidth,$fullheight);
3496: if ($inputfile =~ m|^[/\w.\-]+$|) {
3497: if (open(PIPE,"identify $inputfile 2>&1 |")) {
3498: my $imageinfo = <PIPE>;
3499: if (!close(PIPE)) {
3500: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
3501: }
3502: chomp($imageinfo);
3503: my ($fullsize) =
1.21 raeburn 3504: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 3505: if ($fullsize) {
3506: ($fullwidth,$fullheight) = split(/x/,$fullsize);
3507: }
3508: }
3509: }
3510: return ($fullwidth,$fullheight);
3511: }
3512:
1.9 raeburn 3513: sub check_configuser {
3514: my ($uhome,$dom,$confname,$servadm) = @_;
3515: my ($configuserok,%currroles);
3516: if ($uhome eq 'no_host') {
3517: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
3518: my $configpass = &LONCAPA::Enrollment::create_password();
3519: $configuserok =
3520: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
3521: $configpass,'','','','','',undef,$servadm);
3522: } else {
3523: $configuserok = 'ok';
3524: %currroles =
3525: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
3526: }
3527: return ($configuserok,%currroles);
3528: }
3529:
3530: sub check_authorstatus {
3531: my ($dom,$confname,%currroles) = @_;
3532: my $author_ok;
1.40 raeburn 3533: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 3534: my $start = time;
3535: my $end = 0;
3536: $author_ok =
3537: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 3538: 'au',$end,$start,'','','domconfig');
1.9 raeburn 3539: } else {
3540: $author_ok = 'ok';
3541: }
3542: return $author_ok;
3543: }
3544:
3545: sub publishlogo {
1.46 raeburn 3546: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 3547: my ($output,$fname,$logourl);
3548: if ($action eq 'upload') {
3549: $fname=$env{'form.'.$formname.'.filename'};
3550: chop($env{'form.'.$formname});
3551: } else {
3552: ($fname) = ($formname =~ /([^\/]+)$/);
3553: }
1.46 raeburn 3554: if ($savefileas ne '') {
3555: $fname = $savefileas;
3556: }
1.9 raeburn 3557: $fname=&Apache::lonnet::clean_filename($fname);
3558: # See if there is anything left
3559: unless ($fname) { return ('error: no uploaded file'); }
3560: $fname="$subdir/$fname";
3561: my $filepath='/home/'.$confname.'/public_html';
3562: my ($fnamepath,$file,$fetchthumb);
3563: $file=$fname;
3564: if ($fname=~m|/|) {
3565: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
3566: }
3567: my @parts=split(/\//,$filepath.'/'.$fnamepath);
3568: my $count;
3569: for ($count=4;$count<=$#parts;$count++) {
3570: $filepath.="/$parts[$count]";
3571: if ((-e $filepath)!=1) {
3572: mkdir($filepath,02770);
3573: }
3574: }
3575: # Check for bad extension and disallow upload
3576: if ($file=~/\.(\w+)$/ &&
3577: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
3578: $output =
3579: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
3580: } elsif ($file=~/\.(\w+)$/ &&
3581: !defined(&Apache::loncommon::fileembstyle($1))) {
3582: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
3583: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 3584: $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 3585: } elsif (-d "$filepath/$file") {
3586: $output = &mt('File name is a directory name - rename the file and re-upload');
3587: } else {
3588: my $source = $filepath.'/'.$file;
3589: my $logfile;
3590: if (!open($logfile,">>$source".'.log')) {
3591: return (&mt('No write permission to Construction Space'));
3592: }
3593: print $logfile
3594: "\n================= Publish ".localtime()." ================\n".
3595: $env{'user.name'}.':'.$env{'user.domain'}."\n";
3596: # Save the file
3597: if (!open(FH,'>'.$source)) {
3598: &Apache::lonnet::logthis('Failed to create '.$source);
3599: return (&mt('Failed to create file'));
3600: }
3601: if ($action eq 'upload') {
3602: if (!print FH ($env{'form.'.$formname})) {
3603: &Apache::lonnet::logthis('Failed to write to '.$source);
3604: return (&mt('Failed to write file'));
3605: }
3606: } else {
3607: my $original = &Apache::lonnet::filelocation('',$formname);
3608: if(!copy($original,$source)) {
3609: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
3610: return (&mt('Failed to write file'));
3611: }
3612: }
3613: close(FH);
3614: chmod(0660, $source); # Permissions to rw-rw---.
3615:
3616: my $docroot=$r->dir_config('lonDocRoot');
3617: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
3618: my $copyfile=$targetdir.'/'.$file;
3619:
3620: my @parts=split(/\//,$targetdir);
3621: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
3622: for (my $count=5;$count<=$#parts;$count++) {
3623: $path.="/$parts[$count]";
3624: if (!-e $path) {
3625: print $logfile "\nCreating directory ".$path;
3626: mkdir($path,02770);
3627: }
3628: }
3629: my $versionresult;
3630: if (-e $copyfile) {
3631: $versionresult = &logo_versioning($targetdir,$file,$logfile);
3632: } else {
3633: $versionresult = 'ok';
3634: }
3635: if ($versionresult eq 'ok') {
3636: if (copy($source,$copyfile)) {
3637: print $logfile "\nCopied original source to ".$copyfile."\n";
3638: $output = 'ok';
3639: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
3640: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
3641: } else {
3642: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
3643: $output = &mt('Failed to copy file to RES space').", $!";
3644: }
3645: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
3646: my $inputfile = $filepath.'/'.$file;
3647: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 3648: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
3649: if ($fullwidth ne '' && $fullheight ne '') {
3650: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
3651: my $thumbsize = $thumbwidth.'x'.$thumbheight;
3652: system("convert -sample $thumbsize $inputfile $outfile");
3653: chmod(0660, $filepath.'/tn-'.$file);
3654: if (-e $outfile) {
3655: my $copyfile=$targetdir.'/tn-'.$file;
3656: if (copy($outfile,$copyfile)) {
3657: print $logfile "\nCopied source to ".$copyfile."\n";
3658: &write_metadata($dom,$confname,$formname,
3659: $targetdir,'tn-'.$file,$logfile);
3660: } else {
3661: print $logfile "\nUnable to write ".$copyfile.
3662: ':'.$!."\n";
3663: }
3664: }
1.9 raeburn 3665: }
3666: }
3667: }
3668: } else {
3669: $output = $versionresult;
3670: }
3671: }
3672: return ($output,$logourl);
3673: }
3674:
3675: sub logo_versioning {
3676: my ($targetdir,$file,$logfile) = @_;
3677: my $target = $targetdir.'/'.$file;
3678: my ($maxversion,$fn,$extn,$output);
3679: $maxversion = 0;
3680: if ($file =~ /^(.+)\.(\w+)$/) {
3681: $fn=$1;
3682: $extn=$2;
3683: }
3684: opendir(DIR,$targetdir);
3685: while (my $filename=readdir(DIR)) {
3686: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
3687: $maxversion=($1>$maxversion)?$1:$maxversion;
3688: }
3689: }
3690: $maxversion++;
3691: print $logfile "\nCreating old version ".$maxversion."\n";
3692: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
3693: if (copy($target,$copyfile)) {
3694: print $logfile "Copied old target to ".$copyfile."\n";
3695: $copyfile=$copyfile.'.meta';
3696: if (copy($target.'.meta',$copyfile)) {
3697: print $logfile "Copied old target metadata to ".$copyfile."\n";
3698: $output = 'ok';
3699: } else {
3700: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
3701: $output = &mt('Failed to copy old meta').", $!, ";
3702: }
3703: } else {
3704: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
3705: $output = &mt('Failed to copy old target').", $!, ";
3706: }
3707: return $output;
3708: }
3709:
3710: sub write_metadata {
3711: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
3712: my (%metadatafields,%metadatakeys,$output);
3713: $metadatafields{'title'}=$formname;
3714: $metadatafields{'creationdate'}=time;
3715: $metadatafields{'lastrevisiondate'}=time;
3716: $metadatafields{'copyright'}='public';
3717: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
3718: $env{'user.domain'};
3719: $metadatafields{'authorspace'}=$confname.':'.$dom;
3720: $metadatafields{'domain'}=$dom;
3721: {
3722: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
3723: my $mfh;
3724: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
3725: $output = &mt('Could not write metadata');
3726: }
3727: foreach (sort keys %metadatafields) {
3728: unless ($_=~/\./) {
3729: my $unikey=$_;
3730: $unikey=~/^([A-Za-z]+)/;
3731: my $tag=$1;
3732: $tag=~tr/A-Z/a-z/;
3733: print $mfh "\n\<$tag";
3734: foreach (split(/\,/,$metadatakeys{$unikey})) {
3735: my $value=$metadatafields{$unikey.'.'.$_};
3736: $value=~s/\"/\'\'/g;
3737: print $mfh ' '.$_.'="'.$value.'"';
3738: }
3739: print $mfh '>'.
3740: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
3741: .'</'.$tag.'>';
3742: }
3743: }
3744: $output = 'ok';
3745: print $logfile "\nWrote metadata";
3746: close($mfh);
3747: }
3748: }
3749:
3750: sub check_switchserver {
3751: my ($dom,$confname) = @_;
3752: my ($allowed,$switchserver);
3753: my $home = &Apache::lonnet::homeserver($confname,$dom);
3754: if ($home eq 'no_host') {
3755: $home = &Apache::lonnet::domain($dom,'primary');
3756: }
3757: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 3758: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3759: if (!$allowed) {
3760: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 3761: }
3762: return $switchserver;
3763: }
3764:
1.1 raeburn 3765: sub modify_quotas {
1.86 raeburn 3766: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 3767: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
3768: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 3769: if ($action eq 'quotas') {
3770: $context = 'tools';
3771: } else {
3772: $context = $action;
3773: }
3774: if ($context eq 'requestcourses') {
1.98 raeburn 3775: @usertools = ('official','unofficial','community');
1.101 raeburn 3776: @options =('norequest','approve','autolimit','validate');
3777: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
3778: %titles = &courserequest_titles();
3779: $toolregexp = join('|',@usertools);
3780: %conditions = &courserequest_conditions();
1.86 raeburn 3781: } else {
3782: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 3783: %titles = &tool_titles();
1.86 raeburn 3784: }
1.72 raeburn 3785: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 3786: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 3787: foreach my $key (keys(%env)) {
1.101 raeburn 3788: if ($context eq 'requestcourses') {
3789: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
3790: my $item = $1;
3791: my $type = $2;
3792: if ($type =~ /^limit_(.+)/) {
3793: $limithash{$item}{$1} = $env{$key};
3794: } else {
3795: $confhash{$item}{$type} = $env{$key};
3796: }
3797: }
3798: } else {
1.86 raeburn 3799: if ($key =~ /^form\.quota_(.+)$/) {
3800: $confhash{'defaultquota'}{$1} = $env{$key};
3801: }
1.101 raeburn 3802: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
3803: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
3804: }
1.72 raeburn 3805: }
3806: }
1.102 raeburn 3807: if ($context eq 'requestcourses') {
3808: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
3809: @approvalnotify = sort(@approvalnotify);
3810: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
3811: if (ref($domconfig{$action}) eq 'HASH') {
3812: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
3813: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
3814: $changes{'notify'}{'approval'} = 1;
3815: }
3816: } else {
3817: if ($domconfig{$action}{'notify'}{'approval'}) {
3818: $changes{'notify'}{'approval'} = 1;
3819: }
3820: }
3821: } else {
3822: if ($domconfig{$action}{'notify'}{'approval'}) {
3823: $changes{'notify'}{'approval'} = 1;
3824: }
3825: }
3826: } else {
1.86 raeburn 3827: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
3828: }
1.72 raeburn 3829: foreach my $item (@usertools) {
3830: foreach my $type (@{$types},'default','_LC_adv') {
1.101 raeburn 3831: if ($context eq 'requestcourses') {
3832: if ($confhash{$item}{$type} eq 'autolimit') {
3833: $confhash{$item}{$type} .= '=';
3834: unless ($limithash{$item}{$type} =~ /\D/) {
3835: $confhash{$item}{$type} .= $limithash{$item}{$type};
3836: }
3837: }
1.72 raeburn 3838: } else {
1.101 raeburn 3839: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
3840: $confhash{$item}{$type} = 1;
3841: } else {
3842: $confhash{$item}{$type} = 0;
3843: }
1.72 raeburn 3844: }
1.86 raeburn 3845: if (ref($domconfig{$action}) eq 'HASH') {
3846: if (ref($domconfig{$action}{$item}) eq 'HASH') {
3847: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
3848: $changes{$item}{$type} = 1;
3849: }
3850: } else {
3851: if ($context eq 'requestcourses') {
1.101 raeburn 3852: if ($confhash{$item}{$type} ne 'norequest') {
1.86 raeburn 3853: $changes{$item}{$type} = 1;
3854: }
3855: } else {
3856: if (!$confhash{$item}{$type}) {
3857: $changes{$item}{$type} = 1;
3858: }
3859: }
3860: }
3861: } else {
3862: if ($context eq 'requestcourses') {
1.101 raeburn 3863: if ($confhash{$item}{$type} eq 'norequest') {
1.72 raeburn 3864: $changes{$item}{$type} = 1;
3865: }
3866: } else {
3867: if (!$confhash{$item}{$type}) {
3868: $changes{$item}{$type} = 1;
3869: }
3870: }
3871: }
1.1 raeburn 3872: }
3873: }
1.86 raeburn 3874: unless ($context eq 'requestcourses') {
3875: if (ref($domconfig{'quotas'}) eq 'HASH') {
3876: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3877: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
3878: if (exists($confhash{'defaultquota'}{$key})) {
3879: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
3880: $changes{'defaultquota'}{$key} = 1;
3881: }
3882: } else {
3883: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 3884: }
3885: }
1.86 raeburn 3886: } else {
3887: foreach my $key (keys(%{$domconfig{'quotas'}})) {
3888: if (exists($confhash{'defaultquota'}{$key})) {
3889: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
3890: $changes{'defaultquota'}{$key} = 1;
3891: }
3892: } else {
3893: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 3894: }
1.1 raeburn 3895: }
3896: }
3897: }
1.86 raeburn 3898: if (ref($confhash{'defaultquota'}) eq 'HASH') {
3899: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
3900: if (ref($domconfig{'quotas'}) eq 'HASH') {
3901: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3902: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
3903: $changes{'defaultquota'}{$key} = 1;
3904: }
3905: } else {
3906: if (!exists($domconfig{'quotas'}{$key})) {
3907: $changes{'defaultquota'}{$key} = 1;
3908: }
1.72 raeburn 3909: }
3910: } else {
1.86 raeburn 3911: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 3912: }
1.1 raeburn 3913: }
3914: }
3915: }
1.72 raeburn 3916:
3917: foreach my $key (keys(%confhash)) {
3918: $domdefaults{$key} = $confhash{$key};
3919: }
3920:
1.1 raeburn 3921: my %quotahash = (
1.86 raeburn 3922: $action => { %confhash }
1.1 raeburn 3923: );
3924: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
3925: $dom);
3926: if ($putresult eq 'ok') {
3927: if (keys(%changes) > 0) {
1.72 raeburn 3928: my $cachetime = 24*60*60;
3929: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
3930:
1.1 raeburn 3931: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 3932: unless ($context eq 'requestcourses') {
3933: if (ref($changes{'defaultquota'}) eq 'HASH') {
3934: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
3935: foreach my $type (@{$types},'default') {
3936: if (defined($changes{'defaultquota'}{$type})) {
3937: my $typetitle = $usertypes->{$type};
3938: if ($type eq 'default') {
3939: $typetitle = $othertitle;
3940: }
3941: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 3942: }
3943: }
1.86 raeburn 3944: $resulttext .= '</ul></li>';
1.72 raeburn 3945: }
3946: }
1.80 raeburn 3947: my %newenv;
1.72 raeburn 3948: foreach my $item (@usertools) {
3949: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 3950: my $newacc =
3951: &Apache::lonnet::usertools_access($env{'user.name'},
3952: $env{'user.domain'},
1.86 raeburn 3953: $item,'reload',$context);
3954: if ($context eq 'requestcourses') {
1.101 raeburn 3955: if ($env{'environment.crsrequest.'.$item} ne $newacc) {
3956: $newenv{'environment.crsrequest.'.$item} = $newacc;
1.86 raeburn 3957: }
3958: } else {
3959: if ($env{'environment.availabletools.'.$item} ne $newacc) {
3960: $newenv{'environment.availabletools.'.$item} = $newacc;
3961: }
1.80 raeburn 3962: }
1.72 raeburn 3963: $resulttext .= '<li>'.$titles{$item}.'<ul>';
3964: foreach my $type (@{$types},'default','_LC_adv') {
3965: if ($changes{$item}{$type}) {
3966: my $typetitle = $usertypes->{$type};
3967: if ($type eq 'default') {
3968: $typetitle = $othertitle;
3969: } elsif ($type eq '_LC_adv') {
3970: $typetitle = 'LON-CAPA Advanced Users';
3971: }
3972: if ($confhash{$item}{$type}) {
1.101 raeburn 3973: if ($context eq 'requestcourses') {
3974: my $cond;
3975: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
3976: if ($1 eq '') {
3977: $cond = &mt('(Automatic processing of any request).');
3978: } else {
3979: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
3980: }
3981: } else {
3982: $cond = $conditions{$confhash{$item}{$type}};
3983: }
3984: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
3985: } else {
3986: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
3987: }
1.72 raeburn 3988: } else {
3989: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
3990: }
3991: }
1.26 raeburn 3992: }
1.72 raeburn 3993: $resulttext .= '</ul></li>';
1.26 raeburn 3994: }
1.1 raeburn 3995: }
1.102 raeburn 3996: if ($action eq 'requestcourses') {
3997: if (ref($changes{'notify'}) eq 'HASH') {
3998: if ($changes{'notify'}{'approval'}) {
3999: if (ref($confhash{'notify'}) eq 'HASH') {
4000: if ($confhash{'notify'}{'approval'}) {
4001: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
4002: } else {
4003: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
4004: }
4005: }
4006: }
4007: }
4008: }
1.1 raeburn 4009: $resulttext .= '</ul>';
1.80 raeburn 4010: if (keys(%newenv)) {
4011: &Apache::lonnet::appenv(\%newenv);
4012: }
1.1 raeburn 4013: } else {
1.86 raeburn 4014: if ($context eq 'requestcourses') {
4015: $resulttext = &mt('No changes made to rights to request creation of courses.');
4016: } else {
1.90 weissno 4017: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 4018: }
1.1 raeburn 4019: }
4020: } else {
1.11 albertel 4021: $resulttext = '<span class="LC_error">'.
4022: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4023: }
1.3 raeburn 4024: return $resulttext;
1.1 raeburn 4025: }
4026:
1.3 raeburn 4027: sub modify_autoenroll {
4028: my ($dom,%domconfig) = @_;
1.1 raeburn 4029: my ($resulttext,%changes);
4030: my %currautoenroll;
4031: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4032: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
4033: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
4034: }
4035: }
4036: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
4037: my %title = ( run => 'Auto-enrollment active',
4038: sender => 'Sender for notification messages');
4039: my @offon = ('off','on');
1.17 raeburn 4040: my $sender_uname = $env{'form.sender_uname'};
4041: my $sender_domain = $env{'form.sender_domain'};
4042: if ($sender_domain eq '') {
4043: $sender_uname = '';
4044: } elsif ($sender_uname eq '') {
4045: $sender_domain = '';
4046: }
1.1 raeburn 4047: my %autoenrollhash = (
4048: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 4049: sender_uname => $sender_uname,
4050: sender_domain => $sender_domain,
1.1 raeburn 4051:
4052: }
4053: );
1.4 raeburn 4054: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
4055: $dom);
1.1 raeburn 4056: if ($putresult eq 'ok') {
4057: if (exists($currautoenroll{'run'})) {
4058: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
4059: $changes{'run'} = 1;
4060: }
4061: } elsif ($autorun) {
4062: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 4063: $changes{'run'} = 1;
1.1 raeburn 4064: }
4065: }
1.17 raeburn 4066: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 4067: $changes{'sender'} = 1;
4068: }
1.17 raeburn 4069: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 4070: $changes{'sender'} = 1;
4071: }
4072: if (keys(%changes) > 0) {
4073: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 4074: if ($changes{'run'}) {
1.1 raeburn 4075: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
4076: }
4077: if ($changes{'sender'}) {
1.17 raeburn 4078: if ($sender_uname eq '' || $sender_domain eq '') {
4079: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
4080: } else {
4081: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
4082: }
1.1 raeburn 4083: }
4084: $resulttext .= '</ul>';
4085: } else {
4086: $resulttext = &mt('No changes made to auto-enrollment settings');
4087: }
4088: } else {
1.11 albertel 4089: $resulttext = '<span class="LC_error">'.
4090: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4091: }
1.3 raeburn 4092: return $resulttext;
1.1 raeburn 4093: }
4094:
4095: sub modify_autoupdate {
1.3 raeburn 4096: my ($dom,%domconfig) = @_;
1.1 raeburn 4097: my ($resulttext,%currautoupdate,%fields,%changes);
4098: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
4099: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
4100: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
4101: }
4102: }
4103: my @offon = ('off','on');
4104: my %title = &Apache::lonlocal::texthash (
4105: run => 'Auto-update:',
4106: classlists => 'Updates to user information in classlists?'
4107: );
1.44 raeburn 4108: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 4109: my %fieldtitles = &Apache::lonlocal::texthash (
4110: id => 'Student/Employee ID',
1.20 raeburn 4111: permanentemail => 'E-mail address',
1.1 raeburn 4112: lastname => 'Last Name',
4113: firstname => 'First Name',
4114: middlename => 'Middle Name',
4115: gen => 'Generation',
4116: );
4117: my $othertitle = &mt('All users');
4118: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 4119: $othertitle = &mt('Other users');
1.1 raeburn 4120: }
4121: foreach my $key (keys(%env)) {
4122: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
4123: push(@{$fields{$1}},$2);
4124: }
4125: }
4126: my %updatehash = (
4127: autoupdate => { run => $env{'form.autoupdate_run'},
4128: classlists => $env{'form.classlists'},
4129: fields => {%fields},
4130: }
4131: );
4132: foreach my $key (keys(%currautoupdate)) {
4133: if (($key eq 'run') || ($key eq 'classlists')) {
4134: if (exists($updatehash{autoupdate}{$key})) {
4135: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
4136: $changes{$key} = 1;
4137: }
4138: }
4139: } elsif ($key eq 'fields') {
4140: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 4141: foreach my $item (@{$types},'default') {
1.1 raeburn 4142: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
4143: my $change = 0;
4144: foreach my $type (@{$currautoupdate{$key}{$item}}) {
4145: if (!exists($fields{$item})) {
4146: $change = 1;
4147: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 4148: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 4149: $change = 1;
4150: }
4151: }
4152: }
4153: if ($change) {
4154: push(@{$changes{$key}},$item);
4155: }
1.26 raeburn 4156: }
1.1 raeburn 4157: }
4158: }
4159: }
4160: }
1.26 raeburn 4161: foreach my $item (@{$types},'default') {
4162: if (defined($fields{$item})) {
4163: if (ref($currautoupdate{'fields'}) eq 'HASH') {
4164: if (!exists($currautoupdate{'fields'}{$item})) {
4165: push(@{$changes{'fields'}},$item);
4166: }
4167: } else {
4168: push(@{$changes{'fields'}},$item);
1.1 raeburn 4169: }
4170: }
4171: }
4172: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
4173: $dom);
4174: if ($putresult eq 'ok') {
4175: if (keys(%changes) > 0) {
4176: $resulttext = &mt('Changes made:').'<ul>';
4177: foreach my $key (sort(keys(%changes))) {
4178: if (ref($changes{$key}) eq 'ARRAY') {
4179: foreach my $item (@{$changes{$key}}) {
4180: my @newvalues;
4181: foreach my $type (@{$fields{$item}}) {
4182: push(@newvalues,$fieldtitles{$type});
4183: }
1.3 raeburn 4184: my $newvaluestr;
4185: if (@newvalues > 0) {
4186: $newvaluestr = join(', ',@newvalues);
4187: } else {
4188: $newvaluestr = &mt('none');
1.6 raeburn 4189: }
1.1 raeburn 4190: if ($item eq 'default') {
1.26 raeburn 4191: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 4192: } else {
1.26 raeburn 4193: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 4194: }
4195: }
4196: } else {
4197: my $newvalue;
4198: if ($key eq 'run') {
4199: $newvalue = $offon[$env{'form.autoupdate_run'}];
4200: } else {
4201: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 4202: }
1.1 raeburn 4203: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
4204: }
4205: }
4206: $resulttext .= '</ul>';
4207: } else {
1.3 raeburn 4208: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 4209: }
4210: } else {
1.11 albertel 4211: $resulttext = '<span class="LC_error">'.
4212: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4213: }
1.3 raeburn 4214: return $resulttext;
1.1 raeburn 4215: }
4216:
1.23 raeburn 4217: sub modify_directorysrch {
4218: my ($dom,%domconfig) = @_;
4219: my ($resulttext,%changes);
4220: my %currdirsrch;
4221: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
4222: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
4223: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
4224: }
4225: }
4226: my %title = ( available => 'Directory search available',
1.24 raeburn 4227: localonly => 'Other domains can search',
1.23 raeburn 4228: searchby => 'Search types',
4229: searchtypes => 'Search latitude');
4230: my @offon = ('off','on');
1.24 raeburn 4231: my @otherdoms = ('Yes','No');
1.23 raeburn 4232:
1.25 raeburn 4233: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 4234: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
4235: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
4236:
1.44 raeburn 4237: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 4238: if (keys(%{$usertypes}) == 0) {
4239: @cansearch = ('default');
4240: } else {
4241: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
4242: foreach my $type (@{$currdirsrch{'cansearch'}}) {
4243: if (!grep(/^\Q$type\E$/,@cansearch)) {
4244: push(@{$changes{'cansearch'}},$type);
4245: }
1.23 raeburn 4246: }
1.26 raeburn 4247: foreach my $type (@cansearch) {
4248: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
4249: push(@{$changes{'cansearch'}},$type);
4250: }
1.23 raeburn 4251: }
1.26 raeburn 4252: } else {
4253: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 4254: }
4255: }
4256:
4257: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
4258: foreach my $by (@{$currdirsrch{'searchby'}}) {
4259: if (!grep(/^\Q$by\E$/,@searchby)) {
4260: push(@{$changes{'searchby'}},$by);
4261: }
4262: }
4263: foreach my $by (@searchby) {
4264: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
4265: push(@{$changes{'searchby'}},$by);
4266: }
4267: }
4268: } else {
4269: push(@{$changes{'searchby'}},@searchby);
4270: }
1.25 raeburn 4271:
4272: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
4273: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
4274: if (!grep(/^\Q$type\E$/,@searchtypes)) {
4275: push(@{$changes{'searchtypes'}},$type);
4276: }
4277: }
4278: foreach my $type (@searchtypes) {
4279: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
4280: push(@{$changes{'searchtypes'}},$type);
4281: }
4282: }
4283: } else {
4284: if (exists($currdirsrch{'searchtypes'})) {
4285: foreach my $type (@searchtypes) {
4286: if ($type ne $currdirsrch{'searchtypes'}) {
4287: push(@{$changes{'searchtypes'}},$type);
4288: }
4289: }
4290: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
4291: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
4292: }
4293: } else {
4294: push(@{$changes{'searchtypes'}},@searchtypes);
4295: }
4296: }
4297:
1.23 raeburn 4298: my %dirsrch_hash = (
4299: directorysrch => { available => $env{'form.dirsrch_available'},
4300: cansearch => \@cansearch,
1.24 raeburn 4301: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 4302: searchby => \@searchby,
1.25 raeburn 4303: searchtypes => \@searchtypes,
1.23 raeburn 4304: }
4305: );
4306: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
4307: $dom);
4308: if ($putresult eq 'ok') {
4309: if (exists($currdirsrch{'available'})) {
4310: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
4311: $changes{'available'} = 1;
4312: }
4313: } else {
4314: if ($env{'form.dirsrch_available'} eq '1') {
4315: $changes{'available'} = 1;
4316: }
4317: }
1.24 raeburn 4318: if (exists($currdirsrch{'localonly'})) {
4319: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
4320: $changes{'localonly'} = 1;
4321: }
4322: } else {
4323: if ($env{'form.dirsrch_localonly'} eq '1') {
4324: $changes{'localonly'} = 1;
4325: }
4326: }
1.23 raeburn 4327: if (keys(%changes) > 0) {
4328: $resulttext = &mt('Changes made:').'<ul>';
4329: if ($changes{'available'}) {
4330: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
4331: }
1.24 raeburn 4332: if ($changes{'localonly'}) {
4333: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
4334: }
4335:
1.23 raeburn 4336: if (ref($changes{'cansearch'}) eq 'ARRAY') {
4337: my $chgtext;
1.26 raeburn 4338: if (ref($usertypes) eq 'HASH') {
4339: if (keys(%{$usertypes}) > 0) {
4340: foreach my $type (@{$types}) {
4341: if (grep(/^\Q$type\E$/,@cansearch)) {
4342: $chgtext .= $usertypes->{$type}.'; ';
4343: }
4344: }
4345: if (grep(/^default$/,@cansearch)) {
4346: $chgtext .= $othertitle;
4347: } else {
4348: $chgtext =~ s/\; $//;
4349: }
4350: $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 4351: }
4352: }
4353: }
4354: if (ref($changes{'searchby'}) eq 'ARRAY') {
4355: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4356: my $chgtext;
4357: foreach my $type (@{$titleorder}) {
4358: if (grep(/^\Q$type\E$/,@searchby)) {
4359: if (defined($searchtitles->{$type})) {
4360: $chgtext .= $searchtitles->{$type}.'; ';
4361: }
4362: }
4363: }
4364: $chgtext =~ s/\; $//;
4365: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
4366: }
1.25 raeburn 4367: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
4368: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
4369: my $chgtext;
4370: foreach my $type (@{$srchtypeorder}) {
4371: if (grep(/^\Q$type\E$/,@searchtypes)) {
4372: if (defined($srchtypes_desc->{$type})) {
4373: $chgtext .= $srchtypes_desc->{$type}.'; ';
4374: }
4375: }
4376: }
4377: $chgtext =~ s/\; $//;
4378: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 4379: }
4380: $resulttext .= '</ul>';
4381: } else {
4382: $resulttext = &mt('No changes made to institution directory search settings');
4383: }
4384: } else {
4385: $resulttext = '<span class="LC_error">'.
1.27 raeburn 4386: &mt('An error occurred: [_1]',$putresult).'</span>';
4387: }
4388: return $resulttext;
4389: }
4390:
1.28 raeburn 4391: sub modify_contacts {
4392: my ($dom,%domconfig) = @_;
4393: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
4394: if (ref($domconfig{'contacts'}) eq 'HASH') {
4395: foreach my $key (keys(%{$domconfig{'contacts'}})) {
4396: $currsetting{$key} = $domconfig{'contacts'}{$key};
4397: }
4398: }
4399: my (%others,%to);
4400: my @contacts = ('supportemail','adminemail');
1.102 raeburn 4401: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
4402: 'requestsmail');
1.28 raeburn 4403: foreach my $type (@mailings) {
4404: @{$newsetting{$type}} =
4405: &Apache::loncommon::get_env_multiple('form.'.$type);
4406: foreach my $item (@contacts) {
4407: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
4408: $contacts_hash{contacts}{$type}{$item} = 1;
4409: } else {
4410: $contacts_hash{contacts}{$type}{$item} = 0;
4411: }
4412: }
4413: $others{$type} = $env{'form.'.$type.'_others'};
4414: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
4415: }
4416: foreach my $item (@contacts) {
4417: $to{$item} = $env{'form.'.$item};
4418: $contacts_hash{'contacts'}{$item} = $to{$item};
4419: }
4420: if (keys(%currsetting) > 0) {
4421: foreach my $item (@contacts) {
4422: if ($to{$item} ne $currsetting{$item}) {
4423: $changes{$item} = 1;
4424: }
4425: }
4426: foreach my $type (@mailings) {
4427: foreach my $item (@contacts) {
4428: if (ref($currsetting{$type}) eq 'HASH') {
4429: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
4430: push(@{$changes{$type}},$item);
4431: }
4432: } else {
4433: push(@{$changes{$type}},@{$newsetting{$type}});
4434: }
4435: }
4436: if ($others{$type} ne $currsetting{$type}{'others'}) {
4437: push(@{$changes{$type}},'others');
4438: }
4439: }
4440: } else {
4441: my %default;
4442: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4443: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4444: $default{'errormail'} = 'adminemail';
4445: $default{'packagesmail'} = 'adminemail';
4446: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 4447: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 4448: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 4449: foreach my $item (@contacts) {
4450: if ($to{$item} ne $default{$item}) {
4451: $changes{$item} = 1;
4452: }
4453: }
4454: foreach my $type (@mailings) {
4455: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
4456:
4457: push(@{$changes{$type}},@{$newsetting{$type}});
4458: }
4459: if ($others{$type} ne '') {
4460: push(@{$changes{$type}},'others');
4461: }
4462: }
4463: }
4464: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
4465: $dom);
4466: if ($putresult eq 'ok') {
4467: if (keys(%changes) > 0) {
4468: my ($titles,$short_titles) = &contact_titles();
4469: $resulttext = &mt('Changes made:').'<ul>';
4470: foreach my $item (@contacts) {
4471: if ($changes{$item}) {
4472: $resulttext .= '<li>'.$titles->{$item}.
4473: &mt(' set to: ').
4474: '<span class="LC_cusr_emph">'.
4475: $to{$item}.'</span></li>';
4476: }
4477: }
4478: foreach my $type (@mailings) {
4479: if (ref($changes{$type}) eq 'ARRAY') {
4480: $resulttext .= '<li>'.$titles->{$type}.': ';
4481: my @text;
4482: foreach my $item (@{$newsetting{$type}}) {
4483: push(@text,$short_titles->{$item});
4484: }
4485: if ($others{$type} ne '') {
4486: push(@text,$others{$type});
4487: }
4488: $resulttext .= '<span class="LC_cusr_emph">'.
4489: join(', ',@text).'</span></li>';
4490: }
4491: }
4492: $resulttext .= '</ul>';
4493: } else {
1.34 raeburn 4494: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 4495: }
4496: } else {
4497: $resulttext = '<span class="LC_error">'.
4498: &mt('An error occurred: [_1].',$putresult).'</span>';
4499: }
4500: return $resulttext;
4501: }
4502:
4503: sub modify_usercreation {
1.27 raeburn 4504: my ($dom,%domconfig) = @_;
1.34 raeburn 4505: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 4506: my $warningmsg;
1.27 raeburn 4507: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4508: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
4509: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
4510: }
4511: }
4512: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 4513: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 4514: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 4515: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 4516: foreach my $item(@contexts) {
1.45 raeburn 4517: if ($item eq 'selfcreate') {
1.50 raeburn 4518: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 4519: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4520: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 4521: if (ref($cancreate{$item}) eq 'ARRAY') {
4522: if (grep(/^login$/,@{$cancreate{$item}})) {
4523: $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');
4524: }
1.43 raeburn 4525: }
4526: }
1.50 raeburn 4527: } else {
4528: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 4529: }
1.34 raeburn 4530: }
1.93 raeburn 4531: my ($othertitle,$usertypes,$types) =
4532: &Apache::loncommon::sorted_inst_types($dom);
4533: if (ref($types) eq 'ARRAY') {
4534: if (@{$types} > 0) {
4535: @{$cancreate{'statustocreate'}} =
4536: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 ! raeburn 4537: } else {
! 4538: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 4539: }
4540: push(@contexts,'statustocreate');
4541: }
1.34 raeburn 4542: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
4543: foreach my $item (@contexts) {
1.93 raeburn 4544: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
4545: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 4546: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 ! raeburn 4547: if (ref($cancreate{$item}) eq 'ARRAY') {
! 4548: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
! 4549: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 4550: push(@{$changes{'cancreate'}},$item);
! 4551: }
1.50 raeburn 4552: }
4553: }
4554: }
4555: } else {
4556: if ($curr_usercreation{'cancreate'}{$item} eq '') {
4557: if (@{$cancreate{$item}} > 0) {
4558: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4559: push(@{$changes{'cancreate'}},$item);
4560: }
4561: }
4562: } else {
4563: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
4564: if (@{$cancreate{$item}} < 3) {
4565: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4566: push(@{$changes{'cancreate'}},$item);
4567: }
4568: }
4569: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
4570: if (@{$cancreate{$item}} > 0) {
4571: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4572: push(@{$changes{'cancreate'}},$item);
4573: }
4574: }
4575: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
4576: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4577: push(@{$changes{'cancreate'}},$item);
4578: }
4579: }
4580: }
4581: }
4582: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4583: foreach my $type (@{$cancreate{$item}}) {
4584: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
4585: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
4586: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4587: push(@{$changes{'cancreate'}},$item);
4588: }
4589: }
4590: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
4591: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
4592: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
4593: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4594: push(@{$changes{'cancreate'}},$item);
4595: }
4596: }
4597: }
4598: }
4599: }
4600: } else {
4601: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
4602: push(@{$changes{'cancreate'}},$item);
4603: }
4604: }
1.27 raeburn 4605: }
1.34 raeburn 4606: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
4607: foreach my $item (@contexts) {
1.43 raeburn 4608: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 4609: if ($cancreate{$item} ne 'any') {
4610: push(@{$changes{'cancreate'}},$item);
4611: }
4612: } else {
4613: if ($cancreate{$item} ne 'none') {
4614: push(@{$changes{'cancreate'}},$item);
4615: }
1.27 raeburn 4616: }
4617: }
4618: } else {
1.43 raeburn 4619: foreach my $item (@contexts) {
1.34 raeburn 4620: push(@{$changes{'cancreate'}},$item);
4621: }
1.27 raeburn 4622: }
1.34 raeburn 4623:
1.27 raeburn 4624: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
4625: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
4626: if (!grep(/^\Q$type\E$/,@username_rule)) {
4627: push(@{$changes{'username_rule'}},$type);
4628: }
4629: }
4630: foreach my $type (@username_rule) {
4631: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
4632: push(@{$changes{'username_rule'}},$type);
4633: }
4634: }
4635: } else {
4636: push(@{$changes{'username_rule'}},@username_rule);
4637: }
4638:
1.32 raeburn 4639: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
4640: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
4641: if (!grep(/^\Q$type\E$/,@id_rule)) {
4642: push(@{$changes{'id_rule'}},$type);
4643: }
4644: }
4645: foreach my $type (@id_rule) {
4646: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
4647: push(@{$changes{'id_rule'}},$type);
4648: }
4649: }
4650: } else {
4651: push(@{$changes{'id_rule'}},@id_rule);
4652: }
4653:
1.43 raeburn 4654: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
4655: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
4656: if (!grep(/^\Q$type\E$/,@email_rule)) {
4657: push(@{$changes{'email_rule'}},$type);
4658: }
4659: }
4660: foreach my $type (@email_rule) {
4661: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
4662: push(@{$changes{'email_rule'}},$type);
4663: }
4664: }
4665: } else {
4666: push(@{$changes{'email_rule'}},@email_rule);
4667: }
4668:
4669: my @authen_contexts = ('author','course','domain');
1.28 raeburn 4670: my @authtypes = ('int','krb4','krb5','loc');
4671: my %authhash;
1.43 raeburn 4672: foreach my $item (@authen_contexts) {
1.28 raeburn 4673: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
4674: foreach my $auth (@authtypes) {
4675: if (grep(/^\Q$auth\E$/,@authallowed)) {
4676: $authhash{$item}{$auth} = 1;
4677: } else {
4678: $authhash{$item}{$auth} = 0;
4679: }
4680: }
4681: }
4682: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 4683: foreach my $item (@authen_contexts) {
1.28 raeburn 4684: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
4685: foreach my $auth (@authtypes) {
4686: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
4687: push(@{$changes{'authtypes'}},$item);
4688: last;
4689: }
4690: }
4691: }
4692: }
4693: } else {
1.43 raeburn 4694: foreach my $item (@authen_contexts) {
1.28 raeburn 4695: push(@{$changes{'authtypes'}},$item);
4696: }
4697: }
4698:
1.27 raeburn 4699: my %usercreation_hash = (
1.28 raeburn 4700: usercreation => {
1.34 raeburn 4701: cancreate => \%cancreate,
1.27 raeburn 4702: username_rule => \@username_rule,
1.32 raeburn 4703: id_rule => \@id_rule,
1.43 raeburn 4704: email_rule => \@email_rule,
1.32 raeburn 4705: authtypes => \%authhash,
1.27 raeburn 4706: }
4707: );
4708:
4709: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
4710: $dom);
1.50 raeburn 4711:
4712: my %selfcreatetypes = (
4713: sso => 'users authenticated by institutional single sign on',
4714: login => 'users authenticated by institutional log-in',
4715: email => 'users who provide a valid e-mail address for use as the username',
4716: );
1.27 raeburn 4717: if ($putresult eq 'ok') {
4718: if (keys(%changes) > 0) {
4719: $resulttext = &mt('Changes made:').'<ul>';
4720: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 4721: my %lt = &usercreation_types();
4722: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 4723: my $chgtext;
4724: unless ($type eq 'statustocreate') {
4725: $chgtext = $lt{$type}.', ';
4726: }
1.45 raeburn 4727: if ($type eq 'selfcreate') {
1.50 raeburn 4728: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 4729: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 4730: } else {
1.100 raeburn 4731: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 4732: foreach my $case (@{$cancreate{$type}}) {
4733: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
4734: }
4735: $chgtext .= '</ul>';
1.100 raeburn 4736: if (ref($cancreate{$type}) eq 'ARRAY') {
4737: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
4738: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
4739: if (@{$cancreate{'statustocreate'}} == 0) {
4740: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
4741: }
4742: }
4743: }
4744: }
1.43 raeburn 4745: }
1.93 raeburn 4746: } elsif ($type eq 'statustocreate') {
1.96 raeburn 4747: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
4748: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
4749: if (@{$cancreate{'selfcreate'}} > 0) {
4750: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 4751:
4752: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 4753: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 4754: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
4755: }
1.96 raeburn 4756: } elsif (ref($usertypes) eq 'HASH') {
4757: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 4758: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
4759: } else {
4760: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
4761: }
4762: $chgtext .= '<ul>';
4763: foreach my $case (@{$cancreate{$type}}) {
4764: if ($case eq 'default') {
4765: $chgtext .= '<li>'.$othertitle.'</li>';
4766: } else {
4767: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 4768: }
4769: }
1.100 raeburn 4770: $chgtext .= '</ul>';
4771: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
4772: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
4773: }
4774: }
4775: } else {
4776: if (@{$cancreate{$type}} == 0) {
4777: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
4778: } else {
4779: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
1.93 raeburn 4780: }
4781: }
4782: }
1.43 raeburn 4783: } else {
4784: if ($cancreate{$type} eq 'none') {
4785: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
4786: } elsif ($cancreate{$type} eq 'any') {
4787: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
4788: } elsif ($cancreate{$type} eq 'official') {
4789: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
4790: } elsif ($cancreate{$type} eq 'unofficial') {
4791: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
4792: }
1.34 raeburn 4793: }
4794: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 4795: }
4796: }
4797: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 4798: my ($rules,$ruleorder) =
4799: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 4800: my $chgtext = '<ul>';
4801: foreach my $type (@username_rule) {
4802: if (ref($rules->{$type}) eq 'HASH') {
4803: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
4804: }
4805: }
4806: $chgtext .= '</ul>';
4807: if (@username_rule > 0) {
4808: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4809: } else {
1.28 raeburn 4810: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 4811: }
4812: }
1.32 raeburn 4813: if (ref($changes{'id_rule'}) eq 'ARRAY') {
4814: my ($idrules,$idruleorder) =
4815: &Apache::lonnet::inst_userrules($dom,'id');
4816: my $chgtext = '<ul>';
4817: foreach my $type (@id_rule) {
4818: if (ref($idrules->{$type}) eq 'HASH') {
4819: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
4820: }
4821: }
4822: $chgtext .= '</ul>';
4823: if (@id_rule > 0) {
4824: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4825: } else {
4826: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
4827: }
4828: }
1.43 raeburn 4829: if (ref($changes{'email_rule'}) eq 'ARRAY') {
4830: my ($emailrules,$emailruleorder) =
4831: &Apache::lonnet::inst_userrules($dom,'email');
4832: my $chgtext = '<ul>';
4833: foreach my $type (@email_rule) {
4834: if (ref($emailrules->{$type}) eq 'HASH') {
4835: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
4836: }
4837: }
4838: $chgtext .= '</ul>';
4839: if (@email_rule > 0) {
4840: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
4841: } else {
4842: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
4843: }
4844: }
4845:
1.28 raeburn 4846: my %authname = &authtype_names();
4847: my %context_title = &context_names();
4848: if (ref($changes{'authtypes'}) eq 'ARRAY') {
4849: my $chgtext = '<ul>';
4850: foreach my $type (@{$changes{'authtypes'}}) {
4851: my @allowed;
4852: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
4853: foreach my $auth (@authtypes) {
4854: if ($authhash{$type}{$auth}) {
4855: push(@allowed,$authname{$auth});
4856: }
4857: }
1.43 raeburn 4858: if (@allowed > 0) {
4859: $chgtext .= join(', ',@allowed).'</li>';
4860: } else {
4861: $chgtext .= &mt('none').'</li>';
4862: }
1.28 raeburn 4863: }
4864: $chgtext .= '</ul>';
4865: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
4866: $resulttext .= '</li>';
4867: }
1.27 raeburn 4868: $resulttext .= '</ul>';
4869: } else {
1.28 raeburn 4870: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 4871: }
4872: } else {
4873: $resulttext = '<span class="LC_error">'.
1.23 raeburn 4874: &mt('An error occurred: [_1]',$putresult).'</span>';
4875: }
1.43 raeburn 4876: if ($warningmsg ne '') {
4877: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
4878: }
1.23 raeburn 4879: return $resulttext;
4880: }
4881:
1.33 raeburn 4882: sub modify_usermodification {
4883: my ($dom,%domconfig) = @_;
4884: my ($resulttext,%curr_usermodification,%changes);
4885: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4886: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
4887: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
4888: }
4889: }
1.63 raeburn 4890: my @contexts = ('author','course','selfcreate');
1.33 raeburn 4891: my %context_title = (
4892: author => 'In author context',
4893: course => 'In course context',
1.63 raeburn 4894: selfcreate => 'When self creating account',
1.33 raeburn 4895: );
4896: my @fields = ('lastname','firstname','middlename','generation',
4897: 'permanentemail','id');
4898: my %roles = (
4899: author => ['ca','aa'],
4900: course => ['st','ep','ta','in','cr'],
4901: );
1.63 raeburn 4902: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4903: if (ref($types) eq 'ARRAY') {
4904: push(@{$types},'default');
4905: $usertypes->{'default'} = $othertitle;
4906: }
4907: $roles{'selfcreate'} = $types;
1.33 raeburn 4908: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4909: my %modifyhash;
4910: foreach my $context (@contexts) {
4911: foreach my $role (@{$roles{$context}}) {
4912: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
4913: foreach my $item (@fields) {
4914: if (grep(/^\Q$item\E$/,@modifiable)) {
4915: $modifyhash{$context}{$role}{$item} = 1;
4916: } else {
4917: $modifyhash{$context}{$role}{$item} = 0;
4918: }
4919: }
4920: }
4921: if (ref($curr_usermodification{$context}) eq 'HASH') {
4922: foreach my $role (@{$roles{$context}}) {
4923: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
4924: foreach my $field (@fields) {
4925: if ($modifyhash{$context}{$role}{$field} ne
4926: $curr_usermodification{$context}{$role}{$field}) {
4927: push(@{$changes{$context}},$role);
4928: last;
4929: }
4930: }
4931: }
4932: }
4933: } else {
4934: foreach my $context (@contexts) {
4935: foreach my $role (@{$roles{$context}}) {
4936: push(@{$changes{$context}},$role);
4937: }
4938: }
4939: }
4940: }
4941: my %usermodification_hash = (
4942: usermodification => \%modifyhash,
4943: );
4944: my $putresult = &Apache::lonnet::put_dom('configuration',
4945: \%usermodification_hash,$dom);
4946: if ($putresult eq 'ok') {
4947: if (keys(%changes) > 0) {
4948: $resulttext = &mt('Changes made: ').'<ul>';
4949: foreach my $context (@contexts) {
4950: if (ref($changes{$context}) eq 'ARRAY') {
4951: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
4952: if (ref($changes{$context}) eq 'ARRAY') {
4953: foreach my $role (@{$changes{$context}}) {
4954: my $rolename;
1.63 raeburn 4955: if ($context eq 'selfcreate') {
4956: $rolename = $role;
4957: if (ref($usertypes) eq 'HASH') {
4958: if ($usertypes->{$role} ne '') {
4959: $rolename = $usertypes->{$role};
4960: }
4961: }
1.33 raeburn 4962: } else {
1.63 raeburn 4963: if ($role eq 'cr') {
4964: $rolename = &mt('Custom');
4965: } else {
4966: $rolename = &Apache::lonnet::plaintext($role);
4967: }
1.33 raeburn 4968: }
4969: my @modifiable;
1.63 raeburn 4970: if ($context eq 'selfcreate') {
4971: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1] ',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
4972: } else {
4973: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
4974: }
1.33 raeburn 4975: foreach my $field (@fields) {
4976: if ($modifyhash{$context}{$role}{$field}) {
4977: push(@modifiable,$fieldtitles{$field});
4978: }
4979: }
4980: if (@modifiable > 0) {
4981: $resulttext .= join(', ',@modifiable);
4982: } else {
4983: $resulttext .= &mt('none');
4984: }
4985: $resulttext .= '</li>';
4986: }
4987: $resulttext .= '</ul></li>';
4988: }
4989: }
4990: }
4991: $resulttext .= '</ul>';
4992: } else {
4993: $resulttext = &mt('No changes made to user modification settings');
4994: }
4995: } else {
4996: $resulttext = '<span class="LC_error">'.
4997: &mt('An error occurred: [_1]',$putresult).'</span>';
4998: }
4999: return $resulttext;
5000: }
5001:
1.43 raeburn 5002: sub modify_defaults {
5003: my ($dom,$r) = @_;
5004: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
5005: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.68 raeburn 5006: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
1.43 raeburn 5007: my @authtypes = ('internal','krb4','krb5','localauth');
5008: foreach my $item (@items) {
5009: $newvalues{$item} = $env{'form.'.$item};
5010: if ($item eq 'auth_def') {
5011: if ($newvalues{$item} ne '') {
5012: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
5013: push(@errors,$item);
5014: }
5015: }
5016: } elsif ($item eq 'lang_def') {
5017: if ($newvalues{$item} ne '') {
5018: if ($newvalues{$item} =~ /^(\w+)/) {
5019: my $langcode = $1;
1.103 ! raeburn 5020: if ($langcode ne 'x_chef') {
! 5021: if (code2language($langcode) eq '') {
! 5022: push(@errors,$item);
! 5023: }
1.43 raeburn 5024: }
5025: } else {
5026: push(@errors,$item);
5027: }
5028: }
1.54 raeburn 5029: } elsif ($item eq 'timezone_def') {
5030: if ($newvalues{$item} ne '') {
1.62 raeburn 5031: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 5032: push(@errors,$item);
5033: }
5034: }
1.68 raeburn 5035: } elsif ($item eq 'datelocale_def') {
5036: if ($newvalues{$item} ne '') {
5037: my @datelocale_ids = DateTime::Locale->ids();
5038: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
5039: push(@errors,$item);
5040: }
5041: }
1.43 raeburn 5042: }
5043: if (grep(/^\Q$item\E$/,@errors)) {
5044: $newvalues{$item} = $domdefaults{$item};
5045: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
5046: $changes{$item} = 1;
5047: }
1.72 raeburn 5048: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 5049: }
5050: my %defaults_hash = (
1.72 raeburn 5051: defaults => \%newvalues,
5052: );
1.43 raeburn 5053: my $title = &defaults_titles();
5054: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
5055: $dom);
5056: if ($putresult eq 'ok') {
5057: if (keys(%changes) > 0) {
5058: $resulttext = &mt('Changes made:').'<ul>';
5059: my $version = $r->dir_config('lonVersion');
5060: my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
5061: foreach my $item (sort(keys(%changes))) {
5062: my $value = $env{'form.'.$item};
5063: if ($value eq '') {
5064: $value = &mt('none');
5065: } elsif ($item eq 'auth_def') {
5066: my %authnames = &authtype_names();
5067: my %shortauth = (
5068: internal => 'int',
5069: krb4 => 'krb4',
5070: krb5 => 'krb5',
5071: localauth => 'loc',
5072: );
5073: $value = $authnames{$shortauth{$value}};
5074: }
5075: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
5076: $mailmsgtext .= "$title->{$item} set to $value\n";
5077: }
5078: $resulttext .= '</ul>';
5079: $mailmsgtext .= "\n";
5080: my $cachetime = 24*60*60;
1.72 raeburn 5081: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 5082: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 5083: my $sysmail = $r->dir_config('lonSysEMail');
5084: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
5085: }
1.43 raeburn 5086: } else {
1.54 raeburn 5087: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 5088: }
5089: } else {
5090: $resulttext = '<span class="LC_error">'.
5091: &mt('An error occurred: [_1]',$putresult).'</span>';
5092: }
5093: if (@errors > 0) {
5094: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
5095: foreach my $item (@errors) {
5096: $resulttext .= ' "'.$title->{$item}.'",';
5097: }
5098: $resulttext =~ s/,$//;
5099: }
5100: return $resulttext;
5101: }
5102:
1.46 raeburn 5103: sub modify_scantron {
1.48 raeburn 5104: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 5105: my ($resulttext,%confhash,%changes,$errors);
5106: my $custom = 'custom.tab';
5107: my $default = 'default.tab';
5108: my $servadm = $r->dir_config('lonAdmEMail');
5109: my ($configuserok,$author_ok,$switchserver) =
5110: &config_check($dom,$confname,$servadm);
5111: if ($env{'form.scantronformat.filename'} ne '') {
5112: my $error;
5113: if ($configuserok eq 'ok') {
5114: if ($switchserver) {
5115: $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
5116: } else {
5117: if ($author_ok eq 'ok') {
5118: my ($result,$scantronurl) =
5119: &publishlogo($r,'upload','scantronformat',$dom,
5120: $confname,'scantron','','',$custom);
5121: if ($result eq 'ok') {
5122: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 5123: $changes{'scantronformat'} = 1;
1.46 raeburn 5124: } else {
5125: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
5126: }
5127: } else {
5128: $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$author_ok);
5129: }
5130: }
5131: } else {
5132: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$configuserok);
5133: }
5134: if ($error) {
5135: &Apache::lonnet::logthis($error);
5136: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5137: }
5138: }
1.48 raeburn 5139: if (ref($domconfig{'scantron'}) eq 'HASH') {
5140: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5141: if ($env{'form.scantronformat_del'}) {
5142: $confhash{'scantron'}{'scantronformat'} = '';
5143: $changes{'scantronformat'} = 1;
1.46 raeburn 5144: }
5145: }
5146: }
5147: if (keys(%confhash) > 0) {
5148: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
5149: $dom);
5150: if ($putresult eq 'ok') {
5151: if (keys(%changes) > 0) {
1.48 raeburn 5152: if (ref($confhash{'scantron'}) eq 'HASH') {
5153: $resulttext = &mt('Changes made:').'<ul>';
5154: if ($confhash{'scantron'}{'scantronformat'} eq '') {
5155: $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
5156: } else {
5157: $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 5158: }
1.48 raeburn 5159: $resulttext .= '</ul>';
5160: } else {
5161: $resulttext = &mt('Changes made to scantron format file.');
1.46 raeburn 5162: }
5163: $resulttext .= '</ul>';
5164: &Apache::loncommon::devalidate_domconfig_cache($dom);
5165: } else {
5166: $resulttext = &mt('No changes made to scantron format file');
5167: }
5168: } else {
5169: $resulttext = '<span class="LC_error">'.
5170: &mt('An error occurred: [_1]',$putresult).'</span>';
5171: }
5172: } else {
5173: $resulttext = &mt('No changes made to scantron format file');
5174: }
5175: if ($errors) {
5176: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5177: $errors.'</ul>';
5178: }
5179: return $resulttext;
5180: }
5181:
1.48 raeburn 5182: sub modify_coursecategories {
5183: my ($dom,%domconfig) = @_;
1.57 raeburn 5184: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
5185: $cathash);
1.48 raeburn 5186: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 5187: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 5188: $cathash = $domconfig{'coursecategories'}{'cats'};
5189: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
5190: $changes{'togglecats'} = 1;
5191: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
5192: }
5193: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
5194: $changes{'categorize'} = 1;
5195: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
5196: }
5197: } else {
5198: $changes{'togglecats'} = 1;
5199: $changes{'categorize'} = 1;
1.87 raeburn 5200: $domconfig{'coursecategories'} = {
5201: togglecats => $env{'form.togglecats'},
5202: categorize => $env{'form.categorize'},
5203: };
1.57 raeburn 5204: }
5205: if (ref($cathash) eq 'HASH') {
5206: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 5207: push (@deletecategory,'instcode::0');
5208: }
1.48 raeburn 5209: }
1.57 raeburn 5210: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
5211: if (ref($cathash) eq 'HASH') {
1.48 raeburn 5212: if (@deletecategory > 0) {
5213: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 5214: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 5215: foreach my $item (@deletecategory) {
1.57 raeburn 5216: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
5217: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 5218: $deletions{$item} = 1;
1.57 raeburn 5219: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 5220: }
5221: }
5222: }
1.57 raeburn 5223: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 5224: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 5225: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 5226: $reorderings{$item} = 1;
1.57 raeburn 5227: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 5228: }
5229: if ($env{'form.addcategory_name_'.$item} ne '') {
5230: my $newcat = $env{'form.addcategory_name_'.$item};
5231: my $newdepth = $depth+1;
5232: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 5233: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 5234: $adds{$newitem} = 1;
5235: }
5236: if ($env{'form.subcat_'.$item} ne '') {
5237: my $newcat = $env{'form.subcat_'.$item};
5238: my $newdepth = $depth+1;
5239: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 5240: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 5241: $adds{$newitem} = 1;
5242: }
5243: }
5244: }
5245: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 5246: if (ref($cathash) eq 'HASH') {
1.48 raeburn 5247: my $newitem = 'instcode::0';
1.57 raeburn 5248: if ($cathash->{$newitem} eq '') {
5249: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 5250: $adds{$newitem} = 1;
5251: }
5252: } else {
5253: my $newitem = 'instcode::0';
1.57 raeburn 5254: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 5255: $adds{$newitem} = 1;
5256: }
5257: }
5258: if ($env{'form.addcategory_name'} ne '') {
5259: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
1.57 raeburn 5260: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
1.48 raeburn 5261: $adds{$newitem} = 1;
5262: }
1.57 raeburn 5263: my $putresult;
1.48 raeburn 5264: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5265: if (keys(%deletions) > 0) {
5266: foreach my $key (keys(%deletions)) {
5267: if ($predelallitems{$key} ne '') {
5268: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
5269: }
5270: }
5271: }
5272: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 5273: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 5274: if (ref($chkcats[0]) eq 'ARRAY') {
5275: my $depth = 0;
5276: my $chg = 0;
5277: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
5278: my $name = $chkcats[0][$i];
5279: my $item;
5280: if ($name eq '') {
5281: $chg ++;
5282: } else {
5283: $item = &escape($name).'::0';
5284: if ($chg) {
1.57 raeburn 5285: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 5286: }
5287: $depth ++;
1.57 raeburn 5288: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 5289: $depth --;
5290: }
5291: }
5292: }
1.57 raeburn 5293: }
5294: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5295: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 5296: if ($putresult eq 'ok') {
1.57 raeburn 5297: my %title = (
5298: togglecats => 'Show/Hide a course in the catalog',
5299: categorize => 'Category assigned to course',
5300: );
5301: my %level = (
5302: dom => 'set from "Modify Course" (Domain)',
5303: crs => 'set from "Parameters" (Course)',
5304: );
1.48 raeburn 5305: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 5306: if ($changes{'togglecats'}) {
5307: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
5308: }
5309: if ($changes{'categorize'}) {
5310: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 5311: }
1.57 raeburn 5312: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5313: my $cathash;
5314: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5315: $cathash = $domconfig{'coursecategories'}{'cats'};
5316: } else {
5317: $cathash = {};
5318: }
5319: my (@cats,@trails,%allitems);
5320: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
5321: if (keys(%deletions) > 0) {
5322: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
5323: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
5324: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
5325: }
5326: $resulttext .= '</ul></li>';
5327: }
5328: if (keys(%reorderings) > 0) {
5329: my %sort_by_trail;
5330: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
5331: foreach my $key (keys(%reorderings)) {
5332: if ($allitems{$key} ne '') {
5333: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
5334: }
1.48 raeburn 5335: }
1.57 raeburn 5336: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
5337: $resulttext .= '<li>'.$trails[$trail].'</li>';
5338: }
5339: $resulttext .= '</ul></li>';
1.48 raeburn 5340: }
1.57 raeburn 5341: if (keys(%adds) > 0) {
5342: my %sort_by_trail;
5343: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
5344: foreach my $key (keys(%adds)) {
5345: if ($allitems{$key} ne '') {
5346: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
5347: }
5348: }
5349: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
5350: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 5351: }
1.57 raeburn 5352: $resulttext .= '</ul></li>';
1.48 raeburn 5353: }
5354: }
5355: $resulttext .= '</ul>';
5356: } else {
5357: $resulttext = '<span class="LC_error">'.
1.57 raeburn 5358: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 5359: }
5360: } else {
5361: $resulttext = &mt('No changes made to course categories');
5362: }
5363: return $resulttext;
5364: }
5365:
1.69 raeburn 5366: sub modify_serverstatuses {
5367: my ($dom,%domconfig) = @_;
5368: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
5369: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
5370: %currserverstatus = %{$domconfig{'serverstatuses'}};
5371: }
5372: my @pages = &serverstatus_pages();
5373: foreach my $type (@pages) {
5374: $newserverstatus{$type}{'namedusers'} = '';
5375: $newserverstatus{$type}{'machines'} = '';
5376: if (defined($env{'form.'.$type.'_namedusers'})) {
5377: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
5378: my @okusers;
5379: foreach my $user (@users) {
5380: my ($uname,$udom) = split(/:/,$user);
5381: if (($udom =~ /^$match_domain$/) &&
5382: (&Apache::lonnet::domain($udom)) &&
5383: ($uname =~ /^$match_username$/)) {
5384: if (!grep(/^\Q$user\E/,@okusers)) {
5385: push(@okusers,$user);
5386: }
5387: }
5388: }
5389: if (@okusers > 0) {
5390: @okusers = sort(@okusers);
5391: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
5392: }
5393: }
5394: if (defined($env{'form.'.$type.'_machines'})) {
5395: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
5396: my @okmachines;
5397: foreach my $ip (@machines) {
5398: my @parts = split(/\./,$ip);
5399: next if (@parts < 4);
5400: my $badip = 0;
5401: for (my $i=0; $i<4; $i++) {
5402: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
5403: $badip = 1;
5404: last;
5405: }
5406: }
5407: if (!$badip) {
5408: push(@okmachines,$ip);
5409: }
5410: }
5411: @okmachines = sort(@okmachines);
5412: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
5413: }
5414: }
5415: my %serverstatushash = (
5416: serverstatuses => \%newserverstatus,
5417: );
5418: my %changes;
5419: foreach my $type (@pages) {
1.83 raeburn 5420: foreach my $setting ('namedusers','machines') {
1.84 raeburn 5421: my (@current,@new);
1.83 raeburn 5422: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 5423: if ($currserverstatus{$type}{$setting} ne '') {
5424: @current = split(/,/,$currserverstatus{$type}{$setting});
5425: }
5426: }
5427: if ($newserverstatus{$type}{$setting} ne '') {
5428: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 5429: }
5430: if (@current > 0) {
5431: if (@new > 0) {
5432: foreach my $item (@current) {
5433: if (!grep(/^\Q$item\E$/,@new)) {
5434: $changes{$type}{$setting} = 1;
1.82 raeburn 5435: last;
5436: }
5437: }
1.84 raeburn 5438: foreach my $item (@new) {
5439: if (!grep(/^\Q$item\E$/,@current)) {
5440: $changes{$type}{$setting} = 1;
5441: last;
1.82 raeburn 5442: }
5443: }
5444: } else {
1.83 raeburn 5445: $changes{$type}{$setting} = 1;
1.69 raeburn 5446: }
1.83 raeburn 5447: } elsif (@new > 0) {
5448: $changes{$type}{$setting} = 1;
1.69 raeburn 5449: }
5450: }
5451: }
5452: if (keys(%changes) > 0) {
1.81 raeburn 5453: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5454: my $putresult = &Apache::lonnet::put_dom('configuration',
5455: \%serverstatushash,$dom);
5456: if ($putresult eq 'ok') {
5457: $resulttext .= &mt('Changes made:').'<ul>';
5458: foreach my $type (@pages) {
1.84 raeburn 5459: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 5460: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 5461: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 5462: if ($newserverstatus{$type}{'namedusers'} eq '') {
5463: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
5464: } else {
5465: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
5466: }
1.84 raeburn 5467: }
5468: if ($changes{$type}{'machines'}) {
1.69 raeburn 5469: if ($newserverstatus{$type}{'machines'} eq '') {
5470: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
5471: } else {
5472: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
5473: }
5474:
5475: }
5476: $resulttext .= '</ul></li>';
5477: }
5478: }
5479: $resulttext .= '</ul>';
5480: } else {
5481: $resulttext = '<span class="LC_error">'.
5482: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
5483:
5484: }
5485: } else {
5486: $resulttext = &mt('No changes made to access to server status pages');
5487: }
5488: return $resulttext;
5489: }
5490:
1.48 raeburn 5491: sub recurse_check {
5492: my ($chkcats,$categories,$depth,$name) = @_;
5493: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
5494: my $chg = 0;
5495: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
5496: my $category = $chkcats->[$depth]{$name}[$j];
5497: my $item;
5498: if ($category eq '') {
5499: $chg ++;
5500: } else {
5501: my $deeper = $depth + 1;
5502: $item = &escape($category).':'.&escape($name).':'.$depth;
5503: if ($chg) {
5504: $categories->{$item} -= $chg;
5505: }
5506: &recurse_check($chkcats,$categories,$deeper,$category);
5507: $deeper --;
5508: }
5509: }
5510: }
5511: return;
5512: }
5513:
5514: sub recurse_cat_deletes {
5515: my ($item,$coursecategories,$deletions) = @_;
5516: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
5517: my $subdepth = $depth + 1;
5518: if (ref($coursecategories) eq 'HASH') {
5519: foreach my $subitem (keys(%{$coursecategories})) {
5520: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
5521: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
5522: delete($coursecategories->{$subitem});
5523: $deletions->{$subitem} = 1;
5524: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
5525: }
5526: }
5527: }
5528: return;
5529: }
5530:
1.3 raeburn 5531: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>