Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.126
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.126! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.125 2024/12/29 04:27:32 raeburn Exp $
1.160.6.40 raeburn 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
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.160.6.113 raeburn 177: use Net::CIDR;
1.1 raeburn 178:
1.155 raeburn 179: my $registered_cleanup;
180: my $modified_urls;
181:
1.1 raeburn 182: sub handler {
183: my $r=shift;
184: if ($r->header_only) {
185: &Apache::loncommon::content_type($r,'text/html');
186: $r->send_http_header;
187: return OK;
188: }
189:
1.91 raeburn 190: my $context = 'domain';
1.1 raeburn 191: my $dom = $env{'request.role.domain'};
1.5 albertel 192: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 193: if (&Apache::lonnet::allowed('mau',$dom)) {
194: &Apache::loncommon::content_type($r,'text/html');
195: $r->send_http_header;
196: } else {
197: $env{'user.error.msg'}=
198: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
199: return HTTP_NOT_ACCEPTABLE;
200: }
1.155 raeburn 201:
202: $registered_cleanup=0;
203: @{$modified_urls}=();
204:
1.1 raeburn 205: &Apache::lonhtmlcommon::clear_breadcrumbs();
206: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 207: ['phase','actions']);
1.30 raeburn 208: my $phase = 'pickactions';
1.3 raeburn 209: if ( exists($env{'form.phase'}) ) {
210: $phase = $env{'form.phase'};
211: }
1.150 raeburn 212: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 213: my %domconfig =
1.6 raeburn 214: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 215: 'quotas','autoenroll','autoupdate','autocreate',
216: 'directorysrch','usercreation','usermodification',
217: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 218: 'serverstatuses','requestcourses','helpsettings',
219: 'coursedefaults','usersessions','loadbalancing',
1.160.6.113 raeburn 220: 'requestauthor','selfenrollment','inststatus',
221: 'passwords','wafproxy','ipaccess'],$dom);
222: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
223: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
224: 'contacts','usercreation','selfcreation','usermodification',
225: 'scantron','requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 226: 'serverstatuses','helpsettings','coursedefaults',
227: 'selfenrollment','usersessions');
1.160.6.7 raeburn 228: my %existing;
229: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
230: %existing = %{$domconfig{'loadbalancing'}};
231: }
232: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 233: push(@prefs_order,'loadbalancing');
234: }
1.30 raeburn 235: my %prefs = (
236: 'rolecolors' =>
237: { text => 'Default color schemes',
1.67 raeburn 238: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 239: header => [{col1 => 'Student Settings',
240: col2 => '',},
241: {col1 => 'Coordinator Settings',
242: col2 => '',},
243: {col1 => 'Author Settings',
244: col2 => '',},
245: {col1 => 'Administrator Settings',
246: col2 => '',}],
1.160.6.37 raeburn 247: print => \&print_rolecolors,
248: modify => \&modify_rolecolors,
1.30 raeburn 249: },
1.110 raeburn 250: 'login' =>
1.30 raeburn 251: { text => 'Log-in page options',
1.67 raeburn 252: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 253: header => [{col1 => 'Log-in Page Items',
254: col2 => '',},
255: {col1 => 'Log-in Help',
1.160.6.56 raeburn 256: col2 => 'Value'},
257: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 258: col2 => 'Value'},
259: {col1 => 'SSO',
260: col2 => 'Dual login: SSO and non-SSO options'},
261: ],
1.160.6.37 raeburn 262: print => \&print_login,
263: modify => \&modify_login,
1.30 raeburn 264: },
1.43 raeburn 265: 'defaults' =>
1.160.6.40 raeburn 266: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 267: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 268: header => [{col1 => 'Setting',
1.160.6.40 raeburn 269: col2 => 'Value'},
270: {col1 => 'Institutional user types',
1.160.6.122 raeburn 271: col2 => 'Name displayed'},
272: {col1 => 'Mapping for missing usernames via standard log-in',
273: col2 => 'Rules in use'}],
1.160.6.37 raeburn 274: print => \&print_defaults,
275: modify => \&modify_defaults,
1.43 raeburn 276: },
1.160.6.113 raeburn 277: 'wafproxy' =>
278: { text => 'Web Application Firewall/Reverse Proxy',
279: help => 'Domain_Configuration_WAF_Proxy',
280: header => [{col1 => 'Domain(s)',
281: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
282: },
283: {col1 => 'Domain(s)',
284: col2 => 'WAF Configuration',}],
285: print => \&print_wafproxy,
286: modify => \&modify_wafproxy,
287: },
1.160.6.98 raeburn 288: 'passwords' =>
289: { text => 'Passwords (Internal authentication)',
290: help => 'Domain_Configuration_Passwords',
291: header => [{col1 => 'Resetting Forgotten Password',
292: col2 => 'Settings'},
293: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
294: col2 => 'Settings'},
295: {col1 => 'Rules for LON-CAPA Passwords',
296: col2 => 'Settings'},
297: {col1 => 'Course Owner Changing Student Passwords',
298: col2 => 'Settings'}],
299: print => \&print_passwords,
300: modify => \&modify_passwords,
301: },
1.30 raeburn 302: 'quotas' =>
1.160.6.20 raeburn 303: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 304: help => 'Domain_Configuration_Quotas',
1.77 raeburn 305: header => [{col1 => 'User affiliation',
1.72 raeburn 306: col2 => 'Available tools',
1.160.6.28 raeburn 307: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 308: print => \&print_quotas,
309: modify => \&modify_quotas,
1.30 raeburn 310: },
311: 'autoenroll' =>
312: { text => 'Auto-enrollment settings',
1.67 raeburn 313: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 314: header => [{col1 => 'Configuration setting',
315: col2 => 'Value(s)'}],
1.160.6.37 raeburn 316: print => \&print_autoenroll,
317: modify => \&modify_autoenroll,
1.30 raeburn 318: },
319: 'autoupdate' =>
320: { text => 'Auto-update settings',
1.67 raeburn 321: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 322: header => [{col1 => 'Setting',
323: col2 => 'Value',},
1.131 raeburn 324: {col1 => 'Setting',
325: col2 => 'Affiliation'},
1.43 raeburn 326: {col1 => 'User population',
1.160.6.35 raeburn 327: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 328: print => \&print_autoupdate,
329: modify => \&modify_autoupdate,
1.30 raeburn 330: },
1.125 raeburn 331: 'autocreate' =>
332: { text => 'Auto-course creation settings',
333: help => 'Domain_Configuration_Auto_Creation',
334: header => [{col1 => 'Configuration Setting',
335: col2 => 'Value',}],
1.160.6.37 raeburn 336: print => \&print_autocreate,
337: modify => \&modify_autocreate,
1.125 raeburn 338: },
1.30 raeburn 339: 'directorysrch' =>
1.160.6.72 raeburn 340: { text => 'Directory searches',
1.67 raeburn 341: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 342: header => [{col1 => 'Institutional Directory Setting',
343: col2 => 'Value',},
344: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 345: col2 => 'Value',}],
1.160.6.37 raeburn 346: print => \&print_directorysrch,
347: modify => \&modify_directorysrch,
1.30 raeburn 348: },
349: 'contacts' =>
1.160.6.78 raeburn 350: { text => 'E-mail addresses and helpform',
1.67 raeburn 351: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 352: header => [{col1 => 'Default e-mail addresses',
353: col2 => 'Value',},
354: {col1 => 'Recipient(s) for notifications',
355: col2 => 'Value',},
1.160.6.107 raeburn 356: {col1 => 'Nightly status check e-mail',
357: col2 => 'Settings',},
1.160.6.78 raeburn 358: {col1 => 'Ask helpdesk form settings',
359: col2 => 'Value',},],
1.160.6.37 raeburn 360: print => \&print_contacts,
361: modify => \&modify_contacts,
1.30 raeburn 362: },
363: 'usercreation' =>
364: { text => 'User creation',
1.67 raeburn 365: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 366: header => [{col1 => 'Format rule type',
367: col2 => 'Format rules in force'},
1.34 raeburn 368: {col1 => 'User account creation',
369: col2 => 'Usernames which may be created',},
1.30 raeburn 370: {col1 => 'Context',
1.43 raeburn 371: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 372: print => \&print_usercreation,
373: modify => \&modify_usercreation,
1.30 raeburn 374: },
1.160.6.34 raeburn 375: 'selfcreation' =>
376: { text => 'Users self-creating accounts',
377: help => 'Domain_Configuration_Self_Creation',
378: header => [{col1 => 'Self-creation with institutional username',
379: col2 => 'Enabled?'},
380: {col1 => 'Institutional user type (login/SSO self-creation)',
381: col2 => 'Information user can enter'},
1.160.6.93 raeburn 382: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 383: col2 => 'Settings'}],
1.160.6.37 raeburn 384: print => \&print_selfcreation,
385: modify => \&modify_selfcreation,
1.160.6.34 raeburn 386: },
1.69 raeburn 387: 'usermodification' =>
1.33 raeburn 388: { text => 'User modification',
1.67 raeburn 389: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 390: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 391: col2 => 'User information updatable in author context'},
1.33 raeburn 392: {col1 => 'Target user has role',
1.160.6.35 raeburn 393: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 394: print => \&print_usermodification,
395: modify => \&modify_usermodification,
1.33 raeburn 396: },
1.69 raeburn 397: 'scantron' =>
1.160.6.97 raeburn 398: { text => 'Bubblesheet format',
1.67 raeburn 399: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 400: header => [ {col1 => 'Bubblesheet format file',
401: col2 => ''},
402: {col1 => 'Bubblesheet data upload formats',
403: col2 => 'Settings'}],
1.160.6.37 raeburn 404: print => \&print_scantron,
405: modify => \&modify_scantron,
1.46 raeburn 406: },
1.86 raeburn 407: 'requestcourses' =>
408: {text => 'Request creation of courses',
409: help => 'Domain_Configuration_Request_Courses',
410: header => [{col1 => 'User affiliation',
1.102 raeburn 411: col2 => 'Availability/Processing of requests',},
412: {col1 => 'Setting',
1.160.6.30 raeburn 413: col2 => 'Value'},
414: {col1 => 'Available textbooks',
1.160.6.39 raeburn 415: col2 => ''},
1.160.6.46 raeburn 416: {col1 => 'Available templates',
417: col2 => ''},
1.160.6.39 raeburn 418: {col1 => 'Validation (not official courses)',
419: col2 => 'Value'},],
1.160.6.37 raeburn 420: print => \&print_quotas,
421: modify => \&modify_quotas,
1.86 raeburn 422: },
1.160.6.5 raeburn 423: 'requestauthor' =>
1.160.6.34 raeburn 424: {text => 'Request Authoring Space',
1.160.6.5 raeburn 425: help => 'Domain_Configuration_Request_Author',
426: header => [{col1 => 'User affiliation',
427: col2 => 'Availability/Processing of requests',},
428: {col1 => 'Setting',
429: col2 => 'Value'}],
1.160.6.37 raeburn 430: print => \&print_quotas,
431: modify => \&modify_quotas,
1.160.6.5 raeburn 432: },
1.69 raeburn 433: 'coursecategories' =>
1.120 raeburn 434: { text => 'Cataloging of courses/communities',
1.67 raeburn 435: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 436: header => [{col1 => 'Catalog type/availability',
437: col2 => '',},
438: {col1 => 'Category settings for standard catalog',
1.57 raeburn 439: col2 => '',},
440: {col1 => 'Categories',
441: col2 => '',
442: }],
1.160.6.37 raeburn 443: print => \&print_coursecategories,
444: modify => \&modify_coursecategories,
1.69 raeburn 445: },
446: 'serverstatuses' =>
1.77 raeburn 447: {text => 'Access to server status pages',
1.69 raeburn 448: help => 'Domain_Configuration_Server_Status',
449: header => [{col1 => 'Status Page',
450: col2 => 'Other named users',
451: col3 => 'Specific IPs',
452: }],
1.160.6.37 raeburn 453: print => \&print_serverstatuses,
454: modify => \&modify_serverstatuses,
1.69 raeburn 455: },
1.160.6.73 raeburn 456: 'helpsettings' =>
457: {text => 'Support settings',
458: help => 'Domain_Configuration_Help_Settings',
459: header => [{col1 => 'Help Page Settings (logged-in users)',
460: col2 => 'Value'},
461: {col1 => 'Helpdesk Roles',
462: col2 => 'Settings'},],
463: print => \&print_helpsettings,
464: modify => \&modify_helpsettings,
465: },
1.160.6.39 raeburn 466: 'coursedefaults' =>
1.160.6.16 raeburn 467: {text => 'Course/Community defaults',
468: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 469: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
470: col2 => 'Value',},
471: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 472: col2 => 'Value',},],
1.160.6.37 raeburn 473: print => \&print_coursedefaults,
474: modify => \&modify_coursedefaults,
475: },
1.160.6.39 raeburn 476: 'selfenrollment' =>
1.160.6.37 raeburn 477: {text => 'Self-enrollment in Course/Community',
478: help => 'Domain_Configuration_Selfenrollment',
479: header => [{col1 => 'Configuration Rights',
480: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
481: {col1 => 'Defaults',
482: col2 => 'Value'},
483: {col1 => 'Self-enrollment validation (optional)',
484: col2 => 'Value'},],
485: print => \&print_selfenrollment,
486: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 487: },
1.141 raeburn 488: 'usersessions' =>
1.145 raeburn 489: {text => 'User session hosting/offloading',
1.137 raeburn 490: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 491: header => [{col1 => 'Domain server',
492: col2 => 'Servers to offload sessions to when busy'},
493: {col1 => 'Hosting of users from other domains',
1.137 raeburn 494: col2 => 'Rules'},
495: {col1 => "Hosting domain's own users elsewhere",
496: col2 => 'Rules'}],
1.160.6.37 raeburn 497: print => \&print_usersessions,
498: modify => \&modify_usersessions,
1.137 raeburn 499: },
1.160.6.78 raeburn 500: 'loadbalancing' =>
1.160.6.7 raeburn 501: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 502: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 503: header => [{col1 => 'Balancers',
1.150 raeburn 504: col2 => 'Default destinations',
1.160.6.13 raeburn 505: col3 => 'User affiliation',
1.150 raeburn 506: col4 => 'Overrides'},
507: ],
1.160.6.37 raeburn 508: print => \&print_loadbalancing,
509: modify => \&modify_loadbalancing,
1.150 raeburn 510: },
1.160.6.113 raeburn 511: 'ipaccess' =>
512: {text => 'IP-based access control',
513: help => 'Domain_Configuration_IP_Access',
514: header => [{col1 => 'Setting',
515: col2 => 'Value'},],
516: print => \&print_ipaccess,
517: modify => \&modify_ipaccess,
518: },
1.3 raeburn 519: );
1.110 raeburn 520: if (keys(%servers) > 1) {
521: $prefs{'login'} = { text => 'Log-in page options',
522: help => 'Domain_Configuration_Login_Page',
523: header => [{col1 => 'Log-in Service',
524: col2 => 'Server Setting',},
525: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 526: col2 => ''},
527: {col1 => 'Log-in Help',
1.160.6.56 raeburn 528: col2 => 'Value'},
529: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 530: col2 => 'Value'},
531: {col1 => 'SSO',
532: col2 => 'Dual login: SSO and non-SSO options'},
533: ],
1.160.6.37 raeburn 534: print => \&print_login,
535: modify => \&modify_login,
1.110 raeburn 536: };
537: }
1.160.6.13 raeburn 538:
1.6 raeburn 539: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 540: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 541: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 542: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 543: text=>"Settings to display/modify"});
1.9 raeburn 544: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 545:
1.3 raeburn 546: if ($phase eq 'process') {
1.160.6.27 raeburn 547: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
548: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 549: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 550: $r->rflush();
1.160.6.27 raeburn 551: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 552: }
1.30 raeburn 553: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 554: my $js = &recaptcha_js().
1.160.6.40 raeburn 555: &toggle_display_js();
1.160.6.7 raeburn 556: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 557: my ($othertitle,$usertypes,$types) =
558: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 559: $js .= &lonbalance_targets_js($dom,$types,\%servers,
560: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 561: &new_spares_js().
562: &common_domprefs_js().
563: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 564: }
1.160.6.30 raeburn 565: if (grep(/^requestcourses$/,@actions)) {
566: my $javascript_validations;
567: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
568: $js .= <<END;
569: <script type="text/javascript">
570: $javascript_validations
571: </script>
572: $coursebrowserjs
573: END
1.160.6.113 raeburn 574: } elsif (grep(/^ipaccess$/,@actions)) {
575: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 576: }
1.160.6.93 raeburn 577: if (grep(/^selfcreation$/,@actions)) {
578: $js .= &selfcreate_javascript();
579: }
1.160.6.78 raeburn 580: if (grep(/^contacts$/,@actions)) {
581: $js .= &contacts_javascript();
582: }
1.160.6.97 raeburn 583: if (grep(/^scantron$/,@actions)) {
584: $js .= &scantron_javascript();
585: }
1.150 raeburn 586: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 587: } else {
1.160.6.11 raeburn 588: # check if domconfig user exists for the domain.
589: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 590: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 591: &config_check($dom,$confname,$servadm);
592: unless ($configuserok eq 'ok') {
593: &Apache::lonconfigsettings::print_header($r,$phase,$context);
594: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
595: $confname).
596: '<br />'
597: );
598: if ($switchserver) {
599: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
600: '<br />'.
601: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
602: '<br />'.
603: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
604: '<br />'.
605: &mt('To do that now, use the following link: [_1]',$switchserver)
606: );
607: } else {
608: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
609: '<br />'.
610: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
611: );
612: }
613: $r->print(&Apache::loncommon::end_page());
614: return OK;
615: }
1.21 raeburn 616: if (keys(%domconfig) == 0) {
617: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 618: my @ids=&Apache::lonnet::current_machine_ids();
619: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 620: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 621: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 622: my $custom_img_count = 0;
623: foreach my $img (@loginimages) {
624: if ($designhash{$dom.'.login.'.$img} ne '') {
625: $custom_img_count ++;
626: }
627: }
628: foreach my $role (@roles) {
629: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
630: $custom_img_count ++;
631: }
632: }
633: if ($custom_img_count > 0) {
1.94 raeburn 634: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 635: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 636: $r->print(
637: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
638: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
639: &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 />'.
640: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
641: if ($switch_server) {
1.30 raeburn 642: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 643: }
1.91 raeburn 644: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 645: return OK;
646: }
647: }
648: }
1.91 raeburn 649: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 650: }
651: return OK;
652: }
653:
654: sub process_changes {
1.160.6.24 raeburn 655: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 656: my %domconfig;
657: if (ref($values) eq 'HASH') {
658: %domconfig = %{$values};
659: }
1.3 raeburn 660: my $output;
661: if ($action eq 'login') {
1.160.6.24 raeburn 662: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 663: } elsif ($action eq 'rolecolors') {
1.9 raeburn 664: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 665: $lastactref,%domconfig);
1.3 raeburn 666: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 667: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 668: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 669: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 670: } elsif ($action eq 'autoupdate') {
671: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 672: } elsif ($action eq 'autocreate') {
673: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 674: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 675: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 676: } elsif ($action eq 'usercreation') {
1.28 raeburn 677: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 678: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 679: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 680: } elsif ($action eq 'usermodification') {
681: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 682: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 683: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 684: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 685: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 686: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 687: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 688: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 689: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 690: } elsif ($action eq 'serverstatuses') {
691: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 692: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 693: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 694: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 695: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 696: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 697: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 698: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 699: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 700: } elsif ($action eq 'selfenrollment') {
701: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 702: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 703: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 704: } elsif ($action eq 'loadbalancing') {
705: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98 raeburn 706: } elsif ($action eq 'passwords') {
707: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.113 raeburn 708: } elsif ($action eq 'wafproxy') {
709: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
710: } elsif ($action eq 'ipaccess') {
711: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 712: }
713: return $output;
714: }
715:
716: sub print_config_box {
1.9 raeburn 717: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 718: my $rowtotal = 0;
1.49 raeburn 719: my $output;
720: if ($action eq 'coursecategories') {
721: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 722: } elsif ($action eq 'defaults') {
723: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 724: } elsif ($action eq 'passwords') {
725: $output = &passwords_javascript();
1.160.6.73 raeburn 726: } elsif ($action eq 'helpsettings') {
727: my (%privs,%levelscurrent);
728: my %full=();
729: my %levels=(
730: course => {},
731: domain => {},
732: system => {},
733: );
734: my $context = 'domain';
735: my $crstype = 'Course';
736: my $formname = 'display';
737: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
738: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
739: $output =
740: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
741: \@templateroles);
1.160.6.113 raeburn 742: } elsif ($action eq 'wafproxy') {
743: $output .= &wafproxy_javascript($dom);
744: } elsif ($action eq 'autoupdate') {
745: $output .= &autoupdate_javascript();
1.160.6.116 raeburn 746: } elsif ($action eq 'autoenroll') {
747: $output .= &autoenroll_javascript();
1.160.6.113 raeburn 748: } elsif ($action eq 'login') {
749: $output .= &saml_javascript();
750: } elsif ($action eq 'ipaccess') {
751: $output .= &ipaccess_javascript($settings);
1.91 raeburn 752: }
1.160.6.40 raeburn 753: $output .=
1.30 raeburn 754: '<table class="LC_nested_outer">
1.3 raeburn 755: <tr>
1.160.6.113 raeburn 756: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 757: &mt($item->{text}).' '.
758: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
759: '</tr>';
1.30 raeburn 760: $rowtotal ++;
1.110 raeburn 761: my $numheaders = 1;
762: if (ref($item->{'header'}) eq 'ARRAY') {
763: $numheaders = scalar(@{$item->{'header'}});
764: }
765: if ($numheaders > 1) {
1.64 raeburn 766: my $colspan = '';
1.145 raeburn 767: my $rightcolspan = '';
1.160.6.104 raeburn 768: my $leftnobr = '';
1.160.6.42 raeburn 769: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 770: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 771: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 772: $colspan = ' colspan="2"';
773: }
1.145 raeburn 774: if ($action eq 'usersessions') {
775: $rightcolspan = ' colspan="3"';
776: }
1.160.6.104 raeburn 777: if ($action eq 'passwords') {
778: $leftnobr = ' LC_nobreak';
779: }
1.30 raeburn 780: $output .= '
1.3 raeburn 781: <tr>
782: <td>
783: <table class="LC_nested">
784: <tr class="LC_info_row">
1.160.6.104 raeburn 785: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 786: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 787: </tr>';
1.69 raeburn 788: $rowtotal ++;
1.160.6.37 raeburn 789: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 790: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 791: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.113 raeburn 792: ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy')) {
1.160.6.37 raeburn 793: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 794: } elsif ($action eq 'passwords') {
795: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 796: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 797: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 798: } elsif ($action eq 'scantron') {
799: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 800: } elsif ($action eq 'login') {
1.160.6.113 raeburn 801: if ($numheaders == 5) {
1.160.6.5 raeburn 802: $colspan = ' colspan="2"';
803: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
804: } else {
805: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
806: }
1.160.6.37 raeburn 807: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 808: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 809: } elsif ($action eq 'rolecolors') {
1.30 raeburn 810: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 811: }
1.30 raeburn 812: $output .= '
1.6 raeburn 813: </table>
814: </td>
815: </tr>
816: <tr>
817: <td>
818: <table class="LC_nested">
819: <tr class="LC_info_row">
1.160.6.37 raeburn 820: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 821: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 822: </tr>';
823: $rowtotal ++;
1.160.6.37 raeburn 824: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
825: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 826: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.122 raeburn 827: ($action eq 'contacts') || ($action eq 'passwords') || ($action eq 'defaults')) {
1.160.6.42 raeburn 828: if ($action eq 'coursecategories') {
829: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
830: $colspan = ' colspan="2"';
1.160.6.98 raeburn 831: } elsif ($action eq 'passwords') {
832: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 833: } else {
834: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
835: }
836: $output .= '
1.63 raeburn 837: </table>
838: </td>
839: </tr>
840: <tr>
841: <td>
842: <table class="LC_nested">
843: <tr class="LC_info_row">
1.160.6.113 raeburn 844: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 845: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 846: </tr>'."\n";
847: if ($action eq 'coursecategories') {
848: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 849: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 850: if ($action eq 'passwords') {
851: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
852: } else {
853: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
854: }
855: $output .= '
1.160.6.98 raeburn 856: </tr>
857: </table>
858: </td>
859: </tr>
860: <tr>
861: <td>
862: <table class="LC_nested">
863: <tr class="LC_info_row">
1.160.6.113 raeburn 864: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107 raeburn 865: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 866: if ($action eq 'passwords') {
867: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
868: } else {
869: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
870: }
871: $output .= '
1.160.6.98 raeburn 872: </table>
873: </td>
874: </tr>
875: <tr>';
1.160.6.42 raeburn 876: } else {
877: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
878: }
1.63 raeburn 879: $rowtotal ++;
1.160.6.57 raeburn 880: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.122 raeburn 881: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
882: ($action eq 'wafproxy')) {
1.160.6.37 raeburn 883: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 884: } elsif ($action eq 'scantron') {
885: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 886: } elsif ($action eq 'login') {
1.160.6.113 raeburn 887: if ($numheaders == 5) {
1.160.6.5 raeburn 888: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
889: </table>
890: </td>
891: </tr>
892: <tr>
893: <td>
894: <table class="LC_nested">
895: <tr class="LC_info_row">
896: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 897: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 898: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
899: $rowtotal ++;
900: } else {
901: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
902: }
1.160.6.56 raeburn 903: $output .= '
904: </table>
905: </td>
906: </tr>
907: <tr>
908: <td>
909: <table class="LC_nested">
910: <tr class="LC_info_row">';
1.160.6.113 raeburn 911: if ($numheaders == 5) {
1.160.6.56 raeburn 912: $output .= '
913: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
914: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
915: </tr>';
916: } else {
917: $output .= '
918: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
919: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
920: </tr>';
921: }
922: $rowtotal ++;
1.160.6.113 raeburn 923: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
924: </table>
925: </td>
926: </tr>
927: <tr>
928: <td>
929: <table class="LC_nested">
930: <tr class="LC_info_row">';
931: if ($numheaders == 5) {
932: $output .= '
933: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
934: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
935: </tr>';
936: } else {
937: $output .= '
938: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
939: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
940: </tr>';
941: }
942: $rowtotal ++;
943: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 944: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 945: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
946: $rowtotal ++;
947: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 948: </table>
949: </td>
950: </tr>
951: <tr>
952: <td>
953: <table class="LC_nested">
954: <tr class="LC_info_row">
955: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
956: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 957: &textbookcourses_javascript($settings).
958: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
959: </table>
960: </td>
961: </tr>
962: <tr>
963: <td>
964: <table class="LC_nested">
965: <tr class="LC_info_row">
966: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
967: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
968: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 969: </table>
970: </td>
971: </tr>
972: <tr>
973: <td>
974: <table class="LC_nested">
975: <tr class="LC_info_row">
1.160.6.46 raeburn 976: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
977: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 978: </tr>'.
979: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 980: } elsif ($action eq 'requestauthor') {
981: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 982: $rowtotal ++;
1.122 jms 983: } elsif ($action eq 'rolecolors') {
1.30 raeburn 984: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 985: </table>
986: </td>
987: </tr>
988: <tr>
989: <td>
990: <table class="LC_nested">
991: <tr class="LC_info_row">
1.69 raeburn 992: <td class="LC_left_item"'.$colspan.' valign="top">'.
993: &mt($item->{'header'}->[2]->{'col1'}).'</td>
994: <td class="LC_right_item" valign="top">'.
995: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 996: </tr>'.
1.30 raeburn 997: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 998: </table>
999: </td>
1000: </tr>
1001: <tr>
1002: <td>
1003: <table class="LC_nested">
1004: <tr class="LC_info_row">
1.59 bisitz 1005: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1006: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1007: </tr>'.
1.30 raeburn 1008: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1009: $rowtotal += 2;
1.6 raeburn 1010: }
1.3 raeburn 1011: } else {
1.30 raeburn 1012: $output .= '
1.3 raeburn 1013: <tr>
1014: <td>
1015: <table class="LC_nested">
1.30 raeburn 1016: <tr class="LC_info_row">';
1.160.6.72 raeburn 1017: if ($action eq 'login') {
1.30 raeburn 1018: $output .= '
1.59 bisitz 1019: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1020: } elsif ($action eq 'serverstatuses') {
1021: $output .= '
1022: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1023: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1024:
1.6 raeburn 1025: } else {
1.30 raeburn 1026: $output .= '
1.69 raeburn 1027: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1028: }
1.72 raeburn 1029: if (defined($item->{'header'}->[0]->{'col3'})) {
1030: $output .= '<td class="LC_left_item" valign="top">'.
1031: &mt($item->{'header'}->[0]->{'col2'});
1032: if ($action eq 'serverstatuses') {
1033: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1034: }
1.69 raeburn 1035: } else {
1036: $output .= '<td class="LC_right_item" valign="top">'.
1037: &mt($item->{'header'}->[0]->{'col2'});
1038: }
1039: $output .= '</td>';
1040: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1041: if (defined($item->{'header'}->[0]->{'col4'})) {
1042: $output .= '<td class="LC_left_item" valign="top">'.
1043: &mt($item->{'header'}->[0]->{'col3'});
1044: } else {
1045: $output .= '<td class="LC_right_item" valign="top">'.
1046: &mt($item->{'header'}->[0]->{'col3'});
1047: }
1.69 raeburn 1048: if ($action eq 'serverstatuses') {
1049: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1050: }
1051: $output .= '</td>';
1.6 raeburn 1052: }
1.150 raeburn 1053: if ($item->{'header'}->[0]->{'col4'}) {
1054: $output .= '<td class="LC_right_item" valign="top">'.
1055: &mt($item->{'header'}->[0]->{'col4'});
1056: }
1.69 raeburn 1057: $output .= '</tr>';
1.48 raeburn 1058: $rowtotal ++;
1.160.6.5 raeburn 1059: if ($action eq 'quotas') {
1.86 raeburn 1060: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1061: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1062: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1063: ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1064: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1065: }
1.3 raeburn 1066: }
1.30 raeburn 1067: $output .= '
1.3 raeburn 1068: </table>
1069: </td>
1070: </tr>
1.30 raeburn 1071: </table><br />';
1072: return ($output,$rowtotal);
1.1 raeburn 1073: }
1074:
1.3 raeburn 1075: sub print_login {
1.160.6.5 raeburn 1076: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1077: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1078: my %choices = &login_choices();
1.160.6.113 raeburn 1079: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1080: %lt = &login_file_options();
1081: $switchserver = &check_switchserver($dom,$confname);
1082: }
1.110 raeburn 1083:
1.160.6.5 raeburn 1084: if ($caller eq 'service') {
1.149 raeburn 1085: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1086: my $choice = $choices{'disallowlogin'};
1087: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1088: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1089: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1090: '<th>'.$choices{'server'}.'</th>'.
1091: '<th>'.$choices{'serverpath'}.'</th>'.
1092: '<th>'.$choices{'custompath'}.'</th>'.
1093: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1094: my %disallowed;
1095: if (ref($settings) eq 'HASH') {
1096: if (ref($settings->{'loginvia'}) eq 'HASH') {
1097: %disallowed = %{$settings->{'loginvia'}};
1098: }
1099: }
1100: foreach my $lonhost (sort(keys(%servers))) {
1101: my $direct = 'selected="selected"';
1.128 raeburn 1102: if (ref($disallowed{$lonhost}) eq 'HASH') {
1103: if ($disallowed{$lonhost}{'server'} ne '') {
1104: $direct = '';
1105: }
1.110 raeburn 1106: }
1.115 raeburn 1107: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1108: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1109: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1110: '</option>';
1.160.6.13 raeburn 1111: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1112: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1113: my $selected = '';
1.128 raeburn 1114: if (ref($disallowed{$lonhost}) eq 'HASH') {
1115: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1116: $selected = 'selected="selected"';
1117: }
1.110 raeburn 1118: }
1119: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1120: $servers{$hostid}.'</option>';
1121: }
1.128 raeburn 1122: $datatable .= '</select></td>'.
1123: '<td><select name="'.$lonhost.'_serverpath">';
1124: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1125: my $pathname = $path;
1126: if ($path eq 'custom') {
1127: $pathname = &mt('Custom Path').' ->';
1128: }
1129: my $selected = '';
1130: if (ref($disallowed{$lonhost}) eq 'HASH') {
1131: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1132: $selected = 'selected="selected"';
1133: }
1134: } elsif ($path eq '') {
1135: $selected = 'selected="selected"';
1136: }
1137: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1138: }
1139: $datatable .= '</select></td>';
1140: my ($custom,$exempt);
1141: if (ref($disallowed{$lonhost}) eq 'HASH') {
1142: $custom = $disallowed{$lonhost}{'custompath'};
1143: $exempt = $disallowed{$lonhost}{'exempt'};
1144: }
1145: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1146: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1147: '</tr>';
1.110 raeburn 1148: }
1149: $datatable .= '</table></td></tr>';
1150: return $datatable;
1.160.6.5 raeburn 1151: } elsif ($caller eq 'page') {
1152: my %defaultchecked = (
1153: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1154: 'helpdesk' => 'on',
1.160.6.5 raeburn 1155: 'adminmail' => 'off',
1156: 'newuser' => 'off',
1157: );
1.160.6.14 raeburn 1158: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1159: my (%checkedon,%checkedoff);
1.42 raeburn 1160: foreach my $item (@toggles) {
1.160.6.5 raeburn 1161: if ($defaultchecked{$item} eq 'on') {
1162: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1163: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1164: } elsif ($defaultchecked{$item} eq 'off') {
1165: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1166: $checkedon{$item} = ' ';
1167: }
1.1 raeburn 1168: }
1.160.6.5 raeburn 1169: my @images = ('img','logo','domlogo','login');
1.160.6.119 raeburn 1170: my @alttext = ('img','logo','domlogo');
1.160.6.5 raeburn 1171: my @logintext = ('textcol','bgcol');
1172: my @bgs = ('pgbg','mainbg','sidebg');
1173: my @links = ('link','alink','vlink');
1174: my %designhash = &Apache::loncommon::get_domainconf($dom);
1175: my %defaultdesign = %Apache::loncommon::defaultdesign;
1176: my (%is_custom,%designs);
1177: my %defaults = (
1178: font => $defaultdesign{'login.font'},
1179: );
1.6 raeburn 1180: foreach my $item (@images) {
1.160.6.5 raeburn 1181: $defaults{$item} = $defaultdesign{'login.'.$item};
1182: $defaults{'showlogo'}{$item} = 1;
1183: }
1184: foreach my $item (@bgs) {
1185: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1186: }
1.41 raeburn 1187: foreach my $item (@logintext) {
1.160.6.5 raeburn 1188: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1189: }
1.160.6.5 raeburn 1190: foreach my $item (@links) {
1191: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1192: }
1.160.6.5 raeburn 1193: if (ref($settings) eq 'HASH') {
1194: foreach my $item (@toggles) {
1195: if ($settings->{$item} eq '1') {
1196: $checkedon{$item} = ' checked="checked" ';
1197: $checkedoff{$item} = ' ';
1198: } elsif ($settings->{$item} eq '0') {
1199: $checkedoff{$item} = ' checked="checked" ';
1200: $checkedon{$item} = ' ';
1201: }
1.6 raeburn 1202: }
1.160.6.5 raeburn 1203: foreach my $item (@images) {
1204: if (defined($settings->{$item})) {
1205: $designs{$item} = $settings->{$item};
1206: $is_custom{$item} = 1;
1207: }
1208: if (defined($settings->{'showlogo'}{$item})) {
1209: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1210: }
1211: }
1.160.6.119 raeburn 1212: foreach my $item (@alttext) {
1213: if (ref($settings->{'alttext'}) eq 'HASH') {
1214: if ($settings->{'alttext'}->{$item} ne '') {
1215: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1216: }
1217: }
1218: }
1.160.6.5 raeburn 1219: foreach my $item (@logintext) {
1220: if ($settings->{$item} ne '') {
1221: $designs{'logintext'}{$item} = $settings->{$item};
1222: $is_custom{$item} = 1;
1223: }
1224: }
1225: if ($settings->{'font'} ne '') {
1226: $designs{'font'} = $settings->{'font'};
1227: $is_custom{'font'} = 1;
1228: }
1229: foreach my $item (@bgs) {
1230: if ($settings->{$item} ne '') {
1231: $designs{'bgs'}{$item} = $settings->{$item};
1232: $is_custom{$item} = 1;
1233: }
1234: }
1235: foreach my $item (@links) {
1236: if ($settings->{$item} ne '') {
1237: $designs{'links'}{$item} = $settings->{$item};
1238: $is_custom{$item} = 1;
1239: }
1240: }
1241: } else {
1242: if ($designhash{$dom.'.login.font'} ne '') {
1243: $designs{'font'} = $designhash{$dom.'.login.font'};
1244: $is_custom{'font'} = 1;
1245: }
1246: foreach my $item (@images) {
1247: if ($designhash{$dom.'.login.'.$item} ne '') {
1248: $designs{$item} = $designhash{$dom.'.login.'.$item};
1249: $is_custom{$item} = 1;
1250: }
1251: }
1252: foreach my $item (@bgs) {
1253: if ($designhash{$dom.'.login.'.$item} ne '') {
1254: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1255: $is_custom{$item} = 1;
1256: }
1257: }
1258: foreach my $item (@links) {
1259: if ($designhash{$dom.'.login.'.$item} ne '') {
1260: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1261: $is_custom{$item} = 1;
1262: }
1.6 raeburn 1263: }
1264: }
1.160.6.5 raeburn 1265: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1266: logo => 'Institution Logo',
1267: domlogo => 'Domain Logo',
1268: login => 'Login box');
1269: my $itemcount = 1;
1270: foreach my $item (@toggles) {
1271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1272: $datatable .=
1273: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1274: '</td><td>'.
1275: '<span class="LC_nobreak"><label><input type="radio" name="'.
1276: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1277: '</label> <label><input type="radio" name="'.$item.'"'.
1278: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1279: '</tr>';
1280: $itemcount ++;
1.6 raeburn 1281: }
1.160.6.5 raeburn 1282: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1283: $datatable .= '</tr></table></td></tr>';
1284: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1285: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1286: my $itemcount = 1;
1287: $defaulturl = '/adm/loginproblems.html';
1288: $defaulttype = 'default';
1289: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1290: my @currlangs;
1291: if (ref($settings) eq 'HASH') {
1292: if (ref($settings->{'helpurl'}) eq 'HASH') {
1293: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1294: next if ($settings->{'helpurl'}{$key} eq '');
1295: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1296: $type{$key} = 'custom';
1297: unless ($key eq 'nolang') {
1298: push(@currlangs,$key);
1299: }
1300: }
1301: } elsif ($settings->{'helpurl'} ne '') {
1302: $type{'nolang'} = 'custom';
1303: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1304: }
1305: }
1.160.6.5 raeburn 1306: foreach my $lang ('nolang',sort(@currlangs)) {
1307: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1308: $datatable .= '<tr'.$css_class.'>';
1309: if ($url{$lang} eq '') {
1310: $url{$lang} = $defaulturl;
1311: }
1312: if ($type{$lang} eq '') {
1313: $type{$lang} = $defaulttype;
1314: }
1315: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1316: if ($lang eq 'nolang') {
1317: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1318: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1319: } else {
1320: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1321: $langchoices{$lang},
1322: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1323: }
1324: $datatable .= '</span></td>'."\n".
1325: '<td class="LC_left_item">';
1326: if ($type{$lang} eq 'custom') {
1327: $datatable .= '<span class="LC_nobreak"><label>'.
1328: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1329: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1330: } else {
1331: $datatable .= $lt{'upl'};
1332: }
1333: $datatable .='<br />';
1334: if ($switchserver) {
1335: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1336: } else {
1337: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1338: }
1.160.6.5 raeburn 1339: $datatable .= '</td></tr>';
1340: $itemcount ++;
1.6 raeburn 1341: }
1.160.6.5 raeburn 1342: my @addlangs;
1343: foreach my $lang (sort(keys(%langchoices))) {
1344: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1345: push(@addlangs,$lang);
1346: }
1347: if (@addlangs > 0) {
1348: my %toadd;
1349: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1350: $toadd{''} = &mt('Select');
1351: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1352: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1353: &mt('Add log-in help page for a specific language:').' '.
1354: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1355: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1356: if ($switchserver) {
1357: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1358: } else {
1359: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1360: }
1.160.6.5 raeburn 1361: $datatable .= '</td></tr>';
1362: $itemcount ++;
1.6 raeburn 1363: }
1.160.6.5 raeburn 1364: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1365: } elsif ($caller eq 'headtag') {
1366: my %domservers = &Apache::lonnet::get_servers($dom);
1367: my $choice = $choices{'headtag'};
1368: $css_class = ' class="LC_odd_row"';
1369: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1370: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1371: '<th>'.$choices{'current'}.'</th>'.
1372: '<th>'.$choices{'action'}.'</th>'.
1373: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1374: my (%currurls,%currexempt);
1375: if (ref($settings) eq 'HASH') {
1376: if (ref($settings->{'headtag'}) eq 'HASH') {
1377: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1378: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1379: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1380: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1381: }
1382: }
1383: }
1384: }
1385: foreach my $lonhost (sort(keys(%domservers))) {
1386: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1387: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1388: if ($currurls{$lonhost}) {
1389: $datatable .= '<td class="LC_right_item"><a href="'.
1390: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1391: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1392: '">'.$lt{'curr'}.'</a></td>'.
1393: '<td><span class="LC_nobreak"><label>'.
1394: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1395: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1396: } else {
1397: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1398: }
1399: $datatable .='<br />';
1400: if ($switchserver) {
1401: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1402: } else {
1403: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1404: }
1.160.6.87 raeburn 1405: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1406: }
1407: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1408: } elsif ($caller eq 'saml') {
1409: my %domservers = &Apache::lonnet::get_servers($dom);
1410: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1411: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1412: '<th>'.$choices{'samllanding'}.'</th>'.
1413: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1414: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1415: foreach my $lonhost (keys(%domservers)) {
1416: $samlurl{$lonhost} = '/adm/sso';
1417: $styleon{$lonhost} = 'display:none';
1418: $styleoff{$lonhost} = '';
1419: }
1.160.6.123 raeburn 1420: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.160.6.113 raeburn 1421: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1422: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1423: $saml{$lonhost} = 1;
1424: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1425: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1426: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1427: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1428: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1429: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1430: $styleon{$lonhost} = '';
1431: $styleoff{$lonhost} = 'display:none';
1432: } else {
1433: $styleon{$lonhost} = 'display:none';
1434: $styleoff{$lonhost} = '';
1435: }
1436: }
1437: }
1438: my $itemcount = 1;
1439: foreach my $lonhost (sort(keys(%domservers))) {
1440: my $samlon = ' ';
1441: my $samloff = ' checked="checked" ';
1442: if ($saml{$lonhost}) {
1443: $samlon = $samloff;
1444: $samloff = ' ';
1445: }
1446: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1447: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1448: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1449: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1450: &mt('No').'</label>'.(' 'x2).
1451: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1452: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1453: &mt('Yes').'</label></span></td>'.
1454: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1455: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1456: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1457: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1458: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1459: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1460: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1461: $samltext{$lonhost}.'" /></td><td>';
1462: if ($samlimg{$lonhost}) {
1463: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1464: '<span class="LC_nobreak"><label>'.
1465: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1466: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1467: } else {
1468: $datatable .= $lt{'upl'};
1469: }
1470: $datatable .='<br />';
1471: if ($switchserver) {
1472: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1473: } else {
1474: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1475: }
1476: $datatable .= '</td>'.
1477: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1478: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1479: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1480: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1481: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1482: $samltitle{$lonhost}.'</textarea></td>'.
1483: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1484: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1485: '</table></td>'.
1486: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1487: $itemcount ++;
1488: }
1489: $datatable .= '</table></td></tr>';
1.1 raeburn 1490: }
1.6 raeburn 1491: return $datatable;
1492: }
1493:
1494: sub login_choices {
1495: my %choices =
1496: &Apache::lonlocal::texthash (
1.116 bisitz 1497: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1498: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1499: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1500: disallowlogin => "Login page requests redirected",
1501: hostid => "Server",
1.128 raeburn 1502: server => "Redirect to:",
1503: serverpath => "Path",
1504: custompath => "Custom",
1505: exempt => "Exempt IP(s)",
1.110 raeburn 1506: directlogin => "No redirect",
1507: newuser => "Link to create a user account",
1508: img => "Header",
1509: logo => "Main Logo",
1510: domlogo => "Domain Logo",
1511: login => "Log-in Header",
1512: textcol => "Text color",
1513: bgcol => "Box color",
1514: bgs => "Background colors",
1515: links => "Link colors",
1516: font => "Font color",
1517: pgbg => "Header",
1518: mainbg => "Page",
1519: sidebg => "Login box",
1520: link => "Link",
1521: alink => "Active link",
1522: vlink => "Visited link",
1.160.6.56 raeburn 1523: headtag => "Custom markup",
1524: action => "Action",
1525: current => "Current",
1.160.6.113 raeburn 1526: samllanding => "Dual login?",
1527: samloptions => "Options",
1.160.6.119 raeburn 1528: alttext => "Alt text",
1.6 raeburn 1529: );
1530: return %choices;
1531: }
1532:
1.160.6.113 raeburn 1533: sub login_file_options {
1534: return &Apache::lonlocal::texthash(
1535: del => 'Delete?',
1536: rep => 'Replace:',
1537: upl => 'Upload:',
1538: curr => 'View contents',
1539: default => 'Default',
1540: custom => 'Custom',
1541: none => 'None',
1542: );
1543: }
1544:
1545: sub print_ipaccess {
1546: my ($dom,$settings,$rowtotal) = @_;
1547: my $css_class;
1548: my $itemcount = 0;
1549: my $datatable;
1550: my %ordered;
1551: if (ref($settings) eq 'HASH') {
1552: foreach my $item (keys(%{$settings})) {
1553: if (ref($settings->{$item}) eq 'HASH') {
1554: my $num = $settings->{$item}{'order'};
1555: if ($num eq '') {
1556: $num = scalar(keys(%{$settings}));
1557: }
1558: $ordered{$num} = $item;
1559: }
1560: }
1561: }
1562: my $maxnum = scalar(keys(%ordered));
1563: if (keys(%ordered)) {
1564: my @items = sort { $a <=> $b } keys(%ordered);
1565: for (my $i=0; $i<@items; $i++) {
1566: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1567: my $item = $ordered{$items[$i]};
1568: my ($name,$ipranges,%commblocks,%courses);
1569: if (ref($settings->{$item}) eq 'HASH') {
1570: $name = $settings->{$item}->{'name'};
1571: $ipranges = $settings->{$item}->{'ip'};
1572: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1573: %commblocks = %{$settings->{$item}->{'commblocks'}};
1574: }
1575: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1576: %courses = %{$settings->{$item}->{'courses'}};
1577: }
1578: }
1579: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1580: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1581: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1582: for (my $k=0; $k<=$maxnum; $k++) {
1583: my $vpos = $k+1;
1584: my $selstr;
1585: if ($k == $i) {
1586: $selstr = ' selected="selected" ';
1587: }
1588: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1589: }
1590: $datatable .= '</select>'.(' 'x2).
1591: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1592: &mt('Delete?').'</label></span></td>'.
1593: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1594: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1595: '</td></tr>';
1596: $itemcount ++;
1597: }
1598: }
1599: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1600: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1601: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1602: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1603: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1604: for (my $k=0; $k<$maxnum+1; $k++) {
1605: my $vpos = $k+1;
1606: my $selstr;
1607: if ($k == $maxnum) {
1608: $selstr = ' selected="selected" ';
1609: }
1610: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1611: }
1612: $datatable .= '</select> '."\n".
1613: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1614: '<td colspan="2">'.
1615: &ipaccess_options('add',$itemcount,$dom).
1616: '</td>'."\n".
1617: '</tr>'."\n";
1618: $$rowtotal ++;
1619: return $datatable;
1620: }
1621:
1622: sub ipaccess_options {
1623: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1624: my (%currblocks,%currcourses,$output);
1625: if (ref($blocksref) eq 'HASH') {
1626: %currblocks = %{$blocksref};
1627: }
1628: if (ref($coursesref) eq 'HASH') {
1629: %currcourses = %{$coursesref};
1630: }
1631: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1632: '<span class="LC_nobreak">'.&mt('Name').': '.
1633: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1634: '</span></fieldset>'.
1635: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1636: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1637: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1638: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1639: $ipranges.'</textarea></fieldset>'.
1640: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1641: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1642: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1643: '<table>';
1644: foreach my $cid (sort(keys(%currcourses))) {
1645: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1646: $output .= '<tr><td><span class="LC_nobreak">'.
1647: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1648: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1649: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1650: }
1651: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1652: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1653: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1654: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1655: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1656: '</span></td></tr></table>'."\n".
1657: '</fieldset>';
1658: return $output;
1659: }
1660:
1661: sub blocker_checkboxes {
1662: my ($num,$blocks) = @_;
1663: my ($typeorder,$types) = &commblocktype_text();
1664: my $numinrow = 6;
1665: my $output = '<table>';
1666: for (my $i=0; $i<@{$typeorder}; $i++) {
1667: my $block = $typeorder->[$i];
1668: my $blockstatus;
1669: if (ref($blocks) eq 'HASH') {
1670: if ($blocks->{$block} eq 'on') {
1671: $blockstatus = 'checked="checked"';
1672: }
1673: }
1674: my $rem = $i%($numinrow);
1675: if ($rem == 0) {
1676: if ($i > 0) {
1677: $output .= '</tr>';
1678: }
1679: $output .= '<tr>';
1680: }
1681: if ($i == scalar(@{$typeorder})-1) {
1682: my $colsleft = $numinrow-$rem;
1683: if ($colsleft > 1) {
1684: $output .= '<td colspan="'.$colsleft.'">';
1685: } else {
1686: $output .= '<td>';
1687: }
1688: } else {
1689: $output .= '<td>';
1690: }
1691: my $item = 'ipaccess_block_'.$num;
1692: if ($blockstatus) {
1693: $blockstatus = ' '.$blockstatus;
1694: }
1695: $output .= '<span class="LC_nobreak"><label>'."\n".
1696: '<input type="checkbox" name="'.$item.'"'.
1697: $blockstatus.' value="'.$block.'"'.' />'.
1698: $types->{$block}.'</label></span>'."\n".
1699: '<br /></td>';
1700: }
1701: $output .= '</tr></table>';
1702: return $output;
1703: }
1704:
1705: sub commblocktype_text {
1706: my %types = &Apache::lonlocal::texthash(
1707: 'com' => 'Messaging',
1708: 'chat' => 'Chat Room',
1709: 'boards' => 'Discussion',
1710: 'port' => 'Portfolio',
1711: 'groups' => 'Groups',
1712: 'blogs' => 'Blogs',
1713: 'about' => 'User Information',
1714: 'printout' => 'Printouts',
1715: 'passwd' => 'Change Password',
1716: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1717: 'search' => 'Course search',
1718: 'wishlist' => 'Stored links',
1719: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1720: );
1.160.6.115 raeburn 1721: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1722: return ($typeorder,\%types);
1723: }
1724:
1.6 raeburn 1725: sub print_rolecolors {
1.30 raeburn 1726: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1727: my %choices = &color_font_choices();
1728: my @bgs = ('pgbg','tabbg','sidebg');
1729: my @links = ('link','alink','vlink');
1.160.6.125 raeburn 1730: my @images = ();
1.6 raeburn 1731: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1732: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1733: my %defaultdesign = %Apache::loncommon::defaultdesign;
1734: my (%is_custom,%designs);
1.160.6.22 raeburn 1735: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1736: if (ref($settings) eq 'HASH') {
1737: if (ref($settings->{$role}) eq 'HASH') {
1738: if ($settings->{$role}->{'font'} ne '') {
1739: $designs{'font'} = $settings->{$role}->{'font'};
1740: $is_custom{'font'} = 1;
1741: }
1.97 tempelho 1742: if ($settings->{$role}->{'fontmenu'} ne '') {
1743: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1744: $is_custom{'fontmenu'} = 1;
1745: }
1.6 raeburn 1746: foreach my $item (@bgs) {
1747: if ($settings->{$role}->{$item} ne '') {
1748: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1749: $is_custom{$item} = 1;
1750: }
1751: }
1752: foreach my $item (@links) {
1753: if ($settings->{$role}->{$item} ne '') {
1754: $designs{'links'}{$item} = $settings->{$role}->{$item};
1755: $is_custom{$item} = 1;
1756: }
1757: }
1758: }
1759: } else {
1.97 tempelho 1760: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1761: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1762: $is_custom{'fontmenu'} = 1;
1763: }
1.6 raeburn 1764: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1765: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1766: $is_custom{'font'} = 1;
1767: }
1768: foreach my $item (@bgs) {
1769: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1770: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1771: $is_custom{$item} = 1;
1772:
1773: }
1774: }
1775: foreach my $item (@links) {
1776: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1777: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1778: $is_custom{$item} = 1;
1779: }
1780: }
1781: }
1782: my $itemcount = 1;
1.30 raeburn 1783: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1784: $datatable .= '</tr></table></td></tr>';
1785: return $datatable;
1786: }
1787:
1.160.6.22 raeburn 1788: sub role_defaults {
1789: my ($role,$bgs,$links,$images,$logintext) = @_;
1790: my %defaults;
1791: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1792: return %defaults;
1793: }
1794: my %defaultdesign = %Apache::loncommon::defaultdesign;
1795: if ($role eq 'login') {
1796: %defaults = (
1797: font => $defaultdesign{$role.'.font'},
1798: );
1799: if (ref($logintext) eq 'ARRAY') {
1800: foreach my $item (@{$logintext}) {
1801: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1802: }
1803: }
1804: foreach my $item (@{$images}) {
1805: $defaults{'showlogo'}{$item} = 1;
1806: }
1807: } else {
1808: %defaults = (
1809: font => $defaultdesign{$role.'.font'},
1810: fontmenu => $defaultdesign{$role.'.fontmenu'},
1811: );
1812: }
1813: foreach my $item (@{$bgs}) {
1814: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1815: }
1816: foreach my $item (@{$links}) {
1817: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1818: }
1819: foreach my $item (@{$images}) {
1820: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1821: }
1822: return %defaults;
1823: }
1824:
1.6 raeburn 1825: sub display_color_options {
1.9 raeburn 1826: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1827: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1828: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1829: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1830: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1831: '<td>'.$choices->{'font'}.'</td>';
1832: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1833: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1834: } else {
1835: $datatable .= '<td> </td>';
1836: }
1.160.6.9 raeburn 1837: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1838:
1.8 raeburn 1839: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1840: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1841: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1842: ' </span></td></tr>';
1.107 raeburn 1843: unless ($role eq 'login') {
1844: $datatable .= '<tr'.$css_class.'>'.
1845: '<td>'.$choices->{'fontmenu'}.'</td>';
1846: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1847: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1848: } else {
1849: $datatable .= '<td> </td>';
1850: }
1.160.6.22 raeburn 1851: $current_color = $designs->{'fontmenu'} ?
1852: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1853: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1854: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1855: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1856: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1857: ' </span></td></tr>';
1.97 tempelho 1858: }
1.9 raeburn 1859: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1860: foreach my $img (@{$images}) {
1.18 albertel 1861: $itemcount ++;
1.6 raeburn 1862: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1863: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1864: '<td>'.$choices->{$img};
1.160.6.119 raeburn 1865: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 1866: if ($role eq 'login') {
1867: if ($img eq 'login') {
1868: $login_hdr_pick =
1.135 bisitz 1869: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1870: $logincolors =
1871: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1872: $designs,$defaults);
1.160.6.121 raeburn 1873: } else {
1.160.6.119 raeburn 1874: if ($img ne 'domlogo') {
1875: $datatable.= &logo_display_options($img,$defaults,$designs);
1876: }
1877: if (ref($designs->{'alttext'}) eq 'HASH') {
1878: $alttext = $designs->{'alttext'}{$img};
1879: }
1.70 raeburn 1880: }
1881: }
1882: $datatable .= '</td>';
1.6 raeburn 1883: if ($designs->{$img} ne '') {
1884: $imgfile = $designs->{$img};
1.18 albertel 1885: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1886: } else {
1887: $imgfile = $defaults->{$img};
1888: }
1889: if ($imgfile) {
1.9 raeburn 1890: my ($showfile,$fullsize);
1891: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1892: my $urldir = $1;
1893: my $filename = $2;
1894: my @info = &Apache::lonnet::stat_file($designs->{$img});
1895: if (@info) {
1896: my $thumbfile = 'tn-'.$filename;
1897: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1898: if (@thumb) {
1899: $showfile = $urldir.'/'.$thumbfile;
1900: } else {
1901: $showfile = $imgfile;
1902: }
1903: } else {
1904: $showfile = '';
1905: }
1906: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1907: $showfile = $imgfile;
1.6 raeburn 1908: my $imgdir = $1;
1909: my $filename = $2;
1.159 raeburn 1910: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1911: $showfile = "/$imgdir/tn-".$filename;
1912: } else {
1.159 raeburn 1913: my $input = $londocroot.$imgfile;
1914: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1915: if (!-e $output) {
1.9 raeburn 1916: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1917: my ($fullwidth,$fullheight) = &check_dimensions($input);
1918: if ($fullwidth ne '' && $fullheight ne '') {
1919: if ($fullwidth > $width && $fullheight > $height) {
1920: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1921: my @args = ('convert','-sample',$size,$input,$output);
1922: system({$args[0]} @args);
1.159 raeburn 1923: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1924: }
1925: }
1.6 raeburn 1926: }
1927: }
1.16 raeburn 1928: }
1.6 raeburn 1929: if ($showfile) {
1.40 raeburn 1930: if ($showfile =~ m{^/(adm|res)/}) {
1931: if ($showfile =~ m{^/res/}) {
1932: my $local_showfile =
1933: &Apache::lonnet::filelocation('',$showfile);
1934: &Apache::lonnet::repcopy($local_showfile);
1935: }
1936: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1937: }
1938: if ($imgfile) {
1939: if ($imgfile =~ m{^/(adm|res)/}) {
1940: if ($imgfile =~ m{^/res/}) {
1941: my $local_imgfile =
1942: &Apache::lonnet::filelocation('',$imgfile);
1943: &Apache::lonnet::repcopy($local_imgfile);
1944: }
1945: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1946: } else {
1947: $fullsize = $imgfile;
1948: }
1949: }
1.41 raeburn 1950: $datatable .= '<td>';
1951: if ($img eq 'login') {
1.135 bisitz 1952: $datatable .= $login_hdr_pick;
1953: }
1.41 raeburn 1954: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1955: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1956: } else {
1.160.6.22 raeburn 1957: $datatable .= '<td> </td><td class="LC_left_item">'.
1958: &mt('Upload:').'<br />';
1.6 raeburn 1959: }
1960: } else {
1.160.6.22 raeburn 1961: $datatable .= '<td> </td><td class="LC_left_item">'.
1962: &mt('Upload:').'<br />';
1.6 raeburn 1963: }
1.9 raeburn 1964: if ($switchserver) {
1965: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1966: } else {
1.135 bisitz 1967: if ($img ne 'login') { # suppress file selection for Log-in header
1968: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1969: }
1.9 raeburn 1970: }
1.160.6.119 raeburn 1971: if (($role eq 'login') && ($img ne 'login')) {
1972: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
1973: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
1974: '</label></span>';
1975: }
1.9 raeburn 1976: $datatable .= '</td></tr>';
1.6 raeburn 1977: }
1978: $itemcount ++;
1979: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1980: $datatable .= '<tr'.$css_class.'>'.
1981: '<td>'.$choices->{'bgs'}.'</td>';
1982: my $bgs_def;
1983: foreach my $item (@{$bgs}) {
1984: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1985: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1986: }
1987: }
1988: if ($bgs_def) {
1.8 raeburn 1989: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1990: } else {
1991: $datatable .= '<td> </td>';
1992: }
1993: $datatable .= '<td class="LC_right_item">'.
1994: '<table border="0"><tr>';
1.160.6.13 raeburn 1995:
1.6 raeburn 1996: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1997: $datatable .= '<td align="center">'.$choices->{$item};
1998: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1999: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2000: $datatable .= ' ';
1.6 raeburn 2001: }
1.160.6.9 raeburn 2002: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2003: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2004: }
2005: $datatable .= '</tr></table></td></tr>';
2006: $itemcount ++;
2007: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2008: $datatable .= '<tr'.$css_class.'>'.
2009: '<td>'.$choices->{'links'}.'</td>';
2010: my $links_def;
2011: foreach my $item (@{$links}) {
2012: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2013: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 2014: }
2015: }
2016: if ($links_def) {
1.8 raeburn 2017: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2018: } else {
2019: $datatable .= '<td> </td>';
2020: }
2021: $datatable .= '<td class="LC_right_item">'.
2022: '<table border="0"><tr>';
2023: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2024: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2025: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2026: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2027: $datatable.=' ';
1.6 raeburn 2028: }
1.160.6.9 raeburn 2029: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2030: '" /></td>';
2031: }
1.30 raeburn 2032: $$rowtotal += $itemcount;
1.3 raeburn 2033: return $datatable;
2034: }
2035:
1.70 raeburn 2036: sub logo_display_options {
2037: my ($img,$defaults,$designs) = @_;
2038: my $checkedon;
2039: if (ref($defaults) eq 'HASH') {
2040: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2041: if ($defaults->{'showlogo'}{$img}) {
2042: $checkedon = 'checked="checked" ';
2043: }
2044: }
2045: }
2046: if (ref($designs) eq 'HASH') {
2047: if (ref($designs->{'showlogo'}) eq 'HASH') {
2048: if (defined($designs->{'showlogo'}{$img})) {
2049: if ($designs->{'showlogo'}{$img} == 0) {
2050: $checkedon = '';
2051: } elsif ($designs->{'showlogo'}{$img} == 1) {
2052: $checkedon = 'checked="checked" ';
2053: }
2054: }
2055: }
2056: }
2057: return '<br /><label> <input type="checkbox" name="'.
2058: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2059: &mt('show').'</label>'."\n";
2060: }
2061:
1.41 raeburn 2062: sub login_header_options {
1.135 bisitz 2063: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2064: my $output = '';
1.41 raeburn 2065: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2066: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2067: if (!$is_custom->{'textcol'}) {
2068: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2069: ' ';
2070: }
2071: if (!$is_custom->{'bgcol'}) {
2072: $output .= $choices->{'bgcol'}.': '.
2073: '<span id="css_'.$role.'_font" style="background-color: '.
2074: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2075: }
2076: $output .= '<br />';
2077: }
2078: $output .='<br />';
2079: return $output;
2080: }
2081:
2082: sub login_text_colors {
1.160.6.22 raeburn 2083: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2084: my $color_menu = '<table border="0"><tr>';
2085: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2086: $color_menu .= '<td align="center">'.$choices->{$item};
2087: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2088: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2089: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2090: }
2091: $color_menu .= '</tr></table><br />';
2092: return $color_menu;
2093: }
2094:
2095: sub image_changes {
2096: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2097: my $output;
1.135 bisitz 2098: if ($img eq 'login') {
1.160.6.87 raeburn 2099: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2100: } elsif (!$is_custom) {
1.70 raeburn 2101: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2102: $output = &mt('Default image:').'<br />';
1.41 raeburn 2103: } else {
1.160.6.87 raeburn 2104: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2105: }
2106: }
1.160.6.87 raeburn 2107: if ($img ne 'login') {
1.135 bisitz 2108: if ($img_import) {
2109: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2110: }
2111: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2112: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2113: if ($is_custom) {
2114: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2115: '<input type="checkbox" name="'.
2116: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2117: '</label> '.&mt('Replace:').'</span><br />';
2118: } else {
1.160.6.22 raeburn 2119: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2120: }
1.41 raeburn 2121: }
2122: return $output;
2123: }
2124:
1.3 raeburn 2125: sub print_quotas {
1.86 raeburn 2126: my ($dom,$settings,$rowtotal,$action) = @_;
2127: my $context;
2128: if ($action eq 'quotas') {
2129: $context = 'tools';
2130: } else {
2131: $context = $action;
2132: }
1.160.6.20 raeburn 2133: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2134: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2135: my $typecount = 0;
1.101 raeburn 2136: my ($css_class,%titles);
1.86 raeburn 2137: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 2138: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 2139: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2140: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2141: %titles = &courserequest_titles();
1.160.6.5 raeburn 2142: } elsif ($context eq 'requestauthor') {
2143: @usertools = ('author');
2144: @options = ('norequest','approval','automatic');
2145: %titles = &authorrequest_titles();
1.86 raeburn 2146: } else {
1.160.6.4 raeburn 2147: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2148: %titles = &tool_titles();
1.86 raeburn 2149: }
1.26 raeburn 2150: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2151: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2152: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2153: unless (($context eq 'requestcourses') ||
2154: ($context eq 'requestauthor')) {
1.86 raeburn 2155: if (ref($settings) eq 'HASH') {
2156: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2157: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2158: } else {
2159: $currdefquota = $settings->{$type};
2160: }
1.160.6.20 raeburn 2161: if (ref($settings->{authorquota}) eq 'HASH') {
2162: $currauthorquota = $settings->{authorquota}->{$type};
2163: }
1.78 raeburn 2164: }
1.72 raeburn 2165: }
1.3 raeburn 2166: if (defined($usertypes->{$type})) {
2167: $typecount ++;
2168: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2169: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2170: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2171: '<td class="LC_left_item">';
1.101 raeburn 2172: if ($context eq 'requestcourses') {
2173: $datatable .= '<table><tr>';
2174: }
2175: my %cell;
1.72 raeburn 2176: foreach my $item (@usertools) {
1.101 raeburn 2177: if ($context eq 'requestcourses') {
2178: my ($curroption,$currlimit);
2179: if (ref($settings) eq 'HASH') {
2180: if (ref($settings->{$item}) eq 'HASH') {
2181: $curroption = $settings->{$item}->{$type};
2182: if ($curroption =~ /^autolimit=(\d*)$/) {
2183: $currlimit = $1;
2184: }
2185: }
2186: }
2187: if (!$curroption) {
2188: $curroption = 'norequest';
2189: }
2190: $datatable .= '<th>'.$titles{$item}.'</th>';
2191: foreach my $option (@options) {
2192: my $val = $option;
2193: if ($option eq 'norequest') {
2194: $val = 0;
2195: }
2196: if ($option eq 'validate') {
2197: my $canvalidate = 0;
2198: if (ref($validations{$item}) eq 'HASH') {
2199: if ($validations{$item}{$type}) {
2200: $canvalidate = 1;
2201: }
2202: }
2203: next if (!$canvalidate);
2204: }
2205: my $checked = '';
2206: if ($option eq $curroption) {
2207: $checked = ' checked="checked"';
2208: } elsif ($option eq 'autolimit') {
2209: if ($curroption =~ /^autolimit/) {
2210: $checked = ' checked="checked"';
2211: }
2212: }
2213: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2214: '<input type="radio" name="crsreq_'.$item.
2215: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2216: $titles{$option}.'</label>';
1.101 raeburn 2217: if ($option eq 'autolimit') {
1.127 raeburn 2218: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2219: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2220: 'value="'.$currlimit.'" />';
1.101 raeburn 2221: }
1.127 raeburn 2222: $cell{$item} .= '</span> ';
1.103 raeburn 2223: if ($option eq 'autolimit') {
1.127 raeburn 2224: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2225: }
1.101 raeburn 2226: }
1.160.6.5 raeburn 2227: } elsif ($context eq 'requestauthor') {
2228: my $curroption;
2229: if (ref($settings) eq 'HASH') {
2230: $curroption = $settings->{$type};
2231: }
2232: if (!$curroption) {
2233: $curroption = 'norequest';
2234: }
2235: foreach my $option (@options) {
2236: my $val = $option;
2237: if ($option eq 'norequest') {
2238: $val = 0;
2239: }
2240: my $checked = '';
2241: if ($option eq $curroption) {
2242: $checked = ' checked="checked"';
2243: }
2244: $datatable .= '<span class="LC_nobreak"><label>'.
2245: '<input type="radio" name="authorreq_'.$type.
2246: '" value="'.$val.'"'.$checked.' />'.
2247: $titles{$option}.'</label></span> ';
2248: }
1.101 raeburn 2249: } else {
2250: my $checked = 'checked="checked" ';
2251: if (ref($settings) eq 'HASH') {
2252: if (ref($settings->{$item}) eq 'HASH') {
2253: if ($settings->{$item}->{$type} == 0) {
2254: $checked = '';
2255: } elsif ($settings->{$item}->{$type} == 1) {
2256: $checked = 'checked="checked" ';
2257: }
1.78 raeburn 2258: }
1.72 raeburn 2259: }
1.101 raeburn 2260: $datatable .= '<span class="LC_nobreak"><label>'.
2261: '<input type="checkbox" name="'.$context.'_'.$item.
2262: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2263: '</label></span> ';
1.72 raeburn 2264: }
1.101 raeburn 2265: }
2266: if ($context eq 'requestcourses') {
2267: $datatable .= '</tr><tr>';
2268: foreach my $item (@usertools) {
1.106 raeburn 2269: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2270: }
2271: $datatable .= '</tr></table>';
1.72 raeburn 2272: }
1.86 raeburn 2273: $datatable .= '</td>';
1.160.6.5 raeburn 2274: unless (($context eq 'requestcourses') ||
2275: ($context eq 'requestauthor')) {
1.86 raeburn 2276: $datatable .=
1.160.6.20 raeburn 2277: '<td class="LC_right_item">'.
2278: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2279: '<input type="text" name="quota_'.$type.
1.72 raeburn 2280: '" value="'.$currdefquota.
1.160.6.20 raeburn 2281: '" size="5" /></span>'.(' ' x 2).
2282: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2283: '<input type="text" name="authorquota_'.$type.
2284: '" value="'.$currauthorquota.
2285: '" size="5" /></span></td>';
1.86 raeburn 2286: }
2287: $datatable .= '</tr>';
1.3 raeburn 2288: }
2289: }
2290: }
1.160.6.5 raeburn 2291: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2292: $defaultquota = '20';
1.160.6.20 raeburn 2293: $authorquota = '500';
1.86 raeburn 2294: if (ref($settings) eq 'HASH') {
2295: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2296: $defaultquota = $settings->{'defaultquota'}->{'default'};
2297: } elsif (defined($settings->{'default'})) {
2298: $defaultquota = $settings->{'default'};
2299: }
1.160.6.20 raeburn 2300: if (ref($settings->{'authorquota'}) eq 'HASH') {
2301: $authorquota = $settings->{'authorquota'}->{'default'};
2302: }
1.3 raeburn 2303: }
2304: }
2305: $typecount ++;
2306: $css_class = $typecount%2?' class="LC_odd_row"':'';
2307: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2308: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2309: '<td class="LC_left_item">';
1.101 raeburn 2310: if ($context eq 'requestcourses') {
2311: $datatable .= '<table><tr>';
2312: }
2313: my %defcell;
1.72 raeburn 2314: foreach my $item (@usertools) {
1.101 raeburn 2315: if ($context eq 'requestcourses') {
2316: my ($curroption,$currlimit);
2317: if (ref($settings) eq 'HASH') {
2318: if (ref($settings->{$item}) eq 'HASH') {
2319: $curroption = $settings->{$item}->{'default'};
2320: if ($curroption =~ /^autolimit=(\d*)$/) {
2321: $currlimit = $1;
2322: }
2323: }
2324: }
2325: if (!$curroption) {
2326: $curroption = 'norequest';
2327: }
2328: $datatable .= '<th>'.$titles{$item}.'</th>';
2329: foreach my $option (@options) {
2330: my $val = $option;
2331: if ($option eq 'norequest') {
2332: $val = 0;
2333: }
2334: if ($option eq 'validate') {
2335: my $canvalidate = 0;
2336: if (ref($validations{$item}) eq 'HASH') {
2337: if ($validations{$item}{'default'}) {
2338: $canvalidate = 1;
2339: }
2340: }
2341: next if (!$canvalidate);
2342: }
2343: my $checked = '';
2344: if ($option eq $curroption) {
2345: $checked = ' checked="checked"';
2346: } elsif ($option eq 'autolimit') {
2347: if ($curroption =~ /^autolimit/) {
2348: $checked = ' checked="checked"';
2349: }
2350: }
2351: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2352: '<input type="radio" name="crsreq_'.$item.
2353: '_default" value="'.$val.'"'.$checked.' />'.
2354: $titles{$option}.'</label>';
2355: if ($option eq 'autolimit') {
1.127 raeburn 2356: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2357: $item.'_limit_default" size="1" '.
2358: 'value="'.$currlimit.'" />';
2359: }
1.127 raeburn 2360: $defcell{$item} .= '</span> ';
1.104 raeburn 2361: if ($option eq 'autolimit') {
1.127 raeburn 2362: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2363: }
1.101 raeburn 2364: }
1.160.6.5 raeburn 2365: } elsif ($context eq 'requestauthor') {
2366: my $curroption;
2367: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2368: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2369: }
2370: if (!$curroption) {
2371: $curroption = 'norequest';
2372: }
2373: foreach my $option (@options) {
2374: my $val = $option;
2375: if ($option eq 'norequest') {
2376: $val = 0;
2377: }
2378: my $checked = '';
2379: if ($option eq $curroption) {
2380: $checked = ' checked="checked"';
2381: }
2382: $datatable .= '<span class="LC_nobreak"><label>'.
2383: '<input type="radio" name="authorreq_default"'.
2384: ' value="'.$val.'"'.$checked.' />'.
2385: $titles{$option}.'</label></span> ';
2386: }
1.101 raeburn 2387: } else {
2388: my $checked = 'checked="checked" ';
2389: if (ref($settings) eq 'HASH') {
2390: if (ref($settings->{$item}) eq 'HASH') {
2391: if ($settings->{$item}->{'default'} == 0) {
2392: $checked = '';
2393: } elsif ($settings->{$item}->{'default'} == 1) {
2394: $checked = 'checked="checked" ';
2395: }
1.78 raeburn 2396: }
1.72 raeburn 2397: }
1.101 raeburn 2398: $datatable .= '<span class="LC_nobreak"><label>'.
2399: '<input type="checkbox" name="'.$context.'_'.$item.
2400: '" value="default" '.$checked.'/>'.$titles{$item}.
2401: '</label></span> ';
2402: }
2403: }
2404: if ($context eq 'requestcourses') {
2405: $datatable .= '</tr><tr>';
2406: foreach my $item (@usertools) {
1.106 raeburn 2407: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2408: }
1.101 raeburn 2409: $datatable .= '</tr></table>';
1.72 raeburn 2410: }
1.86 raeburn 2411: $datatable .= '</td>';
1.160.6.5 raeburn 2412: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2413: $datatable .= '<td class="LC_right_item">'.
2414: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2415: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2416: $defaultquota.'" size="5" /></span>'.(' ' x2).
2417: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2418: '<input type="text" name="authorquota" value="'.
2419: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2420: }
2421: $datatable .= '</tr>';
1.72 raeburn 2422: $typecount ++;
2423: $css_class = $typecount%2?' class="LC_odd_row"':'';
2424: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2425: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2426: if ($context eq 'requestcourses') {
1.109 raeburn 2427: $datatable .= &mt('(overrides affiliation, if set)').
2428: '</td>'.
2429: '<td class="LC_left_item">'.
2430: '<table><tr>';
1.101 raeburn 2431: } else {
1.109 raeburn 2432: $datatable .= &mt('(overrides affiliation, if checked)').
2433: '</td>'.
2434: '<td class="LC_left_item" colspan="2">'.
2435: '<br />';
1.101 raeburn 2436: }
2437: my %advcell;
1.72 raeburn 2438: foreach my $item (@usertools) {
1.101 raeburn 2439: if ($context eq 'requestcourses') {
2440: my ($curroption,$currlimit);
2441: if (ref($settings) eq 'HASH') {
2442: if (ref($settings->{$item}) eq 'HASH') {
2443: $curroption = $settings->{$item}->{'_LC_adv'};
2444: if ($curroption =~ /^autolimit=(\d*)$/) {
2445: $currlimit = $1;
2446: }
2447: }
2448: }
2449: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2450: my $checked = '';
2451: if ($curroption eq '') {
2452: $checked = ' checked="checked"';
2453: }
2454: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2455: '<input type="radio" name="crsreq_'.$item.
2456: '__LC_adv" value=""'.$checked.' />'.
2457: &mt('No override set').'</label></span> ';
1.101 raeburn 2458: foreach my $option (@options) {
2459: my $val = $option;
2460: if ($option eq 'norequest') {
2461: $val = 0;
2462: }
2463: if ($option eq 'validate') {
2464: my $canvalidate = 0;
2465: if (ref($validations{$item}) eq 'HASH') {
2466: if ($validations{$item}{'_LC_adv'}) {
2467: $canvalidate = 1;
2468: }
2469: }
2470: next if (!$canvalidate);
2471: }
2472: my $checked = '';
1.104 raeburn 2473: if ($val eq $curroption) {
1.101 raeburn 2474: $checked = ' checked="checked"';
2475: } elsif ($option eq 'autolimit') {
2476: if ($curroption =~ /^autolimit/) {
2477: $checked = ' checked="checked"';
2478: }
2479: }
2480: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2481: '<input type="radio" name="crsreq_'.$item.
2482: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2483: $titles{$option}.'</label>';
2484: if ($option eq 'autolimit') {
1.127 raeburn 2485: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2486: $item.'_limit__LC_adv" size="1" '.
2487: 'value="'.$currlimit.'" />';
2488: }
1.127 raeburn 2489: $advcell{$item} .= '</span> ';
1.104 raeburn 2490: if ($option eq 'autolimit') {
1.127 raeburn 2491: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2492: }
1.101 raeburn 2493: }
1.160.6.5 raeburn 2494: } elsif ($context eq 'requestauthor') {
2495: my $curroption;
2496: if (ref($settings) eq 'HASH') {
2497: $curroption = $settings->{'_LC_adv'};
2498: }
2499: my $checked = '';
2500: if ($curroption eq '') {
2501: $checked = ' checked="checked"';
2502: }
2503: $datatable .= '<span class="LC_nobreak"><label>'.
2504: '<input type="radio" name="authorreq__LC_adv"'.
2505: ' value=""'.$checked.' />'.
2506: &mt('No override set').'</label></span> ';
2507: foreach my $option (@options) {
2508: my $val = $option;
2509: if ($option eq 'norequest') {
2510: $val = 0;
2511: }
2512: my $checked = '';
2513: if ($val eq $curroption) {
2514: $checked = ' checked="checked"';
2515: }
2516: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2517: '<input type="radio" name="authorreq__LC_adv"'.
2518: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2519: $titles{$option}.'</label></span> ';
2520: }
1.101 raeburn 2521: } else {
2522: my $checked = 'checked="checked" ';
2523: if (ref($settings) eq 'HASH') {
2524: if (ref($settings->{$item}) eq 'HASH') {
2525: if ($settings->{$item}->{'_LC_adv'} == 0) {
2526: $checked = '';
2527: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2528: $checked = 'checked="checked" ';
2529: }
1.79 raeburn 2530: }
1.72 raeburn 2531: }
1.101 raeburn 2532: $datatable .= '<span class="LC_nobreak"><label>'.
2533: '<input type="checkbox" name="'.$context.'_'.$item.
2534: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2535: '</label></span> ';
2536: }
2537: }
2538: if ($context eq 'requestcourses') {
2539: $datatable .= '</tr><tr>';
2540: foreach my $item (@usertools) {
1.106 raeburn 2541: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2542: }
1.101 raeburn 2543: $datatable .= '</tr></table>';
1.72 raeburn 2544: }
1.98 raeburn 2545: $datatable .= '</td></tr>';
1.30 raeburn 2546: $$rowtotal += $typecount;
1.3 raeburn 2547: return $datatable;
2548: }
2549:
1.160.6.5 raeburn 2550: sub print_requestmail {
1.160.6.93 raeburn 2551: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2552: my ($now,$datatable,%currapp);
1.102 raeburn 2553: $now = time;
2554: if (ref($settings) eq 'HASH') {
2555: if (ref($settings->{'notify'}) eq 'HASH') {
2556: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2557: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2558: }
2559: }
2560: }
1.160.6.16 raeburn 2561: my $numinrow = 2;
1.160.6.34 raeburn 2562: my $css_class;
1.160.6.93 raeburn 2563: if ($$rowtotal%2) {
2564: $css_class = 'LC_odd_row';
2565: }
2566: if ($customcss) {
2567: $css_class .= " $customcss";
2568: }
2569: $css_class =~ s/^\s+//;
2570: if ($css_class) {
2571: $css_class = ' class="'.$css_class.'"';
2572: }
2573: if ($rowstyle) {
2574: $css_class .= ' style="'.$rowstyle.'"';
2575: }
1.160.6.5 raeburn 2576: my $text;
2577: if ($action eq 'requestcourses') {
2578: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2579: } elsif ($action eq 'requestauthor') {
2580: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2581: } else {
1.160.6.34 raeburn 2582: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2583: }
1.160.6.34 raeburn 2584: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2585: ' <td>'.$text.'</td>'.
1.102 raeburn 2586: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2587: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2588: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2589: if ($numdc > 0) {
2590: $datatable .= $table;
1.102 raeburn 2591: } else {
2592: $datatable .= &mt('There are no active Domain Coordinators');
2593: }
2594: $datatable .='</td></tr>';
2595: return $datatable;
2596: }
2597:
1.160.6.30 raeburn 2598: sub print_studentcode {
2599: my ($settings,$rowtotal) = @_;
2600: my $rownum = 0;
2601: my ($output,%current);
2602: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2603: if (ref($settings) eq 'HASH') {
2604: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2605: foreach my $type (@crstypes) {
2606: $current{$type} = $settings->{'uniquecode'}{$type};
2607: }
1.160.6.30 raeburn 2608: }
2609: }
2610: $output .= '<tr>'.
2611: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2612: '<td class="LC_left_item">';
2613: foreach my $type (@crstypes) {
2614: my $check = ' ';
2615: if ($current{$type}) {
2616: $check = ' checked="checked" ';
2617: }
2618: $output .= '<span class="LC_nobreak"><label>'.
2619: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2620: &mt($type).'</label></span>'.(' 'x2).' ';
2621: }
2622: $output .= '</td></tr>';
2623: $$rowtotal ++;
2624: return $output;
2625: }
2626:
2627: sub print_textbookcourses {
1.160.6.46 raeburn 2628: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2629: my $rownum = 0;
2630: my $css_class;
2631: my $itemcount = 1;
2632: my $maxnum = 0;
2633: my $bookshash;
2634: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2635: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2636: }
2637: my %ordered;
2638: if (ref($bookshash) eq 'HASH') {
2639: foreach my $item (keys(%{$bookshash})) {
2640: if (ref($bookshash->{$item}) eq 'HASH') {
2641: my $num = $bookshash->{$item}{'order'};
2642: $ordered{$num} = $item;
2643: }
2644: }
2645: }
2646: my $confname = $dom.'-domainconfig';
2647: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2648: my $maxnum = scalar(keys(%ordered));
2649: my $datatable;
1.160.6.30 raeburn 2650: if (keys(%ordered)) {
2651: my @items = sort { $a <=> $b } keys(%ordered);
2652: for (my $i=0; $i<@items; $i++) {
2653: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2654: my $key = $ordered{$items[$i]};
2655: my %coursehash=&Apache::lonnet::coursedescription($key);
2656: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2657: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2658: if (ref($bookshash->{$key}) eq 'HASH') {
2659: $subject = $bookshash->{$key}->{'subject'};
2660: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2661: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2662: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2663: $author = $bookshash->{$key}->{'author'};
2664: $image = $bookshash->{$key}->{'image'};
2665: if ($image ne '') {
2666: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2667: my $imagethumb = "$path/tn-".$imagefile;
2668: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2669: }
1.160.6.30 raeburn 2670: }
2671: }
1.160.6.46 raeburn 2672: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2673: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2674: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2675: for (my $k=0; $k<=$maxnum; $k++) {
2676: my $vpos = $k+1;
2677: my $selstr;
2678: if ($k == $i) {
2679: $selstr = ' selected="selected" ';
2680: }
2681: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2682: }
2683: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2684: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2685: &mt('Delete?').'</label></span></td>'.
2686: '<td colspan="2">'.
1.160.6.46 raeburn 2687: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2688: (' 'x2).
1.160.6.46 raeburn 2689: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2690: if ($type eq 'textbooks') {
2691: $datatable .= (' 'x2).
1.160.6.47 raeburn 2692: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2693: (' 'x2).
1.160.6.46 raeburn 2694: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2695: (' 'x2).
2696: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2697: if ($image) {
1.160.6.114 raeburn 2698: $datatable .= $imgsrc.
1.160.6.46 raeburn 2699: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2700: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2701: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2702: }
2703: if ($switchserver) {
2704: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2705: } else {
2706: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2707: }
1.160.6.30 raeburn 2708: }
1.160.6.46 raeburn 2709: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2710: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2711: $coursetitle.'</span></td></tr>'."\n";
2712: $itemcount ++;
2713: }
2714: }
2715: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2716: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2717: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2718: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2719: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2720: for (my $k=0; $k<$maxnum+1; $k++) {
2721: my $vpos = $k+1;
2722: my $selstr;
2723: if ($k == $maxnum) {
2724: $selstr = ' selected="selected" ';
2725: }
2726: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2727: }
2728: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2729: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2730: '<td colspan="2">'.
1.160.6.46 raeburn 2731: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2732: (' 'x2).
1.160.6.46 raeburn 2733: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2734: (' 'x2);
2735: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2736: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2737: (' 'x2).
2738: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2739: (' 'x2).
2740: '<span class="LC_nobreak">'.&mt('Image:').' ';
2741: if ($switchserver) {
2742: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2743: } else {
2744: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2745: }
1.160.6.87 raeburn 2746: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2747: }
1.160.6.87 raeburn 2748: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2749: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2750: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2751: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2752: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2753: '</span></td>'."\n".
2754: '</tr>'."\n";
2755: $itemcount ++;
2756: return $datatable;
2757: }
2758:
2759: sub textbookcourses_javascript {
1.160.6.46 raeburn 2760: my ($settings) = @_;
2761: return unless(ref($settings) eq 'HASH');
2762: my (%ordered,%total,%jstext);
2763: foreach my $type ('textbooks','templates') {
2764: $total{$type} = 0;
2765: if (ref($settings->{$type}) eq 'HASH') {
2766: foreach my $item (keys(%{$settings->{$type}})) {
2767: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2768: my $num = $settings->{$type}->{$item}{'order'};
2769: $ordered{$type}{$num} = $item;
2770: }
2771: }
2772: $total{$type} = scalar(keys(%{$settings->{$type}}));
2773: }
2774: my @jsarray = ();
2775: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2776: push(@jsarray,$ordered{$type}{$item});
2777: }
2778: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2779: }
2780: return <<"ENDSCRIPT";
2781: <script type="text/javascript">
2782: // <![CDATA[
1.160.6.46 raeburn 2783: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2784: var changedVal;
1.160.6.46 raeburn 2785: $jstext{'textbooks'};
2786: $jstext{'templates'};
2787: var newpos;
2788: var maxh;
2789: if (caller == 'textbooks') {
2790: newpos = 'textbooks_addbook_pos';
2791: maxh = 1 + $total{'textbooks'};
2792: } else {
2793: newpos = 'templates_addbook_pos';
2794: maxh = 1 + $total{'templates'};
2795: }
1.160.6.30 raeburn 2796: var current = new Array;
2797: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2798: if (item == newpos) {
2799: changedVal = newitemVal;
2800: } else {
2801: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2802: current[newitemVal] = newpos;
2803: }
1.160.6.46 raeburn 2804: if (caller == 'textbooks') {
2805: for (var i=0; i<textbooks.length; i++) {
2806: var elementName = 'textbooks_'+textbooks[i];
2807: if (elementName != item) {
2808: if (form.elements[elementName]) {
2809: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2810: current[currVal] = elementName;
2811: }
2812: }
2813: }
2814: }
2815: if (caller == 'templates') {
2816: for (var i=0; i<templates.length; i++) {
2817: var elementName = 'templates_'+templates[i];
2818: if (elementName != item) {
2819: if (form.elements[elementName]) {
2820: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2821: current[currVal] = elementName;
2822: }
1.160.6.30 raeburn 2823: }
2824: }
2825: }
2826: var oldVal;
2827: for (var j=0; j<maxh; j++) {
2828: if (current[j] == undefined) {
2829: oldVal = j;
2830: }
2831: }
2832: if (oldVal < changedVal) {
2833: for (var k=oldVal+1; k<=changedVal ; k++) {
2834: var elementName = current[k];
2835: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2836: }
2837: } else {
2838: for (var k=changedVal; k<oldVal; k++) {
2839: var elementName = current[k];
2840: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2841: }
2842: }
2843: return;
2844: }
2845:
2846: // ]]>
2847: </script>
2848:
2849: ENDSCRIPT
2850: }
2851:
1.160.6.113 raeburn 2852: sub wafproxy_javascript {
2853: my ($dom) = @_;
2854: return <<"ENDSCRIPT";
2855: <script type="text/javascript">
2856: // <![CDATA[
2857: function updateWAF() {
2858: if (document.getElementById('wafproxy_remoteip')) {
2859: var wafremote = 0;
2860: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
2861: wafremote = 1;
2862: }
2863: var fields = new Array('header','trust');
2864: for (var i=0; i<fields.length; i++) {
2865: if (document.getElementById('wafproxy_'+fields[i])) {
2866: if (wafremote == 1) {
2867: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
2868: }
2869: else {
2870: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
2871: }
2872: }
2873: }
2874: if (document.getElementById('wafproxyranges_$dom')) {
2875: if (wafremote == 1) {
2876: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2877: } else {
2878: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2879: if (document.display.wafproxy_vpnaccess[i].checked) {
2880: if (document.display.wafproxy_vpnaccess[i].value == 0) {
2881: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2882: }
2883: }
2884: }
2885: }
2886: }
2887: }
2888: return;
2889: }
2890:
2891: function checkWAF() {
2892: if (document.getElementById('wafproxy_remoteip')) {
2893: var wafvpn = 0;
2894: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2895: if (document.display.wafproxy_vpnaccess[i].checked) {
2896: if (document.display.wafproxy_vpnaccess[i].value == 1) {
2897: wafvpn = 1;
2898: }
2899: break;
2900: }
2901: }
2902: var vpn = new Array('vpnint','vpnext');
2903: for (var i=0; i<vpn.length; i++) {
2904: if (document.getElementById('wafproxy_show_'+vpn[i])) {
2905: if (wafvpn == 1) {
2906: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
2907: }
2908: else {
2909: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
2910: }
2911: }
2912: }
2913: if (document.getElementById('wafproxyranges_$dom')) {
2914: if (wafvpn == 1) {
2915: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2916: }
2917: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
2918: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2919: }
2920: }
2921: }
2922: return;
2923: }
2924:
2925: function toggleWAF() {
2926: if (document.getElementById('wafproxy_table')) {
2927: var wafproxy = 0;
2928: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
2929: if (document.display.wafproxy_${dom}[i].checked) {
2930: if (document.display.wafproxy_${dom}[i].value == 1) {
2931: wafproxy = 1;
2932: break;
2933: }
2934: }
2935: }
2936: if (wafproxy == 1) {
2937: document.getElementById('wafproxy_table').style.display='inline';
2938: }
2939: else {
2940: document.getElementById('wafproxy_table').style.display='none';
2941: }
2942: if (document.getElementById('wafproxyrow_${dom}')) {
2943: if (wafproxy == 1) {
2944: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
2945: }
2946: else {
2947: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
2948: }
2949: }
2950: if (document.getElementById('nowafproxyrow_$dom')) {
2951: if (wafproxy == 1) {
2952: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
2953: }
2954: else {
2955: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
2956: }
2957: }
2958: }
2959: return;
2960: }
2961: // ]]>
2962: </script>
2963:
2964: ENDSCRIPT
2965: }
2966:
2967: sub autoupdate_javascript {
2968: return <<"ENDSCRIPT";
2969: <script type="text/javascript">
2970: // <![CDATA[
2971: function toggleLastActiveDays(form) {
2972: var radioname = 'lastactive';
2973: var divid = 'lastactive_div';
2974: var num = form.elements[radioname].length;
2975: if (num) {
2976: var setvis = '';
2977: for (var i=0; i<num; i++) {
2978: if (form.elements[radioname][i].checked) {
2979: if (form.elements[radioname][i].value == '1') {
2980: if (document.getElementById(divid)) {
2981: document.getElementById(divid).style.display = 'inline-block';
2982: }
2983: setvis = 1;
2984: }
2985: break;
2986: }
2987: }
2988: if (!setvis) {
2989: if (document.getElementById(divid)) {
2990: document.getElementById(divid).style.display = 'none';
2991: }
2992: }
2993: }
2994: return;
2995: }
2996: // ]]>
2997: </script>
2998:
2999: ENDSCRIPT
3000: }
3001:
1.160.6.116 raeburn 3002: sub autoenroll_javascript {
3003: return <<"ENDSCRIPT";
3004: <script type="text/javascript">
3005: // <![CDATA[
3006: function toggleFailsafe(form) {
3007: var radioname = 'autoenroll_failsafe';
3008: var divid = 'autoenroll_failsafe_div';
3009: var num = form.elements[radioname].length;
3010: if (num) {
3011: var setvis = '';
3012: for (var i=0; i<num; i++) {
3013: if (form.elements[radioname][i].checked) {
3014: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3015: if (document.getElementById(divid)) {
3016: document.getElementById(divid).style.display = 'inline-block';
3017: }
3018: setvis = 1;
3019: }
3020: break;
3021: }
3022: }
3023: if (!setvis) {
3024: if (document.getElementById(divid)) {
3025: document.getElementById(divid).style.display = 'none';
3026: }
3027: }
3028: }
3029: return;
3030: }
3031: // ]]>
3032: </script>
3033:
3034: ENDSCRIPT
3035: }
3036:
1.160.6.113 raeburn 3037: sub saml_javascript {
3038: return <<"ENDSCRIPT";
3039: <script type="text/javascript">
3040: // <![CDATA[
3041: function toggleSamlOptions(form,hostid) {
3042: var radioname = 'saml_'+hostid;
3043: var tablecellon = 'samloptionson_'+hostid;
3044: var tablecelloff = 'samloptionsoff_'+hostid;
3045: var num = form.elements[radioname].length;
3046: if (num) {
3047: var setvis = '';
3048: for (var i=0; i<num; i++) {
3049: if (form.elements[radioname][i].checked) {
3050: if (form.elements[radioname][i].value == '1') {
3051: if (document.getElementById(tablecellon)) {
3052: document.getElementById(tablecellon).style.display='';
3053: }
3054: if (document.getElementById(tablecelloff)) {
3055: document.getElementById(tablecelloff).style.display='none';
3056: }
3057: setvis = 1;
3058: }
3059: break;
3060: }
3061: }
3062: if (!setvis) {
3063: if (document.getElementById(tablecellon)) {
3064: document.getElementById(tablecellon).style.display='none';
3065: }
3066: if (document.getElementById(tablecelloff)) {
3067: document.getElementById(tablecelloff).style.display='';
3068: }
3069: }
3070: }
3071: return;
3072: }
3073: // ]]>
3074: </script>
3075:
3076: ENDSCRIPT
3077: }
3078:
3079: sub ipaccess_javascript {
3080: my ($settings) = @_;
3081: my (%ordered,$total,%jstext);
3082: $total = 0;
3083: if (ref($settings) eq 'HASH') {
3084: foreach my $item (keys(%{$settings})) {
3085: if (ref($settings->{$item}) eq 'HASH') {
3086: my $num = $settings->{$item}{'order'};
3087: $ordered{$num} = $item;
3088: }
3089: }
3090: $total = scalar(keys(%{$settings}));
3091: }
3092: my @jsarray = ();
3093: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3094: push(@jsarray,$ordered{$item});
3095: }
3096: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3097: return <<"ENDSCRIPT";
3098: <script type="text/javascript">
3099: // <![CDATA[
3100: function reorderIPaccess(form,item) {
3101: var changedVal;
3102: $jstext
3103: var newpos = 'ipaccess_pos_add';
3104: var maxh = 1 + $total;
3105: var current = new Array;
3106: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3107: if (item == newpos) {
3108: changedVal = newitemVal;
3109: } else {
3110: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3111: current[newitemVal] = newpos;
3112: }
3113: for (var i=0; i<ipaccess.length; i++) {
3114: var elementName = 'ipaccess_pos_'+ipaccess[i];
3115: if (elementName != item) {
3116: if (form.elements[elementName]) {
3117: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3118: current[currVal] = elementName;
3119: }
3120: }
3121: }
3122: var oldVal;
3123: for (var j=0; j<maxh; j++) {
3124: if (current[j] == undefined) {
3125: oldVal = j;
3126: }
3127: }
3128: if (oldVal < changedVal) {
3129: for (var k=oldVal+1; k<=changedVal ; k++) {
3130: var elementName = current[k];
3131: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3132: }
3133: } else {
3134: for (var k=changedVal; k<oldVal; k++) {
3135: var elementName = current[k];
3136: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3137: }
3138: }
3139: return;
3140: }
3141: // ]]>
3142: </script>
3143:
3144: ENDSCRIPT
3145: }
3146:
1.3 raeburn 3147: sub print_autoenroll {
1.30 raeburn 3148: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3149: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3150: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3151: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3152: $failsafesty = 'none';
3153: %failsafechecked = (
3154: off => ' checked="checked"',
3155: );
1.3 raeburn 3156: if (ref($settings) eq 'HASH') {
3157: if (exists($settings->{'run'})) {
3158: if ($settings->{'run'} eq '0') {
3159: $runoff = ' checked="checked" ';
3160: $runon = ' ';
3161: } else {
3162: $runon = ' checked="checked" ';
3163: $runoff = ' ';
3164: }
3165: } else {
3166: if ($autorun) {
3167: $runon = ' checked="checked" ';
3168: $runoff = ' ';
3169: } else {
3170: $runoff = ' checked="checked" ';
3171: $runon = ' ';
3172: }
3173: }
1.129 raeburn 3174: if (exists($settings->{'co-owners'})) {
3175: if ($settings->{'co-owners'} eq '0') {
3176: $coownersoff = ' checked="checked" ';
3177: $coownerson = ' ';
3178: } else {
3179: $coownerson = ' checked="checked" ';
3180: $coownersoff = ' ';
3181: }
3182: } else {
3183: $coownersoff = ' checked="checked" ';
3184: $coownerson = ' ';
3185: }
1.3 raeburn 3186: if (exists($settings->{'sender_domain'})) {
3187: $defdom = $settings->{'sender_domain'};
3188: }
1.160.6.116 raeburn 3189: if (exists($settings->{'failsafe'})) {
3190: $failsafe = $settings->{'failsafe'};
3191: if ($failsafe eq 'zero') {
3192: $failsafechecked{'zero'} = ' checked="checked"';
3193: $failsafechecked{'off'} = '';
3194: $failsafesty = 'inline-block';
3195: } elsif ($failsafe eq 'any') {
3196: $failsafechecked{'any'} = ' checked="checked"';
3197: $failsafechecked{'off'} = '';
3198: }
3199: $autofailsafe = $settings->{'autofailsafe'};
3200: } elsif (exists($settings->{'autofailsafe'})) {
3201: $autofailsafe = $settings->{'autofailsafe'};
3202: if ($autofailsafe ne '') {
3203: $failsafechecked{'zero'} = ' checked="checked"';
3204: $failsafe = 'zero';
3205: $failsafechecked{'off'} = '';
3206: }
1.160.6.68 raeburn 3207: }
1.14 raeburn 3208: } else {
3209: if ($autorun) {
3210: $runon = ' checked="checked" ';
3211: $runoff = ' ';
3212: } else {
3213: $runoff = ' checked="checked" ';
3214: $runon = ' ';
3215: }
1.3 raeburn 3216: }
3217: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3218: my $notif_sender;
3219: if (ref($settings) eq 'HASH') {
3220: $notif_sender = $settings->{'sender_uname'};
3221: }
1.3 raeburn 3222: my $datatable='<tr class="LC_odd_row">'.
3223: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3224: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3225: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3226: $runon.' value="1" />'.&mt('Yes').'</label> '.
3227: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3228: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3229: '</tr><tr>'.
3230: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3231: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3232: &mt('username').': '.
3233: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3234: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3235: ': '.$domform.'</span></td></tr>'.
3236: '<tr class="LC_odd_row">'.
3237: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3238: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3239: '<input type="radio" name="autoassign_coowners"'.
3240: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3241: '<label><input type="radio" name="autoassign_coowners"'.
3242: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3243: '</tr><tr>'.
3244: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3245: '<td class="LC_left_item"><span class="LC_nobreak">'.
3246: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
3247: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
3248: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
3249: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3250: '<span class="LC_nobreak">'.
3251: &mt('Threshold for number of students in section to drop: [_1]',
3252: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3253: '</span></div></td></tr>';
1.160.6.68 raeburn 3254: $$rowtotal += 4;
1.3 raeburn 3255: return $datatable;
3256: }
3257:
3258: sub print_autoupdate {
1.30 raeburn 3259: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3260: my ($enable,$datatable);
1.3 raeburn 3261: if ($position eq 'top') {
1.160.6.113 raeburn 3262: my %choices = &Apache::lonlocal::texthash (
3263: run => 'Auto-update active?',
3264: classlists => 'Update information in classlists?',
3265: unexpired => 'Skip updates for users without active or future roles?',
3266: lastactive => 'Skip updates for inactive users?',
3267: );
3268: my $itemcount = 0;
1.3 raeburn 3269: my $updateon = ' ';
3270: my $updateoff = ' checked="checked" ';
3271: if (ref($settings) eq 'HASH') {
3272: if ($settings->{'run'} eq '1') {
3273: $updateon = $updateoff;
3274: $updateoff = ' ';
3275: }
3276: }
1.160.6.113 raeburn 3277: $enable = '<tr class="LC_odd_row">'.
3278: '<td>'.&mt($choices{'run'}).'</td>'.
3279: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3280: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3281: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3282: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3283: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3284: '</tr>';
1.160.6.113 raeburn 3285: my @toggles = ('classlists','unexpired');
3286: my %defaultchecked = ('classlists' => 'off',
3287: 'unexpired' => 'off'
3288: );
3289: $$rowtotal ++;
3290: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3291: \%choices,$itemcount,'','','left','no');
3292: $datatable = $enable.$datatable;
3293: $$rowtotal += $itemcount;
3294: my $lastactiveon = ' ';
3295: my $lastactiveoff = ' checked="checked" ';
3296: my $lastactivestyle = 'none';
3297: my $lastactivedays;
3298: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3299: if (ref($settings) eq 'HASH') {
3300: if ($settings->{'lastactive'} =~ /^\d+$/) {
3301: $lastactiveon = $lastactiveoff;
3302: $lastactiveoff = ' ';
3303: $lastactivestyle = 'inline-block';
3304: $lastactivedays = $settings->{'lastactive'};
3305: }
3306: }
3307: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3308: $datatable .= '<tr'.$css_class.'>'.
3309: '<td>'.$choices{'lastactive'}.'</td>'.
3310: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3311: '<input type="radio" name="lastactive"'.
3312: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3313: ' <label>'.
3314: '<input type="radio" name="lastactive"'.
3315: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3316: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3317: ': '.&mt('inactive = no activity in last [_1] days',
3318: '<input type="text" size="5" name="lastactivedays" value="'.
3319: $lastactivedays.'" />').
3320: '</span></td>'.
3321: '</tr>';
3322: $$rowtotal ++;
1.131 raeburn 3323: } elsif ($position eq 'middle') {
3324: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3325: my $numinrow = 3;
3326: my $locknamesettings;
3327: $datatable .= &insttypes_row($settings,$types,$usertypes,
3328: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3329: 'lockablenames',$rowtotal);
1.131 raeburn 3330: $$rowtotal ++;
1.3 raeburn 3331: } else {
1.44 raeburn 3332: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3333: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3334: 'permanentemail','id');
1.33 raeburn 3335: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3336: my $numrows = 0;
1.26 raeburn 3337: if (ref($types) eq 'ARRAY') {
3338: if (@{$types} > 0) {
3339: $datatable =
3340: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3341: \@fields,$types,\$numrows);
1.30 raeburn 3342: $$rowtotal += @{$types};
1.26 raeburn 3343: }
1.3 raeburn 3344: }
3345: $datatable .=
3346: &usertype_update_row($settings,{'default' => $othertitle},
3347: \%fieldtitles,\@fields,['default'],
3348: \$numrows);
1.30 raeburn 3349: $$rowtotal ++;
1.3 raeburn 3350: }
3351: return $datatable;
3352: }
3353:
1.125 raeburn 3354: sub print_autocreate {
3355: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3356: my (%createon,%createoff,%currhash);
1.125 raeburn 3357: my @types = ('xml','req');
3358: if (ref($settings) eq 'HASH') {
3359: foreach my $item (@types) {
3360: $createoff{$item} = ' checked="checked" ';
3361: $createon{$item} = ' ';
3362: if (exists($settings->{$item})) {
3363: if ($settings->{$item}) {
3364: $createon{$item} = ' checked="checked" ';
3365: $createoff{$item} = ' ';
3366: }
3367: }
3368: }
1.160.6.16 raeburn 3369: if ($settings->{'xmldc'} ne '') {
3370: $currhash{$settings->{'xmldc'}} = 1;
3371: }
1.125 raeburn 3372: } else {
3373: foreach my $item (@types) {
3374: $createoff{$item} = ' checked="checked" ';
3375: $createon{$item} = ' ';
3376: }
3377: }
3378: $$rowtotal += 2;
1.160.6.16 raeburn 3379: my $numinrow = 2;
1.125 raeburn 3380: my $datatable='<tr class="LC_odd_row">'.
3381: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3382: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3383: '<input type="radio" name="autocreate_xml"'.
3384: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3385: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3386: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3387: '</td></tr><tr>'.
3388: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3389: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3390: '<input type="radio" name="autocreate_req"'.
3391: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3392: '<label><input type="radio" name="autocreate_req"'.
3393: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3394: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3395: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3396: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3397: if ($numdc > 1) {
1.160.6.50 raeburn 3398: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3399: '</td><td class="LC_left_item">';
1.125 raeburn 3400: } else {
1.160.6.50 raeburn 3401: $datatable .= &mt('Course creation processed as:').
3402: '</td><td class="LC_right_item">';
1.125 raeburn 3403: }
1.160.6.50 raeburn 3404: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3405: $$rowtotal += $rows;
1.125 raeburn 3406: return $datatable;
3407: }
3408:
1.23 raeburn 3409: sub print_directorysrch {
1.160.6.72 raeburn 3410: my ($position,$dom,$settings,$rowtotal) = @_;
3411: my $datatable;
3412: if ($position eq 'top') {
3413: my $instsrchon = ' ';
3414: my $instsrchoff = ' checked="checked" ';
3415: my ($exacton,$containson,$beginson);
3416: my $instlocalon = ' ';
3417: my $instlocaloff = ' checked="checked" ';
3418: if (ref($settings) eq 'HASH') {
3419: if ($settings->{'available'} eq '1') {
3420: $instsrchon = $instsrchoff;
3421: $instsrchoff = ' ';
3422: }
3423: if ($settings->{'localonly'} eq '1') {
3424: $instlocalon = $instlocaloff;
3425: $instlocaloff = ' ';
3426: }
3427: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3428: foreach my $type (@{$settings->{'searchtypes'}}) {
3429: if ($type eq 'exact') {
3430: $exacton = ' checked="checked" ';
3431: } elsif ($type eq 'contains') {
3432: $containson = ' checked="checked" ';
3433: } elsif ($type eq 'begins') {
3434: $beginson = ' checked="checked" ';
3435: }
3436: }
3437: } else {
3438: if ($settings->{'searchtypes'} eq 'exact') {
3439: $exacton = ' checked="checked" ';
3440: } elsif ($settings->{'searchtypes'} eq 'contains') {
3441: $containson = ' checked="checked" ';
3442: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3443: $exacton = ' checked="checked" ';
3444: $containson = ' checked="checked" ';
3445: }
3446: }
1.23 raeburn 3447: }
1.160.6.72 raeburn 3448: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3449: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 3450:
1.160.6.72 raeburn 3451: my $numinrow = 4;
3452: my $cansrchrow = 0;
3453: $datatable='<tr class="LC_odd_row">'.
3454: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3455: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3456: '<input type="radio" name="dirsrch_available"'.
3457: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3458: '<label><input type="radio" name="dirsrch_available"'.
3459: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3460: '</tr><tr>'.
3461: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3462: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3463: '<input type="radio" name="dirsrch_instlocalonly"'.
3464: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3465: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3466: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3467: '</tr>';
3468: $$rowtotal += 2;
3469: if (ref($usertypes) eq 'HASH') {
3470: if (keys(%{$usertypes}) > 0) {
3471: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 3472: $numinrow,$othertitle,'cansearch',
3473: $rowtotal);
1.160.6.72 raeburn 3474: $cansrchrow = 1;
3475: }
1.26 raeburn 3476: }
1.160.6.72 raeburn 3477: if ($cansrchrow) {
3478: $$rowtotal ++;
3479: $datatable .= '<tr>';
3480: } else {
3481: $datatable .= '<tr class="LC_odd_row">';
3482: }
3483: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3484: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3485: foreach my $title (@{$titleorder}) {
3486: if (defined($searchtitles->{$title})) {
3487: my $check = ' ';
3488: if (ref($settings) eq 'HASH') {
3489: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3490: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3491: $check = ' checked="checked" ';
3492: }
1.39 raeburn 3493: }
1.25 raeburn 3494: }
1.160.6.72 raeburn 3495: $datatable .= '<td class="LC_left_item">'.
3496: '<span class="LC_nobreak"><label>'.
3497: '<input type="checkbox" name="searchby" '.
3498: 'value="'.$title.'"'.$check.'/>'.
3499: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3500: }
3501: }
1.160.6.72 raeburn 3502: $datatable .= '</tr></table></td></tr>';
3503: $$rowtotal ++;
3504: if ($cansrchrow) {
3505: $datatable .= '<tr class="LC_odd_row">';
3506: } else {
3507: $datatable .= '<tr>';
3508: }
3509: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3510: '<td class="LC_left_item" colspan="2">'.
3511: '<span class="LC_nobreak"><label>'.
3512: '<input type="checkbox" name="searchtypes" '.
3513: $exacton.' value="exact" />'.&mt('Exact match').
3514: '</label> '.
3515: '<label><input type="checkbox" name="searchtypes" '.
3516: $beginson.' value="begins" />'.&mt('Begins with').
3517: '</label> '.
3518: '<label><input type="checkbox" name="searchtypes" '.
3519: $containson.' value="contains" />'.&mt('Contains').
3520: '</label></span></td></tr>';
3521: $$rowtotal ++;
1.26 raeburn 3522: } else {
1.160.6.72 raeburn 3523: my $domsrchon = ' checked="checked" ';
3524: my $domsrchoff = ' ';
3525: my $domlocalon = ' ';
3526: my $domlocaloff = ' checked="checked" ';
3527: if (ref($settings) eq 'HASH') {
3528: if ($settings->{'lclocalonly'} eq '1') {
3529: $domlocalon = $domlocaloff;
3530: $domlocaloff = ' ';
3531: }
3532: if ($settings->{'lcavailable'} eq '0') {
3533: $domsrchoff = $domsrchon;
3534: $domsrchon = ' ';
3535: }
3536: }
3537: $datatable='<tr class="LC_odd_row">'.
3538: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3539: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3540: '<input type="radio" name="dirsrch_domavailable"'.
3541: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3542: '<label><input type="radio" name="dirsrch_domavailable"'.
3543: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3544: '</tr><tr>'.
3545: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3546: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3547: '<input type="radio" name="dirsrch_domlocalonly"'.
3548: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3549: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3550: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3551: '</tr>';
3552: $$rowtotal += 2;
1.26 raeburn 3553: }
1.25 raeburn 3554: return $datatable;
3555: }
3556:
1.28 raeburn 3557: sub print_contacts {
1.160.6.78 raeburn 3558: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3559: my $datatable;
3560: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3561: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 3562: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3563: if ($position eq 'top') {
3564: if (ref($settings) eq 'HASH') {
3565: foreach my $item (@contacts) {
3566: if (exists($settings->{$item})) {
3567: $to{$item} = $settings->{$item};
3568: }
1.28 raeburn 3569: }
3570: }
1.160.6.78 raeburn 3571: } elsif ($position eq 'middle') {
3572: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3573: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3574: foreach my $type (@mailings) {
1.160.6.78 raeburn 3575: $otheremails{$type} = '';
3576: }
1.160.6.107 raeburn 3577: } elsif ($position eq 'lower') {
3578: if (ref($settings) eq 'HASH') {
3579: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3580: %lonstatus = %{$settings->{'lonstatus'}};
3581: }
3582: }
1.160.6.78 raeburn 3583: } else {
3584: @mailings = ('helpdeskmail','otherdomsmail');
3585: foreach my $type (@mailings) {
3586: $otheremails{$type} = '';
3587: }
3588: $bccemails{'helpdeskmail'} = '';
3589: $bccemails{'otherdomsmail'} = '';
3590: $includestr{'helpdeskmail'} = '';
3591: $includestr{'otherdomsmail'} = '';
3592: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3593: }
3594: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 3595: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3596: foreach my $type (@mailings) {
3597: if (exists($settings->{$type})) {
3598: if (ref($settings->{$type}) eq 'HASH') {
3599: foreach my $item (@contacts) {
3600: if ($settings->{$type}{$item}) {
3601: $checked{$type}{$item} = ' checked="checked" ';
3602: }
1.28 raeburn 3603: }
1.160.6.78 raeburn 3604: $otheremails{$type} = $settings->{$type}{'others'};
3605: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3606: $bccemails{$type} = $settings->{$type}{'bcc'};
3607: if ($settings->{$type}{'include'} ne '') {
3608: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3609: $includestr{$type} = &unescape($includestr{$type});
3610: }
3611: }
3612: }
3613: } elsif ($type eq 'lonstatusmail') {
3614: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3615: }
3616: }
3617: }
3618: if ($position eq 'bottom') {
3619: foreach my $type (@mailings) {
3620: $bccemails{$type} = $settings->{$type}{'bcc'};
3621: if ($settings->{$type}{'include'} ne '') {
3622: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3623: $includestr{$type} = &unescape($includestr{$type});
3624: }
3625: }
3626: if (ref($settings->{'helpform'}) eq 'HASH') {
3627: if (ref($fields) eq 'ARRAY') {
3628: foreach my $field (@{$fields}) {
3629: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3630: }
1.160.6.78 raeburn 3631: }
3632: if (exists($settings->{'helpform'}{'maxsize'})) {
3633: $maxsize = $settings->{'helpform'}{'maxsize'};
3634: } else {
3635: $maxsize = '1.0';
3636: }
3637: } else {
3638: if (ref($fields) eq 'ARRAY') {
3639: foreach my $field (@{$fields}) {
3640: $currfield{$field} = 'yes';
1.134 raeburn 3641: }
1.28 raeburn 3642: }
1.160.6.78 raeburn 3643: $maxsize = '1.0';
1.28 raeburn 3644: }
3645: }
3646: } else {
1.160.6.78 raeburn 3647: if ($position eq 'top') {
3648: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3649: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3650: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3651: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3652: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3653: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3654: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3655: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3656: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3657: } elsif ($position eq 'bottom') {
3658: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3659: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3660: if (ref($fields) eq 'ARRAY') {
3661: foreach my $field (@{$fields}) {
3662: $currfield{$field} = 'yes';
3663: }
3664: }
3665: $maxsize = '1.0';
3666: }
1.28 raeburn 3667: }
3668: my ($titles,$short_titles) = &contact_titles();
3669: my $rownum = 0;
3670: my $css_class;
1.160.6.78 raeburn 3671: if ($position eq 'top') {
3672: foreach my $item (@contacts) {
3673: $css_class = $rownum%2?' class="LC_odd_row"':'';
3674: $datatable .= '<tr'.$css_class.'>'.
3675: '<td><span class="LC_nobreak">'.$titles->{$item}.
3676: '</span></td><td class="LC_right_item">'.
3677: '<input type="text" name="'.$item.'" value="'.
3678: $to{$item}.'" /></td></tr>';
3679: $rownum ++;
3680: }
1.160.6.101 raeburn 3681: } elsif ($position eq 'bottom') {
3682: $css_class = $rownum%2?' class="LC_odd_row"':'';
3683: $datatable .= '<tr'.$css_class.'>'.
3684: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3685: &mt('(e-mail, subject, and description always shown)').
3686: '</td><td class="LC_left_item">';
3687: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3688: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3689: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3690: foreach my $field (@{$fields}) {
3691: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3692: if (($field eq 'screenshot') || ($field eq 'cc')) {
3693: $datatable .= ' '.&mt('(logged-in users)');
3694: }
3695: $datatable .='</td><td>';
3696: my $clickaction;
3697: if ($field eq 'screenshot') {
3698: $clickaction = ' onclick="screenshotSize(this);"';
3699: }
3700: if (ref($possoptions->{$field}) eq 'ARRAY') {
3701: foreach my $option (@{$possoptions->{$field}}) {
3702: my $checked;
3703: if ($currfield{$field} eq $option) {
3704: $checked = ' checked="checked"';
3705: }
3706: $datatable .= '<span class="LC_nobreak"><label>'.
3707: '<input type="radio" name="helpform_'.$field.'" '.
3708: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3709: '</label></span>'.(' 'x2);
3710: }
3711: }
3712: if ($field eq 'screenshot') {
3713: my $display;
3714: if ($currfield{$field} eq 'no') {
3715: $display = ' style="display:none"';
3716: }
3717: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3718: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3719: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3720: }
3721: $datatable .= '</td></tr>';
3722: }
3723: $datatable .= '</table>';
3724: }
3725: $datatable .= '</td></tr>'."\n";
3726: $rownum ++;
3727: }
1.160.6.107 raeburn 3728: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3729: foreach my $type (@mailings) {
3730: $css_class = $rownum%2?' class="LC_odd_row"':'';
3731: $datatable .= '<tr'.$css_class.'>'.
3732: '<td><span class="LC_nobreak">'.
3733: $titles->{$type}.': </span></td>'.
3734: '<td class="LC_left_item">';
3735: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3736: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3737: }
3738: $datatable .= '<span class="LC_nobreak">';
3739: foreach my $item (@contacts) {
3740: $datatable .= '<label>'.
3741: '<input type="checkbox" name="'.$type.'"'.
3742: $checked{$type}{$item}.
3743: ' value="'.$item.'" />'.$short_titles->{$item}.
3744: '</label> ';
3745: }
3746: $datatable .= '</span><br />'.&mt('Others').': '.
3747: '<input type="text" name="'.$type.'_others" '.
3748: 'value="'.$otheremails{$type}.'" />';
3749: my %locchecked;
3750: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3751: foreach my $loc ('s','b') {
3752: if ($includeloc{$type} eq $loc) {
3753: $locchecked{$loc} = ' checked="checked"';
3754: last;
3755: }
3756: }
3757: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3758: '<input type="text" name="'.$type.'_bcc" '.
3759: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3760: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3761: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3762: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3763: '<span class="LC_nobreak">'.&mt('Location:').' '.
3764: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3765: (' 'x2).
3766: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3767: '</span></fieldset>';
3768: }
3769: $datatable .= '</td></tr>'."\n";
3770: $rownum ++;
3771: }
1.28 raeburn 3772: }
1.160.6.78 raeburn 3773: if ($position eq 'middle') {
3774: my %choices;
1.160.6.107 raeburn 3775: my $corelink = &core_link_msu();
3776: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 3777: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 3778: $corelink);
3779: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3780: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 3781: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 3782: 'reportupdates' => 'on',
3783: 'reportstatus' => 'on');
1.160.6.78 raeburn 3784: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3785: \%choices,$rownum);
3786: $datatable .= $reports;
1.160.6.107 raeburn 3787: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 3788: my (%current,%excluded,%weights);
1.160.6.107 raeburn 3789: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3790: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 3791: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 3792: } else {
1.160.6.109 raeburn 3793: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 3794: }
3795: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 3796: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 3797: } else {
1.160.6.109 raeburn 3798: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 3799: }
3800: if (ref($lonstatus{'weights'}) eq 'HASH') {
3801: foreach my $type ('E','W','N','U') {
3802: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3803: $weights{$type} = $lonstatus{'weights'}{$type};
3804: } else {
3805: $weights{$type} = $defaults->{$type};
3806: }
3807: }
3808: } else {
3809: foreach my $type ('E','W','N','U') {
3810: $weights{$type} = $defaults->{$type};
3811: }
3812: }
3813: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3814: if (@{$lonstatus{'excluded'}} > 0) {
3815: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3816: }
3817: }
1.160.6.109 raeburn 3818: foreach my $item ('errorthreshold','errorsysmail') {
3819: $css_class = $rownum%2?' class="LC_odd_row"':'';
3820: $datatable .= '<tr'.$css_class.'>'.
3821: '<td class="LC_left_item"><span class="LC_nobreak">'.
3822: $titles->{$item}.
3823: '</span></td><td class="LC_left_item">'.
3824: '<input type="text" name="'.$item.'" value="'.
3825: $current{$item}.'" size="5" /></td></tr>';
3826: $rownum ++;
3827: }
1.160.6.107 raeburn 3828: $css_class = $rownum%2?' class="LC_odd_row"':'';
3829: $datatable .= '<tr'.$css_class.'>'.
3830: '<td class="LC_left_item">'.
3831: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3832: '</span></td><td class="LC_left_item"><table><tr>';
3833: foreach my $type ('E','W','N','U') {
3834: $datatable .= '<td>'.$names->{$type}.'<br />'.
3835: '<input type="text" name="errorweights_'.$type.'" value="'.
3836: $weights{$type}.'" size="5" /></td>';
3837: }
3838: $datatable .= '</tr></table></tr>';
3839: $rownum ++;
3840: $css_class = $rownum%2?' class="LC_odd_row"':'';
3841: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3842: $titles->{'errorexcluded'}.'</td>'.
3843: '<td class="LC_left_item"><table>';
3844: my $numinrow = 4;
3845: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3846: for (my $i=0; $i<@ids; $i++) {
3847: my $rem = $i%($numinrow);
3848: if ($rem == 0) {
3849: if ($i > 0) {
3850: $datatable .= '</tr>';
3851: }
3852: $datatable .= '<tr>';
3853: }
3854: my $check;
3855: if ($excluded{$ids[$i]}) {
3856: $check = ' checked="checked" ';
3857: }
3858: $datatable .= '<td class="LC_left_item">'.
3859: '<span class="LC_nobreak"><label>'.
3860: '<input type="checkbox" name="errorexcluded" '.
3861: 'value="'.$ids[$i].'"'.$check.' />'.
3862: $ids[$i].'</label></span></td>';
3863: }
3864: my $colsleft = $numinrow - @ids%($numinrow);
3865: if ($colsleft > 1 ) {
3866: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3867: ' </td>';
3868: } elsif ($colsleft == 1) {
3869: $datatable .= '<td class="LC_left_item"> </td>';
3870: }
3871: $datatable .= '</tr></table></td></tr>';
3872: $rownum ++;
1.160.6.78 raeburn 3873: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 3874: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3875: my (@posstypes,%usertypeshash);
3876: if (ref($types) eq 'ARRAY') {
3877: @posstypes = @{$types};
3878: }
3879: if (@posstypes) {
3880: if (ref($usertypes) eq 'HASH') {
3881: %usertypeshash = %{$usertypes};
3882: }
3883: my @overridden;
3884: my $numinrow = 4;
3885: if (ref($settings) eq 'HASH') {
3886: if (ref($settings->{'overrides'}) eq 'HASH') {
3887: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3888: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3889: push(@overridden,$key);
3890: foreach my $item (@contacts) {
3891: if ($settings->{'overrides'}{$key}{$item}) {
3892: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3893: }
3894: }
3895: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3896: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3897: $includeloc{'override_'.$key} = '';
3898: $includestr{'override_'.$key} = '';
3899: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3900: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3901: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3902: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3903: }
1.160.6.78 raeburn 3904: }
3905: }
3906: }
1.160.6.101 raeburn 3907: }
3908: my $customclass = 'LC_helpdesk_override';
3909: my $optionsprefix = 'LC_options_helpdesk_';
3910:
3911: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3912:
3913: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3914: $numinrow,$othertitle,'overrides',
3915: \$rownum,$onclicktypes,$customclass);
3916: $rownum ++;
3917: $usertypeshash{'default'} = $othertitle;
3918: foreach my $status (@posstypes) {
3919: my $css_class;
3920: if ($rownum%2) {
3921: $css_class = 'LC_odd_row ';
3922: }
3923: $css_class .= $customclass;
3924: my $rowid = $optionsprefix.$status;
3925: my $hidden = 1;
3926: my $currstyle = 'display:none';
3927: if (grep(/^\Q$status\E$/,@overridden)) {
3928: $currstyle = 'display:table-row';
3929: $hidden = 0;
3930: }
3931: my $key = 'override_'.$status;
3932: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3933: $includeloc{$key},$includestr{$key},$status,$rowid,
3934: $usertypeshash{$status},$css_class,$currstyle,
3935: \@contacts,$short_titles);
3936: unless ($hidden) {
3937: $rownum ++;
1.160.6.78 raeburn 3938: }
3939: }
1.134 raeburn 3940: }
1.28 raeburn 3941: }
1.30 raeburn 3942: $$rowtotal += $rownum;
1.28 raeburn 3943: return $datatable;
3944: }
3945:
1.160.6.107 raeburn 3946: sub core_link_msu {
3947: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3948: &mt('LON-CAPA core group - MSU'),600,500);
3949: }
3950:
1.160.6.101 raeburn 3951: sub overridden_helpdesk {
3952: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3953: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3954: my $class = 'LC_left_item';
3955: if ($css_class) {
3956: $css_class = ' class="'.$css_class.'"';
3957: }
3958: if ($rowid) {
3959: $rowid = ' id="'.$rowid.'"';
3960: }
3961: if ($rowstyle) {
3962: $rowstyle = ' style="'.$rowstyle.'"';
3963: }
3964: my ($output,$description);
3965: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3966: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3967: "<td>$description</td>\n".
3968: '<td class="'.$class.'" colspan="2">'.
3969: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3970: '<span class="LC_nobreak">';
3971: if (ref($contacts) eq 'ARRAY') {
3972: foreach my $item (@{$contacts}) {
3973: my $check;
3974: if (ref($checked) eq 'HASH') {
3975: $check = $checked->{$item};
3976: }
3977: my $title;
3978: if (ref($short_titles) eq 'HASH') {
3979: $title = $short_titles->{$item};
3980: }
3981: $output .= '<label>'.
3982: '<input type="checkbox" name="override_'.$type.'"'.$check.
3983: ' value="'.$item.'" />'.$title.'</label> ';
3984: }
3985: }
3986: $output .= '</span><br />'.&mt('Others').': '.
3987: '<input type="text" name="override_'.$type.'_others" '.
3988: 'value="'.$otheremails.'" />';
3989: my %locchecked;
3990: foreach my $loc ('s','b') {
3991: if ($includeloc eq $loc) {
3992: $locchecked{$loc} = ' checked="checked"';
3993: last;
3994: }
3995: }
3996: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3997: '<input type="text" name="override_'.$type.'_bcc" '.
3998: 'value="'.$bccemails.'" /></fieldset>'.
3999: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4000: &mt('Text automatically added to e-mail:').' '.
4001: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4002: '<span class="LC_nobreak">'.&mt('Location:').' '.
4003: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4004: (' 'x2).
4005: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4006: '</span></fieldset>'.
4007: '</td></tr>'."\n";
4008: return $output;
4009: }
4010:
1.160.6.78 raeburn 4011: sub contacts_javascript {
4012: return <<"ENDSCRIPT";
4013:
4014: <script type="text/javascript">
4015: // <![CDATA[
4016:
4017: function screenshotSize(field) {
4018: if (document.getElementById('help_screenshotsize')) {
4019: if (field.value == 'no') {
4020: document.getElementById('help_screenshotsize').style.display="none";
4021: } else {
4022: document.getElementById('help_screenshotsize').style.display="";
4023: }
4024: }
4025: return;
4026: }
4027:
1.160.6.101 raeburn 4028: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4029: if (form.elements[checkbox].length != undefined) {
4030: var count = 0;
4031: if (docount) {
4032: for (var i=0; i<form.elements[checkbox].length; i++) {
4033: if (form.elements[checkbox][i].checked) {
4034: count ++;
4035: }
4036: }
4037: }
4038: for (var i=0; i<form.elements[checkbox].length; i++) {
4039: var type = form.elements[checkbox][i].value;
4040: if (document.getElementById(prefix+type)) {
4041: if (form.elements[checkbox][i].checked) {
4042: document.getElementById(prefix+type).style.display = 'table-row';
4043: if (count % 2 == 1) {
4044: document.getElementById(prefix+type).className = target+' LC_odd_row';
4045: } else {
4046: document.getElementById(prefix+type).className = target;
4047: }
4048: count ++;
4049: } else {
4050: document.getElementById(prefix+type).style.display = 'none';
4051: }
4052: }
4053: }
4054: }
4055: return;
4056: }
4057:
1.160.6.78 raeburn 4058: // ]]>
4059: </script>
4060:
4061: ENDSCRIPT
4062: }
4063:
1.118 jms 4064: sub print_helpsettings {
1.160.6.73 raeburn 4065: my ($position,$dom,$settings,$rowtotal) = @_;
4066: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4067: my $formname = 'display';
1.160.6.5 raeburn 4068: my ($datatable,$itemcount);
1.160.6.73 raeburn 4069: if ($position eq 'top') {
4070: $itemcount = 1;
4071: my (%choices,%defaultchecked,@toggles);
4072: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4073: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4074: &mt('LON-CAPA bug tracker'),600,500));
4075: %defaultchecked = ('submitbugs' => 'on');
4076: @toggles = ('submitbugs');
4077: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4078: \%choices,$itemcount);
4079: $$rowtotal ++;
4080: } else {
4081: my $css_class;
4082: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4083: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4084: if (ref($settings) eq 'HASH') {
4085: if (ref($settings->{'adhoc'}) eq 'HASH') {
4086: %current = %{$settings->{'adhoc'}};
4087: }
1.160.6.77 raeburn 4088: }
4089: my $count = 0;
4090: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4091: if ($key=~/^rolesdef\_(\w+)$/) {
4092: my $rolename = $1;
1.160.6.77 raeburn 4093: my (%privs,$order);
1.160.6.73 raeburn 4094: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4095: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4096: if (ref($current{$rolename}) eq 'HASH') {
4097: $order = $current{$rolename}{'order'};
4098: }
4099: if ($order eq '') {
4100: $order = $count;
4101: }
4102: $ordered{$order} = $rolename;
4103: $count++;
1.160.6.73 raeburn 4104: }
4105: }
1.160.6.77 raeburn 4106: my $maxnum = scalar(keys(%ordered));
4107: my @roles_by_num = ();
4108: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4109: push(@roles_by_num,$item);
4110: }
4111: my $context = 'domprefs';
4112: my $crstype = 'Course';
4113: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4114: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4115: my ($numstatustypes,@jsarray);
4116: if (ref($types) eq 'ARRAY') {
4117: if (@{$types} > 0) {
4118: $numstatustypes = scalar(@{$types});
4119: push(@accesstypes,'status');
4120: @jsarray = ('bystatus');
4121: }
4122: }
1.160.6.86 raeburn 4123: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4124: if (keys(%domhelpdesk)) {
4125: push(@accesstypes,('inc','exc'));
4126: push(@jsarray,('notinc','notexc'));
4127: }
4128: my $hiddenstr = join("','",@jsarray);
4129: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 4130: my $context = 'domprefs';
4131: my $crstype = 'Course';
1.160.6.77 raeburn 4132: my $prefix = 'helproles_';
4133: my $add_class = 'LC_hidden';
4134: foreach my $num (@roles_by_num) {
4135: my $role = $ordered{$num};
4136: my ($desc,$access,@statuses);
4137: if (ref($current{$role}) eq 'HASH') {
4138: $desc = $current{$role}{'desc'};
4139: $access = $current{$role}{'access'};
4140: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4141: @statuses = @{$current{$role}{'insttypes'}};
4142: }
4143: }
4144: if ($desc eq '') {
4145: $desc = $role;
4146: }
4147: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4148: my %full=();
4149: my %levels= (
4150: course => {},
4151: domain => {},
4152: system => {},
4153: );
4154: my %levelscurrent=(
4155: course => {},
4156: domain => {},
4157: system => {},
4158: );
4159: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4160: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4161: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4162: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4163: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4164: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4165: for (my $k=0; $k<=$maxnum; $k++) {
4166: my $vpos = $k+1;
4167: my $selstr;
4168: if ($k == $num) {
4169: $selstr = ' selected="selected" ';
4170: }
4171: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4172: }
4173: $datatable .= '</select>'.(' 'x2).
4174: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4175: '</td>'.
4176: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4177: &mt('Name shown to users:').
4178: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4179: '</fieldset>'.
4180: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4181: $othertitle,$usertypes,$types,\%domhelpdesk).
4182: '<fieldset>'.
4183: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4184: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4185: \%levelscurrent,$identifier,
4186: 'LC_hidden',$prefix.$num.'_privs').
4187: '</fieldset></td>';
1.160.6.73 raeburn 4188: $itemcount ++;
4189: }
4190: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4191: my $newcust = 'custhelp'.$count;
4192: my (%privs,%levelscurrent);
4193: my %full=();
4194: my %levels= (
4195: course => {},
4196: domain => {},
4197: system => {},
4198: );
4199: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4200: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4201: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4202: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4203: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4204: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4205: for (my $k=0; $k<$maxnum+1; $k++) {
4206: my $vpos = $k+1;
4207: my $selstr;
4208: if ($k == $maxnum) {
4209: $selstr = ' selected="selected" ';
4210: }
4211: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4212: }
4213: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4214: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4215: '</label></span></td>'.
1.160.6.77 raeburn 4216: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4217: '<span class="LC_nobreak">'.
4218: &mt('Internal name:').
4219: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4220: '</span>'.(' 'x4).
4221: '<span class="LC_nobreak">'.
4222: &mt('Name shown to users:').
4223: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4224: '</span></fieldset>'.
4225: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4226: $usertypes,$types,\%domhelpdesk).
4227: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4228: &Apache::lonuserutils::custom_role_header($context,$crstype,
4229: \@templateroles,$newcust).
4230: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4231: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4232: '</fieldset>'.
4233: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4234: '</td></tr>';
1.160.6.73 raeburn 4235: $count ++;
4236: $$rowtotal += $count;
4237: }
1.160.6.5 raeburn 4238: return $datatable;
1.121 raeburn 4239: }
4240:
1.160.6.77 raeburn 4241: sub adhocbutton {
4242: my ($prefix,$num,$field,$visibility) = @_;
4243: my %lt = &Apache::lonlocal::texthash(
4244: show => 'Show details',
4245: hide => 'Hide details',
4246: );
4247: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4248: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4249: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4250: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4251: }
4252:
4253: sub helpsettings_javascript {
4254: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4255: return unless(ref($roles_by_num) eq 'ARRAY');
4256: my %html_js_lt = &Apache::lonlocal::texthash(
4257: show => 'Show details',
4258: hide => 'Hide details',
4259: );
4260: &html_escape(\%html_js_lt);
4261: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4262: return <<"ENDSCRIPT";
4263: <script type="text/javascript">
4264: // <![CDATA[
4265:
4266: function reorderHelpRoles(form,item) {
4267: var changedVal;
4268: $jstext
4269: var newpos = 'helproles_${total}_pos';
4270: var maxh = 1 + $total;
4271: var current = new Array();
4272: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4273: if (item == newpos) {
4274: changedVal = newitemVal;
4275: } else {
4276: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4277: current[newitemVal] = newpos;
4278: }
4279: for (var i=0; i<helproles.length; i++) {
4280: var elementName = 'helproles_'+helproles[i]+'_pos';
4281: if (elementName != item) {
4282: if (form.elements[elementName]) {
4283: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4284: current[currVal] = elementName;
4285: }
4286: }
4287: }
4288: var oldVal;
4289: for (var j=0; j<maxh; j++) {
4290: if (current[j] == undefined) {
4291: oldVal = j;
4292: }
4293: }
4294: if (oldVal < changedVal) {
4295: for (var k=oldVal+1; k<=changedVal ; k++) {
4296: var elementName = current[k];
4297: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4298: }
4299: } else {
4300: for (var k=changedVal; k<oldVal; k++) {
4301: var elementName = current[k];
4302: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4303: }
4304: }
4305: return;
4306: }
4307:
4308: function helpdeskAccess(num) {
4309: var curraccess = null;
4310: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4311: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4312: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4313: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4314: }
4315: }
4316: }
4317: var shown = Array();
4318: var hidden = Array();
4319: if (curraccess == 'none') {
4320: hidden = Array('$hiddenstr');
4321: } else {
4322: if (curraccess == 'status') {
4323: shown = Array('bystatus');
4324: hidden = Array('notinc','notexc');
4325: } else {
4326: if (curraccess == 'exc') {
4327: shown = Array('notexc');
4328: hidden = Array('notinc','bystatus');
4329: }
4330: if (curraccess == 'inc') {
4331: shown = Array('notinc');
4332: hidden = Array('notexc','bystatus');
4333: }
1.160.6.79 raeburn 4334: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4335: hidden = Array('notinc','notexc','bystatus');
4336: }
4337: }
4338: }
4339: if (hidden.length > 0) {
4340: for (var i=0; i<hidden.length; i++) {
4341: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4342: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4343: }
4344: }
4345: }
4346: if (shown.length > 0) {
4347: for (var i=0; i<shown.length; i++) {
4348: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4349: if (shown[i] == 'privs') {
4350: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4351: } else {
4352: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4353: }
4354: }
4355: }
4356: }
4357: return;
4358: }
4359:
4360: function toggleHelpdeskItem(num,field) {
4361: if (document.getElementById('helproles_'+num+'_'+field)) {
4362: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4363: document.getElementById('helproles_'+num+'_'+field).className =
4364: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4365: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4366: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4367: }
4368: } else {
4369: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4370: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4371: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4372: }
4373: }
4374: }
4375: return;
4376: }
4377:
4378: // ]]>
4379: </script>
4380:
4381: ENDSCRIPT
4382: }
4383:
4384: sub helpdeskroles_access {
4385: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4386: $usertypes,$types,$domhelpdesk) = @_;
4387: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4388: my %lt = &Apache::lonlocal::texthash(
4389: 'rou' => 'Role usage',
4390: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4391: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4392: 'dh' => 'All with domain helpdesk role',
4393: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4394: 'none' => 'None',
4395: 'status' => 'Determined based on institutional status',
4396: 'inc' => 'Include all, but exclude specific personnel',
4397: 'exc' => 'Exclude all, but include specific personnel',
4398: );
4399: my %usecheck = (
4400: all => ' checked="checked"',
4401: );
4402: my %displaydiv = (
4403: status => 'none',
4404: inc => 'none',
4405: exc => 'none',
4406: priv => 'block',
4407: );
4408: my $output;
4409: if (ref($current) eq 'HASH') {
4410: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4411: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4412: $usecheck{$current->{access}} = $usecheck{'all'};
4413: delete($usecheck{'all'});
4414: if ($current->{access} =~ /^(status|inc|exc)$/) {
4415: my $access = $1;
4416: $displaydiv{$access} = 'inline';
4417: } elsif ($current->{access} eq 'none') {
4418: $displaydiv{'priv'} = 'none';
4419: }
4420: }
4421: }
4422: }
4423: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4424: '<p>'.$lt{'whi'}.'</p>';
4425: foreach my $access (@{$accesstypes}) {
4426: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4427: ' onclick="helpdeskAccess('."'$num'".');" />'.
4428: $lt{$access}.'</label>';
4429: if ($access eq 'status') {
4430: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4431: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4432: $othertitle,$usertypes,$types).
4433: '</div>';
4434: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4435: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4436: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4437: '</div>';
4438: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4439: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4440: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4441: '</div>';
4442: }
4443: $output .= '</p>';
4444: }
4445: $output .= '</fieldset>';
4446: return $output;
4447: }
4448:
1.121 raeburn 4449: sub radiobutton_prefs {
1.160.6.16 raeburn 4450: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 4451: $additional,$align,$firstval) = @_;
1.121 raeburn 4452: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4453: (ref($choices) eq 'HASH'));
4454:
4455: my (%checkedon,%checkedoff,$datatable,$css_class);
4456:
4457: foreach my $item (@{$toggles}) {
4458: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4459: $checkedon{$item} = ' checked="checked" ';
4460: $checkedoff{$item} = ' ';
1.121 raeburn 4461: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4462: $checkedoff{$item} = ' checked="checked" ';
4463: $checkedon{$item} = ' ';
4464: }
4465: }
4466: if (ref($settings) eq 'HASH') {
1.121 raeburn 4467: foreach my $item (@{$toggles}) {
1.118 jms 4468: if ($settings->{$item} eq '1') {
4469: $checkedon{$item} = ' checked="checked" ';
4470: $checkedoff{$item} = ' ';
4471: } elsif ($settings->{$item} eq '0') {
4472: $checkedoff{$item} = ' checked="checked" ';
4473: $checkedon{$item} = ' ';
4474: }
4475: }
1.121 raeburn 4476: }
1.160.6.16 raeburn 4477: if ($onclick) {
4478: $onclick = ' onclick="'.$onclick.'"';
4479: }
1.121 raeburn 4480: foreach my $item (@{$toggles}) {
1.118 jms 4481: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4482: $datatable .=
1.160.6.16 raeburn 4483: '<tr'.$css_class.'><td valign="top">'.
4484: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 4485: '</span></td>';
4486: if ($align eq 'left') {
4487: $datatable .= '<td class="LC_left_item">';
4488: } else {
4489: $datatable .= '<td class="LC_right_item">';
4490: }
1.160.6.113 raeburn 4491: $datatable .= '<span class="LC_nobreak">';
4492: if ($firstval eq 'no') {
4493: $datatable .=
4494: '<label><input type="radio" name="'.
4495: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4496: '</label> <label><input type="radio" name="'.$item.'" '.
4497: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4498: } else {
4499: $datatable .=
1.118 jms 4500: '<label><input type="radio" name="'.
1.160.6.16 raeburn 4501: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4502: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.113 raeburn 4503: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4504: }
4505: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4506: $itemcount ++;
1.121 raeburn 4507: }
4508: return ($datatable,$itemcount);
4509: }
4510:
4511: sub print_coursedefaults {
1.139 raeburn 4512: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4513: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4514: my $itemcount = 1;
1.160.6.16 raeburn 4515: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4516: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4517: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4518: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4519: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4520: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 4521: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 4522: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 4523: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4524: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4525: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4526: );
1.160.6.21 raeburn 4527: my %staticdefaults = (
4528: anonsurvey_threshold => 10,
4529: uploadquota => 500,
1.160.6.57 raeburn 4530: postsubmit => 60,
1.160.6.70 raeburn 4531: mysqltables => 172800,
1.160.6.21 raeburn 4532: );
1.139 raeburn 4533: if ($position eq 'top') {
1.160.6.57 raeburn 4534: %defaultchecked = (
4535: 'uselcmath' => 'on',
4536: 'usejsme' => 'on',
1.160.6.115 raeburn 4537: 'inline_chem' => 'on',
1.160.6.64 raeburn 4538: 'canclone' => 'none',
1.160.6.57 raeburn 4539: );
1.160.6.115 raeburn 4540: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 4541: my $deftex = $Apache::lonnet::deftex;
4542: if (ref($settings) eq 'HASH') {
4543: if ($settings->{'texengine'}) {
4544: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4545: $deftex = $settings->{'texengine'};
4546: }
4547: }
4548: }
4549: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4550: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4551: '<span class="LC_nobreak">'.$choices{'texengine'}.
4552: '</span></td><td class="LC_right_item">'.
4553: '<select name="texengine">'."\n";
4554: my %texoptions = (
4555: MathJax => 'MathJax',
4556: mimetex => &mt('Convert to Images'),
4557: tth => &mt('TeX to HTML'),
4558: );
4559: foreach my $renderer ('MathJax','mimetex','tth') {
4560: my $selected = '';
4561: if ($renderer eq $deftex) {
4562: $selected = ' selected="selected"';
4563: }
4564: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4565: }
4566: $mathdisp .= '</select></td></tr>'."\n";
4567: $itemcount ++;
1.139 raeburn 4568: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4569: \%choices,$itemcount);
1.160.6.90 raeburn 4570: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 4571: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4572: $datatable .=
4573: '<tr'.$css_class.'><td valign="top">'.
4574: '<span class="LC_nobreak">'.$choices{'canclone'}.
4575: '</span></td><td class="LC_left_item">';
4576: my $currcanclone = 'none';
4577: my $onclick;
4578: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 4579: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 4580: none => 'No additional course requesters',
4581: domain => "Any course requester in course's domain",
4582: instcode => 'Course requests for official courses ...',
4583: );
4584: my (%codedefaults,@code_order,@posscodes);
4585: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4586: \@code_order) eq 'ok') {
4587: if (@code_order > 0) {
4588: push(@cloneoptions,'instcode');
4589: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4590: }
4591: }
4592: if (ref($settings) eq 'HASH') {
4593: if ($settings->{'canclone'}) {
4594: if (ref($settings->{'canclone'}) eq 'HASH') {
4595: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4596: if (@code_order > 0) {
4597: $currcanclone = 'instcode';
4598: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4599: }
4600: }
4601: } elsif ($settings->{'canclone'} eq 'domain') {
4602: $currcanclone = $settings->{'canclone'};
4603: }
4604: }
4605: }
4606: foreach my $option (@cloneoptions) {
4607: my ($checked,$additional);
4608: if ($currcanclone eq $option) {
4609: $checked = ' checked="checked"';
4610: }
4611: if ($option eq 'instcode') {
4612: if (@code_order) {
4613: my $show = 'none';
4614: if ($checked) {
4615: $show = 'block';
4616: }
4617: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4618: &mt('Institutional codes for new and cloned course have identical:').
4619: '<br />';
4620: foreach my $item (@code_order) {
4621: my $codechk;
4622: if ($checked) {
4623: if (grep(/^\Q$item\E$/,@posscodes)) {
4624: $codechk = ' checked="checked"';
4625: }
4626: }
4627: $additional .= '<label>'.
4628: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4629: $item.'</label>';
4630: }
4631: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4632: }
4633: }
4634: $datatable .=
4635: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4636: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4637: '</label> '.$additional.'</span><br />';
4638: }
4639: $datatable .= '</td>'.
4640: '</tr>';
4641: $itemcount ++;
1.139 raeburn 4642: } else {
4643: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4644: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4645: my $currusecredits = 0;
1.160.6.57 raeburn 4646: my $postsubmitclient = 1;
1.160.6.30 raeburn 4647: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4648: if (ref($settings) eq 'HASH') {
4649: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4650: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4651: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4652: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4653: }
4654: }
1.160.6.16 raeburn 4655: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4656: foreach my $type (@types) {
4657: next if ($type eq 'community');
4658: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4659: if ($defcredits{$type} ne '') {
4660: $currusecredits = 1;
4661: }
4662: }
4663: }
4664: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4665: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4666: $postsubmitclient = 0;
4667: foreach my $type (@types) {
4668: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4669: }
4670: } else {
4671: foreach my $type (@types) {
4672: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4673: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4674: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4675: } else {
4676: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4677: }
4678: } else {
4679: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4680: }
4681: }
4682: }
4683: } else {
4684: foreach my $type (@types) {
4685: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4686: }
4687: }
1.160.6.70 raeburn 4688: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4689: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4690: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4691: }
4692: } else {
4693: foreach my $type (@types) {
4694: $currmysql{$type} = $staticdefaults{'mysqltables'};
4695: }
4696: }
1.160.6.58 raeburn 4697: } else {
4698: foreach my $type (@types) {
4699: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4700: }
1.139 raeburn 4701: }
4702: if (!$currdefresponder) {
1.160.6.21 raeburn 4703: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4704: } elsif ($currdefresponder < 1) {
4705: $currdefresponder = 1;
4706: }
1.160.6.21 raeburn 4707: foreach my $type (@types) {
4708: if ($curruploadquota{$type} eq '') {
4709: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4710: }
4711: }
1.139 raeburn 4712: $datatable .=
1.160.6.16 raeburn 4713: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4714: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4715: '</span></td>'.
4716: '<td class="LC_right_item"><span class="LC_nobreak">'.
4717: '<input type="text" name="anonsurvey_threshold"'.
4718: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4719: '</td></tr>'."\n";
4720: $itemcount ++;
4721: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4722: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4723: $choices{'uploadquota'}.
4724: '</span></td>'.
4725: '<td align="right" class="LC_right_item">'.
4726: '<table><tr>';
1.160.6.21 raeburn 4727: foreach my $type (@types) {
4728: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4729: '<input type="text" name="uploadquota_'.$type.'"'.
4730: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4731: }
4732: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4733: $itemcount ++;
1.160.6.40 raeburn 4734: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4735: my $display = 'none';
4736: if ($currusecredits) {
4737: $display = 'block';
4738: }
4739: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4740: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4741: foreach my $type (@types) {
4742: next if ($type eq 'community');
4743: $additional .= '<td align="center">'.&mt($type).'<br />'.
4744: '<input type="text" name="'.$type.'_credits"'.
4745: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4746: }
4747: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4748: %defaultchecked = ('coursecredits' => 'off');
4749: @toggles = ('coursecredits');
4750: my $current = {
4751: 'coursecredits' => $currusecredits,
4752: };
4753: (my $table,$itemcount) =
4754: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4755: \%choices,$itemcount,$onclick,$additional,'left');
4756: $datatable .= $table;
4757: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4758: my $display = 'none';
4759: if ($postsubmitclient) {
4760: $display = 'block';
4761: }
4762: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4763: &mt('Number of seconds submit is disabled').'<br />'.
4764: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4765: '<table><tr>';
1.160.6.57 raeburn 4766: foreach my $type (@types) {
4767: $additional .= '<td align="center">'.&mt($type).'<br />'.
4768: '<input type="text" name="'.$type.'_timeout" value="'.
4769: $deftimeout{$type}.'" size="5" /></td>';
4770: }
4771: $additional .= '</tr></table></div>'."\n";
4772: %defaultchecked = ('postsubmit' => 'on');
4773: @toggles = ('postsubmit');
1.160.6.70 raeburn 4774: $current = {
4775: 'postsubmit' => $postsubmitclient,
4776: };
1.160.6.57 raeburn 4777: ($table,$itemcount) =
4778: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4779: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4780: $datatable .= $table;
1.160.6.70 raeburn 4781: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4782: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4783: $choices{'mysqltables'}.
4784: '</span></td>'.
4785: '<td align="right" class="LC_right_item">'.
4786: '<table><tr>';
4787: foreach my $type (@types) {
4788: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4789: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4790: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4791: }
4792: $datatable .= '</tr></table></td></tr>'."\n";
4793: $itemcount ++;
4794:
1.160.6.37 raeburn 4795: }
4796: $$rowtotal += $itemcount;
4797: return $datatable;
4798: }
4799:
4800: sub print_selfenrollment {
4801: my ($position,$dom,$settings,$rowtotal) = @_;
4802: my ($css_class,$datatable);
4803: my $itemcount = 1;
4804: my @types = ('official','unofficial','community','textbook');
4805: if (($position eq 'top') || ($position eq 'middle')) {
4806: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4807: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4808: my @rows;
4809: my $key;
4810: if ($position eq 'top') {
4811: $key = 'admin';
4812: if (ref($rowsref) eq 'ARRAY') {
4813: @rows = @{$rowsref};
4814: }
4815: } elsif ($position eq 'middle') {
4816: $key = 'default';
4817: @rows = ('types','registered','approval','limit');
4818: }
4819: foreach my $row (@rows) {
4820: if (defined($titlesref->{$row})) {
4821: $itemcount ++;
4822: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4823: $datatable .= '<tr'.$css_class.'>'.
4824: '<td>'.$titlesref->{$row}.'</td>'.
4825: '<td class="LC_left_item">'.
4826: '<table><tr>';
4827: my (%current,%currentcap);
4828: if (ref($settings) eq 'HASH') {
4829: if (ref($settings->{$key}) eq 'HASH') {
4830: foreach my $type (@types) {
4831: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4832: $current{$type} = $settings->{$key}->{$type}->{$row};
4833: }
4834: if (($row eq 'limit') && ($key eq 'default')) {
4835: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4836: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4837: }
4838: }
4839: }
4840: }
4841: }
4842: my %roles = (
4843: '0' => &Apache::lonnet::plaintext('dc'),
4844: );
4845:
4846: foreach my $type (@types) {
4847: unless (($row eq 'registered') && ($key eq 'default')) {
4848: $datatable .= '<th>'.&mt($type).'</th>';
4849: }
4850: }
4851: unless (($row eq 'registered') && ($key eq 'default')) {
4852: $datatable .= '</tr><tr>';
4853: }
4854: foreach my $type (@types) {
4855: if ($type eq 'community') {
4856: $roles{'1'} = &mt('Community personnel');
4857: } else {
4858: $roles{'1'} = &mt('Course personnel');
4859: }
4860: $datatable .= '<td style="vertical-align: top">';
4861: if ($position eq 'top') {
4862: my %checked;
4863: if ($current{$type} eq '0') {
4864: $checked{'0'} = ' checked="checked"';
4865: } else {
4866: $checked{'1'} = ' checked="checked"';
4867: }
4868: foreach my $role ('1','0') {
4869: $datatable .= '<span class="LC_nobreak"><label>'.
4870: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4871: 'value="'.$role.'"'.$checked{$role}.' />'.
4872: $roles{$role}.'</label></span> ';
4873: }
4874: } else {
4875: if ($row eq 'types') {
4876: my %checked;
4877: if ($current{$type} =~ /^(all|dom)$/) {
4878: $checked{$1} = ' checked="checked"';
4879: } else {
4880: $checked{''} = ' checked="checked"';
4881: }
4882: foreach my $val ('','dom','all') {
4883: $datatable .= '<span class="LC_nobreak"><label>'.
4884: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4885: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4886: }
4887: } elsif ($row eq 'registered') {
4888: my %checked;
4889: if ($current{$type} eq '1') {
4890: $checked{'1'} = ' checked="checked"';
4891: } else {
4892: $checked{'0'} = ' checked="checked"';
4893: }
4894: foreach my $val ('0','1') {
4895: $datatable .= '<span class="LC_nobreak"><label>'.
4896: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4897: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4898: }
4899: } elsif ($row eq 'approval') {
4900: my %checked;
4901: if ($current{$type} =~ /^([12])$/) {
4902: $checked{$1} = ' checked="checked"';
4903: } else {
4904: $checked{'0'} = ' checked="checked"';
4905: }
4906: for my $val (0..2) {
4907: $datatable .= '<span class="LC_nobreak"><label>'.
4908: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4909: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4910: }
4911: } elsif ($row eq 'limit') {
4912: my %checked;
4913: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4914: $checked{$1} = ' checked="checked"';
4915: } else {
4916: $checked{'none'} = ' checked="checked"';
4917: }
4918: my $cap;
4919: if ($currentcap{$type} =~ /^\d+$/) {
4920: $cap = $currentcap{$type};
4921: }
4922: foreach my $val ('none','allstudents','selfenrolled') {
4923: $datatable .= '<span class="LC_nobreak"><label>'.
4924: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4925: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4926: }
4927: $datatable .= '<br />'.
4928: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4929: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4930: '</span>';
4931: }
4932: }
4933: $datatable .= '</td>';
4934: }
4935: $datatable .= '</tr>';
4936: }
4937: $datatable .= '</table></td></tr>';
4938: }
4939: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4940: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4941: }
4942: $$rowtotal += $itemcount;
4943: return $datatable;
4944: }
4945:
4946: sub print_validation_rows {
4947: my ($caller,$dom,$settings,$rowtotal) = @_;
4948: my ($itemsref,$namesref,$fieldsref);
4949: if ($caller eq 'selfenroll') {
4950: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4951: } elsif ($caller eq 'requestcourses') {
4952: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4953: }
4954: my %currvalidation;
4955: if (ref($settings) eq 'HASH') {
4956: if (ref($settings->{'validation'}) eq 'HASH') {
4957: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4958: }
1.160.6.39 raeburn 4959: }
4960: my $datatable;
4961: my $itemcount = 0;
4962: foreach my $item (@{$itemsref}) {
4963: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4964: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4965: $namesref->{$item}.
4966: '</span></td>'.
4967: '<td class="LC_left_item">';
4968: if (($item eq 'url') || ($item eq 'button')) {
4969: $datatable .= '<span class="LC_nobreak">'.
4970: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4971: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4972: } elsif ($item eq 'fields') {
4973: my @currfields;
4974: if (ref($currvalidation{$item}) eq 'ARRAY') {
4975: @currfields = @{$currvalidation{$item}};
4976: }
4977: foreach my $field (@{$fieldsref}) {
4978: my $check = '';
4979: if (grep(/^\Q$field\E$/,@currfields)) {
4980: $check = ' checked="checked"';
4981: }
4982: $datatable .= '<span class="LC_nobreak"><label>'.
4983: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4984: ' value="'.$field.'"'.$check.' />'.$field.
4985: '</label></span> ';
4986: }
4987: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4988: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4989: $currvalidation{$item}.
1.160.6.37 raeburn 4990: '</textarea>';
1.160.6.39 raeburn 4991: }
4992: $datatable .= '</td></tr>'."\n";
4993: if (ref($rowtotal)) {
1.160.6.37 raeburn 4994: $itemcount ++;
4995: }
1.139 raeburn 4996: }
1.160.6.39 raeburn 4997: if ($caller eq 'requestcourses') {
4998: my %currhash;
1.160.6.51 raeburn 4999: if (ref($settings) eq 'HASH') {
5000: if (ref($settings->{'validation'}) eq 'HASH') {
5001: if ($settings->{'validation'}{'dc'} ne '') {
5002: $currhash{$settings->{'validation'}{'dc'}} = 1;
5003: }
1.160.6.39 raeburn 5004: }
5005: }
5006: my $numinrow = 2;
5007: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5008: 'validationdc',%currhash);
1.160.6.50 raeburn 5009: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 5010: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 5011: if ($numdc > 1) {
1.160.6.50 raeburn 5012: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 5013: } else {
1.160.6.50 raeburn 5014: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 5015: }
1.160.6.50 raeburn 5016: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 5017: $itemcount ++;
5018: }
5019: if (ref($rowtotal)) {
5020: $$rowtotal += $itemcount;
5021: }
1.121 raeburn 5022: return $datatable;
1.118 jms 5023: }
5024:
1.160.6.98 raeburn 5025: sub print_passwords {
5026: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5027: my ($datatable,$css_class);
5028: my $itemcount = 0;
5029: my %titles = &Apache::lonlocal::texthash (
5030: captcha => '"Forgot Password" CAPTCHA validation',
5031: link => 'Reset link expiration (hours)',
5032: case => 'Case-sensitive usernames/e-mail',
5033: prelink => 'Information required (form 1)',
5034: postlink => 'Information required (form 2)',
5035: emailsrc => 'LON-CAPA e-mail address type(s)',
5036: customtext => 'Domain specific text (HTML)',
5037: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5038: intauth_check => 'Check bcrypt cost if authenticated',
5039: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5040: permanent => 'Permanent e-mail address',
5041: critical => 'Critical notification address',
5042: notify => 'Notification address',
5043: min => 'Minimum password length',
5044: max => 'Maximum password length',
5045: chars => 'Required characters',
5046: numsaved => 'Number of previous passwords to save and disallow reuse',
5047: );
5048: if ($position eq 'top') {
5049: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5050: my $shownlinklife = 2;
5051: my $prelink = 'both';
5052: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5053: if (ref($settings) eq 'HASH') {
5054: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5055: $shownlinklife = $settings->{resetlink};
5056: }
5057: if (ref($settings->{resetcase}) eq 'ARRAY') {
5058: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5059: }
5060: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5061: $prelink = $settings->{resetprelink};
5062: }
5063: if (ref($settings->{resetpostlink}) eq 'HASH') {
5064: %postlink = %{$settings->{resetpostlink}};
5065: }
5066: if (ref($settings->{resetemail}) eq 'ARRAY') {
5067: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5068: }
5069: if ($settings->{resetremove}) {
5070: $nostdtext = 1;
5071: }
5072: if ($settings->{resetcustom}) {
5073: $customurl = $settings->{resetcustom};
5074: }
5075: } else {
5076: if (ref($types) eq 'ARRAY') {
5077: foreach my $item (@{$types}) {
5078: $casesens{$item} = 1;
5079: $postlink{$item} = ['username','email'];
5080: }
5081: }
5082: $casesens{'default'} = 1;
5083: $postlink{'default'} = ['username','email'];
5084: $prelink = 'both';
5085: %emailsrc = (
5086: permanent => 1,
5087: critical => 1,
5088: notify => 1,
5089: );
5090: }
5091: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5092: $itemcount ++;
5093: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5094: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5095: '<td class="LC_left_item">'.
5096: '<input type="textbox" value="'.$shownlinklife.'" '.
5097: 'name="passwords_link" size="3" /></td></tr>';
5098: $itemcount ++;
5099: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5100: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5101: '<td class="LC_left_item">';
5102: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5103: foreach my $item (@{$types}) {
5104: my $checkedcase;
5105: if ($casesens{$item}) {
5106: $checkedcase = ' checked="checked"';
5107: }
5108: $datatable .= '<span class="LC_nobreak"><label>'.
5109: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5110: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5111: '</span> ';
1.160.6.98 raeburn 5112: }
5113: }
5114: my $checkedcase;
5115: if ($casesens{'default'}) {
5116: $checkedcase = ' checked="checked"';
5117: }
5118: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5119: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5120: $othertitle.'</label></span></td>';
5121: $itemcount ++;
5122: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5123: my %checkedpre = (
5124: both => ' checked="checked"',
5125: either => '',
5126: );
5127: if ($prelink eq 'either') {
5128: $checkedpre{either} = ' checked="checked"';
5129: $checkedpre{both} = '';
5130: }
5131: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5132: '<td class="LC_left_item"><span class="LC_nobreak">'.
5133: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5134: &mt('Both username and e-mail address').'</label></span> '.
5135: '<span class="LC_nobreak"><label>'.
5136: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5137: &mt('Either username or e-mail address').'</label></span></td></tr>';
5138: $itemcount ++;
5139: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5140: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5141: '<td class="LC_left_item">';
5142: my %postlinked;
5143: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5144: foreach my $item (@{$types}) {
5145: undef(%postlinked);
5146: $datatable .= '<fieldset style="display: inline-block;">'.
5147: '<legend>'.$usertypes->{$item}.'</legend>';
5148: if (ref($postlink{$item}) eq 'ARRAY') {
5149: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5150: }
5151: foreach my $field ('email','username') {
5152: my $checked;
5153: if ($postlinked{$field}) {
5154: $checked = ' checked="checked"';
5155: }
5156: $datatable .= '<span class="LC_nobreak"><label>'.
5157: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5158: $field.'"'.$checked.' />'.$field.'</label>'.
5159: '<span> ';
5160: }
5161: $datatable .= '</fieldset>';
5162: }
5163: }
5164: if (ref($postlink{'default'}) eq 'ARRAY') {
5165: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5166: }
5167: $datatable .= '<fieldset style="display: inline-block;">'.
5168: '<legend>'.$othertitle.'</legend>';
5169: foreach my $field ('email','username') {
5170: my $checked;
5171: if ($postlinked{$field}) {
5172: $checked = ' checked="checked"';
5173: }
5174: $datatable .= '<span class="LC_nobreak"><label>'.
5175: '<input type="checkbox" name="passwords_postlink_default" value="'.
5176: $field.'"'.$checked.' />'.$field.'</label>'.
5177: '<span> ';
5178: }
5179: $datatable .= '</fieldset></td></tr>';
5180: $itemcount ++;
5181: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5182: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5183: '<td class="LC_left_item">';
5184: foreach my $type ('permanent','critical','notify') {
5185: my $checkedemail;
5186: if ($emailsrc{$type}) {
5187: $checkedemail = ' checked="checked"';
5188: }
5189: $datatable .= '<span class="LC_nobreak"><label>'.
5190: '<input type="checkbox" name="passwords_emailsrc" value="'.
5191: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5192: '<span> ';
5193: }
5194: $datatable .= '</td></tr>';
5195: $itemcount ++;
5196: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5197: my $switchserver = &check_switchserver($dom,$confname);
5198: my ($showstd,$noshowstd);
5199: if ($nostdtext) {
5200: $noshowstd = ' checked="checked"';
5201: } else {
5202: $showstd = ' checked="checked"';
5203: }
5204: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5205: '<td class="LC_left_item"><span class="LC_nobreak">'.
5206: &mt('Retain standard text:').
5207: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5208: &mt('Yes').'</label>'.' '.
5209: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5210: &mt('No').'</label></span><br />'.
5211: '<span class="LC_fontsize_small">'.
5212: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5213: &mt('Include custom text:');
5214: if ($customurl) {
1.160.6.104 raeburn 5215: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 5216: undef,undef,undef,undef,'background-color:#ffffff');
5217: $datatable .= '<span class="LC_nobreak"> '.$link.
5218: '<label><input type="checkbox" name="passwords_custom_del"'.
5219: ' value="1" />'.&mt('Delete?').'</label></span>'.
5220: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5221: }
5222: if ($switchserver) {
5223: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5224: } else {
5225: $datatable .='<span class="LC_nobreak"> '.
5226: '<input type="file" name="passwords_customfile" /></span>';
5227: }
5228: $datatable .= '</td></tr>';
5229: } elsif ($position eq 'middle') {
5230: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5231: my @items = ('intauth_cost','intauth_check','intauth_switch');
5232: my %defaults;
5233: if (ref($domconf{'defaults'}) eq 'HASH') {
5234: %defaults = %{$domconf{'defaults'}};
5235: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5236: $defaults{'intauth_cost'} = 10;
5237: }
5238: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5239: $defaults{'intauth_check'} = 0;
5240: }
5241: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5242: $defaults{'intauth_switch'} = 0;
5243: }
5244: } else {
5245: %defaults = (
5246: 'intauth_cost' => 10,
5247: 'intauth_check' => 0,
5248: 'intauth_switch' => 0,
5249: );
5250: }
5251: foreach my $item (@items) {
5252: if ($itemcount%2) {
5253: $css_class = '';
5254: } else {
5255: $css_class = ' class="LC_odd_row" ';
5256: }
5257: $datatable .= '<tr'.$css_class.'>'.
5258: '<td><span class="LC_nobreak">'.$titles{$item}.
5259: '</span></td><td class="LC_left_item" colspan="3">';
5260: if ($item eq 'intauth_switch') {
5261: my @options = (0,1,2);
5262: my %optiondesc = &Apache::lonlocal::texthash (
5263: 0 => 'No',
5264: 1 => 'Yes',
5265: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5266: );
5267: $datatable .= '<table width="100%">';
5268: foreach my $option (@options) {
5269: my $checked = ' ';
5270: if ($defaults{$item} eq $option) {
5271: $checked = ' checked="checked"';
5272: }
5273: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5274: '<label><input type="radio" name="'.$item.
5275: '" value="'.$option.'"'.$checked.' />'.
5276: $optiondesc{$option}.'</label></span></td></tr>';
5277: }
5278: $datatable .= '</table>';
5279: } elsif ($item eq 'intauth_check') {
5280: my @options = (0,1,2);
5281: my %optiondesc = &Apache::lonlocal::texthash (
5282: 0 => 'No',
5283: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5284: 2 => 'Yes, disallow login if stored cost is less than domain default',
5285: );
5286: $datatable .= '<table width="100%">';
5287: foreach my $option (@options) {
5288: my $checked = ' ';
5289: my $onclick;
5290: if ($defaults{$item} eq $option) {
5291: $checked = ' checked="checked"';
5292: }
5293: if ($option == 2) {
5294: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5295: }
5296: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5297: '<label><input type="radio" name="'.$item.
5298: '" value="'.$option.'"'.$checked.$onclick.' />'.
5299: $optiondesc{$option}.'</label></span></td></tr>';
5300: }
5301: $datatable .= '</table>';
5302: } else {
5303: $datatable .= '<input type="text" name="'.$item.'" value="'.
5304: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5305: }
5306: $datatable .= '</td></tr>';
5307: $itemcount ++;
5308: }
5309: } elsif ($position eq 'lower') {
5310: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 5311: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 5312: if (ref($settings) eq 'HASH') {
5313: if ($settings->{min}) {
5314: $min = $settings->{min};
5315: }
5316: if ($settings->{max}) {
5317: $max = $settings->{max};
5318: }
5319: if (ref($settings->{chars}) eq 'ARRAY') {
5320: map { $chars{$_} = 1; } (@{$settings->{chars}});
5321: }
5322: if ($settings->{numsaved}) {
5323: $numsaved = $settings->{numsaved};
5324: }
5325: }
5326: my %rulenames = &Apache::lonlocal::texthash(
5327: uc => 'At least one upper case letter',
5328: lc => 'At least one lower case letter',
5329: num => 'At least one number',
5330: spec => 'At least one non-alphanumeric',
5331: );
5332: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5333: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5334: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5335: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5336: 'onblur="javascript:warnIntPass(this);" />'.
5337: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 5338: '</span></td></tr>';
5339: $itemcount ++;
5340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5341: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5342: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5343: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5344: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5345: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5346: '</span></td></tr>';
5347: $itemcount ++;
5348: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5349: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5350: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5351: '</span></td>';
5352: my $numinrow = 2;
5353: my @possrules = ('uc','lc','num','spec');
5354: $datatable .= '<td class="LC_left_item"><table>';
5355: for (my $i=0; $i<@possrules; $i++) {
5356: my ($rem,$checked);
5357: if ($chars{$possrules[$i]}) {
5358: $checked = ' checked="checked"';
5359: }
5360: $rem = $i%($numinrow);
5361: if ($rem == 0) {
5362: if ($i > 0) {
5363: $datatable .= '</tr>';
5364: }
5365: $datatable .= '<tr>';
5366: }
5367: $datatable .= '<td><span class="LC_nobreak"><label>'.
5368: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5369: $rulenames{$possrules[$i]}.'</label></span></td>';
5370: }
5371: my $rem = @possrules%($numinrow);
5372: my $colsleft = $numinrow - $rem;
5373: if ($colsleft > 1 ) {
5374: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5375: ' </td>';
5376: } elsif ($colsleft == 1) {
5377: $datatable .= '<td class="LC_left_item"> </td>';
5378: }
5379: $datatable .='</table></td></tr>';
5380: $itemcount ++;
5381: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5382: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5383: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5384: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5385: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5386: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5387: '</span></td></tr>';
5388: } else {
5389: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5390: my %ownerchg = (
5391: by => {},
5392: for => {},
5393: );
5394: my %ownertitles = &Apache::lonlocal::texthash (
5395: by => 'Course owner status(es) allowed',
5396: for => 'Student status(es) allowed',
5397: );
5398: if (ref($settings) eq 'HASH') {
5399: if (ref($settings->{crsownerchg}) eq 'HASH') {
5400: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5401: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5402: }
5403: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5404: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5405: }
5406: }
5407: }
5408: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5409: $datatable .= '<tr '.$css_class.'>'.
5410: '<td>'.
5411: &mt('Requirements').'<ul>'.
5412: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5413: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5414: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5415: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5416: '</ul>'.
5417: '</td>'.
5418: '<td class="LC_left_item">';
5419: foreach my $item ('by','for') {
5420: $datatable .= '<fieldset style="display: inline-block;">'.
5421: '<legend>'.$ownertitles{$item}.'</legend>';
5422: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5423: foreach my $type (@{$types}) {
5424: my $checked;
5425: if ($ownerchg{$item}{$type}) {
5426: $checked = ' checked="checked"';
5427: }
5428: $datatable .= '<span class="LC_nobreak"><label>'.
5429: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5430: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 5431: '</span> ';
1.160.6.98 raeburn 5432: }
5433: }
5434: my $checked;
5435: if ($ownerchg{$item}{'default'}) {
5436: $checked = ' checked="checked"';
5437: }
5438: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5439: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5440: $othertitle.'</label></span></fieldset>';
5441: }
5442: $datatable .= '</td></tr>';
5443: }
5444: return $datatable;
5445: }
5446:
1.160.6.113 raeburn 5447: sub print_wafproxy {
5448: my ($position,$dom,$settings,$rowtotal) = @_;
5449: my $css_class;
5450: my $itemcount = 0;
5451: my $datatable;
5452: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5453: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
5454: my %lt = &wafproxy_titles();
5455: foreach my $server (sort(keys(%servers))) {
5456: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
5457: next if ($serverhome eq '');
5458: my $serverdom;
5459: if ($serverhome ne $server) {
5460: $serverdom = &Apache::lonnet::host_domain($serverhome);
5461: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
5462: $othercontrol{$server} = $serverdom;
5463: }
5464: } else {
5465: $serverdom = &Apache::lonnet::host_domain($server);
5466: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
5467: if ($serverdom ne $dom) {
5468: $othercontrol{$server} = $serverdom;
5469: } else {
5470: $setdom = 1;
5471: if (ref($settings) eq 'HASH') {
5472: if (ref($settings->{'alias'}) eq 'HASH') {
5473: $aliases{$dom} = $settings->{'alias'};
5474: if ($aliases{$dom} ne '') {
5475: $showdom = 1;
5476: }
5477: }
5478: if (ref($settings->{'saml'}) eq 'HASH') {
5479: $saml{$dom} = $settings->{'saml'};
5480: }
5481: }
5482: }
5483: }
5484: }
5485: if ($setdom) {
5486: %{$values{$dom}} = ();
5487: if (ref($settings) eq 'HASH') {
5488: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5489: $values{$dom}{$item} = $settings->{$item};
5490: }
5491: }
5492: }
5493: if (keys(%othercontrol)) {
5494: %otherdoms = reverse(%othercontrol);
5495: foreach my $domain (keys(%otherdoms)) {
5496: %{$values{$domain}} = ();
5497: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
5498: if (ref($config{'wafproxy'}) eq 'HASH') {
5499: $aliases{$domain} = $config{'wafproxy'}{'alias'};
5500: if (exists($config{'wafproxy'}{'saml'})) {
5501: $saml{$domain} = $config{'wafproxy'}{'saml'};
5502: }
5503: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5504: $values{$domain}{$item} = $config{'wafproxy'}{$item};
5505: }
5506: }
5507: }
5508: }
5509: if ($position eq 'top') {
5510: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5511: my %aliasinfo;
5512: foreach my $server (sort(keys(%servers))) {
5513: $itemcount ++;
5514: my $dom_in_effect;
5515: my $aliasrows = '<tr>'.
5516: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.160.6.123 raeburn 5517: &mt('Hostname').': '.
5518: '<span class="LC_nobreak LC_cusr_emph">'.
5519: &Apache::lonnet::hostname($server).
5520: '</span></td><td> </td>';
1.160.6.113 raeburn 5521: if ($othercontrol{$server}) {
5522: $dom_in_effect = $othercontrol{$server};
5523: my ($current,$forsaml);
5524: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
5525: $current = $aliases{$dom_in_effect}{$server};
5526: }
5527: if (ref($saml{$dom_in_effect}) eq 'HASH') {
5528: if ($saml{$dom_in_effect}{$server}) {
5529: $forsaml = 1;
5530: }
5531: }
5532: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5533: &mt('Alias').': ';
5534: if ($current) {
5535: $aliasrows .= $current;
5536: if ($forsaml) {
5537: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
5538: }
5539: } else {
5540: $aliasrows .= &mt('None');
5541: }
5542: $aliasrows .= ' <span class="LC_small">('.
5543: &mt('controlled by domain: [_1]',
5544: '<b>'.$dom_in_effect.'</b>').')</span></td>';
5545: } else {
5546: $dom_in_effect = $dom;
5547: my ($current,$samlon,$samloff);
5548: $samloff = ' checked="checked"';
5549: if (ref($aliases{$dom}) eq 'HASH') {
5550: if ($aliases{$dom}{$server}) {
5551: $current = $aliases{$dom}{$server};
5552: }
5553: }
5554: if (ref($saml{$dom}) eq 'HASH') {
5555: if ($saml{$dom}{$server}) {
5556: $samlon = $samloff;
5557: undef($samloff);
5558: }
5559: }
5560: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5561: &mt('Alias').': '.
5562: '<input type="text" name="wafproxy_alias_'.$server.'" '.
5563: 'value="'.$current.'" size="30" />'.
5564: (' 'x2).'<span class="LC_nobreak">'.
5565: &mt('Alias used for SSO Auth').': <label>'.
5566: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
5567: &mt('No').'</label> <label>'.
5568: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
5569: &mt('Yes').'</label></span>'.
5570: '</td>';
5571: }
5572: $aliasrows .= '</tr>';
5573: $aliasinfo{$dom_in_effect} .= $aliasrows;
5574: }
5575: if ($aliasinfo{$dom}) {
5576: my ($onclick,$wafon,$wafoff,$showtable);
5577: $onclick = ' onclick="javascript:toggleWAF();"';
5578: $wafoff = ' checked="checked"';
5579: $showtable = ' style="display:none";';
5580: if ($showdom) {
5581: $wafon = $wafoff;
5582: $wafoff = '';
5583: $showtable = ' style="display:inline;"';
5584: }
5585: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5586: $datatable = '<tr'.$css_class.'>'.
5587: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
5588: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
5589: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
5590: &mt('Yes').'</label>'.(' 'x2).'<label>'.
5591: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
5592: &mt('No').'</label></span></td>'.
5593: '<td class="LC_left_item">'.
5594: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
5595: '</table></td></tr>';
5596: $itemcount++;
5597: }
5598: if (keys(%otherdoms)) {
5599: foreach my $key (sort(keys(%otherdoms))) {
5600: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5601: $datatable .= '<tr'.$css_class.'>'.
5602: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
5603: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
5604: '</table></td></tr>';
5605: $itemcount++;
5606: }
5607: }
5608: } else {
5609: my %ip_methods = &remoteip_methods();
5610: if ($setdom) {
5611: $itemcount ++;
5612: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5613: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
5614: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
5615: $wafstyle = ' style="display:none;"';
5616: $nowafstyle = ' style="display:table-row;"';
5617: $currwafdisplay = ' style="display: none"';
5618: $wafrangestyle = ' style="display: none"';
5619: $curr_remotip = 'n';
5620: $ssltossl = ' checked="checked"';
5621: if ($showdom) {
5622: $wafstyle = ' style="display:table-row;"';
5623: $nowafstyle = ' style="display:none;"';
5624: if (keys(%{$values{$dom}})) {
5625: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
5626: $curr_remotip = $values{$dom}{remoteip};
5627: }
5628: if ($curr_remotip eq 'h') {
5629: $currwafdisplay = ' style="display:table-row"';
5630: $wafrangestyle = ' style="display:inline-block;"';
5631: }
5632: if ($values{$dom}{'sslopt'}) {
5633: $alltossl = ' checked="checked"';
5634: $ssltossl = '';
5635: }
5636: }
5637: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
5638: $vpndircheck = ' checked="checked"';
5639: $currwafvpn = ' style="display:table-row;"';
5640: $wafrangestyle = ' style="display:inline-block;"';
5641: } else {
5642: $vpnaliascheck = ' checked="checked"';
5643: $currwafvpn = ' style="display:none;"';
5644: }
5645: }
5646: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5647: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
5648: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
5649: '</tr>'.
5650: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5651: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
5652: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
5653: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
5654: &mt('Range(s) stored in CIDR notation').'</div></td>'.
5655: '<td class="LC_left_item"><table>'.
5656: '<tr>'.
5657: '<td valign="top">'.$lt{'remoteip'}.': '.
5658: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
5659: foreach my $option ('m','h','n') {
5660: my $sel;
1.160.6.114 raeburn 5661: if ($option eq $curr_remotip) {
5662: $sel = ' selected="selected"';
5663: }
5664: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
5665: $ip_methods{$option}.'</option>';
5666: }
5667: $datatable .= '</select></td></tr>'."\n".
5668: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
5669: $lt{'ipheader'}.': '.
5670: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
5671: 'name="wafproxy_ipheader" />'.
5672: '</td></tr>'."\n".
5673: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
5674: $lt{'trusted'}.':<br />'.
5675: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
5676: $values{$dom}{'trusted'}.'</textarea>'.
5677: '</td></tr>'."\n".
5678: '<tr><td><hr /></td></tr>'."\n".
5679: '<tr>'.
1.160.6.113 raeburn 5680: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
5681: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
5682: $lt{'vpndirect'}.'</label>'.(' 'x2).
5683: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
5684: $lt{'vpnaliased'}.'</label></span></td></tr>';
5685: foreach my $item ('vpnint','vpnext') {
5686: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
5687: '<td valign="top">'.$lt{$item}.':<br />'.
5688: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
5689: $values{$dom}{$item}.'</textarea>'.
5690: '</td></tr>'."\n";
5691: }
5692: $datatable .= '<tr><td><hr /></td></tr>'."\n".
5693: '<tr>'.
5694: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
5695: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
5696: $lt{'alltossl'}.'</label>'.(' 'x2).
5697: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
5698: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
5699: '</table></td></tr>';
5700: }
5701: if (keys(%otherdoms)) {
5702: foreach my $domain (sort(keys(%otherdoms))) {
5703: $itemcount ++;
5704: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5705: $datatable .= '<tr'.$css_class.'>'.
5706: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
5707: '<td class="LC_left_item"><table>';
5708: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
5709: my $showval = &mt('None');
5710: if ($item eq 'ssl') {
5711: $showval = $lt{'ssltossl'};
5712: }
5713: if ($values{$domain}{$item}) {
5714: $showval = $values{$domain}{$item};
5715: if ($item eq 'ssl') {
5716: $showval = $lt{'alltossl'};
5717: } elsif ($item eq 'remoteip') {
5718: $showval = $ip_methods{$values{$domain}{$item}};
5719: }
5720: }
5721: $datatable .= '<tr>'.
5722: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
5723: }
5724: $datatable .= '</table></td></tr>';
5725: }
5726: }
5727: }
5728: $$rowtotal += $itemcount;
5729: return $datatable;
5730: }
5731:
5732: sub wafproxy_titles {
5733: return &Apache::lonlocal::texthash(
5734: remoteip => "Method for determining user's IP",
5735: ipheader => 'Request header containing remote IP',
5736: trusted => 'Trusted IP range(s)',
5737: vpnaccess => 'Access from institutional VPN',
5738: vpndirect => 'via regular hostname (no WAF)',
5739: vpnaliased => 'via aliased hostname (WAF)',
5740: vpnint => 'Internal IP Range(s) for VPN sessions',
5741: vpnext => 'IP Range(s) for backend WAF connections',
5742: sslopt => 'Forwarding http/https',
5743: alltossl => 'WAF forwards both http and https requests to https',
5744: ssltossl => 'WAF forwards http requests to http and https to https',
5745: );
5746: }
5747:
5748: sub remoteip_methods {
5749: return &Apache::lonlocal::texthash(
5750: m => 'Use Apache mod_remoteip',
5751: h => 'Use headers parsed by LON-CAPA',
5752: n => 'Not in use',
5753: );
5754: }
5755:
1.137 raeburn 5756: sub print_usersessions {
5757: my ($position,$dom,$settings,$rowtotal) = @_;
5758: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 5759: my (%by_ip,%by_location,@intdoms);
5760: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 5761:
5762: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5763: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5764: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5765: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5766: my $itemcount = 1;
5767: if ($position eq 'top') {
1.152 raeburn 5768: if (keys(%serverhomes) > 1) {
1.145 raeburn 5769: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 5770: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 5771: if (ref($settings) eq 'HASH') {
5772: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5773: $curroffloadnow = $settings->{'offloadnow'};
5774: }
1.160.6.105 raeburn 5775: if (ref($settings->{'offloadoth'}) eq 'HASH') {
5776: $curroffloadoth = $settings->{'offloadoth'};
5777: }
1.160.6.61 raeburn 5778: }
1.160.6.105 raeburn 5779: my $other_insts = scalar(keys(%by_location));
5780: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
5781: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 5782: } else {
1.140 raeburn 5783: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5784: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 5785: }
1.137 raeburn 5786: } else {
1.145 raeburn 5787: if (keys(%by_location) == 0) {
5788: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5789: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 5790: } else {
5791: my %lt = &usersession_titles();
5792: my $numinrow = 5;
5793: my $prefix;
5794: my @types;
5795: if ($position eq 'bottom') {
5796: $prefix = 'remote';
5797: @types = ('version','excludedomain','includedomain');
5798: } else {
5799: $prefix = 'hosted';
5800: @types = ('excludedomain','includedomain');
5801: }
5802: my (%current,%checkedon,%checkedoff);
5803: my @lcversions = &Apache::lonnet::all_loncaparevs();
5804: my @locations = sort(keys(%by_location));
5805: foreach my $type (@types) {
5806: $checkedon{$type} = '';
5807: $checkedoff{$type} = ' checked="checked"';
5808: }
5809: if (ref($settings) eq 'HASH') {
5810: if (ref($settings->{$prefix}) eq 'HASH') {
5811: foreach my $key (keys(%{$settings->{$prefix}})) {
5812: $current{$key} = $settings->{$prefix}{$key};
5813: if ($key eq 'version') {
5814: if ($current{$key} ne '') {
5815: $checkedon{$key} = ' checked="checked"';
5816: $checkedoff{$key} = '';
5817: }
5818: } elsif (ref($current{$key}) eq 'ARRAY') {
5819: $checkedon{$key} = ' checked="checked"';
5820: $checkedoff{$key} = '';
5821: }
1.137 raeburn 5822: }
5823: }
5824: }
1.145 raeburn 5825: foreach my $type (@types) {
5826: next if ($type ne 'version' && !@locations);
5827: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5828: $datatable .= '<tr'.$css_class.'>
5829: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5830: <span class="LC_nobreak">
5831: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5832: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5833: if ($type eq 'version') {
5834: my $selector = '<select name="'.$prefix.'_version">';
5835: foreach my $version (@lcversions) {
5836: my $selected = '';
5837: if ($current{'version'} eq $version) {
5838: $selected = ' selected="selected"';
5839: }
5840: $selector .= ' <option value="'.$version.'"'.
5841: $selected.'>'.$version.'</option>';
5842: }
5843: $selector .= '</select> ';
5844: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5845: } else {
5846: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5847: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5848: ' />'.(' 'x2).
5849: '<input type="button" value="'.&mt('uncheck all').'" '.
5850: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5851: "\n".
5852: '</div><div><table>';
5853: my $rem;
5854: for (my $i=0; $i<@locations; $i++) {
5855: my ($showloc,$value,$checkedtype);
5856: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5857: my $ip = $by_location{$locations[$i]}->[0];
5858: if (ref($by_ip{$ip}) eq 'ARRAY') {
5859: $value = join(':',@{$by_ip{$ip}});
5860: $showloc = join(', ',@{$by_ip{$ip}});
5861: if (ref($current{$type}) eq 'ARRAY') {
5862: foreach my $loc (@{$by_ip{$ip}}) {
5863: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5864: $checkedtype = ' checked="checked"';
5865: last;
5866: }
5867: }
1.138 raeburn 5868: }
5869: }
5870: }
1.145 raeburn 5871: $rem = $i%($numinrow);
5872: if ($rem == 0) {
5873: if ($i > 0) {
5874: $datatable .= '</tr>';
5875: }
5876: $datatable .= '<tr>';
5877: }
5878: $datatable .= '<td class="LC_left_item">'.
5879: '<span class="LC_nobreak"><label>'.
5880: '<input type="checkbox" name="'.$prefix.'_'.$type.
5881: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5882: '</label></span></td>';
1.137 raeburn 5883: }
1.145 raeburn 5884: $rem = @locations%($numinrow);
5885: my $colsleft = $numinrow - $rem;
5886: if ($colsleft > 1 ) {
5887: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5888: ' </td>';
5889: } elsif ($colsleft == 1) {
5890: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5891: }
1.145 raeburn 5892: $datatable .= '</tr></table>';
1.137 raeburn 5893: }
1.145 raeburn 5894: $datatable .= '</td></tr>';
5895: $itemcount ++;
1.137 raeburn 5896: }
5897: }
5898: }
5899: $$rowtotal += $itemcount;
5900: return $datatable;
5901: }
5902:
1.138 raeburn 5903: sub build_location_hashes {
5904: my ($intdoms,$by_ip,$by_location) = @_;
5905: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5906: (ref($by_location) eq 'HASH'));
5907: my %iphost = &Apache::lonnet::get_iphost();
5908: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5909: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5910: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5911: foreach my $id (@{$iphost{$primary_ip}}) {
5912: my $intdom = &Apache::lonnet::internet_dom($id);
5913: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5914: push(@{$intdoms},$intdom);
5915: }
5916: }
5917: }
5918: foreach my $ip (keys(%iphost)) {
5919: if (ref($iphost{$ip}) eq 'ARRAY') {
5920: foreach my $id (@{$iphost{$ip}}) {
5921: my $location = &Apache::lonnet::internet_dom($id);
5922: if ($location) {
5923: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5924: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5925: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5926: push(@{$by_ip->{$ip}},$location);
5927: }
5928: } else {
5929: $by_ip->{$ip} = [$location];
5930: }
5931: }
5932: }
5933: }
5934: }
5935: foreach my $ip (sort(keys(%{$by_ip}))) {
5936: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5937: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5938: my $first = $by_ip->{$ip}->[0];
5939: if (ref($by_location->{$first}) eq 'ARRAY') {
5940: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5941: push(@{$by_location->{$first}},$ip);
5942: }
5943: } else {
5944: $by_location->{$first} = [$ip];
5945: }
5946: }
5947: }
5948: return;
5949: }
5950:
1.145 raeburn 5951: sub current_offloads_to {
5952: my ($dom,$settings,$servers) = @_;
5953: my (%spareid,%otherdomconfigs);
1.152 raeburn 5954: if (ref($servers) eq 'HASH') {
1.145 raeburn 5955: foreach my $lonhost (sort(keys(%{$servers}))) {
5956: my $gotspares;
1.152 raeburn 5957: if (ref($settings) eq 'HASH') {
5958: if (ref($settings->{'spares'}) eq 'HASH') {
5959: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5960: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5961: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5962: $gotspares = 1;
5963: }
1.145 raeburn 5964: }
5965: }
5966: unless ($gotspares) {
5967: my $gotspares;
5968: my $serverhomeID =
5969: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5970: my $serverhomedom =
5971: &Apache::lonnet::host_domain($serverhomeID);
5972: if ($serverhomedom ne $dom) {
5973: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5974: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5975: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5976: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5977: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5978: $gotspares = 1;
5979: }
5980: }
5981: } else {
5982: $otherdomconfigs{$serverhomedom} =
5983: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5984: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5985: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5986: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5987: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5988: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5989: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5990: $gotspares = 1;
5991: }
5992: }
5993: }
5994: }
5995: }
5996: }
5997: }
5998: unless ($gotspares) {
5999: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6000: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6001: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6002: } else {
6003: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6004: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6005: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6006: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6007: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6008: } else {
1.150 raeburn 6009: my %what = (
6010: spareid => 1,
6011: );
6012: my ($result,$returnhash) =
6013: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6014: if ($result eq 'ok') {
6015: if (ref($returnhash) eq 'HASH') {
6016: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6017: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6018: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6019: }
6020: }
1.145 raeburn 6021: }
6022: }
6023: }
6024: }
6025: }
6026: }
6027: return %spareid;
6028: }
6029:
6030: sub spares_row {
1.160.6.105 raeburn 6031: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
6032: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 6033: my $css_class;
6034: my $numinrow = 4;
6035: my $itemcount = 1;
6036: my $datatable;
1.152 raeburn 6037: my %typetitles = &sparestype_titles();
6038: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6039: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6040: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6041: my ($othercontrol,$serverdom);
6042: if ($serverhome ne $server) {
6043: $serverdom = &Apache::lonnet::host_domain($serverhome);
6044: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6045: } else {
6046: $serverdom = &Apache::lonnet::host_domain($server);
6047: if ($serverdom ne $dom) {
6048: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6049: }
6050: }
6051: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 6052: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 6053: if (ref($curroffloadnow) eq 'HASH') {
6054: if ($curroffloadnow->{$server}) {
6055: $checkednow = ' checked="checked"';
6056: }
6057: }
1.160.6.105 raeburn 6058: if (ref($curroffloadoth) eq 'HASH') {
6059: if ($curroffloadoth->{$server}) {
6060: $checkedoth = ' checked="checked"';
6061: }
6062: }
1.145 raeburn 6063: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6064: $datatable .= '<tr'.$css_class.'>
6065: <td rowspan="2">
1.160.6.13 raeburn 6066: <span class="LC_nobreak">'.
6067: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 6068: ,'<b>'.$server.'</b>').'</span><br />'.
6069: '<span class="LC_nobreak">'."\n".
6070: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 6071: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 6072: "\n";
1.160.6.105 raeburn 6073: if ($other_insts) {
6074: $datatable .= '<br />'.
6075: '<span class="LC_nobreak">'."\n".
6076: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
6077: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6078: "\n";
6079: }
1.145 raeburn 6080: my (%current,%canselect);
1.152 raeburn 6081: my @choices =
6082: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6083: foreach my $type ('primary','default') {
6084: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6085: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6086: my @spares = @{$spareid->{$server}{$type}};
6087: if (@spares > 0) {
1.152 raeburn 6088: if ($othercontrol) {
6089: $current{$type} = join(', ',@spares);
6090: } else {
6091: $current{$type} .= '<table>';
6092: my $numspares = scalar(@spares);
6093: for (my $i=0; $i<@spares; $i++) {
6094: my $rem = $i%($numinrow);
6095: if ($rem == 0) {
6096: if ($i > 0) {
6097: $current{$type} .= '</tr>';
6098: }
6099: $current{$type} .= '<tr>';
1.145 raeburn 6100: }
1.152 raeburn 6101: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
6102: $spareid->{$server}{$type}[$i].
6103: '</label></td>'."\n";
6104: }
6105: my $rem = @spares%($numinrow);
6106: my $colsleft = $numinrow - $rem;
6107: if ($colsleft > 1 ) {
6108: $current{$type} .= '<td colspan="'.$colsleft.
6109: '" class="LC_left_item">'.
6110: ' </td>';
6111: } elsif ($colsleft == 1) {
6112: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6113: }
1.152 raeburn 6114: $current{$type} .= '</tr></table>';
1.150 raeburn 6115: }
1.145 raeburn 6116: }
6117: }
6118: if ($current{$type} eq '') {
6119: $current{$type} = &mt('None specified');
6120: }
1.152 raeburn 6121: if ($othercontrol) {
6122: if ($type eq 'primary') {
6123: $canselect{$type} = $othercontrol;
6124: }
6125: } else {
6126: $canselect{$type} =
6127: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6128: '<select name="newspare_'.$type.'_'.$server.'" '.
6129: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6130: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6131: if (@choices > 0) {
6132: foreach my $lonhost (@choices) {
6133: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6134: }
6135: }
6136: $canselect{$type} .= '</select>'."\n";
6137: }
6138: } else {
6139: $current{$type} = &mt('Could not be determined');
6140: if ($type eq 'primary') {
6141: $canselect{$type} = $othercontrol;
6142: }
1.145 raeburn 6143: }
1.152 raeburn 6144: if ($type eq 'default') {
6145: $datatable .= '<tr'.$css_class.'>';
6146: }
6147: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6148: '<td>'.$current{$type}.'</td>'."\n".
6149: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6150: }
6151: $itemcount ++;
6152: }
6153: }
6154: $$rowtotal += $itemcount;
6155: return $datatable;
6156: }
6157:
1.152 raeburn 6158: sub possible_newspares {
6159: my ($server,$currspares,$serverhomes,$altids) = @_;
6160: my $serverhostname = &Apache::lonnet::hostname($server);
6161: my %excluded;
6162: if ($serverhostname ne '') {
6163: %excluded = (
6164: $serverhostname => 1,
6165: );
6166: }
6167: if (ref($currspares) eq 'HASH') {
6168: foreach my $type (keys(%{$currspares})) {
6169: if (ref($currspares->{$type}) eq 'ARRAY') {
6170: if (@{$currspares->{$type}} > 0) {
6171: foreach my $curr (@{$currspares->{$type}}) {
6172: my $hostname = &Apache::lonnet::hostname($curr);
6173: $excluded{$hostname} = 1;
6174: }
6175: }
6176: }
6177: }
6178: }
6179: my @choices;
6180: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6181: if (keys(%{$serverhomes}) > 1) {
6182: foreach my $name (sort(keys(%{$serverhomes}))) {
6183: unless ($excluded{$name}) {
6184: if (exists($altids->{$serverhomes->{$name}})) {
6185: push(@choices,$altids->{$serverhomes->{$name}});
6186: } else {
6187: push(@choices,$serverhomes->{$name});
1.145 raeburn 6188: }
6189: }
6190: }
6191: }
6192: }
1.152 raeburn 6193: return sort(@choices);
1.145 raeburn 6194: }
6195:
1.150 raeburn 6196: sub print_loadbalancing {
6197: my ($dom,$settings,$rowtotal) = @_;
6198: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6199: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6200: my $numinrow = 1;
6201: my $datatable;
6202: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 6203: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 6204: if (ref($settings) eq 'HASH') {
6205: %existing = %{$settings};
6206: }
6207: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6208: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 6209: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6210: } else {
6211: return;
6212: }
6213: my ($othertitle,$usertypes,$types) =
6214: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 6215: my $rownum = 8;
1.150 raeburn 6216: if (ref($types) eq 'ARRAY') {
6217: $rownum += scalar(@{$types});
6218: }
1.160.6.7 raeburn 6219: my @css_class = ('LC_odd_row','LC_even_row');
6220: my $balnum = 0;
6221: my $islast;
6222: my (@toshow,$disabledtext);
6223: if (keys(%currbalancer) > 0) {
6224: @toshow = sort(keys(%currbalancer));
6225: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6226: push(@toshow,'');
6227: }
6228: } else {
6229: @toshow = ('');
6230: $disabledtext = &mt('No existing load balancer');
6231: }
6232: foreach my $lonhost (@toshow) {
6233: if ($balnum == scalar(@toshow)-1) {
6234: $islast = 1;
6235: } else {
6236: $islast = 0;
6237: }
6238: my $cssidx = $balnum%2;
6239: my $targets_div_style = 'display: none';
6240: my $disabled_div_style = 'display: block';
6241: my $homedom_div_style = 'display: none';
6242: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
6243: '<td rowspan="'.$rownum.'" valign="top">'.
6244: '<p>';
6245: if ($lonhost eq '') {
6246: $datatable .= '<span class="LC_nobreak">';
6247: if (keys(%currbalancer) > 0) {
6248: $datatable .= &mt('Add balancer:');
6249: } else {
6250: $datatable .= &mt('Enable balancer:');
6251: }
6252: $datatable .= ' '.
6253: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6254: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6255: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6256: '<option value="" selected="selected">'.&mt('None').
6257: '</option>'."\n";
6258: foreach my $server (sort(keys(%servers))) {
6259: next if ($currbalancer{$server});
6260: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6261: }
6262: $datatable .=
6263: '</select>'."\n".
6264: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6265: } else {
6266: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6267: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6268: &mt('Stop balancing').'</label>'.
6269: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6270: $targets_div_style = 'display: block';
6271: $disabled_div_style = 'display: none';
6272: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6273: $homedom_div_style = 'display: block';
6274: }
6275: }
6276: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
6277: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6278: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6279: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6280: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6281: my @sparestypes = ('primary','default');
6282: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 6283: my %hostherechecked = (
6284: no => ' checked="checked"',
6285: );
1.160.6.94 raeburn 6286: my %balcookiechecked = (
6287: no => ' checked="checked"',
6288: );
1.160.6.7 raeburn 6289: foreach my $sparetype (@sparestypes) {
6290: my $targettable;
6291: for (my $i=0; $i<$numspares; $i++) {
6292: my $checked;
6293: if (ref($currtargets{$lonhost}) eq 'HASH') {
6294: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6295: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6296: $checked = ' checked="checked"';
6297: }
6298: }
6299: }
6300: my ($chkboxval,$disabled);
6301: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6302: $chkboxval = $spares[$i];
6303: }
6304: if (exists($currbalancer{$spares[$i]})) {
6305: $disabled = ' disabled="disabled"';
6306: }
6307: $targettable .=
1.160.6.55 raeburn 6308: '<td><span class="LC_nobreak"><label>'.
6309: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 6310: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.160.6.55 raeburn 6311: '</span></label></span></td>';
1.160.6.7 raeburn 6312: my $rem = $i%($numinrow);
6313: if ($rem == 0) {
6314: if (($i > 0) && ($i < $numspares-1)) {
6315: $targettable .= '</tr>';
6316: }
6317: if ($i < $numspares-1) {
6318: $targettable .= '<tr>';
1.150 raeburn 6319: }
6320: }
6321: }
1.160.6.7 raeburn 6322: if ($targettable ne '') {
6323: my $rem = $numspares%($numinrow);
6324: my $colsleft = $numinrow - $rem;
6325: if ($colsleft > 1 ) {
6326: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6327: ' </td>';
6328: } elsif ($colsleft == 1) {
6329: $targettable .= '<td class="LC_left_item"> </td>';
6330: }
6331: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6332: '<table><tr>'.$targettable.'</tr></table><br />';
6333: }
1.160.6.76 raeburn 6334: $hostherechecked{$sparetype} = '';
6335: if (ref($currtargets{$lonhost}) eq 'HASH') {
6336: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6337: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6338: $hostherechecked{$sparetype} = ' checked="checked"';
6339: $hostherechecked{'no'} = '';
6340: }
6341: }
6342: }
6343: }
1.160.6.94 raeburn 6344: if ($currcookies{$lonhost}) {
6345: %balcookiechecked = (
6346: yes => ' checked="checked"',
6347: );
6348: }
1.160.6.76 raeburn 6349: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6350: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6351: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6352: foreach my $sparetype (@sparestypes) {
6353: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6354: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6355: '</i></label><br />';
1.160.6.7 raeburn 6356: }
1.160.6.94 raeburn 6357: $datatable .= &mt('Use balancer cookie').'<br />'.
6358: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6359: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6360: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6361: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6362: '</div></td></tr>'.
1.160.6.7 raeburn 6363: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6364: $othertitle,$usertypes,$types,\%servers,
6365: \%currbalancer,$lonhost,
6366: $targets_div_style,$homedom_div_style,
6367: $css_class[$cssidx],$balnum,$islast);
6368: $$rowtotal += $rownum;
6369: $balnum ++;
6370: }
6371: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6372: return $datatable;
6373: }
6374:
6375: sub get_loadbalancers_config {
1.160.6.94 raeburn 6376: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 6377: return unless ((ref($servers) eq 'HASH') &&
6378: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 6379: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6380: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 6381: if (keys(%{$existing}) > 0) {
6382: my $oldlonhost;
6383: foreach my $key (sort(keys(%{$existing}))) {
6384: if ($key eq 'lonhost') {
6385: $oldlonhost = $existing->{'lonhost'};
6386: $currbalancer->{$oldlonhost} = 1;
6387: } elsif ($key eq 'targets') {
6388: if ($oldlonhost) {
6389: $currtargets->{$oldlonhost} = $existing->{'targets'};
6390: }
6391: } elsif ($key eq 'rules') {
6392: if ($oldlonhost) {
6393: $currrules->{$oldlonhost} = $existing->{'rules'};
6394: }
6395: } elsif (ref($existing->{$key}) eq 'HASH') {
6396: $currbalancer->{$key} = 1;
6397: $currtargets->{$key} = $existing->{$key}{'targets'};
6398: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 6399: if ($existing->{$key}{'cookie'}) {
6400: $currcookies->{$key} = 1;
6401: }
1.150 raeburn 6402: }
6403: }
1.160.6.7 raeburn 6404: } else {
6405: my ($balancerref,$targetsref) =
6406: &Apache::lonnet::get_lonbalancer_config($servers);
6407: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6408: foreach my $server (sort(keys(%{$balancerref}))) {
6409: $currbalancer->{$server} = 1;
6410: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6411: }
6412: }
6413: }
1.160.6.7 raeburn 6414: return;
1.150 raeburn 6415: }
6416:
6417: sub loadbalancing_rules {
6418: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 6419: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6420: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6421: my $output;
1.160.6.7 raeburn 6422: my $num = 0;
6423: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6424: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6425: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6426: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 6427: $num ++;
1.150 raeburn 6428: my $current;
6429: if (ref($currrules) eq 'HASH') {
6430: $current = $currrules->{$type};
6431: }
1.160.6.55 raeburn 6432: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 6433: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6434: $current = '';
6435: }
6436: }
6437: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 6438: $servers,$currbalancer,$lonhost,$dom,
6439: $targets_div_style,$homedom_div_style,
6440: $css_class,$balnum,$num,$islast);
1.150 raeburn 6441: }
6442: }
6443: return $output;
6444: }
6445:
6446: sub loadbalancing_titles {
6447: my ($dom,$intdom,$usertypes,$types) = @_;
6448: my %othertypes = (
6449: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6450: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6451: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6452: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 6453: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6454: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6455: );
1.160.6.26 raeburn 6456: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 6457: my @available;
1.150 raeburn 6458: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6459: @available = @{$types};
1.150 raeburn 6460: }
1.160.6.89 raeburn 6461: unless (grep(/^default$/,@available)) {
6462: push(@available,'default');
6463: }
6464: unshift(@alltypes,@available);
1.150 raeburn 6465: my %titles;
6466: foreach my $type (@alltypes) {
6467: if ($type =~ /^_LC_/) {
6468: $titles{$type} = $othertypes{$type};
6469: } elsif ($type eq 'default') {
6470: $titles{$type} = &mt('All users from [_1]',$dom);
6471: if (ref($types) eq 'ARRAY') {
6472: if (@{$types} > 0) {
6473: $titles{$type} = &mt('Other users from [_1]',$dom);
6474: }
6475: }
6476: } elsif (ref($usertypes) eq 'HASH') {
6477: $titles{$type} = $usertypes->{$type};
6478: }
6479: }
6480: return (\@alltypes,\%othertypes,\%titles);
6481: }
6482:
6483: sub loadbalance_rule_row {
1.160.6.7 raeburn 6484: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6485: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 6486: my @rulenames;
1.150 raeburn 6487: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 6488: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 6489: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6490: } else {
1.160.6.26 raeburn 6491: @rulenames = ('default','homeserver');
6492: if ($type eq '_LC_external') {
6493: push(@rulenames,'externalbalancer');
6494: } else {
6495: push(@rulenames,'specific');
6496: }
6497: push(@rulenames,'none');
1.150 raeburn 6498: }
6499: my $style = $targets_div_style;
1.160.6.55 raeburn 6500: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6501: $style = $homedom_div_style;
6502: }
1.160.6.7 raeburn 6503: my $space;
6504: if ($islast && $num == 1) {
6505: $space = '<div display="inline-block"> </div>';
6506: }
6507: my $output =
6508: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
6509: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6510: '<td valaign="top">'.$space.
6511: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6512: for (my $i=0; $i<@rulenames; $i++) {
6513: my $rule = $rulenames[$i];
6514: my ($checked,$extra);
6515: if ($rulenames[$i] eq 'default') {
6516: $rule = '';
6517: }
6518: if ($rulenames[$i] eq 'specific') {
6519: if (ref($servers) eq 'HASH') {
6520: my $default;
6521: if (($current ne '') && (exists($servers->{$current}))) {
6522: $checked = ' checked="checked"';
6523: }
6524: unless ($checked) {
6525: $default = ' selected="selected"';
6526: }
1.160.6.7 raeburn 6527: $extra =
6528: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6529: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6530: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6531: '<option value=""'.$default.'></option>'."\n";
6532: foreach my $server (sort(keys(%{$servers}))) {
6533: if (ref($currbalancer) eq 'HASH') {
6534: next if (exists($currbalancer->{$server}));
6535: }
1.150 raeburn 6536: my $selected;
1.160.6.7 raeburn 6537: if ($server eq $current) {
1.150 raeburn 6538: $selected = ' selected="selected"';
6539: }
1.160.6.7 raeburn 6540: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6541: }
6542: $extra .= '</select>';
6543: }
6544: } elsif ($rule eq $current) {
6545: $checked = ' checked="checked"';
6546: }
6547: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 6548: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6549: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6550: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 6551: ')"'.$checked.' /> ';
1.160.6.56 raeburn 6552: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 6553: $output .= $ruletitles{'particular'};
6554: } else {
6555: $output .= $ruletitles{$rulenames[$i]};
6556: }
6557: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6558: }
6559: $output .= '</div></td></tr>'."\n";
6560: return $output;
6561: }
6562:
6563: sub offloadtype_text {
6564: my %ruletitles = &Apache::lonlocal::texthash (
6565: 'default' => 'Offloads to default destinations',
6566: 'homeserver' => "Offloads to user's home server",
6567: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6568: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 6569: 'none' => 'No offload',
1.160.6.26 raeburn 6570: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6571: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 6572: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6573: );
6574: return %ruletitles;
6575: }
6576:
6577: sub sparestype_titles {
6578: my %typestitles = &Apache::lonlocal::texthash (
6579: 'primary' => 'primary',
6580: 'default' => 'default',
6581: );
6582: return %typestitles;
6583: }
6584:
1.28 raeburn 6585: sub contact_titles {
6586: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 6587: 'supportemail' => 'Support E-mail address',
6588: 'adminemail' => 'Default Server Admin E-mail address',
6589: 'errormail' => 'Error reports to be e-mailed to',
6590: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 6591: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6592: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 6593: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6594: 'requestsmail' => 'E-mail from course requests requiring approval',
6595: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 6596: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 6597: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 6598: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
6599: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 6600: 'errorweights' => 'Weights used to compute error count',
6601: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6602: );
6603: my %short_titles = &Apache::lonlocal::texthash (
6604: adminemail => 'Admin E-mail address',
6605: supportemail => 'Support E-mail',
6606: );
6607: return (\%titles,\%short_titles);
6608: }
6609:
1.160.6.78 raeburn 6610: sub helpform_fields {
6611: my %titles = &Apache::lonlocal::texthash (
6612: 'username' => 'Name',
6613: 'user' => 'Username/domain',
6614: 'phone' => 'Phone',
6615: 'cc' => 'Cc e-mail',
6616: 'course' => 'Course Details',
6617: 'section' => 'Sections',
6618: 'screenshot' => 'File upload',
6619: );
6620: my @fields = ('username','phone','user','course','section','cc','screenshot');
6621: my %possoptions = (
6622: username => ['yes','no','req'],
6623: phone => ['yes','no','req'],
6624: user => ['yes','no'],
6625: cc => ['yes','no'],
6626: course => ['yes','no'],
6627: section => ['yes','no'],
6628: screenshot => ['yes','no'],
6629: );
6630: my %fieldoptions = &Apache::lonlocal::texthash (
6631: 'yes' => 'Optional',
6632: 'req' => 'Required',
6633: 'no' => "Not shown",
6634: );
6635: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6636: }
6637:
1.72 raeburn 6638: sub tool_titles {
6639: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 6640: aboutme => 'Personal web page',
1.86 raeburn 6641: blog => 'Blog',
1.160.6.4 raeburn 6642: webdav => 'WebDAV',
1.86 raeburn 6643: portfolio => 'Portfolio',
1.88 bisitz 6644: official => 'Official courses (with institutional codes)',
6645: unofficial => 'Unofficial courses',
1.98 raeburn 6646: community => 'Communities',
1.160.6.30 raeburn 6647: textbook => 'Textbook courses',
1.86 raeburn 6648: );
1.72 raeburn 6649: return %titles;
6650: }
6651:
1.101 raeburn 6652: sub courserequest_titles {
6653: my %titles = &Apache::lonlocal::texthash (
6654: official => 'Official',
6655: unofficial => 'Unofficial',
6656: community => 'Communities',
1.160.6.30 raeburn 6657: textbook => 'Textbook',
1.101 raeburn 6658: norequest => 'Not allowed',
1.104 raeburn 6659: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6660: validate => 'With validation',
6661: autolimit => 'Numerical limit',
1.103 raeburn 6662: unlimited => '(blank for unlimited)',
1.101 raeburn 6663: );
6664: return %titles;
6665: }
6666:
1.160.6.5 raeburn 6667: sub authorrequest_titles {
6668: my %titles = &Apache::lonlocal::texthash (
6669: norequest => 'Not allowed',
6670: approval => 'Approval by Dom. Coord.',
6671: automatic => 'Automatic approval',
6672: );
6673: return %titles;
6674: }
6675:
1.101 raeburn 6676: sub courserequest_conditions {
6677: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6678: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 6679: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6680: );
6681: return %conditions;
6682: }
6683:
6684:
1.27 raeburn 6685: sub print_usercreation {
1.30 raeburn 6686: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6687: my $numinrow = 4;
1.28 raeburn 6688: my $datatable;
6689: if ($position eq 'top') {
1.30 raeburn 6690: $$rowtotal ++;
1.34 raeburn 6691: my $rowcount = 0;
1.32 raeburn 6692: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6693: if (ref($rules) eq 'HASH') {
6694: if (keys(%{$rules}) > 0) {
1.32 raeburn 6695: $datatable .= &user_formats_row('username',$settings,$rules,
6696: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6697: $$rowtotal ++;
1.32 raeburn 6698: $rowcount ++;
6699: }
6700: }
6701: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6702: if (ref($idrules) eq 'HASH') {
6703: if (keys(%{$idrules}) > 0) {
6704: $datatable .= &user_formats_row('id',$settings,$idrules,
6705: $idruleorder,$numinrow,$rowcount);
6706: $$rowtotal ++;
6707: $rowcount ++;
1.28 raeburn 6708: }
6709: }
1.39 raeburn 6710: if ($rowcount == 0) {
6711: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6712: $$rowtotal ++;
6713: $rowcount ++;
6714: }
1.34 raeburn 6715: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 6716: my @creators = ('author','course','requestcrs');
1.37 raeburn 6717: my ($rules,$ruleorder) =
6718: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6719: my %lt = &usercreation_types();
6720: my %checked;
6721: if (ref($settings) eq 'HASH') {
6722: if (ref($settings->{'cancreate'}) eq 'HASH') {
6723: foreach my $item (@creators) {
6724: $checked{$item} = $settings->{'cancreate'}{$item};
6725: }
6726: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6727: foreach my $item (@creators) {
6728: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6729: $checked{$item} = 'none';
6730: }
6731: }
6732: }
6733: }
6734: my $rownum = 0;
6735: foreach my $item (@creators) {
6736: $rownum ++;
1.160.6.34 raeburn 6737: if ($checked{$item} eq '') {
6738: $checked{$item} = 'any';
1.34 raeburn 6739: }
6740: my $css_class;
6741: if ($rownum%2) {
6742: $css_class = '';
6743: } else {
6744: $css_class = ' class="LC_odd_row" ';
6745: }
6746: $datatable .= '<tr'.$css_class.'>'.
6747: '<td><span class="LC_nobreak">'.$lt{$item}.
6748: '</span></td><td align="right">';
1.160.6.34 raeburn 6749: my @options = ('any');
6750: if (ref($rules) eq 'HASH') {
6751: if (keys(%{$rules}) > 0) {
6752: push(@options,('official','unofficial'));
1.37 raeburn 6753: }
6754: }
1.160.6.34 raeburn 6755: push(@options,'none');
1.37 raeburn 6756: foreach my $option (@options) {
1.50 raeburn 6757: my $type = 'radio';
1.34 raeburn 6758: my $check = ' ';
1.160.6.34 raeburn 6759: if ($checked{$item} eq $option) {
6760: $check = ' checked="checked" ';
1.34 raeburn 6761: }
6762: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6763: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6764: $item.'" value="'.$option.'"'.$check.'/> '.
6765: $lt{$option}.'</label> </span>';
6766: }
6767: $datatable .= '</td></tr>';
6768: }
1.28 raeburn 6769: } else {
6770: my @contexts = ('author','course','domain');
6771: my @authtypes = ('int','krb4','krb5','loc');
6772: my %checked;
6773: if (ref($settings) eq 'HASH') {
6774: if (ref($settings->{'authtypes'}) eq 'HASH') {
6775: foreach my $item (@contexts) {
6776: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6777: foreach my $auth (@authtypes) {
6778: if ($settings->{'authtypes'}{$item}{$auth}) {
6779: $checked{$item}{$auth} = ' checked="checked" ';
6780: }
6781: }
6782: }
6783: }
1.27 raeburn 6784: }
1.35 raeburn 6785: } else {
6786: foreach my $item (@contexts) {
1.36 raeburn 6787: foreach my $auth (@authtypes) {
1.35 raeburn 6788: $checked{$item}{$auth} = ' checked="checked" ';
6789: }
6790: }
1.27 raeburn 6791: }
1.28 raeburn 6792: my %title = &context_names();
6793: my %authname = &authtype_names();
6794: my $rownum = 0;
6795: my $css_class;
6796: foreach my $item (@contexts) {
6797: if ($rownum%2) {
6798: $css_class = '';
6799: } else {
6800: $css_class = ' class="LC_odd_row" ';
6801: }
1.30 raeburn 6802: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6803: '<td>'.$title{$item}.
6804: '</td><td class="LC_left_item">'.
6805: '<span class="LC_nobreak">';
6806: foreach my $auth (@authtypes) {
6807: $datatable .= '<label>'.
6808: '<input type="checkbox" name="'.$item.'_auth" '.
6809: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6810: $authname{$auth}.'</label> ';
6811: }
6812: $datatable .= '</span></td></tr>';
6813: $rownum ++;
1.27 raeburn 6814: }
1.30 raeburn 6815: $$rowtotal += $rownum;
1.27 raeburn 6816: }
6817: return $datatable;
6818: }
6819:
1.160.6.34 raeburn 6820: sub print_selfcreation {
6821: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 6822: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6823: $emaildomain,$datatable);
1.160.6.34 raeburn 6824: if (ref($settings) eq 'HASH') {
6825: if (ref($settings->{'cancreate'}) eq 'HASH') {
6826: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 6827: if (ref($createsettings) eq 'HASH') {
6828: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6829: @selfcreate = @{$createsettings->{'selfcreate'}};
6830: } elsif ($createsettings->{'selfcreate'} ne '') {
6831: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6832: @selfcreate = ('email','login','sso');
6833: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6834: @selfcreate = ($createsettings->{'selfcreate'});
6835: }
6836: }
6837: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6838: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 6839: }
1.160.6.93 raeburn 6840: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6841: $emailoptions = $createsettings->{'emailoptions'};
6842: }
6843: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6844: $emailverified = $createsettings->{'emailverified'};
6845: }
6846: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6847: $emaildomain = $createsettings->{'emaildomain'};
6848: }
1.160.6.34 raeburn 6849: }
6850: }
6851: }
6852: my %radiohash;
6853: my $numinrow = 4;
6854: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 6855: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 6856: if ($position eq 'top') {
6857: my %choices = &Apache::lonlocal::texthash (
6858: cancreate_login => 'Institutional Login',
6859: cancreate_sso => 'Institutional Single Sign On',
6860: );
6861: my @toggles = sort(keys(%choices));
6862: my %defaultchecked = (
6863: 'cancreate_login' => 'off',
6864: 'cancreate_sso' => 'off',
6865: );
1.160.6.35 raeburn 6866: my ($onclick,$itemcount);
1.160.6.34 raeburn 6867: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6868: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 6869: $$rowtotal += $itemcount;
1.160.6.34 raeburn 6870:
6871: if (ref($usertypes) eq 'HASH') {
6872: if (keys(%{$usertypes}) > 0) {
6873: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6874: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 6875: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 6876: $$rowtotal ++;
6877: }
6878: }
1.160.6.44 raeburn 6879: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6880: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6881: $fieldtitles{'inststatus'} = &mt('Institutional status');
6882: my $rem;
6883: my $numperrow = 2;
6884: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6885: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 6886: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 6887: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 6888: '<table>'."\n";
1.160.6.44 raeburn 6889: for (my $i=0; $i<@fields; $i++) {
6890: $rem = $i%($numperrow);
6891: if ($rem == 0) {
6892: if ($i > 0) {
6893: $datatable .= '</tr>';
6894: }
6895: $datatable .= '<tr>';
6896: }
6897: my $currval;
1.160.6.51 raeburn 6898: if (ref($createsettings) eq 'HASH') {
6899: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6900: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6901: }
1.160.6.44 raeburn 6902: }
6903: $datatable .= '<td class="LC_left_item">'.
6904: '<span class="LC_nobreak">'.
6905: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6906: 'value="'.$currval.'" size="10" /> '.
6907: $fieldtitles{$fields[$i]}.'</span></td>';
6908: }
6909: my $colsleft = $numperrow - $rem;
6910: if ($colsleft > 1 ) {
6911: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6912: ' </td>';
6913: } elsif ($colsleft == 1) {
6914: $datatable .= '<td class="LC_left_item"> </td>';
6915: }
6916: $datatable .= '</tr></table></td></tr>';
6917: $$rowtotal ++;
1.160.6.34 raeburn 6918: } elsif ($position eq 'middle') {
6919: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 6920: my @posstypes;
1.160.6.34 raeburn 6921: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6922: @posstypes = @{$types};
6923: }
6924: unless (grep(/^default$/,@posstypes)) {
6925: push(@posstypes,'default');
6926: }
6927: my %usertypeshash;
6928: if (ref($usertypes) eq 'HASH') {
6929: %usertypeshash = %{$usertypes};
6930: }
6931: $usertypeshash{'default'} = $othertitle;
6932: foreach my $status (@posstypes) {
6933: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6934: $numinrow,$$rowtotal,\%usertypeshash);
6935: $$rowtotal ++;
1.160.6.34 raeburn 6936: }
6937: } else {
1.160.6.40 raeburn 6938: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 6939: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 6940: );
6941: my @toggles = sort(keys(%choices));
6942: my %defaultchecked = (
6943: 'cancreate_email' => 'off',
6944: );
1.160.6.93 raeburn 6945: my $customclass = 'LC_selfcreate_email';
6946: my $classprefix = 'LC_canmodify_emailusername_';
6947: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 6948: my $display = 'none';
1.160.6.93 raeburn 6949: my $rowstyle = 'display:none';
1.160.6.40 raeburn 6950: if (grep(/^\Qemail\E$/,@selfcreate)) {
6951: $display = 'block';
1.160.6.93 raeburn 6952: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 6953: }
1.160.6.93 raeburn 6954: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6955: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6956: \%choices,$$rowtotal,$onclick);
6957: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6958: $rowstyle);
6959: $$rowtotal ++;
6960: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6961: $rowstyle);
6962: $$rowtotal ++;
6963: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 6964: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 6965: my ($emailrules,$emailruleorder) =
6966: &Apache::lonnet::inst_userrules($dom,'email');
6967: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6968: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6969: if (ref($types) eq 'ARRAY') {
6970: @posstypes = @{$types};
6971: }
6972: if (@posstypes) {
6973: unless (grep(/^default$/,@posstypes)) {
6974: push(@posstypes,'default');
1.160.6.89 raeburn 6975: }
6976: if (ref($usertypes) eq 'HASH') {
6977: %usertypeshash = %{$usertypes};
6978: }
1.160.6.93 raeburn 6979: my $currassign;
6980: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6981: $currassign = {
6982: selfassign => $domdefaults{'inststatusguest'},
6983: };
6984: @ordered = @{$domdefaults{'inststatusguest'}};
6985: } else {
6986: $currassign = { selfassign => [] };
6987: }
6988: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6989: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6990: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6991: $numinrow,$othertitle,'selfassign',
6992: $rowtotal,$onclicktypes,$customclass,
6993: $rowstyle);
6994: $$rowtotal ++;
1.160.6.89 raeburn 6995: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6996: foreach my $status (@posstypes) {
6997: my $css_class;
6998: if ($$rowtotal%2) {
6999: $css_class = 'LC_odd_row ';
7000: }
7001: $css_class .= $customclass;
7002: my $rowid = $optionsprefix.$status;
7003: my $hidden = 1;
7004: my $currstyle = 'display:none';
7005: if (grep(/^\Q$status\E$/,@ordered)) {
7006: $currstyle = $rowstyle;
7007: $hidden = 0;
7008: }
7009: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7010: $emailrules,$emailruleorder,$settings,$status,$rowid,
7011: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7012: unless ($hidden) {
7013: $$rowtotal ++;
7014: }
1.160.6.89 raeburn 7015: }
7016: } else {
1.160.6.93 raeburn 7017: my $css_class;
7018: if ($$rowtotal%2) {
7019: $css_class = 'LC_odd_row ';
7020: }
7021: $css_class .= $customclass;
1.160.6.89 raeburn 7022: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7023: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7024: $emailrules,$emailruleorder,$settings,'default','',
7025: $othertitle,$css_class,$rowstyle,$intdom);
7026: $$rowtotal ++;
1.160.6.34 raeburn 7027: }
1.160.6.35 raeburn 7028: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7029: $numinrow = 1;
1.160.6.93 raeburn 7030: if (@posstypes) {
7031: foreach my $status (@posstypes) {
7032: my $rowid = $classprefix.$status;
7033: my $datarowstyle = 'display:none';
7034: if (grep(/^\Q$status\E$/,@ordered)) {
7035: $datarowstyle = $rowstyle;
7036: }
7037: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7038: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7039: $infotitles,$rowid,$customclass,$datarowstyle);
7040: unless ($datarowstyle eq 'display:none') {
7041: $$rowtotal ++;
7042: }
1.160.6.34 raeburn 7043: }
1.160.6.93 raeburn 7044: } else {
7045: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7046: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7047: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 7048: }
7049: }
7050: return $datatable;
7051: }
7052:
1.160.6.93 raeburn 7053: sub selfcreate_javascript {
7054: return <<"ENDSCRIPT";
7055:
7056: <script type="text/javascript">
7057: // <![CDATA[
7058:
7059: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7060: var x = document.getElementsByClassName(target);
7061: var insttypes = 0;
7062: var insttypeRegExp = new RegExp(prefix);
7063: if ((x.length != undefined) && (x.length > 0)) {
7064: if (form.elements[radio].length != undefined) {
7065: for (var i=0; i<form.elements[radio].length; i++) {
7066: if (form.elements[radio][i].checked) {
7067: if (form.elements[radio][i].value == 1) {
7068: for (var j=0; j<x.length; j++) {
7069: if (x[j].id == 'undefined') {
7070: x[j].style.display = 'table-row';
7071: } else if (insttypeRegExp.test(x[j].id)) {
7072: insttypes ++;
7073: } else {
7074: x[j].style.display = 'table-row';
7075: }
7076: }
7077: } else {
7078: for (var j=0; j<x.length; j++) {
7079: x[j].style.display = 'none';
7080: }
1.160.6.40 raeburn 7081: }
1.160.6.93 raeburn 7082: break;
7083: }
7084: }
7085: if (insttypes > 0) {
7086: toggleDataRow(form,checkbox,target,altprefix);
7087: toggleDataRow(form,checkbox,target,prefix,1);
7088: }
7089: }
7090: }
7091: return;
7092: }
7093:
7094: function toggleDataRow(form,checkbox,target,prefix,docount) {
7095: if (form.elements[checkbox].length != undefined) {
7096: var count = 0;
7097: if (docount) {
7098: for (var i=0; i<form.elements[checkbox].length; i++) {
7099: if (form.elements[checkbox][i].checked) {
7100: count ++;
7101: }
7102: }
7103: }
7104: for (var i=0; i<form.elements[checkbox].length; i++) {
7105: var type = form.elements[checkbox][i].value;
7106: if (document.getElementById(prefix+type)) {
7107: if (form.elements[checkbox][i].checked) {
7108: document.getElementById(prefix+type).style.display = 'table-row';
7109: if (count % 2 == 1) {
7110: document.getElementById(prefix+type).className = target+' LC_odd_row';
7111: } else {
7112: document.getElementById(prefix+type).className = target;
7113: }
7114: count ++;
1.160.6.40 raeburn 7115: } else {
1.160.6.93 raeburn 7116: document.getElementById(prefix+type).style.display = 'none';
7117: }
7118: }
7119: }
7120: }
7121: return;
7122: }
7123:
7124: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7125: var caller = radio+'_'+status;
7126: if (form.elements[caller].length != undefined) {
7127: for (var i=0; i<form.elements[caller].length; i++) {
7128: if (form.elements[caller][i].checked) {
7129: if (document.getElementById(altprefix+'_inst_'+status)) {
7130: var curr = form.elements[caller][i].value;
7131: if (prefix) {
7132: document.getElementById(prefix+'_'+status).style.display = 'none';
7133: }
7134: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7135: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7136: if (curr == 'custom') {
7137: if (prefix) {
7138: document.getElementById(prefix+'_'+status).style.display = 'inline';
7139: }
7140: } else if (curr == 'inst') {
7141: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7142: } else if (curr == 'noninst') {
7143: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 7144: }
1.160.6.93 raeburn 7145: break;
1.160.6.40 raeburn 7146: }
1.160.6.93 raeburn 7147: }
7148: }
7149: }
7150: }
7151:
7152: // ]]>
7153: </script>
7154:
7155: ENDSCRIPT
7156: }
7157:
7158: sub noninst_users {
7159: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7160: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7161: my $class = 'LC_left_item';
7162: if ($css_class) {
7163: $css_class = ' class="'.$css_class.'"';
7164: }
7165: if ($rowid) {
7166: $rowid = ' id="'.$rowid.'"';
7167: }
7168: if ($rowstyle) {
7169: $rowstyle = ' style="'.$rowstyle.'"';
7170: }
7171: my ($output,$description);
7172: if ($type eq 'default') {
7173: $description = &mt('Requests for: [_1]',$typetitle);
7174: } else {
7175: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7176: }
7177: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7178: "<td>$description</td>\n".
7179: '<td class="'.$class.'" colspan="2">'.
7180: '<table><tr>';
7181: my %headers = &Apache::lonlocal::texthash(
7182: approve => 'Processing',
7183: email => 'E-mail',
7184: username => 'Username',
7185: );
7186: foreach my $item ('approve','email','username') {
7187: $output .= '<th>'.$headers{$item}.'</th>';
7188: }
7189: $output .= '</tr><tr>';
7190: foreach my $item ('approve','email','username') {
7191: $output .= '<td valign="top">';
7192: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7193: if ($item eq 'approve') {
7194: %choices = &Apache::lonlocal::texthash (
7195: automatic => 'Automatically approved',
7196: approval => 'Queued for approval',
7197: );
7198: @options = ('automatic','approval');
7199: $hashref = $processing;
7200: $defoption = 'automatic';
7201: $name = 'cancreate_emailprocess_'.$type;
7202: } elsif ($item eq 'email') {
7203: %choices = &Apache::lonlocal::texthash (
7204: any => 'Any e-mail',
7205: inst => 'Institutional only',
7206: noninst => 'Non-institutional only',
7207: custom => 'Custom restrictions',
7208: );
7209: @options = ('any','inst','noninst');
7210: my $showcustom;
7211: if (ref($emailrules) eq 'HASH') {
7212: if (keys(%{$emailrules}) > 0) {
7213: push(@options,'custom');
7214: $showcustom = 'cancreate_emailrule';
7215: if (ref($settings) eq 'HASH') {
7216: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7217: foreach my $rule (@{$settings->{'email_rule'}}) {
7218: if (exists($emailrules->{$rule})) {
7219: $hascustom ++;
7220: }
7221: }
7222: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7223: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7224: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7225: if (exists($emailrules->{$rule})) {
7226: $hascustom ++;
7227: }
7228: }
7229: }
7230: }
7231: }
7232: }
7233: }
7234: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7235: "'cancreate_emaildomain','$type'".');"';
7236: $hashref = $emailoptions;
7237: $defoption = 'any';
7238: $name = 'cancreate_emailoptions_'.$type;
7239: } elsif ($item eq 'username') {
7240: %choices = &Apache::lonlocal::texthash (
7241: all => 'Same as e-mail',
7242: first => 'Omit @domain',
7243: free => 'Free to choose',
7244: );
7245: @options = ('all','first','free');
7246: $hashref = $emailverified;
7247: $defoption = 'all';
7248: $name = 'cancreate_usernameoptions_'.$type;
7249: }
7250: foreach my $option (@options) {
7251: my $checked;
7252: if (ref($hashref) eq 'HASH') {
7253: if ($type eq '') {
7254: if (!exists($hashref->{'default'})) {
7255: if ($option eq $defoption) {
7256: $checked = ' checked="checked"';
7257: }
7258: } else {
7259: if ($hashref->{'default'} eq $option) {
7260: $checked = ' checked="checked"';
7261: }
1.160.6.40 raeburn 7262: }
7263: } else {
1.160.6.93 raeburn 7264: if (!exists($hashref->{$type})) {
7265: if ($option eq $defoption) {
7266: $checked = ' checked="checked"';
7267: }
7268: } else {
7269: if ($hashref->{$type} eq $option) {
7270: $checked = ' checked="checked"';
7271: }
1.160.6.40 raeburn 7272: }
7273: }
1.160.6.93 raeburn 7274: } elsif (($item eq 'email') && ($hascustom)) {
7275: if ($option eq 'custom') {
7276: $checked = ' checked="checked"';
7277: }
7278: } elsif ($option eq $defoption) {
7279: $checked = ' checked="checked"';
7280: }
7281: $output .= '<span class="LC_nobreak"><label>'.
7282: '<input type="radio" name="'.$name.'"'.
7283: $checked.' value="'.$option.'"'.$onclick.' />'.
7284: $choices{$option}.'</label></span><br />';
7285: if ($item eq 'email') {
7286: if ($option eq 'custom') {
7287: my $id = 'cancreate_emailrule_'.$type;
7288: my $display = 'none';
7289: if ($checked) {
7290: $display = 'inline';
7291: }
7292: my $numinrow = 2;
7293: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7294: '<legend>'.&mt('Disallow').'</legend><table>'.
7295: &user_formats_row('email',$settings,$emailrules,
7296: $emailruleorder,$numinrow,'',$type);
7297: '</table></fieldset>';
7298: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7299: my %text = &Apache::lonlocal::texthash (
7300: inst => 'must end:',
7301: noninst => 'cannot end:',
7302: );
7303: my $value;
7304: if (ref($emaildomain) eq 'HASH') {
7305: if (ref($emaildomain->{$type}) eq 'HASH') {
7306: $value = $emaildomain->{$type}->{$option};
7307: }
7308: }
7309: if ($value eq '') {
7310: $value = '@'.$intdom;
7311: }
7312: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7313: my $display = 'none';
7314: if ($checked) {
7315: $display = 'inline';
7316: }
7317: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7318: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7319: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7320: '</div>';
7321: }
1.160.6.40 raeburn 7322: }
7323: }
1.160.6.93 raeburn 7324: $output .= '</td>'."\n";
1.160.6.40 raeburn 7325: }
1.160.6.93 raeburn 7326: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 7327: return $output;
7328: }
7329:
1.160.6.5 raeburn 7330: sub captcha_choice {
1.160.6.93 raeburn 7331: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 7332: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7333: $vertext,$currver);
1.160.6.5 raeburn 7334: my %lt = &captcha_phrases();
7335: $keyentry = 'hidden';
1.160.6.98 raeburn 7336: my $colspan=2;
1.160.6.5 raeburn 7337: if ($context eq 'cancreate') {
1.160.6.34 raeburn 7338: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 7339: } elsif ($context eq 'login') {
7340: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 7341: } elsif ($context eq 'passwords') {
7342: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7343: $colspan=1;
1.160.6.5 raeburn 7344: }
7345: if (ref($settings) eq 'HASH') {
7346: if ($settings->{'captcha'}) {
7347: $checked{$settings->{'captcha'}} = ' checked="checked"';
7348: } else {
7349: $checked{'original'} = ' checked="checked"';
7350: }
7351: if ($settings->{'captcha'} eq 'recaptcha') {
7352: $pubtext = $lt{'pub'};
7353: $privtext = $lt{'priv'};
7354: $keyentry = 'text';
1.160.6.69 raeburn 7355: $vertext = $lt{'ver'};
7356: $currver = $settings->{'recaptchaversion'};
7357: if ($currver ne '2') {
7358: $currver = 1;
7359: }
1.160.6.5 raeburn 7360: }
7361: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7362: $currpub = $settings->{'recaptchakeys'}{'public'};
7363: $currpriv = $settings->{'recaptchakeys'}{'private'};
7364: }
7365: } else {
7366: $checked{'original'} = ' checked="checked"';
7367: }
1.160.6.93 raeburn 7368: my $css_class;
7369: if ($itemcount%2) {
7370: $css_class = 'LC_odd_row';
7371: }
7372: if ($customcss) {
7373: $css_class .= " $customcss";
7374: }
7375: $css_class =~ s/^\s+//;
7376: if ($css_class) {
7377: $css_class = ' class="'.$css_class.'"';
7378: }
7379: if ($rowstyle) {
7380: $css_class .= ' style="'.$rowstyle.'"';
7381: }
1.160.6.5 raeburn 7382: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 7383: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 7384: '<table><tr><td>'."\n";
7385: foreach my $option ('original','recaptcha','notused') {
7386: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7387: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7388: $lt{$option}.'</label></span>';
7389: unless ($option eq 'notused') {
7390: $output .= (' 'x2)."\n";
7391: }
7392: }
7393: #
7394: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7395: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
7396: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
7397: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
7398: #
7399: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 7400: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 7401: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7402: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7403: $currpub.'" size="40" /></span><br />'."\n".
7404: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7405: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 7406: $currpriv.'" size="40" /></span><br />'.
7407: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7408: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7409: $currver.'" size="3" /></span><br />'.
7410: '</td></tr></table>'."\n".
1.160.6.5 raeburn 7411: '</td></tr>';
7412: return $output;
7413: }
7414:
1.32 raeburn 7415: sub user_formats_row {
1.160.6.93 raeburn 7416: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7417: my $output;
7418: my %text = (
7419: 'username' => 'new usernames',
7420: 'id' => 'IDs',
7421: );
1.160.6.122 raeburn 7422: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 7423: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7424: $output = '<tr '.$css_class.'>'.
7425: '<td><span class="LC_nobreak">'.
7426: &mt("Format rules to check for $text{$type}: ").
7427: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7428: }
1.27 raeburn 7429: my $rem;
7430: if (ref($ruleorder) eq 'ARRAY') {
7431: for (my $i=0; $i<@{$ruleorder}; $i++) {
7432: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7433: my $rem = $i%($numinrow);
7434: if ($rem == 0) {
7435: if ($i > 0) {
7436: $output .= '</tr>';
7437: }
7438: $output .= '<tr>';
7439: }
7440: my $check = ' ';
1.39 raeburn 7441: if (ref($settings) eq 'HASH') {
7442: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7443: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7444: $check = ' checked="checked" ';
7445: }
1.160.6.93 raeburn 7446: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7447: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7448: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7449: $check = ' checked="checked" ';
7450: }
7451: }
1.27 raeburn 7452: }
7453: }
1.160.6.93 raeburn 7454: my $name = $type.'_rule';
7455: if ($type eq 'email') {
7456: $name .= '_'.$status;
7457: }
1.27 raeburn 7458: $output .= '<td class="LC_left_item">'.
7459: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 7460: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7461: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7462: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7463: }
7464: }
7465: $rem = @{$ruleorder}%($numinrow);
7466: }
1.160.6.93 raeburn 7467: my $colsleft;
7468: if ($rem) {
7469: $colsleft = $numinrow - $rem;
7470: }
1.27 raeburn 7471: if ($colsleft > 1 ) {
7472: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7473: ' </td>';
7474: } elsif ($colsleft == 1) {
7475: $output .= '<td class="LC_left_item"> </td>';
7476: }
1.160.6.122 raeburn 7477: $output .= '</tr>';
7478: unless (($type eq 'email') || ($type eq 'unamemap')) {
7479: $output .= '</table></td></tr>';
1.160.6.93 raeburn 7480: }
1.27 raeburn 7481: return $output;
7482: }
7483:
1.34 raeburn 7484: sub usercreation_types {
7485: my %lt = &Apache::lonlocal::texthash (
7486: author => 'When adding a co-author',
7487: course => 'When adding a user to a course',
1.100 raeburn 7488: requestcrs => 'When requesting a course',
1.34 raeburn 7489: any => 'Any',
7490: official => 'Institutional only ',
7491: unofficial => 'Non-institutional only',
7492: none => 'None',
7493: );
7494: return %lt;
1.48 raeburn 7495: }
1.34 raeburn 7496:
1.160.6.34 raeburn 7497: sub selfcreation_types {
7498: my %lt = &Apache::lonlocal::texthash (
7499: selfcreate => 'User creates own account',
7500: any => 'Any',
7501: official => 'Institutional only ',
7502: unofficial => 'Non-institutional only',
7503: email => 'E-mail address',
7504: login => 'Institutional Login',
7505: sso => 'SSO',
7506: );
7507: }
7508:
1.28 raeburn 7509: sub authtype_names {
7510: my %lt = &Apache::lonlocal::texthash(
7511: int => 'Internal',
7512: krb4 => 'Kerberos 4',
7513: krb5 => 'Kerberos 5',
7514: loc => 'Local',
7515: );
7516: return %lt;
7517: }
7518:
7519: sub context_names {
7520: my %context_title = &Apache::lonlocal::texthash(
7521: author => 'Creating users when an Author',
7522: course => 'Creating users when in a course',
7523: domain => 'Creating users when a Domain Coordinator',
7524: );
7525: return %context_title;
7526: }
7527:
1.33 raeburn 7528: sub print_usermodification {
7529: my ($position,$dom,$settings,$rowtotal) = @_;
7530: my $numinrow = 4;
7531: my ($context,$datatable,$rowcount);
7532: if ($position eq 'top') {
7533: $rowcount = 0;
7534: $context = 'author';
7535: foreach my $role ('ca','aa') {
7536: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7537: $numinrow,$rowcount);
7538: $$rowtotal ++;
7539: $rowcount ++;
7540: }
1.160.6.37 raeburn 7541: } elsif ($position eq 'bottom') {
1.33 raeburn 7542: $context = 'course';
7543: $rowcount = 0;
7544: foreach my $role ('st','ep','ta','in','cr') {
7545: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7546: $numinrow,$rowcount);
7547: $$rowtotal ++;
7548: $rowcount ++;
7549: }
7550: }
7551: return $datatable;
7552: }
7553:
1.43 raeburn 7554: sub print_defaults {
1.160.6.40 raeburn 7555: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7556: my $rownum = 0;
1.160.6.80 raeburn 7557: my ($datatable,$css_class,$titles);
7558: unless ($position eq 'bottom') {
7559: $titles = &defaults_titles($dom);
7560: }
1.160.6.40 raeburn 7561: if ($position eq 'top') {
7562: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7563: 'datelocale_def','portal_def');
7564: my %defaults;
7565: if (ref($settings) eq 'HASH') {
7566: %defaults = %{$settings};
1.43 raeburn 7567: } else {
1.160.6.40 raeburn 7568: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7569: foreach my $item (@items) {
7570: $defaults{$item} = $domdefaults{$item};
7571: }
1.43 raeburn 7572: }
1.160.6.40 raeburn 7573: foreach my $item (@items) {
7574: if ($rownum%2) {
7575: $css_class = '';
7576: } else {
7577: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 7578: }
1.160.6.40 raeburn 7579: $datatable .= '<tr'.$css_class.'>'.
7580: '<td><span class="LC_nobreak">'.$titles->{$item}.
7581: '</span></td><td class="LC_right_item" colspan="3">';
7582: if ($item eq 'auth_def') {
7583: my @authtypes = ('internal','krb4','krb5','localauth');
7584: my %shortauth = (
7585: internal => 'int',
7586: krb4 => 'krb4',
7587: krb5 => 'krb5',
7588: localauth => 'loc'
7589: );
7590: my %authnames = &authtype_names();
7591: foreach my $auth (@authtypes) {
7592: my $checked = ' ';
7593: if ($defaults{$item} eq $auth) {
7594: $checked = ' checked="checked" ';
7595: }
7596: $datatable .= '<label><input type="radio" name="'.$item.
7597: '" value="'.$auth.'"'.$checked.'/>'.
7598: $authnames{$shortauth{$auth}}.'</label> ';
7599: }
7600: } elsif ($item eq 'timezone_def') {
7601: my $includeempty = 1;
7602: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7603: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 7604: my $includeempty = 1;
7605: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7606: } elsif ($item eq 'lang_def') {
7607: my $includeempty = 1;
7608: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 7609: } else {
1.160.6.98 raeburn 7610: my $size;
7611: if ($item eq 'portal_def') {
7612: $size = ' size="25"';
7613: }
1.160.6.80 raeburn 7614: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 7615: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 7616: }
7617: $datatable .= '</td></tr>';
7618: $rownum ++;
7619: }
1.160.6.122 raeburn 7620: } elsif ($position eq 'middle') {
1.160.6.80 raeburn 7621: my %defaults;
1.160.6.40 raeburn 7622: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 7623: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 7624: my $maxnum = @{$settings->{'inststatusorder'}};
7625: for (my $i=0; $i<$maxnum; $i++) {
7626: $css_class = $rownum%2?' class="LC_odd_row"':'';
7627: my $item = $settings->{'inststatusorder'}->[$i];
7628: my $title = $settings->{'inststatustypes'}->{$item};
7629: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7630: $datatable .= '<tr'.$css_class.'>'.
7631: '<td><span class="LC_nobreak">'.
7632: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7633: for (my $k=0; $k<=$maxnum; $k++) {
7634: my $vpos = $k+1;
7635: my $selstr;
7636: if ($k == $i) {
7637: $selstr = ' selected="selected" ';
7638: }
7639: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7640: }
7641: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7642: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7643: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 7644: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 7645: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 7646: '</span></td></tr>';
1.160.6.40 raeburn 7647: }
7648: $css_class = $rownum%2?' class="LC_odd_row"':'';
7649: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7650: $datatable .= '<tr '.$css_class.'>'.
7651: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7652: for (my $k=0; $k<=$maxnum; $k++) {
7653: my $vpos = $k+1;
7654: my $selstr;
7655: if ($k == $maxnum) {
7656: $selstr = ' selected="selected" ';
7657: }
7658: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7659: }
7660: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 7661: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 7662: ' '.&mt('(new)').
7663: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 7664: &mt('Name displayed').':'.
1.160.6.40 raeburn 7665: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7666: '</tr>'."\n";
7667: $rownum ++;
1.141 raeburn 7668: }
1.43 raeburn 7669: }
1.160.6.122 raeburn 7670: } else {
7671: my ($unamemaprules,$ruleorder) =
7672: &Apache::lonnet::inst_userrules($dom,'unamemap');
7673: $css_class = $rownum%2?' class="LC_odd_row"':'';
7674: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7675: my $numinrow = 2;
7676: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
7677: &user_formats_row('unamemap',$settings,$unamemaprules,
7678: $ruleorder,$numinrow).
7679: '</table></td></tr>';
7680: }
7681: if ($datatable eq '') {
7682: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
7683: &mt('No rules set for domain in customized localenroll.pm').
7684: '</td></tr>';
7685: }
1.43 raeburn 7686: }
7687: $$rowtotal += $rownum;
7688: return $datatable;
7689: }
7690:
1.160.6.5 raeburn 7691: sub get_languages_hash {
7692: my %langchoices;
7693: foreach my $id (&Apache::loncommon::languageids()) {
7694: my $code = &Apache::loncommon::supportedlanguagecode($id);
7695: if ($code ne '') {
7696: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7697: }
7698: }
7699: return %langchoices;
7700: }
7701:
1.43 raeburn 7702: sub defaults_titles {
1.141 raeburn 7703: my ($dom) = @_;
1.43 raeburn 7704: my %titles = &Apache::lonlocal::texthash (
7705: 'auth_def' => 'Default authentication type',
7706: 'auth_arg_def' => 'Default authentication argument',
7707: 'lang_def' => 'Default language',
1.54 raeburn 7708: 'timezone_def' => 'Default timezone',
1.68 raeburn 7709: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7710: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 7711: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7712: 'intauth_check' => 'Check bcrypt cost if authenticated',
7713: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7714: );
1.141 raeburn 7715: if ($dom) {
7716: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7717: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7718: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7719: $protocol = 'http' if ($protocol ne 'https');
7720: if ($uint_dom) {
7721: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7722: $uint_dom);
7723: }
7724: }
1.43 raeburn 7725: return (\%titles);
7726: }
7727:
1.160.6.97 raeburn 7728: sub print_scantron {
7729: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7730: if ($position eq 'top') {
7731: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7732: } else {
7733: return &print_scantronconfig($dom,$settings,\$rowtotal);
7734: }
7735: }
7736:
7737: sub scantron_javascript {
7738: return <<"ENDSCRIPT";
7739:
7740: <script type="text/javascript">
7741: // <![CDATA[
7742:
7743: function toggleScantron(form) {
7744: var csvfieldset = new Array();
7745: if (document.getElementById('scantroncsv_cols')) {
7746: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7747: }
7748: if (document.getElementById('scantroncsv_options')) {
7749: csvfieldset.push(document.getElementById('scantroncsv_options'));
7750: }
7751: if (csvfieldset.length) {
7752: if (document.getElementById('scantronconfcsv')) {
7753: var scantroncsv = document.getElementById('scantronconfcsv');
7754: if (scantroncsv.checked) {
7755: for (var i=0; i<csvfieldset.length; i++) {
7756: csvfieldset[i].style.display = 'block';
7757: }
7758: } else {
7759: for (var i=0; i<csvfieldset.length; i++) {
7760: csvfieldset[i].style.display = 'none';
7761: }
7762: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7763: if (csvselects.length) {
7764: for (var j=0; j<csvselects.length; j++) {
7765: csvselects[j].selectedIndex = 0;
7766: }
7767: }
7768: }
7769: }
7770: }
7771: return;
7772: }
7773: // ]]>
7774: </script>
7775:
7776: ENDSCRIPT
7777:
7778: }
7779:
1.46 raeburn 7780: sub print_scantronformat {
7781: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7782: my $itemcount = 1;
1.60 raeburn 7783: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7784: %confhash);
1.46 raeburn 7785: my $switchserver = &check_switchserver($dom,$confname);
7786: my %lt = &Apache::lonlocal::texthash (
1.95 www 7787: default => 'Default bubblesheet format file error',
7788: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7789: );
7790: my %scantronfiles = (
7791: default => 'default.tab',
7792: custom => 'custom.tab',
7793: );
7794: foreach my $key (keys(%scantronfiles)) {
7795: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7796: .$scantronfiles{$key};
7797: }
7798: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7799: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7800: if (!$switchserver) {
7801: my $servadm = $r->dir_config('lonAdmEMail');
7802: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7803: if ($configuserok eq 'ok') {
7804: if ($author_ok eq 'ok') {
7805: my %legacyfile = (
1.160.6.97 raeburn 7806: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7807: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 7808: );
7809: my %md5chk;
7810: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7811: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7812: chomp($md5chk{$type});
1.46 raeburn 7813: }
7814: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7815: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 7816: ($scantronurls{$type},my $error) =
1.46 raeburn 7817: &legacy_scantronformat($r,$dom,$confname,
7818: $type,$legacyfile{$type},
7819: $scantronurls{$type},
7820: $scantronfiles{$type});
1.60 raeburn 7821: if ($error ne '') {
7822: $error{$type} = $error;
7823: }
7824: }
7825: if (keys(%error) == 0) {
7826: $is_custom = 1;
1.160.6.97 raeburn 7827: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 7828: $scantronurls{'custom'};
1.160.6.97 raeburn 7829: my $putresult =
1.60 raeburn 7830: &Apache::lonnet::put_dom('configuration',
7831: \%confhash,$dom);
7832: if ($putresult ne 'ok') {
1.160.6.97 raeburn 7833: $error{'custom'} =
1.60 raeburn 7834: '<span class="LC_error">'.
7835: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7836: }
1.46 raeburn 7837: }
7838: } else {
1.60 raeburn 7839: ($scantronurls{'default'},my $error) =
1.46 raeburn 7840: &legacy_scantronformat($r,$dom,$confname,
7841: 'default',$legacyfile{'default'},
7842: $scantronurls{'default'},
7843: $scantronfiles{'default'});
1.60 raeburn 7844: if ($error eq '') {
7845: $confhash{'scantron'}{'scantronformat'} = '';
7846: my $putresult =
7847: &Apache::lonnet::put_dom('configuration',
7848: \%confhash,$dom);
7849: if ($putresult ne 'ok') {
7850: $error{'default'} =
7851: '<span class="LC_error">'.
7852: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7853: }
7854: } else {
7855: $error{'default'} = $error;
7856: }
1.46 raeburn 7857: }
7858: }
7859: }
7860: } else {
1.95 www 7861: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7862: }
7863: }
7864: if (ref($settings) eq 'HASH') {
7865: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7866: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7867: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7868: $scantronurl = '';
7869: } else {
7870: $scantronurl = $settings->{'scantronformat'};
7871: }
7872: $is_custom = 1;
7873: } else {
7874: $scantronurl = $scantronurls{'default'};
7875: }
7876: } else {
1.60 raeburn 7877: if ($is_custom) {
7878: $scantronurl = $scantronurls{'custom'};
7879: } else {
7880: $scantronurl = $scantronurls{'default'};
7881: }
1.46 raeburn 7882: }
7883: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7884: $datatable .= '<tr'.$css_class.'>';
7885: if (!$is_custom) {
1.65 raeburn 7886: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7887: '<span class="LC_nobreak">';
1.46 raeburn 7888: if ($scantronurl) {
1.160.6.21 raeburn 7889: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7890: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7891: } else {
7892: $datatable = &mt('File unavailable for display');
7893: }
1.65 raeburn 7894: $datatable .= '</span></td>';
1.60 raeburn 7895: if (keys(%error) == 0) {
7896: $datatable .= '<td valign="bottom">';
7897: if (!$switchserver) {
7898: $datatable .= &mt('Upload:').'<br />';
7899: }
7900: } else {
7901: my $errorstr;
7902: foreach my $key (sort(keys(%error))) {
7903: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7904: }
7905: $datatable .= '<td>'.$errorstr;
7906: }
1.46 raeburn 7907: } else {
7908: if (keys(%error) > 0) {
7909: my $errorstr;
7910: foreach my $key (sort(keys(%error))) {
7911: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7912: }
1.60 raeburn 7913: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7914: } elsif ($scantronurl) {
1.160.6.26 raeburn 7915: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 7916: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7917: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 7918: $link.
7919: '<label><input type="checkbox" name="scantronformat_del"'.
7920: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7921: '<td><span class="LC_nobreak"> '.
7922: &mt('Replace:').'</span><br />';
1.46 raeburn 7923: }
7924: }
7925: if (keys(%error) == 0) {
7926: if ($switchserver) {
7927: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7928: } else {
1.65 raeburn 7929: $datatable .='<span class="LC_nobreak"> '.
7930: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7931: }
7932: }
7933: $datatable .= '</td></tr>';
7934: $$rowtotal ++;
7935: return $datatable;
7936: }
7937:
7938: sub legacy_scantronformat {
7939: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7940: my ($url,$error);
7941: my @statinfo = &Apache::lonnet::stat_file($newurl);
7942: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7943: (my $result,$url) =
7944: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7945: '','',$newfile);
7946: if ($result ne 'ok') {
1.130 raeburn 7947: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7948: }
7949: }
7950: return ($url,$error);
7951: }
1.43 raeburn 7952:
1.160.6.97 raeburn 7953: sub print_scantronconfig {
7954: my ($dom,$settings,$rowtotal) = @_;
7955: my $itemcount = 2;
7956: my $is_checked = ' checked="checked"';
7957: my %optionson = (
7958: hdr => ' checked="checked"',
7959: pad => ' checked="checked"',
7960: rem => ' checked="checked"',
7961: );
7962: my %optionsoff = (
7963: hdr => '',
7964: pad => '',
7965: rem => '',
7966: );
7967: my $currcsvsty = 'none';
7968: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7969: my @fields = &scantroncsv_fields();
7970: my %titles = &scantronconfig_titles();
7971: if (ref($settings) eq 'HASH') {
7972: if (ref($settings->{config}) eq 'HASH') {
7973: if ($settings->{config}->{dat}) {
7974: $checked{'dat'} = $is_checked;
7975: }
7976: if (ref($settings->{config}->{csv}) eq 'HASH') {
7977: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7978: %csvfields = %{$settings->{config}->{csv}->{fields}};
7979: if (keys(%csvfields) > 0) {
7980: $checked{'csv'} = $is_checked;
7981: $currcsvsty = 'block';
7982: }
7983: }
7984: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7985: %csvoptions = %{$settings->{config}->{csv}->{options}};
7986: foreach my $option (keys(%optionson)) {
7987: unless ($csvoptions{$option}) {
7988: $optionsoff{$option} = $optionson{$option};
7989: $optionson{$option} = '';
7990: }
7991: }
7992: }
7993: }
7994: } else {
7995: $checked{'dat'} = $is_checked;
7996: }
7997: } else {
7998: $checked{'dat'} = $is_checked;
7999: }
8000: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8001: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8002: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8003: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8004: foreach my $item ('dat','csv') {
8005: my $id;
8006: if ($item eq 'csv') {
8007: $id = 'id="scantronconfcsv" ';
8008: }
8009: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8010: $titles{$item}.'</label>'.(' 'x3);
8011: if ($item eq 'csv') {
8012: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8013: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8014: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8015: foreach my $col (@fields) {
8016: my $selnone;
8017: if ($csvfields{$col} eq '') {
8018: $selnone = ' selected="selected"';
8019: }
8020: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8021: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8022: '<option value=""'.$selnone.'></option>';
8023: for (my $i=0; $i<20; $i++) {
8024: my $shown = $i+1;
8025: my $sel;
8026: unless ($selnone) {
8027: if (exists($csvfields{$col})) {
8028: if ($csvfields{$col} == $i) {
8029: $sel = ' selected="selected"';
8030: }
8031: }
8032: }
8033: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8034: }
8035: $datatable .= '</select></td></tr>';
8036: }
8037: $datatable .= '</table></fieldset>'.
8038: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8039: '<legend>'.&mt('CSV Options').'</legend>';
8040: foreach my $option ('hdr','pad','rem') {
8041: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8042: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8043: &mt('Yes').'</label>'.(' 'x2)."\n".
8044: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8045: }
8046: $datatable .= '</fieldset>';
8047: $itemcount ++;
8048: }
8049: }
8050: $datatable .= '</td></tr>';
8051: $$rowtotal ++;
8052: return $datatable;
8053: }
8054:
8055: sub scantronconfig_titles {
8056: return &Apache::lonlocal::texthash(
8057: dat => 'Standard format (.dat)',
8058: csv => 'Comma separated values (.csv)',
8059: hdr => 'Remove first line in file (contains column titles)',
8060: pad => 'Prepend 0s to PaperID',
8061: rem => 'Remove leading spaces (except Question Response columns)',
8062: CODE => 'CODE',
8063: ID => 'Student ID',
8064: PaperID => 'Paper ID',
8065: FirstName => 'First Name',
8066: LastName => 'Last Name',
8067: FirstQuestion => 'First Question Response',
8068: Section => 'Section',
8069: );
8070: }
8071:
8072: sub scantroncsv_fields {
8073: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8074: }
8075:
1.49 raeburn 8076: sub print_coursecategories {
1.57 raeburn 8077: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8078: my $datatable;
8079: if ($position eq 'top') {
1.160.6.42 raeburn 8080: my (%checked);
8081: my @catitems = ('unauth','auth');
8082: my @cattypes = ('std','domonly','codesrch','none');
8083: $checked{'unauth'} = 'std';
8084: $checked{'auth'} = 'std';
8085: if (ref($settings) eq 'HASH') {
8086: foreach my $type (@cattypes) {
8087: if ($type eq $settings->{'unauth'}) {
8088: $checked{'unauth'} = $type;
8089: }
8090: if ($type eq $settings->{'auth'}) {
8091: $checked{'auth'} = $type;
8092: }
8093: }
8094: }
8095: my %lt = &Apache::lonlocal::texthash (
8096: unauth => 'Catalog type for unauthenticated users',
8097: auth => 'Catalog type for authenticated users',
8098: none => 'No catalog',
8099: std => 'Standard catalog',
8100: domonly => 'Domain-only catalog',
8101: codesrch => "Code search form",
8102: );
8103: my $itemcount = 0;
8104: foreach my $item (@catitems) {
8105: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8106: $datatable .= '<tr '.$css_class.'>'.
8107: '<td>'.$lt{$item}.'</td>'.
8108: '<td class="LC_right_item"><span class="LC_nobreak">';
8109: foreach my $type (@cattypes) {
8110: my $ischecked;
8111: if ($checked{$item} eq $type) {
8112: $ischecked=' checked="checked"';
8113: }
8114: $datatable .= '<label>'.
8115: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8116: ' />'.$lt{$type}.'</label> ';
8117: }
1.160.6.87 raeburn 8118: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 8119: $itemcount ++;
8120: }
8121: $$rowtotal += $itemcount;
8122: } elsif ($position eq 'middle') {
1.57 raeburn 8123: my $toggle_cats_crs = ' ';
8124: my $toggle_cats_dom = ' checked="checked" ';
8125: my $can_cat_crs = ' ';
8126: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8127: my $toggle_catscomm_comm = ' ';
8128: my $toggle_catscomm_dom = ' checked="checked" ';
8129: my $can_catcomm_comm = ' ';
8130: my $can_catcomm_dom = ' checked="checked" ';
8131:
1.57 raeburn 8132: if (ref($settings) eq 'HASH') {
8133: if ($settings->{'togglecats'} eq 'crs') {
8134: $toggle_cats_crs = $toggle_cats_dom;
8135: $toggle_cats_dom = ' ';
8136: }
8137: if ($settings->{'categorize'} eq 'crs') {
8138: $can_cat_crs = $can_cat_dom;
8139: $can_cat_dom = ' ';
8140: }
1.120 raeburn 8141: if ($settings->{'togglecatscomm'} eq 'comm') {
8142: $toggle_catscomm_comm = $toggle_catscomm_dom;
8143: $toggle_catscomm_dom = ' ';
8144: }
8145: if ($settings->{'categorizecomm'} eq 'comm') {
8146: $can_catcomm_comm = $can_catcomm_dom;
8147: $can_catcomm_dom = ' ';
8148: }
1.57 raeburn 8149: }
8150: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 8151: togglecats => 'Show/Hide a course in catalog',
8152: togglecatscomm => 'Show/Hide a community in catalog',
8153: categorize => 'Assign a category to a course',
8154: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8155: );
8156: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 8157: dom => 'Set in Domain',
8158: crs => 'Set in Course',
8159: comm => 'Set in Community',
1.57 raeburn 8160: );
8161: $datatable = '<tr class="LC_odd_row">'.
8162: '<td>'.$title{'togglecats'}.'</td>'.
8163: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8164: '<input type="radio" name="togglecats"'.
8165: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8166: '<label><input type="radio" name="togglecats"'.
8167: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8168: '</tr><tr>'.
8169: '<td>'.$title{'categorize'}.'</td>'.
8170: '<td class="LC_right_item"><span class="LC_nobreak">'.
8171: '<label><input type="radio" name="categorize"'.
8172: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8173: '<label><input type="radio" name="categorize"'.
8174: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8175: '</tr><tr class="LC_odd_row">'.
8176: '<td>'.$title{'togglecatscomm'}.'</td>'.
8177: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8178: '<input type="radio" name="togglecatscomm"'.
8179: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8180: '<label><input type="radio" name="togglecatscomm"'.
8181: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8182: '</tr><tr>'.
8183: '<td>'.$title{'categorizecomm'}.'</td>'.
8184: '<td class="LC_right_item"><span class="LC_nobreak">'.
8185: '<label><input type="radio" name="categorizecomm"'.
8186: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8187: '<label><input type="radio" name="categorizecomm"'.
8188: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 8189: '</tr>';
1.120 raeburn 8190: $$rowtotal += 4;
1.57 raeburn 8191: } else {
8192: my $css_class;
8193: my $itemcount = 1;
8194: my $cathash;
8195: if (ref($settings) eq 'HASH') {
8196: $cathash = $settings->{'cats'};
8197: }
8198: if (ref($cathash) eq 'HASH') {
8199: my (@cats,@trails,%allitems,%idx,@jsarray);
8200: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8201: \%allitems,\%idx,\@jsarray);
8202: my $maxdepth = scalar(@cats);
8203: my $colattrib = '';
8204: if ($maxdepth > 2) {
8205: $colattrib = ' colspan="2" ';
8206: }
8207: my @path;
8208: if (@cats > 0) {
8209: if (ref($cats[0]) eq 'ARRAY') {
8210: my $numtop = @{$cats[0]};
8211: my $maxnum = $numtop;
1.120 raeburn 8212: my %default_names = (
8213: instcode => &mt('Official courses'),
8214: communities => &mt('Communities'),
8215: );
8216:
8217: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8218: ($cathash->{'instcode::0'} eq '') ||
8219: (!grep(/^communities$/,@{$cats[0]})) ||
8220: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 8221: $maxnum ++;
8222: }
8223: my $lastidx;
8224: for (my $i=0; $i<$numtop; $i++) {
8225: my $parent = $cats[0][$i];
8226: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8227: my $item = &escape($parent).'::0';
8228: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8229: $lastidx = $idx{$item};
8230: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8231: .'<select name="'.$item.'"'.$chgstr.'>';
8232: for (my $k=0; $k<=$maxnum; $k++) {
8233: my $vpos = $k+1;
8234: my $selstr;
8235: if ($k == $i) {
8236: $selstr = ' selected="selected" ';
8237: }
8238: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8239: }
1.160.6.29 raeburn 8240: $datatable .= '</select></span></td><td>';
1.120 raeburn 8241: if ($parent eq 'instcode' || $parent eq 'communities') {
8242: $datatable .= '<span class="LC_nobreak">'
8243: .$default_names{$parent}.'</span>';
8244: if ($parent eq 'instcode') {
8245: $datatable .= '<br /><span class="LC_nobreak">('
8246: .&mt('with institutional codes')
8247: .')</span></td><td'.$colattrib.'>';
8248: } else {
8249: $datatable .= '<table><tr><td>';
8250: }
8251: $datatable .= '<span class="LC_nobreak">'
8252: .'<label><input type="radio" name="'
8253: .$parent.'" value="1" checked="checked" />'
8254: .&mt('Display').'</label>';
8255: if ($parent eq 'instcode') {
8256: $datatable .= ' ';
8257: } else {
8258: $datatable .= '</span></td></tr><tr><td>'
8259: .'<span class="LC_nobreak">';
8260: }
8261: $datatable .= '<label><input type="radio" name="'
8262: .$parent.'" value="0" />'
8263: .&mt('Do not display').'</label></span>';
8264: if ($parent eq 'communities') {
8265: $datatable .= '</td></tr></table>';
8266: }
8267: $datatable .= '</td>';
1.57 raeburn 8268: } else {
8269: $datatable .= $parent
1.160.6.29 raeburn 8270: .' <span class="LC_nobreak"><label>'
8271: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8272: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8273: }
8274: my $depth = 1;
8275: push(@path,$parent);
8276: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8277: pop(@path);
8278: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8279: $itemcount ++;
8280: }
1.48 raeburn 8281: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8282: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8283: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8284: for (my $k=0; $k<=$maxnum; $k++) {
8285: my $vpos = $k+1;
8286: my $selstr;
1.57 raeburn 8287: if ($k == $numtop) {
1.48 raeburn 8288: $selstr = ' selected="selected" ';
8289: }
8290: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8291: }
1.59 bisitz 8292: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8293: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8294: .'</tr>'."\n";
1.48 raeburn 8295: $itemcount ++;
1.120 raeburn 8296: foreach my $default ('instcode','communities') {
8297: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8298: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8299: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8300: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8301: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8302: for (my $k=0; $k<=$maxnum; $k++) {
8303: my $vpos = $k+1;
8304: my $selstr;
8305: if ($k == $maxnum) {
8306: $selstr = ' selected="selected" ';
8307: }
8308: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8309: }
1.120 raeburn 8310: $datatable .= '</select></span></td>'.
8311: '<td><span class="LC_nobreak">'.
8312: $default_names{$default}.'</span>';
8313: if ($default eq 'instcode') {
8314: $datatable .= '<br /><span class="LC_nobreak">('
8315: .&mt('with institutional codes').')</span>';
8316: }
8317: $datatable .= '</td>'
8318: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8319: .&mt('Display').'</label> '
8320: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8321: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8322: }
8323: }
8324: }
1.57 raeburn 8325: } else {
8326: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8327: }
8328: } else {
1.160.6.87 raeburn 8329: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8330: .&initialize_categories($itemcount);
1.48 raeburn 8331: }
1.57 raeburn 8332: $$rowtotal += $itemcount;
1.48 raeburn 8333: }
8334: return $datatable;
8335: }
8336:
1.69 raeburn 8337: sub print_serverstatuses {
8338: my ($dom,$settings,$rowtotal) = @_;
8339: my $datatable;
8340: my @pages = &serverstatus_pages();
8341: my (%namedaccess,%machineaccess);
8342: foreach my $type (@pages) {
8343: $namedaccess{$type} = '';
8344: $machineaccess{$type}= '';
8345: }
8346: if (ref($settings) eq 'HASH') {
8347: foreach my $type (@pages) {
8348: if (exists($settings->{$type})) {
8349: if (ref($settings->{$type}) eq 'HASH') {
8350: foreach my $key (keys(%{$settings->{$type}})) {
8351: if ($key eq 'namedusers') {
8352: $namedaccess{$type} = $settings->{$type}->{$key};
8353: } elsif ($key eq 'machines') {
8354: $machineaccess{$type} = $settings->{$type}->{$key};
8355: }
8356: }
8357: }
8358: }
8359: }
8360: }
1.81 raeburn 8361: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8362: my $rownum = 0;
8363: my $css_class;
8364: foreach my $type (@pages) {
8365: $rownum ++;
8366: $css_class = $rownum%2?' class="LC_odd_row"':'';
8367: $datatable .= '<tr'.$css_class.'>'.
8368: '<td><span class="LC_nobreak">'.
8369: $titles->{$type}.'</span></td>'.
8370: '<td class="LC_left_item">'.
8371: '<input type="text" name="'.$type.'_namedusers" '.
8372: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8373: '<td class="LC_right_item">'.
8374: '<span class="LC_nobreak">'.
8375: '<input type="text" name="'.$type.'_machines" '.
8376: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 8377: '</span></td></tr>'."\n";
1.69 raeburn 8378: }
8379: $$rowtotal += $rownum;
8380: return $datatable;
8381: }
8382:
8383: sub serverstatus_pages {
8384: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 8385: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 8386: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 8387: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8388: }
8389:
1.160.6.40 raeburn 8390: sub defaults_javascript {
8391: my ($settings) = @_;
1.160.6.98 raeburn 8392: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 8393: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8394: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8395: if ($maxnum eq '') {
8396: $maxnum = 0;
8397: }
8398: $maxnum ++;
1.160.6.51 raeburn 8399: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 8400: return <<"ENDSCRIPT";
8401: <script type="text/javascript">
8402: // <![CDATA[
8403: function reorderTypes(form,caller) {
8404: var changedVal;
8405: $jstext
8406: var newpos = 'addinststatus_pos';
8407: var current = new Array;
8408: var maxh = $maxnum;
8409: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8410: var oldVal;
8411: if (caller == newpos) {
8412: changedVal = newitemVal;
8413: } else {
8414: var curritem = 'inststatus_pos_'+caller;
8415: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8416: current[newitemVal] = newpos;
8417: }
8418: for (var i=0; i<inststatuses.length; i++) {
8419: if (inststatuses[i] != caller) {
8420: var elementName = 'inststatus_pos_'+inststatuses[i];
8421: if (form.elements[elementName]) {
8422: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8423: current[currVal] = elementName;
8424: }
8425: }
8426: }
8427: for (var j=0; j<maxh; j++) {
8428: if (current[j] == undefined) {
8429: oldVal = j;
8430: }
8431: }
8432: if (oldVal < changedVal) {
8433: for (var k=oldVal+1; k<=changedVal ; k++) {
8434: var elementName = current[k];
8435: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8436: }
8437: } else {
8438: for (var k=changedVal; k<oldVal; k++) {
8439: var elementName = current[k];
8440: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8441: }
8442: }
8443: return;
8444: }
8445:
8446: // ]]>
8447: </script>
8448:
8449: ENDSCRIPT
8450: }
8451: }
8452:
1.160.6.98 raeburn 8453: sub passwords_javascript {
1.160.6.99 raeburn 8454: my %intalert = &Apache::lonlocal::texthash (
8455: authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
8456: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
8457: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
8458: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
8459: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
8460: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
8461: );
8462: &js_escape(\%intalert);
8463: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 8464: my $intauthjs = <<"ENDSCRIPT";
8465:
8466: function warnIntAuth(field) {
8467: if (field.name == 'intauth_check') {
8468: if (field.value == '2') {
1.160.6.99 raeburn 8469: alert('$intalert{authcheck}');
1.160.6.98 raeburn 8470: }
8471: }
8472: if (field.name == 'intauth_cost') {
8473: field.value.replace(/\s/g,'');
8474: if (field.value != '') {
8475: var regexdigit=/^\\d+\$/;
8476: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 8477: alert('$intalert{authcost}');
8478: }
8479: }
8480: }
8481: return;
8482: }
8483:
8484: function warnIntPass(field) {
8485: field.value.replace(/^\s+/,'');
8486: field.value.replace(/\s+\$/,'');
8487: var regexdigit=/^\\d+\$/;
8488: if (field.name == 'passwords_min') {
8489: if (field.value == '') {
8490: alert('$intalert{passmin}');
8491: field.value = '$defmin';
8492: } else {
8493: if (!regexdigit.test(field.value)) {
8494: alert('$intalert{passmin}');
8495: field.value = '$defmin';
8496: }
8497: var minval = parseInt(field.value,10);
8498: if (minval < $defmin) {
8499: alert('$intalert{passmin}');
8500: field.value = '$defmin';
8501: }
8502: }
8503: } else {
8504: if (field.value == '0') {
8505: field.value = '';
8506: }
8507: if (field.value != '') {
8508: if (field.name == 'passwords_expire') {
8509: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
8510: if (!regexpposnum.test(field.value)) {
8511: alert('$intalert{passexp}');
8512: field.value = '';
8513: } else {
8514: var expval = parseFloat(field.value);
8515: if (expval == 0) {
8516: alert('$intalert{passexp}');
8517: field.value = '';
8518: }
8519: }
8520: } else {
8521: if (!regexdigit.test(field.value)) {
8522: if (field.name == 'passwords_max') {
8523: alert('$intalert{passmax}');
8524: } else {
8525: if (field.name == 'passwords_numsaved') {
8526: alert('$intalert{passnum}');
8527: }
8528: }
1.160.6.104 raeburn 8529: field.value = '';
1.160.6.99 raeburn 8530: }
1.160.6.98 raeburn 8531: }
8532: }
8533: }
8534: return;
8535: }
8536:
8537: ENDSCRIPT
8538: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8539: }
8540:
1.49 raeburn 8541: sub coursecategories_javascript {
8542: my ($settings) = @_;
1.57 raeburn 8543: my ($output,$jstext,$cathash);
1.49 raeburn 8544: if (ref($settings) eq 'HASH') {
1.57 raeburn 8545: $cathash = $settings->{'cats'};
8546: }
8547: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8548: my (@cats,@jsarray,%idx);
1.57 raeburn 8549: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8550: if (@jsarray > 0) {
8551: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8552: for (my $i=0; $i<@jsarray; $i++) {
8553: if (ref($jsarray[$i]) eq 'ARRAY') {
8554: my $catstr = join('","',@{$jsarray[$i]});
8555: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8556: }
8557: }
8558: }
8559: } else {
8560: $jstext = ' var categories = Array(1);'."\n".
8561: ' categories[0] = Array("instcode_pos");'."\n";
8562: }
1.160.6.42 raeburn 8563: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8564: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 8565: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8566: &js_escape(\$instcode_reserved);
8567: &js_escape(\$communities_reserved);
8568: &js_escape(\$choose_again);
1.49 raeburn 8569: $output = <<"ENDSCRIPT";
8570: <script type="text/javascript">
1.109 raeburn 8571: // <![CDATA[
1.49 raeburn 8572: function reorderCats(form,parent,item,idx) {
8573: var changedVal;
8574: $jstext
8575: var newpos = 'addcategory_pos';
8576: if (parent == '') {
8577: var has_instcode = 0;
8578: var maxtop = categories[idx].length;
8579: for (var j=0; j<maxtop; j++) {
8580: if (categories[idx][j] == 'instcode::0') {
8581: has_instcode == 1;
8582: }
8583: }
8584: if (has_instcode == 0) {
8585: categories[idx][maxtop] = 'instcode_pos';
8586: }
8587: } else {
8588: newpos += '_'+parent;
8589: }
8590: var maxh = 1 + categories[idx].length;
8591: var current = new Array;
8592: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8593: if (item == newpos) {
8594: changedVal = newitemVal;
8595: } else {
8596: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8597: current[newitemVal] = newpos;
8598: }
8599: for (var i=0; i<categories[idx].length; i++) {
8600: var elementName = categories[idx][i];
8601: if (elementName != item) {
8602: if (form.elements[elementName]) {
8603: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8604: current[currVal] = elementName;
8605: }
8606: }
8607: }
8608: var oldVal;
8609: for (var j=0; j<maxh; j++) {
8610: if (current[j] == undefined) {
8611: oldVal = j;
8612: }
8613: }
8614: if (oldVal < changedVal) {
8615: for (var k=oldVal+1; k<=changedVal ; k++) {
8616: var elementName = current[k];
8617: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8618: }
8619: } else {
8620: for (var k=changedVal; k<oldVal; k++) {
8621: var elementName = current[k];
8622: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8623: }
8624: }
8625: return;
8626: }
1.120 raeburn 8627:
8628: function categoryCheck(form) {
8629: if (form.elements['addcategory_name'].value == 'instcode') {
8630: alert('$instcode_reserved\\n$choose_again');
8631: return false;
8632: }
8633: if (form.elements['addcategory_name'].value == 'communities') {
8634: alert('$communities_reserved\\n$choose_again');
8635: return false;
8636: }
8637: return true;
8638: }
8639:
1.109 raeburn 8640: // ]]>
1.49 raeburn 8641: </script>
8642:
8643: ENDSCRIPT
8644: return $output;
8645: }
8646:
1.48 raeburn 8647: sub initialize_categories {
8648: my ($itemcount) = @_;
1.120 raeburn 8649: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 8650: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 8651: instcode => 'Official courses (with institutional codes)',
8652: communities => 'Communities',
8653: );
8654: my $select0 = ' selected="selected"';
8655: my $select1 = '';
8656: foreach my $default ('instcode','communities') {
8657: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 8658: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 8659: if ($default eq 'communities') {
8660: $select1 = $select0;
8661: $select0 = '';
8662: }
8663: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8664: .'<select name="'.$default.'_pos">'
8665: .'<option value="0"'.$select0.'>1</option>'
8666: .'<option value="1"'.$select1.'>2</option>'
8667: .'<option value="2">3</option></select> '
8668: .$default_names{$default}
8669: .'</span></td><td><span class="LC_nobreak">'
8670: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8671: .&mt('Display').'</label> <label>'
8672: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8673: .'</label></span></td></tr>';
1.120 raeburn 8674: $itemcount ++;
8675: }
1.48 raeburn 8676: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8677: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8678: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8679: .'<select name="addcategory_pos"'.$chgstr.'>'
8680: .'<option value="0">1</option>'
8681: .'<option value="1">2</option>'
8682: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 8683: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 8684: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8685: .'</td></tr>';
1.48 raeburn 8686: return $datatable;
8687: }
8688:
8689: sub build_category_rows {
1.49 raeburn 8690: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8691: my ($text,$name,$item,$chgstr);
1.48 raeburn 8692: if (ref($cats) eq 'ARRAY') {
8693: my $maxdepth = scalar(@{$cats});
8694: if (ref($cats->[$depth]) eq 'HASH') {
8695: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8696: my $numchildren = @{$cats->[$depth]{$parent}};
8697: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 8698: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8699: my ($idxnum,$parent_name,$parent_item);
8700: my $higher = $depth - 1;
8701: if ($higher == 0) {
8702: $parent_name = &escape($parent).'::'.$higher;
8703: } else {
8704: if (ref($path) eq 'ARRAY') {
8705: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8706: }
8707: }
8708: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8709: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8710: if ($j < $numchildren) {
1.48 raeburn 8711: $name = $cats->[$depth]{$parent}[$j];
8712: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8713: $idxnum = $idx->{$item};
8714: } else {
8715: $name = $parent_name;
8716: $item = $parent_item;
1.48 raeburn 8717: }
1.49 raeburn 8718: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8719: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8720: for (my $i=0; $i<=$numchildren; $i++) {
8721: my $vpos = $i+1;
8722: my $selstr;
8723: if ($j == $i) {
8724: $selstr = ' selected="selected" ';
8725: }
8726: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8727: }
8728: $text .= '</select> ';
8729: if ($j < $numchildren) {
8730: my $deeper = $depth+1;
8731: $text .= $name.' '
8732: .'<label><input type="checkbox" name="deletecategory" value="'
8733: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8734: if(ref($path) eq 'ARRAY') {
8735: push(@{$path},$name);
1.49 raeburn 8736: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8737: pop(@{$path});
8738: }
8739: } else {
1.160.6.87 raeburn 8740: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8741: if ($j == $numchildren) {
8742: $text .= $name;
8743: } else {
8744: $text .= $item;
8745: }
8746: $text .= '" value="" />';
8747: }
8748: $text .= '</td></tr>';
8749: }
8750: $text .= '</table></td>';
8751: } else {
8752: my $higher = $depth-1;
8753: if ($higher == 0) {
8754: $name = &escape($parent).'::'.$higher;
8755: } else {
8756: if (ref($path) eq 'ARRAY') {
8757: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8758: }
8759: }
8760: my $colspan;
8761: if ($parent ne 'instcode') {
8762: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 8763: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8764: }
8765: }
8766: }
8767: }
8768: return $text;
8769: }
8770:
1.33 raeburn 8771: sub modifiable_userdata_row {
1.160.6.93 raeburn 8772: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8773: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 8774: my ($role,$rolename,$statustype);
8775: $role = $item;
1.160.6.34 raeburn 8776: if ($context eq 'cancreate') {
1.160.6.93 raeburn 8777: if ($item =~ /^(emailusername)_(.+)$/) {
8778: $role = $1;
8779: $statustype = $2;
1.160.6.35 raeburn 8780: if (ref($usertypes) eq 'HASH') {
8781: if ($usertypes->{$statustype}) {
8782: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8783: } else {
8784: $rolename = &mt('Data provided by user');
8785: }
8786: }
1.160.6.34 raeburn 8787: }
8788: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8789: if (ref($usertypes) eq 'HASH') {
8790: $rolename = $usertypes->{$role};
8791: } else {
8792: $rolename = $role;
8793: }
1.33 raeburn 8794: } else {
1.63 raeburn 8795: if ($role eq 'cr') {
8796: $rolename = &mt('Custom role');
8797: } else {
8798: $rolename = &Apache::lonnet::plaintext($role);
8799: }
1.33 raeburn 8800: }
1.160.6.34 raeburn 8801: my (@fields,%fieldtitles);
8802: if (ref($fieldsref) eq 'ARRAY') {
8803: @fields = @{$fieldsref};
8804: } else {
8805: @fields = ('lastname','firstname','middlename','generation',
8806: 'permanentemail','id');
8807: }
8808: if ((ref($titlesref) eq 'HASH')) {
8809: %fieldtitles = %{$titlesref};
8810: } else {
8811: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8812: }
1.33 raeburn 8813: my $output;
1.160.6.93 raeburn 8814: my $css_class;
8815: if ($rowcount%2) {
8816: $css_class = 'LC_odd_row';
8817: }
8818: if ($customcss) {
8819: $css_class .= " $customcss";
8820: }
8821: $css_class =~ s/^\s+//;
8822: if ($css_class) {
8823: $css_class = ' class="'.$css_class.'"';
8824: }
8825: if ($rowstyle) {
8826: $css_class .= ' style="'.$rowstyle.'"';
8827: }
8828: if ($rowid) {
8829: $rowid = ' id="'.$rowid.'"';
8830: }
8831:
8832: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8833: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8834: '<td class="LC_left_item" colspan="2"><table>';
8835: my $rem;
8836: my %checks;
8837: if (ref($settings) eq 'HASH') {
8838: if (ref($settings->{$context}) eq 'HASH') {
8839: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 8840: my $hashref = $settings->{$context}->{$role};
8841: if ($role eq 'emailusername') {
8842: if ($statustype) {
8843: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8844: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 8845: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 8846: foreach my $field (@fields) {
8847: if ($hashref->{$field}) {
8848: $checks{$field} = $hashref->{$field};
8849: }
8850: }
8851: }
8852: }
8853: }
8854: } else {
8855: if (ref($hashref) eq 'HASH') {
8856: foreach my $field (@fields) {
8857: if ($hashref->{$field}) {
8858: $checks{$field} = ' checked="checked" ';
8859: }
8860: }
1.33 raeburn 8861: }
8862: }
8863: }
8864: }
8865: }
1.160.6.93 raeburn 8866:
8867: my $total = scalar(@fields);
8868: for (my $i=0; $i<$total; $i++) {
8869: $rem = $i%($numinrow);
1.33 raeburn 8870: if ($rem == 0) {
8871: if ($i > 0) {
8872: $output .= '</tr>';
8873: }
8874: $output .= '<tr>';
8875: }
8876: my $check = ' ';
1.160.6.35 raeburn 8877: unless ($role eq 'emailusername') {
8878: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 8879: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 8880: } else {
8881: if ($role eq 'st') {
8882: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 8883: $check = ' checked="checked" ';
1.160.6.35 raeburn 8884: }
1.33 raeburn 8885: }
8886: }
8887: }
8888: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 8889: '<span class="LC_nobreak">';
8890: if ($role eq 'emailusername') {
8891: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8892: $checks{$fields[$i]} = 'omit';
8893: }
8894: foreach my $option ('required','optional','omit') {
8895: my $checked='';
8896: if ($checks{$fields[$i]} eq $option) {
8897: $checked='checked="checked" ';
8898: }
8899: $output .= '<label>'.
8900: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8901: &mt($option).'</label>'.(' ' x2);
8902: }
8903: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8904: } else {
8905: $output .= '<label>'.
8906: '<input type="checkbox" name="canmodify_'.$role.'" '.
8907: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8908: '</label>';
8909: }
8910: $output .= '</span></td>';
1.33 raeburn 8911: }
1.160.6.93 raeburn 8912: $rem = $total%$numinrow;
8913: my $colsleft;
8914: if ($rem) {
8915: $colsleft = $numinrow - $rem;
8916: }
8917: if ($colsleft > 1) {
1.33 raeburn 8918: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8919: ' </td>';
8920: } elsif ($colsleft == 1) {
8921: $output .= '<td class="LC_left_item"> </td>';
8922: }
8923: $output .= '</tr></table></td></tr>';
8924: return $output;
8925: }
1.28 raeburn 8926:
1.93 raeburn 8927: sub insttypes_row {
1.160.6.93 raeburn 8928: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8929: $customcss,$rowstyle) = @_;
1.93 raeburn 8930: my %lt = &Apache::lonlocal::texthash (
8931: cansearch => 'Users allowed to search',
8932: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8933: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 8934: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 8935: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8936: );
8937: my $showdom;
8938: if ($context eq 'cansearch') {
8939: $showdom = ' ('.$dom.')';
8940: }
1.160.6.5 raeburn 8941: my $class = 'LC_left_item';
8942: if ($context eq 'statustocreate') {
8943: $class = 'LC_right_item';
8944: }
1.160.6.93 raeburn 8945: my $css_class;
8946: if ($$rowtotal%2) {
8947: $css_class = 'LC_odd_row';
8948: }
8949: if ($customcss) {
8950: $css_class .= ' '.$customcss;
8951: }
8952: $css_class =~ s/^\s+//;
8953: if ($css_class) {
8954: $css_class = ' class="'.$css_class.'"';
8955: }
8956: if ($rowstyle) {
8957: $css_class .= ' style="'.$rowstyle.'"';
8958: }
8959: if ($onclick) {
8960: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 8961: }
8962: my $output = '<tr'.$css_class.'>'.
8963: '<td>'.$lt{$context}.$showdom.
8964: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8965: my $rem;
8966: if (ref($types) eq 'ARRAY') {
8967: for (my $i=0; $i<@{$types}; $i++) {
8968: if (defined($usertypes->{$types->[$i]})) {
8969: my $rem = $i%($numinrow);
8970: if ($rem == 0) {
8971: if ($i > 0) {
8972: $output .= '</tr>';
8973: }
8974: $output .= '<tr>';
1.23 raeburn 8975: }
1.26 raeburn 8976: my $check = ' ';
1.99 raeburn 8977: if (ref($settings) eq 'HASH') {
8978: if (ref($settings->{$context}) eq 'ARRAY') {
8979: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8980: $check = ' checked="checked" ';
8981: }
1.160.6.101 raeburn 8982: } elsif (ref($settings->{$context}) eq 'HASH') {
8983: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8984: $check = ' checked="checked" ';
8985: }
1.99 raeburn 8986: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8987: $check = ' checked="checked" ';
8988: }
1.23 raeburn 8989: }
1.26 raeburn 8990: $output .= '<td class="LC_left_item">'.
8991: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8992: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 8993: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 8994: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8995: }
8996: }
1.26 raeburn 8997: $rem = @{$types}%($numinrow);
1.23 raeburn 8998: }
8999: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 9000: if ($context eq 'overrides') {
9001: if ($colsleft > 1) {
9002: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9003: } else {
9004: $output .= '<td class="LC_left_item">';
9005: }
9006: $output .= ' ';
1.23 raeburn 9007: } else {
1.160.6.101 raeburn 9008: if ($rem == 0) {
9009: $output .= '<tr>';
9010: }
9011: if ($colsleft > 1) {
9012: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9013: } else {
9014: $output .= '<td class="LC_left_item">';
9015: }
9016: my $defcheck = ' ';
9017: if (ref($settings) eq 'HASH') {
9018: if (ref($settings->{$context}) eq 'ARRAY') {
9019: if (grep(/^default$/,@{$settings->{$context}})) {
9020: $defcheck = ' checked="checked" ';
9021: }
9022: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9023: $defcheck = ' checked="checked" ';
9024: }
1.26 raeburn 9025: }
1.160.6.101 raeburn 9026: $output .= '<span class="LC_nobreak"><label>'.
9027: '<input type="checkbox" name="'.$context.'" '.
9028: 'value="default"'.$defcheck.$onclick.' />'.
9029: $othertitle.'</label></span>';
1.23 raeburn 9030: }
1.160.6.101 raeburn 9031: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9032: return $output;
1.23 raeburn 9033: }
9034:
9035: sub sorted_searchtitles {
9036: my %searchtitles = &Apache::lonlocal::texthash(
9037: 'uname' => 'username',
9038: 'lastname' => 'last name',
9039: 'lastfirst' => 'last name, first name',
9040: );
9041: my @titleorder = ('uname','lastname','lastfirst');
9042: return (\%searchtitles,\@titleorder);
9043: }
9044:
1.25 raeburn 9045: sub sorted_searchtypes {
9046: my %srchtypes_desc = (
9047: exact => 'is exact match',
9048: contains => 'contains ..',
9049: begins => 'begins with ..',
9050: );
9051: my @srchtypeorder = ('exact','begins','contains');
9052: return (\%srchtypes_desc,\@srchtypeorder);
9053: }
9054:
1.3 raeburn 9055: sub usertype_update_row {
9056: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9057: my $datatable;
9058: my $numinrow = 4;
9059: foreach my $type (@{$types}) {
9060: if (defined($usertypes->{$type})) {
9061: $$rownums ++;
9062: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9063: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9064: '</td><td class="LC_left_item"><table>';
9065: for (my $i=0; $i<@{$fields}; $i++) {
9066: my $rem = $i%($numinrow);
9067: if ($rem == 0) {
9068: if ($i > 0) {
9069: $datatable .= '</tr>';
9070: }
9071: $datatable .= '<tr>';
9072: }
9073: my $check = ' ';
1.39 raeburn 9074: if (ref($settings) eq 'HASH') {
9075: if (ref($settings->{'fields'}) eq 'HASH') {
9076: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9077: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9078: $check = ' checked="checked" ';
9079: }
1.3 raeburn 9080: }
9081: }
9082: }
9083:
9084: if ($i == @{$fields}-1) {
9085: my $colsleft = $numinrow - $rem;
9086: if ($colsleft > 1) {
9087: $datatable .= '<td colspan="'.$colsleft.'">';
9088: } else {
9089: $datatable .= '<td>';
9090: }
9091: } else {
9092: $datatable .= '<td>';
9093: }
1.8 raeburn 9094: $datatable .= '<span class="LC_nobreak"><label>'.
9095: '<input type="checkbox" name="updateable_'.$type.
9096: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9097: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9098: }
9099: $datatable .= '</tr></table></td></tr>';
9100: }
9101: }
9102: return $datatable;
1.1 raeburn 9103: }
9104:
9105: sub modify_login {
1.160.6.24 raeburn 9106: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 9107: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 9108: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
9109: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.160.6.5 raeburn 9110: %title = ( coursecatalog => 'Display course catalog',
9111: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 9112: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 9113: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 9114: loginheader => 'Log-in box header',
9115: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 9116: @offon = ('off','on');
1.112 raeburn 9117: if (ref($domconfig{login}) eq 'HASH') {
9118: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9119: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9120: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9121: }
9122: }
1.160.6.113 raeburn 9123: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
9124: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
9125: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
9126: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
9127: $saml{$lonhost} = 1;
9128: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
9129: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
9130: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
9131: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
9132: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
9133: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
9134: }
9135: }
9136: }
1.112 raeburn 9137: }
1.9 raeburn 9138: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9139: \%domconfig,\%loginhash);
1.160.6.14 raeburn 9140: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9141: foreach my $item (@toggles) {
9142: $loginhash{login}{$item} = $env{'form.'.$item};
9143: }
1.41 raeburn 9144: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9145: if (ref($colchanges{'login'}) eq 'HASH') {
9146: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9147: \%loginhash);
9148: }
1.110 raeburn 9149:
1.149 raeburn 9150: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 9151: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9152: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9153: if (keys(%servers) > 1) {
9154: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9155: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9156: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9157: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9158: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9159: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9160: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9161: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9162: $changes{'loginvia'}{$lonhost} = 1;
9163: } else {
9164: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9165: $changes{'loginvia'}{$lonhost} = 1;
9166: }
9167: } else {
9168: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9169: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9170: $changes{'loginvia'}{$lonhost} = 1;
9171: }
9172: }
9173: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9174: foreach my $item (@loginvia_attribs) {
9175: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9176: }
9177: } else {
9178: foreach my $item (@loginvia_attribs) {
9179: my $new = $env{'form.'.$lonhost.'_'.$item};
9180: if (($item eq 'serverpath') && ($new eq 'custom')) {
9181: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9182: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9183: $new = '/';
9184: }
9185: }
9186: if (($item eq 'custompath') &&
9187: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9188: $new = '';
9189: }
9190: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9191: $changes{'loginvia'}{$lonhost} = 1;
9192: }
9193: if ($item eq 'exempt') {
1.160.6.56 raeburn 9194: $new = &check_exempt_addresses($new);
1.128 raeburn 9195: }
9196: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9197: }
9198: }
1.112 raeburn 9199: } else {
1.128 raeburn 9200: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9201: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9202: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9203: foreach my $item (@loginvia_attribs) {
9204: my $new = $env{'form.'.$lonhost.'_'.$item};
9205: if (($item eq 'serverpath') && ($new eq 'custom')) {
9206: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9207: $new = '/';
9208: }
9209: }
9210: if (($item eq 'custompath') &&
9211: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9212: $new = '';
9213: }
9214: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9215: }
1.110 raeburn 9216: }
9217: }
9218: }
9219: }
1.119 raeburn 9220:
1.160.6.5 raeburn 9221: my $servadm = $r->dir_config('lonAdmEMail');
9222: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9223: if (ref($domconfig{'login'}) eq 'HASH') {
9224: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9225: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9226: if ($lang eq 'nolang') {
9227: push(@currlangs,$lang);
9228: } elsif (defined($langchoices{$lang})) {
9229: push(@currlangs,$lang);
9230: } else {
9231: next;
9232: }
9233: }
9234: }
9235: }
9236: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9237: if (@currlangs > 0) {
9238: foreach my $lang (@currlangs) {
9239: if (grep(/^\Q$lang\E$/,@delurls)) {
9240: $changes{'helpurl'}{$lang} = 1;
9241: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9242: $changes{'helpurl'}{$lang} = 1;
9243: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9244: push(@newlangs,$lang);
9245: } else {
9246: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9247: }
9248: }
9249: }
9250: unless (grep(/^nolang$/,@currlangs)) {
9251: if ($env{'form.loginhelpurl_nolang.filename'}) {
9252: $changes{'helpurl'}{'nolang'} = 1;
9253: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9254: push(@newlangs,'nolang');
9255: }
9256: }
9257: if ($env{'form.loginhelpurl_add_lang'}) {
9258: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9259: ($env{'form.loginhelpurl_add_file.filename'})) {
9260: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9261: $addedfile = $env{'form.loginhelpurl_add_lang'};
9262: }
9263: }
9264: if ((@newlangs > 0) || ($addedfile)) {
9265: my $error;
9266: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9267: if ($configuserok eq 'ok') {
9268: if ($switchserver) {
9269: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9270: } elsif ($author_ok eq 'ok') {
9271: my @allnew = @newlangs;
9272: if ($addedfile ne '') {
9273: push(@allnew,$addedfile);
9274: }
9275: foreach my $lang (@allnew) {
9276: my $formelem = 'loginhelpurl_'.$lang;
9277: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9278: $formelem = 'loginhelpurl_add_file';
9279: }
9280: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9281: "help/$lang",'','',$newfile{$lang});
9282: if ($result eq 'ok') {
9283: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9284: $changes{'helpurl'}{$lang} = 1;
9285: } else {
9286: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9287: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9288: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
9289: (!grep(/^\Q$lang\E$/,@delurls))) {
9290: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9291: }
9292: }
9293: }
9294: } else {
9295: $error = &mt("Upload of custom log-in help file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
9296: }
9297: } else {
9298: $error = &mt("Upload of custom log-in help file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
9299: }
9300: if ($error) {
9301: &Apache::lonnet::logthis($error);
9302: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9303: }
9304: }
1.160.6.56 raeburn 9305:
9306: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9307: if (ref($domconfig{'login'}) eq 'HASH') {
9308: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9309: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9310: if ($domservers{$lonhost}) {
9311: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9312: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 9313: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 9314: }
9315: }
9316: }
9317: }
9318: }
9319: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9320: foreach my $lonhost (sort(keys(%domservers))) {
9321: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9322: $changes{'headtag'}{$lonhost} = 1;
9323: } else {
9324: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9325: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9326: }
9327: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9328: push(@newhosts,$lonhost);
9329: } elsif ($currheadtagurls{$lonhost}) {
9330: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9331: if ($currexempt{$lonhost}) {
9332: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
9333: $changes{'headtag'}{$lonhost} = 1;
9334: }
9335: } elsif ($possexempt{$lonhost}) {
9336: $changes{'headtag'}{$lonhost} = 1;
9337: }
9338: if ($possexempt{$lonhost}) {
9339: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9340: }
9341: }
9342: }
9343: }
9344: if (@newhosts) {
9345: my $error;
9346: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9347: if ($configuserok eq 'ok') {
9348: if ($switchserver) {
9349: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9350: } elsif ($author_ok eq 'ok') {
9351: foreach my $lonhost (@newhosts) {
9352: my $formelem = 'loginheadtag_'.$lonhost;
9353: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9354: "login/headtag/$lonhost",'','',
9355: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9356: if ($result eq 'ok') {
1.160.6.113 raeburn 9357: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9358: $changes{'headtag'}{$lonhost} = 1;
9359: if ($possexempt{$lonhost}) {
9360: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9361: }
9362: } else {
9363: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9364: $newheadtagurls{$lonhost},$result);
9365: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9366: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9367: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9368: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9369: }
9370: }
9371: }
9372: } else {
9373: $error = &mt("Upload of custom markup file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
9374: }
9375: } else {
9376: $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
9377: }
9378: if ($error) {
9379: &Apache::lonnet::logthis($error);
9380: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9381: }
9382: }
9383: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
9384: my @newsamlimgs;
9385: foreach my $lonhost (keys(%domservers)) {
9386: if ($env{'form.saml_'.$lonhost}) {
9387: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
9388: push(@newsamlimgs,$lonhost);
9389: }
9390: foreach my $item ('text','alt','url','title','notsso') {
9391: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
9392: }
9393: if ($saml{$lonhost}) {
9394: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
9395: #FIXME Need to obsolete published image
9396: delete($currsaml{$lonhost}{'img'});
9397: $changes{'saml'}{$lonhost} = 1;
9398: }
9399: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
9400: $changes{'saml'}{$lonhost} = 1;
9401: }
9402: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
9403: $changes{'saml'}{$lonhost} = 1;
9404: }
9405: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
9406: $changes{'saml'}{$lonhost} = 1;
9407: }
9408: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
9409: $changes{'saml'}{$lonhost} = 1;
9410: }
9411: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
9412: $changes{'saml'}{$lonhost} = 1;
9413: }
9414: } else {
9415: $changes{'saml'}{$lonhost} = 1;
9416: }
9417: foreach my $item ('text','alt','url','title','notsso') {
9418: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
9419: }
9420: } else {
9421: if ($saml{$lonhost}) {
9422: $changes{'saml'}{$lonhost} = 1;
9423: delete($currsaml{$lonhost});
9424: }
9425: }
9426: }
9427: foreach my $posshost (keys(%currsaml)) {
9428: unless (exists($domservers{$posshost})) {
9429: delete($currsaml{$posshost});
9430: }
9431: }
9432: %{$loginhash{'login'}{'saml'}} = %currsaml;
9433: if (@newsamlimgs) {
9434: my $error;
9435: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9436: if ($configuserok eq 'ok') {
9437: if ($switchserver) {
9438: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
9439: } elsif ($author_ok eq 'ok') {
9440: foreach my $lonhost (@newsamlimgs) {
9441: my $formelem = 'saml_img_'.$lonhost;
9442: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9443: "login/saml/$lonhost",'','',
9444: $env{'form.saml_img_'.$lonhost.'.filename'});
9445: if ($result eq 'ok') {
9446: $currsaml{$lonhost}{'img'} = $imgurl;
9447: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
9448: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 9449: } else {
1.160.6.113 raeburn 9450: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
9451: $lonhost,$result);
1.160.6.56 raeburn 9452: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9453: }
9454: }
9455: } else {
1.160.6.113 raeburn 9456: $error = &mt("Upload of SSO button image file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
1.160.6.56 raeburn 9457: }
9458: } else {
1.160.6.113 raeburn 9459: $error = &mt("Upload of SSO button image file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
1.160.6.56 raeburn 9460: }
9461: if ($error) {
9462: &Apache::lonnet::logthis($error);
9463: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9464: }
9465: }
1.160.6.5 raeburn 9466: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
9467:
9468: my $defaulthelpfile = '/adm/loginproblems.html';
9469: my $defaulttext = &mt('Default in use');
9470:
1.1 raeburn 9471: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9472: $dom);
9473: if ($putresult eq 'ok') {
1.160.6.14 raeburn 9474: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9475: my %defaultchecked = (
9476: 'coursecatalog' => 'on',
1.160.6.14 raeburn 9477: 'helpdesk' => 'on',
1.42 raeburn 9478: 'adminmail' => 'off',
1.43 raeburn 9479: 'newuser' => 'off',
1.42 raeburn 9480: );
1.55 raeburn 9481: if (ref($domconfig{'login'}) eq 'HASH') {
9482: foreach my $item (@toggles) {
9483: if ($defaultchecked{$item} eq 'on') {
9484: if (($domconfig{'login'}{$item} eq '0') &&
9485: ($env{'form.'.$item} eq '1')) {
9486: $changes{$item} = 1;
9487: } elsif (($domconfig{'login'}{$item} eq '' ||
9488: $domconfig{'login'}{$item} eq '1') &&
9489: ($env{'form.'.$item} eq '0')) {
9490: $changes{$item} = 1;
9491: }
9492: } elsif ($defaultchecked{$item} eq 'off') {
9493: if (($domconfig{'login'}{$item} eq '1') &&
9494: ($env{'form.'.$item} eq '0')) {
9495: $changes{$item} = 1;
9496: } elsif (($domconfig{'login'}{$item} eq '' ||
9497: $domconfig{'login'}{$item} eq '0') &&
9498: ($env{'form.'.$item} eq '1')) {
9499: $changes{$item} = 1;
9500: }
1.42 raeburn 9501: }
9502: }
1.41 raeburn 9503: }
1.6 raeburn 9504: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9505: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 9506: if (exists($changes{'saml'})) {
9507: my $hostid_in_use;
9508: my @hosts = &Apache::lonnet::current_machine_ids();
9509: if (@hosts > 1) {
9510: foreach my $hostid (@hosts) {
9511: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
9512: $hostid_in_use = $hostid;
9513: last;
9514: }
9515: }
9516: } else {
9517: $hostid_in_use = $r->dir_config('lonHostID');
9518: }
9519: if (($hostid_in_use) &&
9520: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
9521: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
9522: }
9523: if (ref($lastactref) eq 'HASH') {
9524: if (ref($changes{'saml'}) eq 'HASH') {
9525: my %updates;
9526: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
9527: $lastactref->{'samllanding'} = \%updates;
9528: }
9529: }
9530: }
1.160.6.27 raeburn 9531: if (ref($lastactref) eq 'HASH') {
9532: $lastactref->{'domainconfig'} = 1;
9533: }
1.1 raeburn 9534: $resulttext = &mt('Changes made:').'<ul>';
9535: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9536: if ($item eq 'loginvia') {
1.112 raeburn 9537: if (ref($changes{$item}) eq 'HASH') {
9538: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9539: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9540: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9541: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9542: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9543: $protocol = 'http' if ($protocol ne 'https');
9544: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9545:
9546: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9547: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9548: } else {
9549: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9550: }
9551: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9552: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9553: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9554: }
9555: $resulttext .= '</li>';
9556: } else {
9557: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9558: }
1.112 raeburn 9559: } else {
1.128 raeburn 9560: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9561: }
9562: }
1.128 raeburn 9563: $resulttext .= '</ul></li>';
1.112 raeburn 9564: }
1.160.6.5 raeburn 9565: } elsif ($item eq 'helpurl') {
9566: if (ref($changes{$item}) eq 'HASH') {
9567: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9568: if (grep(/^\Q$lang\E$/,@delurls)) {
9569: my ($chg,$link);
9570: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9571: if ($lang eq 'nolang') {
9572: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9573: } else {
9574: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9575: }
9576: $resulttext .= '<li>'.$chg.'</li>';
9577: } else {
9578: my $chg;
9579: if ($lang eq 'nolang') {
9580: $chg = &mt('custom log-in help file for no preferred language');
9581: } else {
9582: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9583: }
9584: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9585: $loginhash{'login'}{'helpurl'}{$lang}.
9586: '?inhibitmenu=yes',$chg,600,500).
9587: '</li>';
9588: }
9589: }
9590: }
1.160.6.56 raeburn 9591: } elsif ($item eq 'headtag') {
9592: if (ref($changes{$item}) eq 'HASH') {
9593: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9594: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9595: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9596: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9597: $resulttext .= '<li><a href="'.
9598: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9599: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9600: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9601: if ($possexempt{$lonhost}) {
9602: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9603: } else {
9604: $resulttext .= &mt('included for any client IP');
9605: }
9606: $resulttext .= '</li>';
9607: }
9608: }
9609: }
1.160.6.113 raeburn 9610: } elsif ($item eq 'saml') {
9611: if (ref($changes{$item}) eq 'HASH') {
9612: my %notlt = (
9613: text => 'Text for log-in by SSO',
9614: img => 'SSO button image',
9615: alt => 'Alt text for button image',
9616: url => 'SSO URL',
9617: title => 'Tooltip for SSO link',
9618: notsso => 'Text for non-SSO log-in',
9619: );
9620: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9621: if (ref($currsaml{$lonhost}) eq 'HASH') {
9622: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
9623: '<ul>';
9624: foreach my $key ('text','img','alt','url','title','notsso') {
9625: if ($currsaml{$lonhost}{$key} eq '') {
9626: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
9627: } else {
9628: my $value = "'$currsaml{$lonhost}{$key}'";
9629: if ($key eq 'img') {
9630: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
9631: }
9632: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
9633: $value).'</li>';
9634: }
9635: }
9636: $resulttext .= '</ul></li>';
9637: } else {
9638: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
9639: }
9640: }
9641: }
1.160.6.5 raeburn 9642: } elsif ($item eq 'captcha') {
9643: if (ref($loginhash{'login'}) eq 'HASH') {
9644: my $chgtxt;
9645: if ($loginhash{'login'}{$item} eq 'notused') {
9646: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9647: } else {
9648: my %captchas = &captcha_phrases();
9649: if ($captchas{$loginhash{'login'}{$item}}) {
9650: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9651: } else {
9652: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9653: }
9654: }
9655: $resulttext .= '<li>'.$chgtxt.'</li>';
9656: }
9657: } elsif ($item eq 'recaptchakeys') {
9658: if (ref($loginhash{'login'}) eq 'HASH') {
9659: my ($privkey,$pubkey);
9660: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9661: $pubkey = $loginhash{'login'}{$item}{'public'};
9662: $privkey = $loginhash{'login'}{$item}{'private'};
9663: }
9664: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9665: if (!$pubkey) {
9666: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9667: } else {
9668: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9669: }
9670: if (!$privkey) {
9671: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9672: } else {
1.160.6.53 raeburn 9673: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 9674: }
9675: $chgtxt .= '</ul>';
9676: $resulttext .= '<li>'.$chgtxt.'</li>';
9677: }
1.160.6.69 raeburn 9678: } elsif ($item eq 'recaptchaversion') {
9679: if (ref($loginhash{'login'}) eq 'HASH') {
9680: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
9681: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
9682: '</li>';
9683: }
9684: }
1.41 raeburn 9685: } else {
9686: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9687: }
1.1 raeburn 9688: }
1.6 raeburn 9689: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9690: } else {
9691: $resulttext = &mt('No changes made to log-in page settings');
9692: }
9693: } else {
1.11 albertel 9694: $resulttext = '<span class="LC_error">'.
9695: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9696: }
1.6 raeburn 9697: if ($errors) {
1.9 raeburn 9698: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9699: $errors.'</ul>';
9700: }
9701: return $resulttext;
9702: }
9703:
1.160.6.56 raeburn 9704: sub check_exempt_addresses {
9705: my ($iplist) = @_;
9706: $iplist =~ s/^\s+//;
9707: $iplist =~ s/\s+$//;
9708: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9709: my (@okips,$new);
9710: foreach my $ip (@poss_ips) {
9711: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9712: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9713: push(@okips,$ip);
9714: }
9715: }
9716: }
9717: if (@okips > 0) {
9718: $new = join(',',@okips);
9719: } else {
9720: $new = '';
9721: }
9722: return $new;
9723: }
9724:
1.6 raeburn 9725: sub color_font_choices {
9726: my %choices =
9727: &Apache::lonlocal::texthash (
9728: bgs => "Background colors",
9729: links => "Link colors",
1.55 raeburn 9730: images => "Images",
1.6 raeburn 9731: font => "Font color",
1.160.6.22 raeburn 9732: fontmenu => "Font menu",
1.76 raeburn 9733: pgbg => "Page",
1.6 raeburn 9734: tabbg => "Header",
9735: sidebg => "Border",
9736: link => "Link",
9737: alink => "Active link",
9738: vlink => "Visited link",
9739: );
9740: return %choices;
9741: }
9742:
1.160.6.113 raeburn 9743: sub modify_ipaccess {
9744: my ($dom,$lastactref,%domconfig) = @_;
9745: my (@allpos,%changes,%confhash,$errors,$resulttext);
9746: my (@items,%deletions,%itemids,@warnings);
9747: my ($typeorder,$types) = &commblocktype_text();
9748: if ($env{'form.ipaccess_add'}) {
9749: my $name = $env{'form.ipaccess_name_add'};
9750: my ($newid,$error) = &get_ipaccess_id($dom,$name);
9751: if ($newid) {
9752: $itemids{'add'} = $newid;
9753: push(@items,'add');
9754: $changes{$newid} = 1;
9755: } else {
9756: $error = &mt('Failed to acquire unique ID for new IP access control item');
9757: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9758: }
9759: }
9760: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9761: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
9762: if (@todelete) {
9763: map { $deletions{$_} = 1; } @todelete;
9764: }
9765: my $maxnum = $env{'form.ipaccess_maxnum'};
9766: for (my $i=0; $i<$maxnum; $i++) {
9767: my $itemid = $env{'form.ipaccess_id_'.$i};
9768: $itemid =~ s/\D+//g;
9769: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9770: if ($deletions{$itemid}) {
9771: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
9772: } else {
9773: push(@items,$i);
9774: $itemids{$i} = $itemid;
9775: }
9776: }
9777: }
9778: }
9779: foreach my $idx (@items) {
9780: my $itemid = $itemids{$idx};
9781: next unless ($itemid);
1.160.6.126! raeburn 9782: my ($position,%current);
! 9783: if ($idx eq 'add') {
! 9784: $position = $env{'form.ipaccess_pos_add'};
! 9785: } else {
! 9786: $position = $env{'form.ipaccess_pos_'.$itemid};
1.160.6.113 raeburn 9787: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9788: %current = %{$domconfig{'ipaccess'}{$itemid}};
9789: }
9790: }
9791: $position =~ s/\D+//g;
9792: if ($position ne '') {
9793: $allpos[$position] = $itemid;
9794: }
9795: my $name = $env{'form.ipaccess_name_'.$idx};
9796: $name =~ s/^\s+|\s+$//g;
9797: $confhash{$itemid}{'name'} = $name;
9798: my $possrange = $env{'form.ipaccess_range_'.$idx};
9799: $possrange =~ s/^\s+|\s+$//g;
9800: unless ($possrange eq '') {
9801: $possrange =~ s/[\r\n]+/\s/g;
9802: $possrange =~ s/\s*-\s*/-/g;
9803: $possrange =~ s/\s+/,/g;
9804: $possrange =~ s/,+/,/g;
9805: if ($possrange ne '') {
9806: my (@ok,$count);
9807: $count = 0;
9808: foreach my $poss (split(/\,/,$possrange)) {
9809: $count ++;
9810: $poss = &validate_ip_pattern($poss);
9811: if ($poss ne '') {
9812: push(@ok,$poss);
9813: }
9814: }
9815: my $diff = $count - scalar(@ok);
9816: if ($diff) {
9817: $errors .= '<li><span class="LC_error">'.
9818: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
9819: $diff,$name).
9820: '</span></li>';
9821: }
9822: if (@ok) {
9823: my @cidr_list;
9824: foreach my $item (@ok) {
9825: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
9826: }
9827: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
9828: }
9829: }
9830: }
9831: foreach my $field ('name','ip') {
9832: unless (($idx eq 'add') || ($changes{$itemid})) {
9833: if ($current{$field} ne $confhash{$itemid}{$field}) {
9834: $changes{$itemid} = 1;
9835: last;
9836: }
9837: }
9838: }
9839: $confhash{$itemid}{'commblocks'} = {};
9840:
9841: my %commblocks;
9842: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
9843: foreach my $type (@{$typeorder}) {
9844: if ($commblocks{$type}) {
9845: $confhash{$itemid}{'commblocks'}{$type} = 'on';
9846: }
9847: unless (($idx eq 'add') || ($changes{$itemid})) {
9848: if (ref($current{'commblocks'}) eq 'HASH') {
9849: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
9850: $changes{$itemid} = 1;
9851: }
9852: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
9853: $changes{$itemid} = 1;
9854: }
9855: }
9856: }
9857: $confhash{$itemid}{'courses'} = {};
9858: my %crsdeletions;
9859: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
9860: if (@delcrs) {
9861: map { $crsdeletions{$_} = 1; } @delcrs;
9862: }
9863: if (ref($current{'courses'}) eq 'HASH') {
9864: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
9865: if ($crsdeletions{$cid}) {
9866: $changes{$itemid} = 1;
9867: } else {
9868: $confhash{$itemid}{'courses'}{$cid} = 1;
9869: }
9870: }
9871: }
9872: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
9873: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
9874: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
9875: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
9876: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
9877: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
9878: $errors .= '<li><span class="LC_error">'.
9879: &mt('Invalid courseID [_1] omitted from list of allowed courses',
9880: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
9881: '</span></li>';
9882: } else {
9883: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
9884: $changes{$itemid} = 1;
9885: }
9886: }
9887: }
9888: if (@allpos > 0) {
9889: my $idx = 0;
9890: foreach my $itemid (@allpos) {
9891: if ($itemid ne '') {
9892: $confhash{$itemid}{'order'} = $idx;
9893: unless ($changes{$itemid}) {
9894: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9895: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9896: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
9897: $changes{$itemid} = 1;
9898: }
9899: }
9900: }
9901: }
9902: $idx ++;
9903: }
9904: }
9905: }
9906: if (keys(%changes)) {
9907: my %defaultshash = (
9908: ipaccess => \%confhash,
9909: );
9910: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9911: $dom);
9912: if ($putresult eq 'ok') {
9913: my $cachetime = 1800;
9914: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
9915: if (ref($lastactref) eq 'HASH') {
9916: $lastactref->{'ipaccess'} = 1;
9917: }
9918: $resulttext = &mt('Changes made:').'<ul>';
9919: my %bynum;
9920: foreach my $itemid (sort(keys(%changes))) {
9921: if (ref($confhash{$itemid}) eq 'HASH') {
9922: my $position = $confhash{$itemid}{'order'};
9923: if ($position =~ /^\d+$/) {
9924: $bynum{$position} = $itemid;
9925: }
9926: }
9927: }
9928: if (keys(%deletions)) {
9929: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
9930: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9931: }
9932: }
9933: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9934: my $itemid = $bynum{$pos};
9935: if (ref($confhash{$itemid}) eq 'HASH') {
9936: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
9937: my $position = $pos + 1;
9938: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9939: if ($confhash{$itemid}{'ip'} eq '') {
9940: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
9941: } else {
9942: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
9943: }
9944: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
9945: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
9946: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
9947: '</li>';
9948: } else {
9949: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
9950: }
9951: if (keys(%{$confhash{$itemid}{'courses'}})) {
9952: my @courses;
9953: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
9954: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
9955: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
9956: }
9957: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
9958: join('</li><li>',@courses).'</li></ul>';
9959: } else {
9960: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
9961: }
9962: $resulttext .= '</ul></li>';
9963: }
9964: }
9965: $resulttext .= '</ul>';
9966: } else {
9967: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9968: }
9969: } else {
9970: $resulttext = &mt('No changes made');
9971: }
9972: if ($errors) {
9973: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
9974: $errors.'</ul></p>';
9975: }
9976: return $resulttext;
9977: }
9978:
9979: sub get_ipaccess_id {
9980: my ($domain,$location) = @_;
9981: # get lock on ipaccess db
9982: my $lockhash = {
9983: lock => $env{'user.name'}.
9984: ':'.$env{'user.domain'},
9985: };
9986: my $tries = 0;
9987: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
9988: my ($id,$error);
9989:
9990: while (($gotlock ne 'ok') && ($tries<10)) {
9991: $tries ++;
9992: sleep (0.1);
9993: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
9994: }
9995: if ($gotlock eq 'ok') {
9996: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
9997: if ($currids{'lock'}) {
9998: delete($currids{'lock'});
9999: if (keys(%currids)) {
10000: my @curr = sort { $a <=> $b } keys(%currids);
10001: if ($curr[-1] =~ /^\d+$/) {
10002: $id = 1 + $curr[-1];
10003: }
10004: } else {
10005: $id = 1;
10006: }
10007: if ($id) {
10008: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
10009: $error = 'nostore';
10010: }
10011: } else {
10012: $error = 'nonumber';
10013: }
10014: }
10015: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
10016: } else {
10017: $error = 'nolock';
10018: }
10019: return ($id,$error);
10020: }
10021:
1.6 raeburn 10022: sub modify_rolecolors {
1.160.6.24 raeburn 10023: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10024: my ($resulttext,%rolehash);
10025: $rolehash{'rolecolors'} = {};
1.55 raeburn 10026: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10027: if ($domconfig{'rolecolors'} eq '') {
10028: $domconfig{'rolecolors'} = {};
10029: }
10030: }
1.9 raeburn 10031: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10032: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10033: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10034: $dom);
10035: if ($putresult eq 'ok') {
10036: if (keys(%changes) > 0) {
1.41 raeburn 10037: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10038: if (ref($lastactref) eq 'HASH') {
10039: $lastactref->{'domainconfig'} = 1;
10040: }
1.6 raeburn 10041: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10042: $rolehash{'rolecolors'});
10043: } else {
10044: $resulttext = &mt('No changes made to default color schemes');
10045: }
10046: } else {
1.11 albertel 10047: $resulttext = '<span class="LC_error">'.
10048: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10049: }
10050: if ($errors) {
10051: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10052: $errors.'</ul>';
10053: }
10054: return $resulttext;
10055: }
10056:
10057: sub modify_colors {
1.9 raeburn 10058: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10059: my (%changes,%choices);
1.51 raeburn 10060: my @bgs;
1.6 raeburn 10061: my @links = ('link','alink','vlink');
1.41 raeburn 10062: my @logintext;
1.6 raeburn 10063: my @images;
10064: my $servadm = $r->dir_config('lonAdmEMail');
10065: my $errors;
1.160.6.22 raeburn 10066: my %defaults;
1.6 raeburn 10067: foreach my $role (@{$roles}) {
10068: if ($role eq 'login') {
1.12 raeburn 10069: %choices = &login_choices();
1.41 raeburn 10070: @logintext = ('textcol','bgcol');
1.12 raeburn 10071: } else {
10072: %choices = &color_font_choices();
10073: }
10074: if ($role eq 'login') {
1.41 raeburn 10075: @images = ('img','logo','domlogo','login');
1.51 raeburn 10076: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10077: } else {
1.160.6.125 raeburn 10078: @images = ();
1.160.6.22 raeburn 10079: @bgs = ('pgbg','tabbg','sidebg');
10080: }
10081: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.160.6.125 raeburn 10082: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
10083: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
10084: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
10085: }
10086: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.160.6.22 raeburn 10087: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10088: }
10089: if ($role eq 'login') {
10090: foreach my $item (@logintext) {
1.160.6.39 raeburn 10091: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10092: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10093: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10094: }
10095: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 10096: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10097: }
10098: }
10099: } else {
1.160.6.39 raeburn 10100: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10101: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10102: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10103: }
1.160.6.125 raeburn 10104: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 10105: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10106: }
1.6 raeburn 10107: }
1.160.6.22 raeburn 10108: foreach my $item (@bgs) {
1.160.6.39 raeburn 10109: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10110: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10111: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10112: }
10113: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 10114: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10115: }
10116: }
10117: foreach my $item (@links) {
1.160.6.39 raeburn 10118: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10119: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10120: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10121: }
10122: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 10123: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10124: }
1.6 raeburn 10125: }
1.46 raeburn 10126: my ($configuserok,$author_ok,$switchserver) =
10127: &config_check($dom,$confname,$servadm);
1.9 raeburn 10128: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10129: if (ref($domconfig->{$role}) ne 'HASH') {
10130: $domconfig->{$role} = {};
10131: }
1.8 raeburn 10132: foreach my $img (@images) {
1.160.6.119 raeburn 10133: if ($role eq 'login') {
10134: if (($img eq 'img') || ($img eq 'logo')) {
10135: if (defined($env{'form.login_showlogo_'.$img})) {
10136: $confhash->{$role}{'showlogo'}{$img} = 1;
10137: } else {
10138: $confhash->{$role}{'showlogo'}{$img} = 0;
10139: }
1.70 raeburn 10140: }
1.160.6.119 raeburn 10141: if ($env{'form.login_alt_'.$img} ne '') {
10142: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
10143: }
10144: }
1.18 albertel 10145: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10146: && !defined($domconfig->{$role}{$img})
10147: && !$env{'form.'.$role.'_del_'.$img}
10148: && $env{'form.'.$role.'_import_'.$img}) {
10149: # import the old configured image from the .tab setting
10150: # if they haven't provided a new one
10151: $domconfig->{$role}{$img} =
10152: $env{'form.'.$role.'_import_'.$img};
10153: }
1.6 raeburn 10154: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10155: my $error;
1.6 raeburn 10156: if ($configuserok eq 'ok') {
1.9 raeburn 10157: if ($switchserver) {
1.12 raeburn 10158: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10159: } else {
10160: if ($author_ok eq 'ok') {
10161: my ($result,$logourl) =
10162: &publishlogo($r,'upload',$role.'_'.$img,
10163: $dom,$confname,$img,$width,$height);
10164: if ($result eq 'ok') {
10165: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10166: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10167: } else {
1.12 raeburn 10168: $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 10169: }
10170: } else {
1.46 raeburn 10171: $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 10172: }
10173: }
10174: } else {
1.46 raeburn 10175: $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 10176: }
10177: if ($error) {
1.8 raeburn 10178: &Apache::lonnet::logthis($error);
1.11 albertel 10179: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10180: }
10181: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10182: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10183: my $error;
10184: if ($configuserok eq 'ok') {
10185: # is confname an author?
10186: if ($switchserver eq '') {
10187: if ($author_ok eq 'ok') {
10188: my ($result,$logourl) =
10189: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10190: $dom,$confname,$img,$width,$height);
10191: if ($result eq 'ok') {
10192: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10193: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10194: }
10195: }
10196: }
10197: }
1.6 raeburn 10198: }
10199: }
10200: }
10201: if (ref($domconfig) eq 'HASH') {
10202: if (ref($domconfig->{$role}) eq 'HASH') {
10203: foreach my $img (@images) {
10204: if ($domconfig->{$role}{$img} ne '') {
10205: if ($env{'form.'.$role.'_del_'.$img}) {
10206: $confhash->{$role}{$img} = '';
1.12 raeburn 10207: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10208: } else {
1.9 raeburn 10209: if ($confhash->{$role}{$img} eq '') {
10210: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10211: }
1.6 raeburn 10212: }
10213: } else {
10214: if ($env{'form.'.$role.'_del_'.$img}) {
10215: $confhash->{$role}{$img} = '';
1.12 raeburn 10216: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10217: }
10218: }
1.160.6.119 raeburn 10219: if ($role eq 'login') {
10220: if (($img eq 'logo') || ($img eq 'img')) {
10221: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10222: if ($confhash->{$role}{'showlogo'}{$img} ne
10223: $domconfig->{$role}{'showlogo'}{$img}) {
10224: $changes{$role}{'showlogo'}{$img} = 1;
10225: }
10226: } else {
10227: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10228: $changes{$role}{'showlogo'}{$img} = 1;
10229: }
1.70 raeburn 10230: }
1.160.6.119 raeburn 10231: }
10232: if ($img ne 'login') {
10233: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
10234: if ($confhash->{$role}{'alttext'}{$img} ne
10235: $domconfig->{$role}{'alttext'}{$img}) {
10236: $changes{$role}{'alttext'}{$img} = 1;
10237: }
10238: } else {
10239: if ($confhash->{$role}{'alttext'}{$img} ne '') {
10240: $changes{$role}{'alttext'}{$img} = 1;
10241: }
1.70 raeburn 10242: }
10243: }
10244: }
10245: }
1.6 raeburn 10246: if ($domconfig->{$role}{'font'} ne '') {
10247: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10248: $changes{$role}{'font'} = 1;
10249: }
10250: } else {
10251: if ($confhash->{$role}{'font'}) {
10252: $changes{$role}{'font'} = 1;
10253: }
10254: }
1.107 raeburn 10255: if ($role ne 'login') {
10256: if ($domconfig->{$role}{'fontmenu'} ne '') {
10257: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10258: $changes{$role}{'fontmenu'} = 1;
10259: }
10260: } else {
10261: if ($confhash->{$role}{'fontmenu'}) {
10262: $changes{$role}{'fontmenu'} = 1;
10263: }
1.97 tempelho 10264: }
10265: }
1.6 raeburn 10266: foreach my $item (@bgs) {
10267: if ($domconfig->{$role}{$item} ne '') {
10268: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10269: $changes{$role}{'bgs'}{$item} = 1;
10270: }
10271: } else {
10272: if ($confhash->{$role}{$item}) {
10273: $changes{$role}{'bgs'}{$item} = 1;
10274: }
10275: }
10276: }
10277: foreach my $item (@links) {
10278: if ($domconfig->{$role}{$item} ne '') {
10279: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10280: $changes{$role}{'links'}{$item} = 1;
10281: }
10282: } else {
10283: if ($confhash->{$role}{$item}) {
10284: $changes{$role}{'links'}{$item} = 1;
10285: }
10286: }
10287: }
1.41 raeburn 10288: foreach my $item (@logintext) {
10289: if ($domconfig->{$role}{$item} ne '') {
10290: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10291: $changes{$role}{'logintext'}{$item} = 1;
10292: }
10293: } else {
10294: if ($confhash->{$role}{$item}) {
10295: $changes{$role}{'logintext'}{$item} = 1;
10296: }
10297: }
10298: }
1.6 raeburn 10299: } else {
10300: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10301: \@logintext,$confhash,\%changes);
1.6 raeburn 10302: }
10303: } else {
10304: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10305: \@logintext,$confhash,\%changes);
1.6 raeburn 10306: }
10307: }
10308: return ($errors,%changes);
10309: }
10310:
1.46 raeburn 10311: sub config_check {
10312: my ($dom,$confname,$servadm) = @_;
10313: my ($configuserok,$author_ok,$switchserver,%currroles);
10314: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10315: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10316: $confname,$servadm);
10317: if ($configuserok eq 'ok') {
10318: $switchserver = &check_switchserver($dom,$confname);
10319: if ($switchserver eq '') {
10320: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10321: }
10322: }
10323: return ($configuserok,$author_ok,$switchserver);
10324: }
10325:
1.6 raeburn 10326: sub default_change_checker {
1.41 raeburn 10327: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10328: foreach my $item (@{$links}) {
10329: if ($confhash->{$role}{$item}) {
10330: $changes->{$role}{'links'}{$item} = 1;
10331: }
10332: }
10333: foreach my $item (@{$bgs}) {
10334: if ($confhash->{$role}{$item}) {
10335: $changes->{$role}{'bgs'}{$item} = 1;
10336: }
10337: }
1.41 raeburn 10338: foreach my $item (@{$logintext}) {
10339: if ($confhash->{$role}{$item}) {
10340: $changes->{$role}{'logintext'}{$item} = 1;
10341: }
10342: }
1.6 raeburn 10343: foreach my $img (@{$images}) {
10344: if ($env{'form.'.$role.'_del_'.$img}) {
10345: $confhash->{$role}{$img} = '';
1.12 raeburn 10346: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10347: }
1.70 raeburn 10348: if ($role eq 'login') {
10349: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10350: $changes->{$role}{'showlogo'}{$img} = 1;
10351: }
1.160.6.119 raeburn 10352: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
10353: if ($confhash->{$role}{'alttext'}{$img} ne '') {
10354: $changes->{$role}{'alttext'}{$img} = 1;
10355: }
10356: }
1.70 raeburn 10357: }
1.6 raeburn 10358: }
10359: if ($confhash->{$role}{'font'}) {
10360: $changes->{$role}{'font'} = 1;
10361: }
1.48 raeburn 10362: }
1.6 raeburn 10363:
10364: sub display_colorchgs {
10365: my ($dom,$changes,$roles,$confhash) = @_;
10366: my (%choices,$resulttext);
10367: if (!grep(/^login$/,@{$roles})) {
10368: $resulttext = &mt('Changes made:').'<br />';
10369: }
10370: foreach my $role (@{$roles}) {
10371: if ($role eq 'login') {
10372: %choices = &login_choices();
10373: } else {
10374: %choices = &color_font_choices();
10375: }
10376: if (ref($changes->{$role}) eq 'HASH') {
10377: if ($role ne 'login') {
10378: $resulttext .= '<h4>'.&mt($role).'</h4>';
10379: }
10380: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10381: if ($role ne 'login') {
10382: $resulttext .= '<ul>';
10383: }
10384: if (ref($changes->{$role}{$key}) eq 'HASH') {
10385: if ($role ne 'login') {
10386: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10387: }
10388: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10389: if (($role eq 'login') && ($key eq 'showlogo')) {
10390: if ($confhash->{$role}{$key}{$item}) {
10391: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10392: } else {
10393: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10394: }
1.160.6.119 raeburn 10395: } elsif (($role eq 'login') && ($key eq 'alttext')) {
10396: if ($confhash->{$role}{$key}{$item} ne '') {
1.160.6.120 raeburn 10397: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.160.6.119 raeburn 10398: $confhash->{$role}{$key}{$item}).'</li>';
10399: } else {
10400: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
10401: }
1.70 raeburn 10402: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10403: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10404: } else {
1.12 raeburn 10405: my $newitem = $confhash->{$role}{$item};
10406: if ($key eq 'images') {
10407: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
10408: }
10409: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10410: }
10411: }
10412: if ($role ne 'login') {
10413: $resulttext .= '</ul></li>';
10414: }
10415: } else {
10416: if ($confhash->{$role}{$key} eq '') {
10417: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10418: } else {
10419: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10420: }
10421: }
10422: if ($role ne 'login') {
10423: $resulttext .= '</ul>';
10424: }
10425: }
10426: }
10427: }
1.3 raeburn 10428: return $resulttext;
1.1 raeburn 10429: }
10430:
1.9 raeburn 10431: sub thumb_dimensions {
10432: return ('200','50');
10433: }
10434:
1.16 raeburn 10435: sub check_dimensions {
10436: my ($inputfile) = @_;
10437: my ($fullwidth,$fullheight);
10438: if ($inputfile =~ m|^[/\w.\-]+$|) {
10439: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10440: my $imageinfo = <PIPE>;
10441: if (!close(PIPE)) {
10442: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10443: }
10444: chomp($imageinfo);
10445: my ($fullsize) =
1.21 raeburn 10446: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10447: if ($fullsize) {
10448: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10449: }
10450: }
10451: }
10452: return ($fullwidth,$fullheight);
10453: }
10454:
1.9 raeburn 10455: sub check_configuser {
10456: my ($uhome,$dom,$confname,$servadm) = @_;
10457: my ($configuserok,%currroles);
10458: if ($uhome eq 'no_host') {
10459: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 10460: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 10461: $configuserok =
10462: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10463: $configpass,'','','','','',undef,$servadm);
10464: } else {
10465: $configuserok = 'ok';
10466: %currroles =
10467: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10468: }
10469: return ($configuserok,%currroles);
10470: }
10471:
10472: sub check_authorstatus {
10473: my ($dom,$confname,%currroles) = @_;
10474: my $author_ok;
1.40 raeburn 10475: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10476: my $start = time;
10477: my $end = 0;
10478: $author_ok =
10479: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10480: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10481: } else {
10482: $author_ok = 'ok';
10483: }
10484: return $author_ok;
10485: }
10486:
10487: sub publishlogo {
1.46 raeburn 10488: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 10489: my ($output,$fname,$logourl);
10490: if ($action eq 'upload') {
10491: $fname=$env{'form.'.$formname.'.filename'};
10492: chop($env{'form.'.$formname});
10493: } else {
10494: ($fname) = ($formname =~ /([^\/]+)$/);
10495: }
1.46 raeburn 10496: if ($savefileas ne '') {
10497: $fname = $savefileas;
10498: }
1.9 raeburn 10499: $fname=&Apache::lonnet::clean_filename($fname);
10500: # See if there is anything left
10501: unless ($fname) { return ('error: no uploaded file'); }
10502: $fname="$subdir/$fname";
1.160.6.5 raeburn 10503: my $docroot=$r->dir_config('lonDocRoot');
10504: my $filepath="$docroot/priv";
10505: my $relpath = "$dom/$confname";
1.9 raeburn 10506: my ($fnamepath,$file,$fetchthumb);
10507: $file=$fname;
10508: if ($fname=~m|/|) {
10509: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10510: }
1.160.6.26 raeburn 10511: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10512: my $count;
1.160.6.5 raeburn 10513: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10514: $filepath.="/$parts[$count]";
10515: if ((-e $filepath)!=1) {
10516: mkdir($filepath,02770);
10517: }
10518: }
10519: # Check for bad extension and disallow upload
10520: if ($file=~/\.(\w+)$/ &&
10521: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10522: $output =
1.160.6.25 raeburn 10523: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10524: } elsif ($file=~/\.(\w+)$/ &&
10525: !defined(&Apache::loncommon::fileembstyle($1))) {
10526: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10527: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 10528: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 10529: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 10530: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10531: } else {
10532: my $source = $filepath.'/'.$file;
10533: my $logfile;
1.160.6.88 raeburn 10534: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 10535: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10536: }
10537: print $logfile
10538: "\n================= Publish ".localtime()." ================\n".
10539: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10540: # Save the file
1.160.6.88 raeburn 10541: if (!open(FH,">",$source)) {
1.9 raeburn 10542: &Apache::lonnet::logthis('Failed to create '.$source);
10543: return (&mt('Failed to create file'));
10544: }
10545: if ($action eq 'upload') {
10546: if (!print FH ($env{'form.'.$formname})) {
10547: &Apache::lonnet::logthis('Failed to write to '.$source);
10548: return (&mt('Failed to write file'));
10549: }
10550: } else {
10551: my $original = &Apache::lonnet::filelocation('',$formname);
10552: if(!copy($original,$source)) {
10553: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10554: return (&mt('Failed to write file'));
10555: }
10556: }
10557: close(FH);
10558: chmod(0660, $source); # Permissions to rw-rw---.
10559:
10560: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10561: my $copyfile=$targetdir.'/'.$file;
10562:
10563: my @parts=split(/\//,$targetdir);
10564: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10565: for (my $count=5;$count<=$#parts;$count++) {
10566: $path.="/$parts[$count]";
10567: if (!-e $path) {
10568: print $logfile "\nCreating directory ".$path;
10569: mkdir($path,02770);
10570: }
10571: }
10572: my $versionresult;
10573: if (-e $copyfile) {
10574: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10575: } else {
10576: $versionresult = 'ok';
10577: }
10578: if ($versionresult eq 'ok') {
10579: if (copy($source,$copyfile)) {
10580: print $logfile "\nCopied original source to ".$copyfile."\n";
10581: $output = 'ok';
10582: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10583: push(@{$modified_urls},[$copyfile,$source]);
10584: my $metaoutput =
10585: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10586: unless ($registered_cleanup) {
10587: my $handlers = $r->get_handlers('PerlCleanupHandler');
10588: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10589: $registered_cleanup=1;
10590: }
1.9 raeburn 10591: } else {
10592: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10593: $output = &mt('Failed to copy file to RES space').", $!";
10594: }
10595: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10596: my $inputfile = $filepath.'/'.$file;
10597: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10598: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10599: if ($fullwidth ne '' && $fullheight ne '') {
10600: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10601: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 10602: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10603: system({$args[0]} @args);
1.16 raeburn 10604: chmod(0660, $filepath.'/tn-'.$file);
10605: if (-e $outfile) {
10606: my $copyfile=$targetdir.'/tn-'.$file;
10607: if (copy($outfile,$copyfile)) {
10608: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10609: my $thumb_metaoutput =
10610: &write_metadata($dom,$confname,$formname,
10611: $targetdir,'tn-'.$file,$logfile);
10612: push(@{$modified_urls},[$copyfile,$outfile]);
10613: unless ($registered_cleanup) {
10614: my $handlers = $r->get_handlers('PerlCleanupHandler');
10615: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10616: $registered_cleanup=1;
10617: }
1.16 raeburn 10618: } else {
10619: print $logfile "\nUnable to write ".$copyfile.
10620: ':'.$!."\n";
10621: }
10622: }
1.9 raeburn 10623: }
10624: }
10625: }
10626: } else {
10627: $output = $versionresult;
10628: }
10629: }
10630: return ($output,$logourl);
10631: }
10632:
10633: sub logo_versioning {
10634: my ($targetdir,$file,$logfile) = @_;
10635: my $target = $targetdir.'/'.$file;
10636: my ($maxversion,$fn,$extn,$output);
10637: $maxversion = 0;
10638: if ($file =~ /^(.+)\.(\w+)$/) {
10639: $fn=$1;
10640: $extn=$2;
10641: }
10642: opendir(DIR,$targetdir);
10643: while (my $filename=readdir(DIR)) {
10644: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10645: $maxversion=($1>$maxversion)?$1:$maxversion;
10646: }
10647: }
10648: $maxversion++;
10649: print $logfile "\nCreating old version ".$maxversion."\n";
10650: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10651: if (copy($target,$copyfile)) {
10652: print $logfile "Copied old target to ".$copyfile."\n";
10653: $copyfile=$copyfile.'.meta';
10654: if (copy($target.'.meta',$copyfile)) {
10655: print $logfile "Copied old target metadata to ".$copyfile."\n";
10656: $output = 'ok';
10657: } else {
10658: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10659: $output = &mt('Failed to copy old meta').", $!, ";
10660: }
10661: } else {
10662: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10663: $output = &mt('Failed to copy old target').", $!, ";
10664: }
10665: return $output;
10666: }
10667:
10668: sub write_metadata {
10669: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10670: my (%metadatafields,%metadatakeys,$output);
10671: $metadatafields{'title'}=$formname;
10672: $metadatafields{'creationdate'}=time;
10673: $metadatafields{'lastrevisiondate'}=time;
10674: $metadatafields{'copyright'}='public';
10675: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10676: $env{'user.domain'};
10677: $metadatafields{'authorspace'}=$confname.':'.$dom;
10678: $metadatafields{'domain'}=$dom;
10679: {
10680: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10681: my $mfh;
1.160.6.88 raeburn 10682: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 10683: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10684: unless ($_=~/\./) {
10685: my $unikey=$_;
10686: $unikey=~/^([A-Za-z]+)/;
10687: my $tag=$1;
10688: $tag=~tr/A-Z/a-z/;
10689: print $mfh "\n\<$tag";
10690: foreach (split(/\,/,$metadatakeys{$unikey})) {
10691: my $value=$metadatafields{$unikey.'.'.$_};
10692: $value=~s/\"/\'\'/g;
10693: print $mfh ' '.$_.'="'.$value.'"';
10694: }
10695: print $mfh '>'.
10696: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10697: .'</'.$tag.'>';
10698: }
10699: }
10700: $output = 'ok';
10701: print $logfile "\nWrote metadata";
10702: close($mfh);
10703: } else {
10704: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10705: $output = &mt('Could not write metadata');
10706: }
10707: }
1.155 raeburn 10708: return $output;
10709: }
10710:
10711: sub notifysubscribed {
10712: foreach my $targetsource (@{$modified_urls}){
10713: next unless (ref($targetsource) eq 'ARRAY');
10714: my ($target,$source)=@{$targetsource};
10715: if ($source ne '') {
1.160.6.88 raeburn 10716: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10717: print $logfh "\nCleanup phase: Notifications\n";
10718: my @subscribed=&subscribed_hosts($target);
10719: foreach my $subhost (@subscribed) {
10720: print $logfh "\nNotifying host ".$subhost.':';
10721: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10722: print $logfh $reply;
10723: }
10724: my @subscribedmeta=&subscribed_hosts("$target.meta");
10725: foreach my $subhost (@subscribedmeta) {
10726: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10727: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10728: $subhost);
10729: print $logfh $reply;
10730: }
10731: print $logfh "\n============ Done ============\n";
1.160 raeburn 10732: close($logfh);
1.155 raeburn 10733: }
10734: }
10735: }
10736: return OK;
10737: }
10738:
10739: sub subscribed_hosts {
10740: my ($target) = @_;
10741: my @subscribed;
1.160.6.88 raeburn 10742: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10743: while (my $subline=<$fh>) {
10744: if ($subline =~ /^($match_lonid):/) {
10745: my $host = $1;
10746: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10747: unless (grep(/^\Q$host\E$/,@subscribed)) {
10748: push(@subscribed,$host);
10749: }
10750: }
10751: }
10752: }
10753: }
10754: return @subscribed;
1.9 raeburn 10755: }
10756:
10757: sub check_switchserver {
10758: my ($dom,$confname) = @_;
10759: my ($allowed,$switchserver);
10760: my $home = &Apache::lonnet::homeserver($confname,$dom);
10761: if ($home eq 'no_host') {
10762: $home = &Apache::lonnet::domain($dom,'primary');
10763: }
10764: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10765: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10766: if (!$allowed) {
1.160.6.11 raeburn 10767: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10768: }
10769: return $switchserver;
10770: }
10771:
1.1 raeburn 10772: sub modify_quotas {
1.160.6.30 raeburn 10773: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10774: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 10775: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 10776: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10777: $validationfieldsref);
1.86 raeburn 10778: if ($action eq 'quotas') {
10779: $context = 'tools';
1.160.6.26 raeburn 10780: } else {
1.86 raeburn 10781: $context = $action;
10782: }
10783: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 10784: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 10785: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10786: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10787: %titles = &courserequest_titles();
10788: $toolregexp = join('|',@usertools);
10789: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 10790: $confname = $dom.'-domainconfig';
10791: my $servadm = $r->dir_config('lonAdmEMail');
10792: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 10793: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10794: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 10795: } elsif ($context eq 'requestauthor') {
10796: @usertools = ('author');
10797: %titles = &authorrequest_titles();
1.86 raeburn 10798: } else {
1.160.6.4 raeburn 10799: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10800: %titles = &tool_titles();
1.86 raeburn 10801: }
1.160.6.27 raeburn 10802: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10803: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10804: foreach my $key (keys(%env)) {
1.101 raeburn 10805: if ($context eq 'requestcourses') {
10806: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10807: my $item = $1;
10808: my $type = $2;
10809: if ($type =~ /^limit_(.+)/) {
10810: $limithash{$item}{$1} = $env{$key};
10811: } else {
10812: $confhash{$item}{$type} = $env{$key};
10813: }
10814: }
1.160.6.5 raeburn 10815: } elsif ($context eq 'requestauthor') {
10816: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10817: $confhash{$1} = $env{$key};
10818: }
1.101 raeburn 10819: } else {
1.86 raeburn 10820: if ($key =~ /^form\.quota_(.+)$/) {
10821: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 10822: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10823: $confhash{'authorquota'}{$1} = $env{$key};
10824: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10825: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10826: }
1.72 raeburn 10827: }
10828: }
1.160.6.5 raeburn 10829: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 10830: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10831: @approvalnotify = sort(@approvalnotify);
10832: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 10833: my @crstypes = ('official','unofficial','community','textbook');
10834: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10835: foreach my $type (@hasuniquecode) {
10836: if (grep(/^\Q$type\E$/,@crstypes)) {
10837: $confhash{'uniquecode'}{$type} = 1;
10838: }
10839: }
1.160.6.46 raeburn 10840: my (%newbook,%allpos);
1.160.6.30 raeburn 10841: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10842: foreach my $type ('textbooks','templates') {
10843: @{$allpos{$type}} = ();
10844: my $invalid;
10845: if ($type eq 'textbooks') {
10846: $invalid = &mt('Invalid LON-CAPA course for textbook');
10847: } else {
10848: $invalid = &mt('Invalid LON-CAPA course for template');
10849: }
10850: if ($env{'form.'.$type.'_addbook'}) {
10851: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10852: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10853: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10854: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10855: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10856: } else {
10857: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10858: my $position = $env{'form.'.$type.'_addbook_pos'};
10859: $position =~ s/\D+//g;
10860: if ($position ne '') {
10861: $allpos{$type}[$position] = $newbook{$type};
10862: }
1.160.6.30 raeburn 10863: }
1.160.6.46 raeburn 10864: } else {
10865: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 10866: }
10867: }
1.160.6.46 raeburn 10868: }
1.160.6.30 raeburn 10869: }
1.102 raeburn 10870: if (ref($domconfig{$action}) eq 'HASH') {
10871: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10872: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10873: $changes{'notify'}{'approval'} = 1;
10874: }
10875: } else {
1.144 raeburn 10876: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10877: $changes{'notify'}{'approval'} = 1;
10878: }
10879: }
1.160.6.30 raeburn 10880: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10881: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10882: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10883: unless ($confhash{'uniquecode'}{$crstype}) {
10884: $changes{'uniquecode'} = 1;
10885: }
10886: }
10887: unless ($changes{'uniquecode'}) {
10888: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10889: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10890: $changes{'uniquecode'} = 1;
10891: }
10892: }
10893: }
10894: } else {
10895: $changes{'uniquecode'} = 1;
10896: }
10897: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10898: $changes{'uniquecode'} = 1;
10899: }
10900: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10901: foreach my $type ('textbooks','templates') {
10902: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10903: my %deletions;
10904: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10905: if (@todelete) {
10906: map { $deletions{$_} = 1; } @todelete;
10907: }
10908: my %imgdeletions;
10909: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10910: if (@todeleteimages) {
10911: map { $imgdeletions{$_} = 1; } @todeleteimages;
10912: }
10913: my $maxnum = $env{'form.'.$type.'_maxnum'};
10914: for (my $i=0; $i<=$maxnum; $i++) {
10915: my $itemid = $env{'form.'.$type.'_id_'.$i};
10916: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10917: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10918: if ($deletions{$key}) {
10919: if ($domconfig{$action}{$type}{$key}{'image'}) {
10920: #FIXME need to obsolete item in RES space
10921: }
10922: next;
10923: } else {
10924: my $newpos = $env{'form.'.$itemid};
10925: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 10926: foreach my $item ('subject','title','publisher','author') {
10927: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10928: ($type eq 'templates'));
1.160.6.46 raeburn 10929: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10930: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10931: $changes{$type}{$key} = 1;
10932: }
10933: }
10934: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 10935: }
1.160.6.46 raeburn 10936: if ($imgdeletions{$key}) {
10937: $changes{$type}{$key} = 1;
10938: #FIXME need to obsolete item in RES space
10939: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10940: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 10941: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10942: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10943: } else {
10944: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10945: $cdom,$cnum,$type,$configuserok,
10946: $switchserver,$author_ok);
10947: if ($imgurl) {
10948: $confhash{$type}{$key}{'image'} = $imgurl;
10949: $changes{$type}{$key} = 1;
10950: }
10951: if ($error) {
10952: &Apache::lonnet::logthis($error);
10953: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10954: }
1.160.6.46 raeburn 10955: }
10956: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10957: $confhash{$type}{$key}{'image'} =
10958: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 10959: }
10960: }
10961: }
10962: }
10963: }
10964: }
1.102 raeburn 10965: } else {
1.144 raeburn 10966: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10967: $changes{'notify'}{'approval'} = 1;
10968: }
1.160.6.30 raeburn 10969: if (ref($confhash{'uniquecode'} eq 'HASH')) {
10970: $changes{'uniquecode'} = 1;
10971: }
10972: }
10973: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10974: foreach my $type ('textbooks','templates') {
10975: if ($newbook{$type}) {
10976: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 10977: foreach my $item ('subject','title','publisher','author') {
10978: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10979: ($type eq 'template'));
1.160.6.46 raeburn 10980: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10981: if ($env{'form.'.$type.'_addbook_'.$item}) {
10982: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10983: }
10984: }
10985: if ($type eq 'textbooks') {
10986: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10987: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 10988: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10989: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10990: } else {
10991: my ($imageurl,$error) =
10992: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10993: $configuserok,$switchserver,$author_ok);
10994: if ($imageurl) {
10995: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10996: }
10997: if ($error) {
10998: &Apache::lonnet::logthis($error);
10999: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11000: }
1.160.6.46 raeburn 11001: }
11002: }
1.160.6.30 raeburn 11003: }
11004: }
1.160.6.46 raeburn 11005: if (@{$allpos{$type}} > 0) {
11006: my $idx = 0;
11007: foreach my $item (@{$allpos{$type}}) {
11008: if ($item ne '') {
11009: $confhash{$type}{$item}{'order'} = $idx;
11010: if (ref($domconfig{$action}) eq 'HASH') {
11011: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11012: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11013: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11014: $changes{$type}{$item} = 1;
11015: }
1.160.6.30 raeburn 11016: }
11017: }
11018: }
1.160.6.46 raeburn 11019: $idx ++;
1.160.6.30 raeburn 11020: }
11021: }
11022: }
11023: }
1.160.6.39 raeburn 11024: if (ref($validationitemsref) eq 'ARRAY') {
11025: foreach my $item (@{$validationitemsref}) {
11026: if ($item eq 'fields') {
11027: my @changed;
11028: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11029: if (@{$confhash{'validation'}{$item}} > 0) {
11030: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11031: }
1.160.6.65 raeburn 11032: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11033: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11034: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11035: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11036: $domconfig{'requestcourses'}{'validation'}{$item});
11037: } else {
11038: @changed = @{$confhash{'validation'}{$item}};
11039: }
1.160.6.39 raeburn 11040: } else {
11041: @changed = @{$confhash{'validation'}{$item}};
11042: }
11043: } else {
11044: @changed = @{$confhash{'validation'}{$item}};
11045: }
11046: if (@changed) {
11047: if ($confhash{'validation'}{$item}) {
11048: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11049: } else {
11050: $changes{'validation'}{$item} = &mt('None');
11051: }
11052: }
11053: } else {
11054: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11055: if ($item eq 'markup') {
11056: if ($env{'form.requestcourses_validation_'.$item}) {
11057: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11058: }
11059: }
1.160.6.65 raeburn 11060: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11061: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11062: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11063: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11064: }
11065: } else {
11066: if ($confhash{'validation'}{$item} ne '') {
11067: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11068: }
1.160.6.39 raeburn 11069: }
11070: } else {
11071: if ($confhash{'validation'}{$item} ne '') {
11072: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11073: }
11074: }
11075: }
11076: }
11077: }
11078: if ($env{'form.validationdc'}) {
11079: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 11080: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 11081: if (exists($domcoords{$newval})) {
11082: $confhash{'validation'}{'dc'} = $newval;
11083: }
11084: }
11085: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 11086: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11087: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11088: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11089: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11090: if ($confhash{'validation'}{'dc'} eq '') {
11091: $changes{'validation'}{'dc'} = &mt('None');
11092: } else {
11093: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11094: }
1.160.6.39 raeburn 11095: }
1.160.6.65 raeburn 11096: } elsif ($confhash{'validation'}{'dc'} ne '') {
11097: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 11098: }
11099: } elsif ($confhash{'validation'}{'dc'} ne '') {
11100: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11101: }
11102: } elsif ($confhash{'validation'}{'dc'} ne '') {
11103: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11104: }
1.160.6.65 raeburn 11105: } else {
11106: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11107: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11108: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11109: $changes{'validation'}{'dc'} = &mt('None');
11110: }
11111: }
1.160.6.39 raeburn 11112: }
11113: }
1.102 raeburn 11114: }
11115: } else {
1.86 raeburn 11116: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 11117: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11118: }
1.72 raeburn 11119: foreach my $item (@usertools) {
11120: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11121: my $unset;
1.101 raeburn 11122: if ($context eq 'requestcourses') {
1.104 raeburn 11123: $unset = '0';
11124: if ($type eq '_LC_adv') {
11125: $unset = '';
11126: }
1.101 raeburn 11127: if ($confhash{$item}{$type} eq 'autolimit') {
11128: $confhash{$item}{$type} .= '=';
11129: unless ($limithash{$item}{$type} =~ /\D/) {
11130: $confhash{$item}{$type} .= $limithash{$item}{$type};
11131: }
11132: }
1.160.6.5 raeburn 11133: } elsif ($context eq 'requestauthor') {
11134: $unset = '0';
11135: if ($type eq '_LC_adv') {
11136: $unset = '';
11137: }
1.72 raeburn 11138: } else {
1.101 raeburn 11139: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11140: $confhash{$item}{$type} = 1;
11141: } else {
11142: $confhash{$item}{$type} = 0;
11143: }
1.72 raeburn 11144: }
1.86 raeburn 11145: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 11146: if ($action eq 'requestauthor') {
11147: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11148: $changes{$type} = 1;
11149: }
11150: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11151: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11152: $changes{$item}{$type} = 1;
11153: }
11154: } else {
11155: if ($context eq 'requestcourses') {
1.104 raeburn 11156: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11157: $changes{$item}{$type} = 1;
11158: }
11159: } else {
11160: if (!$confhash{$item}{$type}) {
11161: $changes{$item}{$type} = 1;
11162: }
11163: }
11164: }
11165: } else {
11166: if ($context eq 'requestcourses') {
1.104 raeburn 11167: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11168: $changes{$item}{$type} = 1;
11169: }
1.160.6.5 raeburn 11170: } elsif ($context eq 'requestauthor') {
11171: if ($confhash{$type} ne $unset) {
11172: $changes{$type} = 1;
11173: }
1.72 raeburn 11174: } else {
11175: if (!$confhash{$item}{$type}) {
11176: $changes{$item}{$type} = 1;
11177: }
11178: }
11179: }
1.1 raeburn 11180: }
11181: }
1.160.6.5 raeburn 11182: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11183: if (ref($domconfig{'quotas'}) eq 'HASH') {
11184: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11185: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11186: if (exists($confhash{'defaultquota'}{$key})) {
11187: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11188: $changes{'defaultquota'}{$key} = 1;
11189: }
11190: } else {
11191: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11192: }
11193: }
1.86 raeburn 11194: } else {
11195: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11196: if (exists($confhash{'defaultquota'}{$key})) {
11197: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11198: $changes{'defaultquota'}{$key} = 1;
11199: }
11200: } else {
11201: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11202: }
1.1 raeburn 11203: }
11204: }
1.160.6.20 raeburn 11205: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11206: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11207: if (exists($confhash{'authorquota'}{$key})) {
11208: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11209: $changes{'authorquota'}{$key} = 1;
11210: }
11211: } else {
11212: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11213: }
11214: }
11215: }
1.1 raeburn 11216: }
1.86 raeburn 11217: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11218: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11219: if (ref($domconfig{'quotas'}) eq 'HASH') {
11220: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11221: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11222: $changes{'defaultquota'}{$key} = 1;
11223: }
11224: } else {
11225: if (!exists($domconfig{'quotas'}{$key})) {
11226: $changes{'defaultquota'}{$key} = 1;
11227: }
1.72 raeburn 11228: }
11229: } else {
1.86 raeburn 11230: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11231: }
1.1 raeburn 11232: }
11233: }
1.160.6.20 raeburn 11234: if (ref($confhash{'authorquota'}) eq 'HASH') {
11235: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11236: if (ref($domconfig{'quotas'}) eq 'HASH') {
11237: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11238: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11239: $changes{'authorquota'}{$key} = 1;
11240: }
11241: } else {
11242: $changes{'authorquota'}{$key} = 1;
11243: }
11244: } else {
11245: $changes{'authorquota'}{$key} = 1;
11246: }
11247: }
11248: }
1.1 raeburn 11249: }
1.72 raeburn 11250:
1.160.6.5 raeburn 11251: if ($context eq 'requestauthor') {
11252: $domdefaults{'requestauthor'} = \%confhash;
11253: } else {
11254: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 11255: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 11256: $domdefaults{$key} = $confhash{$key};
11257: }
1.160.6.5 raeburn 11258: }
1.72 raeburn 11259: }
1.160.6.5 raeburn 11260:
1.1 raeburn 11261: my %quotahash = (
1.86 raeburn 11262: $action => { %confhash }
1.1 raeburn 11263: );
11264: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11265: $dom);
11266: if ($putresult eq 'ok') {
11267: if (keys(%changes) > 0) {
1.72 raeburn 11268: my $cachetime = 24*60*60;
11269: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11270: if (ref($lastactref) eq 'HASH') {
11271: $lastactref->{'domdefaults'} = 1;
11272: }
1.1 raeburn 11273: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 11274: unless (($context eq 'requestcourses') ||
11275: ($context eq 'requestauthor')) {
1.86 raeburn 11276: if (ref($changes{'defaultquota'}) eq 'HASH') {
11277: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11278: foreach my $type (@{$types},'default') {
11279: if (defined($changes{'defaultquota'}{$type})) {
11280: my $typetitle = $usertypes->{$type};
11281: if ($type eq 'default') {
11282: $typetitle = $othertitle;
11283: }
1.160.6.28 raeburn 11284: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11285: }
11286: }
1.86 raeburn 11287: $resulttext .= '</ul></li>';
1.72 raeburn 11288: }
1.160.6.20 raeburn 11289: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 11290: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 11291: foreach my $type (@{$types},'default') {
11292: if (defined($changes{'authorquota'}{$type})) {
11293: my $typetitle = $usertypes->{$type};
11294: if ($type eq 'default') {
11295: $typetitle = $othertitle;
11296: }
1.160.6.28 raeburn 11297: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 11298: }
11299: }
11300: $resulttext .= '</ul></li>';
11301: }
1.72 raeburn 11302: }
1.80 raeburn 11303: my %newenv;
1.72 raeburn 11304: foreach my $item (@usertools) {
1.160.6.5 raeburn 11305: my (%haschgs,%inconf);
11306: if ($context eq 'requestauthor') {
11307: %haschgs = %changes;
11308: %inconf = %confhash;
11309: } else {
11310: if (ref($changes{$item}) eq 'HASH') {
11311: %haschgs = %{$changes{$item}};
11312: }
11313: if (ref($confhash{$item}) eq 'HASH') {
11314: %inconf = %{$confhash{$item}};
11315: }
11316: }
11317: if (keys(%haschgs) > 0) {
1.80 raeburn 11318: my $newacc =
11319: &Apache::lonnet::usertools_access($env{'user.name'},
11320: $env{'user.domain'},
1.86 raeburn 11321: $item,'reload',$context);
1.160.6.5 raeburn 11322: if (($context eq 'requestcourses') ||
11323: ($context eq 'requestauthor')) {
1.108 raeburn 11324: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11325: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11326: }
11327: } else {
11328: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11329: $newenv{'environment.availabletools.'.$item} = $newacc;
11330: }
1.80 raeburn 11331: }
1.160.6.5 raeburn 11332: unless ($context eq 'requestauthor') {
11333: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11334: }
1.72 raeburn 11335: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 11336: if ($haschgs{$type}) {
1.72 raeburn 11337: my $typetitle = $usertypes->{$type};
11338: if ($type eq 'default') {
11339: $typetitle = $othertitle;
11340: } elsif ($type eq '_LC_adv') {
11341: $typetitle = 'LON-CAPA Advanced Users';
11342: }
1.160.6.5 raeburn 11343: if ($inconf{$type}) {
1.101 raeburn 11344: if ($context eq 'requestcourses') {
11345: my $cond;
1.160.6.5 raeburn 11346: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11347: if ($1 eq '') {
11348: $cond = &mt('(Automatic processing of any request).');
11349: } else {
11350: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11351: }
11352: } else {
1.160.6.5 raeburn 11353: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11354: }
11355: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 11356: } elsif ($context eq 'requestauthor') {
11357: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11358: $titles{$inconf{$type}},$typetitle);
11359:
1.101 raeburn 11360: } else {
11361: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11362: }
1.72 raeburn 11363: } else {
1.104 raeburn 11364: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 11365: if ($inconf{$type} eq '0') {
1.104 raeburn 11366: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11367: } else {
11368: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11369: }
11370: } else {
11371: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11372: }
1.72 raeburn 11373: }
11374: }
1.26 raeburn 11375: }
1.160.6.5 raeburn 11376: unless ($context eq 'requestauthor') {
11377: $resulttext .= '</ul></li>';
11378: }
1.26 raeburn 11379: }
1.1 raeburn 11380: }
1.160.6.5 raeburn 11381: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11382: if (ref($changes{'notify'}) eq 'HASH') {
11383: if ($changes{'notify'}{'approval'}) {
11384: if (ref($confhash{'notify'}) eq 'HASH') {
11385: if ($confhash{'notify'}{'approval'}) {
11386: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11387: } else {
1.160.6.5 raeburn 11388: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11389: }
11390: }
11391: }
11392: }
11393: }
1.160.6.30 raeburn 11394: if ($action eq 'requestcourses') {
11395: my @offon = ('off','on');
11396: if ($changes{'uniquecode'}) {
11397: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11398: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11399: $resulttext .= '<li>'.
11400: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11401: '</li>';
11402: } else {
11403: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11404: '</li>';
11405: }
11406: }
1.160.6.46 raeburn 11407: foreach my $type ('textbooks','templates') {
11408: if (ref($changes{$type}) eq 'HASH') {
11409: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11410: foreach my $key (sort(keys(%{$changes{$type}}))) {
11411: my %coursehash = &Apache::lonnet::coursedescription($key);
11412: my $coursetitle = $coursehash{'description'};
11413: my $position = $confhash{$type}{$key}{'order'} + 1;
11414: $resulttext .= '<li>';
1.160.6.47 raeburn 11415: foreach my $item ('subject','title','publisher','author') {
11416: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11417: ($type eq 'templates'));
1.160.6.46 raeburn 11418: my $name = $item.':';
11419: $name =~ s/^(\w)/\U$1/;
11420: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11421: }
11422: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11423: if ($type eq 'textbooks') {
11424: if ($confhash{$type}{$key}{'image'}) {
11425: $resulttext .= ' '.&mt('Image: [_1]',
11426: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11427: ' alt="Textbook cover" />').'<br />';
11428: }
11429: }
11430: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 11431: }
1.160.6.46 raeburn 11432: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 11433: }
11434: }
1.160.6.39 raeburn 11435: if (ref($changes{'validation'}) eq 'HASH') {
11436: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11437: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11438: foreach my $item (@{$validationitemsref}) {
11439: if (exists($changes{'validation'}{$item})) {
11440: if ($item eq 'markup') {
11441: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11442: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11443: } else {
11444: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11445: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11446: }
11447: }
11448: }
11449: if (exists($changes{'validation'}{'dc'})) {
11450: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11451: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11452: }
1.160.6.124 raeburn 11453: $resulttext .= '</ul></li>';
1.160.6.39 raeburn 11454: }
11455: }
1.160.6.30 raeburn 11456: }
1.1 raeburn 11457: $resulttext .= '</ul>';
1.80 raeburn 11458: if (keys(%newenv)) {
11459: &Apache::lonnet::appenv(\%newenv);
11460: }
1.1 raeburn 11461: } else {
1.86 raeburn 11462: if ($context eq 'requestcourses') {
11463: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 11464: } elsif ($context eq 'requestauthor') {
11465: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11466: } else {
1.90 weissno 11467: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11468: }
1.1 raeburn 11469: }
11470: } else {
1.11 albertel 11471: $resulttext = '<span class="LC_error">'.
11472: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11473: }
1.160.6.30 raeburn 11474: if ($errors) {
11475: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11476: '<ul>'.$errors.'</ul></p>';
11477: }
1.3 raeburn 11478: return $resulttext;
1.1 raeburn 11479: }
11480:
1.160.6.30 raeburn 11481: sub process_textbook_image {
1.160.6.46 raeburn 11482: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 11483: my $filename = $env{'form.'.$caller.'.filename'};
11484: my ($error,$url);
11485: my ($width,$height) = (50,50);
11486: if ($configuserok eq 'ok') {
11487: if ($switchserver) {
11488: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11489: $switchserver);
11490: } elsif ($author_ok eq 'ok') {
11491: my ($result,$imageurl) =
11492: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 11493: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 11494: if ($result eq 'ok') {
11495: $url = $imageurl;
11496: } else {
11497: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11498: }
11499: } else {
11500: $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].",$filename,$confname,$dom,$author_ok);
11501: }
11502: } else {
11503: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$configuserok);
11504: }
11505: return ($url,$error);
11506: }
11507:
1.3 raeburn 11508: sub modify_autoenroll {
1.160.6.24 raeburn 11509: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11510: my ($resulttext,%changes);
11511: my %currautoenroll;
11512: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11513: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11514: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11515: }
11516: }
11517: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11518: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11519: sender => 'Sender for notification messages',
1.160.6.68 raeburn 11520: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 11521: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11522: my @offon = ('off','on');
1.17 raeburn 11523: my $sender_uname = $env{'form.sender_uname'};
11524: my $sender_domain = $env{'form.sender_domain'};
11525: if ($sender_domain eq '') {
11526: $sender_uname = '';
11527: } elsif ($sender_uname eq '') {
11528: $sender_domain = '';
11529: }
1.129 raeburn 11530: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 11531: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
11532: $autofailsafe =~ s{^\s+|\s+$}{}g;
11533: if ($autofailsafe =~ /\D/) {
11534: undef($autofailsafe);
11535: }
1.160.6.68 raeburn 11536: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 11537: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
11538: $failsafe = 'off';
11539: undef($autofailsafe);
1.160.6.68 raeburn 11540: }
1.1 raeburn 11541: my %autoenrollhash = (
1.129 raeburn 11542: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11543: 'sender_uname' => $sender_uname,
11544: 'sender_domain' => $sender_domain,
11545: 'co-owners' => $coowners,
1.160.6.116 raeburn 11546: 'autofailsafe' => $autofailsafe,
11547: 'failsafe' => $failsafe,
1.1 raeburn 11548: }
11549: );
1.4 raeburn 11550: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11551: $dom);
1.1 raeburn 11552: if ($putresult eq 'ok') {
11553: if (exists($currautoenroll{'run'})) {
11554: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11555: $changes{'run'} = 1;
11556: }
11557: } elsif ($autorun) {
11558: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11559: $changes{'run'} = 1;
1.1 raeburn 11560: }
11561: }
1.17 raeburn 11562: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11563: $changes{'sender'} = 1;
11564: }
1.17 raeburn 11565: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11566: $changes{'sender'} = 1;
11567: }
1.129 raeburn 11568: if ($currautoenroll{'co-owners'} ne '') {
11569: if ($currautoenroll{'co-owners'} ne $coowners) {
11570: $changes{'coowners'} = 1;
11571: }
11572: } elsif ($coowners) {
11573: $changes{'coowners'} = 1;
1.160.6.68 raeburn 11574: }
1.160.6.116 raeburn 11575: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 11576: $changes{'autofailsafe'} = 1;
11577: }
1.160.6.116 raeburn 11578: if ($currautoenroll{'failsafe'} ne $failsafe) {
11579: $changes{'failsafe'} = 1;
11580: }
1.1 raeburn 11581: if (keys(%changes) > 0) {
11582: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11583: if ($changes{'run'}) {
1.1 raeburn 11584: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11585: }
11586: if ($changes{'sender'}) {
1.17 raeburn 11587: if ($sender_uname eq '' || $sender_domain eq '') {
11588: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11589: } else {
11590: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11591: }
1.1 raeburn 11592: }
1.129 raeburn 11593: if ($changes{'coowners'}) {
11594: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11595: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11596: if (ref($lastactref) eq 'HASH') {
11597: $lastactref->{'domainconfig'} = 1;
11598: }
1.129 raeburn 11599: }
1.160.6.68 raeburn 11600: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 11601: if ($autofailsafe ne '') {
11602: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 11603: } else {
1.160.6.116 raeburn 11604: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 11605: }
1.160.6.116 raeburn 11606: }
11607: if ($changes{'failsafe'}) {
11608: if ($failsafe eq 'off') {
11609: unless ($changes{'autofailsafe'}) {
11610: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
11611: }
11612: } elsif ($failsafe eq 'zero') {
11613: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
11614: } else {
11615: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
11616: }
11617: }
11618: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 11619: &Apache::lonnet::get_domain_defaults($dom,1);
11620: if (ref($lastactref) eq 'HASH') {
11621: $lastactref->{'domdefaults'} = 1;
11622: }
11623: }
1.1 raeburn 11624: $resulttext .= '</ul>';
11625: } else {
11626: $resulttext = &mt('No changes made to auto-enrollment settings');
11627: }
11628: } else {
1.11 albertel 11629: $resulttext = '<span class="LC_error">'.
11630: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11631: }
1.3 raeburn 11632: return $resulttext;
1.1 raeburn 11633: }
11634:
11635: sub modify_autoupdate {
1.3 raeburn 11636: my ($dom,%domconfig) = @_;
1.1 raeburn 11637: my ($resulttext,%currautoupdate,%fields,%changes);
11638: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11639: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11640: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11641: }
11642: }
11643: my @offon = ('off','on');
11644: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 11645: run => 'Auto-update:',
11646: classlists => 'Updates to user information in classlists?',
11647: unexpired => 'Skip updates for users without active or future roles?',
11648: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 11649: );
1.44 raeburn 11650: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11651: my %fieldtitles = &Apache::lonlocal::texthash (
11652: id => 'Student/Employee ID',
1.20 raeburn 11653: permanentemail => 'E-mail address',
1.1 raeburn 11654: lastname => 'Last Name',
11655: firstname => 'First Name',
11656: middlename => 'Middle Name',
1.132 raeburn 11657: generation => 'Generation',
1.1 raeburn 11658: );
1.142 raeburn 11659: $othertitle = &mt('All users');
1.1 raeburn 11660: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11661: $othertitle = &mt('Other users');
1.1 raeburn 11662: }
11663: foreach my $key (keys(%env)) {
11664: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11665: my ($usertype,$item) = ($1,$2);
11666: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11667: if ($usertype eq 'default') {
11668: push(@{$fields{$1}},$2);
11669: } elsif (ref($types) eq 'ARRAY') {
11670: if (grep(/^\Q$usertype\E$/,@{$types})) {
11671: push(@{$fields{$1}},$2);
11672: }
11673: }
11674: }
1.1 raeburn 11675: }
11676: }
1.131 raeburn 11677: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11678: @lockablenames = sort(@lockablenames);
11679: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11680: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11681: if (@changed) {
11682: $changes{'lockablenames'} = 1;
11683: }
11684: } else {
11685: if (@lockablenames) {
11686: $changes{'lockablenames'} = 1;
11687: }
11688: }
1.1 raeburn 11689: my %updatehash = (
11690: autoupdate => { run => $env{'form.autoupdate_run'},
11691: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 11692: unexpired => $env{'form.unexpired'},
1.1 raeburn 11693: fields => {%fields},
1.131 raeburn 11694: lockablenames => \@lockablenames,
1.1 raeburn 11695: }
11696: );
1.160.6.113 raeburn 11697: my $lastactivedays;
11698: if ($env{'form.lastactive'}) {
11699: $lastactivedays = $env{'form.lastactivedays'};
11700: $lastactivedays =~ s/^\s+|\s+$//g;
11701: unless ($lastactivedays =~ /^\d+$/) {
11702: undef($lastactivedays);
11703: $env{'form.lastactive'} = 0;
11704: }
11705: }
11706: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 11707: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 11708: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 11709: if (exists($updatehash{autoupdate}{$key})) {
11710: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11711: $changes{$key} = 1;
11712: }
11713: }
11714: } elsif ($key eq 'fields') {
11715: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11716: foreach my $item (@{$types},'default') {
1.1 raeburn 11717: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11718: my $change = 0;
11719: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11720: if (!exists($fields{$item})) {
11721: $change = 1;
1.132 raeburn 11722: last;
1.1 raeburn 11723: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11724: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11725: $change = 1;
1.132 raeburn 11726: last;
1.1 raeburn 11727: }
11728: }
11729: }
11730: if ($change) {
11731: push(@{$changes{$key}},$item);
11732: }
1.26 raeburn 11733: }
1.1 raeburn 11734: }
11735: }
1.131 raeburn 11736: } elsif ($key eq 'lockablenames') {
11737: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11738: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11739: if (@changed) {
11740: $changes{'lockablenames'} = 1;
11741: }
11742: } else {
11743: if (@lockablenames) {
11744: $changes{'lockablenames'} = 1;
11745: }
11746: }
11747: }
11748: }
11749: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11750: if (@lockablenames) {
11751: $changes{'lockablenames'} = 1;
1.1 raeburn 11752: }
11753: }
1.160.6.113 raeburn 11754: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
11755: if ($updatehash{'autoupdate'}{'unexpired'}) {
11756: $changes{'unexpired'} = 1;
11757: }
11758: }
11759: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
11760: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
11761: $changes{'lastactive'} = 1;
11762: }
11763: }
1.26 raeburn 11764: foreach my $item (@{$types},'default') {
11765: if (defined($fields{$item})) {
11766: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11767: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11768: my $change = 0;
11769: if (ref($fields{$item}) eq 'ARRAY') {
11770: foreach my $type (@{$fields{$item}}) {
11771: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11772: $change = 1;
11773: last;
11774: }
11775: }
11776: }
11777: if ($change) {
11778: push(@{$changes{'fields'}},$item);
11779: }
11780: } else {
1.26 raeburn 11781: push(@{$changes{'fields'}},$item);
11782: }
11783: } else {
11784: push(@{$changes{'fields'}},$item);
1.1 raeburn 11785: }
11786: }
11787: }
11788: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11789: $dom);
11790: if ($putresult eq 'ok') {
11791: if (keys(%changes) > 0) {
11792: $resulttext = &mt('Changes made:').'<ul>';
11793: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11794: if ($key eq 'lockablenames') {
11795: $resulttext .= '<li>';
11796: if (@lockablenames) {
11797: $usertypes->{'default'} = $othertitle;
11798: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11799: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11800: } else {
11801: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11802: }
11803: $resulttext .= '</li>';
11804: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11805: foreach my $item (@{$changes{$key}}) {
11806: my @newvalues;
11807: foreach my $type (@{$fields{$item}}) {
11808: push(@newvalues,$fieldtitles{$type});
11809: }
1.3 raeburn 11810: my $newvaluestr;
11811: if (@newvalues > 0) {
11812: $newvaluestr = join(', ',@newvalues);
11813: } else {
11814: $newvaluestr = &mt('none');
1.6 raeburn 11815: }
1.1 raeburn 11816: if ($item eq 'default') {
1.26 raeburn 11817: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11818: } else {
1.26 raeburn 11819: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11820: }
11821: }
11822: } else {
11823: my $newvalue;
11824: if ($key eq 'run') {
11825: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 11826: } elsif ($key eq 'lastactive') {
11827: $newvalue = $offon[$env{'form.lastactive'}];
11828: unless ($lastactivedays eq '') {
11829: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
11830: }
1.1 raeburn 11831: } else {
11832: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11833: }
1.1 raeburn 11834: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11835: }
11836: }
11837: $resulttext .= '</ul>';
11838: } else {
1.3 raeburn 11839: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11840: }
11841: } else {
1.11 albertel 11842: $resulttext = '<span class="LC_error">'.
11843: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11844: }
1.3 raeburn 11845: return $resulttext;
1.1 raeburn 11846: }
11847:
1.125 raeburn 11848: sub modify_autocreate {
11849: my ($dom,%domconfig) = @_;
11850: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11851: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11852: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11853: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11854: }
11855: }
11856: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11857: req => 'Auto-creation of validated requests for official courses',
11858: xmldc => 'Identity of course creator of courses from XML files',
11859: );
11860: my @types = ('xml','req');
11861: foreach my $item (@types) {
11862: $newvals{$item} = $env{'form.autocreate_'.$item};
11863: $newvals{$item} =~ s/\D//g;
11864: $newvals{$item} = 0 if ($newvals{$item} eq '');
11865: }
11866: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 11867: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11868: unless (exists($domcoords{$newvals{'xmldc'}})) {
11869: $newvals{'xmldc'} = '';
11870: }
11871: %autocreatehash = (
11872: autocreate => { xml => $newvals{'xml'},
11873: req => $newvals{'req'},
11874: }
11875: );
11876: if ($newvals{'xmldc'} ne '') {
11877: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11878: }
11879: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11880: $dom);
11881: if ($putresult eq 'ok') {
11882: my @items = @types;
11883: if ($newvals{'xml'}) {
11884: push(@items,'xmldc');
11885: }
11886: foreach my $item (@items) {
11887: if (exists($currautocreate{$item})) {
11888: if ($currautocreate{$item} ne $newvals{$item}) {
11889: $changes{$item} = 1;
11890: }
11891: } elsif ($newvals{$item}) {
11892: $changes{$item} = 1;
11893: }
11894: }
11895: if (keys(%changes) > 0) {
11896: my @offon = ('off','on');
11897: $resulttext = &mt('Changes made:').'<ul>';
11898: foreach my $item (@types) {
11899: if ($changes{$item}) {
11900: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 11901: $resulttext .= '<li>'.
11902: &mt("$title{$item} set to [_1]$newtxt [_2]",
11903: '<b>','</b>').
11904: '</li>';
1.125 raeburn 11905: }
11906: }
11907: if ($changes{'xmldc'}) {
11908: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11909: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 11910: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 11911: }
11912: $resulttext .= '</ul>';
11913: } else {
11914: $resulttext = &mt('No changes made to auto-creation settings');
11915: }
11916: } else {
11917: $resulttext = '<span class="LC_error">'.
11918: &mt('An error occurred: [_1]',$putresult).'</span>';
11919: }
11920: return $resulttext;
11921: }
11922:
1.23 raeburn 11923: sub modify_directorysrch {
1.160.6.81 raeburn 11924: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 11925: my ($resulttext,%changes);
11926: my %currdirsrch;
11927: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11928: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11929: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11930: }
11931: }
1.160.6.72 raeburn 11932: my %title = ( available => 'Institutional directory search available',
11933: localonly => 'Other domains can search institution',
11934: lcavailable => 'LON-CAPA directory search available',
11935: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11936: searchby => 'Search types',
11937: searchtypes => 'Search latitude');
11938: my @offon = ('off','on');
1.24 raeburn 11939: my @otherdoms = ('Yes','No');
1.23 raeburn 11940:
1.25 raeburn 11941: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11942: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11943: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11944:
1.44 raeburn 11945: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11946: if (keys(%{$usertypes}) == 0) {
11947: @cansearch = ('default');
11948: } else {
11949: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11950: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11951: if (!grep(/^\Q$type\E$/,@cansearch)) {
11952: push(@{$changes{'cansearch'}},$type);
11953: }
1.23 raeburn 11954: }
1.26 raeburn 11955: foreach my $type (@cansearch) {
11956: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11957: push(@{$changes{'cansearch'}},$type);
11958: }
1.23 raeburn 11959: }
1.26 raeburn 11960: } else {
11961: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11962: }
11963: }
11964:
11965: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11966: foreach my $by (@{$currdirsrch{'searchby'}}) {
11967: if (!grep(/^\Q$by\E$/,@searchby)) {
11968: push(@{$changes{'searchby'}},$by);
11969: }
11970: }
11971: foreach my $by (@searchby) {
11972: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11973: push(@{$changes{'searchby'}},$by);
11974: }
11975: }
11976: } else {
11977: push(@{$changes{'searchby'}},@searchby);
11978: }
1.25 raeburn 11979:
11980: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11981: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11982: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11983: push(@{$changes{'searchtypes'}},$type);
11984: }
11985: }
11986: foreach my $type (@searchtypes) {
11987: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11988: push(@{$changes{'searchtypes'}},$type);
11989: }
11990: }
11991: } else {
11992: if (exists($currdirsrch{'searchtypes'})) {
11993: foreach my $type (@searchtypes) {
11994: if ($type ne $currdirsrch{'searchtypes'}) {
11995: push(@{$changes{'searchtypes'}},$type);
11996: }
11997: }
11998: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11999: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12000: }
12001: } else {
12002: push(@{$changes{'searchtypes'}},@searchtypes);
12003: }
12004: }
12005:
1.23 raeburn 12006: my %dirsrch_hash = (
12007: directorysrch => { available => $env{'form.dirsrch_available'},
12008: cansearch => \@cansearch,
1.160.6.72 raeburn 12009: localonly => $env{'form.dirsrch_instlocalonly'},
12010: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12011: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12012: searchby => \@searchby,
1.25 raeburn 12013: searchtypes => \@searchtypes,
1.23 raeburn 12014: }
12015: );
12016: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12017: $dom);
12018: if ($putresult eq 'ok') {
12019: if (exists($currdirsrch{'available'})) {
12020: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12021: $changes{'available'} = 1;
12022: }
12023: } else {
12024: if ($env{'form.dirsrch_available'} eq '1') {
12025: $changes{'available'} = 1;
12026: }
12027: }
1.160.6.72 raeburn 12028: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 12029: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12030: $changes{'lcavailable'} = 1;
12031: }
1.24 raeburn 12032: } else {
1.160.6.72 raeburn 12033: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12034: $changes{'lcavailable'} = 1;
12035: }
12036: }
12037: if (exists($currdirsrch{'localonly'})) {
12038: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 12039: $changes{'localonly'} = 1;
12040: }
1.160.6.72 raeburn 12041: } else {
12042: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
12043: $changes{'localonly'} = 1;
12044: }
12045: }
12046: if (exists($currdirsrch{'lclocalonly'})) {
12047: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12048: $changes{'lclocalonly'} = 1;
12049: }
12050: } else {
12051: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12052: $changes{'lclocalonly'} = 1;
12053: }
1.24 raeburn 12054: }
1.23 raeburn 12055: if (keys(%changes) > 0) {
12056: $resulttext = &mt('Changes made:').'<ul>';
12057: if ($changes{'available'}) {
12058: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12059: }
1.160.6.72 raeburn 12060: if ($changes{'lcavailable'}) {
12061: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12062: }
1.24 raeburn 12063: if ($changes{'localonly'}) {
1.160.6.72 raeburn 12064: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
12065: }
12066: if ($changes{'lclocalonly'}) {
12067: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 12068: }
1.23 raeburn 12069: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12070: my $chgtext;
1.26 raeburn 12071: if (ref($usertypes) eq 'HASH') {
12072: if (keys(%{$usertypes}) > 0) {
12073: foreach my $type (@{$types}) {
12074: if (grep(/^\Q$type\E$/,@cansearch)) {
12075: $chgtext .= $usertypes->{$type}.'; ';
12076: }
12077: }
12078: if (grep(/^default$/,@cansearch)) {
12079: $chgtext .= $othertitle;
12080: } else {
12081: $chgtext =~ s/\; $//;
12082: }
1.160.6.13 raeburn 12083: $resulttext .=
12084: '<li>'.
12085: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12086: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12087: '</li>';
1.23 raeburn 12088: }
12089: }
12090: }
12091: if (ref($changes{'searchby'}) eq 'ARRAY') {
12092: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12093: my $chgtext;
12094: foreach my $type (@{$titleorder}) {
12095: if (grep(/^\Q$type\E$/,@searchby)) {
12096: if (defined($searchtitles->{$type})) {
12097: $chgtext .= $searchtitles->{$type}.'; ';
12098: }
12099: }
12100: }
12101: $chgtext =~ s/\; $//;
12102: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12103: }
1.25 raeburn 12104: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12105: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12106: my $chgtext;
12107: foreach my $type (@{$srchtypeorder}) {
12108: if (grep(/^\Q$type\E$/,@searchtypes)) {
12109: if (defined($srchtypes_desc->{$type})) {
12110: $chgtext .= $srchtypes_desc->{$type}.'; ';
12111: }
12112: }
12113: }
12114: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 12115: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12116: }
12117: $resulttext .= '</ul>';
1.160.6.81 raeburn 12118: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12119: if (ref($lastactref) eq 'HASH') {
12120: $lastactref->{'directorysrch'} = 1;
12121: }
1.23 raeburn 12122: } else {
1.160.6.72 raeburn 12123: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12124: }
12125: } else {
12126: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12127: &mt('An error occurred: [_1]',$putresult).'</span>';
12128: }
12129: return $resulttext;
12130: }
12131:
1.28 raeburn 12132: sub modify_contacts {
1.160.6.24 raeburn 12133: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12134: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12135: if (ref($domconfig{'contacts'}) eq 'HASH') {
12136: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12137: $currsetting{$key} = $domconfig{'contacts'}{$key};
12138: }
12139: }
1.160.6.78 raeburn 12140: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12141: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 12142: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 12143: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 12144: my @toggles = ('reporterrors','reportupdates','reportstatus');
12145: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 12146: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12147: foreach my $type (@mailings) {
12148: @{$newsetting{$type}} =
12149: &Apache::loncommon::get_env_multiple('form.'.$type);
12150: foreach my $item (@contacts) {
12151: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12152: $contacts_hash{contacts}{$type}{$item} = 1;
12153: } else {
12154: $contacts_hash{contacts}{$type}{$item} = 0;
12155: }
1.160.6.78 raeburn 12156: }
1.28 raeburn 12157: $others{$type} = $env{'form.'.$type.'_others'};
12158: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 12159: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12160: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12161: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 12162: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12163: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12164: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12165: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12166: }
1.134 raeburn 12167: }
1.28 raeburn 12168: }
12169: foreach my $item (@contacts) {
12170: $to{$item} = $env{'form.'.$item};
12171: $contacts_hash{'contacts'}{$item} = $to{$item};
12172: }
1.160.6.23 raeburn 12173: foreach my $item (@toggles) {
12174: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12175: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12176: }
12177: }
1.160.6.107 raeburn 12178: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
12179: foreach my $item (@lonstatus) {
12180: if ($item eq 'excluded') {
12181: my (%serverhomes,@excluded);
12182: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
12183: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
12184: if (@possexcluded) {
12185: foreach my $id (sort(@possexcluded)) {
12186: if ($serverhomes{$id}) {
12187: push(@excluded,$id);
12188: }
12189: }
12190: }
12191: if (@excluded) {
12192: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
12193: }
12194: } elsif ($item eq 'weights') {
12195: foreach my $type ('E','W','N','U') {
12196: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
12197: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
12198: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
12199: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
12200: $env{'form.error'.$item.'_'.$type};
12201: }
12202: }
12203: }
12204: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
12205: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
12206: if ($env{'form.error'.$item} =~ /^\d+$/) {
12207: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
12208: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
12209: }
12210: }
12211: }
12212: }
1.160.6.78 raeburn 12213: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12214: foreach my $field (@{$fields}) {
12215: if (ref($possoptions->{$field}) eq 'ARRAY') {
12216: my $value = $env{'form.helpform_'.$field};
12217: $value =~ s/^\s+|\s+$//g;
12218: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 12219: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 12220: if ($field eq 'screenshot') {
12221: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12222: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 12223: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 12224: }
12225: }
12226: }
12227: }
12228: }
12229: }
1.160.6.101 raeburn 12230: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12231: my (@statuses,%usertypeshash,@overrides);
12232: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12233: @statuses = @{$types};
12234: if (ref($usertypes) eq 'HASH') {
12235: %usertypeshash = %{$usertypes};
12236: }
12237: }
12238: if (@statuses) {
12239: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12240: foreach my $type (@possoverrides) {
12241: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12242: push(@overrides,$type);
12243: }
12244: }
12245: if (@overrides) {
12246: foreach my $type (@overrides) {
12247: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12248: foreach my $item (@contacts) {
12249: if (grep(/^\Q$item\E$/,@standard)) {
12250: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12251: $newsetting{'override_'.$type}{$item} = 1;
12252: } else {
12253: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12254: $newsetting{'override_'.$type}{$item} = 0;
12255: }
12256: }
12257: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12258: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12259: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12260: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12261: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12262: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12263: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12264: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12265: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12266: }
12267: }
12268: }
12269: }
1.28 raeburn 12270: if (keys(%currsetting) > 0) {
12271: foreach my $item (@contacts) {
12272: if ($to{$item} ne $currsetting{$item}) {
12273: $changes{$item} = 1;
12274: }
12275: }
12276: foreach my $type (@mailings) {
12277: foreach my $item (@contacts) {
12278: if (ref($currsetting{$type}) eq 'HASH') {
12279: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12280: push(@{$changes{$type}},$item);
12281: }
12282: } else {
12283: push(@{$changes{$type}},@{$newsetting{$type}});
12284: }
12285: }
12286: if ($others{$type} ne $currsetting{$type}{'others'}) {
12287: push(@{$changes{$type}},'others');
12288: }
1.160.6.78 raeburn 12289: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12290: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12291: push(@{$changes{$type}},'bcc');
12292: }
1.160.6.78 raeburn 12293: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12294: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12295: push(@{$changes{$type}},'include');
12296: }
12297: }
12298: }
12299: if (ref($fields) eq 'ARRAY') {
12300: if (ref($currsetting{'helpform'}) eq 'HASH') {
12301: foreach my $field (@{$fields}) {
12302: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12303: push(@{$changes{'helpform'}},$field);
12304: }
12305: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12306: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12307: push(@{$changes{'helpform'}},'maxsize');
12308: }
12309: }
12310: }
12311: } else {
12312: foreach my $field (@{$fields}) {
12313: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12314: push(@{$changes{'helpform'}},$field);
12315: }
12316: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12317: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12318: push(@{$changes{'helpform'}},'maxsize');
12319: }
12320: }
12321: }
1.134 raeburn 12322: }
1.28 raeburn 12323: }
1.160.6.101 raeburn 12324: if (@statuses) {
12325: if (ref($currsetting{'overrides'}) eq 'HASH') {
12326: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12327: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12328: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12329: foreach my $item (@contacts,'bcc','others','include') {
12330: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12331: push(@{$changes{'overrides'}},$key);
12332: last;
12333: }
12334: }
12335: } else {
12336: push(@{$changes{'overrides'}},$key);
12337: }
12338: }
12339: }
12340: foreach my $key (@overrides) {
12341: unless (exists($currsetting{'overrides'}{$key})) {
12342: push(@{$changes{'overrides'}},$key);
12343: }
12344: }
12345: } else {
12346: foreach my $key (@overrides) {
12347: push(@{$changes{'overrides'}},$key);
12348: }
12349: }
12350: }
1.160.6.107 raeburn 12351: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
12352: foreach my $key ('excluded','weights','threshold','sysmail') {
12353: if ($key eq 'excluded') {
12354: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12355: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
12356: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12357: (@{$currsetting{'lonstatus'}{$key}})) {
12358: my @diffs =
12359: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
12360: $currsetting{'lonstatus'}{$key});
12361: if (@diffs) {
12362: push(@{$changes{'lonstatus'}},$key);
12363: }
12364: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
12365: push(@{$changes{'lonstatus'}},$key);
12366: }
12367: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12368: (@{$currsetting{'lonstatus'}{$key}})) {
12369: push(@{$changes{'lonstatus'}},$key);
12370: }
12371: } elsif ($key eq 'weights') {
12372: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12373: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
12374: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12375: foreach my $type ('E','W','N','U') {
12376: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
12377: $currsetting{'lonstatus'}{$key}{$type}) {
12378: push(@{$changes{'lonstatus'}},$key);
12379: last;
12380: }
12381: }
12382: } else {
12383: foreach my $type ('E','W','N','U') {
12384: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
12385: push(@{$changes{'lonstatus'}},$key);
12386: last;
12387: }
12388: }
12389: }
12390: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12391: foreach my $type ('E','W','N','U') {
12392: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
12393: push(@{$changes{'lonstatus'}},$key);
12394: last;
12395: }
12396: }
12397: }
12398: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
12399: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12400: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12401: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
12402: push(@{$changes{'lonstatus'}},$key);
12403: }
12404: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
12405: push(@{$changes{'lonstatus'}},$key);
12406: }
12407: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12408: push(@{$changes{'lonstatus'}},$key);
12409: }
12410: }
12411: }
12412: } else {
12413: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12414: foreach my $key ('excluded','weights','threshold','sysmail') {
12415: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12416: push(@{$changes{'lonstatus'}},$key);
12417: }
12418: }
12419: }
12420: }
1.28 raeburn 12421: } else {
12422: my %default;
12423: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12424: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12425: $default{'errormail'} = 'adminemail';
12426: $default{'packagesmail'} = 'adminemail';
12427: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 12428: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12429: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12430: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 12431: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 12432: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 12433: foreach my $item (@contacts) {
12434: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 12435: $changes{$item} = 1;
1.160.6.23 raeburn 12436: }
1.28 raeburn 12437: }
12438: foreach my $type (@mailings) {
12439: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12440: push(@{$changes{$type}},@{$newsetting{$type}});
12441: }
12442: if ($others{$type} ne '') {
12443: push(@{$changes{$type}},'others');
1.134 raeburn 12444: }
1.160.6.78 raeburn 12445: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12446: if ($bcc{$type} ne '') {
12447: push(@{$changes{$type}},'bcc');
12448: }
1.160.6.78 raeburn 12449: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12450: push(@{$changes{$type}},'include');
12451: }
12452: }
12453: }
12454: if (ref($fields) eq 'ARRAY') {
12455: foreach my $field (@{$fields}) {
12456: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12457: push(@{$changes{'helpform'}},$field);
12458: }
12459: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12460: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12461: push(@{$changes{'helpform'}},'maxsize');
12462: }
12463: }
1.134 raeburn 12464: }
1.28 raeburn 12465: }
1.160.6.107 raeburn 12466: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12467: foreach my $key ('excluded','weights','threshold','sysmail') {
12468: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12469: push(@{$changes{'lonstatus'}},$key);
12470: }
12471: }
12472: }
1.28 raeburn 12473: }
1.160.6.23 raeburn 12474: foreach my $item (@toggles) {
12475: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12476: $changes{$item} = 1;
12477: } elsif ((!$env{'form.'.$item}) &&
12478: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12479: $changes{$item} = 1;
12480: }
12481: }
1.28 raeburn 12482: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12483: $dom);
12484: if ($putresult eq 'ok') {
12485: if (keys(%changes) > 0) {
1.160.6.24 raeburn 12486: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12487: if (ref($lastactref) eq 'HASH') {
12488: $lastactref->{'domainconfig'} = 1;
12489: }
1.28 raeburn 12490: my ($titles,$short_titles) = &contact_titles();
12491: $resulttext = &mt('Changes made:').'<ul>';
12492: foreach my $item (@contacts) {
12493: if ($changes{$item}) {
12494: $resulttext .= '<li>'.$titles->{$item}.
12495: &mt(' set to: ').
12496: '<span class="LC_cusr_emph">'.
12497: $to{$item}.'</span></li>';
12498: }
12499: }
12500: foreach my $type (@mailings) {
12501: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 12502: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12503: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
12504: } else {
12505: $resulttext .= '<li>'.$titles->{$type}.': ';
12506: }
1.28 raeburn 12507: my @text;
12508: foreach my $item (@{$newsetting{$type}}) {
12509: push(@text,$short_titles->{$item});
12510: }
12511: if ($others{$type} ne '') {
12512: push(@text,$others{$type});
12513: }
1.160.6.78 raeburn 12514: if (@text) {
12515: $resulttext .= '<span class="LC_cusr_emph">'.
12516: join(', ',@text).'</span>';
12517: }
12518: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12519: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 12520: my $bcctext;
12521: if (@text) {
12522: $bcctext = ' '.&mt('with Bcc to');
12523: } else {
12524: $bcctext = '(Bcc)';
12525: }
12526: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12527: } elsif (!@text) {
12528: $resulttext .= &mt('No one');
1.134 raeburn 12529: }
1.160.6.78 raeburn 12530: if ($includestr{$type} ne '') {
12531: if ($includeloc{$type} eq 'b') {
12532: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12533: } elsif ($includeloc{$type} eq 's') {
12534: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12535: }
12536: }
12537: } elsif (!@text) {
12538: $resulttext .= &mt('No recipients');
1.134 raeburn 12539: }
12540: $resulttext .= '</li>';
1.28 raeburn 12541: }
12542: }
1.160.6.101 raeburn 12543: if (ref($changes{'overrides'}) eq 'ARRAY') {
12544: my @deletions;
12545: foreach my $type (@{$changes{'overrides'}}) {
12546: if ($usertypeshash{$type}) {
12547: if (grep(/^\Q$type\E/,@overrides)) {
12548: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12549: $usertypeshash{$type}).'<ul><li>';
12550: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12551: my @text;
12552: foreach my $item (@contacts) {
12553: if ($newsetting{'override_'.$type}{$item}) {
12554: push(@text,$short_titles->{$item});
12555: }
12556: }
12557: if ($newsetting{'override_'.$type}{'others'} ne '') {
12558: push(@text,$newsetting{'override_'.$type}{'others'});
12559: }
12560:
12561: if (@text) {
12562: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12563: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12564: }
12565: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12566: my $bcctext;
12567: if (@text) {
12568: $bcctext = ' '.&mt('with Bcc to');
12569: } else {
12570: $bcctext = '(Bcc)';
12571: }
12572: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12573: } elsif (!@text) {
12574: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12575: }
12576: $resulttext .= '</li>';
12577: if ($newsetting{'override_'.$type}{'include'} ne '') {
12578: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12579: if ($loc eq 'b') {
12580: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12581: } elsif ($loc eq 's') {
12582: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12583: }
12584: }
12585: }
12586: $resulttext .= '</li></ul></li>';
12587: } else {
12588: push(@deletions,$usertypeshash{$type});
12589: }
12590: }
12591: }
12592: if (@deletions) {
12593: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12594: join(', ',@deletions)).'</li>';
12595: }
12596: }
1.160.6.23 raeburn 12597: my @offon = ('off','on');
1.160.6.107 raeburn 12598: my $corelink = &core_link_msu();
1.160.6.23 raeburn 12599: if ($changes{'reporterrors'}) {
12600: $resulttext .= '<li>'.
12601: &mt('E-mail error reports to [_1] set to "'.
12602: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 12603: $corelink).
1.160.6.23 raeburn 12604: '</li>';
12605: }
12606: if ($changes{'reportupdates'}) {
12607: $resulttext .= '<li>'.
12608: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12609: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 12610: $corelink).
1.160.6.23 raeburn 12611: '</li>';
12612: }
1.160.6.107 raeburn 12613: if ($changes{'reportstatus'}) {
12614: $resulttext .= '<li>'.
12615: &mt('E-mail status if errors above threshold to [_1] set to "'.
12616: $offon[$env{'form.reportstatus'}].'".',
12617: $corelink).
12618: '</li>';
12619: }
12620: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
12621: $resulttext .= '<li>'.
12622: &mt('Nightly status check e-mail settings').':<ul>';
12623: my (%defval,%use_def,%shown);
12624: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
12625: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
12626: $defval{'weights'} =
12627: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
12628: $defval{'excluded'} = &mt('None');
12629: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
12630: foreach my $item ('threshold','sysmail','weights','excluded') {
12631: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
12632: if (($item eq 'threshold') || ($item eq 'sysmail')) {
12633: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
12634: } elsif ($item eq 'weights') {
12635: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
12636: foreach my $type ('E','W','N','U') {
12637: $shown{$item} .= $lonstatus_names->{$type}.'=';
12638: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
12639: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
12640: } else {
12641: $shown{$item} .= $lonstatus_defs->{$type};
12642: }
12643: $shown{$item} .= ', ';
12644: }
12645: $shown{$item} =~ s/, $//;
12646: } else {
12647: $shown{$item} = $defval{$item};
12648: }
12649: } elsif ($item eq 'excluded') {
12650: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
12651: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
12652: } else {
12653: $shown{$item} = $defval{$item};
12654: }
12655: }
12656: } else {
12657: $shown{$item} = $defval{$item};
12658: }
12659: }
12660: } else {
12661: foreach my $item ('threshold','weights','excluded','sysmail') {
12662: $shown{$item} = $defval{$item};
12663: }
12664: }
12665: foreach my $item ('threshold','weights','excluded','sysmail') {
12666: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
12667: $shown{$item}).'</li>';
12668: }
12669: $resulttext .= '</ul></li>';
12670: }
1.160.6.78 raeburn 12671: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12672: my (@optional,@required,@unused,$maxsizechg);
12673: foreach my $field (@{$changes{'helpform'}}) {
12674: if ($field eq 'maxsize') {
12675: $maxsizechg = 1;
12676: next;
12677: }
12678: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
12679: push(@optional,$field);
12680: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12681: push(@unused,$field);
12682: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
12683: push(@required,$field);
12684: }
12685: }
12686: if (@optional) {
12687: $resulttext .= '<li>'.
12688: &mt('Help form fields changed to "Optional": [_1].',
12689: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12690: '</li>';
12691: }
12692: if (@required) {
12693: $resulttext .= '<li>'.
12694: &mt('Help form fields changed to "Required": [_1].',
12695: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12696: '</li>';
12697: }
12698: if (@unused) {
12699: $resulttext .= '<li>'.
12700: &mt('Help form fields changed to "Not shown": [_1].',
12701: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12702: '</li>';
12703: }
12704: if ($maxsizechg) {
12705: $resulttext .= '<li>'.
12706: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12707: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12708: '</li>';
12709: }
12710: }
1.28 raeburn 12711: $resulttext .= '</ul>';
12712: } else {
1.160.6.78 raeburn 12713: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12714: }
12715: } else {
12716: $resulttext = '<span class="LC_error">'.
12717: &mt('An error occurred: [_1].',$putresult).'</span>';
12718: }
12719: return $resulttext;
12720: }
12721:
1.160.6.98 raeburn 12722: sub modify_passwords {
12723: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12724: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
12725: $updatedefaults,$updateconf);
12726: my $customfn = 'resetpw.html';
12727: if (ref($domconfig{'passwords'}) eq 'HASH') {
12728: %current = %{$domconfig{'passwords'}};
12729: }
12730: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12731: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12732: if (ref($types) eq 'ARRAY') {
12733: @oktypes = @{$types};
12734: }
12735: push(@oktypes,'default');
12736:
12737: my %titles = &Apache::lonlocal::texthash (
12738: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
12739: intauth_check => 'Check bcrypt cost if authenticated',
12740: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
12741: permanent => 'Permanent e-mail address',
12742: critical => 'Critical notification address',
12743: notify => 'Notification address',
12744: min => 'Minimum password length',
12745: max => 'Maximum password length',
12746: chars => 'Required characters',
12747: numsaved => 'Number of previous passwords to save',
12748: reset => 'Resetting Forgotten Password',
12749: intauth => 'Encryption of Stored Passwords (Internal Auth)',
12750: rules => 'Rules for LON-CAPA Passwords',
12751: crsownerchg => 'Course Owner Changing Student Passwords',
12752: username => 'Username',
12753: email => 'E-mail address',
12754: );
12755:
12756: #
12757: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
12758: #
12759: my (%curr_defaults,%save_defaults);
12760: if (ref($domconfig{'defaults'}) eq 'HASH') {
12761: foreach my $key (keys(%{$domconfig{'defaults'}})) {
12762: if ($key =~ /^intauth_(cost|check|switch)$/) {
12763: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
12764: } else {
12765: $save_defaults{$key} = $domconfig{'defaults'}{$key};
12766: }
12767: }
12768: }
12769: my %staticdefaults = (
12770: 'resetlink' => 2,
12771: 'resetcase' => \@oktypes,
12772: 'resetprelink' => 'both',
12773: 'resetemail' => ['critical','notify','permanent'],
12774: 'intauth_cost' => 10,
12775: 'intauth_check' => 0,
12776: 'intauth_switch' => 0,
12777: );
1.160.6.99 raeburn 12778: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 12779: foreach my $type (@oktypes) {
12780: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
12781: }
12782: my $linklife = $env{'form.passwords_link'};
12783: $linklife =~ s/^\s+|\s+$//g;
12784: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
12785: $newvalues{'resetlink'} = $linklife;
12786: if ($current{'resetlink'}) {
12787: if ($current{'resetlink'} ne $linklife) {
12788: $changes{'reset'} = 1;
12789: }
1.160.6.102 raeburn 12790: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12791: if ($staticdefaults{'resetlink'} ne $linklife) {
12792: $changes{'reset'} = 1;
12793: }
12794: }
12795: } elsif ($current{'resetlink'}) {
12796: $changes{'reset'} = 1;
12797: }
12798: my @casesens;
12799: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
12800: foreach my $case (sort(@posscase)) {
12801: if (grep(/^\Q$case\E$/,@oktypes)) {
12802: push(@casesens,$case);
12803: }
12804: }
12805: $newvalues{'resetcase'} = \@casesens;
12806: if (ref($current{'resetcase'}) eq 'ARRAY') {
12807: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12808: if (@diffs > 0) {
12809: $changes{'reset'} = 1;
12810: }
1.160.6.102 raeburn 12811: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12812: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12813: if (@diffs > 0) {
12814: $changes{'reset'} = 1;
12815: }
12816: }
12817: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12818: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12819: if (exists($current{'resetprelink'})) {
12820: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12821: $changes{'reset'} = 1;
12822: }
1.160.6.102 raeburn 12823: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12824: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12825: $changes{'reset'} = 1;
12826: }
12827: }
12828: } elsif ($current{'resetprelink'}) {
12829: $changes{'reset'} = 1;
12830: }
12831: foreach my $type (@oktypes) {
12832: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12833: my @postlink;
12834: foreach my $item (sort(@possplink)) {
12835: if ($item =~ /^(email|username)$/) {
12836: push(@postlink,$item);
12837: }
12838: }
12839: $newvalues{'resetpostlink'}{$type} = \@postlink;
12840: unless ($changes{'reset'}) {
12841: if (ref($current{'resetpostlink'}) eq 'HASH') {
12842: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12843: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12844: if (@diffs > 0) {
12845: $changes{'reset'} = 1;
12846: }
12847: } else {
12848: $changes{'reset'} = 1;
12849: }
1.160.6.102 raeburn 12850: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12851: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12852: if (@diffs > 0) {
12853: $changes{'reset'} = 1;
12854: }
12855: }
12856: }
12857: }
12858: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12859: my @resetemail;
12860: foreach my $item (sort(@possemailsrc)) {
12861: if ($item =~ /^(permanent|critical|notify)$/) {
12862: push(@resetemail,$item);
12863: }
12864: }
12865: $newvalues{'resetemail'} = \@resetemail;
12866: unless ($changes{'reset'}) {
12867: if (ref($current{'resetemail'}) eq 'ARRAY') {
12868: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12869: if (@diffs > 0) {
12870: $changes{'reset'} = 1;
12871: }
1.160.6.102 raeburn 12872: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12873: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12874: if (@diffs > 0) {
12875: $changes{'reset'} = 1;
12876: }
12877: }
12878: }
12879: if ($env{'form.passwords_stdtext'} == 0) {
12880: $newvalues{'resetremove'} = 1;
12881: unless ($current{'resetremove'}) {
12882: $changes{'reset'} = 1;
12883: }
12884: } elsif ($current{'resetremove'}) {
12885: $changes{'reset'} = 1;
12886: }
12887: if ($env{'form.passwords_customfile.filename'} ne '') {
12888: my $servadm = $r->dir_config('lonAdmEMail');
12889: my $servadm = $r->dir_config('lonAdmEMail');
12890: my ($configuserok,$author_ok,$switchserver) =
12891: &config_check($dom,$confname,$servadm);
12892: my $error;
12893: if ($configuserok eq 'ok') {
12894: if ($switchserver) {
12895: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12896: } else {
12897: if ($author_ok eq 'ok') {
12898: my ($result,$customurl) =
12899: &publishlogo($r,'upload','passwords_customfile',$dom,
12900: $confname,'customtext/resetpw','','',$customfn);
12901: if ($result eq 'ok') {
12902: $newvalues{'resetcustom'} = $customurl;
12903: $changes{'reset'} = 1;
12904: } else {
12905: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12906: }
12907: } else {
12908: $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].",$customfn,$confname,$dom,$author_ok);
12909: }
12910: }
12911: } else {
12912: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customfn,$confname,$dom,$configuserok);
12913: }
12914: if ($error) {
12915: &Apache::lonnet::logthis($error);
12916: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12917: }
12918: } elsif ($current{'resetcustom'}) {
12919: if ($env{'form.passwords_custom_del'}) {
12920: $changes{'reset'} = 1;
12921: } else {
12922: $newvalues{'resetcustom'} = $current{'resetcustom'};
12923: }
12924: }
12925: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12926: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12927: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12928: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12929: $changes{'intauth'} = 1;
12930: }
12931: } else {
12932: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12933: }
12934: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12935: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12936: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12937: $changes{'intauth'} = 1;
12938: }
12939: } else {
12940: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12941: }
12942: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12943: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12944: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12945: $changes{'intauth'} = 1;
12946: }
12947: } else {
12948: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12949: }
12950: foreach my $item ('cost','check','switch') {
12951: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12952: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12953: $updatedefaults = 1;
12954: }
12955: }
12956: foreach my $rule ('min','max','numsaved') {
12957: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 12958: my $ruleok;
12959: if ($rule eq 'min') {
12960: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12961: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12962: $ruleok = 1;
12963: }
12964: }
12965: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12966: ($env{'form.passwords_'.$rule} ne '0')) {
12967: $ruleok = 1;
12968: }
12969: if ($ruleok) {
1.160.6.98 raeburn 12970: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12971: if (exists($current{$rule})) {
12972: if ($newvalues{$rule} ne $current{$rule}) {
12973: $changes{'rules'} = 1;
12974: }
12975: } elsif ($rule eq 'min') {
12976: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12977: $changes{'rules'} = 1;
12978: }
1.160.6.104 raeburn 12979: } else {
12980: $changes{'rules'} = 1;
1.160.6.98 raeburn 12981: }
12982: } elsif (exists($current{$rule})) {
12983: $changes{'rules'} = 1;
12984: }
12985: }
12986: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12987: my @chars;
12988: foreach my $item (sort(@posschars)) {
12989: if ($item =~ /^(uc|lc|num|spec)$/) {
12990: push(@chars,$item);
12991: }
12992: }
12993: $newvalues{'chars'} = \@chars;
12994: unless ($changes{'rules'}) {
12995: if (ref($current{'chars'}) eq 'ARRAY') {
12996: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
12997: if (@diffs > 0) {
12998: $changes{'rules'} = 1;
12999: }
13000: } else {
13001: if (@chars > 0) {
13002: $changes{'rules'} = 1;
13003: }
13004: }
13005: }
13006: my %crsownerchg = (
13007: by => [],
13008: for => [],
13009: );
13010: foreach my $item ('by','for') {
13011: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
13012: foreach my $type (sort(@posstypes)) {
13013: if (grep(/^\Q$type\E$/,@oktypes)) {
13014: push(@{$crsownerchg{$item}},$type);
13015: }
13016: }
13017: }
13018: $newvalues{'crsownerchg'} = \%crsownerchg;
13019: if (ref($current{'crsownerchg'}) eq 'HASH') {
13020: foreach my $item ('by','for') {
13021: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
13022: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
13023: if (@diffs > 0) {
13024: $changes{'crsownerchg'} = 1;
13025: last;
13026: }
13027: }
13028: }
1.160.6.102 raeburn 13029: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 13030: foreach my $item ('by','for') {
13031: if (@{$crsownerchg{$item}} > 0) {
13032: $changes{'crsownerchg'} = 1;
13033: last;
13034: }
13035: }
13036: }
13037:
13038: my %confighash = (
13039: defaults => \%save_defaults,
13040: passwords => \%newvalues,
13041: );
13042: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
13043:
13044: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
13045: if ($putresult eq 'ok') {
13046: if (keys(%changes) > 0) {
13047: $resulttext = &mt('Changes made: ').'<ul>';
13048: foreach my $key ('reset','intauth','rules','crsownerchg') {
13049: if ($changes{$key}) {
13050: unless ($key eq 'intauth') {
13051: $updateconf = 1;
13052: }
13053: $resulttext .= '<li>'.$titles{$key}.':<ul>';
13054: if ($key eq 'reset') {
13055: if ($confighash{'passwords'}{'captcha'} eq 'original') {
13056: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
13057: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
13058: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 13059: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
13060: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
13061: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
13062: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
13063: }
1.160.6.98 raeburn 13064: } else {
13065: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
13066: }
13067: if ($confighash{'passwords'}{'resetlink'}) {
13068: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
13069: } else {
13070: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
13071: &mt('Will default to 2 hours').'</li>';
13072: }
13073: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
13074: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
13075: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
13076: } else {
13077: my $casesens;
13078: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
13079: if ($type eq 'default') {
13080: $casesens .= $othertitle.', ';
13081: } elsif ($usertypes->{$type} ne '') {
13082: $casesens .= $usertypes->{$type}.', ';
13083: }
13084: }
13085: $casesens =~ s/\Q, \E$//;
13086: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
13087: }
13088: } else {
13089: $resulttext .= '<li>'.&mt('Case-sensitivity not set for "Forgot Password" web form').' '.&mt('Will default to case-sensitive for username and/or e-mail address for all').'</li>';
13090: }
13091: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
13092: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
13093: } else {
13094: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
13095: }
13096: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
13097: my $output;
13098: if (ref($types) eq 'ARRAY') {
13099: foreach my $type (@{$types}) {
13100: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
13101: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
13102: $output .= $usertypes->{$type}.' -- '.&mt('none');
13103: } else {
13104: $output .= $usertypes->{$type}.' -- '.
13105: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
13106: }
13107: }
13108: }
13109: }
13110: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
13111: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
13112: $output .= $othertitle.' -- '.&mt('none');
13113: } else {
13114: $output .= $othertitle.' -- '.
13115: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
13116: }
13117: }
13118: if ($output) {
13119: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
13120: } else {
13121: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
13122: }
13123: } else {
13124: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
13125: }
13126: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
13127: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
13128: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
13129: } else {
13130: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
13131: }
13132: } else {
1.160.6.110 raeburn 13133: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
1.160.6.98 raeburn 13134: }
13135: if ($confighash{'passwords'}{'resetremove'}) {
13136: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
13137: } else {
13138: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
13139: }
13140: if ($confighash{'passwords'}{'resetcustom'}) {
13141: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 13142: &mt('custom text'),600,500,undef,undef,
13143: undef,undef,'background-color:#ffffff');
13144: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 13145: } else {
13146: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
13147: }
13148: } elsif ($key eq 'intauth') {
13149: foreach my $item ('cost','switch','check') {
13150: my $value = $save_defaults{$key.'_'.$item};
13151: if ($item eq 'switch') {
13152: my %optiondesc = &Apache::lonlocal::texthash (
13153: 0 => 'No',
13154: 1 => 'Yes',
13155: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
13156: );
13157: if ($value =~ /^(0|1|2)$/) {
13158: $value = $optiondesc{$value};
13159: } else {
13160: $value = &mt('none -- defaults to No');
13161: }
13162: } elsif ($item eq 'check') {
13163: my %optiondesc = &Apache::lonlocal::texthash (
13164: 0 => 'No',
13165: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
13166: 2 => 'Yes, disallow login if stored cost is less than domain default',
13167: );
13168: if ($value =~ /^(0|1|2)$/) {
13169: $value = $optiondesc{$value};
13170: } else {
13171: $value = &mt('none -- defaults to No');
13172: }
13173: }
13174: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
13175: }
13176: } elsif ($key eq 'rules') {
13177: foreach my $rule ('min','max','numsaved') {
13178: if ($confighash{'passwords'}{$rule} eq '') {
13179: if ($rule eq 'min') {
13180: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 13181: ' '.&mt('Default of [_1] will be used',
13182: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 13183: } else {
13184: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13185: }
13186: } else {
13187: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
13188: }
13189: }
1.160.6.104 raeburn 13190: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
13191: if (@{$confighash{'passwords'}{'chars'}} > 0) {
13192: my %rulenames = &Apache::lonlocal::texthash(
13193: uc => 'At least one upper case letter',
13194: lc => 'At least one lower case letter',
13195: num => 'At least one number',
13196: spec => 'At least one non-alphanumeric',
13197: );
13198: my $needed = '<ul><li>'.
13199: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
13200: '</li></ul>';
13201: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13202: } else {
13203: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13204: }
13205: } else {
13206: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13207: }
1.160.6.98 raeburn 13208: } elsif ($key eq 'crsownerchg') {
13209: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
13210: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
13211: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
13212: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13213: } else {
13214: my %crsownerstr;
13215: foreach my $item ('by','for') {
13216: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
13217: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
13218: if ($type eq 'default') {
13219: $crsownerstr{$item} .= $othertitle.', ';
13220: } elsif ($usertypes->{$type} ne '') {
13221: $crsownerstr{$item} .= $usertypes->{$type}.', ';
13222: }
13223: }
13224: $crsownerstr{$item} =~ s/\Q, \E$//;
13225: }
13226: }
13227: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
13228: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
13229: }
13230: } else {
13231: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13232: }
13233: }
13234: $resulttext .= '</ul></li>';
13235: }
13236: }
13237: $resulttext .= '</ul>';
13238: } else {
13239: $resulttext = &mt('No changes made to password settings');
13240: }
13241: my $cachetime = 24*60*60;
13242: if ($updatedefaults) {
13243: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13244: if (ref($lastactref) eq 'HASH') {
13245: $lastactref->{'domdefaults'} = 1;
13246: }
13247: }
13248: if ($updateconf) {
13249: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
13250: if (ref($lastactref) eq 'HASH') {
13251: $lastactref->{'passwdconf'} = 1;
13252: }
13253: }
13254: } else {
13255: $resulttext = '<span class="LC_error">'.
13256: &mt('An error occurred: [_1]',$putresult).'</span>';
13257: }
13258: if ($errors) {
13259: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13260: $errors.'</ul></p>';
13261: }
13262: return $resulttext;
13263: }
13264:
1.28 raeburn 13265: sub modify_usercreation {
1.27 raeburn 13266: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 13267: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13268: my $warningmsg;
1.27 raeburn 13269: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13270: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 13271: if ($key eq 'cancreate') {
13272: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13273: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 13274: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 13275: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 13276: } else {
13277: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 13278: }
1.50 raeburn 13279: }
1.43 raeburn 13280: }
1.160.6.34 raeburn 13281: } elsif ($key eq 'email_rule') {
13282: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13283: } else {
13284: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 13285: }
13286: }
1.34 raeburn 13287: }
1.160.6.34 raeburn 13288: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
13289: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
13290: my @contexts = ('author','course','requestcrs');
13291: foreach my $item(@contexts) {
13292: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13293: }
1.34 raeburn 13294: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13295: foreach my $item (@contexts) {
1.160.6.34 raeburn 13296: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13297: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13298: }
1.27 raeburn 13299: }
1.34 raeburn 13300: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13301: foreach my $item (@contexts) {
1.43 raeburn 13302: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13303: if ($cancreate{$item} ne 'any') {
13304: push(@{$changes{'cancreate'}},$item);
13305: }
13306: } else {
13307: if ($cancreate{$item} ne 'none') {
13308: push(@{$changes{'cancreate'}},$item);
13309: }
1.27 raeburn 13310: }
13311: }
13312: } else {
1.43 raeburn 13313: foreach my $item (@contexts) {
1.34 raeburn 13314: push(@{$changes{'cancreate'}},$item);
13315: }
1.27 raeburn 13316: }
1.34 raeburn 13317:
1.27 raeburn 13318: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13319: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13320: if (!grep(/^\Q$type\E$/,@username_rule)) {
13321: push(@{$changes{'username_rule'}},$type);
13322: }
13323: }
13324: foreach my $type (@username_rule) {
13325: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13326: push(@{$changes{'username_rule'}},$type);
13327: }
13328: }
13329: } else {
13330: push(@{$changes{'username_rule'}},@username_rule);
13331: }
13332:
1.32 raeburn 13333: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13334: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13335: if (!grep(/^\Q$type\E$/,@id_rule)) {
13336: push(@{$changes{'id_rule'}},$type);
13337: }
13338: }
13339: foreach my $type (@id_rule) {
13340: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13341: push(@{$changes{'id_rule'}},$type);
13342: }
13343: }
13344: } else {
13345: push(@{$changes{'id_rule'}},@id_rule);
13346: }
13347:
1.43 raeburn 13348: my @authen_contexts = ('author','course','domain');
1.28 raeburn 13349: my @authtypes = ('int','krb4','krb5','loc');
13350: my %authhash;
1.43 raeburn 13351: foreach my $item (@authen_contexts) {
1.28 raeburn 13352: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13353: foreach my $auth (@authtypes) {
13354: if (grep(/^\Q$auth\E$/,@authallowed)) {
13355: $authhash{$item}{$auth} = 1;
13356: } else {
13357: $authhash{$item}{$auth} = 0;
13358: }
13359: }
13360: }
13361: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13362: foreach my $item (@authen_contexts) {
1.28 raeburn 13363: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13364: foreach my $auth (@authtypes) {
13365: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13366: push(@{$changes{'authtypes'}},$item);
13367: last;
13368: }
13369: }
13370: }
13371: }
13372: } else {
1.43 raeburn 13373: foreach my $item (@authen_contexts) {
1.28 raeburn 13374: push(@{$changes{'authtypes'}},$item);
13375: }
13376: }
13377:
1.160.6.34 raeburn 13378: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13379: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13380: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13381: $save_usercreate{'id_rule'} = \@id_rule;
13382: $save_usercreate{'username_rule'} = \@username_rule,
13383: $save_usercreate{'authtypes'} = \%authhash;
13384:
1.27 raeburn 13385: my %usercreation_hash = (
1.160.6.34 raeburn 13386: usercreation => \%save_usercreate,
13387: );
1.27 raeburn 13388:
13389: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13390: $dom);
1.50 raeburn 13391:
1.160.6.34 raeburn 13392: if ($putresult eq 'ok') {
13393: if (keys(%changes) > 0) {
13394: $resulttext = &mt('Changes made:').'<ul>';
13395: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13396: my %lt = &usercreation_types();
13397: foreach my $type (@{$changes{'cancreate'}}) {
13398: my $chgtext = $lt{$type}.', ';
13399: if ($cancreate{$type} eq 'none') {
13400: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13401: } elsif ($cancreate{$type} eq 'any') {
13402: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13403: } elsif ($cancreate{$type} eq 'official') {
13404: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13405: } elsif ($cancreate{$type} eq 'unofficial') {
13406: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13407: }
13408: $resulttext .= '<li>'.$chgtext.'</li>';
13409: }
13410: }
13411: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13412: my ($rules,$ruleorder) =
13413: &Apache::lonnet::inst_userrules($dom,'username');
13414: my $chgtext = '<ul>';
13415: foreach my $type (@username_rule) {
13416: if (ref($rules->{$type}) eq 'HASH') {
13417: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13418: }
13419: }
13420: $chgtext .= '</ul>';
13421: if (@username_rule > 0) {
13422: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13423: } else {
13424: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13425: }
13426: }
13427: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13428: my ($idrules,$idruleorder) =
13429: &Apache::lonnet::inst_userrules($dom,'id');
13430: my $chgtext = '<ul>';
13431: foreach my $type (@id_rule) {
13432: if (ref($idrules->{$type}) eq 'HASH') {
13433: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13434: }
13435: }
13436: $chgtext .= '</ul>';
13437: if (@id_rule > 0) {
13438: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13439: } else {
13440: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13441: }
13442: }
13443: my %authname = &authtype_names();
13444: my %context_title = &context_names();
13445: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13446: my $chgtext = '<ul>';
13447: foreach my $type (@{$changes{'authtypes'}}) {
13448: my @allowed;
13449: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13450: foreach my $auth (@authtypes) {
13451: if ($authhash{$type}{$auth}) {
13452: push(@allowed,$authname{$auth});
13453: }
13454: }
13455: if (@allowed > 0) {
13456: $chgtext .= join(', ',@allowed).'</li>';
13457: } else {
13458: $chgtext .= &mt('none').'</li>';
13459: }
13460: }
13461: $chgtext .= '</ul>';
13462: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13463: $resulttext .= '</li>';
13464: }
13465: $resulttext .= '</ul>';
13466: } else {
13467: $resulttext = &mt('No changes made to user creation settings');
13468: }
13469: } else {
13470: $resulttext = '<span class="LC_error">'.
13471: &mt('An error occurred: [_1]',$putresult).'</span>';
13472: }
13473: if ($warningmsg ne '') {
13474: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13475: }
13476: return $resulttext;
13477: }
13478:
13479: sub modify_selfcreation {
1.160.6.93 raeburn 13480: my ($dom,$lastactref,%domconfig) = @_;
13481: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13482: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13483: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13484: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13485: if (ref($typesref) eq 'ARRAY') {
13486: @types = @{$typesref};
13487: }
13488: if (ref($usertypesref) eq 'HASH') {
13489: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 13490: }
1.160.6.93 raeburn 13491: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 13492: #
13493: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13494: #
13495: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13496: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13497: if ($key eq 'cancreate') {
13498: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13499: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13500: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 13501: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13502: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13503: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13504: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
13505: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 13506: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13507: } else {
13508: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13509: }
13510: }
13511: }
13512: } elsif ($key eq 'email_rule') {
13513: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13514: } else {
13515: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13516: }
13517: }
13518: }
13519: #
13520: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13521: #
13522: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13523: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13524: if ($key eq 'selfcreate') {
13525: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13526: } else {
13527: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13528: }
13529: }
13530: }
1.160.6.93 raeburn 13531: #
13532: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13533: #
13534: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13535: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13536: if ($key eq 'inststatusguest') {
13537: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13538: } else {
13539: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13540: }
13541: }
13542: }
1.160.6.34 raeburn 13543:
13544: my @contexts = ('selfcreate');
13545: @{$cancreate{'selfcreate'}} = ();
13546: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 13547: if (@types) {
13548: @{$cancreate{'statustocreate'}} = ();
13549: }
1.160.6.40 raeburn 13550: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 13551: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 13552: %{$cancreate{'emailverified'}} = ();
13553: %{$cancreate{'emailoptions'}} = ();
13554: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13555: my %selfcreatetypes = (
13556: sso => 'users authenticated by institutional single sign on',
13557: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 13558: email => 'users verified by e-mail',
1.50 raeburn 13559: );
1.160.6.34 raeburn 13560: #
13561: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13562: # is permitted.
13563: #
1.160.6.40 raeburn 13564:
1.160.6.93 raeburn 13565: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 13566:
1.160.6.93 raeburn 13567: my (@statuses,%email_rule);
1.160.6.35 raeburn 13568: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 13569: if ($item eq 'email') {
1.160.6.40 raeburn 13570: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 13571: if (@types) {
13572: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13573: foreach my $status (@poss_statuses) {
13574: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13575: push(@statuses,$status);
13576: }
13577: }
13578: $save_inststatus{'inststatusguest'} = \@statuses;
13579: } else {
13580: push(@statuses,'default');
13581: }
13582: if (@statuses) {
13583: my %curr_rule;
13584: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13585: foreach my $type (@statuses) {
13586: $curr_rule{$type} = $curr_usercreation{'email_rule'};
13587: }
13588: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13589: foreach my $type (@statuses) {
13590: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13591: }
13592: }
13593: push(@{$cancreate{'selfcreate'}},'email');
13594: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13595: my %curremaildom;
13596: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13597: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13598: }
13599: foreach my $type (@statuses) {
13600: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13601: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13602: }
13603: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13604: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13605: }
13606: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13607: #
13608: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13609: #
13610: my $chosen = $1;
13611: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13612: my $emaildom;
13613: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13614: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13615: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13616: if (ref($curremaildom{$type}) eq 'HASH') {
13617: if (exists($curremaildom{$type}{$chosen})) {
13618: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13619: push(@{$changes{'cancreate'}},'emaildomain');
13620: }
13621: } elsif ($emaildom ne '') {
13622: push(@{$changes{'cancreate'}},'emaildomain');
13623: }
13624: } elsif ($emaildom ne '') {
13625: push(@{$changes{'cancreate'}},'emaildomain');
13626: }
13627: }
13628: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13629: } elsif ($chosen eq 'custom') {
13630: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13631: $email_rule{$type} = [];
13632: if (ref($emailrules) eq 'HASH') {
13633: foreach my $rule (@possemail_rules) {
13634: if (exists($emailrules->{$rule})) {
13635: push(@{$email_rule{$type}},$rule);
13636: }
13637: }
13638: }
13639: if (@{$email_rule{$type}}) {
13640: $cancreate{'emailoptions'}{$type} = 'custom';
13641: if (ref($curr_rule{$type}) eq 'ARRAY') {
13642: if (@{$curr_rule{$type}} > 0) {
13643: foreach my $rule (@{$curr_rule{$type}}) {
13644: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13645: push(@{$changes{'email_rule'}},$type);
13646: }
13647: }
13648: }
13649: foreach my $type (@{$email_rule{$type}}) {
13650: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13651: push(@{$changes{'email_rule'}},$type);
13652: }
13653: }
13654: } else {
13655: push(@{$changes{'email_rule'}},$type);
13656: }
13657: }
13658: } else {
13659: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13660: }
13661: }
13662: }
13663: if (@types) {
13664: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13665: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13666: if (@changed) {
13667: push(@{$changes{'inststatus'}},'inststatusguest');
13668: }
13669: } else {
13670: push(@{$changes{'inststatus'}},'inststatusguest');
13671: }
13672: }
13673: } else {
13674: delete($env{'form.cancreate_email'});
13675: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13676: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13677: push(@{$changes{'inststatus'}},'inststatusguest');
13678: }
13679: }
13680: }
13681: } else {
13682: $save_inststatus{'inststatusguest'} = [];
13683: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13684: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13685: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 13686: }
13687: }
1.160.6.34 raeburn 13688: }
13689: } else {
13690: if ($env{'form.cancreate_'.$item}) {
13691: push(@{$cancreate{'selfcreate'}},$item);
13692: }
13693: }
13694: }
1.160.6.93 raeburn 13695: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 13696: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13697: #
1.160.6.35 raeburn 13698: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13699: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.160.6.34 raeburn 13700: #
1.160.6.40 raeburn 13701:
1.160.6.48 raeburn 13702: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 13703: push(@contexts,'emailusername');
1.160.6.93 raeburn 13704: if (@statuses) {
13705: foreach my $type (@statuses) {
1.160.6.35 raeburn 13706: if (ref($infofields) eq 'ARRAY') {
13707: foreach my $field (@{$infofields}) {
13708: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13709: $cancreate{'emailusername'}{$type}{$field} = $1;
13710: }
13711: }
1.160.6.34 raeburn 13712: }
13713: }
13714: }
13715: #
13716: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 13717: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 13718: #
13719:
13720: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13721: @approvalnotify = sort(@approvalnotify);
13722: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13723: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13724: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13725: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13726: push(@{$changes{'cancreate'}},'notify');
13727: }
13728: } else {
13729: if ($cancreate{'notify'}{'approval'}) {
13730: push(@{$changes{'cancreate'}},'notify');
13731: }
13732: }
13733: } elsif ($cancreate{'notify'}{'approval'}) {
13734: push(@{$changes{'cancreate'}},'notify');
13735: }
13736:
13737: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13738: }
13739: #
1.160.6.40 raeburn 13740: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 13741: # institutional log-in.
13742: #
13743: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13744: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13745: ($domdefaults{'auth_def'} eq 'localauth'))) {
13746: $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.').' '.
13747: &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.');
13748: }
13749: }
13750: my @fields = ('lastname','firstname','middlename','generation',
13751: 'permanentemail','id');
1.160.6.44 raeburn 13752: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 13753: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13754: #
13755: # Where usernames may created for institutional log-in and/or institutional single sign on:
13756: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13757: # may self-create accounts
13758: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13759: # which the user may supply, if institutional data is unavailable.
13760: #
13761: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 13762: if (@types) {
13763: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13764: push(@contexts,'statustocreate');
13765: foreach my $type (@types) {
1.160.6.34 raeburn 13766: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13767: foreach my $field (@fields) {
13768: if (grep(/^\Q$field\E$/,@modifiable)) {
13769: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13770: } else {
13771: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13772: }
13773: }
13774: }
13775: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 13776: foreach my $type (@types) {
1.160.6.34 raeburn 13777: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13778: foreach my $field (@fields) {
13779: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13780: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13781: push(@{$changes{'selfcreate'}},$type);
13782: last;
13783: }
13784: }
13785: }
13786: }
13787: } else {
1.160.6.93 raeburn 13788: foreach my $type (@types) {
1.160.6.34 raeburn 13789: push(@{$changes{'selfcreate'}},$type);
13790: }
13791: }
13792: }
1.160.6.44 raeburn 13793: foreach my $field (@shibfields) {
13794: if ($env{'form.shibenv_'.$field} ne '') {
13795: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13796: }
13797: }
13798: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13799: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13800: foreach my $field (@shibfields) {
13801: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13802: push(@{$changes{'cancreate'}},'shibenv');
13803: }
13804: }
13805: } else {
13806: foreach my $field (@shibfields) {
13807: if ($env{'form.shibenv_'.$field}) {
13808: push(@{$changes{'cancreate'}},'shibenv');
13809: last;
13810: }
13811: }
13812: }
13813: }
1.160.6.34 raeburn 13814: }
13815: foreach my $item (@contexts) {
13816: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13817: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13818: if (ref($cancreate{$item}) eq 'ARRAY') {
13819: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13820: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13821: push(@{$changes{'cancreate'}},$item);
13822: }
13823: }
13824: }
13825: }
13826: if (ref($cancreate{$item}) eq 'ARRAY') {
13827: foreach my $type (@{$cancreate{$item}}) {
13828: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13829: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13830: push(@{$changes{'cancreate'}},$item);
13831: }
13832: }
13833: }
13834: }
13835: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13836: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 13837: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13838: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13839: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13840: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13841: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13842: push(@{$changes{'cancreate'}},$item);
13843: }
13844: }
13845: }
1.160.6.93 raeburn 13846: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13847: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13848: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13849: push(@{$changes{'cancreate'}},$item);
13850: }
1.160.6.34 raeburn 13851: }
13852: }
13853: }
1.160.6.93 raeburn 13854: foreach my $type (keys(%{$cancreate{$item}})) {
13855: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13856: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13857: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13858: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13859: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13860: push(@{$changes{'cancreate'}},$item);
13861: }
13862: }
13863: } else {
13864: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13865: push(@{$changes{'cancreate'}},$item);
13866: }
13867: }
13868: }
1.160.6.93 raeburn 13869: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13870: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13871: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13872: push(@{$changes{'cancreate'}},$item);
13873: }
1.160.6.34 raeburn 13874: }
13875: }
13876: }
13877: }
13878: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13879: if (ref($cancreate{$item}) eq 'ARRAY') {
13880: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13881: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13882: push(@{$changes{'cancreate'}},$item);
13883: }
13884: }
1.160.6.93 raeburn 13885: }
13886: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13887: if (ref($cancreate{$item}) eq 'HASH') {
13888: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13889: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 13890: }
13891: }
13892: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 13893: if (ref($cancreate{$item}) eq 'HASH') {
13894: foreach my $type (keys(%{$cancreate{$item}})) {
13895: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13896: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13897: if ($cancreate{$item}{$type}{$field}) {
13898: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13899: push(@{$changes{'cancreate'}},$item);
13900: }
13901: last;
13902: }
13903: }
13904: }
13905: }
1.160.6.34 raeburn 13906: }
13907: }
13908: }
13909: #
13910: # Populate %save_usercreate hash with updates to self-creation configuration.
13911: #
13912: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13913: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 13914: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 13915: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13916: if (ref($cancreate{'notify'}) eq 'HASH') {
13917: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13918: }
1.160.6.40 raeburn 13919: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13920: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13921: }
1.160.6.93 raeburn 13922: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13923: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13924: }
13925: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13926: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13927: }
13928: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13929: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13930: }
1.160.6.34 raeburn 13931: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13932: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13933: }
1.160.6.44 raeburn 13934: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13935: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13936: }
1.160.6.34 raeburn 13937: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 13938: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 13939:
13940: my %userconfig_hash = (
13941: usercreation => \%save_usercreate,
13942: usermodification => \%save_usermodify,
1.160.6.93 raeburn 13943: inststatus => \%save_inststatus,
1.160.6.34 raeburn 13944: );
1.160.6.93 raeburn 13945:
1.160.6.34 raeburn 13946: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13947: $dom);
13948: #
1.160.6.93 raeburn 13949: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 13950: #
1.27 raeburn 13951: if ($putresult eq 'ok') {
13952: if (keys(%changes) > 0) {
13953: $resulttext = &mt('Changes made:').'<ul>';
13954: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 13955: my %lt = &selfcreation_types();
1.34 raeburn 13956: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 13957: my $chgtext = '';
1.45 raeburn 13958: if ($type eq 'selfcreate') {
1.50 raeburn 13959: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 13960: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13961: } else {
1.160.6.34 raeburn 13962: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13963: '<ul>';
1.50 raeburn 13964: foreach my $case (@{$cancreate{$type}}) {
13965: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13966: }
13967: $chgtext .= '</ul>';
1.100 raeburn 13968: if (ref($cancreate{$type}) eq 'ARRAY') {
13969: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13970: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13971: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 13972: $chgtext .= '<span class="LC_warning">'.
13973: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13974: '</span><br />';
1.100 raeburn 13975: }
13976: }
13977: }
1.160.6.93 raeburn 13978: if (grep(/^email$/,@{$cancreate{$type}})) {
13979: if (!@statuses) {
13980: $chgtext .= '<span class="LC_warning">'.
13981: &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
13982: '</span><br />';
13983:
13984: }
13985: }
1.100 raeburn 13986: }
1.43 raeburn 13987: }
1.160.6.44 raeburn 13988: } elsif ($type eq 'shibenv') {
13989: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 13990: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 13991: } else {
13992: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13993: '<ul>';
13994: foreach my $field (@shibfields) {
13995: next if ($cancreate{$type}{$field} eq '');
13996: if ($field eq 'inststatus') {
13997: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13998: } else {
13999: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
14000: }
14001: }
14002: $chgtext .= '</ul>';
1.160.6.93 raeburn 14003: }
1.93 raeburn 14004: } elsif ($type eq 'statustocreate') {
1.96 raeburn 14005: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
14006: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
14007: if (@{$cancreate{'selfcreate'}} > 0) {
14008: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 14009: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 14010: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 14011: $chgtext .= '<br />'.
14012: '<span class="LC_warning">'.
14013: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
14014: '</span>';
14015: }
1.160.6.93 raeburn 14016: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 14017: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 14018: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
14019: } else {
14020: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
14021: }
14022: $chgtext .= '<ul>';
14023: foreach my $case (@{$cancreate{$type}}) {
14024: if ($case eq 'default') {
14025: $chgtext .= '<li>'.$othertitle.'</li>';
14026: } else {
1.160.6.93 raeburn 14027: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 14028: }
14029: }
1.100 raeburn 14030: $chgtext .= '</ul>';
14031: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 14032: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 14033: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
14034: '</span>';
1.100 raeburn 14035: }
14036: }
14037: } else {
14038: if (@{$cancreate{$type}} == 0) {
14039: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
14040: } else {
14041: $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 14042: }
14043: }
1.160.6.93 raeburn 14044: $chgtext .= '<br />';
1.93 raeburn 14045: }
1.160.6.40 raeburn 14046: } elsif ($type eq 'selfcreateprocessing') {
14047: my %choices = &Apache::lonlocal::texthash (
14048: automatic => 'Automatic approval',
14049: approval => 'Queued for approval',
14050: );
1.160.6.93 raeburn 14051: if (@types) {
14052: if (@statuses) {
14053: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
14054: '<ul>';
14055: foreach my $status (@statuses) {
14056: if ($status eq 'default') {
14057: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
14058: } else {
14059: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
14060: }
14061: }
14062: $chgtext .= '</ul>';
14063: }
14064: } else {
14065: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
14066: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
14067: }
14068: } elsif ($type eq 'emailverified') {
14069: my %options = &Apache::lonlocal::texthash (
14070: all => 'Same as e-mail',
14071: first => 'Omit @domain',
14072: free => 'Free to choose',
14073: );
14074: if (@types) {
14075: if (@statuses) {
14076: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
14077: '<ul>';
14078: foreach my $status (@statuses) {
14079: if ($status eq 'default') {
14080: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
14081: } else {
14082: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
14083: }
14084: }
14085: $chgtext .= '</ul>';
14086: }
1.160.6.40 raeburn 14087: } else {
1.160.6.93 raeburn 14088: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
14089: $options{$cancreate{'emailverified'}{'default'}});
14090: }
14091: } elsif ($type eq 'emailoptions') {
14092: my %options = &Apache::lonlocal::texthash (
14093: any => 'Any e-mail',
14094: inst => 'Institutional only',
14095: noninst => 'Non-institutional only',
14096: custom => 'Custom restrictions',
14097: );
14098: if (@types) {
14099: if (@statuses) {
14100: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
14101: '<ul>';
14102: foreach my $status (@statuses) {
14103: if ($type eq 'default') {
14104: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
14105: } else {
14106: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
14107: }
14108: }
14109: $chgtext .= '</ul>';
14110: }
14111: } else {
14112: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
14113: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
14114: } else {
14115: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
14116: $options{$cancreate{'emailoptions'}{'default'}});
14117: }
14118: }
14119: } elsif ($type eq 'emaildomain') {
14120: my $output;
14121: if (@statuses) {
14122: foreach my $type (@statuses) {
14123: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
14124: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
14125: if ($type eq 'default') {
14126: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14127: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14128: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14129: } else {
14130: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
14131: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14132: }
14133: } else {
14134: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14135: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14136: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14137: } else {
14138: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
14139: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14140: }
14141: }
14142: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
14143: if ($type eq 'default') {
14144: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14145: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14146: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14147: } else {
14148: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
14149: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14150: }
14151: } else {
14152: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14153: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14154: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14155: } else {
14156: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
14157: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14158: }
14159: }
14160: }
14161: }
14162: }
14163: }
14164: if ($output ne '') {
14165: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
14166: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 14167: }
1.160.6.5 raeburn 14168: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 14169: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 14170: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
14171: } else {
14172: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 14173: if ($captchas{$savecaptcha{$type}}) {
14174: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 14175: } else {
14176: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
14177: }
14178: }
14179: } elsif ($type eq 'recaptchakeys') {
14180: my ($privkey,$pubkey);
1.160.6.34 raeburn 14181: if (ref($savecaptcha{$type}) eq 'HASH') {
14182: $pubkey = $savecaptcha{$type}{'public'};
14183: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 14184: }
14185: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
14186: if (!$pubkey) {
14187: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
14188: } else {
14189: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
14190: }
14191: if (!$privkey) {
14192: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
14193: } else {
14194: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14195: }
14196: $chgtext .= '</ul>';
1.160.6.69 raeburn 14197: } elsif ($type eq 'recaptchaversion') {
14198: if ($savecaptcha{'captcha'} eq 'recaptcha') {
14199: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
14200: }
1.160.6.34 raeburn 14201: } elsif ($type eq 'emailusername') {
14202: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 14203: if (@statuses) {
14204: foreach my $type (@statuses) {
1.160.6.35 raeburn 14205: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14206: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 14207: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.160.6.35 raeburn 14208: '<ul>';
14209: foreach my $field (@{$infofields}) {
14210: if ($cancreate{'emailusername'}{$type}{$field}) {
14211: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14212: }
14213: }
1.160.6.50 raeburn 14214: $chgtext .= '</ul>';
14215: } else {
1.160.6.93 raeburn 14216: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.160.6.35 raeburn 14217: }
14218: } else {
1.160.6.93 raeburn 14219: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.160.6.34 raeburn 14220: }
14221: }
14222: }
14223: }
14224: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 14225: my $numapprove = 0;
1.160.6.34 raeburn 14226: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14227: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14228: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 14229: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14230: $numapprove ++;
1.160.6.34 raeburn 14231: }
14232: }
1.43 raeburn 14233: }
1.160.6.93 raeburn 14234: unless ($numapprove) {
14235: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14236: }
1.34 raeburn 14237: }
1.160.6.34 raeburn 14238: if ($chgtext) {
14239: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 14240: }
14241: }
14242: }
1.160.6.93 raeburn 14243: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 14244: my ($emailrules,$emailruleorder) =
14245: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 14246: foreach my $type (@{$changes{'email_rule'}}) {
14247: if (ref($email_rule{$type}) eq 'ARRAY') {
14248: my $chgtext = '<ul>';
14249: foreach my $rule (@{$email_rule{$type}}) {
14250: if (ref($emailrules->{$rule}) eq 'HASH') {
14251: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14252: }
14253: }
14254: $chgtext .= '</ul>';
14255: my $typename;
14256: if (@types) {
14257: if ($type eq 'default') {
14258: $typename = $othertitle;
14259: } else {
14260: $typename = $usertypes{$type};
14261: }
14262: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14263: }
14264: if (@{$email_rule{$type}} > 0) {
14265: $resulttext .= '<li>'.
14266: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14267: $usertypes{$type}).
14268: $chgtext.
14269: '</li>';
14270: } else {
14271: $resulttext .= '<li>'.
14272: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
14273: '</li>'.
14274: &mt('(Affiliation: [_1])',$typename);
14275: }
1.43 raeburn 14276: }
14277: }
1.160.6.93 raeburn 14278: }
14279: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14280: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14281: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14282: my $chgtext = '<ul>';
14283: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14284: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14285: }
14286: $chgtext .= '</ul>';
14287: $resulttext .= '<li>'.
14288: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14289: $chgtext.
14290: '</li>';
14291: } else {
14292: $resulttext .= '<li>'.
14293: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14294: '</li>';
14295: }
1.43 raeburn 14296: }
14297: }
1.160.6.34 raeburn 14298: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14299: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14300: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14301: foreach my $type (@{$changes{'selfcreate'}}) {
14302: my $typename = $type;
1.160.6.93 raeburn 14303: if (keys(%usertypes) > 0) {
14304: if ($usertypes{$type} ne '') {
14305: $typename = $usertypes{$type};
1.28 raeburn 14306: }
14307: }
1.160.6.34 raeburn 14308: my @modifiable;
14309: $resulttext .= '<li>'.
14310: &mt('Self-creation of account by users with status: [_1]',
14311: '<span class="LC_cusr_emph">'.$typename.'</span>').
14312: ' - '.&mt('modifiable fields (if institutional data blank): ');
14313: foreach my $field (@fields) {
14314: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14315: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
14316: }
14317: }
14318: if (@modifiable > 0) {
14319: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14320: } else {
1.160.6.34 raeburn 14321: $resulttext .= &mt('none');
1.43 raeburn 14322: }
1.160.6.34 raeburn 14323: $resulttext .= '</li>';
1.28 raeburn 14324: }
1.160.6.34 raeburn 14325: $resulttext .= '</ul></li>';
1.28 raeburn 14326: }
1.27 raeburn 14327: $resulttext .= '</ul>';
1.160.6.93 raeburn 14328: my $cachetime = 24*60*60;
14329: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14330: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14331: if (ref($lastactref) eq 'HASH') {
14332: $lastactref->{'domdefaults'} = 1;
14333: }
1.27 raeburn 14334: } else {
1.160.6.34 raeburn 14335: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14336: }
14337: } else {
14338: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14339: &mt('An error occurred: [_1]',$putresult).'</span>';
14340: }
1.43 raeburn 14341: if ($warningmsg ne '') {
14342: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14343: }
1.23 raeburn 14344: return $resulttext;
14345: }
14346:
1.160.6.5 raeburn 14347: sub process_captcha {
1.160.6.104 raeburn 14348: my ($container,$changes,$newsettings,$currsettings) = @_;
14349: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 14350: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14351: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14352: $newsettings->{'captcha'} = 'original';
14353: }
1.160.6.104 raeburn 14354: my %current;
14355: if (ref($currsettings) eq 'HASH') {
14356: %current = %{$currsettings};
14357: }
14358: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 14359: if ($container eq 'cancreate') {
14360: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14361: push(@{$changes->{'cancreate'}},'captcha');
14362: } elsif (!defined($changes->{'cancreate'})) {
14363: $changes->{'cancreate'} = ['captcha'];
14364: }
1.160.6.102 raeburn 14365: } elsif ($container eq 'passwords') {
14366: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14367: } else {
14368: $changes->{'captcha'} = 1;
14369: }
14370: }
1.160.6.69 raeburn 14371: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 14372: if ($newsettings->{'captcha'} eq 'recaptcha') {
14373: $newpub = $env{'form.'.$container.'_recaptchapub'};
14374: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 14375: $newpub =~ s/[^\w\-]//g;
14376: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 14377: $newsettings->{'recaptchakeys'} = {
14378: public => $newpub,
14379: private => $newpriv,
14380: };
1.160.6.69 raeburn 14381: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14382: $newversion =~ s/\D//g;
14383: if ($newversion ne '2') {
14384: $newversion = 1;
14385: }
14386: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 14387: }
1.160.6.104 raeburn 14388: if (ref($current{'recaptchakeys'}) eq 'HASH') {
14389: $currpub = $current{'recaptchakeys'}{'public'};
14390: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 14391: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14392: $newsettings->{'recaptchakeys'} = {
14393: public => '',
14394: private => '',
14395: }
14396: }
1.160.6.5 raeburn 14397: }
1.160.6.104 raeburn 14398: if ($current{'captcha'} eq 'recaptcha') {
14399: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 14400: if ($currversion ne '2') {
14401: $currversion = 1;
14402: }
14403: }
14404: if ($currversion ne $newversion) {
14405: if ($container eq 'cancreate') {
14406: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14407: push(@{$changes->{'cancreate'}},'recaptchaversion');
14408: } elsif (!defined($changes->{'cancreate'})) {
14409: $changes->{'cancreate'} = ['recaptchaversion'];
14410: }
1.160.6.102 raeburn 14411: } elsif ($container eq 'passwords') {
14412: $changes->{'reset'} = 1;
1.160.6.69 raeburn 14413: } else {
14414: $changes->{'recaptchaversion'} = 1;
14415: }
14416: }
1.160.6.5 raeburn 14417: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
14418: if ($container eq 'cancreate') {
14419: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14420: push(@{$changes->{'cancreate'}},'recaptchakeys');
14421: } elsif (!defined($changes->{'cancreate'})) {
14422: $changes->{'cancreate'} = ['recaptchakeys'];
14423: }
1.160.6.102 raeburn 14424: } elsif ($container eq 'passwords') {
14425: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14426: } else {
14427: $changes->{'recaptchakeys'} = 1;
14428: }
14429: }
14430: return;
14431: }
14432:
1.33 raeburn 14433: sub modify_usermodification {
14434: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 14435: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14436: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14437: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 14438: if ($key eq 'selfcreate') {
14439: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14440: } else {
14441: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14442: }
1.33 raeburn 14443: }
14444: }
1.160.6.34 raeburn 14445: my @contexts = ('author','course');
1.33 raeburn 14446: my %context_title = (
14447: author => 'In author context',
14448: course => 'In course context',
14449: );
14450: my @fields = ('lastname','firstname','middlename','generation',
14451: 'permanentemail','id');
14452: my %roles = (
14453: author => ['ca','aa'],
14454: course => ['st','ep','ta','in','cr'],
14455: );
14456: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14457: foreach my $context (@contexts) {
14458: foreach my $role (@{$roles{$context}}) {
14459: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14460: foreach my $item (@fields) {
14461: if (grep(/^\Q$item\E$/,@modifiable)) {
14462: $modifyhash{$context}{$role}{$item} = 1;
14463: } else {
14464: $modifyhash{$context}{$role}{$item} = 0;
14465: }
14466: }
14467: }
14468: if (ref($curr_usermodification{$context}) eq 'HASH') {
14469: foreach my $role (@{$roles{$context}}) {
14470: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14471: foreach my $field (@fields) {
14472: if ($modifyhash{$context}{$role}{$field} ne
14473: $curr_usermodification{$context}{$role}{$field}) {
14474: push(@{$changes{$context}},$role);
14475: last;
14476: }
14477: }
14478: }
14479: }
14480: } else {
14481: foreach my $context (@contexts) {
14482: foreach my $role (@{$roles{$context}}) {
14483: push(@{$changes{$context}},$role);
14484: }
14485: }
14486: }
14487: }
14488: my %usermodification_hash = (
14489: usermodification => \%modifyhash,
14490: );
14491: my $putresult = &Apache::lonnet::put_dom('configuration',
14492: \%usermodification_hash,$dom);
14493: if ($putresult eq 'ok') {
14494: if (keys(%changes) > 0) {
14495: $resulttext = &mt('Changes made: ').'<ul>';
14496: foreach my $context (@contexts) {
14497: if (ref($changes{$context}) eq 'ARRAY') {
14498: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14499: if (ref($changes{$context}) eq 'ARRAY') {
14500: foreach my $role (@{$changes{$context}}) {
14501: my $rolename;
1.160.6.34 raeburn 14502: if ($role eq 'cr') {
14503: $rolename = &mt('Custom');
1.33 raeburn 14504: } else {
1.160.6.34 raeburn 14505: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14506: }
14507: my @modifiable;
1.160.6.34 raeburn 14508: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14509: foreach my $field (@fields) {
14510: if ($modifyhash{$context}{$role}{$field}) {
14511: push(@modifiable,$fieldtitles{$field});
14512: }
14513: }
14514: if (@modifiable > 0) {
14515: $resulttext .= join(', ',@modifiable);
14516: } else {
14517: $resulttext .= &mt('none');
14518: }
14519: $resulttext .= '</li>';
14520: }
14521: $resulttext .= '</ul></li>';
14522: }
14523: }
14524: }
14525: $resulttext .= '</ul>';
14526: } else {
14527: $resulttext = &mt('No changes made to user modification settings');
14528: }
14529: } else {
14530: $resulttext = '<span class="LC_error">'.
14531: &mt('An error occurred: [_1]',$putresult).'</span>';
14532: }
14533: return $resulttext;
14534: }
14535:
1.43 raeburn 14536: sub modify_defaults {
1.160.6.27 raeburn 14537: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14538: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 14539: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 14540: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 14541: 'portal_def');
1.43 raeburn 14542: my @authtypes = ('internal','krb4','krb5','localauth');
14543: foreach my $item (@items) {
14544: $newvalues{$item} = $env{'form.'.$item};
14545: if ($item eq 'auth_def') {
14546: if ($newvalues{$item} ne '') {
14547: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14548: push(@errors,$item);
14549: }
14550: }
14551: } elsif ($item eq 'lang_def') {
14552: if ($newvalues{$item} ne '') {
14553: if ($newvalues{$item} =~ /^(\w+)/) {
14554: my $langcode = $1;
1.103 raeburn 14555: if ($langcode ne 'x_chef') {
14556: if (code2language($langcode) eq '') {
14557: push(@errors,$item);
14558: }
1.43 raeburn 14559: }
14560: } else {
14561: push(@errors,$item);
14562: }
14563: }
1.54 raeburn 14564: } elsif ($item eq 'timezone_def') {
14565: if ($newvalues{$item} ne '') {
1.62 raeburn 14566: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14567: push(@errors,$item);
14568: }
14569: }
1.68 raeburn 14570: } elsif ($item eq 'datelocale_def') {
14571: if ($newvalues{$item} ne '') {
14572: my @datelocale_ids = DateTime::Locale->ids();
14573: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14574: push(@errors,$item);
14575: }
14576: }
1.141 raeburn 14577: } elsif ($item eq 'portal_def') {
14578: if ($newvalues{$item} ne '') {
14579: 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])\/?$/) {
14580: push(@errors,$item);
14581: }
14582: }
1.43 raeburn 14583: }
14584: if (grep(/^\Q$item\E$/,@errors)) {
14585: $newvalues{$item} = $domdefaults{$item};
14586: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14587: $changes{$item} = 1;
14588: }
1.72 raeburn 14589: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14590: }
1.160.6.98 raeburn 14591: my %staticdefaults = (
14592: 'intauth_cost' => 10,
14593: 'intauth_check' => 0,
14594: 'intauth_switch' => 0,
14595: );
14596: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
14597: if (exists($domdefaults{$item})) {
14598: $newvalues{$item} = $domdefaults{$item};
14599: } else {
14600: $newvalues{$item} = $staticdefaults{$item};
14601: }
14602: }
1.160.6.122 raeburn 14603: my ($unamemaprules,$ruleorder);
14604: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
14605: if (@possunamemaprules) {
14606: ($unamemaprules,$ruleorder) =
14607: &Apache::lonnet::inst_userrules($dom,'unamemap');
14608: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
14609: if (@{$ruleorder} > 0) {
14610: my %possrules;
14611: map { $possrules{$_} = 1; } @possunamemaprules;
14612: foreach my $rule (@{$ruleorder}) {
14613: if ($possrules{$rule}) {
14614: push(@{$newvalues{'unamemap_rule'}},$rule);
14615: }
14616: }
14617: }
14618: }
14619: }
14620: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
14621: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
14622: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
14623: $newvalues{'unamemap_rule'});
14624: if (@rulediffs) {
14625: $changes{'unamemap_rule'} = 1;
14626: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
14627: }
14628: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
14629: $changes{'unamemap_rule'} = 1;
14630: delete($domdefaults{'unamemap_rule'});
14631: }
14632: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
14633: if (@{$newvalues{'unamemap_rule'}} > 0) {
14634: $changes{'unamemap_rule'} = 1;
14635: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
14636: }
14637: }
1.43 raeburn 14638: my %defaults_hash = (
1.72 raeburn 14639: defaults => \%newvalues,
14640: );
1.43 raeburn 14641: my $title = &defaults_titles();
1.160.6.40 raeburn 14642:
14643: my $currinststatus;
14644: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14645: $currinststatus = $domconfig{'inststatus'};
14646: } else {
14647: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14648: $currinststatus = {
14649: inststatustypes => $usertypes,
14650: inststatusorder => $types,
14651: inststatusguest => [],
14652: };
14653: }
14654: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14655: my @allpos;
14656: my %alltypes;
1.160.6.93 raeburn 14657: my @inststatusguest;
14658: if (ref($currinststatus) eq 'HASH') {
14659: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14660: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14661: unless (grep(/^\Q$type\E$/,@todelete)) {
14662: push(@inststatusguest,$type);
14663: }
14664: }
14665: }
14666: }
14667: my ($currtitles,$currorder);
1.160.6.40 raeburn 14668: if (ref($currinststatus) eq 'HASH') {
14669: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14670: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14671: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14672: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14673: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14674: }
14675: }
14676: unless (grep(/^\Q$type\E$/,@todelete)) {
14677: my $position = $env{'form.inststatus_pos_'.$type};
14678: $position =~ s/\D+//g;
14679: $allpos[$position] = $type;
14680: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14681: $alltypes{$type} =~ s/`//g;
14682: }
14683: }
14684: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14685: $currtitles =~ s/,$//;
14686: }
14687: }
14688: if ($env{'form.addinststatus'}) {
14689: my $newtype = $env{'form.addinststatus'};
14690: $newtype =~ s/\W//g;
14691: unless (exists($alltypes{$newtype})) {
14692: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14693: $alltypes{$newtype} =~ s/`//g;
14694: my $position = $env{'form.addinststatus_pos'};
14695: $position =~ s/\D+//g;
14696: if ($position ne '') {
14697: $allpos[$position] = $newtype;
14698: }
14699: }
14700: }
1.160.6.93 raeburn 14701: my @orderedstatus;
1.160.6.40 raeburn 14702: foreach my $type (@allpos) {
14703: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14704: push(@orderedstatus,$type);
14705: }
14706: }
14707: foreach my $type (keys(%alltypes)) {
14708: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14709: delete($alltypes{$type});
14710: }
14711: }
14712: $defaults_hash{'inststatus'} = {
14713: inststatustypes => \%alltypes,
14714: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 14715: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 14716: };
14717: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14718: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14719: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14720: }
14721: }
14722: if ($currorder ne join(',',@orderedstatus)) {
14723: $changes{'inststatus'}{'inststatusorder'} = 1;
14724: }
14725: my $newtitles;
14726: foreach my $item (@orderedstatus) {
14727: $newtitles .= $alltypes{$item}.',';
14728: }
14729: $newtitles =~ s/,$//;
14730: if ($currtitles ne $newtitles) {
14731: $changes{'inststatus'}{'inststatustypes'} = 1;
14732: }
1.43 raeburn 14733: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14734: $dom);
14735: if ($putresult eq 'ok') {
14736: if (keys(%changes) > 0) {
14737: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 14738: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14739: 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";
14740: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 14741: if ($item eq 'inststatus') {
14742: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 14743: if (@orderedstatus) {
1.160.6.40 raeburn 14744: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14745: foreach my $type (@orderedstatus) {
14746: $resulttext .= $alltypes{$type}.', ';
14747: }
14748: $resulttext =~ s/, $//;
14749: $resulttext .= '</li>';
1.160.6.93 raeburn 14750: } else {
14751: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 14752: }
14753: }
1.160.6.122 raeburn 14754: } elsif ($item eq 'unamemap_rule') {
14755: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
14756: my @rulenames;
14757: if (ref($unamemaprules) eq 'HASH') {
14758: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
14759: if (ref($unamemaprules->{$rule}) eq 'HASH') {
14760: push(@rulenames,$unamemaprules->{$rule}->{'name'});
14761: }
14762: }
14763: }
14764: if (@rulenames) {
14765: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
14766: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
14767: '</li>';
14768: } else {
14769: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
14770: }
14771: } else {
14772: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
14773: }
1.160.6.40 raeburn 14774: } else {
14775: my $value = $env{'form.'.$item};
14776: if ($value eq '') {
14777: $value = &mt('none');
14778: } elsif ($item eq 'auth_def') {
14779: my %authnames = &authtype_names();
14780: my %shortauth = (
14781: internal => 'int',
14782: krb4 => 'krb4',
14783: krb5 => 'krb5',
14784: localauth => 'loc',
14785: );
14786: $value = $authnames{$shortauth{$value}};
14787: }
14788: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14789: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14790: }
14791: }
14792: $resulttext .= '</ul>';
14793: $mailmsgtext .= "\n";
14794: my $cachetime = 24*60*60;
1.72 raeburn 14795: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 14796: if (ref($lastactref) eq 'HASH') {
14797: $lastactref->{'domdefaults'} = 1;
14798: }
1.68 raeburn 14799: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 14800: my $notify = 1;
14801: if (ref($domconfig{'contacts'}) eq 'HASH') {
14802: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14803: $notify = 0;
14804: }
14805: }
14806: if ($notify) {
14807: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14808: "LON-CAPA Domain Settings Change - $dom",
14809: $mailmsgtext);
14810: }
1.54 raeburn 14811: }
1.43 raeburn 14812: } else {
1.54 raeburn 14813: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14814: }
14815: } else {
14816: $resulttext = '<span class="LC_error">'.
14817: &mt('An error occurred: [_1]',$putresult).'</span>';
14818: }
14819: if (@errors > 0) {
14820: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14821: foreach my $item (@errors) {
14822: $resulttext .= ' "'.$title->{$item}.'",';
14823: }
14824: $resulttext =~ s/,$//;
14825: }
14826: return $resulttext;
14827: }
14828:
1.46 raeburn 14829: sub modify_scantron {
1.160.6.24 raeburn 14830: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14831: my ($resulttext,%confhash,%changes,$errors);
14832: my $custom = 'custom.tab';
14833: my $default = 'default.tab';
14834: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 14835: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 14836: &config_check($dom,$confname,$servadm);
14837: if ($env{'form.scantronformat.filename'} ne '') {
14838: my $error;
14839: if ($configuserok eq 'ok') {
14840: if ($switchserver) {
1.130 raeburn 14841: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14842: } else {
14843: if ($author_ok eq 'ok') {
14844: my ($result,$scantronurl) =
14845: &publishlogo($r,'upload','scantronformat',$dom,
14846: $confname,'scantron','','',$custom);
14847: if ($result eq 'ok') {
14848: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14849: $changes{'scantronformat'} = 1;
1.46 raeburn 14850: } else {
14851: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14852: }
14853: } else {
14854: $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);
14855: }
14856: }
14857: } else {
14858: $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);
14859: }
14860: if ($error) {
14861: &Apache::lonnet::logthis($error);
14862: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14863: }
14864: }
1.48 raeburn 14865: if (ref($domconfig{'scantron'}) eq 'HASH') {
14866: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14867: if ($env{'form.scantronformat_del'}) {
14868: $confhash{'scantron'}{'scantronformat'} = '';
14869: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 14870: } else {
14871: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
14872: }
14873: }
14874: }
14875: my @options = ('hdr','pad','rem');
14876: my @fields = &scantroncsv_fields();
14877: my %titles = &scantronconfig_titles();
14878: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
14879: my ($newdat,$currdat,%newcol,%currcol);
14880: if (grep(/^dat$/,@formats)) {
14881: $confhash{'scantron'}{config}{dat} = 1;
14882: $newdat = 1;
14883: } else {
14884: $newdat = 0;
14885: }
14886: if (grep(/^csv$/,@formats)) {
14887: my %bynum;
14888: foreach my $field (@fields) {
14889: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14890: my $posscol = $1;
14891: if (($posscol < 20) && (!$bynum{$posscol})) {
14892: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14893: $bynum{$posscol} = $field;
14894: $newcol{$field} = $posscol;
14895: }
14896: }
14897: }
14898: if (keys(%newcol)) {
14899: foreach my $option (@options) {
14900: if ($env{'form.scantroncsv_'.$option}) {
14901: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14902: }
14903: }
14904: }
14905: }
14906: $currdat = 1;
14907: if (ref($domconfig{'scantron'}) eq 'HASH') {
14908: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14909: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14910: $currdat = 0;
14911: }
14912: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14913: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14914: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14915: }
14916: }
14917: }
14918: }
14919: if ($currdat != $newdat) {
14920: $changes{'config'} = 1;
14921: } else {
14922: foreach my $field (@fields) {
14923: if ($currcol{$field} ne '') {
14924: if ($currcol{$field} ne $newcol{$field}) {
14925: $changes{'config'} = 1;
14926: last;
14927: }
14928: } elsif ($newcol{$field} ne '') {
14929: $changes{'config'} = 1;
14930: last;
1.46 raeburn 14931: }
14932: }
14933: }
14934: if (keys(%confhash) > 0) {
14935: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14936: $dom);
14937: if ($putresult eq 'ok') {
14938: if (keys(%changes) > 0) {
1.48 raeburn 14939: if (ref($confhash{'scantron'}) eq 'HASH') {
14940: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 14941: if ($changes{'scantronformat'}) {
14942: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14943: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14944: } else {
14945: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14946: }
14947: }
14948: if ($changes{'config'}) {
14949: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14950: if ($confhash{'scantron'}{'config'}{'dat'}) {
14951: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14952: }
14953: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14954: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14955: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14956: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14957: foreach my $field (@fields) {
14958: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14959: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14960: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14961: }
14962: }
14963: $resulttext .= '</ul></li>';
14964: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14965: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14966: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14967: foreach my $option (@options) {
14968: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14969: $resulttext .= '<li>'.$titles{$option}.'</li>';
14970: }
14971: }
14972: $resulttext .= '</ul></li>';
14973: }
14974: }
14975: }
14976: }
14977: }
14978: } else {
14979: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14980: }
1.46 raeburn 14981: }
1.48 raeburn 14982: $resulttext .= '</ul>';
14983: } else {
1.130 raeburn 14984: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14985: }
14986: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14987: if (ref($lastactref) eq 'HASH') {
14988: $lastactref->{'domainconfig'} = 1;
14989: }
1.46 raeburn 14990: } else {
1.160.6.97 raeburn 14991: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14992: }
14993: } else {
14994: $resulttext = '<span class="LC_error">'.
14995: &mt('An error occurred: [_1]',$putresult).'</span>';
14996: }
14997: } else {
1.160.6.97 raeburn 14998: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14999: }
15000: if ($errors) {
15001: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15002: $errors.'</ul>';
15003: }
15004: return $resulttext;
15005: }
15006:
1.48 raeburn 15007: sub modify_coursecategories {
1.160.6.43 raeburn 15008: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 15009: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
15010: $cathash);
1.48 raeburn 15011: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 15012: my @catitems = ('unauth','auth');
15013: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 15014: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 15015: $cathash = $domconfig{'coursecategories'}{'cats'};
15016: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
15017: $changes{'togglecats'} = 1;
15018: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
15019: }
15020: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
15021: $changes{'categorize'} = 1;
15022: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
15023: }
1.120 raeburn 15024: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
15025: $changes{'togglecatscomm'} = 1;
15026: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
15027: }
15028: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
15029: $changes{'categorizecomm'} = 1;
15030: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
15031: }
1.160.6.42 raeburn 15032: foreach my $item (@catitems) {
15033: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15034: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
15035: $changes{$item} = 1;
15036: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15037: }
15038: }
15039: }
1.57 raeburn 15040: } else {
15041: $changes{'togglecats'} = 1;
15042: $changes{'categorize'} = 1;
1.124 raeburn 15043: $changes{'togglecatscomm'} = 1;
15044: $changes{'categorizecomm'} = 1;
1.87 raeburn 15045: $domconfig{'coursecategories'} = {
15046: togglecats => $env{'form.togglecats'},
15047: categorize => $env{'form.categorize'},
1.124 raeburn 15048: togglecatscomm => $env{'form.togglecatscomm'},
15049: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 15050: };
1.160.6.42 raeburn 15051: foreach my $item (@catitems) {
15052: if ($env{'form.coursecat_'.$item} ne 'std') {
15053: $changes{$item} = 1;
15054: }
15055: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15056: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15057: }
15058: }
1.57 raeburn 15059: }
15060: if (ref($cathash) eq 'HASH') {
15061: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 15062: push (@deletecategory,'instcode::0');
15063: }
1.120 raeburn 15064: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
15065: push(@deletecategory,'communities::0');
15066: }
1.48 raeburn 15067: }
1.57 raeburn 15068: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
15069: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15070: if (@deletecategory > 0) {
15071: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 15072: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 15073: foreach my $item (@deletecategory) {
1.57 raeburn 15074: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
15075: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 15076: $deletions{$item} = 1;
1.57 raeburn 15077: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 15078: }
15079: }
15080: }
1.57 raeburn 15081: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 15082: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 15083: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 15084: $reorderings{$item} = 1;
1.57 raeburn 15085: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 15086: }
15087: if ($env{'form.addcategory_name_'.$item} ne '') {
15088: my $newcat = $env{'form.addcategory_name_'.$item};
15089: my $newdepth = $depth+1;
15090: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15091: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 15092: $adds{$newitem} = 1;
15093: }
15094: if ($env{'form.subcat_'.$item} ne '') {
15095: my $newcat = $env{'form.subcat_'.$item};
15096: my $newdepth = $depth+1;
15097: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15098: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 15099: $adds{$newitem} = 1;
15100: }
15101: }
15102: }
15103: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 15104: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15105: my $newitem = 'instcode::0';
1.57 raeburn 15106: if ($cathash->{$newitem} eq '') {
15107: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15108: $adds{$newitem} = 1;
15109: }
15110: } else {
15111: my $newitem = 'instcode::0';
1.57 raeburn 15112: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15113: $adds{$newitem} = 1;
15114: }
15115: }
1.120 raeburn 15116: if ($env{'form.communities'} eq '1') {
15117: if (ref($cathash) eq 'HASH') {
15118: my $newitem = 'communities::0';
15119: if ($cathash->{$newitem} eq '') {
15120: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15121: $adds{$newitem} = 1;
15122: }
15123: } else {
15124: my $newitem = 'communities::0';
15125: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15126: $adds{$newitem} = 1;
15127: }
15128: }
1.48 raeburn 15129: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 15130: if (($env{'form.addcategory_name'} ne 'instcode') &&
15131: ($env{'form.addcategory_name'} ne 'communities')) {
15132: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
15133: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
15134: $adds{$newitem} = 1;
15135: }
1.48 raeburn 15136: }
1.57 raeburn 15137: my $putresult;
1.48 raeburn 15138: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15139: if (keys(%deletions) > 0) {
15140: foreach my $key (keys(%deletions)) {
15141: if ($predelallitems{$key} ne '') {
15142: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
15143: }
15144: }
15145: }
15146: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 15147: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 15148: if (ref($chkcats[0]) eq 'ARRAY') {
15149: my $depth = 0;
15150: my $chg = 0;
15151: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
15152: my $name = $chkcats[0][$i];
15153: my $item;
15154: if ($name eq '') {
15155: $chg ++;
15156: } else {
15157: $item = &escape($name).'::0';
15158: if ($chg) {
1.57 raeburn 15159: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 15160: }
15161: $depth ++;
1.57 raeburn 15162: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 15163: $depth --;
15164: }
15165: }
15166: }
1.57 raeburn 15167: }
15168: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15169: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 15170: if ($putresult eq 'ok') {
1.57 raeburn 15171: my %title = (
1.120 raeburn 15172: togglecats => 'Show/Hide a course in catalog',
15173: categorize => 'Assign a category to a course',
15174: togglecatscomm => 'Show/Hide a community in catalog',
15175: categorizecomm => 'Assign a category to a community',
1.57 raeburn 15176: );
15177: my %level = (
1.120 raeburn 15178: dom => 'set in Domain ("Modify Course/Community")',
15179: crs => 'set in Course ("Course Configuration")',
15180: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 15181: none => 'No catalog',
15182: std => 'Standard catalog',
15183: domonly => 'Domain-only catalog',
15184: codesrch => 'Code search form',
1.57 raeburn 15185: );
1.48 raeburn 15186: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 15187: if ($changes{'togglecats'}) {
15188: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
15189: }
15190: if ($changes{'categorize'}) {
15191: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 15192: }
1.120 raeburn 15193: if ($changes{'togglecatscomm'}) {
15194: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
15195: }
15196: if ($changes{'categorizecomm'}) {
15197: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
15198: }
1.160.6.42 raeburn 15199: if ($changes{'unauth'}) {
15200: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
15201: }
15202: if ($changes{'auth'}) {
15203: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
15204: }
1.57 raeburn 15205: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15206: my $cathash;
15207: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
15208: $cathash = $domconfig{'coursecategories'}{'cats'};
15209: } else {
15210: $cathash = {};
15211: }
15212: my (@cats,@trails,%allitems);
15213: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
15214: if (keys(%deletions) > 0) {
15215: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
15216: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
15217: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
15218: }
15219: $resulttext .= '</ul></li>';
15220: }
15221: if (keys(%reorderings) > 0) {
15222: my %sort_by_trail;
15223: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
15224: foreach my $key (keys(%reorderings)) {
15225: if ($allitems{$key} ne '') {
15226: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15227: }
1.48 raeburn 15228: }
1.57 raeburn 15229: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15230: $resulttext .= '<li>'.$trails[$trail].'</li>';
15231: }
15232: $resulttext .= '</ul></li>';
1.48 raeburn 15233: }
1.57 raeburn 15234: if (keys(%adds) > 0) {
15235: my %sort_by_trail;
15236: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
15237: foreach my $key (keys(%adds)) {
15238: if ($allitems{$key} ne '') {
15239: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15240: }
15241: }
15242: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15243: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 15244: }
1.57 raeburn 15245: $resulttext .= '</ul></li>';
1.48 raeburn 15246: }
1.160.6.92 raeburn 15247: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
15248: if (ref($lastactref) eq 'HASH') {
15249: $lastactref->{'cats'} = 1;
15250: }
1.48 raeburn 15251: }
15252: $resulttext .= '</ul>';
1.160.6.43 raeburn 15253: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 15254: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15255: if ($changes{'auth'}) {
15256: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
15257: }
15258: if ($changes{'unauth'}) {
15259: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
15260: }
15261: my $cachetime = 24*60*60;
15262: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 15263: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 15264: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 15265: }
15266: }
1.48 raeburn 15267: } else {
15268: $resulttext = '<span class="LC_error">'.
1.57 raeburn 15269: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 15270: }
15271: } else {
1.120 raeburn 15272: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 15273: }
15274: return $resulttext;
15275: }
15276:
1.69 raeburn 15277: sub modify_serverstatuses {
15278: my ($dom,%domconfig) = @_;
15279: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
15280: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
15281: %currserverstatus = %{$domconfig{'serverstatuses'}};
15282: }
15283: my @pages = &serverstatus_pages();
15284: foreach my $type (@pages) {
15285: $newserverstatus{$type}{'namedusers'} = '';
15286: $newserverstatus{$type}{'machines'} = '';
15287: if (defined($env{'form.'.$type.'_namedusers'})) {
15288: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
15289: my @okusers;
15290: foreach my $user (@users) {
15291: my ($uname,$udom) = split(/:/,$user);
15292: if (($udom =~ /^$match_domain$/) &&
15293: (&Apache::lonnet::domain($udom)) &&
15294: ($uname =~ /^$match_username$/)) {
15295: if (!grep(/^\Q$user\E/,@okusers)) {
15296: push(@okusers,$user);
15297: }
15298: }
15299: }
15300: if (@okusers > 0) {
15301: @okusers = sort(@okusers);
15302: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15303: }
15304: }
15305: if (defined($env{'form.'.$type.'_machines'})) {
15306: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15307: my @okmachines;
15308: foreach my $ip (@machines) {
15309: my @parts = split(/\./,$ip);
15310: next if (@parts < 4);
15311: my $badip = 0;
15312: for (my $i=0; $i<4; $i++) {
15313: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15314: $badip = 1;
15315: last;
15316: }
15317: }
15318: if (!$badip) {
15319: push(@okmachines,$ip);
15320: }
15321: }
15322: @okmachines = sort(@okmachines);
15323: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15324: }
15325: }
15326: my %serverstatushash = (
15327: serverstatuses => \%newserverstatus,
15328: );
15329: foreach my $type (@pages) {
1.83 raeburn 15330: foreach my $setting ('namedusers','machines') {
1.84 raeburn 15331: my (@current,@new);
1.83 raeburn 15332: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 15333: if ($currserverstatus{$type}{$setting} ne '') {
15334: @current = split(/,/,$currserverstatus{$type}{$setting});
15335: }
15336: }
15337: if ($newserverstatus{$type}{$setting} ne '') {
15338: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 15339: }
15340: if (@current > 0) {
15341: if (@new > 0) {
15342: foreach my $item (@current) {
15343: if (!grep(/^\Q$item\E$/,@new)) {
15344: $changes{$type}{$setting} = 1;
1.82 raeburn 15345: last;
15346: }
15347: }
1.84 raeburn 15348: foreach my $item (@new) {
15349: if (!grep(/^\Q$item\E$/,@current)) {
15350: $changes{$type}{$setting} = 1;
15351: last;
1.82 raeburn 15352: }
15353: }
15354: } else {
1.83 raeburn 15355: $changes{$type}{$setting} = 1;
1.69 raeburn 15356: }
1.83 raeburn 15357: } elsif (@new > 0) {
15358: $changes{$type}{$setting} = 1;
1.69 raeburn 15359: }
15360: }
15361: }
15362: if (keys(%changes) > 0) {
1.81 raeburn 15363: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15364: my $putresult = &Apache::lonnet::put_dom('configuration',
15365: \%serverstatushash,$dom);
15366: if ($putresult eq 'ok') {
15367: $resulttext .= &mt('Changes made:').'<ul>';
15368: foreach my $type (@pages) {
1.84 raeburn 15369: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15370: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15371: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15372: if ($newserverstatus{$type}{'namedusers'} eq '') {
15373: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15374: } else {
15375: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15376: }
1.84 raeburn 15377: }
15378: if ($changes{$type}{'machines'}) {
1.69 raeburn 15379: if ($newserverstatus{$type}{'machines'} eq '') {
15380: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15381: } else {
15382: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15383: }
15384:
15385: }
15386: $resulttext .= '</ul></li>';
15387: }
15388: }
15389: $resulttext .= '</ul>';
15390: } else {
15391: $resulttext = '<span class="LC_error">'.
15392: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15393:
15394: }
15395: } else {
15396: $resulttext = &mt('No changes made to access to server status pages');
15397: }
15398: return $resulttext;
15399: }
15400:
1.118 jms 15401: sub modify_helpsettings {
1.160.6.77 raeburn 15402: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 15403: my ($resulttext,$errors,%changes,%helphash);
15404: my %defaultchecked = ('submitbugs' => 'on');
15405: my @offon = ('off','on');
1.118 jms 15406: my @toggles = ('submitbugs');
1.160.6.77 raeburn 15407: my %current = ('submitbugs' => '',
15408: 'adhoc' => {},
15409: );
1.118 jms 15410: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 15411: %current = %{$domconfig{'helpsettings'}};
15412: }
1.160.6.77 raeburn 15413: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 15414: foreach my $item (@toggles) {
15415: if ($defaultchecked{$item} eq 'on') {
15416: if ($current{$item} eq '') {
15417: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 15418: $changes{$item} = 1;
15419: }
1.160.6.73 raeburn 15420: } elsif ($current{$item} ne $env{'form.'.$item}) {
15421: $changes{$item} = 1;
15422: }
15423: } elsif ($defaultchecked{$item} eq 'off') {
15424: if ($current{$item} eq '') {
15425: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 15426: $changes{$item} = 1;
15427: }
1.160.6.73 raeburn 15428: } elsif ($current{$item} ne $env{'form.'.$item}) {
15429: $changes{$item} = 1;
15430: }
15431: }
15432: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15433: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15434: }
15435: }
1.160.6.77 raeburn 15436: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 15437: my $confname = $dom.'-domainconfig';
15438: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 15439: my (@allpos,%newsettings,%changedprivs,$newrole);
15440: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 15441: my @accesstypes = ('all','dh','da','none','status','inc','exc');
15442: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 15443: my %lt = &Apache::lonlocal::texthash(
15444: s => 'system',
15445: d => 'domain',
15446: order => 'Display order',
15447: access => 'Role usage',
1.160.6.79 raeburn 15448: all => 'All with domain helpdesk or helpdesk assistant role',
15449: dh => 'All with domain helpdesk role',
15450: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 15451: none => 'None',
15452: status => 'Determined based on institutional status',
15453: inc => 'Include all, but exclude specific personnel',
15454: exc => 'Exclude all, but include specific personnel',
15455: );
15456: for (my $num=0; $num<=$maxnum; $num++) {
15457: my ($prefix,$identifier,$rolename,%curr);
15458: if ($num == $maxnum) {
15459: next unless ($env{'form.newcusthelp'} == $maxnum);
15460: $identifier = 'custhelp'.$num;
15461: $prefix = 'helproles_'.$num;
15462: $rolename = $env{'form.custhelpname'.$num};
15463: $rolename=~s/[^A-Za-z0-9]//gs;
15464: next if ($rolename eq '');
15465: next if (exists($existing{'rolesdef_'.$rolename}));
15466: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15467: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15468: $newprivs{'c'},$confname,$dom);
15469: if ($result ne 'ok') {
15470: $errors .= '<li><span class="LC_error">'.
15471: &mt('An error occurred storing the new custom role: [_1]',
15472: $result).'</span></li>';
15473: next;
15474: } else {
15475: $changedprivs{$rolename} = \%newprivs;
15476: $newrole = $rolename;
15477: }
15478: } else {
15479: $prefix = 'helproles_'.$num;
15480: $rolename = $env{'form.'.$prefix};
15481: next if ($rolename eq '');
15482: next unless (exists($existing{'rolesdef_'.$rolename}));
15483: $identifier = 'custhelp'.$num;
15484: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15485: my %currprivs;
15486: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
15487: split(/\_/,$existing{'rolesdef_'.$rolename});
15488: foreach my $level ('c','d','s') {
15489: if ($newprivs{$level} ne $currprivs{$level}) {
15490: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15491: $newprivs{'c'},$confname,$dom);
15492: if ($result ne 'ok') {
15493: $errors .= '<li><span class="LC_error">'.
15494: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15495: $rolename,$result).'</span></li>';
15496: } else {
15497: $changedprivs{$rolename} = \%newprivs;
15498: }
15499: last;
15500: }
15501: }
15502: if (ref($current{'adhoc'}) eq 'HASH') {
15503: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15504: %curr = %{$current{'adhoc'}{$rolename}};
15505: }
15506: }
15507: }
15508: my $newpos = $env{'form.'.$prefix.'_pos'};
15509: $newpos =~ s/\D+//g;
15510: $allpos[$newpos] = $rolename;
15511: my $newdesc = $env{'form.'.$prefix.'_desc'};
15512: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15513: if ($curr{'desc'}) {
15514: if ($curr{'desc'} ne $newdesc) {
15515: $changes{'customrole'}{$rolename}{'desc'} = 1;
15516: $newsettings{$rolename}{'desc'} = $newdesc;
15517: }
15518: } elsif ($newdesc ne '') {
15519: $changes{'customrole'}{$rolename}{'desc'} = 1;
15520: $newsettings{$rolename}{'desc'} = $newdesc;
15521: }
15522: my $access = $env{'form.'.$prefix.'_access'};
15523: if (grep(/^\Q$access\E$/,@accesstypes)) {
15524: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15525: if ($access eq 'status') {
15526: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15527: if (scalar(@statuses) == 0) {
15528: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
15529: } else {
15530: my (@shownstatus,$numtypes);
15531: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15532: if (ref($types) eq 'ARRAY') {
15533: $numtypes = scalar(@{$types});
15534: foreach my $type (sort(@statuses)) {
15535: if ($type eq 'default') {
15536: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15537: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15538: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15539: push(@shownstatus,$usertypes->{$type});
15540: }
1.160.6.73 raeburn 15541: }
15542: }
1.160.6.77 raeburn 15543: if (grep(/^default$/,@statuses)) {
15544: push(@shownstatus,$othertitle);
15545: }
15546: if (scalar(@shownstatus) == 1+$numtypes) {
15547: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15548: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15549: } else {
15550: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15551: if (ref($curr{'status'}) eq 'ARRAY') {
15552: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15553: if (@diffs) {
15554: $changes{'customrole'}{$rolename}{$access} = 1;
15555: }
15556: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15557: $changes{'customrole'}{$rolename}{$access} = 1;
15558: }
15559: }
15560: }
15561: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15562: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15563: my @newspecstaff;
15564: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15565: foreach my $person (sort(@personnel)) {
15566: if ($domhelpdesk{$person}) {
15567: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15568: }
15569: }
15570: if (ref($curr{$access}) eq 'ARRAY') {
15571: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15572: if (@diffs) {
15573: $changes{'customrole'}{$rolename}{$access} = 1;
15574: }
15575: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15576: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 15577: }
1.160.6.77 raeburn 15578: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15579: my ($uname,$udom) = split(/:/,$person);
15580: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15581: }
15582: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 15583: }
1.160.6.77 raeburn 15584: } else {
15585: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15586: }
15587: unless ($curr{'access'} eq $access) {
15588: $changes{'customrole'}{$rolename}{'access'} = 1;
15589: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 15590: }
15591: }
1.160.6.77 raeburn 15592: if (@allpos > 0) {
15593: my $idx = 0;
15594: foreach my $rolename (@allpos) {
15595: if ($rolename ne '') {
15596: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15597: if (ref($current{'adhoc'}) eq 'HASH') {
15598: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15599: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15600: $changes{'customrole'}{$rolename}{'order'} = 1;
15601: $newsettings{$rolename}{'order'} = $idx+1;
15602: }
15603: }
1.160.6.73 raeburn 15604: }
1.160.6.77 raeburn 15605: $idx ++;
1.122 jms 15606: }
15607: }
1.118 jms 15608: }
1.123 jms 15609: my $putresult;
15610: if (keys(%changes) > 0) {
1.160.6.5 raeburn 15611: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
15612: if ($putresult eq 'ok') {
1.160.6.77 raeburn 15613: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15614: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15615: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15616: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15617: }
15618: }
15619: my $cachetime = 24*60*60;
15620: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15621: if (ref($lastactref) eq 'HASH') {
15622: $lastactref->{'domdefaults'} = 1;
15623: }
15624: } else {
15625: $errors .= '<li><span class="LC_error">'.
15626: &mt('An error occurred storing the settings: [_1]',
15627: $putresult).'</span></li>';
15628: }
15629: }
15630: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15631: $resulttext = &mt('Changes made:').'<ul>';
15632: my (%shownprivs,@levelorder);
15633: @levelorder = ('c','d','s');
15634: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 15635: foreach my $item (sort(keys(%changes))) {
15636: if ($item eq 'submitbugs') {
15637: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15638: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15639: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 15640: } elsif ($item eq 'customrole') {
15641: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 15642: my @keyorder = ('order','desc','access','status','exc','inc');
15643: my %keytext = &Apache::lonlocal::texthash(
15644: order => 'Order',
15645: desc => 'Role description',
15646: access => 'Role usage',
1.160.6.83 raeburn 15647: status => 'Allowed institutional types',
1.160.6.77 raeburn 15648: exc => 'Allowed personnel',
15649: inc => 'Disallowed personnel',
15650: );
1.160.6.73 raeburn 15651: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 15652: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15653: if ($role eq $newrole) {
15654: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15655: $role).'<ul>';
15656: } else {
15657: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15658: $role).'<ul>';
15659: }
15660: foreach my $key (@keyorder) {
15661: if ($changes{'customrole'}{$role}{$key}) {
15662: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15663: $keytext{$key},$newsettings{$role}{$key}).
15664: '</li>';
15665: }
15666: }
15667: if (ref($changedprivs{$role}) eq 'HASH') {
15668: $shownprivs{$role} = 1;
15669: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15670: foreach my $level (@levelorder) {
15671: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15672: next if ($item eq '');
15673: my ($priv) = split(/\&/,$item,2);
15674: if (&Apache::lonnet::plaintext($priv)) {
15675: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15676: unless ($level eq 'c') {
15677: $resulttext .= ' ('.$lt{$level}.')';
15678: }
15679: $resulttext .= '</li>';
15680: }
15681: }
15682: }
15683: $resulttext .= '</ul>';
15684: }
15685: $resulttext .= '</ul></li>';
15686: }
1.160.6.73 raeburn 15687: }
15688: }
1.160.6.5 raeburn 15689: }
15690: }
15691: }
1.160.6.77 raeburn 15692: if (keys(%changedprivs)) {
15693: foreach my $role (sort(keys(%changedprivs))) {
15694: unless ($shownprivs{$role}) {
15695: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15696: $role).'<ul>'.
15697: '<li>'.&mt('Privileges set to :').'<ul>';
15698: foreach my $level (@levelorder) {
15699: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15700: next if ($item eq '');
15701: my ($priv) = split(/\&/,$item,2);
15702: if (&Apache::lonnet::plaintext($priv)) {
15703: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15704: unless ($level eq 'c') {
15705: $resulttext .= ' ('.$lt{$level}.')';
15706: }
15707: $resulttext .= '</li>';
15708: }
15709: }
15710: }
15711: $resulttext .= '</ul></li></ul></li>';
15712: }
15713: }
15714: }
15715: $resulttext .= '</ul>';
15716: } else {
15717: $resulttext = &mt('No changes made to help settings');
1.118 jms 15718: }
15719: if ($errors) {
1.160.6.5 raeburn 15720: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 15721: $errors.'</ul>';
1.118 jms 15722: }
15723: return $resulttext;
15724: }
15725:
1.121 raeburn 15726: sub modify_coursedefaults {
1.160.6.27 raeburn 15727: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15728: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 15729: my %defaultchecked = (
15730: 'uselcmath' => 'on',
1.160.6.115 raeburn 15731: 'usejsme' => 'on',
15732: 'inline_chem' => 'on',
1.160.6.57 raeburn 15733: );
1.160.6.115 raeburn 15734: my @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.21 raeburn 15735: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 15736: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
15737: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 15738: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 15739: my %staticdefaults = (
15740: anonsurvey_threshold => 10,
15741: uploadquota => 500,
1.160.6.57 raeburn 15742: postsubmit => 60,
1.160.6.70 raeburn 15743: mysqltables => 172800,
1.160.6.21 raeburn 15744: );
1.160.6.90 raeburn 15745: my %texoptions = (
15746: MathJax => 'MathJax',
15747: mimetex => &mt('Convert to Images'),
15748: tth => &mt('TeX to HTML'),
15749: );
1.121 raeburn 15750: $defaultshash{'coursedefaults'} = {};
15751:
15752: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15753: if ($domconfig{'coursedefaults'} eq '') {
15754: $domconfig{'coursedefaults'} = {};
15755: }
15756: }
15757:
15758: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15759: foreach my $item (@toggles) {
15760: if ($defaultchecked{$item} eq 'on') {
15761: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15762: ($env{'form.'.$item} eq '0')) {
15763: $changes{$item} = 1;
1.160.6.16 raeburn 15764: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15765: $changes{$item} = 1;
15766: }
15767: } elsif ($defaultchecked{$item} eq 'off') {
15768: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15769: ($env{'form.'.$item} eq '1')) {
15770: $changes{$item} = 1;
15771: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15772: $changes{$item} = 1;
15773: }
15774: }
15775: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15776: }
1.160.6.21 raeburn 15777: foreach my $item (@numbers) {
15778: my ($currdef,$newdef);
1.160.6.26 raeburn 15779: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 15780: if ($item eq 'anonsurvey_threshold') {
15781: $currdef = $domconfig{'coursedefaults'}{$item};
15782: $newdef =~ s/\D//g;
15783: if ($newdef eq '' || $newdef < 1) {
15784: $newdef = 1;
15785: }
15786: $defaultshash{'coursedefaults'}{$item} = $newdef;
15787: } else {
1.160.6.70 raeburn 15788: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15789: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15790: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 15791: }
15792: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 15793: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 15794: }
15795: if ($currdef ne $newdef) {
15796: if ($item eq 'anonsurvey_threshold') {
15797: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15798: $changes{$item} = 1;
15799: }
1.160.6.70 raeburn 15800: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
15801: my $setting = $1;
15802: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15803: $changes{$setting} = 1;
1.160.6.21 raeburn 15804: }
15805: }
1.139 raeburn 15806: }
15807: }
1.160.6.90 raeburn 15808: my $texengine;
15809: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15810: $texengine = $env{'form.texengine'};
15811: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
15812: if ($currdef eq '') {
15813: unless ($texengine eq $Apache::lonnet::deftex) {
15814: $changes{'texengine'} = 1;
15815: }
15816: } elsif ($currdef ne $texengine) {
15817: $changes{'texengine'} = 1;
15818: }
15819: }
15820: if ($texengine ne '') {
15821: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15822: }
1.160.6.64 raeburn 15823: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15824: my @currclonecode;
15825: if (ref($currclone) eq 'HASH') {
15826: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15827: @currclonecode = @{$currclone->{'instcode'}};
15828: }
15829: }
15830: my $newclone;
15831: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
15832: $newclone = $env{'form.canclone'};
15833: }
15834: if ($newclone eq 'instcode') {
15835: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15836: my (%codedefaults,@code_order,@clonecode);
15837: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15838: \@code_order);
15839: foreach my $item (@code_order) {
15840: if (grep(/^\Q$item\E$/,@newcodes)) {
15841: push(@clonecode,$item);
15842: }
15843: }
15844: if (@clonecode) {
15845: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15846: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15847: if (@diffs) {
15848: $changes{'canclone'} = 1;
15849: }
15850: } else {
15851: $newclone eq '';
15852: }
15853: } elsif ($newclone ne '') {
15854: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15855: }
15856: if ($newclone ne $currclone) {
15857: $changes{'canclone'} = 1;
15858: }
1.160.6.57 raeburn 15859: my %credits;
15860: foreach my $type (@types) {
15861: unless ($type eq 'community') {
15862: $credits{$type} = $env{'form.'.$type.'_credits'};
15863: $credits{$type} =~ s/[^\d.]+//g;
15864: }
15865: }
15866: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15867: ($env{'form.coursecredits'} eq '1')) {
15868: $changes{'coursecredits'} = 1;
15869: foreach my $type (keys(%credits)) {
15870: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15871: }
15872: } else {
15873: if ($env{'form.coursecredits'} eq '1') {
15874: foreach my $type (@types) {
15875: unless ($type eq 'community') {
15876: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
15877: $changes{'coursecredits'} = 1;
15878: }
15879: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15880: }
15881: }
15882: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15883: foreach my $type (@types) {
15884: unless ($type eq 'community') {
15885: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15886: $changes{'coursecredits'} = 1;
15887: last;
15888: }
15889: }
15890: }
15891: }
15892: }
15893: if ($env{'form.postsubmit'} eq '1') {
15894: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15895: my %currtimeout;
15896: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15897: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15898: $changes{'postsubmit'} = 1;
15899: }
15900: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15901: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15902: }
15903: } else {
15904: $changes{'postsubmit'} = 1;
15905: }
15906: foreach my $type (@types) {
15907: my $timeout = $env{'form.'.$type.'_timeout'};
15908: $timeout =~ s/\D//g;
15909: if ($timeout == $staticdefaults{'postsubmit'}) {
15910: $timeout = '';
15911: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15912: $timeout = '0';
15913: }
15914: unless ($timeout eq '') {
15915: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15916: }
15917: if (exists($currtimeout{$type})) {
15918: if ($timeout ne $currtimeout{$type}) {
15919: $changes{'postsubmit'} = 1;
15920: }
15921: } elsif ($timeout ne '') {
15922: $changes{'postsubmit'} = 1;
15923: }
15924: }
15925: } else {
15926: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15927: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15928: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15929: $changes{'postsubmit'} = 1;
15930: }
15931: } else {
15932: $changes{'postsubmit'} = 1;
15933: }
1.160.6.16 raeburn 15934: }
1.121 raeburn 15935: }
15936: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15937: $dom);
15938: if ($putresult eq 'ok') {
15939: if (keys(%changes) > 0) {
1.160.6.27 raeburn 15940: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 15941: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 15942: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 15943: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
15944: ($changes{'inline_chem'})) {
15945: foreach my $item ('uselcmath','usejsme','inline_chem','texengine') {
1.160.6.57 raeburn 15946: if ($changes{$item}) {
15947: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15948: }
1.160.6.16 raeburn 15949: }
15950: if ($changes{'coursecredits'}) {
15951: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 15952: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15953: $domdefaults{$type.'credits'} =
15954: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15955: }
15956: }
15957: }
15958: if ($changes{'postsubmit'}) {
15959: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15960: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15961: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15962: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15963: $domdefaults{$type.'postsubtimeout'} =
15964: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15965: }
15966: }
1.160.6.16 raeburn 15967: }
15968: }
1.160.6.21 raeburn 15969: if ($changes{'uploadquota'}) {
15970: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15971: foreach my $type (@types) {
15972: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15973: }
15974: }
15975: }
1.160.6.64 raeburn 15976: if ($changes{'canclone'}) {
15977: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15978: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15979: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15980: if (@clonecodes) {
15981: $domdefaults{'canclone'} = join('+',@clonecodes);
15982: }
15983: }
15984: } else {
15985: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15986: }
15987: }
1.121 raeburn 15988: my $cachetime = 24*60*60;
15989: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15990: if (ref($lastactref) eq 'HASH') {
15991: $lastactref->{'domdefaults'} = 1;
15992: }
1.121 raeburn 15993: }
15994: $resulttext = &mt('Changes made:').'<ul>';
15995: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 15996: if ($item eq 'uselcmath') {
1.121 raeburn 15997: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 15998: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 15999: } else {
1.160.6.57 raeburn 16000: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
16001: }
16002: } elsif ($item eq 'usejsme') {
16003: if ($env{'form.'.$item} eq '1') {
16004: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
16005: } else {
16006: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 16007: }
1.160.6.115 raeburn 16008: } elsif ($item eq 'inline_chem') {
16009: if ($env{'form.'.$item} eq '1') {
16010: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
16011: } else {
16012: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
16013: }
1.160.6.90 raeburn 16014: } elsif ($item eq 'texengine') {
16015: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
16016: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
16017: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
16018: }
1.139 raeburn 16019: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 16020: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 16021: } elsif ($item eq 'uploadquota') {
16022: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
16023: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
16024: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
16025: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 16026: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
16027:
1.160.6.21 raeburn 16028: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
16029: '</ul>'.
16030: '</li>';
16031: } else {
16032: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
16033: }
1.160.6.70 raeburn 16034: } elsif ($item eq 'mysqltables') {
16035: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
16036: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
16037: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
16038: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
16039: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
16040: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
16041: '</ul>'.
16042: '</li>';
16043: } else {
16044: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
16045: }
1.160.6.57 raeburn 16046: } elsif ($item eq 'postsubmit') {
16047: if ($domdefaults{'postsubmit'} eq 'off') {
16048: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
16049: } else {
16050: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
16051: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16052: $resulttext .= &mt('durations:').'<ul>';
16053: foreach my $type (@types) {
16054: $resulttext .= '<li>';
16055: my $timeout;
16056: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16057: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
16058: }
16059: my $display;
16060: if ($timeout eq '0') {
16061: $display = &mt('unlimited');
16062: } elsif ($timeout eq '') {
16063: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
16064: } else {
16065: $display = &mt('[quant,_1,second]',$timeout);
16066: }
16067: if ($type eq 'community') {
16068: $resulttext .= &mt('Communities');
16069: } elsif ($type eq 'official') {
16070: $resulttext .= &mt('Official courses');
16071: } elsif ($type eq 'unofficial') {
16072: $resulttext .= &mt('Unofficial courses');
16073: } elsif ($type eq 'textbook') {
16074: $resulttext .= &mt('Textbook courses');
16075: }
16076: $resulttext .= ' -- '.$display.'</li>';
16077: }
16078: $resulttext .= '</ul>';
16079: }
16080: $resulttext .= '</li>';
16081: }
1.160.6.16 raeburn 16082: } elsif ($item eq 'coursecredits') {
16083: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16084: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 16085: ($domdefaults{'unofficialcredits'} eq '') &&
16086: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 16087: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16088: } else {
16089: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
16090: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
16091: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 16092: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 16093: '</ul>'.
16094: '</li>';
16095: }
16096: } else {
16097: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16098: }
1.160.6.64 raeburn 16099: } elsif ($item eq 'canclone') {
16100: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
16101: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
16102: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
16103: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
16104: }
16105: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
16106: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
16107: } else {
16108: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
16109: }
1.140 raeburn 16110: }
1.121 raeburn 16111: }
16112: $resulttext .= '</ul>';
16113: } else {
16114: $resulttext = &mt('No changes made to course defaults');
16115: }
16116: } else {
16117: $resulttext = '<span class="LC_error">'.
16118: &mt('An error occurred: [_1]',$putresult).'</span>';
16119: }
16120: return $resulttext;
16121: }
16122:
1.160.6.37 raeburn 16123: sub modify_selfenrollment {
16124: my ($dom,$lastactref,%domconfig) = @_;
16125: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
16126: my @types = ('official','unofficial','community','textbook');
16127: my %titles = &tool_titles();
16128: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
16129: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
16130: $ordered{'default'} = ['types','registered','approval','limit'];
16131:
16132: my (%roles,%shown,%toplevel);
16133: $roles{'0'} = &Apache::lonnet::plaintext('dc');
16134:
16135: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
16136: if ($domconfig{'selfenrollment'} eq '') {
16137: $domconfig{'selfenrollment'} = {};
16138: }
16139: }
16140: %toplevel = (
16141: admin => 'Configuration Rights',
16142: default => 'Default settings',
16143: validation => 'Validation of self-enrollment requests',
16144: );
16145: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
16146:
16147: if (ref($ordered{'admin'}) eq 'ARRAY') {
16148: foreach my $item (@{$ordered{'admin'}}) {
16149: foreach my $type (@types) {
16150: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
16151: $selfenrollhash{'admin'}{$type}{$item} = 1;
16152: } else {
16153: $selfenrollhash{'admin'}{$type}{$item} = 0;
16154: }
16155: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
16156: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
16157: if ($selfenrollhash{'admin'}{$type}{$item} ne
16158: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
16159: push(@{$changes{'admin'}{$type}},$item);
16160: }
16161: } else {
16162: if (!$selfenrollhash{'admin'}{$type}{$item}) {
16163: push(@{$changes{'admin'}{$type}},$item);
16164: }
16165: }
16166: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
16167: push(@{$changes{'admin'}{$type}},$item);
16168: }
16169: }
16170: }
16171: }
16172:
16173: foreach my $item (@{$ordered{'default'}}) {
16174: foreach my $type (@types) {
16175: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
16176: if ($item eq 'types') {
16177: unless (($value eq 'all') || ($value eq 'dom')) {
16178: $value = '';
16179: }
16180: } elsif ($item eq 'registered') {
16181: unless ($value eq '1') {
16182: $value = 0;
16183: }
16184: } elsif ($item eq 'approval') {
16185: unless ($value =~ /^[012]$/) {
16186: $value = 0;
16187: }
16188: } else {
16189: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16190: $value = 'none';
16191: }
16192: }
16193: $selfenrollhash{'default'}{$type}{$item} = $value;
16194: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
16195: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16196: if ($selfenrollhash{'default'}{$type}{$item} ne
16197: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
16198: push(@{$changes{'default'}{$type}},$item);
16199: }
16200: } else {
16201: push(@{$changes{'default'}{$type}},$item);
16202: }
16203: } else {
16204: push(@{$changes{'default'}{$type}},$item);
16205: }
16206: if ($item eq 'limit') {
16207: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16208: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
16209: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
16210: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
16211: }
16212: } else {
16213: $selfenrollhash{'default'}{$type}{'cap'} = '';
16214: }
16215: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16216: if ($selfenrollhash{'default'}{$type}{'cap'} ne
16217: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
16218: push(@{$changes{'default'}{$type}},'cap');
16219: }
16220: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
16221: push(@{$changes{'default'}{$type}},'cap');
16222: }
16223: }
16224: }
16225: }
16226:
16227: foreach my $item (@{$itemsref}) {
16228: if ($item eq 'fields') {
16229: my @changed;
16230: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
16231: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
16232: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
16233: }
16234: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16235: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
16236: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
16237: $domconfig{'selfenrollment'}{'validation'}{$item});
16238: } else {
16239: @changed = @{$selfenrollhash{'validation'}{$item}};
16240: }
16241: } else {
16242: @changed = @{$selfenrollhash{'validation'}{$item}};
16243: }
16244: if (@changed) {
16245: if ($selfenrollhash{'validation'}{$item}) {
16246: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
16247: } else {
16248: $changes{'validation'}{$item} = &mt('None');
16249: }
16250: }
16251: } else {
16252: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
16253: if ($item eq 'markup') {
16254: if ($env{'form.selfenroll_validation_'.$item}) {
16255: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
16256: }
16257: }
16258: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16259: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
16260: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
16261: }
16262: }
16263: }
16264: }
16265:
16266: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
16267: $dom);
16268: if ($putresult eq 'ok') {
16269: if (keys(%changes) > 0) {
16270: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16271: $resulttext = &mt('Changes made:').'<ul>';
16272: foreach my $key ('admin','default','validation') {
16273: if (ref($changes{$key}) eq 'HASH') {
16274: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
16275: if ($key eq 'validation') {
16276: foreach my $item (@{$itemsref}) {
16277: if (exists($changes{$key}{$item})) {
16278: if ($item eq 'markup') {
16279: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16280: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
16281: } else {
16282: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16283: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
16284: }
16285: }
16286: }
16287: } else {
16288: foreach my $type (@types) {
16289: if ($type eq 'community') {
16290: $roles{'1'} = &mt('Community personnel');
16291: } else {
16292: $roles{'1'} = &mt('Course personnel');
16293: }
16294: if (ref($changes{$key}{$type}) eq 'ARRAY') {
16295: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16296: if ($key eq 'admin') {
16297: my @mgrdc = ();
16298: if (ref($ordered{$key}) eq 'ARRAY') {
16299: foreach my $item (@{$ordered{'admin'}}) {
16300: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16301: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16302: push(@mgrdc,$item);
16303: }
16304: }
16305: }
16306: if (@mgrdc) {
16307: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16308: } else {
16309: delete($domdefaults{$type.'selfenrolladmdc'});
16310: }
16311: }
16312: } else {
16313: if (ref($ordered{$key}) eq 'ARRAY') {
16314: foreach my $item (@{$ordered{$key}}) {
16315: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16316: $domdefaults{$type.'selfenroll'.$item} =
16317: $selfenrollhash{$key}{$type}{$item};
16318: }
16319: }
16320: }
16321: }
16322: }
16323: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16324: foreach my $item (@{$ordered{$key}}) {
16325: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16326: $resulttext .= '<li>';
16327: if ($key eq 'admin') {
16328: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16329: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16330: } else {
16331: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16332: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16333: }
16334: $resulttext .= '</li>';
16335: }
16336: }
16337: $resulttext .= '</ul></li>';
16338: }
16339: }
16340: $resulttext .= '</ul></li>';
16341: }
16342: }
1.160.6.93 raeburn 16343: }
16344: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16345: my $cachetime = 24*60*60;
16346: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16347: if (ref($lastactref) eq 'HASH') {
16348: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 16349: }
16350: }
16351: $resulttext .= '</ul>';
16352: } else {
16353: $resulttext = &mt('No changes made to self-enrollment settings');
16354: }
16355: } else {
16356: $resulttext = '<span class="LC_error">'.
16357: &mt('An error occurred: [_1]',$putresult).'</span>';
16358: }
16359: return $resulttext;
16360: }
16361:
1.160.6.113 raeburn 16362: sub modify_wafproxy {
16363: my ($dom,$action,$lastactref,%domconfig) = @_;
16364: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16365: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
16366: %wafproxy,%changes,%expirecache,%expiresaml);
16367: foreach my $server (sort(keys(%servers))) {
16368: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16369: if ($serverhome eq $server) {
16370: my $serverdom = &Apache::lonnet::host_domain($server);
16371: if ($serverdom eq $dom) {
16372: $canset{$server} = 1;
16373: }
16374: }
16375: }
16376: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
16377: %{$values{$dom}} = ();
16378: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
16379: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
16380: }
16381: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
16382: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
16383: }
16384: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16385: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
16386: }
16387: }
16388: my $output;
16389: if (keys(%canset)) {
16390: %{$wafproxy{'alias'}} = ();
16391: %{$wafproxy{'saml'}} = ();
16392: foreach my $key (sort(keys(%canset))) {
16393: if ($env{'form.wafproxy_'.$dom}) {
16394: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
16395: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
16396: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
16397: $changes{'alias'} = 1;
16398: }
16399: if ($env{'form.wafproxy_alias_saml_'.$key}) {
16400: $wafproxy{'saml'}{$key} = 1;
16401: }
16402: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
16403: $changes{'saml'} = 1;
16404: }
16405: } else {
16406: $wafproxy{'alias'}{$key} = '';
16407: $wafproxy{'saml'}{$key} = '';
16408: if ($curralias{$key}) {
16409: $changes{'alias'} = 1;
16410: }
16411: if ($currsaml{$key}) {
16412: $changes{'saml'} = 1;
16413: }
16414: }
16415: if ($wafproxy{'alias'}{$key} eq '') {
16416: if ($curralias{$key}) {
16417: $expirecache{$key} = 1;
16418: }
16419: delete($wafproxy{'alias'}{$key});
16420: }
16421: if ($wafproxy{'saml'}{$key} eq '') {
16422: if ($currsaml{$key}) {
16423: $expiresaml{$key} = 1;
16424: }
16425: delete($wafproxy{'saml'}{$key});
16426: }
16427: }
16428: unless (keys(%{$wafproxy{'alias'}})) {
16429: delete($wafproxy{'alias'});
16430: }
16431: unless (keys(%{$wafproxy{'saml'}})) {
16432: delete($wafproxy{'saml'});
16433: }
16434: # Localization for values in %warn occurs in &mt() calls separately.
16435: my %warn = (
16436: trusted => 'trusted IP range(s)',
16437: vpnint => 'internal IP range(s) for VPN sessions(s)',
16438: vpnext => 'IP range(s) for backend WAF connections',
16439: );
16440: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16441: my $possible = $env{'form.wafproxy_'.$item};
16442: $possible =~ s/^\s+|\s+$//g;
16443: if ($possible ne '') {
16444: if ($item eq 'remoteip') {
16445: if ($possible =~ /^[mhn]$/) {
16446: $wafproxy{$item} = $possible;
16447: }
16448: } elsif ($item eq 'ipheader') {
16449: if ($wafproxy{'remoteip'} eq 'h') {
16450: $wafproxy{$item} = $possible;
16451: }
16452: } elsif ($item eq 'sslopt') {
16453: if ($possible =~ /^0|1$/) {
16454: $wafproxy{$item} = $possible;
16455: }
16456: } else {
16457: my (@ok,$count);
16458: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
16459: unless ($env{'form.wafproxy_vpnaccess'}) {
16460: $possible = '';
16461: }
16462: } elsif ($item eq 'trusted') {
16463: unless ($wafproxy{'remoteip'} eq 'h') {
16464: $possible = '';
16465: }
16466: }
16467: unless ($possible eq '') {
16468: $possible =~ s/[\r\n]+/\s/g;
16469: $possible =~ s/\s*-\s*/-/g;
16470: $possible =~ s/\s+/,/g;
16471: $possible =~ s/,+/,/g;
16472: }
16473: $count = 0;
16474: if ($possible ne '') {
16475: foreach my $poss (split(/\,/,$possible)) {
16476: $count ++;
16477: $poss = &validate_ip_pattern($poss);
16478: if ($poss ne '') {
16479: push(@ok,$poss);
16480: }
16481: }
16482: my $diff = $count - scalar(@ok);
16483: if ($diff) {
16484: push(@warnings,'<li>'.
16485: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
16486: $diff,$warn{$item}).
16487: '</li>');
16488: }
16489: if (@ok) {
16490: my @cidr_list;
16491: foreach my $item (@ok) {
16492: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
16493: }
16494: $wafproxy{$item} = join(',',@cidr_list);
16495: }
16496: }
16497: }
16498: if ($wafproxy{$item} ne $currvalue{$item}) {
16499: $changes{$item} = 1;
16500: }
16501: } elsif ($currvalue{$item}) {
16502: $changes{$item} = 1;
16503: }
16504: }
16505: } else {
16506: if (keys(%curralias)) {
16507: $changes{'alias'} = 1;
16508: }
16509: if (keys(%currsaml)) {
16510: $changes{'saml'} = 1;
16511: }
16512: if (keys(%currvalue)) {
16513: foreach my $key (keys(%currvalue)) {
16514: $changes{$key} = 1;
16515: }
16516: }
16517: }
16518: if (keys(%changes)) {
16519: my %defaultshash = (
16520: wafproxy => \%wafproxy,
16521: );
16522: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16523: $dom);
16524: if ($putresult eq 'ok') {
16525: my $cachetime = 24*60*60;
16526: my (%domdefaults,$updatedomdefs);
16527: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
16528: if ($changes{$item}) {
16529: unless ($updatedomdefs) {
16530: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16531: $updatedomdefs = 1;
16532: }
16533: if ($wafproxy{$item}) {
16534: $domdefaults{'waf_'.$item} = $wafproxy{$item};
16535: } elsif (exists($domdefaults{'waf_'.$item})) {
16536: delete($domdefaults{'waf_'.$item});
16537: }
16538: }
16539: }
16540: if ($updatedomdefs) {
16541: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16542: if (ref($lastactref) eq 'HASH') {
16543: $lastactref->{'domdefaults'} = 1;
16544: }
16545: }
16546: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
16547: my %updates = %expirecache;
16548: foreach my $key (keys(%expirecache)) {
16549: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
16550: }
16551: if (ref($wafproxy{'alias'}) eq 'HASH') {
16552: my $cachetime = 24*60*60;
16553: foreach my $key (keys(%{$wafproxy{'alias'}})) {
16554: $updates{$key} = 1;
16555: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
16556: $cachetime);
16557: }
16558: }
16559: if (ref($lastactref) eq 'HASH') {
16560: $lastactref->{'proxyalias'} = \%updates;
16561: }
16562: }
16563: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
16564: my %samlupdates = %expiresaml;
16565: foreach my $key (keys(%expiresaml)) {
16566: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
16567: }
16568: if (ref($wafproxy{'saml'}) eq 'HASH') {
16569: my $cachetime = 24*60*60;
16570: foreach my $key (keys(%{$wafproxy{'saml'}})) {
16571: $samlupdates{$key} = 1;
16572: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
16573: $cachetime);
16574: }
16575: }
16576: if (ref($lastactref) eq 'HASH') {
16577: $lastactref->{'proxysaml'} = \%samlupdates;
16578: }
16579: }
16580: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 16581: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 16582: if ($changes{$item}) {
16583: if ($item eq 'alias') {
16584: my $numaliased = 0;
16585: if (ref($wafproxy{'alias'}) eq 'HASH') {
16586: my $shown;
16587: if (keys(%{$wafproxy{'alias'}})) {
16588: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
16589: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
16590: &Apache::lonnet::hostname($server),
16591: $wafproxy{'alias'}{$server}).'</li>';
16592: $numaliased ++;
16593: }
16594: if ($numaliased) {
16595: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
16596: '<ul>'.$shown.'</ul>').'</li>';
16597: }
16598: }
16599: }
16600: unless ($numaliased) {
16601: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
16602: }
16603: } elsif ($item eq 'saml') {
16604: my $shown;
16605: if (ref($wafproxy{'saml'}) eq 'HASH') {
16606: if (keys(%{$wafproxy{'saml'}})) {
16607: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
16608: }
16609: }
16610: if ($shown) {
16611: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
16612: $shown).'</li>';
16613: } else {
16614: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
16615: }
16616: } else {
16617: if ($item eq 'remoteip') {
16618: my %ip_methods = &remoteip_methods();
16619: if ($wafproxy{$item} =~ /^[mh]$/) {
16620: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
16621: $ip_methods{$wafproxy{$item}}).'</li>';
16622: } else {
16623: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
16624: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
16625: '</li>';
16626: } else {
16627: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
16628: }
16629: }
16630: } elsif ($item eq 'ipheader') {
16631: if ($wafproxy{$item}) {
16632: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
16633: $wafproxy{$item}).'</li>';
16634: } else {
16635: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
16636: }
16637: } elsif ($item eq 'trusted') {
16638: if ($wafproxy{$item}) {
16639: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
16640: $wafproxy{$item}).'</li>';
16641: } else {
16642: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
16643: }
16644: } elsif ($item eq 'vpnint') {
16645: if ($wafproxy{$item}) {
16646: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
16647: $wafproxy{$item}).'</li>';
16648: } else {
16649: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
16650: }
16651: } elsif ($item eq 'vpnext') {
16652: if ($wafproxy{$item}) {
16653: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
16654: $wafproxy{$item}).'</li>';
16655: } else {
16656: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
16657: }
16658: } elsif ($item eq 'sslopt') {
16659: if ($wafproxy{$item}) {
16660: $output .= '<li>'.&mt('WAF/Reverse Proxy expected to forward requests to https on LON-CAPA node, regardless of original protocol in web browser (http or https).').'</li>';
16661: } else {
16662: $output .= '<li>'.&mt('WAF/Reverse Proxy expected to preserve original protocol in web browser (either http or https) when forwarding to LON-CAPA node.').'</li>';
16663: }
16664: }
16665: }
16666: }
16667: }
1.160.6.123 raeburn 16668: $output .= '</ul>';
1.160.6.113 raeburn 16669: } else {
16670: $output = '<span class="LC_error">'.
16671: &mt('An error occurred: [_1]',$putresult).'</span>';
16672: }
16673: } elsif (keys(%canset)) {
16674: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
16675: }
16676: if (@warnings) {
16677: $output .= '<br />'.&mt('Warnings:').'<ul>'.
16678: join("\n",@warnings).'</ul>';
16679: }
16680: return $output;
16681: }
16682:
16683: sub validate_ip_pattern {
16684: my ($pattern) = @_;
16685: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
16686: my ($start,$end) = ($1,$2);
16687: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
16688: if (($start !~ m{/}) && ($end !~ m{/})) {
16689: return $start.'-'.$end;
16690: }
16691: }
16692: } elsif ($pattern ne '') {
16693: $pattern = &Net::CIDR::cidrvalidate($pattern);
16694: if ($pattern ne '') {
16695: return $pattern;
16696: }
16697: }
16698: return;
16699: }
16700:
1.137 raeburn 16701: sub modify_usersessions {
1.160.6.27 raeburn 16702: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16703: my @hostingtypes = ('version','excludedomain','includedomain');
16704: my @offloadtypes = ('primary','default');
16705: my %types = (
16706: remote => \@hostingtypes,
16707: hosted => \@hostingtypes,
16708: spares => \@offloadtypes,
16709: );
16710: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16711: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 16712: my (%by_ip,%by_location,@intdoms);
16713: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
16714: my @locations = sort(keys(%by_location));
1.137 raeburn 16715: my (%defaultshash,%changes);
16716: foreach my $prefix (@prefixes) {
16717: $defaultshash{'usersessions'}{$prefix} = {};
16718: }
1.160.6.27 raeburn 16719: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16720: my $resulttext;
1.138 raeburn 16721: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16722: foreach my $prefix (@prefixes) {
1.145 raeburn 16723: next if ($prefix eq 'spares');
16724: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16725: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16726: if ($type eq 'version') {
16727: my $value = $env{'form.'.$prefix.'_'.$type};
16728: my $okvalue;
16729: if ($value ne '') {
16730: if (grep(/^\Q$value\E$/,@lcversions)) {
16731: $okvalue = $value;
16732: }
16733: }
16734: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16735: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16736: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16737: if ($inuse == 0) {
16738: $changes{$prefix}{$type} = 1;
16739: } else {
16740: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16741: $changes{$prefix}{$type} = 1;
16742: }
16743: if ($okvalue ne '') {
16744: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16745: }
16746: }
16747: } else {
16748: if (($inuse == 1) && ($okvalue ne '')) {
16749: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16750: $changes{$prefix}{$type} = 1;
16751: }
16752: }
16753: } else {
16754: if (($inuse == 1) && ($okvalue ne '')) {
16755: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16756: $changes{$prefix}{$type} = 1;
16757: }
16758: }
16759: } else {
16760: if (($inuse == 1) && ($okvalue ne '')) {
16761: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16762: $changes{$prefix}{$type} = 1;
16763: }
16764: }
16765: } else {
16766: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16767: my @okvals;
16768: foreach my $val (@vals) {
1.138 raeburn 16769: if ($val =~ /:/) {
16770: my @items = split(/:/,$val);
16771: foreach my $item (@items) {
16772: if (ref($by_location{$item}) eq 'ARRAY') {
16773: push(@okvals,$item);
16774: }
16775: }
16776: } else {
16777: if (ref($by_location{$val}) eq 'ARRAY') {
16778: push(@okvals,$val);
16779: }
1.137 raeburn 16780: }
16781: }
16782: @okvals = sort(@okvals);
16783: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16784: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16785: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16786: if ($inuse == 0) {
16787: $changes{$prefix}{$type} = 1;
16788: } else {
16789: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16790: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16791: if (@changed > 0) {
16792: $changes{$prefix}{$type} = 1;
16793: }
16794: }
16795: } else {
16796: if ($inuse == 1) {
16797: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16798: $changes{$prefix}{$type} = 1;
16799: }
16800: }
16801: } else {
16802: if ($inuse == 1) {
16803: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16804: $changes{$prefix}{$type} = 1;
16805: }
16806: }
16807: } else {
16808: if ($inuse == 1) {
16809: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16810: $changes{$prefix}{$type} = 1;
16811: }
16812: }
16813: }
16814: }
16815: }
1.145 raeburn 16816:
16817: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16818: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16819: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16820: my $savespares;
16821:
16822: foreach my $lonhost (sort(keys(%servers))) {
16823: my $serverhomeID =
16824: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16825: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16826: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16827: my %spareschg;
16828: foreach my $type (@{$types{'spares'}}) {
16829: my @okspares;
16830: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16831: foreach my $server (@checked) {
1.152 raeburn 16832: if (&Apache::lonnet::hostname($server) ne '') {
16833: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16834: unless (grep(/^\Q$server\E$/,@okspares)) {
16835: push(@okspares,$server);
16836: }
1.145 raeburn 16837: }
16838: }
16839: }
16840: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16841: my $newspare;
1.152 raeburn 16842: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16843: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16844: $newspare = $new;
16845: }
16846: }
1.152 raeburn 16847: my @spares;
16848: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16849: @spares = sort(@okspares,$newspare);
16850: } else {
16851: @spares = sort(@okspares);
16852: }
16853: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16854: if (ref($spareid{$lonhost}) eq 'HASH') {
16855: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16856: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16857: if (@diffs > 0) {
16858: $spareschg{$type} = 1;
16859: }
16860: }
16861: }
16862: }
16863: if (keys(%spareschg) > 0) {
16864: $changes{'spares'}{$lonhost} = \%spareschg;
16865: }
16866: }
1.160.6.61 raeburn 16867: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 16868: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 16869: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16870: my @okoffload;
16871: if (@offloadnow) {
16872: foreach my $server (@offloadnow) {
16873: if (&Apache::lonnet::hostname($server) ne '') {
16874: unless (grep(/^\Q$server\E$/,@okoffload)) {
16875: push(@okoffload,$server);
16876: }
16877: }
16878: }
16879: if (@okoffload) {
16880: foreach my $lonhost (@okoffload) {
16881: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16882: }
16883: }
16884: }
1.160.6.105 raeburn 16885: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
16886: my @okoffloadoth;
16887: if (@offloadoth) {
16888: foreach my $server (@offloadoth) {
16889: if (&Apache::lonnet::hostname($server) ne '') {
16890: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
16891: push(@okoffloadoth,$server);
16892: }
16893: }
16894: }
16895: if (@okoffloadoth) {
16896: foreach my $lonhost (@okoffloadoth) {
16897: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
16898: }
16899: }
16900: }
1.145 raeburn 16901: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16902: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16903: if (ref($changes{'spares'}) eq 'HASH') {
16904: if (keys(%{$changes{'spares'}}) > 0) {
16905: $savespares = 1;
16906: }
16907: }
16908: } else {
16909: $savespares = 1;
16910: }
1.160.6.105 raeburn 16911: foreach my $offload ('offloadnow','offloadoth') {
16912: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
16913: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
16914: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
16915: $changes{$offload} = 1;
1.160.6.61 raeburn 16916: last;
16917: }
16918: }
1.160.6.105 raeburn 16919: unless ($changes{$offload}) {
16920: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
16921: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
16922: $changes{$offload} = 1;
16923: last;
16924: }
16925: }
16926: }
16927: } else {
16928: if (($offload eq 'offloadnow') && (@okoffload)) {
16929: $changes{'offloadnow'} = 1;
16930: }
16931: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
16932: $changes{'offloadoth'} = 1;
16933: }
1.160.6.61 raeburn 16934: }
1.160.6.105 raeburn 16935: }
16936: } else {
16937: if (@okoffload) {
1.160.6.61 raeburn 16938: $changes{'offloadnow'} = 1;
16939: }
1.160.6.105 raeburn 16940: if (@okoffloadoth) {
16941: $changes{'offloadoth'} = 1;
16942: }
1.145 raeburn 16943: }
1.147 raeburn 16944: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16945: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16946: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16947: $dom);
16948: if ($putresult eq 'ok') {
16949: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16950: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16951: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16952: }
16953: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16954: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16955: }
1.160.6.61 raeburn 16956: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16957: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16958: }
1.160.6.105 raeburn 16959: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16960: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
16961: }
1.137 raeburn 16962: }
16963: my $cachetime = 24*60*60;
16964: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 16965: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 16966: if (ref($lastactref) eq 'HASH') {
16967: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 16968: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 16969: }
1.147 raeburn 16970: if (keys(%changes) > 0) {
16971: my %lt = &usersession_titles();
16972: $resulttext = &mt('Changes made:').'<ul>';
16973: foreach my $prefix (@prefixes) {
16974: if (ref($changes{$prefix}) eq 'HASH') {
16975: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16976: if ($prefix eq 'spares') {
16977: if (ref($changes{$prefix}) eq 'HASH') {
16978: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16979: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16980: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 16981: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16982: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16983: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16984: foreach my $type (@{$types{$prefix}}) {
16985: if ($changes{$prefix}{$lonhost}{$type}) {
16986: my $offloadto = &mt('None');
16987: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16988: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16989: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16990: }
1.145 raeburn 16991: }
1.147 raeburn 16992: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16993: }
1.137 raeburn 16994: }
16995: }
1.147 raeburn 16996: $resulttext .= '</li>';
1.137 raeburn 16997: }
16998: }
1.147 raeburn 16999: } else {
17000: foreach my $type (@{$types{$prefix}}) {
17001: if (defined($changes{$prefix}{$type})) {
17002: my $newvalue;
17003: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
17004: if (ref($defaultshash{'usersessions'}{$prefix})) {
17005: if ($type eq 'version') {
17006: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
17007: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
17008: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
17009: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
17010: }
1.145 raeburn 17011: }
17012: }
17013: }
1.147 raeburn 17014: if ($newvalue eq '') {
17015: if ($type eq 'version') {
17016: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
17017: } else {
17018: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
17019: }
1.145 raeburn 17020: } else {
1.147 raeburn 17021: if ($type eq 'version') {
17022: $newvalue .= ' '.&mt('(or later)');
17023: }
17024: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 17025: }
1.137 raeburn 17026: }
17027: }
17028: }
1.147 raeburn 17029: $resulttext .= '</ul>';
1.137 raeburn 17030: }
17031: }
1.160.6.61 raeburn 17032: if ($changes{'offloadnow'}) {
17033: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
17034: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 17035: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 17036: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
17037: $resulttext .= '<li>'.$lonhost.'</li>';
17038: }
17039: $resulttext .= '</ul>';
17040: } else {
1.160.6.105 raeburn 17041: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
17042: }
17043: } else {
17044: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
17045: }
17046: }
17047: if ($changes{'offloadoth'}) {
17048: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
17049: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
17050: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
17051: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
17052: $resulttext .= '<li>'.$lonhost.'</li>';
17053: }
17054: $resulttext .= '</ul>';
17055: } else {
17056: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 17057: }
17058: } else {
1.160.6.105 raeburn 17059: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 17060: }
17061: }
1.147 raeburn 17062: $resulttext .= '</ul>';
17063: } else {
17064: $resulttext = $nochgmsg;
1.137 raeburn 17065: }
17066: } else {
17067: $resulttext = '<span class="LC_error">'.
17068: &mt('An error occurred: [_1]',$putresult).'</span>';
17069: }
17070: } else {
1.147 raeburn 17071: $resulttext = $nochgmsg;
1.137 raeburn 17072: }
17073: return $resulttext;
17074: }
17075:
1.150 raeburn 17076: sub modify_loadbalancing {
17077: my ($dom,%domconfig) = @_;
17078: my $primary_id = &Apache::lonnet::domain($dom,'primary');
17079: my $intdom = &Apache::lonnet::internet_dom($primary_id);
17080: my ($othertitle,$usertypes,$types) =
17081: &Apache::loncommon::sorted_inst_types($dom);
17082: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 17083: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 17084: my @sparestypes = ('primary','default');
17085: my %typetitles = &sparestype_titles();
17086: my $resulttext;
1.160.6.94 raeburn 17087: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 17088: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17089: %existing = %{$domconfig{'loadbalancing'}};
17090: }
17091: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 17092: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 17093: my ($saveloadbalancing,%defaultshash,%changes);
17094: my ($alltypes,$othertypes,$titles) =
17095: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
17096: my %ruletitles = &offloadtype_text();
17097: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
17098: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
17099: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
17100: if ($balancer eq '') {
17101: next;
17102: }
17103: if (!exists($servers{$balancer})) {
17104: if (exists($currbalancer{$balancer})) {
17105: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 17106: }
1.160.6.7 raeburn 17107: next;
17108: }
17109: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
17110: push(@{$changes{'delete'}},$balancer);
17111: next;
17112: }
17113: if (!exists($currbalancer{$balancer})) {
17114: push(@{$changes{'add'}},$balancer);
17115: }
17116: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
17117: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
17118: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
17119: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17120: $saveloadbalancing = 1;
17121: }
17122: foreach my $sparetype (@sparestypes) {
17123: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
17124: my @offloadto;
17125: foreach my $target (@targets) {
17126: if (($servers{$target}) && ($target ne $balancer)) {
17127: if ($sparetype eq 'default') {
17128: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
17129: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 17130: }
17131: }
1.160.6.7 raeburn 17132: unless(grep(/^\Q$target\E$/,@offloadto)) {
17133: push(@offloadto,$target);
17134: }
1.150 raeburn 17135: }
17136: }
1.160.6.76 raeburn 17137: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
17138: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
17139: push(@offloadto,$balancer);
17140: }
17141: }
17142: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 17143: }
1.160.6.94 raeburn 17144: if ($env{'form.loadbalancing_cookie_'.$i}) {
17145: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
17146: if (exists($currbalancer{$balancer})) {
17147: unless ($currcookies{$balancer}) {
17148: $changes{'curr'}{$balancer}{'cookie'} = 1;
17149: }
17150: }
17151: } elsif (exists($currbalancer{$balancer})) {
17152: if ($currcookies{$balancer}) {
17153: $changes{'curr'}{$balancer}{'cookie'} = 1;
17154: }
17155: }
1.160.6.7 raeburn 17156: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 17157: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 17158: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
17159: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 17160: if (@targetdiffs > 0) {
1.160.6.7 raeburn 17161: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17162: }
1.160.6.7 raeburn 17163: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17164: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17165: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17166: }
17167: }
17168: }
17169: } else {
1.160.6.7 raeburn 17170: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
17171: foreach my $sparetype (@sparestypes) {
17172: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17173: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17174: $changes{'curr'}{$balancer}{'targets'} = 1;
17175: }
1.150 raeburn 17176: }
17177: }
1.160.6.7 raeburn 17178: }
1.150 raeburn 17179: }
17180: my $ishomedom;
1.160.6.7 raeburn 17181: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
17182: $ishomedom = 1;
1.150 raeburn 17183: }
17184: if (ref($alltypes) eq 'ARRAY') {
17185: foreach my $type (@{$alltypes}) {
17186: my $rule;
1.160.6.7 raeburn 17187: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 17188: (!$ishomedom)) {
1.160.6.7 raeburn 17189: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
17190: }
17191: if ($rule eq 'specific') {
1.160.6.55 raeburn 17192: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
17193: if (exists($servers{$specifiedhost})) {
17194: $rule = $specifiedhost;
17195: }
1.150 raeburn 17196: }
1.160.6.7 raeburn 17197: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
17198: if (ref($currrules{$balancer}) eq 'HASH') {
17199: if ($rule ne $currrules{$balancer}{$type}) {
17200: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17201: }
17202: } elsif ($rule ne '') {
1.160.6.7 raeburn 17203: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17204: }
17205: }
17206: }
1.160.6.7 raeburn 17207: }
17208: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
17209: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
17210: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
17211: $defaultshash{'loadbalancing'} = {};
17212: }
17213: my $putresult = &Apache::lonnet::put_dom('configuration',
17214: \%defaultshash,$dom);
17215: if ($putresult eq 'ok') {
17216: if (keys(%changes) > 0) {
1.160.6.54 raeburn 17217: my %toupdate;
1.160.6.7 raeburn 17218: if (ref($changes{'delete'}) eq 'ARRAY') {
17219: foreach my $balancer (sort(@{$changes{'delete'}})) {
17220: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 17221: $toupdate{$balancer} = 1;
1.150 raeburn 17222: }
1.160.6.7 raeburn 17223: }
17224: if (ref($changes{'add'}) eq 'ARRAY') {
17225: foreach my $balancer (sort(@{$changes{'add'}})) {
17226: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 17227: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 17228: }
17229: }
17230: if (ref($changes{'curr'}) eq 'HASH') {
17231: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 17232: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 17233: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
17234: if ($changes{'curr'}{$balancer}{'targets'}) {
17235: my %offloadstr;
17236: foreach my $sparetype (@sparestypes) {
17237: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17238: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17239: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17240: }
17241: }
1.150 raeburn 17242: }
1.160.6.7 raeburn 17243: if (keys(%offloadstr) == 0) {
17244: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 17245: } else {
1.160.6.7 raeburn 17246: my $showoffload;
17247: foreach my $sparetype (@sparestypes) {
17248: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
17249: if (defined($offloadstr{$sparetype})) {
17250: $showoffload .= $offloadstr{$sparetype};
17251: } else {
17252: $showoffload .= &mt('None');
17253: }
17254: $showoffload .= (' 'x3);
17255: }
17256: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 17257: }
17258: }
17259: }
1.160.6.7 raeburn 17260: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
17261: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
17262: foreach my $type (@{$alltypes}) {
17263: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
17264: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17265: my $balancetext;
17266: if ($rule eq '') {
17267: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 17268: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 17269: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
17270: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 17271: foreach my $sparetype (@sparestypes) {
17272: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17273: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17274: }
17275: }
1.160.6.55 raeburn 17276: foreach my $item (@{$alltypes}) {
17277: next if ($item =~ /^_LC_ipchange/);
17278: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
17279: if ($hasrule eq 'homeserver') {
17280: map { $toupdate{$_} = 1; } (keys(%libraryservers));
17281: } else {
17282: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
17283: if ($servers{$hasrule}) {
17284: $toupdate{$hasrule} = 1;
17285: }
17286: }
17287: }
17288: }
17289: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
17290: $balancetext = $ruletitles{$rule};
17291: } else {
17292: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17293: $balancetext = $ruletitles{'particular'}.' '.$receiver;
17294: if ($receiver) {
17295: $toupdate{$receiver};
17296: }
17297: }
17298: } else {
17299: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 17300: }
1.160.6.7 raeburn 17301: } else {
17302: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
17303: }
1.160.6.26 raeburn 17304: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 17305: }
17306: }
17307: }
17308: }
1.160.6.94 raeburn 17309: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 17310: if ($currcookies{$balancer}) {
17311: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
17312: $balancer).'</li>';
17313: } else {
17314: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
17315: $balancer).'</li>';
17316: }
1.160.6.94 raeburn 17317: }
1.160.6.106 raeburn 17318: }
17319: }
17320: if (keys(%toupdate)) {
17321: my %thismachine;
17322: my $updatedhere;
17323: my $cachetime = 60*60*24;
17324: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17325: foreach my $lonhost (keys(%toupdate)) {
17326: if ($thismachine{$lonhost}) {
17327: unless ($updatedhere) {
17328: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
17329: $defaultshash{'loadbalancing'},
17330: $cachetime);
17331: $updatedhere = 1;
1.160.6.54 raeburn 17332: }
1.160.6.106 raeburn 17333: } else {
17334: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
17335: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 17336: }
1.150 raeburn 17337: }
1.160.6.7 raeburn 17338: }
17339: if ($resulttext ne '') {
17340: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 17341: } else {
17342: $resulttext = $nochgmsg;
17343: }
17344: } else {
1.160.6.7 raeburn 17345: $resulttext = $nochgmsg;
1.150 raeburn 17346: }
17347: } else {
1.160.6.7 raeburn 17348: $resulttext = '<span class="LC_error">'.
17349: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 17350: }
17351: } else {
1.160.6.7 raeburn 17352: $resulttext = $nochgmsg;
1.150 raeburn 17353: }
17354: return $resulttext;
17355: }
17356:
1.48 raeburn 17357: sub recurse_check {
17358: my ($chkcats,$categories,$depth,$name) = @_;
17359: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
17360: my $chg = 0;
17361: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
17362: my $category = $chkcats->[$depth]{$name}[$j];
17363: my $item;
17364: if ($category eq '') {
17365: $chg ++;
17366: } else {
17367: my $deeper = $depth + 1;
17368: $item = &escape($category).':'.&escape($name).':'.$depth;
17369: if ($chg) {
17370: $categories->{$item} -= $chg;
17371: }
17372: &recurse_check($chkcats,$categories,$deeper,$category);
17373: $deeper --;
17374: }
17375: }
17376: }
17377: return;
17378: }
17379:
17380: sub recurse_cat_deletes {
17381: my ($item,$coursecategories,$deletions) = @_;
17382: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17383: my $subdepth = $depth + 1;
17384: if (ref($coursecategories) eq 'HASH') {
17385: foreach my $subitem (keys(%{$coursecategories})) {
17386: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
17387: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
17388: delete($coursecategories->{$subitem});
17389: $deletions->{$subitem} = 1;
17390: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 17391: }
1.48 raeburn 17392: }
17393: }
17394: return;
17395: }
17396:
1.125 raeburn 17397: sub active_dc_picker {
1.160.6.16 raeburn 17398: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 17399: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 17400: my @domcoord = keys(%domcoords);
17401: if (keys(%currhash)) {
17402: foreach my $dc (keys(%currhash)) {
17403: unless (exists($domcoords{$dc})) {
17404: push(@domcoord,$dc);
17405: }
17406: }
17407: }
17408: @domcoord = sort(@domcoord);
17409: my $numdcs = scalar(@domcoord);
17410: my $rows = 0;
17411: my $table;
1.125 raeburn 17412: if ($numdcs > 1) {
1.160.6.16 raeburn 17413: $table = '<table>';
17414: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 17415: my $rem = $i%($numinrow);
17416: if ($rem == 0) {
17417: if ($i > 0) {
1.160.6.16 raeburn 17418: $table .= '</tr>';
1.125 raeburn 17419: }
1.160.6.16 raeburn 17420: $table .= '<tr>';
17421: $rows ++;
1.125 raeburn 17422: }
1.160.6.16 raeburn 17423: my $check = '';
17424: if ($inputtype eq 'radio') {
17425: if (keys(%currhash) == 0) {
17426: if (!$i) {
17427: $check = ' checked="checked"';
17428: }
17429: } elsif (exists($currhash{$domcoord[$i]})) {
17430: $check = ' checked="checked"';
17431: }
17432: } else {
17433: if (exists($currhash{$domcoord[$i]})) {
17434: $check = ' checked="checked"';
1.125 raeburn 17435: }
17436: }
1.160.6.16 raeburn 17437: if ($i == @domcoord - 1) {
1.125 raeburn 17438: my $colsleft = $numinrow - $rem;
17439: if ($colsleft > 1) {
1.160.6.16 raeburn 17440: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 17441: } else {
1.160.6.16 raeburn 17442: $table .= '<td class="LC_left_item">';
1.125 raeburn 17443: }
17444: } else {
1.160.6.16 raeburn 17445: $table .= '<td class="LC_left_item">';
17446: }
17447: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17448: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17449: $table .= '<span class="LC_nobreak"><label>'.
17450: '<input type="'.$inputtype.'" name="'.$name.'"'.
17451: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17452: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 17453: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 17454: }
1.160.6.33 raeburn 17455: $table .= '</label></span></td>';
1.125 raeburn 17456: }
1.160.6.16 raeburn 17457: $table .= '</tr></table>';
17458: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 17459: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17460: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 17461: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 17462: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 17463: if ($user ne $dcname.':'.$dcdom) {
17464: $table .= ' ('.$dcname.':'.$dcdom.')';
17465: }
1.160.6.16 raeburn 17466: } else {
17467: my $check;
17468: if (exists($currhash{$domcoord[0]})) {
17469: $check = ' checked="checked"';
17470: }
1.160.6.50 raeburn 17471: $table = '<span class="LC_nobreak"><label>'.
17472: '<input type="checkbox" name="'.$name.'" '.
17473: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 17474: if ($user ne $dcname.':'.$dcdom) {
17475: $table .= ' ('.$dcname.':'.$dcdom.')';
17476: }
17477: $table .= '</label></span>';
1.160.6.16 raeburn 17478: $rows ++;
17479: }
1.125 raeburn 17480: }
1.160.6.16 raeburn 17481: return ($numdcs,$table,$rows);
1.125 raeburn 17482: }
17483:
1.137 raeburn 17484: sub usersession_titles {
17485: return &Apache::lonlocal::texthash(
17486: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17487: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17488: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17489: version => 'LON-CAPA version requirement',
1.138 raeburn 17490: excludedomain => 'Allow all, but exclude specific domains',
17491: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17492: primary => 'Primary (checked first)',
1.154 raeburn 17493: default => 'Default',
1.137 raeburn 17494: );
17495: }
17496:
1.152 raeburn 17497: sub id_for_thisdom {
17498: my (%servers) = @_;
17499: my %altids;
17500: foreach my $server (keys(%servers)) {
17501: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17502: if ($serverhome ne $server) {
17503: $altids{$serverhome} = $server;
17504: }
17505: }
17506: return %altids;
17507: }
17508:
1.150 raeburn 17509: sub count_servers {
17510: my ($currbalancer,%servers) = @_;
17511: my (@spares,$numspares);
17512: foreach my $lonhost (sort(keys(%servers))) {
17513: next if ($currbalancer eq $lonhost);
17514: push(@spares,$lonhost);
17515: }
17516: if ($currbalancer) {
17517: $numspares = scalar(@spares);
17518: } else {
17519: $numspares = scalar(@spares) - 1;
17520: }
17521: return ($numspares,@spares);
17522: }
17523:
17524: sub lonbalance_targets_js {
1.160.6.7 raeburn 17525: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17526: my $select = &mt('Select');
17527: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17528: if (ref($servers) eq 'HASH') {
17529: $alltargets = join("','",sort(keys(%{$servers})));
17530: my @homedoms;
17531: foreach my $server (sort(keys(%{$servers}))) {
17532: if (&Apache::lonnet::host_domain($server) eq $dom) {
17533: push(@homedoms,'1');
17534: } else {
17535: push(@homedoms,'0');
17536: }
17537: }
17538: $allishome = join("','",@homedoms);
17539: }
17540: if (ref($types) eq 'ARRAY') {
17541: if (@{$types} > 0) {
17542: @alltypes = @{$types};
17543: }
17544: }
17545: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17546: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 17547: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 17548: if (ref($settings) eq 'HASH') {
17549: %existing = %{$settings};
17550: }
17551: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 17552: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 17553: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17554: return <<"END";
17555:
17556: <script type="text/javascript">
17557: // <![CDATA[
17558:
1.160.6.7 raeburn 17559: currBalancers = new Array('$balancers');
17560:
17561: function toggleTargets(balnum) {
17562: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17563: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17564: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17565: var prevbalancer = prevhostitem.value;
17566: var baltotal = document.getElementById('loadbalancing_total').value;
17567: prevhostitem.value = balancer;
17568: if (prevbalancer != '') {
17569: var prevIdx = currBalancers.indexOf(prevbalancer);
17570: if (prevIdx != -1) {
17571: currBalancers.splice(prevIdx,1);
17572: }
17573: }
1.150 raeburn 17574: if (balancer == '') {
1.160.6.7 raeburn 17575: hideSpares(balnum);
1.150 raeburn 17576: } else {
1.160.6.7 raeburn 17577: var currIdx = currBalancers.indexOf(balancer);
17578: if (currIdx == -1) {
17579: currBalancers.push(balancer);
17580: }
1.150 raeburn 17581: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 17582: var ishomedom = homedoms[lonhostitem.selectedIndex];
17583: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17584: }
1.160.6.7 raeburn 17585: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17586: return;
17587: }
17588:
1.160.6.7 raeburn 17589: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17590: var alltargets = new Array('$alltargets');
17591: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17592: var offloadtypes = new Array('primary','default');
17593:
1.160.6.7 raeburn 17594: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17595: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17596:
1.151 raeburn 17597: for (var i=0; i<offloadtypes.length; i++) {
17598: var count = 0;
17599: for (var j=0; j<alltargets.length; j++) {
17600: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 17601: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17602: item.value = alltargets[j];
17603: item.style.textAlign='left';
17604: item.style.textFace='normal';
17605: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17606: if (currBalancers.indexOf(alltargets[j]) == -1) {
17607: item.disabled = '';
17608: } else {
17609: item.disabled = 'disabled';
17610: item.checked = false;
17611: }
1.151 raeburn 17612: count ++;
17613: }
1.150 raeburn 17614: }
17615: }
1.151 raeburn 17616: for (var k=0; k<insttypes.length; k++) {
17617: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17618: if (ishomedom == 1) {
1.160.6.7 raeburn 17619: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17620: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17621: } else {
1.160.6.7 raeburn 17622: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17623: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17624: }
17625: } else {
1.160.6.7 raeburn 17626: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17627: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17628: }
1.151 raeburn 17629: if ((insttypes[k] != '_LC_external') &&
17630: ((insttypes[k] != '_LC_internetdom') ||
17631: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 17632: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17633: item.options.length = 0;
17634: item.options[0] = new Option("","",true,true);
17635: var idx = 0;
1.151 raeburn 17636: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 17637: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17638: idx ++;
17639: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17640: }
17641: }
17642: }
17643: }
17644: return;
17645: }
17646:
1.160.6.7 raeburn 17647: function hideSpares(balnum) {
1.150 raeburn 17648: var alltargets = new Array('$alltargets');
17649: var insttypes = new Array('$allinsttypes');
17650: var offloadtypes = new Array('primary','default');
17651:
1.160.6.7 raeburn 17652: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17653: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17654:
17655: var total = alltargets.length - 1;
17656: for (var i=0; i<offloadtypes; i++) {
17657: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 17658: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17659: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17660: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17661: }
1.150 raeburn 17662: }
17663: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 17664: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17665: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17666: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 17667: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17668: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17669: }
17670: }
17671: return;
17672: }
17673:
1.160.6.7 raeburn 17674: function checkOffloads(item,balnum,type) {
1.150 raeburn 17675: var alltargets = new Array('$alltargets');
17676: var offloadtypes = new Array('primary','default');
17677: if (item.checked) {
17678: var total = alltargets.length - 1;
17679: var other;
17680: if (type == offloadtypes[0]) {
1.151 raeburn 17681: other = offloadtypes[1];
1.150 raeburn 17682: } else {
1.151 raeburn 17683: other = offloadtypes[0];
1.150 raeburn 17684: }
17685: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 17686: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17687: if (server == item.value) {
1.160.6.7 raeburn 17688: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17689: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17690: }
17691: }
17692: }
17693: }
17694: return;
17695: }
17696:
1.160.6.7 raeburn 17697: function singleServerToggle(balnum,type) {
17698: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17699: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 17700: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17701: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17702:
17703: } else {
1.160.6.7 raeburn 17704: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17705: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17706: }
17707: return;
17708: }
17709:
1.160.6.7 raeburn 17710: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17711: if (type == '_LC_external') {
1.160.6.26 raeburn 17712: return;
1.150 raeburn 17713: }
1.160.6.7 raeburn 17714: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17715: for (var i=0; i<typesRules.length; i++) {
17716: if (formname.elements[typesRules[i]].checked) {
17717: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 17718: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17719: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17720: } else {
1.160.6.7 raeburn 17721: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17722: }
17723: }
17724: }
17725: return;
17726: }
17727:
17728: function balancerDeleteChange(balnum) {
17729: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17730: var baltotal = document.getElementById('loadbalancing_total').value;
17731: var addtarget;
17732: var removetarget;
17733: var action = 'delete';
17734: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17735: var lonhost = hostitem.value;
17736: var currIdx = currBalancers.indexOf(lonhost);
17737: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17738: if (currIdx != -1) {
17739: currBalancers.splice(currIdx,1);
17740: }
17741: addtarget = lonhost;
17742: } else {
17743: if (currIdx == -1) {
17744: currBalancers.push(lonhost);
17745: }
17746: removetarget = lonhost;
17747: action = 'undelete';
17748: }
17749: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17750: }
17751: return;
17752: }
17753:
17754: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17755: if (baltotal > 1) {
17756: var offloadtypes = new Array('primary','default');
17757: var alltargets = new Array('$alltargets');
17758: var insttypes = new Array('$allinsttypes');
17759: for (var i=0; i<baltotal; i++) {
17760: if (i != balnum) {
17761: for (var j=0; j<offloadtypes.length; j++) {
17762: var total = alltargets.length - 1;
17763: for (var k=0; k<total; k++) {
17764: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17765: var server = serveritem.value;
17766: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17767: if (server == addtarget) {
17768: serveritem.disabled = '';
17769: }
17770: }
17771: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17772: if (server == removetarget) {
17773: serveritem.disabled = 'disabled';
17774: serveritem.checked = false;
17775: }
17776: }
17777: }
17778: }
17779: for (var j=0; j<insttypes.length; j++) {
17780: if (insttypes[j] != '_LC_external') {
17781: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17782: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17783: var currSel = singleserver.selectedIndex;
17784: var currVal = singleserver.options[currSel].value;
17785: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17786: var numoptions = singleserver.options.length;
17787: var needsnew = 1;
17788: for (var k=0; k<numoptions; k++) {
17789: if (singleserver.options[k] == addtarget) {
17790: needsnew = 0;
17791: break;
17792: }
17793: }
17794: if (needsnew == 1) {
17795: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17796: }
17797: }
17798: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17799: singleserver.options.length = 0;
17800: if ((currVal) && (currVal != removetarget)) {
17801: singleserver.options[0] = new Option("","",false,false);
17802: } else {
17803: singleserver.options[0] = new Option("","",true,true);
17804: }
17805: var idx = 0;
17806: for (var m=0; m<alltargets.length; m++) {
17807: if (currBalancers.indexOf(alltargets[m]) == -1) {
17808: idx ++;
17809: if (currVal == alltargets[m]) {
17810: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17811: } else {
17812: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17813: }
17814: }
17815: }
17816: }
17817: }
17818: }
17819: }
1.150 raeburn 17820: }
17821: }
17822: }
17823: return;
17824: }
17825:
1.152 raeburn 17826: // ]]>
17827: </script>
17828:
17829: END
17830: }
17831:
17832: sub new_spares_js {
17833: my @sparestypes = ('primary','default');
17834: my $types = join("','",@sparestypes);
17835: my $select = &mt('Select');
17836: return <<"END";
17837:
17838: <script type="text/javascript">
17839: // <![CDATA[
17840:
17841: function updateNewSpares(formname,lonhost) {
17842: var types = new Array('$types');
17843: var include = new Array();
17844: var exclude = new Array();
17845: for (var i=0; i<types.length; i++) {
17846: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17847: for (var j=0; j<spareboxes.length; j++) {
17848: if (formname.elements[spareboxes[j]].checked) {
17849: exclude.push(formname.elements[spareboxes[j]].value);
17850: } else {
17851: include.push(formname.elements[spareboxes[j]].value);
17852: }
17853: }
17854: }
17855: for (var i=0; i<types.length; i++) {
17856: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17857: var selIdx = newSpare.selectedIndex;
17858: var currnew = newSpare.options[selIdx].value;
17859: var okSpares = new Array();
17860: for (var j=0; j<newSpare.options.length; j++) {
17861: var possible = newSpare.options[j].value;
17862: if (possible != '') {
17863: if (exclude.indexOf(possible) == -1) {
17864: okSpares.push(possible);
17865: } else {
17866: if (currnew == possible) {
17867: selIdx = 0;
17868: }
17869: }
17870: }
17871: }
17872: for (var k=0; k<include.length; k++) {
17873: if (okSpares.indexOf(include[k]) == -1) {
17874: okSpares.push(include[k]);
17875: }
17876: }
17877: okSpares.sort();
17878: newSpare.options.length = 0;
17879: if (selIdx == 0) {
17880: newSpare.options[0] = new Option("$select","",true,true);
17881: } else {
17882: newSpare.options[0] = new Option("$select","",false,false);
17883: }
17884: for (var m=0; m<okSpares.length; m++) {
17885: var idx = m+1;
17886: var selThis = 0;
17887: if (selIdx != 0) {
17888: if (okSpares[m] == currnew) {
17889: selThis = 1;
17890: }
17891: }
17892: if (selThis == 1) {
17893: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17894: } else {
17895: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17896: }
17897: }
17898: }
17899: return;
17900: }
17901:
17902: function checkNewSpares(lonhost,type) {
17903: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17904: var chosen = newSpare.options[newSpare.selectedIndex].value;
17905: if (chosen != '') {
17906: var othertype;
17907: var othernewSpare;
17908: if (type == 'primary') {
17909: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17910: }
17911: if (type == 'default') {
17912: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17913: }
17914: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17915: othernewSpare.selectedIndex = 0;
17916: }
17917: }
17918: return;
17919: }
17920:
17921: // ]]>
17922: </script>
17923:
17924: END
17925:
17926: }
17927:
17928: sub common_domprefs_js {
17929: return <<"END";
17930:
17931: <script type="text/javascript">
17932: // <![CDATA[
17933:
1.150 raeburn 17934: function getIndicesByName(formname,item) {
1.152 raeburn 17935: var group = new Array();
1.150 raeburn 17936: for (var i=0;i<formname.elements.length;i++) {
17937: if (formname.elements[i].name == item) {
1.152 raeburn 17938: group.push(formname.elements[i].id);
1.150 raeburn 17939: }
17940: }
1.152 raeburn 17941: return group;
1.150 raeburn 17942: }
17943:
17944: // ]]>
17945: </script>
17946:
17947: END
1.152 raeburn 17948:
1.150 raeburn 17949: }
17950:
1.160.6.5 raeburn 17951: sub recaptcha_js {
17952: my %lt = &captcha_phrases();
17953: return <<"END";
17954:
17955: <script type="text/javascript">
17956: // <![CDATA[
17957:
17958: function updateCaptcha(caller,context) {
17959: var privitem;
17960: var pubitem;
17961: var privtext;
17962: var pubtext;
1.160.6.69 raeburn 17963: var versionitem;
17964: var versiontext;
1.160.6.5 raeburn 17965: if (document.getElementById(context+'_recaptchapub')) {
17966: pubitem = document.getElementById(context+'_recaptchapub');
17967: } else {
17968: return;
17969: }
17970: if (document.getElementById(context+'_recaptchapriv')) {
17971: privitem = document.getElementById(context+'_recaptchapriv');
17972: } else {
17973: return;
17974: }
17975: if (document.getElementById(context+'_recaptchapubtxt')) {
17976: pubtext = document.getElementById(context+'_recaptchapubtxt');
17977: } else {
17978: return;
17979: }
17980: if (document.getElementById(context+'_recaptchaprivtxt')) {
17981: privtext = document.getElementById(context+'_recaptchaprivtxt');
17982: } else {
17983: return;
17984: }
1.160.6.69 raeburn 17985: if (document.getElementById(context+'_recaptchaversion')) {
17986: versionitem = document.getElementById(context+'_recaptchaversion');
17987: } else {
17988: return;
17989: }
17990: if (document.getElementById(context+'_recaptchavertxt')) {
17991: versiontext = document.getElementById(context+'_recaptchavertxt');
17992: } else {
17993: return;
17994: }
1.160.6.5 raeburn 17995: if (caller.checked) {
17996: if (caller.value == 'recaptcha') {
17997: pubitem.type = 'text';
17998: privitem.type = 'text';
17999: pubitem.size = '40';
18000: privitem.size = '40';
18001: pubtext.innerHTML = "$lt{'pub'}";
18002: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 18003: versionitem.type = 'text';
18004: versionitem.size = '3';
18005: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 18006: } else {
18007: pubitem.type = 'hidden';
18008: privitem.type = 'hidden';
1.160.6.69 raeburn 18009: versionitem.type = 'hidden';
1.160.6.5 raeburn 18010: pubtext.innerHTML = '';
18011: privtext.innerHTML = '';
1.160.6.69 raeburn 18012: versiontext.innerHTML = '';
1.160.6.5 raeburn 18013: }
18014: }
18015: return;
18016: }
18017:
18018: // ]]>
18019: </script>
18020:
18021: END
18022:
18023: }
18024:
1.160.6.40 raeburn 18025: sub toggle_display_js {
1.160.6.16 raeburn 18026: return <<"END";
18027:
18028: <script type="text/javascript">
18029: // <![CDATA[
18030:
1.160.6.40 raeburn 18031: function toggleDisplay(domForm,caller) {
18032: if (document.getElementById(caller)) {
18033: var divitem = document.getElementById(caller);
18034: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 18035: var checkval = 1;
18036: var dispval = 'block';
1.160.6.93 raeburn 18037: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 18038: if (caller == 'emailoptions') {
18039: optionsElement = domForm.cancreate_email;
18040: }
1.160.6.57 raeburn 18041: if (caller == 'studentsubmission') {
18042: optionsElement = domForm.postsubmit;
18043: }
1.160.6.64 raeburn 18044: if (caller == 'cloneinstcode') {
18045: optionsElement = domForm.canclone;
18046: checkval = 'instcode';
18047: }
1.160.6.93 raeburn 18048: if (selfcreateRegExp.test(caller)) {
18049: optionsElement = domForm.elements[caller];
18050: checkval = 'other';
18051: dispval = 'inline'
18052: }
1.160.6.40 raeburn 18053: if (optionsElement.length) {
1.160.6.16 raeburn 18054: var currval;
1.160.6.40 raeburn 18055: for (var i=0; i<optionsElement.length; i++) {
18056: if (optionsElement[i].checked) {
18057: currval = optionsElement[i].value;
1.160.6.16 raeburn 18058: }
18059: }
1.160.6.64 raeburn 18060: if (currval == checkval) {
18061: divitem.style.display = dispval;
1.160.6.16 raeburn 18062: } else {
1.160.6.40 raeburn 18063: divitem.style.display = 'none';
1.160.6.16 raeburn 18064: }
18065: }
18066: }
18067: return;
18068: }
18069:
18070: // ]]>
18071: </script>
18072:
18073: END
18074:
18075: }
18076:
1.160.6.5 raeburn 18077: sub captcha_phrases {
18078: return &Apache::lonlocal::texthash (
18079: priv => 'Private key',
18080: pub => 'Public key',
18081: original => 'original (CAPTCHA)',
18082: recaptcha => 'successor (ReCAPTCHA)',
18083: notused => 'unused',
1.160.6.69 raeburn 18084: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 18085: );
18086: }
18087:
1.160.6.24 raeburn 18088: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 18089: my ($dom,$cachekeys) = @_;
18090: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 18091: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18092: my %thismachine;
18093: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 18094: my @posscached = ('domainconfig','domdefaults','usersessions',
1.160.6.113 raeburn 18095: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
18096: 'ipaccess');
18097: my %cache_by_lonhost;
18098: if (exists($cachekeys->{'samllanding'})) {
18099: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
18100: my %landing = %{$cachekeys->{'samllanding'}};
18101: my %domservers = &Apache::lonnet::get_servers($dom);
18102: if (keys(%domservers)) {
18103: foreach my $server (keys(%domservers)) {
18104: my @cached;
18105: next if ($thismachine{$server});
18106: if ($landing{$server}) {
18107: push(@cached,&escape('samllanding').':'.&escape($server));
18108: }
18109: if (@cached) {
18110: $cache_by_lonhost{$server} = \@cached;
18111: }
18112: }
18113: }
18114: }
18115: }
1.160.6.61 raeburn 18116: if (keys(%servers)) {
1.160.6.24 raeburn 18117: foreach my $server (keys(%servers)) {
18118: next if ($thismachine{$server});
1.160.6.27 raeburn 18119: my @cached;
18120: foreach my $name (@posscached) {
18121: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 18122: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
18123: if (ref($cachekeys->{$name}) eq 'HASH') {
18124: foreach my $key (keys(%{$cachekeys->{$name}})) {
18125: push(@cached,&escape($name).':'.&escape($key));
18126: }
18127: }
18128: } else {
18129: push(@cached,&escape($name).':'.&escape($dom));
18130: }
1.160.6.27 raeburn 18131: }
18132: }
1.160.6.113 raeburn 18133: if ((exists($cache_by_lonhost{$server})) &&
18134: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
18135: push(@cached,@{$cache_by_lonhost{$server}});
18136: }
1.160.6.27 raeburn 18137: if (@cached) {
18138: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
18139: }
1.160.6.24 raeburn 18140: }
18141: }
18142: return;
18143: }
18144:
1.3 raeburn 18145: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>