Annotation of loncom/interface/domainprefs.pm, revision 1.142
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.142 ! raeburn 4: # $Id: domainprefs.pm,v 1.141 2010/12/08 03:38:46 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:
1.104 raeburn 108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 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:
1.104 raeburn 119: approval
1.101 raeburn 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.125 raeburn 202: 'quotas','autoenroll','autoupdate','autocreate',
203: 'directorysrch','usercreation','usermodification',
204: 'contacts','defaults','scantron','coursecategories',
205: 'serverstatuses','requestcourses','helpsettings',
1.137 raeburn 206: 'coursedefaults','usersessions'],$dom);
1.43 raeburn 207: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 208: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 209: 'usercreation','usermodification','scantron',
1.121 raeburn 210: 'requestcourses','coursecategories','serverstatuses','helpsettings',
1.137 raeburn 211: 'coursedefaults','usersessions');
1.30 raeburn 212: my %prefs = (
213: 'rolecolors' =>
214: { text => 'Default color schemes',
1.67 raeburn 215: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 216: header => [{col1 => 'Student Settings',
217: col2 => '',},
218: {col1 => 'Coordinator Settings',
219: col2 => '',},
220: {col1 => 'Author Settings',
221: col2 => '',},
222: {col1 => 'Administrator Settings',
223: col2 => '',}],
224: },
1.110 raeburn 225: 'login' =>
1.30 raeburn 226: { text => 'Log-in page options',
1.67 raeburn 227: help => 'Domain_Configuration_Login_Page',
1.30 raeburn 228: header => [{col1 => 'Item',
229: col2 => '',}],
230: },
1.110 raeburn 231:
1.43 raeburn 232: 'defaults' =>
1.141 raeburn 233: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 234: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 235: header => [{col1 => 'Setting',
236: col2 => 'Value'}],
237: },
1.30 raeburn 238: 'quotas' =>
1.133 raeburn 239: { text => 'User blogs, personal information pages, portfolios',
1.67 raeburn 240: help => 'Domain_Configuration_Quotas',
1.77 raeburn 241: header => [{col1 => 'User affiliation',
1.72 raeburn 242: col2 => 'Available tools',
243: col3 => 'Portfolio quota',}],
1.30 raeburn 244: },
245: 'autoenroll' =>
246: { text => 'Auto-enrollment settings',
1.67 raeburn 247: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 248: header => [{col1 => 'Configuration setting',
249: col2 => 'Value(s)'}],
250: },
251: 'autoupdate' =>
252: { text => 'Auto-update settings',
1.67 raeburn 253: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 254: header => [{col1 => 'Setting',
255: col2 => 'Value',},
1.131 raeburn 256: {col1 => 'Setting',
257: col2 => 'Affiliation'},
1.43 raeburn 258: {col1 => 'User population',
1.131 raeburn 259: col2 => 'Updateable user data'}],
1.30 raeburn 260: },
1.125 raeburn 261: 'autocreate' =>
262: { text => 'Auto-course creation settings',
263: help => 'Domain_Configuration_Auto_Creation',
264: header => [{col1 => 'Configuration Setting',
265: col2 => 'Value',}],
266: },
1.30 raeburn 267: 'directorysrch' =>
268: { text => 'Institutional directory searches',
1.67 raeburn 269: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 270: header => [{col1 => 'Setting',
271: col2 => 'Value',}],
272: },
273: 'contacts' =>
274: { text => 'Contact Information',
1.67 raeburn 275: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 276: header => [{col1 => 'Setting',
277: col2 => 'Value',}],
278: },
279:
280: 'usercreation' =>
281: { text => 'User creation',
1.67 raeburn 282: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 283: header => [{col1 => 'Format rule type',
284: col2 => 'Format rules in force'},
1.34 raeburn 285: {col1 => 'User account creation',
286: col2 => 'Usernames which may be created',},
1.30 raeburn 287: {col1 => 'Context',
1.43 raeburn 288: col2 => 'Assignable authentication types'}],
1.30 raeburn 289: },
1.69 raeburn 290: 'usermodification' =>
1.33 raeburn 291: { text => 'User modification',
1.67 raeburn 292: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 293: header => [{col1 => 'Target user has role',
294: col2 => 'User information updateable in author context'},
295: {col1 => 'Target user has role',
1.63 raeburn 296: col2 => 'User information updateable in course context'},
297: {col1 => "Status of user",
298: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 299: },
1.69 raeburn 300: 'scantron' =>
1.95 www 301: { text => 'Bubblesheet format file',
1.67 raeburn 302: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 303: header => [ {col1 => 'Item',
304: col2 => '',
305: }],
306: },
1.86 raeburn 307: 'requestcourses' =>
308: {text => 'Request creation of courses',
309: help => 'Domain_Configuration_Request_Courses',
310: header => [{col1 => 'User affiliation',
1.102 raeburn 311: col2 => 'Availability/Processing of requests',},
312: {col1 => 'Setting',
313: col2 => 'Value'}],
1.86 raeburn 314: },
1.69 raeburn 315: 'coursecategories' =>
1.120 raeburn 316: { text => 'Cataloging of courses/communities',
1.67 raeburn 317: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 318: header => [{col1 => 'Category settings',
1.57 raeburn 319: col2 => '',},
320: {col1 => 'Categories',
321: col2 => '',
322: }],
1.69 raeburn 323: },
324: 'serverstatuses' =>
1.77 raeburn 325: {text => 'Access to server status pages',
1.69 raeburn 326: help => 'Domain_Configuration_Server_Status',
327: header => [{col1 => 'Status Page',
328: col2 => 'Other named users',
329: col3 => 'Specific IPs',
330: }],
331: },
1.118 jms 332: 'helpsettings' =>
333: {text => 'Help page settings',
334: help => 'Domain_Configuration_Help_Settings',
1.122 jms 335: header => [{col1 => 'Authenticated Help Settings',
336: col2 => ''},
337: {col1 => 'Unauthenticated Help Settings',
338: col2 => ''}],
1.118 jms 339: },
1.121 raeburn 340: 'coursedefaults' =>
341: {text => 'Course/Community defaults',
342: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 343: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
344: col2 => 'Value',},
345: {col1 => 'Defaults which can be overridden for each course by a DC',
346: col2 => 'Value',},],
1.121 raeburn 347: },
1.120 raeburn 348: 'privacy' =>
349: {text => 'User Privacy',
350: help => 'Domain_Configuration_User_Privacy',
351: header => [{col1 => 'Setting',
352: col2 => 'Value',}],
353: },
1.141 raeburn 354: 'usersessions' =>
1.137 raeburn 355: {text => 'User session hosting',
356: help => 'Domain_Configuration_User_Sessions',
357: header => [{col1 => 'Hosting of users from other domains',
358: col2 => 'Rules'},
359: {col1 => "Hosting domain's own users elsewhere",
360: col2 => 'Rules'}],
361: },
1.3 raeburn 362: );
1.117 raeburn 363: my %servers = &dom_servers($dom);
1.110 raeburn 364: if (keys(%servers) > 1) {
365: $prefs{'login'} = { text => 'Log-in page options',
366: help => 'Domain_Configuration_Login_Page',
367: header => [{col1 => 'Log-in Service',
368: col2 => 'Server Setting',},
369: {col1 => 'Log-in Page Items',
370: col2 => ''}],
371: };
372: }
1.6 raeburn 373: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 374: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 375: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 376: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 377: text=>"Settings to display/modify"});
1.9 raeburn 378: my $confname = $dom.'-domainconfig';
1.3 raeburn 379: if ($phase eq 'process') {
1.91 raeburn 380: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 381: } elsif ($phase eq 'display') {
1.91 raeburn 382: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname);
1.1 raeburn 383: } else {
1.21 raeburn 384: if (keys(%domconfig) == 0) {
385: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 386: my @ids=&Apache::lonnet::current_machine_ids();
387: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 388: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 389: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 390: my $custom_img_count = 0;
391: foreach my $img (@loginimages) {
392: if ($designhash{$dom.'.login.'.$img} ne '') {
393: $custom_img_count ++;
394: }
395: }
396: foreach my $role (@roles) {
397: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
398: $custom_img_count ++;
399: }
400: }
401: if ($custom_img_count > 0) {
1.94 raeburn 402: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 403: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 404: $r->print(
405: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
406: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
407: &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 />'.
408: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
409: if ($switch_server) {
1.30 raeburn 410: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 411: }
1.91 raeburn 412: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 413: return OK;
414: }
415: }
416: }
1.91 raeburn 417: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 418: }
419: return OK;
420: }
421:
422: sub process_changes {
1.92 raeburn 423: my ($r,$dom,$confname,$action,$roles,$values) = @_;
424: my %domconfig;
425: if (ref($values) eq 'HASH') {
426: %domconfig = %{$values};
427: }
1.3 raeburn 428: my $output;
429: if ($action eq 'login') {
1.9 raeburn 430: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 431: } elsif ($action eq 'rolecolors') {
1.9 raeburn 432: $output = &modify_rolecolors($r,$dom,$confname,$roles,
433: %domconfig);
1.3 raeburn 434: } elsif ($action eq 'quotas') {
1.86 raeburn 435: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 436: } elsif ($action eq 'autoenroll') {
437: $output = &modify_autoenroll($dom,%domconfig);
438: } elsif ($action eq 'autoupdate') {
439: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 440: } elsif ($action eq 'autocreate') {
441: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 442: } elsif ($action eq 'directorysrch') {
443: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 444: } elsif ($action eq 'usercreation') {
1.28 raeburn 445: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 446: } elsif ($action eq 'usermodification') {
447: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 448: } elsif ($action eq 'contacts') {
449: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 450: } elsif ($action eq 'defaults') {
451: $output = &modify_defaults($dom,$r);
1.46 raeburn 452: } elsif ($action eq 'scantron') {
1.48 raeburn 453: $output = &modify_scantron($r,$dom,$confname,%domconfig);
454: } elsif ($action eq 'coursecategories') {
455: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 456: } elsif ($action eq 'serverstatuses') {
457: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 458: } elsif ($action eq 'requestcourses') {
459: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 460: } elsif ($action eq 'helpsettings') {
1.122 jms 461: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 462: } elsif ($action eq 'coursedefaults') {
463: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 464: } elsif ($action eq 'usersessions') {
465: $output = &modify_usersessions($dom,%domconfig);
1.3 raeburn 466: }
467: return $output;
468: }
469:
470: sub print_config_box {
1.9 raeburn 471: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 472: my $rowtotal = 0;
1.49 raeburn 473: my $output;
474: if ($action eq 'coursecategories') {
475: $output = &coursecategories_javascript($settings);
1.91 raeburn 476: }
1.49 raeburn 477: $output .=
1.30 raeburn 478: '<table class="LC_nested_outer">
1.3 raeburn 479: <tr>
1.66 raeburn 480: <th align="left" valign="middle"><span class="LC_nobreak">'.
481: &mt($item->{text}).' '.
482: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
483: '</tr>';
1.30 raeburn 484: $rowtotal ++;
1.110 raeburn 485: my $numheaders = 1;
486: if (ref($item->{'header'}) eq 'ARRAY') {
487: $numheaders = scalar(@{$item->{'header'}});
488: }
489: if ($numheaders > 1) {
1.64 raeburn 490: my $colspan = '';
1.122 jms 491: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
1.64 raeburn 492: $colspan = ' colspan="2"';
493: }
1.30 raeburn 494: $output .= '
1.3 raeburn 495: <tr>
496: <td>
497: <table class="LC_nested">
498: <tr class="LC_info_row">
1.59 bisitz 499: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
500: <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 501: </tr>';
1.69 raeburn 502: $rowtotal ++;
1.6 raeburn 503: if ($action eq 'autoupdate') {
1.30 raeburn 504: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 505: } elsif ($action eq 'usercreation') {
1.33 raeburn 506: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
507: } elsif ($action eq 'usermodification') {
508: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 509: } elsif ($action eq 'coursecategories') {
510: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 511: } elsif ($action eq 'login') {
512: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
513: $colspan = ' colspan="2"';
1.102 raeburn 514: } elsif ($action eq 'requestcourses') {
515: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.118 jms 516: } elsif ($action eq 'helpsettings') {
1.122 jms 517: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 518: } elsif ($action eq 'usersessions') {
519: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 520: } elsif ($action eq 'rolecolors') {
1.30 raeburn 521: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 522: } elsif ($action eq 'coursedefaults') {
523: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 524: }
1.30 raeburn 525: $output .= '
1.6 raeburn 526: </table>
527: </td>
528: </tr>
529: <tr>
530: <td>
531: <table class="LC_nested">
532: <tr class="LC_info_row">
1.59 bisitz 533: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 534: $output .= '
1.59 bisitz 535: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 536: </tr>';
537: $rowtotal ++;
1.6 raeburn 538: if ($action eq 'autoupdate') {
1.131 raeburn 539: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
540: </table>
541: </td>
542: </tr>
543: <tr>
544: <td>
545: <table class="LC_nested">
546: <tr class="LC_info_row">
547: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
548: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
549: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
550: $rowtotal ++;
1.28 raeburn 551: } elsif ($action eq 'usercreation') {
1.34 raeburn 552: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
553: </table>
554: </td>
555: </tr>
556: <tr>
557: <td>
558: <table class="LC_nested">
559: <tr class="LC_info_row">
1.59 bisitz 560: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
561: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 562: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
563: $rowtotal ++;
1.33 raeburn 564: } elsif ($action eq 'usermodification') {
1.63 raeburn 565: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
566: </table>
567: </td>
568: </tr>
569: <tr>
570: <td>
571: <table class="LC_nested">
572: <tr class="LC_info_row">
573: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
574: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
575: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
576: $rowtotal ++;
1.57 raeburn 577: } elsif ($action eq 'coursecategories') {
578: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 579: } elsif ($action eq 'login') {
580: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 581: } elsif ($action eq 'requestcourses') {
582: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.122 jms 583: } elsif ($action eq 'helpsettings') {
584: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 585: } elsif ($action eq 'usersessions') {
586: $output .= &print_usersessions('bottom',$dom,$settings,\$rowtotal);
1.139 raeburn 587: } elsif ($action eq 'coursedefaults') {
588: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 589: } elsif ($action eq 'rolecolors') {
1.30 raeburn 590: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 591: </table>
592: </td>
593: </tr>
594: <tr>
595: <td>
596: <table class="LC_nested">
597: <tr class="LC_info_row">
1.69 raeburn 598: <td class="LC_left_item"'.$colspan.' valign="top">'.
599: &mt($item->{'header'}->[2]->{'col1'}).'</td>
600: <td class="LC_right_item" valign="top">'.
601: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 602: </tr>'.
1.30 raeburn 603: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 604: </table>
605: </td>
606: </tr>
607: <tr>
608: <td>
609: <table class="LC_nested">
610: <tr class="LC_info_row">
1.59 bisitz 611: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
612: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 613: </tr>'.
1.30 raeburn 614: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
615: $rowtotal += 2;
1.6 raeburn 616: }
1.3 raeburn 617: } else {
1.30 raeburn 618: $output .= '
1.3 raeburn 619: <tr>
620: <td>
621: <table class="LC_nested">
1.30 raeburn 622: <tr class="LC_info_row">';
1.24 raeburn 623: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 624: $output .= '
1.59 bisitz 625: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 626: } elsif ($action eq 'serverstatuses') {
627: $output .= '
628: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
629: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
630:
1.6 raeburn 631: } else {
1.30 raeburn 632: $output .= '
1.69 raeburn 633: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
634: }
1.72 raeburn 635: if (defined($item->{'header'}->[0]->{'col3'})) {
636: $output .= '<td class="LC_left_item" valign="top">'.
637: &mt($item->{'header'}->[0]->{'col2'});
638: if ($action eq 'serverstatuses') {
639: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
640: }
1.69 raeburn 641: } else {
642: $output .= '<td class="LC_right_item" valign="top">'.
643: &mt($item->{'header'}->[0]->{'col2'});
644: }
645: $output .= '</td>';
646: if ($item->{'header'}->[0]->{'col3'}) {
647: $output .= '<td class="LC_right_item" valign="top">'.
648: &mt($item->{'header'}->[0]->{'col3'});
649: if ($action eq 'serverstatuses') {
650: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
651: }
652: $output .= '</td>';
1.6 raeburn 653: }
1.69 raeburn 654: $output .= '</tr>';
1.48 raeburn 655: $rowtotal ++;
1.3 raeburn 656: if ($action eq 'login') {
1.110 raeburn 657: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
658: \$rowtotal);
1.3 raeburn 659: } elsif ($action eq 'quotas') {
1.86 raeburn 660: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 661: } elsif ($action eq 'autoenroll') {
1.30 raeburn 662: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 663: } elsif ($action eq 'autocreate') {
664: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 665: } elsif ($action eq 'directorysrch') {
1.30 raeburn 666: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 667: } elsif ($action eq 'contacts') {
1.30 raeburn 668: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 669: } elsif ($action eq 'defaults') {
670: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 671: } elsif ($action eq 'scantron') {
672: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 673: } elsif ($action eq 'serverstatuses') {
674: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 675: } elsif ($action eq 'helpsettings') {
1.122 jms 676: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 677: }
1.3 raeburn 678: }
1.30 raeburn 679: $output .= '
1.3 raeburn 680: </table>
681: </td>
682: </tr>
1.30 raeburn 683: </table><br />';
684: return ($output,$rowtotal);
1.1 raeburn 685: }
686:
1.3 raeburn 687: sub print_login {
1.110 raeburn 688: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
689: my ($css_class,$datatable);
1.6 raeburn 690: my %choices = &login_choices();
1.110 raeburn 691:
692: if ($position eq 'top') {
1.117 raeburn 693: my %servers = &dom_servers($dom);
1.110 raeburn 694: my $choice = $choices{'disallowlogin'};
695: $css_class = ' class="LC_odd_row"';
1.128 raeburn 696: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 697: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 698: '<th>'.$choices{'server'}.'</th>'.
699: '<th>'.$choices{'serverpath'}.'</th>'.
700: '<th>'.$choices{'custompath'}.'</th>'.
701: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 702: my %disallowed;
703: if (ref($settings) eq 'HASH') {
704: if (ref($settings->{'loginvia'}) eq 'HASH') {
705: %disallowed = %{$settings->{'loginvia'}};
706: }
707: }
708: foreach my $lonhost (sort(keys(%servers))) {
709: my $direct = 'selected="selected"';
1.128 raeburn 710: if (ref($disallowed{$lonhost}) eq 'HASH') {
711: if ($disallowed{$lonhost}{'server'} ne '') {
712: $direct = '';
713: }
1.110 raeburn 714: }
1.115 raeburn 715: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 716: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 717: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
718: '</option>';
719: foreach my $hostid (keys(%servers)) {
1.115 raeburn 720: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 721: my $selected = '';
1.128 raeburn 722: if (ref($disallowed{$lonhost}) eq 'HASH') {
723: if ($hostid eq $disallowed{$lonhost}{'server'}) {
724: $selected = 'selected="selected"';
725: }
1.110 raeburn 726: }
727: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
728: $servers{$hostid}.'</option>';
729: }
1.128 raeburn 730: $datatable .= '</select></td>'.
731: '<td><select name="'.$lonhost.'_serverpath">';
732: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
733: my $pathname = $path;
734: if ($path eq 'custom') {
735: $pathname = &mt('Custom Path').' ->';
736: }
737: my $selected = '';
738: if (ref($disallowed{$lonhost}) eq 'HASH') {
739: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
740: $selected = 'selected="selected"';
741: }
742: } elsif ($path eq '') {
743: $selected = 'selected="selected"';
744: }
745: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
746: }
747: $datatable .= '</select></td>';
748: my ($custom,$exempt);
749: if (ref($disallowed{$lonhost}) eq 'HASH') {
750: $custom = $disallowed{$lonhost}{'custompath'};
751: $exempt = $disallowed{$lonhost}{'exempt'};
752: }
753: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
754: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
755: '</tr>';
1.110 raeburn 756: }
757: $datatable .= '</table></td></tr>';
758: return $datatable;
759: }
760:
1.42 raeburn 761: my %defaultchecked = (
1.43 raeburn 762: 'coursecatalog' => 'on',
763: 'adminmail' => 'off',
764: 'newuser' => 'off',
765: );
1.118 jms 766: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 767: my (%checkedon,%checkedoff);
768: foreach my $item (@toggles) {
769: if ($defaultchecked{$item} eq 'on') {
770: $checkedon{$item} = ' checked="checked" ';
771: $checkedoff{$item} = ' ';
772: } elsif ($defaultchecked{$item} eq 'off') {
773: $checkedoff{$item} = ' checked="checked" ';
774: $checkedon{$item} = ' ';
775: }
776: }
1.41 raeburn 777: my @images = ('img','logo','domlogo','login');
778: my @logintext = ('textcol','bgcol');
1.6 raeburn 779: my @bgs = ('pgbg','mainbg','sidebg');
780: my @links = ('link','alink','vlink');
1.7 albertel 781: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 782: my %defaultdesign = %Apache::loncommon::defaultdesign;
783: my (%is_custom,%designs);
784: my %defaults = (
785: font => $defaultdesign{'login.font'},
786: );
787: foreach my $item (@images) {
788: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 789: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 790: }
791: foreach my $item (@bgs) {
792: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
793: }
1.41 raeburn 794: foreach my $item (@logintext) {
795: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
796: }
1.6 raeburn 797: foreach my $item (@links) {
798: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
799: }
1.3 raeburn 800: if (ref($settings) eq 'HASH') {
1.42 raeburn 801: foreach my $item (@toggles) {
802: if ($settings->{$item} eq '1') {
803: $checkedon{$item} = ' checked="checked" ';
804: $checkedoff{$item} = ' ';
805: } elsif ($settings->{$item} eq '0') {
806: $checkedoff{$item} = ' checked="checked" ';
807: $checkedon{$item} = ' ';
808: }
1.1 raeburn 809: }
1.6 raeburn 810: foreach my $item (@images) {
1.70 raeburn 811: if (defined($settings->{$item})) {
1.6 raeburn 812: $designs{$item} = $settings->{$item};
813: $is_custom{$item} = 1;
814: }
1.70 raeburn 815: if (defined($settings->{'showlogo'}{$item})) {
816: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
817: }
1.6 raeburn 818: }
1.41 raeburn 819: foreach my $item (@logintext) {
820: if ($settings->{$item} ne '') {
821: $designs{'logintext'}{$item} = $settings->{$item};
822: $is_custom{$item} = 1;
823: }
824: }
1.6 raeburn 825: if ($settings->{'font'} ne '') {
826: $designs{'font'} = $settings->{'font'};
827: $is_custom{'font'} = 1;
828: }
829: foreach my $item (@bgs) {
830: if ($settings->{$item} ne '') {
831: $designs{'bgs'}{$item} = $settings->{$item};
832: $is_custom{$item} = 1;
833: }
834: }
835: foreach my $item (@links) {
836: if ($settings->{$item} ne '') {
837: $designs{'links'}{$item} = $settings->{$item};
838: $is_custom{$item} = 1;
839: }
840: }
841: } else {
842: if ($designhash{$dom.'.login.font'} ne '') {
843: $designs{'font'} = $designhash{$dom.'.login.font'};
844: $is_custom{'font'} = 1;
845: }
1.8 raeburn 846: foreach my $item (@images) {
847: if ($designhash{$dom.'.login.'.$item} ne '') {
848: $designs{$item} = $designhash{$dom.'.login.'.$item};
849: $is_custom{$item} = 1;
850: }
851: }
1.6 raeburn 852: foreach my $item (@bgs) {
853: if ($designhash{$dom.'.login.'.$item} ne '') {
854: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
855: $is_custom{$item} = 1;
856: }
857: }
858: foreach my $item (@links) {
859: if ($designhash{$dom.'.login.'.$item} ne '') {
860: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
861: $is_custom{$item} = 1;
862: }
863: }
1.1 raeburn 864: }
1.6 raeburn 865: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
866: logo => 'Institution Logo',
1.41 raeburn 867: domlogo => 'Domain Logo',
868: login => 'Login box');
1.6 raeburn 869: my $itemcount = 1;
1.42 raeburn 870: foreach my $item (@toggles) {
871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
872: $datatable .=
873: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
874: '</td><td>'.
875: '<span class="LC_nobreak"><label><input type="radio" name="'.
876: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
877: '</label> <label><input type="radio" name="'.$item.'"'.
878: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
879: '</tr>';
880: $itemcount ++;
881: }
1.135 bisitz 882: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6 raeburn 883: $datatable .= '</tr></table></td></tr>';
884: return $datatable;
885: }
886:
887: sub login_choices {
888: my %choices =
889: &Apache::lonlocal::texthash (
1.116 bisitz 890: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 891: adminmail => "Display Administrator's E-mail Address?",
892: disallowlogin => "Login page requests redirected",
893: hostid => "Server",
1.128 raeburn 894: server => "Redirect to:",
895: serverpath => "Path",
896: custompath => "Custom",
897: exempt => "Exempt IP(s)",
1.110 raeburn 898: directlogin => "No redirect",
899: newuser => "Link to create a user account",
900: img => "Header",
901: logo => "Main Logo",
902: domlogo => "Domain Logo",
903: login => "Log-in Header",
904: textcol => "Text color",
905: bgcol => "Box color",
906: bgs => "Background colors",
907: links => "Link colors",
908: font => "Font color",
909: pgbg => "Header",
910: mainbg => "Page",
911: sidebg => "Login box",
912: link => "Link",
913: alink => "Active link",
914: vlink => "Visited link",
1.6 raeburn 915: );
916: return %choices;
917: }
918:
919: sub print_rolecolors {
1.30 raeburn 920: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 921: my %choices = &color_font_choices();
922: my @bgs = ('pgbg','tabbg','sidebg');
923: my @links = ('link','alink','vlink');
924: my @images = ('img');
925: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 926: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 927: my %defaultdesign = %Apache::loncommon::defaultdesign;
928: my (%is_custom,%designs);
929: my %defaults = (
930: img => $defaultdesign{$role.'.img'},
931: font => $defaultdesign{$role.'.font'},
1.97 tempelho 932: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 933: );
934: foreach my $item (@bgs) {
935: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
936: }
937: foreach my $item (@links) {
938: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
939: }
940: if (ref($settings) eq 'HASH') {
941: if (ref($settings->{$role}) eq 'HASH') {
942: if ($settings->{$role}->{'img'} ne '') {
943: $designs{'img'} = $settings->{$role}->{'img'};
944: $is_custom{'img'} = 1;
945: }
946: if ($settings->{$role}->{'font'} ne '') {
947: $designs{'font'} = $settings->{$role}->{'font'};
948: $is_custom{'font'} = 1;
949: }
1.97 tempelho 950: if ($settings->{$role}->{'fontmenu'} ne '') {
951: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
952: $is_custom{'fontmenu'} = 1;
953: }
1.6 raeburn 954: foreach my $item (@bgs) {
955: if ($settings->{$role}->{$item} ne '') {
956: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
957: $is_custom{$item} = 1;
958: }
959: }
960: foreach my $item (@links) {
961: if ($settings->{$role}->{$item} ne '') {
962: $designs{'links'}{$item} = $settings->{$role}->{$item};
963: $is_custom{$item} = 1;
964: }
965: }
966: }
967: } else {
968: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
969: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
970: $is_custom{'img'} = 1;
971: }
1.97 tempelho 972: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
973: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
974: $is_custom{'fontmenu'} = 1;
975: }
1.6 raeburn 976: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
977: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
978: $is_custom{'font'} = 1;
979: }
980: foreach my $item (@bgs) {
981: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
982: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
983: $is_custom{$item} = 1;
984:
985: }
986: }
987: foreach my $item (@links) {
988: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
989: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
990: $is_custom{$item} = 1;
991: }
992: }
993: }
994: my $itemcount = 1;
1.30 raeburn 995: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 996: $datatable .= '</tr></table></td></tr>';
997: return $datatable;
998: }
999:
1000: sub display_color_options {
1.9 raeburn 1001: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1002: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.6 raeburn 1003: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1004: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1005: '<td>'.$choices->{'font'}.'</td>';
1006: if (!$is_custom->{'font'}) {
1.30 raeburn 1007: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1008: } else {
1009: $datatable .= '<td> </td>';
1010: }
1011: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 1012: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 1013: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 1014: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 1015: ' <span id="css_'.$role.'_font" style="background-color: '.
1016: $designs->{'font'}.';"> </span>'.
1.8 raeburn 1017: '</span></td></tr>';
1.107 raeburn 1018: unless ($role eq 'login') {
1019: $datatable .= '<tr'.$css_class.'>'.
1020: '<td>'.$choices->{'fontmenu'}.'</td>';
1021: if (!$is_custom->{'fontmenu'}) {
1022: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1023: } else {
1024: $datatable .= '<td> </td>';
1025: }
1026: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1027: $datatable .= '<td><span class="LC_nobreak">'.
1028: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1029: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1030: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1031: $designs->{'fontmenu'}.';"> </span>'.
1032: '</span></td></tr>';
1.97 tempelho 1033: }
1.9 raeburn 1034: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1035: foreach my $img (@{$images}) {
1.18 albertel 1036: $itemcount ++;
1.6 raeburn 1037: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1038: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1039: '<td>'.$choices->{$img};
1.41 raeburn 1040: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1041: if ($role eq 'login') {
1042: if ($img eq 'login') {
1043: $login_hdr_pick =
1.135 bisitz 1044: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1045: $logincolors =
1046: &login_text_colors($img,$role,$logintext,$phase,$choices,
1047: $designs);
1048: } elsif ($img ne 'domlogo') {
1049: $datatable.= &logo_display_options($img,$defaults,$designs);
1050: }
1051: }
1052: $datatable .= '</td>';
1.6 raeburn 1053: if ($designs->{$img} ne '') {
1054: $imgfile = $designs->{$img};
1.18 albertel 1055: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1056: } else {
1057: $imgfile = $defaults->{$img};
1058: }
1059: if ($imgfile) {
1.9 raeburn 1060: my ($showfile,$fullsize);
1061: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1062: my $urldir = $1;
1063: my $filename = $2;
1064: my @info = &Apache::lonnet::stat_file($designs->{$img});
1065: if (@info) {
1066: my $thumbfile = 'tn-'.$filename;
1067: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1068: if (@thumb) {
1069: $showfile = $urldir.'/'.$thumbfile;
1070: } else {
1071: $showfile = $imgfile;
1072: }
1073: } else {
1074: $showfile = '';
1075: }
1076: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1077: $showfile = $imgfile;
1.6 raeburn 1078: my $imgdir = $1;
1079: my $filename = $2;
1080: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
1081: $showfile = "/$imgdir/tn-".$filename;
1082: } else {
1083: my $input = "/home/httpd/html".$imgfile;
1084: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
1085: if (!-e $output) {
1.9 raeburn 1086: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1087: my ($fullwidth,$fullheight) = &check_dimensions($input);
1088: if ($fullwidth ne '' && $fullheight ne '') {
1089: if ($fullwidth > $width && $fullheight > $height) {
1090: my $size = $width.'x'.$height;
1091: system("convert -sample $size $input $output");
1092: $showfile = '/'.$imgdir.'/tn-'.$filename;
1093: }
1094: }
1.6 raeburn 1095: }
1096: }
1.16 raeburn 1097: }
1.6 raeburn 1098: if ($showfile) {
1.40 raeburn 1099: if ($showfile =~ m{^/(adm|res)/}) {
1100: if ($showfile =~ m{^/res/}) {
1101: my $local_showfile =
1102: &Apache::lonnet::filelocation('',$showfile);
1103: &Apache::lonnet::repcopy($local_showfile);
1104: }
1105: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1106: }
1107: if ($imgfile) {
1108: if ($imgfile =~ m{^/(adm|res)/}) {
1109: if ($imgfile =~ m{^/res/}) {
1110: my $local_imgfile =
1111: &Apache::lonnet::filelocation('',$imgfile);
1112: &Apache::lonnet::repcopy($local_imgfile);
1113: }
1114: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1115: } else {
1116: $fullsize = $imgfile;
1117: }
1118: }
1.41 raeburn 1119: $datatable .= '<td>';
1120: if ($img eq 'login') {
1.135 bisitz 1121: $datatable .= $login_hdr_pick;
1122: }
1.41 raeburn 1123: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1124: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1125: } else {
1126: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1127: &mt('Upload:');
1128: }
1129: } else {
1130: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1131: &mt('Upload:');
1132: }
1.9 raeburn 1133: if ($switchserver) {
1134: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1135: } else {
1.135 bisitz 1136: if ($img ne 'login') { # suppress file selection for Log-in header
1137: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1138: }
1.9 raeburn 1139: }
1140: $datatable .= '</td></tr>';
1.6 raeburn 1141: }
1142: $itemcount ++;
1143: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1144: $datatable .= '<tr'.$css_class.'>'.
1145: '<td>'.$choices->{'bgs'}.'</td>';
1146: my $bgs_def;
1147: foreach my $item (@{$bgs}) {
1148: if (!$is_custom->{$item}) {
1.70 raeburn 1149: $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 1150: }
1151: }
1152: if ($bgs_def) {
1.8 raeburn 1153: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1154: } else {
1155: $datatable .= '<td> </td>';
1156: }
1157: $datatable .= '<td class="LC_right_item">'.
1158: '<table border="0"><tr>';
1159: foreach my $item (@{$bgs}) {
1160: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1161: $datatable .= '<td align="center">'.$link;
1162: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1163: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1164: }
1165: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1166: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1167: }
1168: $datatable .= '</tr></table></td></tr>';
1169: $itemcount ++;
1170: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1171: $datatable .= '<tr'.$css_class.'>'.
1172: '<td>'.$choices->{'links'}.'</td>';
1173: my $links_def;
1174: foreach my $item (@{$links}) {
1175: if (!$is_custom->{$item}) {
1.30 raeburn 1176: $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 1177: }
1178: }
1179: if ($links_def) {
1.8 raeburn 1180: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1181: } else {
1182: $datatable .= '<td> </td>';
1183: }
1184: $datatable .= '<td class="LC_right_item">'.
1185: '<table border="0"><tr>';
1186: foreach my $item (@{$links}) {
1.30 raeburn 1187: $datatable .= '<td align="center">'."\n".
1188: &color_pick($phase,$role,$item,$choices->{$item},
1189: $designs->{'links'}{$item});
1.6 raeburn 1190: if ($designs->{'links'}{$item}) {
1.30 raeburn 1191: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1192: }
1193: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1194: '" /></td>';
1195: }
1.30 raeburn 1196: $$rowtotal += $itemcount;
1.3 raeburn 1197: return $datatable;
1198: }
1199:
1.70 raeburn 1200: sub logo_display_options {
1201: my ($img,$defaults,$designs) = @_;
1202: my $checkedon;
1203: if (ref($defaults) eq 'HASH') {
1204: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1205: if ($defaults->{'showlogo'}{$img}) {
1206: $checkedon = 'checked="checked" ';
1207: }
1208: }
1209: }
1210: if (ref($designs) eq 'HASH') {
1211: if (ref($designs->{'showlogo'}) eq 'HASH') {
1212: if (defined($designs->{'showlogo'}{$img})) {
1213: if ($designs->{'showlogo'}{$img} == 0) {
1214: $checkedon = '';
1215: } elsif ($designs->{'showlogo'}{$img} == 1) {
1216: $checkedon = 'checked="checked" ';
1217: }
1218: }
1219: }
1220: }
1221: return '<br /><label> <input type="checkbox" name="'.
1222: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1223: &mt('show').'</label>'."\n";
1224: }
1225:
1.41 raeburn 1226: sub login_header_options {
1.135 bisitz 1227: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1228: my $output = '';
1.41 raeburn 1229: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1230: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1231: if (!$is_custom->{'textcol'}) {
1232: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1233: ' ';
1234: }
1235: if (!$is_custom->{'bgcol'}) {
1236: $output .= $choices->{'bgcol'}.': '.
1237: '<span id="css_'.$role.'_font" style="background-color: '.
1238: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1239: }
1240: $output .= '<br />';
1241: }
1242: $output .='<br />';
1243: return $output;
1244: }
1245:
1246: sub login_text_colors {
1247: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1248: my $color_menu = '<table border="0"><tr>';
1249: foreach my $item (@{$logintext}) {
1250: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1251: $color_menu .= '<td align="center">'.$link;
1252: if ($designs->{'logintext'}{$item}) {
1253: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1254: }
1255: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1256: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1257: '<td> </td>';
1258: }
1259: $color_menu .= '</tr></table><br />';
1260: return $color_menu;
1261: }
1262:
1263: sub image_changes {
1264: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1265: my $output;
1.135 bisitz 1266: if ($img eq 'login') {
1267: # suppress image for Log-in header
1268: } elsif (!$is_custom) {
1.70 raeburn 1269: if ($img ne 'domlogo') {
1.41 raeburn 1270: $output .= &mt('Default image:').'<br />';
1271: } else {
1272: $output .= &mt('Default in use:').'<br />';
1273: }
1274: }
1.135 bisitz 1275: if ($img eq 'login') { # suppress image for Log-in header
1276: $output .= '<td>'.$logincolors;
1.41 raeburn 1277: } else {
1.135 bisitz 1278: if ($img_import) {
1279: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1280: }
1281: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1282: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1283: if ($is_custom) {
1284: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1285: '<input type="checkbox" name="'.
1286: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1287: '</label> '.&mt('Replace:').'</span><br />';
1288: } else {
1289: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1290: }
1.41 raeburn 1291: }
1292: return $output;
1293: }
1294:
1.6 raeburn 1295: sub color_pick {
1296: my ($phase,$role,$item,$desc,$curcol) = @_;
1297: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1298: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1299: ');">'.$desc.'</a>';
1300: return $link;
1301: }
1302:
1.3 raeburn 1303: sub print_quotas {
1.86 raeburn 1304: my ($dom,$settings,$rowtotal,$action) = @_;
1305: my $context;
1306: if ($action eq 'quotas') {
1307: $context = 'tools';
1308: } else {
1309: $context = $action;
1310: }
1.101 raeburn 1311: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1312: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1313: my $typecount = 0;
1.101 raeburn 1314: my ($css_class,%titles);
1.86 raeburn 1315: if ($context eq 'requestcourses') {
1.98 raeburn 1316: @usertools = ('official','unofficial','community');
1.106 raeburn 1317: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1318: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1319: %titles = &courserequest_titles();
1.86 raeburn 1320: } else {
1321: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 1322: %titles = &tool_titles();
1.86 raeburn 1323: }
1.26 raeburn 1324: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1325: foreach my $type (@{$types}) {
1.72 raeburn 1326: my $currdefquota;
1.86 raeburn 1327: unless ($context eq 'requestcourses') {
1328: if (ref($settings) eq 'HASH') {
1329: if (ref($settings->{defaultquota}) eq 'HASH') {
1330: $currdefquota = $settings->{defaultquota}->{$type};
1331: } else {
1332: $currdefquota = $settings->{$type};
1333: }
1.78 raeburn 1334: }
1.72 raeburn 1335: }
1.3 raeburn 1336: if (defined($usertypes->{$type})) {
1337: $typecount ++;
1338: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1339: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1340: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1341: '<td class="LC_left_item">';
1.101 raeburn 1342: if ($context eq 'requestcourses') {
1343: $datatable .= '<table><tr>';
1344: }
1345: my %cell;
1.72 raeburn 1346: foreach my $item (@usertools) {
1.101 raeburn 1347: if ($context eq 'requestcourses') {
1348: my ($curroption,$currlimit);
1349: if (ref($settings) eq 'HASH') {
1350: if (ref($settings->{$item}) eq 'HASH') {
1351: $curroption = $settings->{$item}->{$type};
1352: if ($curroption =~ /^autolimit=(\d*)$/) {
1353: $currlimit = $1;
1354: }
1355: }
1356: }
1357: if (!$curroption) {
1358: $curroption = 'norequest';
1359: }
1360: $datatable .= '<th>'.$titles{$item}.'</th>';
1361: foreach my $option (@options) {
1362: my $val = $option;
1363: if ($option eq 'norequest') {
1364: $val = 0;
1365: }
1366: if ($option eq 'validate') {
1367: my $canvalidate = 0;
1368: if (ref($validations{$item}) eq 'HASH') {
1369: if ($validations{$item}{$type}) {
1370: $canvalidate = 1;
1371: }
1372: }
1373: next if (!$canvalidate);
1374: }
1375: my $checked = '';
1376: if ($option eq $curroption) {
1377: $checked = ' checked="checked"';
1378: } elsif ($option eq 'autolimit') {
1379: if ($curroption =~ /^autolimit/) {
1380: $checked = ' checked="checked"';
1381: }
1382: }
1383: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1384: '<input type="radio" name="crsreq_'.$item.
1385: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1386: $titles{$option}.'</label>';
1.101 raeburn 1387: if ($option eq 'autolimit') {
1.127 raeburn 1388: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1389: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1390: 'value="'.$currlimit.'" />';
1.101 raeburn 1391: }
1.127 raeburn 1392: $cell{$item} .= '</span> ';
1.103 raeburn 1393: if ($option eq 'autolimit') {
1.127 raeburn 1394: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1395: }
1.101 raeburn 1396: }
1397: } else {
1398: my $checked = 'checked="checked" ';
1399: if (ref($settings) eq 'HASH') {
1400: if (ref($settings->{$item}) eq 'HASH') {
1401: if ($settings->{$item}->{$type} == 0) {
1402: $checked = '';
1403: } elsif ($settings->{$item}->{$type} == 1) {
1404: $checked = 'checked="checked" ';
1405: }
1.78 raeburn 1406: }
1.72 raeburn 1407: }
1.101 raeburn 1408: $datatable .= '<span class="LC_nobreak"><label>'.
1409: '<input type="checkbox" name="'.$context.'_'.$item.
1410: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1411: '</label></span> ';
1.72 raeburn 1412: }
1.101 raeburn 1413: }
1414: if ($context eq 'requestcourses') {
1415: $datatable .= '</tr><tr>';
1416: foreach my $item (@usertools) {
1.106 raeburn 1417: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1418: }
1419: $datatable .= '</tr></table>';
1.72 raeburn 1420: }
1.86 raeburn 1421: $datatable .= '</td>';
1422: unless ($context eq 'requestcourses') {
1423: $datatable .=
1424: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1425: '<input type="text" name="quota_'.$type.
1.72 raeburn 1426: '" value="'.$currdefquota.
1.86 raeburn 1427: '" size="5" /> Mb</span></td>';
1428: }
1429: $datatable .= '</tr>';
1.3 raeburn 1430: }
1431: }
1432: }
1.86 raeburn 1433: unless ($context eq 'requestcourses') {
1434: $defaultquota = '20';
1435: if (ref($settings) eq 'HASH') {
1436: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1437: $defaultquota = $settings->{'defaultquota'}->{'default'};
1438: } elsif (defined($settings->{'default'})) {
1439: $defaultquota = $settings->{'default'};
1440: }
1.3 raeburn 1441: }
1442: }
1443: $typecount ++;
1444: $css_class = $typecount%2?' class="LC_odd_row"':'';
1445: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1446: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1447: '<td class="LC_left_item">';
1.101 raeburn 1448: if ($context eq 'requestcourses') {
1449: $datatable .= '<table><tr>';
1450: }
1451: my %defcell;
1.72 raeburn 1452: foreach my $item (@usertools) {
1.101 raeburn 1453: if ($context eq 'requestcourses') {
1454: my ($curroption,$currlimit);
1455: if (ref($settings) eq 'HASH') {
1456: if (ref($settings->{$item}) eq 'HASH') {
1457: $curroption = $settings->{$item}->{'default'};
1458: if ($curroption =~ /^autolimit=(\d*)$/) {
1459: $currlimit = $1;
1460: }
1461: }
1462: }
1463: if (!$curroption) {
1464: $curroption = 'norequest';
1465: }
1466: $datatable .= '<th>'.$titles{$item}.'</th>';
1467: foreach my $option (@options) {
1468: my $val = $option;
1469: if ($option eq 'norequest') {
1470: $val = 0;
1471: }
1472: if ($option eq 'validate') {
1473: my $canvalidate = 0;
1474: if (ref($validations{$item}) eq 'HASH') {
1475: if ($validations{$item}{'default'}) {
1476: $canvalidate = 1;
1477: }
1478: }
1479: next if (!$canvalidate);
1480: }
1481: my $checked = '';
1482: if ($option eq $curroption) {
1483: $checked = ' checked="checked"';
1484: } elsif ($option eq 'autolimit') {
1485: if ($curroption =~ /^autolimit/) {
1486: $checked = ' checked="checked"';
1487: }
1488: }
1489: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1490: '<input type="radio" name="crsreq_'.$item.
1491: '_default" value="'.$val.'"'.$checked.' />'.
1492: $titles{$option}.'</label>';
1493: if ($option eq 'autolimit') {
1.127 raeburn 1494: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1495: $item.'_limit_default" size="1" '.
1496: 'value="'.$currlimit.'" />';
1497: }
1.127 raeburn 1498: $defcell{$item} .= '</span> ';
1.104 raeburn 1499: if ($option eq 'autolimit') {
1.127 raeburn 1500: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1501: }
1.101 raeburn 1502: }
1503: } else {
1504: my $checked = 'checked="checked" ';
1505: if (ref($settings) eq 'HASH') {
1506: if (ref($settings->{$item}) eq 'HASH') {
1507: if ($settings->{$item}->{'default'} == 0) {
1508: $checked = '';
1509: } elsif ($settings->{$item}->{'default'} == 1) {
1510: $checked = 'checked="checked" ';
1511: }
1.78 raeburn 1512: }
1.72 raeburn 1513: }
1.101 raeburn 1514: $datatable .= '<span class="LC_nobreak"><label>'.
1515: '<input type="checkbox" name="'.$context.'_'.$item.
1516: '" value="default" '.$checked.'/>'.$titles{$item}.
1517: '</label></span> ';
1518: }
1519: }
1520: if ($context eq 'requestcourses') {
1521: $datatable .= '</tr><tr>';
1522: foreach my $item (@usertools) {
1.106 raeburn 1523: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1524: }
1.101 raeburn 1525: $datatable .= '</tr></table>';
1.72 raeburn 1526: }
1.86 raeburn 1527: $datatable .= '</td>';
1528: unless ($context eq 'requestcourses') {
1529: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1530: '<input type="text" name="defaultquota" value="'.
1531: $defaultquota.'" size="5" /> Mb</span></td>';
1532: }
1533: $datatable .= '</tr>';
1.72 raeburn 1534: $typecount ++;
1535: $css_class = $typecount%2?' class="LC_odd_row"':'';
1536: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1537: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1538: if ($context eq 'requestcourses') {
1.109 raeburn 1539: $datatable .= &mt('(overrides affiliation, if set)').
1540: '</td>'.
1541: '<td class="LC_left_item">'.
1542: '<table><tr>';
1.101 raeburn 1543: } else {
1.109 raeburn 1544: $datatable .= &mt('(overrides affiliation, if checked)').
1545: '</td>'.
1546: '<td class="LC_left_item" colspan="2">'.
1547: '<br />';
1.101 raeburn 1548: }
1549: my %advcell;
1.72 raeburn 1550: foreach my $item (@usertools) {
1.101 raeburn 1551: if ($context eq 'requestcourses') {
1552: my ($curroption,$currlimit);
1553: if (ref($settings) eq 'HASH') {
1554: if (ref($settings->{$item}) eq 'HASH') {
1555: $curroption = $settings->{$item}->{'_LC_adv'};
1556: if ($curroption =~ /^autolimit=(\d*)$/) {
1557: $currlimit = $1;
1558: }
1559: }
1560: }
1561: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1562: my $checked = '';
1563: if ($curroption eq '') {
1564: $checked = ' checked="checked"';
1565: }
1566: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1567: '<input type="radio" name="crsreq_'.$item.
1568: '__LC_adv" value=""'.$checked.' />'.
1569: &mt('No override set').'</label></span> ';
1.101 raeburn 1570: foreach my $option (@options) {
1571: my $val = $option;
1572: if ($option eq 'norequest') {
1573: $val = 0;
1574: }
1575: if ($option eq 'validate') {
1576: my $canvalidate = 0;
1577: if (ref($validations{$item}) eq 'HASH') {
1578: if ($validations{$item}{'_LC_adv'}) {
1579: $canvalidate = 1;
1580: }
1581: }
1582: next if (!$canvalidate);
1583: }
1584: my $checked = '';
1.104 raeburn 1585: if ($val eq $curroption) {
1.101 raeburn 1586: $checked = ' checked="checked"';
1587: } elsif ($option eq 'autolimit') {
1588: if ($curroption =~ /^autolimit/) {
1589: $checked = ' checked="checked"';
1590: }
1591: }
1592: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1593: '<input type="radio" name="crsreq_'.$item.
1594: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1595: $titles{$option}.'</label>';
1596: if ($option eq 'autolimit') {
1.127 raeburn 1597: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1598: $item.'_limit__LC_adv" size="1" '.
1599: 'value="'.$currlimit.'" />';
1600: }
1.127 raeburn 1601: $advcell{$item} .= '</span> ';
1.104 raeburn 1602: if ($option eq 'autolimit') {
1.127 raeburn 1603: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1604: }
1.101 raeburn 1605: }
1606: } else {
1607: my $checked = 'checked="checked" ';
1608: if (ref($settings) eq 'HASH') {
1609: if (ref($settings->{$item}) eq 'HASH') {
1610: if ($settings->{$item}->{'_LC_adv'} == 0) {
1611: $checked = '';
1612: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1613: $checked = 'checked="checked" ';
1614: }
1.79 raeburn 1615: }
1.72 raeburn 1616: }
1.101 raeburn 1617: $datatable .= '<span class="LC_nobreak"><label>'.
1618: '<input type="checkbox" name="'.$context.'_'.$item.
1619: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1620: '</label></span> ';
1621: }
1622: }
1623: if ($context eq 'requestcourses') {
1624: $datatable .= '</tr><tr>';
1625: foreach my $item (@usertools) {
1.106 raeburn 1626: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1627: }
1.101 raeburn 1628: $datatable .= '</tr></table>';
1.72 raeburn 1629: }
1.98 raeburn 1630: $datatable .= '</td></tr>';
1.30 raeburn 1631: $$rowtotal += $typecount;
1.3 raeburn 1632: return $datatable;
1633: }
1634:
1.102 raeburn 1635: sub print_courserequestmail {
1636: my ($dom,$settings,$rowtotal) = @_;
1.104 raeburn 1637: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1638: $now = time;
1639: $rows = 0;
1640: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1641: foreach my $server (keys(%dompersonnel)) {
1642: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1643: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1644: if (!grep(/^$uname:$udom$/,@domcoord)) {
1645: push(@domcoord,$uname.':'.$udom);
1646: }
1647: }
1648: }
1649: if (ref($settings) eq 'HASH') {
1650: if (ref($settings->{'notify'}) eq 'HASH') {
1651: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1652: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1653: }
1654: }
1655: }
1.104 raeburn 1656: if (@currapproval) {
1657: foreach my $dc (@currapproval) {
1.102 raeburn 1658: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1659: push(@domcoord,$dc);
1660: }
1661: }
1662: }
1663: @domcoord = sort(@domcoord);
1664: my $numinrow = 4;
1665: my $numdc = @domcoord;
1666: my $css_class = 'class="LC_odd_row"';
1667: $datatable = '<tr'.$css_class.'>'.
1668: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1669: ' </td>'.
1670: ' <td class="LC_left_item">';
1671: if (@domcoord > 0) {
1672: $datatable .= '<table>';
1673: for (my $i=0; $i<$numdc; $i++) {
1674: my $rem = $i%($numinrow);
1675: if ($rem == 0) {
1676: if ($i > 0) {
1677: $datatable .= '</tr>';
1678: }
1679: $datatable .= '<tr>';
1680: $rows ++;
1681: }
1682: my $check = ' ';
1.104 raeburn 1683: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1684: $check = ' checked="checked" ';
1685: }
1686: my ($uname,$udom) = split(':',$domcoord[$i]);
1687: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1688: if ($i == $numdc-1) {
1689: my $colsleft = $numinrow-$rem;
1690: if ($colsleft > 1) {
1691: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1692: } else {
1693: $datatable .= '<td class="LC_left_item">';
1694: }
1695: } else {
1696: $datatable .= '<td class="LC_left_item">';
1697: }
1698: $datatable .= '<span class="LC_nobreak"><label>'.
1699: '<input type="checkbox" name="reqapprovalnotify" '.
1700: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1701: $fullname.'</label></span></td>';
1702: }
1703: $datatable .= '</tr></table>';
1704: } else {
1705: $datatable .= &mt('There are no active Domain Coordinators');
1706: $rows ++;
1707: }
1708: $datatable .='</td></tr>';
1709: $$rowtotal += $rows;
1710: return $datatable;
1711: }
1712:
1.3 raeburn 1713: sub print_autoenroll {
1.30 raeburn 1714: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1715: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1716: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1717: if (ref($settings) eq 'HASH') {
1718: if (exists($settings->{'run'})) {
1719: if ($settings->{'run'} eq '0') {
1720: $runoff = ' checked="checked" ';
1721: $runon = ' ';
1722: } else {
1723: $runon = ' checked="checked" ';
1724: $runoff = ' ';
1725: }
1726: } else {
1727: if ($autorun) {
1728: $runon = ' checked="checked" ';
1729: $runoff = ' ';
1730: } else {
1731: $runoff = ' checked="checked" ';
1732: $runon = ' ';
1733: }
1734: }
1.129 raeburn 1735: if (exists($settings->{'co-owners'})) {
1736: if ($settings->{'co-owners'} eq '0') {
1737: $coownersoff = ' checked="checked" ';
1738: $coownerson = ' ';
1739: } else {
1740: $coownerson = ' checked="checked" ';
1741: $coownersoff = ' ';
1742: }
1743: } else {
1744: $coownersoff = ' checked="checked" ';
1745: $coownerson = ' ';
1746: }
1.3 raeburn 1747: if (exists($settings->{'sender_domain'})) {
1748: $defdom = $settings->{'sender_domain'};
1749: }
1.14 raeburn 1750: } else {
1751: if ($autorun) {
1752: $runon = ' checked="checked" ';
1753: $runoff = ' ';
1754: } else {
1755: $runoff = ' checked="checked" ';
1756: $runon = ' ';
1757: }
1.3 raeburn 1758: }
1759: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1760: my $notif_sender;
1761: if (ref($settings) eq 'HASH') {
1762: $notif_sender = $settings->{'sender_uname'};
1763: }
1.3 raeburn 1764: my $datatable='<tr class="LC_odd_row">'.
1765: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1766: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1767: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1768: $runon.' value="1" />'.&mt('Yes').'</label> '.
1769: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1770: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1771: '</tr><tr>'.
1772: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1773: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1774: &mt('username').': '.
1775: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1776: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 1777: ': '.$domform.'</span></td></tr>'.
1778: '<tr class="LC_odd_row">'.
1779: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1780: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1781: '<input type="radio" name="autoassign_coowners"'.
1782: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1783: '<label><input type="radio" name="autoassign_coowners"'.
1784: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1785: '</tr>';
1786: $$rowtotal += 3;
1.3 raeburn 1787: return $datatable;
1788: }
1789:
1790: sub print_autoupdate {
1.30 raeburn 1791: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1792: my $datatable;
1793: if ($position eq 'top') {
1794: my $updateon = ' ';
1795: my $updateoff = ' checked="checked" ';
1796: my $classlistson = ' ';
1797: my $classlistsoff = ' checked="checked" ';
1798: if (ref($settings) eq 'HASH') {
1799: if ($settings->{'run'} eq '1') {
1800: $updateon = $updateoff;
1801: $updateoff = ' ';
1802: }
1803: if ($settings->{'classlists'} eq '1') {
1804: $classlistson = $classlistsoff;
1805: $classlistsoff = ' ';
1806: }
1807: }
1808: my %title = (
1809: run => 'Auto-update active?',
1810: classlists => 'Update information in classlists?',
1811: );
1812: $datatable = '<tr class="LC_odd_row">'.
1813: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1814: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1815: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1816: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1817: '<label><input type="radio" name="autoupdate_run"'.
1818: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1819: '</tr><tr>'.
1820: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1821: '<td class="LC_right_item"><span class="LC_nobreak">'.
1822: '<label><input type="radio" name="classlists"'.
1823: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1824: '<label><input type="radio" name="classlists"'.
1825: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1826: '</tr>';
1.30 raeburn 1827: $$rowtotal += 2;
1.131 raeburn 1828: } elsif ($position eq 'middle') {
1829: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1830: my $numinrow = 3;
1831: my $locknamesettings;
1832: $datatable .= &insttypes_row($settings,$types,$usertypes,
1833: $dom,$numinrow,$othertitle,
1834: 'lockablenames');
1835: $$rowtotal ++;
1.3 raeburn 1836: } else {
1.44 raeburn 1837: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 1838: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 1839: 'permanentemail','id');
1.33 raeburn 1840: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1841: my $numrows = 0;
1.26 raeburn 1842: if (ref($types) eq 'ARRAY') {
1843: if (@{$types} > 0) {
1844: $datatable =
1845: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1846: \@fields,$types,\$numrows);
1.30 raeburn 1847: $$rowtotal += @{$types};
1.26 raeburn 1848: }
1.3 raeburn 1849: }
1850: $datatable .=
1851: &usertype_update_row($settings,{'default' => $othertitle},
1852: \%fieldtitles,\@fields,['default'],
1853: \$numrows);
1.30 raeburn 1854: $$rowtotal ++;
1.3 raeburn 1855: }
1856: return $datatable;
1857: }
1858:
1.125 raeburn 1859: sub print_autocreate {
1860: my ($dom,$settings,$rowtotal) = @_;
1861: my (%createon,%createoff);
1862: my $curr_dc;
1863: my @types = ('xml','req');
1864: if (ref($settings) eq 'HASH') {
1865: foreach my $item (@types) {
1866: $createoff{$item} = ' checked="checked" ';
1867: $createon{$item} = ' ';
1868: if (exists($settings->{$item})) {
1869: if ($settings->{$item}) {
1870: $createon{$item} = ' checked="checked" ';
1871: $createoff{$item} = ' ';
1872: }
1873: }
1874: }
1875: $curr_dc = $settings->{'xmldc'};
1876: } else {
1877: foreach my $item (@types) {
1878: $createoff{$item} = ' checked="checked" ';
1879: $createon{$item} = ' ';
1880: }
1881: }
1882: $$rowtotal += 2;
1883: my $datatable='<tr class="LC_odd_row">'.
1884: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
1885: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1886: '<input type="radio" name="autocreate_xml"'.
1887: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
1888: '<label><input type="radio" name="autocreate_xml"'.
1889: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>';
1890: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
1891: if ($numdc > 1) {
1892: $datatable .= '</td><tr><td>'.
1893: &mt('XML files processed as: (choose Dom. Coord.)').
1894: '</td><td class="LC_left_item">'.$dctable.'</td></tr>'.
1895: '<tr class="LC_odd_row">';
1896: $$rowtotal ++ ;
1897: } else {
1898: $datatable .= '</td></tr><tr>';
1899: }
1900: $datatable .= '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
1901: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1902: '<input type="radio" name="autocreate_req"'.
1903: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
1904: '<label><input type="radio" name="autocreate_req"'.
1905: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span></td>'.
1906: '</tr>';
1907: return $datatable;
1908: }
1909:
1.23 raeburn 1910: sub print_directorysrch {
1.30 raeburn 1911: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1912: my $srchon = ' ';
1913: my $srchoff = ' checked="checked" ';
1.25 raeburn 1914: my ($exacton,$containson,$beginson);
1.24 raeburn 1915: my $localon = ' ';
1916: my $localoff = ' checked="checked" ';
1.23 raeburn 1917: if (ref($settings) eq 'HASH') {
1918: if ($settings->{'available'} eq '1') {
1919: $srchon = $srchoff;
1920: $srchoff = ' ';
1921: }
1.24 raeburn 1922: if ($settings->{'localonly'} eq '1') {
1923: $localon = $localoff;
1924: $localoff = ' ';
1925: }
1.25 raeburn 1926: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1927: foreach my $type (@{$settings->{'searchtypes'}}) {
1928: if ($type eq 'exact') {
1929: $exacton = ' checked="checked" ';
1930: } elsif ($type eq 'contains') {
1931: $containson = ' checked="checked" ';
1932: } elsif ($type eq 'begins') {
1933: $beginson = ' checked="checked" ';
1934: }
1935: }
1936: } else {
1937: if ($settings->{'searchtypes'} eq 'exact') {
1938: $exacton = ' checked="checked" ';
1939: } elsif ($settings->{'searchtypes'} eq 'contains') {
1940: $containson = ' checked="checked" ';
1941: } elsif ($settings->{'searchtypes'} eq 'specify') {
1942: $exacton = ' checked="checked" ';
1943: $containson = ' checked="checked" ';
1944: }
1.23 raeburn 1945: }
1946: }
1947: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1948: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1949:
1950: my $numinrow = 4;
1.26 raeburn 1951: my $cansrchrow = 0;
1.23 raeburn 1952: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1953: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1954: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1955: '<input type="radio" name="dirsrch_available"'.
1956: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1957: '<label><input type="radio" name="dirsrch_available"'.
1958: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1959: '</tr><tr>'.
1.30 raeburn 1960: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1961: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1962: '<input type="radio" name="dirsrch_localonly"'.
1963: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1964: '<label><input type="radio" name="dirsrch_localonly"'.
1965: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1966: '</tr>';
1.30 raeburn 1967: $$rowtotal += 2;
1.26 raeburn 1968: if (ref($usertypes) eq 'HASH') {
1969: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 1970: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1971: $numinrow,$othertitle,'cansearch');
1.26 raeburn 1972: $cansrchrow = 1;
1973: }
1974: }
1975: if ($cansrchrow) {
1.30 raeburn 1976: $$rowtotal ++;
1.26 raeburn 1977: $datatable .= '<tr>';
1978: } else {
1979: $datatable .= '<tr class="LC_odd_row">';
1980: }
1.30 raeburn 1981: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1982: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1983: foreach my $title (@{$titleorder}) {
1984: if (defined($searchtitles->{$title})) {
1985: my $check = ' ';
1.93 raeburn 1986: if (ref($settings) eq 'HASH') {
1.39 raeburn 1987: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1988: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1989: $check = ' checked="checked" ';
1990: }
1.25 raeburn 1991: }
1992: }
1993: $datatable .= '<td class="LC_left_item">'.
1994: '<span class="LC_nobreak"><label>'.
1995: '<input type="checkbox" name="searchby" '.
1996: 'value="'.$title.'"'.$check.'/>'.
1997: $searchtitles->{$title}.'</label></span></td>';
1998: }
1999: }
1.26 raeburn 2000: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2001: $$rowtotal ++;
1.26 raeburn 2002: if ($cansrchrow) {
2003: $datatable .= '<tr class="LC_odd_row">';
2004: } else {
2005: $datatable .= '<tr>';
2006: }
1.30 raeburn 2007: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2008: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2009: '<span class="LC_nobreak"><label>'.
2010: '<input type="checkbox" name="searchtypes" '.
2011: $exacton.' value="exact" />'.&mt('Exact match').
2012: '</label> '.
2013: '<label><input type="checkbox" name="searchtypes" '.
2014: $beginson.' value="begins" />'.&mt('Begins with').
2015: '</label> '.
2016: '<label><input type="checkbox" name="searchtypes" '.
2017: $containson.' value="contains" />'.&mt('Contains').
2018: '</label></span></td></tr>';
1.30 raeburn 2019: $$rowtotal ++;
1.25 raeburn 2020: return $datatable;
2021: }
2022:
1.28 raeburn 2023: sub print_contacts {
1.30 raeburn 2024: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2025: my $datatable;
2026: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2027: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2028: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2029: 'requestsmail');
1.28 raeburn 2030: foreach my $type (@mailings) {
2031: $otheremails{$type} = '';
2032: }
1.134 raeburn 2033: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2034: if (ref($settings) eq 'HASH') {
2035: foreach my $item (@contacts) {
2036: if (exists($settings->{$item})) {
2037: $to{$item} = $settings->{$item};
2038: }
2039: }
2040: foreach my $type (@mailings) {
2041: if (exists($settings->{$type})) {
2042: if (ref($settings->{$type}) eq 'HASH') {
2043: foreach my $item (@contacts) {
2044: if ($settings->{$type}{$item}) {
2045: $checked{$type}{$item} = ' checked="checked" ';
2046: }
2047: }
2048: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2049: if ($type eq 'helpdeskmail') {
2050: $bccemails{$type} = $settings->{$type}{'bcc'};
2051: }
1.28 raeburn 2052: }
1.89 raeburn 2053: } elsif ($type eq 'lonstatusmail') {
2054: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2055: }
2056: }
2057: } else {
2058: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2059: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2060: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2061: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2062: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2063: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2064: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2065: }
2066: my ($titles,$short_titles) = &contact_titles();
2067: my $rownum = 0;
2068: my $css_class;
2069: foreach my $item (@contacts) {
1.69 raeburn 2070: $rownum ++;
2071: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2072: $datatable .= '<tr'.$css_class.'>'.
2073: '<td><span class="LC_nobreak">'.$titles->{$item}.
2074: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2075: '<input type="text" name="'.$item.'" value="'.
2076: $to{$item}.'" /></td></tr>';
2077: }
2078: foreach my $type (@mailings) {
1.69 raeburn 2079: $rownum ++;
2080: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2081: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2082: '<td><span class="LC_nobreak">'.
2083: $titles->{$type}.': </span></td>'.
1.28 raeburn 2084: '<td class="LC_left_item">'.
2085: '<span class="LC_nobreak">';
2086: foreach my $item (@contacts) {
2087: $datatable .= '<label>'.
2088: '<input type="checkbox" name="'.$type.'"'.
2089: $checked{$type}{$item}.
2090: ' value="'.$item.'" />'.$short_titles->{$item}.
2091: '</label> ';
2092: }
2093: $datatable .= '</span><br />'.&mt('Others').': '.
2094: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2095: 'value="'.$otheremails{$type}.'" />';
2096: if ($type eq 'helpdeskmail') {
1.136 raeburn 2097: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2098: '<input type="text" name="'.$type.'_bcc" '.
2099: 'value="'.$bccemails{$type}.'" />';
2100: }
2101: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2102: }
1.30 raeburn 2103: $$rowtotal += $rownum;
1.28 raeburn 2104: return $datatable;
2105: }
2106:
1.118 jms 2107: sub print_helpsettings {
1.122 jms 2108:
2109: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2110: my ($css_class,$datatable);
2111:
2112: my $switchserver = &check_switchserver($dom,$confname);
2113:
2114: my $itemcount = 1;
2115:
2116: if ($position eq 'top') {
2117:
2118: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2119:
2120: %choices =
2121: &Apache::lonlocal::texthash (
2122: submitbugs => 'Display "Submit a bug" link?',
2123: );
2124:
2125: %defaultchecked = ('submitbugs' => 'on');
2126:
2127: @toggles = ('submitbugs',);
2128:
2129: foreach my $item (@toggles) {
2130: if ($defaultchecked{$item} eq 'on') {
2131: $checkedon{$item} = ' checked="checked" ';
2132: $checkedoff{$item} = ' ';
2133: } elsif ($defaultchecked{$item} eq 'off') {
2134: $checkedoff{$item} = ' checked="checked" ';
2135: $checkedon{$item} = ' ';
2136: }
2137: }
2138:
2139: if (ref($settings) eq 'HASH') {
2140: foreach my $item (@toggles) {
2141: if ($settings->{$item} eq '1') {
2142: $checkedon{$item} = ' checked="checked" ';
2143: $checkedoff{$item} = ' ';
2144: } elsif ($settings->{$item} eq '0') {
2145: $checkedoff{$item} = ' checked="checked" ';
2146: $checkedon{$item} = ' ';
2147: }
2148: }
2149: }
2150:
2151: foreach my $item (@toggles) {
2152: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2153: $datatable .=
2154: '<tr'.$css_class.'>
2155: <td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
2156: <td><span class="LC_nobreak"> </span></td>
2157: <td class="LC_right_item"><span class="LC_nobreak">
2158: <label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>
2159: <label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2160: '</span></td>'.
2161: '</tr>';
2162: $itemcount ++;
2163: }
2164:
2165: } else {
2166:
2167: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2168:
2169: $datatable .= '<tr'.$css_class.'>';
2170:
2171: if (ref($settings) eq 'HASH') {
2172: if ($settings->{'loginhelpurl'} ne '') {
2173: my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
2174: $datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
2175: $datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
2176: } else {
2177: $datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
2178: $datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
2179: }
2180: } else {
2181: $datatable .= '<td><span class="LC_left_item"> </span></td>';
2182: $datatable .= '<td><span class="LC_right_item"> </span></td>';
2183: }
2184:
2185: $datatable .= '<td width="33%"><span class="LC_right_item">';
2186: if ($switchserver) {
2187: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2188: } else {
2189: $datatable .= &mt('Upload Custom Login Page Help File:');
2190: $datatable .='<input type="file" name="loginhelpurl" />';
2191: }
2192: $datatable .= '</span></td></tr>';
2193:
2194: }
2195:
2196: return $datatable;
2197:
1.121 raeburn 2198: }
2199:
1.122 jms 2200:
1.121 raeburn 2201: sub radiobutton_prefs {
2202: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2203: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2204: (ref($choices) eq 'HASH'));
2205:
2206: my (%checkedon,%checkedoff,$datatable,$css_class);
2207:
2208: foreach my $item (@{$toggles}) {
2209: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2210: $checkedon{$item} = ' checked="checked" ';
2211: $checkedoff{$item} = ' ';
1.121 raeburn 2212: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2213: $checkedoff{$item} = ' checked="checked" ';
2214: $checkedon{$item} = ' ';
2215: }
2216: }
2217: if (ref($settings) eq 'HASH') {
1.121 raeburn 2218: foreach my $item (@{$toggles}) {
1.118 jms 2219: if ($settings->{$item} eq '1') {
2220: $checkedon{$item} = ' checked="checked" ';
2221: $checkedoff{$item} = ' ';
2222: } elsif ($settings->{$item} eq '0') {
2223: $checkedoff{$item} = ' checked="checked" ';
2224: $checkedon{$item} = ' ';
2225: }
2226: }
1.121 raeburn 2227: }
2228: foreach my $item (@{$toggles}) {
1.118 jms 2229: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2230: $datatable .=
2231: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2232: '</span></td>'.
2233: '<td class="LC_right_item"><span class="LC_nobreak">'.
2234: '<label><input type="radio" name="'.
2235: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2236: '</label> <label><input type="radio" name="'.$item.'" '.
2237: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2238: '</span></td>'.
2239: '</tr>';
2240: $itemcount ++;
1.121 raeburn 2241: }
2242: return ($datatable,$itemcount);
2243: }
2244:
2245: sub print_coursedefaults {
1.139 raeburn 2246: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2247: my ($css_class,$datatable);
2248: my $itemcount = 1;
1.139 raeburn 2249: if ($position eq 'top') {
2250: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2251: %choices =
2252: &Apache::lonlocal::texthash (
2253: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2254: );
2255: %defaultchecked = ('canuse_pdfforms' => 'off');
2256: @toggles = ('canuse_pdfforms',);
2257: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2258: \%choices,$itemcount);
1.139 raeburn 2259: $$rowtotal += $itemcount;
2260: } else {
2261: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2262: my %choices =
2263: &Apache::lonlocal::texthash (
2264: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2265: );
2266: my $currdefresponder;
2267: if (ref($settings) eq 'HASH') {
2268: $currdefresponder = $settings->{'anonsurvey_threshold'};
2269: }
2270: if (!$currdefresponder) {
2271: $currdefresponder = 10;
2272: } elsif ($currdefresponder < 1) {
2273: $currdefresponder = 1;
2274: }
2275: $datatable .=
2276: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2277: '</span></td>'.
2278: '<td class="LC_right_item"><span class="LC_nobreak">'.
2279: '<input type="text" name="anonsurvey_threshold"'.
2280: ' value="'.$currdefresponder.'" size="5" /></span>'.
2281: '</td></tr>';
2282: }
1.121 raeburn 2283: return $datatable;
1.118 jms 2284: }
2285:
1.137 raeburn 2286: sub print_usersessions {
2287: my ($position,$dom,$settings,$rowtotal) = @_;
2288: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2289: my (%by_ip,%by_location,@intdoms);
2290: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
2291: if (keys(%by_location) == 0) {
2292: if ($position eq 'top') {
2293: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
2294: &mt('Nothing to set here, as the cluster to which this domain belongs only contains this institution.');
2295: }
2296: }
1.137 raeburn 2297: my %lt = &usersession_titles();
2298: my $itemcount = 1;
1.140 raeburn 2299: my $numinrow = 5;
1.137 raeburn 2300: my $prefix;
2301: my @types;
2302: if ($position eq 'top') {
2303: $prefix = 'hosted';
2304: @types = ('excludedomain','includedomain');
2305: } else {
2306: $prefix = 'remote';
2307: @types = ('version','excludedomain','includedomain');
1.138 raeburn 2308: }
1.137 raeburn 2309: my (%current,%checkedon,%checkedoff);
2310: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 2311: my @locations = sort(keys(%by_location));
1.137 raeburn 2312: foreach my $type (@types) {
2313: $checkedon{$type} = '';
2314: $checkedoff{$type} = ' checked="checked"';
2315: }
2316: if (ref($settings) eq 'HASH') {
2317: if (ref($settings->{$prefix}) eq 'HASH') {
2318: foreach my $key (keys(%{$settings->{$prefix}})) {
2319: $current{$key} = $settings->{$prefix}{$key};
2320: if ($key eq 'version') {
2321: if ($current{$key} ne '') {
2322: $checkedon{$key} = ' checked="checked"';
2323: $checkedoff{$key} = '';
2324: }
2325: } elsif (ref($current{$key}) eq 'ARRAY') {
2326: $checkedon{$key} = ' checked="checked"';
2327: $checkedoff{$key} = '';
2328: }
2329: }
2330: }
2331: }
2332: foreach my $type (@types) {
1.140 raeburn 2333: next if ($type ne 'version' && !@locations);
1.137 raeburn 2334: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2335: $datatable .= '<tr'.$css_class.'>
2336: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2337: <span class="LC_nobreak">
2338: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2339: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2340: if ($type eq 'version') {
2341: my $selector = '<select name="'.$prefix.'_version">';
2342: foreach my $version (@lcversions) {
2343: my $selected = '';
2344: if ($current{'version'} eq $version) {
2345: $selected = ' selected="selected"';
2346: }
2347: $selector .= ' <option value="'.$version.'"'.
2348: $selected.'>'.$version.'</option>';
2349: }
2350: $selector .= '</select> ';
2351: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2352: } else {
2353: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2354: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2355: ' />'.(' 'x2).
2356: '<input type="button" value="'.&mt('uncheck all').'" '.
2357: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2358: "\n".
2359: '</div><div><table>';
2360: my $rem;
1.138 raeburn 2361: for (my $i=0; $i<@locations; $i++) {
2362: my ($showloc,$value,$checkedtype);
2363: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2364: my $ip = $by_location{$locations[$i]}->[0];
2365: if (ref($by_ip{$ip}) eq 'ARRAY') {
2366: $value = join(':',@{$by_ip{$ip}});
2367: $showloc = join(', ',@{$by_ip{$ip}});
2368: if (ref($current{$type}) eq 'ARRAY') {
2369: foreach my $loc (@{$by_ip{$ip}}) {
2370: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2371: $checkedtype = ' checked="checked"';
2372: last;
2373: }
2374: }
2375: }
1.137 raeburn 2376: }
2377: }
2378: $rem = $i%($numinrow);
2379: if ($rem == 0) {
2380: if ($i > 0) {
2381: $datatable .= '</tr>';
2382: }
2383: $datatable .= '<tr>';
2384: }
2385: $datatable .= '<td class="LC_left_item">'.
2386: '<span class="LC_nobreak"><label>'.
2387: '<input type="checkbox" name="'.$prefix.'_'.$type.
1.138 raeburn 2388: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
1.137 raeburn 2389: '</label></span></td>';
2390: }
1.138 raeburn 2391: $rem = @locations%($numinrow);
1.137 raeburn 2392: my $colsleft = $numinrow - $rem;
2393: if ($colsleft > 1 ) {
2394: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2395: ' </td>';
2396: } elsif ($colsleft == 1) {
2397: $datatable .= '<td class="LC_left_item"> </td>';
2398: }
2399: $datatable .= '</tr></table>';
2400: }
2401: $datatable .= '</td></tr>';
2402: $itemcount ++;
2403: }
2404: $$rowtotal += $itemcount;
2405: return $datatable;
2406: }
2407:
1.138 raeburn 2408: sub build_location_hashes {
2409: my ($intdoms,$by_ip,$by_location) = @_;
2410: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2411: (ref($by_location) eq 'HASH'));
2412: my %iphost = &Apache::lonnet::get_iphost();
2413: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2414: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2415: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2416: foreach my $id (@{$iphost{$primary_ip}}) {
2417: my $intdom = &Apache::lonnet::internet_dom($id);
2418: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2419: push(@{$intdoms},$intdom);
2420: }
2421: }
2422: }
2423: foreach my $ip (keys(%iphost)) {
2424: if (ref($iphost{$ip}) eq 'ARRAY') {
2425: foreach my $id (@{$iphost{$ip}}) {
2426: my $location = &Apache::lonnet::internet_dom($id);
2427: if ($location) {
2428: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2429: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2430: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2431: push(@{$by_ip->{$ip}},$location);
2432: }
2433: } else {
2434: $by_ip->{$ip} = [$location];
2435: }
2436: }
2437: }
2438: }
2439: }
2440: foreach my $ip (sort(keys(%{$by_ip}))) {
2441: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2442: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2443: my $first = $by_ip->{$ip}->[0];
2444: if (ref($by_location->{$first}) eq 'ARRAY') {
2445: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2446: push(@{$by_location->{$first}},$ip);
2447: }
2448: } else {
2449: $by_location->{$first} = [$ip];
2450: }
2451: }
2452: }
2453: return;
2454: }
2455:
1.28 raeburn 2456: sub contact_titles {
2457: my %titles = &Apache::lonlocal::texthash (
2458: 'supportemail' => 'Support E-mail address',
1.69 raeburn 2459: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 2460: 'errormail' => 'Error reports to be e-mailed to',
2461: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 2462: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
2463: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 2464: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 2465: );
2466: my %short_titles = &Apache::lonlocal::texthash (
2467: adminemail => 'Admin E-mail address',
2468: supportemail => 'Support E-mail',
2469: );
2470: return (\%titles,\%short_titles);
2471: }
2472:
1.72 raeburn 2473: sub tool_titles {
2474: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 2475: aboutme => 'Personal Information Page',
1.86 raeburn 2476: blog => 'Blog',
2477: portfolio => 'Portfolio',
1.88 bisitz 2478: official => 'Official courses (with institutional codes)',
2479: unofficial => 'Unofficial courses',
1.98 raeburn 2480: community => 'Communities',
1.86 raeburn 2481: );
1.72 raeburn 2482: return %titles;
2483: }
2484:
1.101 raeburn 2485: sub courserequest_titles {
2486: my %titles = &Apache::lonlocal::texthash (
2487: official => 'Official',
2488: unofficial => 'Unofficial',
2489: community => 'Communities',
2490: norequest => 'Not allowed',
1.104 raeburn 2491: approval => 'Approval by Dom. Coord.',
1.101 raeburn 2492: validate => 'With validation',
2493: autolimit => 'Numerical limit',
1.103 raeburn 2494: unlimited => '(blank for unlimited)',
1.101 raeburn 2495: );
2496: return %titles;
2497: }
2498:
2499: sub courserequest_conditions {
2500: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 2501: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 2502: validate => '(Processing of request subject to instittutional validation).',
2503: );
2504: return %conditions;
2505: }
2506:
2507:
1.27 raeburn 2508: sub print_usercreation {
1.30 raeburn 2509: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 2510: my $numinrow = 4;
1.28 raeburn 2511: my $datatable;
2512: if ($position eq 'top') {
1.30 raeburn 2513: $$rowtotal ++;
1.34 raeburn 2514: my $rowcount = 0;
1.32 raeburn 2515: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 2516: if (ref($rules) eq 'HASH') {
2517: if (keys(%{$rules}) > 0) {
1.32 raeburn 2518: $datatable .= &user_formats_row('username',$settings,$rules,
2519: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 2520: $$rowtotal ++;
1.32 raeburn 2521: $rowcount ++;
2522: }
2523: }
2524: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
2525: if (ref($idrules) eq 'HASH') {
2526: if (keys(%{$idrules}) > 0) {
2527: $datatable .= &user_formats_row('id',$settings,$idrules,
2528: $idruleorder,$numinrow,$rowcount);
2529: $$rowtotal ++;
2530: $rowcount ++;
1.28 raeburn 2531: }
2532: }
1.43 raeburn 2533: my ($emailrules,$emailruleorder) =
2534: &Apache::lonnet::inst_userrules($dom,'email');
2535: if (ref($emailrules) eq 'HASH') {
2536: if (keys(%{$emailrules}) > 0) {
2537: $datatable .= &user_formats_row('email',$settings,$emailrules,
2538: $emailruleorder,$numinrow,$rowcount);
2539: $$rowtotal ++;
2540: $rowcount ++;
2541: }
2542: }
1.39 raeburn 2543: if ($rowcount == 0) {
2544: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
2545: $$rowtotal ++;
2546: $rowcount ++;
2547: }
1.34 raeburn 2548: } elsif ($position eq 'middle') {
1.100 raeburn 2549: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 2550: my ($rules,$ruleorder) =
2551: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 2552: my %lt = &usercreation_types();
2553: my %checked;
1.50 raeburn 2554: my @selfcreate;
1.34 raeburn 2555: if (ref($settings) eq 'HASH') {
2556: if (ref($settings->{'cancreate'}) eq 'HASH') {
2557: foreach my $item (@creators) {
2558: $checked{$item} = $settings->{'cancreate'}{$item};
2559: }
1.50 raeburn 2560: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
2561: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
2562: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
2563: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
2564: @selfcreate = ('email','login','sso');
2565: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
2566: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
2567: }
2568: }
1.34 raeburn 2569: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
2570: foreach my $item (@creators) {
2571: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
2572: $checked{$item} = 'none';
2573: }
2574: }
2575: }
2576: }
2577: my $rownum = 0;
2578: foreach my $item (@creators) {
2579: $rownum ++;
1.50 raeburn 2580: if ($item ne 'selfcreate') {
2581: if ($checked{$item} eq '') {
1.43 raeburn 2582: $checked{$item} = 'any';
2583: }
1.34 raeburn 2584: }
2585: my $css_class;
2586: if ($rownum%2) {
2587: $css_class = '';
2588: } else {
2589: $css_class = ' class="LC_odd_row" ';
2590: }
2591: $datatable .= '<tr'.$css_class.'>'.
2592: '<td><span class="LC_nobreak">'.$lt{$item}.
2593: '</span></td><td align="right">';
1.50 raeburn 2594: my @options;
1.45 raeburn 2595: if ($item eq 'selfcreate') {
1.43 raeburn 2596: push(@options,('email','login','sso'));
2597: } else {
1.50 raeburn 2598: @options = ('any');
1.43 raeburn 2599: if (ref($rules) eq 'HASH') {
2600: if (keys(%{$rules}) > 0) {
2601: push(@options,('official','unofficial'));
2602: }
1.37 raeburn 2603: }
1.50 raeburn 2604: push(@options,'none');
1.37 raeburn 2605: }
2606: foreach my $option (@options) {
1.50 raeburn 2607: my $type = 'radio';
1.34 raeburn 2608: my $check = ' ';
1.50 raeburn 2609: if ($item eq 'selfcreate') {
2610: $type = 'checkbox';
2611: if (grep(/^\Q$option\E$/,@selfcreate)) {
2612: $check = ' checked="checked" ';
2613: }
2614: } else {
2615: if ($checked{$item} eq $option) {
2616: $check = ' checked="checked" ';
2617: }
1.34 raeburn 2618: }
2619: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 2620: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 2621: $item.'" value="'.$option.'"'.$check.'/> '.
2622: $lt{$option}.'</label> </span>';
2623: }
2624: $datatable .= '</td></tr>';
2625: }
1.93 raeburn 2626: my ($othertitle,$usertypes,$types) =
2627: &Apache::loncommon::sorted_inst_types($dom);
2628: if (ref($usertypes) eq 'HASH') {
2629: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 2630: my $createsettings;
2631: if (ref($settings) eq 'HASH') {
2632: $createsettings = $settings->{cancreate};
2633: }
2634: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 2635: $dom,$numinrow,$othertitle,
2636: 'statustocreate');
2637: $$rowtotal ++;
2638: }
2639: }
1.28 raeburn 2640: } else {
2641: my @contexts = ('author','course','domain');
2642: my @authtypes = ('int','krb4','krb5','loc');
2643: my %checked;
2644: if (ref($settings) eq 'HASH') {
2645: if (ref($settings->{'authtypes'}) eq 'HASH') {
2646: foreach my $item (@contexts) {
2647: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
2648: foreach my $auth (@authtypes) {
2649: if ($settings->{'authtypes'}{$item}{$auth}) {
2650: $checked{$item}{$auth} = ' checked="checked" ';
2651: }
2652: }
2653: }
2654: }
1.27 raeburn 2655: }
1.35 raeburn 2656: } else {
2657: foreach my $item (@contexts) {
1.36 raeburn 2658: foreach my $auth (@authtypes) {
1.35 raeburn 2659: $checked{$item}{$auth} = ' checked="checked" ';
2660: }
2661: }
1.27 raeburn 2662: }
1.28 raeburn 2663: my %title = &context_names();
2664: my %authname = &authtype_names();
2665: my $rownum = 0;
2666: my $css_class;
2667: foreach my $item (@contexts) {
2668: if ($rownum%2) {
2669: $css_class = '';
2670: } else {
2671: $css_class = ' class="LC_odd_row" ';
2672: }
1.30 raeburn 2673: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 2674: '<td>'.$title{$item}.
2675: '</td><td class="LC_left_item">'.
2676: '<span class="LC_nobreak">';
2677: foreach my $auth (@authtypes) {
2678: $datatable .= '<label>'.
2679: '<input type="checkbox" name="'.$item.'_auth" '.
2680: $checked{$item}{$auth}.' value="'.$auth.'" />'.
2681: $authname{$auth}.'</label> ';
2682: }
2683: $datatable .= '</span></td></tr>';
2684: $rownum ++;
1.27 raeburn 2685: }
1.30 raeburn 2686: $$rowtotal += $rownum;
1.27 raeburn 2687: }
2688: return $datatable;
2689: }
2690:
1.32 raeburn 2691: sub user_formats_row {
2692: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
2693: my $output;
2694: my %text = (
2695: 'username' => 'new usernames',
2696: 'id' => 'IDs',
1.45 raeburn 2697: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 2698: );
2699: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2700: $output = '<tr '.$css_class.'>'.
1.63 raeburn 2701: '<td><span class="LC_nobreak">';
2702: if ($type eq 'email') {
2703: $output .= &mt("Formats disallowed for $text{$type}: ");
2704: } else {
2705: $output .= &mt("Format rules to check for $text{$type}: ");
2706: }
2707: $output .= '</span></td>'.
2708: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 2709: my $rem;
2710: if (ref($ruleorder) eq 'ARRAY') {
2711: for (my $i=0; $i<@{$ruleorder}; $i++) {
2712: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
2713: my $rem = $i%($numinrow);
2714: if ($rem == 0) {
2715: if ($i > 0) {
2716: $output .= '</tr>';
2717: }
2718: $output .= '<tr>';
2719: }
2720: my $check = ' ';
1.39 raeburn 2721: if (ref($settings) eq 'HASH') {
2722: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
2723: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
2724: $check = ' checked="checked" ';
2725: }
1.27 raeburn 2726: }
2727: }
2728: $output .= '<td class="LC_left_item">'.
2729: '<span class="LC_nobreak"><label>'.
1.32 raeburn 2730: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 2731: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
2732: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
2733: }
2734: }
2735: $rem = @{$ruleorder}%($numinrow);
2736: }
2737: my $colsleft = $numinrow - $rem;
2738: if ($colsleft > 1 ) {
2739: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2740: ' </td>';
2741: } elsif ($colsleft == 1) {
2742: $output .= '<td class="LC_left_item"> </td>';
2743: }
2744: $output .= '</tr></table></td></tr>';
2745: return $output;
2746: }
2747:
1.34 raeburn 2748: sub usercreation_types {
2749: my %lt = &Apache::lonlocal::texthash (
2750: author => 'When adding a co-author',
2751: course => 'When adding a user to a course',
1.100 raeburn 2752: requestcrs => 'When requesting a course',
1.45 raeburn 2753: selfcreate => 'User creates own account',
1.34 raeburn 2754: any => 'Any',
2755: official => 'Institutional only ',
2756: unofficial => 'Non-institutional only',
1.85 schafran 2757: email => 'E-mail address',
1.43 raeburn 2758: login => 'Institutional Login',
2759: sso => 'SSO',
1.34 raeburn 2760: none => 'None',
2761: );
2762: return %lt;
1.48 raeburn 2763: }
1.34 raeburn 2764:
1.28 raeburn 2765: sub authtype_names {
2766: my %lt = &Apache::lonlocal::texthash(
2767: int => 'Internal',
2768: krb4 => 'Kerberos 4',
2769: krb5 => 'Kerberos 5',
2770: loc => 'Local',
2771: );
2772: return %lt;
2773: }
2774:
2775: sub context_names {
2776: my %context_title = &Apache::lonlocal::texthash(
2777: author => 'Creating users when an Author',
2778: course => 'Creating users when in a course',
2779: domain => 'Creating users when a Domain Coordinator',
2780: );
2781: return %context_title;
2782: }
2783:
1.33 raeburn 2784: sub print_usermodification {
2785: my ($position,$dom,$settings,$rowtotal) = @_;
2786: my $numinrow = 4;
2787: my ($context,$datatable,$rowcount);
2788: if ($position eq 'top') {
2789: $rowcount = 0;
2790: $context = 'author';
2791: foreach my $role ('ca','aa') {
2792: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2793: $numinrow,$rowcount);
2794: $$rowtotal ++;
2795: $rowcount ++;
2796: }
1.63 raeburn 2797: } elsif ($position eq 'middle') {
1.33 raeburn 2798: $context = 'course';
2799: $rowcount = 0;
2800: foreach my $role ('st','ep','ta','in','cr') {
2801: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2802: $numinrow,$rowcount);
2803: $$rowtotal ++;
2804: $rowcount ++;
2805: }
1.63 raeburn 2806: } elsif ($position eq 'bottom') {
2807: $context = 'selfcreate';
2808: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2809: $usertypes->{'default'} = $othertitle;
2810: if (ref($types) eq 'ARRAY') {
2811: push(@{$types},'default');
2812: $usertypes->{'default'} = $othertitle;
2813: foreach my $status (@{$types}) {
2814: $datatable .= &modifiable_userdata_row($context,$status,$settings,
2815: $numinrow,$rowcount,$usertypes);
2816: $$rowtotal ++;
2817: $rowcount ++;
2818: }
2819: }
1.33 raeburn 2820: }
2821: return $datatable;
2822: }
2823:
1.43 raeburn 2824: sub print_defaults {
2825: my ($dom,$rowtotal) = @_;
1.68 raeburn 2826: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 2827: 'datelocale_def','portal_def');
1.43 raeburn 2828: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 2829: my $titles = &defaults_titles($dom);
1.43 raeburn 2830: my $rownum = 0;
2831: my ($datatable,$css_class);
2832: foreach my $item (@items) {
2833: if ($rownum%2) {
2834: $css_class = '';
2835: } else {
2836: $css_class = ' class="LC_odd_row" ';
2837: }
2838: $datatable .= '<tr'.$css_class.'>'.
2839: '<td><span class="LC_nobreak">'.$titles->{$item}.
2840: '</span></td><td class="LC_right_item">';
2841: if ($item eq 'auth_def') {
2842: my @authtypes = ('internal','krb4','krb5','localauth');
2843: my %shortauth = (
2844: internal => 'int',
2845: krb4 => 'krb4',
2846: krb5 => 'krb5',
2847: localauth => 'loc'
2848: );
2849: my %authnames = &authtype_names();
2850: foreach my $auth (@authtypes) {
2851: my $checked = ' ';
2852: if ($domdefaults{$item} eq $auth) {
2853: $checked = ' checked="checked" ';
2854: }
2855: $datatable .= '<label><input type="radio" name="'.$item.
2856: '" value="'.$auth.'"'.$checked.'/>'.
2857: $authnames{$shortauth{$auth}}.'</label> ';
2858: }
1.54 raeburn 2859: } elsif ($item eq 'timezone_def') {
2860: my $includeempty = 1;
2861: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 2862: } elsif ($item eq 'datelocale_def') {
2863: my $includeempty = 1;
2864: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 2865: } else {
1.141 raeburn 2866: my $size;
2867: if ($item eq 'portal_def') {
2868: $size = ' size="25"';
2869: }
1.43 raeburn 2870: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 2871: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 2872: }
2873: $datatable .= '</td></tr>';
2874: $rownum ++;
2875: }
2876: $$rowtotal += $rownum;
2877: return $datatable;
2878: }
2879:
2880: sub defaults_titles {
1.141 raeburn 2881: my ($dom) = @_;
1.43 raeburn 2882: my %titles = &Apache::lonlocal::texthash (
2883: 'auth_def' => 'Default authentication type',
2884: 'auth_arg_def' => 'Default authentication argument',
2885: 'lang_def' => 'Default language',
1.54 raeburn 2886: 'timezone_def' => 'Default timezone',
1.68 raeburn 2887: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 2888: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 2889: );
1.141 raeburn 2890: if ($dom) {
2891: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
2892: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
2893: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
2894: $protocol = 'http' if ($protocol ne 'https');
2895: if ($uint_dom) {
2896: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
2897: $uint_dom);
2898: }
2899: }
1.43 raeburn 2900: return (\%titles);
2901: }
2902:
1.46 raeburn 2903: sub print_scantronformat {
2904: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
2905: my $itemcount = 1;
1.60 raeburn 2906: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
2907: %confhash);
1.46 raeburn 2908: my $switchserver = &check_switchserver($dom,$confname);
2909: my %lt = &Apache::lonlocal::texthash (
1.95 www 2910: default => 'Default bubblesheet format file error',
2911: custom => 'Custom bubblesheet format file error',
1.46 raeburn 2912: );
2913: my %scantronfiles = (
2914: default => 'default.tab',
2915: custom => 'custom.tab',
2916: );
2917: foreach my $key (keys(%scantronfiles)) {
2918: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
2919: .$scantronfiles{$key};
2920: }
2921: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
2922: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
2923: if (!$switchserver) {
2924: my $servadm = $r->dir_config('lonAdmEMail');
2925: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
2926: if ($configuserok eq 'ok') {
2927: if ($author_ok eq 'ok') {
2928: my %legacyfile = (
2929: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
2930: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
2931: );
2932: my %md5chk;
2933: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2934: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
2935: chomp($md5chk{$type});
1.46 raeburn 2936: }
2937: if ($md5chk{'default'} ne $md5chk{'custom'}) {
2938: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2939: ($scantronurls{$type},my $error) =
1.46 raeburn 2940: &legacy_scantronformat($r,$dom,$confname,
2941: $type,$legacyfile{$type},
2942: $scantronurls{$type},
2943: $scantronfiles{$type});
1.60 raeburn 2944: if ($error ne '') {
2945: $error{$type} = $error;
2946: }
2947: }
2948: if (keys(%error) == 0) {
2949: $is_custom = 1;
2950: $confhash{'scantron'}{'scantronformat'} =
2951: $scantronurls{'custom'};
2952: my $putresult =
2953: &Apache::lonnet::put_dom('configuration',
2954: \%confhash,$dom);
2955: if ($putresult ne 'ok') {
2956: $error{'custom'} =
2957: '<span class="LC_error">'.
2958: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2959: }
1.46 raeburn 2960: }
2961: } else {
1.60 raeburn 2962: ($scantronurls{'default'},my $error) =
1.46 raeburn 2963: &legacy_scantronformat($r,$dom,$confname,
2964: 'default',$legacyfile{'default'},
2965: $scantronurls{'default'},
2966: $scantronfiles{'default'});
1.60 raeburn 2967: if ($error eq '') {
2968: $confhash{'scantron'}{'scantronformat'} = '';
2969: my $putresult =
2970: &Apache::lonnet::put_dom('configuration',
2971: \%confhash,$dom);
2972: if ($putresult ne 'ok') {
2973: $error{'default'} =
2974: '<span class="LC_error">'.
2975: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2976: }
2977: } else {
2978: $error{'default'} = $error;
2979: }
1.46 raeburn 2980: }
2981: }
2982: }
2983: } else {
1.95 www 2984: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 2985: }
2986: }
2987: if (ref($settings) eq 'HASH') {
2988: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
2989: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
2990: if ((!@info) || ($info[0] eq 'no_such_dir')) {
2991: $scantronurl = '';
2992: } else {
2993: $scantronurl = $settings->{'scantronformat'};
2994: }
2995: $is_custom = 1;
2996: } else {
2997: $scantronurl = $scantronurls{'default'};
2998: }
2999: } else {
1.60 raeburn 3000: if ($is_custom) {
3001: $scantronurl = $scantronurls{'custom'};
3002: } else {
3003: $scantronurl = $scantronurls{'default'};
3004: }
1.46 raeburn 3005: }
3006: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3007: $datatable .= '<tr'.$css_class.'>';
3008: if (!$is_custom) {
1.65 raeburn 3009: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3010: '<span class="LC_nobreak">';
1.46 raeburn 3011: if ($scantronurl) {
3012: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3013: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3014: } else {
3015: $datatable = &mt('File unavailable for display');
3016: }
1.65 raeburn 3017: $datatable .= '</span></td>';
1.60 raeburn 3018: if (keys(%error) == 0) {
3019: $datatable .= '<td valign="bottom">';
3020: if (!$switchserver) {
3021: $datatable .= &mt('Upload:').'<br />';
3022: }
3023: } else {
3024: my $errorstr;
3025: foreach my $key (sort(keys(%error))) {
3026: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3027: }
3028: $datatable .= '<td>'.$errorstr;
3029: }
1.46 raeburn 3030: } else {
3031: if (keys(%error) > 0) {
3032: my $errorstr;
3033: foreach my $key (sort(keys(%error))) {
3034: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3035: }
1.60 raeburn 3036: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3037: } elsif ($scantronurl) {
1.65 raeburn 3038: $datatable .= '<td><span class="LC_nobreak">'.
3039: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3040: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3041: '<input type="checkbox" name="scantronformat_del"'.
3042: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3043: '<td><span class="LC_nobreak"> '.
3044: &mt('Replace:').'</span><br />';
1.46 raeburn 3045: }
3046: }
3047: if (keys(%error) == 0) {
3048: if ($switchserver) {
3049: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3050: } else {
1.65 raeburn 3051: $datatable .='<span class="LC_nobreak"> '.
3052: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3053: }
3054: }
3055: $datatable .= '</td></tr>';
3056: $$rowtotal ++;
3057: return $datatable;
3058: }
3059:
3060: sub legacy_scantronformat {
3061: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3062: my ($url,$error);
3063: my @statinfo = &Apache::lonnet::stat_file($newurl);
3064: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3065: (my $result,$url) =
3066: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3067: '','',$newfile);
3068: if ($result ne 'ok') {
1.130 raeburn 3069: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3070: }
3071: }
3072: return ($url,$error);
3073: }
1.43 raeburn 3074:
1.49 raeburn 3075: sub print_coursecategories {
1.57 raeburn 3076: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3077: my $datatable;
3078: if ($position eq 'top') {
3079: my $toggle_cats_crs = ' ';
3080: my $toggle_cats_dom = ' checked="checked" ';
3081: my $can_cat_crs = ' ';
3082: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3083: my $toggle_catscomm_comm = ' ';
3084: my $toggle_catscomm_dom = ' checked="checked" ';
3085: my $can_catcomm_comm = ' ';
3086: my $can_catcomm_dom = ' checked="checked" ';
3087:
1.57 raeburn 3088: if (ref($settings) eq 'HASH') {
3089: if ($settings->{'togglecats'} eq 'crs') {
3090: $toggle_cats_crs = $toggle_cats_dom;
3091: $toggle_cats_dom = ' ';
3092: }
3093: if ($settings->{'categorize'} eq 'crs') {
3094: $can_cat_crs = $can_cat_dom;
3095: $can_cat_dom = ' ';
3096: }
1.120 raeburn 3097: if ($settings->{'togglecatscomm'} eq 'comm') {
3098: $toggle_catscomm_comm = $toggle_catscomm_dom;
3099: $toggle_catscomm_dom = ' ';
3100: }
3101: if ($settings->{'categorizecomm'} eq 'comm') {
3102: $can_catcomm_comm = $can_catcomm_dom;
3103: $can_catcomm_dom = ' ';
3104: }
1.57 raeburn 3105: }
3106: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3107: togglecats => 'Show/Hide a course in catalog',
3108: togglecatscomm => 'Show/Hide a community in catalog',
3109: categorize => 'Assign a category to a course',
3110: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3111: );
3112: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3113: dom => 'Set in Domain',
3114: crs => 'Set in Course',
3115: comm => 'Set in Community',
1.57 raeburn 3116: );
3117: $datatable = '<tr class="LC_odd_row">'.
3118: '<td>'.$title{'togglecats'}.'</td>'.
3119: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3120: '<input type="radio" name="togglecats"'.
3121: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3122: '<label><input type="radio" name="togglecats"'.
3123: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3124: '</tr><tr>'.
3125: '<td>'.$title{'categorize'}.'</td>'.
3126: '<td class="LC_right_item"><span class="LC_nobreak">'.
3127: '<label><input type="radio" name="categorize"'.
3128: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3129: '<label><input type="radio" name="categorize"'.
3130: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3131: '</tr><tr class="LC_odd_row">'.
3132: '<td>'.$title{'togglecatscomm'}.'</td>'.
3133: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3134: '<input type="radio" name="togglecatscomm"'.
3135: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3136: '<label><input type="radio" name="togglecatscomm"'.
3137: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3138: '</tr><tr>'.
3139: '<td>'.$title{'categorizecomm'}.'</td>'.
3140: '<td class="LC_right_item"><span class="LC_nobreak">'.
3141: '<label><input type="radio" name="categorizecomm"'.
3142: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3143: '<label><input type="radio" name="categorizecomm"'.
3144: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3145: '</tr>';
1.120 raeburn 3146: $$rowtotal += 4;
1.57 raeburn 3147: } else {
3148: my $css_class;
3149: my $itemcount = 1;
3150: my $cathash;
3151: if (ref($settings) eq 'HASH') {
3152: $cathash = $settings->{'cats'};
3153: }
3154: if (ref($cathash) eq 'HASH') {
3155: my (@cats,@trails,%allitems,%idx,@jsarray);
3156: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3157: \%allitems,\%idx,\@jsarray);
3158: my $maxdepth = scalar(@cats);
3159: my $colattrib = '';
3160: if ($maxdepth > 2) {
3161: $colattrib = ' colspan="2" ';
3162: }
3163: my @path;
3164: if (@cats > 0) {
3165: if (ref($cats[0]) eq 'ARRAY') {
3166: my $numtop = @{$cats[0]};
3167: my $maxnum = $numtop;
1.120 raeburn 3168: my %default_names = (
3169: instcode => &mt('Official courses'),
3170: communities => &mt('Communities'),
3171: );
3172:
3173: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3174: ($cathash->{'instcode::0'} eq '') ||
3175: (!grep(/^communities$/,@{$cats[0]})) ||
3176: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3177: $maxnum ++;
3178: }
3179: my $lastidx;
3180: for (my $i=0; $i<$numtop; $i++) {
3181: my $parent = $cats[0][$i];
3182: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3183: my $item = &escape($parent).'::0';
3184: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3185: $lastidx = $idx{$item};
3186: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3187: .'<select name="'.$item.'"'.$chgstr.'>';
3188: for (my $k=0; $k<=$maxnum; $k++) {
3189: my $vpos = $k+1;
3190: my $selstr;
3191: if ($k == $i) {
3192: $selstr = ' selected="selected" ';
3193: }
3194: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3195: }
3196: $datatable .= '</select></td><td>';
1.120 raeburn 3197: if ($parent eq 'instcode' || $parent eq 'communities') {
3198: $datatable .= '<span class="LC_nobreak">'
3199: .$default_names{$parent}.'</span>';
3200: if ($parent eq 'instcode') {
3201: $datatable .= '<br /><span class="LC_nobreak">('
3202: .&mt('with institutional codes')
3203: .')</span></td><td'.$colattrib.'>';
3204: } else {
3205: $datatable .= '<table><tr><td>';
3206: }
3207: $datatable .= '<span class="LC_nobreak">'
3208: .'<label><input type="radio" name="'
3209: .$parent.'" value="1" checked="checked" />'
3210: .&mt('Display').'</label>';
3211: if ($parent eq 'instcode') {
3212: $datatable .= ' ';
3213: } else {
3214: $datatable .= '</span></td></tr><tr><td>'
3215: .'<span class="LC_nobreak">';
3216: }
3217: $datatable .= '<label><input type="radio" name="'
3218: .$parent.'" value="0" />'
3219: .&mt('Do not display').'</label></span>';
3220: if ($parent eq 'communities') {
3221: $datatable .= '</td></tr></table>';
3222: }
3223: $datatable .= '</td>';
1.57 raeburn 3224: } else {
3225: $datatable .= $parent
3226: .' <label><input type="checkbox" name="deletecategory" '
3227: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3228: }
3229: my $depth = 1;
3230: push(@path,$parent);
3231: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3232: pop(@path);
3233: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3234: $itemcount ++;
3235: }
1.48 raeburn 3236: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 3237: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3238: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 3239: for (my $k=0; $k<=$maxnum; $k++) {
3240: my $vpos = $k+1;
3241: my $selstr;
1.57 raeburn 3242: if ($k == $numtop) {
1.48 raeburn 3243: $selstr = ' selected="selected" ';
3244: }
3245: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3246: }
1.59 bisitz 3247: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 3248: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3249: .'</tr>'."\n";
1.48 raeburn 3250: $itemcount ++;
1.120 raeburn 3251: foreach my $default ('instcode','communities') {
3252: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3254: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3255: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3256: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3257: for (my $k=0; $k<=$maxnum; $k++) {
3258: my $vpos = $k+1;
3259: my $selstr;
3260: if ($k == $maxnum) {
3261: $selstr = ' selected="selected" ';
3262: }
3263: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 3264: }
1.120 raeburn 3265: $datatable .= '</select></span></td>'.
3266: '<td><span class="LC_nobreak">'.
3267: $default_names{$default}.'</span>';
3268: if ($default eq 'instcode') {
3269: $datatable .= '<br /><span class="LC_nobreak">('
3270: .&mt('with institutional codes').')</span>';
3271: }
3272: $datatable .= '</td>'
3273: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3274: .&mt('Display').'</label> '
3275: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3276: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 3277: }
3278: }
3279: }
1.57 raeburn 3280: } else {
3281: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 3282: }
3283: } else {
1.57 raeburn 3284: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3285: .&initialize_categories($itemcount);
1.48 raeburn 3286: }
1.57 raeburn 3287: $$rowtotal += $itemcount;
1.48 raeburn 3288: }
3289: return $datatable;
3290: }
3291:
1.69 raeburn 3292: sub print_serverstatuses {
3293: my ($dom,$settings,$rowtotal) = @_;
3294: my $datatable;
3295: my @pages = &serverstatus_pages();
3296: my (%namedaccess,%machineaccess);
3297: foreach my $type (@pages) {
3298: $namedaccess{$type} = '';
3299: $machineaccess{$type}= '';
3300: }
3301: if (ref($settings) eq 'HASH') {
3302: foreach my $type (@pages) {
3303: if (exists($settings->{$type})) {
3304: if (ref($settings->{$type}) eq 'HASH') {
3305: foreach my $key (keys(%{$settings->{$type}})) {
3306: if ($key eq 'namedusers') {
3307: $namedaccess{$type} = $settings->{$type}->{$key};
3308: } elsif ($key eq 'machines') {
3309: $machineaccess{$type} = $settings->{$type}->{$key};
3310: }
3311: }
3312: }
3313: }
3314: }
3315: }
1.81 raeburn 3316: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 3317: my $rownum = 0;
3318: my $css_class;
3319: foreach my $type (@pages) {
3320: $rownum ++;
3321: $css_class = $rownum%2?' class="LC_odd_row"':'';
3322: $datatable .= '<tr'.$css_class.'>'.
3323: '<td><span class="LC_nobreak">'.
3324: $titles->{$type}.'</span></td>'.
3325: '<td class="LC_left_item">'.
3326: '<input type="text" name="'.$type.'_namedusers" '.
3327: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3328: '<td class="LC_right_item">'.
3329: '<span class="LC_nobreak">'.
3330: '<input type="text" name="'.$type.'_machines" '.
3331: 'value="'.$machineaccess{$type}.'" size="10" />'.
3332: '</td></tr>'."\n";
3333: }
3334: $$rowtotal += $rownum;
3335: return $datatable;
3336: }
3337:
3338: sub serverstatus_pages {
3339: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3340: 'clusterstatus','metadata_keywords','metadata_harvest',
1.113 raeburn 3341: 'takeoffline','takeonline','showenv','toggledebug');
1.69 raeburn 3342: }
3343:
1.49 raeburn 3344: sub coursecategories_javascript {
3345: my ($settings) = @_;
1.57 raeburn 3346: my ($output,$jstext,$cathash);
1.49 raeburn 3347: if (ref($settings) eq 'HASH') {
1.57 raeburn 3348: $cathash = $settings->{'cats'};
3349: }
3350: if (ref($cathash) eq 'HASH') {
1.49 raeburn 3351: my (@cats,@jsarray,%idx);
1.57 raeburn 3352: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 3353: if (@jsarray > 0) {
3354: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3355: for (my $i=0; $i<@jsarray; $i++) {
3356: if (ref($jsarray[$i]) eq 'ARRAY') {
3357: my $catstr = join('","',@{$jsarray[$i]});
3358: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
3359: }
3360: }
3361: }
3362: } else {
3363: $jstext = ' var categories = Array(1);'."\n".
3364: ' categories[0] = Array("instcode_pos");'."\n";
3365: }
1.120 raeburn 3366: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
3367: my $communities_reserved = &mt('The name: "communities" is a reserved category');
3368: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 3369: $output = <<"ENDSCRIPT";
3370: <script type="text/javascript">
1.109 raeburn 3371: // <![CDATA[
1.49 raeburn 3372: function reorderCats(form,parent,item,idx) {
3373: var changedVal;
3374: $jstext
3375: var newpos = 'addcategory_pos';
3376: var current = new Array;
3377: if (parent == '') {
3378: var has_instcode = 0;
3379: var maxtop = categories[idx].length;
3380: for (var j=0; j<maxtop; j++) {
3381: if (categories[idx][j] == 'instcode::0') {
3382: has_instcode == 1;
3383: }
3384: }
3385: if (has_instcode == 0) {
3386: categories[idx][maxtop] = 'instcode_pos';
3387: }
3388: } else {
3389: newpos += '_'+parent;
3390: }
3391: var maxh = 1 + categories[idx].length;
3392: var current = new Array;
3393: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3394: if (item == newpos) {
3395: changedVal = newitemVal;
3396: } else {
3397: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3398: current[newitemVal] = newpos;
3399: }
3400: for (var i=0; i<categories[idx].length; i++) {
3401: var elementName = categories[idx][i];
3402: if (elementName != item) {
3403: if (form.elements[elementName]) {
3404: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3405: current[currVal] = elementName;
3406: }
3407: }
3408: }
3409: var oldVal;
3410: for (var j=0; j<maxh; j++) {
3411: if (current[j] == undefined) {
3412: oldVal = j;
3413: }
3414: }
3415: if (oldVal < changedVal) {
3416: for (var k=oldVal+1; k<=changedVal ; k++) {
3417: var elementName = current[k];
3418: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3419: }
3420: } else {
3421: for (var k=changedVal; k<oldVal; k++) {
3422: var elementName = current[k];
3423: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3424: }
3425: }
3426: return;
3427: }
1.120 raeburn 3428:
3429: function categoryCheck(form) {
3430: if (form.elements['addcategory_name'].value == 'instcode') {
3431: alert('$instcode_reserved\\n$choose_again');
3432: return false;
3433: }
3434: if (form.elements['addcategory_name'].value == 'communities') {
3435: alert('$communities_reserved\\n$choose_again');
3436: return false;
3437: }
3438: return true;
3439: }
3440:
1.109 raeburn 3441: // ]]>
1.49 raeburn 3442: </script>
3443:
3444: ENDSCRIPT
3445: return $output;
3446: }
3447:
1.48 raeburn 3448: sub initialize_categories {
3449: my ($itemcount) = @_;
1.120 raeburn 3450: my ($datatable,$css_class,$chgstr);
3451: my %default_names = (
3452: instcode => 'Official courses (with institutional codes)',
3453: communities => 'Communities',
3454: );
3455: my $select0 = ' selected="selected"';
3456: my $select1 = '';
3457: foreach my $default ('instcode','communities') {
3458: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3459: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3460: if ($default eq 'communities') {
3461: $select1 = $select0;
3462: $select0 = '';
3463: }
3464: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3465: .'<select name="'.$default.'_pos">'
3466: .'<option value="0"'.$select0.'>1</option>'
3467: .'<option value="1"'.$select1.'>2</option>'
3468: .'<option value="2">3</option></select> '
3469: .$default_names{$default}
3470: .'</span></td><td><span class="LC_nobreak">'
3471: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
3472: .&mt('Display').'</label> <label>'
3473: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 3474: .'</label></span></td></tr>';
1.120 raeburn 3475: $itemcount ++;
3476: }
1.48 raeburn 3477: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 3478: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 3479: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 3480: .'<select name="addcategory_pos"'.$chgstr.'>'
3481: .'<option value="0">1</option>'
3482: .'<option value="1">2</option>'
3483: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 3484: .&mt('Add category').'</td><td>'.&mt('Name:')
3485: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
3486: return $datatable;
3487: }
3488:
3489: sub build_category_rows {
1.49 raeburn 3490: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
3491: my ($text,$name,$item,$chgstr);
1.48 raeburn 3492: if (ref($cats) eq 'ARRAY') {
3493: my $maxdepth = scalar(@{$cats});
3494: if (ref($cats->[$depth]) eq 'HASH') {
3495: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
3496: my $numchildren = @{$cats->[$depth]{$parent}};
3497: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3498: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 3499: my ($idxnum,$parent_name,$parent_item);
3500: my $higher = $depth - 1;
3501: if ($higher == 0) {
3502: $parent_name = &escape($parent).'::'.$higher;
3503: } else {
3504: if (ref($path) eq 'ARRAY') {
3505: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
3506: }
3507: }
3508: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 3509: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 3510: if ($j < $numchildren) {
1.48 raeburn 3511: $name = $cats->[$depth]{$parent}[$j];
3512: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 3513: $idxnum = $idx->{$item};
3514: } else {
3515: $name = $parent_name;
3516: $item = $parent_item;
1.48 raeburn 3517: }
1.49 raeburn 3518: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
3519: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 3520: for (my $i=0; $i<=$numchildren; $i++) {
3521: my $vpos = $i+1;
3522: my $selstr;
3523: if ($j == $i) {
3524: $selstr = ' selected="selected" ';
3525: }
3526: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
3527: }
3528: $text .= '</select> ';
3529: if ($j < $numchildren) {
3530: my $deeper = $depth+1;
3531: $text .= $name.' '
3532: .'<label><input type="checkbox" name="deletecategory" value="'
3533: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
3534: if(ref($path) eq 'ARRAY') {
3535: push(@{$path},$name);
1.49 raeburn 3536: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 3537: pop(@{$path});
3538: }
3539: } else {
1.59 bisitz 3540: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 3541: if ($j == $numchildren) {
3542: $text .= $name;
3543: } else {
3544: $text .= $item;
3545: }
3546: $text .= '" value="" />';
3547: }
3548: $text .= '</td></tr>';
3549: }
3550: $text .= '</table></td>';
3551: } else {
3552: my $higher = $depth-1;
3553: if ($higher == 0) {
3554: $name = &escape($parent).'::'.$higher;
3555: } else {
3556: if (ref($path) eq 'ARRAY') {
3557: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
3558: }
3559: }
3560: my $colspan;
3561: if ($parent ne 'instcode') {
3562: $colspan = $maxdepth - $depth - 1;
3563: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
3564: }
3565: }
3566: }
3567: }
3568: return $text;
3569: }
3570:
1.33 raeburn 3571: sub modifiable_userdata_row {
1.63 raeburn 3572: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 3573: my $rolename;
1.63 raeburn 3574: if ($context eq 'selfcreate') {
3575: if (ref($usertypes) eq 'HASH') {
3576: $rolename = $usertypes->{$role};
3577: } else {
3578: $rolename = $role;
3579: }
1.33 raeburn 3580: } else {
1.63 raeburn 3581: if ($role eq 'cr') {
3582: $rolename = &mt('Custom role');
3583: } else {
3584: $rolename = &Apache::lonnet::plaintext($role);
3585: }
1.33 raeburn 3586: }
3587: my @fields = ('lastname','firstname','middlename','generation',
3588: 'permanentemail','id');
3589: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3590: my $output;
3591: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3592: $output = '<tr '.$css_class.'>'.
3593: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
3594: '<td class="LC_left_item" colspan="2"><table>';
3595: my $rem;
3596: my %checks;
3597: if (ref($settings) eq 'HASH') {
3598: if (ref($settings->{$context}) eq 'HASH') {
3599: if (ref($settings->{$context}->{$role}) eq 'HASH') {
3600: foreach my $field (@fields) {
3601: if ($settings->{$context}->{$role}->{$field}) {
3602: $checks{$field} = ' checked="checked" ';
3603: }
3604: }
3605: }
3606: }
3607: }
3608: for (my $i=0; $i<@fields; $i++) {
3609: my $rem = $i%($numinrow);
3610: if ($rem == 0) {
3611: if ($i > 0) {
3612: $output .= '</tr>';
3613: }
3614: $output .= '<tr>';
3615: }
3616: my $check = ' ';
3617: if (exists($checks{$fields[$i]})) {
3618: $check = $checks{$fields[$i]}
3619: } else {
3620: if ($role eq 'st') {
3621: if (ref($settings) ne 'HASH') {
3622: $check = ' checked="checked" ';
3623: }
3624: }
3625: }
3626: $output .= '<td class="LC_left_item">'.
3627: '<span class="LC_nobreak"><label>'.
3628: '<input type="checkbox" name="canmodify_'.$role.'" '.
3629: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
3630: '</label></span></td>';
3631: $rem = @fields%($numinrow);
3632: }
3633: my $colsleft = $numinrow - $rem;
3634: if ($colsleft > 1 ) {
3635: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3636: ' </td>';
3637: } elsif ($colsleft == 1) {
3638: $output .= '<td class="LC_left_item"> </td>';
3639: }
3640: $output .= '</tr></table></td></tr>';
3641: return $output;
3642: }
1.28 raeburn 3643:
1.93 raeburn 3644: sub insttypes_row {
3645: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
3646: my %lt = &Apache::lonlocal::texthash (
3647: cansearch => 'Users allowed to search',
3648: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 3649: lockablenames => 'User preference to lock name',
1.93 raeburn 3650: );
3651: my $showdom;
3652: if ($context eq 'cansearch') {
3653: $showdom = ' ('.$dom.')';
3654: }
1.25 raeburn 3655: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 3656: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 3657: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 3658: my $rem;
3659: if (ref($types) eq 'ARRAY') {
3660: for (my $i=0; $i<@{$types}; $i++) {
3661: if (defined($usertypes->{$types->[$i]})) {
3662: my $rem = $i%($numinrow);
3663: if ($rem == 0) {
3664: if ($i > 0) {
3665: $output .= '</tr>';
3666: }
3667: $output .= '<tr>';
1.23 raeburn 3668: }
1.26 raeburn 3669: my $check = ' ';
1.99 raeburn 3670: if (ref($settings) eq 'HASH') {
3671: if (ref($settings->{$context}) eq 'ARRAY') {
3672: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
3673: $check = ' checked="checked" ';
3674: }
3675: } elsif ($context eq 'statustocreate') {
1.26 raeburn 3676: $check = ' checked="checked" ';
3677: }
1.23 raeburn 3678: }
1.26 raeburn 3679: $output .= '<td class="LC_left_item">'.
3680: '<span class="LC_nobreak"><label>'.
1.93 raeburn 3681: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 3682: 'value="'.$types->[$i].'"'.$check.'/>'.
3683: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 3684: }
3685: }
1.26 raeburn 3686: $rem = @{$types}%($numinrow);
1.23 raeburn 3687: }
3688: my $colsleft = $numinrow - $rem;
1.131 raeburn 3689: if (($rem == 0) && (@{$types} > 0)) {
3690: $output .= '<tr>';
3691: }
1.23 raeburn 3692: if ($colsleft > 1) {
1.25 raeburn 3693: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 3694: } else {
1.25 raeburn 3695: $output .= '<td class="LC_left_item">';
1.23 raeburn 3696: }
3697: my $defcheck = ' ';
1.99 raeburn 3698: if (ref($settings) eq 'HASH') {
3699: if (ref($settings->{$context}) eq 'ARRAY') {
3700: if (grep(/^default$/,@{$settings->{$context}})) {
3701: $defcheck = ' checked="checked" ';
3702: }
3703: } elsif ($context eq 'statustocreate') {
1.26 raeburn 3704: $defcheck = ' checked="checked" ';
3705: }
1.23 raeburn 3706: }
1.25 raeburn 3707: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 3708: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 3709: 'value="default"'.$defcheck.'/>'.
3710: $othertitle.'</label></span></td>'.
3711: '</tr></table></td></tr>';
3712: return $output;
1.23 raeburn 3713: }
3714:
3715: sub sorted_searchtitles {
3716: my %searchtitles = &Apache::lonlocal::texthash(
3717: 'uname' => 'username',
3718: 'lastname' => 'last name',
3719: 'lastfirst' => 'last name, first name',
3720: );
3721: my @titleorder = ('uname','lastname','lastfirst');
3722: return (\%searchtitles,\@titleorder);
3723: }
3724:
1.25 raeburn 3725: sub sorted_searchtypes {
3726: my %srchtypes_desc = (
3727: exact => 'is exact match',
3728: contains => 'contains ..',
3729: begins => 'begins with ..',
3730: );
3731: my @srchtypeorder = ('exact','begins','contains');
3732: return (\%srchtypes_desc,\@srchtypeorder);
3733: }
3734:
1.3 raeburn 3735: sub usertype_update_row {
3736: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
3737: my $datatable;
3738: my $numinrow = 4;
3739: foreach my $type (@{$types}) {
3740: if (defined($usertypes->{$type})) {
3741: $$rownums ++;
3742: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
3743: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
3744: '</td><td class="LC_left_item"><table>';
3745: for (my $i=0; $i<@{$fields}; $i++) {
3746: my $rem = $i%($numinrow);
3747: if ($rem == 0) {
3748: if ($i > 0) {
3749: $datatable .= '</tr>';
3750: }
3751: $datatable .= '<tr>';
3752: }
3753: my $check = ' ';
1.39 raeburn 3754: if (ref($settings) eq 'HASH') {
3755: if (ref($settings->{'fields'}) eq 'HASH') {
3756: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
3757: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
3758: $check = ' checked="checked" ';
3759: }
1.3 raeburn 3760: }
3761: }
3762: }
3763:
3764: if ($i == @{$fields}-1) {
3765: my $colsleft = $numinrow - $rem;
3766: if ($colsleft > 1) {
3767: $datatable .= '<td colspan="'.$colsleft.'">';
3768: } else {
3769: $datatable .= '<td>';
3770: }
3771: } else {
3772: $datatable .= '<td>';
3773: }
1.8 raeburn 3774: $datatable .= '<span class="LC_nobreak"><label>'.
3775: '<input type="checkbox" name="updateable_'.$type.
3776: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
3777: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 3778: }
3779: $datatable .= '</tr></table></td></tr>';
3780: }
3781: }
3782: return $datatable;
1.1 raeburn 3783: }
3784:
3785: sub modify_login {
1.9 raeburn 3786: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 3787: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 3788: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 3789: adminmail => 'Display administrator E-mail address',
1.43 raeburn 3790: newuser => 'Link for visitors to create a user account',
1.41 raeburn 3791: loginheader => 'Log-in box header');
1.3 raeburn 3792: my @offon = ('off','on');
1.112 raeburn 3793: my %curr_loginvia;
3794: if (ref($domconfig{login}) eq 'HASH') {
3795: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
3796: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
3797: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
3798: }
3799: }
3800: }
1.6 raeburn 3801: my %loginhash;
1.9 raeburn 3802: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
3803: \%domconfig,\%loginhash);
1.118 jms 3804: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3805: foreach my $item (@toggles) {
3806: $loginhash{login}{$item} = $env{'form.'.$item};
3807: }
1.41 raeburn 3808: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 3809: if (ref($colchanges{'login'}) eq 'HASH') {
3810: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
3811: \%loginhash);
3812: }
1.110 raeburn 3813:
1.117 raeburn 3814: my %servers = &dom_servers($dom);
1.128 raeburn 3815: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 3816: if (keys(%servers) > 1) {
3817: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 3818: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
3819: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
3820: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
3821: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
3822: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
3823: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
3824: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
3825: $changes{'loginvia'}{$lonhost} = 1;
3826: } else {
3827: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
3828: $changes{'loginvia'}{$lonhost} = 1;
3829: }
3830: } else {
3831: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
3832: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
3833: $changes{'loginvia'}{$lonhost} = 1;
3834: }
3835: }
3836: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
3837: foreach my $item (@loginvia_attribs) {
3838: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
3839: }
3840: } else {
3841: foreach my $item (@loginvia_attribs) {
3842: my $new = $env{'form.'.$lonhost.'_'.$item};
3843: if (($item eq 'serverpath') && ($new eq 'custom')) {
3844: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
3845: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
3846: $new = '/';
3847: }
3848: }
3849: if (($item eq 'custompath') &&
3850: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
3851: $new = '';
3852: }
3853: if ($new ne $curr_loginvia{$lonhost}{$item}) {
3854: $changes{'loginvia'}{$lonhost} = 1;
3855: }
3856: if ($item eq 'exempt') {
3857: $new =~ s/^\s+//;
3858: $new =~ s/\s+$//;
3859: my @poss_ips = split(/\s*[,:]\s*/,$new);
3860: my @okips;
3861: foreach my $ip (@poss_ips) {
3862: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
3863: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
3864: push(@okips,$ip);
3865: }
3866: }
3867: }
3868: if (@okips > 0) {
3869: $new = join(',',@okips);
3870: } else {
3871: $new = '';
3872: }
3873: }
3874:
3875: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
3876: }
3877: }
1.112 raeburn 3878: } else {
1.128 raeburn 3879: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
3880: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 3881: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 3882: foreach my $item (@loginvia_attribs) {
3883: my $new = $env{'form.'.$lonhost.'_'.$item};
3884: if (($item eq 'serverpath') && ($new eq 'custom')) {
3885: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
3886: $new = '/';
3887: }
3888: }
3889: if (($item eq 'custompath') &&
3890: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
3891: $new = '';
3892: }
3893: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
3894: }
1.110 raeburn 3895: }
3896: }
3897: }
3898: }
1.119 raeburn 3899:
1.1 raeburn 3900: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
3901: $dom);
3902: if ($putresult eq 'ok') {
1.118 jms 3903: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3904: my %defaultchecked = (
3905: 'coursecatalog' => 'on',
3906: 'adminmail' => 'off',
1.43 raeburn 3907: 'newuser' => 'off',
1.42 raeburn 3908: );
1.55 raeburn 3909: if (ref($domconfig{'login'}) eq 'HASH') {
3910: foreach my $item (@toggles) {
3911: if ($defaultchecked{$item} eq 'on') {
3912: if (($domconfig{'login'}{$item} eq '0') &&
3913: ($env{'form.'.$item} eq '1')) {
3914: $changes{$item} = 1;
3915: } elsif (($domconfig{'login'}{$item} eq '' ||
3916: $domconfig{'login'}{$item} eq '1') &&
3917: ($env{'form.'.$item} eq '0')) {
3918: $changes{$item} = 1;
3919: }
3920: } elsif ($defaultchecked{$item} eq 'off') {
3921: if (($domconfig{'login'}{$item} eq '1') &&
3922: ($env{'form.'.$item} eq '0')) {
3923: $changes{$item} = 1;
3924: } elsif (($domconfig{'login'}{$item} eq '' ||
3925: $domconfig{'login'}{$item} eq '0') &&
3926: ($env{'form.'.$item} eq '1')) {
3927: $changes{$item} = 1;
3928: }
1.42 raeburn 3929: }
3930: }
1.41 raeburn 3931: }
1.6 raeburn 3932: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 3933: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 3934: $resulttext = &mt('Changes made:').'<ul>';
3935: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 3936: if ($item eq 'loginvia') {
1.112 raeburn 3937: if (ref($changes{$item}) eq 'HASH') {
3938: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
3939: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 3940: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
3941: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
3942: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
3943: $protocol = 'http' if ($protocol ne 'https');
3944: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
3945:
3946: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
3947: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
3948: } else {
3949: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
3950: }
3951: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
3952: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
3953: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
3954: }
3955: $resulttext .= '</li>';
3956: } else {
3957: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
3958: }
1.112 raeburn 3959: } else {
1.128 raeburn 3960: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 3961: }
3962: }
1.128 raeburn 3963: $resulttext .= '</ul></li>';
1.112 raeburn 3964: }
1.41 raeburn 3965: } else {
3966: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
3967: }
1.1 raeburn 3968: }
1.6 raeburn 3969: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 3970: } else {
3971: $resulttext = &mt('No changes made to log-in page settings');
3972: }
3973: } else {
1.11 albertel 3974: $resulttext = '<span class="LC_error">'.
3975: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3976: }
1.6 raeburn 3977: if ($errors) {
1.9 raeburn 3978: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 3979: $errors.'</ul>';
3980: }
3981: return $resulttext;
3982: }
3983:
3984: sub color_font_choices {
3985: my %choices =
3986: &Apache::lonlocal::texthash (
3987: img => "Header",
3988: bgs => "Background colors",
3989: links => "Link colors",
1.55 raeburn 3990: images => "Images",
1.6 raeburn 3991: font => "Font color",
1.97 tempelho 3992: fontmenu => "Font Menu",
1.76 raeburn 3993: pgbg => "Page",
1.6 raeburn 3994: tabbg => "Header",
3995: sidebg => "Border",
3996: link => "Link",
3997: alink => "Active link",
3998: vlink => "Visited link",
3999: );
4000: return %choices;
4001: }
4002:
4003: sub modify_rolecolors {
1.9 raeburn 4004: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4005: my ($resulttext,%rolehash);
4006: $rolehash{'rolecolors'} = {};
1.55 raeburn 4007: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4008: if ($domconfig{'rolecolors'} eq '') {
4009: $domconfig{'rolecolors'} = {};
4010: }
4011: }
1.9 raeburn 4012: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4013: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4014: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4015: $dom);
4016: if ($putresult eq 'ok') {
4017: if (keys(%changes) > 0) {
1.41 raeburn 4018: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4019: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4020: $rolehash{'rolecolors'});
4021: } else {
4022: $resulttext = &mt('No changes made to default color schemes');
4023: }
4024: } else {
1.11 albertel 4025: $resulttext = '<span class="LC_error">'.
4026: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4027: }
4028: if ($errors) {
4029: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4030: $errors.'</ul>';
4031: }
4032: return $resulttext;
4033: }
4034:
4035: sub modify_colors {
1.9 raeburn 4036: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 4037: my (%changes,%choices);
1.51 raeburn 4038: my @bgs;
1.6 raeburn 4039: my @links = ('link','alink','vlink');
1.41 raeburn 4040: my @logintext;
1.6 raeburn 4041: my @images;
4042: my $servadm = $r->dir_config('lonAdmEMail');
4043: my $errors;
4044: foreach my $role (@{$roles}) {
4045: if ($role eq 'login') {
1.12 raeburn 4046: %choices = &login_choices();
1.41 raeburn 4047: @logintext = ('textcol','bgcol');
1.12 raeburn 4048: } else {
4049: %choices = &color_font_choices();
1.107 raeburn 4050: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 4051: }
4052: if ($role eq 'login') {
1.41 raeburn 4053: @images = ('img','logo','domlogo','login');
1.51 raeburn 4054: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 4055: } else {
4056: @images = ('img');
1.51 raeburn 4057: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 4058: }
4059: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 4060: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 4061: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4062: }
1.46 raeburn 4063: my ($configuserok,$author_ok,$switchserver) =
4064: &config_check($dom,$confname,$servadm);
1.9 raeburn 4065: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 4066: if (ref($domconfig->{$role}) ne 'HASH') {
4067: $domconfig->{$role} = {};
4068: }
1.8 raeburn 4069: foreach my $img (@images) {
1.70 raeburn 4070: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4071: if (defined($env{'form.login_showlogo_'.$img})) {
4072: $confhash->{$role}{'showlogo'}{$img} = 1;
4073: } else {
4074: $confhash->{$role}{'showlogo'}{$img} = 0;
4075: }
4076: }
1.18 albertel 4077: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4078: && !defined($domconfig->{$role}{$img})
4079: && !$env{'form.'.$role.'_del_'.$img}
4080: && $env{'form.'.$role.'_import_'.$img}) {
4081: # import the old configured image from the .tab setting
4082: # if they haven't provided a new one
4083: $domconfig->{$role}{$img} =
4084: $env{'form.'.$role.'_import_'.$img};
4085: }
1.6 raeburn 4086: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 4087: my $error;
1.6 raeburn 4088: if ($configuserok eq 'ok') {
1.9 raeburn 4089: if ($switchserver) {
1.12 raeburn 4090: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 4091: } else {
4092: if ($author_ok eq 'ok') {
4093: my ($result,$logourl) =
4094: &publishlogo($r,'upload',$role.'_'.$img,
4095: $dom,$confname,$img,$width,$height);
4096: if ($result eq 'ok') {
4097: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 4098: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4099: } else {
1.12 raeburn 4100: $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 4101: }
4102: } else {
1.46 raeburn 4103: $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 4104: }
4105: }
4106: } else {
1.46 raeburn 4107: $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 4108: }
4109: if ($error) {
1.8 raeburn 4110: &Apache::lonnet::logthis($error);
1.11 albertel 4111: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 4112: }
4113: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 4114: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4115: my $error;
4116: if ($configuserok eq 'ok') {
4117: # is confname an author?
4118: if ($switchserver eq '') {
4119: if ($author_ok eq 'ok') {
4120: my ($result,$logourl) =
4121: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4122: $dom,$confname,$img,$width,$height);
4123: if ($result eq 'ok') {
4124: $confhash->{$role}{$img} = $logourl;
1.18 albertel 4125: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4126: }
4127: }
4128: }
4129: }
1.6 raeburn 4130: }
4131: }
4132: }
4133: if (ref($domconfig) eq 'HASH') {
4134: if (ref($domconfig->{$role}) eq 'HASH') {
4135: foreach my $img (@images) {
4136: if ($domconfig->{$role}{$img} ne '') {
4137: if ($env{'form.'.$role.'_del_'.$img}) {
4138: $confhash->{$role}{$img} = '';
1.12 raeburn 4139: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4140: } else {
1.9 raeburn 4141: if ($confhash->{$role}{$img} eq '') {
4142: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4143: }
1.6 raeburn 4144: }
4145: } else {
4146: if ($env{'form.'.$role.'_del_'.$img}) {
4147: $confhash->{$role}{$img} = '';
1.12 raeburn 4148: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4149: }
4150: }
1.70 raeburn 4151: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4152: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4153: if ($confhash->{$role}{'showlogo'}{$img} ne
4154: $domconfig->{$role}{'showlogo'}{$img}) {
4155: $changes{$role}{'showlogo'}{$img} = 1;
4156: }
4157: } else {
4158: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4159: $changes{$role}{'showlogo'}{$img} = 1;
4160: }
4161: }
4162: }
4163: }
1.6 raeburn 4164: if ($domconfig->{$role}{'font'} ne '') {
4165: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4166: $changes{$role}{'font'} = 1;
4167: }
4168: } else {
4169: if ($confhash->{$role}{'font'}) {
4170: $changes{$role}{'font'} = 1;
4171: }
4172: }
1.107 raeburn 4173: if ($role ne 'login') {
4174: if ($domconfig->{$role}{'fontmenu'} ne '') {
4175: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4176: $changes{$role}{'fontmenu'} = 1;
4177: }
4178: } else {
4179: if ($confhash->{$role}{'fontmenu'}) {
4180: $changes{$role}{'fontmenu'} = 1;
4181: }
1.97 tempelho 4182: }
4183: }
1.6 raeburn 4184: foreach my $item (@bgs) {
4185: if ($domconfig->{$role}{$item} ne '') {
4186: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4187: $changes{$role}{'bgs'}{$item} = 1;
4188: }
4189: } else {
4190: if ($confhash->{$role}{$item}) {
4191: $changes{$role}{'bgs'}{$item} = 1;
4192: }
4193: }
4194: }
4195: foreach my $item (@links) {
4196: if ($domconfig->{$role}{$item} ne '') {
4197: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4198: $changes{$role}{'links'}{$item} = 1;
4199: }
4200: } else {
4201: if ($confhash->{$role}{$item}) {
4202: $changes{$role}{'links'}{$item} = 1;
4203: }
4204: }
4205: }
1.41 raeburn 4206: foreach my $item (@logintext) {
4207: if ($domconfig->{$role}{$item} ne '') {
4208: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4209: $changes{$role}{'logintext'}{$item} = 1;
4210: }
4211: } else {
4212: if ($confhash->{$role}{$item}) {
4213: $changes{$role}{'logintext'}{$item} = 1;
4214: }
4215: }
4216: }
1.6 raeburn 4217: } else {
4218: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4219: \@logintext,$confhash,\%changes);
1.6 raeburn 4220: }
4221: } else {
4222: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4223: \@logintext,$confhash,\%changes);
1.6 raeburn 4224: }
4225: }
4226: return ($errors,%changes);
4227: }
4228:
1.46 raeburn 4229: sub config_check {
4230: my ($dom,$confname,$servadm) = @_;
4231: my ($configuserok,$author_ok,$switchserver,%currroles);
4232: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4233: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4234: $confname,$servadm);
4235: if ($configuserok eq 'ok') {
4236: $switchserver = &check_switchserver($dom,$confname);
4237: if ($switchserver eq '') {
4238: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4239: }
4240: }
4241: return ($configuserok,$author_ok,$switchserver);
4242: }
4243:
1.6 raeburn 4244: sub default_change_checker {
1.41 raeburn 4245: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 4246: foreach my $item (@{$links}) {
4247: if ($confhash->{$role}{$item}) {
4248: $changes->{$role}{'links'}{$item} = 1;
4249: }
4250: }
4251: foreach my $item (@{$bgs}) {
4252: if ($confhash->{$role}{$item}) {
4253: $changes->{$role}{'bgs'}{$item} = 1;
4254: }
4255: }
1.41 raeburn 4256: foreach my $item (@{$logintext}) {
4257: if ($confhash->{$role}{$item}) {
4258: $changes->{$role}{'logintext'}{$item} = 1;
4259: }
4260: }
1.6 raeburn 4261: foreach my $img (@{$images}) {
4262: if ($env{'form.'.$role.'_del_'.$img}) {
4263: $confhash->{$role}{$img} = '';
1.12 raeburn 4264: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 4265: }
1.70 raeburn 4266: if ($role eq 'login') {
4267: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4268: $changes->{$role}{'showlogo'}{$img} = 1;
4269: }
4270: }
1.6 raeburn 4271: }
4272: if ($confhash->{$role}{'font'}) {
4273: $changes->{$role}{'font'} = 1;
4274: }
1.48 raeburn 4275: }
1.6 raeburn 4276:
4277: sub display_colorchgs {
4278: my ($dom,$changes,$roles,$confhash) = @_;
4279: my (%choices,$resulttext);
4280: if (!grep(/^login$/,@{$roles})) {
4281: $resulttext = &mt('Changes made:').'<br />';
4282: }
4283: foreach my $role (@{$roles}) {
4284: if ($role eq 'login') {
4285: %choices = &login_choices();
4286: } else {
4287: %choices = &color_font_choices();
4288: }
4289: if (ref($changes->{$role}) eq 'HASH') {
4290: if ($role ne 'login') {
4291: $resulttext .= '<h4>'.&mt($role).'</h4>';
4292: }
4293: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4294: if ($role ne 'login') {
4295: $resulttext .= '<ul>';
4296: }
4297: if (ref($changes->{$role}{$key}) eq 'HASH') {
4298: if ($role ne 'login') {
4299: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4300: }
4301: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 4302: if (($role eq 'login') && ($key eq 'showlogo')) {
4303: if ($confhash->{$role}{$key}{$item}) {
4304: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4305: } else {
4306: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4307: }
4308: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 4309: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4310: } else {
1.12 raeburn 4311: my $newitem = $confhash->{$role}{$item};
4312: if ($key eq 'images') {
4313: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4314: }
4315: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 4316: }
4317: }
4318: if ($role ne 'login') {
4319: $resulttext .= '</ul></li>';
4320: }
4321: } else {
4322: if ($confhash->{$role}{$key} eq '') {
4323: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4324: } else {
4325: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4326: }
4327: }
4328: if ($role ne 'login') {
4329: $resulttext .= '</ul>';
4330: }
4331: }
4332: }
4333: }
1.3 raeburn 4334: return $resulttext;
1.1 raeburn 4335: }
4336:
1.9 raeburn 4337: sub thumb_dimensions {
4338: return ('200','50');
4339: }
4340:
1.16 raeburn 4341: sub check_dimensions {
4342: my ($inputfile) = @_;
4343: my ($fullwidth,$fullheight);
4344: if ($inputfile =~ m|^[/\w.\-]+$|) {
4345: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4346: my $imageinfo = <PIPE>;
4347: if (!close(PIPE)) {
4348: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4349: }
4350: chomp($imageinfo);
4351: my ($fullsize) =
1.21 raeburn 4352: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 4353: if ($fullsize) {
4354: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4355: }
4356: }
4357: }
4358: return ($fullwidth,$fullheight);
4359: }
4360:
1.9 raeburn 4361: sub check_configuser {
4362: my ($uhome,$dom,$confname,$servadm) = @_;
4363: my ($configuserok,%currroles);
4364: if ($uhome eq 'no_host') {
4365: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
4366: my $configpass = &LONCAPA::Enrollment::create_password();
4367: $configuserok =
4368: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
4369: $configpass,'','','','','',undef,$servadm);
4370: } else {
4371: $configuserok = 'ok';
4372: %currroles =
4373: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
4374: }
4375: return ($configuserok,%currroles);
4376: }
4377:
4378: sub check_authorstatus {
4379: my ($dom,$confname,%currroles) = @_;
4380: my $author_ok;
1.40 raeburn 4381: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 4382: my $start = time;
4383: my $end = 0;
4384: $author_ok =
4385: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 4386: 'au',$end,$start,'','','domconfig');
1.9 raeburn 4387: } else {
4388: $author_ok = 'ok';
4389: }
4390: return $author_ok;
4391: }
4392:
4393: sub publishlogo {
1.46 raeburn 4394: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 4395: my ($output,$fname,$logourl);
4396: if ($action eq 'upload') {
4397: $fname=$env{'form.'.$formname.'.filename'};
4398: chop($env{'form.'.$formname});
4399: } else {
4400: ($fname) = ($formname =~ /([^\/]+)$/);
4401: }
1.46 raeburn 4402: if ($savefileas ne '') {
4403: $fname = $savefileas;
4404: }
1.9 raeburn 4405: $fname=&Apache::lonnet::clean_filename($fname);
4406: # See if there is anything left
4407: unless ($fname) { return ('error: no uploaded file'); }
4408: $fname="$subdir/$fname";
4409: my $filepath='/home/'.$confname.'/public_html';
4410: my ($fnamepath,$file,$fetchthumb);
4411: $file=$fname;
4412: if ($fname=~m|/|) {
4413: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4414: }
4415: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4416: my $count;
4417: for ($count=4;$count<=$#parts;$count++) {
4418: $filepath.="/$parts[$count]";
4419: if ((-e $filepath)!=1) {
4420: mkdir($filepath,02770);
4421: }
4422: }
4423: # Check for bad extension and disallow upload
4424: if ($file=~/\.(\w+)$/ &&
4425: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4426: $output =
4427: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4428: } elsif ($file=~/\.(\w+)$/ &&
4429: !defined(&Apache::loncommon::fileembstyle($1))) {
4430: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4431: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 4432: $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 4433: } elsif (-d "$filepath/$file") {
4434: $output = &mt('File name is a directory name - rename the file and re-upload');
4435: } else {
4436: my $source = $filepath.'/'.$file;
4437: my $logfile;
4438: if (!open($logfile,">>$source".'.log')) {
4439: return (&mt('No write permission to Construction Space'));
4440: }
4441: print $logfile
4442: "\n================= Publish ".localtime()." ================\n".
4443: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4444: # Save the file
4445: if (!open(FH,'>'.$source)) {
4446: &Apache::lonnet::logthis('Failed to create '.$source);
4447: return (&mt('Failed to create file'));
4448: }
4449: if ($action eq 'upload') {
4450: if (!print FH ($env{'form.'.$formname})) {
4451: &Apache::lonnet::logthis('Failed to write to '.$source);
4452: return (&mt('Failed to write file'));
4453: }
4454: } else {
4455: my $original = &Apache::lonnet::filelocation('',$formname);
4456: if(!copy($original,$source)) {
4457: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4458: return (&mt('Failed to write file'));
4459: }
4460: }
4461: close(FH);
4462: chmod(0660, $source); # Permissions to rw-rw---.
4463:
4464: my $docroot=$r->dir_config('lonDocRoot');
4465: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4466: my $copyfile=$targetdir.'/'.$file;
4467:
4468: my @parts=split(/\//,$targetdir);
4469: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
4470: for (my $count=5;$count<=$#parts;$count++) {
4471: $path.="/$parts[$count]";
4472: if (!-e $path) {
4473: print $logfile "\nCreating directory ".$path;
4474: mkdir($path,02770);
4475: }
4476: }
4477: my $versionresult;
4478: if (-e $copyfile) {
4479: $versionresult = &logo_versioning($targetdir,$file,$logfile);
4480: } else {
4481: $versionresult = 'ok';
4482: }
4483: if ($versionresult eq 'ok') {
4484: if (copy($source,$copyfile)) {
4485: print $logfile "\nCopied original source to ".$copyfile."\n";
4486: $output = 'ok';
4487: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
4488: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
4489: } else {
4490: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
4491: $output = &mt('Failed to copy file to RES space').", $!";
4492: }
4493: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
4494: my $inputfile = $filepath.'/'.$file;
4495: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 4496: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
4497: if ($fullwidth ne '' && $fullheight ne '') {
4498: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
4499: my $thumbsize = $thumbwidth.'x'.$thumbheight;
4500: system("convert -sample $thumbsize $inputfile $outfile");
4501: chmod(0660, $filepath.'/tn-'.$file);
4502: if (-e $outfile) {
4503: my $copyfile=$targetdir.'/tn-'.$file;
4504: if (copy($outfile,$copyfile)) {
4505: print $logfile "\nCopied source to ".$copyfile."\n";
4506: &write_metadata($dom,$confname,$formname,
4507: $targetdir,'tn-'.$file,$logfile);
4508: } else {
4509: print $logfile "\nUnable to write ".$copyfile.
4510: ':'.$!."\n";
4511: }
4512: }
1.9 raeburn 4513: }
4514: }
4515: }
4516: } else {
4517: $output = $versionresult;
4518: }
4519: }
4520: return ($output,$logourl);
4521: }
4522:
4523: sub logo_versioning {
4524: my ($targetdir,$file,$logfile) = @_;
4525: my $target = $targetdir.'/'.$file;
4526: my ($maxversion,$fn,$extn,$output);
4527: $maxversion = 0;
4528: if ($file =~ /^(.+)\.(\w+)$/) {
4529: $fn=$1;
4530: $extn=$2;
4531: }
4532: opendir(DIR,$targetdir);
4533: while (my $filename=readdir(DIR)) {
4534: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
4535: $maxversion=($1>$maxversion)?$1:$maxversion;
4536: }
4537: }
4538: $maxversion++;
4539: print $logfile "\nCreating old version ".$maxversion."\n";
4540: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
4541: if (copy($target,$copyfile)) {
4542: print $logfile "Copied old target to ".$copyfile."\n";
4543: $copyfile=$copyfile.'.meta';
4544: if (copy($target.'.meta',$copyfile)) {
4545: print $logfile "Copied old target metadata to ".$copyfile."\n";
4546: $output = 'ok';
4547: } else {
4548: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
4549: $output = &mt('Failed to copy old meta').", $!, ";
4550: }
4551: } else {
4552: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
4553: $output = &mt('Failed to copy old target').", $!, ";
4554: }
4555: return $output;
4556: }
4557:
4558: sub write_metadata {
4559: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
4560: my (%metadatafields,%metadatakeys,$output);
4561: $metadatafields{'title'}=$formname;
4562: $metadatafields{'creationdate'}=time;
4563: $metadatafields{'lastrevisiondate'}=time;
4564: $metadatafields{'copyright'}='public';
4565: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
4566: $env{'user.domain'};
4567: $metadatafields{'authorspace'}=$confname.':'.$dom;
4568: $metadatafields{'domain'}=$dom;
4569: {
4570: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
4571: my $mfh;
4572: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
4573: $output = &mt('Could not write metadata');
4574: }
4575: foreach (sort keys %metadatafields) {
4576: unless ($_=~/\./) {
4577: my $unikey=$_;
4578: $unikey=~/^([A-Za-z]+)/;
4579: my $tag=$1;
4580: $tag=~tr/A-Z/a-z/;
4581: print $mfh "\n\<$tag";
4582: foreach (split(/\,/,$metadatakeys{$unikey})) {
4583: my $value=$metadatafields{$unikey.'.'.$_};
4584: $value=~s/\"/\'\'/g;
4585: print $mfh ' '.$_.'="'.$value.'"';
4586: }
4587: print $mfh '>'.
4588: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
4589: .'</'.$tag.'>';
4590: }
4591: }
4592: $output = 'ok';
4593: print $logfile "\nWrote metadata";
4594: close($mfh);
4595: }
4596: }
4597:
4598: sub check_switchserver {
4599: my ($dom,$confname) = @_;
4600: my ($allowed,$switchserver);
4601: my $home = &Apache::lonnet::homeserver($confname,$dom);
4602: if ($home eq 'no_host') {
4603: $home = &Apache::lonnet::domain($dom,'primary');
4604: }
4605: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 4606: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
4607: if (!$allowed) {
4608: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 4609: }
4610: return $switchserver;
4611: }
4612:
1.1 raeburn 4613: sub modify_quotas {
1.86 raeburn 4614: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 4615: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
4616: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 4617: if ($action eq 'quotas') {
4618: $context = 'tools';
4619: } else {
4620: $context = $action;
4621: }
4622: if ($context eq 'requestcourses') {
1.98 raeburn 4623: @usertools = ('official','unofficial','community');
1.106 raeburn 4624: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 4625: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
4626: %titles = &courserequest_titles();
4627: $toolregexp = join('|',@usertools);
4628: %conditions = &courserequest_conditions();
1.86 raeburn 4629: } else {
4630: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 4631: %titles = &tool_titles();
1.86 raeburn 4632: }
1.72 raeburn 4633: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 4634: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 4635: foreach my $key (keys(%env)) {
1.101 raeburn 4636: if ($context eq 'requestcourses') {
4637: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
4638: my $item = $1;
4639: my $type = $2;
4640: if ($type =~ /^limit_(.+)/) {
4641: $limithash{$item}{$1} = $env{$key};
4642: } else {
4643: $confhash{$item}{$type} = $env{$key};
4644: }
4645: }
4646: } else {
1.86 raeburn 4647: if ($key =~ /^form\.quota_(.+)$/) {
4648: $confhash{'defaultquota'}{$1} = $env{$key};
4649: }
1.101 raeburn 4650: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
4651: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
4652: }
1.72 raeburn 4653: }
4654: }
1.102 raeburn 4655: if ($context eq 'requestcourses') {
4656: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
4657: @approvalnotify = sort(@approvalnotify);
4658: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
4659: if (ref($domconfig{$action}) eq 'HASH') {
4660: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
4661: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
4662: $changes{'notify'}{'approval'} = 1;
4663: }
4664: } else {
4665: if ($domconfig{$action}{'notify'}{'approval'}) {
4666: $changes{'notify'}{'approval'} = 1;
4667: }
4668: }
4669: } else {
4670: if ($domconfig{$action}{'notify'}{'approval'}) {
4671: $changes{'notify'}{'approval'} = 1;
4672: }
4673: }
4674: } else {
1.86 raeburn 4675: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
4676: }
1.72 raeburn 4677: foreach my $item (@usertools) {
4678: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 4679: my $unset;
1.101 raeburn 4680: if ($context eq 'requestcourses') {
1.104 raeburn 4681: $unset = '0';
4682: if ($type eq '_LC_adv') {
4683: $unset = '';
4684: }
1.101 raeburn 4685: if ($confhash{$item}{$type} eq 'autolimit') {
4686: $confhash{$item}{$type} .= '=';
4687: unless ($limithash{$item}{$type} =~ /\D/) {
4688: $confhash{$item}{$type} .= $limithash{$item}{$type};
4689: }
4690: }
1.72 raeburn 4691: } else {
1.101 raeburn 4692: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
4693: $confhash{$item}{$type} = 1;
4694: } else {
4695: $confhash{$item}{$type} = 0;
4696: }
1.72 raeburn 4697: }
1.86 raeburn 4698: if (ref($domconfig{$action}) eq 'HASH') {
4699: if (ref($domconfig{$action}{$item}) eq 'HASH') {
4700: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
4701: $changes{$item}{$type} = 1;
4702: }
4703: } else {
4704: if ($context eq 'requestcourses') {
1.104 raeburn 4705: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 4706: $changes{$item}{$type} = 1;
4707: }
4708: } else {
4709: if (!$confhash{$item}{$type}) {
4710: $changes{$item}{$type} = 1;
4711: }
4712: }
4713: }
4714: } else {
4715: if ($context eq 'requestcourses') {
1.104 raeburn 4716: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 4717: $changes{$item}{$type} = 1;
4718: }
4719: } else {
4720: if (!$confhash{$item}{$type}) {
4721: $changes{$item}{$type} = 1;
4722: }
4723: }
4724: }
1.1 raeburn 4725: }
4726: }
1.86 raeburn 4727: unless ($context eq 'requestcourses') {
4728: if (ref($domconfig{'quotas'}) eq 'HASH') {
4729: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
4730: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
4731: if (exists($confhash{'defaultquota'}{$key})) {
4732: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
4733: $changes{'defaultquota'}{$key} = 1;
4734: }
4735: } else {
4736: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 4737: }
4738: }
1.86 raeburn 4739: } else {
4740: foreach my $key (keys(%{$domconfig{'quotas'}})) {
4741: if (exists($confhash{'defaultquota'}{$key})) {
4742: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
4743: $changes{'defaultquota'}{$key} = 1;
4744: }
4745: } else {
4746: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 4747: }
1.1 raeburn 4748: }
4749: }
4750: }
1.86 raeburn 4751: if (ref($confhash{'defaultquota'}) eq 'HASH') {
4752: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
4753: if (ref($domconfig{'quotas'}) eq 'HASH') {
4754: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
4755: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
4756: $changes{'defaultquota'}{$key} = 1;
4757: }
4758: } else {
4759: if (!exists($domconfig{'quotas'}{$key})) {
4760: $changes{'defaultquota'}{$key} = 1;
4761: }
1.72 raeburn 4762: }
4763: } else {
1.86 raeburn 4764: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 4765: }
1.1 raeburn 4766: }
4767: }
4768: }
1.72 raeburn 4769:
4770: foreach my $key (keys(%confhash)) {
4771: $domdefaults{$key} = $confhash{$key};
4772: }
4773:
1.1 raeburn 4774: my %quotahash = (
1.86 raeburn 4775: $action => { %confhash }
1.1 raeburn 4776: );
4777: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
4778: $dom);
4779: if ($putresult eq 'ok') {
4780: if (keys(%changes) > 0) {
1.72 raeburn 4781: my $cachetime = 24*60*60;
4782: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
4783:
1.1 raeburn 4784: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 4785: unless ($context eq 'requestcourses') {
4786: if (ref($changes{'defaultquota'}) eq 'HASH') {
4787: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
4788: foreach my $type (@{$types},'default') {
4789: if (defined($changes{'defaultquota'}{$type})) {
4790: my $typetitle = $usertypes->{$type};
4791: if ($type eq 'default') {
4792: $typetitle = $othertitle;
4793: }
4794: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 4795: }
4796: }
1.86 raeburn 4797: $resulttext .= '</ul></li>';
1.72 raeburn 4798: }
4799: }
1.80 raeburn 4800: my %newenv;
1.72 raeburn 4801: foreach my $item (@usertools) {
4802: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 4803: my $newacc =
4804: &Apache::lonnet::usertools_access($env{'user.name'},
4805: $env{'user.domain'},
1.86 raeburn 4806: $item,'reload',$context);
4807: if ($context eq 'requestcourses') {
1.108 raeburn 4808: if ($env{'environment.canrequest.'.$item} ne $newacc) {
4809: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 4810: }
4811: } else {
4812: if ($env{'environment.availabletools.'.$item} ne $newacc) {
4813: $newenv{'environment.availabletools.'.$item} = $newacc;
4814: }
1.80 raeburn 4815: }
1.72 raeburn 4816: $resulttext .= '<li>'.$titles{$item}.'<ul>';
4817: foreach my $type (@{$types},'default','_LC_adv') {
4818: if ($changes{$item}{$type}) {
4819: my $typetitle = $usertypes->{$type};
4820: if ($type eq 'default') {
4821: $typetitle = $othertitle;
4822: } elsif ($type eq '_LC_adv') {
4823: $typetitle = 'LON-CAPA Advanced Users';
4824: }
4825: if ($confhash{$item}{$type}) {
1.101 raeburn 4826: if ($context eq 'requestcourses') {
4827: my $cond;
4828: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
4829: if ($1 eq '') {
4830: $cond = &mt('(Automatic processing of any request).');
4831: } else {
4832: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
4833: }
4834: } else {
4835: $cond = $conditions{$confhash{$item}{$type}};
4836: }
4837: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
4838: } else {
4839: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
4840: }
1.72 raeburn 4841: } else {
1.104 raeburn 4842: if ($type eq '_LC_adv') {
4843: if ($confhash{$item}{$type} eq '0') {
4844: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
4845: } else {
4846: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
4847: }
4848: } else {
4849: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
4850: }
1.72 raeburn 4851: }
4852: }
1.26 raeburn 4853: }
1.72 raeburn 4854: $resulttext .= '</ul></li>';
1.26 raeburn 4855: }
1.1 raeburn 4856: }
1.102 raeburn 4857: if ($action eq 'requestcourses') {
4858: if (ref($changes{'notify'}) eq 'HASH') {
4859: if ($changes{'notify'}{'approval'}) {
4860: if (ref($confhash{'notify'}) eq 'HASH') {
4861: if ($confhash{'notify'}{'approval'}) {
4862: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
4863: } else {
4864: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
4865: }
4866: }
4867: }
4868: }
4869: }
1.1 raeburn 4870: $resulttext .= '</ul>';
1.80 raeburn 4871: if (keys(%newenv)) {
4872: &Apache::lonnet::appenv(\%newenv);
4873: }
1.1 raeburn 4874: } else {
1.86 raeburn 4875: if ($context eq 'requestcourses') {
4876: $resulttext = &mt('No changes made to rights to request creation of courses.');
4877: } else {
1.90 weissno 4878: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 4879: }
1.1 raeburn 4880: }
4881: } else {
1.11 albertel 4882: $resulttext = '<span class="LC_error">'.
4883: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4884: }
1.3 raeburn 4885: return $resulttext;
1.1 raeburn 4886: }
4887:
1.3 raeburn 4888: sub modify_autoenroll {
4889: my ($dom,%domconfig) = @_;
1.1 raeburn 4890: my ($resulttext,%changes);
4891: my %currautoenroll;
4892: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4893: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
4894: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
4895: }
4896: }
4897: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
4898: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 4899: sender => 'Sender for notification messages',
4900: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 4901: my @offon = ('off','on');
1.17 raeburn 4902: my $sender_uname = $env{'form.sender_uname'};
4903: my $sender_domain = $env{'form.sender_domain'};
4904: if ($sender_domain eq '') {
4905: $sender_uname = '';
4906: } elsif ($sender_uname eq '') {
4907: $sender_domain = '';
4908: }
1.129 raeburn 4909: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 4910: my %autoenrollhash = (
1.129 raeburn 4911: autoenroll => { 'run' => $env{'form.autoenroll_run'},
4912: 'sender_uname' => $sender_uname,
4913: 'sender_domain' => $sender_domain,
4914: 'co-owners' => $coowners,
1.1 raeburn 4915: }
4916: );
1.4 raeburn 4917: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
4918: $dom);
1.1 raeburn 4919: if ($putresult eq 'ok') {
4920: if (exists($currautoenroll{'run'})) {
4921: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
4922: $changes{'run'} = 1;
4923: }
4924: } elsif ($autorun) {
4925: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 4926: $changes{'run'} = 1;
1.1 raeburn 4927: }
4928: }
1.17 raeburn 4929: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 4930: $changes{'sender'} = 1;
4931: }
1.17 raeburn 4932: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 4933: $changes{'sender'} = 1;
4934: }
1.129 raeburn 4935: if ($currautoenroll{'co-owners'} ne '') {
4936: if ($currautoenroll{'co-owners'} ne $coowners) {
4937: $changes{'coowners'} = 1;
4938: }
4939: } elsif ($coowners) {
4940: $changes{'coowners'} = 1;
4941: }
1.1 raeburn 4942: if (keys(%changes) > 0) {
4943: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 4944: if ($changes{'run'}) {
1.1 raeburn 4945: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
4946: }
4947: if ($changes{'sender'}) {
1.17 raeburn 4948: if ($sender_uname eq '' || $sender_domain eq '') {
4949: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
4950: } else {
4951: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
4952: }
1.1 raeburn 4953: }
1.129 raeburn 4954: if ($changes{'coowners'}) {
4955: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
4956: &Apache::loncommon::devalidate_domconfig_cache($dom);
4957: }
1.1 raeburn 4958: $resulttext .= '</ul>';
4959: } else {
4960: $resulttext = &mt('No changes made to auto-enrollment settings');
4961: }
4962: } else {
1.11 albertel 4963: $resulttext = '<span class="LC_error">'.
4964: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4965: }
1.3 raeburn 4966: return $resulttext;
1.1 raeburn 4967: }
4968:
4969: sub modify_autoupdate {
1.3 raeburn 4970: my ($dom,%domconfig) = @_;
1.1 raeburn 4971: my ($resulttext,%currautoupdate,%fields,%changes);
4972: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
4973: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
4974: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
4975: }
4976: }
4977: my @offon = ('off','on');
4978: my %title = &Apache::lonlocal::texthash (
4979: run => 'Auto-update:',
4980: classlists => 'Updates to user information in classlists?'
4981: );
1.44 raeburn 4982: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 4983: my %fieldtitles = &Apache::lonlocal::texthash (
4984: id => 'Student/Employee ID',
1.20 raeburn 4985: permanentemail => 'E-mail address',
1.1 raeburn 4986: lastname => 'Last Name',
4987: firstname => 'First Name',
4988: middlename => 'Middle Name',
1.132 raeburn 4989: generation => 'Generation',
1.1 raeburn 4990: );
1.142 ! raeburn 4991: $othertitle = &mt('All users');
1.1 raeburn 4992: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 4993: $othertitle = &mt('Other users');
1.1 raeburn 4994: }
4995: foreach my $key (keys(%env)) {
4996: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 4997: my ($usertype,$item) = ($1,$2);
4998: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
4999: if ($usertype eq 'default') {
5000: push(@{$fields{$1}},$2);
5001: } elsif (ref($types) eq 'ARRAY') {
5002: if (grep(/^\Q$usertype\E$/,@{$types})) {
5003: push(@{$fields{$1}},$2);
5004: }
5005: }
5006: }
1.1 raeburn 5007: }
5008: }
1.131 raeburn 5009: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5010: @lockablenames = sort(@lockablenames);
5011: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5012: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5013: if (@changed) {
5014: $changes{'lockablenames'} = 1;
5015: }
5016: } else {
5017: if (@lockablenames) {
5018: $changes{'lockablenames'} = 1;
5019: }
5020: }
1.1 raeburn 5021: my %updatehash = (
5022: autoupdate => { run => $env{'form.autoupdate_run'},
5023: classlists => $env{'form.classlists'},
5024: fields => {%fields},
1.131 raeburn 5025: lockablenames => \@lockablenames,
1.1 raeburn 5026: }
5027: );
5028: foreach my $key (keys(%currautoupdate)) {
5029: if (($key eq 'run') || ($key eq 'classlists')) {
5030: if (exists($updatehash{autoupdate}{$key})) {
5031: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5032: $changes{$key} = 1;
5033: }
5034: }
5035: } elsif ($key eq 'fields') {
5036: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 5037: foreach my $item (@{$types},'default') {
1.1 raeburn 5038: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5039: my $change = 0;
5040: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5041: if (!exists($fields{$item})) {
5042: $change = 1;
1.132 raeburn 5043: last;
1.1 raeburn 5044: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 5045: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 5046: $change = 1;
1.132 raeburn 5047: last;
1.1 raeburn 5048: }
5049: }
5050: }
5051: if ($change) {
5052: push(@{$changes{$key}},$item);
5053: }
1.26 raeburn 5054: }
1.1 raeburn 5055: }
5056: }
1.131 raeburn 5057: } elsif ($key eq 'lockablenames') {
5058: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5059: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5060: if (@changed) {
5061: $changes{'lockablenames'} = 1;
5062: }
5063: } else {
5064: if (@lockablenames) {
5065: $changes{'lockablenames'} = 1;
5066: }
5067: }
5068: }
5069: }
5070: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5071: if (@lockablenames) {
5072: $changes{'lockablenames'} = 1;
1.1 raeburn 5073: }
5074: }
1.26 raeburn 5075: foreach my $item (@{$types},'default') {
5076: if (defined($fields{$item})) {
5077: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 5078: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5079: my $change = 0;
5080: if (ref($fields{$item}) eq 'ARRAY') {
5081: foreach my $type (@{$fields{$item}}) {
5082: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5083: $change = 1;
5084: last;
5085: }
5086: }
5087: }
5088: if ($change) {
5089: push(@{$changes{'fields'}},$item);
5090: }
5091: } else {
1.26 raeburn 5092: push(@{$changes{'fields'}},$item);
5093: }
5094: } else {
5095: push(@{$changes{'fields'}},$item);
1.1 raeburn 5096: }
5097: }
5098: }
5099: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5100: $dom);
5101: if ($putresult eq 'ok') {
5102: if (keys(%changes) > 0) {
5103: $resulttext = &mt('Changes made:').'<ul>';
5104: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 5105: if ($key eq 'lockablenames') {
5106: $resulttext .= '<li>';
5107: if (@lockablenames) {
5108: $usertypes->{'default'} = $othertitle;
5109: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5110: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5111: } else {
5112: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5113: }
5114: $resulttext .= '</li>';
5115: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 5116: foreach my $item (@{$changes{$key}}) {
5117: my @newvalues;
5118: foreach my $type (@{$fields{$item}}) {
5119: push(@newvalues,$fieldtitles{$type});
5120: }
1.3 raeburn 5121: my $newvaluestr;
5122: if (@newvalues > 0) {
5123: $newvaluestr = join(', ',@newvalues);
5124: } else {
5125: $newvaluestr = &mt('none');
1.6 raeburn 5126: }
1.1 raeburn 5127: if ($item eq 'default') {
1.26 raeburn 5128: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 5129: } else {
1.26 raeburn 5130: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 5131: }
5132: }
5133: } else {
5134: my $newvalue;
5135: if ($key eq 'run') {
5136: $newvalue = $offon[$env{'form.autoupdate_run'}];
5137: } else {
5138: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 5139: }
1.1 raeburn 5140: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5141: }
5142: }
5143: $resulttext .= '</ul>';
5144: } else {
1.3 raeburn 5145: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 5146: }
5147: } else {
1.11 albertel 5148: $resulttext = '<span class="LC_error">'.
5149: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5150: }
1.3 raeburn 5151: return $resulttext;
1.1 raeburn 5152: }
5153:
1.125 raeburn 5154: sub modify_autocreate {
5155: my ($dom,%domconfig) = @_;
5156: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5157: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5158: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5159: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5160: }
5161: }
5162: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5163: req => 'Auto-creation of validated requests for official courses',
5164: xmldc => 'Identity of course creator of courses from XML files',
5165: );
5166: my @types = ('xml','req');
5167: foreach my $item (@types) {
5168: $newvals{$item} = $env{'form.autocreate_'.$item};
5169: $newvals{$item} =~ s/\D//g;
5170: $newvals{$item} = 0 if ($newvals{$item} eq '');
5171: }
5172: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5173: my %domcoords = &get_active_dcs($dom);
5174: unless (exists($domcoords{$newvals{'xmldc'}})) {
5175: $newvals{'xmldc'} = '';
5176: }
5177: %autocreatehash = (
5178: autocreate => { xml => $newvals{'xml'},
5179: req => $newvals{'req'},
5180: }
5181: );
5182: if ($newvals{'xmldc'} ne '') {
5183: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5184: }
5185: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5186: $dom);
5187: if ($putresult eq 'ok') {
5188: my @items = @types;
5189: if ($newvals{'xml'}) {
5190: push(@items,'xmldc');
5191: }
5192: foreach my $item (@items) {
5193: if (exists($currautocreate{$item})) {
5194: if ($currautocreate{$item} ne $newvals{$item}) {
5195: $changes{$item} = 1;
5196: }
5197: } elsif ($newvals{$item}) {
5198: $changes{$item} = 1;
5199: }
5200: }
5201: if (keys(%changes) > 0) {
5202: my @offon = ('off','on');
5203: $resulttext = &mt('Changes made:').'<ul>';
5204: foreach my $item (@types) {
5205: if ($changes{$item}) {
5206: my $newtxt = $offon[$newvals{$item}];
5207: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5208: }
5209: }
5210: if ($changes{'xmldc'}) {
5211: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5212: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5213: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5214: }
5215: $resulttext .= '</ul>';
5216: } else {
5217: $resulttext = &mt('No changes made to auto-creation settings');
5218: }
5219: } else {
5220: $resulttext = '<span class="LC_error">'.
5221: &mt('An error occurred: [_1]',$putresult).'</span>';
5222: }
5223: return $resulttext;
5224: }
5225:
1.23 raeburn 5226: sub modify_directorysrch {
5227: my ($dom,%domconfig) = @_;
5228: my ($resulttext,%changes);
5229: my %currdirsrch;
5230: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5231: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5232: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5233: }
5234: }
5235: my %title = ( available => 'Directory search available',
1.24 raeburn 5236: localonly => 'Other domains can search',
1.23 raeburn 5237: searchby => 'Search types',
5238: searchtypes => 'Search latitude');
5239: my @offon = ('off','on');
1.24 raeburn 5240: my @otherdoms = ('Yes','No');
1.23 raeburn 5241:
1.25 raeburn 5242: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 5243: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5244: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5245:
1.44 raeburn 5246: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 5247: if (keys(%{$usertypes}) == 0) {
5248: @cansearch = ('default');
5249: } else {
5250: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
5251: foreach my $type (@{$currdirsrch{'cansearch'}}) {
5252: if (!grep(/^\Q$type\E$/,@cansearch)) {
5253: push(@{$changes{'cansearch'}},$type);
5254: }
1.23 raeburn 5255: }
1.26 raeburn 5256: foreach my $type (@cansearch) {
5257: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
5258: push(@{$changes{'cansearch'}},$type);
5259: }
1.23 raeburn 5260: }
1.26 raeburn 5261: } else {
5262: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 5263: }
5264: }
5265:
5266: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
5267: foreach my $by (@{$currdirsrch{'searchby'}}) {
5268: if (!grep(/^\Q$by\E$/,@searchby)) {
5269: push(@{$changes{'searchby'}},$by);
5270: }
5271: }
5272: foreach my $by (@searchby) {
5273: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
5274: push(@{$changes{'searchby'}},$by);
5275: }
5276: }
5277: } else {
5278: push(@{$changes{'searchby'}},@searchby);
5279: }
1.25 raeburn 5280:
5281: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
5282: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
5283: if (!grep(/^\Q$type\E$/,@searchtypes)) {
5284: push(@{$changes{'searchtypes'}},$type);
5285: }
5286: }
5287: foreach my $type (@searchtypes) {
5288: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
5289: push(@{$changes{'searchtypes'}},$type);
5290: }
5291: }
5292: } else {
5293: if (exists($currdirsrch{'searchtypes'})) {
5294: foreach my $type (@searchtypes) {
5295: if ($type ne $currdirsrch{'searchtypes'}) {
5296: push(@{$changes{'searchtypes'}},$type);
5297: }
5298: }
5299: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
5300: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
5301: }
5302: } else {
5303: push(@{$changes{'searchtypes'}},@searchtypes);
5304: }
5305: }
5306:
1.23 raeburn 5307: my %dirsrch_hash = (
5308: directorysrch => { available => $env{'form.dirsrch_available'},
5309: cansearch => \@cansearch,
1.24 raeburn 5310: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 5311: searchby => \@searchby,
1.25 raeburn 5312: searchtypes => \@searchtypes,
1.23 raeburn 5313: }
5314: );
5315: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
5316: $dom);
5317: if ($putresult eq 'ok') {
5318: if (exists($currdirsrch{'available'})) {
5319: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
5320: $changes{'available'} = 1;
5321: }
5322: } else {
5323: if ($env{'form.dirsrch_available'} eq '1') {
5324: $changes{'available'} = 1;
5325: }
5326: }
1.24 raeburn 5327: if (exists($currdirsrch{'localonly'})) {
5328: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
5329: $changes{'localonly'} = 1;
5330: }
5331: } else {
5332: if ($env{'form.dirsrch_localonly'} eq '1') {
5333: $changes{'localonly'} = 1;
5334: }
5335: }
1.23 raeburn 5336: if (keys(%changes) > 0) {
5337: $resulttext = &mt('Changes made:').'<ul>';
5338: if ($changes{'available'}) {
5339: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
5340: }
1.24 raeburn 5341: if ($changes{'localonly'}) {
5342: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
5343: }
5344:
1.23 raeburn 5345: if (ref($changes{'cansearch'}) eq 'ARRAY') {
5346: my $chgtext;
1.26 raeburn 5347: if (ref($usertypes) eq 'HASH') {
5348: if (keys(%{$usertypes}) > 0) {
5349: foreach my $type (@{$types}) {
5350: if (grep(/^\Q$type\E$/,@cansearch)) {
5351: $chgtext .= $usertypes->{$type}.'; ';
5352: }
5353: }
5354: if (grep(/^default$/,@cansearch)) {
5355: $chgtext .= $othertitle;
5356: } else {
5357: $chgtext =~ s/\; $//;
5358: }
5359: $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 5360: }
5361: }
5362: }
5363: if (ref($changes{'searchby'}) eq 'ARRAY') {
5364: my ($searchtitles,$titleorder) = &sorted_searchtitles();
5365: my $chgtext;
5366: foreach my $type (@{$titleorder}) {
5367: if (grep(/^\Q$type\E$/,@searchby)) {
5368: if (defined($searchtitles->{$type})) {
5369: $chgtext .= $searchtitles->{$type}.'; ';
5370: }
5371: }
5372: }
5373: $chgtext =~ s/\; $//;
5374: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5375: }
1.25 raeburn 5376: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5377: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5378: my $chgtext;
5379: foreach my $type (@{$srchtypeorder}) {
5380: if (grep(/^\Q$type\E$/,@searchtypes)) {
5381: if (defined($srchtypes_desc->{$type})) {
5382: $chgtext .= $srchtypes_desc->{$type}.'; ';
5383: }
5384: }
5385: }
5386: $chgtext =~ s/\; $//;
5387: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 5388: }
5389: $resulttext .= '</ul>';
5390: } else {
5391: $resulttext = &mt('No changes made to institution directory search settings');
5392: }
5393: } else {
5394: $resulttext = '<span class="LC_error">'.
1.27 raeburn 5395: &mt('An error occurred: [_1]',$putresult).'</span>';
5396: }
5397: return $resulttext;
5398: }
5399:
1.28 raeburn 5400: sub modify_contacts {
5401: my ($dom,%domconfig) = @_;
5402: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5403: if (ref($domconfig{'contacts'}) eq 'HASH') {
5404: foreach my $key (keys(%{$domconfig{'contacts'}})) {
5405: $currsetting{$key} = $domconfig{'contacts'}{$key};
5406: }
5407: }
1.134 raeburn 5408: my (%others,%to,%bcc);
1.28 raeburn 5409: my @contacts = ('supportemail','adminemail');
1.102 raeburn 5410: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
5411: 'requestsmail');
1.28 raeburn 5412: foreach my $type (@mailings) {
5413: @{$newsetting{$type}} =
5414: &Apache::loncommon::get_env_multiple('form.'.$type);
5415: foreach my $item (@contacts) {
5416: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
5417: $contacts_hash{contacts}{$type}{$item} = 1;
5418: } else {
5419: $contacts_hash{contacts}{$type}{$item} = 0;
5420: }
5421: }
5422: $others{$type} = $env{'form.'.$type.'_others'};
5423: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 5424: if ($type eq 'helpdeskmail') {
5425: $bcc{$type} = $env{'form.'.$type.'_bcc'};
5426: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
5427: }
1.28 raeburn 5428: }
5429: foreach my $item (@contacts) {
5430: $to{$item} = $env{'form.'.$item};
5431: $contacts_hash{'contacts'}{$item} = $to{$item};
5432: }
5433: if (keys(%currsetting) > 0) {
5434: foreach my $item (@contacts) {
5435: if ($to{$item} ne $currsetting{$item}) {
5436: $changes{$item} = 1;
5437: }
5438: }
5439: foreach my $type (@mailings) {
5440: foreach my $item (@contacts) {
5441: if (ref($currsetting{$type}) eq 'HASH') {
5442: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
5443: push(@{$changes{$type}},$item);
5444: }
5445: } else {
5446: push(@{$changes{$type}},@{$newsetting{$type}});
5447: }
5448: }
5449: if ($others{$type} ne $currsetting{$type}{'others'}) {
5450: push(@{$changes{$type}},'others');
5451: }
1.134 raeburn 5452: if ($type eq 'helpdeskmail') {
5453: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
5454: push(@{$changes{$type}},'bcc');
5455: }
5456: }
1.28 raeburn 5457: }
5458: } else {
5459: my %default;
5460: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
5461: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
5462: $default{'errormail'} = 'adminemail';
5463: $default{'packagesmail'} = 'adminemail';
5464: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 5465: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 5466: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 5467: foreach my $item (@contacts) {
5468: if ($to{$item} ne $default{$item}) {
5469: $changes{$item} = 1;
5470: }
5471: }
5472: foreach my $type (@mailings) {
5473: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
5474:
5475: push(@{$changes{$type}},@{$newsetting{$type}});
5476: }
5477: if ($others{$type} ne '') {
5478: push(@{$changes{$type}},'others');
1.134 raeburn 5479: }
5480: if ($type eq 'helpdeskmail') {
5481: if ($bcc{$type} ne '') {
5482: push(@{$changes{$type}},'bcc');
5483: }
5484: }
1.28 raeburn 5485: }
5486: }
5487: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
5488: $dom);
5489: if ($putresult eq 'ok') {
5490: if (keys(%changes) > 0) {
5491: my ($titles,$short_titles) = &contact_titles();
5492: $resulttext = &mt('Changes made:').'<ul>';
5493: foreach my $item (@contacts) {
5494: if ($changes{$item}) {
5495: $resulttext .= '<li>'.$titles->{$item}.
5496: &mt(' set to: ').
5497: '<span class="LC_cusr_emph">'.
5498: $to{$item}.'</span></li>';
5499: }
5500: }
5501: foreach my $type (@mailings) {
5502: if (ref($changes{$type}) eq 'ARRAY') {
5503: $resulttext .= '<li>'.$titles->{$type}.': ';
5504: my @text;
5505: foreach my $item (@{$newsetting{$type}}) {
5506: push(@text,$short_titles->{$item});
5507: }
5508: if ($others{$type} ne '') {
5509: push(@text,$others{$type});
5510: }
5511: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 5512: join(', ',@text).'</span>';
5513: if ($type eq 'helpdeskmail') {
5514: if ($bcc{$type} ne '') {
5515: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
5516: }
5517: }
5518: $resulttext .= '</li>';
1.28 raeburn 5519: }
5520: }
5521: $resulttext .= '</ul>';
5522: } else {
1.34 raeburn 5523: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 5524: }
5525: } else {
5526: $resulttext = '<span class="LC_error">'.
5527: &mt('An error occurred: [_1].',$putresult).'</span>';
5528: }
5529: return $resulttext;
5530: }
5531:
5532: sub modify_usercreation {
1.27 raeburn 5533: my ($dom,%domconfig) = @_;
1.34 raeburn 5534: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 5535: my $warningmsg;
1.27 raeburn 5536: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5537: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
5538: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
5539: }
5540: }
5541: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 5542: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 5543: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 5544: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 5545: foreach my $item(@contexts) {
1.45 raeburn 5546: if ($item eq 'selfcreate') {
1.50 raeburn 5547: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 5548: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5549: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 5550: if (ref($cancreate{$item}) eq 'ARRAY') {
5551: if (grep(/^login$/,@{$cancreate{$item}})) {
5552: $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.');
5553: }
1.43 raeburn 5554: }
5555: }
1.50 raeburn 5556: } else {
5557: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 5558: }
1.34 raeburn 5559: }
1.93 raeburn 5560: my ($othertitle,$usertypes,$types) =
5561: &Apache::loncommon::sorted_inst_types($dom);
5562: if (ref($types) eq 'ARRAY') {
5563: if (@{$types} > 0) {
5564: @{$cancreate{'statustocreate'}} =
5565: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 5566: } else {
5567: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 5568: }
5569: push(@contexts,'statustocreate');
5570: }
1.34 raeburn 5571: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
5572: foreach my $item (@contexts) {
1.93 raeburn 5573: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
5574: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 5575: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 5576: if (ref($cancreate{$item}) eq 'ARRAY') {
5577: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
5578: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5579: push(@{$changes{'cancreate'}},$item);
5580: }
1.50 raeburn 5581: }
5582: }
5583: }
5584: } else {
5585: if ($curr_usercreation{'cancreate'}{$item} eq '') {
5586: if (@{$cancreate{$item}} > 0) {
5587: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5588: push(@{$changes{'cancreate'}},$item);
5589: }
5590: }
5591: } else {
5592: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
5593: if (@{$cancreate{$item}} < 3) {
5594: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5595: push(@{$changes{'cancreate'}},$item);
5596: }
5597: }
5598: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
5599: if (@{$cancreate{$item}} > 0) {
5600: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5601: push(@{$changes{'cancreate'}},$item);
5602: }
5603: }
5604: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
5605: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5606: push(@{$changes{'cancreate'}},$item);
5607: }
5608: }
5609: }
5610: }
5611: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5612: foreach my $type (@{$cancreate{$item}}) {
5613: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
5614: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
5615: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5616: push(@{$changes{'cancreate'}},$item);
5617: }
5618: }
5619: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
5620: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
5621: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
5622: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5623: push(@{$changes{'cancreate'}},$item);
5624: }
5625: }
5626: }
5627: }
5628: }
5629: } else {
5630: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
5631: push(@{$changes{'cancreate'}},$item);
5632: }
5633: }
1.27 raeburn 5634: }
1.34 raeburn 5635: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
5636: foreach my $item (@contexts) {
1.43 raeburn 5637: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 5638: if ($cancreate{$item} ne 'any') {
5639: push(@{$changes{'cancreate'}},$item);
5640: }
5641: } else {
5642: if ($cancreate{$item} ne 'none') {
5643: push(@{$changes{'cancreate'}},$item);
5644: }
1.27 raeburn 5645: }
5646: }
5647: } else {
1.43 raeburn 5648: foreach my $item (@contexts) {
1.34 raeburn 5649: push(@{$changes{'cancreate'}},$item);
5650: }
1.27 raeburn 5651: }
1.34 raeburn 5652:
1.27 raeburn 5653: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
5654: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
5655: if (!grep(/^\Q$type\E$/,@username_rule)) {
5656: push(@{$changes{'username_rule'}},$type);
5657: }
5658: }
5659: foreach my $type (@username_rule) {
5660: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
5661: push(@{$changes{'username_rule'}},$type);
5662: }
5663: }
5664: } else {
5665: push(@{$changes{'username_rule'}},@username_rule);
5666: }
5667:
1.32 raeburn 5668: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
5669: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
5670: if (!grep(/^\Q$type\E$/,@id_rule)) {
5671: push(@{$changes{'id_rule'}},$type);
5672: }
5673: }
5674: foreach my $type (@id_rule) {
5675: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
5676: push(@{$changes{'id_rule'}},$type);
5677: }
5678: }
5679: } else {
5680: push(@{$changes{'id_rule'}},@id_rule);
5681: }
5682:
1.43 raeburn 5683: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
5684: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
5685: if (!grep(/^\Q$type\E$/,@email_rule)) {
5686: push(@{$changes{'email_rule'}},$type);
5687: }
5688: }
5689: foreach my $type (@email_rule) {
5690: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
5691: push(@{$changes{'email_rule'}},$type);
5692: }
5693: }
5694: } else {
5695: push(@{$changes{'email_rule'}},@email_rule);
5696: }
5697:
5698: my @authen_contexts = ('author','course','domain');
1.28 raeburn 5699: my @authtypes = ('int','krb4','krb5','loc');
5700: my %authhash;
1.43 raeburn 5701: foreach my $item (@authen_contexts) {
1.28 raeburn 5702: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
5703: foreach my $auth (@authtypes) {
5704: if (grep(/^\Q$auth\E$/,@authallowed)) {
5705: $authhash{$item}{$auth} = 1;
5706: } else {
5707: $authhash{$item}{$auth} = 0;
5708: }
5709: }
5710: }
5711: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 5712: foreach my $item (@authen_contexts) {
1.28 raeburn 5713: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
5714: foreach my $auth (@authtypes) {
5715: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
5716: push(@{$changes{'authtypes'}},$item);
5717: last;
5718: }
5719: }
5720: }
5721: }
5722: } else {
1.43 raeburn 5723: foreach my $item (@authen_contexts) {
1.28 raeburn 5724: push(@{$changes{'authtypes'}},$item);
5725: }
5726: }
5727:
1.27 raeburn 5728: my %usercreation_hash = (
1.28 raeburn 5729: usercreation => {
1.34 raeburn 5730: cancreate => \%cancreate,
1.27 raeburn 5731: username_rule => \@username_rule,
1.32 raeburn 5732: id_rule => \@id_rule,
1.43 raeburn 5733: email_rule => \@email_rule,
1.32 raeburn 5734: authtypes => \%authhash,
1.27 raeburn 5735: }
5736: );
5737:
5738: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
5739: $dom);
1.50 raeburn 5740:
5741: my %selfcreatetypes = (
5742: sso => 'users authenticated by institutional single sign on',
5743: login => 'users authenticated by institutional log-in',
5744: email => 'users who provide a valid e-mail address for use as the username',
5745: );
1.27 raeburn 5746: if ($putresult eq 'ok') {
5747: if (keys(%changes) > 0) {
5748: $resulttext = &mt('Changes made:').'<ul>';
5749: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 5750: my %lt = &usercreation_types();
5751: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 5752: my $chgtext;
5753: unless ($type eq 'statustocreate') {
5754: $chgtext = $lt{$type}.', ';
5755: }
1.45 raeburn 5756: if ($type eq 'selfcreate') {
1.50 raeburn 5757: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 5758: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 5759: } else {
1.100 raeburn 5760: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 5761: foreach my $case (@{$cancreate{$type}}) {
5762: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
5763: }
5764: $chgtext .= '</ul>';
1.100 raeburn 5765: if (ref($cancreate{$type}) eq 'ARRAY') {
5766: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
5767: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
5768: if (@{$cancreate{'statustocreate'}} == 0) {
5769: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
5770: }
5771: }
5772: }
5773: }
1.43 raeburn 5774: }
1.93 raeburn 5775: } elsif ($type eq 'statustocreate') {
1.96 raeburn 5776: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
5777: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
5778: if (@{$cancreate{'selfcreate'}} > 0) {
5779: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 5780:
5781: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 5782: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 5783: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
5784: }
1.96 raeburn 5785: } elsif (ref($usertypes) eq 'HASH') {
5786: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 5787: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
5788: } else {
5789: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
5790: }
5791: $chgtext .= '<ul>';
5792: foreach my $case (@{$cancreate{$type}}) {
5793: if ($case eq 'default') {
5794: $chgtext .= '<li>'.$othertitle.'</li>';
5795: } else {
5796: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 5797: }
5798: }
1.100 raeburn 5799: $chgtext .= '</ul>';
5800: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
5801: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
5802: }
5803: }
5804: } else {
5805: if (@{$cancreate{$type}} == 0) {
5806: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
5807: } else {
5808: $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 5809: }
5810: }
5811: }
1.43 raeburn 5812: } else {
5813: if ($cancreate{$type} eq 'none') {
5814: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
5815: } elsif ($cancreate{$type} eq 'any') {
5816: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
5817: } elsif ($cancreate{$type} eq 'official') {
5818: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
5819: } elsif ($cancreate{$type} eq 'unofficial') {
5820: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
5821: }
1.34 raeburn 5822: }
5823: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 5824: }
5825: }
5826: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 5827: my ($rules,$ruleorder) =
5828: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 5829: my $chgtext = '<ul>';
5830: foreach my $type (@username_rule) {
5831: if (ref($rules->{$type}) eq 'HASH') {
5832: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
5833: }
5834: }
5835: $chgtext .= '</ul>';
5836: if (@username_rule > 0) {
5837: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
5838: } else {
1.28 raeburn 5839: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 5840: }
5841: }
1.32 raeburn 5842: if (ref($changes{'id_rule'}) eq 'ARRAY') {
5843: my ($idrules,$idruleorder) =
5844: &Apache::lonnet::inst_userrules($dom,'id');
5845: my $chgtext = '<ul>';
5846: foreach my $type (@id_rule) {
5847: if (ref($idrules->{$type}) eq 'HASH') {
5848: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
5849: }
5850: }
5851: $chgtext .= '</ul>';
5852: if (@id_rule > 0) {
5853: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
5854: } else {
5855: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
5856: }
5857: }
1.43 raeburn 5858: if (ref($changes{'email_rule'}) eq 'ARRAY') {
5859: my ($emailrules,$emailruleorder) =
5860: &Apache::lonnet::inst_userrules($dom,'email');
5861: my $chgtext = '<ul>';
5862: foreach my $type (@email_rule) {
5863: if (ref($emailrules->{$type}) eq 'HASH') {
5864: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
5865: }
5866: }
5867: $chgtext .= '</ul>';
5868: if (@email_rule > 0) {
5869: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
5870: } else {
5871: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
5872: }
5873: }
5874:
1.28 raeburn 5875: my %authname = &authtype_names();
5876: my %context_title = &context_names();
5877: if (ref($changes{'authtypes'}) eq 'ARRAY') {
5878: my $chgtext = '<ul>';
5879: foreach my $type (@{$changes{'authtypes'}}) {
5880: my @allowed;
5881: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
5882: foreach my $auth (@authtypes) {
5883: if ($authhash{$type}{$auth}) {
5884: push(@allowed,$authname{$auth});
5885: }
5886: }
1.43 raeburn 5887: if (@allowed > 0) {
5888: $chgtext .= join(', ',@allowed).'</li>';
5889: } else {
5890: $chgtext .= &mt('none').'</li>';
5891: }
1.28 raeburn 5892: }
5893: $chgtext .= '</ul>';
5894: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
5895: $resulttext .= '</li>';
5896: }
1.27 raeburn 5897: $resulttext .= '</ul>';
5898: } else {
1.28 raeburn 5899: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 5900: }
5901: } else {
5902: $resulttext = '<span class="LC_error">'.
1.23 raeburn 5903: &mt('An error occurred: [_1]',$putresult).'</span>';
5904: }
1.43 raeburn 5905: if ($warningmsg ne '') {
5906: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
5907: }
1.23 raeburn 5908: return $resulttext;
5909: }
5910:
1.33 raeburn 5911: sub modify_usermodification {
5912: my ($dom,%domconfig) = @_;
5913: my ($resulttext,%curr_usermodification,%changes);
5914: if (ref($domconfig{'usermodification'}) eq 'HASH') {
5915: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
5916: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
5917: }
5918: }
1.63 raeburn 5919: my @contexts = ('author','course','selfcreate');
1.33 raeburn 5920: my %context_title = (
5921: author => 'In author context',
5922: course => 'In course context',
1.63 raeburn 5923: selfcreate => 'When self creating account',
1.33 raeburn 5924: );
5925: my @fields = ('lastname','firstname','middlename','generation',
5926: 'permanentemail','id');
5927: my %roles = (
5928: author => ['ca','aa'],
5929: course => ['st','ep','ta','in','cr'],
5930: );
1.63 raeburn 5931: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5932: if (ref($types) eq 'ARRAY') {
5933: push(@{$types},'default');
5934: $usertypes->{'default'} = $othertitle;
5935: }
5936: $roles{'selfcreate'} = $types;
1.33 raeburn 5937: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5938: my %modifyhash;
5939: foreach my $context (@contexts) {
5940: foreach my $role (@{$roles{$context}}) {
5941: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
5942: foreach my $item (@fields) {
5943: if (grep(/^\Q$item\E$/,@modifiable)) {
5944: $modifyhash{$context}{$role}{$item} = 1;
5945: } else {
5946: $modifyhash{$context}{$role}{$item} = 0;
5947: }
5948: }
5949: }
5950: if (ref($curr_usermodification{$context}) eq 'HASH') {
5951: foreach my $role (@{$roles{$context}}) {
5952: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
5953: foreach my $field (@fields) {
5954: if ($modifyhash{$context}{$role}{$field} ne
5955: $curr_usermodification{$context}{$role}{$field}) {
5956: push(@{$changes{$context}},$role);
5957: last;
5958: }
5959: }
5960: }
5961: }
5962: } else {
5963: foreach my $context (@contexts) {
5964: foreach my $role (@{$roles{$context}}) {
5965: push(@{$changes{$context}},$role);
5966: }
5967: }
5968: }
5969: }
5970: my %usermodification_hash = (
5971: usermodification => \%modifyhash,
5972: );
5973: my $putresult = &Apache::lonnet::put_dom('configuration',
5974: \%usermodification_hash,$dom);
5975: if ($putresult eq 'ok') {
5976: if (keys(%changes) > 0) {
5977: $resulttext = &mt('Changes made: ').'<ul>';
5978: foreach my $context (@contexts) {
5979: if (ref($changes{$context}) eq 'ARRAY') {
5980: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
5981: if (ref($changes{$context}) eq 'ARRAY') {
5982: foreach my $role (@{$changes{$context}}) {
5983: my $rolename;
1.63 raeburn 5984: if ($context eq 'selfcreate') {
5985: $rolename = $role;
5986: if (ref($usertypes) eq 'HASH') {
5987: if ($usertypes->{$role} ne '') {
5988: $rolename = $usertypes->{$role};
5989: }
5990: }
1.33 raeburn 5991: } else {
1.63 raeburn 5992: if ($role eq 'cr') {
5993: $rolename = &mt('Custom');
5994: } else {
5995: $rolename = &Apache::lonnet::plaintext($role);
5996: }
1.33 raeburn 5997: }
5998: my @modifiable;
1.63 raeburn 5999: if ($context eq 'selfcreate') {
1.126 bisitz 6000: $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): ');
1.63 raeburn 6001: } else {
6002: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6003: }
1.33 raeburn 6004: foreach my $field (@fields) {
6005: if ($modifyhash{$context}{$role}{$field}) {
6006: push(@modifiable,$fieldtitles{$field});
6007: }
6008: }
6009: if (@modifiable > 0) {
6010: $resulttext .= join(', ',@modifiable);
6011: } else {
6012: $resulttext .= &mt('none');
6013: }
6014: $resulttext .= '</li>';
6015: }
6016: $resulttext .= '</ul></li>';
6017: }
6018: }
6019: }
6020: $resulttext .= '</ul>';
6021: } else {
6022: $resulttext = &mt('No changes made to user modification settings');
6023: }
6024: } else {
6025: $resulttext = '<span class="LC_error">'.
6026: &mt('An error occurred: [_1]',$putresult).'</span>';
6027: }
6028: return $resulttext;
6029: }
6030:
1.43 raeburn 6031: sub modify_defaults {
6032: my ($dom,$r) = @_;
6033: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6034: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 6035: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 6036: my @authtypes = ('internal','krb4','krb5','localauth');
6037: foreach my $item (@items) {
6038: $newvalues{$item} = $env{'form.'.$item};
6039: if ($item eq 'auth_def') {
6040: if ($newvalues{$item} ne '') {
6041: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6042: push(@errors,$item);
6043: }
6044: }
6045: } elsif ($item eq 'lang_def') {
6046: if ($newvalues{$item} ne '') {
6047: if ($newvalues{$item} =~ /^(\w+)/) {
6048: my $langcode = $1;
1.103 raeburn 6049: if ($langcode ne 'x_chef') {
6050: if (code2language($langcode) eq '') {
6051: push(@errors,$item);
6052: }
1.43 raeburn 6053: }
6054: } else {
6055: push(@errors,$item);
6056: }
6057: }
1.54 raeburn 6058: } elsif ($item eq 'timezone_def') {
6059: if ($newvalues{$item} ne '') {
1.62 raeburn 6060: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 6061: push(@errors,$item);
6062: }
6063: }
1.68 raeburn 6064: } elsif ($item eq 'datelocale_def') {
6065: if ($newvalues{$item} ne '') {
6066: my @datelocale_ids = DateTime::Locale->ids();
6067: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6068: push(@errors,$item);
6069: }
6070: }
1.141 raeburn 6071: } elsif ($item eq 'portal_def') {
6072: if ($newvalues{$item} ne '') {
6073: unless ($newvalues{$item} =~ /^https?\:\/\/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\/?$/) {
6074: push(@errors,$item);
6075: }
6076: }
1.43 raeburn 6077: }
6078: if (grep(/^\Q$item\E$/,@errors)) {
6079: $newvalues{$item} = $domdefaults{$item};
6080: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6081: $changes{$item} = 1;
6082: }
1.72 raeburn 6083: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 6084: }
6085: my %defaults_hash = (
1.72 raeburn 6086: defaults => \%newvalues,
6087: );
1.43 raeburn 6088: my $title = &defaults_titles();
6089: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6090: $dom);
6091: if ($putresult eq 'ok') {
6092: if (keys(%changes) > 0) {
6093: $resulttext = &mt('Changes made:').'<ul>';
6094: my $version = $r->dir_config('lonVersion');
6095: 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";
6096: foreach my $item (sort(keys(%changes))) {
6097: my $value = $env{'form.'.$item};
6098: if ($value eq '') {
6099: $value = &mt('none');
6100: } elsif ($item eq 'auth_def') {
6101: my %authnames = &authtype_names();
6102: my %shortauth = (
6103: internal => 'int',
6104: krb4 => 'krb4',
6105: krb5 => 'krb5',
6106: localauth => 'loc',
6107: );
6108: $value = $authnames{$shortauth{$value}};
6109: }
6110: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6111: $mailmsgtext .= "$title->{$item} set to $value\n";
6112: }
6113: $resulttext .= '</ul>';
6114: $mailmsgtext .= "\n";
6115: my $cachetime = 24*60*60;
1.72 raeburn 6116: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 6117: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 6118: my $sysmail = $r->dir_config('lonSysEMail');
6119: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6120: }
1.43 raeburn 6121: } else {
1.54 raeburn 6122: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 6123: }
6124: } else {
6125: $resulttext = '<span class="LC_error">'.
6126: &mt('An error occurred: [_1]',$putresult).'</span>';
6127: }
6128: if (@errors > 0) {
6129: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6130: foreach my $item (@errors) {
6131: $resulttext .= ' "'.$title->{$item}.'",';
6132: }
6133: $resulttext =~ s/,$//;
6134: }
6135: return $resulttext;
6136: }
6137:
1.46 raeburn 6138: sub modify_scantron {
1.48 raeburn 6139: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 6140: my ($resulttext,%confhash,%changes,$errors);
6141: my $custom = 'custom.tab';
6142: my $default = 'default.tab';
6143: my $servadm = $r->dir_config('lonAdmEMail');
6144: my ($configuserok,$author_ok,$switchserver) =
6145: &config_check($dom,$confname,$servadm);
6146: if ($env{'form.scantronformat.filename'} ne '') {
6147: my $error;
6148: if ($configuserok eq 'ok') {
6149: if ($switchserver) {
1.130 raeburn 6150: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 6151: } else {
6152: if ($author_ok eq 'ok') {
6153: my ($result,$scantronurl) =
6154: &publishlogo($r,'upload','scantronformat',$dom,
6155: $confname,'scantron','','',$custom);
6156: if ($result eq 'ok') {
6157: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 6158: $changes{'scantronformat'} = 1;
1.46 raeburn 6159: } else {
6160: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6161: }
6162: } else {
6163: $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);
6164: }
6165: }
6166: } else {
6167: $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);
6168: }
6169: if ($error) {
6170: &Apache::lonnet::logthis($error);
6171: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6172: }
6173: }
1.48 raeburn 6174: if (ref($domconfig{'scantron'}) eq 'HASH') {
6175: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6176: if ($env{'form.scantronformat_del'}) {
6177: $confhash{'scantron'}{'scantronformat'} = '';
6178: $changes{'scantronformat'} = 1;
1.46 raeburn 6179: }
6180: }
6181: }
6182: if (keys(%confhash) > 0) {
6183: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6184: $dom);
6185: if ($putresult eq 'ok') {
6186: if (keys(%changes) > 0) {
1.48 raeburn 6187: if (ref($confhash{'scantron'}) eq 'HASH') {
6188: $resulttext = &mt('Changes made:').'<ul>';
6189: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 6190: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 6191: } else {
1.130 raeburn 6192: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 6193: }
1.48 raeburn 6194: $resulttext .= '</ul>';
6195: } else {
1.130 raeburn 6196: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 6197: }
6198: $resulttext .= '</ul>';
6199: &Apache::loncommon::devalidate_domconfig_cache($dom);
6200: } else {
1.130 raeburn 6201: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6202: }
6203: } else {
6204: $resulttext = '<span class="LC_error">'.
6205: &mt('An error occurred: [_1]',$putresult).'</span>';
6206: }
6207: } else {
1.130 raeburn 6208: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6209: }
6210: if ($errors) {
6211: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6212: $errors.'</ul>';
6213: }
6214: return $resulttext;
6215: }
6216:
1.48 raeburn 6217: sub modify_coursecategories {
6218: my ($dom,%domconfig) = @_;
1.57 raeburn 6219: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6220: $cathash);
1.48 raeburn 6221: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 6222: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 6223: $cathash = $domconfig{'coursecategories'}{'cats'};
6224: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6225: $changes{'togglecats'} = 1;
6226: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6227: }
6228: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6229: $changes{'categorize'} = 1;
6230: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6231: }
1.120 raeburn 6232: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6233: $changes{'togglecatscomm'} = 1;
6234: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6235: }
6236: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6237: $changes{'categorizecomm'} = 1;
6238: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6239: }
1.57 raeburn 6240: } else {
6241: $changes{'togglecats'} = 1;
6242: $changes{'categorize'} = 1;
1.124 raeburn 6243: $changes{'togglecatscomm'} = 1;
6244: $changes{'categorizecomm'} = 1;
1.87 raeburn 6245: $domconfig{'coursecategories'} = {
6246: togglecats => $env{'form.togglecats'},
6247: categorize => $env{'form.categorize'},
1.124 raeburn 6248: togglecatscomm => $env{'form.togglecatscomm'},
6249: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 6250: };
1.57 raeburn 6251: }
6252: if (ref($cathash) eq 'HASH') {
6253: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 6254: push (@deletecategory,'instcode::0');
6255: }
1.120 raeburn 6256: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
6257: push(@deletecategory,'communities::0');
6258: }
1.48 raeburn 6259: }
1.57 raeburn 6260: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
6261: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6262: if (@deletecategory > 0) {
6263: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 6264: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 6265: foreach my $item (@deletecategory) {
1.57 raeburn 6266: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
6267: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 6268: $deletions{$item} = 1;
1.57 raeburn 6269: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 6270: }
6271: }
6272: }
1.57 raeburn 6273: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 6274: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 6275: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 6276: $reorderings{$item} = 1;
1.57 raeburn 6277: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 6278: }
6279: if ($env{'form.addcategory_name_'.$item} ne '') {
6280: my $newcat = $env{'form.addcategory_name_'.$item};
6281: my $newdepth = $depth+1;
6282: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6283: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 6284: $adds{$newitem} = 1;
6285: }
6286: if ($env{'form.subcat_'.$item} ne '') {
6287: my $newcat = $env{'form.subcat_'.$item};
6288: my $newdepth = $depth+1;
6289: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6290: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 6291: $adds{$newitem} = 1;
6292: }
6293: }
6294: }
6295: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 6296: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6297: my $newitem = 'instcode::0';
1.57 raeburn 6298: if ($cathash->{$newitem} eq '') {
6299: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6300: $adds{$newitem} = 1;
6301: }
6302: } else {
6303: my $newitem = 'instcode::0';
1.57 raeburn 6304: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6305: $adds{$newitem} = 1;
6306: }
6307: }
1.120 raeburn 6308: if ($env{'form.communities'} eq '1') {
6309: if (ref($cathash) eq 'HASH') {
6310: my $newitem = 'communities::0';
6311: if ($cathash->{$newitem} eq '') {
6312: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6313: $adds{$newitem} = 1;
6314: }
6315: } else {
6316: my $newitem = 'communities::0';
6317: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6318: $adds{$newitem} = 1;
6319: }
6320: }
1.48 raeburn 6321: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 6322: if (($env{'form.addcategory_name'} ne 'instcode') &&
6323: ($env{'form.addcategory_name'} ne 'communities')) {
6324: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
6325: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
6326: $adds{$newitem} = 1;
6327: }
1.48 raeburn 6328: }
1.57 raeburn 6329: my $putresult;
1.48 raeburn 6330: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6331: if (keys(%deletions) > 0) {
6332: foreach my $key (keys(%deletions)) {
6333: if ($predelallitems{$key} ne '') {
6334: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
6335: }
6336: }
6337: }
6338: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 6339: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 6340: if (ref($chkcats[0]) eq 'ARRAY') {
6341: my $depth = 0;
6342: my $chg = 0;
6343: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
6344: my $name = $chkcats[0][$i];
6345: my $item;
6346: if ($name eq '') {
6347: $chg ++;
6348: } else {
6349: $item = &escape($name).'::0';
6350: if ($chg) {
1.57 raeburn 6351: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 6352: }
6353: $depth ++;
1.57 raeburn 6354: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 6355: $depth --;
6356: }
6357: }
6358: }
1.57 raeburn 6359: }
6360: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6361: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 6362: if ($putresult eq 'ok') {
1.57 raeburn 6363: my %title = (
1.120 raeburn 6364: togglecats => 'Show/Hide a course in catalog',
6365: categorize => 'Assign a category to a course',
6366: togglecatscomm => 'Show/Hide a community in catalog',
6367: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6368: );
6369: my %level = (
1.120 raeburn 6370: dom => 'set in Domain ("Modify Course/Community")',
6371: crs => 'set in Course ("Course Configuration")',
6372: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 6373: );
1.48 raeburn 6374: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 6375: if ($changes{'togglecats'}) {
6376: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
6377: }
6378: if ($changes{'categorize'}) {
6379: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 6380: }
1.120 raeburn 6381: if ($changes{'togglecatscomm'}) {
6382: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
6383: }
6384: if ($changes{'categorizecomm'}) {
6385: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
6386: }
1.57 raeburn 6387: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6388: my $cathash;
6389: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6390: $cathash = $domconfig{'coursecategories'}{'cats'};
6391: } else {
6392: $cathash = {};
6393: }
6394: my (@cats,@trails,%allitems);
6395: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
6396: if (keys(%deletions) > 0) {
6397: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
6398: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
6399: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
6400: }
6401: $resulttext .= '</ul></li>';
6402: }
6403: if (keys(%reorderings) > 0) {
6404: my %sort_by_trail;
6405: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
6406: foreach my $key (keys(%reorderings)) {
6407: if ($allitems{$key} ne '') {
6408: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6409: }
1.48 raeburn 6410: }
1.57 raeburn 6411: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6412: $resulttext .= '<li>'.$trails[$trail].'</li>';
6413: }
6414: $resulttext .= '</ul></li>';
1.48 raeburn 6415: }
1.57 raeburn 6416: if (keys(%adds) > 0) {
6417: my %sort_by_trail;
6418: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
6419: foreach my $key (keys(%adds)) {
6420: if ($allitems{$key} ne '') {
6421: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6422: }
6423: }
6424: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6425: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 6426: }
1.57 raeburn 6427: $resulttext .= '</ul></li>';
1.48 raeburn 6428: }
6429: }
6430: $resulttext .= '</ul>';
6431: } else {
6432: $resulttext = '<span class="LC_error">'.
1.57 raeburn 6433: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 6434: }
6435: } else {
1.120 raeburn 6436: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 6437: }
6438: return $resulttext;
6439: }
6440:
1.69 raeburn 6441: sub modify_serverstatuses {
6442: my ($dom,%domconfig) = @_;
6443: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
6444: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
6445: %currserverstatus = %{$domconfig{'serverstatuses'}};
6446: }
6447: my @pages = &serverstatus_pages();
6448: foreach my $type (@pages) {
6449: $newserverstatus{$type}{'namedusers'} = '';
6450: $newserverstatus{$type}{'machines'} = '';
6451: if (defined($env{'form.'.$type.'_namedusers'})) {
6452: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
6453: my @okusers;
6454: foreach my $user (@users) {
6455: my ($uname,$udom) = split(/:/,$user);
6456: if (($udom =~ /^$match_domain$/) &&
6457: (&Apache::lonnet::domain($udom)) &&
6458: ($uname =~ /^$match_username$/)) {
6459: if (!grep(/^\Q$user\E/,@okusers)) {
6460: push(@okusers,$user);
6461: }
6462: }
6463: }
6464: if (@okusers > 0) {
6465: @okusers = sort(@okusers);
6466: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
6467: }
6468: }
6469: if (defined($env{'form.'.$type.'_machines'})) {
6470: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
6471: my @okmachines;
6472: foreach my $ip (@machines) {
6473: my @parts = split(/\./,$ip);
6474: next if (@parts < 4);
6475: my $badip = 0;
6476: for (my $i=0; $i<4; $i++) {
6477: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
6478: $badip = 1;
6479: last;
6480: }
6481: }
6482: if (!$badip) {
6483: push(@okmachines,$ip);
6484: }
6485: }
6486: @okmachines = sort(@okmachines);
6487: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
6488: }
6489: }
6490: my %serverstatushash = (
6491: serverstatuses => \%newserverstatus,
6492: );
6493: foreach my $type (@pages) {
1.83 raeburn 6494: foreach my $setting ('namedusers','machines') {
1.84 raeburn 6495: my (@current,@new);
1.83 raeburn 6496: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 6497: if ($currserverstatus{$type}{$setting} ne '') {
6498: @current = split(/,/,$currserverstatus{$type}{$setting});
6499: }
6500: }
6501: if ($newserverstatus{$type}{$setting} ne '') {
6502: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 6503: }
6504: if (@current > 0) {
6505: if (@new > 0) {
6506: foreach my $item (@current) {
6507: if (!grep(/^\Q$item\E$/,@new)) {
6508: $changes{$type}{$setting} = 1;
1.82 raeburn 6509: last;
6510: }
6511: }
1.84 raeburn 6512: foreach my $item (@new) {
6513: if (!grep(/^\Q$item\E$/,@current)) {
6514: $changes{$type}{$setting} = 1;
6515: last;
1.82 raeburn 6516: }
6517: }
6518: } else {
1.83 raeburn 6519: $changes{$type}{$setting} = 1;
1.69 raeburn 6520: }
1.83 raeburn 6521: } elsif (@new > 0) {
6522: $changes{$type}{$setting} = 1;
1.69 raeburn 6523: }
6524: }
6525: }
6526: if (keys(%changes) > 0) {
1.81 raeburn 6527: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6528: my $putresult = &Apache::lonnet::put_dom('configuration',
6529: \%serverstatushash,$dom);
6530: if ($putresult eq 'ok') {
6531: $resulttext .= &mt('Changes made:').'<ul>';
6532: foreach my $type (@pages) {
1.84 raeburn 6533: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 6534: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 6535: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 6536: if ($newserverstatus{$type}{'namedusers'} eq '') {
6537: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
6538: } else {
6539: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
6540: }
1.84 raeburn 6541: }
6542: if ($changes{$type}{'machines'}) {
1.69 raeburn 6543: if ($newserverstatus{$type}{'machines'} eq '') {
6544: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
6545: } else {
6546: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
6547: }
6548:
6549: }
6550: $resulttext .= '</ul></li>';
6551: }
6552: }
6553: $resulttext .= '</ul>';
6554: } else {
6555: $resulttext = '<span class="LC_error">'.
6556: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
6557:
6558: }
6559: } else {
6560: $resulttext = &mt('No changes made to access to server status pages');
6561: }
6562: return $resulttext;
6563: }
6564:
1.118 jms 6565: sub modify_helpsettings {
1.122 jms 6566: my ($r,$dom,$confname,%domconfig) = @_;
1.118 jms 6567: my ($resulttext,$errors,%changes,%helphash);
6568:
1.122 jms 6569: my $customhelpfile = $env{'form.loginhelpurl.filename'};
6570: my $defaulthelpfile = 'defaulthelp.html';
6571: my $servadm = $r->dir_config('lonAdmEMail');
6572: my ($configuserok,$author_ok,$switchserver) =
6573: &config_check($dom,$confname,$servadm);
6574:
1.118 jms 6575: my %defaultchecked = ('submitbugs' => 'on');
6576: my @offon = ('off','on');
1.122 jms 6577: my %title = ( submitbugs => 'Display link for users to submit a bug',
6578: loginhelpurl => 'Unauthenticated login help page set to custom file');
6579:
1.118 jms 6580: my @toggles = ('submitbugs');
6581:
6582: $helphash{'helpsettings'} = {};
6583:
6584: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
6585: if ($domconfig{'helpsettings'} eq '') {
6586: $domconfig{'helpsettings'} = {};
6587: }
6588: }
6589:
6590: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
6591:
6592: foreach my $item (@toggles) {
6593:
6594: if ($defaultchecked{$item} eq 'on') {
6595: if (($domconfig{'helpsettings'}{$item} eq '') &&
6596: ($env{'form.'.$item} eq '0')) {
6597: $changes{$item} = 1;
6598: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
6599: $changes{$item} = 1;
6600: }
6601: } elsif ($defaultchecked{$item} eq 'off') {
6602: if (($domconfig{'helpsettings'}{$item} eq '') &&
6603: ($env{'form.'.$item} eq '1')) {
6604: $changes{$item} = 1;
6605: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
6606: $changes{$item} = 1;
6607: }
6608: }
6609: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 6610: }
6611:
6612: if ($customhelpfile ne '') {
6613: my $error;
6614: if ($configuserok eq 'ok') {
6615: if ($switchserver) {
6616: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6617: } else {
6618: if ($author_ok eq 'ok') {
6619: my ($result,$loginhelpurl) =
6620: &publishlogo($r,'upload','loginhelpurl',$dom,
6621: $confname,'help','','',$customhelpfile);
6622: if ($result eq 'ok') {
6623: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
6624: $changes{'loginhelpurl'} = 1;
6625: } else {
6626: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
6627: }
6628: } else {
6629: $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].",$customhelpfile,$confname,$dom,$author_ok);
6630: }
6631: }
6632: } else {
6633: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
6634: }
6635: if ($error) {
6636: &Apache::lonnet::logthis($error);
6637: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6638: }
6639: }
6640:
6641: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
6642: if ($env{'form.loginhelpurl_del'}) {
6643: $helphash{'helpsettings'}{'loginhelpurl'} = '';
6644: $changes{'loginhelpurl'} = 1;
6645: }
6646: }
1.118 jms 6647: }
6648:
1.123 jms 6649:
6650: my $putresult;
6651:
6652: if (keys(%changes) > 0) {
6653: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
6654: } else {
6655: $putresult = 'ok';
6656: }
1.118 jms 6657:
6658: if ($putresult eq 'ok') {
6659: if (keys(%changes) > 0) {
6660: $resulttext = &mt('Changes made:').'<ul>';
6661: foreach my $item (sort(keys(%changes))) {
6662: if ($item eq 'submitbugs') {
6663: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6664: }
1.122 jms 6665: if ($item eq 'loginhelpurl') {
6666: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
6667: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
6668: } else {
6669: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
6670: }
6671: }
1.118 jms 6672: }
6673: $resulttext .= '</ul>';
6674: } else {
6675: $resulttext = &mt('No changes made to help settings');
6676: }
6677: } else {
6678: $resulttext = '<span class="LC_error">'.
6679: &mt('An error occurred: [_1]',$putresult).'</span>';
6680: }
6681: if ($errors) {
6682: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6683: $errors.'</ul>';
6684: }
6685: return $resulttext;
6686: }
6687:
1.121 raeburn 6688: sub modify_coursedefaults {
6689: my ($dom,%domconfig) = @_;
6690: my ($resulttext,$errors,%changes,%defaultshash);
6691: my %defaultchecked = ('canuse_pdfforms' => 'off');
6692: my @offon = ('off','on');
6693: my @toggles = ('canuse_pdfforms');
6694:
6695: $defaultshash{'coursedefaults'} = {};
6696:
6697: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
6698: if ($domconfig{'coursedefaults'} eq '') {
6699: $domconfig{'coursedefaults'} = {};
6700: }
6701: }
6702:
6703: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
6704: foreach my $item (@toggles) {
6705: if ($defaultchecked{$item} eq 'on') {
6706: if (($domconfig{'coursedefaults'}{$item} eq '') &&
6707: ($env{'form.'.$item} eq '0')) {
6708: $changes{$item} = 1;
6709: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
6710: $changes{$item} = 1;
6711: }
6712: } elsif ($defaultchecked{$item} eq 'off') {
6713: if (($domconfig{'coursedefaults'}{$item} eq '') &&
6714: ($env{'form.'.$item} eq '1')) {
6715: $changes{$item} = 1;
6716: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
6717: $changes{$item} = 1;
6718: }
6719: }
6720: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
6721: }
1.139 raeburn 6722: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
6723: my $newdefresponder = $env{'form.anonsurvey_threshold'};
6724: $newdefresponder =~ s/\D//g;
6725: if ($newdefresponder eq '' || $newdefresponder < 1) {
6726: $newdefresponder = 1;
6727: }
6728: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
6729: if ($currdefresponder ne $newdefresponder) {
6730: unless ($currdefresponder eq '' && $newdefresponder == 10) {
6731: $changes{'anonsurvey_threshold'} = 1;
6732: }
6733: }
1.121 raeburn 6734: }
6735: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
6736: $dom);
6737: if ($putresult eq 'ok') {
6738: if (keys(%changes) > 0) {
6739: if ($changes{'canuse_pdfforms'}) {
6740: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6741: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
6742: my $cachetime = 24*60*60;
6743: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6744: }
6745: $resulttext = &mt('Changes made:').'<ul>';
6746: foreach my $item (sort(keys(%changes))) {
6747: if ($item eq 'canuse_pdfforms') {
6748: if ($env{'form.'.$item} eq '1') {
6749: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
6750: } else {
6751: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
6752: }
1.139 raeburn 6753: } elsif ($item eq 'anonsurvey_threshold') {
6754: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 6755: }
1.121 raeburn 6756: }
6757: $resulttext .= '</ul>';
6758: } else {
6759: $resulttext = &mt('No changes made to course defaults');
6760: }
6761: } else {
6762: $resulttext = '<span class="LC_error">'.
6763: &mt('An error occurred: [_1]',$putresult).'</span>';
6764: }
6765: return $resulttext;
6766: }
6767:
1.137 raeburn 6768: sub modify_usersessions {
6769: my ($dom,%domconfig) = @_;
6770: my @types = ('version','excludedomain','includedomain');
6771: my @prefixes = ('remote','hosted');
6772: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 6773: my (%by_ip,%by_location,@intdoms);
6774: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
6775: my @locations = sort(keys(%by_location));
1.137 raeburn 6776: my (%defaultshash,%changes);
6777: foreach my $prefix (@prefixes) {
6778: $defaultshash{'usersessions'}{$prefix} = {};
6779: }
6780: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6781: my $resulttext;
1.138 raeburn 6782: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 6783: foreach my $prefix (@prefixes) {
6784: foreach my $type (@types) {
6785: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
6786: if ($type eq 'version') {
6787: my $value = $env{'form.'.$prefix.'_'.$type};
6788: my $okvalue;
6789: if ($value ne '') {
6790: if (grep(/^\Q$value\E$/,@lcversions)) {
6791: $okvalue = $value;
6792: }
6793: }
6794: if (ref($domconfig{'usersessions'}) eq 'HASH') {
6795: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
6796: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
6797: if ($inuse == 0) {
6798: $changes{$prefix}{$type} = 1;
6799: } else {
6800: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
6801: $changes{$prefix}{$type} = 1;
6802: }
6803: if ($okvalue ne '') {
6804: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
6805: }
6806: }
6807: } else {
6808: if (($inuse == 1) && ($okvalue ne '')) {
6809: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
6810: $changes{$prefix}{$type} = 1;
6811: }
6812: }
6813: } else {
6814: if (($inuse == 1) && ($okvalue ne '')) {
6815: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
6816: $changes{$prefix}{$type} = 1;
6817: }
6818: }
6819: } else {
6820: if (($inuse == 1) && ($okvalue ne '')) {
6821: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
6822: $changes{$prefix}{$type} = 1;
6823: }
6824: }
6825: } else {
6826: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
6827: my @okvals;
6828: foreach my $val (@vals) {
1.138 raeburn 6829: if ($val =~ /:/) {
6830: my @items = split(/:/,$val);
6831: foreach my $item (@items) {
6832: if (ref($by_location{$item}) eq 'ARRAY') {
6833: push(@okvals,$item);
6834: }
6835: }
6836: } else {
6837: if (ref($by_location{$val}) eq 'ARRAY') {
6838: push(@okvals,$val);
6839: }
1.137 raeburn 6840: }
6841: }
6842: @okvals = sort(@okvals);
6843: if (ref($domconfig{'usersessions'}) eq 'HASH') {
6844: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
6845: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
6846: if ($inuse == 0) {
6847: $changes{$prefix}{$type} = 1;
6848: } else {
6849: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
6850: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
6851: if (@changed > 0) {
6852: $changes{$prefix}{$type} = 1;
6853: }
6854: }
6855: } else {
6856: if ($inuse == 1) {
6857: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
6858: $changes{$prefix}{$type} = 1;
6859: }
6860: }
6861: } else {
6862: if ($inuse == 1) {
6863: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
6864: $changes{$prefix}{$type} = 1;
6865: }
6866: }
6867: } else {
6868: if ($inuse == 1) {
6869: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
6870: $changes{$prefix}{$type} = 1;
6871: }
6872: }
6873: }
6874: }
6875: }
6876: if (keys(%changes) > 0) {
6877: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
6878: $dom);
6879: if ($putresult eq 'ok') {
6880: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
6881: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
6882: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
6883: }
6884: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
6885: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
6886: }
6887: }
6888: my $cachetime = 24*60*60;
6889: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6890: my %lt = &usersession_titles();
6891: $resulttext = &mt('Changes made:').'<ul>';
6892: foreach my $prefix (@prefixes) {
6893: if (ref($changes{$prefix}) eq 'HASH') {
6894: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
6895: foreach my $type (@types) {
6896: if (defined($changes{$prefix}{$type})) {
6897: my $newvalue;
6898: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
6899: if (ref($defaultshash{'usersessions'}{$prefix})) {
6900: if ($type eq 'version') {
6901: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
6902: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
6903: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
6904: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
6905: }
6906: }
6907: }
6908: }
6909: if ($newvalue eq '') {
6910: if ($type eq 'version') {
6911: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
6912: } else {
6913: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
6914: }
6915: } else {
6916: if ($type eq 'version') {
6917: $newvalue .= ' '.&mt('(or later)');
6918: }
6919: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
6920: }
6921: }
6922: }
6923: $resulttext .= '</ul>';
6924: }
6925: }
6926: $resulttext .= '</ul>';
6927: } else {
6928: $resulttext = '<span class="LC_error">'.
6929: &mt('An error occurred: [_1]',$putresult).'</span>';
6930: }
6931: } else {
6932: $resulttext = &mt('No changes made to settings for user session hosting.');
6933: }
6934: return $resulttext;
6935: }
6936:
1.48 raeburn 6937: sub recurse_check {
6938: my ($chkcats,$categories,$depth,$name) = @_;
6939: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
6940: my $chg = 0;
6941: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
6942: my $category = $chkcats->[$depth]{$name}[$j];
6943: my $item;
6944: if ($category eq '') {
6945: $chg ++;
6946: } else {
6947: my $deeper = $depth + 1;
6948: $item = &escape($category).':'.&escape($name).':'.$depth;
6949: if ($chg) {
6950: $categories->{$item} -= $chg;
6951: }
6952: &recurse_check($chkcats,$categories,$deeper,$category);
6953: $deeper --;
6954: }
6955: }
6956: }
6957: return;
6958: }
6959:
6960: sub recurse_cat_deletes {
6961: my ($item,$coursecategories,$deletions) = @_;
6962: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
6963: my $subdepth = $depth + 1;
6964: if (ref($coursecategories) eq 'HASH') {
6965: foreach my $subitem (keys(%{$coursecategories})) {
6966: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
6967: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
6968: delete($coursecategories->{$subitem});
6969: $deletions->{$subitem} = 1;
6970: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
6971: }
6972: }
6973: }
6974: return;
6975: }
6976:
1.117 raeburn 6977: sub dom_servers {
6978: my ($dom) = @_;
6979: my (%uniqservers,%servers);
6980: my $primaryserver = &Apache::lonnet::hostname(&Apache::lonnet::domain($dom,'primary'));
6981: my @machinedoms = &Apache::lonnet::machine_domains($primaryserver);
6982: foreach my $mdom (@machinedoms) {
6983: my %currservers = %servers;
6984: my %server = &Apache::lonnet::get_servers($mdom);
6985: %servers = (%currservers,%server);
6986: }
6987: my %by_hostname;
6988: foreach my $id (keys(%servers)) {
6989: push(@{$by_hostname{$servers{$id}}},$id);
6990: }
6991: foreach my $hostname (sort(keys(%by_hostname))) {
6992: if (@{$by_hostname{$hostname}} > 1) {
6993: my $match = 0;
6994: foreach my $id (@{$by_hostname{$hostname}}) {
6995: if (&Apache::lonnet::host_domain($id) eq $dom) {
6996: $uniqservers{$id} = $hostname;
6997: $match = 1;
6998: }
6999: }
7000: unless ($match) {
7001: $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
7002: }
7003: } else {
7004: $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
7005: }
7006: }
7007: return %uniqservers;
7008: }
7009:
1.125 raeburn 7010: sub get_active_dcs {
7011: my ($dom) = @_;
7012: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
7013: my %domcoords;
7014: my $numdcs = 0;
7015: my $now = time;
7016: foreach my $server (keys(%dompersonnel)) {
7017: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
7018: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
7019: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
7020: if (($end eq '') || ($end == 0) || ($end > $now)) {
7021: if ($start <= $now) {
7022: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
7023: }
7024: }
7025: }
7026: }
7027: return %domcoords;
7028: }
7029:
7030: sub active_dc_picker {
7031: my ($dom,$curr_dc) = @_;
7032: my %domcoords = &get_active_dcs($dom);
7033: my @dcs = sort(keys(%domcoords));
7034: my $numdcs = scalar(@dcs);
7035: my $datatable;
7036: my $numinrow = 2;
7037: if ($numdcs > 1) {
7038: $datatable = '<table>';
7039: for (my $i=0; $i<@dcs; $i++) {
7040: my $rem = $i%($numinrow);
7041: if ($rem == 0) {
7042: if ($i > 0) {
7043: $datatable .= '</tr>';
7044: }
7045: $datatable .= '<tr>';
7046: }
7047: my $check = ' ';
7048: if ($curr_dc eq '') {
7049: if (!$i) {
7050: $check = ' checked="checked" ';
7051: }
7052: } elsif ($dcs[$i] eq $curr_dc) {
7053: $check = ' checked="checked" ';
7054: }
7055: if ($i == @dcs - 1) {
7056: my $colsleft = $numinrow - $rem;
7057: if ($colsleft > 1) {
7058: $datatable .= '<td colspan="'.$colsleft.'">';
7059: } else {
7060: $datatable .= '<td>';
7061: }
7062: } else {
7063: $datatable .= '<td>';
7064: }
7065: my ($dcname,$dcdom) = split(':',$dcs[$i]);
7066: $datatable .= '<span class="LC_nobreak"><label>'.
7067: '<input type="radio" name="autocreate_xmldc"'.
7068: ' value="'.$dcs[$i].'"'.$check.'/>'.
7069: &Apache::loncommon::plainname($dcname,$dcdom).
7070: '</label></span></td>';
7071: }
7072: $datatable .= '</tr></table>';
7073: } elsif (@dcs) {
7074: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
7075: $dcs[0].'" />';
7076: }
7077: return ($numdcs,$datatable);
7078: }
7079:
1.137 raeburn 7080: sub usersession_titles {
7081: return &Apache::lonlocal::texthash(
7082: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
7083:
7084: remote => 'Hosting of sessions for users in this domain on servers in other domains',
7085: version => 'LON-CAPA version requirement',
1.138 raeburn 7086: excludedomain => 'Allow all, but exclude specific domains',
7087: includedomain => 'Deny all, but include specific domains',
1.137 raeburn 7088: );
7089: }
7090:
1.3 raeburn 7091: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>