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